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 | |
Mathias Agopian | 875d8e1 | 2013-06-07 15:35:48 -0700 | [diff] [blame] | 17 | #ifndef SF_RENDERENGINE_H_ |
| 18 | #define SF_RENDERENGINE_H_ |
| 19 | |
Chia-I Wu | b2c7624 | 2017-11-09 17:17:07 -0800 | [diff] [blame] | 20 | #include <memory> |
| 21 | |
Mathias Agopian | 875d8e1 | 2013-06-07 15:35:48 -0700 | [diff] [blame] | 22 | #include <stdint.h> |
| 23 | #include <sys/types.h> |
| 24 | |
| 25 | #include <EGL/egl.h> |
Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 26 | #include <EGL/eglext.h> |
Riley Andrews | c3ebe66 | 2014-09-04 16:20:31 -0700 | [diff] [blame] | 27 | #include <Transform.h> |
Chia-I Wu | 767fcf7 | 2017-11-30 22:07:38 -0800 | [diff] [blame] | 28 | #include <android-base/unique_fd.h> |
chaviw | 13fdc49 | 2017-06-27 12:40:18 -0700 | [diff] [blame] | 29 | #include <gui/SurfaceControl.h> |
Chia-I Wu | b027f80 | 2017-11-29 14:00:52 -0800 | [diff] [blame] | 30 | #include <math/mat4.h> |
Mathias Agopian | 875d8e1 | 2013-06-07 15:35:48 -0700 | [diff] [blame] | 31 | |
Jesse Hall | 19e8729 | 2013-12-23 21:02:15 -0800 | [diff] [blame] | 32 | #define EGL_NO_CONFIG ((EGLConfig)0) |
| 33 | |
Chia-I Wu | eadbaa6 | 2017-11-09 11:26:15 -0800 | [diff] [blame] | 34 | struct ANativeWindowBuffer; |
| 35 | |
Mathias Agopian | 875d8e1 | 2013-06-07 15:35:48 -0700 | [diff] [blame] | 36 | // --------------------------------------------------------------------------- |
| 37 | namespace android { |
| 38 | // --------------------------------------------------------------------------- |
| 39 | |
| 40 | class String8; |
Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 41 | class Rect; |
| 42 | class Region; |
| 43 | class Mesh; |
Mathias Agopian | 49457ac | 2013-08-14 18:20:17 -0700 | [diff] [blame] | 44 | class Texture; |
Mathias Agopian | 875d8e1 | 2013-06-07 15:35:48 -0700 | [diff] [blame] | 45 | |
Chia-I Wu | f846a35 | 2017-11-10 09:22:52 -0800 | [diff] [blame] | 46 | namespace RE { |
Chia-I Wu | 401ef83 | 2017-12-01 10:52:22 -0800 | [diff] [blame^] | 47 | class Image; |
Chia-I Wu | f846a35 | 2017-11-10 09:22:52 -0800 | [diff] [blame] | 48 | class Surface; |
Chia-I Wu | 401ef83 | 2017-12-01 10:52:22 -0800 | [diff] [blame^] | 49 | } // namespace RE |
Chia-I Wu | f846a35 | 2017-11-10 09:22:52 -0800 | [diff] [blame] | 50 | |
Mathias Agopian | 875d8e1 | 2013-06-07 15:35:48 -0700 | [diff] [blame] | 51 | class RenderEngine { |
| 52 | enum GlesVersion { |
Chia-I Wu | b027f80 | 2017-11-29 14:00:52 -0800 | [diff] [blame] | 53 | GLES_VERSION_1_0 = 0x10000, |
| 54 | GLES_VERSION_1_1 = 0x10001, |
| 55 | GLES_VERSION_2_0 = 0x20000, |
| 56 | GLES_VERSION_3_0 = 0x30000, |
Mathias Agopian | 875d8e1 | 2013-06-07 15:35:48 -0700 | [diff] [blame] | 57 | }; |
| 58 | static GlesVersion parseGlesVersion(const char* str); |
| 59 | |
Chia-I Wu | 2b6386e | 2017-11-09 13:03:17 -0800 | [diff] [blame] | 60 | EGLDisplay mEGLDisplay; |
Jesse Hall | 05f8c70 | 2013-12-23 20:44:38 -0800 | [diff] [blame] | 61 | EGLConfig mEGLConfig; |
Mathias Agopian | 875d8e1 | 2013-06-07 15:35:48 -0700 | [diff] [blame] | 62 | EGLContext mEGLContext; |
Chia-I Wu | 2b6386e | 2017-11-09 13:03:17 -0800 | [diff] [blame] | 63 | void setEGLHandles(EGLDisplay display, EGLConfig config, EGLContext ctxt); |
Mathias Agopian | 875d8e1 | 2013-06-07 15:35:48 -0700 | [diff] [blame] | 64 | |
Chia-I Wu | b027f80 | 2017-11-29 14:00:52 -0800 | [diff] [blame] | 65 | virtual void bindImageAsFramebuffer(EGLImageKHR image, uint32_t* texName, uint32_t* fbName, |
| 66 | uint32_t* status) = 0; |
Mathias Agopian | 458197d | 2013-08-15 14:56:51 -0700 | [diff] [blame] | 67 | virtual void unbindFramebuffer(uint32_t texName, uint32_t fbName) = 0; |
| 68 | |
Mathias Agopian | 875d8e1 | 2013-06-07 15:35:48 -0700 | [diff] [blame] | 69 | protected: |
| 70 | RenderEngine(); |
Mathias Agopian | 875d8e1 | 2013-06-07 15:35:48 -0700 | [diff] [blame] | 71 | |
| 72 | public: |
Chia-I Wu | b2c7624 | 2017-11-09 17:17:07 -0800 | [diff] [blame] | 73 | virtual ~RenderEngine() = 0; |
| 74 | |
Kalle Raita | bbdcf1f | 2017-05-22 15:47:46 -0700 | [diff] [blame] | 75 | enum FeatureFlag { |
| 76 | WIDE_COLOR_SUPPORT = 1 << 0 // Platform has a wide color display |
| 77 | }; |
Chia-I Wu | d4d9c6f | 2017-11-09 16:55:31 -0800 | [diff] [blame] | 78 | static std::unique_ptr<RenderEngine> create(int hwcFormat, uint32_t featureFlags); |
Jesse Hall | 05f8c70 | 2013-12-23 20:44:38 -0800 | [diff] [blame] | 79 | |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 80 | static EGLConfig chooseEglConfig(EGLDisplay display, int format, bool logConfig); |
Mathias Agopian | 875d8e1 | 2013-06-07 15:35:48 -0700 | [diff] [blame] | 81 | |
Dan Stoza | 4e63777 | 2016-07-28 13:31:51 -0700 | [diff] [blame] | 82 | void primeCache() const; |
| 83 | |
Mathias Agopian | 458197d | 2013-08-15 14:56:51 -0700 | [diff] [blame] | 84 | // dump the extension strings. always call the base class. |
| 85 | virtual void dump(String8& result); |
| 86 | |
Chia-I Wu | 401ef83 | 2017-12-01 10:52:22 -0800 | [diff] [blame^] | 87 | bool supportsImageCrop() const; |
| 88 | |
Chia-I Wu | 767fcf7 | 2017-11-30 22:07:38 -0800 | [diff] [blame] | 89 | // synchronization |
| 90 | |
| 91 | // flush submits RenderEngine command stream for execution and returns a |
| 92 | // native fence fd that is signaled when the execution has completed. It |
| 93 | // returns -1 on errors. |
| 94 | base::unique_fd flush(); |
| 95 | // finish waits until RenderEngine command stream has been executed. It |
| 96 | // returns false on errors. |
| 97 | bool finish(); |
| 98 | // waitFence inserts a wait on an external fence fd to RenderEngine |
| 99 | // command stream. It returns false on errors. |
| 100 | bool waitFence(base::unique_fd fenceFd); |
| 101 | |
Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 102 | // helpers |
| 103 | void clearWithColor(float red, float green, float blue, float alpha); |
Chia-I Wu | b027f80 | 2017-11-29 14:00:52 -0800 | [diff] [blame] | 104 | void fillRegionWithColor(const Region& region, uint32_t height, float red, float green, |
| 105 | float blue, float alpha); |
Mathias Agopian | 875d8e1 | 2013-06-07 15:35:48 -0700 | [diff] [blame] | 106 | |
Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 107 | // common to all GL versions |
| 108 | void setScissor(uint32_t left, uint32_t bottom, uint32_t right, uint32_t top); |
| 109 | void disableScissor(); |
| 110 | void genTextures(size_t count, uint32_t* names); |
| 111 | void deleteTextures(size_t count, uint32_t const* names); |
Chia-I Wu | 401ef83 | 2017-12-01 10:52:22 -0800 | [diff] [blame^] | 112 | void bindExternalTextureImage(uint32_t texName, const RE::Image& image); |
Mathias Agopian | d555684 | 2013-09-19 17:08:37 -0700 | [diff] [blame] | 113 | 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] | 114 | |
Chia-I Wu | eadbaa6 | 2017-11-09 11:26:15 -0800 | [diff] [blame] | 115 | class BindNativeBufferAsFramebuffer { |
Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 116 | RenderEngine& mEngine; |
Chia-I Wu | eadbaa6 | 2017-11-09 11:26:15 -0800 | [diff] [blame] | 117 | EGLImageKHR mImage; |
Mathias Agopian | 458197d | 2013-08-15 14:56:51 -0700 | [diff] [blame] | 118 | uint32_t mTexName, mFbName; |
| 119 | uint32_t mStatus; |
Chia-I Wu | b027f80 | 2017-11-29 14:00:52 -0800 | [diff] [blame] | 120 | |
Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 121 | public: |
Chia-I Wu | eadbaa6 | 2017-11-09 11:26:15 -0800 | [diff] [blame] | 122 | BindNativeBufferAsFramebuffer(RenderEngine& engine, ANativeWindowBuffer* buffer); |
| 123 | ~BindNativeBufferAsFramebuffer(); |
Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 124 | int getStatus() const; |
| 125 | }; |
| 126 | |
Chia-I Wu | f846a35 | 2017-11-10 09:22:52 -0800 | [diff] [blame] | 127 | bool setCurrentSurface(const RE::Surface& surface); |
Chia-I Wu | 7f40290 | 2017-11-09 12:51:10 -0800 | [diff] [blame] | 128 | void resetCurrentSurface(); |
| 129 | |
Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 130 | // set-up |
| 131 | virtual void checkErrors() const; |
Chia-I Wu | b027f80 | 2017-11-29 14:00:52 -0800 | [diff] [blame] | 132 | virtual void setViewportAndProjection(size_t vpw, size_t vph, Rect sourceCrop, size_t hwh, |
| 133 | bool yswap, Transform::orientation_flags rotation) = 0; |
| 134 | virtual void setupLayerBlending(bool premultipliedAlpha, bool opaque, bool disableTexture, |
| 135 | const half4& color) = 0; |
Courtney Goeltzenleuchter | 5d94389 | 2017-03-22 13:46:46 -0600 | [diff] [blame] | 136 | virtual void setColorMode(android_color_mode mode) = 0; |
| 137 | virtual void setSourceDataSpace(android_dataspace source) = 0; |
| 138 | virtual void setWideColor(bool hasWideColor) = 0; |
| 139 | virtual bool usesWideColor() = 0; |
Mathias Agopian | 49457ac | 2013-08-14 18:20:17 -0700 | [diff] [blame] | 140 | virtual void setupLayerTexturing(const Texture& texture) = 0; |
Mathias Agopian | 875d8e1 | 2013-06-07 15:35:48 -0700 | [diff] [blame] | 141 | virtual void setupLayerBlackedOut() = 0; |
Mathias Agopian | 19733a3 | 2013-08-28 18:13:56 -0700 | [diff] [blame] | 142 | virtual void setupFillWithColor(float r, float g, float b, float a) = 0; |
Mathias Agopian | 875d8e1 | 2013-06-07 15:35:48 -0700 | [diff] [blame] | 143 | |
Chia-I Wu | b027f80 | 2017-11-29 14:00:52 -0800 | [diff] [blame] | 144 | virtual mat4 setupColorTransform(const mat4& /* colorTransform */) { return mat4(); } |
Dan Stoza | f008799 | 2014-10-20 15:46:09 -0700 | [diff] [blame] | 145 | |
Mathias Agopian | 875d8e1 | 2013-06-07 15:35:48 -0700 | [diff] [blame] | 146 | virtual void disableTexturing() = 0; |
| 147 | virtual void disableBlending() = 0; |
| 148 | |
Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 149 | // drawing |
Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 150 | virtual void drawMesh(const Mesh& mesh) = 0; |
Mathias Agopian | 875d8e1 | 2013-06-07 15:35:48 -0700 | [diff] [blame] | 151 | |
Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 152 | // queries |
Mathias Agopian | 875d8e1 | 2013-06-07 15:35:48 -0700 | [diff] [blame] | 153 | virtual size_t getMaxTextureSize() const = 0; |
| 154 | virtual size_t getMaxViewportDims() const = 0; |
| 155 | |
Chia-I Wu | f846a35 | 2017-11-10 09:22:52 -0800 | [diff] [blame] | 156 | // internal to RenderEngine |
Chia-I Wu | 2b6386e | 2017-11-09 13:03:17 -0800 | [diff] [blame] | 157 | EGLDisplay getEGLDisplay() const; |
Jesse Hall | 05f8c70 | 2013-12-23 20:44:38 -0800 | [diff] [blame] | 158 | EGLConfig getEGLConfig() const; |
Mathias Agopian | 875d8e1 | 2013-06-07 15:35:48 -0700 | [diff] [blame] | 159 | }; |
| 160 | |
| 161 | // --------------------------------------------------------------------------- |
| 162 | }; // namespace android |
| 163 | // --------------------------------------------------------------------------- |
| 164 | |
| 165 | #endif /* SF_RENDERENGINE_H_ */ |