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_FRAMEWORK_JAVASCRIPT_BRIDGE_JS_VIEW_JS_OFFSCREEN_RENDERING_CONTEXT_H 17 #define FOUNDATION_ACE_FRAMEWORK_JAVASCRIPT_BRIDGE_JS_VIEW_JS_OFFSCREEN_RENDERING_CONTEXT_H 18 19 #include "bridge/declarative_frontend/jsview/canvas/js_canvas_renderer.h" 20 #include "bridge/declarative_frontend/jsview/canvas/js_rendering_context_settings.h" 21 22 namespace OHOS::Ace::Framework { 23 24 class JSOffscreenRenderingContext : public JSCanvasRenderer { 25 public: 26 JSOffscreenRenderingContext(); 27 ~JSOffscreenRenderingContext() override = default; 28 29 static void JSBind(BindingTarget globalObj); 30 static void Constructor(const JSCallbackInfo& args); 31 static void Destructor(JSOffscreenRenderingContext* controller); 32 33 void JsTransferToImageBitmap(const JSCallbackInfo& info); 34 AddOffscreenCanvasPattern(const RefPtr<AceType> & pattern)35 static void AddOffscreenCanvasPattern(const RefPtr<AceType>& pattern) 36 { 37 CHECK_NULL_VOID(pattern); 38 std::lock_guard<std::mutex> lock(mutex_); 39 offscreenPatternMap_[offscreenPatternCount_++] = pattern; 40 } 41 GetOffscreenPattern(int32_t id)42 static RefPtr<AceType> GetOffscreenPattern(int32_t id) 43 { 44 std::lock_guard<std::mutex> lock(mutex_); 45 return offscreenPatternMap_[id]; 46 } 47 GetId()48 uint32_t GetId() 49 { 50 return id_; 51 } 52 SetWidth(double width)53 void SetWidth(double width) 54 { 55 width_ = width; 56 } 57 GetWidth()58 double GetWidth() const 59 { 60 return width_; 61 } 62 SetHeight(double height)63 void SetHeight(double height) 64 { 65 height_ = height; 66 } 67 GetHeight()68 double GetHeight() const 69 { 70 return height_; 71 } 72 73 ACE_DISALLOW_COPY_AND_MOVE(JSOffscreenRenderingContext); 74 75 private: 76 static std::mutex mutex_; 77 uint32_t id_ = 0; 78 double width_ = 0.0f; 79 double height_ = 0.0f; 80 static std::unordered_map<uint32_t, RefPtr<AceType>> offscreenPatternMap_; 81 static uint32_t offscreenPatternCount_; 82 }; 83 } // namespace OHOS::Ace::Framework 84 #endif // FOUNDATION_ACE_FRAMEWORK_JAVASCRIPT_BRIDGE_JS_VIEW_JS_OFFSCREEN_RENDERING_CONTEXT_H 85