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 FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_RENDERING_CONTEXT_2D_CONTENT_MODIFIER_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_RENDERING_CONTEXT_2D_CONTENT_MODIFIER_H 18 19 #include <optional> 20 #include <vector> 21 22 #include "base/memory/ace_type.h" 23 #include "core/components_ng/base/modifier.h" 24 #ifdef USE_ROSEN_DRAWING 25 #include "core/components_ng/render/drawing.h" 26 #endif 27 28 namespace OHOS::Rosen { 29 class RSRecordingCanvas; 30 } 31 32 namespace OHOS::Ace::NG { 33 class Pattern; 34 35 class RenderingContext2DModifier : public ContentModifier { 36 DECLARE_ACE_TYPE(RenderingContext2DModifier, ContentModifier) 37 38 public: 39 RenderingContext2DModifier(); 40 ~RenderingContext2DModifier() override = default; 41 void onDraw(DrawingContext& drawingContext) override; 42 std::string GetDumpInfo(); 43 bool needResetSurface_ = false; 44 RefPtr<RenderContext> renderContext_ = nullptr; 45 MarkModifierDirty()46 void MarkModifierDirty() 47 { 48 CHECK_NULL_VOID(needRender_); 49 needRender_->Set(!needRender_->Get()); 50 } 51 52 #ifndef USE_ROSEN_DRAWING UpdateCanvas(std::shared_ptr<OHOS::Rosen::RSRecordingCanvas> rsRecordingCanvas)53 void UpdateCanvas(std::shared_ptr<OHOS::Rosen::RSRecordingCanvas> rsRecordingCanvas) 54 #else 55 void UpdateCanvas(std::shared_ptr<RSRecordingCanvas> rsRecordingCanvas) 56 #endif 57 { 58 rsRecordingCanvas_ = rsRecordingCanvas; 59 } 60 61 private: 62 RefPtr<PropertyBool> needRender_; 63 #ifndef USE_ROSEN_DRAWING 64 std::shared_ptr<OHOS::Rosen::RSRecordingCanvas> rsRecordingCanvas_; 65 #else 66 std::shared_ptr<RSRecordingCanvas> rsRecordingCanvas_; 67 #endif 68 SizeT<int32_t> recordingCanvasDrawSize_ = {0.0f, 0.0f}; 69 SizeT<int32_t> drawCmdSize_ = {0.0f, 0.0f}; 70 ACE_DISALLOW_COPY_AND_MOVE(RenderingContext2DModifier); 71 }; 72 } // namespace OHOS::Ace::NG 73 74 #endif