blob: d183a15f384291ebd92c542c4c4ecfe3c534a5de [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;
45
John Reck3b202512014-06-23 13:13:08 -070046namespace renderthread {
John Reck443a7142014-09-04 17:40:05 -070047class CanvasContext;
John Reck3b202512014-06-23 13:13:08 -070048class RenderThread;
49}
50
51// TODO: Replace Cache's GL state tracking with this. For now it's more a thin
52// wrapper of Caches for users to migrate to.
53class RenderState {
54 PREVENT_COPY_AND_ASSIGN(RenderState);
Chris Craik5854b342015-10-26 15:49:56 -070055 friend class renderthread::RenderThread;
56 friend class Caches;
John Reck3b202512014-06-23 13:13:08 -070057public:
58 void onGLContextCreated();
Chris Craik1d477422014-08-26 17:30:15 -070059 void onGLContextDestroyed();
John Reck3b202512014-06-23 13:13:08 -070060
Greg Daniel45ec62b2017-01-04 14:27:00 -050061 void onVkContextCreated();
62 void onVkContextDestroyed();
63
Chris Craik9fded232015-11-11 16:42:34 -080064 void flush(Caches::FlushMode flushMode);
65
John Reck3b202512014-06-23 13:13:08 -070066 void setViewport(GLsizei width, GLsizei height);
67 void getViewport(GLsizei* outWidth, GLsizei* outHeight);
68
69 void bindFramebuffer(GLuint fbo);
Chris Craik818c9fb2015-10-23 14:33:42 -070070 GLuint getFramebuffer() { return mFramebuffer; }
John Reck0b8d0672016-01-29 14:18:22 -080071 GLuint createFramebuffer();
Chris Craik818c9fb2015-10-23 14:33:42 -070072 void deleteFramebuffer(GLuint fbo);
73
John Reck3b202512014-06-23 13:13:08 -070074 void invokeFunctor(Functor* functor, DrawGlInfo::Mode mode, DrawGlInfo* info);
75
76 void debugOverdraw(bool enable, bool clear);
77
John Reck49bc4ac2015-01-29 12:53:38 -080078 void registerLayer(Layer* layer) {
Chris Craik1d477422014-08-26 17:30:15 -070079 mActiveLayers.insert(layer);
80 }
John Reck49bc4ac2015-01-29 12:53:38 -080081 void unregisterLayer(Layer* layer) {
Chris Craik1d477422014-08-26 17:30:15 -070082 mActiveLayers.erase(layer);
83 }
84
John Reck443a7142014-09-04 17:40:05 -070085 void registerCanvasContext(renderthread::CanvasContext* context) {
86 mRegisteredContexts.insert(context);
87 }
88
89 void unregisterCanvasContext(renderthread::CanvasContext* context) {
90 mRegisteredContexts.erase(context);
91 }
92
John Reck0e89e2b2014-10-31 14:49:06 -070093 // TODO: This system is a little clunky feeling, this could use some
94 // more thinking...
95 void postDecStrong(VirtualLightRefBase* object);
96
Chris Craik12efe642015-09-28 15:52:12 -070097 void render(const Glop& glop, const Matrix4& orthoMatrix);
Chris Craik6c15ffa2015-02-02 13:50:55 -080098
Chris Craik44eb2c02015-01-29 09:45:09 -080099 Blend& blend() { return *mBlend; }
Chris Craik96a5c4c2015-01-27 15:46:35 -0800100 MeshState& meshState() { return *mMeshState; }
101 Scissor& scissor() { return *mScissor; }
102 Stencil& stencil() { return *mStencil; }
Chris Craik117bdbc2015-02-05 10:12:38 -0800103
Chris Craik9fded232015-11-11 16:42:34 -0800104 OffscreenBufferPool& layerPool() { return mLayerPool; }
105
Greg Daniel45ec62b2017-01-04 14:27:00 -0500106 GrContext* getGrContext() const;
107
Chris Craik117bdbc2015-02-05 10:12:38 -0800108 void dump();
John Reck3b202512014-06-23 13:13:08 -0700109
Chris Craik5854b342015-10-26 15:49:56 -0700110private:
John Reck3b202512014-06-23 13:13:08 -0700111 void interruptForFunctorInvoke();
112 void resumeFromFunctorInvoke();
113
Chih-Hung Hsieh49796452016-08-10 14:08:35 -0700114 explicit RenderState(renderthread::RenderThread& thread);
John Reck3b202512014-06-23 13:13:08 -0700115 ~RenderState();
116
Chris Craik65fe5ee2015-01-26 18:06:29 -0800117
John Reck0e89e2b2014-10-31 14:49:06 -0700118 renderthread::RenderThread& mRenderThread;
Chris Craik44eb2c02015-01-29 09:45:09 -0800119 Caches* mCaches = nullptr;
Chris Craik96a5c4c2015-01-27 15:46:35 -0800120
Chris Craik44eb2c02015-01-29 09:45:09 -0800121 Blend* mBlend = nullptr;
122 MeshState* mMeshState = nullptr;
123 Scissor* mScissor = nullptr;
124 Stencil* mStencil = nullptr;
Chris Craik96a5c4c2015-01-27 15:46:35 -0800125
Chris Craik9fded232015-11-11 16:42:34 -0800126 OffscreenBufferPool mLayerPool;
127
John Reck49bc4ac2015-01-29 12:53:38 -0800128 std::set<Layer*> mActiveLayers;
John Reck443a7142014-09-04 17:40:05 -0700129 std::set<renderthread::CanvasContext*> mRegisteredContexts;
John Reck3b202512014-06-23 13:13:08 -0700130
131 GLsizei mViewportWidth;
132 GLsizei mViewportHeight;
133 GLuint mFramebuffer;
John Reck0e89e2b2014-10-31 14:49:06 -0700134
135 pthread_t mThreadId;
John Reck3b202512014-06-23 13:13:08 -0700136};
137
138} /* namespace uirenderer */
139} /* namespace android */
140
141#endif /* RENDERSTATE_H */