| Mathias Agopian | 875d8e1 | 2013-06-07 15:35:48 -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 |  | 
|  | 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> | 
| Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 25 | #include <EGL/eglext.h> | 
| Mathias Agopian | 1d77b71 | 2017-02-17 15:46:13 -0800 | [diff] [blame] | 26 | #include <math/mat4.h> | 
| Riley Andrews | c3ebe66 | 2014-09-04 16:20:31 -0700 | [diff] [blame] | 27 | #include <Transform.h> | 
| Mathias Agopian | 875d8e1 | 2013-06-07 15:35:48 -0700 | [diff] [blame] | 28 |  | 
| Jesse Hall | 19e8729 | 2013-12-23 21:02:15 -0800 | [diff] [blame] | 29 | #define EGL_NO_CONFIG ((EGLConfig)0) | 
|  | 30 |  | 
| Mathias Agopian | 875d8e1 | 2013-06-07 15:35:48 -0700 | [diff] [blame] | 31 | // --------------------------------------------------------------------------- | 
|  | 32 | namespace android { | 
|  | 33 | // --------------------------------------------------------------------------- | 
|  | 34 |  | 
|  | 35 | class String8; | 
| Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 36 | class Rect; | 
|  | 37 | class Region; | 
|  | 38 | class Mesh; | 
| Mathias Agopian | 49457ac | 2013-08-14 18:20:17 -0700 | [diff] [blame] | 39 | class Texture; | 
| Mathias Agopian | 875d8e1 | 2013-06-07 15:35:48 -0700 | [diff] [blame] | 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 |  | 
| Jesse Hall | 05f8c70 | 2013-12-23 20:44:38 -0800 | [diff] [blame] | 50 | EGLConfig mEGLConfig; | 
| Mathias Agopian | 875d8e1 | 2013-06-07 15:35:48 -0700 | [diff] [blame] | 51 | EGLContext mEGLContext; | 
| Jesse Hall | 05f8c70 | 2013-12-23 20:44:38 -0800 | [diff] [blame] | 52 | void setEGLHandles(EGLConfig config, EGLContext ctxt); | 
| Mathias Agopian | 875d8e1 | 2013-06-07 15:35:48 -0700 | [diff] [blame] | 53 |  | 
| Mathias Agopian | 458197d | 2013-08-15 14:56:51 -0700 | [diff] [blame] | 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 |  | 
| Mathias Agopian | 875d8e1 | 2013-06-07 15:35:48 -0700 | [diff] [blame] | 57 | protected: | 
|  | 58 | RenderEngine(); | 
|  | 59 | virtual ~RenderEngine() = 0; | 
|  | 60 |  | 
|  | 61 | public: | 
| Kalle Raita | bbdcf1f | 2017-05-22 15:47:46 -0700 | [diff] [blame] | 62 | enum FeatureFlag { | 
|  | 63 | WIDE_COLOR_SUPPORT = 1 << 0 // Platform has a wide color display | 
|  | 64 | }; | 
|  | 65 | static RenderEngine* create(EGLDisplay display, int hwcFormat, uint32_t featureFlags); | 
| Jesse Hall | 05f8c70 | 2013-12-23 20:44:38 -0800 | [diff] [blame] | 66 |  | 
| Steven Thomas | b02664d | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 67 | static EGLConfig chooseEglConfig(EGLDisplay display, int format, bool logConfig); | 
| Mathias Agopian | 875d8e1 | 2013-06-07 15:35:48 -0700 | [diff] [blame] | 68 |  | 
| Dan Stoza | 4e63777 | 2016-07-28 13:31:51 -0700 | [diff] [blame] | 69 | void primeCache() const; | 
|  | 70 |  | 
| Mathias Agopian | 458197d | 2013-08-15 14:56:51 -0700 | [diff] [blame] | 71 | // dump the extension strings. always call the base class. | 
|  | 72 | virtual void dump(String8& result); | 
|  | 73 |  | 
| Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 74 | // helpers | 
| Riley Andrews | 9707f4d | 2014-10-23 16:17:04 -0700 | [diff] [blame] | 75 | void flush(); | 
| Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 76 | void clearWithColor(float red, float green, float blue, float alpha); | 
|  | 77 | void fillRegionWithColor(const Region& region, uint32_t height, | 
|  | 78 | float red, float green, float blue, float alpha); | 
| Mathias Agopian | 875d8e1 | 2013-06-07 15:35:48 -0700 | [diff] [blame] | 79 |  | 
| Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 80 | // common to all GL versions | 
|  | 81 | void setScissor(uint32_t left, uint32_t bottom, uint32_t right, uint32_t top); | 
|  | 82 | void disableScissor(); | 
|  | 83 | void genTextures(size_t count, uint32_t* names); | 
|  | 84 | void deleteTextures(size_t count, uint32_t const* names); | 
| Mathias Agopian | d555684 | 2013-09-19 17:08:37 -0700 | [diff] [blame] | 85 | void readPixels(size_t l, size_t b, size_t w, size_t h, uint32_t* pixels); | 
| Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 86 |  | 
|  | 87 | class BindImageAsFramebuffer { | 
|  | 88 | RenderEngine& mEngine; | 
| Mathias Agopian | 458197d | 2013-08-15 14:56:51 -0700 | [diff] [blame] | 89 | uint32_t mTexName, mFbName; | 
|  | 90 | uint32_t mStatus; | 
| Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 91 | public: | 
|  | 92 | BindImageAsFramebuffer(RenderEngine& engine, EGLImageKHR image); | 
|  | 93 | ~BindImageAsFramebuffer(); | 
|  | 94 | int getStatus() const; | 
|  | 95 | }; | 
|  | 96 |  | 
|  | 97 | // set-up | 
|  | 98 | virtual void checkErrors() const; | 
| Dan Stoza | c187900 | 2014-05-22 15:59:05 -0700 | [diff] [blame] | 99 | virtual void setViewportAndProjection(size_t vpw, size_t vph, | 
| Riley Andrews | c3ebe66 | 2014-09-04 16:20:31 -0700 | [diff] [blame] | 100 | Rect sourceCrop, size_t hwh, bool yswap, Transform::orientation_flags rotation) = 0; | 
| Fabien Sanglard | 9d96de4 | 2016-10-11 00:15:18 +0000 | [diff] [blame] | 101 | #ifdef USE_HWC2 | 
| Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 102 | virtual void setupLayerBlending(bool premultipliedAlpha, bool opaque, float alpha) = 0; | 
|  | 103 | virtual void setupDimLayerBlending(float alpha) = 0; | 
| Courtney Goeltzenleuchter | 5d94389 | 2017-03-22 13:46:46 -0600 | [diff] [blame] | 104 | virtual void setColorMode(android_color_mode mode) = 0; | 
|  | 105 | virtual void setSourceDataSpace(android_dataspace source) = 0; | 
|  | 106 | virtual void setWideColor(bool hasWideColor) = 0; | 
|  | 107 | virtual bool usesWideColor() = 0; | 
| Fabien Sanglard | 9d96de4 | 2016-10-11 00:15:18 +0000 | [diff] [blame] | 108 | #else | 
|  | 109 | virtual void setupLayerBlending(bool premultipliedAlpha, bool opaque, int alpha) = 0; | 
|  | 110 | virtual void setupDimLayerBlending(int alpha) = 0; | 
|  | 111 | #endif | 
| Mathias Agopian | 49457ac | 2013-08-14 18:20:17 -0700 | [diff] [blame] | 112 | virtual void setupLayerTexturing(const Texture& texture) = 0; | 
| Mathias Agopian | 875d8e1 | 2013-06-07 15:35:48 -0700 | [diff] [blame] | 113 | virtual void setupLayerBlackedOut() = 0; | 
| Mathias Agopian | 19733a3 | 2013-08-28 18:13:56 -0700 | [diff] [blame] | 114 | virtual void setupFillWithColor(float r, float g, float b, float a) = 0; | 
| Mathias Agopian | 875d8e1 | 2013-06-07 15:35:48 -0700 | [diff] [blame] | 115 |  | 
| Dan Stoza | f008799 | 2014-10-20 15:46:09 -0700 | [diff] [blame] | 116 | virtual mat4 setupColorTransform(const mat4& /* colorTransform */) { | 
|  | 117 | return mat4(); | 
|  | 118 | } | 
|  | 119 |  | 
| Mathias Agopian | 875d8e1 | 2013-06-07 15:35:48 -0700 | [diff] [blame] | 120 | virtual void disableTexturing() = 0; | 
|  | 121 | virtual void disableBlending() = 0; | 
|  | 122 |  | 
| Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 123 | // drawing | 
| Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 124 | virtual void drawMesh(const Mesh& mesh) = 0; | 
| Mathias Agopian | 875d8e1 | 2013-06-07 15:35:48 -0700 | [diff] [blame] | 125 |  | 
| Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 126 | // queries | 
| Mathias Agopian | 875d8e1 | 2013-06-07 15:35:48 -0700 | [diff] [blame] | 127 | virtual size_t getMaxTextureSize() const = 0; | 
|  | 128 | virtual size_t getMaxViewportDims() const = 0; | 
|  | 129 |  | 
| Jesse Hall | 05f8c70 | 2013-12-23 20:44:38 -0800 | [diff] [blame] | 130 | EGLConfig getEGLConfig() const; | 
| Mathias Agopian | 875d8e1 | 2013-06-07 15:35:48 -0700 | [diff] [blame] | 131 | EGLContext getEGLContext() const; | 
|  | 132 | }; | 
|  | 133 |  | 
|  | 134 | // --------------------------------------------------------------------------- | 
|  | 135 | }; // namespace android | 
|  | 136 | // --------------------------------------------------------------------------- | 
|  | 137 |  | 
|  | 138 | #endif /* SF_RENDERENGINE_H_ */ |