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 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> 24 #include <Transform.h> 25 26 #include "Description.h" 27 #include "ProgramCache.h" 28 #include "RenderEngine.h" 29 30 // --------------------------------------------------------------------------- 31 namespace android { 32 // --------------------------------------------------------------------------- 33 34 class String8; 35 class Mesh; 36 class Texture; 37 38 namespace RE { 39 namespace impl { 40 41 class GLES20RenderEngine : public RenderEngine { 42 GLuint mProtectedTexName; 43 GLint mMaxViewportDims[2]; 44 GLint mMaxTextureSize; 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 }; 55 56 Description mState; 57 Vector<Group> mGroupStack; 58 59 virtual void bindImageAsFramebuffer(EGLImageKHR image, uint32_t* texName, uint32_t* fbName, 60 uint32_t* status); 61 virtual void unbindFramebuffer(uint32_t texName, uint32_t fbName); 62 63 public: 64 GLES20RenderEngine(uint32_t featureFlags); // See RenderEngine::FeatureFlag 65 virtual ~GLES20RenderEngine(); 66 67 protected: 68 virtual void dump(String8& result); 69 virtual void setViewportAndProjection(size_t vpw, size_t vph, Rect sourceCrop, size_t hwh, 70 bool yswap, Transform::orientation_flags rotation); 71 virtual void setupLayerBlending(bool premultipliedAlpha, bool opaque, bool disableTexture, 72 const half4& color) override; 73 74 // Color management related functions and state 75 void setSourceY410BT2020(bool enable) override; 76 void setSourceDataSpace(ui::Dataspace source) override; 77 void setOutputDataSpace(ui::Dataspace dataspace) override; 78 void setDisplayMaxLuminance(const float maxLuminance) override; 79 80 virtual void setupLayerTexturing(const Texture& texture); 81 virtual void setupLayerBlackedOut(); 82 virtual void setupFillWithColor(float r, float g, float b, float a); 83 virtual void setupColorTransform(const mat4& colorTransform); 84 virtual void setSaturationMatrix(const mat4& saturationMatrix); 85 virtual void disableTexturing(); 86 virtual void disableBlending(); 87 88 virtual void drawMesh(const Mesh& mesh); 89 90 virtual size_t getMaxTextureSize() const; 91 virtual size_t getMaxViewportDims() const; 92 93 // Current dataspace of layer being rendered 94 ui::Dataspace mDataSpace = ui::Dataspace::UNKNOWN; 95 96 // Current output dataspace of the render engine 97 ui::Dataspace mOutputDataSpace = ui::Dataspace::UNKNOWN; 98 99 // Currently only supporting sRGB, BT2020 and DisplayP3 color spaces 100 const bool mPlatformHasWideColor = false; 101 mat4 mSrgbToDisplayP3; 102 mat4 mDisplayP3ToSrgb; 103 mat3 mSrgbToXyz; 104 mat3 mBt2020ToXyz; 105 mat3 mDisplayP3ToXyz; 106 mat4 mXyzToSrgb; 107 mat4 mXyzToDisplayP3; 108 mat4 mXyzToBt2020; 109 110 private: 111 // A data space is considered HDR data space if it has BT2020 color space 112 // with PQ or HLG transfer function. 113 bool isHdrDataSpace(const ui::Dataspace dataSpace) const; 114 bool needsXYZTransformMatrix() const; 115 }; 116 117 // --------------------------------------------------------------------------- 118 } // namespace impl 119 } // namespace RE 120 } // namespace android 121 // --------------------------------------------------------------------------- 122 123 #endif /* SF_GLES20RENDERENGINE_H_ */ 124