blob: 04dc1b192213de3c22be3a1bcf2fbe573f16dec6 [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;
Peiyong Lin60bedb52018-09-05 10:47:31 -070051 bool isCurrent() const override;
Peiyong Linf1bada92018-08-29 09:39:31 -070052 bool setCurrentSurface(const Surface& surface) override;
53 void resetCurrentSurface() override;
Peiyong Lin60bedb52018-09-05 10:47:31 -070054 base::unique_fd flush() override;
55 bool finish() override;
56 bool waitFence(base::unique_fd fenceFd) override;
57 void clearWithColor(float red, float green, float blue, float alpha) override;
58 void fillRegionWithColor(const Region& region, uint32_t height, float red, float green,
59 float blue, float alpha) override;
60 void setScissor(uint32_t left, uint32_t bottom, uint32_t right, uint32_t top) override;
61 void disableScissor() override;
62 void genTextures(size_t count, uint32_t* names) override;
63 void deleteTextures(size_t count, uint32_t const* names) override;
Peiyong Line5a9a7f2018-08-30 15:32:13 -070064 void bindExternalTextureImage(uint32_t texName, const Image& image) override;
Peiyong Lin60bedb52018-09-05 10:47:31 -070065 void readPixels(size_t l, size_t b, size_t w, size_t h, uint32_t* pixels) override;
Peiyong Line5a9a7f2018-08-30 15:32:13 -070066 status_t bindFrameBuffer(Framebuffer* framebuffer) override;
67 void unbindFrameBuffer(Framebuffer* framebuffer) override;
Peiyong Lin60bedb52018-09-05 10:47:31 -070068 void checkErrors() const override;
Peiyong Linf1bada92018-08-29 09:39:31 -070069
Mathias Agopian3f844832013-08-07 21:24:32 -070070protected:
Peiyong Line5a9a7f2018-08-30 15:32:13 -070071 void dump(String8& result) override;
72 void setViewportAndProjection(size_t vpw, size_t vph, Rect sourceCrop,
73 ui::Transform::orientation_flags rotation) override;
74 void setupLayerBlending(bool premultipliedAlpha, bool opaque, bool disableTexture,
75 const half4& color) override;
Courtney Goeltzenleuchter5d943892017-03-22 13:46:46 -060076
77 // Color management related functions and state
Chia-I Wu69bf10f2018-02-20 13:04:50 -080078 void setSourceY410BT2020(bool enable) override;
Peiyong Lin34beb7a2018-03-28 11:57:12 -070079 void setSourceDataSpace(ui::Dataspace source) override;
80 void setOutputDataSpace(ui::Dataspace dataspace) override;
Peiyong Linfb069302018-04-25 14:34:31 -070081 void setDisplayMaxLuminance(const float maxLuminance) override;
Kalle Raitabbdcf1f2017-05-22 15:47:46 -070082
Peiyong Line5a9a7f2018-08-30 15:32:13 -070083 void setupLayerTexturing(const Texture& texture) override;
84 void setupLayerBlackedOut() override;
85 void setupFillWithColor(float r, float g, float b, float a) override;
86 void setupColorTransform(const mat4& colorTransform) override;
87 void disableTexturing() override;
88 void disableBlending() override;
Mathias Agopian3f844832013-08-07 21:24:32 -070089
Peiyong Line5a9a7f2018-08-30 15:32:13 -070090 void drawMesh(const Mesh& mesh) override;
Mathias Agopian3f844832013-08-07 21:24:32 -070091
Peiyong Line5a9a7f2018-08-30 15:32:13 -070092 size_t getMaxTextureSize() const override;
93 size_t getMaxViewportDims() const override;
94
95private:
96 // A data space is considered HDR data space if it has BT2020 color space
97 // with PQ or HLG transfer function.
98 bool isHdrDataSpace(const ui::Dataspace dataSpace) const;
99 bool needsXYZTransformMatrix() const;
100
101 GLuint mProtectedTexName;
102 GLint mMaxViewportDims[2];
103 GLint mMaxTextureSize;
104 GLuint mVpWidth;
105 GLuint mVpHeight;
106 Description mState;
107
108 mat4 mSrgbToDisplayP3;
109 mat4 mDisplayP3ToSrgb;
110 mat3 mSrgbToXyz;
111 mat3 mBt2020ToXyz;
112 mat3 mDisplayP3ToXyz;
113 mat4 mXyzToSrgb;
114 mat4 mXyzToDisplayP3;
115 mat4 mXyzToBt2020;
116
117 bool mRenderToFbo = false;
Peiyong Linfb069302018-04-25 14:34:31 -0700118
119 // Current dataspace of layer being rendered
120 ui::Dataspace mDataSpace = ui::Dataspace::UNKNOWN;
121
122 // Current output dataspace of the render engine
123 ui::Dataspace mOutputDataSpace = ui::Dataspace::UNKNOWN;
124
Peiyong Lin13effd12018-07-24 17:01:47 -0700125 // Whether device supports color management, currently color management
126 // supports sRGB, DisplayP3 color spaces.
127 const bool mUseColorManagement = false;
Mathias Agopian3f844832013-08-07 21:24:32 -0700128};
129
Peiyong Lin833074a2018-08-28 11:53:54 -0700130} // namespace gl
131} // namespace renderengine
132} // namespace android
Mathias Agopian3f844832013-08-07 21:24:32 -0700133
134#endif /* SF_GLES20RENDERENGINE_H_ */