blob: 577dc0aa8f3266ff33cad542a59320a4b398195d [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 Agopianff2ed702013-09-01 21:36:12 -070026#include <ui/mat4.h>
Mathias Agopian875d8e12013-06-07 15:35:48 -070027
Jesse Hall19e87292013-12-23 21:02:15 -080028#define EGL_NO_CONFIG ((EGLConfig)0)
29
Mathias Agopian875d8e12013-06-07 15:35:48 -070030// ---------------------------------------------------------------------------
31namespace android {
32// ---------------------------------------------------------------------------
33
34class String8;
Mathias Agopian3f844832013-08-07 21:24:32 -070035class Rect;
36class Region;
37class Mesh;
Mathias Agopian49457ac2013-08-14 18:20:17 -070038class Texture;
Mathias Agopian875d8e12013-06-07 15:35:48 -070039
40class 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
Jesse Hall05f8c702013-12-23 20:44:38 -080049 EGLConfig mEGLConfig;
Mathias Agopian875d8e12013-06-07 15:35:48 -070050 EGLContext mEGLContext;
Jesse Hall05f8c702013-12-23 20:44:38 -080051 void setEGLHandles(EGLConfig config, EGLContext ctxt);
Mathias Agopian875d8e12013-06-07 15:35:48 -070052
Mathias Agopian458197d2013-08-15 14:56:51 -070053 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
Mathias Agopian875d8e12013-06-07 15:35:48 -070056protected:
57 RenderEngine();
58 virtual ~RenderEngine() = 0;
59
60public:
Jesse Hall05f8c702013-12-23 20:44:38 -080061 static RenderEngine* create(EGLDisplay display, int hwcFormat);
62
63 static EGLConfig chooseEglConfig(EGLDisplay display, int format);
Mathias Agopian875d8e12013-06-07 15:35:48 -070064
Mathias Agopian458197d2013-08-15 14:56:51 -070065 // dump the extension strings. always call the base class.
66 virtual void dump(String8& result);
67
Mathias Agopian3f844832013-08-07 21:24:32 -070068 // 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);
Mathias Agopian875d8e12013-06-07 15:35:48 -070072
Mathias Agopian3f844832013-08-07 21:24:32 -070073 // 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);
Mathias Agopiand5556842013-09-19 17:08:37 -070078 void readPixels(size_t l, size_t b, size_t w, size_t h, uint32_t* pixels);
Mathias Agopian3f844832013-08-07 21:24:32 -070079
80 class BindImageAsFramebuffer {
81 RenderEngine& mEngine;
Mathias Agopian458197d2013-08-15 14:56:51 -070082 uint32_t mTexName, mFbName;
83 uint32_t mStatus;
Mathias Agopian3f844832013-08-07 21:24:32 -070084 public:
85 BindImageAsFramebuffer(RenderEngine& engine, EGLImageKHR image);
86 ~BindImageAsFramebuffer();
87 int getStatus() const;
88 };
89
90 // set-up
91 virtual void checkErrors() const;
Mathias Agopian3f844832013-08-07 21:24:32 -070092 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 -070093 virtual void setupLayerBlending(bool premultipliedAlpha, bool opaque, int alpha) = 0;
94 virtual void setupDimLayerBlending(int alpha) = 0;
Mathias Agopian49457ac2013-08-14 18:20:17 -070095 virtual void setupLayerTexturing(const Texture& texture) = 0;
Mathias Agopian875d8e12013-06-07 15:35:48 -070096 virtual void setupLayerBlackedOut() = 0;
Mathias Agopian19733a32013-08-28 18:13:56 -070097 virtual void setupFillWithColor(float r, float g, float b, float a) = 0;
Mathias Agopian875d8e12013-06-07 15:35:48 -070098
99 virtual void disableTexturing() = 0;
100 virtual void disableBlending() = 0;
101
Mathias Agopian3f844832013-08-07 21:24:32 -0700102 // drawing
Mathias Agopian3f844832013-08-07 21:24:32 -0700103 virtual void drawMesh(const Mesh& mesh) = 0;
Mathias Agopian875d8e12013-06-07 15:35:48 -0700104
Mathias Agopianff2ed702013-09-01 21:36:12 -0700105 // grouping
106 // creates a color-transform group, everything drawn in the group will be
107 // transformed by the given color transform when endGroup() is called.
108 virtual void beginGroup(const mat4& colorTransform) = 0;
109 virtual void endGroup() = 0;
110
Mathias Agopian3f844832013-08-07 21:24:32 -0700111 // queries
Mathias Agopian875d8e12013-06-07 15:35:48 -0700112 virtual size_t getMaxTextureSize() const = 0;
113 virtual size_t getMaxViewportDims() const = 0;
114
Jesse Hall05f8c702013-12-23 20:44:38 -0800115 EGLConfig getEGLConfig() const;
Mathias Agopian875d8e12013-06-07 15:35:48 -0700116 EGLContext getEGLContext() const;
117};
118
119// ---------------------------------------------------------------------------
120}; // namespace android
121// ---------------------------------------------------------------------------
122
123#endif /* SF_RENDERENGINE_H_ */