• 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 ROSENRENDER_ROSEN_WEBGL_RENDERING_CONTEXT_BASIC_BASE
17 #define ROSENRENDER_ROSEN_WEBGL_RENDERING_CONTEXT_BASIC_BASE
18 
19 #include <GLES2/gl2.h>
20 #include <EGL/egl.h>
21 #include <EGL/eglext.h>
22 #include "../canvas_render_context_base.h"
23 #include "webgl_context_attributes.h"
24 
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28 
29 namespace OHOS {
30 namespace Rosen {
31 class WebGLRenderingContextBasicBase : public OHOS::Ace::CanvasRenderContextBase {
32 public:
33     static WebGLRenderingContextBasicBase *instance;
34 
WebGLRenderingContextBasicBase()35     WebGLRenderingContextBasicBase() {};
36 
~WebGLRenderingContextBasicBase()37     virtual ~WebGLRenderingContextBasicBase() {};
38 
39     static WebGLRenderingContextBasicBase *GetContext(std::string id);
40 
41     void SetEglWindow(void *window);
42 
43     void Create(void *context) override;
44 
45     void Init() override;
46 
47     void Attach(uint64_t textureId) override;
48 
49     void Update() override;
50 
51     void Detach() override;
52 
53     void SetBitMapPtr(char *bitMapPtr, int bitMapWidth, int bitMapHeight) override;
54 
55     uint64_t CreateTexture() override;
56 
57     void SetTexture(uint64_t id);
58 
59     void SetUpdateCallback(std::function<void()>) override;
60 
61 public:
62     GLuint frameBufferId = 0;
63     GLuint textureId = 0;
64     GLuint imgId = 0;
65     void drawImg();
66     GLuint compileShader(GLenum type, const char *sources);
67     int useProgram();
68     GLuint program = 0;
69     GLuint vertShader = 0;
70     GLuint fragShader = 0;
71     GLint uniformSampler = 0;
72     EGLSurface mEGLSurface = nullptr;
73     NativeWindow *mEglWindow = nullptr;
74     WebGLContextAttributes *webGlContextAttributes = nullptr;
75     char *mBitMapPtr = nullptr;
76     int mBitMapWidth = 0;
77     int mBitMapHeight = 0;
78     std::function<void()> mUpdateCallback;
79 };
80 } // namespace Rosen
81 } // namespace OHOS
82 
83 OHOS::Rosen::WebGLRenderingContextBasicBase *GetWebGLInstance(std::string id);
84 
85 #ifdef __cplusplus
86 }
87 #endif
88 
89 #endif // ROSENRENDER_ROSEN_WEBGL_RENDERING_CONTEXT_BASIC_BASE
90