Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(973)

Side by Side Diff: gpu/command_buffer/service/in_process_command_buffer.cc

Issue 851473003: gpu: Optimize in-process idle task scheduling (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "gpu/command_buffer/service/in_process_command_buffer.h" 5 #include "gpu/command_buffer/service/in_process_command_buffer.h"
6 6
7 #include <queue> 7 #include <queue>
8 #include <set> 8 #include <set>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 } 75 }
76 76
77 void ScheduleTask(const base::Closure& task) override; 77 void ScheduleTask(const base::Closure& task) override;
78 void ScheduleIdleWork(const base::Closure& callback) override; 78 void ScheduleIdleWork(const base::Closure& callback) override;
79 bool UseVirtualizedGLContexts() override { return false; } 79 bool UseVirtualizedGLContexts() override { return false; }
80 scoped_refptr<gles2::ShaderTranslatorCache> shader_translator_cache() 80 scoped_refptr<gles2::ShaderTranslatorCache> shader_translator_cache()
81 override; 81 override;
82 82
83 private: 83 private:
84 ~GpuInProcessThread() override; 84 ~GpuInProcessThread() override;
85
86 void CheckIdleTasksLocked();
87 void RunIdleTask();
88
85 friend class base::RefCountedThreadSafe<GpuInProcessThread>; 89 friend class base::RefCountedThreadSafe<GpuInProcessThread>;
86 90
87 scoped_refptr<gpu::gles2::ShaderTranslatorCache> shader_translator_cache_; 91 scoped_refptr<gpu::gles2::ShaderTranslatorCache> shader_translator_cache_;
92
93 base::Lock lock_;
94 bool idle_post_pending_;
95 std::queue<base::Closure> pending_idle_tasks_;
88 DISALLOW_COPY_AND_ASSIGN(GpuInProcessThread); 96 DISALLOW_COPY_AND_ASSIGN(GpuInProcessThread);
89 }; 97 };
90 98
91 GpuInProcessThread::GpuInProcessThread() : base::Thread("GpuThread") { 99 GpuInProcessThread::GpuInProcessThread()
100 : base::Thread("GpuThread"), idle_post_pending_(false) {
92 Start(); 101 Start();
93 } 102 }
94 103
95 GpuInProcessThread::~GpuInProcessThread() { 104 GpuInProcessThread::~GpuInProcessThread() {
96 Stop(); 105 Stop();
97 } 106 }
98 107
99 void GpuInProcessThread::ScheduleTask(const base::Closure& task) { 108 void GpuInProcessThread::ScheduleTask(const base::Closure& task) {
100 message_loop()->PostTask(FROM_HERE, task); 109 message_loop()->PostTask(FROM_HERE, task);
no sievers 2015/01/13 21:00:00 Should this also change then and have its own queu
boliu 2015/01/13 22:07:23 I think we get this behavior with the current code
101 } 110 }
102 111
103 void GpuInProcessThread::ScheduleIdleWork(const base::Closure& callback) { 112 void GpuInProcessThread::ScheduleIdleWork(const base::Closure& callback) {
104 message_loop()->PostDelayedTask( 113 base::AutoLock lock(lock_);
105 FROM_HERE, callback, base::TimeDelta::FromMilliseconds(5)); 114 pending_idle_tasks_.push(callback);
115 CheckIdleTasksLocked();
116 }
117
118 void GpuInProcessThread::CheckIdleTasksLocked() {
119 lock_.AssertAcquired();
120 if (pending_idle_tasks_.size() && !idle_post_pending_) {
121 idle_post_pending_ = true;
122 message_loop()->PostTask(
123 FROM_HERE, base::Bind(&GpuInProcessThread::RunIdleTask, this));
124 }
125 }
126
127 void GpuInProcessThread::RunIdleTask() {
128 base::Closure idle_task;
129 base::AutoLock lock(lock_);
130 idle_post_pending_ = false;
131 DCHECK(pending_idle_tasks_.size());
132 idle_task = pending_idle_tasks_.front();
133 pending_idle_tasks_.pop();
134
135 {
136 base::AutoUnlock unlock(lock_);
137 idle_task.Run();
138 }
139
140 CheckIdleTasksLocked();
106 } 141 }
107 142
108 scoped_refptr<gles2::ShaderTranslatorCache> 143 scoped_refptr<gles2::ShaderTranslatorCache>
109 GpuInProcessThread::shader_translator_cache() { 144 GpuInProcessThread::shader_translator_cache() {
110 if (!shader_translator_cache_.get()) 145 if (!shader_translator_cache_.get())
111 shader_translator_cache_ = new gpu::gles2::ShaderTranslatorCache; 146 shader_translator_cache_ = new gpu::gles2::ShaderTranslatorCache;
112 return shader_translator_cache_; 147 return shader_translator_cache_;
113 } 148 }
114 149
115 struct GpuInProcessThreadHolder { 150 struct GpuInProcessThreadHolder {
(...skipping 829 matching lines...) Expand 10 before | Expand all | Expand 10 after
945 980
946 #if defined(OS_ANDROID) 981 #if defined(OS_ANDROID)
947 scoped_refptr<gfx::SurfaceTexture> 982 scoped_refptr<gfx::SurfaceTexture>
948 InProcessCommandBuffer::GetSurfaceTexture(uint32 stream_id) { 983 InProcessCommandBuffer::GetSurfaceTexture(uint32 stream_id) {
949 DCHECK(stream_texture_manager_); 984 DCHECK(stream_texture_manager_);
950 return stream_texture_manager_->GetSurfaceTexture(stream_id); 985 return stream_texture_manager_->GetSurfaceTexture(stream_id);
951 } 986 }
952 #endif 987 #endif
953 988
954 } // namespace gpu 989 } // namespace gpu
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698