Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2013 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 | |
Peiyong Lin | 7e219eb | 2018-12-03 05:40:42 -0800 | [diff] [blame] | 17 | #ifndef SF_GLESRENDERENGINE_H_ |
| 18 | #define SF_GLESRENDERENGINE_H_ |
Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 19 | |
| 20 | #include <stdint.h> |
| 21 | #include <sys/types.h> |
| 22 | |
Peiyong Lin | f11f39b | 2018-09-05 14:37:41 -0700 | [diff] [blame] | 23 | #include <EGL/egl.h> |
| 24 | #include <EGL/eglext.h> |
Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 25 | #include <GLES2/gl2.h> |
Peiyong Lin | cbc184f | 2018-08-22 13:24:10 -0700 | [diff] [blame] | 26 | #include <renderengine/RenderEngine.h> |
Peiyong Lin | 833074a | 2018-08-28 11:53:54 -0700 | [diff] [blame] | 27 | #include <renderengine/private/Description.h> |
Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 28 | |
Peiyong Lin | f11f39b | 2018-09-05 14:37:41 -0700 | [diff] [blame] | 29 | #define EGL_NO_CONFIG ((EGLConfig)0) |
| 30 | |
Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 31 | namespace android { |
Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 32 | |
Peiyong Lin | 833074a | 2018-08-28 11:53:54 -0700 | [diff] [blame] | 33 | namespace renderengine { |
| 34 | |
Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 35 | class Mesh; |
Mathias Agopian | 49457ac | 2013-08-14 18:20:17 -0700 | [diff] [blame] | 36 | class Texture; |
Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 37 | |
Peiyong Lin | 833074a | 2018-08-28 11:53:54 -0700 | [diff] [blame] | 38 | namespace gl { |
Lloyd Pique | 144e116 | 2017-12-20 16:44:52 -0800 | [diff] [blame] | 39 | |
Peiyong Lin | f1bada9 | 2018-08-29 09:39:31 -0700 | [diff] [blame] | 40 | class GLImage; |
Peiyong Lin | f1bada9 | 2018-08-29 09:39:31 -0700 | [diff] [blame] | 41 | |
Peiyong Lin | 7e219eb | 2018-12-03 05:40:42 -0800 | [diff] [blame] | 42 | class GLESRenderEngine : public impl::RenderEngine { |
Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 43 | public: |
Peiyong Lin | 7e219eb | 2018-12-03 05:40:42 -0800 | [diff] [blame] | 44 | static std::unique_ptr<GLESRenderEngine> create(int hwcFormat, uint32_t featureFlags); |
Peiyong Lin | f11f39b | 2018-09-05 14:37:41 -0700 | [diff] [blame] | 45 | static EGLConfig chooseEglConfig(EGLDisplay display, int format, bool logConfig); |
| 46 | |
Peiyong Lin | 7e219eb | 2018-12-03 05:40:42 -0800 | [diff] [blame] | 47 | GLESRenderEngine(uint32_t featureFlags, // See RenderEngine::FeatureFlag |
Peiyong Lin | fb530cf | 2018-12-15 05:07:38 +0000 | [diff] [blame] | 48 | EGLDisplay display, EGLConfig config, EGLContext ctxt, EGLSurface dummy, |
| 49 | EGLContext protectedContext, EGLSurface protectedDummy); |
Peiyong Lin | 7e219eb | 2018-12-03 05:40:42 -0800 | [diff] [blame] | 50 | ~GLESRenderEngine() override; |
Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 51 | |
Peiyong Lin | e5a9a7f | 2018-08-30 15:32:13 -0700 | [diff] [blame] | 52 | std::unique_ptr<Framebuffer> createFramebuffer() override; |
Peiyong Lin | e5a9a7f | 2018-08-30 15:32:13 -0700 | [diff] [blame] | 53 | std::unique_ptr<Image> createImage() override; |
Peiyong Lin | f1bada9 | 2018-08-29 09:39:31 -0700 | [diff] [blame] | 54 | |
| 55 | void primeCache() const override; |
Peiyong Lin | 60bedb5 | 2018-09-05 10:47:31 -0700 | [diff] [blame] | 56 | bool isCurrent() const override; |
Peiyong Lin | 60bedb5 | 2018-09-05 10:47:31 -0700 | [diff] [blame] | 57 | base::unique_fd flush() override; |
| 58 | bool finish() override; |
| 59 | bool waitFence(base::unique_fd fenceFd) override; |
| 60 | void clearWithColor(float red, float green, float blue, float alpha) override; |
Chia-I Wu | 28e3a25 | 2018-09-07 12:05:02 -0700 | [diff] [blame] | 61 | void fillRegionWithColor(const Region& region, float red, float green, float blue, |
| 62 | float alpha) override; |
Alec Mouri | 05483a0 | 2018-09-10 21:03:42 +0000 | [diff] [blame] | 63 | void setScissor(const Rect& region) override; |
Peiyong Lin | 60bedb5 | 2018-09-05 10:47:31 -0700 | [diff] [blame] | 64 | void disableScissor() override; |
| 65 | void genTextures(size_t count, uint32_t* names) override; |
| 66 | void deleteTextures(size_t count, uint32_t const* names) override; |
Peiyong Lin | e5a9a7f | 2018-08-30 15:32:13 -0700 | [diff] [blame] | 67 | void bindExternalTextureImage(uint32_t texName, const Image& image) override; |
| 68 | status_t bindFrameBuffer(Framebuffer* framebuffer) override; |
| 69 | void unbindFrameBuffer(Framebuffer* framebuffer) override; |
Peiyong Lin | 60bedb5 | 2018-09-05 10:47:31 -0700 | [diff] [blame] | 70 | void checkErrors() const override; |
Peiyong Lin | f1bada9 | 2018-08-29 09:39:31 -0700 | [diff] [blame] | 71 | |
Peiyong Lin | fb530cf | 2018-12-15 05:07:38 +0000 | [diff] [blame] | 72 | bool isProtected() const override { return mInProtectedContext; } |
| 73 | bool supportsProtectedContent() const override; |
| 74 | bool useProtectedContext(bool useProtectedContext) override; |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame^] | 75 | status_t drawLayers(const DisplaySettings& display, const std::vector<LayerSettings>& layers, |
| 76 | ANativeWindowBuffer* buffer, base::unique_fd* drawFence) override; |
Alec Mouri | 6e57f68 | 2018-09-29 20:45:08 -0700 | [diff] [blame] | 77 | |
Peiyong Lin | f11f39b | 2018-09-05 14:37:41 -0700 | [diff] [blame] | 78 | // internal to RenderEngine |
| 79 | EGLDisplay getEGLDisplay() const { return mEGLDisplay; } |
| 80 | EGLConfig getEGLConfig() const { return mEGLConfig; } |
| 81 | |
Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 82 | protected: |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 83 | void dump(std::string& result) override; |
Peiyong Lin | e5a9a7f | 2018-08-30 15:32:13 -0700 | [diff] [blame] | 84 | void setViewportAndProjection(size_t vpw, size_t vph, Rect sourceCrop, |
| 85 | ui::Transform::orientation_flags rotation) override; |
| 86 | void setupLayerBlending(bool premultipliedAlpha, bool opaque, bool disableTexture, |
Lucas Dupin | 1b6531c | 2018-07-05 17:18:21 -0700 | [diff] [blame] | 87 | const half4& color, float cornerRadius) override; |
Peiyong Lin | e5a9a7f | 2018-08-30 15:32:13 -0700 | [diff] [blame] | 88 | void setupLayerTexturing(const Texture& texture) override; |
| 89 | void setupLayerBlackedOut() override; |
| 90 | void setupFillWithColor(float r, float g, float b, float a) override; |
Peiyong Lin | d378863 | 2018-09-18 16:01:31 -0700 | [diff] [blame] | 91 | void setColorTransform(const mat4& colorTransform) override; |
Peiyong Lin | e5a9a7f | 2018-08-30 15:32:13 -0700 | [diff] [blame] | 92 | void disableTexturing() override; |
| 93 | void disableBlending() override; |
Lucas Dupin | 1b6531c | 2018-07-05 17:18:21 -0700 | [diff] [blame] | 94 | void setupCornerRadiusCropSize(float width, float height) override; |
Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 95 | |
Peiyong Lin | f11f39b | 2018-09-05 14:37:41 -0700 | [diff] [blame] | 96 | // HDR and color management related functions and state |
| 97 | void setSourceY410BT2020(bool enable) override; |
| 98 | void setSourceDataSpace(ui::Dataspace source) override; |
| 99 | void setOutputDataSpace(ui::Dataspace dataspace) override; |
| 100 | void setDisplayMaxLuminance(const float maxLuminance) override; |
| 101 | |
| 102 | // drawing |
Peiyong Lin | e5a9a7f | 2018-08-30 15:32:13 -0700 | [diff] [blame] | 103 | void drawMesh(const Mesh& mesh) override; |
Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 104 | |
Peiyong Lin | e5a9a7f | 2018-08-30 15:32:13 -0700 | [diff] [blame] | 105 | size_t getMaxTextureSize() const override; |
| 106 | size_t getMaxViewportDims() const override; |
| 107 | |
| 108 | private: |
Peiyong Lin | f11f39b | 2018-09-05 14:37:41 -0700 | [diff] [blame] | 109 | enum GlesVersion { |
| 110 | GLES_VERSION_1_0 = 0x10000, |
| 111 | GLES_VERSION_1_1 = 0x10001, |
| 112 | GLES_VERSION_2_0 = 0x20000, |
| 113 | GLES_VERSION_3_0 = 0x30000, |
| 114 | }; |
| 115 | |
| 116 | static GlesVersion parseGlesVersion(const char* str); |
Peiyong Lin | a5e9f1b | 2018-11-27 22:49:37 -0800 | [diff] [blame] | 117 | static EGLContext createEglContext(EGLDisplay display, EGLConfig config, |
Peiyong Lin | fb530cf | 2018-12-15 05:07:38 +0000 | [diff] [blame] | 118 | EGLContext shareContext, bool useContextPriority, |
| 119 | Protection protection); |
Peiyong Lin | a5e9f1b | 2018-11-27 22:49:37 -0800 | [diff] [blame] | 120 | static EGLSurface createDummyEglPbufferSurface(EGLDisplay display, EGLConfig config, |
Peiyong Lin | fb530cf | 2018-12-15 05:07:38 +0000 | [diff] [blame] | 121 | int hwcFormat, Protection protection); |
Peiyong Lin | f11f39b | 2018-09-05 14:37:41 -0700 | [diff] [blame] | 122 | |
Peiyong Lin | e5a9a7f | 2018-08-30 15:32:13 -0700 | [diff] [blame] | 123 | // A data space is considered HDR data space if it has BT2020 color space |
| 124 | // with PQ or HLG transfer function. |
| 125 | bool isHdrDataSpace(const ui::Dataspace dataSpace) const; |
| 126 | bool needsXYZTransformMatrix() const; |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame^] | 127 | // Defines the viewport, and sets the projection matrix to the projection |
| 128 | // defined by the clip. |
| 129 | void setViewportAndProjection(Rect viewport, Rect clip); |
Peiyong Lin | e5a9a7f | 2018-08-30 15:32:13 -0700 | [diff] [blame] | 130 | |
Peiyong Lin | f11f39b | 2018-09-05 14:37:41 -0700 | [diff] [blame] | 131 | EGLDisplay mEGLDisplay; |
| 132 | EGLConfig mEGLConfig; |
| 133 | EGLContext mEGLContext; |
Alec Mouri | 0a9c7b8 | 2018-11-16 13:05:25 -0800 | [diff] [blame] | 134 | EGLSurface mDummySurface; |
Peiyong Lin | fb530cf | 2018-12-15 05:07:38 +0000 | [diff] [blame] | 135 | EGLContext mProtectedEGLContext; |
| 136 | EGLSurface mProtectedDummySurface; |
Peiyong Lin | e5a9a7f | 2018-08-30 15:32:13 -0700 | [diff] [blame] | 137 | GLuint mProtectedTexName; |
| 138 | GLint mMaxViewportDims[2]; |
| 139 | GLint mMaxTextureSize; |
| 140 | GLuint mVpWidth; |
| 141 | GLuint mVpHeight; |
| 142 | Description mState; |
| 143 | |
Peiyong Lin | 70b26ce | 2018-09-18 19:02:39 -0700 | [diff] [blame] | 144 | mat4 mSrgbToXyz; |
Peiyong Lin | 70b26ce | 2018-09-18 19:02:39 -0700 | [diff] [blame] | 145 | mat4 mDisplayP3ToXyz; |
Valerie Hau | eb8e076 | 2018-11-06 10:10:42 -0800 | [diff] [blame] | 146 | mat4 mBt2020ToXyz; |
Peiyong Lin | e5a9a7f | 2018-08-30 15:32:13 -0700 | [diff] [blame] | 147 | mat4 mXyzToSrgb; |
| 148 | mat4 mXyzToDisplayP3; |
| 149 | mat4 mXyzToBt2020; |
Valerie Hau | eb8e076 | 2018-11-06 10:10:42 -0800 | [diff] [blame] | 150 | mat4 mSrgbToDisplayP3; |
| 151 | mat4 mSrgbToBt2020; |
| 152 | mat4 mDisplayP3ToSrgb; |
| 153 | mat4 mDisplayP3ToBt2020; |
| 154 | mat4 mBt2020ToSrgb; |
| 155 | mat4 mBt2020ToDisplayP3; |
Peiyong Lin | e5a9a7f | 2018-08-30 15:32:13 -0700 | [diff] [blame] | 156 | |
Peiyong Lin | fb530cf | 2018-12-15 05:07:38 +0000 | [diff] [blame] | 157 | bool mInProtectedContext = false; |
Alec Mouri | 05483a0 | 2018-09-10 21:03:42 +0000 | [diff] [blame] | 158 | int32_t mFboHeight = 0; |
Peiyong Lin | fb06930 | 2018-04-25 14:34:31 -0700 | [diff] [blame] | 159 | |
| 160 | // Current dataspace of layer being rendered |
| 161 | ui::Dataspace mDataSpace = ui::Dataspace::UNKNOWN; |
| 162 | |
| 163 | // Current output dataspace of the render engine |
| 164 | ui::Dataspace mOutputDataSpace = ui::Dataspace::UNKNOWN; |
| 165 | |
Peiyong Lin | 13effd1 | 2018-07-24 17:01:47 -0700 | [diff] [blame] | 166 | // Whether device supports color management, currently color management |
| 167 | // supports sRGB, DisplayP3 color spaces. |
| 168 | const bool mUseColorManagement = false; |
Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 169 | }; |
| 170 | |
Peiyong Lin | 46080ef | 2018-10-26 18:43:14 -0700 | [diff] [blame] | 171 | } // namespace gl |
| 172 | } // namespace renderengine |
| 173 | } // namespace android |
Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 174 | |
Peiyong Lin | 7e219eb | 2018-12-03 05:40:42 -0800 | [diff] [blame] | 175 | #endif /* SF_GLESRENDERENGINE_H_ */ |