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 | 875d8e1 | 2013-06-07 15:35:48 -0700 | [diff] [blame] | 26 | |
| 27 | // --------------------------------------------------------------------------- |
| 28 | namespace android { |
| 29 | // --------------------------------------------------------------------------- |
| 30 | |
| 31 | class String8; |
Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 32 | class Rect; |
| 33 | class Region; |
| 34 | class Mesh; |
Mathias Agopian | 875d8e1 | 2013-06-07 15:35:48 -0700 | [diff] [blame] | 35 | |
| 36 | class RenderEngine { |
| 37 | enum GlesVersion { |
| 38 | GLES_VERSION_1_0 = 0x10000, |
| 39 | GLES_VERSION_1_1 = 0x10001, |
| 40 | GLES_VERSION_2_0 = 0x20000, |
| 41 | GLES_VERSION_3_0 = 0x30000, |
| 42 | }; |
| 43 | static GlesVersion parseGlesVersion(const char* str); |
| 44 | |
| 45 | EGLContext mEGLContext; |
| 46 | void setEGLContext(EGLContext ctxt); |
| 47 | |
| 48 | protected: |
| 49 | RenderEngine(); |
| 50 | virtual ~RenderEngine() = 0; |
| 51 | |
| 52 | public: |
| 53 | static RenderEngine* create(EGLDisplay display, EGLConfig config); |
| 54 | |
Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 55 | // helpers |
| 56 | void clearWithColor(float red, float green, float blue, float alpha); |
| 57 | void fillRegionWithColor(const Region& region, uint32_t height, |
| 58 | float red, float green, float blue, float alpha); |
Mathias Agopian | 875d8e1 | 2013-06-07 15:35:48 -0700 | [diff] [blame] | 59 | |
Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 60 | // common to all GL versions |
| 61 | void setScissor(uint32_t left, uint32_t bottom, uint32_t right, uint32_t top); |
| 62 | void disableScissor(); |
| 63 | void genTextures(size_t count, uint32_t* names); |
| 64 | void deleteTextures(size_t count, uint32_t const* names); |
| 65 | |
| 66 | class BindImageAsFramebuffer { |
| 67 | RenderEngine& mEngine; |
| 68 | unsigned int mTexName, mFbName; |
| 69 | unsigned int mStatus; |
| 70 | public: |
| 71 | BindImageAsFramebuffer(RenderEngine& engine, EGLImageKHR image); |
| 72 | ~BindImageAsFramebuffer(); |
| 73 | int getStatus() const; |
| 74 | }; |
| 75 | |
| 76 | // set-up |
| 77 | virtual void checkErrors() const; |
Mathias Agopian | 875d8e1 | 2013-06-07 15:35:48 -0700 | [diff] [blame] | 78 | virtual void dump(String8& result) = 0; |
Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 79 | 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] | 80 | virtual void setupLayerBlending(bool premultipliedAlpha, bool opaque, int alpha) = 0; |
| 81 | virtual void setupDimLayerBlending(int alpha) = 0; |
| 82 | virtual void setupLayerTexturing(size_t textureName, bool useFiltering, const float* textureMatrix) = 0; |
| 83 | virtual void setupLayerBlackedOut() = 0; |
| 84 | |
| 85 | virtual void disableTexturing() = 0; |
| 86 | virtual void disableBlending() = 0; |
| 87 | |
Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 88 | // drawing |
| 89 | virtual void fillWithColor(const Mesh& mesh, float r, float g, float b, float a) = 0; |
| 90 | virtual void drawMesh(const Mesh& mesh) = 0; |
Mathias Agopian | 875d8e1 | 2013-06-07 15:35:48 -0700 | [diff] [blame] | 91 | |
Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 92 | // queries |
Mathias Agopian | 875d8e1 | 2013-06-07 15:35:48 -0700 | [diff] [blame] | 93 | virtual size_t getMaxTextureSize() const = 0; |
| 94 | virtual size_t getMaxViewportDims() const = 0; |
| 95 | |
Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 96 | |
| 97 | |
Mathias Agopian | 875d8e1 | 2013-06-07 15:35:48 -0700 | [diff] [blame] | 98 | EGLContext getEGLContext() const; |
| 99 | }; |
| 100 | |
| 101 | // --------------------------------------------------------------------------- |
| 102 | }; // namespace android |
| 103 | // --------------------------------------------------------------------------- |
| 104 | |
| 105 | #endif /* SF_RENDERENGINE_H_ */ |