blob: 3c2b2ea139b1fcbe8989db31454d238a2f8cefdd [file] [log] [blame]
Mathias Agopian875d8e12013-06-07 15:35:48 -07001/*
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>
Mathias Agopian3f844832013-08-07 21:24:32 -070025#include <EGL/eglext.h>
Mathias Agopian875d8e12013-06-07 15:35:48 -070026
27// ---------------------------------------------------------------------------
28namespace android {
29// ---------------------------------------------------------------------------
30
31class String8;
Mathias Agopian3f844832013-08-07 21:24:32 -070032class Rect;
33class Region;
34class Mesh;
Mathias Agopian875d8e12013-06-07 15:35:48 -070035
36class RenderEngine {
37 enum GlesVersion {
38 GLES_VERSION_1_0 = 0x10000,
39 GLES_VERSION_1_1 = 0x10001,
40 GLES_VERSION_2_0 = 0x20000,
41 GLES_VERSION_3_0 = 0x30000,
42 };
43 static GlesVersion parseGlesVersion(const char* str);
44
45 EGLContext mEGLContext;
46 void setEGLContext(EGLContext ctxt);
47
Mathias Agopian458197d2013-08-15 14:56:51 -070048 virtual void bindImageAsFramebuffer(EGLImageKHR image, uint32_t* texName, uint32_t* fbName, uint32_t* status) = 0;
49 virtual void unbindFramebuffer(uint32_t texName, uint32_t fbName) = 0;
50
Mathias Agopian875d8e12013-06-07 15:35:48 -070051protected:
52 RenderEngine();
53 virtual ~RenderEngine() = 0;
54
55public:
56 static RenderEngine* create(EGLDisplay display, EGLConfig config);
57
Mathias Agopian458197d2013-08-15 14:56:51 -070058 // dump the extension strings. always call the base class.
59 virtual void dump(String8& result);
60
Mathias Agopian3f844832013-08-07 21:24:32 -070061 // helpers
62 void clearWithColor(float red, float green, float blue, float alpha);
63 void fillRegionWithColor(const Region& region, uint32_t height,
64 float red, float green, float blue, float alpha);
Mathias Agopian875d8e12013-06-07 15:35:48 -070065
Mathias Agopian3f844832013-08-07 21:24:32 -070066 // common to all GL versions
67 void setScissor(uint32_t left, uint32_t bottom, uint32_t right, uint32_t top);
68 void disableScissor();
69 void genTextures(size_t count, uint32_t* names);
70 void deleteTextures(size_t count, uint32_t const* names);
71
72 class BindImageAsFramebuffer {
73 RenderEngine& mEngine;
Mathias Agopian458197d2013-08-15 14:56:51 -070074 uint32_t mTexName, mFbName;
75 uint32_t mStatus;
Mathias Agopian3f844832013-08-07 21:24:32 -070076 public:
77 BindImageAsFramebuffer(RenderEngine& engine, EGLImageKHR image);
78 ~BindImageAsFramebuffer();
79 int getStatus() const;
80 };
81
82 // set-up
83 virtual void checkErrors() const;
Mathias Agopian3f844832013-08-07 21:24:32 -070084 virtual void setViewportAndProjection(size_t vpw, size_t vph, size_t w, size_t h, bool yswap) = 0;
Mathias Agopian875d8e12013-06-07 15:35:48 -070085 virtual void setupLayerBlending(bool premultipliedAlpha, bool opaque, int alpha) = 0;
86 virtual void setupDimLayerBlending(int alpha) = 0;
87 virtual void setupLayerTexturing(size_t textureName, bool useFiltering, const float* textureMatrix) = 0;
88 virtual void setupLayerBlackedOut() = 0;
89
90 virtual void disableTexturing() = 0;
91 virtual void disableBlending() = 0;
92
Mathias Agopian3f844832013-08-07 21:24:32 -070093 // drawing
94 virtual void fillWithColor(const Mesh& mesh, float r, float g, float b, float a) = 0;
95 virtual void drawMesh(const Mesh& mesh) = 0;
Mathias Agopian875d8e12013-06-07 15:35:48 -070096
Mathias Agopian3f844832013-08-07 21:24:32 -070097 // queries
Mathias Agopian875d8e12013-06-07 15:35:48 -070098 virtual size_t getMaxTextureSize() const = 0;
99 virtual size_t getMaxViewportDims() const = 0;
100
Mathias Agopian3f844832013-08-07 21:24:32 -0700101
102
Mathias Agopian875d8e12013-06-07 15:35:48 -0700103 EGLContext getEGLContext() const;
104};
105
106// ---------------------------------------------------------------------------
107}; // namespace android
108// ---------------------------------------------------------------------------
109
110#endif /* SF_RENDERENGINE_H_ */