1 /* 2 * Copyright (c) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef OHOS_HDI_DISPLAY_V1_0_DISPLAY_CMD_REQUESTER_H 17 #define OHOS_HDI_DISPLAY_V1_0_DISPLAY_CMD_REQUESTER_H 18 19 #include <unordered_map> 20 #include "hdf_base.h" 21 #include "hdf_log.h" 22 #include "hdi_smq.h" 23 #include "buffer_handle_parcelable.h" 24 #include "buffer_handle_utils.h" 25 #include "command_data_packer.h" 26 #include "command_data_unpacker.h" 27 #include "display_cmd_utils.h" 28 #include "hdifd_parcelable.h" 29 #include "idisplay_composer_hwi.h" 30 #include "v1_0/display_composer_type.h" 31 32 namespace OHOS { 33 namespace HDI { 34 namespace Display { 35 namespace Composer { 36 namespace V1_0 { 37 using namespace OHOS::HDI::Base; 38 using namespace OHOS::HDI::Display::Composer::V1_0; 39 using HdifdSet = std::vector<std::shared_ptr<HdifdParcelable>>; 40 41 template <typename Transfer, typename HalImpl> 42 class DisplayCmdResponser { 43 public: Create(std::shared_ptr<HalImpl> impl)44 static std::unique_ptr<DisplayCmdResponser> Create(std::shared_ptr<HalImpl> impl) 45 { 46 return std::make_unique<DisplayCmdResponser>(impl); 47 } 48 DisplayCmdResponser(std::shared_ptr<HalImpl> halImpl)49 DisplayCmdResponser(std::shared_ptr<HalImpl> halImpl) 50 : impl_(halImpl), 51 request_(nullptr), 52 isReplyUpdated_(false), 53 reply_(nullptr), 54 replyCommandCnt_(0), 55 replyPacker_(nullptr) 56 { 57 } 58 ~DisplayCmdResponser()59 ~DisplayCmdResponser() {} 60 InitCmdRequest(const std::shared_ptr<Transfer> & request)61 int32_t InitCmdRequest(const std::shared_ptr<Transfer> &request) 62 { 63 if (request_ != nullptr) { 64 request_.reset(); 65 } 66 request_ = request; 67 68 return HDF_SUCCESS; 69 } 70 GetCmdReply(std::shared_ptr<Transfer> & reply)71 int32_t GetCmdReply(std::shared_ptr<Transfer> &reply) 72 { 73 int32_t ec = HDF_SUCCESS; 74 if (isReplyUpdated_ == false) { 75 ec = InitReply(CmdUtils::INIT_ELEMENT_COUNT); 76 } 77 if (ec == HDF_SUCCESS) { 78 if (reply_ != nullptr) { 79 reply = reply_; 80 } else { 81 ec = HDF_FAILURE; 82 } 83 } 84 isReplyUpdated_ = false; 85 if (ec != HDF_SUCCESS) { 86 HDF_LOGE("error: GetCmdReply failure"); 87 } 88 return ec; 89 } 90 ProcessRequestCmd(std::shared_ptr<CommandDataUnpacker> unpacker,int32_t cmd,const std::vector<HdifdInfo> & inFds,std::vector<HdifdInfo> & outFds)91 void ProcessRequestCmd(std::shared_ptr<CommandDataUnpacker> unpacker, int32_t cmd, 92 const std::vector<HdifdInfo> &inFds, std::vector<HdifdInfo> &outFds) 93 { 94 HDF_LOGD("PackSection, cmd-[%{public}d] = %{public}s", cmd, CmdUtils::CommandToString(cmd)); 95 switch (cmd) { 96 case REQUEST_CMD_PREPAREDISPLAYLAYERS: 97 OnPrepareDisplayLayers(unpacker); 98 break; 99 case REQUEST_CMD_SETDISPLAYCLIENTBUFFER: 100 OnSetDisplayClientBuffer(unpacker, inFds); 101 break; 102 case REQUEST_CMD_SETDISPLAYCLIENTDAMAGE: 103 OnSetDisplayClientDamage(unpacker); 104 break; 105 case REQUEST_CMD_COMMIT: 106 OnCommit(unpacker, outFds); 107 break; 108 case REQUEST_CMD_SETLAYERALPHA: 109 OnSetLayerAlpha(unpacker); 110 break; 111 case REQUEST_CMD_SETLAYERPOSITION: 112 OnSetLayerPosition(unpacker); 113 break; 114 case REQUEST_CMD_SETLAYERCROP: 115 OnSetLayerCrop(unpacker); 116 break; 117 case REQUEST_CMD_SETLAYERZORDER: 118 OnSetLayerZorder(unpacker); 119 break; 120 case REQUEST_CMD_SETLAYERPREMULTI: 121 OnSetLayerPreMulti(unpacker); 122 break; 123 case REQUEST_CMD_SETTRANSFORMMODE: 124 OnSetTransformMode(unpacker); 125 break; 126 case REQUEST_CMD_SETLAYERDIRTYREGION: 127 OnSetLayerDirtyRegion(unpacker); 128 break; 129 case REQUEST_CMD_SETLAYERVISIBLEREGION: 130 OnSetLayerVisibleRegion(unpacker); 131 break; 132 case REQUEST_CMD_SETLAYERBUFFER: 133 OnSetLayerBuffer(unpacker, inFds); 134 break; 135 case REQUEST_CMD_SETLAYERCOMPOSITIONTYPE: 136 OnSetLayerCompositionType(unpacker); 137 break; 138 case REQUEST_CMD_SETLAYERBLENDTYPE: 139 OnSetLayerBlendType(unpacker); 140 break; 141 case REQUEST_CMD_SETLAYERVISIBLE: 142 OnSetLayerVisible(unpacker); 143 break; 144 case CONTROL_CMD_REQUEST_END: 145 OnRequestEnd(unpacker); 146 break; 147 default: 148 HDF_LOGE("error: not support display command, unpacked cmd = %{public}d", cmd); 149 ec = HDF_FAILURE; 150 break; 151 } 152 } 153 CmdRequest(uint32_t inEleCnt,const std::vector<HdifdInfo> & inFds,uint32_t & outEleCnt,std::vector<HdifdInfo> & outFds)154 int32_t CmdRequest(uint32_t inEleCnt, const std::vector<HdifdInfo> &inFds, uint32_t &outEleCnt, 155 std::vector<HdifdInfo> &outFds) 156 { 157 std::shared_ptr<char[]> requestData(new char[inEleCnt * CmdUtils::ELEMENT_SIZE], std::default_delete<char[]>()); 158 int32_t ec = request_->Read(reinterpret_cast<int32_t *>(requestData.get()), inEleCnt, 159 CmdUtils::TRANSFER_WAIT_TIME); 160 161 std::shared_ptr<CommandDataUnpacker> unpacker = std::make_shared<CommandDataUnpacker>(); 162 if (ec == HDF_SUCCESS) { 163 unpacker->Init(requestData.get(), inEleCnt * CmdUtils::ELEMENT_SIZE); 164 unpacker->Dump(); 165 } else { 166 ec = HDF_FAILURE; 167 } 168 int32_t unpackCmd = -1; 169 if (ec != HDF_SUCCESS || unpacker->PackBegin(unpackCmd) == false) { 170 HDF_LOGE("error: Check RequestBegin failed."); 171 ec = HDF_FAILURE; 172 } 173 if (unpackCmd != CONTROL_CMD_REQUEST_BEGIN) { 174 HDF_LOGI("error: unpacker PackBegin cmd not match, cmd(%{public}d)=%{public}s.", unpackCmd, 175 CmdUtils::CommandToString(unpackCmd)); 176 ec = HDF_FAILURE; 177 } 178 179 while (ec == HDF_SUCCESS && unpacker->NextSection()) { 180 if (!unpacker->BeginSection(unpackCmd)) { 181 HDF_LOGE("error: PackSection failed, unpackCmd=%{public}s.", CmdUtils::CommandToString(unpackCmd)); 182 ec = HDF_FAILURE; 183 } 184 ProcessRequestCmd(unpacker, unpackCmd, inFds, outFds); 185 } 186 /* pack request end commands */ 187 replyPacker_->PackEnd(CONTROL_CMD_REPLY_END); 188 HDF_LOGE("CmdReply command cnt=%{public}d", replyCommandCnt_); 189 /* Write reply pack */ 190 replyPacker_->Dump(); 191 outEleCnt = replyPacker_->ValidSize() / CmdUtils::ELEMENT_SIZE; 192 ec = reply_->Write(reinterpret_cast<int32_t *>(replyPacker_->GetDataPtr()), outEleCnt, 193 CmdUtils::TRANSFER_WAIT_TIME); 194 if (ec != HDF_SUCCESS) { 195 HDF_LOGE("Reply write failure, ec=%{public}d", ec); 196 outEleCnt = 0; 197 } 198 int32_t ec2 = PeriodDataReset(); 199 return (ec == HDF_SUCCESS ? ec2 : ec); 200 } 201 202 private: InitReply(uint32_t size)203 int32_t InitReply(uint32_t size) 204 { 205 reply_ = std::make_shared<Transfer>(size, SmqType::SYNCED_SMQ); 206 if (reply_ == nullptr) { 207 HDF_LOGE("nullptr error"); 208 return HDF_FAILURE; 209 } 210 replyPacker_ = std::make_shared<CommandDataPacker>(); 211 if (replyPacker_ == nullptr || replyPacker_->Init(reply_->GetSize() * CmdUtils::ELEMENT_SIZE) == false) { 212 HDF_LOGE("replyPacker init failure"); 213 return HDF_FAILURE; 214 } 215 return CmdUtils::StartPack(CONTROL_CMD_REPLY_BEGIN, replyPacker_); 216 } 217 OnRequestEnd(std::shared_ptr<CommandDataUnpacker> unpacker)218 void OnRequestEnd(std::shared_ptr<CommandDataUnpacker> unpacker) 219 { 220 size_t errCnt = errMaps_.size(); 221 if (errCnt >= 0) { 222 int32_t ec = CmdUtils::StartSection(REPLY_CMD_SETERROR, replyPacker_); 223 bool retVal = (ec == HDF_SUCCESS) ? true : false; 224 if (retVal) { 225 retVal = replyPacker_->WriteUint32(errCnt); 226 } 227 for (auto it = errMaps_.begin(); it != errMaps_.end(); ++it) { 228 if (retVal) { 229 break; 230 } 231 if (retVal) { 232 retVal = replyPacker_->WriteInt32(it->first); 233 } 234 if (retVal) { 235 retVal = replyPacker_->WriteInt32(it->second); 236 } 237 HDF_LOGE("Call display cmd failed, Id:%{public}s, ec=%{public}d", CmdUtils::CommandToString(it->first), 238 it->second); 239 } 240 if (retVal) { 241 CmdUtils::EndSection(replyPacker_); 242 } else { 243 HDF_LOGE("OnRequestEnd failed"); 244 } 245 replyCommandCnt_++; 246 } 247 return; 248 } 249 OnPrepareDisplayLayers(std::shared_ptr<CommandDataUnpacker> unpacker)250 void OnPrepareDisplayLayers(std::shared_ptr<CommandDataUnpacker> unpacker) 251 { 252 uint32_t devId = -1; 253 int32_t ec = unpacker->ReadUint32(devId) ? HDF_SUCCESS : HDF_FAILURE; 254 255 bool needFlush = false; 256 if (ec == HDF_SUCCESS) { 257 ec = impl_->PrepareDisplayLayers(devId, needFlush); 258 } 259 if (ec == HDF_SUCCESS) { 260 ec = CmdUtils::StartSection(REPLY_CMD_PREPAREDISPLAYLAYERS, replyPacker_); 261 } 262 if (ec == HDF_SUCCESS) { 263 ec = replyPacker_->WriteBool(needFlush) ? HDF_SUCCESS : HDF_FAILURE; 264 } 265 if (ec == HDF_SUCCESS) { 266 ec = CmdUtils::EndSection(replyPacker_); 267 replyCommandCnt_++; 268 } 269 if (ec != HDF_SUCCESS) { 270 errMaps_.emplace(REQUEST_CMD_PREPAREDISPLAYLAYERS, ec); 271 } 272 return; 273 } 274 OnSetDisplayClientBuffer(std::shared_ptr<CommandDataUnpacker> unpacker,const std::vector<HdifdInfo> & inFds)275 void OnSetDisplayClientBuffer(std::shared_ptr<CommandDataUnpacker> unpacker, const std::vector<HdifdInfo> &inFds) 276 { 277 uint32_t devId; 278 int32_t ec = unpacker->ReadUint32(devId) ? HDF_SUCCESS : HDF_FAILURE; 279 280 BufferHandle *buffer = nullptr; 281 if (ec == HDF_SUCCESS) { 282 ec = CmdUtils::BufferHandleUnpack(unpacker, inFds, buffer); 283 } 284 285 int32_t fence = -1; 286 if (ec == HDF_SUCCESS) { 287 ec = CmdUtils::FileDescriptorUnpack(unpacker, inFds, fence); 288 } 289 HdifdParcelable fdParcel(fence); 290 291 if (ec == HDF_SUCCESS) { 292 ec = impl_->SetDisplayClientBuffer(devId, *buffer, fdParcel.GetFd()); 293 } 294 FreeBufferHandle(buffer); 295 if (ec != HDF_SUCCESS) { 296 errMaps_.emplace(REQUEST_CMD_SETDISPLAYCLIENTBUFFER, ec); 297 } 298 return; 299 } 300 OnSetDisplayClientDamage(std::shared_ptr<CommandDataUnpacker> unpacker)301 void OnSetDisplayClientDamage(std::shared_ptr<CommandDataUnpacker> unpacker) 302 { 303 uint32_t devId = -1; 304 uint32_t vectSize = 0; 305 int32_t ec = unpacker->ReadUint32(devId) ? HDF_SUCCESS : HDF_FAILURE; 306 if (ec == HDF_SUCCESS) { 307 ec = unpacker->ReadUint32(vectSize) ? HDF_SUCCESS : HDF_FAILURE; 308 } 309 310 std::vector<IRect> rects; 311 rects.reserve(vectSize); 312 for (int32_t i = 0; i < vectSize; i++) { 313 if (ec == HDF_FAILURE) { 314 break; 315 } 316 ec = CmdUtils::RectUnpack(unpacker, rects[i]); 317 } 318 if (ec == HDF_SUCCESS) { 319 ec = impl_->SetDisplayClientDamage(devId, rects); 320 } 321 if (ec != HDF_SUCCESS) { 322 errMaps_.emplace(REQUEST_CMD_SETDISPLAYCLIENTDAMAGE, ec); 323 } 324 return; 325 } 326 OnCommit(std::shared_ptr<CommandDataUnpacker> unpacker,std::vector<HdifdInfo> & outFds)327 void OnCommit(std::shared_ptr<CommandDataUnpacker> unpacker, std::vector<HdifdInfo> &outFds) 328 { 329 uint32_t devId = -1; 330 int32_t fence = -1; 331 332 int32_t ec = unpacker->ReadUint32(devId) ? HDF_SUCCESS : HDF_FAILURE; 333 if (ec == HDF_SUCCESS) { 334 ec = impl_->Commit(devId, fence); 335 } 336 HdifdParcelable fdParcel(fence); 337 if (ec == HDF_SUCCESS) { 338 ec = CmdUtils::StartSection(REPLY_CMD_COMMIT, replyPacker_); 339 } 340 if (ec == HDF_SUCCESS) { 341 ec = CmdUtils::FileDescriptorPack(fdParcel.GetFd(), replyPacker_, outFds); 342 } 343 if (ec == HDF_SUCCESS) { 344 ec = CmdUtils::EndSection(replyPacker_); 345 replyCommandCnt_++; 346 } 347 if (ec != HDF_SUCCESS) { 348 errMaps_.emplace(REQUEST_CMD_COMMIT, ec); 349 } 350 351 return; 352 } 353 OnSetLayerAlpha(std::shared_ptr<CommandDataUnpacker> unpacker)354 void OnSetLayerAlpha(std::shared_ptr<CommandDataUnpacker> unpacker) 355 { 356 uint32_t devId = -1; 357 uint32_t layerId = -1; 358 LayerAlpha alpha = {0}; 359 360 int32_t ec = CmdUtils::SetupDeviceUnpack(unpacker, devId, layerId); 361 bool retVal = (ec == HDF_SUCCESS) ? true : false; 362 if (retVal) { 363 retVal = unpacker->ReadBool(alpha.enGlobalAlpha); 364 } 365 if (retVal) { 366 retVal = unpacker->ReadBool(alpha.enPixelAlpha); 367 } 368 if (retVal) { 369 retVal = unpacker->ReadUint8(alpha.alpha0); 370 } 371 if (retVal) { 372 retVal = unpacker->ReadUint8(alpha.alpha1); 373 } 374 if (retVal) { 375 retVal = unpacker->ReadUint8(alpha.gAlpha); 376 } 377 if (retVal) { 378 ec = impl_->SetLayerAlpha(devId, layerId, alpha); 379 } else { 380 ec = retVal ? HDF_SUCCESS : HDF_FAILURE; 381 } 382 if (ec != HDF_SUCCESS) { 383 errMaps_.emplace(REQUEST_CMD_SETLAYERALPHA, ec); 384 } 385 return; 386 } 387 OnSetLayerPosition(std::shared_ptr<CommandDataUnpacker> unpacker)388 void OnSetLayerPosition(std::shared_ptr<CommandDataUnpacker> unpacker) 389 { 390 uint32_t devId = -1; 391 uint32_t layerId = -1; 392 IRect rect = {0} 393 394 int32_t ec = CmdUtils::SetupDeviceUnpack(unpacker, devId, layerId); 395 if (ec == HDF_SUCCESS) { 396 ec = CmdUtils::RectUnpack(unpacker, rect); 397 } 398 if (ec == HDF_SUCCESS) { 399 ec = impl_->SetLayerPosition(devId, layerId, rect); 400 } 401 if (ec != HDF_SUCCESS) { 402 errMaps_.emplace(REQUEST_CMD_SETLAYERPOSITION, ec); 403 } 404 return; 405 } 406 OnSetLayerCrop(std::shared_ptr<CommandDataUnpacker> unpacker)407 void OnSetLayerCrop(std::shared_ptr<CommandDataUnpacker> unpacker) 408 { 409 uint32_t devId = -1; 410 uint32_t layerId = -1; 411 IRect rect = {0}; 412 413 int32_t ec = CmdUtils::SetupDeviceUnpack(unpacker, devId, layerId); 414 if (ec == HDF_SUCCESS) { 415 ec = CmdUtils::RectUnpack(unpacker, rect); 416 } 417 if (ec == HDF_SUCCESS) { 418 ec = impl_->SetLayerCrop(devId, layerId, rect); 419 } 420 if (ec != HDF_SUCCESS) { 421 errMaps_.emplace(REQUEST_CMD_SETLAYERCROP, ec); 422 } 423 return; 424 } 425 OnSetLayerZorder(std::shared_ptr<CommandDataUnpacker> unpacker)426 void OnSetLayerZorder(std::shared_ptr<CommandDataUnpacker> unpacker) 427 { 428 uint32_t devId = -1; 429 uint32_t layerId = -1; 430 uint32_t zorder = 0; 431 432 int32_t ec = CmdUtils::SetupDeviceUnpack(unpacker, devId, layerId); 433 if (ec == HDF_SUCCESS) { 434 ec = unpacker->ReadUint32(zorder) ? HDF_SUCCESS : HDF_FAILURE; 435 } 436 if (ec == HDF_SUCCESS) { 437 ec = impl_->SetLayerZorder(devId, layerId, zorder); 438 } 439 if (ec != HDF_SUCCESS) { 440 errMaps_.emplace(REQUEST_CMD_SETLAYERZORDER, ec); 441 } 442 return; 443 } 444 OnSetLayerPreMulti(std::shared_ptr<CommandDataUnpacker> unpacker)445 void OnSetLayerPreMulti(std::shared_ptr<CommandDataUnpacker> unpacker) 446 { 447 uint32_t devId = -1; 448 uint32_t layerId = -1; 449 bool preMulti = false; 450 451 int32_t ec = CmdUtils::SetupDeviceUnpack(unpacker, devId, layerId); 452 if (ec == HDF_SUCCESS) { 453 ec = unpacker->ReadBool(preMulti) ? HDF_SUCCESS : HDF_FAILURE; 454 } 455 if (ec == HDF_SUCCESS) { 456 ec = impl_->SetLayerPreMulti(devId, layerId, preMulti); 457 } 458 if (ec != HDF_SUCCESS) { 459 errMaps_.emplace(REQUEST_CMD_SETLAYERPREMULTI, ec); 460 } 461 return; 462 } 463 OnSetTransformMode(std::shared_ptr<CommandDataUnpacker> unpacker)464 void OnSetTransformMode(std::shared_ptr<CommandDataUnpacker> unpacker) 465 { 466 uint32_t devId = -1; 467 uint32_t layerId = -1; 468 int32_t type = 0; 469 470 int32_t ec = CmdUtils::SetupDeviceUnpack(unpacker, devId, layerId); 471 if (ec == HDF_SUCCESS) { 472 ec = unpacker->ReadInt32(type) ? HDF_SUCCESS : HDF_FAILURE; 473 } 474 if (ec == HDF_SUCCESS) { 475 ec = impl_->SetTransformMode(devId, layerId, static_cast<TransformType>(type)); 476 } 477 if (ec != HDF_SUCCESS) { 478 errMaps_.emplace(REQUEST_CMD_SETTRANSFORMMODE, ec); 479 } 480 return; 481 } 482 OnSetLayerDirtyRegion(std::shared_ptr<CommandDataUnpacker> unpacker)483 void OnSetLayerDirtyRegion(std::shared_ptr<CommandDataUnpacker> unpacker) 484 { 485 uint32_t devId = -1; 486 uint32_t layerId = -1; 487 IRect rect = {0}; 488 489 int32_t ec = CmdUtils::SetupDeviceUnpack(unpacker, devId, layerId); 490 if (ec == HDF_SUCCESS) { 491 ec = CmdUtils::RectUnpack(unpacker, rect); 492 } 493 if (ec == HDF_SUCCESS) { 494 ec = impl_->SetLayerDirtyRegion(devId, layerId, rect); 495 } 496 if (ec != HDF_SUCCESS) { 497 errMaps_.emplace(REQUEST_CMD_SETLAYERDIRTYREGION, ec); 498 } 499 return; 500 } 501 OnSetLayerVisibleRegion(std::shared_ptr<CommandDataUnpacker> unpacker)502 void OnSetLayerVisibleRegion(std::shared_ptr<CommandDataUnpacker> unpacker) 503 { 504 uint32_t devId = -1; 505 uint32_t layerId = -1; 506 uint32_t vectSize = 0; 507 508 int32_t ec = CmdUtils::SetupDeviceUnpack(unpacker, devId, layerId); 509 if (ec == HDF_SUCCESS) { 510 ec = unpacker->ReadUint32(vectSize) ? HDF_SUCCESS : HDF_FAILURE; 511 } 512 std::vector<IRect> rects; 513 for (int32_t i = 0; i < vectSize; i++) { 514 if (ec == HDF_FAILURE) { 515 break; 516 } 517 IRect rect; 518 ec = CmdUtils::RectUnpack(unpacker, rect); 519 rects.push_back(rect); 520 } 521 if (ec == HDF_SUCCESS) { 522 ec = impl_->SetLayerVisibleRegion(devId, layerId, rects); 523 } 524 if (ec != HDF_SUCCESS) { 525 errMaps_.emplace(REQUEST_CMD_SETLAYERVISIBLEREGION, ec); 526 } 527 return; 528 } 529 OnSetLayerBuffer(std::shared_ptr<CommandDataUnpacker> unpacker,const std::vector<HdifdInfo> & inFds)530 void OnSetLayerBuffer(std::shared_ptr<CommandDataUnpacker> unpacker, const std::vector<HdifdInfo> &inFds) 531 { 532 uint32_t devId = -1; 533 uint32_t layerId = -1; 534 BufferHandle *buffer = nullptr; 535 536 int32_t ec = CmdUtils::SetupDeviceUnpack(unpacker, devId, layerId); 537 if (ec == HDF_SUCCESS) { 538 ec = CmdUtils::BufferHandleUnpack(unpacker, inFds, buffer); 539 } 540 int32_t fence = -1; 541 if (ec == HDF_SUCCESS) { 542 ec = CmdUtils::FileDescriptorUnpack(unpacker, inFds, fence); 543 } 544 HdifdParcelable fdParcel(fence); 545 if (ec == HDF_SUCCESS) { 546 ec = impl_->SetLayerBuffer(devId, layerId, *buffer, fdParcel.GetFd()); 547 } 548 FreeBufferHandle(buffer); 549 if (ec != HDF_SUCCESS) { 550 errMaps_.emplace(REQUEST_CMD_SETLAYERBUFFER, ec); 551 } 552 return; 553 } 554 OnSetLayerCompositionType(std::shared_ptr<CommandDataUnpacker> unpacker)555 void OnSetLayerCompositionType(std::shared_ptr<CommandDataUnpacker> unpacker) 556 { 557 uint32_t devId = -1; 558 uint32_t layerId = -1; 559 int32_t ec = CmdUtils::SetupDeviceUnpack(unpacker, devId, layerId); 560 int32_t type; 561 562 if (ec == HDF_SUCCESS) { 563 ec = unpacker->ReadInt32(type) ? HDF_SUCCESS : HDF_FAILURE; 564 } 565 if (ec == HDF_SUCCESS) { 566 ec = impl_->SetLayerCompositionType(devId, layerId, static_cast<CompositionType>(type)); 567 } 568 if (ec != HDF_SUCCESS) { 569 errMaps_.emplace(REQUEST_CMD_SETLAYERCOMPOSITIONTYPE, ec); 570 } 571 return; 572 } 573 OnSetLayerBlendType(std::shared_ptr<CommandDataUnpacker> unpacker)574 void OnSetLayerBlendType(std::shared_ptr<CommandDataUnpacker> unpacker) 575 { 576 uint32_t devId = -1; 577 uint32_t layerId = -1; 578 int32_t ec = CmdUtils::SetupDeviceUnpack(unpacker, devId, layerId); 579 int32_t type; 580 if (ec == HDF_SUCCESS) { 581 ec = unpacker->ReadInt32(type) ? HDF_SUCCESS : HDF_FAILURE; 582 } 583 if (ec == HDF_SUCCESS) { 584 ec = impl_->SetLayerBlendType(devId, layerId, static_cast<BlendType>(type)); 585 } 586 if (ec != HDF_SUCCESS) { 587 errMaps_.emplace(REQUEST_CMD_SETLAYERBLENDTYPE, ec); 588 } 589 return; 590 } 591 OnSetLayerVisible(std::shared_ptr<CommandDataUnpacker> unpacker)592 void OnSetLayerVisible(std::shared_ptr<CommandDataUnpacker> unpacker) 593 { 594 uint32_t devId = -1; 595 uint32_t layerId = -1; 596 int32_t ec = CmdUtils::SetupDeviceUnpack(unpacker, devId, layerId); 597 bool visible = false; 598 if (ec == HDF_SUCCESS) { 599 ec = unpacker->ReadBool(visible) ? HDF_SUCCESS : HDF_FAILURE; 600 } 601 602 if (ec == HDF_SUCCESS) { 603 ec = impl_->SetLayerVisible(devId, layerId, visible); 604 } 605 606 if (ec != HDF_SUCCESS) { 607 errMaps_.emplace(REQUEST_CMD_SETLAYERPREMULTI, ec); 608 } 609 return; 610 } 611 PeriodDataReset()612 int32_t PeriodDataReset() 613 { 614 replyCommandCnt_ = 0; 615 errMaps_.clear(); 616 617 int32_t ec = CmdUtils::StartPack(CONTROL_CMD_REPLY_BEGIN, replyPacker_); 618 if (ec != HDF_SUCCESS) { 619 HDF_LOGE("PackBegin failure, ec=%{public}d", ec); 620 } 621 return ec; 622 } 623 624 private: 625 std::shared_ptr<HalImpl> impl_; 626 std::shared_ptr<Transfer> request_; 627 bool isReplyUpdated_; 628 std::shared_ptr<Transfer> reply_; 629 /* period data */ 630 uint32_t replyCommandCnt_; 631 std::shared_ptr<CommandDataPacker> replyPacker_; 632 std::unordered_map<int32_t, int32_t> errMaps_; 633 }; 634 using HdiDisplayCmdResponser = DisplayCmdResponser<SharedMemQueue<int32_t>, IDisplayComposerHwi>; 635 } // namespace V1_0 636 } // namespace Composer 637 } // namespace Display 638 } // namespace HDI 639 } // namespace OHOS 640 #endif // OHOS_HDI_DISPLAY_V1_0_DISPLAY_CMD_REQUESTER_H