Commit 0d830e6b authored by boliu@chromium.org's avatar boliu@chromium.org

gpu: Avoid unbounded idle queue in in-process context

Before this, a task is added to the idle queue each time in flush and
ScheduleMoreIdleWork. This means that as long as there is idle work, the
size of the queue grows by one in each flush.

Fix this by not adding any idle tasks if there is already one pending.

BUG=401712

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

Cr-Commit-Position: refs/heads/master@{#288283}
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@288283 0039d316-1c4b-4281-b951-d872f2087c98
parent 64b5c89e
...@@ -206,6 +206,7 @@ InProcessCommandBuffer::GetDefaultService() { ...@@ -206,6 +206,7 @@ InProcessCommandBuffer::GetDefaultService() {
InProcessCommandBuffer::InProcessCommandBuffer( InProcessCommandBuffer::InProcessCommandBuffer(
const scoped_refptr<Service>& service) const scoped_refptr<Service>& service)
: context_lost_(false), : context_lost_(false),
idle_work_pending_(false),
last_put_offset_(-1), last_put_offset_(-1),
flush_event_(false, false), flush_event_(false, false),
service_(service.get() ? service : GetDefaultService()), service_(service.get() ? service : GetDefaultService()),
...@@ -505,23 +506,30 @@ void InProcessCommandBuffer::FlushOnGpuThread(int32 put_offset) { ...@@ -505,23 +506,30 @@ void InProcessCommandBuffer::FlushOnGpuThread(int32 put_offset) {
// pump idle work until the query is passed. // pump idle work until the query is passed.
if (put_offset == state_after_last_flush_.get_offset && if (put_offset == state_after_last_flush_.get_offset &&
gpu_scheduler_->HasMoreWork()) { gpu_scheduler_->HasMoreWork()) {
service_->ScheduleIdleWork( ScheduleIdleWorkOnGpuThread();
base::Bind(&InProcessCommandBuffer::ScheduleMoreIdleWork,
gpu_thread_weak_ptr_));
} }
} }
void InProcessCommandBuffer::ScheduleMoreIdleWork() { void InProcessCommandBuffer::PerformIdleWork() {
CheckSequencedThread(); CheckSequencedThread();
idle_work_pending_ = false;
base::AutoLock lock(command_buffer_lock_); base::AutoLock lock(command_buffer_lock_);
if (gpu_scheduler_->HasMoreWork()) { if (gpu_scheduler_->HasMoreWork()) {
gpu_scheduler_->PerformIdleWork(); gpu_scheduler_->PerformIdleWork();
service_->ScheduleIdleWork( ScheduleIdleWorkOnGpuThread();
base::Bind(&InProcessCommandBuffer::ScheduleMoreIdleWork,
gpu_thread_weak_ptr_));
} }
} }
void InProcessCommandBuffer::ScheduleIdleWorkOnGpuThread() {
CheckSequencedThread();
if (idle_work_pending_)
return;
idle_work_pending_ = true;
service_->ScheduleIdleWork(
base::Bind(&InProcessCommandBuffer::PerformIdleWork,
gpu_thread_weak_ptr_));
}
void InProcessCommandBuffer::Flush(int32 put_offset) { void InProcessCommandBuffer::Flush(int32 put_offset) {
CheckSequencedThread(); CheckSequencedThread();
if (last_state_.error != gpu::error::kNoError) if (last_state_.error != gpu::error::kNoError)
......
...@@ -189,6 +189,7 @@ class GPU_EXPORT InProcessCommandBuffer : public CommandBuffer, ...@@ -189,6 +189,7 @@ class GPU_EXPORT InProcessCommandBuffer : public CommandBuffer,
bool InitializeOnGpuThread(const InitializeOnGpuThreadParams& params); bool InitializeOnGpuThread(const InitializeOnGpuThreadParams& params);
bool DestroyOnGpuThread(); bool DestroyOnGpuThread();
void FlushOnGpuThread(int32 put_offset); void FlushOnGpuThread(int32 put_offset);
void ScheduleIdleWorkOnGpuThread();
uint32 CreateStreamTextureOnGpuThread(uint32 client_texture_id); uint32 CreateStreamTextureOnGpuThread(uint32 client_texture_id);
bool MakeCurrent(); bool MakeCurrent();
base::Closure WrapCallback(const base::Closure& callback); base::Closure WrapCallback(const base::Closure& callback);
...@@ -213,7 +214,7 @@ class GPU_EXPORT InProcessCommandBuffer : public CommandBuffer, ...@@ -213,7 +214,7 @@ class GPU_EXPORT InProcessCommandBuffer : public CommandBuffer,
void OnResizeView(gfx::Size size, float scale_factor); void OnResizeView(gfx::Size size, float scale_factor);
bool GetBufferChanged(int32 transfer_buffer_id); bool GetBufferChanged(int32 transfer_buffer_id);
void PumpCommands(); void PumpCommands();
void ScheduleMoreIdleWork(); void PerformIdleWork();
static scoped_refptr<Service> GetDefaultService(); static scoped_refptr<Service> GetDefaultService();
...@@ -226,6 +227,7 @@ class GPU_EXPORT InProcessCommandBuffer : public CommandBuffer, ...@@ -226,6 +227,7 @@ class GPU_EXPORT InProcessCommandBuffer : public CommandBuffer,
scoped_refptr<gfx::GLContext> context_; scoped_refptr<gfx::GLContext> context_;
scoped_refptr<gfx::GLSurface> surface_; scoped_refptr<gfx::GLSurface> surface_;
base::Closure context_lost_callback_; base::Closure context_lost_callback_;
bool idle_work_pending_; // Used to throttle PerformIdleWork.
// Members accessed on the client thread: // Members accessed on the client thread:
State last_state_; State last_state_;
......
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