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 | ff2ed70 | 2013-09-01 21:36:12 -0700 | [diff] [blame] | 26 | #include <ui/mat4.h> |
Mathias Agopian | 875d8e1 | 2013-06-07 15:35:48 -0700 | [diff] [blame] | 27 | |
| 28 | // --------------------------------------------------------------------------- |
| 29 | namespace android { |
| 30 | // --------------------------------------------------------------------------- |
| 31 | |
| 32 | class String8; |
Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 33 | class Rect; |
| 34 | class Region; |
| 35 | class Mesh; |
Mathias Agopian | 49457ac | 2013-08-14 18:20:17 -0700 | [diff] [blame] | 36 | class Texture; |
Mathias Agopian | 875d8e1 | 2013-06-07 15:35:48 -0700 | [diff] [blame] | 37 | |
| 38 | class RenderEngine { |
| 39 | enum GlesVersion { |
| 40 | GLES_VERSION_1_0 = 0x10000, |
| 41 | GLES_VERSION_1_1 = 0x10001, |
| 42 | GLES_VERSION_2_0 = 0x20000, |
| 43 | GLES_VERSION_3_0 = 0x30000, |
| 44 | }; |
| 45 | static GlesVersion parseGlesVersion(const char* str); |
| 46 | |
| 47 | EGLContext mEGLContext; |
| 48 | void setEGLContext(EGLContext ctxt); |
| 49 | |
Mathias Agopian | 458197d | 2013-08-15 14:56:51 -0700 | [diff] [blame] | 50 | virtual void bindImageAsFramebuffer(EGLImageKHR image, uint32_t* texName, uint32_t* fbName, uint32_t* status) = 0; |
| 51 | virtual void unbindFramebuffer(uint32_t texName, uint32_t fbName) = 0; |
| 52 | |
Mathias Agopian | 875d8e1 | 2013-06-07 15:35:48 -0700 | [diff] [blame] | 53 | protected: |
| 54 | RenderEngine(); |
| 55 | virtual ~RenderEngine() = 0; |
| 56 | |
| 57 | public: |
| 58 | static RenderEngine* create(EGLDisplay display, EGLConfig config); |
| 59 | |
Mathias Agopian | 458197d | 2013-08-15 14:56:51 -0700 | [diff] [blame] | 60 | // dump the extension strings. always call the base class. |
| 61 | virtual void dump(String8& result); |
| 62 | |
Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 63 | // helpers |
| 64 | void clearWithColor(float red, float green, float blue, float alpha); |
| 65 | void fillRegionWithColor(const Region& region, uint32_t height, |
| 66 | float red, float green, float blue, float alpha); |
Mathias Agopian | 875d8e1 | 2013-06-07 15:35:48 -0700 | [diff] [blame] | 67 | |
Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 68 | // common to all GL versions |
| 69 | void setScissor(uint32_t left, uint32_t bottom, uint32_t right, uint32_t top); |
| 70 | void disableScissor(); |
| 71 | void genTextures(size_t count, uint32_t* names); |
| 72 | void deleteTextures(size_t count, uint32_t const* names); |
Mathias Agopian | d555684 | 2013-09-19 17:08:37 -0700 | [diff] [blame^] | 73 | 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] | 74 | |
| 75 | class BindImageAsFramebuffer { |
| 76 | RenderEngine& mEngine; |
Mathias Agopian | 458197d | 2013-08-15 14:56:51 -0700 | [diff] [blame] | 77 | uint32_t mTexName, mFbName; |
| 78 | uint32_t mStatus; |
Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 79 | public: |
| 80 | BindImageAsFramebuffer(RenderEngine& engine, EGLImageKHR image); |
| 81 | ~BindImageAsFramebuffer(); |
| 82 | int getStatus() const; |
| 83 | }; |
| 84 | |
| 85 | // set-up |
| 86 | virtual void checkErrors() const; |
Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 87 | virtual void setViewportAndProjection(size_t vpw, size_t vph, size_t w, size_t h, bool yswap) = 0; |
Mathias Agopian | 875d8e1 | 2013-06-07 15:35:48 -0700 | [diff] [blame] | 88 | virtual void setupLayerBlending(bool premultipliedAlpha, bool opaque, int alpha) = 0; |
| 89 | virtual void setupDimLayerBlending(int alpha) = 0; |
Mathias Agopian | 49457ac | 2013-08-14 18:20:17 -0700 | [diff] [blame] | 90 | virtual void setupLayerTexturing(const Texture& texture) = 0; |
Mathias Agopian | 875d8e1 | 2013-06-07 15:35:48 -0700 | [diff] [blame] | 91 | virtual void setupLayerBlackedOut() = 0; |
Mathias Agopian | 19733a3 | 2013-08-28 18:13:56 -0700 | [diff] [blame] | 92 | virtual void setupFillWithColor(float r, float g, float b, float a) = 0; |
Mathias Agopian | 875d8e1 | 2013-06-07 15:35:48 -0700 | [diff] [blame] | 93 | |
| 94 | virtual void disableTexturing() = 0; |
| 95 | virtual void disableBlending() = 0; |
| 96 | |
Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 97 | // drawing |
Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 98 | virtual void drawMesh(const Mesh& mesh) = 0; |
Mathias Agopian | 875d8e1 | 2013-06-07 15:35:48 -0700 | [diff] [blame] | 99 | |
Mathias Agopian | ff2ed70 | 2013-09-01 21:36:12 -0700 | [diff] [blame] | 100 | // grouping |
| 101 | // creates a color-transform group, everything drawn in the group will be |
| 102 | // transformed by the given color transform when endGroup() is called. |
| 103 | virtual void beginGroup(const mat4& colorTransform) = 0; |
| 104 | virtual void endGroup() = 0; |
| 105 | |
Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 106 | // queries |
Mathias Agopian | 875d8e1 | 2013-06-07 15:35:48 -0700 | [diff] [blame] | 107 | virtual size_t getMaxTextureSize() const = 0; |
| 108 | virtual size_t getMaxViewportDims() const = 0; |
| 109 | |
Mathias Agopian | 875d8e1 | 2013-06-07 15:35:48 -0700 | [diff] [blame] | 110 | EGLContext getEGLContext() const; |
| 111 | }; |
| 112 | |
| 113 | // --------------------------------------------------------------------------- |
| 114 | }; // namespace android |
| 115 | // --------------------------------------------------------------------------- |
| 116 | |
| 117 | #endif /* SF_RENDERENGINE_H_ */ |