ComposerHal.cpp 46 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471
  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 "HwcComposer"
  18. #include <inttypes.h>
  19. #include <log/log.h>
  20. #include "ComposerHal.h"
  21. #include <composer-command-buffer/2.2/ComposerCommandBuffer.h>
  22. #include <gui/BufferQueue.h>
  23. #include <hidl/HidlTransportSupport.h>
  24. #include <hidl/HidlTransportUtils.h>
  25. namespace android {
  26. using hardware::Return;
  27. using hardware::hidl_vec;
  28. using hardware::hidl_handle;
  29. namespace Hwc2 {
  30. Composer::~Composer() = default;
  31. namespace {
  32. class BufferHandle {
  33. public:
  34. explicit BufferHandle(const native_handle_t* buffer) {
  35. // nullptr is not a valid handle to HIDL
  36. mHandle = (buffer) ? buffer : native_handle_init(mStorage, 0, 0);
  37. }
  38. operator const hidl_handle&() const // NOLINT(google-explicit-constructor)
  39. {
  40. return mHandle;
  41. }
  42. private:
  43. NATIVE_HANDLE_DECLARE_STORAGE(mStorage, 0, 0);
  44. hidl_handle mHandle;
  45. };
  46. class FenceHandle
  47. {
  48. public:
  49. FenceHandle(int fd, bool owned)
  50. : mOwned(owned)
  51. {
  52. native_handle_t* handle;
  53. if (fd >= 0) {
  54. handle = native_handle_init(mStorage, 1, 0);
  55. handle->data[0] = fd;
  56. } else {
  57. // nullptr is not a valid handle to HIDL
  58. handle = native_handle_init(mStorage, 0, 0);
  59. }
  60. mHandle = handle;
  61. }
  62. ~FenceHandle()
  63. {
  64. if (mOwned) {
  65. native_handle_close(mHandle);
  66. }
  67. }
  68. operator const hidl_handle&() const // NOLINT(google-explicit-constructor)
  69. {
  70. return mHandle;
  71. }
  72. private:
  73. bool mOwned;
  74. NATIVE_HANDLE_DECLARE_STORAGE(mStorage, 1, 0);
  75. hidl_handle mHandle;
  76. };
  77. // assume NO_RESOURCES when Status::isOk returns false
  78. constexpr Error kDefaultError = Error::NO_RESOURCES;
  79. template<typename T, typename U>
  80. T unwrapRet(Return<T>& ret, const U& default_val)
  81. {
  82. return (ret.isOk()) ? static_cast<T>(ret) :
  83. static_cast<T>(default_val);
  84. }
  85. Error unwrapRet(Return<Error>& ret)
  86. {
  87. return unwrapRet(ret, kDefaultError);
  88. }
  89. } // anonymous namespace
  90. namespace impl {
  91. Composer::CommandWriter::CommandWriter(uint32_t initialMaxSize)
  92. : CommandWriterBase(initialMaxSize) {}
  93. Composer::CommandWriter::~CommandWriter()
  94. {
  95. }
  96. void Composer::CommandWriter::setLayerInfo(uint32_t type, uint32_t appId)
  97. {
  98. constexpr uint16_t kSetLayerInfoLength = 2;
  99. beginCommand(static_cast<V2_1::IComposerClient::Command>(
  100. IVrComposerClient::VrCommand::SET_LAYER_INFO),
  101. kSetLayerInfoLength);
  102. write(type);
  103. write(appId);
  104. endCommand();
  105. }
  106. void Composer::CommandWriter::setClientTargetMetadata(
  107. const IVrComposerClient::BufferMetadata& metadata)
  108. {
  109. constexpr uint16_t kSetClientTargetMetadataLength = 7;
  110. beginCommand(static_cast<V2_1::IComposerClient::Command>(
  111. IVrComposerClient::VrCommand::SET_CLIENT_TARGET_METADATA),
  112. kSetClientTargetMetadataLength);
  113. writeBufferMetadata(metadata);
  114. endCommand();
  115. }
  116. void Composer::CommandWriter::setLayerBufferMetadata(
  117. const IVrComposerClient::BufferMetadata& metadata)
  118. {
  119. constexpr uint16_t kSetLayerBufferMetadataLength = 7;
  120. beginCommand(static_cast<V2_1::IComposerClient::Command>(
  121. IVrComposerClient::VrCommand::SET_LAYER_BUFFER_METADATA),
  122. kSetLayerBufferMetadataLength);
  123. writeBufferMetadata(metadata);
  124. endCommand();
  125. }
  126. void Composer::CommandWriter::writeBufferMetadata(
  127. const IVrComposerClient::BufferMetadata& metadata)
  128. {
  129. write(metadata.width);
  130. write(metadata.height);
  131. write(metadata.stride);
  132. write(metadata.layerCount);
  133. writeSigned(static_cast<int32_t>(metadata.format));
  134. write64(metadata.usage);
  135. }
  136. Composer::Composer(const std::string& serviceName)
  137. : mWriter(kWriterInitialSize),
  138. mIsUsingVrComposer(serviceName == std::string("vr"))
  139. {
  140. mComposer = V2_1::IComposer::getService(serviceName);
  141. if (mComposer == nullptr) {
  142. LOG_ALWAYS_FATAL("failed to get hwcomposer service");
  143. }
  144. if (sp<IComposer> composer_2_3 = IComposer::castFrom(mComposer)) {
  145. composer_2_3->createClient_2_3([&](const auto& tmpError, const auto& tmpClient) {
  146. if (tmpError == Error::NONE) {
  147. mClient = tmpClient;
  148. mClient_2_2 = tmpClient;
  149. mClient_2_3 = tmpClient;
  150. }
  151. });
  152. } else {
  153. mComposer->createClient([&](const auto& tmpError, const auto& tmpClient) {
  154. if (tmpError != Error::NONE) {
  155. return;
  156. }
  157. mClient = tmpClient;
  158. if (sp<V2_2::IComposer> composer_2_2 = V2_2::IComposer::castFrom(mComposer)) {
  159. mClient_2_2 = V2_2::IComposerClient::castFrom(mClient);
  160. LOG_ALWAYS_FATAL_IF(mClient_2_2 == nullptr,
  161. "IComposer 2.2 did not return IComposerClient 2.2");
  162. }
  163. });
  164. }
  165. if (mClient == nullptr) {
  166. LOG_ALWAYS_FATAL("failed to create composer client");
  167. }
  168. if (mIsUsingVrComposer) {
  169. sp<IVrComposerClient> vrClient = IVrComposerClient::castFrom(mClient);
  170. if (vrClient == nullptr) {
  171. LOG_ALWAYS_FATAL("failed to create vr composer client");
  172. }
  173. }
  174. }
  175. Composer::~Composer() = default;
  176. std::vector<IComposer::Capability> Composer::getCapabilities()
  177. {
  178. std::vector<IComposer::Capability> capabilities;
  179. mComposer->getCapabilities(
  180. [&](const auto& tmpCapabilities) {
  181. capabilities = tmpCapabilities;
  182. });
  183. return capabilities;
  184. }
  185. std::string Composer::dumpDebugInfo()
  186. {
  187. std::string info;
  188. mComposer->dumpDebugInfo([&](const auto& tmpInfo) {
  189. info = tmpInfo.c_str();
  190. });
  191. return info;
  192. }
  193. void Composer::registerCallback(const sp<IComposerCallback>& callback)
  194. {
  195. android::hardware::setMinSchedulerPolicy(callback, SCHED_FIFO, 2);
  196. auto ret = mClient->registerCallback(callback);
  197. if (!ret.isOk()) {
  198. ALOGE("failed to register IComposerCallback");
  199. }
  200. }
  201. bool Composer::isRemote() {
  202. return mClient->isRemote();
  203. }
  204. void Composer::resetCommands() {
  205. mWriter.reset();
  206. }
  207. Error Composer::executeCommands() {
  208. return execute();
  209. }
  210. uint32_t Composer::getMaxVirtualDisplayCount()
  211. {
  212. auto ret = mClient->getMaxVirtualDisplayCount();
  213. return unwrapRet(ret, 0);
  214. }
  215. Error Composer::createVirtualDisplay(uint32_t width, uint32_t height,
  216. PixelFormat* format, Display* outDisplay)
  217. {
  218. const uint32_t bufferSlotCount = 1;
  219. Error error = kDefaultError;
  220. if (mClient_2_2) {
  221. mClient_2_2->createVirtualDisplay_2_2(width, height,
  222. static_cast<types::V1_1::PixelFormat>(*format),
  223. bufferSlotCount,
  224. [&](const auto& tmpError, const auto& tmpDisplay,
  225. const auto& tmpFormat) {
  226. error = tmpError;
  227. if (error != Error::NONE) {
  228. return;
  229. }
  230. *outDisplay = tmpDisplay;
  231. *format = static_cast<types::V1_2::PixelFormat>(
  232. tmpFormat);
  233. });
  234. } else {
  235. mClient->createVirtualDisplay(width, height,
  236. static_cast<types::V1_0::PixelFormat>(*format), bufferSlotCount,
  237. [&](const auto& tmpError, const auto& tmpDisplay,
  238. const auto& tmpFormat) {
  239. error = tmpError;
  240. if (error != Error::NONE) {
  241. return;
  242. }
  243. *outDisplay = tmpDisplay;
  244. *format = static_cast<PixelFormat>(tmpFormat);
  245. });
  246. }
  247. return error;
  248. }
  249. Error Composer::destroyVirtualDisplay(Display display)
  250. {
  251. auto ret = mClient->destroyVirtualDisplay(display);
  252. return unwrapRet(ret);
  253. }
  254. Error Composer::acceptDisplayChanges(Display display)
  255. {
  256. mWriter.selectDisplay(display);
  257. mWriter.acceptDisplayChanges();
  258. return Error::NONE;
  259. }
  260. Error Composer::createLayer(Display display, Layer* outLayer)
  261. {
  262. Error error = kDefaultError;
  263. mClient->createLayer(display, BufferQueue::NUM_BUFFER_SLOTS,
  264. [&](const auto& tmpError, const auto& tmpLayer) {
  265. error = tmpError;
  266. if (error != Error::NONE) {
  267. return;
  268. }
  269. *outLayer = tmpLayer;
  270. });
  271. return error;
  272. }
  273. Error Composer::destroyLayer(Display display, Layer layer)
  274. {
  275. auto ret = mClient->destroyLayer(display, layer);
  276. return unwrapRet(ret);
  277. }
  278. Error Composer::getActiveConfig(Display display, Config* outConfig)
  279. {
  280. Error error = kDefaultError;
  281. mClient->getActiveConfig(display,
  282. [&](const auto& tmpError, const auto& tmpConfig) {
  283. error = tmpError;
  284. if (error != Error::NONE) {
  285. return;
  286. }
  287. *outConfig = tmpConfig;
  288. });
  289. return error;
  290. }
  291. Error Composer::getChangedCompositionTypes(Display display,
  292. std::vector<Layer>* outLayers,
  293. std::vector<IComposerClient::Composition>* outTypes)
  294. {
  295. mReader.takeChangedCompositionTypes(display, outLayers, outTypes);
  296. return Error::NONE;
  297. }
  298. Error Composer::getColorModes(Display display,
  299. std::vector<ColorMode>* outModes)
  300. {
  301. Error error = kDefaultError;
  302. if (mClient_2_3) {
  303. mClient_2_3->getColorModes_2_3(display, [&](const auto& tmpError, const auto& tmpModes) {
  304. error = tmpError;
  305. if (error != Error::NONE) {
  306. return;
  307. }
  308. *outModes = tmpModes;
  309. });
  310. } else if (mClient_2_2) {
  311. mClient_2_2->getColorModes_2_2(display, [&](const auto& tmpError, const auto& tmpModes) {
  312. error = tmpError;
  313. if (error != Error::NONE) {
  314. return;
  315. }
  316. for (types::V1_1::ColorMode colorMode : tmpModes) {
  317. outModes->push_back(static_cast<ColorMode>(colorMode));
  318. }
  319. });
  320. } else {
  321. mClient->getColorModes(display,
  322. [&](const auto& tmpError, const auto& tmpModes) {
  323. error = tmpError;
  324. if (error != Error::NONE) {
  325. return;
  326. }
  327. for (types::V1_0::ColorMode colorMode : tmpModes) {
  328. outModes->push_back(static_cast<ColorMode>(colorMode));
  329. }
  330. });
  331. }
  332. return error;
  333. }
  334. Error Composer::getDisplayAttribute(Display display, Config config,
  335. IComposerClient::Attribute attribute, int32_t* outValue)
  336. {
  337. Error error = kDefaultError;
  338. mClient->getDisplayAttribute(display, config, attribute,
  339. [&](const auto& tmpError, const auto& tmpValue) {
  340. error = tmpError;
  341. if (error != Error::NONE) {
  342. return;
  343. }
  344. *outValue = tmpValue;
  345. });
  346. return error;
  347. }
  348. Error Composer::getDisplayConfigs(Display display,
  349. std::vector<Config>* outConfigs)
  350. {
  351. Error error = kDefaultError;
  352. mClient->getDisplayConfigs(display,
  353. [&](const auto& tmpError, const auto& tmpConfigs) {
  354. error = tmpError;
  355. if (error != Error::NONE) {
  356. return;
  357. }
  358. *outConfigs = tmpConfigs;
  359. });
  360. return error;
  361. }
  362. Error Composer::getDisplayName(Display display, std::string* outName)
  363. {
  364. Error error = kDefaultError;
  365. mClient->getDisplayName(display,
  366. [&](const auto& tmpError, const auto& tmpName) {
  367. error = tmpError;
  368. if (error != Error::NONE) {
  369. return;
  370. }
  371. *outName = tmpName.c_str();
  372. });
  373. return error;
  374. }
  375. Error Composer::getDisplayRequests(Display display,
  376. uint32_t* outDisplayRequestMask, std::vector<Layer>* outLayers,
  377. std::vector<uint32_t>* outLayerRequestMasks)
  378. {
  379. mReader.takeDisplayRequests(display, outDisplayRequestMask,
  380. outLayers, outLayerRequestMasks);
  381. return Error::NONE;
  382. }
  383. Error Composer::getDisplayType(Display display,
  384. IComposerClient::DisplayType* outType)
  385. {
  386. Error error = kDefaultError;
  387. mClient->getDisplayType(display,
  388. [&](const auto& tmpError, const auto& tmpType) {
  389. error = tmpError;
  390. if (error != Error::NONE) {
  391. return;
  392. }
  393. *outType = tmpType;
  394. });
  395. return error;
  396. }
  397. Error Composer::getDozeSupport(Display display, bool* outSupport)
  398. {
  399. Error error = kDefaultError;
  400. mClient->getDozeSupport(display,
  401. [&](const auto& tmpError, const auto& tmpSupport) {
  402. error = tmpError;
  403. if (error != Error::NONE) {
  404. return;
  405. }
  406. *outSupport = tmpSupport;
  407. });
  408. return error;
  409. }
  410. Error Composer::getHdrCapabilities(Display display,
  411. std::vector<Hdr>* outTypes, float* outMaxLuminance,
  412. float* outMaxAverageLuminance, float* outMinLuminance)
  413. {
  414. Error error = kDefaultError;
  415. if (mClient_2_3) {
  416. mClient_2_3->getHdrCapabilities_2_3(display,
  417. [&](const auto& tmpError, const auto& tmpTypes,
  418. const auto& tmpMaxLuminance,
  419. const auto& tmpMaxAverageLuminance,
  420. const auto& tmpMinLuminance) {
  421. error = tmpError;
  422. if (error != Error::NONE) {
  423. return;
  424. }
  425. *outTypes = tmpTypes;
  426. *outMaxLuminance = tmpMaxLuminance;
  427. *outMaxAverageLuminance = tmpMaxAverageLuminance;
  428. *outMinLuminance = tmpMinLuminance;
  429. });
  430. } else {
  431. mClient->getHdrCapabilities(display,
  432. [&](const auto& tmpError, const auto& tmpTypes,
  433. const auto& tmpMaxLuminance,
  434. const auto& tmpMaxAverageLuminance,
  435. const auto& tmpMinLuminance) {
  436. error = tmpError;
  437. if (error != Error::NONE) {
  438. return;
  439. }
  440. outTypes->clear();
  441. for (auto type : tmpTypes) {
  442. outTypes->push_back(static_cast<Hdr>(type));
  443. }
  444. *outMaxLuminance = tmpMaxLuminance;
  445. *outMaxAverageLuminance = tmpMaxAverageLuminance;
  446. *outMinLuminance = tmpMinLuminance;
  447. });
  448. }
  449. return error;
  450. }
  451. Error Composer::getReleaseFences(Display display,
  452. std::vector<Layer>* outLayers, std::vector<int>* outReleaseFences)
  453. {
  454. mReader.takeReleaseFences(display, outLayers, outReleaseFences);
  455. return Error::NONE;
  456. }
  457. Error Composer::presentDisplay(Display display, int* outPresentFence)
  458. {
  459. mWriter.selectDisplay(display);
  460. mWriter.presentDisplay();
  461. Error error = execute();
  462. if (error != Error::NONE) {
  463. return error;
  464. }
  465. mReader.takePresentFence(display, outPresentFence);
  466. return Error::NONE;
  467. }
  468. Error Composer::setActiveConfig(Display display, Config config)
  469. {
  470. auto ret = mClient->setActiveConfig(display, config);
  471. return unwrapRet(ret);
  472. }
  473. Error Composer::setClientTarget(Display display, uint32_t slot,
  474. const sp<GraphicBuffer>& target,
  475. int acquireFence, Dataspace dataspace,
  476. const std::vector<IComposerClient::Rect>& damage)
  477. {
  478. mWriter.selectDisplay(display);
  479. if (mIsUsingVrComposer && target.get()) {
  480. IVrComposerClient::BufferMetadata metadata = {
  481. .width = target->getWidth(),
  482. .height = target->getHeight(),
  483. .stride = target->getStride(),
  484. .layerCount = target->getLayerCount(),
  485. .format = static_cast<types::V1_0::PixelFormat>(target->getPixelFormat()),
  486. .usage = target->getUsage(),
  487. };
  488. mWriter.setClientTargetMetadata(metadata);
  489. }
  490. const native_handle_t* handle = nullptr;
  491. if (target.get()) {
  492. handle = target->getNativeBuffer()->handle;
  493. }
  494. mWriter.setClientTarget(slot, handle, acquireFence, dataspace, damage);
  495. return Error::NONE;
  496. }
  497. Error Composer::setColorMode(Display display, ColorMode mode,
  498. RenderIntent renderIntent)
  499. {
  500. hardware::Return<Error> ret(kDefaultError);
  501. if (mClient_2_3) {
  502. ret = mClient_2_3->setColorMode_2_3(display, mode, renderIntent);
  503. } else if (mClient_2_2) {
  504. ret = mClient_2_2->setColorMode_2_2(display, static_cast<types::V1_1::ColorMode>(mode),
  505. renderIntent);
  506. } else {
  507. ret = mClient->setColorMode(display,
  508. static_cast<types::V1_0::ColorMode>(mode));
  509. }
  510. return unwrapRet(ret);
  511. }
  512. Error Composer::setColorTransform(Display display, const float* matrix,
  513. ColorTransform hint)
  514. {
  515. mWriter.selectDisplay(display);
  516. mWriter.setColorTransform(matrix, hint);
  517. return Error::NONE;
  518. }
  519. Error Composer::setOutputBuffer(Display display, const native_handle_t* buffer,
  520. int releaseFence)
  521. {
  522. mWriter.selectDisplay(display);
  523. mWriter.setOutputBuffer(0, buffer, dup(releaseFence));
  524. return Error::NONE;
  525. }
  526. Error Composer::setPowerMode(Display display, IComposerClient::PowerMode mode) {
  527. Return<Error> ret(Error::UNSUPPORTED);
  528. if (mClient_2_2) {
  529. ret = mClient_2_2->setPowerMode_2_2(display, mode);
  530. } else if (mode != IComposerClient::PowerMode::ON_SUSPEND) {
  531. ret = mClient->setPowerMode(display, static_cast<V2_1::IComposerClient::PowerMode>(mode));
  532. }
  533. return unwrapRet(ret);
  534. }
  535. Error Composer::setVsyncEnabled(Display display, IComposerClient::Vsync enabled)
  536. {
  537. auto ret = mClient->setVsyncEnabled(display, enabled);
  538. return unwrapRet(ret);
  539. }
  540. Error Composer::setClientTargetSlotCount(Display display)
  541. {
  542. const uint32_t bufferSlotCount = BufferQueue::NUM_BUFFER_SLOTS;
  543. auto ret = mClient->setClientTargetSlotCount(display, bufferSlotCount);
  544. return unwrapRet(ret);
  545. }
  546. Error Composer::validateDisplay(Display display, uint32_t* outNumTypes,
  547. uint32_t* outNumRequests)
  548. {
  549. mWriter.selectDisplay(display);
  550. mWriter.validateDisplay();
  551. Error error = execute();
  552. if (error != Error::NONE) {
  553. return error;
  554. }
  555. mReader.hasChanges(display, outNumTypes, outNumRequests);
  556. return Error::NONE;
  557. }
  558. Error Composer::presentOrValidateDisplay(Display display, uint32_t* outNumTypes,
  559. uint32_t* outNumRequests, int* outPresentFence, uint32_t* state) {
  560. mWriter.selectDisplay(display);
  561. mWriter.presentOrvalidateDisplay();
  562. Error error = execute();
  563. if (error != Error::NONE) {
  564. return error;
  565. }
  566. mReader.takePresentOrValidateStage(display, state);
  567. if (*state == 1) { // Present succeeded
  568. mReader.takePresentFence(display, outPresentFence);
  569. }
  570. if (*state == 0) { // Validate succeeded.
  571. mReader.hasChanges(display, outNumTypes, outNumRequests);
  572. }
  573. return Error::NONE;
  574. }
  575. Error Composer::setCursorPosition(Display display, Layer layer,
  576. int32_t x, int32_t y)
  577. {
  578. mWriter.selectDisplay(display);
  579. mWriter.selectLayer(layer);
  580. mWriter.setLayerCursorPosition(x, y);
  581. return Error::NONE;
  582. }
  583. Error Composer::setLayerBuffer(Display display, Layer layer,
  584. uint32_t slot, const sp<GraphicBuffer>& buffer, int acquireFence)
  585. {
  586. mWriter.selectDisplay(display);
  587. mWriter.selectLayer(layer);
  588. if (mIsUsingVrComposer && buffer.get()) {
  589. IVrComposerClient::BufferMetadata metadata = {
  590. .width = buffer->getWidth(),
  591. .height = buffer->getHeight(),
  592. .stride = buffer->getStride(),
  593. .layerCount = buffer->getLayerCount(),
  594. .format = static_cast<types::V1_0::PixelFormat>(buffer->getPixelFormat()),
  595. .usage = buffer->getUsage(),
  596. };
  597. mWriter.setLayerBufferMetadata(metadata);
  598. }
  599. const native_handle_t* handle = nullptr;
  600. if (buffer.get()) {
  601. handle = buffer->getNativeBuffer()->handle;
  602. }
  603. mWriter.setLayerBuffer(slot, handle, acquireFence);
  604. return Error::NONE;
  605. }
  606. Error Composer::setLayerSurfaceDamage(Display display, Layer layer,
  607. const std::vector<IComposerClient::Rect>& damage)
  608. {
  609. mWriter.selectDisplay(display);
  610. mWriter.selectLayer(layer);
  611. mWriter.setLayerSurfaceDamage(damage);
  612. return Error::NONE;
  613. }
  614. Error Composer::setLayerBlendMode(Display display, Layer layer,
  615. IComposerClient::BlendMode mode)
  616. {
  617. mWriter.selectDisplay(display);
  618. mWriter.selectLayer(layer);
  619. mWriter.setLayerBlendMode(mode);
  620. return Error::NONE;
  621. }
  622. Error Composer::setLayerColor(Display display, Layer layer,
  623. const IComposerClient::Color& color)
  624. {
  625. mWriter.selectDisplay(display);
  626. mWriter.selectLayer(layer);
  627. mWriter.setLayerColor(color);
  628. return Error::NONE;
  629. }
  630. Error Composer::setLayerCompositionType(Display display, Layer layer,
  631. IComposerClient::Composition type)
  632. {
  633. mWriter.selectDisplay(display);
  634. mWriter.selectLayer(layer);
  635. mWriter.setLayerCompositionType(type);
  636. return Error::NONE;
  637. }
  638. Error Composer::setLayerDataspace(Display display, Layer layer,
  639. Dataspace dataspace)
  640. {
  641. mWriter.selectDisplay(display);
  642. mWriter.selectLayer(layer);
  643. mWriter.setLayerDataspace(dataspace);
  644. return Error::NONE;
  645. }
  646. Error Composer::setLayerDisplayFrame(Display display, Layer layer,
  647. const IComposerClient::Rect& frame)
  648. {
  649. mWriter.selectDisplay(display);
  650. mWriter.selectLayer(layer);
  651. mWriter.setLayerDisplayFrame(frame);
  652. return Error::NONE;
  653. }
  654. Error Composer::setLayerPlaneAlpha(Display display, Layer layer,
  655. float alpha)
  656. {
  657. mWriter.selectDisplay(display);
  658. mWriter.selectLayer(layer);
  659. mWriter.setLayerPlaneAlpha(alpha);
  660. return Error::NONE;
  661. }
  662. Error Composer::setLayerSidebandStream(Display display, Layer layer,
  663. const native_handle_t* stream)
  664. {
  665. mWriter.selectDisplay(display);
  666. mWriter.selectLayer(layer);
  667. mWriter.setLayerSidebandStream(stream);
  668. return Error::NONE;
  669. }
  670. Error Composer::setLayerSourceCrop(Display display, Layer layer,
  671. const IComposerClient::FRect& crop)
  672. {
  673. mWriter.selectDisplay(display);
  674. mWriter.selectLayer(layer);
  675. mWriter.setLayerSourceCrop(crop);
  676. return Error::NONE;
  677. }
  678. Error Composer::setLayerTransform(Display display, Layer layer,
  679. Transform transform)
  680. {
  681. mWriter.selectDisplay(display);
  682. mWriter.selectLayer(layer);
  683. mWriter.setLayerTransform(transform);
  684. return Error::NONE;
  685. }
  686. Error Composer::setLayerVisibleRegion(Display display, Layer layer,
  687. const std::vector<IComposerClient::Rect>& visible)
  688. {
  689. mWriter.selectDisplay(display);
  690. mWriter.selectLayer(layer);
  691. mWriter.setLayerVisibleRegion(visible);
  692. return Error::NONE;
  693. }
  694. Error Composer::setLayerZOrder(Display display, Layer layer, uint32_t z)
  695. {
  696. mWriter.selectDisplay(display);
  697. mWriter.selectLayer(layer);
  698. mWriter.setLayerZOrder(z);
  699. return Error::NONE;
  700. }
  701. Error Composer::setLayerInfo(Display display, Layer layer, uint32_t type,
  702. uint32_t appId)
  703. {
  704. if (mIsUsingVrComposer) {
  705. mWriter.selectDisplay(display);
  706. mWriter.selectLayer(layer);
  707. mWriter.setLayerInfo(type, appId);
  708. }
  709. return Error::NONE;
  710. }
  711. Error Composer::execute()
  712. {
  713. // prepare input command queue
  714. bool queueChanged = false;
  715. uint32_t commandLength = 0;
  716. hidl_vec<hidl_handle> commandHandles;
  717. if (!mWriter.writeQueue(&queueChanged, &commandLength, &commandHandles)) {
  718. mWriter.reset();
  719. return Error::NO_RESOURCES;
  720. }
  721. // set up new input command queue if necessary
  722. if (queueChanged) {
  723. auto ret = mClient->setInputCommandQueue(*mWriter.getMQDescriptor());
  724. auto error = unwrapRet(ret);
  725. if (error != Error::NONE) {
  726. mWriter.reset();
  727. return error;
  728. }
  729. }
  730. if (commandLength == 0) {
  731. mWriter.reset();
  732. return Error::NONE;
  733. }
  734. Error error = kDefaultError;
  735. hardware::Return<void> ret;
  736. auto hidl_callback = [&](const auto& tmpError, const auto& tmpOutChanged,
  737. const auto& tmpOutLength, const auto& tmpOutHandles)
  738. {
  739. error = tmpError;
  740. // set up new output command queue if necessary
  741. if (error == Error::NONE && tmpOutChanged) {
  742. error = kDefaultError;
  743. mClient->getOutputCommandQueue(
  744. [&](const auto& tmpError,
  745. const auto& tmpDescriptor)
  746. {
  747. error = tmpError;
  748. if (error != Error::NONE) {
  749. return;
  750. }
  751. mReader.setMQDescriptor(tmpDescriptor);
  752. });
  753. }
  754. if (error != Error::NONE) {
  755. return;
  756. }
  757. if (mReader.readQueue(tmpOutLength, tmpOutHandles)) {
  758. error = mReader.parse();
  759. mReader.reset();
  760. } else {
  761. error = Error::NO_RESOURCES;
  762. }
  763. };
  764. if (mClient_2_2) {
  765. ret = mClient_2_2->executeCommands_2_2(commandLength, commandHandles, hidl_callback);
  766. } else {
  767. ret = mClient->executeCommands(commandLength, commandHandles, hidl_callback);
  768. }
  769. // executeCommands can fail because of out-of-fd and we do not want to
  770. // abort() in that case
  771. if (!ret.isOk()) {
  772. ALOGE("executeCommands failed because of %s", ret.description().c_str());
  773. }
  774. if (error == Error::NONE) {
  775. std::vector<CommandReader::CommandError> commandErrors =
  776. mReader.takeErrors();
  777. for (const auto& cmdErr : commandErrors) {
  778. auto command =
  779. static_cast<IComposerClient::Command>(mWriter.getCommand(cmdErr.location));
  780. if (command == IComposerClient::Command::VALIDATE_DISPLAY ||
  781. command == IComposerClient::Command::PRESENT_DISPLAY ||
  782. command == IComposerClient::Command::PRESENT_OR_VALIDATE_DISPLAY) {
  783. error = cmdErr.error;
  784. } else {
  785. ALOGW("command 0x%x generated error %d",
  786. command, cmdErr.error);
  787. }
  788. }
  789. }
  790. mWriter.reset();
  791. return error;
  792. }
  793. // Composer HAL 2.2
  794. Error Composer::setLayerPerFrameMetadata(Display display, Layer layer,
  795. const std::vector<IComposerClient::PerFrameMetadata>& perFrameMetadatas) {
  796. if (!mClient_2_2) {
  797. return Error::UNSUPPORTED;
  798. }
  799. mWriter.selectDisplay(display);
  800. mWriter.selectLayer(layer);
  801. mWriter.setLayerPerFrameMetadata(perFrameMetadatas);
  802. return Error::NONE;
  803. }
  804. std::vector<IComposerClient::PerFrameMetadataKey> Composer::getPerFrameMetadataKeys(
  805. Display display) {
  806. std::vector<IComposerClient::PerFrameMetadataKey> keys;
  807. if (!mClient_2_2) {
  808. return keys;
  809. }
  810. Error error = kDefaultError;
  811. if (mClient_2_3) {
  812. mClient_2_3->getPerFrameMetadataKeys_2_3(display,
  813. [&](const auto& tmpError, const auto& tmpKeys) {
  814. error = tmpError;
  815. if (error != Error::NONE) {
  816. ALOGW("getPerFrameMetadataKeys failed "
  817. "with %d",
  818. tmpError);
  819. return;
  820. }
  821. keys = tmpKeys;
  822. });
  823. } else {
  824. mClient_2_2
  825. ->getPerFrameMetadataKeys(display, [&](const auto& tmpError, const auto& tmpKeys) {
  826. error = tmpError;
  827. if (error != Error::NONE) {
  828. ALOGW("getPerFrameMetadataKeys failed with %d", tmpError);
  829. return;
  830. }
  831. keys.clear();
  832. for (auto key : tmpKeys) {
  833. keys.push_back(static_cast<IComposerClient::PerFrameMetadataKey>(key));
  834. }
  835. });
  836. }
  837. return keys;
  838. }
  839. Error Composer::getRenderIntents(Display display, ColorMode colorMode,
  840. std::vector<RenderIntent>* outRenderIntents) {
  841. if (!mClient_2_2) {
  842. outRenderIntents->push_back(RenderIntent::COLORIMETRIC);
  843. return Error::NONE;
  844. }
  845. Error error = kDefaultError;
  846. auto getRenderIntentsLambda = [&](const auto& tmpError, const auto& tmpKeys) {
  847. error = tmpError;
  848. if (error != Error::NONE) {
  849. return;
  850. }
  851. *outRenderIntents = tmpKeys;
  852. };
  853. if (mClient_2_3) {
  854. mClient_2_3->getRenderIntents_2_3(display, colorMode, getRenderIntentsLambda);
  855. } else {
  856. mClient_2_2->getRenderIntents(display, static_cast<types::V1_1::ColorMode>(colorMode),
  857. getRenderIntentsLambda);
  858. }
  859. return error;
  860. }
  861. Error Composer::getDataspaceSaturationMatrix(Dataspace dataspace, mat4* outMatrix)
  862. {
  863. if (!mClient_2_2) {
  864. *outMatrix = mat4();
  865. return Error::NONE;
  866. }
  867. Error error = kDefaultError;
  868. mClient_2_2->getDataspaceSaturationMatrix(static_cast<types::V1_1::Dataspace>(dataspace),
  869. [&](const auto& tmpError, const auto& tmpMatrix) {
  870. error = tmpError;
  871. if (error != Error::NONE) {
  872. return;
  873. }
  874. *outMatrix = mat4(tmpMatrix.data());
  875. });
  876. return error;
  877. }
  878. // Composer HAL 2.3
  879. Error Composer::getDisplayIdentificationData(Display display, uint8_t* outPort,
  880. std::vector<uint8_t>* outData) {
  881. if (!mClient_2_3) {
  882. return Error::UNSUPPORTED;
  883. }
  884. Error error = kDefaultError;
  885. mClient_2_3->getDisplayIdentificationData(display,
  886. [&](const auto& tmpError, const auto& tmpPort,
  887. const auto& tmpData) {
  888. error = tmpError;
  889. if (error != Error::NONE) {
  890. return;
  891. }
  892. *outPort = tmpPort;
  893. *outData = tmpData;
  894. });
  895. return error;
  896. }
  897. Error Composer::setLayerColorTransform(Display display, Layer layer, const float* matrix)
  898. {
  899. if (!mClient_2_3) {
  900. return Error::UNSUPPORTED;
  901. }
  902. mWriter.selectDisplay(display);
  903. mWriter.selectLayer(layer);
  904. mWriter.setLayerColorTransform(matrix);
  905. return Error::NONE;
  906. }
  907. Error Composer::getDisplayedContentSamplingAttributes(Display display, PixelFormat* outFormat,
  908. Dataspace* outDataspace,
  909. uint8_t* outComponentMask) {
  910. if (!outFormat || !outDataspace || !outComponentMask) {
  911. return Error::BAD_PARAMETER;
  912. }
  913. if (!mClient_2_3) {
  914. return Error::UNSUPPORTED;
  915. }
  916. Error error = kDefaultError;
  917. mClient_2_3->getDisplayedContentSamplingAttributes(display,
  918. [&](const auto tmpError,
  919. const auto& tmpFormat,
  920. const auto& tmpDataspace,
  921. const auto& tmpComponentMask) {
  922. error = tmpError;
  923. if (error == Error::NONE) {
  924. *outFormat = tmpFormat;
  925. *outDataspace = tmpDataspace;
  926. *outComponentMask =
  927. static_cast<uint8_t>(
  928. tmpComponentMask);
  929. }
  930. });
  931. return error;
  932. }
  933. Error Composer::getDisplayCapabilities(Display display,
  934. std::vector<DisplayCapability>* outCapabilities) {
  935. if (!mClient_2_3) {
  936. return Error::UNSUPPORTED;
  937. }
  938. Error error = kDefaultError;
  939. mClient_2_3->getDisplayCapabilities(display,
  940. [&](const auto& tmpError, const auto& tmpCapabilities) {
  941. error = tmpError;
  942. if (error != Error::NONE) {
  943. return;
  944. }
  945. *outCapabilities = tmpCapabilities;
  946. });
  947. return error;
  948. }
  949. Error Composer::setDisplayContentSamplingEnabled(Display display, bool enabled,
  950. uint8_t componentMask, uint64_t maxFrames) {
  951. if (!mClient_2_3) {
  952. return Error::UNSUPPORTED;
  953. }
  954. auto enable = enabled ? V2_3::IComposerClient::DisplayedContentSampling::ENABLE
  955. : V2_3::IComposerClient::DisplayedContentSampling::DISABLE;
  956. return mClient_2_3->setDisplayedContentSamplingEnabled(display, enable, componentMask,
  957. maxFrames);
  958. }
  959. Error Composer::getDisplayedContentSample(Display display, uint64_t maxFrames, uint64_t timestamp,
  960. DisplayedFrameStats* outStats) {
  961. if (!outStats) {
  962. return Error::BAD_PARAMETER;
  963. }
  964. if (!mClient_2_3) {
  965. return Error::UNSUPPORTED;
  966. }
  967. Error error = kDefaultError;
  968. mClient_2_3->getDisplayedContentSample(display, maxFrames, timestamp,
  969. [&](const auto tmpError, auto tmpNumFrames,
  970. const auto& tmpSamples0, const auto& tmpSamples1,
  971. const auto& tmpSamples2, const auto& tmpSamples3) {
  972. error = tmpError;
  973. if (error == Error::NONE) {
  974. outStats->numFrames = tmpNumFrames;
  975. outStats->component_0_sample = tmpSamples0;
  976. outStats->component_1_sample = tmpSamples1;
  977. outStats->component_2_sample = tmpSamples2;
  978. outStats->component_3_sample = tmpSamples3;
  979. }
  980. });
  981. return error;
  982. }
  983. Error Composer::setLayerPerFrameMetadataBlobs(
  984. Display display, Layer layer,
  985. const std::vector<IComposerClient::PerFrameMetadataBlob>& metadata) {
  986. if (!mClient_2_3) {
  987. return Error::UNSUPPORTED;
  988. }
  989. mWriter.selectDisplay(display);
  990. mWriter.selectLayer(layer);
  991. mWriter.setLayerPerFrameMetadataBlobs(metadata);
  992. return Error::NONE;
  993. }
  994. Error Composer::setDisplayBrightness(Display display, float brightness) {
  995. if (!mClient_2_3) {
  996. return Error::UNSUPPORTED;
  997. }
  998. return mClient_2_3->setDisplayBrightness(display, brightness);
  999. }
  1000. CommandReader::~CommandReader()
  1001. {
  1002. resetData();
  1003. }
  1004. Error CommandReader::parse()
  1005. {
  1006. resetData();
  1007. IComposerClient::Command command;
  1008. uint16_t length = 0;
  1009. while (!isEmpty()) {
  1010. auto command_2_1 = reinterpret_cast<V2_1::IComposerClient::Command*>(&command);
  1011. if (!beginCommand(command_2_1, &length)) {
  1012. break;
  1013. }
  1014. bool parsed = false;
  1015. switch (command) {
  1016. case IComposerClient::Command::SELECT_DISPLAY:
  1017. parsed = parseSelectDisplay(length);
  1018. break;
  1019. case IComposerClient::Command::SET_ERROR:
  1020. parsed = parseSetError(length);
  1021. break;
  1022. case IComposerClient::Command::SET_CHANGED_COMPOSITION_TYPES:
  1023. parsed = parseSetChangedCompositionTypes(length);
  1024. break;
  1025. case IComposerClient::Command::SET_DISPLAY_REQUESTS:
  1026. parsed = parseSetDisplayRequests(length);
  1027. break;
  1028. case IComposerClient::Command::SET_PRESENT_FENCE:
  1029. parsed = parseSetPresentFence(length);
  1030. break;
  1031. case IComposerClient::Command::SET_RELEASE_FENCES:
  1032. parsed = parseSetReleaseFences(length);
  1033. break;
  1034. case IComposerClient::Command ::SET_PRESENT_OR_VALIDATE_DISPLAY_RESULT:
  1035. parsed = parseSetPresentOrValidateDisplayResult(length);
  1036. break;
  1037. default:
  1038. parsed = false;
  1039. break;
  1040. }
  1041. endCommand();
  1042. if (!parsed) {
  1043. ALOGE("failed to parse command 0x%x length %" PRIu16,
  1044. command, length);
  1045. break;
  1046. }
  1047. }
  1048. return isEmpty() ? Error::NONE : Error::NO_RESOURCES;
  1049. }
  1050. bool CommandReader::parseSelectDisplay(uint16_t length)
  1051. {
  1052. if (length != CommandWriterBase::kSelectDisplayLength) {
  1053. return false;
  1054. }
  1055. mCurrentReturnData = &mReturnData[read64()];
  1056. return true;
  1057. }
  1058. bool CommandReader::parseSetError(uint16_t length)
  1059. {
  1060. if (length != CommandWriterBase::kSetErrorLength) {
  1061. return false;
  1062. }
  1063. auto location = read();
  1064. auto error = static_cast<Error>(readSigned());
  1065. mErrors.emplace_back(CommandError{location, error});
  1066. return true;
  1067. }
  1068. bool CommandReader::parseSetChangedCompositionTypes(uint16_t length)
  1069. {
  1070. // (layer id, composition type) pairs
  1071. if (length % 3 != 0 || !mCurrentReturnData) {
  1072. return false;
  1073. }
  1074. uint32_t count = length / 3;
  1075. mCurrentReturnData->changedLayers.reserve(count);
  1076. mCurrentReturnData->compositionTypes.reserve(count);
  1077. while (count > 0) {
  1078. auto layer = read64();
  1079. auto type = static_cast<IComposerClient::Composition>(readSigned());
  1080. mCurrentReturnData->changedLayers.push_back(layer);
  1081. mCurrentReturnData->compositionTypes.push_back(type);
  1082. count--;
  1083. }
  1084. return true;
  1085. }
  1086. bool CommandReader::parseSetDisplayRequests(uint16_t length)
  1087. {
  1088. // display requests followed by (layer id, layer requests) pairs
  1089. if (length % 3 != 1 || !mCurrentReturnData) {
  1090. return false;
  1091. }
  1092. mCurrentReturnData->displayRequests = read();
  1093. uint32_t count = (length - 1) / 3;
  1094. mCurrentReturnData->requestedLayers.reserve(count);
  1095. mCurrentReturnData->requestMasks.reserve(count);
  1096. while (count > 0) {
  1097. auto layer = read64();
  1098. auto layerRequestMask = read();
  1099. mCurrentReturnData->requestedLayers.push_back(layer);
  1100. mCurrentReturnData->requestMasks.push_back(layerRequestMask);
  1101. count--;
  1102. }
  1103. return true;
  1104. }
  1105. bool CommandReader::parseSetPresentFence(uint16_t length)
  1106. {
  1107. if (length != CommandWriterBase::kSetPresentFenceLength ||
  1108. !mCurrentReturnData) {
  1109. return false;
  1110. }
  1111. if (mCurrentReturnData->presentFence >= 0) {
  1112. close(mCurrentReturnData->presentFence);
  1113. }
  1114. mCurrentReturnData->presentFence = readFence();
  1115. return true;
  1116. }
  1117. bool CommandReader::parseSetReleaseFences(uint16_t length)
  1118. {
  1119. // (layer id, release fence index) pairs
  1120. if (length % 3 != 0 || !mCurrentReturnData) {
  1121. return false;
  1122. }
  1123. uint32_t count = length / 3;
  1124. mCurrentReturnData->releasedLayers.reserve(count);
  1125. mCurrentReturnData->releaseFences.reserve(count);
  1126. while (count > 0) {
  1127. auto layer = read64();
  1128. auto fence = readFence();
  1129. mCurrentReturnData->releasedLayers.push_back(layer);
  1130. mCurrentReturnData->releaseFences.push_back(fence);
  1131. count--;
  1132. }
  1133. return true;
  1134. }
  1135. bool CommandReader::parseSetPresentOrValidateDisplayResult(uint16_t length)
  1136. {
  1137. if (length != CommandWriterBase::kPresentOrValidateDisplayResultLength || !mCurrentReturnData) {
  1138. return false;
  1139. }
  1140. mCurrentReturnData->presentOrValidateState = read();
  1141. return true;
  1142. }
  1143. void CommandReader::resetData()
  1144. {
  1145. mErrors.clear();
  1146. for (auto& data : mReturnData) {
  1147. if (data.second.presentFence >= 0) {
  1148. close(data.second.presentFence);
  1149. }
  1150. for (auto fence : data.second.releaseFences) {
  1151. if (fence >= 0) {
  1152. close(fence);
  1153. }
  1154. }
  1155. }
  1156. mReturnData.clear();
  1157. mCurrentReturnData = nullptr;
  1158. }
  1159. std::vector<CommandReader::CommandError> CommandReader::takeErrors()
  1160. {
  1161. return std::move(mErrors);
  1162. }
  1163. bool CommandReader::hasChanges(Display display,
  1164. uint32_t* outNumChangedCompositionTypes,
  1165. uint32_t* outNumLayerRequestMasks) const
  1166. {
  1167. auto found = mReturnData.find(display);
  1168. if (found == mReturnData.end()) {
  1169. *outNumChangedCompositionTypes = 0;
  1170. *outNumLayerRequestMasks = 0;
  1171. return false;
  1172. }
  1173. const ReturnData& data = found->second;
  1174. *outNumChangedCompositionTypes = data.compositionTypes.size();
  1175. *outNumLayerRequestMasks = data.requestMasks.size();
  1176. return !(data.compositionTypes.empty() && data.requestMasks.empty());
  1177. }
  1178. void CommandReader::takeChangedCompositionTypes(Display display,
  1179. std::vector<Layer>* outLayers,
  1180. std::vector<IComposerClient::Composition>* outTypes)
  1181. {
  1182. auto found = mReturnData.find(display);
  1183. if (found == mReturnData.end()) {
  1184. outLayers->clear();
  1185. outTypes->clear();
  1186. return;
  1187. }
  1188. ReturnData& data = found->second;
  1189. *outLayers = std::move(data.changedLayers);
  1190. *outTypes = std::move(data.compositionTypes);
  1191. }
  1192. void CommandReader::takeDisplayRequests(Display display,
  1193. uint32_t* outDisplayRequestMask, std::vector<Layer>* outLayers,
  1194. std::vector<uint32_t>* outLayerRequestMasks)
  1195. {
  1196. auto found = mReturnData.find(display);
  1197. if (found == mReturnData.end()) {
  1198. *outDisplayRequestMask = 0;
  1199. outLayers->clear();
  1200. outLayerRequestMasks->clear();
  1201. return;
  1202. }
  1203. ReturnData& data = found->second;
  1204. *outDisplayRequestMask = data.displayRequests;
  1205. *outLayers = std::move(data.requestedLayers);
  1206. *outLayerRequestMasks = std::move(data.requestMasks);
  1207. }
  1208. void CommandReader::takeReleaseFences(Display display,
  1209. std::vector<Layer>* outLayers, std::vector<int>* outReleaseFences)
  1210. {
  1211. auto found = mReturnData.find(display);
  1212. if (found == mReturnData.end()) {
  1213. outLayers->clear();
  1214. outReleaseFences->clear();
  1215. return;
  1216. }
  1217. ReturnData& data = found->second;
  1218. *outLayers = std::move(data.releasedLayers);
  1219. *outReleaseFences = std::move(data.releaseFences);
  1220. }
  1221. void CommandReader::takePresentFence(Display display, int* outPresentFence)
  1222. {
  1223. auto found = mReturnData.find(display);
  1224. if (found == mReturnData.end()) {
  1225. *outPresentFence = -1;
  1226. return;
  1227. }
  1228. ReturnData& data = found->second;
  1229. *outPresentFence = data.presentFence;
  1230. data.presentFence = -1;
  1231. }
  1232. void CommandReader::takePresentOrValidateStage(Display display, uint32_t* state) {
  1233. auto found = mReturnData.find(display);
  1234. if (found == mReturnData.end()) {
  1235. *state= -1;
  1236. return;
  1237. }
  1238. ReturnData& data = found->second;
  1239. *state = data.presentOrValidateState;
  1240. }
  1241. } // namespace impl
  1242. } // namespace Hwc2
  1243. } // namespace android