| 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_memory_tracker.h" |
| 11 #include "components/view_manager/gles2/gpu_state.h" | 12 #include "components/view_manager/gles2/gpu_state.h" |
| 12 #include "components/view_manager/gles2/mojo_buffer_backing.h" | 13 #include "components/view_manager/gles2/mojo_buffer_backing.h" |
| 13 #include "gpu/command_buffer/common/constants.h" | 14 #include "gpu/command_buffer/common/constants.h" |
| 14 #include "gpu/command_buffer/common/value_state.h" | 15 #include "gpu/command_buffer/common/value_state.h" |
| 15 #include "gpu/command_buffer/service/command_buffer_service.h" | 16 #include "gpu/command_buffer/service/command_buffer_service.h" |
| 16 #include "gpu/command_buffer/service/context_group.h" | 17 #include "gpu/command_buffer/service/context_group.h" |
| 17 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" | 18 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" |
| 18 #include "gpu/command_buffer/service/gpu_scheduler.h" | 19 #include "gpu/command_buffer/service/gpu_scheduler.h" |
| 19 #include "gpu/command_buffer/service/image_factory.h" | 20 #include "gpu/command_buffer/service/image_factory.h" |
| 20 #include "gpu/command_buffer/service/image_manager.h" | 21 #include "gpu/command_buffer/service/image_manager.h" |
| 21 #include "gpu/command_buffer/service/mailbox_manager.h" | 22 #include "gpu/command_buffer/service/mailbox_manager.h" |
| 22 #include "gpu/command_buffer/service/memory_tracking.h" | 23 #include "gpu/command_buffer/service/memory_tracking.h" |
| 23 #include "gpu/command_buffer/service/sync_point_manager.h" | 24 #include "gpu/command_buffer/service/sync_point_manager.h" |
| 24 #include "gpu/command_buffer/service/valuebuffer_manager.h" | 25 #include "gpu/command_buffer/service/valuebuffer_manager.h" |
| 25 #include "mojo/converters/geometry/geometry_type_converters.h" | 26 #include "mojo/converters/geometry/geometry_type_converters.h" |
| 26 #include "mojo/platform_handle/platform_handle_functions.h" | 27 #include "mojo/platform_handle/platform_handle_functions.h" |
| 27 #include "ui/gfx/gpu_memory_buffer.h" | 28 #include "ui/gfx/gpu_memory_buffer.h" |
| 28 #include "ui/gfx/vsync_provider.h" | 29 #include "ui/gfx/vsync_provider.h" |
| 29 #include "ui/gl/gl_context.h" | 30 #include "ui/gl/gl_context.h" |
| 30 #include "ui/gl/gl_image_shared_memory.h" | 31 #include "ui/gl/gl_image_shared_memory.h" |
| 31 #include "ui/gl/gl_surface.h" | 32 #include "ui/gl/gl_surface.h" |
| 32 | 33 |
| 33 namespace gles2 { | 34 namespace gles2 { |
| 34 | 35 |
| 35 namespace { | |
| 36 | |
| 37 class MemoryTrackerStub : public gpu::gles2::MemoryTracker { | |
| 38 public: | |
| 39 MemoryTrackerStub() {} | |
| 40 | |
| 41 void TrackMemoryAllocatedChange( | |
| 42 size_t old_size, | |
| 43 size_t new_size, | |
| 44 gpu::gles2::MemoryTracker::Pool pool) override {} | |
| 45 | |
| 46 bool EnsureGPUMemoryAvailable(size_t size_needed) override { return true; }; | |
| 47 uint64_t ClientTracingId() const override { return 0; } | |
| 48 int ClientId() const override { return 0; } | |
| 49 | |
| 50 private: | |
| 51 ~MemoryTrackerStub() override {} | |
| 52 | |
| 53 DISALLOW_COPY_AND_ASSIGN(MemoryTrackerStub); | |
| 54 }; | |
| 55 | |
| 56 } // anonymous namespace | |
| 57 | |
| 58 CommandBufferDriver::Client::~Client() { | 36 CommandBufferDriver::Client::~Client() { |
| 59 } | 37 } |
| 60 | 38 |
| 61 CommandBufferDriver::CommandBufferDriver(scoped_refptr<GpuState> gpu_state) | 39 CommandBufferDriver::CommandBufferDriver(scoped_refptr<GpuState> gpu_state) |
| 62 : CommandBufferDriver(gfx::kNullAcceleratedWidget, | 40 : CommandBufferDriver(gfx::kNullAcceleratedWidget, |
| 63 gpu_state, | 41 gpu_state, |
| 64 base::Callback<void(CommandBufferDriver*)>()) {} | 42 base::Callback<void(CommandBufferDriver*)>()) {} |
| 65 | 43 |
| 66 CommandBufferDriver::CommandBufferDriver( | 44 CommandBufferDriver::CommandBufferDriver( |
| 67 gfx::AcceleratedWidget widget, | 45 gfx::AcceleratedWidget widget, |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 static_cast<gpu::error::ContextLostReason>( | 81 static_cast<gpu::error::ContextLostReason>( |
| 104 decoder_->GetContextLostReason()); | 82 decoder_->GetContextLostReason()); |
| 105 command_buffer_->SetContextLostReason(reason); | 83 command_buffer_->SetContextLostReason(reason); |
| 106 command_buffer_->SetParseError(gpu::error::kLostContext); | 84 command_buffer_->SetParseError(gpu::error::kLostContext); |
| 107 OnContextLost(reason); | 85 OnContextLost(reason); |
| 108 return false; | 86 return false; |
| 109 } | 87 } |
| 110 | 88 |
| 111 bool CommandBufferDriver::DoInitialize( | 89 bool CommandBufferDriver::DoInitialize( |
| 112 mojo::ScopedSharedBufferHandle shared_state) { | 90 mojo::ScopedSharedBufferHandle shared_state) { |
| 113 if (widget_ == gfx::kNullAcceleratedWidget) | 91 if (widget_ == gfx::kNullAcceleratedWidget) { |
| 114 surface_ = gfx::GLSurface::CreateOffscreenGLSurface(gfx::Size(1, 1)); | 92 surface_ = gfx::GLSurface::CreateOffscreenGLSurface(gfx::Size(1, 1)); |
| 115 else { | 93 } else { |
| 116 surface_ = gfx::GLSurface::CreateViewGLSurface(widget_); | 94 surface_ = gfx::GLSurface::CreateViewGLSurface(widget_); |
| 117 if (auto vsync_provider = surface_->GetVSyncProvider()) { | |
| 118 vsync_provider->GetVSyncParameters( | |
| 119 base::Bind(&CommandBufferDriver::OnUpdateVSyncParameters, | |
| 120 weak_factory_.GetWeakPtr())); | |
| 121 } | |
| 122 } | 95 } |
| 123 | 96 |
| 124 if (!surface_.get()) | 97 if (!surface_.get()) |
| 125 return false; | 98 return false; |
| 126 | 99 |
| 127 // TODO(piman): virtual contexts, gpu preference. | 100 // TODO(piman): virtual contexts, gpu preference. |
| 128 context_ = gfx::GLContext::CreateGLContext( | 101 context_ = gfx::GLContext::CreateGLContext( |
| 129 gpu_state_->share_group(), surface_.get(), gfx::PreferIntegratedGpu); | 102 gpu_state_->share_group(), surface_.get(), gfx::PreferIntegratedGpu); |
| 130 if (!context_.get()) | 103 if (!context_.get()) |
| 131 return false; | 104 return false; |
| 132 | 105 |
| 133 if (!context_->MakeCurrent(surface_.get())) | 106 if (!context_->MakeCurrent(surface_.get())) |
| 134 return false; | 107 return false; |
| 135 | 108 |
| 136 // TODO(piman): ShaderTranslatorCache is currently per-ContextGroup but | 109 // TODO(piman): ShaderTranslatorCache is currently per-ContextGroup but |
| 137 // only needs to be per-thread. | 110 // only needs to be per-thread. |
| 138 bool bind_generates_resource = false; | 111 bool bind_generates_resource = false; |
| 139 scoped_refptr<gpu::gles2::ContextGroup> context_group = | 112 scoped_refptr<gpu::gles2::ContextGroup> context_group = |
| 140 new gpu::gles2::ContextGroup( | 113 new gpu::gles2::ContextGroup( |
| 141 gpu_state_->mailbox_manager(), new MemoryTrackerStub, | 114 gpu_state_->mailbox_manager(), new GpuMemoryTracker, |
| 142 new gpu::gles2::ShaderTranslatorCache, nullptr, nullptr, nullptr, | 115 new gpu::gles2::ShaderTranslatorCache, nullptr, nullptr, nullptr, |
| 143 bind_generates_resource); | 116 bind_generates_resource); |
| 144 | 117 |
| 145 command_buffer_.reset( | 118 command_buffer_.reset( |
| 146 new gpu::CommandBufferService(context_group->transfer_buffer_manager())); | 119 new gpu::CommandBufferService(context_group->transfer_buffer_manager())); |
| 147 bool result = command_buffer_->Initialize(); | 120 bool result = command_buffer_->Initialize(); |
| 148 DCHECK(result); | 121 DCHECK(result); |
| 149 | 122 |
| 150 decoder_.reset(::gpu::gles2::GLES2Decoder::Create(context_group.get())); | 123 decoder_.reset(::gpu::gles2::GLES2Decoder::Create(context_group.get())); |
| 151 scheduler_.reset(new gpu::GpuScheduler(command_buffer_.get(), decoder_.get(), | 124 scheduler_.reset(new gpu::GpuScheduler(command_buffer_.get(), decoder_.get(), |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 340 | 313 |
| 341 void CommandBufferDriver::OnSyncPointRetired() { | 314 void CommandBufferDriver::OnSyncPointRetired() { |
| 342 scheduler_->SetScheduled(true); | 315 scheduler_->SetScheduled(true); |
| 343 } | 316 } |
| 344 | 317 |
| 345 void CommandBufferDriver::OnContextLost(uint32_t reason) { | 318 void CommandBufferDriver::OnContextLost(uint32_t reason) { |
| 346 loss_observer_->DidLoseContext(reason); | 319 loss_observer_->DidLoseContext(reason); |
| 347 client_->DidLoseContext(); | 320 client_->DidLoseContext(); |
| 348 } | 321 } |
| 349 | 322 |
| 350 void CommandBufferDriver::OnUpdateVSyncParameters( | |
| 351 const base::TimeTicks timebase, | |
| 352 const base::TimeDelta interval) { | |
| 353 client_->UpdateVSyncParameters(timebase, interval); | |
| 354 } | |
| 355 | |
| 356 void CommandBufferDriver::DestroyDecoder() { | 323 void CommandBufferDriver::DestroyDecoder() { |
| 357 if (decoder_) { | 324 if (decoder_) { |
| 358 bool have_context = decoder_->MakeCurrent(); | 325 bool have_context = decoder_->MakeCurrent(); |
| 359 decoder_->Destroy(have_context); | 326 decoder_->Destroy(have_context); |
| 360 decoder_.reset(); | 327 decoder_.reset(); |
| 361 } | 328 } |
| 362 } | 329 } |
| 363 | 330 |
| 364 } // namespace gles2 | 331 } // namespace gles2 |
| OLD | NEW |