John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 1 | /* |
| 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 Gaillard | a0cb362 | 2024-04-09 14:54:06 +0100 | [diff] [blame] | 19 | #include <pthread.h> |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 20 | #include <utils/RefBase.h> |
Jerome Gaillard | a0cb362 | 2024-04-09 14:54:06 +0100 | [diff] [blame] | 21 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 22 | #include <set> |
Chris Craik | 5854b34 | 2015-10-26 15:49:56 -0700 | [diff] [blame] | 23 | |
Jerome Gaillard | a0cb362 | 2024-04-09 14:54:06 +0100 | [diff] [blame] | 24 | #include "utils/Macros.h" |
| 25 | |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 26 | namespace android { |
| 27 | namespace uirenderer { |
| 28 | |
Tom Hudson | 2dc236b | 2014-10-15 15:46:42 -0400 | [diff] [blame] | 29 | class Layer; |
| 30 | |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 31 | namespace renderthread { |
Derek Sollenberger | f9e45d1 | 2017-06-01 13:07:39 -0400 | [diff] [blame] | 32 | class CacheManager; |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 33 | class RenderThread; |
| 34 | } |
| 35 | |
Derek Sollenberger | 5a5a648 | 2018-09-19 13:52:13 -0400 | [diff] [blame] | 36 | class IGpuContextCallback { |
| 37 | public: |
| 38 | virtual void onContextDestroyed() = 0; |
| 39 | protected: |
| 40 | virtual ~IGpuContextCallback() {} |
| 41 | }; |
| 42 | |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 43 | // wrapper of Caches for users to migrate to. |
| 44 | class RenderState { |
| 45 | PREVENT_COPY_AND_ASSIGN(RenderState); |
Chris Craik | 5854b34 | 2015-10-26 15:49:56 -0700 | [diff] [blame] | 46 | friend class renderthread::RenderThread; |
Derek Sollenberger | f9e45d1 | 2017-06-01 13:07:39 -0400 | [diff] [blame] | 47 | friend class renderthread::CacheManager; |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 48 | |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 49 | public: |
Derek Sollenberger | 5a5a648 | 2018-09-19 13:52:13 -0400 | [diff] [blame] | 50 | void registerContextCallback(IGpuContextCallback* cb) { mContextCallbacks.insert(cb); } |
| 51 | void removeContextCallback(IGpuContextCallback* cb) { mContextCallbacks.erase(cb); } |
| 52 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 53 | void registerLayer(Layer* layer) { mActiveLayers.insert(layer); } |
| 54 | void unregisterLayer(Layer* layer) { mActiveLayers.erase(layer); } |
Chris Craik | 1d47742 | 2014-08-26 17:30:15 -0700 | [diff] [blame] | 55 | |
John Reck | 0e89e2b | 2014-10-31 14:49:06 -0700 | [diff] [blame] | 56 | // TODO: This system is a little clunky feeling, this could use some |
| 57 | // more thinking... |
| 58 | void postDecStrong(VirtualLightRefBase* object); |
| 59 | |
Derek Sollenberger | 28a4d99 | 2018-09-20 13:37:24 -0400 | [diff] [blame] | 60 | renderthread::RenderThread& getRenderThread() const { return mRenderThread; } |
Stan Iliev | 564ca3e | 2018-09-04 22:00:00 +0000 | [diff] [blame] | 61 | |
Chris Craik | 5854b34 | 2015-10-26 15:49:56 -0700 | [diff] [blame] | 62 | private: |
Chih-Hung Hsieh | 4979645 | 2016-08-10 14:08:35 -0700 | [diff] [blame] | 63 | explicit RenderState(renderthread::RenderThread& thread); |
Derek Sollenberger | 28a4d99 | 2018-09-20 13:37:24 -0400 | [diff] [blame] | 64 | ~RenderState() {} |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 65 | |
Derek Sollenberger | 5a5a648 | 2018-09-19 13:52:13 -0400 | [diff] [blame] | 66 | // Context notifications are only to be triggered by renderthread::RenderThread |
Derek Sollenberger | 5a5a648 | 2018-09-19 13:52:13 -0400 | [diff] [blame] | 67 | void onContextDestroyed(); |
| 68 | |
Derek Sollenberger | 5a5a648 | 2018-09-19 13:52:13 -0400 | [diff] [blame] | 69 | std::set<IGpuContextCallback*> mContextCallbacks; |
John Reck | 49bc4ac | 2015-01-29 12:53:38 -0800 | [diff] [blame] | 70 | std::set<Layer*> mActiveLayers; |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 71 | |
Derek Sollenberger | 28a4d99 | 2018-09-20 13:37:24 -0400 | [diff] [blame] | 72 | renderthread::RenderThread& mRenderThread; |
John Reck | 0e89e2b | 2014-10-31 14:49:06 -0700 | [diff] [blame] | 73 | pthread_t mThreadId; |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 74 | }; |
| 75 | |
| 76 | } /* namespace uirenderer */ |
| 77 | } /* namespace android */ |
| 78 | |
| 79 | #endif /* RENDERSTATE_H */ |