blob: 3847347773c431b911c874329648e903aff57279 [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>
chaviw13fdc492017-06-27 12:40:18 -070028#include <gui/SurfaceControl.h>
Chia-I Wub027f802017-11-29 14:00:52 -080029#include <math/mat4.h>
Mathias Agopian875d8e12013-06-07 15:35:48 -070030
Jesse Hall19e87292013-12-23 21:02:15 -080031#define EGL_NO_CONFIG ((EGLConfig)0)
32
Chia-I Wueadbaa62017-11-09 11:26:15 -080033struct ANativeWindowBuffer;
34
Mathias Agopian875d8e12013-06-07 15:35:48 -070035// ---------------------------------------------------------------------------
36namespace android {
37// ---------------------------------------------------------------------------
38
39class String8;
Mathias Agopian3f844832013-08-07 21:24:32 -070040class Rect;
41class Region;
42class Mesh;
Mathias Agopian49457ac2013-08-14 18:20:17 -070043class Texture;
Mathias Agopian875d8e12013-06-07 15:35:48 -070044
Chia-I Wuf846a352017-11-10 09:22:52 -080045namespace RE {
46class Surface;
47}
48
Mathias Agopian875d8e12013-06-07 15:35:48 -070049class RenderEngine {
50 enum GlesVersion {
Chia-I Wub027f802017-11-29 14:00:52 -080051 GLES_VERSION_1_0 = 0x10000,
52 GLES_VERSION_1_1 = 0x10001,
53 GLES_VERSION_2_0 = 0x20000,
54 GLES_VERSION_3_0 = 0x30000,
Mathias Agopian875d8e12013-06-07 15:35:48 -070055 };
56 static GlesVersion parseGlesVersion(const char* str);
57
Chia-I Wu2b6386e2017-11-09 13:03:17 -080058 EGLDisplay mEGLDisplay;
Jesse Hall05f8c702013-12-23 20:44:38 -080059 EGLConfig mEGLConfig;
Mathias Agopian875d8e12013-06-07 15:35:48 -070060 EGLContext mEGLContext;
Chia-I Wu2b6386e2017-11-09 13:03:17 -080061 void setEGLHandles(EGLDisplay display, EGLConfig config, EGLContext ctxt);
Mathias Agopian875d8e12013-06-07 15:35:48 -070062
Chia-I Wub027f802017-11-29 14:00:52 -080063 virtual void bindImageAsFramebuffer(EGLImageKHR image, uint32_t* texName, uint32_t* fbName,
64 uint32_t* status) = 0;
Mathias Agopian458197d2013-08-15 14:56:51 -070065 virtual void unbindFramebuffer(uint32_t texName, uint32_t fbName) = 0;
66
Mathias Agopian875d8e12013-06-07 15:35:48 -070067protected:
68 RenderEngine();
Mathias Agopian875d8e12013-06-07 15:35:48 -070069
70public:
Chia-I Wub2c76242017-11-09 17:17:07 -080071 virtual ~RenderEngine() = 0;
72
Kalle Raitabbdcf1f2017-05-22 15:47:46 -070073 enum FeatureFlag {
74 WIDE_COLOR_SUPPORT = 1 << 0 // Platform has a wide color display
75 };
Chia-I Wud4d9c6f2017-11-09 16:55:31 -080076 static std::unique_ptr<RenderEngine> create(int hwcFormat, uint32_t featureFlags);
Jesse Hall05f8c702013-12-23 20:44:38 -080077
Steven Thomas94e35b92017-07-26 18:48:28 -070078 static EGLConfig chooseEglConfig(EGLDisplay display, int format, bool logConfig);
Mathias Agopian875d8e12013-06-07 15:35:48 -070079
Dan Stoza4e637772016-07-28 13:31:51 -070080 void primeCache() const;
81
Mathias Agopian458197d2013-08-15 14:56:51 -070082 // dump the extension strings. always call the base class.
83 virtual void dump(String8& result);
84
Mathias Agopian3f844832013-08-07 21:24:32 -070085 // helpers
Chia-I Wub0c041b2017-11-09 11:36:33 -080086 // flush returns -1 or a valid native fence fd owned by the caller
87 int flush(bool wait);
Mathias Agopian3f844832013-08-07 21:24:32 -070088 void clearWithColor(float red, float green, float blue, float alpha);
Chia-I Wub027f802017-11-29 14:00:52 -080089 void fillRegionWithColor(const Region& region, uint32_t height, float red, float green,
90 float blue, float alpha);
Mathias Agopian875d8e12013-06-07 15:35:48 -070091
Mathias Agopian3f844832013-08-07 21:24:32 -070092 // common to all GL versions
93 void setScissor(uint32_t left, uint32_t bottom, uint32_t right, uint32_t top);
94 void disableScissor();
95 void genTextures(size_t count, uint32_t* names);
96 void deleteTextures(size_t count, uint32_t const* names);
Mathias Agopiand5556842013-09-19 17:08:37 -070097 void readPixels(size_t l, size_t b, size_t w, size_t h, uint32_t* pixels);
Mathias Agopian3f844832013-08-07 21:24:32 -070098
Chia-I Wueadbaa62017-11-09 11:26:15 -080099 class BindNativeBufferAsFramebuffer {
Mathias Agopian3f844832013-08-07 21:24:32 -0700100 RenderEngine& mEngine;
Chia-I Wueadbaa62017-11-09 11:26:15 -0800101 EGLImageKHR mImage;
Mathias Agopian458197d2013-08-15 14:56:51 -0700102 uint32_t mTexName, mFbName;
103 uint32_t mStatus;
Chia-I Wub027f802017-11-29 14:00:52 -0800104
Mathias Agopian3f844832013-08-07 21:24:32 -0700105 public:
Chia-I Wueadbaa62017-11-09 11:26:15 -0800106 BindNativeBufferAsFramebuffer(RenderEngine& engine, ANativeWindowBuffer* buffer);
107 ~BindNativeBufferAsFramebuffer();
Mathias Agopian3f844832013-08-07 21:24:32 -0700108 int getStatus() const;
109 };
110
Chia-I Wuf846a352017-11-10 09:22:52 -0800111 bool setCurrentSurface(const RE::Surface& surface);
Chia-I Wu7f402902017-11-09 12:51:10 -0800112 void resetCurrentSurface();
113
Mathias Agopian3f844832013-08-07 21:24:32 -0700114 // set-up
115 virtual void checkErrors() const;
Chia-I Wub027f802017-11-29 14:00:52 -0800116 virtual void setViewportAndProjection(size_t vpw, size_t vph, Rect sourceCrop, size_t hwh,
117 bool yswap, Transform::orientation_flags rotation) = 0;
118 virtual void setupLayerBlending(bool premultipliedAlpha, bool opaque, bool disableTexture,
119 const half4& color) = 0;
Courtney Goeltzenleuchter5d943892017-03-22 13:46:46 -0600120 virtual void setColorMode(android_color_mode mode) = 0;
121 virtual void setSourceDataSpace(android_dataspace source) = 0;
122 virtual void setWideColor(bool hasWideColor) = 0;
123 virtual bool usesWideColor() = 0;
Mathias Agopian49457ac2013-08-14 18:20:17 -0700124 virtual void setupLayerTexturing(const Texture& texture) = 0;
Mathias Agopian875d8e12013-06-07 15:35:48 -0700125 virtual void setupLayerBlackedOut() = 0;
Mathias Agopian19733a32013-08-28 18:13:56 -0700126 virtual void setupFillWithColor(float r, float g, float b, float a) = 0;
Mathias Agopian875d8e12013-06-07 15:35:48 -0700127
Chia-I Wub027f802017-11-29 14:00:52 -0800128 virtual mat4 setupColorTransform(const mat4& /* colorTransform */) { return mat4(); }
Dan Stozaf0087992014-10-20 15:46:09 -0700129
Mathias Agopian875d8e12013-06-07 15:35:48 -0700130 virtual void disableTexturing() = 0;
131 virtual void disableBlending() = 0;
132
Mathias Agopian3f844832013-08-07 21:24:32 -0700133 // drawing
Mathias Agopian3f844832013-08-07 21:24:32 -0700134 virtual void drawMesh(const Mesh& mesh) = 0;
Mathias Agopian875d8e12013-06-07 15:35:48 -0700135
Mathias Agopian3f844832013-08-07 21:24:32 -0700136 // queries
Mathias Agopian875d8e12013-06-07 15:35:48 -0700137 virtual size_t getMaxTextureSize() const = 0;
138 virtual size_t getMaxViewportDims() const = 0;
139
Chia-I Wuf846a352017-11-10 09:22:52 -0800140 // internal to RenderEngine
Chia-I Wu2b6386e2017-11-09 13:03:17 -0800141 EGLDisplay getEGLDisplay() const;
Jesse Hall05f8c702013-12-23 20:44:38 -0800142 EGLConfig getEGLConfig() const;
Mathias Agopian875d8e12013-06-07 15:35:48 -0700143};
144
145// ---------------------------------------------------------------------------
146}; // namespace android
147// ---------------------------------------------------------------------------
148
149#endif /* SF_RENDERENGINE_H_ */