OLD | NEW |
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/view_manager/gles2/command_buffer_driver.h" | 5 #include "components/view_manager/gles2/command_buffer_driver.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/macros.h" | 8 #include "base/macros.h" |
9 #include "base/memory/shared_memory.h" | 9 #include "base/memory/shared_memory.h" |
10 #include "components/view_manager/gles2/command_buffer_type_conversions.h" | 10 #include "components/view_manager/gles2/command_buffer_type_conversions.h" |
| 11 #include "components/view_manager/gles2/gpu_state.h" |
11 #include "components/view_manager/gles2/mojo_buffer_backing.h" | 12 #include "components/view_manager/gles2/mojo_buffer_backing.h" |
12 #include "gpu/command_buffer/common/constants.h" | 13 #include "gpu/command_buffer/common/constants.h" |
13 #include "gpu/command_buffer/common/value_state.h" | 14 #include "gpu/command_buffer/common/value_state.h" |
14 #include "gpu/command_buffer/service/command_buffer_service.h" | 15 #include "gpu/command_buffer/service/command_buffer_service.h" |
15 #include "gpu/command_buffer/service/context_group.h" | 16 #include "gpu/command_buffer/service/context_group.h" |
16 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" | 17 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" |
17 #include "gpu/command_buffer/service/gpu_scheduler.h" | 18 #include "gpu/command_buffer/service/gpu_scheduler.h" |
18 #include "gpu/command_buffer/service/image_factory.h" | 19 #include "gpu/command_buffer/service/image_factory.h" |
19 #include "gpu/command_buffer/service/image_manager.h" | 20 #include "gpu/command_buffer/service/image_manager.h" |
20 #include "gpu/command_buffer/service/mailbox_manager.h" | 21 #include "gpu/command_buffer/service/mailbox_manager.h" |
(...skipping 27 matching lines...) Expand all Loading... |
48 ~MemoryTrackerStub() override {} | 49 ~MemoryTrackerStub() override {} |
49 | 50 |
50 DISALLOW_COPY_AND_ASSIGN(MemoryTrackerStub); | 51 DISALLOW_COPY_AND_ASSIGN(MemoryTrackerStub); |
51 }; | 52 }; |
52 | 53 |
53 } // anonymous namespace | 54 } // anonymous namespace |
54 | 55 |
55 CommandBufferDriver::Client::~Client() { | 56 CommandBufferDriver::Client::~Client() { |
56 } | 57 } |
57 | 58 |
58 CommandBufferDriver::CommandBufferDriver( | 59 CommandBufferDriver::CommandBufferDriver(scoped_refptr<GpuState> gpu_state) |
59 gfx::GLShareGroup* share_group, | |
60 gpu::gles2::MailboxManager* mailbox_manager, | |
61 gpu::SyncPointManager* sync_point_manager) | |
62 : CommandBufferDriver(gfx::kNullAcceleratedWidget, | 60 : CommandBufferDriver(gfx::kNullAcceleratedWidget, |
63 share_group, | 61 gpu_state, |
64 mailbox_manager, | 62 base::Callback<void(CommandBufferDriver*)>()) {} |
65 sync_point_manager, | |
66 base::Callback<void(CommandBufferDriver*)>()) { | |
67 } | |
68 | 63 |
69 CommandBufferDriver::CommandBufferDriver( | 64 CommandBufferDriver::CommandBufferDriver( |
70 gfx::AcceleratedWidget widget, | 65 gfx::AcceleratedWidget widget, |
71 gfx::GLShareGroup* share_group, | 66 scoped_refptr<GpuState> gpu_state, |
72 gpu::gles2::MailboxManager* mailbox_manager, | |
73 gpu::SyncPointManager* sync_point_manager, | |
74 const base::Callback<void(CommandBufferDriver*)>& destruct_callback) | 67 const base::Callback<void(CommandBufferDriver*)>& destruct_callback) |
75 : client_(nullptr), | 68 : client_(nullptr), |
76 widget_(widget), | 69 widget_(widget), |
77 share_group_(share_group), | 70 gpu_state_(gpu_state), |
78 mailbox_manager_(mailbox_manager), | |
79 sync_point_manager_(sync_point_manager), | |
80 destruct_callback_(destruct_callback), | 71 destruct_callback_(destruct_callback), |
81 weak_factory_(this) { | 72 weak_factory_(this) { |
82 } | 73 } |
83 | 74 |
84 CommandBufferDriver::~CommandBufferDriver() { | 75 CommandBufferDriver::~CommandBufferDriver() { |
85 DestroyDecoder(); | 76 DestroyDecoder(); |
86 if (!destruct_callback_.is_null()) | 77 if (!destruct_callback_.is_null()) |
87 destruct_callback_.Run(this); | 78 destruct_callback_.Run(this); |
88 } | 79 } |
89 | 80 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 vsync_provider->GetVSyncParameters( | 116 vsync_provider->GetVSyncParameters( |
126 base::Bind(&CommandBufferDriver::OnUpdateVSyncParameters, | 117 base::Bind(&CommandBufferDriver::OnUpdateVSyncParameters, |
127 weak_factory_.GetWeakPtr())); | 118 weak_factory_.GetWeakPtr())); |
128 } | 119 } |
129 } | 120 } |
130 | 121 |
131 if (!surface_.get()) | 122 if (!surface_.get()) |
132 return false; | 123 return false; |
133 | 124 |
134 // TODO(piman): virtual contexts, gpu preference. | 125 // TODO(piman): virtual contexts, gpu preference. |
135 context_ = gfx::GLContext::CreateGLContext(share_group_.get(), surface_.get(), | 126 context_ = gfx::GLContext::CreateGLContext( |
136 gfx::PreferIntegratedGpu); | 127 gpu_state_->share_group(), surface_.get(), gfx::PreferIntegratedGpu); |
137 if (!context_.get()) | 128 if (!context_.get()) |
138 return false; | 129 return false; |
139 | 130 |
140 if (!context_->MakeCurrent(surface_.get())) | 131 if (!context_->MakeCurrent(surface_.get())) |
141 return false; | 132 return false; |
142 | 133 |
143 // TODO(piman): ShaderTranslatorCache is currently per-ContextGroup but | 134 // TODO(piman): ShaderTranslatorCache is currently per-ContextGroup but |
144 // only needs to be per-thread. | 135 // only needs to be per-thread. |
145 bool bind_generates_resource = false; | 136 bool bind_generates_resource = false; |
146 scoped_refptr<gpu::gles2::ContextGroup> context_group = | 137 scoped_refptr<gpu::gles2::ContextGroup> context_group = |
147 new gpu::gles2::ContextGroup( | 138 new gpu::gles2::ContextGroup( |
148 mailbox_manager_.get(), new MemoryTrackerStub, | 139 gpu_state_->mailbox_manager(), new MemoryTrackerStub, |
149 new gpu::gles2::ShaderTranslatorCache, nullptr, nullptr, nullptr, | 140 new gpu::gles2::ShaderTranslatorCache, nullptr, nullptr, nullptr, |
150 bind_generates_resource); | 141 bind_generates_resource); |
151 | 142 |
152 command_buffer_.reset( | 143 command_buffer_.reset( |
153 new gpu::CommandBufferService(context_group->transfer_buffer_manager())); | 144 new gpu::CommandBufferService(context_group->transfer_buffer_manager())); |
154 bool result = command_buffer_->Initialize(); | 145 bool result = command_buffer_->Initialize(); |
155 DCHECK(result); | 146 DCHECK(result); |
156 | 147 |
157 decoder_.reset(::gpu::gles2::GLES2Decoder::Create(context_group.get())); | 148 decoder_.reset(::gpu::gles2::GLES2Decoder::Create(context_group.get())); |
158 scheduler_.reset(new gpu::GpuScheduler(command_buffer_.get(), decoder_.get(), | 149 scheduler_.reset(new gpu::GpuScheduler(command_buffer_.get(), decoder_.get(), |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
330 OnContextLost(state.context_lost_reason); | 321 OnContextLost(state.context_lost_reason); |
331 } | 322 } |
332 | 323 |
333 void CommandBufferDriver::OnResize(gfx::Size size, float scale_factor) { | 324 void CommandBufferDriver::OnResize(gfx::Size size, float scale_factor) { |
334 surface_->Resize(size); | 325 surface_->Resize(size); |
335 } | 326 } |
336 | 327 |
337 bool CommandBufferDriver::OnWaitSyncPoint(uint32_t sync_point) { | 328 bool CommandBufferDriver::OnWaitSyncPoint(uint32_t sync_point) { |
338 if (!sync_point) | 329 if (!sync_point) |
339 return true; | 330 return true; |
340 if (sync_point_manager_->IsSyncPointRetired(sync_point)) | 331 if (gpu_state_->sync_point_manager()->IsSyncPointRetired(sync_point)) |
341 return true; | 332 return true; |
342 scheduler_->SetScheduled(false); | 333 scheduler_->SetScheduled(false); |
343 sync_point_manager_->AddSyncPointCallback( | 334 gpu_state_->sync_point_manager()->AddSyncPointCallback( |
344 sync_point, base::Bind(&CommandBufferDriver::OnSyncPointRetired, | 335 sync_point, base::Bind(&CommandBufferDriver::OnSyncPointRetired, |
345 weak_factory_.GetWeakPtr())); | 336 weak_factory_.GetWeakPtr())); |
346 return scheduler_->IsScheduled(); | 337 return scheduler_->IsScheduled(); |
347 } | 338 } |
348 | 339 |
349 void CommandBufferDriver::OnSyncPointRetired() { | 340 void CommandBufferDriver::OnSyncPointRetired() { |
350 scheduler_->SetScheduled(true); | 341 scheduler_->SetScheduled(true); |
351 } | 342 } |
352 | 343 |
353 void CommandBufferDriver::OnContextLost(uint32_t reason) { | 344 void CommandBufferDriver::OnContextLost(uint32_t reason) { |
354 loss_observer_->DidLoseContext(reason); | 345 loss_observer_->DidLoseContext(reason); |
355 client_->DidLoseContext(); | 346 client_->DidLoseContext(); |
356 } | 347 } |
357 | 348 |
358 void CommandBufferDriver::OnUpdateVSyncParameters( | 349 void CommandBufferDriver::OnUpdateVSyncParameters( |
359 const base::TimeTicks timebase, | 350 const base::TimeTicks timebase, |
360 const base::TimeDelta interval) { | 351 const base::TimeDelta interval) { |
361 client_->UpdateVSyncParameters(timebase, interval); | 352 client_->UpdateVSyncParameters(timebase, interval); |
362 } | 353 } |
363 | 354 |
364 void CommandBufferDriver::DestroyDecoder() { | 355 void CommandBufferDriver::DestroyDecoder() { |
365 if (decoder_) { | 356 if (decoder_) { |
366 bool have_context = decoder_->MakeCurrent(); | 357 bool have_context = decoder_->MakeCurrent(); |
367 decoder_->Destroy(have_context); | 358 decoder_->Destroy(have_context); |
368 decoder_.reset(); | 359 decoder_.reset(); |
369 } | 360 } |
370 } | 361 } |
371 | 362 |
372 } // namespace gles2 | 363 } // namespace gles2 |
OLD | NEW |