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>
27 #include <Transform.h>
29 #define EGL_NO_CONFIG ((EGLConfig)0)
31 // ---------------------------------------------------------------------------
33 // ---------------------------------------------------------------------------
43 GLES_VERSION_1_0 = 0x10000,
44 GLES_VERSION_1_1 = 0x10001,
45 GLES_VERSION_2_0 = 0x20000,
46 GLES_VERSION_3_0 = 0x30000,
48 static GlesVersion parseGlesVersion(const char* str);
51 EGLContext mEGLContext;
52 void setEGLHandles(EGLConfig config, EGLContext ctxt);
54 virtual void bindImageAsFramebuffer(EGLImageKHR image, uint32_t* texName, uint32_t* fbName, uint32_t* status) = 0;
55 virtual void unbindFramebuffer(uint32_t texName, uint32_t fbName) = 0;
59 virtual ~RenderEngine() = 0;
62 static RenderEngine* create(EGLDisplay display, int hwcFormat);
64 static EGLConfig chooseEglConfig(EGLDisplay display, int format);
66 // dump the extension strings. always call the base class.
67 virtual void dump(String8& result);
70 void clearWithColor(float red, float green, float blue, float alpha);
71 void fillRegionWithColor(const Region& region, uint32_t height,
72 float red, float green, float blue, float alpha);
74 // common to all GL versions
75 void setScissor(uint32_t left, uint32_t bottom, uint32_t right, uint32_t top);
76 void disableScissor();
77 void genTextures(size_t count, uint32_t* names);
78 void deleteTextures(size_t count, uint32_t const* names);
79 void readPixels(size_t l, size_t b, size_t w, size_t h, uint32_t* pixels);
81 class BindImageAsFramebuffer {
82 RenderEngine& mEngine;
83 uint32_t mTexName, mFbName;
86 BindImageAsFramebuffer(RenderEngine& engine, EGLImageKHR image);
87 ~BindImageAsFramebuffer();
88 int getStatus() const;
92 virtual void checkErrors() const;
93 virtual void setViewportAndProjection(size_t vpw, size_t vph,
94 Rect sourceCrop, size_t hwh, bool yswap, Transform::orientation_flags rotation) = 0;
95 virtual void setupLayerBlending(bool premultipliedAlpha, bool opaque, int alpha) = 0;
96 virtual void setupDimLayerBlending(int alpha) = 0;
97 virtual void setupLayerTexturing(const Texture& texture) = 0;
98 virtual void setupLayerBlackedOut() = 0;
99 virtual void setupFillWithColor(float r, float g, float b, float a) = 0;
101 virtual void disableTexturing() = 0;
102 virtual void disableBlending() = 0;
105 virtual void drawMesh(const Mesh& mesh) = 0;
108 // creates a color-transform group, everything drawn in the group will be
109 // transformed by the given color transform when endGroup() is called.
110 virtual void beginGroup(const mat4& colorTransform) = 0;
111 virtual void endGroup() = 0;
114 virtual size_t getMaxTextureSize() const = 0;
115 virtual size_t getMaxViewportDims() const = 0;
117 EGLConfig getEGLConfig() const;
118 EGLContext getEGLContext() const;
121 // ---------------------------------------------------------------------------
122 }; // namespace android
123 // ---------------------------------------------------------------------------
125 #endif /* SF_RENDERENGINE_H_ */