diff options
author | boliu@chromium.org <boliu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-02-20 17:17:03 +0000 |
---|---|---|
committer | boliu@chromium.org <boliu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-02-20 17:17:03 +0000 |
commit | 2e6449895e540ba2f10d7c8b1909c888194207a5 (patch) | |
tree | 8d7efd3a60347dc47512e39e2d7e54e638ac7e51 | |
parent | 04fc4e6ce3c6408bc9fdf02000b0ae6d9d72e3ed (diff) | |
download | chromium_src-2e6449895e540ba2f10d7c8b1909c888194207a5.zip chromium_src-2e6449895e540ba2f10d7c8b1909c888194207a5.tar.gz chromium_src-2e6449895e540ba2f10d7c8b1909c888194207a5.tar.bz2 |
aw: Do not assume functor will be called on UI thread
Instead save the thread of the DrawGL call and use that to determine if
GL is allowed. Not that RequestGL and most other things still run on UI
thread.
No thread safety added in this change.
BUG=344087
Review URL: https://codereview.chromium.org/172793002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@252285 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | android_webview/browser/gl_view_renderer_manager.cc | 21 | ||||
-rw-r--r-- | android_webview/browser/gl_view_renderer_manager.h | 8 | ||||
-rw-r--r-- | android_webview/browser/in_process_view_renderer.cc | 12 |
3 files changed, 34 insertions, 7 deletions
diff --git a/android_webview/browser/gl_view_renderer_manager.cc b/android_webview/browser/gl_view_renderer_manager.cc index bca0d13..6c9ab4a8 100644 --- a/android_webview/browser/gl_view_renderer_manager.cc +++ b/android_webview/browser/gl_view_renderer_manager.cc @@ -5,16 +5,34 @@ #include "android_webview/browser/gl_view_renderer_manager.h" #include "base/logging.h" +#include "base/threading/platform_thread.h" namespace android_webview { +using base::AutoLock; + GLViewRendererManager::GLViewRendererManager() {} GLViewRendererManager::~GLViewRendererManager() {} +bool GLViewRendererManager::OnRenderThread() const { + AutoLock auto_lock(lock_); + return render_thread_.is_equal(base::PlatformThread::CurrentHandle()); +} + +void GLViewRendererManager::MarkRenderThread() { + lock_.AssertAcquired(); + if (render_thread_.is_null()) + render_thread_ = base::PlatformThread::CurrentHandle(); + DCHECK(render_thread_.is_equal(base::PlatformThread::CurrentHandle())); +} + GLViewRendererManager::Key GLViewRendererManager::DidDrawGL( Key key, BrowserViewRenderer* view) { + AutoLock auto_lock(lock_); + MarkRenderThread(); + if (key == mru_list_.end()) { DCHECK(mru_list_.end() == std::find(mru_list_.begin(), mru_list_.end(), view)); @@ -28,17 +46,20 @@ GLViewRendererManager::Key GLViewRendererManager::DidDrawGL( } void GLViewRendererManager::NoLongerExpectsDrawGL(Key key) { + AutoLock auto_lock(lock_); DCHECK(mru_list_.end() != key); mru_list_.erase(key); } BrowserViewRenderer* GLViewRendererManager::GetMostRecentlyDrawn() const { + AutoLock auto_lock(lock_); if (mru_list_.begin() == mru_list_.end()) return NULL; return *mru_list_.begin(); } GLViewRendererManager::Key GLViewRendererManager::NullKey() { + AutoLock auto_lock(lock_); return mru_list_.end(); } diff --git a/android_webview/browser/gl_view_renderer_manager.h b/android_webview/browser/gl_view_renderer_manager.h index 67595fb..588390c 100644 --- a/android_webview/browser/gl_view_renderer_manager.h +++ b/android_webview/browser/gl_view_renderer_manager.h @@ -8,6 +8,8 @@ #include <list> #include "base/basictypes.h" +#include "base/synchronization/lock.h" +#include "base/threading/platform_thread.h" namespace android_webview { @@ -21,6 +23,8 @@ class GLViewRendererManager { GLViewRendererManager(); ~GLViewRendererManager(); + bool OnRenderThread() const; + // If |key| is NullKey(), then |view| is inserted at the front and a new key // is returned. Otherwise |key| must point to |view| which is moved to the // front. @@ -33,6 +37,10 @@ class GLViewRendererManager { Key NullKey(); private: + void MarkRenderThread(); + + mutable base::Lock lock_; + base::PlatformThreadHandle render_thread_; ListType mru_list_; DISALLOW_COPY_AND_ASSIGN(GLViewRendererManager); diff --git a/android_webview/browser/in_process_view_renderer.cc b/android_webview/browser/in_process_view_renderer.cc index 26eaa2f..b0df091 100644 --- a/android_webview/browser/in_process_view_renderer.cc +++ b/android_webview/browser/in_process_view_renderer.cc @@ -43,7 +43,6 @@ namespace android_webview { namespace { - const void* kUserDataKey = &kUserDataKey; class UserData : public content::WebContents::Data { @@ -139,20 +138,22 @@ AwDrawSWFunctionTable* g_sw_draw_functions = NULL; const int64 kFallbackTickTimeoutInMilliseconds = 20; - // Used to calculate memory and resource allocation. Determined experimentally. size_t g_memory_multiplier = 10; size_t g_num_gralloc_limit = 150; const size_t kBytesPerPixel = 4; const size_t kMemoryAllocationStep = 5 * 1024 * 1024; +base::LazyInstance<GLViewRendererManager>::Leaky g_view_renderer_manager = + LAZY_INSTANCE_INITIALIZER; + class ScopedAllowGL { public: ScopedAllowGL(); ~ScopedAllowGL(); static bool IsAllowed() { - return BrowserThread::CurrentlyOn(BrowserThread::UI) && allow_gl; + return g_view_renderer_manager.Get().OnRenderThread() && allow_gl; } private: @@ -162,7 +163,7 @@ class ScopedAllowGL { }; ScopedAllowGL::ScopedAllowGL() { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); + DCHECK(g_view_renderer_manager.Get().OnRenderThread()); DCHECK(!allow_gl); allow_gl = true; } @@ -173,9 +174,6 @@ ScopedAllowGL::~ScopedAllowGL() { bool ScopedAllowGL::allow_gl = false; -base::LazyInstance<GLViewRendererManager>::Leaky g_view_renderer_manager = - LAZY_INSTANCE_INITIALIZER; - void RequestProcessGLOnUIThread() { if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { BrowserThread::PostTask( |