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 FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_BASE_ROSEN_RENDER_CONTEXT_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_BASE_ROSEN_RENDER_CONTEXT_H 18 19 #include "third_party/skia/include/core/SkCanvas.h" 20 #include "third_party/skia/include/core/SkRefCnt.h" 21 22 #include "base/geometry/rect.h" 23 #include "core/pipeline/base/render_context.h" 24 #include "core/pipeline/base/render_node.h" 25 26 class SkImage; 27 class SkPicture; 28 class SkPictureRecorder; 29 30 namespace OHOS::Ace { 31 32 class RosenRenderContext : public RenderContext { 33 DECLARE_ACE_TYPE(RosenRenderContext, RenderContext) 34 35 public: 36 RosenRenderContext() = default; 37 ~RosenRenderContext() override; 38 39 void Repaint(const RefPtr<RenderNode>& node) override; 40 void PaintChild(const RefPtr<RenderNode>& child, const Offset& offset) override; 41 bool IsIntersectWith(const RefPtr<RenderNode>& child, Offset& offset) override; 42 void Restore() override; 43 44 void InitContext( 45 const std::shared_ptr<RSNode>& rsNode, const Rect& rect, const Offset& initialOffset = Offset::Zero()); 46 SkCanvas* GetCanvas(); 47 const std::shared_ptr<RSNode>& GetRSNode(); 48 49 void StartRecording(); 50 void StopRecordingIfNeeded(); 51 IsRecording()52 bool IsRecording() 53 { 54 return !!recordingCanvas_; 55 } 56 57 sk_sp<SkPicture> FinishRecordingAsPicture(); 58 sk_sp<SkImage> FinishRecordingAsImage(); 59 60 private: 61 void UpdateChildren(const std::shared_ptr<RSNode>& rsNode); 62 63 std::shared_ptr<RSNode> rsNode_ = nullptr; 64 SkPictureRecorder* recorder_ = nullptr; 65 SkCanvas* recordingCanvas_ = nullptr; 66 SkCanvas* rosenCanvas_ = nullptr; 67 Rect estimatedRect_; 68 std::vector<std::weak_ptr<RSNode>> childNodes_; 69 }; 70 71 } // namespace OHOS::Ace 72 73 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_BASE_ROSEN_RENDER_CONTEXT_H 74