blob: 642f9dc50eb1a5433494eb86442d82f6dd0d7fd7 [file] [log] [blame]
Romain Guyfb8b7632010-08-23 21:05:08 -07001/*
2 * Copyright (C) 2010 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
Chris Craik5e00c7c2016-07-06 16:10:09 -070017#pragma once
Romain Guyfb8b7632010-08-23 21:05:08 -070018
John Reck8dc02f92017-07-17 09:55:02 -070019#include "DeviceInfo.h"
Chris Craik96a5c4c2015-01-27 15:46:35 -080020#include "Extensions.h"
Chris Craik96a5c4c2015-01-27 15:46:35 -080021#include "ResourceCache.h"
John Reck1bcacfd2017-11-03 10:12:19 -070022#include "renderstate/PixelBufferState.h"
23#include "renderstate/TextureState.h"
Chris Craik96a5c4c2015-01-27 15:46:35 -080024#include "thread/TaskManager.h"
John Reck1bcacfd2017-11-03 10:12:19 -070025#include "thread/TaskProcessor.h"
Chris Craik96a5c4c2015-01-27 15:46:35 -080026
Chris Craik96a5c4c2015-01-27 15:46:35 -080027#include <memory>
John Reck1bcacfd2017-11-03 10:12:19 -070028#include <vector>
Chris Craik59744b72014-07-01 17:56:52 -070029
Romain Guy3b748a42013-04-17 18:54:38 -070030#include <GLES3/gl3.h>
31
32#include <utils/KeyedVector.h>
Romain Guyfb8b7632010-08-23 21:05:08 -070033
Romain Guy79537452011-10-12 13:48:51 -070034#include <cutils/compiler.h>
35
Tom Hudson2dc236b2014-10-15 15:46:42 -040036#include <SkPath.h>
37
John Reck272a6852015-07-29 16:48:58 -070038#include <vector>
39
Romain Guyfb8b7632010-08-23 21:05:08 -070040namespace android {
41namespace uirenderer {
42
Romain Guy03750a02010-10-18 14:06:08 -070043///////////////////////////////////////////////////////////////////////////////
Romain Guy03750a02010-10-18 14:06:08 -070044// Caches
45///////////////////////////////////////////////////////////////////////////////
46
John Recke18264b2014-03-12 13:56:30 -070047class RenderNode;
John Reck17035b02014-09-03 07:39:53 -070048class RenderState;
Romain Guybb0acdf2012-03-05 13:44:35 -080049
Chris Craik96a5c4c2015-01-27 15:46:35 -080050class ANDROID_API Caches {
51public:
52 static Caches& createInstance(RenderState& renderState) {
53 LOG_ALWAYS_FATAL_IF(sInstance, "double create of Caches attempted");
54 sInstance = new Caches(renderState);
55 return *sInstance;
56 }
Romain Guyfb8b7632010-08-23 21:05:08 -070057
Chris Craik96a5c4c2015-01-27 15:46:35 -080058 static Caches& getInstance() {
59 LOG_ALWAYS_FATAL_IF(!sInstance, "instance not yet created");
60 return *sInstance;
61 }
Romain Guyfb8b7632010-08-23 21:05:08 -070062
John Reck1bcacfd2017-11-03 10:12:19 -070063 static bool hasInstance() { return sInstance != nullptr; }
64
Chris Craik96a5c4c2015-01-27 15:46:35 -080065private:
Chih-Hung Hsiehfaecb782016-07-21 11:23:06 -070066 explicit Caches(RenderState& renderState);
Chris Craik96a5c4c2015-01-27 15:46:35 -080067 static Caches* sInstance;
Romain Guy9bca4792010-10-25 18:42:25 -070068
Romain Guyfb8b7632010-08-23 21:05:08 -070069public:
John Reck1bcacfd2017-11-03 10:12:19 -070070 enum class FlushMode { Layers = 0, Moderate, Full };
Romain Guybdf76092011-07-18 15:00:43 -070071
72 /**
Romain Guydfa10462012-05-12 16:18:58 -070073 * Initialize caches.
Romain Guy8ff6b9e2011-11-09 20:10:18 -080074 */
Romain Guy3b748a42013-04-17 18:54:38 -070075 bool init();
Romain Guy8ff6b9e2011-11-09 20:10:18 -080076
John Reckdb009172016-03-17 11:02:07 -070077 bool isInitialized() { return mInitialized; }
78
Romain Guy8ff6b9e2011-11-09 20:10:18 -080079 /**
Romain Guybdf76092011-07-18 15:00:43 -070080 * Flush the cache.
81 *
82 * @param mode Indicates how much of the cache should be flushed
83 */
84 void flush(FlushMode mode);
85
Romain Guy5b3b3522010-10-27 18:57:51 -070086 /**
Romain Guy8ff6b9e2011-11-09 20:10:18 -080087 * Destroys all resources associated with this cache. This should
Chris Craikb9ce116d2015-08-20 15:14:06 -070088 * be called after a flush(FlushMode::Full).
Romain Guy8ff6b9e2011-11-09 20:10:18 -080089 */
90 void terminate();
91
92 /**
Romain Guyfe48f652010-11-11 15:36:56 -080093 * Call this on each frame to ensure that garbage is deleted from
94 * GPU memory.
95 */
96 void clearGarbage();
97
98 /**
Romain Guy253f2c22016-09-28 17:34:42 -070099 * Returns the GL RGBA internal format to use for the current device
100 * If the device supports linear blending and needSRGB is true,
101 * this function returns GL_SRGB8_ALPHA8, otherwise it returns GL_RGBA
102 */
103 constexpr GLint rgbaInternalFormat(bool needSRGB = true) const {
Romain Guyefb4b062017-02-27 11:00:04 -0800104 return extensions().hasLinearBlending() && needSRGB ? GL_SRGB8_ALPHA8 : GL_RGBA;
Romain Guy253f2c22016-09-28 17:34:42 -0700105 }
106
Chris Craik117bdbc2015-02-05 10:12:38 -0800107public:
Romain Guy5dc7fa72013-03-11 20:48:31 -0700108 TaskManager tasks;
109
Romain Guyf9f00162013-05-09 11:50:12 -0700110 bool gpuPixelBuffersEnabled;
111
John Reck8dc02f92017-07-17 09:55:02 -0700112 const Extensions& extensions() const { return DeviceInfo::get()->extensions(); }
Chris Craik44eb2c02015-01-29 09:45:09 -0800113 PixelBufferState& pixelBufferState() { return *mPixelBufferState; }
114 TextureState& textureState() { return *mTextureState; }
Chris Craik96a5c4c2015-01-27 15:46:35 -0800115
Romain Guye190aa62010-11-10 19:01:29 -0800116private:
Romain Guyf9f00162013-05-09 11:50:12 -0700117 void initStaticProperties();
Romain Guydfa10462012-05-12 16:18:58 -0700118
John Reck1bcacfd2017-11-03 10:12:19 -0700119 static void eventMarkNull(GLsizei length, const GLchar* marker) {}
120 static void startMarkNull(GLsizei length, const GLchar* marker) {}
121 static void endMarkNull() {}
Romain Guy13631f32012-01-30 17:41:55 -0800122
Romain Guyf3a910b42011-12-12 20:35:21 -0800123 // Used to render layers
Chris Craik51d6a3d2014-12-22 17:16:56 -0800124 std::unique_ptr<TextureVertex[]> mRegionMesh;
Romain Guy3b748a42013-04-17 18:54:38 -0700125
Romain Guy8ff6b9e2011-11-09 20:10:18 -0800126 bool mInitialized;
Romain Guy54c1a642012-09-27 17:55:46 -0700127
Chris Craik6c15ffa2015-02-02 13:50:55 -0800128 // TODO: move below to RenderState
129 PixelBufferState* mPixelBufferState = nullptr;
130 TextureState* mTextureState = nullptr;
Chris Craik6c15ffa2015-02-02 13:50:55 -0800131
John Reck1bcacfd2017-11-03 10:12:19 -0700132}; // class Caches
Romain Guyfb8b7632010-08-23 21:05:08 -0700133
John Reck1bcacfd2017-11-03 10:12:19 -0700134}; // namespace uirenderer
135}; // namespace android