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