blob: 8876d66c9eda20c604b24b150ef1bfa3e9458b20 [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
33class String8;
Peiyong Lin833074a2018-08-28 11:53:54 -070034
35namespace renderengine {
36
Mathias Agopian3f844832013-08-07 21:24:32 -070037class Mesh;
Mathias Agopian49457ac2013-08-14 18:20:17 -070038class Texture;
Mathias Agopian3f844832013-08-07 21:24:32 -070039
Peiyong Lin833074a2018-08-28 11:53:54 -070040namespace gl {
Lloyd Pique144e1162017-12-20 16:44:52 -080041
Peiyong Linf1bada92018-08-29 09:39:31 -070042class GLImage;
Peiyong Linf1bada92018-08-29 09:39:31 -070043
Peiyong Lin7e219eb2018-12-03 05:40:42 -080044class GLESRenderEngine : public impl::RenderEngine {
Mathias Agopian3f844832013-08-07 21:24:32 -070045public:
Peiyong Lin7e219eb2018-12-03 05:40:42 -080046 static std::unique_ptr<GLESRenderEngine> create(int hwcFormat, uint32_t featureFlags);
Peiyong Linf11f39b2018-09-05 14:37:41 -070047 static EGLConfig chooseEglConfig(EGLDisplay display, int format, bool logConfig);
48
Peiyong Lin7e219eb2018-12-03 05:40:42 -080049 GLESRenderEngine(uint32_t featureFlags, // See RenderEngine::FeatureFlag
50 EGLDisplay display, EGLConfig config, EGLContext ctxt, EGLSurface dummy);
51 ~GLESRenderEngine() override;
Mathias Agopian3f844832013-08-07 21:24:32 -070052
Peiyong Line5a9a7f2018-08-30 15:32:13 -070053 std::unique_ptr<Framebuffer> createFramebuffer() override;
Peiyong Line5a9a7f2018-08-30 15:32:13 -070054 std::unique_ptr<Image> createImage() override;
Peiyong Linf1bada92018-08-29 09:39:31 -070055
56 void primeCache() const override;
Peiyong Lin60bedb52018-09-05 10:47:31 -070057 bool isCurrent() const override;
Peiyong Lin60bedb52018-09-05 10:47:31 -070058 base::unique_fd flush() override;
59 bool finish() override;
60 bool waitFence(base::unique_fd fenceFd) override;
61 void clearWithColor(float red, float green, float blue, float alpha) override;
Chia-I Wu28e3a252018-09-07 12:05:02 -070062 void fillRegionWithColor(const Region& region, float red, float green, float blue,
63 float alpha) override;
Alec Mouri05483a02018-09-10 21:03:42 +000064 void setScissor(const Rect& region) override;
Peiyong Lin60bedb52018-09-05 10:47:31 -070065 void disableScissor() override;
66 void genTextures(size_t count, uint32_t* names) override;
67 void deleteTextures(size_t count, uint32_t const* names) override;
Peiyong Line5a9a7f2018-08-30 15:32:13 -070068 void bindExternalTextureImage(uint32_t texName, const Image& image) override;
69 status_t bindFrameBuffer(Framebuffer* framebuffer) override;
70 void unbindFrameBuffer(Framebuffer* framebuffer) override;
Peiyong Lin60bedb52018-09-05 10:47:31 -070071 void checkErrors() const override;
Peiyong Linf1bada92018-08-29 09:39:31 -070072
Alec Mouri6e57f682018-09-29 20:45:08 -070073 status_t drawLayers(const DisplaySettings& settings, const std::vector<LayerSettings>& layers,
74 ANativeWindowBuffer* const buffer,
75 base::unique_fd* displayFence) const override;
76
Peiyong Linf11f39b2018-09-05 14:37:41 -070077 // internal to RenderEngine
78 EGLDisplay getEGLDisplay() const { return mEGLDisplay; }
79 EGLConfig getEGLConfig() const { return mEGLConfig; }
80
Mathias Agopian3f844832013-08-07 21:24:32 -070081protected:
Peiyong Line5a9a7f2018-08-30 15:32:13 -070082 void dump(String8& result) override;
83 void setViewportAndProjection(size_t vpw, size_t vph, Rect sourceCrop,
84 ui::Transform::orientation_flags rotation) override;
85 void setupLayerBlending(bool premultipliedAlpha, bool opaque, bool disableTexture,
Lucas Dupin1b6531c2018-07-05 17:18:21 -070086 const half4& color, float cornerRadius) override;
Peiyong Line5a9a7f2018-08-30 15:32:13 -070087 void setupLayerTexturing(const Texture& texture) override;
88 void setupLayerBlackedOut() override;
89 void setupFillWithColor(float r, float g, float b, float a) override;
Peiyong Lind3788632018-09-18 16:01:31 -070090 void setColorTransform(const mat4& colorTransform) override;
Peiyong Line5a9a7f2018-08-30 15:32:13 -070091 void disableTexturing() override;
92 void disableBlending() override;
Lucas Dupin1b6531c2018-07-05 17:18:21 -070093 void setupCornerRadiusCropSize(float width, float height) override;
Mathias Agopian3f844832013-08-07 21:24:32 -070094
Peiyong Linf11f39b2018-09-05 14:37:41 -070095 // HDR and color management related functions and state
96 void setSourceY410BT2020(bool enable) override;
97 void setSourceDataSpace(ui::Dataspace source) override;
98 void setOutputDataSpace(ui::Dataspace dataspace) override;
99 void setDisplayMaxLuminance(const float maxLuminance) override;
100
101 // drawing
Peiyong Line5a9a7f2018-08-30 15:32:13 -0700102 void drawMesh(const Mesh& mesh) override;
Mathias Agopian3f844832013-08-07 21:24:32 -0700103
Peiyong Line5a9a7f2018-08-30 15:32:13 -0700104 size_t getMaxTextureSize() const override;
105 size_t getMaxViewportDims() const override;
106
107private:
Peiyong Linf11f39b2018-09-05 14:37:41 -0700108 enum GlesVersion {
109 GLES_VERSION_1_0 = 0x10000,
110 GLES_VERSION_1_1 = 0x10001,
111 GLES_VERSION_2_0 = 0x20000,
112 GLES_VERSION_3_0 = 0x30000,
113 };
114
115 static GlesVersion parseGlesVersion(const char* str);
Peiyong Lina5e9f1b2018-11-27 22:49:37 -0800116 static EGLContext createEglContext(EGLDisplay display, EGLConfig config,
117 EGLContext shareContext, bool useContextPriority);
118 static EGLSurface createDummyEglPbufferSurface(EGLDisplay display, EGLConfig config,
119 int hwcFormat);
Peiyong Linf11f39b2018-09-05 14:37:41 -0700120
Peiyong Line5a9a7f2018-08-30 15:32:13 -0700121 // A data space is considered HDR data space if it has BT2020 color space
122 // with PQ or HLG transfer function.
123 bool isHdrDataSpace(const ui::Dataspace dataSpace) const;
124 bool needsXYZTransformMatrix() const;
Alec Mouri0a9c7b82018-11-16 13:05:25 -0800125 void setEGLHandles(EGLDisplay display, EGLConfig config, EGLContext ctxt, EGLSurface dummy);
Peiyong Line5a9a7f2018-08-30 15:32:13 -0700126
Peiyong Linf11f39b2018-09-05 14:37:41 -0700127 EGLDisplay mEGLDisplay;
128 EGLConfig mEGLConfig;
129 EGLContext mEGLContext;
Alec Mouri0a9c7b82018-11-16 13:05:25 -0800130 EGLSurface mDummySurface;
Peiyong Line5a9a7f2018-08-30 15:32:13 -0700131 GLuint mProtectedTexName;
132 GLint mMaxViewportDims[2];
133 GLint mMaxTextureSize;
134 GLuint mVpWidth;
135 GLuint mVpHeight;
136 Description mState;
137
Peiyong Lin70b26ce2018-09-18 19:02:39 -0700138 mat4 mSrgbToXyz;
Peiyong Lin70b26ce2018-09-18 19:02:39 -0700139 mat4 mDisplayP3ToXyz;
Valerie Haueb8e0762018-11-06 10:10:42 -0800140 mat4 mBt2020ToXyz;
Peiyong Line5a9a7f2018-08-30 15:32:13 -0700141 mat4 mXyzToSrgb;
142 mat4 mXyzToDisplayP3;
143 mat4 mXyzToBt2020;
Valerie Haueb8e0762018-11-06 10:10:42 -0800144 mat4 mSrgbToDisplayP3;
145 mat4 mSrgbToBt2020;
146 mat4 mDisplayP3ToSrgb;
147 mat4 mDisplayP3ToBt2020;
148 mat4 mBt2020ToSrgb;
149 mat4 mBt2020ToDisplayP3;
Peiyong Line5a9a7f2018-08-30 15:32:13 -0700150
Alec Mouri05483a02018-09-10 21:03:42 +0000151 int32_t mFboHeight = 0;
Peiyong Linfb069302018-04-25 14:34:31 -0700152
153 // Current dataspace of layer being rendered
154 ui::Dataspace mDataSpace = ui::Dataspace::UNKNOWN;
155
156 // Current output dataspace of the render engine
157 ui::Dataspace mOutputDataSpace = ui::Dataspace::UNKNOWN;
158
Peiyong Lin13effd12018-07-24 17:01:47 -0700159 // Whether device supports color management, currently color management
160 // supports sRGB, DisplayP3 color spaces.
161 const bool mUseColorManagement = false;
Mathias Agopian3f844832013-08-07 21:24:32 -0700162};
163
Peiyong Lin46080ef2018-10-26 18:43:14 -0700164} // namespace gl
165} // namespace renderengine
166} // namespace android
Mathias Agopian3f844832013-08-07 21:24:32 -0700167
Peiyong Lin7e219eb2018-12-03 05:40:42 -0800168#endif /* SF_GLESRENDERENGINE_H_ */