Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 1 | /* |
| 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 Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 17 | #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 Lin | cbc184f | 2018-08-22 13:24:10 -0700 | [diff] [blame] | 24 | #include <renderengine/RenderEngine.h> |
Peiyong Lin | 833074a | 2018-08-28 11:53:54 -0700 | [diff] [blame] | 25 | #include <renderengine/private/Description.h> |
Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 26 | |
Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 27 | namespace android { |
Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 28 | |
| 29 | class String8; |
Peiyong Lin | 833074a | 2018-08-28 11:53:54 -0700 | [diff] [blame] | 30 | |
| 31 | namespace renderengine { |
| 32 | |
Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 33 | class Mesh; |
Mathias Agopian | 49457ac | 2013-08-14 18:20:17 -0700 | [diff] [blame] | 34 | class Texture; |
Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 35 | |
Peiyong Lin | 833074a | 2018-08-28 11:53:54 -0700 | [diff] [blame] | 36 | namespace gl { |
Lloyd Pique | 144e116 | 2017-12-20 16:44:52 -0800 | [diff] [blame] | 37 | |
Peiyong Lin | f1bada9 | 2018-08-29 09:39:31 -0700 | [diff] [blame^] | 38 | class GLImage; |
| 39 | class GLSurface; |
| 40 | |
Peiyong Lin | 833074a | 2018-08-28 11:53:54 -0700 | [diff] [blame] | 41 | class GLES20RenderEngine : public impl::RenderEngine { |
Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 42 | GLuint mProtectedTexName; |
| 43 | GLint mMaxViewportDims[2]; |
| 44 | GLint mMaxTextureSize; |
Mathias Agopian | ff2ed70 | 2013-09-01 21:36:12 -0700 | [diff] [blame] | 45 | GLuint mVpWidth; |
| 46 | GLuint mVpHeight; |
| 47 | |
| 48 | struct Group { |
| 49 | GLuint texture; |
| 50 | GLuint fbo; |
| 51 | GLuint width; |
| 52 | GLuint height; |
| 53 | mat4 colorTransform; |
| 54 | }; |
Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 55 | |
| 56 | Description mState; |
| 57 | |
Chia-I Wu | b027f80 | 2017-11-29 14:00:52 -0800 | [diff] [blame] | 58 | virtual void bindImageAsFramebuffer(EGLImageKHR image, uint32_t* texName, uint32_t* fbName, |
| 59 | uint32_t* status); |
Mathias Agopian | 458197d | 2013-08-15 14:56:51 -0700 | [diff] [blame] | 60 | virtual void unbindFramebuffer(uint32_t texName, uint32_t fbName); |
| 61 | |
Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 62 | public: |
Kalle Raita | bbdcf1f | 2017-05-22 15:47:46 -0700 | [diff] [blame] | 63 | GLES20RenderEngine(uint32_t featureFlags); // See RenderEngine::FeatureFlag |
Chia-I Wu | b2c7624 | 2017-11-09 17:17:07 -0800 | [diff] [blame] | 64 | virtual ~GLES20RenderEngine(); |
Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 65 | |
Peiyong Lin | f1bada9 | 2018-08-29 09:39:31 -0700 | [diff] [blame^] | 66 | std::unique_ptr<renderengine::Surface> createSurface() override; |
| 67 | std::unique_ptr<renderengine::Image> createImage() override; |
| 68 | |
| 69 | void primeCache() const override; |
| 70 | |
| 71 | bool isCurrent() const; |
| 72 | bool setCurrentSurface(const Surface& surface) override; |
| 73 | void resetCurrentSurface() override; |
| 74 | |
| 75 | void bindExternalTextureImage(uint32_t texName, const renderengine::Image& image) override; |
| 76 | |
| 77 | |
Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 78 | protected: |
Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 79 | virtual void dump(String8& result); |
Chia-I Wu | b027f80 | 2017-11-29 14:00:52 -0800 | [diff] [blame] | 80 | virtual void setViewportAndProjection(size_t vpw, size_t vph, Rect sourceCrop, size_t hwh, |
Peiyong Lin | efefaac | 2018-08-17 12:27:51 -0700 | [diff] [blame] | 81 | bool yswap, ui::Transform::orientation_flags rotation); |
Chia-I Wu | b027f80 | 2017-11-29 14:00:52 -0800 | [diff] [blame] | 82 | virtual void setupLayerBlending(bool premultipliedAlpha, bool opaque, bool disableTexture, |
| 83 | const half4& color) override; |
Courtney Goeltzenleuchter | 5d94389 | 2017-03-22 13:46:46 -0600 | [diff] [blame] | 84 | |
| 85 | // Color management related functions and state |
Chia-I Wu | 69bf10f | 2018-02-20 13:04:50 -0800 | [diff] [blame] | 86 | void setSourceY410BT2020(bool enable) override; |
Peiyong Lin | 34beb7a | 2018-03-28 11:57:12 -0700 | [diff] [blame] | 87 | void setSourceDataSpace(ui::Dataspace source) override; |
| 88 | void setOutputDataSpace(ui::Dataspace dataspace) override; |
Peiyong Lin | fb06930 | 2018-04-25 14:34:31 -0700 | [diff] [blame] | 89 | void setDisplayMaxLuminance(const float maxLuminance) override; |
Kalle Raita | bbdcf1f | 2017-05-22 15:47:46 -0700 | [diff] [blame] | 90 | |
Mathias Agopian | 49457ac | 2013-08-14 18:20:17 -0700 | [diff] [blame] | 91 | virtual void setupLayerTexturing(const Texture& texture); |
Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 92 | virtual void setupLayerBlackedOut(); |
Mathias Agopian | 19733a3 | 2013-08-28 18:13:56 -0700 | [diff] [blame] | 93 | virtual void setupFillWithColor(float r, float g, float b, float a); |
Chia-I Wu | 8e50e69 | 2018-05-04 10:12:37 -0700 | [diff] [blame] | 94 | virtual void setupColorTransform(const mat4& colorTransform); |
Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 95 | virtual void disableTexturing(); |
| 96 | virtual void disableBlending(); |
| 97 | |
Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 98 | virtual void drawMesh(const Mesh& mesh); |
| 99 | |
Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 100 | virtual size_t getMaxTextureSize() const; |
| 101 | virtual size_t getMaxViewportDims() const; |
Peiyong Lin | fb06930 | 2018-04-25 14:34:31 -0700 | [diff] [blame] | 102 | |
| 103 | // Current dataspace of layer being rendered |
| 104 | ui::Dataspace mDataSpace = ui::Dataspace::UNKNOWN; |
| 105 | |
| 106 | // Current output dataspace of the render engine |
| 107 | ui::Dataspace mOutputDataSpace = ui::Dataspace::UNKNOWN; |
| 108 | |
Peiyong Lin | 13effd1 | 2018-07-24 17:01:47 -0700 | [diff] [blame] | 109 | // Whether device supports color management, currently color management |
| 110 | // supports sRGB, DisplayP3 color spaces. |
| 111 | const bool mUseColorManagement = false; |
Peiyong Lin | fb06930 | 2018-04-25 14:34:31 -0700 | [diff] [blame] | 112 | mat4 mSrgbToDisplayP3; |
Peiyong Lin | a296b0c | 2018-04-30 16:55:29 -0700 | [diff] [blame] | 113 | mat4 mDisplayP3ToSrgb; |
| 114 | mat3 mSrgbToXyz; |
| 115 | mat3 mBt2020ToXyz; |
| 116 | mat3 mDisplayP3ToXyz; |
Peiyong Lin | 9b03c73 | 2018-05-17 10:14:02 -0700 | [diff] [blame] | 117 | mat4 mXyzToSrgb; |
Peiyong Lin | a296b0c | 2018-04-30 16:55:29 -0700 | [diff] [blame] | 118 | mat4 mXyzToDisplayP3; |
| 119 | mat4 mXyzToBt2020; |
| 120 | |
| 121 | private: |
| 122 | // A data space is considered HDR data space if it has BT2020 color space |
| 123 | // with PQ or HLG transfer function. |
| 124 | bool isHdrDataSpace(const ui::Dataspace dataSpace) const; |
| 125 | bool needsXYZTransformMatrix() const; |
Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 126 | }; |
| 127 | |
Peiyong Lin | 833074a | 2018-08-28 11:53:54 -0700 | [diff] [blame] | 128 | } // namespace gl |
| 129 | } // namespace renderengine |
| 130 | } // namespace android |
Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 131 | |
| 132 | #endif /* SF_GLES20RENDERENGINE_H_ */ |