blob: dee02e9873d8df7670ea03a985cb2389a07c3efc [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 "utils/Macros.h"
20
Chris Craik5854b342015-10-26 15:49:56 -070021#include <GLES2/gl2.h>
22#include <GLES2/gl2ext.h>
Chris Craik5854b342015-10-26 15:49:56 -070023#include <private/hwui/DrawGlInfo.h>
John Reck1bcacfd2017-11-03 10:12:19 -070024#include <ui/Region.h>
25#include <utils/Functor.h>
26#include <utils/Mutex.h>
27#include <utils/RefBase.h>
28#include <set>
Chris Craik5854b342015-10-26 15:49:56 -070029
Greg Daniel45ec62b2017-01-04 14:27:00 -050030class GrContext;
31
John Reck3b202512014-06-23 13:13:08 -070032namespace android {
33namespace uirenderer {
34
Tom Hudson2dc236b2014-10-15 15:46:42 -040035class Layer;
sergeyv3e9999b2017-01-19 15:37:02 -080036class DeferredLayerUpdater;
Tom Hudson2dc236b2014-10-15 15:46:42 -040037
John Reck3b202512014-06-23 13:13:08 -070038namespace renderthread {
Derek Sollenbergerf9e45d12017-06-01 13:07:39 -040039class CacheManager;
John Reck443a7142014-09-04 17:40:05 -070040class CanvasContext;
John Reck3b202512014-06-23 13:13:08 -070041class RenderThread;
42}
43
Derek Sollenberger5a5a6482018-09-19 13:52:13 -040044class IGpuContextCallback {
45public:
46 virtual void onContextDestroyed() = 0;
47protected:
48 virtual ~IGpuContextCallback() {}
49};
50
John Reck3b202512014-06-23 13:13:08 -070051// wrapper of Caches for users to migrate to.
52class RenderState {
53 PREVENT_COPY_AND_ASSIGN(RenderState);
Chris Craik5854b342015-10-26 15:49:56 -070054 friend class renderthread::RenderThread;
Derek Sollenbergerf9e45d12017-06-01 13:07:39 -040055 friend class renderthread::CacheManager;
John Reck1bcacfd2017-11-03 10:12:19 -070056
John Reck3b202512014-06-23 13:13:08 -070057public:
John Reck9a814872017-05-22 15:04:21 -070058 void onBitmapDestroyed(uint32_t pixelRefId);
Chris Craik9fded232015-11-11 16:42:34 -080059
John Reck3b202512014-06-23 13:13:08 -070060 void setViewport(GLsizei width, GLsizei height);
61 void getViewport(GLsizei* outWidth, GLsizei* outHeight);
62
63 void bindFramebuffer(GLuint fbo);
Chris Craik818c9fb2015-10-23 14:33:42 -070064 GLuint getFramebuffer() { return mFramebuffer; }
John Reck0b8d0672016-01-29 14:18:22 -080065 GLuint createFramebuffer();
Chris Craik818c9fb2015-10-23 14:33:42 -070066 void deleteFramebuffer(GLuint fbo);
67
John Reck3b202512014-06-23 13:13:08 -070068 void debugOverdraw(bool enable, bool clear);
69
Derek Sollenberger5a5a6482018-09-19 13:52:13 -040070 void registerContextCallback(IGpuContextCallback* cb) { mContextCallbacks.insert(cb); }
71 void removeContextCallback(IGpuContextCallback* cb) { mContextCallbacks.erase(cb); }
72
John Reck1bcacfd2017-11-03 10:12:19 -070073 void registerLayer(Layer* layer) { mActiveLayers.insert(layer); }
74 void unregisterLayer(Layer* layer) { mActiveLayers.erase(layer); }
Chris Craik1d477422014-08-26 17:30:15 -070075
John Reck443a7142014-09-04 17:40:05 -070076 void registerCanvasContext(renderthread::CanvasContext* context) {
77 mRegisteredContexts.insert(context);
78 }
79
80 void unregisterCanvasContext(renderthread::CanvasContext* context) {
81 mRegisteredContexts.erase(context);
82 }
83
sergeyv3e9999b2017-01-19 15:37:02 -080084 void registerDeferredLayerUpdater(DeferredLayerUpdater* layerUpdater) {
85 mActiveLayerUpdaters.insert(layerUpdater);
86 }
87
88 void unregisterDeferredLayerUpdater(DeferredLayerUpdater* layerUpdater) {
89 mActiveLayerUpdaters.erase(layerUpdater);
90 }
91
John Reck0e89e2b2014-10-31 14:49:06 -070092 // TODO: This system is a little clunky feeling, this could use some
93 // more thinking...
94 void postDecStrong(VirtualLightRefBase* object);
95
Greg Daniel45ec62b2017-01-04 14:27:00 -050096 GrContext* getGrContext() const;
97
Chris Craik117bdbc2015-02-05 10:12:38 -080098 void dump();
John Reck3b202512014-06-23 13:13:08 -070099
Stan Iliev564ca3e2018-09-04 22:00:00 +0000100 renderthread::RenderThread& getRenderThread();
101
Chris Craik5854b342015-10-26 15:49:56 -0700102private:
Chih-Hung Hsieh49796452016-08-10 14:08:35 -0700103 explicit RenderState(renderthread::RenderThread& thread);
John Reck3b202512014-06-23 13:13:08 -0700104 ~RenderState();
105
Derek Sollenberger5a5a6482018-09-19 13:52:13 -0400106 // Context notifications are only to be triggered by renderthread::RenderThread
107 void onContextCreated();
108 void onContextDestroyed();
109
John Reck0e89e2b2014-10-31 14:49:06 -0700110 renderthread::RenderThread& mRenderThread;
Chris Craik96a5c4c2015-01-27 15:46:35 -0800111
Derek Sollenberger5a5a6482018-09-19 13:52:13 -0400112 std::set<IGpuContextCallback*> mContextCallbacks;
John Reck49bc4ac2015-01-29 12:53:38 -0800113 std::set<Layer*> mActiveLayers;
sergeyv3e9999b2017-01-19 15:37:02 -0800114 std::set<DeferredLayerUpdater*> mActiveLayerUpdaters;
John Reck443a7142014-09-04 17:40:05 -0700115 std::set<renderthread::CanvasContext*> mRegisteredContexts;
John Reck3b202512014-06-23 13:13:08 -0700116
117 GLsizei mViewportWidth;
118 GLsizei mViewportHeight;
119 GLuint mFramebuffer;
John Reck0e89e2b2014-10-31 14:49:06 -0700120
121 pthread_t mThreadId;
John Reck3b202512014-06-23 13:13:08 -0700122};
123
124} /* namespace uirenderer */
125} /* namespace android */
126
127#endif /* RENDERSTATE_H */