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> |
Peiyong Lin | 1f6aa12 | 2018-09-10 16:28:08 -0700 | [diff] [blame] | 21 | #include <SkImageInfo.h> |
John Reck | d04794a | 2015-05-08 10:04:36 -0700 | [diff] [blame] | 22 | #include <SkRect.h> |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 23 | #include <cutils/compiler.h> |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 24 | #include <utils/StrongPointer.h> |
Stan Iliev | aaa9e83 | 2019-09-17 14:07:23 -0400 | [diff] [blame] | 25 | |
Peiyong Lin | 1f6aa12 | 2018-09-10 16:28:08 -0700 | [diff] [blame] | 26 | #include "IRenderPipeline.h" |
John Reck | 8e539ca | 2018-11-15 15:21:29 -0800 | [diff] [blame] | 27 | #include "utils/Result.h" |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 28 | |
| 29 | namespace android { |
| 30 | namespace uirenderer { |
| 31 | namespace renderthread { |
| 32 | |
Greg Daniel | cd55852 | 2016-11-17 13:31:40 -0500 | [diff] [blame] | 33 | class Frame; |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 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: |
John Reck | 1e51071 | 2018-04-23 08:15:03 -0700 | [diff] [blame] | 40 | explicit EglManager(); |
| 41 | |
| 42 | ~EglManager(); |
| 43 | |
sergeyv | 694d499 | 2016-10-27 10:23:13 -0700 | [diff] [blame] | 44 | static const char* eglErrorString(); |
John Reck | 1e51071 | 2018-04-23 08:15:03 -0700 | [diff] [blame] | 45 | |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 46 | void initialize(); |
| 47 | |
| 48 | bool hasEglContext(); |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 49 | |
Peiyong Lin | 3bff135 | 2018-12-11 07:56:07 -0800 | [diff] [blame] | 50 | Result<EGLSurface, EGLint> createSurface(EGLNativeWindowType window, ColorMode colorMode, |
Brian Osman | e0cf597 | 2019-01-23 10:41:20 -0500 | [diff] [blame] | 51 | sk_sp<SkColorSpace> colorSpace); |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 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 |
John Reck | 1e51071 | 2018-04-23 08:15:03 -0700 | [diff] [blame] | 58 | bool makeCurrent(EGLSurface surface, EGLint* errOut = nullptr, bool force = false); |
John Reck | 149173d | 2015-08-10 09:52:29 -0700 | [diff] [blame] | 59 | Frame beginFrame(EGLSurface surface); |
| 60 | void damageFrame(const Frame& frame, const SkRect& dirty); |
John Reck | c96955d | 2016-02-26 14:56:44 -0800 | [diff] [blame] | 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(); |
John Reck | 149173d | 2015-08-10 09:52:29 -0700 | [diff] [blame] | 65 | bool swapBuffers(const Frame& frame, const SkRect& screenDirty); |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 66 | |
John Reck | 1125d1f | 2014-10-23 11:02:19 -0700 | [diff] [blame] | 67 | // Returns true iff the surface is now preserving buffers. |
| 68 | bool setPreserveBuffer(EGLSurface surface, bool preserve); |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 69 | |
John Reck | 5515637 | 2015-01-21 07:46:37 -0800 | [diff] [blame] | 70 | void fence(); |
| 71 | |
John Reck | e170fb6 | 2018-05-07 08:12:07 -0700 | [diff] [blame] | 72 | EGLDisplay eglDisplay() const { return mEglDisplay; } |
| 73 | |
Stan Iliev | 564ca3e | 2018-09-04 22:00:00 +0000 | [diff] [blame] | 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. |
Stan Iliev | aaa9e83 | 2019-09-17 14:07:23 -0400 | [diff] [blame] | 76 | status_t fenceWait(int fence); |
Stan Iliev | 564ca3e | 2018-09-04 22:00:00 +0000 | [diff] [blame] | 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. |
Stan Iliev | aaa9e83 | 2019-09-17 14:07:23 -0400 | [diff] [blame] | 80 | status_t createReleaseFence(bool useFenceSync, EGLSyncKHR* eglFence, int* nativeFence); |
Stan Iliev | 564ca3e | 2018-09-04 22:00:00 +0000 | [diff] [blame] | 81 | |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 82 | private: |
Peiyong Lin | 3bff135 | 2018-12-11 07:56:07 -0800 | [diff] [blame] | 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); |
John Reck | b36bfdd | 2020-07-23 13:47:49 -0700 | [diff] [blame^] | 91 | static EGLConfig load1010102Config(EGLDisplay display, SwapBehavior swapBehavior); |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 92 | |
John Reck | 149173d | 2015-08-10 09:52:29 -0700 | [diff] [blame] | 93 | void initExtensions(); |
John Reck | d7db4d7 | 2015-05-20 07:18:55 -0700 | [diff] [blame] | 94 | void createPBufferSurface(); |
Romain Guy | 26a2b97 | 2017-04-17 09:39:51 -0700 | [diff] [blame] | 95 | void loadConfigs(); |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 96 | void createContext(); |
John Reck | 149173d | 2015-08-10 09:52:29 -0700 | [diff] [blame] | 97 | EGLint queryBufferAge(EGLSurface surface); |
Season Li | 13d1b4a | 2015-07-29 17:16:19 -0700 | [diff] [blame] | 98 | |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 99 | EGLDisplay mEglDisplay; |
| 100 | EGLConfig mEglConfig; |
John Reck | b36bfdd | 2020-07-23 13:47:49 -0700 | [diff] [blame^] | 101 | EGLConfig mEglConfigF16; |
| 102 | EGLConfig mEglConfig1010102; |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 103 | EGLContext mEglContext; |
| 104 | EGLSurface mPBufferSurface; |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 105 | EGLSurface mCurrentSurface; |
Peiyong Lin | 3bff135 | 2018-12-11 07:56:07 -0800 | [diff] [blame] | 106 | bool mHasWideColorGamutSupport; |
John Reck | 149173d | 2015-08-10 09:52:29 -0700 | [diff] [blame] | 107 | SwapBehavior mSwapBehavior = SwapBehavior::Discard; |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 108 | }; |
| 109 | |
| 110 | } /* namespace renderthread */ |
| 111 | } /* namespace uirenderer */ |
| 112 | } /* namespace android */ |
| 113 | |
| 114 | #endif /* EGLMANAGER_H */ |