blob: f8869197b1d9effe78c39ba31fae091ac023eea3 [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
Mathias Agopian875d8e12013-06-07 15:35:48 -070017#ifndef SF_RENDERENGINE_H_
18#define SF_RENDERENGINE_H_
19
Chia-I Wub2c76242017-11-09 17:17:07 -080020#include <memory>
21
Mathias Agopian875d8e12013-06-07 15:35:48 -070022#include <stdint.h>
23#include <sys/types.h>
24
25#include <EGL/egl.h>
Mathias Agopian3f844832013-08-07 21:24:32 -070026#include <EGL/eglext.h>
Riley Andrewsc3ebe662014-09-04 16:20:31 -070027#include <Transform.h>
Chia-I Wu767fcf72017-11-30 22:07:38 -080028#include <android-base/unique_fd.h>
chaviw13fdc492017-06-27 12:40:18 -070029#include <gui/SurfaceControl.h>
Chia-I Wub027f802017-11-29 14:00:52 -080030#include <math/mat4.h>
Mathias Agopian875d8e12013-06-07 15:35:48 -070031
Jesse Hall19e87292013-12-23 21:02:15 -080032#define EGL_NO_CONFIG ((EGLConfig)0)
33
Chia-I Wueadbaa62017-11-09 11:26:15 -080034struct ANativeWindowBuffer;
35
Mathias Agopian875d8e12013-06-07 15:35:48 -070036// ---------------------------------------------------------------------------
37namespace android {
38// ---------------------------------------------------------------------------
39
40class String8;
Mathias Agopian3f844832013-08-07 21:24:32 -070041class Rect;
42class Region;
43class Mesh;
Mathias Agopian49457ac2013-08-14 18:20:17 -070044class Texture;
Mathias Agopian875d8e12013-06-07 15:35:48 -070045
Chia-I Wuf846a352017-11-10 09:22:52 -080046namespace RE {
Chia-I Wu401ef832017-12-01 10:52:22 -080047class Image;
Chia-I Wuf846a352017-11-10 09:22:52 -080048class Surface;
Chia-I Wu401ef832017-12-01 10:52:22 -080049} // namespace RE
Chia-I Wuf846a352017-11-10 09:22:52 -080050
Mathias Agopian875d8e12013-06-07 15:35:48 -070051class RenderEngine {
52 enum GlesVersion {
Chia-I Wub027f802017-11-29 14:00:52 -080053 GLES_VERSION_1_0 = 0x10000,
54 GLES_VERSION_1_1 = 0x10001,
55 GLES_VERSION_2_0 = 0x20000,
56 GLES_VERSION_3_0 = 0x30000,
Mathias Agopian875d8e12013-06-07 15:35:48 -070057 };
58 static GlesVersion parseGlesVersion(const char* str);
59
Chia-I Wu2b6386e2017-11-09 13:03:17 -080060 EGLDisplay mEGLDisplay;
Jesse Hall05f8c702013-12-23 20:44:38 -080061 EGLConfig mEGLConfig;
Mathias Agopian875d8e12013-06-07 15:35:48 -070062 EGLContext mEGLContext;
Chia-I Wu2b6386e2017-11-09 13:03:17 -080063 void setEGLHandles(EGLDisplay display, EGLConfig config, EGLContext ctxt);
Mathias Agopian875d8e12013-06-07 15:35:48 -070064
Chia-I Wub027f802017-11-29 14:00:52 -080065 virtual void bindImageAsFramebuffer(EGLImageKHR image, uint32_t* texName, uint32_t* fbName,
66 uint32_t* status) = 0;
Mathias Agopian458197d2013-08-15 14:56:51 -070067 virtual void unbindFramebuffer(uint32_t texName, uint32_t fbName) = 0;
68
Mathias Agopian875d8e12013-06-07 15:35:48 -070069protected:
70 RenderEngine();
Mathias Agopian875d8e12013-06-07 15:35:48 -070071
72public:
Chia-I Wub2c76242017-11-09 17:17:07 -080073 virtual ~RenderEngine() = 0;
74
Kalle Raitabbdcf1f2017-05-22 15:47:46 -070075 enum FeatureFlag {
76 WIDE_COLOR_SUPPORT = 1 << 0 // Platform has a wide color display
77 };
Chia-I Wud4d9c6f2017-11-09 16:55:31 -080078 static std::unique_ptr<RenderEngine> create(int hwcFormat, uint32_t featureFlags);
Jesse Hall05f8c702013-12-23 20:44:38 -080079
Steven Thomas94e35b92017-07-26 18:48:28 -070080 static EGLConfig chooseEglConfig(EGLDisplay display, int format, bool logConfig);
Mathias Agopian875d8e12013-06-07 15:35:48 -070081
Dan Stoza4e637772016-07-28 13:31:51 -070082 void primeCache() const;
83
Mathias Agopian458197d2013-08-15 14:56:51 -070084 // dump the extension strings. always call the base class.
85 virtual void dump(String8& result);
86
Chia-I Wu401ef832017-12-01 10:52:22 -080087 bool supportsImageCrop() const;
88
Chia-I Wu9f2db772017-11-30 21:06:50 -080089 bool isCurrent() const;
90 bool setCurrentSurface(const RE::Surface& surface);
91 void resetCurrentSurface();
92
Chia-I Wu767fcf72017-11-30 22:07:38 -080093 // synchronization
94
95 // flush submits RenderEngine command stream for execution and returns a
96 // native fence fd that is signaled when the execution has completed. It
97 // returns -1 on errors.
98 base::unique_fd flush();
99 // finish waits until RenderEngine command stream has been executed. It
100 // returns false on errors.
101 bool finish();
102 // waitFence inserts a wait on an external fence fd to RenderEngine
103 // command stream. It returns false on errors.
104 bool waitFence(base::unique_fd fenceFd);
105
Mathias Agopian3f844832013-08-07 21:24:32 -0700106 // helpers
107 void clearWithColor(float red, float green, float blue, float alpha);
Chia-I Wub027f802017-11-29 14:00:52 -0800108 void fillRegionWithColor(const Region& region, uint32_t height, float red, float green,
109 float blue, float alpha);
Mathias Agopian875d8e12013-06-07 15:35:48 -0700110
Mathias Agopian3f844832013-08-07 21:24:32 -0700111 // common to all GL versions
112 void setScissor(uint32_t left, uint32_t bottom, uint32_t right, uint32_t top);
113 void disableScissor();
114 void genTextures(size_t count, uint32_t* names);
115 void deleteTextures(size_t count, uint32_t const* names);
Chia-I Wu401ef832017-12-01 10:52:22 -0800116 void bindExternalTextureImage(uint32_t texName, const RE::Image& image);
Mathias Agopiand5556842013-09-19 17:08:37 -0700117 void readPixels(size_t l, size_t b, size_t w, size_t h, uint32_t* pixels);
Mathias Agopian3f844832013-08-07 21:24:32 -0700118
Chia-I Wueadbaa62017-11-09 11:26:15 -0800119 class BindNativeBufferAsFramebuffer {
Mathias Agopian3f844832013-08-07 21:24:32 -0700120 RenderEngine& mEngine;
Chia-I Wueadbaa62017-11-09 11:26:15 -0800121 EGLImageKHR mImage;
Mathias Agopian458197d2013-08-15 14:56:51 -0700122 uint32_t mTexName, mFbName;
123 uint32_t mStatus;
Chia-I Wub027f802017-11-29 14:00:52 -0800124
Mathias Agopian3f844832013-08-07 21:24:32 -0700125 public:
Chia-I Wueadbaa62017-11-09 11:26:15 -0800126 BindNativeBufferAsFramebuffer(RenderEngine& engine, ANativeWindowBuffer* buffer);
127 ~BindNativeBufferAsFramebuffer();
Mathias Agopian3f844832013-08-07 21:24:32 -0700128 int getStatus() const;
129 };
130
131 // set-up
132 virtual void checkErrors() const;
Chia-I Wub027f802017-11-29 14:00:52 -0800133 virtual void setViewportAndProjection(size_t vpw, size_t vph, Rect sourceCrop, size_t hwh,
134 bool yswap, Transform::orientation_flags rotation) = 0;
135 virtual void setupLayerBlending(bool premultipliedAlpha, bool opaque, bool disableTexture,
136 const half4& color) = 0;
Courtney Goeltzenleuchter5d943892017-03-22 13:46:46 -0600137 virtual void setColorMode(android_color_mode mode) = 0;
138 virtual void setSourceDataSpace(android_dataspace source) = 0;
139 virtual void setWideColor(bool hasWideColor) = 0;
140 virtual bool usesWideColor() = 0;
Mathias Agopian49457ac2013-08-14 18:20:17 -0700141 virtual void setupLayerTexturing(const Texture& texture) = 0;
Mathias Agopian875d8e12013-06-07 15:35:48 -0700142 virtual void setupLayerBlackedOut() = 0;
Mathias Agopian19733a32013-08-28 18:13:56 -0700143 virtual void setupFillWithColor(float r, float g, float b, float a) = 0;
Mathias Agopian875d8e12013-06-07 15:35:48 -0700144
Chia-I Wub027f802017-11-29 14:00:52 -0800145 virtual mat4 setupColorTransform(const mat4& /* colorTransform */) { return mat4(); }
Dan Stozaf0087992014-10-20 15:46:09 -0700146
Mathias Agopian875d8e12013-06-07 15:35:48 -0700147 virtual void disableTexturing() = 0;
148 virtual void disableBlending() = 0;
149
Mathias Agopian3f844832013-08-07 21:24:32 -0700150 // drawing
Mathias Agopian3f844832013-08-07 21:24:32 -0700151 virtual void drawMesh(const Mesh& mesh) = 0;
Mathias Agopian875d8e12013-06-07 15:35:48 -0700152
Mathias Agopian3f844832013-08-07 21:24:32 -0700153 // queries
Mathias Agopian875d8e12013-06-07 15:35:48 -0700154 virtual size_t getMaxTextureSize() const = 0;
155 virtual size_t getMaxViewportDims() const = 0;
156
Chia-I Wuf846a352017-11-10 09:22:52 -0800157 // internal to RenderEngine
Chia-I Wu2b6386e2017-11-09 13:03:17 -0800158 EGLDisplay getEGLDisplay() const;
Jesse Hall05f8c702013-12-23 20:44:38 -0800159 EGLConfig getEGLConfig() const;
Mathias Agopian875d8e12013-06-07 15:35:48 -0700160};
161
162// ---------------------------------------------------------------------------
163}; // namespace android
164// ---------------------------------------------------------------------------
165
166#endif /* SF_RENDERENGINE_H_ */