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

Side by Side Diff: components/mus/gles2/command_buffer_driver.cc

Issue 1460833002: gpu: Implement the new fence syncs in mojo command buffer. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update Created 5 years 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 "components/mus/gles2/command_buffer_driver.h" 5 #include "components/mus/gles2/command_buffer_driver.h"
6 6
7 #include "base/atomic_sequence_num.h"
7 #include "base/bind.h" 8 #include "base/bind.h"
8 #include "base/macros.h" 9 #include "base/macros.h"
9 #include "base/memory/shared_memory.h" 10 #include "base/memory/shared_memory.h"
10 #include "base/process/process_handle.h" 11 #include "base/process/process_handle.h"
11 #include "components/mus/gles2/command_buffer_type_conversions.h" 12 #include "components/mus/gles2/command_buffer_type_conversions.h"
12 #include "components/mus/gles2/gpu_memory_tracker.h" 13 #include "components/mus/gles2/gpu_memory_tracker.h"
13 #include "components/mus/gles2/gpu_state.h" 14 #include "components/mus/gles2/gpu_state.h"
14 #include "components/mus/gles2/mojo_buffer_backing.h" 15 #include "components/mus/gles2/mojo_buffer_backing.h"
15 #include "gpu/command_buffer/common/value_state.h" 16 #include "gpu/command_buffer/common/value_state.h"
16 #include "gpu/command_buffer/service/command_buffer_service.h" 17 #include "gpu/command_buffer/service/command_buffer_service.h"
(...skipping 11 matching lines...) Expand all
28 #include "mojo/platform_handle/platform_handle_functions.h" 29 #include "mojo/platform_handle/platform_handle_functions.h"
29 #include "ui/gfx/buffer_format_util.h" 30 #include "ui/gfx/buffer_format_util.h"
30 #include "ui/gfx/gpu_memory_buffer.h" 31 #include "ui/gfx/gpu_memory_buffer.h"
31 #include "ui/gfx/vsync_provider.h" 32 #include "ui/gfx/vsync_provider.h"
32 #include "ui/gl/gl_context.h" 33 #include "ui/gl/gl_context.h"
33 #include "ui/gl/gl_image_shared_memory.h" 34 #include "ui/gl/gl_image_shared_memory.h"
34 #include "ui/gl/gl_surface.h" 35 #include "ui/gl/gl_surface.h"
35 36
36 namespace mus { 37 namespace mus {
37 38
39 namespace {
40
41 base::StaticAtomicSequenceNumber g_next_command_buffer_id;
42
43 }
44
38 CommandBufferDriver::Client::~Client() {} 45 CommandBufferDriver::Client::~Client() {}
39 46
40 CommandBufferDriver::CommandBufferDriver(scoped_refptr<GpuState> gpu_state) 47 CommandBufferDriver::CommandBufferDriver(scoped_refptr<GpuState> gpu_state)
41 : client_(nullptr), gpu_state_(gpu_state), weak_factory_(this) {} 48 : command_buffer_id_(g_next_command_buffer_id.GetNext()),
49 client_(nullptr),
50 gpu_state_(gpu_state),
51 weak_factory_(this) {}
42 52
43 CommandBufferDriver::~CommandBufferDriver() { 53 CommandBufferDriver::~CommandBufferDriver() {
44 DestroyDecoder(); 54 DestroyDecoder();
45 } 55 }
46 56
47 void CommandBufferDriver::Initialize( 57 void CommandBufferDriver::Initialize(
48 mojo::InterfacePtrInfo<mojom::CommandBufferSyncClient> sync_client, 58 mojo::InterfacePtrInfo<mojom::CommandBufferSyncClient> sync_client,
49 mojo::InterfacePtrInfo<mojom::CommandBufferLostContextObserver> 59 mojo::InterfacePtrInfo<mojom::CommandBufferLostContextObserver>
50 loss_observer, 60 loss_observer,
51 mojo::ScopedSharedBufferHandle shared_state, 61 mojo::ScopedSharedBufferHandle shared_state,
52 mojo::Array<int32_t> attribs) { 62 mojo::Array<int32_t> attribs) {
53 sync_client_ = mojo::MakeProxy(sync_client.Pass()); 63 sync_client_ = mojo::MakeProxy(sync_client.Pass());
54 loss_observer_ = mojo::MakeProxy(loss_observer.Pass()); 64 loss_observer_ = mojo::MakeProxy(loss_observer.Pass());
55 bool success = DoInitialize(shared_state.Pass(), attribs.Pass()); 65 bool success = DoInitialize(shared_state.Pass(), attribs.Pass());
56 mojom::GpuCapabilitiesPtr capabilities = 66 mojom::GpuCapabilitiesPtr capabilities =
57 success ? mojom::GpuCapabilities::From(decoder_->GetCapabilities()) 67 success ? mojom::GpuCapabilities::From(decoder_->GetCapabilities())
58 : nullptr; 68 : nullptr;
59 sync_client_->DidInitialize(success, capabilities.Pass()); 69 sync_client_->DidInitialize(success,
70 gpu::CommandBufferNamespace::MOJO,
71 command_buffer_id_,
72 capabilities.Pass());
60 } 73 }
61 74
62 bool CommandBufferDriver::MakeCurrent() { 75 bool CommandBufferDriver::MakeCurrent() {
63 if (!decoder_) 76 if (!decoder_)
64 return false; 77 return false;
65 if (decoder_->MakeCurrent()) 78 if (decoder_->MakeCurrent())
66 return true; 79 return true;
67 DLOG(ERROR) << "Context lost because MakeCurrent failed."; 80 DLOG(ERROR) << "Context lost because MakeCurrent failed.";
68 gpu::error::ContextLostReason reason = 81 gpu::error::ContextLostReason reason =
69 static_cast<gpu::error::ContextLostReason>( 82 static_cast<gpu::error::ContextLostReason>(
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 nullptr, bind_generates_resource); 119 nullptr, bind_generates_resource);
107 120
108 command_buffer_.reset( 121 command_buffer_.reset(
109 new gpu::CommandBufferService(context_group->transfer_buffer_manager())); 122 new gpu::CommandBufferService(context_group->transfer_buffer_manager()));
110 bool result = command_buffer_->Initialize(); 123 bool result = command_buffer_->Initialize();
111 DCHECK(result); 124 DCHECK(result);
112 125
113 decoder_.reset(::gpu::gles2::GLES2Decoder::Create(context_group.get())); 126 decoder_.reset(::gpu::gles2::GLES2Decoder::Create(context_group.get()));
114 scheduler_.reset(new gpu::GpuScheduler(command_buffer_.get(), decoder_.get(), 127 scheduler_.reset(new gpu::GpuScheduler(command_buffer_.get(), decoder_.get(),
115 decoder_.get())); 128 decoder_.get()));
129 sync_point_order_data_ = gpu::SyncPointOrderData::Create();
130 sync_point_client_ = gpu_state_->sync_point_manager()->CreateSyncPointClient(
131 sync_point_order_data_, gpu::CommandBufferNamespace::MOJO,
132 command_buffer_id_);
116 decoder_->set_engine(scheduler_.get()); 133 decoder_->set_engine(scheduler_.get());
117 decoder_->SetWaitSyncPointCallback(base::Bind( 134 decoder_->SetWaitSyncPointCallback(base::Bind(
118 &CommandBufferDriver::OnWaitSyncPoint, base::Unretained(this))); 135 &CommandBufferDriver::OnWaitSyncPoint, base::Unretained(this)));
119 decoder_->SetFenceSyncReleaseCallback(base::Bind( 136 decoder_->SetFenceSyncReleaseCallback(base::Bind(
120 &CommandBufferDriver::OnFenceSyncRelease, base::Unretained(this))); 137 &CommandBufferDriver::OnFenceSyncRelease, base::Unretained(this)));
121 decoder_->SetWaitFenceSyncCallback(base::Bind( 138 decoder_->SetWaitFenceSyncCallback(base::Bind(
122 &CommandBufferDriver::OnWaitFenceSync, base::Unretained(this))); 139 &CommandBufferDriver::OnWaitFenceSync, base::Unretained(this)));
123 140
124 gpu::gles2::DisallowedFeatures disallowed_features; 141 gpu::gles2::DisallowedFeatures disallowed_features;
125 142
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 if (gpu_state_->sync_point_manager()->IsSyncPointRetired(sync_point)) 309 if (gpu_state_->sync_point_manager()->IsSyncPointRetired(sync_point))
293 return true; 310 return true;
294 scheduler_->SetScheduled(false); 311 scheduler_->SetScheduled(false);
295 gpu_state_->sync_point_manager()->AddSyncPointCallback( 312 gpu_state_->sync_point_manager()->AddSyncPointCallback(
296 sync_point, base::Bind(&CommandBufferDriver::OnSyncPointRetired, 313 sync_point, base::Bind(&CommandBufferDriver::OnSyncPointRetired,
297 weak_factory_.GetWeakPtr())); 314 weak_factory_.GetWeakPtr()));
298 return scheduler_->scheduled(); 315 return scheduler_->scheduled();
299 } 316 }
300 317
301 void CommandBufferDriver::OnFenceSyncRelease(uint64_t release) { 318 void CommandBufferDriver::OnFenceSyncRelease(uint64_t release) {
302 // TODO(dyen): Implement once CommandBufferID has been figured out and 319 if (!sync_point_client_->client_state()->IsFenceSyncReleased(release))
303 // we have a SyncPointClient. It would probably look like what is commented 320 sync_point_client_->ReleaseFenceSync(release);
304 // out below:
305 // if (!sync_point_client_->client_state()->IsFenceSyncReleased(release))
306 // sync_point_client_->ReleaseFenceSync(release);
307 NOTIMPLEMENTED();
308 } 321 }
309 322
310 bool CommandBufferDriver::OnWaitFenceSync( 323 bool CommandBufferDriver::OnWaitFenceSync(
311 gpu::CommandBufferNamespace namespace_id, 324 gpu::CommandBufferNamespace namespace_id,
312 uint64_t command_buffer_id, 325 uint64_t command_buffer_id,
313 uint64_t release) { 326 uint64_t release) {
314 gpu::SyncPointManager* sync_point_manager = gpu_state_->sync_point_manager(); 327 gpu::SyncPointManager* sync_point_manager = gpu_state_->sync_point_manager();
315 DCHECK(sync_point_manager); 328 DCHECK(sync_point_manager);
316 329
317 scoped_refptr<gpu::SyncPointClientState> release_state = 330 scoped_refptr<gpu::SyncPointClientState> release_state =
318 sync_point_manager->GetSyncPointClientState(namespace_id, 331 sync_point_manager->GetSyncPointClientState(namespace_id,
319 command_buffer_id); 332 command_buffer_id);
320 333
321 if (!release_state) 334 if (!release_state)
322 return true; 335 return true;
323 336
324 if (release_state->IsFenceSyncReleased(release)) 337 if (release_state->IsFenceSyncReleased(release))
325 return true; 338 return true;
326 339
327 // TODO(dyen): Implement once CommandBufferID has been figured out and 340
328 // we have a SyncPointClient. It would probably look like what is commented 341 scheduler_->SetScheduled(false);
329 // out below: 342 sync_point_client_->Wait(
330 // scheduler_->SetScheduled(false); 343 release_state.get(),
331 // sync_point_client_->Wait( 344 release,
332 // release_state.get(), 345 base::Bind(&CommandBufferDriver::OnSyncPointRetired,
333 // release, 346 weak_factory_.GetWeakPtr()));
334 // base::Bind(&CommandBufferDriver::OnSyncPointRetired,
335 // weak_factory_.GetWeakPtr()));
336 NOTIMPLEMENTED();
337 return scheduler_->scheduled(); 347 return scheduler_->scheduled();
338 } 348 }
339 349
340 void CommandBufferDriver::OnSyncPointRetired() { 350 void CommandBufferDriver::OnSyncPointRetired() {
341 scheduler_->SetScheduled(true); 351 scheduler_->SetScheduled(true);
342 gpu_state_->command_buffer_task_runner()->OnScheduled(this); 352 gpu_state_->command_buffer_task_runner()->OnScheduled(this);
343 } 353 }
344 354
345 void CommandBufferDriver::OnContextLost(uint32_t reason) { 355 void CommandBufferDriver::OnContextLost(uint32_t reason) {
346 loss_observer_->DidLoseContext(reason); 356 loss_observer_->DidLoseContext(reason);
347 client_->DidLoseContext(); 357 client_->DidLoseContext();
348 } 358 }
349 359
350 void CommandBufferDriver::DestroyDecoder() { 360 void CommandBufferDriver::DestroyDecoder() {
351 if (decoder_) { 361 if (decoder_) {
352 bool have_context = decoder_->MakeCurrent(); 362 bool have_context = decoder_->MakeCurrent();
353 decoder_->Destroy(have_context); 363 decoder_->Destroy(have_context);
354 decoder_.reset(); 364 decoder_.reset();
355 } 365 }
356 } 366 }
357 367
358 } // namespace mus 368 } // namespace mus
OLDNEW
« no previous file with comments | « components/mus/gles2/command_buffer_driver.h ('k') | components/mus/gles2/command_buffer_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698