2 * Copyright 2013 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 #ifndef SF_RENDERENGINE_H_
19 #define SF_RENDERENGINE_H_
22 #include <sys/types.h>
25 #include <EGL/eglext.h>
28 #define EGL_NO_CONFIG ((EGLConfig)0)
30 // ---------------------------------------------------------------------------
32 // ---------------------------------------------------------------------------
42 GLES_VERSION_1_0 = 0x10000,
43 GLES_VERSION_1_1 = 0x10001,
44 GLES_VERSION_2_0 = 0x20000,
45 GLES_VERSION_3_0 = 0x30000,
47 static GlesVersion parseGlesVersion(const char* str);
50 EGLContext mEGLContext;
51 void setEGLHandles(EGLConfig config, EGLContext ctxt);
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;
58 virtual ~RenderEngine() = 0;
61 static RenderEngine* create(EGLDisplay display, int hwcFormat);
63 static EGLConfig chooseEglConfig(EGLDisplay display, int format);
65 // dump the extension strings. always call the base class.
66 virtual void dump(String8& result);
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);
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);
80 class BindImageAsFramebuffer {
81 RenderEngine& mEngine;
82 uint32_t mTexName, mFbName;
85 BindImageAsFramebuffer(RenderEngine& engine, EGLImageKHR image);
86 ~BindImageAsFramebuffer();
87 int getStatus() const;
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;
100 virtual void disableTexturing() = 0;
101 virtual void disableBlending() = 0;
104 virtual void drawMesh(const Mesh& mesh) = 0;
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;
113 virtual size_t getMaxTextureSize() const = 0;
114 virtual size_t getMaxViewportDims() const = 0;
116 EGLConfig getEGLConfig() const;
117 EGLContext getEGLContext() const;
120 // ---------------------------------------------------------------------------
121 }; // namespace android
122 // ---------------------------------------------------------------------------
124 #endif /* SF_RENDERENGINE_H_ */