Chromium Code Reviews| Index: android_webview/browser/in_process_view_renderer.cc |
| diff --git a/android_webview/browser/in_process_view_renderer.cc b/android_webview/browser/in_process_view_renderer.cc |
| index dbb4c241a9956a3aefb6d87cee559899050ea36c..9da04092b685516c7e6ee8ac260363efebe12229 100644 |
| --- a/android_webview/browser/in_process_view_renderer.cc |
| +++ b/android_webview/browser/in_process_view_renderer.cc |
| @@ -12,10 +12,14 @@ |
| #include "base/android/jni_android.h" |
| #include "base/command_line.h" |
| #include "base/debug/trace_event.h" |
| +#include "base/lazy_instance.h" |
| #include "base/logging.h" |
| #include "base/strings/stringprintf.h" |
| +#include "base/threading/non_thread_safe.h" |
| #include "content/public/browser/android/synchronous_compositor.h" |
| +#include "content/public/browser/browser_thread.h" |
| #include "content/public/browser/web_contents.h" |
| +#include "gpu/command_buffer/service/in_process_command_buffer.h" |
| #include "skia/ext/refptr.h" |
| #include "third_party/skia/include/core/SkBitmap.h" |
| #include "third_party/skia/include/core/SkCanvas.h" |
| @@ -30,6 +34,7 @@ |
| using base::android::AttachCurrentThread; |
| using base::android::JavaRef; |
| using base::android::ScopedJavaLocalRef; |
| +using content::BrowserThread; |
| namespace android_webview { |
| @@ -124,8 +129,43 @@ bool g_is_skia_version_compatible = false; |
| const int64 kFallbackTickTimeoutInMilliseconds = 500; |
| +class ScopedAllowGL : public base::NonThreadSafe { |
|
joth
2013/07/30 01:13:06
sub-classing NonThreadSafe doesn't do anything unl
no sievers
2013/07/31 18:19:28
Done.
|
| + public: |
| + ScopedAllowGL(); |
| + virtual ~ScopedAllowGL(); |
| + |
| + static bool IsAllowed() { return allow_gl; } |
|
joth
2013/07/30 01:13:06
nit: maybe easier to follow the threading rules if
no sievers
2013/07/31 18:19:28
Done.
|
| + |
| + private: |
| + static bool allow_gl = false; |
|
joth
2013/07/30 01:13:06
nit: g_allow_gl
also remove the "= false" -- you
no sievers
2013/07/31 18:19:28
Done.
|
| + |
| + DISALLOW_COPY_AND_ASSIGN(ScopedAllowGL); |
| +}; |
| + |
| +ScopedAllowGL::ScopedAllowGL() { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| + DCHECK(!g_allow_gl); |
| + g_allow_gl = true; |
| +} |
| + |
| +ScopedAllowGL::~ScopedAllowGL() { |
| + g_allow_gl = false; |
| +} |
| + |
| +bool ScopedAllowGL::allow_gl = false; |
| + |
| } // namespace |
| +// Called from different threads! |
| +static void ScheduleGpuWork() { |
| + if (BrowserThread::CurrentlyOn(BrowserThread::UI) && |
| + ScopedAllowGL::IsAllowed()) { |
| + gpu::InProcessCommandBuffer::ProcessGpuWorkOnCurrentThread(); |
| + } else { |
| + // TODO: We need to request a callback with a GL context current here. |
| + } |
| +} |
| + |
| // static |
| void BrowserViewRenderer::SetAwDrawSWFunctionTable( |
| AwDrawSWFunctionTable* table) { |
| @@ -134,6 +174,9 @@ void BrowserViewRenderer::SetAwDrawSWFunctionTable( |
| g_sw_draw_functions->is_skia_version_compatible(&SkGraphics::GetVersion); |
| LOG_IF(WARNING, !g_is_skia_version_compatible) |
| << "Skia versions are not compatible, rendering performance will suffer."; |
| + |
| + gpu::InProcessCommandBuffer::SetScheduleCallback( |
| + base::Bind(&ScheduleGpuWork)); |
| } |
| // static |
| @@ -228,6 +271,8 @@ void InProcessViewRenderer::DrawGL(AwDrawGLInfo* draw_info) { |
| } |
| ScopedAppGLStateRestore state_restore(ScopedAppGLStateRestore::MODE_DRAW); |
| + gpu::InProcessCommandBuffer::ProcessGpuWorkOnCurrentThread(); |
| + ScopedAllowGL allow_gl; |
| if (attached_to_window_ && compositor_ && !hardware_initialized_) { |
| TRACE_EVENT0("android_webview", "InitializeHwDraw"); |
| @@ -459,6 +504,8 @@ void InProcessViewRenderer::OnDetachedFromWindow() { |
| ScopedAppGLStateRestore state_restore( |
| ScopedAppGLStateRestore::MODE_DETACH_FROM_WINDOW); |
| + gpu::InProcessCommandBuffer::ProcessGpuWorkOnCurrentThread(); |
| + ScopedAllowGL allow_gl; |
| compositor_->ReleaseHwDraw(); |
| hardware_initialized_ = false; |
| } |