1 /* 2 * Copyright (c) 2021 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 FRAMEWORKS_SURFACE_INCLUDE_CONSUMER_SURFACE_H 17 #define FRAMEWORKS_SURFACE_INCLUDE_CONSUMER_SURFACE_H 18 19 /** 20 * @file consumer_surface.h 21 * @brief consumer of surface. 22 * Through this class, the data produced by the producer can be obtained for data consumption.\n 23 */ 24 #include <iconsumer_surface.h> 25 #include <map> 26 #include <string> 27 #include "buffer_queue.h" 28 #include "buffer_queue_consumer.h" 29 #include "buffer_queue_producer.h" 30 31 namespace OHOS { 32 class ConsumerSurface : public IConsumerSurface { 33 public: 34 ConsumerSurface(const std::string &name); 35 virtual ~ConsumerSurface(); 36 /** 37 * @brief Initialization function. 38 * 39 * @return {@link GSERROR_OK} 0 - Success. 40 */ 41 GSError Init(); 42 /** 43 * @brief Determine if it is the consumer. 44 * 45 * @return true - is consumer. 46 * @return false - is not consumer. 47 */ 48 bool IsConsumer() const override; 49 /** 50 * @brief Get the Producer from the surface. 51 * 52 * @return sptr<IBufferProducer> The object of producer. 53 */ 54 sptr<IBufferProducer> GetProducer() const override; 55 /** 56 * @brief Acquire buffer for data consumed. 57 * When the fenceFd is used up, you need to close it. 58 * 59 * @param buffer [out] The buffer for data consumed. 60 * @param fence [out] fence fd for asynchronous waiting mechanism. 61 * @param timestamp [out] The timestamp of the produced data. 62 * @param damage [out] The dirty buffer area set by the producer. 63 * @return {@link GSERROR_OK} 0 - Success. 64 * {@link GSERROR_INVALID_ARGUMENTS} 40001000 - Param invalid. 65 * {@link GSERROR_NO_BUFFER} 40601000 - no buffer. 66 * 67 * @see ReleaseBuffer 68 */ 69 GSError AcquireBuffer(sptr<SurfaceBuffer>& buffer, int32_t &fence, 70 int64_t ×tamp, Rect &damage) override; 71 /** 72 * @brief Release buffer for data production. 73 * 74 * @param buffer [in] Consumed data buffer. 75 * @param fence [in] fence fd for asynchronous waiting mechanism. 76 * @return {@link GSERROR_OK} 0 - Success. 77 * {@link GSERROR_INVALID_ARGUMENTS} 40001000 - Param invalid. 78 * {@link SURFACE_ERROR_BUFFER_NOT_INCACHE} 41210000 - Buffer not in cache. 79 * {@link SURFACE_ERROR_BUFFER_STATE_INVALID} 41207000 - Buffer state invalid. 80 */ 81 GSError ReleaseBuffer(sptr<SurfaceBuffer>& buffer, int32_t fence) override; 82 /** 83 * @brief Acquire buffer for data consumed. 84 * 85 * @param buffer [out] The buffer for data consumed. 86 * @param fence [out] fence fd for asynchronous waiting mechanism. 87 * @param timestamp [out] The timestamp of the produced data. 88 * @param damage [out] The dirty buffer area set by the producer. 89 * @return {@link GSERROR_OK} 0 - Success. 90 * {@link GSERROR_INVALID_ARGUMENTS} 40001000 - Param invalid. 91 * {@link GSERROR_NO_BUFFER} 40601000 - no buffer. 92 * 93 * @see ReleaseBuffer 94 */ 95 GSError AcquireBuffer(sptr<SurfaceBuffer>& buffer, sptr<SyncFence>& fence, 96 int64_t ×tamp, Rect &damage) override; 97 /** 98 * @brief Acquire buffer for data consumed. 99 * 100 * @param buffer [out] The buffer for data consumed. 101 * @param fence [out] fence fd for asynchronous waiting mechanism. 102 * @param timestamp [out] The timestamp of the produced data. 103 * @param damage [out] The dirty buffer area set by the producer. 104 * @param isLppMode [in] Normal buffer or LPP buffer. 105 * @return {@link GSERROR_OK} 0 - Success. 106 * {@link GSERROR_INVALID_ARGUMENTS} 40001000 - Param invalid. 107 * {@link GSERROR_NO_BUFFER} 40601000 - no buffer. 108 * 109 * @see ReleaseBuffer 110 */ 111 GSError AcquireBuffer(sptr<SurfaceBuffer>& buffer, sptr<SyncFence>& fence, 112 int64_t ×tamp, std::vector<Rect> &damages, bool isLppMode = false) override; 113 /** 114 * @brief Acquire buffer for data consumed. 115 * 116 * @param returnValue [out] Acquire buffer return value. 117 * @param expectPresentTimestamp [in] Expect present timestamp. 118 * @param isUsingAutoTimestamp [in] Is using auto timestamp. 119 * @return {@link GSERROR_OK} 0 - Success. 120 * {@link GSERROR_INVALID_ARGUMENTS} 40001000 - Param invalid. 121 * {@link GSERROR_NO_BUFFER} 40601000 - no buffer. 122 * {@link GSERROR_NO_BUFFER_READY} 40605000 - No buffer timestamp meets the target time. 123 */ 124 GSError AcquireBuffer(AcquireBufferReturnValue &returnValue, int64_t expectPresentTimestamp, 125 bool isUsingAutoTimestamp) override; 126 /** 127 * @brief Release buffer for data production. 128 * 129 * @param buffer [in] Consumed data buffer. 130 * @param fence [in] fence fd for asynchronous waiting mechanism. 131 * @return {@link GSERROR_OK} 0 - Success. 132 * {@link GSERROR_INVALID_ARGUMENTS} 40001000 - Param invalid. 133 * {@link SURFACE_ERROR_BUFFER_NOT_INCACHE} 41210000 - Buffer not in cache. 134 * {@link SURFACE_ERROR_BUFFER_STATE_INVALID} 41207000 - Buffer state invalid. 135 */ 136 GSError ReleaseBuffer(sptr<SurfaceBuffer>& buffer, const sptr<SyncFence>& fence) override; 137 /** 138 * @brief Attach the buffer to the surface. 139 * 140 * @param buffer [in] Indicates the pointer to a SurfaceBuffer instance. 141 * @return {@link GSERROR_OK} 0 - Success. 142 * {@link GSERROR_INVALID_ARGUMENTS} 40001000 - Param invalid. 143 * {@link GSERROR_NO_CONSUMER} 41202000 - no consumer. 144 * {@link SURFACE_ERROR_BUFFER_STATE_INVALID} 41207000 - Buffer state invalid. 145 * {@link SURFACE_ERROR_CONSUMER_UNREGISTER_LISTENER} 41212000 - no register listener. 146 * {@link GSERROR_OUT_OF_RANGE} 40603000 - out of range. 147 */ 148 GSError AttachBuffer(sptr<SurfaceBuffer>& buffer) override; 149 /** 150 * @brief Detach the buffer from the surface. 151 * 152 * @param buffer [in] Indicates the pointer to a SurfaceBuffer instance. 153 * @return {@link GSERROR_OK} 0 - Success. 154 * {@link GSERROR_INVALID_ARGUMENTS} 40001000 - Param invalid. 155 * {@link GSERROR_NO_ENTRY} 40602000 - Buffer state invalid or buffer not in cache. 156 */ 157 GSError DetachBuffer(sptr<SurfaceBuffer>& buffer) override; 158 /** 159 * @brief Determine whether a buffer is ready for use 160 * 161 * @return true There has available buffer. 162 * @return false There has not available buffer. 163 */ 164 bool QueryIfBufferAvailable() override; 165 /** 166 * @brief Get the Queue Size from the surface. 167 * 168 * @return uint32_t Queue size of the surface. 169 */ 170 uint32_t GetQueueSize() override; 171 /** 172 * @brief Set the Queue Size for the surface. 173 * 174 * @param queueSize [in] The buffer queue size. 175 * @return {@link GSERROR_OK} 0 - Success. 176 * {@link GSERROR_INVALID_ARGUMENTS} 40001000 - Param invalid. 177 */ 178 GSError SetQueueSize(uint32_t queueSize) override; 179 /** 180 * @brief Get the Name of the surface. 181 * 182 * @return const std::string& The name of The surface. 183 */ 184 const std::string& GetName() override; 185 /** 186 * @brief Set the Default Width And Height for the surface. 187 * 188 * @param width [in] The default width for the surface. 189 * @param height [in] The default height for the surface. 190 * @return {@link GSERROR_OK} 0 - Success. 191 * {@link GSERROR_INVALID_ARGUMENTS} 40001000 - Param invalid. 192 */ 193 GSError SetDefaultWidthAndHeight(int32_t width, int32_t height) override; 194 /** 195 * @brief Get the Default Width from the surface. 196 * 197 * @return int32_t The default width of the surface. 198 */ 199 int32_t GetDefaultWidth() override; 200 /** 201 * @brief Get the Default Height from the surface. 202 * 203 * @return int32_t The default height of the surface. 204 */ 205 int32_t GetDefaultHeight() override; 206 /** 207 * @brief Set the Default Usage for the surface. 208 * 209 * @param usage [in] the Default Usage of the surface. 210 * @return {@link GSERROR_OK} 0 - Success. 211 * {@link GSERROR_INVALID_ARGUMENTS} 40001000 - Param invalid. 212 */ 213 GSError SetDefaultUsage(uint64_t usage) override; 214 /** 215 * @brief Get the Default Usage from the surface. 216 * 217 * @return uint64_t the Default Usage of the surface. 218 */ 219 uint64_t GetDefaultUsage() override; 220 /** 221 * @brief Set the User Data for the surface. 222 * 223 * @param key [in] Indicates the key of the user data. 224 * @param val [in] Indicates the val of the user data. 225 * @return {@link GSERROR_OK} 0 - Success. 226 * {@link GSERROR_OUT_OF_RANGE} 40603000 - Size out of range. 227 * {@link GSERROR_API_FAILED} 50001000 - Set value repeat. 228 */ 229 GSError SetUserData(const std::string &key, const std::string &val) override; 230 /** 231 * @brief Get the User Data of the surface. 232 * 233 * @param key [in] Indicates the key of the user data. 234 * @return std::string The val of the user data. 235 */ 236 std::string GetUserData(const std::string &key) override; 237 /** 238 * @brief Register consumer listener function. 239 * 240 * @param listener The callback of consumer function. 241 * @return {@link GSERROR_OK} 0 - Success. 242 * {@link GSERROR_INVALID_ARGUMENTS} 40001000 - Param invalid. 243 */ 244 GSError RegisterConsumerListener(sptr<IBufferConsumerListener>& listener) override; 245 /** 246 * @brief Register consumer listener function. 247 * 248 * @param listener The callback of consumer function. 249 * @return {@link GSERROR_OK} 0 - Success. 250 * {@link GSERROR_INVALID_ARGUMENTS} 40001000 - Param invalid. 251 */ 252 GSError RegisterConsumerListener(IBufferConsumerListenerClazz *listener) override; 253 /** 254 * @brief Register release listener function. 255 * 256 * @param listener The callback of release function. 257 * @return {@link GSERROR_OK} 0 - Success. 258 * {@link GSERROR_INVALID_ARGUMENTS} 40001000 - Param invalid. 259 */ 260 GSError RegisterReleaseListener(OnReleaseFunc func) override; 261 /** 262 * @brief Unregister release listener function. 263 * 264 * @return {@link GSERROR_OK} 0 - Success. 265 */ UnRegisterReleaseListener()266 GSError UnRegisterReleaseListener() override 267 { 268 return GSERROR_OK; 269 } 270 /** 271 * @brief Register delete buffer listener function. 272 * 273 * @param func The callback of delete buffer function. 274 * @param isForUniRedraw Is for uni redraw. 275 * @return {@link GSERROR_OK} 0 - Success. 276 * {@link GSERROR_INVALID_ARGUMENTS} 40001000 - Param invalid. 277 */ 278 GSError RegisterDeleteBufferListener(OnDeleteBufferFunc func, bool isForUniRedraw = false) override; 279 /** 280 * @brief Unregister consumer listener function. 281 * 282 * @return {@link GSERROR_OK} 0 - Success. 283 * {@link GSERROR_INVALID_ARGUMENTS} 40001000 - Param invalid. 284 */ 285 GSError UnregisterConsumerListener() override; 286 /** 287 * @brief Get the Unique Id of the surface. 288 * 289 * @return uint64_t The Unique Id of the surface. 290 */ 291 uint64_t GetUniqueId() const override; 292 /** 293 * @brief Dump info of the surface. 294 * 295 * @param result The info of the surface. 296 */ 297 void Dump(std::string &result) const override; 298 /** 299 * @brief Dump current frame layer info of the surface. 300 * 301 */ 302 void DumpCurrentFrameLayer() const override; 303 /** 304 * @brief Clean the surface buffer cache and inform consumer. 305 * This interface will empty all caches of the current process. 306 * 307 * @return {@link GSERROR_OK} 0 - Success. 308 * {@link GSERROR_INVALID_ARGUMENTS} 40001000 - Param invalid. 309 */ 310 GSError GoBackground() override; 311 /** 312 * @brief Set the Transform type for the surface. 313 * 314 * @param transform The Transform type. 315 * @return {@link GSERROR_OK} 0 - Success. 316 * {@link GSERROR_INVALID_ARGUMENTS} 40001000 - Param invalid. 317 */ 318 GSError SetTransform(GraphicTransformType transform) override; 319 /** 320 * @brief Get the Transform type from the surface. 321 * 322 * @return GraphicTransformType The Transform type. 323 */ 324 GraphicTransformType GetTransform() const override; 325 /** 326 * @brief Set the Scaling Mode for the surface buffer. 327 * 328 * @param sequence [in] The number of surface buffer. 329 * @param scalingMode [in] Scaling mode. 330 * @return {@link GSERROR_OK} 0 - Success. 331 * {@link GSERROR_INVALID_ARGUMENTS} 40001000 - Param invalid. 332 */ 333 GSError SetScalingMode(uint32_t sequence, ScalingMode scalingMode) override; 334 /** 335 * @brief Get the Scaling Mode of the surface buffer. 336 * 337 * @param sequence [in] The number of surface buffer. 338 * @param scalingMode [out] Scaling mode. 339 * @return {@link GSERROR_OK} 0 - Success. 340 * {@link GSERROR_INVALID_ARGUMENTS} 40001000 - Param invalid. 341 */ 342 GSError GetScalingMode(uint32_t sequence, ScalingMode &scalingMode) override; 343 /** 344 * @brief Set the Meta Data for the surface buffer. 345 * 346 * @param sequence [in] The number of surface buffer. 347 * @param metaData [in] Meta data info. 348 * @return {@link GSERROR_OK} 0 - Success. 349 * {@link GSERROR_INVALID_ARGUMENTS} 40001000 - Param invalid. 350 */ 351 GSError SetMetaData(uint32_t sequence, const std::vector<GraphicHDRMetaData> &metaData) override; 352 /** 353 * @brief Set the Meta Data for the surface buffer 354 * 355 * @param sequence [in] The number of surface buffer. 356 * @param key [in] The key of meta data. 357 * @param metaData [in] Meta data info. 358 * @return {@link GSERROR_OK} 0 - Success. 359 * {@link GSERROR_INVALID_ARGUMENTS} 40001000 - Param invalid. 360 */ 361 GSError SetMetaDataSet(uint32_t sequence, GraphicHDRMetadataKey key, const std::vector<uint8_t> &metaData) override; 362 /** 363 * @brief Get the meta data type of the surface buffer. 364 * 365 * @param sequence [in] The number of surface buffer. 366 * @param type [out] The meta data type. 367 * @return {@link GSERROR_OK} 0 - Success. 368 * {@link GSERROR_INVALID_ARGUMENTS} 40001000 - Param invalid. 369 */ 370 GSError QueryMetaDataType(uint32_t sequence, HDRMetaDataType &type) const override; 371 /** 372 * @brief Get the Meta Data of the surface buffer 373 * 374 * @param sequence [in] The number of surface buffer. 375 * @param metaData [out] Meta data info. 376 * @return {@link GSERROR_OK} 0 - Success. 377 * {@link GSERROR_INVALID_ARGUMENTS} 40001000 - Param invalid. 378 */ 379 GSError GetMetaData(uint32_t sequence, std::vector<GraphicHDRMetaData> &metaData) const override; 380 /** 381 * @brief Get the Meta Data of the surface buffer 382 * 383 * @param sequence [in] The number of surface buffer. 384 * @param key [in] The key of meta data. 385 * @param metaData [out] Meta data info. 386 * @return {@link GSERROR_OK} 0 - Success. 387 * {@link GSERROR_INVALID_ARGUMENTS} 40001000 - Param invalid. 388 */ 389 GSError GetMetaDataSet(uint32_t sequence, GraphicHDRMetadataKey &key, 390 std::vector<uint8_t> &metaData) const override; 391 /** 392 * @brief Set the Tunnel Handle for the surface. 393 * 394 * @param handle [in] Tunnel handle. 395 * @return {@link GSERROR_OK} 0 - Success. 396 * {@link GSERROR_INVALID_ARGUMENTS} 40001000 - Param invalid. 397 */ 398 GSError SetTunnelHandle(const GraphicExtDataHandle *handle) override; 399 /** 400 * @brief Get the Tunnel Handle of the surface. 401 * 402 * @return sptr<SurfaceTunnelHandle> Tunnel handle. 403 */ 404 sptr<SurfaceTunnelHandle> GetTunnelHandle() const override; 405 /** 406 * @brief Set the Present Timestamp for the surface buffer. 407 * 408 * @param sequence [in] The number of surface buffer. 409 * @param timestamp [in] The present time info. 410 * @return {@link GSERROR_OK} 0 - Success. 411 * {@link GSERROR_INVALID_ARGUMENTS} 40001000 - Param invalid. 412 * {@link GSERROR_NO_ENTRY} 40602000 - Buffer not in cache. 413 */ 414 GSError SetPresentTimestamp(uint32_t sequence, const GraphicPresentTimestamp ×tamp) override; 415 /** 416 * @brief Attach the buffer to the surface. 417 * 418 * @param buffer [in] Indicates the pointer to a SurfaceBuffer instance. 419 * @return {@link GSERROR_OK} 0 - Success. 420 * {@link GSERROR_INVALID_ARGUMENTS} 40001000 - Param invalid. 421 * {@link GSERROR_NO_CONSUMER} 41202000 - no consumer. 422 * {@link SURFACE_ERROR_BUFFER_STATE_INVALID} 41207000 - Buffer state invalid. 423 * {@link SURFACE_ERROR_CONSUMER_UNREGISTER_LISTENER} 41212000 - no register listener. 424 * {@link GSERROR_OUT_OF_RANGE} 40603000 - out of range. 425 */ 426 GSError AttachBuffer(sptr<SurfaceBuffer>& buffer, int32_t timeOut) override; 427 /** 428 * @brief Register surface remote object. 429 * 430 * @param client [in] The remote object. 431 * @return {@link GSERROR_OK} 0 - Success. 432 * {@link GSERROR_INVALID_ARGUMENTS} 40001000 - Param invalid. 433 */ 434 GSError RegisterSurfaceDelegator(sptr<IRemoteObject> client) override; 435 /** 436 * @brief Register release listener function. 437 * 438 * @param func [in] The callback of release function. 439 * @return {@link GSERROR_OK} 0 - Success. 440 * {@link GSERROR_INVALID_ARGUMENTS} 40001000 - Param invalid. 441 */ RegisterReleaseListener(OnReleaseFuncWithFence func)442 GSError RegisterReleaseListener(OnReleaseFuncWithFence func) override 443 { 444 return GSERROR_NOT_SUPPORT; 445 } 446 /** 447 * @brief Register user data change listener callback. 448 * 449 * @param funcName [in] The callback function name. 450 * @param func [in] The callback function. 451 * @return {@link GSERROR_OK} 0 - Success. 452 * {@link GSERROR_INVALID_ARGUMENTS} 40001000 - Param invalid. 453 */ 454 GSError RegisterUserDataChangeListener(const std::string &funcName, OnUserDataChangeFunc func) override; 455 /** 456 * @brief Unregister user data change listener callback. 457 * 458 * @param funcName [in] The callback function name. 459 * @return {@link GSERROR_OK} 0 - Success. 460 * {@link GSERROR_INVALID_ARGUMENTS} 40001000 - Param invalid. 461 */ 462 GSError UnRegisterUserDataChangeListener(const std::string &funcName) override; 463 /** 464 * @brief Clear user data change listener callback. 465 * 466 * @return {@link GSERROR_OK} 0 - Success. 467 */ 468 GSError ClearUserDataChangeListener() override; 469 /** 470 * @brief Set whether the requested buffer is in HEBC mode. 471 * 472 * @param on [in] The switch of HEBC mode. 473 */ 474 void ConsumerRequestCpuAccess(bool on) override; 475 /** 476 * @brief Attach buffer to the surface. 477 * 478 * @param buffer [in] Indicates the pointer to a SurfaceBuffer instance. 479 * @return {@link GSERROR_OK} 0 - Success. 480 * {@link GSERROR_INVALID_ARGUMENTS} 40001000 - Param invalid. 481 * {@link SURFACE_ERROR_UNKOWN} 50002000 - Inner error. 482 * {@link SURFACE_ERROR_BUFFER_IS_INCACHE} 41208000 - Buffer is in cache. 483 * {@link SURFACE_ERROR_BUFFER_QUEUE_FULL} 41209000 - Buffer queue is full. 484 */ 485 GSError AttachBufferToQueue(sptr<SurfaceBuffer> buffer) override; 486 /** 487 * @brief Detach buffer from the surface. 488 * if isReserveSlot is true, a slot in the bufferqueue will be kept 489 * empty until attachbuffer is used to fill the slot. 490 * if isReserveSlot is true, it must used with AttachBufferToQueue together. 491 * 492 * @param buffer [in] Indicates the pointer to a SurfaceBuffer instance. 493 * @param isReserveSlot [in] Is need reserve slot or not. 494 * @return {@link GSERROR_OK} 0 - Success. 495 * {@link GSERROR_INVALID_ARGUMENTS} 40001000 - Param invalid. 496 * {@link SURFACE_ERROR_UNKOWN} 50002000 - Inner error. 497 * {@link SURFACE_ERROR_BUFFER_NOT_INCACHE} 41210000 - Buffer is not in cache. 498 * {@link SURFACE_ERROR_BUFFER_STATE_INVALID} 41207000 - Buffer state is invalid. 499 */ 500 GSError DetachBufferFromQueue(sptr<SurfaceBuffer> buffer, bool isReserveSlot = false) override; 501 /** 502 * @brief Get the Transform Hint from the surface 503 * 504 * @return GraphicTransformType The type of transform hint. 505 */ 506 GraphicTransformType GetTransformHint() const override; 507 /** 508 * @brief Set the Transform Hint of the surface. 509 * 510 * @param transformHint [in] The type of transform hint. 511 * @return {@link GSERROR_OK} 0 - Success. 512 * {@link GSERROR_INVALID_ARGUMENTS} 40001000 - Param invalid. 513 */ 514 GSError SetTransformHint(GraphicTransformType transformHint) override; 515 /** 516 * @brief Get the buffer hold state. 517 * 518 * @return true The buffer hold is on. 519 * @return false The buffer hold is off. 520 */ IsBufferHold()521 inline bool IsBufferHold() override 522 { 523 if (consumer_ == nullptr) { 524 return false; 525 } 526 return consumer_->IsBufferHold(); 527 } 528 /** 529 * @brief Set the Buffer Hold for the surface. 530 * 531 * @param hold [in] Indicates the switch to bool instance. 532 */ 533 void SetBufferHold(bool hold) override; 534 /** 535 * @brief Set the Scaling Mode for the surface buffer. 536 * 537 * @param sequence [in] The number of surface buffer. 538 * @param scalingMode [in] Scaling mode. 539 * @return {@link GSERROR_OK} 0 - Success. 540 * {@link GSERROR_INVALID_ARGUMENTS} 40001000 - Param invalid. 541 */ 542 GSError SetScalingMode(ScalingMode scalingMode) override; 543 /** 544 * @brief Set the Surface Source Type for the surface. 545 * 546 * @param sourceType [in] The source type. 547 * @return {@link GSERROR_OK} 0 - Success. 548 * {@link GSERROR_INVALID_ARGUMENTS} 40001000 - Param invalid. 549 */ 550 GSError SetSurfaceSourceType(OHSurfaceSource sourceType) override; 551 /** 552 * @brief Get the Surface Source Type of the surface. 553 * 554 * @return OHSurfaceSource The source type. 555 */ 556 OHSurfaceSource GetSurfaceSourceType() const override; 557 /** 558 * @brief Set the Surface App Framework Type for the surface. 559 * 560 * @param appFrameworkType [in] The app frame work type. 561 * @return {@link GSERROR_OK} 0 - Success. 562 * {@link GSERROR_INVALID_ARGUMENTS} 40001000 - Param invalid. 563 */ 564 GSError SetSurfaceAppFrameworkType(std::string appFrameworkType) override; 565 /** 566 * @brief Get the Surface App Framework Type of the surface. 567 * 568 * @return std::string The app frame work type. 569 */ 570 std::string GetSurfaceAppFrameworkType() const override; 571 /** 572 * @brief Get the Hdr White Point Brightness from the surface. 573 * 574 * @return float The brightness value for the surface. 575 */ 576 float GetHdrWhitePointBrightness() const override; 577 /** 578 * @brief Get the Sdr White Point Brightness from the surface. 579 * 580 * @return float The brightness value for the surface. 581 */ 582 float GetSdrWhitePointBrightness() const override; 583 /** 584 * @brief Get the Surface Buffer Transform Type from the surface. 585 * 586 * @param buffer [in] Indicates the pointer to a SurfaceBuffer instance. 587 * @param transformType [out] The Transform type. 588 * @return {@link GSERROR_OK} 0 - Success. 589 * {@link GSERROR_INVALID_ARGUMENTS} 40001000 - Param invalid. 590 */ 591 GSError GetSurfaceBufferTransformType(sptr<SurfaceBuffer> buffer, GraphicTransformType *transformType) override; 592 /** 593 * @brief Check whether the surface buffer in cache. 594 * 595 * @param seqNum [in] The number of the surface buffer. 596 * @param isInCache [out] Is buffer in cache result. 597 * @return {@link GSERROR_OK} 0 - Success. 598 * {@link SURFACE_ERROR_UNKOWN} 50002000 - Internal error. 599 */ 600 GSError IsSurfaceBufferInCache(uint32_t seqNum, bool &isInCache) override; 601 /** 602 * @brief Get the Global Alpha form the surface. 603 * 604 * @param alpha [out] The Global Alpha of the surface. 605 * @return {@link GSERROR_OK} 0 - Success. 606 * {@link SURFACE_ERROR_UNKOWN} 50002000 - Internal error. 607 */ 608 GSError GetGlobalAlpha(int32_t &alpha) override; 609 /** 610 * @brief Get the Available Buffer Count from the surface. 611 * 612 * @return uint32_t The Available Buffer Count of the surface. 613 */ 614 uint32_t GetAvailableBufferCount() const override; 615 /** 616 * @brief Get the Last Flushed Desired Present Time Stamp from the surface. 617 * 618 * @param lastFlushedDesiredPresentTimeStamp [out] The Last Flushed Desired Present Time Stamp 619 * @return {@link GSERROR_OK} 0 - Success. 620 * {@link SURFACE_ERROR_UNKOWN} 50002000 - Internal error. 621 */ 622 GSError GetLastFlushedDesiredPresentTimeStamp(int64_t &lastFlushedDesiredPresentTimeStamp) const override; 623 /** 624 * @brief Get the Front Desired Present Time Stamp from the surface 625 * 626 * @param desiredPresentTimeStamp [out] The Front Desired Present Time Stamp. 627 * @param isAutoTimeStamp [out] Is auto time stamp. 628 * @return {@link GSERROR_OK} 0 - Success. 629 * {@link SURFACE_ERROR_UNKOWN} 50002000 - Internal error. 630 */ 631 GSError GetFrontDesiredPresentTimeStamp(int64_t &desiredPresentTimeStamp, bool &isAutoTimeStamp) const override; 632 /** 633 * @brief Get the Buffer Support Fast Compose from the surface. 634 * 635 * @param bufferSupportFastCompose [out] The Buffer Support Fast Compose. 636 * @return {@link GSERROR_OK} 0 - Success. 637 * {@link SURFACE_ERROR_UNKOWN} 50002000 - Internal error. 638 */ 639 GSError GetBufferSupportFastCompose(bool &bufferSupportFastCompose) override; 640 /** 641 * @brief Get the Buffer Cache Config from the surface buffer. 642 * 643 * @param buffer [in] Indicates the pointer to a SurfaceBuffer instance. 644 * @param config [out] The config info of the surface buffer. 645 * @return {@link GSERROR_OK} 0 - Success. 646 * {@link GSERROR_INVALID_ARGUMENTS} 40001000 - Param invalid. 647 * {@link SURFACE_ERROR_UNKOWN} 50002000 - Internal error. 648 */ 649 GSError GetBufferCacheConfig(const sptr<SurfaceBuffer>& buffer, BufferRequestConfig& config) override; 650 /** 651 * @brief Get the Cycle Buffers Number from the surface. 652 * 653 * @param cycleBuffersNumber [out] The Cycle Buffers Number of the surface. 654 * @return {@link GSERROR_OK} 0 - Success. 655 * {@link SURFACE_ERROR_UNKOWN} 50002000 - Inner error. 656 */ 657 GSError GetCycleBuffersNumber(uint32_t& cycleBuffersNumber) override; 658 /** 659 * @brief Set the Cycle Buffers Number for the surface. 660 * 661 * @param cycleBuffersNumber [in] The Cycle Buffers Number of the surface. 662 * @return {@link GSERROR_NOT_SUPPORT} 50102000 - Not support. 663 */ SetCycleBuffersNumber(uint32_t cycleBuffersNumber)664 GSError SetCycleBuffersNumber(uint32_t cycleBuffersNumber) override 665 { 666 (void)cycleBuffersNumber; 667 return GSERROR_NOT_SUPPORT; 668 } 669 /** 670 * @brief Get the Frame Gravity form the surface. 671 * 672 * @param frameGravity [out] The frame gravity value. 673 * @return {@link GSERROR_OK} 0 - Success. 674 * {@link SURFACE_ERROR_UNKOWN} 50002000 - Inner error. 675 */ 676 GSError GetFrameGravity(int32_t &frameGravity) override; 677 /** 678 * @brief Get the Fixed Rotation form the surface. 679 * 680 * @param fixedRotation [out] The frame rotation value. 681 * @return {@link GSERROR_OK} 0 - Success. 682 * {@link SURFACE_ERROR_UNKOWN} 50002000 - Inner error. 683 */ 684 GSError GetFixedRotation(int32_t &fixedRotation) override; 685 /** 686 * @brief Get the Last Consume Time from the surface. 687 * 688 * @param lastConsumeTime [out] The Last Consume Time. 689 * @return {@link GSERROR_OK} 0 - Success. 690 * {@link SURFACE_ERROR_UNKOWN} 50002000 - Inner error. 691 */ 692 GSError GetLastConsumeTime(int64_t &lastConsumeTime) const override; 693 /** 694 * @brief Set the Max Queue Size for the surface. 695 * 696 * @param queueSize [in] the Max Queue Size. 697 * @return {@link GSERROR_OK} 0 - Success. 698 * {@link SURFACE_ERROR_UNKOWN} 50002000 - Inner error. 699 */ 700 GSError SetMaxQueueSize(uint32_t queueSize) override; 701 /** 702 * @brief Get the Max Queue Size form the surface. 703 * 704 * @param queueSize [out] the Max Queue Size. 705 * @return {@link GSERROR_OK} 0 - Success. 706 * {@link SURFACE_ERROR_UNKOWN} 50002000 - Inner error. 707 */ 708 GSError GetMaxQueueSize(uint32_t &queueSize) const override; 709 /** 710 * @brief Acquire buffer for data consumed. 711 * 712 * @param returnValue [out] Acquire buffer return value Contains the acquired buffer information including 713 * buffer, fence, damages, and other timestamp. 714 * @return {@link GSERROR_OK} 0 - Success. 715 * {@link GSERROR_NO_BUFFER} 40601000 - no buffer. 716 */ 717 GSError AcquireBuffer(AcquireBufferReturnValue& returnValue) override; 718 /** 719 * @brief Release buffer for data production. 720 * 721 * @param sequence [in] Consumed data buffer sequence. 722 * @param fence [in] fence fd for asynchronous waiting mechanism. 723 * @return {@link GSERROR_OK} 0 - Success. 724 * {@link GSERROR_INVALID_ARGUMENTS} 40001000 - Param invalid. 725 * {@link SURFACE_ERROR_BUFFER_NOT_INCACHE} 41210000 - Buffer not in cache. 726 * {@link SURFACE_ERROR_BUFFER_STATE_INVALID} 41207000 - Buffer state invalid. 727 */ 728 GSError ReleaseBuffer(uint32_t sequence, const sptr<SyncFence>& fence) override; 729 /** 730 * @brief Sets whether the bufferqueue is used by the game 731 * @param isActiveGame [in] Flag indicating whether the queue is used by game: 732 * - true: Optimize for game usage 733 * - false: Normal operation mode 734 * @return {@link GSERROR_OK} 0 - Success. 735 * {@link SURFACE_ERROR_UNKOWN} 50002000 - Inner error. 736 */ 737 GSError SetIsActiveGame(bool isActiveGame) override; 738 /** 739 * @brief Set the playback source for Lpp video 740 * 741 * @param isShbSource [in] sensorhub sends video source 742 * @param isRsSource [in] render_service sends video source 743 * @return {@link GSERROR_OK} 0 - Success. 744 * {@link SURFACE_ERROR_UNKNOWN} 50002000 - Inner error. 745 * {@link GSERROR_TYPE_ERROR} 41204000 - Inner error. 746 * {@link GSERROR_OUT_OF_RANGE} 40603000 - Inner error. 747 */ 748 GSError SetLppDrawSource(bool isShbSource, bool isRsSource) override; 749 /** 750 * @brief Get the alpha type for the surface. 751 * 752 * @param alphaType [in] the alpha type 753 * @return {@link GSERROR_OK} 0 - Success. 754 * {@link SURFACE_ERROR_UNKNOWN} 50002000 - Inner error. 755 */ 756 GSError GetAlphaType(GraphicAlphaType &alphaType) override; 757 /** 758 * @brief Sets whether alloc takes priority over reuse when request buffer 759 * @param isPriorityAlloc [in] Flag indicating whether alloc takes priority over reuse when request buffer: 760 * - true: Alloc takes priority over reuse 761 * - false: Reuse takes priority over alloc 762 * @return {@link GSERROR_OK} 0 - Success. 763 * {@link SURFACE_ERROR_UNKOWN} 50002000 - Inner error. 764 */ 765 GSError SetIsPriorityAlloc(bool isPriorityAlloc) override; 766 private: 767 std::map<std::string, std::string> userData_; 768 sptr<BufferQueueProducer> producer_ = nullptr; 769 sptr<BufferQueueConsumer> consumer_ = nullptr; 770 std::string name_ = "not init"; 771 std::map<std::string, OnUserDataChangeFunc> onUserDataChange_; 772 std::mutex lockMutex_; 773 uint64_t uniqueId_ = 0; 774 std::atomic<bool> hasRegistercallBackForRT_ = false; 775 std::atomic<bool> hasRegistercallBackForRedraw_ = false; 776 std::atomic<bool> isFirstBuffer_ = true; 777 std::atomic<bool> supportFastCompose_ = false; 778 }; 779 } // namespace OHOS 780 781 #endif // FRAMEWORKS_SURFACE_INCLUDE_CONSUMER_SURFACE_H 782