blob: d19137be1fc0b738363d7347b37eb6eebdf2e3c2 [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 Agopian1d77b712017-02-17 15:46:13 -080026#include <math/mat4.h>
Riley Andrewsc3ebe662014-09-04 16:20:31 -070027#include <Transform.h>
Mathias Agopian875d8e12013-06-07 15:35:48 -070028
Jesse Hall19e87292013-12-23 21:02:15 -080029#define EGL_NO_CONFIG ((EGLConfig)0)
30
Mathias Agopian875d8e12013-06-07 15:35:48 -070031// ---------------------------------------------------------------------------
32namespace android {
33// ---------------------------------------------------------------------------
34
35class String8;
Mathias Agopian3f844832013-08-07 21:24:32 -070036class Rect;
37class Region;
38class Mesh;
Mathias Agopian49457ac2013-08-14 18:20:17 -070039class Texture;
Mathias Agopian875d8e12013-06-07 15:35:48 -070040
41class RenderEngine {
42 enum GlesVersion {
43 GLES_VERSION_1_0 = 0x10000,
44 GLES_VERSION_1_1 = 0x10001,
45 GLES_VERSION_2_0 = 0x20000,
46 GLES_VERSION_3_0 = 0x30000,
47 };
48 static GlesVersion parseGlesVersion(const char* str);
49
Jesse Hall05f8c702013-12-23 20:44:38 -080050 EGLConfig mEGLConfig;
Mathias Agopian875d8e12013-06-07 15:35:48 -070051 EGLContext mEGLContext;
Jesse Hall05f8c702013-12-23 20:44:38 -080052 void setEGLHandles(EGLConfig config, EGLContext ctxt);
Mathias Agopian875d8e12013-06-07 15:35:48 -070053
Mathias Agopian458197d2013-08-15 14:56:51 -070054 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;
56
Mathias Agopian875d8e12013-06-07 15:35:48 -070057protected:
58 RenderEngine();
59 virtual ~RenderEngine() = 0;
60
61public:
Jesse Hall05f8c702013-12-23 20:44:38 -080062 static RenderEngine* create(EGLDisplay display, int hwcFormat);
63
64 static EGLConfig chooseEglConfig(EGLDisplay display, int format);
Mathias Agopian875d8e12013-06-07 15:35:48 -070065
Dan Stoza4e637772016-07-28 13:31:51 -070066 void primeCache() const;
67
Mathias Agopian458197d2013-08-15 14:56:51 -070068 // dump the extension strings. always call the base class.
69 virtual void dump(String8& result);
70
Mathias Agopian3f844832013-08-07 21:24:32 -070071 // helpers
Riley Andrews9707f4d2014-10-23 16:17:04 -070072 void flush();
Mathias Agopian3f844832013-08-07 21:24:32 -070073 void clearWithColor(float red, float green, float blue, float alpha);
74 void fillRegionWithColor(const Region& region, uint32_t height,
75 float red, float green, float blue, float alpha);
Mathias Agopian875d8e12013-06-07 15:35:48 -070076
Mathias Agopian3f844832013-08-07 21:24:32 -070077 // common to all GL versions
78 void setScissor(uint32_t left, uint32_t bottom, uint32_t right, uint32_t top);
79 void disableScissor();
80 void genTextures(size_t count, uint32_t* names);
81 void deleteTextures(size_t count, uint32_t const* names);
Mathias Agopiand5556842013-09-19 17:08:37 -070082 void readPixels(size_t l, size_t b, size_t w, size_t h, uint32_t* pixels);
Mathias Agopian3f844832013-08-07 21:24:32 -070083
84 class BindImageAsFramebuffer {
85 RenderEngine& mEngine;
Mathias Agopian458197d2013-08-15 14:56:51 -070086 uint32_t mTexName, mFbName;
87 uint32_t mStatus;
Mathias Agopian3f844832013-08-07 21:24:32 -070088 public:
89 BindImageAsFramebuffer(RenderEngine& engine, EGLImageKHR image);
90 ~BindImageAsFramebuffer();
91 int getStatus() const;
92 };
93
94 // set-up
95 virtual void checkErrors() const;
Dan Stozac1879002014-05-22 15:59:05 -070096 virtual void setViewportAndProjection(size_t vpw, size_t vph,
Riley Andrewsc3ebe662014-09-04 16:20:31 -070097 Rect sourceCrop, size_t hwh, bool yswap, Transform::orientation_flags rotation) = 0;
Fabien Sanglard9d96de42016-10-11 00:15:18 +000098#ifdef USE_HWC2
Dan Stoza9e56aa02015-11-02 13:00:03 -080099 virtual void setupLayerBlending(bool premultipliedAlpha, bool opaque, float alpha) = 0;
100 virtual void setupDimLayerBlending(float alpha) = 0;
Fabien Sanglard9d96de42016-10-11 00:15:18 +0000101#else
102 virtual void setupLayerBlending(bool premultipliedAlpha, bool opaque, int alpha) = 0;
103 virtual void setupDimLayerBlending(int alpha) = 0;
104#endif
Mathias Agopian49457ac2013-08-14 18:20:17 -0700105 virtual void setupLayerTexturing(const Texture& texture) = 0;
Mathias Agopian875d8e12013-06-07 15:35:48 -0700106 virtual void setupLayerBlackedOut() = 0;
Mathias Agopian19733a32013-08-28 18:13:56 -0700107 virtual void setupFillWithColor(float r, float g, float b, float a) = 0;
Mathias Agopian875d8e12013-06-07 15:35:48 -0700108
Dan Stozaf0087992014-10-20 15:46:09 -0700109 virtual mat4 setupColorTransform(const mat4& /* colorTransform */) {
110 return mat4();
111 }
112
Mathias Agopian875d8e12013-06-07 15:35:48 -0700113 virtual void disableTexturing() = 0;
114 virtual void disableBlending() = 0;
115
Mathias Agopian3f844832013-08-07 21:24:32 -0700116 // drawing
Mathias Agopian3f844832013-08-07 21:24:32 -0700117 virtual void drawMesh(const Mesh& mesh) = 0;
Mathias Agopian875d8e12013-06-07 15:35:48 -0700118
Mathias Agopian3f844832013-08-07 21:24:32 -0700119 // queries
Mathias Agopian875d8e12013-06-07 15:35:48 -0700120 virtual size_t getMaxTextureSize() const = 0;
121 virtual size_t getMaxViewportDims() const = 0;
122
Jesse Hall05f8c702013-12-23 20:44:38 -0800123 EGLConfig getEGLConfig() const;
Mathias Agopian875d8e12013-06-07 15:35:48 -0700124 EGLContext getEGLContext() const;
125};
126
127// ---------------------------------------------------------------------------
128}; // namespace android
129// ---------------------------------------------------------------------------
130
131#endif /* SF_RENDERENGINE_H_ */