blob: ca6d1b8b74c60f957c72bd5573cd984d93615a30 [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 Reck3b202512014-06-23 13:13:08 -070067private:
John Reck3b202512014-06-23 13:13:08 -070068
John Reck149173d2015-08-10 09:52:29 -070069 void initExtensions();
John Reckd7db4d72015-05-20 07:18:55 -070070 void createPBufferSurface();
Romain Guy26a2b972017-04-17 09:39:51 -070071 void loadConfigs();
John Reck3b202512014-06-23 13:13:08 -070072 void createContext();
John Reck149173d2015-08-10 09:52:29 -070073 EGLint queryBufferAge(EGLSurface surface);
Season Li13d1b4a2015-07-29 17:16:19 -070074
John Reck3b202512014-06-23 13:13:08 -070075 EGLDisplay mEglDisplay;
76 EGLConfig mEglConfig;
Romain Guy26a2b972017-04-17 09:39:51 -070077 EGLConfig mEglConfigWideGamut;
John Reck3b202512014-06-23 13:13:08 -070078 EGLContext mEglContext;
79 EGLSurface mPBufferSurface;
80
John Reck3b202512014-06-23 13:13:08 -070081 EGLSurface mCurrentSurface;
82
John Reck149173d2015-08-10 09:52:29 -070083 enum class SwapBehavior {
84 Discard,
85 Preserved,
86 BufferAge,
87 };
88 SwapBehavior mSwapBehavior = SwapBehavior::Discard;
John Reck3b202512014-06-23 13:13:08 -070089};
90
91} /* namespace renderthread */
92} /* namespace uirenderer */
93} /* namespace android */
94
95#endif /* EGLMANAGER_H */