SurfaceInterceptor.cpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607
  1. /*
  2. * Copyright 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. #undef LOG_TAG
  17. #define LOG_TAG "SurfaceInterceptor"
  18. #define ATRACE_TAG ATRACE_TAG_GRAPHICS
  19. #include "Layer.h"
  20. #include "SurfaceFlinger.h"
  21. #include "SurfaceInterceptor.h"
  22. #include <fstream>
  23. #include <android-base/file.h>
  24. #include <log/log.h>
  25. #include <utils/Trace.h>
  26. namespace android {
  27. // ----------------------------------------------------------------------------
  28. // TODO(marissaw): add new layer state values to SurfaceInterceptor
  29. SurfaceInterceptor::~SurfaceInterceptor() = default;
  30. namespace impl {
  31. SurfaceInterceptor::SurfaceInterceptor(SurfaceFlinger* flinger)
  32. : mFlinger(flinger)
  33. {
  34. }
  35. void SurfaceInterceptor::enable(const SortedVector<sp<Layer>>& layers,
  36. const DefaultKeyedVector< wp<IBinder>, DisplayDeviceState>& displays)
  37. {
  38. if (mEnabled) {
  39. return;
  40. }
  41. ATRACE_CALL();
  42. mEnabled = true;
  43. std::lock_guard<std::mutex> protoGuard(mTraceMutex);
  44. saveExistingDisplaysLocked(displays);
  45. saveExistingSurfacesLocked(layers);
  46. }
  47. void SurfaceInterceptor::disable() {
  48. if (!mEnabled) {
  49. return;
  50. }
  51. ATRACE_CALL();
  52. std::lock_guard<std::mutex> protoGuard(mTraceMutex);
  53. mEnabled = false;
  54. status_t err(writeProtoFileLocked());
  55. ALOGE_IF(err == PERMISSION_DENIED, "Could not save the proto file! Permission denied");
  56. ALOGE_IF(err == NOT_ENOUGH_DATA, "Could not save the proto file! There are missing fields");
  57. mTrace.Clear();
  58. }
  59. bool SurfaceInterceptor::isEnabled() {
  60. return mEnabled;
  61. }
  62. void SurfaceInterceptor::saveExistingDisplaysLocked(
  63. const DefaultKeyedVector< wp<IBinder>, DisplayDeviceState>& displays)
  64. {
  65. // Caveat: The initial snapshot does not capture the power mode of the existing displays
  66. ATRACE_CALL();
  67. for (size_t i = 0 ; i < displays.size() ; i++) {
  68. addDisplayCreationLocked(createTraceIncrementLocked(), displays[i]);
  69. addInitialDisplayStateLocked(createTraceIncrementLocked(), displays[i]);
  70. }
  71. }
  72. void SurfaceInterceptor::saveExistingSurfacesLocked(const SortedVector<sp<Layer>>& layers) {
  73. ATRACE_CALL();
  74. for (const auto& l : layers) {
  75. l->traverseInZOrder(LayerVector::StateSet::Drawing, [this](Layer* layer) {
  76. addSurfaceCreationLocked(createTraceIncrementLocked(), layer);
  77. addInitialSurfaceStateLocked(createTraceIncrementLocked(), layer);
  78. });
  79. }
  80. }
  81. void SurfaceInterceptor::addInitialSurfaceStateLocked(Increment* increment,
  82. const sp<const Layer>& layer)
  83. {
  84. Transaction* transaction(increment->mutable_transaction());
  85. const uint32_t layerFlags = layer->getTransactionFlags();
  86. transaction->set_synchronous(layerFlags & BnSurfaceComposer::eSynchronous);
  87. transaction->set_animation(layerFlags & BnSurfaceComposer::eAnimation);
  88. const int32_t layerId(getLayerId(layer));
  89. addPositionLocked(transaction, layerId, layer->mCurrentState.active_legacy.transform.tx(),
  90. layer->mCurrentState.active_legacy.transform.ty());
  91. addDepthLocked(transaction, layerId, layer->mCurrentState.z);
  92. addAlphaLocked(transaction, layerId, layer->mCurrentState.color.a);
  93. addTransparentRegionLocked(transaction, layerId,
  94. layer->mCurrentState.activeTransparentRegion_legacy);
  95. addLayerStackLocked(transaction, layerId, layer->mCurrentState.layerStack);
  96. addCropLocked(transaction, layerId, layer->mCurrentState.crop_legacy);
  97. addCornerRadiusLocked(transaction, layerId, layer->mCurrentState.cornerRadius);
  98. if (layer->mCurrentState.barrierLayer_legacy != nullptr) {
  99. addDeferTransactionLocked(transaction, layerId,
  100. layer->mCurrentState.barrierLayer_legacy.promote(),
  101. layer->mCurrentState.frameNumber_legacy);
  102. }
  103. addOverrideScalingModeLocked(transaction, layerId, layer->getEffectiveScalingMode());
  104. addFlagsLocked(transaction, layerId, layer->mCurrentState.flags);
  105. }
  106. void SurfaceInterceptor::addInitialDisplayStateLocked(Increment* increment,
  107. const DisplayDeviceState& display)
  108. {
  109. Transaction* transaction(increment->mutable_transaction());
  110. transaction->set_synchronous(false);
  111. transaction->set_animation(false);
  112. addDisplaySurfaceLocked(transaction, display.sequenceId, display.surface);
  113. addDisplayLayerStackLocked(transaction, display.sequenceId, display.layerStack);
  114. addDisplaySizeLocked(transaction, display.sequenceId, display.width, display.height);
  115. addDisplayProjectionLocked(transaction, display.sequenceId, display.orientation,
  116. display.viewport, display.frame);
  117. }
  118. status_t SurfaceInterceptor::writeProtoFileLocked() {
  119. ATRACE_CALL();
  120. std::string output;
  121. if (!mTrace.IsInitialized()) {
  122. return NOT_ENOUGH_DATA;
  123. }
  124. if (!mTrace.SerializeToString(&output)) {
  125. return PERMISSION_DENIED;
  126. }
  127. if (!android::base::WriteStringToFile(output, mOutputFileName, true)) {
  128. return PERMISSION_DENIED;
  129. }
  130. return NO_ERROR;
  131. }
  132. const sp<const Layer> SurfaceInterceptor::getLayer(const wp<const IBinder>& weakHandle) {
  133. const sp<const IBinder>& handle(weakHandle.promote());
  134. const auto layerHandle(static_cast<const Layer::Handle*>(handle.get()));
  135. const sp<const Layer> layer(layerHandle->owner.promote());
  136. // layer could be a nullptr at this point
  137. return layer;
  138. }
  139. const std::string SurfaceInterceptor::getLayerName(const sp<const Layer>& layer) {
  140. return layer->getName().string();
  141. }
  142. int32_t SurfaceInterceptor::getLayerId(const sp<const Layer>& layer) {
  143. return layer->sequence;
  144. }
  145. Increment* SurfaceInterceptor::createTraceIncrementLocked() {
  146. Increment* increment(mTrace.add_increment());
  147. increment->set_time_stamp(systemTime());
  148. return increment;
  149. }
  150. SurfaceChange* SurfaceInterceptor::createSurfaceChangeLocked(Transaction* transaction,
  151. int32_t layerId)
  152. {
  153. SurfaceChange* change(transaction->add_surface_change());
  154. change->set_id(layerId);
  155. return change;
  156. }
  157. DisplayChange* SurfaceInterceptor::createDisplayChangeLocked(Transaction* transaction,
  158. int32_t sequenceId)
  159. {
  160. DisplayChange* dispChange(transaction->add_display_change());
  161. dispChange->set_id(sequenceId);
  162. return dispChange;
  163. }
  164. void SurfaceInterceptor::setProtoRectLocked(Rectangle* protoRect, const Rect& rect) {
  165. protoRect->set_left(rect.left);
  166. protoRect->set_top(rect.top);
  167. protoRect->set_right(rect.right);
  168. protoRect->set_bottom(rect.bottom);
  169. }
  170. void SurfaceInterceptor::addPositionLocked(Transaction* transaction, int32_t layerId,
  171. float x, float y)
  172. {
  173. SurfaceChange* change(createSurfaceChangeLocked(transaction, layerId));
  174. PositionChange* posChange(change->mutable_position());
  175. posChange->set_x(x);
  176. posChange->set_y(y);
  177. }
  178. void SurfaceInterceptor::addDepthLocked(Transaction* transaction, int32_t layerId,
  179. uint32_t z)
  180. {
  181. SurfaceChange* change(createSurfaceChangeLocked(transaction, layerId));
  182. LayerChange* depthChange(change->mutable_layer());
  183. depthChange->set_layer(z);
  184. }
  185. void SurfaceInterceptor::addSizeLocked(Transaction* transaction, int32_t layerId, uint32_t w,
  186. uint32_t h)
  187. {
  188. SurfaceChange* change(createSurfaceChangeLocked(transaction, layerId));
  189. SizeChange* sizeChange(change->mutable_size());
  190. sizeChange->set_w(w);
  191. sizeChange->set_h(h);
  192. }
  193. void SurfaceInterceptor::addAlphaLocked(Transaction* transaction, int32_t layerId,
  194. float alpha)
  195. {
  196. SurfaceChange* change(createSurfaceChangeLocked(transaction, layerId));
  197. AlphaChange* alphaChange(change->mutable_alpha());
  198. alphaChange->set_alpha(alpha);
  199. }
  200. void SurfaceInterceptor::addMatrixLocked(Transaction* transaction, int32_t layerId,
  201. const layer_state_t::matrix22_t& matrix)
  202. {
  203. SurfaceChange* change(createSurfaceChangeLocked(transaction, layerId));
  204. MatrixChange* matrixChange(change->mutable_matrix());
  205. matrixChange->set_dsdx(matrix.dsdx);
  206. matrixChange->set_dtdx(matrix.dtdx);
  207. matrixChange->set_dsdy(matrix.dsdy);
  208. matrixChange->set_dtdy(matrix.dtdy);
  209. }
  210. void SurfaceInterceptor::addTransparentRegionLocked(Transaction* transaction,
  211. int32_t layerId, const Region& transRegion)
  212. {
  213. SurfaceChange* change(createSurfaceChangeLocked(transaction, layerId));
  214. TransparentRegionHintChange* transparentChange(change->mutable_transparent_region_hint());
  215. for (const auto& rect : transRegion) {
  216. Rectangle* protoRect(transparentChange->add_region());
  217. setProtoRectLocked(protoRect, rect);
  218. }
  219. }
  220. void SurfaceInterceptor::addFlagsLocked(Transaction* transaction, int32_t layerId,
  221. uint8_t flags)
  222. {
  223. // There can be multiple flags changed
  224. if (flags & layer_state_t::eLayerHidden) {
  225. SurfaceChange* change(createSurfaceChangeLocked(transaction, layerId));
  226. HiddenFlagChange* flagChange(change->mutable_hidden_flag());
  227. flagChange->set_hidden_flag(true);
  228. }
  229. if (flags & layer_state_t::eLayerOpaque) {
  230. SurfaceChange* change(createSurfaceChangeLocked(transaction, layerId));
  231. OpaqueFlagChange* flagChange(change->mutable_opaque_flag());
  232. flagChange->set_opaque_flag(true);
  233. }
  234. if (flags & layer_state_t::eLayerSecure) {
  235. SurfaceChange* change(createSurfaceChangeLocked(transaction, layerId));
  236. SecureFlagChange* flagChange(change->mutable_secure_flag());
  237. flagChange->set_secure_flag(true);
  238. }
  239. }
  240. void SurfaceInterceptor::addLayerStackLocked(Transaction* transaction, int32_t layerId,
  241. uint32_t layerStack)
  242. {
  243. SurfaceChange* change(createSurfaceChangeLocked(transaction, layerId));
  244. LayerStackChange* layerStackChange(change->mutable_layer_stack());
  245. layerStackChange->set_layer_stack(layerStack);
  246. }
  247. void SurfaceInterceptor::addCropLocked(Transaction* transaction, int32_t layerId,
  248. const Rect& rect)
  249. {
  250. SurfaceChange* change(createSurfaceChangeLocked(transaction, layerId));
  251. CropChange* cropChange(change->mutable_crop());
  252. Rectangle* protoRect(cropChange->mutable_rectangle());
  253. setProtoRectLocked(protoRect, rect);
  254. }
  255. void SurfaceInterceptor::addCornerRadiusLocked(Transaction* transaction, int32_t layerId,
  256. float cornerRadius)
  257. {
  258. SurfaceChange* change(createSurfaceChangeLocked(transaction, layerId));
  259. CornerRadiusChange* cornerRadiusChange(change->mutable_corner_radius());
  260. cornerRadiusChange->set_corner_radius(cornerRadius);
  261. }
  262. void SurfaceInterceptor::addDeferTransactionLocked(Transaction* transaction, int32_t layerId,
  263. const sp<const Layer>& layer, uint64_t frameNumber)
  264. {
  265. SurfaceChange* change(createSurfaceChangeLocked(transaction, layerId));
  266. if (layer == nullptr) {
  267. ALOGE("An existing layer could not be retrieved with the handle"
  268. " for the deferred transaction");
  269. return;
  270. }
  271. DeferredTransactionChange* deferTransaction(change->mutable_deferred_transaction());
  272. deferTransaction->set_layer_id(getLayerId(layer));
  273. deferTransaction->set_frame_number(frameNumber);
  274. }
  275. void SurfaceInterceptor::addOverrideScalingModeLocked(Transaction* transaction,
  276. int32_t layerId, int32_t overrideScalingMode)
  277. {
  278. SurfaceChange* change(createSurfaceChangeLocked(transaction, layerId));
  279. OverrideScalingModeChange* overrideChange(change->mutable_override_scaling_mode());
  280. overrideChange->set_override_scaling_mode(overrideScalingMode);
  281. }
  282. void SurfaceInterceptor::addSurfaceChangesLocked(Transaction* transaction,
  283. const layer_state_t& state)
  284. {
  285. const sp<const Layer> layer(getLayer(state.surface));
  286. if (layer == nullptr) {
  287. ALOGE("An existing layer could not be retrieved with the surface "
  288. "from the layer_state_t surface in the update transaction");
  289. return;
  290. }
  291. const int32_t layerId(getLayerId(layer));
  292. if (state.what & layer_state_t::ePositionChanged) {
  293. addPositionLocked(transaction, layerId, state.x, state.y);
  294. }
  295. if (state.what & layer_state_t::eLayerChanged) {
  296. addDepthLocked(transaction, layerId, state.z);
  297. }
  298. if (state.what & layer_state_t::eSizeChanged) {
  299. addSizeLocked(transaction, layerId, state.w, state.h);
  300. }
  301. if (state.what & layer_state_t::eAlphaChanged) {
  302. addAlphaLocked(transaction, layerId, state.alpha);
  303. }
  304. if (state.what & layer_state_t::eMatrixChanged) {
  305. addMatrixLocked(transaction, layerId, state.matrix);
  306. }
  307. if (state.what & layer_state_t::eTransparentRegionChanged) {
  308. addTransparentRegionLocked(transaction, layerId, state.transparentRegion);
  309. }
  310. if (state.what & layer_state_t::eFlagsChanged) {
  311. addFlagsLocked(transaction, layerId, state.flags);
  312. }
  313. if (state.what & layer_state_t::eLayerStackChanged) {
  314. addLayerStackLocked(transaction, layerId, state.layerStack);
  315. }
  316. if (state.what & layer_state_t::eCropChanged_legacy) {
  317. addCropLocked(transaction, layerId, state.crop_legacy);
  318. }
  319. if (state.what & layer_state_t::eCornerRadiusChanged) {
  320. addCornerRadiusLocked(transaction, layerId, state.cornerRadius);
  321. }
  322. if (state.what & layer_state_t::eDeferTransaction_legacy) {
  323. sp<Layer> otherLayer = nullptr;
  324. if (state.barrierHandle_legacy != nullptr) {
  325. otherLayer =
  326. static_cast<Layer::Handle*>(state.barrierHandle_legacy.get())->owner.promote();
  327. } else if (state.barrierGbp_legacy != nullptr) {
  328. auto const& gbp = state.barrierGbp_legacy;
  329. if (mFlinger->authenticateSurfaceTextureLocked(gbp)) {
  330. otherLayer = (static_cast<MonitoredProducer*>(gbp.get()))->getLayer();
  331. } else {
  332. ALOGE("Attempt to defer transaction to to an unrecognized GraphicBufferProducer");
  333. }
  334. }
  335. addDeferTransactionLocked(transaction, layerId, otherLayer, state.frameNumber_legacy);
  336. }
  337. if (state.what & layer_state_t::eOverrideScalingModeChanged) {
  338. addOverrideScalingModeLocked(transaction, layerId, state.overrideScalingMode);
  339. }
  340. }
  341. void SurfaceInterceptor::addDisplayChangesLocked(Transaction* transaction,
  342. const DisplayState& state, int32_t sequenceId)
  343. {
  344. if (state.what & DisplayState::eSurfaceChanged) {
  345. addDisplaySurfaceLocked(transaction, sequenceId, state.surface);
  346. }
  347. if (state.what & DisplayState::eLayerStackChanged) {
  348. addDisplayLayerStackLocked(transaction, sequenceId, state.layerStack);
  349. }
  350. if (state.what & DisplayState::eDisplaySizeChanged) {
  351. addDisplaySizeLocked(transaction, sequenceId, state.width, state.height);
  352. }
  353. if (state.what & DisplayState::eDisplayProjectionChanged) {
  354. addDisplayProjectionLocked(transaction, sequenceId, state.orientation, state.viewport,
  355. state.frame);
  356. }
  357. }
  358. void SurfaceInterceptor::addTransactionLocked(Increment* increment,
  359. const Vector<ComposerState>& stateUpdates,
  360. const DefaultKeyedVector< wp<IBinder>, DisplayDeviceState>& displays,
  361. const Vector<DisplayState>& changedDisplays, uint32_t transactionFlags)
  362. {
  363. Transaction* transaction(increment->mutable_transaction());
  364. transaction->set_synchronous(transactionFlags & BnSurfaceComposer::eSynchronous);
  365. transaction->set_animation(transactionFlags & BnSurfaceComposer::eAnimation);
  366. for (const auto& compState: stateUpdates) {
  367. addSurfaceChangesLocked(transaction, compState.state);
  368. }
  369. for (const auto& disp: changedDisplays) {
  370. ssize_t dpyIdx = displays.indexOfKey(disp.token);
  371. if (dpyIdx >= 0) {
  372. const DisplayDeviceState& dispState(displays.valueAt(dpyIdx));
  373. addDisplayChangesLocked(transaction, disp, dispState.sequenceId);
  374. }
  375. }
  376. }
  377. void SurfaceInterceptor::addSurfaceCreationLocked(Increment* increment,
  378. const sp<const Layer>& layer)
  379. {
  380. SurfaceCreation* creation(increment->mutable_surface_creation());
  381. creation->set_id(getLayerId(layer));
  382. creation->set_name(getLayerName(layer));
  383. creation->set_w(layer->mCurrentState.active_legacy.w);
  384. creation->set_h(layer->mCurrentState.active_legacy.h);
  385. }
  386. void SurfaceInterceptor::addSurfaceDeletionLocked(Increment* increment,
  387. const sp<const Layer>& layer)
  388. {
  389. SurfaceDeletion* deletion(increment->mutable_surface_deletion());
  390. deletion->set_id(getLayerId(layer));
  391. }
  392. void SurfaceInterceptor::addBufferUpdateLocked(Increment* increment, const sp<const Layer>& layer,
  393. uint32_t width, uint32_t height, uint64_t frameNumber)
  394. {
  395. BufferUpdate* update(increment->mutable_buffer_update());
  396. update->set_id(getLayerId(layer));
  397. update->set_w(width);
  398. update->set_h(height);
  399. update->set_frame_number(frameNumber);
  400. }
  401. void SurfaceInterceptor::addVSyncUpdateLocked(Increment* increment, nsecs_t timestamp) {
  402. VSyncEvent* event(increment->mutable_vsync_event());
  403. event->set_when(timestamp);
  404. }
  405. void SurfaceInterceptor::addDisplaySurfaceLocked(Transaction* transaction, int32_t sequenceId,
  406. const sp<const IGraphicBufferProducer>& surface)
  407. {
  408. if (surface == nullptr) {
  409. return;
  410. }
  411. uint64_t bufferQueueId = 0;
  412. status_t err(surface->getUniqueId(&bufferQueueId));
  413. if (err == NO_ERROR) {
  414. DisplayChange* dispChange(createDisplayChangeLocked(transaction, sequenceId));
  415. DispSurfaceChange* surfaceChange(dispChange->mutable_surface());
  416. surfaceChange->set_buffer_queue_id(bufferQueueId);
  417. surfaceChange->set_buffer_queue_name(surface->getConsumerName().string());
  418. }
  419. else {
  420. ALOGE("invalid graphic buffer producer received while tracing a display change (%s)",
  421. strerror(-err));
  422. }
  423. }
  424. void SurfaceInterceptor::addDisplayLayerStackLocked(Transaction* transaction,
  425. int32_t sequenceId, uint32_t layerStack)
  426. {
  427. DisplayChange* dispChange(createDisplayChangeLocked(transaction, sequenceId));
  428. LayerStackChange* layerStackChange(dispChange->mutable_layer_stack());
  429. layerStackChange->set_layer_stack(layerStack);
  430. }
  431. void SurfaceInterceptor::addDisplaySizeLocked(Transaction* transaction, int32_t sequenceId,
  432. uint32_t w, uint32_t h)
  433. {
  434. DisplayChange* dispChange(createDisplayChangeLocked(transaction, sequenceId));
  435. SizeChange* sizeChange(dispChange->mutable_size());
  436. sizeChange->set_w(w);
  437. sizeChange->set_h(h);
  438. }
  439. void SurfaceInterceptor::addDisplayProjectionLocked(Transaction* transaction,
  440. int32_t sequenceId, int32_t orientation, const Rect& viewport, const Rect& frame)
  441. {
  442. DisplayChange* dispChange(createDisplayChangeLocked(transaction, sequenceId));
  443. ProjectionChange* projectionChange(dispChange->mutable_projection());
  444. projectionChange->set_orientation(orientation);
  445. Rectangle* viewportRect(projectionChange->mutable_viewport());
  446. setProtoRectLocked(viewportRect, viewport);
  447. Rectangle* frameRect(projectionChange->mutable_frame());
  448. setProtoRectLocked(frameRect, frame);
  449. }
  450. void SurfaceInterceptor::addDisplayCreationLocked(Increment* increment,
  451. const DisplayDeviceState& info)
  452. {
  453. DisplayCreation* creation(increment->mutable_display_creation());
  454. creation->set_id(info.sequenceId);
  455. creation->set_name(info.displayName);
  456. creation->set_is_secure(info.isSecure);
  457. if (info.displayId) {
  458. creation->set_display_id(info.displayId->value);
  459. }
  460. }
  461. void SurfaceInterceptor::addDisplayDeletionLocked(Increment* increment, int32_t sequenceId) {
  462. DisplayDeletion* deletion(increment->mutable_display_deletion());
  463. deletion->set_id(sequenceId);
  464. }
  465. void SurfaceInterceptor::addPowerModeUpdateLocked(Increment* increment, int32_t sequenceId,
  466. int32_t mode)
  467. {
  468. PowerModeUpdate* powerModeUpdate(increment->mutable_power_mode_update());
  469. powerModeUpdate->set_id(sequenceId);
  470. powerModeUpdate->set_mode(mode);
  471. }
  472. void SurfaceInterceptor::saveTransaction(const Vector<ComposerState>& stateUpdates,
  473. const DefaultKeyedVector< wp<IBinder>, DisplayDeviceState>& displays,
  474. const Vector<DisplayState>& changedDisplays, uint32_t flags)
  475. {
  476. if (!mEnabled || (stateUpdates.size() <= 0 && changedDisplays.size() <= 0)) {
  477. return;
  478. }
  479. ATRACE_CALL();
  480. std::lock_guard<std::mutex> protoGuard(mTraceMutex);
  481. addTransactionLocked(createTraceIncrementLocked(), stateUpdates, displays, changedDisplays,
  482. flags);
  483. }
  484. void SurfaceInterceptor::saveSurfaceCreation(const sp<const Layer>& layer) {
  485. if (!mEnabled || layer == nullptr) {
  486. return;
  487. }
  488. ATRACE_CALL();
  489. std::lock_guard<std::mutex> protoGuard(mTraceMutex);
  490. addSurfaceCreationLocked(createTraceIncrementLocked(), layer);
  491. }
  492. void SurfaceInterceptor::saveSurfaceDeletion(const sp<const Layer>& layer) {
  493. if (!mEnabled || layer == nullptr) {
  494. return;
  495. }
  496. ATRACE_CALL();
  497. std::lock_guard<std::mutex> protoGuard(mTraceMutex);
  498. addSurfaceDeletionLocked(createTraceIncrementLocked(), layer);
  499. }
  500. void SurfaceInterceptor::saveBufferUpdate(const sp<const Layer>& layer, uint32_t width,
  501. uint32_t height, uint64_t frameNumber)
  502. {
  503. if (!mEnabled || layer == nullptr) {
  504. return;
  505. }
  506. ATRACE_CALL();
  507. std::lock_guard<std::mutex> protoGuard(mTraceMutex);
  508. addBufferUpdateLocked(createTraceIncrementLocked(), layer, width, height, frameNumber);
  509. }
  510. void SurfaceInterceptor::saveVSyncEvent(nsecs_t timestamp) {
  511. if (!mEnabled) {
  512. return;
  513. }
  514. std::lock_guard<std::mutex> protoGuard(mTraceMutex);
  515. addVSyncUpdateLocked(createTraceIncrementLocked(), timestamp);
  516. }
  517. void SurfaceInterceptor::saveDisplayCreation(const DisplayDeviceState& info) {
  518. if (!mEnabled) {
  519. return;
  520. }
  521. ATRACE_CALL();
  522. std::lock_guard<std::mutex> protoGuard(mTraceMutex);
  523. addDisplayCreationLocked(createTraceIncrementLocked(), info);
  524. }
  525. void SurfaceInterceptor::saveDisplayDeletion(int32_t sequenceId) {
  526. if (!mEnabled) {
  527. return;
  528. }
  529. ATRACE_CALL();
  530. std::lock_guard<std::mutex> protoGuard(mTraceMutex);
  531. addDisplayDeletionLocked(createTraceIncrementLocked(), sequenceId);
  532. }
  533. void SurfaceInterceptor::savePowerModeUpdate(int32_t sequenceId, int32_t mode) {
  534. if (!mEnabled) {
  535. return;
  536. }
  537. ATRACE_CALL();
  538. std::lock_guard<std::mutex> protoGuard(mTraceMutex);
  539. addPowerModeUpdateLocked(createTraceIncrementLocked(), sequenceId, mode);
  540. }
  541. } // namespace impl
  542. } // namespace android