1 // Copyright 2013 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "android_webview/browser/gl_view_renderer_manager.h" 6 7 #include "base/logging.h" 8 #include "base/threading/platform_thread.h" 9 10 namespace android_webview { 11 12 using base::AutoLock; 13 14 namespace { 15 base::LazyInstance<GLViewRendererManager>::Leaky g_view_renderer_manager = 16 LAZY_INSTANCE_INITIALIZER; 17 } // namespace 18 19 // static GetInstance()20GLViewRendererManager* GLViewRendererManager::GetInstance() { 21 return g_view_renderer_manager.Pointer(); 22 } 23 GLViewRendererManager()24GLViewRendererManager::GLViewRendererManager() {} 25 ~GLViewRendererManager()26GLViewRendererManager::~GLViewRendererManager() {} 27 NullKey()28GLViewRendererManager::Key GLViewRendererManager::NullKey() { 29 AutoLock auto_lock(lock_); 30 return mru_list_.end(); 31 } 32 PushBack(RendererType view)33GLViewRendererManager::Key GLViewRendererManager::PushBack(RendererType view) { 34 AutoLock auto_lock(lock_); 35 DCHECK(mru_list_.end() == 36 std::find(mru_list_.begin(), mru_list_.end(), view)); 37 mru_list_.push_back(view); 38 Key back = mru_list_.end(); 39 back--; 40 return back; 41 } 42 DidDrawGL(Key key)43void GLViewRendererManager::DidDrawGL(Key key) { 44 AutoLock auto_lock(lock_); 45 DCHECK(mru_list_.end() != key); 46 mru_list_.splice(mru_list_.begin(), mru_list_, key); 47 } 48 Remove(Key key)49void GLViewRendererManager::Remove(Key key) { 50 AutoLock auto_lock(lock_); 51 DCHECK(mru_list_.end() != key); 52 mru_list_.erase(key); 53 } 54 55 GLViewRendererManager::RendererType GetMostRecentlyDrawn() const56GLViewRendererManager::GetMostRecentlyDrawn() const { 57 AutoLock auto_lock(lock_); 58 if (mru_list_.begin() == mru_list_.end()) 59 return NULL; 60 return *mru_list_.begin(); 61 } 62 63 } // namespace android_webview 64