Debian Codegraph @

libs/hwui/renderthread/EglManager.h

raw symbols SCIP
1 /*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 #ifndef EGLMANAGER_H
17 #define EGLMANAGER_H
18
19 #include <EGL/egl.h>
20 #include <EGL/eglext.h>
21 #include <SkImageInfo.h>
22 #include <SkRect.h>
23 #include <cutils/compiler.h>
24 #include <utils/StrongPointer.h>
25
26 #include "IRenderPipeline.h"
27 #include "utils/Result.h"
28
29 namespace android {
30 namespace uirenderer {
31 namespace renderthread {
32
33 class Frame;
34 class RenderThread;
35
36 // This class contains the shared global EGL objects, such as EGLDisplay
37 // and EGLConfig, which are re-used by CanvasContext
38 class EglManager {
39 public:
40 explicit EglManager();
41
42 ~EglManager();
43
44 static const char* eglErrorString();
45
46 void initialize();
47
48 bool hasEglContext();
49
50 Result<EGLSurface, EGLint> createSurface(EGLNativeWindowType window, ColorMode colorMode,
51 sk_sp<SkColorSpace> colorSpace);
52 void destroySurface(EGLSurface surface);
53
54 void destroy();
55
56 bool isCurrent(EGLSurface surface) { return mCurrentSurface == surface; }
57 // Returns true if the current surface changed, false if it was already current
58 bool makeCurrent(EGLSurface surface, EGLint* errOut = nullptr, bool force = false);
59 Frame beginFrame(EGLSurface surface);
60 void damageFrame(const Frame& frame, const SkRect& dirty);
61 // If this returns true it is mandatory that swapBuffers is called
62 // if damageFrame is called without subsequent calls to damageFrame().
63 // See EGL_KHR_partial_update for more information
64 bool damageRequiresSwap();
65 bool swapBuffers(const Frame& frame, const SkRect& screenDirty);
66
67 // Returns true iff the surface is now preserving buffers.
68 bool setPreserveBuffer(EGLSurface surface, bool preserve);
69
70 void fence();
71
72 EGLDisplay eglDisplay() const { return mEglDisplay; }
73
74 // Inserts a wait on fence command into the OpenGL ES command stream. If EGL extension
75 // support is missing, block the CPU on the fence.
76 status_t fenceWait(int fence);
77
78 // Creates a fence that is signaled, when all the pending GL commands are flushed.
79 // Depending on installed extensions, the result is either Android native fence or EGL fence.
80 status_t createReleaseFence(bool useFenceSync, EGLSyncKHR* eglFence, int* nativeFence);
81
82 private:
83 enum class SwapBehavior {
84 Discard,
85 Preserved,
86 BufferAge,
87 };
88
89 static EGLConfig load8BitsConfig(EGLDisplay display, SwapBehavior swapBehavior);
90 static EGLConfig loadFP16Config(EGLDisplay display, SwapBehavior swapBehavior);
91 static EGLConfig load1010102Config(EGLDisplay display, SwapBehavior swapBehavior);
92 static EGLConfig loadA8Config(EGLDisplay display, SwapBehavior swapBehavior);
93
94 void initExtensions();
95 void createPBufferSurface();
96 void loadConfigs();
97 void createContext();
98 EGLint queryBufferAge(EGLSurface surface);
99
100 EGLDisplay mEglDisplay;
101 EGLConfig mEglConfig;
102 EGLConfig mEglConfigF16;
103 EGLConfig mEglConfig1010102;
104 EGLConfig mEglConfigA8;
105 EGLContext mEglContext;
106 EGLSurface mPBufferSurface;
107 EGLSurface mCurrentSurface;
108 bool mHasWideColorGamutSupport;
109 SwapBehavior mSwapBehavior = SwapBehavior::Discard;
110 };
111
112 } /* namespace renderthread */
113 } /* namespace uirenderer */
114 } /* namespace android */
115
116 #endif /* EGLMANAGER_H */