1 /*-------------------------------------------------------------------------
2 * drawElements Quality Program EGL Module
3 * ---------------------------------------
5 * Copyright 2017 The Android Open Source Project
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
21 * \brief Test the EGL_ANDROID_get_frame_timestamps extension.
22 *//*--------------------------------------------------------------------*/
24 #include "teglGetFrameTimestampsTests.hpp"
26 #include "teglSimpleConfigCase.hpp"
28 #include "egluNativeWindow.hpp"
29 #include "egluUtil.hpp"
30 #include "egluUnique.hpp"
31 #include "eglwLibrary.hpp"
32 #include "eglwEnums.hpp"
34 #include "gluDefs.hpp"
35 #include "glwEnums.hpp"
36 #include "glwFunctions.hpp"
38 #include "tcuResultCollector.hpp"
39 #include "tcuTestLog.hpp"
40 #include "tcuSurface.hpp"
41 #include "tcuTexture.hpp"
42 #include "tcuTextureUtil.hpp"
43 #include "tcuImageCompare.hpp"
44 #include "tcuVector.hpp"
45 #include "tcuVectorUtil.hpp"
49 #include "deUniquePtr.hpp"
50 #include "deThread.hpp"
57 // Tentative EGL header definitions for EGL_ANDROID_get_Frame_timestamps.
58 // \todo [2017-01-25 brianderson] Remove once defined in the official headers.
59 #define EGL_TIMESTAMPS_ANDROID 0x3430
60 #define EGL_COMPOSITE_DEADLINE_ANDROID 0x3431
61 #define EGL_COMPOSITE_INTERVAL_ANDROID 0x3432
62 #define EGL_COMPOSITE_TO_PRESENT_LATENCY_ANDROID 0x3433
63 #define EGL_REQUESTED_PRESENT_TIME_ANDROID 0x3434
64 #define EGL_RENDERING_COMPLETE_TIME_ANDROID 0x3435
65 #define EGL_COMPOSITION_LATCH_TIME_ANDROID 0x3436
66 #define EGL_FIRST_COMPOSITION_START_TIME_ANDROID 0x3437
67 #define EGL_LAST_COMPOSITION_START_TIME_ANDROID 0x3438
68 #define EGL_FIRST_COMPOSITION_GPU_FINISHED_TIME_ANDROID 0x3439
69 #define EGL_DISPLAY_PRESENT_TIME_ANDROID 0x343A
70 #define EGL_DEQUEUE_READY_TIME_ANDROID 0x343B
71 #define EGL_READS_DONE_TIME_ANDROID 0x343C
72 typedef deInt64 EGLnsecsANDROID;
73 typedef deUint64 EGLuint64KHR;
74 #define EGL_TIMESTAMP_PENDING_ANDROID (-2)
75 #define EGL_TIMESTAMP_INVALID_ANDROID (-1)
76 typedef EGLW_APICALL eglw::EGLBoolean (EGLW_APIENTRY* eglGetNextFrameIdANDROIDFunc) (eglw::EGLDisplay dpy, eglw::EGLSurface surface, EGLuint64KHR *frameId);
77 typedef EGLW_APICALL eglw::EGLBoolean (EGLW_APIENTRY* eglGetCompositorTimingANDROIDFunc) (eglw::EGLDisplay dpy, eglw::EGLSurface surface, eglw::EGLint numTimestamps, const eglw::EGLint *names, EGLnsecsANDROID *values);
78 typedef EGLW_APICALL eglw::EGLBoolean (EGLW_APIENTRY* eglGetCompositorTimingSupportedANDROIDFunc) (eglw::EGLDisplay dpy, eglw::EGLSurface surface, eglw::EGLint name);
79 typedef EGLW_APICALL eglw::EGLBoolean (EGLW_APIENTRY* eglGetFrameTimestampsANDROIDFunc) (eglw::EGLDisplay dpy, eglw::EGLSurface surface, EGLuint64KHR frameId, eglw::EGLint numTimestamps, const eglw::EGLint *timestamps, EGLnsecsANDROID *values);
80 typedef EGLW_APICALL eglw::EGLBoolean (EGLW_APIENTRY* eglGetFrameTimestampSupportedANDROIDFunc) (eglw::EGLDisplay dpy, eglw::EGLSurface surface, eglw::EGLint timestamp);
82 #define CHECK_NAKED_EGL_CALL(EGLW, CALL) do { CALL; eglu::checkError((EGLW).getError(), #CALL, __FILE__, __LINE__); } while (deGetFalse())
97 // Careful: This has microsecond precision, which can cause timestamps to
98 // appear non monotonic when compared to the nanosecond precision timestamps
99 // we get from the eglGetFrameTimestamps extension.
100 // Current test expectations only make sure microsecond precision timestamps
101 // are less than the nanosecond precision timestamps, so this is okay.
102 EGLnsecsANDROID getNanoseconds (void)
104 return deGetMicroseconds() * 1000;
111 , swapBufferBeginNs (-1)
112 , compositeDeadline (-1)
113 , compositeInterval (-1)
114 , compositeToPresentLatency (-1)
115 , requestedPresent (-1)
117 , firstCompositionStart (-1)
118 , lastCompositionStart (-1)
120 , renderingComplete (-1)
121 , firstCompositionGpuFinished (-1)
122 , displayPresent (-1)
127 EGLuint64KHR frameId;
129 // Timestamps sampled by the test.
130 EGLnsecsANDROID swapBufferBeginNs;
133 EGLnsecsANDROID compositeDeadline;
134 EGLnsecsANDROID compositeInterval;
135 EGLnsecsANDROID compositeToPresentLatency;
138 EGLnsecsANDROID requestedPresent;
139 EGLnsecsANDROID latch;
140 EGLnsecsANDROID firstCompositionStart;
141 EGLnsecsANDROID lastCompositionStart;
142 EGLnsecsANDROID dequeueReady;
145 EGLnsecsANDROID renderingComplete;
146 EGLnsecsANDROID firstCompositionGpuFinished;
147 EGLnsecsANDROID displayPresent;
148 EGLnsecsANDROID readsDone;
161 TimestampInfo(bool required_, bool supported_, size_t supportedIndex_)
162 : required(required_)
163 , supported(supported_)
164 , supportedIndex(supportedIndex_)
170 size_t supportedIndex;
173 typedef std::map<eglw::EGLint, TimestampInfo> TimestampInfoMap;
175 EGLnsecsANDROID getTimestamp(eglw::EGLint name, TimestampInfoMap& map, const std::vector<EGLnsecsANDROID>& supportedValues)
177 TimestampInfo& info = map[name];
178 return info.supported ? supportedValues[info.supportedIndex] : EGL_TIMESTAMP_INVALID_ANDROID;
181 void populateFrameTimes(FrameTimes* frameTimes, TimestampInfoMap& map, const std::vector<EGLnsecsANDROID>& supportedValues)
183 frameTimes->requestedPresent = getTimestamp(EGL_REQUESTED_PRESENT_TIME_ANDROID, map, supportedValues);
184 frameTimes->renderingComplete = getTimestamp(EGL_RENDERING_COMPLETE_TIME_ANDROID, map, supportedValues);
185 frameTimes->latch = getTimestamp(EGL_COMPOSITION_LATCH_TIME_ANDROID, map, supportedValues);
186 frameTimes->firstCompositionStart = getTimestamp(EGL_FIRST_COMPOSITION_START_TIME_ANDROID, map, supportedValues);
187 frameTimes->lastCompositionStart = getTimestamp(EGL_LAST_COMPOSITION_START_TIME_ANDROID, map, supportedValues);
188 frameTimes->firstCompositionGpuFinished = getTimestamp(EGL_FIRST_COMPOSITION_GPU_FINISHED_TIME_ANDROID, map, supportedValues);
189 frameTimes->displayPresent = getTimestamp(EGL_DISPLAY_PRESENT_TIME_ANDROID, map, supportedValues);
190 frameTimes->dequeueReady = getTimestamp(EGL_DEQUEUE_READY_TIME_ANDROID, map, supportedValues);
191 frameTimes->readsDone = getTimestamp(EGL_READS_DONE_TIME_ANDROID, map, supportedValues);
194 bool timestampValid (EGLnsecsANDROID timestamp)
196 return (timestamp >= 0) || (timestamp == EGL_TIMESTAMP_PENDING_ANDROID);
199 bool timestampPending (EGLnsecsANDROID timestamp)
201 return timestamp == EGL_TIMESTAMP_PENDING_ANDROID;
204 void verifySingleFrame (const FrameTimes& frameTimes, tcu::ResultCollector& result, bool verifyReadsDone)
206 // Verify CPU timeline is monotonic.
207 result.check(frameTimes.swapBufferBeginNs < frameTimes.latch, "Buffer latched before it was swapped.");
208 result.check(frameTimes.latch < frameTimes.firstCompositionStart, "Buffer composited before it was latched.");
209 result.check(frameTimes.firstCompositionStart <= frameTimes.lastCompositionStart, "First composition start after last composition start.");
210 result.check(frameTimes.lastCompositionStart < frameTimes.dequeueReady, "Buffer composited after it was ready to be dequeued.");
212 // Verify GPU timeline is monotonic.
213 if (timestampValid(frameTimes.firstCompositionGpuFinished))
214 result.check(frameTimes.renderingComplete < frameTimes.firstCompositionGpuFinished, "Buffer rendering completed after compositor GPU work finished.");
216 if (timestampValid(frameTimes.displayPresent))
217 result.check(frameTimes.renderingComplete < frameTimes.displayPresent, "Buffer displayed before rendering completed.");
219 if (timestampValid(frameTimes.firstCompositionGpuFinished) && timestampValid(frameTimes.displayPresent))
220 result.check(frameTimes.firstCompositionGpuFinished < frameTimes.displayPresent, "Buffer displayed before compositor GPU work completed");
222 // Drivers may maintain shadow copies of the buffer, so the readsDone time
223 // of the real buffer may be earlier than apparent dependencies. We can only
224 // be sure that the readsDone time must be after the renderingComplete time.
226 result.check(frameTimes.renderingComplete < frameTimes.readsDone, "Buffer rendering completed after reads completed.");
228 // Verify CPU/GPU dependencies
229 result.check(frameTimes.renderingComplete < frameTimes.latch, "Buffer latched before rendering completed.");
230 if (timestampValid(frameTimes.firstCompositionGpuFinished))
231 result.check(frameTimes.firstCompositionStart < frameTimes.firstCompositionGpuFinished, "Composition CPU work started after GPU work finished.");
233 if (timestampValid(frameTimes.displayPresent))
234 result.check(frameTimes.firstCompositionStart < frameTimes.displayPresent, "Buffer displayed before it was composited.");
237 void verifyNeighboringFrames (const FrameTimes& frame1, const FrameTimes& frame2, tcu::ResultCollector& result, bool verifyReadsDone)
240 result.check(frame1.swapBufferBeginNs < frame2.swapBufferBeginNs, "Swap begin times not monotonic.");
241 result.check(frame1.latch < frame2.latch, "Latch times not monotonic.");
242 result.check(frame1.lastCompositionStart < frame2.latch, "Old buffer composited after new buffer latched.");
243 result.check(frame1.lastCompositionStart < frame2.firstCompositionStart, "Composition times overlap.");
244 result.check(frame1.dequeueReady < frame2.dequeueReady, "Dequeue ready times not monotonic.");
247 result.check(frame1.renderingComplete < frame2.renderingComplete, "Rendering complete times not monotonic.");
249 if (timestampValid(frame1.firstCompositionGpuFinished) && timestampValid(frame2.firstCompositionGpuFinished))
250 result.check(frame1.firstCompositionGpuFinished < frame2.firstCompositionGpuFinished, "Composition GPU work complete times not monotonic.");
252 if (timestampValid(frame1.displayPresent) && timestampValid(frame2.displayPresent))
253 result.check(frame1.displayPresent < frame2.displayPresent, "Display present times not monotonic.");
255 if (verifyReadsDone && timestampValid(frame1.readsDone) && timestampValid(frame2.readsDone))
256 result.check(frame1.readsDone < frame2.readsDone, "Reads done times not monotonic.");
259 EGLContext createGLES2Context (const Library& egl, EGLDisplay display, EGLConfig config)
261 EGLContext context = EGL_NO_CONTEXT;
262 const EGLint attribList[] =
264 EGL_CONTEXT_CLIENT_VERSION, 2,
268 EGLU_CHECK_CALL(egl, bindAPI(EGL_OPENGL_ES_API));
270 context = egl.createContext(display, config, EGL_NO_CONTEXT, attribList);
271 EGLU_CHECK_MSG(egl, "eglCreateContext() failed");
277 class GetFrameTimestampTest : public SimpleConfigCase
280 GetFrameTimestampTest (EglTestContext& eglTestCtx, const NamedFilterList& filters);
281 ~GetFrameTimestampTest (void);
284 void executeForConfig (EGLDisplay display, EGLConfig config);
285 void initializeExtension (const Library& egl);
288 GetFrameTimestampTest (const GetFrameTimestampTest&);
289 GetFrameTimestampTest& operator= (const GetFrameTimestampTest&);
291 // TODO: Move these to eglw::Library.
292 eglGetNextFrameIdANDROIDFunc m_eglGetNextFrameIdANDROID;
293 eglGetCompositorTimingANDROIDFunc m_eglGetCompositorTimingANDROID;
294 eglGetCompositorTimingSupportedANDROIDFunc m_eglGetCompositorTimingSupportedANDROID;
295 eglGetFrameTimestampsANDROIDFunc m_eglGetFrameTimestampsANDROID;
296 eglGetFrameTimestampSupportedANDROIDFunc m_eglGetFrameTimestampSupportedANDROID;
298 tcu::ResultCollector m_result;
301 GetFrameTimestampTest::GetFrameTimestampTest (EglTestContext& eglTestCtx, const NamedFilterList& filters)
302 : SimpleConfigCase (eglTestCtx, filters.getName(), filters.getDescription(), filters)
303 , m_eglGetNextFrameIdANDROID (DE_NULL)
304 , m_eglGetCompositorTimingANDROID (DE_NULL)
305 , m_eglGetCompositorTimingSupportedANDROID (DE_NULL)
306 , m_eglGetFrameTimestampsANDROID (DE_NULL)
307 , m_eglGetFrameTimestampSupportedANDROID (DE_NULL)
308 , m_result (m_testCtx.getLog())
312 GetFrameTimestampTest::~GetFrameTimestampTest (void)
316 void GetFrameTimestampTest::initializeExtension (const Library& egl)
318 m_eglGetNextFrameIdANDROID = reinterpret_cast<eglGetNextFrameIdANDROIDFunc>(egl.getProcAddress("eglGetNextFrameIdANDROID"));
319 EGLU_CHECK_MSG(egl, "getProcAddress of eglGetNextFrameIdANDROID failed.");
320 m_eglGetCompositorTimingANDROID = reinterpret_cast<eglGetCompositorTimingANDROIDFunc>(egl.getProcAddress("eglGetCompositorTimingANDROID"));
321 EGLU_CHECK_MSG(egl, "getProcAddress of eglGetCompositorTimingANDROID failed.");
322 m_eglGetCompositorTimingSupportedANDROID = reinterpret_cast<eglGetCompositorTimingSupportedANDROIDFunc>(egl.getProcAddress("eglGetCompositorTimingSupportedANDROID"));
323 EGLU_CHECK_MSG(egl, "getProcAddress of eglGetCompositorTimingSupportedANDROID failed.");
324 m_eglGetFrameTimestampsANDROID = reinterpret_cast<eglGetFrameTimestampsANDROIDFunc>(egl.getProcAddress("eglGetFrameTimestampsANDROID"));
325 EGLU_CHECK_MSG(egl, "getProcAddress of eglGetFrameTimestampsANDROID failed.");
326 m_eglGetFrameTimestampSupportedANDROID = reinterpret_cast<eglGetFrameTimestampSupportedANDROIDFunc>(egl.getProcAddress("eglGetFrameTimestampSupportedANDROID"));
327 EGLU_CHECK_MSG(egl, "getProcAddress of eglGetFrameTimestampSupportedANDROID failed.");
331 string getConfigIdString (const Library& egl, EGLDisplay display, EGLConfig config)
333 std::ostringstream stream;
336 EGLU_CHECK_CALL(egl, getConfigAttrib(display, config , EGL_CONFIG_ID, &id));
343 deUint32 createGLES2Program (const glw::Functions& gl, TestLog& log)
345 const char* const vertexShaderSource =
346 "attribute highp vec2 a_pos;\n"
349 "\tgl_Position = vec4(a_pos, 0.0, 1.0);\n"
352 const char* const fragmentShaderSource =
355 "\tgl_FragColor = vec4(0.9, 0.1, 0.4, 1.0);\n"
358 deUint32 program = 0;
359 deUint32 vertexShader = 0;
360 deUint32 fragmentShader = 0;
362 deInt32 vertexCompileStatus;
363 string vertexInfoLog;
364 deInt32 fragmentCompileStatus;
365 string fragmentInfoLog;
367 string programInfoLog;
371 program = gl.createProgram();
372 vertexShader = gl.createShader(GL_VERTEX_SHADER);
373 fragmentShader = gl.createShader(GL_FRAGMENT_SHADER);
375 GLU_EXPECT_NO_ERROR(gl.getError(), "Failed to create shaders and program");
377 gl.shaderSource(vertexShader, 1, &vertexShaderSource, DE_NULL);
378 gl.compileShader(vertexShader);
379 GLU_EXPECT_NO_ERROR(gl.getError(), "Failed to setup vertex shader");
381 gl.shaderSource(fragmentShader, 1, &fragmentShaderSource, DE_NULL);
382 gl.compileShader(fragmentShader);
383 GLU_EXPECT_NO_ERROR(gl.getError(), "Failed to setup fragment shader");
386 deInt32 infoLogLength = 0;
388 gl.getShaderiv(vertexShader, GL_COMPILE_STATUS, &vertexCompileStatus);
389 gl.getShaderiv(vertexShader, GL_INFO_LOG_LENGTH, &infoLogLength);
391 vertexInfoLog.resize(infoLogLength, '\0');
393 gl.getShaderInfoLog(vertexShader, (glw::GLsizei)vertexInfoLog.length(), &infoLogLength, &(vertexInfoLog[0]));
394 GLU_EXPECT_NO_ERROR(gl.getError(), "Failed to get vertex shader compile info");
396 vertexInfoLog.resize(infoLogLength);
400 deInt32 infoLogLength = 0;
402 gl.getShaderiv(fragmentShader, GL_COMPILE_STATUS, &fragmentCompileStatus);
403 gl.getShaderiv(fragmentShader, GL_INFO_LOG_LENGTH, &infoLogLength);
405 fragmentInfoLog.resize(infoLogLength, '\0');
407 gl.getShaderInfoLog(fragmentShader, (glw::GLsizei)fragmentInfoLog.length(), &infoLogLength, &(fragmentInfoLog[0]));
408 GLU_EXPECT_NO_ERROR(gl.getError(), "Failed to get fragment shader compile info");
410 fragmentInfoLog.resize(infoLogLength);
413 gl.attachShader(program, vertexShader);
414 gl.attachShader(program, fragmentShader);
415 gl.linkProgram(program);
416 GLU_EXPECT_NO_ERROR(gl.getError(), "Failed to setup program");
419 deInt32 infoLogLength = 0;
421 gl.getProgramiv(program, GL_LINK_STATUS, &linkStatus);
422 gl.getProgramiv(program, GL_INFO_LOG_LENGTH, &infoLogLength);
424 programInfoLog.resize(infoLogLength, '\0');
426 gl.getProgramInfoLog(program, (glw::GLsizei)programInfoLog.length(), &infoLogLength, &(programInfoLog[0]));
427 GLU_EXPECT_NO_ERROR(gl.getError(), "Failed to get program link info");
429 programInfoLog.resize(infoLogLength);
432 if (linkStatus == 0 || vertexCompileStatus == 0 || fragmentCompileStatus == 0)
435 log.startShaderProgram(linkStatus != 0, programInfoLog.c_str());
437 log << TestLog::Shader(QP_SHADER_TYPE_VERTEX, vertexShaderSource, vertexCompileStatus != 0, vertexInfoLog);
438 log << TestLog::Shader(QP_SHADER_TYPE_FRAGMENT, fragmentShaderSource, fragmentCompileStatus != 0, fragmentInfoLog);
440 log.endShaderProgram();
443 gl.deleteShader(vertexShader);
444 gl.deleteShader(fragmentShader);
445 GLU_EXPECT_NO_ERROR(gl.getError(), "Failed to delete shaders");
447 TCU_CHECK(linkStatus != 0 && vertexCompileStatus != 0 && fragmentCompileStatus != 0);
452 gl.deleteProgram(program);
455 gl.deleteShader(vertexShader);
458 gl.deleteShader(fragmentShader);
466 void GetFrameTimestampTest::executeForConfig (EGLDisplay display, EGLConfig config)
468 const Library& egl = m_eglTestCtx.getLibrary();
470 if (!eglu::hasExtension(egl, display, "EGL_ANDROID_get_frame_timestamps"))
471 TCU_THROW(NotSupportedError, "EGL_ANDROID_get_frame_timestamps is not supported");
473 initializeExtension(egl);
475 const string configIdStr (getConfigIdString(egl, display, config));
476 tcu::ScopedLogSection logSection (m_testCtx.getLog(), ("Config ID " + configIdStr).c_str(), ("Config ID " + configIdStr).c_str());
477 const eglu::NativeWindowFactory& factory = eglu::selectNativeWindowFactory(m_eglTestCtx.getNativeDisplayFactory(), m_testCtx.getCommandLine());
480 TestLog& log = m_testCtx.getLog();
482 log << TestLog::Message << "EGL_RED_SIZE: " << eglu::getConfigAttribInt(egl, display, config, EGL_RED_SIZE) << TestLog::EndMessage;
483 log << TestLog::Message << "EGL_GREEN_SIZE: " << eglu::getConfigAttribInt(egl, display, config, EGL_GREEN_SIZE) << TestLog::EndMessage;
484 log << TestLog::Message << "EGL_BLUE_SIZE: " << eglu::getConfigAttribInt(egl, display, config, EGL_BLUE_SIZE) << TestLog::EndMessage;
485 log << TestLog::Message << "EGL_ALPHA_SIZE: " << eglu::getConfigAttribInt(egl, display, config, EGL_ALPHA_SIZE) << TestLog::EndMessage;
486 log << TestLog::Message << "EGL_DEPTH_SIZE: " << eglu::getConfigAttribInt(egl, display, config, EGL_DEPTH_SIZE) << TestLog::EndMessage;
487 log << TestLog::Message << "EGL_STENCIL_SIZE: " << eglu::getConfigAttribInt(egl, display, config, EGL_STENCIL_SIZE) << TestLog::EndMessage;
488 log << TestLog::Message << "EGL_SAMPLES: " << eglu::getConfigAttribInt(egl, display, config, EGL_SAMPLES) << TestLog::EndMessage;
491 de::UniquePtr<eglu::NativeWindow> window (factory.createWindow(&m_eglTestCtx.getNativeDisplay(), display, config, DE_NULL, eglu::WindowParams(128, 128, eglu::WindowParams::VISIBILITY_VISIBLE)));
493 eglu::UniqueSurface surface (egl, display, eglu::createWindowSurface(m_eglTestCtx.getNativeDisplay(), *window, display, config, DE_NULL));
494 eglu::UniqueContext context (egl, display, createGLES2Context(egl, display, config));
496 deUint32 program = 0;
498 EGLU_CHECK_CALL(egl, surfaceAttrib(display, *surface, EGL_TIMESTAMPS_ANDROID, EGL_TRUE));
500 m_eglTestCtx.initGLFunctions(&gl, glu::ApiType::es(2,0));
502 EGLU_CHECK_CALL(egl, makeCurrent(display, *surface, *surface, *context));
506 // EGL_DISPLAY_PRESENT_TIME_ANDROID support is currently optional
507 // but should be required once HWC1 is no longer supported.
508 // All HWC2 devices should support EGL_DISPLAY_PRESENT_TIME_ANDROID.
509 TimestampInfoMap timestamps;
510 timestamps[EGL_REQUESTED_PRESENT_TIME_ANDROID] = TimestampInfo(true, false, 0);
511 timestamps[EGL_RENDERING_COMPLETE_TIME_ANDROID] = TimestampInfo(true, false, 0);
512 timestamps[EGL_COMPOSITION_LATCH_TIME_ANDROID] = TimestampInfo(true, false, 0);
513 timestamps[EGL_FIRST_COMPOSITION_START_TIME_ANDROID] = TimestampInfo(true, false, 0);
514 timestamps[EGL_LAST_COMPOSITION_START_TIME_ANDROID] = TimestampInfo(true, false, 0);
515 timestamps[EGL_FIRST_COMPOSITION_GPU_FINISHED_TIME_ANDROID] = TimestampInfo(true, false, 0);
516 timestamps[EGL_DISPLAY_PRESENT_TIME_ANDROID] = TimestampInfo(false, false, 0);
517 timestamps[EGL_DEQUEUE_READY_TIME_ANDROID] = TimestampInfo(true, false, 0);
518 timestamps[EGL_READS_DONE_TIME_ANDROID] = TimestampInfo(true, false, 0);
520 const eglw::EGLint invalidTimestampName = EGL_READS_DONE_TIME_ANDROID + 1;
522 // Verify required timestamps are supported and populate supportedNames.
523 std::vector<eglw::EGLint> supportedNames;
524 for (TimestampInfoMap::iterator i = timestamps.begin(); i != timestamps.end(); i++)
526 TimestampInfo& info = i->second;
527 info.supported = m_eglGetFrameTimestampSupportedANDROID(display, *surface, i->first) != EGL_FALSE;
528 EGLU_CHECK_MSG(egl, "eglGetFrameTimestampSupportedANDROID failed.");
532 info.supportedIndex = supportedNames.size();
533 supportedNames.push_back(i->first);
536 TCU_CHECK_MSG(!info.required, "Required timestamp not supported.");
539 // Verify unsupported timestamps are reported properly.
540 const bool invalidSupported = m_eglGetFrameTimestampSupportedANDROID(display, *surface, invalidTimestampName) != EGL_FALSE;
541 EGLU_CHECK_MSG(egl, "eglGetFrameTimestampSupportedANDROID failed.");
542 TCU_CHECK_MSG(!invalidSupported, "Non existant timestamp reports that it is supported.");
544 // Verify compositor timings are supported.
545 const bool deadlineSupported = m_eglGetCompositorTimingSupportedANDROID(display, *surface, EGL_COMPOSITE_DEADLINE_ANDROID) != EGL_FALSE;
546 EGLU_CHECK_MSG(egl, "eglGetCompositorTimingSupportedANDROID failed.");
547 TCU_CHECK_MSG(deadlineSupported, "EGL_COMPOSITE_DEADLINE_ANDROID not supported.");
548 const bool intervalSupported = m_eglGetCompositorTimingSupportedANDROID(display, *surface, EGL_COMPOSITE_INTERVAL_ANDROID) != EGL_FALSE;
549 EGLU_CHECK_MSG(egl, "eglGetCompositorTimingSupportedANDROID failed.");
550 TCU_CHECK_MSG(intervalSupported, "EGL_COMPOSITE_INTERVAL_ANDROID not supported.");
551 const bool latencySupported = m_eglGetCompositorTimingSupportedANDROID(display, *surface, EGL_COMPOSITE_TO_PRESENT_LATENCY_ANDROID) != EGL_FALSE;
552 EGLU_CHECK_MSG(egl, "eglGetCompositorTimingSupportedANDROID failed.");
553 TCU_CHECK_MSG(latencySupported, "EGL_COMPOSITE_TO_PRESENT_LATENCY_ANDROID not supported.");
555 const float positions1[] =
566 const float positions2[] =
577 deUint32 posLocation;
579 program = createGLES2Program(gl, m_testCtx.getLog());
581 gl.useProgram(program);
582 posLocation = gl.getAttribLocation(program, "a_pos");
583 gl.enableVertexAttribArray(posLocation);
584 GLU_EXPECT_NO_ERROR(gl.getError(), "Failed to setup shader program for rendering");
586 const size_t frameCount = 120;
587 std::vector<FrameTimes> frameTimes(frameCount);
588 for (size_t i = 0; i < frameCount; i++)
590 FrameTimes& frame = frameTimes[i];
592 const eglw::EGLint compositorTimingNames[] =
594 EGL_COMPOSITE_DEADLINE_ANDROID,
595 EGL_COMPOSITE_INTERVAL_ANDROID,
596 EGL_COMPOSITE_TO_PRESENT_LATENCY_ANDROID,
598 const EGLint compositorTimingCount = DE_LENGTH_OF_ARRAY(compositorTimingNames);
599 EGLnsecsANDROID compositorTimingValues[compositorTimingCount] = { -2 };
601 // Get the current time before making any API calls in case "now"
602 // just happens to get sampled near one of the composite deadlines.
603 EGLnsecsANDROID now = getNanoseconds();
606 EGLuint64KHR nextFrameId = 0;
607 CHECK_NAKED_EGL_CALL(egl, m_eglGetNextFrameIdANDROID(display, *surface, &nextFrameId));
608 frame.frameId = nextFrameId;
610 // Get the compositor timing.
611 CHECK_NAKED_EGL_CALL(egl, m_eglGetCompositorTimingANDROID(
612 display, *surface, compositorTimingCount,
613 compositorTimingNames, compositorTimingValues));
614 frame.compositeDeadline = compositorTimingValues[0];
615 frame.compositeInterval = compositorTimingValues[1];
616 frame.compositeToPresentLatency = compositorTimingValues[2];
618 // Verify compositor timing is sane.
619 m_result.check(1000000 < frame.compositeInterval, "Reported refresh rate greater than 1kHz.");
620 m_result.check(frame.compositeInterval < 1000000000, "Reported refresh rate less than 1Hz.");
621 m_result.check(0 < frame.compositeToPresentLatency, "Composite to present latency must be greater than 0.");
622 m_result.check(frame.compositeToPresentLatency < frame.compositeInterval * 3, "Composite to present latency is more than 3 vsyncs.");
623 const EGLnsecsANDROID minDeadline = now;
624 m_result.check(minDeadline < frame.compositeDeadline, "Next composite deadline is in the past.");
625 const EGLnsecsANDROID maxDeadline = now + frame.compositeInterval * 2;
626 m_result.check(frame.compositeDeadline < maxDeadline, "Next composite deadline over two intervals away.");
628 const float colorAngle = (static_cast<float>(i) / static_cast<float>(frameCount)) * 6.28318f;
629 gl.clearColor((1.0f + deFloatSin(colorAngle)) / 2.0f, 0.7f, (1.0f + deFloatCos(colorAngle)) / 2.0f, 1.0f);
630 gl.clear(GL_COLOR_BUFFER_BIT);
631 GLU_EXPECT_NO_ERROR(gl.getError(), "Failed to clear surface");
633 const bool posSelect = ((i % 2) == 0);
634 gl.vertexAttribPointer(posLocation, 2, GL_FLOAT, GL_FALSE, 0, posSelect ? positions1 : positions2);
635 gl.drawArrays(GL_TRIANGLES, 0, 6);
636 GLU_EXPECT_NO_ERROR(gl.getError(), "Failed to render");
638 frame.swapBufferBeginNs = getNanoseconds();
639 EGLU_CHECK_CALL(egl, swapBuffers(display, *surface));
641 // All timestamps from 5 frames ago should definitely be available.
642 const size_t frameDelay = 5;
645 // \todo [2017-01-25 brianderson] Remove this work around once reads done is fixed.
646 const bool verifyReadsDone = i > (frameDelay + 3);
647 FrameTimes& frame5ago = frameTimes[i-frameDelay];
648 std::vector<EGLnsecsANDROID> supportedValues(supportedNames.size(), 0);
650 CHECK_NAKED_EGL_CALL(egl, m_eglGetFrameTimestampsANDROID(
651 display, *surface, frame5ago.frameId, static_cast<eglw::EGLint>(supportedNames.size()),
652 &supportedNames[0], &supportedValues[0]));
653 populateFrameTimes(&frame5ago, timestamps, supportedValues);
655 verifySingleFrame(frame5ago, m_result, verifyReadsDone);
656 if (i >= frameDelay + 1)
658 FrameTimes& frame6ago = frameTimes[i-frameDelay-1];
659 verifyNeighboringFrames(frame6ago, frame5ago, m_result, verifyReadsDone);
664 // All timestamps for the most recently swapped frame should
665 // become available by only polling eglGetFrametimestamps.
666 // No additional swaps should be necessary.
667 FrameTimes& lastFrame = frameTimes.back();
668 const EGLnsecsANDROID pollingDeadline = lastFrame.swapBufferBeginNs + 1000000000;
669 bool finalTimestampAvailable = false;
673 std::vector<EGLnsecsANDROID> supportedValues(supportedNames.size(), 0);
674 CHECK_NAKED_EGL_CALL(egl, m_eglGetFrameTimestampsANDROID(
675 display, *surface, lastFrame.frameId, static_cast<eglw::EGLint>(supportedNames.size()),
676 &supportedNames[0], &supportedValues[0]));
677 populateFrameTimes(&lastFrame, timestamps, supportedValues);
679 // Poll for present if it's supported.
680 // Otherwise, poll for firstCompositionStart.
681 if (timestamps[EGL_DISPLAY_PRESENT_TIME_ANDROID].supported)
682 finalTimestampAvailable = !timestampPending(lastFrame.displayPresent);
684 finalTimestampAvailable = !timestampPending(lastFrame.firstCompositionStart);
685 } while (!finalTimestampAvailable && (getNanoseconds() < pollingDeadline));
687 m_result.check(finalTimestampAvailable, "Timed out polling for timestamps of last swap.");
688 m_result.check((lastFrame.requestedPresent >= 0), "Requested present of last swap not avaiable.");
689 m_result.check((lastFrame.renderingComplete >= 0), "Rendering complete of last swap not avaiable.");
690 m_result.check((lastFrame.latch >= 0), "Latch of last swap not avaiable.");
691 m_result.check((lastFrame.firstCompositionStart >= 0), "First composite time of last swap not avaiable.");
692 m_result.check((lastFrame.lastCompositionStart >= 0), "Last composite time of last swap not avaiable.");
694 window->processEvents();
695 gl.disableVertexAttribArray(posLocation);
697 GLU_EXPECT_NO_ERROR(gl.getError(), "Failed to release program state");
699 gl.deleteProgram(program);
701 GLU_EXPECT_NO_ERROR(gl.getError(), "glDeleteProgram()");
703 m_result.setTestContextResult(m_testCtx);
708 gl.deleteProgram(program);
710 EGLU_CHECK_CALL(egl, makeCurrent(display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT));
714 EGLU_CHECK_CALL(egl, makeCurrent(display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT));
717 class GetFrameTimestampsTests : public TestCaseGroup
720 GetFrameTimestampsTests (EglTestContext& eglTestCtx);
724 GetFrameTimestampsTests (const GetFrameTimestampsTests&);
725 GetFrameTimestampsTests& operator= (const GetFrameTimestampsTests&);
729 GetFrameTimestampsTests::GetFrameTimestampsTests (EglTestContext& eglTestCtx)
730 : TestCaseGroup(eglTestCtx, "get_frame_timestamps", "Get frame timestamp tests")
734 bool isWindow (const eglu::CandidateConfig& c)
736 return (c.surfaceType() & EGL_WINDOW_BIT) != 0;
739 void GetFrameTimestampsTests::init (void)
741 eglu::FilterList baseFilters;
742 baseFilters << isWindow;
744 vector<NamedFilterList> filterLists;
745 getDefaultFilterLists(filterLists, baseFilters);
747 for (vector<NamedFilterList>::iterator i = filterLists.begin(); i != filterLists.end(); i++)
748 addChild(new GetFrameTimestampTest(m_eglTestCtx, *i));
753 TestCaseGroup* createGetFrameTimestampsTests (EglTestContext& eglTestCtx)
755 return new GetFrameTimestampsTests(eglTestCtx);