blob: 315fa2db68782de827d67189edf7d8dac8d3a84b [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 <set>
30#include <GLES2/gl2.h>
31#include <GLES2/gl2ext.h>
32#include <ui/Region.h>
33#include <utils/Mutex.h>
34#include <utils/Functor.h>
35#include <utils/RefBase.h>
36#include <private/hwui/DrawGlInfo.h>
37
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 Reck3b202512014-06-23 13:13:08 -070060public:
61 void onGLContextCreated();
Chris Craik1d477422014-08-26 17:30:15 -070062 void onGLContextDestroyed();
John Reck3b202512014-06-23 13:13:08 -070063
Greg Daniel45ec62b2017-01-04 14:27:00 -050064 void onVkContextCreated();
65 void onVkContextDestroyed();
66
Chris Craik9fded232015-11-11 16:42:34 -080067 void flush(Caches::FlushMode flushMode);
John Reck9a814872017-05-22 15:04:21 -070068 void onBitmapDestroyed(uint32_t pixelRefId);
Chris Craik9fded232015-11-11 16:42:34 -080069
John Reck3b202512014-06-23 13:13:08 -070070 void setViewport(GLsizei width, GLsizei height);
71 void getViewport(GLsizei* outWidth, GLsizei* outHeight);
72
73 void bindFramebuffer(GLuint fbo);
Chris Craik818c9fb2015-10-23 14:33:42 -070074 GLuint getFramebuffer() { return mFramebuffer; }
John Reck0b8d0672016-01-29 14:18:22 -080075 GLuint createFramebuffer();
Chris Craik818c9fb2015-10-23 14:33:42 -070076 void deleteFramebuffer(GLuint fbo);
77
John Reck3b202512014-06-23 13:13:08 -070078 void invokeFunctor(Functor* functor, DrawGlInfo::Mode mode, DrawGlInfo* info);
79
80 void debugOverdraw(bool enable, bool clear);
81
John Reck49bc4ac2015-01-29 12:53:38 -080082 void registerLayer(Layer* layer) {
Chris Craik1d477422014-08-26 17:30:15 -070083 mActiveLayers.insert(layer);
84 }
John Reck49bc4ac2015-01-29 12:53:38 -080085 void unregisterLayer(Layer* layer) {
Chris Craik1d477422014-08-26 17:30:15 -070086 mActiveLayers.erase(layer);
87 }
88
John Reck443a7142014-09-04 17:40:05 -070089 void registerCanvasContext(renderthread::CanvasContext* context) {
90 mRegisteredContexts.insert(context);
91 }
92
93 void unregisterCanvasContext(renderthread::CanvasContext* context) {
94 mRegisteredContexts.erase(context);
95 }
96
sergeyv3e9999b2017-01-19 15:37:02 -080097 void registerDeferredLayerUpdater(DeferredLayerUpdater* layerUpdater) {
98 mActiveLayerUpdaters.insert(layerUpdater);
99 }
100
101 void unregisterDeferredLayerUpdater(DeferredLayerUpdater* layerUpdater) {
102 mActiveLayerUpdaters.erase(layerUpdater);
103 }
104
John Reck0e89e2b2014-10-31 14:49:06 -0700105 // TODO: This system is a little clunky feeling, this could use some
106 // more thinking...
107 void postDecStrong(VirtualLightRefBase* object);
108
Arun530a2b42017-01-23 12:47:57 +0000109 void render(const Glop& glop, const Matrix4& orthoMatrix, bool overrideDisableBlending);
Chris Craik6c15ffa2015-02-02 13:50:55 -0800110
Chris Craik44eb2c02015-01-29 09:45:09 -0800111 Blend& blend() { return *mBlend; }
Chris Craik96a5c4c2015-01-27 15:46:35 -0800112 MeshState& meshState() { return *mMeshState; }
113 Scissor& scissor() { return *mScissor; }
114 Stencil& stencil() { return *mStencil; }
Chris Craik117bdbc2015-02-05 10:12:38 -0800115
John Reck642ebea2017-07-17 09:55:02 -0700116 OffscreenBufferPool& layerPool() { return *mLayerPool; }
Chris Craik9fded232015-11-11 16:42:34 -0800117
Greg Daniel45ec62b2017-01-04 14:27:00 -0500118 GrContext* getGrContext() const;
119
Chris Craik117bdbc2015-02-05 10:12:38 -0800120 void dump();
John Reck3b202512014-06-23 13:13:08 -0700121
Chris Craik5854b342015-10-26 15:49:56 -0700122private:
John Reck3b202512014-06-23 13:13:08 -0700123 void interruptForFunctorInvoke();
124 void resumeFromFunctorInvoke();
sergeyvc3f13162017-02-06 11:45:14 -0800125 void destroyLayersInUpdater();
John Reck3b202512014-06-23 13:13:08 -0700126
Chih-Hung Hsieh49796452016-08-10 14:08:35 -0700127 explicit RenderState(renderthread::RenderThread& thread);
John Reck3b202512014-06-23 13:13:08 -0700128 ~RenderState();
129
Chris Craik65fe5ee2015-01-26 18:06:29 -0800130
John Reck0e89e2b2014-10-31 14:49:06 -0700131 renderthread::RenderThread& mRenderThread;
Chris Craik44eb2c02015-01-29 09:45:09 -0800132 Caches* mCaches = nullptr;
Chris Craik96a5c4c2015-01-27 15:46:35 -0800133
Chris Craik44eb2c02015-01-29 09:45:09 -0800134 Blend* mBlend = nullptr;
135 MeshState* mMeshState = nullptr;
136 Scissor* mScissor = nullptr;
137 Stencil* mStencil = nullptr;
Chris Craik96a5c4c2015-01-27 15:46:35 -0800138
John Reck642ebea2017-07-17 09:55:02 -0700139 OffscreenBufferPool* mLayerPool = nullptr;
Chris Craik9fded232015-11-11 16:42:34 -0800140
John Reck49bc4ac2015-01-29 12:53:38 -0800141 std::set<Layer*> mActiveLayers;
sergeyv3e9999b2017-01-19 15:37:02 -0800142 std::set<DeferredLayerUpdater*> mActiveLayerUpdaters;
John Reck443a7142014-09-04 17:40:05 -0700143 std::set<renderthread::CanvasContext*> mRegisteredContexts;
John Reck3b202512014-06-23 13:13:08 -0700144
145 GLsizei mViewportWidth;
146 GLsizei mViewportHeight;
147 GLuint mFramebuffer;
John Reck0e89e2b2014-10-31 14:49:06 -0700148
149 pthread_t mThreadId;
John Reck3b202512014-06-23 13:13:08 -0700150};
151
152} /* namespace uirenderer */
153} /* namespace android */
154
155#endif /* RENDERSTATE_H */