blob: f78bf7a4e088c24cb17e5ed460f1df76e15ec5a3 [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 {
John Reck443a7142014-09-04 17:40:05 -070048class CanvasContext;
John Reck3b202512014-06-23 13:13:08 -070049class RenderThread;
50}
51
52// TODO: Replace Cache's GL state tracking with this. For now it's more a thin
53// wrapper of Caches for users to migrate to.
54class RenderState {
55 PREVENT_COPY_AND_ASSIGN(RenderState);
Chris Craik5854b342015-10-26 15:49:56 -070056 friend class renderthread::RenderThread;
57 friend class Caches;
John Reck3b202512014-06-23 13:13:08 -070058public:
59 void onGLContextCreated();
Chris Craik1d477422014-08-26 17:30:15 -070060 void onGLContextDestroyed();
John Reck3b202512014-06-23 13:13:08 -070061
Greg Daniel45ec62b2017-01-04 14:27:00 -050062 void onVkContextCreated();
63 void onVkContextDestroyed();
64
Chris Craik9fded232015-11-11 16:42:34 -080065 void flush(Caches::FlushMode flushMode);
66
John Reck3b202512014-06-23 13:13:08 -070067 void setViewport(GLsizei width, GLsizei height);
68 void getViewport(GLsizei* outWidth, GLsizei* outHeight);
69
70 void bindFramebuffer(GLuint fbo);
Chris Craik818c9fb2015-10-23 14:33:42 -070071 GLuint getFramebuffer() { return mFramebuffer; }
John Reck0b8d0672016-01-29 14:18:22 -080072 GLuint createFramebuffer();
Chris Craik818c9fb2015-10-23 14:33:42 -070073 void deleteFramebuffer(GLuint fbo);
74
John Reck3b202512014-06-23 13:13:08 -070075 void invokeFunctor(Functor* functor, DrawGlInfo::Mode mode, DrawGlInfo* info);
76
77 void debugOverdraw(bool enable, bool clear);
78
John Reck49bc4ac2015-01-29 12:53:38 -080079 void registerLayer(Layer* layer) {
Chris Craik1d477422014-08-26 17:30:15 -070080 mActiveLayers.insert(layer);
81 }
John Reck49bc4ac2015-01-29 12:53:38 -080082 void unregisterLayer(Layer* layer) {
Chris Craik1d477422014-08-26 17:30:15 -070083 mActiveLayers.erase(layer);
84 }
85
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
Chris Craik12efe642015-09-28 15:52:12 -0700106 void render(const Glop& glop, const Matrix4& orthoMatrix);
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
Chris Craik9fded232015-11-11 16:42:34 -0800113 OffscreenBufferPool& layerPool() { return mLayerPool; }
114
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
Chris Craik65fe5ee2015-01-26 18:06:29 -0800127
John Reck0e89e2b2014-10-31 14:49:06 -0700128 renderthread::RenderThread& mRenderThread;
Chris Craik44eb2c02015-01-29 09:45:09 -0800129 Caches* mCaches = nullptr;
Chris Craik96a5c4c2015-01-27 15:46:35 -0800130
Chris Craik44eb2c02015-01-29 09:45:09 -0800131 Blend* mBlend = nullptr;
132 MeshState* mMeshState = nullptr;
133 Scissor* mScissor = nullptr;
134 Stencil* mStencil = nullptr;
Chris Craik96a5c4c2015-01-27 15:46:35 -0800135
Chris Craik9fded232015-11-11 16:42:34 -0800136 OffscreenBufferPool mLayerPool;
137
John Reck49bc4ac2015-01-29 12:53:38 -0800138 std::set<Layer*> mActiveLayers;
sergeyv3e9999b2017-01-19 15:37:02 -0800139 std::set<DeferredLayerUpdater*> mActiveLayerUpdaters;
John Reck443a7142014-09-04 17:40:05 -0700140 std::set<renderthread::CanvasContext*> mRegisteredContexts;
John Reck3b202512014-06-23 13:13:08 -0700141
142 GLsizei mViewportWidth;
143 GLsizei mViewportHeight;
144 GLuint mFramebuffer;
John Reck0e89e2b2014-10-31 14:49:06 -0700145
146 pthread_t mThreadId;
John Reck3b202512014-06-23 13:13:08 -0700147};
148
149} /* namespace uirenderer */
150} /* namespace android */
151
152#endif /* RENDERSTATE_H */