blob: e08d32a7735c01dfa1bcd120385ead0dd797ce2d [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
John Reck1bcacfd2017-11-03 10:12:19 -070021#include <utils/RefBase.h>
22#include <set>
Chris Craik5854b342015-10-26 15:49:56 -070023
John Reck3b202512014-06-23 13:13:08 -070024namespace android {
25namespace uirenderer {
26
Tom Hudson2dc236b2014-10-15 15:46:42 -040027class Layer;
28
John Reck3b202512014-06-23 13:13:08 -070029namespace renderthread {
Derek Sollenbergerf9e45d12017-06-01 13:07:39 -040030class CacheManager;
John Reck3b202512014-06-23 13:13:08 -070031class RenderThread;
32}
33
Derek Sollenberger5a5a6482018-09-19 13:52:13 -040034class IGpuContextCallback {
35public:
36 virtual void onContextDestroyed() = 0;
37protected:
38 virtual ~IGpuContextCallback() {}
39};
40
John Reck3b202512014-06-23 13:13:08 -070041// wrapper of Caches for users to migrate to.
42class RenderState {
43 PREVENT_COPY_AND_ASSIGN(RenderState);
Chris Craik5854b342015-10-26 15:49:56 -070044 friend class renderthread::RenderThread;
Derek Sollenbergerf9e45d12017-06-01 13:07:39 -040045 friend class renderthread::CacheManager;
John Reck1bcacfd2017-11-03 10:12:19 -070046
John Reck3b202512014-06-23 13:13:08 -070047public:
Derek Sollenberger5a5a6482018-09-19 13:52:13 -040048 void registerContextCallback(IGpuContextCallback* cb) { mContextCallbacks.insert(cb); }
49 void removeContextCallback(IGpuContextCallback* cb) { mContextCallbacks.erase(cb); }
50
John Reck1bcacfd2017-11-03 10:12:19 -070051 void registerLayer(Layer* layer) { mActiveLayers.insert(layer); }
52 void unregisterLayer(Layer* layer) { mActiveLayers.erase(layer); }
Chris Craik1d477422014-08-26 17:30:15 -070053
John Reck0e89e2b2014-10-31 14:49:06 -070054 // TODO: This system is a little clunky feeling, this could use some
55 // more thinking...
56 void postDecStrong(VirtualLightRefBase* object);
57
Derek Sollenberger28a4d992018-09-20 13:37:24 -040058 renderthread::RenderThread& getRenderThread() const { return mRenderThread; }
Stan Iliev564ca3e2018-09-04 22:00:00 +000059
Chris Craik5854b342015-10-26 15:49:56 -070060private:
Chih-Hung Hsieh49796452016-08-10 14:08:35 -070061 explicit RenderState(renderthread::RenderThread& thread);
Derek Sollenberger28a4d992018-09-20 13:37:24 -040062 ~RenderState() {}
John Reck3b202512014-06-23 13:13:08 -070063
Derek Sollenberger5a5a6482018-09-19 13:52:13 -040064 // Context notifications are only to be triggered by renderthread::RenderThread
Derek Sollenberger5a5a6482018-09-19 13:52:13 -040065 void onContextDestroyed();
66
Derek Sollenberger5a5a6482018-09-19 13:52:13 -040067 std::set<IGpuContextCallback*> mContextCallbacks;
John Reck49bc4ac2015-01-29 12:53:38 -080068 std::set<Layer*> mActiveLayers;
John Reck3b202512014-06-23 13:13:08 -070069
Derek Sollenberger28a4d992018-09-20 13:37:24 -040070 renderthread::RenderThread& mRenderThread;
John Reck0e89e2b2014-10-31 14:49:06 -070071 pthread_t mThreadId;
John Reck3b202512014-06-23 13:13:08 -070072};
73
74} /* namespace uirenderer */
75} /* namespace android */
76
77#endif /* RENDERSTATE_H */