John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 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 | |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 19 | #include <EGL/egl.h> |
Stan Iliev | 564ca3e | 2018-09-04 22:00:00 +0000 | [diff] [blame^] | 20 | #include <EGL/eglext.h> |
John Reck | d04794a | 2015-05-08 10:04:36 -0700 | [diff] [blame] | 21 | #include <SkRect.h> |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 22 | #include <cutils/compiler.h> |
Stan Iliev | 564ca3e | 2018-09-04 22:00:00 +0000 | [diff] [blame^] | 23 | #include <ui/Fence.h> |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 24 | #include <ui/GraphicBuffer.h> |
| 25 | #include <utils/StrongPointer.h> |
| 26 | |
| 27 | namespace android { |
| 28 | namespace uirenderer { |
| 29 | namespace renderthread { |
| 30 | |
Greg Daniel | cd55852 | 2016-11-17 13:31:40 -0500 | [diff] [blame] | 31 | class Frame; |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 32 | class RenderThread; |
| 33 | |
| 34 | // This class contains the shared global EGL objects, such as EGLDisplay |
| 35 | // and EGLConfig, which are re-used by CanvasContext |
| 36 | class EglManager { |
| 37 | public: |
John Reck | 1e51071 | 2018-04-23 08:15:03 -0700 | [diff] [blame] | 38 | explicit EglManager(); |
| 39 | |
| 40 | ~EglManager(); |
| 41 | |
sergeyv | 694d499 | 2016-10-27 10:23:13 -0700 | [diff] [blame] | 42 | static const char* eglErrorString(); |
John Reck | 1e51071 | 2018-04-23 08:15:03 -0700 | [diff] [blame] | 43 | |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 44 | void initialize(); |
| 45 | |
| 46 | bool hasEglContext(); |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 47 | |
Romain Guy | 26a2b97 | 2017-04-17 09:39:51 -0700 | [diff] [blame] | 48 | EGLSurface createSurface(EGLNativeWindowType window, bool wideColorGamut); |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 49 | void destroySurface(EGLSurface surface); |
| 50 | |
| 51 | void destroy(); |
| 52 | |
| 53 | bool isCurrent(EGLSurface surface) { return mCurrentSurface == surface; } |
| 54 | // Returns true if the current surface changed, false if it was already current |
John Reck | 1e51071 | 2018-04-23 08:15:03 -0700 | [diff] [blame] | 55 | bool makeCurrent(EGLSurface surface, EGLint* errOut = nullptr, bool force = false); |
John Reck | 149173d | 2015-08-10 09:52:29 -0700 | [diff] [blame] | 56 | Frame beginFrame(EGLSurface surface); |
| 57 | void damageFrame(const Frame& frame, const SkRect& dirty); |
John Reck | c96955d | 2016-02-26 14:56:44 -0800 | [diff] [blame] | 58 | // If this returns true it is mandatory that swapBuffers is called |
| 59 | // if damageFrame is called without subsequent calls to damageFrame(). |
| 60 | // See EGL_KHR_partial_update for more information |
| 61 | bool damageRequiresSwap(); |
John Reck | 149173d | 2015-08-10 09:52:29 -0700 | [diff] [blame] | 62 | bool swapBuffers(const Frame& frame, const SkRect& screenDirty); |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 63 | |
John Reck | 1125d1f | 2014-10-23 11:02:19 -0700 | [diff] [blame] | 64 | // Returns true iff the surface is now preserving buffers. |
| 65 | bool setPreserveBuffer(EGLSurface surface, bool preserve); |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 66 | |
John Reck | 5515637 | 2015-01-21 07:46:37 -0800 | [diff] [blame] | 67 | void fence(); |
| 68 | |
John Reck | e170fb6 | 2018-05-07 08:12:07 -0700 | [diff] [blame] | 69 | EGLDisplay eglDisplay() const { return mEglDisplay; } |
| 70 | |
Stan Iliev | 564ca3e | 2018-09-04 22:00:00 +0000 | [diff] [blame^] | 71 | // Inserts a wait on fence command into the OpenGL ES command stream. If EGL extension |
| 72 | // support is missing, block the CPU on the fence. |
| 73 | status_t fenceWait(sp<Fence>& fence); |
| 74 | |
| 75 | // Creates a fence that is signaled, when all the pending GL commands are flushed. |
| 76 | // Depending on installed extensions, the result is either Android native fence or EGL fence. |
| 77 | status_t createReleaseFence(bool useFenceSync, EGLSyncKHR* eglFence, sp<Fence>& nativeFence); |
| 78 | |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 79 | private: |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 80 | |
John Reck | 149173d | 2015-08-10 09:52:29 -0700 | [diff] [blame] | 81 | void initExtensions(); |
John Reck | d7db4d7 | 2015-05-20 07:18:55 -0700 | [diff] [blame] | 82 | void createPBufferSurface(); |
Romain Guy | 26a2b97 | 2017-04-17 09:39:51 -0700 | [diff] [blame] | 83 | void loadConfigs(); |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 84 | void createContext(); |
John Reck | 149173d | 2015-08-10 09:52:29 -0700 | [diff] [blame] | 85 | EGLint queryBufferAge(EGLSurface surface); |
Season Li | 13d1b4a | 2015-07-29 17:16:19 -0700 | [diff] [blame] | 86 | |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 87 | EGLDisplay mEglDisplay; |
| 88 | EGLConfig mEglConfig; |
Romain Guy | 26a2b97 | 2017-04-17 09:39:51 -0700 | [diff] [blame] | 89 | EGLConfig mEglConfigWideGamut; |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 90 | EGLContext mEglContext; |
| 91 | EGLSurface mPBufferSurface; |
| 92 | |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 93 | EGLSurface mCurrentSurface; |
| 94 | |
John Reck | 149173d | 2015-08-10 09:52:29 -0700 | [diff] [blame] | 95 | enum class SwapBehavior { |
| 96 | Discard, |
| 97 | Preserved, |
| 98 | BufferAge, |
| 99 | }; |
| 100 | SwapBehavior mSwapBehavior = SwapBehavior::Discard; |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 101 | }; |
| 102 | |
| 103 | } /* namespace renderthread */ |
| 104 | } /* namespace uirenderer */ |
| 105 | } /* namespace android */ |
| 106 | |
| 107 | #endif /* EGLMANAGER_H */ |