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_RENDERENGINE_H_ 19 #define SF_RENDERENGINE_H_ 20 21 #include <stdint.h> 22 #include <sys/types.h> 23 24 #include <EGL/egl.h> 25 #include <EGL/eglext.h> 26 #include <ui/mat4.h> 27 #include <Transform.h> 28 29 #define EGL_NO_CONFIG ((EGLConfig)0) 30 31 // --------------------------------------------------------------------------- 32 namespace android { 33 // --------------------------------------------------------------------------- 34 35 class String8; 36 class Rect; 37 class Region; 38 class Mesh; 39 class Texture; 40 41 class RenderEngine { 42 enum GlesVersion { 43 GLES_VERSION_1_0 = 0x10000, 44 GLES_VERSION_1_1 = 0x10001, 45 GLES_VERSION_2_0 = 0x20000, 46 GLES_VERSION_3_0 = 0x30000, 47 }; 48 static GlesVersion parseGlesVersion(const char* str); 49 50 EGLConfig mEGLConfig; 51 EGLContext mEGLContext; 52 void setEGLHandles(EGLConfig config, EGLContext ctxt); 53 54 virtual void bindImageAsFramebuffer(EGLImageKHR image, uint32_t* texName, uint32_t* fbName, uint32_t* status) = 0; 55 virtual void unbindFramebuffer(uint32_t texName, uint32_t fbName) = 0; 56 57 protected: 58 RenderEngine(); 59 virtual ~RenderEngine() = 0; 60 61 public: 62 static RenderEngine* create(EGLDisplay display, int hwcFormat); 63 64 static EGLConfig chooseEglConfig(EGLDisplay display, int format); 65 66 void primeCache() const; 67 68 // dump the extension strings. always call the base class. 69 virtual void dump(String8& result); 70 71 // helpers 72 void flush(); 73 void clearWithColor(float red, float green, float blue, float alpha); 74 void fillRegionWithColor(const Region& region, uint32_t height, 75 float red, float green, float blue, float alpha); 76 77 // common to all GL versions 78 void setScissor(uint32_t left, uint32_t bottom, uint32_t right, uint32_t top); 79 void disableScissor(); 80 void genTextures(size_t count, uint32_t* names); 81 void deleteTextures(size_t count, uint32_t const* names); 82 void readPixels(size_t l, size_t b, size_t w, size_t h, uint32_t* pixels); 83 84 class BindImageAsFramebuffer { 85 RenderEngine& mEngine; 86 uint32_t mTexName, mFbName; 87 uint32_t mStatus; 88 public: 89 BindImageAsFramebuffer(RenderEngine& engine, EGLImageKHR image); 90 ~BindImageAsFramebuffer(); 91 int getStatus() const; 92 }; 93 94 // set-up 95 virtual void checkErrors() const; 96 virtual void setViewportAndProjection(size_t vpw, size_t vph, 97 Rect sourceCrop, size_t hwh, bool yswap, Transform::orientation_flags rotation) = 0; 98 #ifdef USE_HWC2 99 virtual void setupLayerBlending(bool premultipliedAlpha, bool opaque, float alpha) = 0; 100 virtual void setupDimLayerBlending(float alpha) = 0; 101 #else 102 virtual void setupLayerBlending(bool premultipliedAlpha, bool opaque, int alpha) = 0; 103 virtual void setupDimLayerBlending(int alpha) = 0; 104 #endif 105 virtual void setupLayerTexturing(const Texture& texture) = 0; 106 virtual void setupLayerBlackedOut() = 0; 107 virtual void setupFillWithColor(float r, float g, float b, float a) = 0; 108 109 virtual mat4 setupColorTransform(const mat4& /* colorTransform */) { 110 return mat4(); 111 } 112 113 virtual void disableTexturing() = 0; 114 virtual void disableBlending() = 0; 115 116 // drawing 117 virtual void drawMesh(const Mesh& mesh) = 0; 118 119 // queries 120 virtual size_t getMaxTextureSize() const = 0; 121 virtual size_t getMaxViewportDims() const = 0; 122 123 EGLConfig getEGLConfig() const; 124 EGLContext getEGLContext() const; 125 }; 126 127 // --------------------------------------------------------------------------- 128 }; // namespace android 129 // --------------------------------------------------------------------------- 130 131 #endif /* SF_RENDERENGINE_H_ */ 132