Bug 1913568 - Add texture transform support to GLReadTexImageHelper. r=gfx-reviewers,nical
Add the capability to transform the texture coordinates when reading from a texture, similar to existing support in GLBlitHelper and CompositorOGL. This patch doesn't change any behaviour, but this capability will be made use of by a later patch in this series. Differential Revision: https://phabricator.services.mozilla.com/D220580
This commit is contained in:
@@ -41,8 +41,12 @@ GLReadTexImageHelper::~GLReadTexImageHelper() {
|
||||
static const GLchar readTextureImageVS[] =
|
||||
"attribute vec2 aVertex;\n"
|
||||
"attribute vec2 aTexCoord;\n"
|
||||
"uniform mat4 uTexMatrix;\n"
|
||||
"varying vec2 vTexCoord;\n"
|
||||
"void main() { gl_Position = vec4(aVertex, 0, 1); vTexCoord = aTexCoord; }";
|
||||
"void main() {\n"
|
||||
" gl_Position = vec4(aVertex, 0, 1);\n"
|
||||
" vTexCoord = (uTexMatrix * vec4(aTexCoord, 0.0, 1.0)).xy;\n"
|
||||
"}";
|
||||
|
||||
static const GLchar readTextureImageFS_TEXTURE_2D[] =
|
||||
"#ifdef GL_ES\n"
|
||||
@@ -482,6 +486,7 @@ already_AddRefed<DataSourceSurface> ReadBackSurface(GLContext* gl,
|
||||
|
||||
already_AddRefed<DataSourceSurface> GLReadTexImageHelper::ReadTexImage(
|
||||
GLuint aTextureId, GLenum aTextureTarget, const gfx::IntSize& aSize,
|
||||
const gfx::Matrix4x4& aTexMatrix,
|
||||
/* ShaderConfigOGL.mFeature */ int aConfig, bool aYInvert) {
|
||||
/* Allocate resulting image surface */
|
||||
int32_t stride = aSize.width * BytesPerPixel(SurfaceFormat::R8G8B8A8);
|
||||
@@ -491,8 +496,8 @@ already_AddRefed<DataSourceSurface> GLReadTexImageHelper::ReadTexImage(
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (!ReadTexImage(isurf, aTextureId, aTextureTarget, aSize, aConfig,
|
||||
aYInvert)) {
|
||||
if (!ReadTexImage(isurf, aTextureId, aTextureTarget, aSize, aTexMatrix,
|
||||
aConfig, aYInvert)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -501,7 +506,7 @@ already_AddRefed<DataSourceSurface> GLReadTexImageHelper::ReadTexImage(
|
||||
|
||||
bool GLReadTexImageHelper::ReadTexImage(
|
||||
DataSourceSurface* aDest, GLuint aTextureId, GLenum aTextureTarget,
|
||||
const gfx::IntSize& aSize,
|
||||
const gfx::IntSize& aSize, const gfx::Matrix4x4& aTexMatrix,
|
||||
/* ShaderConfigOGL.mFeature */ int aConfig, bool aYInvert) {
|
||||
MOZ_ASSERT(aTextureTarget == LOCAL_GL_TEXTURE_2D ||
|
||||
aTextureTarget == LOCAL_GL_TEXTURE_EXTERNAL ||
|
||||
@@ -567,7 +572,10 @@ bool GLReadTexImageHelper::ReadTexImage(
|
||||
mGL->fUseProgram(program);
|
||||
CLEANUP_IF_GLERROR_OCCURRED("when using program");
|
||||
mGL->fUniform1i(mGL->fGetUniformLocation(program, "uTexture"), 0);
|
||||
CLEANUP_IF_GLERROR_OCCURRED("when setting uniform location");
|
||||
CLEANUP_IF_GLERROR_OCCURRED("when setting uniform uTexture");
|
||||
mGL->fUniformMatrix4fv(mGL->fGetUniformLocation(program, "uTexMatrix"), 1,
|
||||
false, aTexMatrix.components);
|
||||
CLEANUP_IF_GLERROR_OCCURRED("when setting uniform uTexMatrix");
|
||||
|
||||
/* Setup quad geometry */
|
||||
mGL->fBindBuffer(LOCAL_GL_ARRAY_BUFFER, 0);
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include "mozilla/Attributes.h"
|
||||
#include "nsSize.h"
|
||||
#include "mozilla/RefPtr.h"
|
||||
#include "mozilla/gfx/MatrixFwd.h"
|
||||
#include "mozilla/gfx/Types.h"
|
||||
|
||||
namespace mozilla {
|
||||
@@ -72,11 +73,13 @@ class GLReadTexImageHelper final {
|
||||
*/
|
||||
already_AddRefed<gfx::DataSourceSurface> ReadTexImage(
|
||||
GLuint aTextureId, GLenum aTextureTarget, const gfx::IntSize& aSize,
|
||||
const gfx::Matrix4x4& aTexMatrix,
|
||||
/* ShaderProgramType */ int aShaderProgram, bool aYInvert = false);
|
||||
|
||||
bool ReadTexImage(gfx::DataSourceSurface* aDest, GLuint aTextureId,
|
||||
GLenum aTextureTarget, const gfx::IntSize& aSize,
|
||||
int aShaderProgram, bool aYInvert = false);
|
||||
const gfx::Matrix4x4& aTexMatrix, int aShaderProgram,
|
||||
bool aYInvert = false);
|
||||
};
|
||||
|
||||
} // namespace gl
|
||||
|
||||
@@ -209,8 +209,8 @@ RenderAndroidHardwareBufferTextureHost::ReadTexImage() {
|
||||
int shaderConfig = config.mFeatures;
|
||||
|
||||
bool ret = mGL->ReadTexImageHelper()->ReadTexImage(
|
||||
surf, mTextureHandle, LOCAL_GL_TEXTURE_EXTERNAL, GetSize(), shaderConfig,
|
||||
/* aYInvert */ false);
|
||||
surf, mTextureHandle, LOCAL_GL_TEXTURE_EXTERNAL, GetSize(),
|
||||
gfx::Matrix4x4(), shaderConfig, /* aYInvert */ false);
|
||||
if (!ret) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -251,7 +251,7 @@ RenderAndroidSurfaceTextureHost::ReadTexImage() {
|
||||
|
||||
bool ret = mGL->ReadTexImageHelper()->ReadTexImage(
|
||||
surf, mSurfTex->GetTexName(), LOCAL_GL_TEXTURE_EXTERNAL, mSize,
|
||||
shaderConfig, /* aYInvert */ false);
|
||||
gfx::Matrix4x4(), shaderConfig, /* aYInvert */ false);
|
||||
if (!ret) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -209,8 +209,8 @@ RenderEGLImageTextureHost::ReadTexImage() {
|
||||
int shaderConfig = config.mFeatures;
|
||||
|
||||
bool ret = mGL->ReadTexImageHelper()->ReadTexImage(
|
||||
surf, mTextureHandle, mTextureTarget, mSize, shaderConfig,
|
||||
/* aYInvert */ false);
|
||||
surf, mTextureHandle, mTextureTarget, mSize, gfx::Matrix4x4(),
|
||||
shaderConfig, /* aYInvert */ false);
|
||||
if (!ret) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user