• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "base/memory/referenced.h"
20 #include "bridge/declarative_frontend/engine/bindings_defines.h"
21 #include "bridge/declarative_frontend/jsview/js_canvas_renderer.h"
22 
23 #include "frameworks/bridge/declarative_frontend/jsview/js_rendering_context_settings.h"
24 #include "frameworks/bridge/declarative_frontend/jsview/js_view_abstract.h"
25 
26 namespace OHOS::Ace::Framework {
27 
28 class JSOffscreenRenderingContext : public JSCanvasRenderer {
29 public:
30     JSOffscreenRenderingContext();
31     ~JSOffscreenRenderingContext() override = default;
32 
33     static void JSBind(BindingTarget globalObj);
34     static void Constructor(const JSCallbackInfo& args);
35     static void Destructor(JSOffscreenRenderingContext* controller);
36 
37     void JsTransferToImageBitmap(const JSCallbackInfo& info);
GetOffscreenCanvas(int32_t id)38     static RefPtr<OffscreenCanvas> GetOffscreenCanvas(int32_t id)
39     {
40         std::lock_guard<std::mutex> lock(mutex_);
41         return offscreenCanvasMap_[id];
42     }
43 
GetOffscreenCanvasPattern(int32_t id)44     static RefPtr<NG::OffscreenCanvasPattern> GetOffscreenCanvasPattern(int32_t id)
45     {
46         std::lock_guard<std::mutex> lock(mutex_);
47         return offscreenCanvasPatternMap_[id];
48     }
49 
GetId()50     uint32_t GetId()
51     {
52         return id;
53     }
54 
55     ACE_DISALLOW_COPY_AND_MOVE(JSOffscreenRenderingContext);
56 
57 private:
58     static std::mutex mutex_;
59     static std::unordered_map<uint32_t, RefPtr<OffscreenCanvas>> offscreenCanvasMap_;
60     static std::unordered_map<uint32_t, RefPtr<NG::OffscreenCanvasPattern>> offscreenCanvasPatternMap_;
61     static uint32_t offscreenCanvasCount_;
62     static uint32_t offscreenCanvasPatternCount_;
63     uint32_t id;
64 };
65 
66 } // namespace OHOS::Ace::Framework
67 
68 #endif // FOUNDATION_ACE_FRAMEWORK_JAVASCRIPT_BRIDGE_JS_VIEW_JS_OFFSCREEN_RENDERING_CONTEXT_H