1 /* 2 * Copyright (c) 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 RENDER_SERVICE_RCD_SURFACE_RENDER_NODE_DRAWABLE_H 17 #define RENDER_SERVICE_RCD_SURFACE_RENDER_NODE_DRAWABLE_H 18 19 #include <memory> 20 #include "common/rs_common_def.h" 21 #include "platform/drawing/rs_surface.h" 22 #include "drawable/rs_render_node_drawable.h" 23 #include "pipeline/rs_processor_factory.h" 24 #include "pipeline/rs_render_node.h" 25 #include "pipeline/rs_surface_handler.h" 26 #include "pipeline/render_thread/rs_uni_render_virtual_processor.h" 27 #include "screen_manager/rs_screen_manager.h" 28 29 namespace OHOS::Rosen { 30 31 struct CldInfo { 32 uint32_t cldDataOffset = 0; 33 uint32_t cldSize = 0; 34 uint32_t cldWidth = 0; 35 uint32_t cldHeight = 0; 36 uint32_t cldStride = 0; 37 uint32_t exWidth = 0; 38 uint32_t exHeight = 0; 39 uint32_t baseColor = 0; 40 }; 41 42 namespace DrawableV2 { 43 44 // use normal hardware composer node drawable instead when it supports rcd feature in OH 6.0 rcd refactoring 45 class RSRcdSurfaceRenderNodeDrawable : public RSRenderNodeDrawable { 46 public: 47 ~RSRcdSurfaceRenderNodeDrawable() override = default; 48 49 static RSRenderNodeDrawable::Ptr OnGenerate(std::shared_ptr<const RSRenderNode> node); 50 51 bool CreateSurface(sptr<IBufferConsumerListener> listener); 52 bool IsSurfaceCreated() const; 53 std::shared_ptr<RSSurface> GetRSSurface() const; 54 sptr<IBufferConsumerListener> GetConsumerListener() const; 55 GetSurfaceHandler()56 const std::shared_ptr<RSSurfaceHandler> GetSurfaceHandler() const 57 { 58 return surfaceHandler_; 59 } 60 void SetSurfaceType(uint32_t surfaceType); 61 bool IsTopSurface() const; 62 bool IsBottomSurface() const; 63 bool IsInvalidSurface() const; 64 65 bool IsRcdEnabled() const; 66 bool IsResourceChanged() const; 67 68 BufferRequestConfig GetHardenBufferRequestConfig() const; 69 bool ProcessRcdSurfaceRenderNode(std::shared_ptr<RSProcessor> processor); 70 71 bool ConsumeAndUpdateBuffer(); 72 void ClearBufferCache(); 73 bool SetHardwareResourceToBuffer(); 74 75 const CldInfo& GetCldInfo() const; 76 77 void SetRenderTargetId(NodeId id); 78 79 bool PrepareResourceBuffer(); 80 bool FillHardwareResource(int width, int height); 81 82 bool DoProcessRenderTask(std::shared_ptr<RSProcessor> processor); 83 84 private: 85 explicit RSRcdSurfaceRenderNodeDrawable(std::shared_ptr<const RSRenderNode> &&node); 86 87 NodeId GetRenderTargetId() const; 88 std::shared_ptr<Drawing::Bitmap> GetRcdBitmap() const; 89 90 uint32_t GetRcdBufferWidth() const; 91 uint32_t GetRcdBufferHeight() const; 92 uint32_t GetRcdBufferSize() const; 93 94 CldInfo cldInfo_; 95 96 NodeId renderTargetId_ = 0; 97 uint32_t surfaceType_ = 0; 98 99 bool surfaceCreated_ = false; 100 std::shared_ptr<RSSurface> surface_ = nullptr; 101 sptr<IBufferConsumerListener> consumerListener_; 102 103 using Registrar = RenderNodeDrawableRegistrar<RSRenderNodeType::ROUND_CORNER_NODE, OnGenerate>; 104 static Registrar instance_; 105 106 std::shared_ptr<RSSurfaceHandler> surfaceHandler_; 107 108 // dirty manager 109 std::shared_ptr<RSDirtyRegionManager> syncDirtyManager_ = nullptr; 110 }; 111 } // namespace DrawableV2 112 } // namespace OHOS::Rosen 113 #endif // RENDER_SERVICE_RCD_SURFACE_RENDER_NODE_DRAWABLE_H 114