blob: c830184bfa741bf6029e15ac3c191c207e623d43 [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 Lin833074a2018-08-28 11:53:54 -070038class GLES20RenderEngine : public impl::RenderEngine {
Mathias Agopian3f844832013-08-07 21:24:32 -070039 GLuint mProtectedTexName;
40 GLint mMaxViewportDims[2];
41 GLint mMaxTextureSize;
Mathias Agopianff2ed702013-09-01 21:36:12 -070042 GLuint mVpWidth;
43 GLuint mVpHeight;
44
45 struct Group {
46 GLuint texture;
47 GLuint fbo;
48 GLuint width;
49 GLuint height;
50 mat4 colorTransform;
51 };
Mathias Agopian3f844832013-08-07 21:24:32 -070052
53 Description mState;
54
Chia-I Wub027f802017-11-29 14:00:52 -080055 virtual void bindImageAsFramebuffer(EGLImageKHR image, uint32_t* texName, uint32_t* fbName,
56 uint32_t* status);
Mathias Agopian458197d2013-08-15 14:56:51 -070057 virtual void unbindFramebuffer(uint32_t texName, uint32_t fbName);
58
Mathias Agopian3f844832013-08-07 21:24:32 -070059public:
Kalle Raitabbdcf1f2017-05-22 15:47:46 -070060 GLES20RenderEngine(uint32_t featureFlags); // See RenderEngine::FeatureFlag
Chia-I Wub2c76242017-11-09 17:17:07 -080061 virtual ~GLES20RenderEngine();
Mathias Agopian3f844832013-08-07 21:24:32 -070062
63protected:
Mathias Agopian3f844832013-08-07 21:24:32 -070064 virtual void dump(String8& result);
Chia-I Wub027f802017-11-29 14:00:52 -080065 virtual void setViewportAndProjection(size_t vpw, size_t vph, Rect sourceCrop, size_t hwh,
Peiyong Linefefaac2018-08-17 12:27:51 -070066 bool yswap, ui::Transform::orientation_flags rotation);
Chia-I Wub027f802017-11-29 14:00:52 -080067 virtual void setupLayerBlending(bool premultipliedAlpha, bool opaque, bool disableTexture,
68 const half4& color) override;
Courtney Goeltzenleuchter5d943892017-03-22 13:46:46 -060069
70 // Color management related functions and state
Chia-I Wu69bf10f2018-02-20 13:04:50 -080071 void setSourceY410BT2020(bool enable) override;
Peiyong Lin34beb7a2018-03-28 11:57:12 -070072 void setSourceDataSpace(ui::Dataspace source) override;
73 void setOutputDataSpace(ui::Dataspace dataspace) override;
Peiyong Linfb069302018-04-25 14:34:31 -070074 void setDisplayMaxLuminance(const float maxLuminance) override;
Kalle Raitabbdcf1f2017-05-22 15:47:46 -070075
Mathias Agopian49457ac2013-08-14 18:20:17 -070076 virtual void setupLayerTexturing(const Texture& texture);
Mathias Agopian3f844832013-08-07 21:24:32 -070077 virtual void setupLayerBlackedOut();
Mathias Agopian19733a32013-08-28 18:13:56 -070078 virtual void setupFillWithColor(float r, float g, float b, float a);
Chia-I Wu8e50e692018-05-04 10:12:37 -070079 virtual void setupColorTransform(const mat4& colorTransform);
Mathias Agopian3f844832013-08-07 21:24:32 -070080 virtual void disableTexturing();
81 virtual void disableBlending();
82
Mathias Agopian3f844832013-08-07 21:24:32 -070083 virtual void drawMesh(const Mesh& mesh);
84
Mathias Agopian3f844832013-08-07 21:24:32 -070085 virtual size_t getMaxTextureSize() const;
86 virtual size_t getMaxViewportDims() const;
Peiyong Linfb069302018-04-25 14:34:31 -070087
88 // Current dataspace of layer being rendered
89 ui::Dataspace mDataSpace = ui::Dataspace::UNKNOWN;
90
91 // Current output dataspace of the render engine
92 ui::Dataspace mOutputDataSpace = ui::Dataspace::UNKNOWN;
93
Peiyong Lin13effd12018-07-24 17:01:47 -070094 // Whether device supports color management, currently color management
95 // supports sRGB, DisplayP3 color spaces.
96 const bool mUseColorManagement = false;
Peiyong Linfb069302018-04-25 14:34:31 -070097 mat4 mSrgbToDisplayP3;
Peiyong Lina296b0c2018-04-30 16:55:29 -070098 mat4 mDisplayP3ToSrgb;
99 mat3 mSrgbToXyz;
100 mat3 mBt2020ToXyz;
101 mat3 mDisplayP3ToXyz;
Peiyong Lin9b03c732018-05-17 10:14:02 -0700102 mat4 mXyzToSrgb;
Peiyong Lina296b0c2018-04-30 16:55:29 -0700103 mat4 mXyzToDisplayP3;
104 mat4 mXyzToBt2020;
105
106private:
107 // A data space is considered HDR data space if it has BT2020 color space
108 // with PQ or HLG transfer function.
109 bool isHdrDataSpace(const ui::Dataspace dataSpace) const;
110 bool needsXYZTransformMatrix() const;
Mathias Agopian3f844832013-08-07 21:24:32 -0700111};
112
Peiyong Lin833074a2018-08-28 11:53:54 -0700113} // namespace gl
114} // namespace renderengine
115} // namespace android
Mathias Agopian3f844832013-08-07 21:24:32 -0700116
117#endif /* SF_GLES20RENDERENGINE_H_ */