blob: 8e8bb8b68a1c59c4cb77f51e7c1782dbe20a0d8d [file] [log] [blame]
John Reck3b202512014-06-23 13:13:08 -07001/*
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
John Reck3b202512014-06-23 13:13:08 -070019#include <EGL/egl.h>
John Reckd04794a2015-05-08 10:04:36 -070020#include <SkRect.h>
John Reck1bcacfd2017-11-03 10:12:19 -070021#include <cutils/compiler.h>
John Reck3b202512014-06-23 13:13:08 -070022#include <ui/GraphicBuffer.h>
23#include <utils/StrongPointer.h>
24
25namespace android {
26namespace uirenderer {
27namespace renderthread {
28
Greg Danielcd558522016-11-17 13:31:40 -050029class Frame;
John Reck3b202512014-06-23 13:13:08 -070030class RenderThread;
31
32// This class contains the shared global EGL objects, such as EGLDisplay
33// and EGLConfig, which are re-used by CanvasContext
34class EglManager {
35public:
John Reck1e510712018-04-23 08:15:03 -070036 explicit EglManager();
37
38 ~EglManager();
39
sergeyv694d4992016-10-27 10:23:13 -070040 static const char* eglErrorString();
John Reck1e510712018-04-23 08:15:03 -070041
John Reck3b202512014-06-23 13:13:08 -070042 void initialize();
43
44 bool hasEglContext();
John Reck3b202512014-06-23 13:13:08 -070045
Romain Guy26a2b972017-04-17 09:39:51 -070046 EGLSurface createSurface(EGLNativeWindowType window, bool wideColorGamut);
John Reck3b202512014-06-23 13:13:08 -070047 void destroySurface(EGLSurface surface);
48
49 void destroy();
50
51 bool isCurrent(EGLSurface surface) { return mCurrentSurface == surface; }
52 // Returns true if the current surface changed, false if it was already current
John Reck1e510712018-04-23 08:15:03 -070053 bool makeCurrent(EGLSurface surface, EGLint* errOut = nullptr, bool force = false);
John Reck149173d2015-08-10 09:52:29 -070054 Frame beginFrame(EGLSurface surface);
55 void damageFrame(const Frame& frame, const SkRect& dirty);
John Reckc96955d2016-02-26 14:56:44 -080056 // If this returns true it is mandatory that swapBuffers is called
57 // if damageFrame is called without subsequent calls to damageFrame().
58 // See EGL_KHR_partial_update for more information
59 bool damageRequiresSwap();
John Reck149173d2015-08-10 09:52:29 -070060 bool swapBuffers(const Frame& frame, const SkRect& screenDirty);
John Reck3b202512014-06-23 13:13:08 -070061
John Reck1125d1f2014-10-23 11:02:19 -070062 // Returns true iff the surface is now preserving buffers.
63 bool setPreserveBuffer(EGLSurface surface, bool preserve);
John Reck3b202512014-06-23 13:13:08 -070064
John Reck55156372015-01-21 07:46:37 -080065 void fence();
66
John Recke170fb62018-05-07 08:12:07 -070067 EGLDisplay eglDisplay() const { return mEglDisplay; }
68
John Reck3b202512014-06-23 13:13:08 -070069private:
John Reck3b202512014-06-23 13:13:08 -070070
John Reck149173d2015-08-10 09:52:29 -070071 void initExtensions();
John Reckd7db4d72015-05-20 07:18:55 -070072 void createPBufferSurface();
Romain Guy26a2b972017-04-17 09:39:51 -070073 void loadConfigs();
John Reck3b202512014-06-23 13:13:08 -070074 void createContext();
John Reck149173d2015-08-10 09:52:29 -070075 EGLint queryBufferAge(EGLSurface surface);
Season Li13d1b4a2015-07-29 17:16:19 -070076
John Reck3b202512014-06-23 13:13:08 -070077 EGLDisplay mEglDisplay;
78 EGLConfig mEglConfig;
Romain Guy26a2b972017-04-17 09:39:51 -070079 EGLConfig mEglConfigWideGamut;
John Reck3b202512014-06-23 13:13:08 -070080 EGLContext mEglContext;
81 EGLSurface mPBufferSurface;
82
John Reck3b202512014-06-23 13:13:08 -070083 EGLSurface mCurrentSurface;
84
John Reck149173d2015-08-10 09:52:29 -070085 enum class SwapBehavior {
86 Discard,
87 Preserved,
88 BufferAge,
89 };
90 SwapBehavior mSwapBehavior = SwapBehavior::Discard;
John Reck3b202512014-06-23 13:13:08 -070091};
92
93} /* namespace renderthread */
94} /* namespace uirenderer */
95} /* namespace android */
96
97#endif /* EGLMANAGER_H */