blob: 787946f79f6be8ffcb479999848f7e0142599aff [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);
John Reck9a814872017-05-22 15:04:21 -070066 void onBitmapDestroyed(uint32_t pixelRefId);
Chris Craik9fded232015-11-11 16:42:34 -080067
John Reck3b202512014-06-23 13:13:08 -070068 void setViewport(GLsizei width, GLsizei height);
69 void getViewport(GLsizei* outWidth, GLsizei* outHeight);
70
71 void bindFramebuffer(GLuint fbo);
Chris Craik818c9fb2015-10-23 14:33:42 -070072 GLuint getFramebuffer() { return mFramebuffer; }
John Reck0b8d0672016-01-29 14:18:22 -080073 GLuint createFramebuffer();
Chris Craik818c9fb2015-10-23 14:33:42 -070074 void deleteFramebuffer(GLuint fbo);
75
John Reck3b202512014-06-23 13:13:08 -070076 void invokeFunctor(Functor* functor, DrawGlInfo::Mode mode, DrawGlInfo* info);
77
78 void debugOverdraw(bool enable, bool clear);
79
John Reck49bc4ac2015-01-29 12:53:38 -080080 void registerLayer(Layer* layer) {
Chris Craik1d477422014-08-26 17:30:15 -070081 mActiveLayers.insert(layer);
82 }
John Reck49bc4ac2015-01-29 12:53:38 -080083 void unregisterLayer(Layer* layer) {
Chris Craik1d477422014-08-26 17:30:15 -070084 mActiveLayers.erase(layer);
85 }
86
John Reck443a7142014-09-04 17:40:05 -070087 void registerCanvasContext(renderthread::CanvasContext* context) {
88 mRegisteredContexts.insert(context);
89 }
90
91 void unregisterCanvasContext(renderthread::CanvasContext* context) {
92 mRegisteredContexts.erase(context);
93 }
94
sergeyv3e9999b2017-01-19 15:37:02 -080095 void registerDeferredLayerUpdater(DeferredLayerUpdater* layerUpdater) {
96 mActiveLayerUpdaters.insert(layerUpdater);
97 }
98
99 void unregisterDeferredLayerUpdater(DeferredLayerUpdater* layerUpdater) {
100 mActiveLayerUpdaters.erase(layerUpdater);
101 }
102
John Reck0e89e2b2014-10-31 14:49:06 -0700103 // TODO: This system is a little clunky feeling, this could use some
104 // more thinking...
105 void postDecStrong(VirtualLightRefBase* object);
106
Chris Craik12efe642015-09-28 15:52:12 -0700107 void render(const Glop& glop, const Matrix4& orthoMatrix);
Chris Craik6c15ffa2015-02-02 13:50:55 -0800108
Chris Craik44eb2c02015-01-29 09:45:09 -0800109 Blend& blend() { return *mBlend; }
Chris Craik96a5c4c2015-01-27 15:46:35 -0800110 MeshState& meshState() { return *mMeshState; }
111 Scissor& scissor() { return *mScissor; }
112 Stencil& stencil() { return *mStencil; }
Chris Craik117bdbc2015-02-05 10:12:38 -0800113
Chris Craik9fded232015-11-11 16:42:34 -0800114 OffscreenBufferPool& layerPool() { return mLayerPool; }
115
Greg Daniel45ec62b2017-01-04 14:27:00 -0500116 GrContext* getGrContext() const;
117
Chris Craik117bdbc2015-02-05 10:12:38 -0800118 void dump();
John Reck3b202512014-06-23 13:13:08 -0700119
Chris Craik5854b342015-10-26 15:49:56 -0700120private:
John Reck3b202512014-06-23 13:13:08 -0700121 void interruptForFunctorInvoke();
122 void resumeFromFunctorInvoke();
sergeyvc3f13162017-02-06 11:45:14 -0800123 void destroyLayersInUpdater();
John Reck3b202512014-06-23 13:13:08 -0700124
Chih-Hung Hsieh49796452016-08-10 14:08:35 -0700125 explicit RenderState(renderthread::RenderThread& thread);
John Reck3b202512014-06-23 13:13:08 -0700126 ~RenderState();
127
Chris Craik65fe5ee2015-01-26 18:06:29 -0800128
John Reck0e89e2b2014-10-31 14:49:06 -0700129 renderthread::RenderThread& mRenderThread;
Chris Craik44eb2c02015-01-29 09:45:09 -0800130 Caches* mCaches = nullptr;
Chris Craik96a5c4c2015-01-27 15:46:35 -0800131
Chris Craik44eb2c02015-01-29 09:45:09 -0800132 Blend* mBlend = nullptr;
133 MeshState* mMeshState = nullptr;
134 Scissor* mScissor = nullptr;
135 Stencil* mStencil = nullptr;
Chris Craik96a5c4c2015-01-27 15:46:35 -0800136
Chris Craik9fded232015-11-11 16:42:34 -0800137 OffscreenBufferPool mLayerPool;
138
John Reck49bc4ac2015-01-29 12:53:38 -0800139 std::set<Layer*> mActiveLayers;
sergeyv3e9999b2017-01-19 15:37:02 -0800140 std::set<DeferredLayerUpdater*> mActiveLayerUpdaters;
John Reck443a7142014-09-04 17:40:05 -0700141 std::set<renderthread::CanvasContext*> mRegisteredContexts;
John Reck3b202512014-06-23 13:13:08 -0700142
143 GLsizei mViewportWidth;
144 GLsizei mViewportHeight;
145 GLuint mFramebuffer;
John Reck0e89e2b2014-10-31 14:49:06 -0700146
147 pthread_t mThreadId;
John Reck3b202512014-06-23 13:13:08 -0700148};
149
150} /* namespace uirenderer */
151} /* namespace android */
152
153#endif /* RENDERSTATE_H */