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

Side by Side Diff: content/common/gpu/client/command_buffer_proxy_impl.cc

Issue 654223006: Cleanup GpuMemoryBuffer (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "content/common/gpu/client/command_buffer_proxy_impl.h" 5 #include "content/common/gpu/client/command_buffer_proxy_impl.h"
6 6
7 #include "base/callback.h" 7 #include "base/callback.h"
8 #include "base/debug/trace_event.h" 8 #include "base/debug/trace_event.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/memory/shared_memory.h" 10 #include "base/memory/shared_memory.h"
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 NOTREACHED(); 75 NOTREACHED();
76 return false; 76 return false;
77 default: 77 default:
78 NOTREACHED(); 78 NOTREACHED();
79 return false; 79 return false;
80 } 80 }
81 } 81 }
82 82
83 } // namespace 83 } // namespace
84 84
85 CommandBufferProxyImpl::CommandBufferProxyImpl( 85 CommandBufferProxyImpl::CommandBufferProxyImpl(GpuChannelHost* channel,
86 GpuChannelHost* channel, 86 int route_id)
87 int route_id)
88 : channel_(channel), 87 : channel_(channel),
89 route_id_(route_id), 88 route_id_(route_id),
90 flush_count_(0), 89 flush_count_(0),
91 last_put_offset_(-1), 90 last_put_offset_(-1),
92 next_signal_id_(0) { 91 next_signal_id_(0),
92 main_loop_proxy_(base::MessageLoopProxy::current()),
93 tracker_(new GpuMemoryBufferUsageTracker) {
93 } 94 }
94 95
95 CommandBufferProxyImpl::~CommandBufferProxyImpl() { 96 CommandBufferProxyImpl::~CommandBufferProxyImpl() {
96 FOR_EACH_OBSERVER(DeletionObserver, 97 FOR_EACH_OBSERVER(DeletionObserver,
97 deletion_observers_, 98 deletion_observers_,
98 OnWillDeleteImpl()); 99 OnWillDeleteImpl());
99 } 100 }
100 101
101 bool CommandBufferProxyImpl::OnMessageReceived(const IPC::Message& message) { 102 bool CommandBufferProxyImpl::OnMessageReceived(const IPC::Message& message) {
102 bool handled = true; 103 bool handled = true;
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 const std::vector<ui::LatencyInfo>& latency_info) { 253 const std::vector<ui::LatencyInfo>& latency_info) {
253 for (size_t i = 0; i < latency_info.size(); i++) 254 for (size_t i = 0; i < latency_info.size(); i++)
254 latency_info_.push_back(latency_info[i]); 255 latency_info_.push_back(latency_info[i]);
255 } 256 }
256 257
257 void CommandBufferProxyImpl::SetSwapBuffersCompletionCallback( 258 void CommandBufferProxyImpl::SetSwapBuffersCompletionCallback(
258 const SwapBuffersCompletionCallback& callback) { 259 const SwapBuffersCompletionCallback& callback) {
259 swap_buffers_completion_callback_ = callback; 260 swap_buffers_completion_callback_ = callback;
260 } 261 }
261 262
263 CommandBufferProxyImpl::CallbackMessageLoopPair::CallbackMessageLoopPair(
264 const base::Closure& callback,
265 scoped_refptr<base::MessageLoopProxy> message_loop)
266 : callback(callback), message_loop(message_loop) {
267 }
268
269 CommandBufferProxyImpl::CallbackMessageLoopPair::~CallbackMessageLoopPair() {
270 }
271
272 CommandBufferProxyImpl::GpuMemoryBufferUsageTracker::
273 GpuMemoryBufferUsageTracker()
274 : next_gpu_memory_buffer_usage_id_(0) {
275 }
276
277 void CommandBufferProxyImpl::GpuMemoryBufferUsageTracker::OnWillDeleteImpl() {
278 base::AutoLock lock(gpu_memory_buffer_task_lock_);
279 GpuMemoryBufferUsageCompletedMap::iterator it =
280 gpu_memory_buffer_tasks_.begin();
281 for (; it != gpu_memory_buffer_tasks_.end(); it++) {
282 it->second.message_loop->PostTask(
283 FROM_HERE,
284 base::Bind(&CommandBufferProxyImpl::GpuMemoryBufferUsageTracker::
285 UsageCompletedOnCaller,
286 this,
287 it->first));
288 }
289 }
290
291 uint32 CommandBufferProxyImpl::GpuMemoryBufferUsageTracker::AddUsage(
292 const CallbackMessageLoopPair& task) {
293 base::AutoLock lock(gpu_memory_buffer_task_lock_);
294 uint32 usage_id = next_gpu_memory_buffer_usage_id_++;
295
296 gpu_memory_buffer_tasks_.insert(std::make_pair(usage_id, task));
297 return usage_id;
298 }
299
300 void CommandBufferProxyImpl::GpuMemoryBufferUsageTracker::UsageCompleted(
301 uint32 task_id) {
302 base::AutoLock lock(gpu_memory_buffer_task_lock_);
303 GpuMemoryBufferUsageCompletedMap::iterator it =
304 gpu_memory_buffer_tasks_.find(task_id);
305 DCHECK(it != gpu_memory_buffer_tasks_.end());
306 it->second.message_loop->PostTask(
307 FROM_HERE,
308 base::Bind(&CommandBufferProxyImpl::GpuMemoryBufferUsageTracker::
309 UsageCompletedOnCaller,
310 this,
311 task_id));
312 }
313
314 CommandBufferProxyImpl::GpuMemoryBufferUsageTracker::
315 ~GpuMemoryBufferUsageTracker() {
316 }
317
318 void
319 CommandBufferProxyImpl::GpuMemoryBufferUsageTracker::UsageCompletedOnCaller(
320 uint32 task_id) {
321 base::Closure callback;
322 {
323 base::AutoLock lock(gpu_memory_buffer_task_lock_);
324 GpuMemoryBufferUsageCompletedMap::iterator it =
325 gpu_memory_buffer_tasks_.find(task_id);
326 DCHECK(it != gpu_memory_buffer_tasks_.end());
327
328 callback = it->second.callback;
329 gpu_memory_buffer_tasks_.erase(it);
330 }
331 callback.Run();
332 }
333
334 void CommandBufferProxyImpl::WaitForPendingGpuMemoryBufferUsageToComplete(
335 const base::Closure& callback) {
336 uint32 usage_id = tracker_->AddUsage(
337 CallbackMessageLoopPair(callback, base::MessageLoopProxy::current()));
338
339 main_loop_proxy_->PostTask(
340 FROM_HERE,
341 base::Bind(&CommandBufferProxyImpl::
342 WaitForPendingGpuMemoryBufferUsageToCompleteOnMain,
343 base::Unretained(this),
344 usage_id));
345 }
346
347 void CommandBufferProxyImpl::WaitForPendingGpuMemoryBufferUsageToCompleteOnMain(
348 uint32 usage_id) {
349 SignalSyncPoint(
350 InsertSyncPoint(),
351 base::Bind(
352 &CommandBufferProxyImpl::GpuMemoryBufferUsageTracker::UsageCompleted,
353 tracker_,
354 usage_id));
355 }
356
262 void CommandBufferProxyImpl::WaitForTokenInRange(int32 start, int32 end) { 357 void CommandBufferProxyImpl::WaitForTokenInRange(int32 start, int32 end) {
263 TRACE_EVENT2("gpu", 358 TRACE_EVENT2("gpu",
264 "CommandBufferProxyImpl::WaitForToken", 359 "CommandBufferProxyImpl::WaitForToken",
265 "start", 360 "start",
266 start, 361 start,
267 "end", 362 "end",
268 end); 363 end);
269 TryUpdateState(); 364 TryUpdateState();
270 if (!InRange(start, end, last_state_.token) && 365 if (!InRange(start, end, last_state_.token) &&
271 last_state_.error == gpu::error::kNoError) { 366 last_state_.error == gpu::error::kNoError) {
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after
582 if (!ui::LatencyInfo::Verify( 677 if (!ui::LatencyInfo::Verify(
583 latency_info, "CommandBufferProxyImpl::OnSwapBuffersCompleted")) { 678 latency_info, "CommandBufferProxyImpl::OnSwapBuffersCompleted")) {
584 swap_buffers_completion_callback_.Run(std::vector<ui::LatencyInfo>()); 679 swap_buffers_completion_callback_.Run(std::vector<ui::LatencyInfo>());
585 return; 680 return;
586 } 681 }
587 swap_buffers_completion_callback_.Run(latency_info); 682 swap_buffers_completion_callback_.Run(latency_info);
588 } 683 }
589 } 684 }
590 685
591 } // namespace content 686 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698