| 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 "services/gles2/command_buffer_driver.h" | 5 #include "services/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 "gpu/command_buffer/common/constants.h" | 10 #include "gpu/command_buffer/common/constants.h" |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 } // anonymous namespace | 48 } // anonymous namespace |
| 49 | 49 |
| 50 CommandBufferDriver::Client::~Client() { | 50 CommandBufferDriver::Client::~Client() { |
| 51 } | 51 } |
| 52 | 52 |
| 53 CommandBufferDriver::CommandBufferDriver( | 53 CommandBufferDriver::CommandBufferDriver( |
| 54 gfx::GLShareGroup* share_group, | 54 gfx::GLShareGroup* share_group, |
| 55 gpu::gles2::MailboxManager* mailbox_manager, | 55 gpu::gles2::MailboxManager* mailbox_manager, |
| 56 gpu::SyncPointManager* sync_point_manager) | 56 gpu::SyncPointManager* sync_point_manager) |
| 57 : CommandBufferDriver(gfx::kNullAcceleratedWidget, | 57 : CommandBufferDriver(gfx::kNullAcceleratedWidget, |
| 58 gfx::Size(1, 1), | |
| 59 share_group, | 58 share_group, |
| 60 mailbox_manager, | 59 mailbox_manager, |
| 61 sync_point_manager) { | 60 sync_point_manager) { |
| 62 } | 61 } |
| 63 | 62 |
| 64 CommandBufferDriver::CommandBufferDriver( | 63 CommandBufferDriver::CommandBufferDriver( |
| 65 gfx::AcceleratedWidget widget, | 64 gfx::AcceleratedWidget widget, |
| 66 const gfx::Size& size, | |
| 67 gfx::GLShareGroup* share_group, | 65 gfx::GLShareGroup* share_group, |
| 68 gpu::gles2::MailboxManager* mailbox_manager, | 66 gpu::gles2::MailboxManager* mailbox_manager, |
| 69 gpu::SyncPointManager* sync_point_manager) | 67 gpu::SyncPointManager* sync_point_manager) |
| 70 : client_(nullptr), | 68 : client_(nullptr), |
| 71 widget_(widget), | 69 widget_(widget), |
| 72 size_(size), | |
| 73 share_group_(share_group), | 70 share_group_(share_group), |
| 74 mailbox_manager_(mailbox_manager), | 71 mailbox_manager_(mailbox_manager), |
| 75 sync_point_manager_(sync_point_manager), | 72 sync_point_manager_(sync_point_manager), |
| 76 weak_factory_(this) { | 73 weak_factory_(this) { |
| 77 } | 74 } |
| 78 | 75 |
| 79 CommandBufferDriver::~CommandBufferDriver() { | 76 CommandBufferDriver::~CommandBufferDriver() { |
| 80 if (decoder_) { | 77 if (decoder_) { |
| 81 bool have_context = decoder_->MakeCurrent(); | 78 bool have_context = decoder_->MakeCurrent(); |
| 82 decoder_->Destroy(have_context); | 79 decoder_->Destroy(have_context); |
| 83 } | 80 } |
| 84 } | 81 } |
| 85 | 82 |
| 86 void CommandBufferDriver::Initialize( | 83 void CommandBufferDriver::Initialize( |
| 87 mojo::CommandBufferSyncClientPtr sync_client, | 84 mojo::CommandBufferSyncClientPtr sync_client, |
| 88 mojo::CommandBufferLostContextObserverPtr loss_observer, | 85 mojo::CommandBufferLostContextObserverPtr loss_observer, |
| 89 mojo::ScopedSharedBufferHandle shared_state) { | 86 mojo::ScopedSharedBufferHandle shared_state) { |
| 90 sync_client_ = sync_client.Pass(); | 87 sync_client_ = sync_client.Pass(); |
| 91 loss_observer_ = loss_observer.Pass(); | 88 loss_observer_ = loss_observer.Pass(); |
| 92 bool success = DoInitialize(shared_state.Pass()); | 89 bool success = DoInitialize(shared_state.Pass()); |
| 93 mojo::GpuCapabilitiesPtr capabilities = | 90 mojo::GpuCapabilitiesPtr capabilities = |
| 94 success ? mojo::GpuCapabilities::From(decoder_->GetCapabilities()) | 91 success ? mojo::GpuCapabilities::From(decoder_->GetCapabilities()) |
| 95 : mojo::GpuCapabilities::New(); | 92 : mojo::GpuCapabilities::New(); |
| 96 sync_client_->DidInitialize(success, capabilities.Pass()); | 93 sync_client_->DidInitialize(success, capabilities.Pass()); |
| 97 } | 94 } |
| 98 | 95 |
| 99 bool CommandBufferDriver::DoInitialize( | 96 bool CommandBufferDriver::DoInitialize( |
| 100 mojo::ScopedSharedBufferHandle shared_state) { | 97 mojo::ScopedSharedBufferHandle shared_state) { |
| 101 if (widget_ == gfx::kNullAcceleratedWidget) | 98 if (widget_ == gfx::kNullAcceleratedWidget) |
| 102 surface_ = gfx::GLSurface::CreateOffscreenGLSurface(size_); | 99 surface_ = gfx::GLSurface::CreateOffscreenGLSurface(gfx::Size(1, 1)); |
| 103 else { | 100 else { |
| 104 surface_ = gfx::GLSurface::CreateViewGLSurface(widget_); | 101 surface_ = gfx::GLSurface::CreateViewGLSurface(widget_); |
| 105 if (auto vsync_provider = surface_->GetVSyncProvider()) { | 102 if (auto vsync_provider = surface_->GetVSyncProvider()) { |
| 106 vsync_provider->GetVSyncParameters( | 103 vsync_provider->GetVSyncParameters( |
| 107 base::Bind(&CommandBufferDriver::OnUpdateVSyncParameters, | 104 base::Bind(&CommandBufferDriver::OnUpdateVSyncParameters, |
| 108 weak_factory_.GetWeakPtr())); | 105 weak_factory_.GetWeakPtr())); |
| 109 } | 106 } |
| 110 } | 107 } |
| 111 | 108 |
| 112 if (!surface_.get()) | 109 if (!surface_.get()) |
| (...skipping 28 matching lines...) Expand all Loading... |
| 141 decoder_->set_engine(scheduler_.get()); | 138 decoder_->set_engine(scheduler_.get()); |
| 142 decoder_->SetResizeCallback( | 139 decoder_->SetResizeCallback( |
| 143 base::Bind(&CommandBufferDriver::OnResize, base::Unretained(this))); | 140 base::Bind(&CommandBufferDriver::OnResize, base::Unretained(this))); |
| 144 decoder_->SetWaitSyncPointCallback(base::Bind( | 141 decoder_->SetWaitSyncPointCallback(base::Bind( |
| 145 &CommandBufferDriver::OnWaitSyncPoint, base::Unretained(this))); | 142 &CommandBufferDriver::OnWaitSyncPoint, base::Unretained(this))); |
| 146 | 143 |
| 147 gpu::gles2::DisallowedFeatures disallowed_features; | 144 gpu::gles2::DisallowedFeatures disallowed_features; |
| 148 | 145 |
| 149 // TODO(piman): attributes. | 146 // TODO(piman): attributes. |
| 150 std::vector<int32> attrib_vector; | 147 std::vector<int32> attrib_vector; |
| 151 if (!decoder_->Initialize(surface_, context_, false /* offscreen */, size_, | 148 if (!decoder_->Initialize(surface_, context_, false /* offscreen */, |
| 152 disallowed_features, attrib_vector)) | 149 gfx::Size(1, 1), disallowed_features, |
| 150 attrib_vector)) |
| 153 return false; | 151 return false; |
| 154 | 152 |
| 155 command_buffer_->SetPutOffsetChangeCallback(base::Bind( | 153 command_buffer_->SetPutOffsetChangeCallback(base::Bind( |
| 156 &gpu::GpuScheduler::PutChanged, base::Unretained(scheduler_.get()))); | 154 &gpu::GpuScheduler::PutChanged, base::Unretained(scheduler_.get()))); |
| 157 command_buffer_->SetGetBufferChangeCallback(base::Bind( | 155 command_buffer_->SetGetBufferChangeCallback(base::Bind( |
| 158 &gpu::GpuScheduler::SetGetBuffer, base::Unretained(scheduler_.get()))); | 156 &gpu::GpuScheduler::SetGetBuffer, base::Unretained(scheduler_.get()))); |
| 159 command_buffer_->SetParseErrorCallback( | 157 command_buffer_->SetParseErrorCallback( |
| 160 base::Bind(&CommandBufferDriver::OnParseError, base::Unretained(this))); | 158 base::Bind(&CommandBufferDriver::OnParseError, base::Unretained(this))); |
| 161 | 159 |
| 162 // TODO(piman): other callbacks | 160 // TODO(piman): other callbacks |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 client_->DidLoseContext(); | 241 client_->DidLoseContext(); |
| 244 } | 242 } |
| 245 | 243 |
| 246 void CommandBufferDriver::OnUpdateVSyncParameters( | 244 void CommandBufferDriver::OnUpdateVSyncParameters( |
| 247 const base::TimeTicks timebase, | 245 const base::TimeTicks timebase, |
| 248 const base::TimeDelta interval) { | 246 const base::TimeDelta interval) { |
| 249 client_->UpdateVSyncParameters(timebase, interval); | 247 client_->UpdateVSyncParameters(timebase, interval); |
| 250 } | 248 } |
| 251 | 249 |
| 252 } // namespace gles2 | 250 } // namespace gles2 |
| OLD | NEW |