• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2023 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 "webgl/webgl_buffer.h"
17 #include "context/webgl_rendering_context_base.h"
18 
19 #include "napi/n_class.h"
20 #include "napi/n_func_arg.h"
21 #include "napi/n_val.h"
22 #include "util/log.h"
23 
24 namespace OHOS {
25 namespace Rosen {
26 using namespace std;
Constructor(napi_env env,napi_callback_info info)27 napi_value WebGLBuffer::Constructor(napi_env env, napi_callback_info info)
28 {
29     NFuncArg funcArg(env, info);
30     if (!funcArg.InitArgs(NARG_CNT::ZERO)) {
31         return nullptr;
32     }
33 
34     unique_ptr<WebGLBuffer> webGlBuffer = make_unique<WebGLBuffer>();
35     if (!NClass::SetEntityFor<WebGLBuffer>(env, funcArg.GetThisVar(), move(webGlBuffer))) {
36         LOGE("SetEntityFor webGlBuffer failed.");
37         return nullptr;
38     }
39     return funcArg.GetThisVar();
40 }
41 
Export(napi_env env,napi_value exports)42 bool WebGLBuffer::Export(napi_env env, napi_value exports)
43 {
44     vector<napi_property_descriptor> props = {};
45 
46     string className = GetClassName();
47     bool succ = false;
48     napi_value clas = nullptr;
49     tie(succ, clas) = NClass::DefineClass(exports_.env_, className, WebGLBuffer::Constructor, std::move(props));
50     if (!succ) {
51         LOGE("DefineClass webGlBuffer failed.");
52         return false;
53     }
54     succ = NClass::SaveClass(exports_.env_, className, clas);
55     if (!succ) {
56         LOGE("SaveClass webGlBuffer failed.");
57         return false;
58     }
59 
60     return exports_.AddProp(className, clas);
61 }
62 
GetClassName()63 string WebGLBuffer::GetClassName()
64 {
65     return WebGLBuffer::className;
66 }
67 
~WebGLBuffer()68 WebGLBuffer::~WebGLBuffer()
69 {
70     LOGD("Free WebGLBuffer %{public}p", this);
71 }
72 } // namespace Rosen
73 } // namespace OHOS
74