• 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 #include "../include/context/webgl_rendering_context_basic_base.h"
17 #include "../include/context/webgl_rendering_context.h"
18 #include "../include/util/egl_manager.h"
19 #include "../include/context/webgl2_rendering_context.h"
20 #include "../../common/napi/n_class.h"
21 #include "../include/util/log.h"
22 #include "../include/util/object_manager.h"
23 
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27 
28 using namespace std;
29 
GetWebGLInstance(string id)30 OHOS::Rosen::WebGLRenderingContextBasicBase *GetWebGLInstance(string id)
31 {
32     return OHOS::Rosen::WebGLRenderingContextBasicBase::GetContext(id);
33 }
34 
35 namespace OHOS {
36 namespace Rosen {
37 WebGLRenderingContextBasicBase *WebGLRenderingContextBasicBase::instance = nullptr;
38 
GetContext(string id)39 WebGLRenderingContextBasicBase *WebGLRenderingContextBasicBase::GetContext(string id)
40 {
41     LOGI("WebGLRenderingContextBasicBase::GetContext.");
42     return instance;
43 }
44 
SetEglWindow(void * window)45 void WebGLRenderingContextBasicBase::SetEglWindow(void *window)
46 {
47     mEglWindow = reinterpret_cast<NativeWindow *>(window);
48 }
49 
Create(void * context)50 void WebGLRenderingContextBasicBase::Create(void *context)
51 {
52     LOGI("WebGLRenderingContextBasicBase::Create.\n");
53 }
54 
Init()55 void WebGLRenderingContextBasicBase::Init()
56 {
57     EglManager::GetInstance().Init();
58 }
59 
SetBitMapPtr(char * bitMapPtr,int bitMapWidth,int bitMapHeight)60 void WebGLRenderingContextBasicBase::SetBitMapPtr(char *bitMapPtr, int bitMapWidth, int bitMapHeight)
61 {
62     LOGI("WebGLRenderingContextBasicBase bitMapWidth = %{public}d, bitMapHeight = %{public}d",
63         bitMapWidth, bitMapHeight);
64     mBitMapPtr = bitMapPtr;
65     mBitMapWidth = bitMapWidth;
66     mBitMapHeight = bitMapHeight;
67     EglManager::GetInstance().SetPbufferAttributes(bitMapWidth, bitMapHeight);
68 }
69 
CreateTexture()70 uint64_t WebGLRenderingContextBasicBase::CreateTexture()
71 {
72     return 0;
73 }
74 
SetUpdateCallback(std::function<void ()> callback)75 void WebGLRenderingContextBasicBase::SetUpdateCallback(std::function<void()> callback)
76 {
77     mUpdateCallback = callback;
78 }
79 
SetTexture(uint64_t id)80 void WebGLRenderingContextBasicBase::SetTexture(uint64_t id) {}
81 
Attach(uint64_t textureId)82 void WebGLRenderingContextBasicBase::Attach(uint64_t textureId) {}
83 
Update()84 void WebGLRenderingContextBasicBase::Update()
85 {
86     if (mEglWindow) {
87         LOGI("WebGLRenderingContextBasicBase eglSwapBuffers");
88         EGLDisplay eglDisplay = EglManager::GetInstance().GetEGLDisplay();
89         eglSwapBuffers(eglDisplay, mEGLSurface);
90     } else {
91         LOGI("WebGLRenderingContextBasicBase glReadPixels");
92         glPixelStorei(GL_PACK_ALIGNMENT, 1);
93         glReadPixels(0, 0, mBitMapWidth, mBitMapHeight, GL_RGBA, GL_UNSIGNED_BYTE, mBitMapPtr);
94     }
95     if (mUpdateCallback) {
96         LOGI("WebGLRenderingContextBasicBase mUpdateCallback");
97         mUpdateCallback();
98     } else {
99         LOGE("WebGLRenderingContextBasicBase mUpdateCallback null");
100     }
101 }
102 
Detach()103 void WebGLRenderingContextBasicBase::Detach() {}
104 } // namespace Rosen
105 } // namespace OHOS
106 
107 #ifdef __cplusplus
108 }
109 #endif
110