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