| 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" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 #include "ui/gl/gl_context.h" | 30 #include "ui/gl/gl_context.h" |
| 31 #include "ui/gl/gl_image_shared_memory.h" | 31 #include "ui/gl/gl_image_shared_memory.h" |
| 32 #include "ui/gl/gl_surface.h" | 32 #include "ui/gl/gl_surface.h" |
| 33 | 33 |
| 34 namespace gles2 { | 34 namespace gles2 { |
| 35 | 35 |
| 36 CommandBufferDriver::Client::~Client() { | 36 CommandBufferDriver::Client::~Client() { |
| 37 } | 37 } |
| 38 | 38 |
| 39 CommandBufferDriver::CommandBufferDriver(scoped_refptr<GpuState> gpu_state) | 39 CommandBufferDriver::CommandBufferDriver(scoped_refptr<GpuState> gpu_state) |
| 40 : CommandBufferDriver(gfx::kNullAcceleratedWidget, | |
| 41 gpu_state, | |
| 42 base::Callback<void(CommandBufferDriver*)>()) {} | |
| 43 | |
| 44 CommandBufferDriver::CommandBufferDriver( | |
| 45 gfx::AcceleratedWidget widget, | |
| 46 scoped_refptr<GpuState> gpu_state, | |
| 47 const base::Callback<void(CommandBufferDriver*)>& destruct_callback) | |
| 48 : client_(nullptr), | 40 : client_(nullptr), |
| 49 widget_(widget), | |
| 50 gpu_state_(gpu_state), | 41 gpu_state_(gpu_state), |
| 51 destruct_callback_(destruct_callback), | |
| 52 weak_factory_(this) { | 42 weak_factory_(this) { |
| 53 } | 43 } |
| 54 | 44 |
| 55 CommandBufferDriver::~CommandBufferDriver() { | 45 CommandBufferDriver::~CommandBufferDriver() { |
| 56 DestroyDecoder(); | 46 DestroyDecoder(); |
| 57 if (!destruct_callback_.is_null()) | |
| 58 destruct_callback_.Run(this); | |
| 59 } | 47 } |
| 60 | 48 |
| 61 void CommandBufferDriver::Initialize( | 49 void CommandBufferDriver::Initialize( |
| 62 mojo::CommandBufferSyncClientPtr sync_client, | 50 mojo::CommandBufferSyncClientPtr sync_client, |
| 63 mojo::CommandBufferLostContextObserverPtr loss_observer, | 51 mojo::CommandBufferLostContextObserverPtr loss_observer, |
| 64 mojo::ScopedSharedBufferHandle shared_state) { | 52 mojo::ScopedSharedBufferHandle shared_state) { |
| 65 sync_client_ = sync_client.Pass(); | 53 sync_client_ = sync_client.Pass(); |
| 66 loss_observer_ = loss_observer.Pass(); | 54 loss_observer_ = loss_observer.Pass(); |
| 67 bool success = DoInitialize(shared_state.Pass()); | 55 bool success = DoInitialize(shared_state.Pass()); |
| 68 mojo::GpuCapabilitiesPtr capabilities = | 56 mojo::GpuCapabilitiesPtr capabilities = |
| (...skipping 12 matching lines...) Expand all Loading... |
| 81 static_cast<gpu::error::ContextLostReason>( | 69 static_cast<gpu::error::ContextLostReason>( |
| 82 decoder_->GetContextLostReason()); | 70 decoder_->GetContextLostReason()); |
| 83 command_buffer_->SetContextLostReason(reason); | 71 command_buffer_->SetContextLostReason(reason); |
| 84 command_buffer_->SetParseError(gpu::error::kLostContext); | 72 command_buffer_->SetParseError(gpu::error::kLostContext); |
| 85 OnContextLost(reason); | 73 OnContextLost(reason); |
| 86 return false; | 74 return false; |
| 87 } | 75 } |
| 88 | 76 |
| 89 bool CommandBufferDriver::DoInitialize( | 77 bool CommandBufferDriver::DoInitialize( |
| 90 mojo::ScopedSharedBufferHandle shared_state) { | 78 mojo::ScopedSharedBufferHandle shared_state) { |
| 91 if (widget_ == gfx::kNullAcceleratedWidget) | 79 surface_ = gfx::GLSurface::CreateOffscreenGLSurface(gfx::Size(1, 1)); |
| 92 surface_ = gfx::GLSurface::CreateOffscreenGLSurface(gfx::Size(1, 1)); | |
| 93 else { | |
| 94 surface_ = gfx::GLSurface::CreateViewGLSurface(widget_); | |
| 95 if (auto vsync_provider = surface_->GetVSyncProvider()) { | |
| 96 vsync_provider->GetVSyncParameters( | |
| 97 base::Bind(&CommandBufferDriver::OnUpdateVSyncParameters, | |
| 98 weak_factory_.GetWeakPtr())); | |
| 99 } | |
| 100 } | |
| 101 | 80 |
| 102 if (!surface_.get()) | 81 if (!surface_.get()) |
| 103 return false; | 82 return false; |
| 104 | 83 |
| 105 // TODO(piman): virtual contexts, gpu preference. | 84 // TODO(piman): virtual contexts, gpu preference. |
| 106 context_ = gfx::GLContext::CreateGLContext( | 85 context_ = gfx::GLContext::CreateGLContext( |
| 107 gpu_state_->share_group(), surface_.get(), gfx::PreferIntegratedGpu); | 86 gpu_state_->share_group(), surface_.get(), gfx::PreferIntegratedGpu); |
| 108 if (!context_.get()) | 87 if (!context_.get()) |
| 109 return false; | 88 return false; |
| 110 | 89 |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 if (!context_) | 149 if (!context_) |
| 171 return; | 150 return; |
| 172 if (!context_->MakeCurrent(surface_.get())) { | 151 if (!context_->MakeCurrent(surface_.get())) { |
| 173 DLOG(WARNING) << "Context lost"; | 152 DLOG(WARNING) << "Context lost"; |
| 174 OnContextLost(gpu::error::kUnknown); | 153 OnContextLost(gpu::error::kUnknown); |
| 175 return; | 154 return; |
| 176 } | 155 } |
| 177 command_buffer_->Flush(put_offset); | 156 command_buffer_->Flush(put_offset); |
| 178 } | 157 } |
| 179 | 158 |
| 180 void CommandBufferDriver::DestroyWindow() { | |
| 181 DestroyDecoder(); | |
| 182 surface_ = nullptr; | |
| 183 context_ = nullptr; | |
| 184 destruct_callback_.Reset(); | |
| 185 } | |
| 186 | |
| 187 void CommandBufferDriver::MakeProgress(int32_t last_get_offset) { | 159 void CommandBufferDriver::MakeProgress(int32_t last_get_offset) { |
| 188 // TODO(piman): handle out-of-order. | 160 // TODO(piman): handle out-of-order. |
| 189 sync_client_->DidMakeProgress( | 161 sync_client_->DidMakeProgress( |
| 190 mojo::CommandBufferState::From(command_buffer_->GetLastState())); | 162 mojo::CommandBufferState::From(command_buffer_->GetLastState())); |
| 191 } | 163 } |
| 192 | 164 |
| 193 void CommandBufferDriver::RegisterTransferBuffer( | 165 void CommandBufferDriver::RegisterTransferBuffer( |
| 194 int32_t id, | 166 int32_t id, |
| 195 mojo::ScopedSharedBufferHandle transfer_buffer, | 167 mojo::ScopedSharedBufferHandle transfer_buffer, |
| 196 uint32_t size) { | 168 uint32_t size) { |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 318 | 290 |
| 319 void CommandBufferDriver::OnSyncPointRetired() { | 291 void CommandBufferDriver::OnSyncPointRetired() { |
| 320 scheduler_->SetScheduled(true); | 292 scheduler_->SetScheduled(true); |
| 321 } | 293 } |
| 322 | 294 |
| 323 void CommandBufferDriver::OnContextLost(uint32_t reason) { | 295 void CommandBufferDriver::OnContextLost(uint32_t reason) { |
| 324 loss_observer_->DidLoseContext(reason); | 296 loss_observer_->DidLoseContext(reason); |
| 325 client_->DidLoseContext(); | 297 client_->DidLoseContext(); |
| 326 } | 298 } |
| 327 | 299 |
| 328 void CommandBufferDriver::OnUpdateVSyncParameters( | |
| 329 const base::TimeTicks timebase, | |
| 330 const base::TimeDelta interval) { | |
| 331 client_->UpdateVSyncParameters(timebase, interval); | |
| 332 } | |
| 333 | |
| 334 void CommandBufferDriver::DestroyDecoder() { | 300 void CommandBufferDriver::DestroyDecoder() { |
| 335 if (decoder_) { | 301 if (decoder_) { |
| 336 bool have_context = decoder_->MakeCurrent(); | 302 bool have_context = decoder_->MakeCurrent(); |
| 337 decoder_->Destroy(have_context); | 303 decoder_->Destroy(have_context); |
| 338 decoder_.reset(); | 304 decoder_.reset(); |
| 339 } | 305 } |
| 340 } | 306 } |
| 341 | 307 |
| 342 } // namespace gles2 | 308 } // namespace gles2 |
| OLD | NEW |