blob: 3113e5339c8226819fa1d4b2a2f5dad44571b0fb [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
23#include <GLES2/gl2.h>
Peiyong Lincbc184f2018-08-22 13:24:10 -070024#include <renderengine/RenderEngine.h>
Peiyong Lin833074a2018-08-28 11:53:54 -070025#include <renderengine/private/Description.h>
Mathias Agopian3f844832013-08-07 21:24:32 -070026
Mathias Agopian3f844832013-08-07 21:24:32 -070027namespace android {
Mathias Agopian3f844832013-08-07 21:24:32 -070028
29class String8;
Peiyong Lin833074a2018-08-28 11:53:54 -070030
31namespace renderengine {
32
Mathias Agopian3f844832013-08-07 21:24:32 -070033class Mesh;
Mathias Agopian49457ac2013-08-14 18:20:17 -070034class Texture;
Mathias Agopian3f844832013-08-07 21:24:32 -070035
Peiyong Lin833074a2018-08-28 11:53:54 -070036namespace gl {
Lloyd Pique144e1162017-12-20 16:44:52 -080037
Peiyong Linf1bada92018-08-29 09:39:31 -070038class GLImage;
39class GLSurface;
40
Peiyong Lin833074a2018-08-28 11:53:54 -070041class GLES20RenderEngine : public impl::RenderEngine {
Mathias Agopian3f844832013-08-07 21:24:32 -070042public:
Kalle Raitabbdcf1f2017-05-22 15:47:46 -070043 GLES20RenderEngine(uint32_t featureFlags); // See RenderEngine::FeatureFlag
Peiyong Line5a9a7f2018-08-30 15:32:13 -070044 ~GLES20RenderEngine() override;
Mathias Agopian3f844832013-08-07 21:24:32 -070045
Peiyong Line5a9a7f2018-08-30 15:32:13 -070046 std::unique_ptr<Framebuffer> createFramebuffer() override;
47 std::unique_ptr<Surface> createSurface() override;
48 std::unique_ptr<Image> createImage() override;
Peiyong Linf1bada92018-08-29 09:39:31 -070049
50 void primeCache() const override;
51
52 bool isCurrent() const;
53 bool setCurrentSurface(const Surface& surface) override;
54 void resetCurrentSurface() override;
55
Peiyong Line5a9a7f2018-08-30 15:32:13 -070056 void bindExternalTextureImage(uint32_t texName, const Image& image) override;
57 status_t bindFrameBuffer(Framebuffer* framebuffer) override;
58 void unbindFrameBuffer(Framebuffer* framebuffer) override;
Peiyong Linf1bada92018-08-29 09:39:31 -070059
Mathias Agopian3f844832013-08-07 21:24:32 -070060protected:
Peiyong Line5a9a7f2018-08-30 15:32:13 -070061 void dump(String8& result) override;
62 void setViewportAndProjection(size_t vpw, size_t vph, Rect sourceCrop,
63 ui::Transform::orientation_flags rotation) override;
64 void setupLayerBlending(bool premultipliedAlpha, bool opaque, bool disableTexture,
65 const half4& color) override;
Courtney Goeltzenleuchter5d943892017-03-22 13:46:46 -060066
67 // Color management related functions and state
Chia-I Wu69bf10f2018-02-20 13:04:50 -080068 void setSourceY410BT2020(bool enable) override;
Peiyong Lin34beb7a2018-03-28 11:57:12 -070069 void setSourceDataSpace(ui::Dataspace source) override;
70 void setOutputDataSpace(ui::Dataspace dataspace) override;
Peiyong Linfb069302018-04-25 14:34:31 -070071 void setDisplayMaxLuminance(const float maxLuminance) override;
Kalle Raitabbdcf1f2017-05-22 15:47:46 -070072
Peiyong Line5a9a7f2018-08-30 15:32:13 -070073 void setupLayerTexturing(const Texture& texture) override;
74 void setupLayerBlackedOut() override;
75 void setupFillWithColor(float r, float g, float b, float a) override;
76 void setupColorTransform(const mat4& colorTransform) override;
77 void disableTexturing() override;
78 void disableBlending() override;
Mathias Agopian3f844832013-08-07 21:24:32 -070079
Peiyong Line5a9a7f2018-08-30 15:32:13 -070080 void drawMesh(const Mesh& mesh) override;
Mathias Agopian3f844832013-08-07 21:24:32 -070081
Peiyong Line5a9a7f2018-08-30 15:32:13 -070082 size_t getMaxTextureSize() const override;
83 size_t getMaxViewportDims() const override;
84
85private:
86 // A data space is considered HDR data space if it has BT2020 color space
87 // with PQ or HLG transfer function.
88 bool isHdrDataSpace(const ui::Dataspace dataSpace) const;
89 bool needsXYZTransformMatrix() const;
90
91 GLuint mProtectedTexName;
92 GLint mMaxViewportDims[2];
93 GLint mMaxTextureSize;
94 GLuint mVpWidth;
95 GLuint mVpHeight;
96 Description mState;
97
98 mat4 mSrgbToDisplayP3;
99 mat4 mDisplayP3ToSrgb;
100 mat3 mSrgbToXyz;
101 mat3 mBt2020ToXyz;
102 mat3 mDisplayP3ToXyz;
103 mat4 mXyzToSrgb;
104 mat4 mXyzToDisplayP3;
105 mat4 mXyzToBt2020;
106
107 bool mRenderToFbo = false;
Peiyong Linfb069302018-04-25 14:34:31 -0700108
109 // Current dataspace of layer being rendered
110 ui::Dataspace mDataSpace = ui::Dataspace::UNKNOWN;
111
112 // Current output dataspace of the render engine
113 ui::Dataspace mOutputDataSpace = ui::Dataspace::UNKNOWN;
114
Peiyong Lin13effd12018-07-24 17:01:47 -0700115 // Whether device supports color management, currently color management
116 // supports sRGB, DisplayP3 color spaces.
117 const bool mUseColorManagement = false;
Mathias Agopian3f844832013-08-07 21:24:32 -0700118};
119
Peiyong Lin833074a2018-08-28 11:53:54 -0700120} // namespace gl
121} // namespace renderengine
122} // namespace android
Mathias Agopian3f844832013-08-07 21:24:32 -0700123
124#endif /* SF_GLES20RENDERENGINE_H_ */