You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

surface_control.cpp 22KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539
  1. /*
  2. * Copyright 2018 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. #include <android/hardware/configstore/1.0/ISurfaceFlingerConfigs.h>
  17. #include <android/native_window.h>
  18. #include <android/surface_control.h>
  19. #include <configstore/Utils.h>
  20. #include <gui/HdrMetadata.h>
  21. #include <gui/ISurfaceComposer.h>
  22. #include <gui/Surface.h>
  23. #include <gui/SurfaceComposerClient.h>
  24. #include <gui/SurfaceControl.h>
  25. #include <ui/HdrCapabilities.h>
  26. #include <utils/Timers.h>
  27. using namespace android::hardware::configstore;
  28. using namespace android::hardware::configstore::V1_0;
  29. using namespace android;
  30. using android::hardware::configstore::V1_0::ISurfaceFlingerConfigs;
  31. using Transaction = SurfaceComposerClient::Transaction;
  32. #define CHECK_NOT_NULL(name) \
  33. LOG_ALWAYS_FATAL_IF(name == nullptr, "nullptr passed as " #name " argument");
  34. #define CHECK_VALID_RECT(name) \
  35. LOG_ALWAYS_FATAL_IF(!static_cast<const Rect&>(name).isValid(), \
  36. "invalid arg passed as " #name " argument");
  37. static bool getWideColorSupport(const sp<SurfaceControl>& surfaceControl) {
  38. sp<SurfaceComposerClient> client = surfaceControl->getClient();
  39. const sp<IBinder> display = client->getInternalDisplayToken();
  40. if (display == nullptr) {
  41. ALOGE("unable to get wide color support for disconnected internal display");
  42. return false;
  43. }
  44. bool isWideColorDisplay = false;
  45. status_t err = client->isWideColorDisplay(display, &isWideColorDisplay);
  46. if (err) {
  47. ALOGE("unable to get wide color support");
  48. return false;
  49. }
  50. return isWideColorDisplay;
  51. }
  52. static bool getHdrSupport(const sp<SurfaceControl>& surfaceControl) {
  53. sp<SurfaceComposerClient> client = surfaceControl->getClient();
  54. const sp<IBinder> display = client->getInternalDisplayToken();
  55. if (display == nullptr) {
  56. ALOGE("unable to get hdr capabilities for disconnected internal display");
  57. return false;
  58. }
  59. HdrCapabilities hdrCapabilities;
  60. status_t err = client->getHdrCapabilities(display, &hdrCapabilities);
  61. if (err) {
  62. ALOGE("unable to get hdr capabilities");
  63. return false;
  64. }
  65. return !hdrCapabilities.getSupportedHdrTypes().empty();
  66. }
  67. static bool isDataSpaceValid(const sp<SurfaceControl>& surfaceControl, ADataSpace dataSpace) {
  68. static_assert(static_cast<int>(ADATASPACE_UNKNOWN) == static_cast<int>(HAL_DATASPACE_UNKNOWN));
  69. static_assert(static_cast<int>(ADATASPACE_SCRGB_LINEAR) == static_cast<int>(HAL_DATASPACE_V0_SCRGB_LINEAR));
  70. static_assert(static_cast<int>(ADATASPACE_SRGB) == static_cast<int>(HAL_DATASPACE_V0_SRGB));
  71. static_assert(static_cast<int>(ADATASPACE_SCRGB) == static_cast<int>(HAL_DATASPACE_V0_SCRGB));
  72. static_assert(static_cast<int>(ADATASPACE_DISPLAY_P3) == static_cast<int>(HAL_DATASPACE_DISPLAY_P3));
  73. static_assert(static_cast<int>(ADATASPACE_BT2020_PQ) == static_cast<int>(HAL_DATASPACE_BT2020_PQ));
  74. switch (static_cast<android_dataspace_t>(dataSpace)) {
  75. case HAL_DATASPACE_UNKNOWN:
  76. case HAL_DATASPACE_V0_SRGB:
  77. return true;
  78. // These data space need wide gamut support.
  79. case HAL_DATASPACE_V0_SCRGB_LINEAR:
  80. case HAL_DATASPACE_V0_SCRGB:
  81. case HAL_DATASPACE_DISPLAY_P3:
  82. return getWideColorSupport(surfaceControl);
  83. // These data space need HDR support.
  84. case HAL_DATASPACE_BT2020_PQ:
  85. return getHdrSupport(surfaceControl);
  86. default:
  87. return false;
  88. }
  89. }
  90. Transaction* ASurfaceTransaction_to_Transaction(ASurfaceTransaction* aSurfaceTransaction) {
  91. return reinterpret_cast<Transaction*>(aSurfaceTransaction);
  92. }
  93. SurfaceControl* ASurfaceControl_to_SurfaceControl(ASurfaceControl* aSurfaceControl) {
  94. return reinterpret_cast<SurfaceControl*>(aSurfaceControl);
  95. }
  96. void SurfaceControl_acquire(SurfaceControl* surfaceControl) {
  97. // incStrong/decStrong token must be the same, doesn't matter what it is
  98. surfaceControl->incStrong((void*)SurfaceControl_acquire);
  99. }
  100. void SurfaceControl_release(SurfaceControl* surfaceControl) {
  101. // incStrong/decStrong token must be the same, doesn't matter what it is
  102. surfaceControl->decStrong((void*)SurfaceControl_acquire);
  103. }
  104. ASurfaceControl* ASurfaceControl_createFromWindow(ANativeWindow* window, const char* debug_name) {
  105. CHECK_NOT_NULL(window);
  106. CHECK_NOT_NULL(debug_name);
  107. sp<SurfaceComposerClient> client = new SurfaceComposerClient();
  108. if (client->initCheck() != NO_ERROR) {
  109. return nullptr;
  110. }
  111. uint32_t flags = ISurfaceComposerClient::eFXSurfaceBufferState;
  112. sp<SurfaceControl> surfaceControl =
  113. client->createWithSurfaceParent(String8(debug_name), 0 /* width */, 0 /* height */,
  114. // Format is only relevant for buffer queue layers.
  115. PIXEL_FORMAT_UNKNOWN /* format */, flags,
  116. static_cast<Surface*>(window));
  117. if (!surfaceControl) {
  118. return nullptr;
  119. }
  120. SurfaceControl_acquire(surfaceControl.get());
  121. return reinterpret_cast<ASurfaceControl*>(surfaceControl.get());
  122. }
  123. ASurfaceControl* ASurfaceControl_create(ASurfaceControl* parent, const char* debug_name) {
  124. CHECK_NOT_NULL(parent);
  125. CHECK_NOT_NULL(debug_name);
  126. SurfaceComposerClient* client = ASurfaceControl_to_SurfaceControl(parent)->getClient().get();
  127. SurfaceControl* surfaceControlParent = ASurfaceControl_to_SurfaceControl(parent);
  128. uint32_t flags = ISurfaceComposerClient::eFXSurfaceBufferState;
  129. sp<SurfaceControl> surfaceControl =
  130. client->createSurface(String8(debug_name), 0 /* width */, 0 /* height */,
  131. // Format is only relevant for buffer queue layers.
  132. PIXEL_FORMAT_UNKNOWN /* format */, flags,
  133. surfaceControlParent);
  134. if (!surfaceControl) {
  135. return nullptr;
  136. }
  137. SurfaceControl_acquire(surfaceControl.get());
  138. return reinterpret_cast<ASurfaceControl*>(surfaceControl.get());
  139. }
  140. void ASurfaceControl_release(ASurfaceControl* aSurfaceControl) {
  141. sp<SurfaceControl> surfaceControl = ASurfaceControl_to_SurfaceControl(aSurfaceControl);
  142. SurfaceControl_release(surfaceControl.get());
  143. }
  144. ASurfaceTransaction* ASurfaceTransaction_create() {
  145. Transaction* transaction = new Transaction;
  146. return reinterpret_cast<ASurfaceTransaction*>(transaction);
  147. }
  148. void ASurfaceTransaction_delete(ASurfaceTransaction* aSurfaceTransaction) {
  149. Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction);
  150. delete transaction;
  151. }
  152. void ASurfaceTransaction_apply(ASurfaceTransaction* aSurfaceTransaction) {
  153. CHECK_NOT_NULL(aSurfaceTransaction);
  154. Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction);
  155. transaction->apply();
  156. }
  157. typedef struct ASurfaceControlStats {
  158. int64_t acquireTime;
  159. sp<Fence> previousReleaseFence;
  160. } ASurfaceControlStats;
  161. struct ASurfaceTransactionStats {
  162. std::unordered_map<ASurfaceControl*, ASurfaceControlStats> aSurfaceControlStats;
  163. int64_t latchTime;
  164. sp<Fence> presentFence;
  165. };
  166. int64_t ASurfaceTransactionStats_getLatchTime(ASurfaceTransactionStats* aSurfaceTransactionStats) {
  167. CHECK_NOT_NULL(aSurfaceTransactionStats);
  168. return aSurfaceTransactionStats->latchTime;
  169. }
  170. int ASurfaceTransactionStats_getPresentFenceFd(ASurfaceTransactionStats* aSurfaceTransactionStats) {
  171. CHECK_NOT_NULL(aSurfaceTransactionStats);
  172. auto& presentFence = aSurfaceTransactionStats->presentFence;
  173. return (presentFence) ? presentFence->dup() : -1;
  174. }
  175. void ASurfaceTransactionStats_getASurfaceControls(ASurfaceTransactionStats* aSurfaceTransactionStats,
  176. ASurfaceControl*** outASurfaceControls,
  177. size_t* outASurfaceControlsSize) {
  178. CHECK_NOT_NULL(aSurfaceTransactionStats);
  179. CHECK_NOT_NULL(outASurfaceControls);
  180. CHECK_NOT_NULL(outASurfaceControlsSize);
  181. size_t size = aSurfaceTransactionStats->aSurfaceControlStats.size();
  182. SurfaceControl** surfaceControls = new SurfaceControl*[size];
  183. ASurfaceControl** aSurfaceControls = reinterpret_cast<ASurfaceControl**>(surfaceControls);
  184. size_t i = 0;
  185. for (auto& [aSurfaceControl, aSurfaceControlStats] : aSurfaceTransactionStats->aSurfaceControlStats) {
  186. aSurfaceControls[i] = aSurfaceControl;
  187. i++;
  188. }
  189. *outASurfaceControls = aSurfaceControls;
  190. *outASurfaceControlsSize = size;
  191. }
  192. int64_t ASurfaceTransactionStats_getAcquireTime(ASurfaceTransactionStats* aSurfaceTransactionStats,
  193. ASurfaceControl* aSurfaceControl) {
  194. CHECK_NOT_NULL(aSurfaceTransactionStats);
  195. CHECK_NOT_NULL(aSurfaceControl);
  196. const auto& aSurfaceControlStats =
  197. aSurfaceTransactionStats->aSurfaceControlStats.find(aSurfaceControl);
  198. LOG_ALWAYS_FATAL_IF(
  199. aSurfaceControlStats == aSurfaceTransactionStats->aSurfaceControlStats.end(),
  200. "ASurfaceControl not found");
  201. return aSurfaceControlStats->second.acquireTime;
  202. }
  203. int ASurfaceTransactionStats_getPreviousReleaseFenceFd(
  204. ASurfaceTransactionStats* aSurfaceTransactionStats, ASurfaceControl* aSurfaceControl) {
  205. CHECK_NOT_NULL(aSurfaceTransactionStats);
  206. CHECK_NOT_NULL(aSurfaceControl);
  207. const auto& aSurfaceControlStats =
  208. aSurfaceTransactionStats->aSurfaceControlStats.find(aSurfaceControl);
  209. LOG_ALWAYS_FATAL_IF(
  210. aSurfaceControlStats == aSurfaceTransactionStats->aSurfaceControlStats.end(),
  211. "ASurfaceControl not found");
  212. auto& previousReleaseFence = aSurfaceControlStats->second.previousReleaseFence;
  213. return (previousReleaseFence) ? previousReleaseFence->dup() : -1;
  214. }
  215. void ASurfaceTransactionStats_releaseASurfaceControls(ASurfaceControl** aSurfaceControls) {
  216. CHECK_NOT_NULL(aSurfaceControls);
  217. SurfaceControl** surfaceControls = reinterpret_cast<SurfaceControl**>(aSurfaceControls);
  218. delete[] surfaceControls;
  219. }
  220. void ASurfaceTransaction_setOnComplete(ASurfaceTransaction* aSurfaceTransaction, void* context,
  221. ASurfaceTransaction_OnComplete func) {
  222. CHECK_NOT_NULL(aSurfaceTransaction);
  223. CHECK_NOT_NULL(context);
  224. CHECK_NOT_NULL(func);
  225. TransactionCompletedCallbackTakesContext callback = [func](void* callback_context,
  226. nsecs_t latchTime,
  227. const sp<Fence>& presentFence,
  228. const std::vector<SurfaceControlStats>& surfaceControlStats) {
  229. ASurfaceTransactionStats aSurfaceTransactionStats;
  230. aSurfaceTransactionStats.latchTime = latchTime;
  231. aSurfaceTransactionStats.presentFence = presentFence;
  232. auto& aSurfaceControlStats = aSurfaceTransactionStats.aSurfaceControlStats;
  233. for (const auto& [surfaceControl, acquireTime, previousReleaseFence] : surfaceControlStats) {
  234. ASurfaceControl* aSurfaceControl = reinterpret_cast<ASurfaceControl*>(surfaceControl.get());
  235. aSurfaceControlStats[aSurfaceControl].acquireTime = acquireTime;
  236. aSurfaceControlStats[aSurfaceControl].previousReleaseFence = previousReleaseFence;
  237. }
  238. (*func)(callback_context, &aSurfaceTransactionStats);
  239. };
  240. Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction);
  241. transaction->addTransactionCompletedCallback(callback, context);
  242. }
  243. void ASurfaceTransaction_reparent(ASurfaceTransaction* aSurfaceTransaction,
  244. ASurfaceControl* aSurfaceControl,
  245. ASurfaceControl* newParentASurfaceControl) {
  246. CHECK_NOT_NULL(aSurfaceTransaction);
  247. CHECK_NOT_NULL(aSurfaceControl);
  248. sp<SurfaceControl> surfaceControl = ASurfaceControl_to_SurfaceControl(aSurfaceControl);
  249. sp<SurfaceControl> newParentSurfaceControl = ASurfaceControl_to_SurfaceControl(
  250. newParentASurfaceControl);
  251. sp<IBinder> newParentHandle = (newParentSurfaceControl)? newParentSurfaceControl->getHandle() : nullptr;
  252. Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction);
  253. transaction->reparent(surfaceControl, newParentHandle);
  254. }
  255. void ASurfaceTransaction_setVisibility(ASurfaceTransaction* aSurfaceTransaction,
  256. ASurfaceControl* aSurfaceControl,
  257. int8_t visibility) {
  258. CHECK_NOT_NULL(aSurfaceTransaction);
  259. CHECK_NOT_NULL(aSurfaceControl);
  260. sp<SurfaceControl> surfaceControl = ASurfaceControl_to_SurfaceControl(aSurfaceControl);
  261. Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction);
  262. switch (visibility) {
  263. case ASURFACE_TRANSACTION_VISIBILITY_SHOW:
  264. transaction->show(surfaceControl);
  265. break;
  266. case ASURFACE_TRANSACTION_VISIBILITY_HIDE:
  267. transaction->hide(surfaceControl);
  268. break;
  269. default:
  270. LOG_ALWAYS_FATAL("invalid visibility %d", visibility);
  271. }
  272. }
  273. void ASurfaceTransaction_setZOrder(ASurfaceTransaction* aSurfaceTransaction,
  274. ASurfaceControl* aSurfaceControl,
  275. int32_t z_order) {
  276. CHECK_NOT_NULL(aSurfaceTransaction);
  277. CHECK_NOT_NULL(aSurfaceControl);
  278. sp<SurfaceControl> surfaceControl = ASurfaceControl_to_SurfaceControl(aSurfaceControl);
  279. Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction);
  280. transaction->setLayer(surfaceControl, z_order);
  281. }
  282. void ASurfaceTransaction_setBuffer(ASurfaceTransaction* aSurfaceTransaction,
  283. ASurfaceControl* aSurfaceControl,
  284. AHardwareBuffer* buffer, int acquire_fence_fd) {
  285. CHECK_NOT_NULL(aSurfaceTransaction);
  286. CHECK_NOT_NULL(aSurfaceControl);
  287. sp<SurfaceControl> surfaceControl = ASurfaceControl_to_SurfaceControl(aSurfaceControl);
  288. Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction);
  289. sp<GraphicBuffer> graphic_buffer(reinterpret_cast<GraphicBuffer*>(buffer));
  290. transaction->setBuffer(surfaceControl, graphic_buffer);
  291. if (acquire_fence_fd != -1) {
  292. sp<Fence> fence = new Fence(acquire_fence_fd);
  293. transaction->setAcquireFence(surfaceControl, fence);
  294. }
  295. }
  296. void ASurfaceTransaction_setGeometry(ASurfaceTransaction* aSurfaceTransaction,
  297. ASurfaceControl* aSurfaceControl, const ARect& source,
  298. const ARect& destination, int32_t transform) {
  299. CHECK_NOT_NULL(aSurfaceTransaction);
  300. CHECK_NOT_NULL(aSurfaceControl);
  301. CHECK_VALID_RECT(source);
  302. CHECK_VALID_RECT(destination);
  303. sp<SurfaceControl> surfaceControl = ASurfaceControl_to_SurfaceControl(aSurfaceControl);
  304. Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction);
  305. transaction->setCrop(surfaceControl, static_cast<const Rect&>(source));
  306. transaction->setFrame(surfaceControl, static_cast<const Rect&>(destination));
  307. transaction->setTransform(surfaceControl, transform);
  308. bool transformToInverseDisplay = (NATIVE_WINDOW_TRANSFORM_INVERSE_DISPLAY & transform) ==
  309. NATIVE_WINDOW_TRANSFORM_INVERSE_DISPLAY;
  310. transaction->setTransformToDisplayInverse(surfaceControl, transformToInverseDisplay);
  311. }
  312. void ASurfaceTransaction_setBufferTransparency(ASurfaceTransaction* aSurfaceTransaction,
  313. ASurfaceControl* aSurfaceControl,
  314. int8_t transparency) {
  315. CHECK_NOT_NULL(aSurfaceTransaction);
  316. CHECK_NOT_NULL(aSurfaceControl);
  317. sp<SurfaceControl> surfaceControl = ASurfaceControl_to_SurfaceControl(aSurfaceControl);
  318. Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction);
  319. uint32_t flags = (transparency == ASURFACE_TRANSACTION_TRANSPARENCY_OPAQUE) ?
  320. layer_state_t::eLayerOpaque : 0;
  321. transaction->setFlags(surfaceControl, flags, layer_state_t::eLayerOpaque);
  322. }
  323. void ASurfaceTransaction_setDamageRegion(ASurfaceTransaction* aSurfaceTransaction,
  324. ASurfaceControl* aSurfaceControl,
  325. const ARect rects[], uint32_t count) {
  326. CHECK_NOT_NULL(aSurfaceTransaction);
  327. CHECK_NOT_NULL(aSurfaceControl);
  328. sp<SurfaceControl> surfaceControl = ASurfaceControl_to_SurfaceControl(aSurfaceControl);
  329. Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction);
  330. Region region;
  331. for (uint32_t i = 0; i < count; ++i) {
  332. region.orSelf(static_cast<const Rect&>(rects[i]));
  333. }
  334. // Hardware composer interprets a DamageRegion with a single Rect of {0,0,0,0} to be an
  335. // undamaged region and {0,0,-1,-1} to be a fully damaged buffer. This is a confusing
  336. // distinction for a public api. Instead, default both cases to be a fully damaged buffer.
  337. if (count == 1 && region.getBounds().isEmpty()) {
  338. transaction->setSurfaceDamageRegion(surfaceControl, Region::INVALID_REGION);
  339. return;
  340. }
  341. transaction->setSurfaceDamageRegion(surfaceControl, region);
  342. }
  343. void ASurfaceTransaction_setDesiredPresentTime(ASurfaceTransaction* aSurfaceTransaction,
  344. int64_t desiredPresentTime) {
  345. CHECK_NOT_NULL(aSurfaceTransaction);
  346. Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction);
  347. transaction->setDesiredPresentTime(static_cast<nsecs_t>(desiredPresentTime));
  348. }
  349. void ASurfaceTransaction_setBufferAlpha(ASurfaceTransaction* aSurfaceTransaction,
  350. ASurfaceControl* aSurfaceControl,
  351. float alpha) {
  352. CHECK_NOT_NULL(aSurfaceTransaction);
  353. CHECK_NOT_NULL(aSurfaceControl);
  354. LOG_ALWAYS_FATAL_IF(alpha < 0.0 || alpha > 1.0, "invalid alpha");
  355. sp<SurfaceControl> surfaceControl = ASurfaceControl_to_SurfaceControl(aSurfaceControl);
  356. Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction);
  357. transaction->setAlpha(surfaceControl, alpha);
  358. }
  359. void ASurfaceTransaction_setBufferDataSpace(ASurfaceTransaction* aSurfaceTransaction,
  360. ASurfaceControl* aSurfaceControl,
  361. ADataSpace aDataSpace) {
  362. CHECK_NOT_NULL(aSurfaceTransaction);
  363. CHECK_NOT_NULL(aSurfaceControl);
  364. sp<SurfaceControl> surfaceControl = ASurfaceControl_to_SurfaceControl(aSurfaceControl);
  365. LOG_ALWAYS_FATAL_IF(!isDataSpaceValid(surfaceControl, aDataSpace), "invalid dataspace");
  366. Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction);
  367. transaction->setDataspace(surfaceControl, static_cast<ui::Dataspace>(aDataSpace));
  368. }
  369. void ASurfaceTransaction_setHdrMetadata_smpte2086(ASurfaceTransaction* aSurfaceTransaction,
  370. ASurfaceControl* aSurfaceControl,
  371. struct AHdrMetadata_smpte2086* metadata) {
  372. CHECK_NOT_NULL(aSurfaceTransaction);
  373. CHECK_NOT_NULL(aSurfaceControl);
  374. sp<SurfaceControl> surfaceControl = ASurfaceControl_to_SurfaceControl(aSurfaceControl);
  375. Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction);
  376. HdrMetadata hdrMetadata;
  377. if (metadata) {
  378. hdrMetadata.smpte2086.displayPrimaryRed.x = metadata->displayPrimaryRed.x;
  379. hdrMetadata.smpte2086.displayPrimaryRed.y = metadata->displayPrimaryRed.y;
  380. hdrMetadata.smpte2086.displayPrimaryGreen.x = metadata->displayPrimaryGreen.x;
  381. hdrMetadata.smpte2086.displayPrimaryGreen.y = metadata->displayPrimaryGreen.y;
  382. hdrMetadata.smpte2086.displayPrimaryBlue.x = metadata->displayPrimaryBlue.x;
  383. hdrMetadata.smpte2086.displayPrimaryBlue.y = metadata->displayPrimaryBlue.y;
  384. hdrMetadata.smpte2086.whitePoint.x = metadata->whitePoint.x;
  385. hdrMetadata.smpte2086.whitePoint.y = metadata->whitePoint.y;
  386. hdrMetadata.smpte2086.minLuminance = metadata->minLuminance;
  387. hdrMetadata.smpte2086.maxLuminance = metadata->maxLuminance;
  388. hdrMetadata.validTypes |= HdrMetadata::SMPTE2086;
  389. } else {
  390. hdrMetadata.validTypes &= ~HdrMetadata::SMPTE2086;
  391. }
  392. transaction->setHdrMetadata(surfaceControl, hdrMetadata);
  393. }
  394. void ASurfaceTransaction_setHdrMetadata_cta861_3(ASurfaceTransaction* aSurfaceTransaction,
  395. ASurfaceControl* aSurfaceControl,
  396. struct AHdrMetadata_cta861_3* metadata) {
  397. CHECK_NOT_NULL(aSurfaceTransaction);
  398. CHECK_NOT_NULL(aSurfaceControl);
  399. sp<SurfaceControl> surfaceControl = ASurfaceControl_to_SurfaceControl(aSurfaceControl);
  400. Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction);
  401. HdrMetadata hdrMetadata;
  402. if (metadata) {
  403. hdrMetadata.cta8613.maxContentLightLevel = metadata->maxContentLightLevel;
  404. hdrMetadata.cta8613.maxFrameAverageLightLevel = metadata->maxFrameAverageLightLevel;
  405. hdrMetadata.validTypes |= HdrMetadata::CTA861_3;
  406. } else {
  407. hdrMetadata.validTypes &= ~HdrMetadata::CTA861_3;
  408. }
  409. transaction->setHdrMetadata(surfaceControl, hdrMetadata);
  410. }
  411. void ASurfaceTransaction_setColor(ASurfaceTransaction* aSurfaceTransaction,
  412. ASurfaceControl* aSurfaceControl,
  413. float r, float g, float b, float alpha,
  414. ADataSpace dataspace) {
  415. CHECK_NOT_NULL(aSurfaceTransaction);
  416. CHECK_NOT_NULL(aSurfaceControl);
  417. sp<SurfaceControl> surfaceControl = ASurfaceControl_to_SurfaceControl(aSurfaceControl);
  418. LOG_ALWAYS_FATAL_IF(!isDataSpaceValid(surfaceControl, dataspace), "invalid dataspace");
  419. Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction);
  420. half3 color;
  421. color.r = r;
  422. color.g = g;
  423. color.b = b;
  424. transaction->setBackgroundColor(surfaceControl, color, alpha, static_cast<ui::Dataspace>(dataspace));
  425. }