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/js_canvas_renderer.h" 20 #include "frameworks/bridge/declarative_frontend/jsview/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 53 ACE_DISALLOW_COPY_AND_MOVE(JSOffscreenRenderingContext); 54 55 private: 56 static std::mutex mutex_; 57 uint32_t id; 58 59 static std::unordered_map<uint32_t, RefPtr<AceType>> offscreenPatternMap_; 60 static uint32_t offscreenPatternCount_; 61 }; 62 } // namespace OHOS::Ace::Framework 63 #endif // FOUNDATION_ACE_FRAMEWORK_JAVASCRIPT_BRIDGE_JS_VIEW_JS_OFFSCREEN_RENDERING_CONTEXT_H 64