blob: bd5eac26723a8912bd23aa6ca41663e4b6a6d88f [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
Chia-I Wub2c76242017-11-09 17:17:07 -080021#include <memory>
22
Mathias Agopian875d8e12013-06-07 15:35:48 -070023#include <stdint.h>
24#include <sys/types.h>
25
26#include <EGL/egl.h>
Mathias Agopian3f844832013-08-07 21:24:32 -070027#include <EGL/eglext.h>
Mathias Agopian1d77b712017-02-17 15:46:13 -080028#include <math/mat4.h>
Riley Andrewsc3ebe662014-09-04 16:20:31 -070029#include <Transform.h>
chaviw13fdc492017-06-27 12:40:18 -070030#include <gui/SurfaceControl.h>
Mathias Agopian875d8e12013-06-07 15:35:48 -070031
Jesse Hall19e87292013-12-23 21:02:15 -080032#define EGL_NO_CONFIG ((EGLConfig)0)
33
Mathias Agopian875d8e12013-06-07 15:35:48 -070034// ---------------------------------------------------------------------------
35namespace android {
36// ---------------------------------------------------------------------------
37
38class String8;
Mathias Agopian3f844832013-08-07 21:24:32 -070039class Rect;
40class Region;
41class Mesh;
Mathias Agopian49457ac2013-08-14 18:20:17 -070042class Texture;
Mathias Agopian875d8e12013-06-07 15:35:48 -070043
44class RenderEngine {
45 enum GlesVersion {
46 GLES_VERSION_1_0 = 0x10000,
47 GLES_VERSION_1_1 = 0x10001,
48 GLES_VERSION_2_0 = 0x20000,
49 GLES_VERSION_3_0 = 0x30000,
50 };
51 static GlesVersion parseGlesVersion(const char* str);
52
Chia-I Wu2b6386e2017-11-09 13:03:17 -080053 EGLDisplay mEGLDisplay;
Jesse Hall05f8c702013-12-23 20:44:38 -080054 EGLConfig mEGLConfig;
Mathias Agopian875d8e12013-06-07 15:35:48 -070055 EGLContext mEGLContext;
Chia-I Wu2b6386e2017-11-09 13:03:17 -080056 void setEGLHandles(EGLDisplay display, EGLConfig config, EGLContext ctxt);
Mathias Agopian875d8e12013-06-07 15:35:48 -070057
Mathias Agopian458197d2013-08-15 14:56:51 -070058 virtual void bindImageAsFramebuffer(EGLImageKHR image, uint32_t* texName, uint32_t* fbName, uint32_t* status) = 0;
59 virtual void unbindFramebuffer(uint32_t texName, uint32_t fbName) = 0;
60
Mathias Agopian875d8e12013-06-07 15:35:48 -070061protected:
62 RenderEngine();
Mathias Agopian875d8e12013-06-07 15:35:48 -070063
64public:
Chia-I Wub2c76242017-11-09 17:17:07 -080065 virtual ~RenderEngine() = 0;
66
Kalle Raitabbdcf1f2017-05-22 15:47:46 -070067 enum FeatureFlag {
68 WIDE_COLOR_SUPPORT = 1 << 0 // Platform has a wide color display
69 };
Chia-I Wud4d9c6f2017-11-09 16:55:31 -080070 static std::unique_ptr<RenderEngine> create(int hwcFormat, uint32_t featureFlags);
Jesse Hall05f8c702013-12-23 20:44:38 -080071
Steven Thomas94e35b92017-07-26 18:48:28 -070072 static EGLConfig chooseEglConfig(EGLDisplay display, int format, bool logConfig);
Mathias Agopian875d8e12013-06-07 15:35:48 -070073
Dan Stoza4e637772016-07-28 13:31:51 -070074 void primeCache() const;
75
Mathias Agopian458197d2013-08-15 14:56:51 -070076 // dump the extension strings. always call the base class.
77 virtual void dump(String8& result);
78
Mathias Agopian3f844832013-08-07 21:24:32 -070079 // helpers
Riley Andrews9707f4d2014-10-23 16:17:04 -070080 void flush();
Mathias Agopian3f844832013-08-07 21:24:32 -070081 void clearWithColor(float red, float green, float blue, float alpha);
82 void fillRegionWithColor(const Region& region, uint32_t height,
83 float red, float green, float blue, float alpha);
Mathias Agopian875d8e12013-06-07 15:35:48 -070084
Mathias Agopian3f844832013-08-07 21:24:32 -070085 // common to all GL versions
86 void setScissor(uint32_t left, uint32_t bottom, uint32_t right, uint32_t top);
87 void disableScissor();
88 void genTextures(size_t count, uint32_t* names);
89 void deleteTextures(size_t count, uint32_t const* names);
Mathias Agopiand5556842013-09-19 17:08:37 -070090 void readPixels(size_t l, size_t b, size_t w, size_t h, uint32_t* pixels);
Mathias Agopian3f844832013-08-07 21:24:32 -070091
92 class BindImageAsFramebuffer {
93 RenderEngine& mEngine;
Mathias Agopian458197d2013-08-15 14:56:51 -070094 uint32_t mTexName, mFbName;
95 uint32_t mStatus;
Mathias Agopian3f844832013-08-07 21:24:32 -070096 public:
97 BindImageAsFramebuffer(RenderEngine& engine, EGLImageKHR image);
98 ~BindImageAsFramebuffer();
99 int getStatus() const;
100 };
101
Chia-I Wu7f402902017-11-09 12:51:10 -0800102 bool setCurrentSurface(EGLSurface surface);
103 void resetCurrentSurface();
104
Mathias Agopian3f844832013-08-07 21:24:32 -0700105 // set-up
106 virtual void checkErrors() const;
Dan Stozac1879002014-05-22 15:59:05 -0700107 virtual void setViewportAndProjection(size_t vpw, size_t vph,
Riley Andrewsc3ebe662014-09-04 16:20:31 -0700108 Rect sourceCrop, size_t hwh, bool yswap, Transform::orientation_flags rotation) = 0;
chaviw13fdc492017-06-27 12:40:18 -0700109 virtual void setupLayerBlending(bool premultipliedAlpha, bool opaque,
110 bool disableTexture, const half4& color) = 0;
Courtney Goeltzenleuchter5d943892017-03-22 13:46:46 -0600111 virtual void setColorMode(android_color_mode mode) = 0;
112 virtual void setSourceDataSpace(android_dataspace source) = 0;
113 virtual void setWideColor(bool hasWideColor) = 0;
114 virtual bool usesWideColor() = 0;
Mathias Agopian49457ac2013-08-14 18:20:17 -0700115 virtual void setupLayerTexturing(const Texture& texture) = 0;
Mathias Agopian875d8e12013-06-07 15:35:48 -0700116 virtual void setupLayerBlackedOut() = 0;
Mathias Agopian19733a32013-08-28 18:13:56 -0700117 virtual void setupFillWithColor(float r, float g, float b, float a) = 0;
Mathias Agopian875d8e12013-06-07 15:35:48 -0700118
Dan Stozaf0087992014-10-20 15:46:09 -0700119 virtual mat4 setupColorTransform(const mat4& /* colorTransform */) {
120 return mat4();
121 }
122
Mathias Agopian875d8e12013-06-07 15:35:48 -0700123 virtual void disableTexturing() = 0;
124 virtual void disableBlending() = 0;
125
Mathias Agopian3f844832013-08-07 21:24:32 -0700126 // drawing
Mathias Agopian3f844832013-08-07 21:24:32 -0700127 virtual void drawMesh(const Mesh& mesh) = 0;
Mathias Agopian875d8e12013-06-07 15:35:48 -0700128
Mathias Agopian3f844832013-08-07 21:24:32 -0700129 // queries
Mathias Agopian875d8e12013-06-07 15:35:48 -0700130 virtual size_t getMaxTextureSize() const = 0;
131 virtual size_t getMaxViewportDims() const = 0;
132
Chia-I Wu2b6386e2017-11-09 13:03:17 -0800133 EGLDisplay getEGLDisplay() const;
Jesse Hall05f8c702013-12-23 20:44:38 -0800134 EGLConfig getEGLConfig() const;
Mathias Agopian875d8e12013-06-07 15:35:48 -0700135 EGLContext getEGLContext() const;
136};
137
138// ---------------------------------------------------------------------------
139}; // namespace android
140// ---------------------------------------------------------------------------
141
142#endif /* SF_RENDERENGINE_H_ */