blob: 60657cf91123a61878d8dfc6576177b28d963c41 [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
Jerome Gaillarda0cb3622024-04-09 14:54:06 +010019#include <pthread.h>
John Reck1bcacfd2017-11-03 10:12:19 -070020#include <utils/RefBase.h>
Jerome Gaillarda0cb3622024-04-09 14:54:06 +010021
John Reck1bcacfd2017-11-03 10:12:19 -070022#include <set>
Chris Craik5854b342015-10-26 15:49:56 -070023
Jerome Gaillarda0cb3622024-04-09 14:54:06 +010024#include "utils/Macros.h"
25
John Reck3b202512014-06-23 13:13:08 -070026namespace android {
27namespace uirenderer {
28
Tom Hudson2dc236b2014-10-15 15:46:42 -040029class Layer;
30
John Reck3b202512014-06-23 13:13:08 -070031namespace renderthread {
Derek Sollenbergerf9e45d12017-06-01 13:07:39 -040032class CacheManager;
John Reck3b202512014-06-23 13:13:08 -070033class RenderThread;
34}
35
Derek Sollenberger5a5a6482018-09-19 13:52:13 -040036class IGpuContextCallback {
37public:
38 virtual void onContextDestroyed() = 0;
39protected:
40 virtual ~IGpuContextCallback() {}
41};
42
John Reck3b202512014-06-23 13:13:08 -070043// wrapper of Caches for users to migrate to.
44class RenderState {
45 PREVENT_COPY_AND_ASSIGN(RenderState);
Chris Craik5854b342015-10-26 15:49:56 -070046 friend class renderthread::RenderThread;
Derek Sollenbergerf9e45d12017-06-01 13:07:39 -040047 friend class renderthread::CacheManager;
John Reck1bcacfd2017-11-03 10:12:19 -070048
John Reck3b202512014-06-23 13:13:08 -070049public:
Derek Sollenberger5a5a6482018-09-19 13:52:13 -040050 void registerContextCallback(IGpuContextCallback* cb) { mContextCallbacks.insert(cb); }
51 void removeContextCallback(IGpuContextCallback* cb) { mContextCallbacks.erase(cb); }
52
John Reck1bcacfd2017-11-03 10:12:19 -070053 void registerLayer(Layer* layer) { mActiveLayers.insert(layer); }
54 void unregisterLayer(Layer* layer) { mActiveLayers.erase(layer); }
Chris Craik1d477422014-08-26 17:30:15 -070055
John Reck0e89e2b2014-10-31 14:49:06 -070056 // TODO: This system is a little clunky feeling, this could use some
57 // more thinking...
58 void postDecStrong(VirtualLightRefBase* object);
59
Derek Sollenberger28a4d992018-09-20 13:37:24 -040060 renderthread::RenderThread& getRenderThread() const { return mRenderThread; }
Stan Iliev564ca3e2018-09-04 22:00:00 +000061
Chris Craik5854b342015-10-26 15:49:56 -070062private:
Chih-Hung Hsieh49796452016-08-10 14:08:35 -070063 explicit RenderState(renderthread::RenderThread& thread);
Derek Sollenberger28a4d992018-09-20 13:37:24 -040064 ~RenderState() {}
John Reck3b202512014-06-23 13:13:08 -070065
Derek Sollenberger5a5a6482018-09-19 13:52:13 -040066 // Context notifications are only to be triggered by renderthread::RenderThread
Derek Sollenberger5a5a6482018-09-19 13:52:13 -040067 void onContextDestroyed();
68
Derek Sollenberger5a5a6482018-09-19 13:52:13 -040069 std::set<IGpuContextCallback*> mContextCallbacks;
John Reck49bc4ac2015-01-29 12:53:38 -080070 std::set<Layer*> mActiveLayers;
John Reck3b202512014-06-23 13:13:08 -070071
Derek Sollenberger28a4d992018-09-20 13:37:24 -040072 renderthread::RenderThread& mRenderThread;
John Reck0e89e2b2014-10-31 14:49:06 -070073 pthread_t mThreadId;
John Reck3b202512014-06-23 13:13:08 -070074};
75
76} /* namespace uirenderer */
77} /* namespace android */
78
79#endif /* RENDERSTATE_H */