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