1 /* 2 * Copyright (c) 2021-2025 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_PRODUCER_SURFACE_H 17 #define FRAMEWORKS_SURFACE_INCLUDE_PRODUCER_SURFACE_H 18 19 /** 20 * @file producer_surface.h 21 * @brief producer of surface. 22 * Through this class, memory can be allocated from the BufferQueue for data production, 23 * and the memory data can be delivered to the consumer for data consumption.\n 24 */ 25 #include <atomic> 26 #include <ibuffer_producer.h> 27 #include <map> 28 #include <string> 29 #include <surface.h> 30 #include <vector> 31 #include "buffer_queue.h" 32 #include "buffer_queue_consumer.h" 33 #include "producer_surface_delegator.h" 34 #include "surface_buffer.h" 35 36 struct NativeWindow; 37 namespace OHOS { 38 class ProducerSurface : public Surface { 39 public: 40 ProducerSurface(sptr<IBufferProducer>& producer); 41 virtual ~ProducerSurface(); 42 /** 43 * @brief Initialization function. 44 * 45 * @return {@link GSERROR_OK} 0 - Success. 46 */ 47 GSError Init(); 48 /** 49 * @brief Determine if it is the consumer. 50 * 51 * @return true - is consumer. 52 * @return false - is not consumer. 53 */ 54 bool IsConsumer() const override; 55 /** 56 * @brief Get the Producer from the surface. 57 * 58 * @return sptr<IBufferProducer> - The object of producer. 59 */ 60 sptr<IBufferProducer> GetProducer() const override; 61 /** 62 * @brief Request buffer for data production. 63 * When the fenceFd is used up, you need to close it. 64 * 65 * @param buffer [out] The buffer for data production. 66 * @param fence [out] fence fd for asynchronous waiting mechanism. 67 * @param config [in] The parameter type for requesting a buffer. 68 * @return {@link GSERROR_OK} 0 - Success. 69 * {@link GSERROR_INVALID_ARGUMENTS} 40001000 - Param invalid. 70 * {@link GSERROR_NO_CONSUMER} 41202000 - no consumer. 71 * {@link GSERROR_NO_BUFFER} 40601000 - no buffer. 72 * {@link} GSERROR_CONSUMER_IS_CONNECTED 41206000 - consumer is connected already. 73 * 74 * @see FlushBuffer 75 */ 76 GSError RequestBuffer(sptr<SurfaceBuffer>& buffer, 77 int32_t &fence, BufferRequestConfig &config) override; 78 /** 79 * @brief Request buffers for data production. 80 * 81 * @param buffer [out] The buffers for data production. 82 * @param fence [out] fence fds for asynchronous waiting mechanism. 83 * @param config [in] The parameter type for requesting a buffer. 84 * @return {@link GSERROR_OK} 0 - Success. 85 * {@link GSERROR_INVALID_ARGUMENTS} 40001000 - Param invalid. 86 * {@link GSERROR_NO_CONSUMER} 41202000 - no consumer. 87 * {@link GSERROR_NO_BUFFER} 40601000 - no buffer. 88 * {@link} GSERROR_CONSUMER_IS_CONNECTED 41206000 - consumer is connected already. 89 * 90 * @see FlushBuffers 91 */ 92 GSError RequestBuffers(std::vector<sptr<SurfaceBuffer>> &buffers, 93 std::vector<sptr<SyncFence>> &fences, BufferRequestConfig &config) override; 94 /** 95 * @brief Cancel the requested buffer. 96 * Change buffer state from requested to released. 97 * @param buffer [in] Indicates the pointer to a SurfaceBuffer instance. 98 * @return {@link GSERROR_OK} 0 - Success. 99 * {@link SURFACE_ERROR_UNKOWN} 50002000 - Internal error. 100 * {@link SURFACE_ERROR_BUFFER_NOT_INCACHE} 41210000 - Buffer not in cache. 101 * {@link SURFACE_ERROR_BUFFER_STATE_INVALID} 41207000 - Buffer state invalid. 102 */ 103 GSError CancelBuffer(sptr<SurfaceBuffer>& buffer) override; 104 /** 105 * @brief Flush buffer to data consumption. 106 * 107 * @param buffer [in] Processed data buffer. 108 * @param fence [in] fence fd for asynchronous waiting mechanism. 109 * @param config [in] The parameter type for flushing a buffer. 110 * @return {@link GSERROR_OK} 0 - Success. 111 * {@link GSERROR_INVALID_ARGUMENTS} 40001000 - Param invalid. 112 * {@link GSERROR_NO_CONSUMER} 41202000 - no consumer. 113 * {@link SURFACE_ERROR_BUFFER_NOT_INCACHE} 41210000 - Buffer not in cache. 114 * {@link SURFACE_ERROR_BUFFER_STATE_INVALID} 41207000 - Buffer state invalid. 115 * {@link SURFACE_ERROR_CONSUMER_UNREGISTER_LISTENER} 41212000 - no register listener. 116 */ 117 GSError FlushBuffer(sptr<SurfaceBuffer>& buffer, 118 int32_t fence, BufferFlushConfig &config) override; 119 /** 120 * @brief Flush buffers to data consumption. 121 * 122 * @param buffer [in] Processed data buffers. 123 * @param fence [in] fence fds for asynchronous waiting mechanism. 124 * @param config [in] The parameter type for flushing buffers. 125 * @return {@link GSERROR_OK} 0 - Success. 126 * {@link GSERROR_INVALID_ARGUMENTS} 40001000 - Param invalid. 127 * {@link GSERROR_NO_CONSUMER} 41202000 - no consumer. 128 * {@link SURFACE_ERROR_BUFFER_NOT_INCACHE} 41210000 - Buffer not in cache. 129 * {@link SURFACE_ERROR_BUFFER_STATE_INVALID} 41207000 - Buffer state invalid. 130 * {@link SURFACE_ERROR_CONSUMER_UNREGISTER_LISTENER} 41212000 - no register listener. 131 */ 132 GSError FlushBuffers(const std::vector<sptr<SurfaceBuffer>> &buffers, 133 const std::vector<sptr<SyncFence>> &fences, const std::vector<BufferFlushConfigWithDamages> &config) override; 134 /** 135 * @brief Request buffer for data production. 136 * 137 * @param buffer [out] The buffer for data production. 138 * @param fence [out] fence fd for asynchronous waiting mechanism. 139 * @param config [in] The parameter type for requesting a buffer. 140 * @return {@link GSERROR_OK} 0 - Success. 141 * {@link GSERROR_INVALID_ARGUMENTS} 40001000 - Param invalid. 142 * {@link GSERROR_NO_CONSUMER} 41202000 - no consumer. 143 * {@link GSERROR_NO_BUFFER} 40601000 - no buffer. 144 * {@link} GSERROR_CONSUMER_IS_CONNECTED 41206000 - consumer is connected already. 145 * 146 * @see FlushBuffer 147 */ 148 GSError RequestBuffer(sptr<SurfaceBuffer>& buffer, 149 sptr<SyncFence>& fence, BufferRequestConfig &config) override; 150 /** 151 * @brief Flush buffer to data consumption. 152 * 153 * @param buffer [in] Processed data buffer. 154 * @param fence [in] fence fd for asynchronous waiting mechanism. 155 * @param config [in] The parameter type for flushing a buffer. 156 * @return {@link GSERROR_OK} 0 - Success. 157 * {@link GSERROR_INVALID_ARGUMENTS} 40001000 - Param invalid. 158 * {@link GSERROR_NO_CONSUMER} 41202000 - no consumer. 159 * {@link SURFACE_ERROR_BUFFER_NOT_INCACHE} 41210000 - Buffer not in cache. 160 * {@link SURFACE_ERROR_BUFFER_STATE_INVALID} 41207000 - Buffer state invalid. 161 * {@link SURFACE_ERROR_CONSUMER_UNREGISTER_LISTENER} 41212000 - no register listener. 162 */ 163 GSError FlushBuffer(sptr<SurfaceBuffer>& buffer, 164 const sptr<SyncFence>& fence, BufferFlushConfig &config) override; 165 /** 166 * @brief Get the Last Flushed Buffer object. 167 * 168 * @param buffer [out] Indicates the pointer to a SurfaceBuffer instance. 169 * @param fence [out] fence fd for asynchronous waiting mechanism. 170 * @param matrix [out] Orientation matrix. 171 * @param isUseNewMatrix [in] Is use new matrix switch. 172 * @return {@link GSERROR_OK} 0 - Success. 173 * {@link GSERROR_INVALID_ARGUMENTS} 40001000 - Param invalid. 174 * {@link SURFACE_ERROR_BUFFER_STATE_INVALID} 41207000 - Buffer state invalid. 175 * {@link SURFACE_ERROR_UNKOWN} 50002000 - Internal error. 176 * {@link SURFACE_ERROR_NOT_SUPPORT} 50102000 - Not surport usage. 177 */ 178 GSError GetLastFlushedBuffer(sptr<SurfaceBuffer>& buffer, 179 sptr<SyncFence>& fence, float matrix[16], bool isUseNewMatrix = false) override; 180 /** 181 * @brief Flush buffer to data consumption. 182 * 183 * @param buffer [in] Processed data buffer. 184 * @param fence [in] fence fd for asynchronous waiting mechanism. 185 * @param config [in] The parameter type for flushing a buffer. 186 * @return {@link GSERROR_OK} 0 - Success. 187 * {@link GSERROR_INVALID_ARGUMENTS} 40001000 - Param invalid. 188 * {@link GSERROR_NO_CONSUMER} 41202000 - no consumer. 189 * {@link SURFACE_ERROR_BUFFER_NOT_INCACHE} 41210000 - Buffer not in cache. 190 * {@link SURFACE_ERROR_BUFFER_STATE_INVALID} 41207000 - Buffer state invalid. 191 * {@link SURFACE_ERROR_CONSUMER_UNREGISTER_LISTENER} 41212000 - no register listener. 192 */ 193 GSError FlushBuffer(sptr<SurfaceBuffer>& buffer, const sptr<SyncFence>& fence, 194 BufferFlushConfigWithDamages &config, bool needLock = true) override; 195 /** 196 * @brief Attach the buffer to the surface. 197 * 198 * @param buffer [in] Indicates the pointer to a SurfaceBuffer instance. 199 * @return {@link GSERROR_OK} 0 - Success. 200 * {@link GSERROR_INVALID_ARGUMENTS} 40001000 - Param invalid. 201 * {@link GSERROR_NO_CONSUMER} 41202000 - no consumer. 202 * {@link SURFACE_ERROR_BUFFER_STATE_INVALID} 41207000 - Buffer state invalid. 203 * {@link SURFACE_ERROR_CONSUMER_UNREGISTER_LISTENER} 41212000 - no register listener. 204 * {@link GSERROR_OUT_OF_RANGE} 40603000 - out of range. 205 */ 206 GSError AttachBuffer(sptr<SurfaceBuffer>& buffer) override; 207 /** 208 * @brief Attach the buffer to the surface. 209 * 210 * @param buffer [in] Indicates the pointer to a SurfaceBuffer instance. 211 * @param timeOut [in] Timeout interval. 212 * @return {@link GSERROR_OK} 0 - Success. 213 * {@link GSERROR_INVALID_ARGUMENTS} 40001000 - Param invalid. 214 * {@link GSERROR_NO_CONSUMER} 41202000 - no consumer. 215 * {@link SURFACE_ERROR_BUFFER_STATE_INVALID} 41207000 - Buffer state invalid. 216 * {@link SURFACE_ERROR_CONSUMER_UNREGISTER_LISTENER} 41212000 - no register listener. 217 * {@link GSERROR_OUT_OF_RANGE} 40603000 - out of range. 218 */ 219 GSError AttachBuffer(sptr<SurfaceBuffer>& buffer, int32_t timeOut) override; 220 /** 221 * @brief Detach the buffer from the surface. 222 * 223 * @param buffer [in] Indicates the pointer to a SurfaceBuffer instance. 224 * @return {@link GSERROR_OK} 0 - Success. 225 * {@link GSERROR_INVALID_ARGUMENTS} 40001000 - Param invalid. 226 * {@link GSERROR_NO_ENTRY} 40602000 - Buffer state invalid or buffer not in cache. 227 */ 228 GSError DetachBuffer(sptr<SurfaceBuffer>& buffer) override; 229 /** 230 * @brief Get the Queue Size from the surface. 231 * 232 * @return uint32_t The buffer queue size. 233 */ 234 uint32_t GetQueueSize() override; 235 /** 236 * @brief Set the Queue Size for the surface. 237 * 238 * @param queueSize [in] The buffer queue size. 239 * @return {@link GSERROR_OK} 0 - Success. 240 * {@link GSERROR_INVALID_ARGUMENTS} 40001000 - Param invalid. 241 */ 242 GSError SetQueueSize(uint32_t queueSize) override; 243 /** 244 * @brief Get the Name of the surface. 245 * 246 * @return const std::string& The name of The surface. 247 */ 248 const std::string& GetName() override; 249 /** 250 * @brief Get the Unique Id of the surface. 251 * 252 * @return uint64_t The Unique Id of the surface. 253 */ 254 uint64_t GetUniqueId() const override; 255 /** 256 * @brief Get the Default Width of the surface. 257 * 258 * @return int32_t The default width of the surface. 259 */ 260 int32_t GetDefaultWidth() override; 261 /** 262 * @brief Get the Default height of the surface. 263 * 264 * @return int32_t The default height of the surface. 265 */ 266 int32_t GetDefaultHeight() override; 267 /** 268 * @brief Set the Default Usage of the surface. 269 * 270 * @param usage [in] the Default Usage of the surface. 271 * @return {@link GSERROR_OK} 0 - Success. 272 * {@link GSERROR_INVALID_ARGUMENTS} 40001000 - Param invalid. 273 */ 274 GSError SetDefaultUsage(uint64_t usage) override; 275 /** 276 * @brief Get the Default Usage of the surface. 277 * 278 * @return uint64_t the Default Usage of the surface. 279 */ 280 uint64_t GetDefaultUsage() override; 281 /** 282 * @brief Set the Buffer Hold for the surface. 283 * 284 * @param hold [in] Indicates the switch to bool instance. 285 */ 286 void SetBufferHold(bool hold) override; 287 /** 288 * @brief Set the Buffer Realloc Flag. 289 * 290 * @param flag [in] Indicates the switch to bool instance. 291 */ 292 GSError SetBufferReallocFlag(bool flag) override; 293 /** 294 * @brief Set the User Data for the surface. 295 * 296 * @param key [in] Indicates the key of the user data. 297 * @param val [in] Indicates the val of the user data. 298 * @return {@link GSERROR_OK} 0 - Success. 299 * {@link GSERROR_OUT_OF_RANGE} 40603000 - Size out of range. 300 * {@link GSERROR_API_FAILED} 50001000 - Set value repeat. 301 */ 302 GSError SetUserData(const std::string &key, const std::string &val) override; 303 /** 304 * @brief Get the User Data of the surface. 305 * 306 * @param key [in] Indicates the key of the user data. 307 * @return std::string The val of the user data. 308 */ 309 std::string GetUserData(const std::string &key) override; 310 /** 311 * @brief Register release listener function. 312 * 313 * @param func [in] The callback of release function. 314 * @return {@link GSERROR_OK} 0 - Success. 315 * {@link GSERROR_INVALID_ARGUMENTS} 40001000 - Param invalid. 316 */ 317 GSError RegisterReleaseListener(OnReleaseFunc func) override; 318 /** 319 * @brief Register release listener function. 320 * 321 * @param func [in] The callback of release function. 322 * @return {@link GSERROR_OK} 0 - Success. 323 * {@link GSERROR_INVALID_ARGUMENTS} 40001000 - Param invalid. 324 */ 325 GSError RegisterReleaseListener(OnReleaseFuncWithFence func) override; 326 /** 327 * @brief Register release listener function. 328 * 329 * @param func [in] The callback of release function. 330 * @return {@link GSERROR_OK} 0 - Success. 331 * {@link GSERROR_INVALID_ARGUMENTS} 40001000 - Param invalid. 332 */ 333 GSError RegisterReleaseListenerBackup(OnReleaseFuncWithFence func) override; 334 /** 335 * @brief Unregister release listener function. 336 * 337 * @return {@link GSERROR_OK} 0 - Success. 338 * {@link GSERROR_INVALID_ARGUMENTS} 40001000 - Param invalid. 339 */ 340 GSError UnRegisterReleaseListener() override; 341 /** 342 * @brief Unregister release listener function. 343 * 344 * @return {@link GSERROR_OK} 0 - Success. 345 * {@link GSERROR_INVALID_ARGUMENTS} 40001000 - Param invalid. 346 */ 347 GSError UnRegisterReleaseListenerBackup() override; 348 /** 349 * @brief Dump info of the surface. 350 * 351 * @param result The info of the surface. 352 */ Dump(std::string & result)353 void Dump(std::string &result) const override {}; 354 /** 355 * @brief Clean the surface buffer cache. 356 * This interface will empty all caches of the current process. 357 * 358 * @param cleanAll [in] Clean all buffer or reserve one buffer. 359 * @return {@link GSERROR_OK} 0 - Success. 360 * {@link GSERROR_INVALID_ARGUMENTS} 40001000 - Param invalid. 361 * {@link GSERROR_CONSUMER_IS_CONNECTED} 41206000 - surface is connected by other client. 362 */ 363 GSError CleanCache(bool cleanAll = false) override; 364 /** 365 * @brief Clean the surface buffer cache and inform consumer. 366 * This interface will empty all caches of the current process. 367 * 368 * @return {@link GSERROR_OK} 0 - Success. 369 * {@link GSERROR_INVALID_ARGUMENTS} 40001000 - Param invalid. 370 */ 371 GSError GoBackground() override; 372 /** 373 * @brief Set the Transform type for the surface. 374 * 375 * @param transform The Transform type. 376 * @return {@link GSERROR_OK} 0 - Success. 377 * {@link GSERROR_INVALID_ARGUMENTS} 40001000 - Param invalid. 378 */ 379 GSError SetTransform(GraphicTransformType transform) override; 380 /** 381 * @brief Get the Transform type from the surface. 382 * 383 * @return GraphicTransformType The Transform type. 384 */ 385 GraphicTransformType GetTransform() const override; 386 /** 387 * @brief The client establishes a connection to the server. 388 * 389 * @return {@link GSERROR_OK} 0 - Success. 390 * {@link GSERROR_INVALID_ARGUMENTS} 40001000 - Param invalid. 391 * {@link GSERROR_CONSUMER_IS_CONNECTED} 41206000 - surface is connected by other client. 392 */ 393 GSError Connect() override; 394 /** 395 * @brief Terminate the client-server connection. 396 * 397 * @return {@link GSERROR_OK} 0 - Success. 398 * {@link GSERROR_INVALID_ARGUMENTS} 40001000 - Param invalid. 399 * {@link SURFACE_ERROR_CONSUMER_DISCONNECTED} 41211000 - surface is already disconnected. 400 */ 401 GSError Disconnect() override; 402 /** 403 * @brief Set the Scaling Mode for the surface buffer. 404 * 405 * @param sequence [in] The number of surface buffer. 406 * @param scalingMode [in] Scaling mode. 407 * @return {@link GSERROR_OK} 0 - Success. 408 * {@link GSERROR_INVALID_ARGUMENTS} 40001000 - Param invalid. 409 */ 410 GSError SetScalingMode(uint32_t sequence, ScalingMode scalingMode) override; 411 /** 412 * @brief Set the Meta Data for the surface buffer 413 * 414 * @param sequence [in] The number of surface buffer. 415 * @param metaData [in] Meta data info. 416 * @return {@link GSERROR_OK} 0 - Success. 417 * {@link GSERROR_INVALID_ARGUMENTS} 40001000 - Param invalid. 418 */ 419 GSError SetMetaData(uint32_t sequence, const std::vector<GraphicHDRMetaData> &metaData) override; 420 /** 421 * @brief Set the Meta Data for the surface buffer 422 * 423 * @param sequence [in] The number of surface buffer. 424 * @param key [in] The key of meta data. 425 * @param metaData [in] Meta data info. 426 * @return {@link GSERROR_OK} 0 - Success. 427 * {@link GSERROR_INVALID_ARGUMENTS} 40001000 - Param invalid. 428 */ 429 GSError SetMetaDataSet(uint32_t sequence, GraphicHDRMetadataKey key, const std::vector<uint8_t> &metaData) override; 430 /** 431 * @brief Set the Tunnel Handle for the surface. 432 * 433 * @param handle [in] Tunnel handle. 434 * @return {@link GSERROR_OK} 0 - Success. 435 * {@link GSERROR_INVALID_ARGUMENTS} 40001000 - Param invalid. 436 */ 437 GSError SetTunnelHandle(const GraphicExtDataHandle *handle) override; 438 /** 439 * @brief Get the Present Timestamp from the surface buffer. 440 * 441 * @param sequence [in] The number of surface buffer. 442 * @param type [in] Present timestamp type. 443 * @param time [out] The present time info. 444 * @return {@link GSERROR_OK} 0 - Success. 445 * {@link GSERROR_INVALID_ARGUMENTS} 40001000 - Param invalid. 446 * {@link GSERROR_NO_ENTRY} 40602000 - Buffer not in cache. 447 * {@link GSERROR_TYPE_ERROR 41204000} - The type is not support. 448 */ 449 GSError GetPresentTimestamp(uint32_t sequence, GraphicPresentTimestampType type, int64_t &time) const override; 450 /** 451 * @brief Set the Wptr Native Window for the Surface. 452 * 453 * @param nativeWindow [in] Indicates the pointer to a nativewindow instance. 454 * @return {@link GSERROR_OK} 0 - Success. 455 * {@link GSERROR_INVALID_ARGUMENTS} 40001000 - Param invalid. 456 */ 457 GSError SetWptrNativeWindowToPSurface(void* nativeWindow) override; 458 /** 459 * @brief Register surface remote object. 460 * 461 * @param client [in] The remote object. 462 * @return {@link GSERROR_OK} 0 - Success. 463 * {@link GSERROR_INVALID_ARGUMENTS} 40001000 - Param invalid. 464 */ 465 virtual GSError RegisterSurfaceDelegator(sptr<IRemoteObject> client) override; 466 /** 467 * @brief Register user data change listener callback. 468 * 469 * @param funcName [in] The callback function name. 470 * @param func [in] The callback function. 471 * @return {@link GSERROR_OK} 0 - Success. 472 * {@link GSERROR_INVALID_ARGUMENTS} 40001000 - Param invalid. 473 */ 474 GSError RegisterUserDataChangeListener(const std::string &funcName, OnUserDataChangeFunc func) override; 475 /** 476 * @brief Unregister user data change listener callback. 477 * 478 * @param funcName [in] The callback function name. 479 * @return {@link GSERROR_OK} 0 - Success. 480 * {@link GSERROR_INVALID_ARGUMENTS} 40001000 - Param invalid. 481 */ 482 GSError UnRegisterUserDataChangeListener(const std::string &funcName) override; 483 /** 484 * @brief Clear user data change listener callback. 485 * 486 * @return {@link GSERROR_OK} 0 - Success. 487 */ 488 GSError ClearUserDataChangeListener() override; 489 /** 490 * @brief Attach buffer to the surface. 491 * 492 * @param buffer [in] Indicates the pointer to a SurfaceBuffer instance. 493 * @return {@link GSERROR_OK} 0 - Success. 494 * {@link GSERROR_INVALID_ARGUMENTS} 40001000 - Param invalid. 495 * {@link SURFACE_ERROR_UNKOWN} 50002000 - Inner error. 496 * {@link SURFACE_ERROR_BUFFER_IS_INCACHE} 41208000 - Buffer is in cache. 497 * {@link SURFACE_ERROR_BUFFER_QUEUE_FULL} 41209000 - Buffer queue is full. 498 */ 499 GSError AttachBufferToQueue(sptr<SurfaceBuffer> buffer) override; 500 /** 501 * @brief Detach buffer from the surface. 502 * 503 * @param buffer [in] Indicates the pointer to a SurfaceBuffer instance. 504 * @param isReserveSlot [in] Is need reserve slot or not. 505 * @return {@link GSERROR_OK} 0 - Success. 506 * {@link GSERROR_INVALID_ARGUMENTS} 40001000 - Param invalid. 507 * {@link SURFACE_ERROR_UNKOWN} 50002000 - Inner error. 508 * {@link SURFACE_ERROR_BUFFER_NOT_INCACHE} 41210000 - Buffer is not in cache. 509 * {@link SURFACE_ERROR_BUFFER_STATE_INVALID} 41207000 - Buffer state is invalid. 510 */ 511 GSError DetachBufferFromQueue(sptr<SurfaceBuffer> buffer, bool isReserveSlot = false) override; 512 /** 513 * @brief Get the Transform Hint from the surface 514 * 515 * @return GraphicTransformType The type of transform hint. 516 */ 517 GraphicTransformType GetTransformHint() const override; 518 /** 519 * @brief Set the Transform Hint of the surface. 520 * 521 * @param transformHint [in] The type of transform hint. 522 * @return {@link GSERROR_OK} 0 - Success. 523 * {@link GSERROR_INVALID_ARGUMENTS} 40001000 - Param invalid. 524 */ 525 GSError SetTransformHint(GraphicTransformType transformHint) override; 526 /** 527 * @brief Set the Buffer Name. 528 * 529 * @param name [in] The buffer name. 530 * @return {@link GSERROR_OK} 0 - Success. 531 */ 532 GSError SetBufferName(const std::string &name) override; 533 /** 534 * @brief Set the Request Width And Height for the surface. 535 * 536 * @param width [in] The width of the surface. 537 * @param height [in] The height of the surface. 538 */ 539 void SetRequestWidthAndHeight(int32_t width, int32_t height) override; 540 /** 541 * @brief Get the Request Width of the surface. 542 * 543 * @return int32_t The width of the surface. 544 */ 545 int32_t GetRequestWidth() override; 546 /** 547 * @brief Get the Request Height of the surface. 548 * 549 * @return int32_t The height of the surface. 550 */ 551 int32_t GetRequestHeight() override; 552 /** 553 * @brief Set the Scaling Mode for the surface. 554 * 555 * @param scalingMode [in] The scaling mode. 556 * @return {@link GSERROR_OK} 0 - Success. 557 * {@link GSERROR_INVALID_ARGUMENTS} 40001000 - Param invalid. 558 */ 559 GSError SetScalingMode(ScalingMode scalingMode) override; 560 /** 561 * @brief Set the Surface Source Type for the surface. 562 * 563 * @param sourceType [in] The source type. 564 * @return {@link GSERROR_OK} 0 - Success. 565 * {@link GSERROR_INVALID_ARGUMENTS} 40001000 - Param invalid. 566 */ 567 GSError SetSurfaceSourceType(OHSurfaceSource sourceType) override; 568 /** 569 * @brief Get the Surface Source Type of the surface. 570 * 571 * @return OHSurfaceSource The source type. 572 */ 573 OHSurfaceSource GetSurfaceSourceType() const override; 574 /** 575 * @brief Set the Surface App Framework Type for the surface. 576 * 577 * @param appFrameworkType [in] The app frame work type. 578 * @return {@link GSERROR_OK} 0 - Success. 579 * {@link GSERROR_INVALID_ARGUMENTS} 40001000 - Param invalid. 580 */ 581 GSError SetSurfaceAppFrameworkType(std::string appFrameworkType) override; 582 /** 583 * @brief Get the Surface App Framework Type of the surface. 584 * 585 * @return std::string The app frame work type. 586 */ 587 std::string GetSurfaceAppFrameworkType() const override; 588 /** 589 * @brief Set the Window Config for the surface. 590 * 591 * @param config [in] The buffer request config. 592 */ 593 void SetWindowConfig(const BufferRequestConfig& config) override; 594 /** 595 * @brief Set the Window Config Width And Height for the surface. 596 * 597 * @param width [in] The width of the surface. 598 * @param height [in] The height of the surface. 599 */ 600 void SetWindowConfigWidthAndHeight(int32_t width, int32_t height) override; 601 /** 602 * @brief Set the Window Config Stride for the surface. 603 * 604 * @param stride [in] The stride type of the surface. 605 */ 606 void SetWindowConfigStride(int32_t stride) override; 607 /** 608 * @brief Set the Window Config Format for the surface. 609 * 610 * @param format [in] The format type of the surface. 611 */ 612 void SetWindowConfigFormat(int32_t format) override; 613 /** 614 * @brief Set the Window Config Usage for the surface. 615 * 616 * @param usage [in] The usage type of the surface. 617 */ 618 void SetWindowConfigUsage(uint64_t usage) override; 619 /** 620 * @brief Set the Window Config Timeout for the surface. 621 * 622 * @param timeout [in] The timeout of the surface. 623 */ 624 void SetWindowConfigTimeout(int32_t timeout) override; 625 /** 626 * @brief Set the Window Config Color Gamut for the surface. 627 * 628 * @param colorGamut [in] The colorGamut type of the surface. 629 */ 630 void SetWindowConfigColorGamut(GraphicColorGamut colorGamut) override; 631 /** 632 * @brief Set the Window Config Transform for the surface. 633 * 634 * @param transform [in] The transform type of the surface. 635 */ 636 void SetWindowConfigTransform(GraphicTransformType transform) override; 637 /** 638 * @brief Get the Window Config from the surface. 639 * 640 * @return BufferRequestConfig The config of the surface buffer. 641 */ 642 BufferRequestConfig GetWindowConfig() override; 643 /** 644 * @brief Set the Hdr White Point Brightness for the surface. 645 * 646 * @param brightness [in] The brightness value for the surface. 647 * @return {@link GSERROR_OK} 0 - Success. 648 * {@link GSERROR_INVALID_ARGUMENTS} 40001000 - Param invalid. 649 */ 650 GSError SetHdrWhitePointBrightness(float brightness) override; 651 /** 652 * @brief Set the Sdr White Point Brightness for the surface. 653 * 654 * @param brightness [in] The brightness value for the surface. 655 * @return {@link GSERROR_OK} 0 - Success. 656 * {@link GSERROR_INVALID_ARGUMENTS} 40001000 - Param invalid. 657 */ 658 GSError SetSdrWhitePointBrightness(float brightness) override; 659 /** 660 * @brief Get the Producer Init Info from the surface. 661 * 662 * @param info [out] The producer init information. 663 * @return {@link GSERROR_OK} 0 - Success. 664 * {@link GSERROR_INVALID_ARGUMENTS} 40001000 - Param invalid. 665 */ 666 GSError GetProducerInitInfo(ProducerInitInfo &info) override; 667 /** 668 * @brief Acquire The last flushed buffer form the surface. 669 * 670 * @param buffer [out] Indicates the pointer to a SurfaceBuffer instance. 671 * @param fence [out] Fence fd for asynchronous waiting mechanism. 672 * @param matrix [out] Orientation matrix. 673 * @param matrixSize [in] The matrix array size. 674 * @param isUseNewMatrix [in] Is use new matrix switch. 675 * @return {@link GSERROR_OK} 0 - Success. 676 * {@link GSERROR_INVALID_ARGUMENTS} 40001000 - Param invalid. 677 * {@link SURFACE_ERROR_BUFFER_STATE_INVALID} 41207000 - Buffer state invalid. 678 * {@link SURFACE_ERROR_UNKOWN} 50002000 - Internal error. 679 * {@link SURFACE_ERROR_NOT_SUPPORT} 50102000 - Not surport usage. 680 */ 681 GSError AcquireLastFlushedBuffer(sptr<SurfaceBuffer> &buffer, sptr<SyncFence> &fence, 682 float matrix[16], uint32_t matrixSize, bool isUseNewMatrix) override; 683 /** 684 * @brief Give back the last flushed buffer to the surface. 685 * 686 * @param buffer [in] Indicates the pointer to a SurfaceBuffer instance. 687 * @return {@link GSERROR_OK} 0 - Success. 688 * {@link GSERROR_INVALID_ARGUMENTS} 40001000 - Param invalid. 689 * {@link SURFACE_ERROR_BUFFER_STATE_INVALID} 41207000 - Buffer state invalid. 690 */ 691 GSError ReleaseLastFlushedBuffer(sptr<SurfaceBuffer> buffer) override; 692 /** 693 * @brief Set the Global Alpha for the surface. 694 * 695 * @param alpha [in] The Global Alpha of the surface. 696 * @return {@link GSERROR_OK} 0 - Success. 697 * {@link GSERROR_INVALID_ARGUMENTS} 40001000 - Param invalid. 698 */ 699 GSError SetGlobalAlpha(int32_t alpha) override; 700 /** 701 * @brief Set the request buffer isblocked for the surface. 702 * Blocking mode: Keep the original logic unchanged. 703 * Non-blocking mode: 704 * 1.If all buffers are requested and no buffer is in flushed state, immediately return GSERROR_NO_BUFFER. 705 * 2.If all buffers are requested and there are buffers in flushed state, return the earliest flushed buffer 706 * to the user through the RequestBuffer interface. 707 * 708 * @param noblock [in] Request buffer mode flag: 709 * - false: Blocking request mode (default) 710 * - true: Non-blocking request mode 711 * @return {@link GSERROR_OK} 0 - Success. 712 * {@link GSERROR_INVALID_ARGUMENTS} 40001000 - Param invalid. 713 */ 714 GSError SetRequestBufferNoblockMode(bool noblock = false) override; 715 /** 716 * @brief Check the surface is in hebc white list. 717 * 718 * @return true Is in hebc white list. 719 * @return false Not in the hebc white list. 720 */ IsInHebcList()721 virtual bool IsInHebcList() override 722 { 723 return initInfo_.isInHebcList; 724 } 725 /** 726 * @brief Request and detach the buffer from the surface. 727 * 728 * @param buffer [out] Indicates the pointer to a SurfaceBuffer instance. 729 * @param fence [out] Fence fd for asynchronous waiting mechanism. 730 * @param config [in] The parameter type for requesting the buffer. 731 * @return {@link GSERROR_OK} 0 - Success. 732 * {@link GSERROR_INVALID_ARGUMENTS} 40001000 - Param invalid. 733 * {@link GSERROR_NO_CONSUMER} 41202000 - no consumer. 734 * {@link GSERROR_NO_BUFFER} 40601000 - no buffer. 735 * {@link} GSERROR_CONSUMER_IS_CONNECTED 41206000 - consumer is connected already. 736 * {@link SURFACE_ERROR_UNKOWN} 50002000 - Inner error. 737 */ 738 GSError RequestAndDetachBuffer(sptr<SurfaceBuffer>& buffer, sptr<SyncFence>& fence, 739 BufferRequestConfig& config) override; 740 /** 741 * @brief Attach and flush the buffer to the surface. 742 * 743 * @param buffer [in] Indicates the pointer to a SurfaceBuffer instance. 744 * @param fence [in] Fence fd for asynchronous waiting mechanism. 745 * @param config [in] The parameter type for flushing the buffer. 746 * @param needMap [in] Is need map. 747 * @return {@link GSERROR_OK} 0 - Success. 748 * {@link GSERROR_INVALID_ARGUMENTS} 40001000 - Param invalid. 749 * {@link SURFACE_ERROR_UNKOWN} 50002000 - Inner error. 750 * {@link SURFACE_ERROR_BUFFER_IS_INCACHE} 41208000 - Buffer is in cache. 751 * {@link SURFACE_ERROR_BUFFER_QUEUE_FULL} 41209000 - Buffer queue is full. 752 * {@link GSERROR_NO_CONSUMER} 41202000 - no consumer. 753 * {@link SURFACE_ERROR_CONSUMER_UNREGISTER_LISTENER} 41212000 - no register listener. 754 */ 755 GSError AttachAndFlushBuffer(sptr<SurfaceBuffer>& buffer, const sptr<SyncFence>& fence, 756 BufferFlushConfig& config, bool needMap) override; 757 /** 758 * @brief Get the Cycle Buffers Number from the surface. 759 * 760 * @param cycleBuffersNumber [out] The Cycle Buffers Number of the surface. 761 * @return {@link GSERROR_OK} 0 - Success. 762 * {@link SURFACE_ERROR_UNKOWN} 50002000 - Inner error. 763 */ 764 GSError GetCycleBuffersNumber(uint32_t& cycleBuffersNumber) override; 765 /** 766 * @brief Set the Cycle Buffers Number for the surface. 767 * 768 * @param cycleBuffersNumber [in] The Cycle Buffers Number of the surface. 769 * @return {@link GSERROR_OK} 0 - Success. 770 * {@link SURFACE_ERROR_UNKOWN} 50002000 - Inner error. 771 */ 772 GSError SetCycleBuffersNumber(uint32_t cycleBuffersNumber) override; 773 /** 774 * @brief Set the Frame Gravity for the surface. 775 * 776 * @param frameGravity [in] The frame gravity value. 777 * @return {@link GSERROR_OK} 0 - Success. 778 * {@link SURFACE_ERROR_UNKOWN} 50002000 - Inner error. 779 */ 780 GSError SetFrameGravity(int32_t frameGravity) override; 781 /** 782 * @brief Set the Fixed Rotation for the surface. 783 * 784 * @param fixedRotation [in] The frame rotation value. 785 * @return {@link GSERROR_OK} 0 - Success. 786 * {@link SURFACE_ERROR_UNKOWN} 50002000 - Inner error. 787 */ 788 GSError SetFixedRotation(int32_t fixedRotation) override; 789 /** 790 * @brief The client establishes a connection to the server. 791 * In the strictly disconnected state, the producer must call the ConnectStrictly() interface before request 792 * buffer. Unlike Connect(), ConnectStrictly() does not distinguish between process IDs (PIDs) and is 793 * suitable for stricter connection management scenarios. 794 * @return {@link GSERROR_OK} 0 - Success. 795 * {@link GSERROR_INVALID_ARGUMENTS} 40001000 - Param invalid. 796 */ 797 GSError ConnectStrictly() override; 798 /** 799 * @brief Terminate the client-server connection. 800 * After calling DisconnectStrictly(), the consumer (server) enter the strictly disconnected state. 801 * In this state, any attempt by the producer (client) to request buffer will fail and return the error code 802 * GSERROR_CONSUMER_DISCONNECTED. 803 * @return {@link GSERROR_OK} 0 - Success. 804 * {@link GSERROR_INVALID_ARGUMENTS} 40001000 - Param invalid. 805 */ 806 GSError DisconnectStrictly() override; 807 /** 808 * @brief Advance buffer allocation. 809 * 1.The interface needs to be used before first use of requestBuffer; otherwise, the buffer is already 810 * allocated, causing the preAlloc interface to fail to optimize the buffer allocation time; 811 * 2.The specifications of the SurfaceBuffer preAlloc cannot exceed the size of the bufferQueueCache; 812 * 3.The interface is an asynchronous interface; 813 * @param config [in] The parameter type for requesting the buffer. 814 * @param allocBufferCount [in] The number of alloc buffer count. 815 * @return {@link GSERROR_OK} 0 - Success. 816 * {@link GSERROR_INVALID_ARGUMENTS} 40001000 - Param invalid. 817 * {@link SURFACE_ERROR_BUFFER_QUEUE_FULL} 41209000 - Buffer queue is full. 818 * {@link SURFACE_ERROR_OUT_OF_RANGE} 40603000 - out of range. 819 */ 820 GSError PreAllocBuffers(const BufferRequestConfig &config, uint32_t allocBufferCount) override; 821 /** 822 * @brief Request a buffer with lock. 823 * 824 * @param config Indicates the buffer config to be requested. 825 * @param region Indicates the info of the dirty region. 826 * @param buffer Indicates the pointer to a <b>SurfaceBuffer</b> instance. 827 * @return Returns the error code of the request of lock. 828 * {@link GSERROR_INVALID_OPERATING} 41201000 - Operate invalid. 829 */ 830 GSError ProducerSurfaceLockBuffer(BufferRequestConfig &config, Region region, sptr<SurfaceBuffer>& buffer) override; 831 /** 832 * @brief Unlock a buffer with lock. 833 * 834 * @return Returns the error code of the request of unlock. 835 * {@link GSERROR_INVALID_OPERATING} 41201000 - Operate invalid. 836 */ 837 GSError ProducerSurfaceUnlockAndFlushBuffer() override; 838 /** 839 * @brief Set the fd of Lpp shared memory. 840 * @param fd File descriptor. 841 * @param state Link or Unlink. 842 * @return Returns the error code of the request of unlock. 843 * {@link GSERROR_INVALID_OPERATING} 41201000 - Operate invalid. 844 */ 845 GSError SetLppShareFd(int fd, bool state) override; 846 /** 847 * @brief Set the alpha type for the surface. 848 * 849 * @param alphaType [in] the alpha type 850 * @return {@link GSERROR_OK} 0 - Success. 851 * {@link SURFACE_ERROR_UNKNOWN} 50002000 - Inner error. 852 */ 853 GSError SetAlphaType(GraphicAlphaType alphaType) override; 854 private: 855 GSError PropertyChangeCallback(const SurfaceProperty& property); 856 GSError ResetPropertyListenerInner(uint64_t producerId); 857 bool IsRemote(); 858 void CleanAllLocked(uint32_t *bufSeqNum); 859 GSError AddCacheLocked(sptr<BufferExtraData> &bedataimpl, 860 IBufferProducer::RequestBufferReturnValue &retval, BufferRequestConfig &config); 861 GSError SetMetadataValue(sptr<SurfaceBuffer>& buffer); 862 GSError CleanCacheLocked(bool cleanAll); 863 void SetBufferConfigLocked(sptr<BufferExtraData>& bedataimpl, 864 IBufferProducer::RequestBufferReturnValue& retval, BufferRequestConfig& config); 865 void DeleteCacheBufferLocked(sptr<BufferExtraData>& bedataimpl, 866 IBufferProducer::RequestBufferReturnValue& retval, BufferRequestConfig& config); 867 GSError UpdateCacheLocked(sptr<BufferExtraData>& bedataimpl, 868 IBufferProducer::RequestBufferReturnValue& retval, BufferRequestConfig& config); 869 void ReleasePreCacheBuffer(int bufferCacheSize); 870 871 GSError RequestBufferLocked(sptr<SurfaceBuffer>& buffer, 872 sptr<SyncFence>& fence, BufferRequestConfig& config); 873 GSError ProducerSurfaceCancelBufferLocked(sptr<SurfaceBuffer>& buffer); 874 875 mutable std::mutex mutex_; 876 std::atomic_bool inited_ = false; 877 std::map<int32_t, sptr<SurfaceBuffer>> bufferProducerCache_; 878 std::map<std::string, std::string> userData_; 879 sptr<IBufferProducer> producer_ = nullptr; 880 std::string name_ = "not init"; 881 uint64_t queueId_ = 0; 882 bool isDisconnected_ = true; 883 sptr<IProducerListener> listener_; 884 sptr<IProducerListener> listenerBackup_; 885 std::mutex listenerMutex_; 886 wptr<NativeWindow> wpNativeWindow_ = nullptr; 887 wptr<ProducerSurfaceDelegator> wpPSurfaceDelegator_ = nullptr; 888 std::mutex delegatorMutex_; 889 std::map<std::string, OnUserDataChangeFunc> onUserDataChange_; 890 std::mutex lockMutex_; 891 std::string bufferName_ = ""; 892 int32_t requestWidth_ = 0; 893 int32_t requestHeight_ = 0; 894 GraphicTransformType lastSetTransformHint_ = GraphicTransformType::GRAPHIC_ROTATE_NONE; 895 BufferRequestConfig windowConfig_ = {0}; 896 ProducerInitInfo initInfo_ = {0}; 897 sptr<SurfaceBuffer> preCacheBuffer_ = nullptr; 898 sptr<SurfaceBuffer> mLockedBuffer_ = nullptr; 899 Region region_ = {.rects = nullptr, .rectNumber = 0}; 900 }; 901 } // namespace OHOS 902 903 #endif // FRAMEWORKS_SURFACE_INCLUDE_PRODUCER_SURFACE_H 904