• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
19 #include <pthread.h>
20 #include <utils/RefBase.h>
21 
22 #include <set>
23 
24 #include "utils/Macros.h"
25 
26 namespace android {
27 namespace uirenderer {
28 
29 class Layer;
30 
31 namespace renderthread {
32 class CacheManager;
33 class RenderThread;
34 }
35 
36 class IGpuContextCallback {
37 public:
38     virtual void onContextDestroyed() = 0;
39 protected:
~IGpuContextCallback()40     virtual ~IGpuContextCallback() {}
41 };
42 
43 // wrapper of Caches for users to migrate to.
44 class RenderState {
45     PREVENT_COPY_AND_ASSIGN(RenderState);
46     friend class renderthread::RenderThread;
47     friend class renderthread::CacheManager;
48 
49 public:
registerContextCallback(IGpuContextCallback * cb)50     void registerContextCallback(IGpuContextCallback* cb) { mContextCallbacks.insert(cb); }
removeContextCallback(IGpuContextCallback * cb)51     void removeContextCallback(IGpuContextCallback* cb) { mContextCallbacks.erase(cb); }
52 
registerLayer(Layer * layer)53     void registerLayer(Layer* layer) { mActiveLayers.insert(layer); }
unregisterLayer(Layer * layer)54     void unregisterLayer(Layer* layer) { mActiveLayers.erase(layer); }
55 
56     // TODO: This system is a little clunky feeling, this could use some
57     // more thinking...
58     void postDecStrong(VirtualLightRefBase* object);
59 
getRenderThread()60     renderthread::RenderThread& getRenderThread() const { return mRenderThread; }
61 
62 private:
63     explicit RenderState(renderthread::RenderThread& thread);
~RenderState()64     ~RenderState() {}
65 
66     // Context notifications are only to be triggered by renderthread::RenderThread
67     void onContextDestroyed();
68 
69     std::set<IGpuContextCallback*> mContextCallbacks;
70     std::set<Layer*> mActiveLayers;
71 
72     renderthread::RenderThread& mRenderThread;
73     pthread_t mThreadId;
74 };
75 
76 } /* namespace uirenderer */
77 } /* namespace android */
78 
79 #endif /* RENDERSTATE_H */
80