Commit 86eb5b22 authored by boliu@chromium.org's avatar boliu@chromium.org

aw: Improve DeferredGpuCommandService scheduling

Simple fixes first. First if GPU thread is already executing GL, then
don't schedule and just make sure the GPU flushes before finishing
executing said GL.

Then make sure we don't send repeated and unnecessary RequestDrawGL.

BUG=344087

Review URL: https://codereview.chromium.org/299363003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@273092 0039d316-1c4b-4281-b951-d872f2087c98
parent eb116935
......@@ -6,12 +6,43 @@
#include "android_webview/browser/gl_view_renderer_manager.h"
#include "android_webview/browser/shared_renderer_state.h"
#include "base/synchronization/lock.h"
#include "content/public/browser/android/synchronous_compositor.h"
#include "gpu/command_buffer/service/shader_translator_cache.h"
namespace android_webview {
namespace {
// TODO(boliu): Consider using base/atomicops.h.
class ThreadSafeBool {
public:
ThreadSafeBool();
void Set(bool boolean);
bool Get();
private:
base::Lock lock_;
bool boolean_;
DISALLOW_COPY_AND_ASSIGN(ThreadSafeBool);
};
ThreadSafeBool::ThreadSafeBool() : boolean_(false) {
}
void ThreadSafeBool::Set(bool boolean) {
base::AutoLock lock(lock_);
boolean_ = boolean;
}
bool ThreadSafeBool::Get() {
base::AutoLock lock(lock_);
return boolean_;
}
base::LazyInstance<ThreadSafeBool> g_request_pending =
LAZY_INSTANCE_INITIALIZER;
base::LazyInstance<scoped_refptr<DeferredGpuCommandService> >
g_service = LAZY_INSTANCE_INITIALIZER;
} // namespace
......@@ -31,13 +62,22 @@ ScopedAllowGL::ScopedAllowGL() {
g_service.Get()->RunTasks();
}
ScopedAllowGL::~ScopedAllowGL() { allow_gl.Get().Set(false); }
ScopedAllowGL::~ScopedAllowGL() {
allow_gl.Get().Set(false);
g_request_pending.Get().Set(false);
if (g_service.Get())
g_service.Get()->RunTasks();
}
// static
void DeferredGpuCommandService::SetInstance() {
if (!g_service.Get()) {
g_service.Get() = new DeferredGpuCommandService;
content::SynchronousCompositor::SetGpuService(g_service.Get());
// Initialize global booleans.
g_request_pending.Get().Set(false);
}
}
......@@ -63,7 +103,11 @@ void DeferredGpuCommandService::RequestProcessGL() {
LOG(ERROR) << "No hardware renderer. Deadlock likely";
return;
}
renderer_state->ClientRequestDrawGL();
if (!g_request_pending.Get().Get()) {
g_request_pending.Get().Set(true);
renderer_state->ClientRequestDrawGL();
}
}
// Called from different threads!
......@@ -75,7 +119,6 @@ void DeferredGpuCommandService::ScheduleTask(const base::Closure& task) {
if (ScopedAllowGL::IsAllowed()) {
RunTasks();
} else {
// TODO(boliu): Improve this to avoid PostTask storm.
RequestProcessGL();
}
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment