1 /* 2 * Copyright (c) 2024 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_BRIDGE_CJ_FRONTEND_CPP_VIEW_OFFSCREEN_RENDERING_CONTEXT_H 17 #define FRAMEWORKS_BRIDGE_CJ_FRONTEND_CPP_VIEW_OFFSCREEN_RENDERING_CONTEXT_H 18 19 #include <cstdint> 20 #include "render_image.h" 21 22 #include "bridge/cj_frontend/cppview/canvas_renderer.h" 23 #include "core/components/common/properties/paint_state.h" 24 25 namespace OHOS::Ace::Framework { 26 class ACE_EXPORT CJOffscreenRenderingContext : public NativeCanvasRenderer { 27 public: 28 CJOffscreenRenderingContext(double width, double height, bool antialias, int32_t unit); 29 CJOffscreenRenderingContext(); 30 ~CJOffscreenRenderingContext() override; 31 32 int64_t CJTransferToImageBitmap(); 33 AddOffscreenCanvasPattern(const RefPtr<AceType> & pattern)34 static void AddOffscreenCanvasPattern(const RefPtr<AceType>& pattern) 35 { 36 CHECK_NULL_VOID(pattern); 37 std::lock_guard<std::mutex> lock(mutex_); 38 offscreenPatternMap_[offscreenPatternCount_++] = pattern; 39 } 40 GetOffscreenPattern(int32_t id)41 static RefPtr<AceType> GetOffscreenPattern(int32_t id) 42 { 43 std::lock_guard<std::mutex> lock(mutex_); 44 return offscreenPatternMap_[id]; 45 } 46 GetId()47 uint32_t GetId() 48 { 49 return id_; 50 } 51 SetWidth(double width)52 void SetWidth(double width) 53 { 54 width_ = width; 55 } 56 GetWidth()57 double GetWidth() const 58 { 59 return width_; 60 } 61 SetHeight(double height)62 void SetHeight(double height) 63 { 64 height_ = height; 65 } 66 GetHeight()67 double GetHeight() const 68 { 69 return height_; 70 } 71 72 private: 73 static std::mutex mutex_; 74 75 uint32_t id_; 76 double width_ = 0.0f; 77 double height_ = 0.0f; 78 79 static std::unordered_map<uint32_t, RefPtr<AceType>> offscreenPatternMap_; 80 static uint32_t offscreenPatternCount_; 81 }; 82 } // namespace OHOS::Ace::Framework 83 #endif // FRAMEWORKS_BRIDGE_CJ_FRONTEND_CPP_VIEW_OFFSCREEN_RENDERING_CONTEXT_H 84