blob: e033cf2c5046bd1d660635b956510051d7e05015 [file] [log] [blame]
John Reck3b202512014-06-23 13:13:08 -07001/*
2 * Copyright (C) 2014 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#ifndef RENDERSTATE_H
17#define RENDERSTATE_H
18
John Reck3b202512014-06-23 13:13:08 -070019#include "Caches.h"
Chris Craik6c15ffa2015-02-02 13:50:55 -080020#include "Glop.h"
Chris Craik5854b342015-10-26 15:49:56 -070021#include "renderstate/Blend.h"
Chris Craik96a5c4c2015-01-27 15:46:35 -080022#include "renderstate/MeshState.h"
Chris Craik9fded232015-11-11 16:42:34 -080023#include "renderstate/OffscreenBufferPool.h"
Chris Craik96a5c4c2015-01-27 15:46:35 -080024#include "renderstate/PixelBufferState.h"
25#include "renderstate/Scissor.h"
26#include "renderstate/Stencil.h"
John Reck3b202512014-06-23 13:13:08 -070027#include "utils/Macros.h"
28
Chris Craik5854b342015-10-26 15:49:56 -070029#include <GLES2/gl2.h>
30#include <GLES2/gl2ext.h>
Chris Craik5854b342015-10-26 15:49:56 -070031#include <private/hwui/DrawGlInfo.h>
John Reck1bcacfd2017-11-03 10:12:19 -070032#include <ui/Region.h>
33#include <utils/Functor.h>
34#include <utils/Mutex.h>
35#include <utils/RefBase.h>
36#include <set>
Chris Craik5854b342015-10-26 15:49:56 -070037
Greg Daniel45ec62b2017-01-04 14:27:00 -050038class GrContext;
39
John Reck3b202512014-06-23 13:13:08 -070040namespace android {
41namespace uirenderer {
42
Tom Hudson2dc236b2014-10-15 15:46:42 -040043class Caches;
44class Layer;
sergeyv3e9999b2017-01-19 15:37:02 -080045class DeferredLayerUpdater;
Tom Hudson2dc236b2014-10-15 15:46:42 -040046
John Reck3b202512014-06-23 13:13:08 -070047namespace renderthread {
Derek Sollenbergerf9e45d12017-06-01 13:07:39 -040048class CacheManager;
John Reck443a7142014-09-04 17:40:05 -070049class CanvasContext;
John Reck3b202512014-06-23 13:13:08 -070050class RenderThread;
51}
52
53// TODO: Replace Cache's GL state tracking with this. For now it's more a thin
54// wrapper of Caches for users to migrate to.
55class RenderState {
56 PREVENT_COPY_AND_ASSIGN(RenderState);
Chris Craik5854b342015-10-26 15:49:56 -070057 friend class renderthread::RenderThread;
58 friend class Caches;
Derek Sollenbergerf9e45d12017-06-01 13:07:39 -040059 friend class renderthread::CacheManager;
John Reck1bcacfd2017-11-03 10:12:19 -070060
John Reck3b202512014-06-23 13:13:08 -070061public:
62 void onGLContextCreated();
Chris Craik1d477422014-08-26 17:30:15 -070063 void onGLContextDestroyed();
John Reck3b202512014-06-23 13:13:08 -070064
Greg Daniel45ec62b2017-01-04 14:27:00 -050065 void onVkContextCreated();
66 void onVkContextDestroyed();
67
Chris Craik9fded232015-11-11 16:42:34 -080068 void flush(Caches::FlushMode flushMode);
John Reck9a814872017-05-22 15:04:21 -070069 void onBitmapDestroyed(uint32_t pixelRefId);
Chris Craik9fded232015-11-11 16:42:34 -080070
John Reck3b202512014-06-23 13:13:08 -070071 void setViewport(GLsizei width, GLsizei height);
72 void getViewport(GLsizei* outWidth, GLsizei* outHeight);
73
74 void bindFramebuffer(GLuint fbo);
Chris Craik818c9fb2015-10-23 14:33:42 -070075 GLuint getFramebuffer() { return mFramebuffer; }
John Reck0b8d0672016-01-29 14:18:22 -080076 GLuint createFramebuffer();
Chris Craik818c9fb2015-10-23 14:33:42 -070077 void deleteFramebuffer(GLuint fbo);
78
John Reck3b202512014-06-23 13:13:08 -070079 void invokeFunctor(Functor* functor, DrawGlInfo::Mode mode, DrawGlInfo* info);
80
81 void debugOverdraw(bool enable, bool clear);
82
John Reck1bcacfd2017-11-03 10:12:19 -070083 void registerLayer(Layer* layer) { mActiveLayers.insert(layer); }
84 void unregisterLayer(Layer* layer) { mActiveLayers.erase(layer); }
Chris Craik1d477422014-08-26 17:30:15 -070085
John Reck443a7142014-09-04 17:40:05 -070086 void registerCanvasContext(renderthread::CanvasContext* context) {
87 mRegisteredContexts.insert(context);
88 }
89
90 void unregisterCanvasContext(renderthread::CanvasContext* context) {
91 mRegisteredContexts.erase(context);
92 }
93
sergeyv3e9999b2017-01-19 15:37:02 -080094 void registerDeferredLayerUpdater(DeferredLayerUpdater* layerUpdater) {
95 mActiveLayerUpdaters.insert(layerUpdater);
96 }
97
98 void unregisterDeferredLayerUpdater(DeferredLayerUpdater* layerUpdater) {
99 mActiveLayerUpdaters.erase(layerUpdater);
100 }
101
John Reck0e89e2b2014-10-31 14:49:06 -0700102 // TODO: This system is a little clunky feeling, this could use some
103 // more thinking...
104 void postDecStrong(VirtualLightRefBase* object);
105
Arun530a2b42017-01-23 12:47:57 +0000106 void render(const Glop& glop, const Matrix4& orthoMatrix, bool overrideDisableBlending);
Chris Craik6c15ffa2015-02-02 13:50:55 -0800107
Chris Craik44eb2c02015-01-29 09:45:09 -0800108 Blend& blend() { return *mBlend; }
Chris Craik96a5c4c2015-01-27 15:46:35 -0800109 MeshState& meshState() { return *mMeshState; }
110 Scissor& scissor() { return *mScissor; }
111 Stencil& stencil() { return *mStencil; }
Chris Craik117bdbc2015-02-05 10:12:38 -0800112
John Reck642ebea2017-07-17 09:55:02 -0700113 OffscreenBufferPool& layerPool() { return *mLayerPool; }
Chris Craik9fded232015-11-11 16:42:34 -0800114
Greg Daniel45ec62b2017-01-04 14:27:00 -0500115 GrContext* getGrContext() const;
116
Chris Craik117bdbc2015-02-05 10:12:38 -0800117 void dump();
John Reck3b202512014-06-23 13:13:08 -0700118
Chris Craik5854b342015-10-26 15:49:56 -0700119private:
John Reck3b202512014-06-23 13:13:08 -0700120 void interruptForFunctorInvoke();
121 void resumeFromFunctorInvoke();
sergeyvc3f13162017-02-06 11:45:14 -0800122 void destroyLayersInUpdater();
John Reck3b202512014-06-23 13:13:08 -0700123
Chih-Hung Hsieh49796452016-08-10 14:08:35 -0700124 explicit RenderState(renderthread::RenderThread& thread);
John Reck3b202512014-06-23 13:13:08 -0700125 ~RenderState();
126
John Reck0e89e2b2014-10-31 14:49:06 -0700127 renderthread::RenderThread& mRenderThread;
Chris Craik44eb2c02015-01-29 09:45:09 -0800128 Caches* mCaches = nullptr;
Chris Craik96a5c4c2015-01-27 15:46:35 -0800129
Chris Craik44eb2c02015-01-29 09:45:09 -0800130 Blend* mBlend = nullptr;
131 MeshState* mMeshState = nullptr;
132 Scissor* mScissor = nullptr;
133 Stencil* mStencil = nullptr;
Chris Craik96a5c4c2015-01-27 15:46:35 -0800134
John Reck642ebea2017-07-17 09:55:02 -0700135 OffscreenBufferPool* mLayerPool = nullptr;
Chris Craik9fded232015-11-11 16:42:34 -0800136
John Reck49bc4ac2015-01-29 12:53:38 -0800137 std::set<Layer*> mActiveLayers;
sergeyv3e9999b2017-01-19 15:37:02 -0800138 std::set<DeferredLayerUpdater*> mActiveLayerUpdaters;
John Reck443a7142014-09-04 17:40:05 -0700139 std::set<renderthread::CanvasContext*> mRegisteredContexts;
John Reck3b202512014-06-23 13:13:08 -0700140
141 GLsizei mViewportWidth;
142 GLsizei mViewportHeight;
143 GLuint mFramebuffer;
John Reck0e89e2b2014-10-31 14:49:06 -0700144
145 pthread_t mThreadId;
John Reck3b202512014-06-23 13:13:08 -0700146};
147
148} /* namespace uirenderer */
149} /* namespace android */
150
151#endif /* RENDERSTATE_H */