blob: 07e5585c0468985ba6bf16431c98e9f9bfee1904 [file] [log] [blame]
Mathias Agopian3f844832013-08-07 21:24:32 -07001/*
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 Lin7e219eb2018-12-03 05:40:42 -080017#ifndef SF_GLESRENDERENGINE_H_
18#define SF_GLESRENDERENGINE_H_
Mathias Agopian3f844832013-08-07 21:24:32 -070019
20#include <stdint.h>
21#include <sys/types.h>
22
Peiyong Linf11f39b2018-09-05 14:37:41 -070023#include <EGL/egl.h>
24#include <EGL/eglext.h>
Mathias Agopian3f844832013-08-07 21:24:32 -070025#include <GLES2/gl2.h>
Peiyong Lincbc184f2018-08-22 13:24:10 -070026#include <renderengine/RenderEngine.h>
Peiyong Lin833074a2018-08-28 11:53:54 -070027#include <renderengine/private/Description.h>
Mathias Agopian3f844832013-08-07 21:24:32 -070028
Peiyong Linf11f39b2018-09-05 14:37:41 -070029#define EGL_NO_CONFIG ((EGLConfig)0)
30
Mathias Agopian3f844832013-08-07 21:24:32 -070031namespace android {
Mathias Agopian3f844832013-08-07 21:24:32 -070032
Peiyong Lin833074a2018-08-28 11:53:54 -070033namespace renderengine {
34
Mathias Agopian3f844832013-08-07 21:24:32 -070035class Mesh;
Mathias Agopian49457ac2013-08-14 18:20:17 -070036class Texture;
Mathias Agopian3f844832013-08-07 21:24:32 -070037
Peiyong Lin833074a2018-08-28 11:53:54 -070038namespace gl {
Lloyd Pique144e1162017-12-20 16:44:52 -080039
Peiyong Linf1bada92018-08-29 09:39:31 -070040class GLImage;
Peiyong Linf1bada92018-08-29 09:39:31 -070041
Peiyong Lin7e219eb2018-12-03 05:40:42 -080042class GLESRenderEngine : public impl::RenderEngine {
Mathias Agopian3f844832013-08-07 21:24:32 -070043public:
Peiyong Lin7e219eb2018-12-03 05:40:42 -080044 static std::unique_ptr<GLESRenderEngine> create(int hwcFormat, uint32_t featureFlags);
Peiyong Linf11f39b2018-09-05 14:37:41 -070045 static EGLConfig chooseEglConfig(EGLDisplay display, int format, bool logConfig);
46
Peiyong Lin7e219eb2018-12-03 05:40:42 -080047 GLESRenderEngine(uint32_t featureFlags, // See RenderEngine::FeatureFlag
Peiyong Linfb530cf2018-12-15 05:07:38 +000048 EGLDisplay display, EGLConfig config, EGLContext ctxt, EGLSurface dummy,
49 EGLContext protectedContext, EGLSurface protectedDummy);
Peiyong Lin7e219eb2018-12-03 05:40:42 -080050 ~GLESRenderEngine() override;
Mathias Agopian3f844832013-08-07 21:24:32 -070051
Peiyong Line5a9a7f2018-08-30 15:32:13 -070052 std::unique_ptr<Framebuffer> createFramebuffer() override;
Peiyong Line5a9a7f2018-08-30 15:32:13 -070053 std::unique_ptr<Image> createImage() override;
Peiyong Linf1bada92018-08-29 09:39:31 -070054
55 void primeCache() const override;
Peiyong Lin60bedb52018-09-05 10:47:31 -070056 bool isCurrent() const override;
Peiyong Lin60bedb52018-09-05 10:47:31 -070057 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 Wu28e3a252018-09-07 12:05:02 -070061 void fillRegionWithColor(const Region& region, float red, float green, float blue,
62 float alpha) override;
Alec Mouri05483a02018-09-10 21:03:42 +000063 void setScissor(const Rect& region) override;
Peiyong Lin60bedb52018-09-05 10:47:31 -070064 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 Line5a9a7f2018-08-30 15:32:13 -070067 void bindExternalTextureImage(uint32_t texName, const Image& image) override;
68 status_t bindFrameBuffer(Framebuffer* framebuffer) override;
69 void unbindFrameBuffer(Framebuffer* framebuffer) override;
Peiyong Lin60bedb52018-09-05 10:47:31 -070070 void checkErrors() const override;
Peiyong Linf1bada92018-08-29 09:39:31 -070071
Peiyong Linfb530cf2018-12-15 05:07:38 +000072 bool isProtected() const override { return mInProtectedContext; }
73 bool supportsProtectedContent() const override;
74 bool useProtectedContext(bool useProtectedContext) override;
Alec Mouri6e57f682018-09-29 20:45:08 -070075 status_t drawLayers(const DisplaySettings& settings, const std::vector<LayerSettings>& layers,
76 ANativeWindowBuffer* const buffer,
77 base::unique_fd* displayFence) const override;
78
Peiyong Linf11f39b2018-09-05 14:37:41 -070079 // internal to RenderEngine
80 EGLDisplay getEGLDisplay() const { return mEGLDisplay; }
81 EGLConfig getEGLConfig() const { return mEGLConfig; }
82
Mathias Agopian3f844832013-08-07 21:24:32 -070083protected:
Yiwei Zhang5434a782018-12-05 18:06:32 -080084 void dump(std::string& result) override;
Peiyong Line5a9a7f2018-08-30 15:32:13 -070085 void setViewportAndProjection(size_t vpw, size_t vph, Rect sourceCrop,
86 ui::Transform::orientation_flags rotation) override;
87 void setupLayerBlending(bool premultipliedAlpha, bool opaque, bool disableTexture,
Lucas Dupin1b6531c2018-07-05 17:18:21 -070088 const half4& color, float cornerRadius) override;
Peiyong Line5a9a7f2018-08-30 15:32:13 -070089 void setupLayerTexturing(const Texture& texture) override;
90 void setupLayerBlackedOut() override;
91 void setupFillWithColor(float r, float g, float b, float a) override;
Peiyong Lind3788632018-09-18 16:01:31 -070092 void setColorTransform(const mat4& colorTransform) override;
Peiyong Line5a9a7f2018-08-30 15:32:13 -070093 void disableTexturing() override;
94 void disableBlending() override;
Lucas Dupin1b6531c2018-07-05 17:18:21 -070095 void setupCornerRadiusCropSize(float width, float height) override;
Mathias Agopian3f844832013-08-07 21:24:32 -070096
Peiyong Linf11f39b2018-09-05 14:37:41 -070097 // HDR and color management related functions and state
98 void setSourceY410BT2020(bool enable) override;
99 void setSourceDataSpace(ui::Dataspace source) override;
100 void setOutputDataSpace(ui::Dataspace dataspace) override;
101 void setDisplayMaxLuminance(const float maxLuminance) override;
102
103 // drawing
Peiyong Line5a9a7f2018-08-30 15:32:13 -0700104 void drawMesh(const Mesh& mesh) override;
Mathias Agopian3f844832013-08-07 21:24:32 -0700105
Peiyong Line5a9a7f2018-08-30 15:32:13 -0700106 size_t getMaxTextureSize() const override;
107 size_t getMaxViewportDims() const override;
108
109private:
Peiyong Linf11f39b2018-09-05 14:37:41 -0700110 enum GlesVersion {
111 GLES_VERSION_1_0 = 0x10000,
112 GLES_VERSION_1_1 = 0x10001,
113 GLES_VERSION_2_0 = 0x20000,
114 GLES_VERSION_3_0 = 0x30000,
115 };
116
117 static GlesVersion parseGlesVersion(const char* str);
Peiyong Lina5e9f1b2018-11-27 22:49:37 -0800118 static EGLContext createEglContext(EGLDisplay display, EGLConfig config,
Peiyong Linfb530cf2018-12-15 05:07:38 +0000119 EGLContext shareContext, bool useContextPriority,
120 Protection protection);
Peiyong Lina5e9f1b2018-11-27 22:49:37 -0800121 static EGLSurface createDummyEglPbufferSurface(EGLDisplay display, EGLConfig config,
Peiyong Linfb530cf2018-12-15 05:07:38 +0000122 int hwcFormat, Protection protection);
Peiyong Linf11f39b2018-09-05 14:37:41 -0700123
Peiyong Line5a9a7f2018-08-30 15:32:13 -0700124 // A data space is considered HDR data space if it has BT2020 color space
125 // with PQ or HLG transfer function.
126 bool isHdrDataSpace(const ui::Dataspace dataSpace) const;
127 bool needsXYZTransformMatrix() const;
128
Peiyong Linf11f39b2018-09-05 14:37:41 -0700129 EGLDisplay mEGLDisplay;
130 EGLConfig mEGLConfig;
131 EGLContext mEGLContext;
Alec Mouri0a9c7b82018-11-16 13:05:25 -0800132 EGLSurface mDummySurface;
Peiyong Linfb530cf2018-12-15 05:07:38 +0000133 EGLContext mProtectedEGLContext;
134 EGLSurface mProtectedDummySurface;
Peiyong Line5a9a7f2018-08-30 15:32:13 -0700135 GLuint mProtectedTexName;
136 GLint mMaxViewportDims[2];
137 GLint mMaxTextureSize;
138 GLuint mVpWidth;
139 GLuint mVpHeight;
140 Description mState;
141
Peiyong Lin70b26ce2018-09-18 19:02:39 -0700142 mat4 mSrgbToXyz;
Peiyong Lin70b26ce2018-09-18 19:02:39 -0700143 mat4 mDisplayP3ToXyz;
Valerie Haueb8e0762018-11-06 10:10:42 -0800144 mat4 mBt2020ToXyz;
Peiyong Line5a9a7f2018-08-30 15:32:13 -0700145 mat4 mXyzToSrgb;
146 mat4 mXyzToDisplayP3;
147 mat4 mXyzToBt2020;
Valerie Haueb8e0762018-11-06 10:10:42 -0800148 mat4 mSrgbToDisplayP3;
149 mat4 mSrgbToBt2020;
150 mat4 mDisplayP3ToSrgb;
151 mat4 mDisplayP3ToBt2020;
152 mat4 mBt2020ToSrgb;
153 mat4 mBt2020ToDisplayP3;
Peiyong Line5a9a7f2018-08-30 15:32:13 -0700154
Peiyong Linfb530cf2018-12-15 05:07:38 +0000155 bool mInProtectedContext = false;
Alec Mouri05483a02018-09-10 21:03:42 +0000156 int32_t mFboHeight = 0;
Peiyong Linfb069302018-04-25 14:34:31 -0700157
158 // Current dataspace of layer being rendered
159 ui::Dataspace mDataSpace = ui::Dataspace::UNKNOWN;
160
161 // Current output dataspace of the render engine
162 ui::Dataspace mOutputDataSpace = ui::Dataspace::UNKNOWN;
163
Peiyong Lin13effd12018-07-24 17:01:47 -0700164 // Whether device supports color management, currently color management
165 // supports sRGB, DisplayP3 color spaces.
166 const bool mUseColorManagement = false;
Mathias Agopian3f844832013-08-07 21:24:32 -0700167};
168
Peiyong Lin46080ef2018-10-26 18:43:14 -0700169} // namespace gl
170} // namespace renderengine
171} // namespace android
Mathias Agopian3f844832013-08-07 21:24:32 -0700172
Peiyong Lin7e219eb2018-12-03 05:40:42 -0800173#endif /* SF_GLESRENDERENGINE_H_ */