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

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

Issue 1641513004: Update //base to chromium 9659b08ea5a34f889dc4166217f438095ddc10d2 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 4 years, 10 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
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/async_pixel_transfer_manager_share_group.h" 5 #include "gpu/command_buffer/service/async_pixel_transfer_manager_share_group.h"
6 6
7 #include <list> 7 #include <list>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/lazy_instance.h" 10 #include "base/lazy_instance.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
13 #include "base/memory/weak_ptr.h" 13 #include "base/memory/weak_ptr.h"
14 #include "base/single_thread_task_runner.h"
14 #include "base/synchronization/cancellation_flag.h" 15 #include "base/synchronization/cancellation_flag.h"
15 #include "base/synchronization/lock.h" 16 #include "base/synchronization/lock.h"
16 #include "base/synchronization/waitable_event.h" 17 #include "base/synchronization/waitable_event.h"
17 #include "base/threading/thread.h" 18 #include "base/threading/thread.h"
18 #include "base/threading/thread_checker.h" 19 #include "base/threading/thread_checker.h"
19 #include "base/trace_event/trace_event.h" 20 #include "base/trace_event/trace_event.h"
20 #include "base/trace_event/trace_event_synthetic_delay.h" 21 #include "base/trace_event/trace_event_synthetic_delay.h"
21 #include "gpu/command_buffer/service/async_pixel_transfer_delegate.h" 22 #include "gpu/command_buffer/service/async_pixel_transfer_delegate.h"
22 #include "ui/gl/gl_bindings.h" 23 #include "ui/gl/gl_bindings.h"
23 #include "ui/gl/gl_context.h" 24 #include "ui/gl/gl_context.h"
(...skipping 14 matching lines...) Expand all
38 observer->DidComplete(mem_params); 39 observer->DidComplete(mem_params);
39 } 40 }
40 41
41 // TODO(backer): Factor out common thread scheduling logic from the EGL and 42 // TODO(backer): Factor out common thread scheduling logic from the EGL and
42 // ShareGroup implementations. http://crbug.com/239889 43 // ShareGroup implementations. http://crbug.com/239889
43 class TransferThread : public base::Thread { 44 class TransferThread : public base::Thread {
44 public: 45 public:
45 TransferThread() 46 TransferThread()
46 : base::Thread(kAsyncTransferThreadName), 47 : base::Thread(kAsyncTransferThreadName),
47 initialized_(false) { 48 initialized_(false) {
49 base::Thread::Options options;
48 Start(); 50 Start();
49 #if defined(OS_ANDROID) || defined(OS_LINUX) 51 #if defined(OS_ANDROID) || defined(OS_LINUX)
50 SetPriority(base::ThreadPriority::BACKGROUND); 52 options.priority = base::ThreadPriority::BACKGROUND;
51 #endif 53 #endif
54 StartWithOptions(options);
52 } 55 }
53 56
54 ~TransferThread() override { 57 ~TransferThread() override {
55 // The only instance of this class was declared leaky. 58 // The only instance of this class was declared leaky.
56 NOTREACHED(); 59 NOTREACHED();
57 } 60 }
58 61
59 void InitializeOnMainThread(gfx::GLContext* parent_context) { 62 void InitializeOnMainThread(gfx::GLContext* parent_context) {
60 TRACE_EVENT0("gpu", "TransferThread::InitializeOnMainThread"); 63 TRACE_EVENT0("gpu", "TransferThread::InitializeOnMainThread");
61 if (initialized_) 64 if (initialized_)
62 return; 65 return;
63 66
64 base::WaitableEvent wait_for_init(true, false); 67 base::WaitableEvent wait_for_init(true, false);
65 message_loop_proxy()->PostTask( 68 task_runner()->PostTask(
66 FROM_HERE, 69 FROM_HERE,
67 base::Bind(&TransferThread::InitializeOnTransferThread, 70 base::Bind(&TransferThread::InitializeOnTransferThread,
68 base::Unretained(this), 71 base::Unretained(this), base::Unretained(parent_context),
69 base::Unretained(parent_context), 72 &wait_for_init));
70 &wait_for_init));
71 wait_for_init.Wait(); 73 wait_for_init.Wait();
72 } 74 }
73 75
74 void CleanUp() override { 76 void CleanUp() override {
75 surface_ = NULL; 77 surface_ = NULL;
76 context_ = NULL; 78 context_ = NULL;
77 } 79 }
78 80
79 private: 81 private:
80 bool initialized_; 82 bool initialized_;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 initialized_ = true; 119 initialized_ = true;
118 caller_wait->Signal(); 120 caller_wait->Signal();
119 } 121 }
120 122
121 DISALLOW_COPY_AND_ASSIGN(TransferThread); 123 DISALLOW_COPY_AND_ASSIGN(TransferThread);
122 }; 124 };
123 125
124 base::LazyInstance<TransferThread>::Leaky 126 base::LazyInstance<TransferThread>::Leaky
125 g_transfer_thread = LAZY_INSTANCE_INITIALIZER; 127 g_transfer_thread = LAZY_INSTANCE_INITIALIZER;
126 128
127 base::MessageLoopProxy* transfer_message_loop_proxy() { 129 base::SingleThreadTaskRunner* transfer_task_runner() {
128 return g_transfer_thread.Pointer()->message_loop_proxy().get(); 130 return g_transfer_thread.Pointer()->task_runner().get();
129 } 131 }
130 132
131 class PendingTask : public base::RefCountedThreadSafe<PendingTask> { 133 class PendingTask : public base::RefCountedThreadSafe<PendingTask> {
132 public: 134 public:
133 explicit PendingTask(const base::Closure& task) 135 explicit PendingTask(const base::Closure& task)
134 : task_(task), task_pending_(true, false) {} 136 : task_(task), task_pending_(true, false) {}
135 137
136 bool TryRun() { 138 bool TryRun() {
137 // This is meant to be called on the main thread where the texture 139 // This is meant to be called on the main thread where the texture
138 // is already bound. 140 // is already bound.
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 const AsyncMemoryParams mem_params, 242 const AsyncMemoryParams mem_params,
241 scoped_refptr<AsyncPixelTransferUploadStats> texture_upload_stats, 243 scoped_refptr<AsyncPixelTransferUploadStats> texture_upload_stats,
242 const base::Closure& bind_callback) { 244 const base::Closure& bind_callback) {
243 TRACE_EVENT_SYNTHETIC_DELAY_BEGIN("gpu.AsyncTexImage"); 245 TRACE_EVENT_SYNTHETIC_DELAY_BEGIN("gpu.AsyncTexImage");
244 pending_upload_task_ = new PendingTask(base::Bind( 246 pending_upload_task_ = new PendingTask(base::Bind(
245 &TransferStateInternal::PerformAsyncTexImage2D, 247 &TransferStateInternal::PerformAsyncTexImage2D,
246 this, 248 this,
247 tex_params, 249 tex_params,
248 mem_params, 250 mem_params,
249 texture_upload_stats)); 251 texture_upload_stats));
250 transfer_message_loop_proxy()->PostTask( 252 transfer_task_runner()->PostTask(
251 FROM_HERE, 253 FROM_HERE, base::Bind(&PendingTask::BindAndRun, pending_upload_task_,
252 base::Bind( 254 texture_id_));
253 &PendingTask::BindAndRun, pending_upload_task_, texture_id_));
254 255
255 // Save the late bind callback, so we can notify the client when it is 256 // Save the late bind callback, so we can notify the client when it is
256 // bound. 257 // bound.
257 bind_callback_ = bind_callback; 258 bind_callback_ = bind_callback;
258 } 259 }
259 260
260 void ScheduleAsyncTexSubImage2D( 261 void ScheduleAsyncTexSubImage2D(
261 AsyncTexSubImage2DParams tex_params, 262 AsyncTexSubImage2DParams tex_params,
262 AsyncMemoryParams mem_params, 263 AsyncMemoryParams mem_params,
263 scoped_refptr<AsyncPixelTransferUploadStats> texture_upload_stats) { 264 scoped_refptr<AsyncPixelTransferUploadStats> texture_upload_stats) {
264 TRACE_EVENT_SYNTHETIC_DELAY_BEGIN("gpu.AsyncTexImage"); 265 TRACE_EVENT_SYNTHETIC_DELAY_BEGIN("gpu.AsyncTexImage");
265 pending_upload_task_ = new PendingTask(base::Bind( 266 pending_upload_task_ = new PendingTask(base::Bind(
266 &TransferStateInternal::PerformAsyncTexSubImage2D, 267 &TransferStateInternal::PerformAsyncTexSubImage2D,
267 this, 268 this,
268 tex_params, 269 tex_params,
269 mem_params, 270 mem_params,
270 texture_upload_stats)); 271 texture_upload_stats));
271 transfer_message_loop_proxy()->PostTask( 272 transfer_task_runner()->PostTask(
272 FROM_HERE, 273 FROM_HERE, base::Bind(&PendingTask::BindAndRun, pending_upload_task_,
273 base::Bind( 274 texture_id_));
274 &PendingTask::BindAndRun, pending_upload_task_, texture_id_));
275 } 275 }
276 276
277 private: 277 private:
278 friend class base::RefCountedThreadSafe<TransferStateInternal>; 278 friend class base::RefCountedThreadSafe<TransferStateInternal>;
279 279
280 virtual ~TransferStateInternal() { 280 virtual ~TransferStateInternal() {
281 } 281 }
282 282
283 void PerformAsyncTexImage2D( 283 void PerformAsyncTexImage2D(
284 AsyncTexImage2DParams tex_params, 284 AsyncTexImage2DParams tex_params,
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
499 499
500 shared_state_.pending_allocations.pop_front(); 500 shared_state_.pending_allocations.pop_front();
501 } 501 }
502 } 502 }
503 503
504 void AsyncPixelTransferManagerShareGroup::AsyncNotifyCompletion( 504 void AsyncPixelTransferManagerShareGroup::AsyncNotifyCompletion(
505 const AsyncMemoryParams& mem_params, 505 const AsyncMemoryParams& mem_params,
506 AsyncPixelTransferCompletionObserver* observer) { 506 AsyncPixelTransferCompletionObserver* observer) {
507 // Post a PerformNotifyCompletion task to the upload thread. This task 507 // Post a PerformNotifyCompletion task to the upload thread. This task
508 // will run after all async transfers are complete. 508 // will run after all async transfers are complete.
509 transfer_message_loop_proxy()->PostTask( 509 transfer_task_runner()->PostTask(
510 FROM_HERE, 510 FROM_HERE, base::Bind(&PerformNotifyCompletion, mem_params,
511 base::Bind(&PerformNotifyCompletion, 511 make_scoped_refptr(observer)));
512 mem_params,
513 make_scoped_refptr(observer)));
514 } 512 }
515 513
516 uint32 AsyncPixelTransferManagerShareGroup::GetTextureUploadCount() { 514 uint32 AsyncPixelTransferManagerShareGroup::GetTextureUploadCount() {
517 return shared_state_.texture_upload_stats->GetStats(NULL); 515 return shared_state_.texture_upload_stats->GetStats(NULL);
518 } 516 }
519 517
520 base::TimeDelta 518 base::TimeDelta
521 AsyncPixelTransferManagerShareGroup::GetTotalTextureUploadTime() { 519 AsyncPixelTransferManagerShareGroup::GetTotalTextureUploadTime() {
522 base::TimeDelta total_texture_upload_time; 520 base::TimeDelta total_texture_upload_time;
523 shared_state_.texture_upload_stats->GetStats(&total_texture_upload_time); 521 shared_state_.texture_upload_stats->GetStats(&total_texture_upload_time);
(...skipping 19 matching lines...) Expand all
543 541
544 AsyncPixelTransferDelegate* 542 AsyncPixelTransferDelegate*
545 AsyncPixelTransferManagerShareGroup::CreatePixelTransferDelegateImpl( 543 AsyncPixelTransferManagerShareGroup::CreatePixelTransferDelegateImpl(
546 gles2::TextureRef* ref, 544 gles2::TextureRef* ref,
547 const AsyncTexImage2DParams& define_params) { 545 const AsyncTexImage2DParams& define_params) {
548 return new AsyncPixelTransferDelegateShareGroup( 546 return new AsyncPixelTransferDelegateShareGroup(
549 &shared_state_, ref->service_id(), define_params); 547 &shared_state_, ref->service_id(), define_params);
550 } 548 }
551 549
552 } // namespace gpu 550 } // namespace gpu
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698