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> |
Stan Iliev | 564ca3e | 2018-09-04 22:00:00 +0000 | [diff] [blame] | 24 | #include <ui/Fence.h> |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 25 | #include <ui/GraphicBuffer.h> |
| 26 | #include <utils/StrongPointer.h> |
Peiyong Lin | 1f6aa12 | 2018-09-10 16:28:08 -0700 | [diff] [blame^] | 27 | #include "IRenderPipeline.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 | 1f6aa12 | 2018-09-10 16:28:08 -0700 | [diff] [blame^] | 50 | EGLSurface createSurface(EGLNativeWindowType window, ColorMode colorMode); |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 51 | void destroySurface(EGLSurface surface); |
| 52 | |
| 53 | void destroy(); |
| 54 | |
| 55 | bool isCurrent(EGLSurface surface) { return mCurrentSurface == surface; } |
| 56 | // 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] | 57 | bool makeCurrent(EGLSurface surface, EGLint* errOut = nullptr, bool force = false); |
John Reck | 149173d | 2015-08-10 09:52:29 -0700 | [diff] [blame] | 58 | Frame beginFrame(EGLSurface surface); |
| 59 | void damageFrame(const Frame& frame, const SkRect& dirty); |
John Reck | c96955d | 2016-02-26 14:56:44 -0800 | [diff] [blame] | 60 | // If this returns true it is mandatory that swapBuffers is called |
| 61 | // if damageFrame is called without subsequent calls to damageFrame(). |
| 62 | // See EGL_KHR_partial_update for more information |
| 63 | bool damageRequiresSwap(); |
John Reck | 149173d | 2015-08-10 09:52:29 -0700 | [diff] [blame] | 64 | bool swapBuffers(const Frame& frame, const SkRect& screenDirty); |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 65 | |
John Reck | 1125d1f | 2014-10-23 11:02:19 -0700 | [diff] [blame] | 66 | // Returns true iff the surface is now preserving buffers. |
| 67 | bool setPreserveBuffer(EGLSurface surface, bool preserve); |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 68 | |
John Reck | 5515637 | 2015-01-21 07:46:37 -0800 | [diff] [blame] | 69 | void fence(); |
| 70 | |
John Reck | e170fb6 | 2018-05-07 08:12:07 -0700 | [diff] [blame] | 71 | EGLDisplay eglDisplay() const { return mEglDisplay; } |
| 72 | |
Stan Iliev | 564ca3e | 2018-09-04 22:00:00 +0000 | [diff] [blame] | 73 | // Inserts a wait on fence command into the OpenGL ES command stream. If EGL extension |
| 74 | // support is missing, block the CPU on the fence. |
| 75 | status_t fenceWait(sp<Fence>& fence); |
| 76 | |
| 77 | // Creates a fence that is signaled, when all the pending GL commands are flushed. |
| 78 | // Depending on installed extensions, the result is either Android native fence or EGL fence. |
| 79 | status_t createReleaseFence(bool useFenceSync, EGLSyncKHR* eglFence, sp<Fence>& nativeFence); |
| 80 | |
Peiyong Lin | 1f6aa12 | 2018-09-10 16:28:08 -0700 | [diff] [blame^] | 81 | SkColorType getSurfaceColorType() const { return mSurfaceColorType; } |
| 82 | sk_sp<SkColorSpace> getSurfaceColorSpace() { return mSurfaceColorSpace; } |
| 83 | |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 84 | private: |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 85 | |
John Reck | 149173d | 2015-08-10 09:52:29 -0700 | [diff] [blame] | 86 | void initExtensions(); |
John Reck | d7db4d7 | 2015-05-20 07:18:55 -0700 | [diff] [blame] | 87 | void createPBufferSurface(); |
Romain Guy | 26a2b97 | 2017-04-17 09:39:51 -0700 | [diff] [blame] | 88 | void loadConfigs(); |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 89 | void createContext(); |
John Reck | 149173d | 2015-08-10 09:52:29 -0700 | [diff] [blame] | 90 | EGLint queryBufferAge(EGLSurface surface); |
Season Li | 13d1b4a | 2015-07-29 17:16:19 -0700 | [diff] [blame] | 91 | |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 92 | EGLDisplay mEglDisplay; |
| 93 | EGLConfig mEglConfig; |
Romain Guy | 26a2b97 | 2017-04-17 09:39:51 -0700 | [diff] [blame] | 94 | EGLConfig mEglConfigWideGamut; |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 95 | EGLContext mEglContext; |
| 96 | EGLSurface mPBufferSurface; |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 97 | EGLSurface mCurrentSurface; |
Peiyong Lin | 1f6aa12 | 2018-09-10 16:28:08 -0700 | [diff] [blame^] | 98 | SkColorSpace::Gamut mSurfaceColorGamut; |
| 99 | SkColorType mSurfaceColorType; |
| 100 | sk_sp<SkColorSpace> mSurfaceColorSpace; |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 101 | |
John Reck | 149173d | 2015-08-10 09:52:29 -0700 | [diff] [blame] | 102 | enum class SwapBehavior { |
| 103 | Discard, |
| 104 | Preserved, |
| 105 | BufferAge, |
| 106 | }; |
| 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 */ |