Skip to content

Commit 87f3265

Browse files
author
Jamie Gennis
committed
EGL: default to swap interval 1
This change explicitly sets swap interval 1 on the window when an EGLSurface is created to render to it. Change-Id: I91eb29dbee3ae4a55076b921f084d503fbe94e03
1 parent c10a94c commit 87f3265

File tree

4 files changed

+39
-0
lines changed

4 files changed

+39
-0
lines changed

include/gui/SurfaceTexture.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,10 @@ class SurfaceTexture : public BnSurfaceTexture {
202202
// getCurrentScalingMode returns the scaling mode of the current buffer
203203
uint32_t getCurrentScalingMode() const;
204204

205+
// isSynchronousMode returns whether the SurfaceTexture is currently in
206+
// synchronous mode.
207+
bool isSynchronousMode() const;
208+
205209
// abandon frees all the buffers and puts the SurfaceTexture into the
206210
// 'abandoned' state. Once put in this state the SurfaceTexture can never
207211
// leave it. When in the 'abandoned' state, all methods of the

libs/gui/SurfaceTexture.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,6 +1005,11 @@ uint32_t SurfaceTexture::getCurrentScalingMode() const {
10051005
return mCurrentScalingMode;
10061006
}
10071007

1008+
bool SurfaceTexture::isSynchronousMode() const {
1009+
Mutex::Autolock lock(mMutex);
1010+
return mSynchronousMode;
1011+
}
1012+
10081013
int SurfaceTexture::query(int what, int* outValue)
10091014
{
10101015
Mutex::Autolock lock(mMutex);

libs/gui/tests/SurfaceTexture_test.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1245,6 +1245,31 @@ TEST_F(SurfaceTextureGLToGLTest, EglDestroySurfaceAfterAbandonUnrefsBuffers) {
12451245
EXPECT_EQ(1, buffers[2]->getStrongCount());
12461246
}
12471247

1248+
TEST_F(SurfaceTextureGLToGLTest, EglSurfaceDefaultsToSynchronousMode) {
1249+
// This test requires 3 buffers to run on a single thread.
1250+
mST->setBufferCountServer(3);
1251+
1252+
ASSERT_TRUE(mST->isSynchronousMode());
1253+
1254+
for (int i = 0; i < 10; i++) {
1255+
// Produce a frame
1256+
EXPECT_TRUE(eglMakeCurrent(mEglDisplay, mProducerEglSurface,
1257+
mProducerEglSurface, mProducerEglContext));
1258+
ASSERT_EQ(EGL_SUCCESS, eglGetError());
1259+
glClear(GL_COLOR_BUFFER_BIT);
1260+
EXPECT_TRUE(eglSwapBuffers(mEglDisplay, mProducerEglSurface));
1261+
ASSERT_EQ(EGL_SUCCESS, eglGetError());
1262+
1263+
// Consume a frame
1264+
EXPECT_TRUE(eglMakeCurrent(mEglDisplay, mEglSurface, mEglSurface,
1265+
mEglContext));
1266+
ASSERT_EQ(EGL_SUCCESS, eglGetError());
1267+
ASSERT_EQ(NO_ERROR, mST->updateTexImage());
1268+
}
1269+
1270+
ASSERT_TRUE(mST->isSynchronousMode());
1271+
}
1272+
12481273
/*
12491274
* This test fixture is for testing GL -> GL texture streaming from one thread
12501275
* to another. It contains functionality to create a producer thread that will

opengl/libs/EGL/eglApi.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,11 @@ EGLSurface eglCreateWindowSurface( EGLDisplay dpy, EGLConfig config,
370370
}
371371
}
372372

373+
// the EGL spec requires that a new EGLSurface default to swap interval
374+
// 1, so explicitly set that on the window here.
375+
ANativeWindow* anw = reinterpret_cast<ANativeWindow*>(window);
376+
anw->setSwapInterval(anw, 1);
377+
373378
EGLSurface surface = cnx->egl.eglCreateWindowSurface(
374379
iDpy, iConfig, window, attrib_list);
375380
if (surface != EGL_NO_SURFACE) {

0 commit comments

Comments
 (0)