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