Skip to content

Commit 8606fef

Browse files
author
Jamie Gennis
committed
SurfaceTexture: parameterize the texture target
This change adds a hack to allow Android Browser to use a SurfaceTexture to stream RGBA images to a GL_TEXTURE_2D texture object. Change-Id: Idb90064d5d4b920959ef3be7451362ac5012460e
1 parent ce0a7ad commit 8606fef

2 files changed

Lines changed: 19 additions & 8 deletions

File tree

include/gui/SurfaceTexture.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <EGL/egl.h>
2121
#include <EGL/eglext.h>
2222
#include <GLES2/gl2.h>
23+
#include <GLES2/gl2ext.h>
2324

2425
#include <gui/ISurfaceTexture.h>
2526

@@ -61,7 +62,8 @@ class SurfaceTexture : public BnSurfaceTexture {
6162

6263
// tex indicates the name OpenGL texture to which images are to be streamed.
6364
// This texture name cannot be changed once the SurfaceTexture is created.
64-
SurfaceTexture(GLuint tex, bool allowSynchronousMode = true);
65+
SurfaceTexture(GLuint tex, bool allowSynchronousMode = true,
66+
GLenum texTarget = GL_TEXTURE_EXTERNAL_OES);
6567

6668
virtual ~SurfaceTexture();
6769

@@ -458,6 +460,14 @@ class SurfaceTexture : public BnSurfaceTexture {
458460
// member variables are accessed.
459461
mutable Mutex mMutex;
460462

463+
// mTexTarget is the GL texture target with which the GL texture object is
464+
// associated. It is set in the constructor and never changed. It is
465+
// almost always GL_TEXTURE_EXTERNAL_OES except for one use case in Android
466+
// Browser. In that case it is set to GL_TEXTURE_2D to allow
467+
// glCopyTexSubImage to read from the texture. This is a hack to work
468+
// around a GL driver limitation on the number of FBO attachments, which the
469+
// browser's tile cache exceeds.
470+
const GLenum mTexTarget;
461471
};
462472

463473
// ----------------------------------------------------------------------------

libs/gui/SurfaceTexture.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ static int32_t createProcessUniqueId() {
9494
return android_atomic_inc(&globalCounter);
9595
}
9696

97-
SurfaceTexture::SurfaceTexture(GLuint tex, bool allowSynchronousMode) :
97+
SurfaceTexture::SurfaceTexture(GLuint tex, bool allowSynchronousMode,
98+
GLenum texTarget) :
9899
mDefaultWidth(1),
99100
mDefaultHeight(1),
100101
mPixelFormat(PIXEL_FORMAT_RGBA_8888),
@@ -110,7 +111,8 @@ SurfaceTexture::SurfaceTexture(GLuint tex, bool allowSynchronousMode) :
110111
mSynchronousMode(false),
111112
mAllowSynchronousMode(allowSynchronousMode),
112113
mConnectedApi(NO_CONNECTED_API),
113-
mAbandoned(false) {
114+
mAbandoned(false),
115+
mTexTarget(texTarget) {
114116
// Choose a name using the PID and a process-unique ID.
115117
mName = String8::format("unnamed-%d-%d", getpid(), createProcessUniqueId());
116118

@@ -698,9 +700,8 @@ status_t SurfaceTexture::updateTexImage() {
698700
ST_LOGW("updateTexImage: clearing GL error: %#04x", error);
699701
}
700702

701-
glBindTexture(GL_TEXTURE_EXTERNAL_OES, mTexName);
702-
glEGLImageTargetTexture2DOES(GL_TEXTURE_EXTERNAL_OES,
703-
(GLeglImageOES)image);
703+
glBindTexture(mTexTarget, mTexName);
704+
glEGLImageTargetTexture2DOES(mTexTarget, (GLeglImageOES)image);
704705

705706
bool failed = false;
706707
while ((error = glGetError()) != GL_NO_ERROR) {
@@ -735,7 +736,7 @@ status_t SurfaceTexture::updateTexImage() {
735736
mDequeueCondition.signal();
736737
} else {
737738
// We always bind the texture even if we don't update its contents.
738-
glBindTexture(GL_TEXTURE_EXTERNAL_OES, mTexName);
739+
glBindTexture(mTexTarget, mTexName);
739740
}
740741

741742
return OK;
@@ -761,7 +762,7 @@ bool SurfaceTexture::isExternalFormat(uint32_t format)
761762
}
762763

763764
GLenum SurfaceTexture::getCurrentTextureTarget() const {
764-
return GL_TEXTURE_EXTERNAL_OES;
765+
return mTexTarget;
765766
}
766767

767768
void SurfaceTexture::getTransformMatrix(float mtx[16]) {

0 commit comments

Comments
 (0)