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 #include "renderstate/RenderState.h"
     17 
     18 #include "renderthread/RenderThread.h"
     19 #include "GpuMemoryTracker.h"
     20 
     21 namespace android {
     22 namespace uirenderer {
     23 
     24 RenderState::RenderState(renderthread::RenderThread& thread) : mRenderThread(thread) {
     25     mThreadId = pthread_self();
     26 }
     27 
     28 void RenderState::onContextCreated() {
     29     GpuMemoryTracker::onGpuContextCreated();
     30 }
     31 
     32 void RenderState::onContextDestroyed() {
     33     for(auto callback : mContextCallbacks) {
     34         callback->onContextDestroyed();
     35     }
     36     GpuMemoryTracker::onGpuContextDestroyed();
     37 }
     38 
     39 void RenderState::postDecStrong(VirtualLightRefBase* object) {
     40     if (pthread_equal(mThreadId, pthread_self())) {
     41         object->decStrong(nullptr);
     42     } else {
     43         mRenderThread.queue().post([object]() { object->decStrong(nullptr); });
     44     }
     45 }
     46 
     47 ///////////////////////////////////////////////////////////////////////////////
     48 // Render
     49 ///////////////////////////////////////////////////////////////////////////////
     50 
     51 } /* namespace uirenderer */
     52 } /* namespace android */
     53