| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
#ifndef EGLMANAGER_H |
| 17 |
#define EGLMANAGER_H |
| 18 |
|
| 19 |
#include <EGL/egl.h> |
| 20 |
#include <EGL/eglext.h> |
| 21 |
#include <SkImageInfo.h> |
| 22 |
#include <SkRect.h> |
| 23 |
#include <cutils/compiler.h> |
| 24 |
#include <utils/StrongPointer.h> |
| 25 |
|
| 26 |
#include "IRenderPipeline.h" |
| 27 |
#include "utils/Result.h" |
| 28 |
|
| 29 |
namespace android { |
| 30 |
namespace uirenderer { |
| 31 |
namespace renderthread { |
| 32 |
|
| 33 |
class Frame; |
| 34 |
class RenderThread; |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
class EglManager { |
| 39 |
public: |
| 40 |
explicit EglManager(); |
| 41 |
|
| 42 |
~EglManager(); |
| 43 |
|
| 44 |
static const char* eglErrorString(); |
| 45 |
|
| 46 |
void initialize(); |
| 47 |
|
| 48 |
bool hasEglContext(); |
| 49 |
|
| 50 |
Result<EGLSurface, EGLint> createSurface(EGLNativeWindowType window, ColorMode colorMode, |
| 51 |
sk_sp<SkColorSpace> colorSpace); |
| 52 |
void destroySurface(EGLSurface surface); |
| 53 |
|
| 54 |
void destroy(); |
| 55 |
|
| 56 |
bool isCurrent(EGLSurface surface) { return mCurrentSurface == surface; } |
| 57 |
|
| 58 |
bool makeCurrent(EGLSurface surface, EGLint* errOut = nullptr, bool force = false); |
| 59 |
Frame beginFrame(EGLSurface surface); |
| 60 |
void damageFrame(const Frame& frame, const SkRect& dirty); |
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
bool damageRequiresSwap(); |
| 65 |
bool swapBuffers(const Frame& frame, const SkRect& screenDirty); |
| 66 |
|
| 67 |
|
| 68 |
bool setPreserveBuffer(EGLSurface surface, bool preserve); |
| 69 |
|
| 70 |
void fence(); |
| 71 |
|
| 72 |
EGLDisplay eglDisplay() const { return mEglDisplay; } |
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
status_t fenceWait(int fence); |
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
status_t createReleaseFence(bool useFenceSync, EGLSyncKHR* eglFence, int* nativeFence); |
| 81 |
|
| 82 |
private: |
| 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); |
| 91 |
static EGLConfig load1010102Config(EGLDisplay display, SwapBehavior swapBehavior); |
| 92 |
static EGLConfig loadA8Config(EGLDisplay display, SwapBehavior swapBehavior); |
| 93 |
|
| 94 |
void initExtensions(); |
| 95 |
void createPBufferSurface(); |
| 96 |
void loadConfigs(); |
| 97 |
void createContext(); |
| 98 |
EGLint queryBufferAge(EGLSurface surface); |
| 99 |
|
| 100 |
EGLDisplay mEglDisplay; |
| 101 |
EGLConfig mEglConfig; |
| 102 |
EGLConfig mEglConfigF16; |
| 103 |
EGLConfig mEglConfig1010102; |
| 104 |
EGLConfig mEglConfigA8; |
| 105 |
EGLContext mEglContext; |
| 106 |
EGLSurface mPBufferSurface; |
| 107 |
EGLSurface mCurrentSurface; |
| 108 |
bool mHasWideColorGamutSupport; |
| 109 |
SwapBehavior mSwapBehavior = SwapBehavior::Discard; |
| 110 |
}; |
| 111 |
|
| 112 |
} |
| 113 |
} |
| 114 |
} |
| 115 |
|
| 116 |
#endif |