blob: 64827686f30d0b69893a4bb1faf57172d8f775c8 [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 Craik9fded232015-11-11 16:42:34 -080020#include "renderstate/OffscreenBufferPool.h"
Chris Craik96a5c4c2015-01-27 15:46:35 -080021#include "renderstate/PixelBufferState.h"
John Reck3b202512014-06-23 13:13:08 -070022#include "utils/Macros.h"
23
Chris Craik5854b342015-10-26 15:49:56 -070024#include <GLES2/gl2.h>
25#include <GLES2/gl2ext.h>
Chris Craik5854b342015-10-26 15:49:56 -070026#include <private/hwui/DrawGlInfo.h>
John Reck1bcacfd2017-11-03 10:12:19 -070027#include <ui/Region.h>
28#include <utils/Functor.h>
29#include <utils/Mutex.h>
30#include <utils/RefBase.h>
31#include <set>
Chris Craik5854b342015-10-26 15:49:56 -070032
Greg Daniel45ec62b2017-01-04 14:27:00 -050033class GrContext;
34
John Reck3b202512014-06-23 13:13:08 -070035namespace android {
36namespace uirenderer {
37
Tom Hudson2dc236b2014-10-15 15:46:42 -040038class Caches;
39class Layer;
sergeyv3e9999b2017-01-19 15:37:02 -080040class DeferredLayerUpdater;
Tom Hudson2dc236b2014-10-15 15:46:42 -040041
John Reck3b202512014-06-23 13:13:08 -070042namespace renderthread {
Derek Sollenbergerf9e45d12017-06-01 13:07:39 -040043class CacheManager;
John Reck443a7142014-09-04 17:40:05 -070044class CanvasContext;
John Reck3b202512014-06-23 13:13:08 -070045class RenderThread;
46}
47
48// TODO: Replace Cache's GL state tracking with this. For now it's more a thin
49// wrapper of Caches for users to migrate to.
50class RenderState {
51 PREVENT_COPY_AND_ASSIGN(RenderState);
Chris Craik5854b342015-10-26 15:49:56 -070052 friend class renderthread::RenderThread;
53 friend class Caches;
Derek Sollenbergerf9e45d12017-06-01 13:07:39 -040054 friend class renderthread::CacheManager;
John Reck1bcacfd2017-11-03 10:12:19 -070055
John Reck3b202512014-06-23 13:13:08 -070056public:
57 void onGLContextCreated();
Chris Craik1d477422014-08-26 17:30:15 -070058 void onGLContextDestroyed();
John Reck3b202512014-06-23 13:13:08 -070059
Greg Daniel45ec62b2017-01-04 14:27:00 -050060 void onVkContextCreated();
61 void onVkContextDestroyed();
62
Chris Craik9fded232015-11-11 16:42:34 -080063 void flush(Caches::FlushMode flushMode);
John Reck9a814872017-05-22 15:04:21 -070064 void onBitmapDestroyed(uint32_t pixelRefId);
Chris Craik9fded232015-11-11 16:42:34 -080065
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 Reck1bcacfd2017-11-03 10:12:19 -070078 void registerLayer(Layer* layer) { mActiveLayers.insert(layer); }
79 void unregisterLayer(Layer* layer) { mActiveLayers.erase(layer); }
Chris Craik1d477422014-08-26 17:30:15 -070080
John Reck443a7142014-09-04 17:40:05 -070081 void registerCanvasContext(renderthread::CanvasContext* context) {
82 mRegisteredContexts.insert(context);
83 }
84
85 void unregisterCanvasContext(renderthread::CanvasContext* context) {
86 mRegisteredContexts.erase(context);
87 }
88
sergeyv3e9999b2017-01-19 15:37:02 -080089 void registerDeferredLayerUpdater(DeferredLayerUpdater* layerUpdater) {
90 mActiveLayerUpdaters.insert(layerUpdater);
91 }
92
93 void unregisterDeferredLayerUpdater(DeferredLayerUpdater* layerUpdater) {
94 mActiveLayerUpdaters.erase(layerUpdater);
95 }
96
John Reck0e89e2b2014-10-31 14:49:06 -070097 // TODO: This system is a little clunky feeling, this could use some
98 // more thinking...
99 void postDecStrong(VirtualLightRefBase* object);
100
John Reck642ebea2017-07-17 09:55:02 -0700101 OffscreenBufferPool& layerPool() { return *mLayerPool; }
Chris Craik9fded232015-11-11 16:42:34 -0800102
Greg Daniel45ec62b2017-01-04 14:27:00 -0500103 GrContext* getGrContext() const;
104
Chris Craik117bdbc2015-02-05 10:12:38 -0800105 void dump();
John Reck3b202512014-06-23 13:13:08 -0700106
Chris Craik5854b342015-10-26 15:49:56 -0700107private:
John Reck3b202512014-06-23 13:13:08 -0700108 void interruptForFunctorInvoke();
109 void resumeFromFunctorInvoke();
sergeyvc3f13162017-02-06 11:45:14 -0800110 void destroyLayersInUpdater();
John Reck3b202512014-06-23 13:13:08 -0700111
Chih-Hung Hsieh49796452016-08-10 14:08:35 -0700112 explicit RenderState(renderthread::RenderThread& thread);
John Reck3b202512014-06-23 13:13:08 -0700113 ~RenderState();
114
John Reck0e89e2b2014-10-31 14:49:06 -0700115 renderthread::RenderThread& mRenderThread;
Chris Craik44eb2c02015-01-29 09:45:09 -0800116 Caches* mCaches = nullptr;
Chris Craik96a5c4c2015-01-27 15:46:35 -0800117
John Reck642ebea2017-07-17 09:55:02 -0700118 OffscreenBufferPool* mLayerPool = nullptr;
Chris Craik9fded232015-11-11 16:42:34 -0800119
John Reck49bc4ac2015-01-29 12:53:38 -0800120 std::set<Layer*> mActiveLayers;
sergeyv3e9999b2017-01-19 15:37:02 -0800121 std::set<DeferredLayerUpdater*> mActiveLayerUpdaters;
John Reck443a7142014-09-04 17:40:05 -0700122 std::set<renderthread::CanvasContext*> mRegisteredContexts;
John Reck3b202512014-06-23 13:13:08 -0700123
124 GLsizei mViewportWidth;
125 GLsizei mViewportHeight;
126 GLuint mFramebuffer;
John Reck0e89e2b2014-10-31 14:49:06 -0700127
128 pthread_t mThreadId;
John Reck3b202512014-06-23 13:13:08 -0700129};
130
131} /* namespace uirenderer */
132} /* namespace android */
133
134#endif /* RENDERSTATE_H */