• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 #include "bridge/declarative_frontend/engine/bindings.h"
17 #include "bridge/declarative_frontend/jsview/js_offscreen_canvas.h"
18 
19 namespace OHOS::Ace::Framework {
JSBind(BindingTarget globalObj)20 void JSOffscreenCanvas::JSBind(BindingTarget globalObj)
21 {
22     JSClass<JSOffscreenCanvas>::Declare("OffscreenCanvas");
23     JSClass<JSOffscreenCanvas>::CustomProperty("width", &JSOffscreenCanvas::JsGetWidth,
24         &JSOffscreenCanvas::JsSetWidth);
25     JSClass<JSOffscreenCanvas>::CustomProperty("height", &JSOffscreenCanvas::JsGetHeight,
26         &JSOffscreenCanvas::JsSetHeight);
27     JSClass<JSOffscreenCanvas>::CustomMethod("transferToImageBitmap",
28         &JSOffscreenCanvas::JsTransferToImageBitmap);
29     JSClass<JSOffscreenCanvas>::Bind(globalObj, JSOffscreenCanvas::Constructor,
30         JSOffscreenCanvas::Destructor);
31 }
32 
Constructor(const JSCallbackInfo & args)33 void JSOffscreenCanvas::Constructor(const JSCallbackInfo& args)
34 {
35     auto jsRenderContext = Referenced::MakeRefPtr<JSOffscreenCanvas>();
36     jsRenderContext->IncRefCount();
37     args.SetReturnValue(Referenced::RawPtr(jsRenderContext));
38 }
39 
Destructor(JSOffscreenCanvas * context)40 void JSOffscreenCanvas::Destructor(JSOffscreenCanvas* context)
41 {
42     if (context != nullptr) {
43         context->DecRefCount();
44     } else {
45         LOGE("context is null");
46         return;
47     }
48 }
49 
JsGetWidth(const JSCallbackInfo & info)50 void JSOffscreenCanvas::JsGetWidth(const JSCallbackInfo& info)
51 {
52     double width = 0.0;
53     auto returnValue = JSVal(ToJSValue(width));
54     auto returnPtr = JSRef<JSVal>::Make(returnValue);
55     info.SetReturnValue(returnPtr);
56 }
57 
JsGetHeight(const JSCallbackInfo & info)58 void JSOffscreenCanvas::JsGetHeight(const JSCallbackInfo& info)
59 {
60     double height = 0.0;
61     auto returnValue = JSVal(ToJSValue(height));
62     auto returnPtr = JSRef<JSVal>::Make(returnValue);
63     info.SetReturnValue(returnPtr);
64 }
65 
JsSetWidth(const JSCallbackInfo & info)66 void JSOffscreenCanvas::JsSetWidth(const JSCallbackInfo& info)
67 {
68     return;
69 }
70 
JsSetHeight(const JSCallbackInfo & info)71 void JSOffscreenCanvas::JsSetHeight(const JSCallbackInfo& info)
72 {
73     return;
74 }
75 
JsTransferToImageBitmap(const JSCallbackInfo & info)76 void JSOffscreenCanvas::JsTransferToImageBitmap(const JSCallbackInfo& info)
77 {
78     auto retObj = JSRef<JSObject>::New();
79     info.SetReturnValue(retObj);
80 }
81 
82 } // namespace OHOS::Ace::Framework
83