blob: 4f03a904a9006df6c3e2c41c4ae7fbc9420089db [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
Mathias Agopian3f844832013-08-07 21:24:32 -070017#ifndef SF_GLES20RENDERENGINE_H_
18#define SF_GLES20RENDERENGINE_H_
19
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;
43class GLSurface;
44
Peiyong Lin833074a2018-08-28 11:53:54 -070045class GLES20RenderEngine : public impl::RenderEngine {
Mathias Agopian3f844832013-08-07 21:24:32 -070046public:
Peiyong Linf11f39b2018-09-05 14:37:41 -070047 static std::unique_ptr<GLES20RenderEngine> create(int hwcFormat, uint32_t featureFlags);
48 static EGLConfig chooseEglConfig(EGLDisplay display, int format, bool logConfig);
49
Kalle Raitabbdcf1f2017-05-22 15:47:46 -070050 GLES20RenderEngine(uint32_t featureFlags); // See RenderEngine::FeatureFlag
Peiyong Line5a9a7f2018-08-30 15:32:13 -070051 ~GLES20RenderEngine() override;
Mathias Agopian3f844832013-08-07 21:24:32 -070052
Peiyong Line5a9a7f2018-08-30 15:32:13 -070053 std::unique_ptr<Framebuffer> createFramebuffer() override;
54 std::unique_ptr<Surface> createSurface() override;
55 std::unique_ptr<Image> createImage() override;
Peiyong Linf1bada92018-08-29 09:39:31 -070056
57 void primeCache() const override;
Peiyong Lin60bedb52018-09-05 10:47:31 -070058 bool isCurrent() const override;
Peiyong Linf1bada92018-08-29 09:39:31 -070059 bool setCurrentSurface(const Surface& surface) override;
60 void resetCurrentSurface() override;
Peiyong Lin60bedb52018-09-05 10:47:31 -070061 base::unique_fd flush() override;
62 bool finish() override;
63 bool waitFence(base::unique_fd fenceFd) override;
64 void clearWithColor(float red, float green, float blue, float alpha) override;
Chia-I Wu28e3a252018-09-07 12:05:02 -070065 void fillRegionWithColor(const Region& region, float red, float green, float blue,
66 float alpha) override;
Alec Mouri05483a02018-09-10 21:03:42 +000067 void setScissor(const Rect& region) override;
Peiyong Lin60bedb52018-09-05 10:47:31 -070068 void disableScissor() override;
69 void genTextures(size_t count, uint32_t* names) override;
70 void deleteTextures(size_t count, uint32_t const* names) override;
Peiyong Line5a9a7f2018-08-30 15:32:13 -070071 void bindExternalTextureImage(uint32_t texName, const Image& image) override;
72 status_t bindFrameBuffer(Framebuffer* framebuffer) override;
73 void unbindFrameBuffer(Framebuffer* framebuffer) override;
Peiyong Lin60bedb52018-09-05 10:47:31 -070074 void checkErrors() const override;
Peiyong Linf1bada92018-08-29 09:39:31 -070075
Peiyong Linf11f39b2018-09-05 14:37:41 -070076 // internal to RenderEngine
77 EGLDisplay getEGLDisplay() const { return mEGLDisplay; }
78 EGLConfig getEGLConfig() const { return mEGLConfig; }
79
Mathias Agopian3f844832013-08-07 21:24:32 -070080protected:
Peiyong Line5a9a7f2018-08-30 15:32:13 -070081 void dump(String8& result) override;
82 void setViewportAndProjection(size_t vpw, size_t vph, Rect sourceCrop,
83 ui::Transform::orientation_flags rotation) override;
84 void setupLayerBlending(bool premultipliedAlpha, bool opaque, bool disableTexture,
85 const half4& color) override;
Peiyong Line5a9a7f2018-08-30 15:32:13 -070086 void setupLayerTexturing(const Texture& texture) override;
87 void setupLayerBlackedOut() override;
88 void setupFillWithColor(float r, float g, float b, float a) override;
Peiyong Lind3788632018-09-18 16:01:31 -070089 void setColorTransform(const mat4& colorTransform) override;
Peiyong Line5a9a7f2018-08-30 15:32:13 -070090 void disableTexturing() override;
91 void disableBlending() override;
Mathias Agopian3f844832013-08-07 21:24:32 -070092
Peiyong Linf11f39b2018-09-05 14:37:41 -070093 // HDR and color management related functions and state
94 void setSourceY410BT2020(bool enable) override;
95 void setSourceDataSpace(ui::Dataspace source) override;
96 void setOutputDataSpace(ui::Dataspace dataspace) override;
97 void setDisplayMaxLuminance(const float maxLuminance) override;
98
99 // drawing
Peiyong Line5a9a7f2018-08-30 15:32:13 -0700100 void drawMesh(const Mesh& mesh) override;
Mathias Agopian3f844832013-08-07 21:24:32 -0700101
Peiyong Line5a9a7f2018-08-30 15:32:13 -0700102 size_t getMaxTextureSize() const override;
103 size_t getMaxViewportDims() const override;
104
105private:
Peiyong Linf11f39b2018-09-05 14:37:41 -0700106 enum GlesVersion {
107 GLES_VERSION_1_0 = 0x10000,
108 GLES_VERSION_1_1 = 0x10001,
109 GLES_VERSION_2_0 = 0x20000,
110 GLES_VERSION_3_0 = 0x30000,
111 };
112
113 static GlesVersion parseGlesVersion(const char* str);
114
Peiyong Line5a9a7f2018-08-30 15:32:13 -0700115 // A data space is considered HDR data space if it has BT2020 color space
116 // with PQ or HLG transfer function.
117 bool isHdrDataSpace(const ui::Dataspace dataSpace) const;
118 bool needsXYZTransformMatrix() const;
Peiyong Linf11f39b2018-09-05 14:37:41 -0700119 void setEGLHandles(EGLDisplay display, EGLConfig config, EGLContext ctxt);
Peiyong Line5a9a7f2018-08-30 15:32:13 -0700120
Peiyong Linf11f39b2018-09-05 14:37:41 -0700121 EGLDisplay mEGLDisplay;
122 EGLConfig mEGLConfig;
123 EGLContext mEGLContext;
Peiyong Line5a9a7f2018-08-30 15:32:13 -0700124 GLuint mProtectedTexName;
125 GLint mMaxViewportDims[2];
126 GLint mMaxTextureSize;
127 GLuint mVpWidth;
128 GLuint mVpHeight;
129 Description mState;
130
131 mat4 mSrgbToDisplayP3;
132 mat4 mDisplayP3ToSrgb;
Peiyong Lin70b26ce2018-09-18 19:02:39 -0700133 mat4 mSrgbToXyz;
134 mat4 mBt2020ToXyz;
135 mat4 mDisplayP3ToXyz;
Peiyong Line5a9a7f2018-08-30 15:32:13 -0700136 mat4 mXyzToSrgb;
137 mat4 mXyzToDisplayP3;
138 mat4 mXyzToBt2020;
139
140 bool mRenderToFbo = false;
Alec Mouri05483a02018-09-10 21:03:42 +0000141 int32_t mSurfaceHeight = 0;
142 int32_t mFboHeight = 0;
Peiyong Linfb069302018-04-25 14:34:31 -0700143
144 // Current dataspace of layer being rendered
145 ui::Dataspace mDataSpace = ui::Dataspace::UNKNOWN;
146
147 // Current output dataspace of the render engine
148 ui::Dataspace mOutputDataSpace = ui::Dataspace::UNKNOWN;
149
Peiyong Lin13effd12018-07-24 17:01:47 -0700150 // Whether device supports color management, currently color management
151 // supports sRGB, DisplayP3 color spaces.
152 const bool mUseColorManagement = false;
Mathias Agopian3f844832013-08-07 21:24:32 -0700153};
154
Peiyong Lin833074a2018-08-28 11:53:54 -0700155} // namespace gl
156} // namespace renderengine
157} // namespace android
Mathias Agopian3f844832013-08-07 21:24:32 -0700158
159#endif /* SF_GLES20RENDERENGINE_H_ */