1 /* 2 * Copyright (c) 2023 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_CORE_RS_DRIVEN_SURFACE_RENDER_NODE_H 17 #define RENDER_SERVICE_CORE_RS_DRIVEN_SURFACE_RENDER_NODE_H 18 19 #include <ibuffer_consumer_listener.h> 20 #include <memory> 21 #include <surface.h> 22 23 #include "common/rs_rect.h" 24 #include "pipeline/rs_canvas_render_node.h" 25 #include "pipeline/rs_render_node.h" 26 #include "pipeline/rs_surface_handler.h" 27 #ifdef NEW_RENDER_CONTEXT 28 #include "rs_render_surface.h" 29 #include "render_context_base.h" 30 #else 31 #include "platform/drawing/rs_surface.h" 32 #include "render_context/render_context.h" 33 #endif 34 #include "sync_fence.h" 35 36 namespace OHOS { 37 namespace Rosen { 38 //////////////////////////////////////////////////////////////////////////// 39 // the definitions must be kept in sync with libdriven_render 40 struct DrivenFrameState { 41 RectF surfaceBounds; 42 RectF contentBounds; 43 RectF frameBounds; 44 RectF frameViewPort; 45 RectI frameClipRect; 46 std::vector<std::pair<int32_t, Vector4f>> framePaintItems; 47 48 DrivenFrameState& operator=(const DrivenFrameState& other) 49 { 50 surfaceBounds = other.surfaceBounds; 51 contentBounds = other.contentBounds; 52 frameBounds = other.frameBounds; 53 frameViewPort = other.frameViewPort; 54 frameClipRect = other.frameClipRect; 55 framePaintItems.assign(other.framePaintItems.begin(), other.framePaintItems.end()); 56 return *this; 57 } 58 ClearDrivenFrameState59 void Clear() 60 { 61 surfaceBounds.Clear(); 62 contentBounds.Clear(); 63 frameBounds.Clear(); 64 frameViewPort.Clear(); 65 frameClipRect.Clear(); 66 framePaintItems.clear(); 67 } 68 GetFrameOffsetXDrivenFrameState69 float GetFrameOffsetX() const 70 { 71 return frameViewPort.GetLeft() - surfaceBounds.GetLeft(); 72 } GetFrameOffsetYDrivenFrameState73 float GetFrameOffsetY() const 74 { 75 return frameViewPort.GetTop() - surfaceBounds.GetTop(); 76 } 77 }; 78 79 enum class DrivenSurfaceRenderMode : uint32_t { 80 EXPANDED, 81 REUSABLE, 82 DISABLED 83 }; 84 85 enum class DrivenSurfaceType : uint32_t { 86 BACKGROUND, 87 CONTENT, 88 INVALID 89 }; 90 91 struct DrivenExtInfo { 92 bool surfaceCreated_ = false; 93 RectI srcRect_; 94 RectI dstRect_; 95 96 DrivenFrameState activateState_; 97 DrivenFrameState currentState_; 98 DrivenFrameState lastFrameState_; 99 float yOffset_ = 0.0f; 100 DrivenSurfaceRenderMode renderMode_ = DrivenSurfaceRenderMode::DISABLED; 101 DrivenSurfaceType surfaceType_ = DrivenSurfaceType::INVALID; 102 }; 103 //////////////////////////////////////////////////////////////////////////// 104 105 class RSDrivenSurfaceRenderNode : public RSRenderNode, public RSSurfaceHandler { 106 public: 107 using WeakPtr = std::weak_ptr<RSDrivenSurfaceRenderNode>; 108 using SharedPtr = std::shared_ptr<RSDrivenSurfaceRenderNode>; 109 110 RSDrivenSurfaceRenderNode(NodeId id, DrivenSurfaceType type, std::weak_ptr<RSContext> context = {}); 111 ~RSDrivenSurfaceRenderNode() override; 112 113 const RectI& GetSrcRect() const; 114 const RectI& GetDstRect() const; 115 116 void SetDrivenCanvasNode(RSBaseRenderNode::SharedPtr node); 117 RSBaseRenderNode::SharedPtr GetDrivenCanvasNode() const; 118 119 bool CreateSurface(sptr<IBufferConsumerListener> listener); 120 bool IsSurfaceCreated() const; 121 #ifdef NEW_RENDER_CONTEXT 122 std::shared_ptr<RSRenderSurface> GetRSSurface() const; 123 #else 124 std::shared_ptr<RSSurface> GetRSSurface() const; 125 #endif 126 sptr<IBufferConsumerListener> GetConsumerListener() const; 127 BufferRequestConfig GetBufferRequestConfig() const; 128 void ClearBufferCache(); 129 130 void ResetCurrFrameState(); 131 void Reset(); 132 void PushFramePaintItem(Vector4f paintItem, int32_t itemIndex); 133 void DisabledRenderMode(); 134 void SetCurrFrameBounds(const RectF& bounds, const RectF& viewPort, const RectI& contentAbsRect); 135 void UpdateActivateFrameState(const RectI& dstRect, bool backgroundDirty, bool contentDirty, bool nonContentDirty); 136 137 bool IsExpandedMode() const; 138 bool IsReusableMode() const; 139 bool IsDisabledMode() const; 140 bool IsBackgroundSurface() const; 141 bool IsContentSurface() const; 142 bool IsInvalidSurface() const; 143 144 float GetFrameOffsetX() const; 145 float GetFrameOffsetY() const; 146 const RectI& GetFrameClipRect() const; 147 GetDrivenSurfaceRenderMode()148 const DrivenSurfaceRenderMode& GetDrivenSurfaceRenderMode() const 149 { 150 return drivenExtInfo_.renderMode_; 151 } 152 153 private: 154 float GetSurfaceWidth() const; 155 float GetSurfaceHeight() const; 156 #ifdef NEW_RENDER_CONTEXT 157 std::shared_ptr<RSRenderSurface> surface_; 158 #else 159 std::shared_ptr<RSSurface> surface_; 160 #endif 161 sptr<IBufferConsumerListener> consumerListener_; 162 RSBaseRenderNode::SharedPtr drivenCanvasNode_ = nullptr; 163 164 DrivenExtInfo drivenExtInfo_; 165 }; 166 } // namespace Rosen 167 } // namespace OHOS 168 #endif // RENDER_SERVICE_CORE_RS_DRIVEN_SURFACE_RENDER_NODE_H 169