1 /*
2 * Copyright (C) 2016 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 // TODO(b/129481165): remove the #pragma below and fix conversion issues
18 #pragma clang diagnostic push
19 #pragma clang diagnostic ignored "-Wconversion"
20
21 #include <frameworks/native/cmds/surfacereplayer/proto/src/trace.pb.h>
22 #include <google/protobuf/io/zero_copy_stream_impl.h>
23 #include <gtest/gtest.h>
24 #include <gui/ISurfaceComposer.h>
25 #include <gui/LayerState.h>
26 #include <gui/Surface.h>
27 #include <gui/SurfaceComposerClient.h>
28 #include <private/gui/ComposerService.h>
29 #include <ui/DisplayConfig.h>
30
31 #include <fstream>
32 #include <random>
33 #include <thread>
34
35 namespace android {
36
37 using Transaction = SurfaceComposerClient::Transaction;
38 using SurfaceChange = surfaceflinger::SurfaceChange;
39 using Trace = surfaceflinger::Trace;
40 using Increment = surfaceflinger::Increment;
41
42 constexpr int32_t SCALING_UPDATE = 1;
43 constexpr uint32_t BUFFER_UPDATES = 18;
44 constexpr uint32_t LAYER_UPDATE = INT_MAX - 2;
45 constexpr uint32_t SIZE_UPDATE = 134;
46 constexpr uint32_t STACK_UPDATE = 1;
47 constexpr uint64_t DEFERRED_UPDATE = 0;
48 constexpr int32_t RELATIVE_Z = 42;
49 constexpr float ALPHA_UPDATE = 0.29f;
50 constexpr float CORNER_RADIUS_UPDATE = 0.2f;
51 constexpr int BACKGROUND_BLUR_RADIUS_UPDATE = 24;
52 constexpr float POSITION_UPDATE = 121;
53 const Rect CROP_UPDATE(16, 16, 32, 32);
54 const float SHADOW_RADIUS_UPDATE = 35.0f;
55
56 const String8 DISPLAY_NAME("SurfaceInterceptor Display Test");
57 constexpr auto TEST_BG_SURFACE_NAME = "BG Interceptor Test Surface";
58 constexpr auto TEST_FG_SURFACE_NAME = "FG Interceptor Test Surface";
59 constexpr auto UNIQUE_TEST_BG_SURFACE_NAME = "BG Interceptor Test Surface#0";
60 constexpr auto UNIQUE_TEST_FG_SURFACE_NAME = "FG Interceptor Test Surface#0";
61 constexpr auto LAYER_NAME = "Layer Create and Delete Test";
62 constexpr auto UNIQUE_LAYER_NAME = "Layer Create and Delete Test#0";
63
64 constexpr auto DEFAULT_FILENAME = "/data/misc/wmtrace/transaction_trace.pb";
65
66 // Fill an RGBA_8888 formatted surface with a single color.
fillSurfaceRGBA8(const sp<SurfaceControl> & sc,uint8_t r,uint8_t g,uint8_t b)67 static void fillSurfaceRGBA8(const sp<SurfaceControl>& sc, uint8_t r, uint8_t g, uint8_t b) {
68 ANativeWindow_Buffer outBuffer;
69 sp<Surface> s = sc->getSurface();
70 ASSERT_TRUE(s != nullptr);
71 ASSERT_EQ(NO_ERROR, s->lock(&outBuffer, nullptr));
72 uint8_t* img = reinterpret_cast<uint8_t*>(outBuffer.bits);
73 for (int y = 0; y < outBuffer.height; y++) {
74 for (int x = 0; x < outBuffer.width; x++) {
75 uint8_t* pixel = img + (4 * (y*outBuffer.stride + x));
76 pixel[0] = r;
77 pixel[1] = g;
78 pixel[2] = b;
79 pixel[3] = 255;
80 }
81 }
82 ASSERT_EQ(NO_ERROR, s->unlockAndPost());
83 }
84
readProtoFile(Trace * trace)85 static status_t readProtoFile(Trace* trace) {
86 status_t err = NO_ERROR;
87
88 int fd = open(DEFAULT_FILENAME, O_RDONLY);
89 {
90 google::protobuf::io::FileInputStream f(fd);
91 if (fd && !trace->ParseFromZeroCopyStream(&f)) {
92 err = PERMISSION_DENIED;
93 }
94 }
95 close(fd);
96
97 return err;
98 }
99
enableInterceptor()100 static void enableInterceptor() {
101 system("service call SurfaceFlinger 1020 i32 1 > /dev/null");
102 }
103
disableInterceptor()104 static void disableInterceptor() {
105 system("service call SurfaceFlinger 1020 i32 0 > /dev/null");
106 }
107
getSurfaceId(const Trace & capturedTrace,const std::string & surfaceName)108 int32_t getSurfaceId(const Trace& capturedTrace, const std::string& surfaceName) {
109 int32_t layerId = 0;
110 for (const auto& increment : capturedTrace.increment()) {
111 if (increment.increment_case() == increment.kSurfaceCreation) {
112 if (increment.surface_creation().name() == surfaceName) {
113 layerId = increment.surface_creation().id();
114 }
115 }
116 }
117 return layerId;
118 }
119
getDisplayId(const Trace & capturedTrace,const std::string & displayName)120 int32_t getDisplayId(const Trace& capturedTrace, const std::string& displayName) {
121 int32_t displayId = 0;
122 for (const auto& increment : capturedTrace.increment()) {
123 if (increment.increment_case() == increment.kDisplayCreation) {
124 if (increment.display_creation().name() == displayName) {
125 displayId = increment.display_creation().id();
126 break;
127 }
128 }
129 }
130 return displayId;
131 }
132
133 class SurfaceInterceptorTest : public ::testing::Test {
134 protected:
SetUp()135 void SetUp() override {
136 // Allow SurfaceInterceptor write to /data
137 system("setenforce 0");
138
139 mComposerClient = new SurfaceComposerClient;
140 ASSERT_EQ(NO_ERROR, mComposerClient->initCheck());
141 }
142
TearDown()143 void TearDown() override {
144 mComposerClient->dispose();
145 mBGSurfaceControl.clear();
146 mFGSurfaceControl.clear();
147 mComposerClient.clear();
148 system("setenforce 1");
149 }
150
151 sp<SurfaceComposerClient> mComposerClient;
152 sp<SurfaceControl> mBGSurfaceControl;
153 sp<SurfaceControl> mFGSurfaceControl;
154 int32_t mBGLayerId;
155 int32_t mFGLayerId;
156
157 public:
158 using TestTransactionAction = void (SurfaceInterceptorTest::*)(Transaction&);
159 using TestAction = void (SurfaceInterceptorTest::*)();
160 using TestBooleanVerification = bool (SurfaceInterceptorTest::*)(const Trace&);
161 using TestVerification = void (SurfaceInterceptorTest::*)(const Trace&);
162
163 void setupBackgroundSurface();
164 void preProcessTrace(const Trace& trace);
165
166 // captureTest will enable SurfaceInterceptor, setup background surface,
167 // disable SurfaceInterceptor, collect the trace and process the trace for
168 // id of background surface before further verification.
169 void captureTest(TestTransactionAction action, TestBooleanVerification verification);
170 void captureTest(TestTransactionAction action, SurfaceChange::SurfaceChangeCase changeCase);
171 void captureTest(TestTransactionAction action, Increment::IncrementCase incrementCase);
172 void captureTest(TestAction action, TestBooleanVerification verification);
173 void captureTest(TestAction action, TestVerification verification);
174 void runInTransaction(TestTransactionAction action);
175
176 // Verification of changes to a surface
177 bool positionUpdateFound(const SurfaceChange& change, bool foundPosition);
178 bool sizeUpdateFound(const SurfaceChange& change, bool foundSize);
179 bool alphaUpdateFound(const SurfaceChange& change, bool foundAlpha);
180 bool layerUpdateFound(const SurfaceChange& change, bool foundLayer);
181 bool cropUpdateFound(const SurfaceChange& change, bool foundCrop);
182 bool cornerRadiusUpdateFound(const SurfaceChange& change, bool foundCornerRadius);
183 bool backgroundBlurRadiusUpdateFound(const SurfaceChange& change,
184 bool foundBackgroundBlurRadius);
185 bool matrixUpdateFound(const SurfaceChange& change, bool foundMatrix);
186 bool scalingModeUpdateFound(const SurfaceChange& change, bool foundScalingMode);
187 bool transparentRegionHintUpdateFound(const SurfaceChange& change, bool foundTransparentRegion);
188 bool layerStackUpdateFound(const SurfaceChange& change, bool foundLayerStack);
189 bool hiddenFlagUpdateFound(const SurfaceChange& change, bool foundHiddenFlag);
190 bool opaqueFlagUpdateFound(const SurfaceChange& change, bool foundOpaqueFlag);
191 bool secureFlagUpdateFound(const SurfaceChange& change, bool foundSecureFlag);
192 bool deferredTransactionUpdateFound(const SurfaceChange& change, bool foundDeferred);
193 bool reparentUpdateFound(const SurfaceChange& change, bool found);
194 bool relativeParentUpdateFound(const SurfaceChange& change, bool found);
195 bool detachChildrenUpdateFound(const SurfaceChange& change, bool found);
196 bool reparentChildrenUpdateFound(const SurfaceChange& change, bool found);
197 bool shadowRadiusUpdateFound(const SurfaceChange& change, bool found);
198 bool surfaceUpdateFound(const Trace& trace, SurfaceChange::SurfaceChangeCase changeCase);
199
200 // Find all of the updates in the single trace
201 void assertAllUpdatesFound(const Trace& trace);
202
203 // Verification of creation and deletion of a surface
204 bool surfaceCreationFound(const Increment& increment, bool foundSurface);
205 bool surfaceDeletionFound(const Increment& increment, const int32_t targetId,
206 bool foundSurface);
207 bool displayCreationFound(const Increment& increment, bool foundDisplay);
208 bool displayDeletionFound(const Increment& increment, const int32_t targetId,
209 bool foundDisplay);
210 bool singleIncrementFound(const Trace& trace, Increment::IncrementCase incrementCase);
211
212 // Verification of buffer updates
213 bool bufferUpdatesFound(const Trace& trace);
214
215 // Perform each of the possible changes to a surface
216 void positionUpdate(Transaction&);
217 void sizeUpdate(Transaction&);
218 void alphaUpdate(Transaction&);
219 void layerUpdate(Transaction&);
220 void cropUpdate(Transaction&);
221 void cornerRadiusUpdate(Transaction&);
222 void backgroundBlurRadiusUpdate(Transaction&);
223 void matrixUpdate(Transaction&);
224 void overrideScalingModeUpdate(Transaction&);
225 void transparentRegionHintUpdate(Transaction&);
226 void layerStackUpdate(Transaction&);
227 void hiddenFlagUpdate(Transaction&);
228 void opaqueFlagUpdate(Transaction&);
229 void secureFlagUpdate(Transaction&);
230 void deferredTransactionUpdate(Transaction&);
231 void reparentUpdate(Transaction&);
232 void relativeParentUpdate(Transaction&);
233 void detachChildrenUpdate(Transaction&);
234 void reparentChildrenUpdate(Transaction&);
235 void shadowRadiusUpdate(Transaction&);
236 void surfaceCreation(Transaction&);
237 void displayCreation(Transaction&);
238 void displayDeletion(Transaction&);
239
240 void nBufferUpdates();
241 void runAllUpdates();
242
243 private:
244 void captureInTransaction(TestTransactionAction action, Trace*);
245 void capture(TestAction action, Trace*);
246 };
247
captureInTransaction(TestTransactionAction action,Trace * outTrace)248 void SurfaceInterceptorTest::captureInTransaction(TestTransactionAction action, Trace* outTrace) {
249 enableInterceptor();
250 setupBackgroundSurface();
251 runInTransaction(action);
252 disableInterceptor();
253 ASSERT_EQ(NO_ERROR, readProtoFile(outTrace));
254 preProcessTrace(*outTrace);
255 }
256
capture(TestAction action,Trace * outTrace)257 void SurfaceInterceptorTest::capture(TestAction action, Trace* outTrace) {
258 enableInterceptor();
259 setupBackgroundSurface();
260 (this->*action)();
261 disableInterceptor();
262 ASSERT_EQ(NO_ERROR, readProtoFile(outTrace));
263 preProcessTrace(*outTrace);
264 }
265
setupBackgroundSurface()266 void SurfaceInterceptorTest::setupBackgroundSurface() {
267 const auto display = SurfaceComposerClient::getInternalDisplayToken();
268 ASSERT_FALSE(display == nullptr);
269
270 DisplayConfig config;
271 ASSERT_EQ(NO_ERROR, SurfaceComposerClient::getActiveDisplayConfig(display, &config));
272 const ui::Size& resolution = config.resolution;
273
274 // Background surface
275 mBGSurfaceControl =
276 mComposerClient->createSurface(String8(TEST_BG_SURFACE_NAME), resolution.getWidth(),
277 resolution.getHeight(), PIXEL_FORMAT_RGBA_8888, 0);
278 ASSERT_TRUE(mBGSurfaceControl != nullptr);
279 ASSERT_TRUE(mBGSurfaceControl->isValid());
280
281 // Foreground surface
282 mFGSurfaceControl =
283 mComposerClient->createSurface(String8(TEST_FG_SURFACE_NAME), resolution.getWidth(),
284 resolution.getHeight(), PIXEL_FORMAT_RGBA_8888, 0);
285 ASSERT_TRUE(mFGSurfaceControl != nullptr);
286 ASSERT_TRUE(mFGSurfaceControl->isValid());
287
288 Transaction t;
289 t.setDisplayLayerStack(display, 0);
290 ASSERT_EQ(NO_ERROR,
291 t.setLayer(mBGSurfaceControl, INT_MAX - 3)
292 .show(mBGSurfaceControl)
293 .setLayer(mFGSurfaceControl, INT_MAX - 3)
294 .show(mFGSurfaceControl)
295 .apply());
296 }
297
preProcessTrace(const Trace & trace)298 void SurfaceInterceptorTest::preProcessTrace(const Trace& trace) {
299 mBGLayerId = getSurfaceId(trace, UNIQUE_TEST_BG_SURFACE_NAME);
300 mFGLayerId = getSurfaceId(trace, UNIQUE_TEST_FG_SURFACE_NAME);
301 }
302
captureTest(TestTransactionAction action,TestBooleanVerification verification)303 void SurfaceInterceptorTest::captureTest(TestTransactionAction action,
304 TestBooleanVerification verification) {
305 Trace capturedTrace;
306 captureInTransaction(action, &capturedTrace);
307 ASSERT_TRUE((this->*verification)(capturedTrace));
308 }
309
captureTest(TestTransactionAction action,Increment::IncrementCase incrementCase)310 void SurfaceInterceptorTest::captureTest(TestTransactionAction action,
311 Increment::IncrementCase incrementCase) {
312 Trace capturedTrace;
313 captureInTransaction(action, &capturedTrace);
314 ASSERT_TRUE(singleIncrementFound(capturedTrace, incrementCase));
315 }
316
captureTest(TestTransactionAction action,SurfaceChange::SurfaceChangeCase changeCase)317 void SurfaceInterceptorTest::captureTest(TestTransactionAction action,
318 SurfaceChange::SurfaceChangeCase changeCase) {
319 Trace capturedTrace;
320 captureInTransaction(action, &capturedTrace);
321 ASSERT_TRUE(surfaceUpdateFound(capturedTrace, changeCase));
322 }
323
captureTest(TestAction action,TestBooleanVerification verification)324 void SurfaceInterceptorTest::captureTest(TestAction action, TestBooleanVerification verification) {
325 Trace capturedTrace;
326 capture(action, &capturedTrace);
327 ASSERT_TRUE((this->*verification)(capturedTrace));
328 }
329
captureTest(TestAction action,TestVerification verification)330 void SurfaceInterceptorTest::captureTest(TestAction action, TestVerification verification) {
331 Trace capturedTrace;
332 capture(action, &capturedTrace);
333 (this->*verification)(capturedTrace);
334 }
335
runInTransaction(TestTransactionAction action)336 void SurfaceInterceptorTest::runInTransaction(TestTransactionAction action) {
337 Transaction t;
338 (this->*action)(t);
339 t.apply(true);
340 }
341
positionUpdate(Transaction & t)342 void SurfaceInterceptorTest::positionUpdate(Transaction& t) {
343 t.setPosition(mBGSurfaceControl, POSITION_UPDATE, POSITION_UPDATE);
344 }
345
sizeUpdate(Transaction & t)346 void SurfaceInterceptorTest::sizeUpdate(Transaction& t) {
347 t.setSize(mBGSurfaceControl, SIZE_UPDATE, SIZE_UPDATE);
348 }
349
alphaUpdate(Transaction & t)350 void SurfaceInterceptorTest::alphaUpdate(Transaction& t) {
351 t.setAlpha(mBGSurfaceControl, ALPHA_UPDATE);
352 }
353
cornerRadiusUpdate(Transaction & t)354 void SurfaceInterceptorTest::cornerRadiusUpdate(Transaction& t) {
355 t.setCornerRadius(mBGSurfaceControl, CORNER_RADIUS_UPDATE);
356 }
357
backgroundBlurRadiusUpdate(Transaction & t)358 void SurfaceInterceptorTest::backgroundBlurRadiusUpdate(Transaction& t) {
359 t.setBackgroundBlurRadius(mBGSurfaceControl, BACKGROUND_BLUR_RADIUS_UPDATE);
360 }
361
layerUpdate(Transaction & t)362 void SurfaceInterceptorTest::layerUpdate(Transaction& t) {
363 t.setLayer(mBGSurfaceControl, LAYER_UPDATE);
364 }
365
cropUpdate(Transaction & t)366 void SurfaceInterceptorTest::cropUpdate(Transaction& t) {
367 t.setCrop_legacy(mBGSurfaceControl, CROP_UPDATE);
368 }
369
matrixUpdate(Transaction & t)370 void SurfaceInterceptorTest::matrixUpdate(Transaction& t) {
371 t.setMatrix(mBGSurfaceControl, M_SQRT1_2, M_SQRT1_2, -M_SQRT1_2, M_SQRT1_2);
372 }
373
overrideScalingModeUpdate(Transaction & t)374 void SurfaceInterceptorTest::overrideScalingModeUpdate(Transaction& t) {
375 t.setOverrideScalingMode(mBGSurfaceControl, SCALING_UPDATE);
376 }
377
transparentRegionHintUpdate(Transaction & t)378 void SurfaceInterceptorTest::transparentRegionHintUpdate(Transaction& t) {
379 Region region(CROP_UPDATE);
380 t.setTransparentRegionHint(mBGSurfaceControl, region);
381 }
382
layerStackUpdate(Transaction & t)383 void SurfaceInterceptorTest::layerStackUpdate(Transaction& t) {
384 t.setLayerStack(mBGSurfaceControl, STACK_UPDATE);
385 }
386
hiddenFlagUpdate(Transaction & t)387 void SurfaceInterceptorTest::hiddenFlagUpdate(Transaction& t) {
388 t.setFlags(mBGSurfaceControl, layer_state_t::eLayerHidden, layer_state_t::eLayerHidden);
389 }
390
opaqueFlagUpdate(Transaction & t)391 void SurfaceInterceptorTest::opaqueFlagUpdate(Transaction& t) {
392 t.setFlags(mBGSurfaceControl, layer_state_t::eLayerOpaque, layer_state_t::eLayerOpaque);
393 }
394
secureFlagUpdate(Transaction & t)395 void SurfaceInterceptorTest::secureFlagUpdate(Transaction& t) {
396 t.setFlags(mBGSurfaceControl, layer_state_t::eLayerSecure, layer_state_t::eLayerSecure);
397 }
398
deferredTransactionUpdate(Transaction & t)399 void SurfaceInterceptorTest::deferredTransactionUpdate(Transaction& t) {
400 t.deferTransactionUntil_legacy(mBGSurfaceControl, mBGSurfaceControl->getHandle(),
401 DEFERRED_UPDATE);
402 }
403
reparentUpdate(Transaction & t)404 void SurfaceInterceptorTest::reparentUpdate(Transaction& t) {
405 t.reparent(mBGSurfaceControl, mFGSurfaceControl->getHandle());
406 }
407
relativeParentUpdate(Transaction & t)408 void SurfaceInterceptorTest::relativeParentUpdate(Transaction& t) {
409 t.setRelativeLayer(mBGSurfaceControl, mFGSurfaceControl->getHandle(), RELATIVE_Z);
410 }
411
detachChildrenUpdate(Transaction & t)412 void SurfaceInterceptorTest::detachChildrenUpdate(Transaction& t) {
413 t.detachChildren(mBGSurfaceControl);
414 }
415
reparentChildrenUpdate(Transaction & t)416 void SurfaceInterceptorTest::reparentChildrenUpdate(Transaction& t) {
417 t.reparentChildren(mBGSurfaceControl, mFGSurfaceControl->getHandle());
418 }
419
shadowRadiusUpdate(Transaction & t)420 void SurfaceInterceptorTest::shadowRadiusUpdate(Transaction& t) {
421 t.setShadowRadius(mBGSurfaceControl, SHADOW_RADIUS_UPDATE);
422 }
423
displayCreation(Transaction &)424 void SurfaceInterceptorTest::displayCreation(Transaction&) {
425 sp<IBinder> testDisplay = SurfaceComposerClient::createDisplay(DISPLAY_NAME, true);
426 SurfaceComposerClient::destroyDisplay(testDisplay);
427 }
428
displayDeletion(Transaction &)429 void SurfaceInterceptorTest::displayDeletion(Transaction&) {
430 sp<IBinder> testDisplay = SurfaceComposerClient::createDisplay(DISPLAY_NAME, false);
431 SurfaceComposerClient::destroyDisplay(testDisplay);
432 }
433
runAllUpdates()434 void SurfaceInterceptorTest::runAllUpdates() {
435 runInTransaction(&SurfaceInterceptorTest::positionUpdate);
436 runInTransaction(&SurfaceInterceptorTest::sizeUpdate);
437 runInTransaction(&SurfaceInterceptorTest::alphaUpdate);
438 runInTransaction(&SurfaceInterceptorTest::cornerRadiusUpdate);
439 runInTransaction(&SurfaceInterceptorTest::backgroundBlurRadiusUpdate);
440 runInTransaction(&SurfaceInterceptorTest::layerUpdate);
441 runInTransaction(&SurfaceInterceptorTest::cropUpdate);
442 runInTransaction(&SurfaceInterceptorTest::matrixUpdate);
443 runInTransaction(&SurfaceInterceptorTest::overrideScalingModeUpdate);
444 runInTransaction(&SurfaceInterceptorTest::transparentRegionHintUpdate);
445 runInTransaction(&SurfaceInterceptorTest::layerStackUpdate);
446 runInTransaction(&SurfaceInterceptorTest::hiddenFlagUpdate);
447 runInTransaction(&SurfaceInterceptorTest::opaqueFlagUpdate);
448 runInTransaction(&SurfaceInterceptorTest::secureFlagUpdate);
449 runInTransaction(&SurfaceInterceptorTest::deferredTransactionUpdate);
450 runInTransaction(&SurfaceInterceptorTest::reparentUpdate);
451 runInTransaction(&SurfaceInterceptorTest::reparentChildrenUpdate);
452 runInTransaction(&SurfaceInterceptorTest::detachChildrenUpdate);
453 runInTransaction(&SurfaceInterceptorTest::relativeParentUpdate);
454 runInTransaction(&SurfaceInterceptorTest::shadowRadiusUpdate);
455 }
456
surfaceCreation(Transaction &)457 void SurfaceInterceptorTest::surfaceCreation(Transaction&) {
458 mComposerClient->createSurface(String8(LAYER_NAME), SIZE_UPDATE, SIZE_UPDATE,
459 PIXEL_FORMAT_RGBA_8888, 0);
460 }
461
nBufferUpdates()462 void SurfaceInterceptorTest::nBufferUpdates() {
463 std::random_device rd;
464 std::mt19937_64 gen(rd());
465 // This makes testing fun
466 std::uniform_int_distribution<uint8_t> dis;
467 for (uint32_t i = 0; i < BUFFER_UPDATES; ++i) {
468 fillSurfaceRGBA8(mBGSurfaceControl, dis(gen), dis(gen), dis(gen));
469 }
470 }
471
positionUpdateFound(const SurfaceChange & change,bool foundPosition)472 bool SurfaceInterceptorTest::positionUpdateFound(const SurfaceChange& change, bool foundPosition) {
473 // There should only be one position transaction with x and y = POSITION_UPDATE
474 bool hasX(change.position().x() == POSITION_UPDATE);
475 bool hasY(change.position().y() == POSITION_UPDATE);
476 if (hasX && hasY && !foundPosition) {
477 foundPosition = true;
478 } else if (hasX && hasY && foundPosition) {
479 // Failed because the position update was found a second time
480 [] () { FAIL(); }();
481 }
482 return foundPosition;
483 }
484
sizeUpdateFound(const SurfaceChange & change,bool foundSize)485 bool SurfaceInterceptorTest::sizeUpdateFound(const SurfaceChange& change, bool foundSize) {
486 bool hasWidth(change.size().h() == SIZE_UPDATE);
487 bool hasHeight(change.size().w() == SIZE_UPDATE);
488 if (hasWidth && hasHeight && !foundSize) {
489 foundSize = true;
490 } else if (hasWidth && hasHeight && foundSize) {
491 [] () { FAIL(); }();
492 }
493 return foundSize;
494 }
495
alphaUpdateFound(const SurfaceChange & change,bool foundAlpha)496 bool SurfaceInterceptorTest::alphaUpdateFound(const SurfaceChange& change, bool foundAlpha) {
497 bool hasAlpha(change.alpha().alpha() == ALPHA_UPDATE);
498 if (hasAlpha && !foundAlpha) {
499 foundAlpha = true;
500 } else if (hasAlpha && foundAlpha) {
501 [] () { FAIL(); }();
502 }
503 return foundAlpha;
504 }
505
cornerRadiusUpdateFound(const SurfaceChange & change,bool foundCornerRadius)506 bool SurfaceInterceptorTest::cornerRadiusUpdateFound(const SurfaceChange &change,
507 bool foundCornerRadius) {
508 bool hasCornerRadius(change.corner_radius().corner_radius() == CORNER_RADIUS_UPDATE);
509 if (hasCornerRadius && !foundCornerRadius) {
510 foundCornerRadius = true;
511 } else if (hasCornerRadius && foundCornerRadius) {
512 [] () { FAIL(); }();
513 }
514 return foundCornerRadius;
515 }
516
backgroundBlurRadiusUpdateFound(const SurfaceChange & change,bool foundBackgroundBlur)517 bool SurfaceInterceptorTest::backgroundBlurRadiusUpdateFound(const SurfaceChange& change,
518 bool foundBackgroundBlur) {
519 bool hasBackgroundBlur(change.background_blur_radius().background_blur_radius() ==
520 BACKGROUND_BLUR_RADIUS_UPDATE);
521 if (hasBackgroundBlur && !foundBackgroundBlur) {
522 foundBackgroundBlur = true;
523 } else if (hasBackgroundBlur && foundBackgroundBlur) {
524 []() { FAIL(); }();
525 }
526 return foundBackgroundBlur;
527 }
528
layerUpdateFound(const SurfaceChange & change,bool foundLayer)529 bool SurfaceInterceptorTest::layerUpdateFound(const SurfaceChange& change, bool foundLayer) {
530 bool hasLayer(change.layer().layer() == LAYER_UPDATE);
531 if (hasLayer && !foundLayer) {
532 foundLayer = true;
533 } else if (hasLayer && foundLayer) {
534 [] () { FAIL(); }();
535 }
536 return foundLayer;
537 }
538
cropUpdateFound(const SurfaceChange & change,bool foundCrop)539 bool SurfaceInterceptorTest::cropUpdateFound(const SurfaceChange& change, bool foundCrop) {
540 bool hasLeft(change.crop().rectangle().left() == CROP_UPDATE.left);
541 bool hasTop(change.crop().rectangle().top() == CROP_UPDATE.top);
542 bool hasRight(change.crop().rectangle().right() == CROP_UPDATE.right);
543 bool hasBottom(change.crop().rectangle().bottom() == CROP_UPDATE.bottom);
544 if (hasLeft && hasRight && hasTop && hasBottom && !foundCrop) {
545 foundCrop = true;
546 } else if (hasLeft && hasRight && hasTop && hasBottom && foundCrop) {
547 [] () { FAIL(); }();
548 }
549 return foundCrop;
550 }
551
matrixUpdateFound(const SurfaceChange & change,bool foundMatrix)552 bool SurfaceInterceptorTest::matrixUpdateFound(const SurfaceChange& change, bool foundMatrix) {
553 bool hasSx((float)change.matrix().dsdx() == (float)M_SQRT1_2);
554 bool hasTx((float)change.matrix().dtdx() == (float)M_SQRT1_2);
555 bool hasSy((float)change.matrix().dsdy() == (float)M_SQRT1_2);
556 bool hasTy((float)change.matrix().dtdy() == (float)-M_SQRT1_2);
557 if (hasSx && hasTx && hasSy && hasTy && !foundMatrix) {
558 foundMatrix = true;
559 } else if (hasSx && hasTx && hasSy && hasTy && foundMatrix) {
560 [] () { FAIL(); }();
561 }
562 return foundMatrix;
563 }
564
scalingModeUpdateFound(const SurfaceChange & change,bool foundScalingMode)565 bool SurfaceInterceptorTest::scalingModeUpdateFound(const SurfaceChange& change,
566 bool foundScalingMode) {
567 bool hasScalingUpdate(change.override_scaling_mode().override_scaling_mode() == SCALING_UPDATE);
568 if (hasScalingUpdate && !foundScalingMode) {
569 foundScalingMode = true;
570 } else if (hasScalingUpdate && foundScalingMode) {
571 [] () { FAIL(); }();
572 }
573 return foundScalingMode;
574 }
575
transparentRegionHintUpdateFound(const SurfaceChange & change,bool foundTransparentRegion)576 bool SurfaceInterceptorTest::transparentRegionHintUpdateFound(const SurfaceChange& change,
577 bool foundTransparentRegion) {
578 auto traceRegion = change.transparent_region_hint().region(0);
579 bool hasLeft(traceRegion.left() == CROP_UPDATE.left);
580 bool hasTop(traceRegion.top() == CROP_UPDATE.top);
581 bool hasRight(traceRegion.right() == CROP_UPDATE.right);
582 bool hasBottom(traceRegion.bottom() == CROP_UPDATE.bottom);
583 if (hasLeft && hasRight && hasTop && hasBottom && !foundTransparentRegion) {
584 foundTransparentRegion = true;
585 } else if (hasLeft && hasRight && hasTop && hasBottom && foundTransparentRegion) {
586 [] () { FAIL(); }();
587 }
588 return foundTransparentRegion;
589 }
590
layerStackUpdateFound(const SurfaceChange & change,bool foundLayerStack)591 bool SurfaceInterceptorTest::layerStackUpdateFound(const SurfaceChange& change,
592 bool foundLayerStack) {
593 bool hasLayerStackUpdate(change.layer_stack().layer_stack() == STACK_UPDATE);
594 if (hasLayerStackUpdate && !foundLayerStack) {
595 foundLayerStack = true;
596 } else if (hasLayerStackUpdate && foundLayerStack) {
597 [] () { FAIL(); }();
598 }
599 return foundLayerStack;
600 }
601
hiddenFlagUpdateFound(const SurfaceChange & change,bool foundHiddenFlag)602 bool SurfaceInterceptorTest::hiddenFlagUpdateFound(const SurfaceChange& change,
603 bool foundHiddenFlag) {
604 bool hasHiddenFlag(change.hidden_flag().hidden_flag());
605 if (hasHiddenFlag && !foundHiddenFlag) {
606 foundHiddenFlag = true;
607 } else if (hasHiddenFlag && foundHiddenFlag) {
608 [] () { FAIL(); }();
609 }
610 return foundHiddenFlag;
611 }
612
opaqueFlagUpdateFound(const SurfaceChange & change,bool foundOpaqueFlag)613 bool SurfaceInterceptorTest::opaqueFlagUpdateFound(const SurfaceChange& change,
614 bool foundOpaqueFlag) {
615 bool hasOpaqueFlag(change.opaque_flag().opaque_flag());
616 if (hasOpaqueFlag && !foundOpaqueFlag) {
617 foundOpaqueFlag = true;
618 } else if (hasOpaqueFlag && foundOpaqueFlag) {
619 [] () { FAIL(); }();
620 }
621 return foundOpaqueFlag;
622 }
623
secureFlagUpdateFound(const SurfaceChange & change,bool foundSecureFlag)624 bool SurfaceInterceptorTest::secureFlagUpdateFound(const SurfaceChange& change,
625 bool foundSecureFlag) {
626 bool hasSecureFlag(change.secure_flag().secure_flag());
627 if (hasSecureFlag && !foundSecureFlag) {
628 foundSecureFlag = true;
629 } else if (hasSecureFlag && foundSecureFlag) {
630 [] () { FAIL(); }();
631 }
632 return foundSecureFlag;
633 }
634
deferredTransactionUpdateFound(const SurfaceChange & change,bool foundDeferred)635 bool SurfaceInterceptorTest::deferredTransactionUpdateFound(const SurfaceChange& change,
636 bool foundDeferred) {
637 bool hasId(change.deferred_transaction().layer_id() == mBGLayerId);
638 bool hasFrameNumber(change.deferred_transaction().frame_number() == DEFERRED_UPDATE);
639 if (hasId && hasFrameNumber && !foundDeferred) {
640 foundDeferred = true;
641 } else if (hasId && hasFrameNumber && foundDeferred) {
642 [] () { FAIL(); }();
643 }
644 return foundDeferred;
645 }
646
reparentUpdateFound(const SurfaceChange & change,bool found)647 bool SurfaceInterceptorTest::reparentUpdateFound(const SurfaceChange& change, bool found) {
648 bool hasId(change.reparent().parent_id() == mFGLayerId);
649 if (hasId && !found) {
650 found = true;
651 } else if (hasId && found) {
652 []() { FAIL(); }();
653 }
654 return found;
655 }
656
relativeParentUpdateFound(const SurfaceChange & change,bool found)657 bool SurfaceInterceptorTest::relativeParentUpdateFound(const SurfaceChange& change, bool found) {
658 bool hasId(change.relative_parent().relative_parent_id() == mFGLayerId);
659 if (hasId && !found) {
660 found = true;
661 } else if (hasId && found) {
662 []() { FAIL(); }();
663 }
664 return found;
665 }
666
detachChildrenUpdateFound(const SurfaceChange & change,bool found)667 bool SurfaceInterceptorTest::detachChildrenUpdateFound(const SurfaceChange& change, bool found) {
668 bool detachChildren(change.detach_children().detach_children());
669 if (detachChildren && !found) {
670 found = true;
671 } else if (detachChildren && found) {
672 []() { FAIL(); }();
673 }
674 return found;
675 }
676
reparentChildrenUpdateFound(const SurfaceChange & change,bool found)677 bool SurfaceInterceptorTest::reparentChildrenUpdateFound(const SurfaceChange& change, bool found) {
678 bool hasId(change.reparent_children().parent_id() == mFGLayerId);
679 if (hasId && !found) {
680 found = true;
681 } else if (hasId && found) {
682 []() { FAIL(); }();
683 }
684 return found;
685 }
686
shadowRadiusUpdateFound(const SurfaceChange & change,bool foundShadowRadius)687 bool SurfaceInterceptorTest::shadowRadiusUpdateFound(const SurfaceChange& change,
688 bool foundShadowRadius) {
689 bool hasShadowRadius(change.shadow_radius().radius() == SHADOW_RADIUS_UPDATE);
690 if (hasShadowRadius && !foundShadowRadius) {
691 foundShadowRadius = true;
692 } else if (hasShadowRadius && foundShadowRadius) {
693 []() { FAIL(); }();
694 }
695 return foundShadowRadius;
696 }
697
surfaceUpdateFound(const Trace & trace,SurfaceChange::SurfaceChangeCase changeCase)698 bool SurfaceInterceptorTest::surfaceUpdateFound(const Trace& trace,
699 SurfaceChange::SurfaceChangeCase changeCase) {
700 bool foundUpdate = false;
701 for (const auto& increment : trace.increment()) {
702 if (increment.increment_case() == increment.kTransaction) {
703 for (const auto& change : increment.transaction().surface_change()) {
704 if (change.id() == mBGLayerId && change.SurfaceChange_case() == changeCase) {
705 switch (changeCase) {
706 case SurfaceChange::SurfaceChangeCase::kPosition:
707 // foundUpdate is sent for the tests to fail on duplicated increments
708 foundUpdate = positionUpdateFound(change, foundUpdate);
709 break;
710 case SurfaceChange::SurfaceChangeCase::kSize:
711 foundUpdate = sizeUpdateFound(change, foundUpdate);
712 break;
713 case SurfaceChange::SurfaceChangeCase::kAlpha:
714 foundUpdate = alphaUpdateFound(change, foundUpdate);
715 break;
716 case SurfaceChange::SurfaceChangeCase::kLayer:
717 foundUpdate = layerUpdateFound(change, foundUpdate);
718 break;
719 case SurfaceChange::SurfaceChangeCase::kCrop:
720 foundUpdate = cropUpdateFound(change, foundUpdate);
721 break;
722 case SurfaceChange::SurfaceChangeCase::kCornerRadius:
723 foundUpdate = cornerRadiusUpdateFound(change, foundUpdate);
724 break;
725 case SurfaceChange::SurfaceChangeCase::kBackgroundBlurRadius:
726 foundUpdate = backgroundBlurRadiusUpdateFound(change, foundUpdate);
727 break;
728 case SurfaceChange::SurfaceChangeCase::kMatrix:
729 foundUpdate = matrixUpdateFound(change, foundUpdate);
730 break;
731 case SurfaceChange::SurfaceChangeCase::kOverrideScalingMode:
732 foundUpdate = scalingModeUpdateFound(change, foundUpdate);
733 break;
734 case SurfaceChange::SurfaceChangeCase::kTransparentRegionHint:
735 foundUpdate = transparentRegionHintUpdateFound(change, foundUpdate);
736 break;
737 case SurfaceChange::SurfaceChangeCase::kLayerStack:
738 foundUpdate = layerStackUpdateFound(change, foundUpdate);
739 break;
740 case SurfaceChange::SurfaceChangeCase::kHiddenFlag:
741 foundUpdate = hiddenFlagUpdateFound(change, foundUpdate);
742 break;
743 case SurfaceChange::SurfaceChangeCase::kOpaqueFlag:
744 foundUpdate = opaqueFlagUpdateFound(change, foundUpdate);
745 break;
746 case SurfaceChange::SurfaceChangeCase::kSecureFlag:
747 foundUpdate = secureFlagUpdateFound(change, foundUpdate);
748 break;
749 case SurfaceChange::SurfaceChangeCase::kDeferredTransaction:
750 foundUpdate = deferredTransactionUpdateFound(change, foundUpdate);
751 break;
752 case SurfaceChange::SurfaceChangeCase::kReparent:
753 foundUpdate = reparentUpdateFound(change, foundUpdate);
754 break;
755 case SurfaceChange::SurfaceChangeCase::kReparentChildren:
756 foundUpdate = reparentChildrenUpdateFound(change, foundUpdate);
757 break;
758 case SurfaceChange::SurfaceChangeCase::kRelativeParent:
759 foundUpdate = relativeParentUpdateFound(change, foundUpdate);
760 break;
761 case SurfaceChange::SurfaceChangeCase::kDetachChildren:
762 foundUpdate = detachChildrenUpdateFound(change, foundUpdate);
763 break;
764 case SurfaceChange::SurfaceChangeCase::kShadowRadius:
765 foundUpdate = shadowRadiusUpdateFound(change, foundUpdate);
766 break;
767 case SurfaceChange::SurfaceChangeCase::SURFACECHANGE_NOT_SET:
768 break;
769 }
770 }
771 }
772 }
773 }
774 return foundUpdate;
775 }
776
assertAllUpdatesFound(const Trace & trace)777 void SurfaceInterceptorTest::assertAllUpdatesFound(const Trace& trace) {
778 ASSERT_TRUE(surfaceUpdateFound(trace, SurfaceChange::SurfaceChangeCase::kPosition));
779 ASSERT_TRUE(surfaceUpdateFound(trace, SurfaceChange::SurfaceChangeCase::kSize));
780 ASSERT_TRUE(surfaceUpdateFound(trace, SurfaceChange::SurfaceChangeCase::kAlpha));
781 ASSERT_TRUE(surfaceUpdateFound(trace, SurfaceChange::SurfaceChangeCase::kLayer));
782 ASSERT_TRUE(surfaceUpdateFound(trace, SurfaceChange::SurfaceChangeCase::kCrop));
783 ASSERT_TRUE(surfaceUpdateFound(trace, SurfaceChange::SurfaceChangeCase::kMatrix));
784 ASSERT_TRUE(surfaceUpdateFound(trace, SurfaceChange::SurfaceChangeCase::kOverrideScalingMode));
785 ASSERT_TRUE(surfaceUpdateFound(trace, SurfaceChange::SurfaceChangeCase::kTransparentRegionHint));
786 ASSERT_TRUE(surfaceUpdateFound(trace, SurfaceChange::SurfaceChangeCase::kLayerStack));
787 ASSERT_TRUE(surfaceUpdateFound(trace, SurfaceChange::SurfaceChangeCase::kHiddenFlag));
788 ASSERT_TRUE(surfaceUpdateFound(trace, SurfaceChange::SurfaceChangeCase::kOpaqueFlag));
789 ASSERT_TRUE(surfaceUpdateFound(trace, SurfaceChange::SurfaceChangeCase::kSecureFlag));
790 ASSERT_TRUE(surfaceUpdateFound(trace, SurfaceChange::SurfaceChangeCase::kDeferredTransaction));
791 ASSERT_TRUE(surfaceUpdateFound(trace, SurfaceChange::SurfaceChangeCase::kReparent));
792 ASSERT_TRUE(surfaceUpdateFound(trace, SurfaceChange::SurfaceChangeCase::kReparentChildren));
793 ASSERT_TRUE(surfaceUpdateFound(trace, SurfaceChange::SurfaceChangeCase::kRelativeParent));
794 ASSERT_TRUE(surfaceUpdateFound(trace, SurfaceChange::SurfaceChangeCase::kDetachChildren));
795 }
796
surfaceCreationFound(const Increment & increment,bool foundSurface)797 bool SurfaceInterceptorTest::surfaceCreationFound(const Increment& increment, bool foundSurface) {
798 bool isMatch(increment.surface_creation().name() == UNIQUE_LAYER_NAME &&
799 increment.surface_creation().w() == SIZE_UPDATE &&
800 increment.surface_creation().h() == SIZE_UPDATE);
801 if (isMatch && !foundSurface) {
802 foundSurface = true;
803 } else if (isMatch && foundSurface) {
804 [] () { FAIL(); }();
805 }
806 return foundSurface;
807 }
808
surfaceDeletionFound(const Increment & increment,const int32_t targetId,bool foundSurface)809 bool SurfaceInterceptorTest::surfaceDeletionFound(const Increment& increment,
810 const int32_t targetId, bool foundSurface) {
811 bool isMatch(increment.surface_deletion().id() == targetId);
812 if (isMatch && !foundSurface) {
813 foundSurface = true;
814 } else if (isMatch && foundSurface) {
815 [] () { FAIL(); }();
816 }
817 return foundSurface;
818 }
819
displayCreationFound(const Increment & increment,bool foundDisplay)820 bool SurfaceInterceptorTest::displayCreationFound(const Increment& increment, bool foundDisplay) {
821 bool isMatch(increment.display_creation().name() == DISPLAY_NAME.string() &&
822 increment.display_creation().is_secure());
823 if (isMatch && !foundDisplay) {
824 foundDisplay = true;
825 } else if (isMatch && foundDisplay) {
826 [] () { FAIL(); }();
827 }
828 return foundDisplay;
829 }
830
displayDeletionFound(const Increment & increment,const int32_t targetId,bool foundDisplay)831 bool SurfaceInterceptorTest::displayDeletionFound(const Increment& increment,
832 const int32_t targetId, bool foundDisplay) {
833 bool isMatch(increment.display_deletion().id() == targetId);
834 if (isMatch && !foundDisplay) {
835 foundDisplay = true;
836 } else if (isMatch && foundDisplay) {
837 [] () { FAIL(); }();
838 }
839 return foundDisplay;
840 }
841
singleIncrementFound(const Trace & trace,Increment::IncrementCase incrementCase)842 bool SurfaceInterceptorTest::singleIncrementFound(const Trace& trace,
843 Increment::IncrementCase incrementCase) {
844 bool foundIncrement = false;
845 for (const auto& increment : trace.increment()) {
846 if (increment.increment_case() == incrementCase) {
847 int32_t targetId = 0;
848 switch (incrementCase) {
849 case Increment::IncrementCase::kSurfaceCreation:
850 foundIncrement = surfaceCreationFound(increment, foundIncrement);
851 break;
852 case Increment::IncrementCase::kSurfaceDeletion:
853 // Find the id of created surface.
854 targetId = getSurfaceId(trace, UNIQUE_LAYER_NAME);
855 foundIncrement = surfaceDeletionFound(increment, targetId, foundIncrement);
856 break;
857 case Increment::IncrementCase::kDisplayCreation:
858 foundIncrement = displayCreationFound(increment, foundIncrement);
859 break;
860 case Increment::IncrementCase::kDisplayDeletion:
861 // Find the id of created display.
862 targetId = getDisplayId(trace, DISPLAY_NAME.string());
863 foundIncrement = displayDeletionFound(increment, targetId, foundIncrement);
864 break;
865 default:
866 /* code */
867 break;
868 }
869 }
870 }
871 return foundIncrement;
872 }
873
bufferUpdatesFound(const Trace & trace)874 bool SurfaceInterceptorTest::bufferUpdatesFound(const Trace& trace) {
875 uint32_t updates = 0;
876 for (const auto& inc : trace.increment()) {
877 if (inc.increment_case() == inc.kBufferUpdate && inc.buffer_update().id() == mBGLayerId) {
878 updates++;
879 }
880 }
881 return updates == BUFFER_UPDATES;
882 }
883
TEST_F(SurfaceInterceptorTest,InterceptPositionUpdateWorks)884 TEST_F(SurfaceInterceptorTest, InterceptPositionUpdateWorks) {
885 captureTest(&SurfaceInterceptorTest::positionUpdate,
886 SurfaceChange::SurfaceChangeCase::kPosition);
887 }
888
TEST_F(SurfaceInterceptorTest,InterceptSizeUpdateWorks)889 TEST_F(SurfaceInterceptorTest, InterceptSizeUpdateWorks) {
890 captureTest(&SurfaceInterceptorTest::sizeUpdate, SurfaceChange::SurfaceChangeCase::kSize);
891 }
892
TEST_F(SurfaceInterceptorTest,InterceptAlphaUpdateWorks)893 TEST_F(SurfaceInterceptorTest, InterceptAlphaUpdateWorks) {
894 captureTest(&SurfaceInterceptorTest::alphaUpdate, SurfaceChange::SurfaceChangeCase::kAlpha);
895 }
896
TEST_F(SurfaceInterceptorTest,InterceptLayerUpdateWorks)897 TEST_F(SurfaceInterceptorTest, InterceptLayerUpdateWorks) {
898 captureTest(&SurfaceInterceptorTest::layerUpdate, SurfaceChange::SurfaceChangeCase::kLayer);
899 }
900
TEST_F(SurfaceInterceptorTest,InterceptCropUpdateWorks)901 TEST_F(SurfaceInterceptorTest, InterceptCropUpdateWorks) {
902 captureTest(&SurfaceInterceptorTest::cropUpdate, SurfaceChange::SurfaceChangeCase::kCrop);
903 }
904
TEST_F(SurfaceInterceptorTest,InterceptCornerRadiusUpdateWorks)905 TEST_F(SurfaceInterceptorTest, InterceptCornerRadiusUpdateWorks) {
906 captureTest(&SurfaceInterceptorTest::cornerRadiusUpdate,
907 SurfaceChange::SurfaceChangeCase::kCornerRadius);
908 }
909
TEST_F(SurfaceInterceptorTest,InterceptBackgroundBlurRadiusUpdateWorks)910 TEST_F(SurfaceInterceptorTest, InterceptBackgroundBlurRadiusUpdateWorks) {
911 captureTest(&SurfaceInterceptorTest::backgroundBlurRadiusUpdate,
912 SurfaceChange::SurfaceChangeCase::kBackgroundBlurRadius);
913 }
914
TEST_F(SurfaceInterceptorTest,InterceptMatrixUpdateWorks)915 TEST_F(SurfaceInterceptorTest, InterceptMatrixUpdateWorks) {
916 captureTest(&SurfaceInterceptorTest::matrixUpdate, SurfaceChange::SurfaceChangeCase::kMatrix);
917 }
918
TEST_F(SurfaceInterceptorTest,InterceptOverrideScalingModeUpdateWorks)919 TEST_F(SurfaceInterceptorTest, InterceptOverrideScalingModeUpdateWorks) {
920 captureTest(&SurfaceInterceptorTest::overrideScalingModeUpdate,
921 SurfaceChange::SurfaceChangeCase::kOverrideScalingMode);
922 }
923
TEST_F(SurfaceInterceptorTest,InterceptTransparentRegionHintUpdateWorks)924 TEST_F(SurfaceInterceptorTest, InterceptTransparentRegionHintUpdateWorks) {
925 captureTest(&SurfaceInterceptorTest::transparentRegionHintUpdate,
926 SurfaceChange::SurfaceChangeCase::kTransparentRegionHint);
927 }
928
TEST_F(SurfaceInterceptorTest,InterceptLayerStackUpdateWorks)929 TEST_F(SurfaceInterceptorTest, InterceptLayerStackUpdateWorks) {
930 captureTest(&SurfaceInterceptorTest::layerStackUpdate,
931 SurfaceChange::SurfaceChangeCase::kLayerStack);
932 }
933
TEST_F(SurfaceInterceptorTest,InterceptHiddenFlagUpdateWorks)934 TEST_F(SurfaceInterceptorTest, InterceptHiddenFlagUpdateWorks) {
935 captureTest(&SurfaceInterceptorTest::hiddenFlagUpdate,
936 SurfaceChange::SurfaceChangeCase::kHiddenFlag);
937 }
938
TEST_F(SurfaceInterceptorTest,InterceptOpaqueFlagUpdateWorks)939 TEST_F(SurfaceInterceptorTest, InterceptOpaqueFlagUpdateWorks) {
940 captureTest(&SurfaceInterceptorTest::opaqueFlagUpdate,
941 SurfaceChange::SurfaceChangeCase::kOpaqueFlag);
942 }
943
TEST_F(SurfaceInterceptorTest,InterceptSecureFlagUpdateWorks)944 TEST_F(SurfaceInterceptorTest, InterceptSecureFlagUpdateWorks) {
945 captureTest(&SurfaceInterceptorTest::secureFlagUpdate,
946 SurfaceChange::SurfaceChangeCase::kSecureFlag);
947 }
948
TEST_F(SurfaceInterceptorTest,InterceptDeferredTransactionUpdateWorks)949 TEST_F(SurfaceInterceptorTest, InterceptDeferredTransactionUpdateWorks) {
950 captureTest(&SurfaceInterceptorTest::deferredTransactionUpdate,
951 SurfaceChange::SurfaceChangeCase::kDeferredTransaction);
952 }
953
TEST_F(SurfaceInterceptorTest,InterceptReparentUpdateWorks)954 TEST_F(SurfaceInterceptorTest, InterceptReparentUpdateWorks) {
955 captureTest(&SurfaceInterceptorTest::reparentUpdate,
956 SurfaceChange::SurfaceChangeCase::kReparent);
957 }
958
TEST_F(SurfaceInterceptorTest,InterceptReparentChildrenUpdateWorks)959 TEST_F(SurfaceInterceptorTest, InterceptReparentChildrenUpdateWorks) {
960 captureTest(&SurfaceInterceptorTest::reparentChildrenUpdate,
961 SurfaceChange::SurfaceChangeCase::kReparentChildren);
962 }
963
TEST_F(SurfaceInterceptorTest,InterceptRelativeParentUpdateWorks)964 TEST_F(SurfaceInterceptorTest, InterceptRelativeParentUpdateWorks) {
965 captureTest(&SurfaceInterceptorTest::relativeParentUpdate,
966 SurfaceChange::SurfaceChangeCase::kRelativeParent);
967 }
968
TEST_F(SurfaceInterceptorTest,InterceptDetachChildrenUpdateWorks)969 TEST_F(SurfaceInterceptorTest, InterceptDetachChildrenUpdateWorks) {
970 captureTest(&SurfaceInterceptorTest::detachChildrenUpdate,
971 SurfaceChange::SurfaceChangeCase::kDetachChildren);
972 }
973
TEST_F(SurfaceInterceptorTest,InterceptShadowRadiusUpdateWorks)974 TEST_F(SurfaceInterceptorTest, InterceptShadowRadiusUpdateWorks) {
975 captureTest(&SurfaceInterceptorTest::shadowRadiusUpdate,
976 SurfaceChange::SurfaceChangeCase::kShadowRadius);
977 }
978
TEST_F(SurfaceInterceptorTest,InterceptAllUpdatesWorks)979 TEST_F(SurfaceInterceptorTest, InterceptAllUpdatesWorks) {
980 captureTest(&SurfaceInterceptorTest::runAllUpdates,
981 &SurfaceInterceptorTest::assertAllUpdatesFound);
982 }
983
TEST_F(SurfaceInterceptorTest,InterceptSurfaceCreationWorks)984 TEST_F(SurfaceInterceptorTest, InterceptSurfaceCreationWorks) {
985 captureTest(&SurfaceInterceptorTest::surfaceCreation,
986 Increment::IncrementCase::kSurfaceCreation);
987 }
988
TEST_F(SurfaceInterceptorTest,InterceptDisplayCreationWorks)989 TEST_F(SurfaceInterceptorTest, InterceptDisplayCreationWorks) {
990 captureTest(&SurfaceInterceptorTest::displayCreation,
991 Increment::IncrementCase::kDisplayCreation);
992 }
993
TEST_F(SurfaceInterceptorTest,InterceptDisplayDeletionWorks)994 TEST_F(SurfaceInterceptorTest, InterceptDisplayDeletionWorks) {
995 enableInterceptor();
996 runInTransaction(&SurfaceInterceptorTest::displayDeletion);
997 disableInterceptor();
998 Trace capturedTrace;
999 ASSERT_EQ(NO_ERROR, readProtoFile(&capturedTrace));
1000 ASSERT_TRUE(singleIncrementFound(capturedTrace, Increment::IncrementCase::kDisplayDeletion));
1001 }
1002
TEST_F(SurfaceInterceptorTest,InterceptBufferUpdateWorks)1003 TEST_F(SurfaceInterceptorTest, InterceptBufferUpdateWorks) {
1004 captureTest(&SurfaceInterceptorTest::nBufferUpdates,
1005 &SurfaceInterceptorTest::bufferUpdatesFound);
1006 }
1007
1008 // If the interceptor is enabled while buffer updates are being pushed, the interceptor should
1009 // first create a snapshot of the existing displays and surfaces and then start capturing
1010 // the buffer updates
TEST_F(SurfaceInterceptorTest,InterceptWhileBufferUpdatesWorks)1011 TEST_F(SurfaceInterceptorTest, InterceptWhileBufferUpdatesWorks) {
1012 setupBackgroundSurface();
1013 std::thread bufferUpdates(&SurfaceInterceptorTest::nBufferUpdates, this);
1014 enableInterceptor();
1015 disableInterceptor();
1016 bufferUpdates.join();
1017
1018 Trace capturedTrace;
1019 ASSERT_EQ(NO_ERROR, readProtoFile(&capturedTrace));
1020 const auto& firstIncrement = capturedTrace.mutable_increment(0);
1021 ASSERT_EQ(firstIncrement->increment_case(), Increment::IncrementCase::kDisplayCreation);
1022 }
1023
TEST_F(SurfaceInterceptorTest,InterceptSimultaneousUpdatesWorks)1024 TEST_F(SurfaceInterceptorTest, InterceptSimultaneousUpdatesWorks) {
1025 enableInterceptor();
1026 setupBackgroundSurface();
1027 std::thread bufferUpdates(&SurfaceInterceptorTest::nBufferUpdates, this);
1028 std::thread surfaceUpdates(&SurfaceInterceptorTest::runAllUpdates, this);
1029 runInTransaction(&SurfaceInterceptorTest::surfaceCreation);
1030 bufferUpdates.join();
1031 surfaceUpdates.join();
1032 disableInterceptor();
1033
1034 Trace capturedTrace;
1035 ASSERT_EQ(NO_ERROR, readProtoFile(&capturedTrace));
1036 preProcessTrace(capturedTrace);
1037
1038 assertAllUpdatesFound(capturedTrace);
1039 ASSERT_TRUE(bufferUpdatesFound(capturedTrace));
1040 ASSERT_TRUE(singleIncrementFound(capturedTrace, Increment::IncrementCase::kSurfaceCreation));
1041 }
1042 }
1043
1044 // TODO(b/129481165): remove the #pragma below and fix conversion issues
1045 #pragma clang diagnostic pop // ignored "-Wconversion"
1046