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_query.h"
17
18 #include "napi/n_class.h"
19 #include "napi/n_func_arg.h"
20 #include "napi/n_val.h"
21
22 namespace OHOS {
23 namespace Rosen {
24 using namespace std;
Constructor(napi_env env,napi_callback_info info)25 napi_value WebGLQuery::Constructor(napi_env env, napi_callback_info info)
26 {
27 NFuncArg funcArg(env, info);
28 if (!funcArg.InitArgs(NARG_CNT::ZERO)) {
29 return nullptr;
30 }
31
32 unique_ptr<WebGLQuery> webGlQuery = make_unique<WebGLQuery>();
33 if (!NClass::SetEntityFor<WebGLQuery>(env, funcArg.GetThisVar(), move(webGlQuery))) {
34 LOGE("SetEntityFor webGlQuery failed.");
35 return nullptr;
36 }
37 return funcArg.GetThisVar();
38 }
39
Export(napi_env env,napi_value exports)40 bool WebGLQuery::Export(napi_env env, napi_value exports)
41 {
42 vector<napi_property_descriptor> props = {};
43
44 string className = GetClassName();
45 bool succ = false;
46 napi_value clas = nullptr;
47 tie(succ, clas) = NClass::DefineClass(exports_.env_, className, WebGLQuery::Constructor, std::move(props));
48 if (!succ) {
49 LOGE("DefineClass webGlQuery failed.");
50 return false;
51 }
52 succ = NClass::SaveClass(exports_.env_, className, clas);
53 if (!succ) {
54 LOGE("SaveClass webGlQuery failed.");
55 return false;
56 }
57
58 return exports_.AddProp(className, clas);
59 }
60
GetClassName()61 string WebGLQuery::GetClassName()
62 {
63 return WebGLQuery::className;
64 }
65 } // namespace Rosen
66 } // namespace OHOS
67