OSDN Git Service

Merge "Add new system APK locations." into lmp-dev
[android-x86/frameworks-native.git] / services / surfaceflinger / RenderEngine / RenderEngine.h
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 // ---------------------------------------------------------------------------
31 namespace android {
32 // ---------------------------------------------------------------------------
33
34 class String8;
35 class Rect;
36 class Region;
37 class Mesh;
38 class Texture;
39
40 class 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
56 protected:
57     RenderEngine();
58     virtual ~RenderEngine() = 0;
59
60 public:
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,
93             Rect sourceCrop, size_t hwh, bool yswap) = 0;
94     virtual void setupLayerBlending(bool premultipliedAlpha, bool opaque, int alpha) = 0;
95     virtual void setupDimLayerBlending(int alpha) = 0;
96     virtual void setupLayerTexturing(const Texture& texture) = 0;
97     virtual void setupLayerBlackedOut() = 0;
98     virtual void setupFillWithColor(float r, float g, float b, float a) = 0;
99
100     virtual void disableTexturing() = 0;
101     virtual void disableBlending() = 0;
102
103     // drawing
104     virtual void drawMesh(const Mesh& mesh) = 0;
105
106     // grouping
107     // creates a color-transform group, everything drawn in the group will be
108     // transformed by the given color transform when endGroup() is called.
109     virtual void beginGroup(const mat4& colorTransform) = 0;
110     virtual void endGroup() = 0;
111
112     // queries
113     virtual size_t getMaxTextureSize() const = 0;
114     virtual size_t getMaxViewportDims() const = 0;
115
116     EGLConfig getEGLConfig() const;
117     EGLContext getEGLContext() const;
118 };
119
120 // ---------------------------------------------------------------------------
121 }; // namespace android
122 // ---------------------------------------------------------------------------
123
124 #endif /* SF_RENDERENGINE_H_ */