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 18 #ifndef SF_GLES20RENDERENGINE_H_ 19 #define SF_GLES20RENDERENGINE_H_ 20 21 #include <stdint.h> 22 #include <sys/types.h> 23 24 #include <GLES2/gl2.h> 25 #include <Transform.h> 26 27 #include "RenderEngine.h" 28 #include "ProgramCache.h" 29 #include "Description.h" 30 31 // --------------------------------------------------------------------------- 32 namespace android { 33 // --------------------------------------------------------------------------- 34 35 class String8; 36 class Mesh; 37 class Texture; 38 39 class GLES20RenderEngine : public RenderEngine { 40 GLuint mProtectedTexName; 41 GLint mMaxViewportDims[2]; 42 GLint mMaxTextureSize; 43 GLuint mVpWidth; 44 GLuint mVpHeight; 45 46 struct Group { 47 GLuint texture; 48 GLuint fbo; 49 GLuint width; 50 GLuint height; 51 mat4 colorTransform; 52 }; 53 54 Description mState; 55 Vector<Group> mGroupStack; 56 57 virtual void bindImageAsFramebuffer(EGLImageKHR image, 58 uint32_t* texName, uint32_t* fbName, uint32_t* status); 59 virtual void unbindFramebuffer(uint32_t texName, uint32_t fbName); 60 61 public: 62 GLES20RenderEngine(uint32_t featureFlags); // See RenderEngine::FeatureFlag 63 64 protected: 65 virtual ~GLES20RenderEngine(); 66 67 virtual void dump(String8& result); 68 virtual void setViewportAndProjection(size_t vpw, size_t vph, 69 Rect sourceCrop, size_t hwh, bool yswap, 70 Transform::orientation_flags rotation); 71 #ifdef USE_HWC2 72 virtual void setupLayerBlending(bool premultipliedAlpha, bool opaque, 73 float alpha) override; 74 virtual void setupDimLayerBlending(float alpha) override; 75 76 // Color management related functions and state 77 void setColorMode(android_color_mode mode); 78 void setSourceDataSpace(android_dataspace source); 79 void setWideColor(bool hasWideColor); 80 bool usesWideColor(); 81 82 // Current color mode of display using the render engine 83 android_color_mode mColorMode = HAL_COLOR_MODE_NATIVE; 84 85 // Current dataspace of layer being rendered 86 android_dataspace mDataSpace = HAL_DATASPACE_V0_SRGB; 87 88 // Indicate if wide-color mode is needed or not 89 bool mDisplayHasWideColor = false; 90 bool mUseWideColor = false; 91 uint64_t mWideColorFrameCount = 0; 92 93 // Currently only supporting sRGB and DisplayP3 color spaces 94 mat4 mSrgbToDisplayP3; 95 #else 96 virtual void setupLayerBlending(bool premultipliedAlpha, bool opaque, 97 int alpha); 98 virtual void setupDimLayerBlending(int alpha); 99 #endif 100 bool mPlatformHasWideColor = false; 101 102 virtual void setupLayerTexturing(const Texture& texture); 103 virtual void setupLayerBlackedOut(); 104 virtual void setupFillWithColor(float r, float g, float b, float a); 105 virtual mat4 setupColorTransform(const mat4& colorTransform); 106 virtual void disableTexturing(); 107 virtual void disableBlending(); 108 109 virtual void drawMesh(const Mesh& mesh); 110 111 virtual size_t getMaxTextureSize() const; 112 virtual size_t getMaxViewportDims() const; 113 }; 114 115 // --------------------------------------------------------------------------- 116 }; // namespace android 117 // --------------------------------------------------------------------------- 118 119 #endif /* SF_GLES20RENDERENGINE_H_ */ 120