• 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 #ifndef FRAMEWORKS_OPENGL_WRAPPER_EGL_WRAPPER_DISPLAY_H
16 #define FRAMEWORKS_OPENGL_WRAPPER_EGL_WRAPPER_DISPLAY_H
17 
18 #include <mutex>
19 #include <unordered_set>
20 #include <EGL/egl.h>
21 #include <EGL/eglext.h>
22 
23 namespace OHOS {
24 class EglWrapperObject;
25 class EglWrapperContext;
26 class EglWrapperSurface;
27 
28 class EglWrapperDisplay {
29 public:
30     EGLBoolean Init(EGLint *major, EGLint *minor);
31     EGLBoolean Terminate();
32     EGLBoolean MakeCurrent(EGLSurface draw, EGLSurface read, EGLContext ctx);
33     static EglWrapperDisplay *GetWrapperDisplay(EGLDisplay display);
34     static EGLDisplay GetEglDisplay(EGLenum platform, EGLNativeDisplayType disp, const EGLAttrib *attribList);
35     static EGLDisplay GetEglDisplayExt(EGLenum platform, void *disp, const EGLint *attribList);
36     static bool ValidateEglContext(EGLContext ctx);
37     static bool ValidateEglSurface(EGLSurface surf);
38     EGLContext CreateEglContext(EGLConfig config, EGLContext shareList, const EGLint *attribList);
39     EGLSurface CreateEglSurface(EGLConfig config, NativeWindowType window, const EGLint *attribList);
40     EGLBoolean DestroyEglContext(EGLContext context);
41     EGLBoolean DestroyEglSurface(EGLSurface surf);
42 
43     void AddObject(EglWrapperObject *obj);
44     void RemoveObject(EglWrapperObject *obj);
45 
46     EGLBoolean CopyBuffers(EGLSurface surf, NativePixmapType target);
47     EGLSurface CreatePbufferSurface(EGLConfig config, const EGLint *attribList);
48     EGLSurface CreatePixmapSurface(EGLConfig config, EGLNativePixmapType pixmap, const EGLint* attribList);
IsReady()49     inline bool IsReady() const
50     {
51         return (refCnt_ > 0);
52     };
GetEglDisplay()53     inline EGLDisplay GetEglDisplay() const
54     {
55         return disp_;
56     };
57 
58     EGLBoolean QueryContext(EGLContext ctx, EGLint attribute, EGLint *value);
59     EGLBoolean QuerySurface(EGLSurface surf, EGLint attribute, EGLint *value);
60     EGLBoolean SwapBuffers(EGLSurface surf);
61     EGLBoolean BindTexImage(EGLSurface surf, EGLint buffer);
62     EGLBoolean ReleaseTexImage(EGLSurface surf, EGLint buffer);
63     EGLBoolean SurfaceAttrib(EGLSurface surf, EGLint attribute, EGLint value);
64     EGLSurface CreatePbufferFromClientBuffer(EGLenum buftype,
65         EGLClientBuffer buffer, EGLConfig config, const EGLint *attribList);
66     EGLImage CreateImage(EGLContext ctx, EGLenum target,
67         EGLClientBuffer buffer, const EGLAttrib *attribList);
68     EGLBoolean DestroyImage(EGLImage img);
69     EGLSurface CreatePlatformWindowSurface(EGLConfig config,
70         void *nativeWindow, const EGLAttrib *attribList);
71     EGLSurface CreatePlatformPixmapSurface(EGLConfig config,
72         void *nativePixmap, const EGLAttrib *attribList);
73     EGLBoolean LockSurfaceKHR(EGLSurface surf, const EGLint *attribList);
74     EGLBoolean UnlockSurfaceKHR(EGLSurface surf);
75 
76     EGLImageKHR CreateImageKHR(EGLContext ctx, EGLenum target,
77         EGLClientBuffer buffer, const EGLint *attribList);
78     EGLBoolean DestroyImageKHR(EGLImageKHR img);
79 
80     EGLSurface CreateStreamProducerSurfaceKHR(EGLConfig config,
81         EGLStreamKHR stream, const EGLint *attribList);
82 
83     EGLBoolean SwapBuffersWithDamageKHR(EGLSurface draw, EGLint *rects, EGLint nRects);
84     EGLBoolean SetDamageRegionKHR(EGLSurface surf, EGLint *rects, EGLint nRects);
85 
86 private:
87     EglWrapperDisplay() noexcept;
88     ~EglWrapperDisplay();
89     EGLDisplay GetEglNativeDisplay(EGLenum platform, EGLNativeDisplayType disp, const EGLAttrib *attribList);
90     EGLDisplay GetEglNativeDisplayExt(EGLenum platform, void *disp, const EGLint *attribList);
91     bool CheckObject(EglWrapperObject *obj);
92     void ClearObjects();
93     EGLBoolean InternalMakeCurrent(EglWrapperSurface *draw, EglWrapperSurface *read, EglWrapperContext *ctx);
94 
95     static EglWrapperDisplay wrapperDisp_;
96     EGLDisplay  disp_;
97     std::mutex  lockMutex_;
98     std::mutex  refLockMutex_;
99     std::unordered_set<EglWrapperObject *> objects_;
100     uint32_t    refCnt_;
101 };
102 } // namespace OHOS
103 #endif // FRAMEWORKS_OPENGL_WRAPPER_EGL_WRAPPER_DISPLAY_H
104