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 1becdf1d5a885a2b4830b64ae44b5b70bd96d163..9ea8c98f890ec62d09ec03fc7fb31e6f17be0809 100644 |
--- a/android_webview/browser/in_process_view_renderer.cc |
+++ b/android_webview/browser/in_process_view_renderer.cc |
@@ -22,7 +22,6 @@ |
#include "content/public/browser/browser_thread.h" |
#include "content/public/browser/web_contents.h" |
#include "content/public/common/content_switches.h" |
-#include "gpu/command_buffer/service/in_process_command_buffer.h" |
#include "third_party/skia/include/core/SkBitmap.h" |
#include "third_party/skia/include/core/SkBitmapDevice.h" |
#include "third_party/skia/include/core/SkCanvas.h" |
@@ -192,21 +191,55 @@ void RequestProcessGLOnUIThread() { |
} // namespace |
+DeferredGpuCommandService::DeferredGpuCommandService() {} |
+ |
+DeferredGpuCommandService::~DeferredGpuCommandService() { |
+ base::AutoLock lock(tasks_lock_); |
+ DCHECK(tasks_.empty()); |
+} |
+ |
// Called from different threads! |
-static void ScheduleGpuWork() { |
+void DeferredGpuCommandService::ScheduleTask(const base::Closure& task) { |
if (ScopedAllowGL::IsAllowed()) { |
- gpu::InProcessCommandBuffer::ProcessGpuWorkOnCurrentThread(); |
+ task.Run(); |
} else { |
+ base::AutoLock lock(tasks_lock_); |
+ tasks_.push(task); |
RequestProcessGLOnUIThread(); |
} |
} |
+void DeferredGpuCommandService::ScheduleIdleWork(const base::Closure& callback) { |
+ // TODO(sievers): Should this do anything? |
boliu
2014/02/08 18:55:54
We can make this work, if it's needed.
|
+} |
+ |
+void DeferredGpuCommandService::RunTasks() { |
+ size_t num_tasks; |
boliu
2014/02/08 18:55:54
bool has_more_tasks?
no sievers
2014/02/12 03:09:15
Done.
|
+ { |
+ base::AutoLock lock(tasks_lock_); |
boliu
2014/02/08 18:55:54
Do we need a lock? We are single threaded here :)
no sievers
2014/02/12 03:09:15
Yes, because of the video context which queues tas
|
+ num_tasks = tasks_.size(); |
+ } |
+ |
+ while (num_tasks) { |
+ base::Closure task; |
+ { |
+ base::AutoLock lock(tasks_lock_); |
+ task = tasks_.front(); |
+ tasks_.pop(); |
+ } |
+ task.Run(); |
+ { |
+ base::AutoLock lock(tasks_lock_); |
+ num_tasks = tasks_.size(); |
+ } |
+ |
+ } |
+} |
+ |
// static |
void BrowserViewRenderer::SetAwDrawSWFunctionTable( |
AwDrawSWFunctionTable* table) { |
g_sw_draw_functions = table; |
- gpu::InProcessCommandBuffer::SetScheduleCallback( |
- base::Bind(&ScheduleGpuWork)); |
} |
// static |
@@ -351,7 +384,7 @@ void InProcessViewRenderer::TrimMemory(int level) { |
TRACE_EVENT0("android_webview", "InProcessViewRenderer::TrimMemory"); |
ScopedAppGLStateRestore state_restore( |
ScopedAppGLStateRestore::MODE_RESOURCE_MANAGEMENT); |
- gpu::InProcessCommandBuffer::ProcessGpuWorkOnCurrentThread(); |
+ gl_queue_->RunTasks(); |
ScopedAllowGL allow_gl; |
SetMemoryPolicy(policy); |
@@ -392,11 +425,14 @@ bool InProcessViewRenderer::InitializeHwDraw() { |
TRACE_EVENT0("android_webview", "InitializeHwDraw"); |
DCHECK(!gl_surface_); |
gl_surface_ = new AwGLSurface; |
- hardware_failed_ = !compositor_->InitializeHwDraw(gl_surface_); |
+ gl_queue_ = new DeferredGpuCommandQueue; |
+ hardware_failed_ = !compositor_->InitializeHwDraw(gl_surface_, gl_queue_); |
hardware_initialized_ = true; |
- if (hardware_failed_) |
+ if (hardware_failed_) { |
gl_surface_ = NULL; |
+ gl_queue_ = NULL; |
+ } |
return !hardware_failed_; |
} |
@@ -416,7 +452,7 @@ void InProcessViewRenderer::DrawGL(AwDrawGLInfo* draw_info) { |
} |
ScopedAppGLStateRestore state_restore(ScopedAppGLStateRestore::MODE_DRAW); |
- gpu::InProcessCommandBuffer::ProcessGpuWorkOnCurrentThread(); |
+ gl_queue_->RunTasks(); |
ScopedAllowGL allow_gl; |
if (!attached_to_window_) { |
@@ -705,13 +741,14 @@ void InProcessViewRenderer::OnDetachedFromWindow() { |
ScopedAppGLStateRestore state_restore( |
ScopedAppGLStateRestore::MODE_RESOURCE_MANAGEMENT); |
- gpu::InProcessCommandBuffer::ProcessGpuWorkOnCurrentThread(); |
+ gl_queue->RunTasks(); |
ScopedAllowGL allow_gl; |
compositor_->ReleaseHwDraw(); |
hardware_initialized_ = false; |
} |
gl_surface_ = NULL; |
+ gl_queue_ = NULL; |
attached_to_window_ = false; |
} |