Skip to content

Commit

Permalink
Merge "Define, document, and test the behavior of very large SurfaceT…
Browse files Browse the repository at this point in the history
…extures" into ics-mr1
  • Loading branch information
pixelflinger authored and Android (Google) Code Review committed Nov 14, 2011
2 parents cde433c + b89d88f commit c93a151
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 7 deletions.
6 changes: 3 additions & 3 deletions core/jni/android/graphics/SurfaceTexture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,10 +212,10 @@ static void SurfaceTexture_setDefaultBufferSize(
surfaceTexture->setDefaultBufferSize(width, height);
}

static void SurfaceTexture_updateTexImage(JNIEnv* env, jobject thiz)
static jint SurfaceTexture_updateTexImage(JNIEnv* env, jobject thiz)
{
sp<SurfaceTexture> surfaceTexture(SurfaceTexture_getSurfaceTexture(env, thiz));
surfaceTexture->updateTexImage();
return surfaceTexture->updateTexImage();
}

static void SurfaceTexture_getTransformMatrix(JNIEnv* env, jobject thiz,
Expand Down Expand Up @@ -246,7 +246,7 @@ static JNINativeMethod gSurfaceTextureMethods[] = {
{"nativeInit", "(ILjava/lang/Object;Z)V", (void*)SurfaceTexture_init },
{"nativeFinalize", "()V", (void*)SurfaceTexture_finalize },
{"nativeSetDefaultBufferSize", "(II)V", (void*)SurfaceTexture_setDefaultBufferSize },
{"nativeUpdateTexImage", "()V", (void*)SurfaceTexture_updateTexImage },
{"nativeUpdateTexImage", "()I", (void*)SurfaceTexture_updateTexImage },
{"nativeGetTransformMatrix", "([F)V", (void*)SurfaceTexture_getTransformMatrix },
{"nativeGetTimestamp", "()J", (void*)SurfaceTexture_getTimestamp },
{"nativeRelease", "()V", (void*)SurfaceTexture_release },
Expand Down
14 changes: 12 additions & 2 deletions graphics/java/android/graphics/SurfaceTexture.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package android.graphics;

import java.lang.ref.WeakReference;

import android.os.Handler;
import android.os.Looper;
import android.os.Message;
Expand Down Expand Up @@ -141,6 +142,12 @@ public void setOnFrameAvailableListener(OnFrameAvailableListener l) {
* android.view.Surface#lockCanvas} is called. For OpenGL ES, the EGLSurface should be
* destroyed (via eglDestroySurface), made not-current (via eglMakeCurrent), and then recreated
* (via eglCreateWindowSurface) to ensure that the new default size has taken effect.
*
* The width and height parameters must be no greater than the minimum of
* GL_MAX_VIEWPORT_DIMS and GL_MAX_TEXTURE_SIZE (see
* {@link javax.microedition.khronos.opengles.GL10#glGetIntegerv glGetIntegerv}).
* An error due to invalid dimensions might not be reported until
* updateTexImage() is called.
*/
public void setDefaultBufferSize(int width, int height) {
nativeSetDefaultBufferSize(width, height);
Expand All @@ -152,7 +159,10 @@ public void setDefaultBufferSize(int width, int height) {
* implicitly bind its texture to the GL_TEXTURE_EXTERNAL_OES texture target.
*/
public void updateTexImage() {
nativeUpdateTexImage();
int err = nativeUpdateTexImage();
if (err != 0) {
throw new RuntimeException("Error during updateTexImage (see logs)");
}
}

/**
Expand Down Expand Up @@ -258,7 +268,7 @@ private static void postEventFromNative(Object selfRef) {
private native void nativeGetTransformMatrix(float[] mtx);
private native long nativeGetTimestamp();
private native void nativeSetDefaultBufferSize(int width, int height);
private native void nativeUpdateTexImage();
private native int nativeUpdateTexImage();
private native int nativeGetQueuedCount();
private native void nativeRelease();

Expand Down
12 changes: 10 additions & 2 deletions include/gui/SurfaceTexture.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,11 @@ class SurfaceTexture : public BnSurfaceTexture {
// pointed to by the buf argument and a status of OK is returned. If no
// slot is available then a status of -EBUSY is returned and buf is
// unmodified.
virtual status_t dequeueBuffer(int *buf, uint32_t w, uint32_t h,
// The width and height parameters must be no greater than the minimum of
// GL_MAX_VIEWPORT_DIMS and GL_MAX_TEXTURE_SIZE (see: glGetIntegerv).
// An error due to invalid dimensions might not be reported until
// updateTexImage() is called.
virtual status_t dequeueBuffer(int *buf, uint32_t width, uint32_t height,
uint32_t format, uint32_t usage);

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

// getCurrentBuffer returns the buffer associated with the current image.
sp<GraphicBuffer> getCurrentBuffer() const;
Expand Down
32 changes: 32 additions & 0 deletions libs/gui/tests/SurfaceTexture_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1520,4 +1520,36 @@ TEST_F(SurfaceTextureGLTest, EglDestroySurfaceAfterAbandonUnrefsBuffers) {
EXPECT_EQ(1, buffers[2]->getStrongCount());
}

TEST_F(SurfaceTextureGLTest, InvalidWidthOrHeightFails) {
int texHeight = 16;
ANativeWindowBuffer* anb;

GLint maxTextureSize;
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxTextureSize);

// make sure it works with small textures
mST->setDefaultBufferSize(16, texHeight);
EXPECT_EQ(NO_ERROR, mANW->dequeueBuffer(mANW.get(), &anb));
EXPECT_EQ(16, anb->width);
EXPECT_EQ(texHeight, anb->height);
EXPECT_EQ(NO_ERROR, mANW->queueBuffer(mANW.get(), anb));
EXPECT_EQ(NO_ERROR, mST->updateTexImage());

// make sure it works with GL_MAX_TEXTURE_SIZE
mST->setDefaultBufferSize(maxTextureSize, texHeight);
EXPECT_EQ(NO_ERROR, mANW->dequeueBuffer(mANW.get(), &anb));
EXPECT_EQ(maxTextureSize, anb->width);
EXPECT_EQ(texHeight, anb->height);
EXPECT_EQ(NO_ERROR, mANW->queueBuffer(mANW.get(), anb));
EXPECT_EQ(NO_ERROR, mST->updateTexImage());

// make sure it fails with GL_MAX_TEXTURE_SIZE+1
mST->setDefaultBufferSize(maxTextureSize+1, texHeight);
EXPECT_EQ(NO_ERROR, mANW->dequeueBuffer(mANW.get(), &anb));
EXPECT_EQ(maxTextureSize+1, anb->width);
EXPECT_EQ(texHeight, anb->height);
EXPECT_EQ(NO_ERROR, mANW->queueBuffer(mANW.get(), anb));
ASSERT_NE(NO_ERROR, mST->updateTexImage());
}

} // namespace android

0 comments on commit c93a151

Please sign in to comment.