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> |
John Reck | d04794a | 2015-05-08 10:04:36 -0700 | [diff] [blame] | 20 | #include <SkRect.h> |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 21 | #include <cutils/compiler.h> |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 22 | #include <ui/GraphicBuffer.h> |
| 23 | #include <utils/StrongPointer.h> |
| 24 | |
| 25 | namespace android { |
| 26 | namespace uirenderer { |
| 27 | namespace renderthread { |
| 28 | |
Greg Daniel | cd55852 | 2016-11-17 13:31:40 -0500 | [diff] [blame] | 29 | class Frame; |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 30 | class RenderThread; |
| 31 | |
| 32 | // This class contains the shared global EGL objects, such as EGLDisplay |
| 33 | // and EGLConfig, which are re-used by CanvasContext |
| 34 | class EglManager { |
| 35 | public: |
John Reck | 1e51071 | 2018-04-23 08:15:03 -0700 | [diff] [blame] | 36 | explicit EglManager(); |
| 37 | |
| 38 | ~EglManager(); |
| 39 | |
sergeyv | 694d499 | 2016-10-27 10:23:13 -0700 | [diff] [blame] | 40 | static const char* eglErrorString(); |
John Reck | 1e51071 | 2018-04-23 08:15:03 -0700 | [diff] [blame] | 41 | |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 42 | void initialize(); |
| 43 | |
| 44 | bool hasEglContext(); |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 45 | |
Romain Guy | 26a2b97 | 2017-04-17 09:39:51 -0700 | [diff] [blame] | 46 | EGLSurface createSurface(EGLNativeWindowType window, bool wideColorGamut); |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 47 | 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 Reck | 1e51071 | 2018-04-23 08:15:03 -0700 | [diff] [blame] | 53 | bool makeCurrent(EGLSurface surface, EGLint* errOut = nullptr, bool force = false); |
John Reck | 149173d | 2015-08-10 09:52:29 -0700 | [diff] [blame] | 54 | Frame beginFrame(EGLSurface surface); |
| 55 | void damageFrame(const Frame& frame, const SkRect& dirty); |
John Reck | c96955d | 2016-02-26 14:56:44 -0800 | [diff] [blame] | 56 | // 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 Reck | 149173d | 2015-08-10 09:52:29 -0700 | [diff] [blame] | 60 | bool swapBuffers(const Frame& frame, const SkRect& screenDirty); |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 61 | |
John Reck | 1125d1f | 2014-10-23 11:02:19 -0700 | [diff] [blame] | 62 | // Returns true iff the surface is now preserving buffers. |
| 63 | bool setPreserveBuffer(EGLSurface surface, bool preserve); |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 64 | |
John Reck | 5515637 | 2015-01-21 07:46:37 -0800 | [diff] [blame] | 65 | void fence(); |
| 66 | |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 67 | private: |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 68 | |
John Reck | 149173d | 2015-08-10 09:52:29 -0700 | [diff] [blame] | 69 | void initExtensions(); |
John Reck | d7db4d7 | 2015-05-20 07:18:55 -0700 | [diff] [blame] | 70 | void createPBufferSurface(); |
Romain Guy | 26a2b97 | 2017-04-17 09:39:51 -0700 | [diff] [blame] | 71 | void loadConfigs(); |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 72 | void createContext(); |
John Reck | 149173d | 2015-08-10 09:52:29 -0700 | [diff] [blame] | 73 | EGLint queryBufferAge(EGLSurface surface); |
Season Li | 13d1b4a | 2015-07-29 17:16:19 -0700 | [diff] [blame] | 74 | |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 75 | EGLDisplay mEglDisplay; |
| 76 | EGLConfig mEglConfig; |
Romain Guy | 26a2b97 | 2017-04-17 09:39:51 -0700 | [diff] [blame] | 77 | EGLConfig mEglConfigWideGamut; |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 78 | EGLContext mEglContext; |
| 79 | EGLSurface mPBufferSurface; |
| 80 | |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 81 | EGLSurface mCurrentSurface; |
| 82 | |
John Reck | 149173d | 2015-08-10 09:52:29 -0700 | [diff] [blame] | 83 | enum class SwapBehavior { |
| 84 | Discard, |
| 85 | Preserved, |
| 86 | BufferAge, |
| 87 | }; |
| 88 | SwapBehavior mSwapBehavior = SwapBehavior::Discard; |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 89 | }; |
| 90 | |
| 91 | } /* namespace renderthread */ |
| 92 | } /* namespace uirenderer */ |
| 93 | } /* namespace android */ |
| 94 | |
| 95 | #endif /* EGLMANAGER_H */ |