Skip to content

Commit c93a151

Browse files
pixelflingerAndroid (Google) Code Review
authored andcommitted
Merge "Define, document, and test the behavior of very large SurfaceTextures" into ics-mr1
2 parents cde433c + b89d88f commit c93a151

File tree

4 files changed

+57
-7
lines changed

4 files changed

+57
-7
lines changed

core/jni/android/graphics/SurfaceTexture.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -212,10 +212,10 @@ static void SurfaceTexture_setDefaultBufferSize(
212212
surfaceTexture->setDefaultBufferSize(width, height);
213213
}
214214

215-
static void SurfaceTexture_updateTexImage(JNIEnv* env, jobject thiz)
215+
static jint SurfaceTexture_updateTexImage(JNIEnv* env, jobject thiz)
216216
{
217217
sp<SurfaceTexture> surfaceTexture(SurfaceTexture_getSurfaceTexture(env, thiz));
218-
surfaceTexture->updateTexImage();
218+
return surfaceTexture->updateTexImage();
219219
}
220220

221221
static void SurfaceTexture_getTransformMatrix(JNIEnv* env, jobject thiz,
@@ -246,7 +246,7 @@ static JNINativeMethod gSurfaceTextureMethods[] = {
246246
{"nativeInit", "(ILjava/lang/Object;Z)V", (void*)SurfaceTexture_init },
247247
{"nativeFinalize", "()V", (void*)SurfaceTexture_finalize },
248248
{"nativeSetDefaultBufferSize", "(II)V", (void*)SurfaceTexture_setDefaultBufferSize },
249-
{"nativeUpdateTexImage", "()V", (void*)SurfaceTexture_updateTexImage },
249+
{"nativeUpdateTexImage", "()I", (void*)SurfaceTexture_updateTexImage },
250250
{"nativeGetTransformMatrix", "([F)V", (void*)SurfaceTexture_getTransformMatrix },
251251
{"nativeGetTimestamp", "()J", (void*)SurfaceTexture_getTimestamp },
252252
{"nativeRelease", "()V", (void*)SurfaceTexture_release },

graphics/java/android/graphics/SurfaceTexture.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package android.graphics;
1818

1919
import java.lang.ref.WeakReference;
20+
2021
import android.os.Handler;
2122
import android.os.Looper;
2223
import android.os.Message;
@@ -141,6 +142,12 @@ public void setOnFrameAvailableListener(OnFrameAvailableListener l) {
141142
* android.view.Surface#lockCanvas} is called. For OpenGL ES, the EGLSurface should be
142143
* destroyed (via eglDestroySurface), made not-current (via eglMakeCurrent), and then recreated
143144
* (via eglCreateWindowSurface) to ensure that the new default size has taken effect.
145+
*
146+
* The width and height parameters must be no greater than the minimum of
147+
* GL_MAX_VIEWPORT_DIMS and GL_MAX_TEXTURE_SIZE (see
148+
* {@link javax.microedition.khronos.opengles.GL10#glGetIntegerv glGetIntegerv}).
149+
* An error due to invalid dimensions might not be reported until
150+
* updateTexImage() is called.
144151
*/
145152
public void setDefaultBufferSize(int width, int height) {
146153
nativeSetDefaultBufferSize(width, height);
@@ -152,7 +159,10 @@ public void setDefaultBufferSize(int width, int height) {
152159
* implicitly bind its texture to the GL_TEXTURE_EXTERNAL_OES texture target.
153160
*/
154161
public void updateTexImage() {
155-
nativeUpdateTexImage();
162+
int err = nativeUpdateTexImage();
163+
if (err != 0) {
164+
throw new RuntimeException("Error during updateTexImage (see logs)");
165+
}
156166
}
157167

158168
/**
@@ -258,7 +268,7 @@ private static void postEventFromNative(Object selfRef) {
258268
private native void nativeGetTransformMatrix(float[] mtx);
259269
private native long nativeGetTimestamp();
260270
private native void nativeSetDefaultBufferSize(int width, int height);
261-
private native void nativeUpdateTexImage();
271+
private native int nativeUpdateTexImage();
262272
private native int nativeGetQueuedCount();
263273
private native void nativeRelease();
264274

include/gui/SurfaceTexture.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,11 @@ class SurfaceTexture : public BnSurfaceTexture {
7979
// pointed to by the buf argument and a status of OK is returned. If no
8080
// slot is available then a status of -EBUSY is returned and buf is
8181
// unmodified.
82-
virtual status_t dequeueBuffer(int *buf, uint32_t w, uint32_t h,
82+
// The width and height parameters must be no greater than the minimum of
83+
// GL_MAX_VIEWPORT_DIMS and GL_MAX_TEXTURE_SIZE (see: glGetIntegerv).
84+
// An error due to invalid dimensions might not be reported until
85+
// updateTexImage() is called.
86+
virtual status_t dequeueBuffer(int *buf, uint32_t width, uint32_t height,
8387
uint32_t format, uint32_t usage);
8488

8589
// queueBuffer returns a filled buffer to the SurfaceTexture. In addition, a
@@ -176,7 +180,11 @@ class SurfaceTexture : public BnSurfaceTexture {
176180
// requestBuffers when a with and height of zero is requested.
177181
// A call to setDefaultBufferSize() may trigger requestBuffers() to
178182
// be called from the client.
179-
status_t setDefaultBufferSize(uint32_t w, uint32_t h);
183+
// The width and height parameters must be no greater than the minimum of
184+
// GL_MAX_VIEWPORT_DIMS and GL_MAX_TEXTURE_SIZE (see: glGetIntegerv).
185+
// An error due to invalid dimensions might not be reported until
186+
// updateTexImage() is called.
187+
status_t setDefaultBufferSize(uint32_t width, uint32_t height);
180188

181189
// getCurrentBuffer returns the buffer associated with the current image.
182190
sp<GraphicBuffer> getCurrentBuffer() const;

libs/gui/tests/SurfaceTexture_test.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1520,4 +1520,36 @@ TEST_F(SurfaceTextureGLTest, EglDestroySurfaceAfterAbandonUnrefsBuffers) {
15201520
EXPECT_EQ(1, buffers[2]->getStrongCount());
15211521
}
15221522

1523+
TEST_F(SurfaceTextureGLTest, InvalidWidthOrHeightFails) {
1524+
int texHeight = 16;
1525+
ANativeWindowBuffer* anb;
1526+
1527+
GLint maxTextureSize;
1528+
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxTextureSize);
1529+
1530+
// make sure it works with small textures
1531+
mST->setDefaultBufferSize(16, texHeight);
1532+
EXPECT_EQ(NO_ERROR, mANW->dequeueBuffer(mANW.get(), &anb));
1533+
EXPECT_EQ(16, anb->width);
1534+
EXPECT_EQ(texHeight, anb->height);
1535+
EXPECT_EQ(NO_ERROR, mANW->queueBuffer(mANW.get(), anb));
1536+
EXPECT_EQ(NO_ERROR, mST->updateTexImage());
1537+
1538+
// make sure it works with GL_MAX_TEXTURE_SIZE
1539+
mST->setDefaultBufferSize(maxTextureSize, texHeight);
1540+
EXPECT_EQ(NO_ERROR, mANW->dequeueBuffer(mANW.get(), &anb));
1541+
EXPECT_EQ(maxTextureSize, anb->width);
1542+
EXPECT_EQ(texHeight, anb->height);
1543+
EXPECT_EQ(NO_ERROR, mANW->queueBuffer(mANW.get(), anb));
1544+
EXPECT_EQ(NO_ERROR, mST->updateTexImage());
1545+
1546+
// make sure it fails with GL_MAX_TEXTURE_SIZE+1
1547+
mST->setDefaultBufferSize(maxTextureSize+1, texHeight);
1548+
EXPECT_EQ(NO_ERROR, mANW->dequeueBuffer(mANW.get(), &anb));
1549+
EXPECT_EQ(maxTextureSize+1, anb->width);
1550+
EXPECT_EQ(texHeight, anb->height);
1551+
EXPECT_EQ(NO_ERROR, mANW->queueBuffer(mANW.get(), anb));
1552+
ASSERT_NE(NO_ERROR, mST->updateTexImage());
1553+
}
1554+
15231555
} // namespace android

0 commit comments

Comments
 (0)