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/gles2/command_buffer_driver.h" | 5 #include "components/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/gles2/command_buffer_type_conversions.h" | 10 #include "components/gles2/command_buffer_type_conversions.h" |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 share_group, | 58 share_group, |
59 mailbox_manager, | 59 mailbox_manager, |
60 sync_point_manager) { | 60 sync_point_manager, |
| 61 base::Callback<void(CommandBufferDriver*)>()) { |
61 } | 62 } |
62 | 63 |
63 CommandBufferDriver::CommandBufferDriver( | 64 CommandBufferDriver::CommandBufferDriver( |
64 gfx::AcceleratedWidget widget, | 65 gfx::AcceleratedWidget widget, |
65 gfx::GLShareGroup* share_group, | 66 gfx::GLShareGroup* share_group, |
66 gpu::gles2::MailboxManager* mailbox_manager, | 67 gpu::gles2::MailboxManager* mailbox_manager, |
67 gpu::SyncPointManager* sync_point_manager) | 68 gpu::SyncPointManager* sync_point_manager, |
| 69 const base::Callback<void(CommandBufferDriver*)>& destruct_callback) |
68 : client_(nullptr), | 70 : client_(nullptr), |
69 widget_(widget), | 71 widget_(widget), |
70 share_group_(share_group), | 72 share_group_(share_group), |
71 mailbox_manager_(mailbox_manager), | 73 mailbox_manager_(mailbox_manager), |
72 sync_point_manager_(sync_point_manager), | 74 sync_point_manager_(sync_point_manager), |
| 75 destruct_callback_(destruct_callback), |
73 weak_factory_(this) { | 76 weak_factory_(this) { |
74 } | 77 } |
75 | 78 |
76 CommandBufferDriver::~CommandBufferDriver() { | 79 CommandBufferDriver::~CommandBufferDriver() { |
77 if (decoder_) { | 80 DestroyDecoder(); |
78 bool have_context = decoder_->MakeCurrent(); | 81 if (!destruct_callback_.is_null()) |
79 decoder_->Destroy(have_context); | 82 destruct_callback_.Run(this); |
80 } | |
81 } | 83 } |
82 | 84 |
83 void CommandBufferDriver::Initialize( | 85 void CommandBufferDriver::Initialize( |
84 mojo::CommandBufferSyncClientPtr sync_client, | 86 mojo::CommandBufferSyncClientPtr sync_client, |
85 mojo::CommandBufferLostContextObserverPtr loss_observer, | 87 mojo::CommandBufferLostContextObserverPtr loss_observer, |
86 mojo::ScopedSharedBufferHandle shared_state) { | 88 mojo::ScopedSharedBufferHandle shared_state) { |
87 sync_client_ = sync_client.Pass(); | 89 sync_client_ = sync_client.Pass(); |
88 loss_observer_ = loss_observer.Pass(); | 90 loss_observer_ = loss_observer.Pass(); |
89 bool success = DoInitialize(shared_state.Pass()); | 91 bool success = DoInitialize(shared_state.Pass()); |
90 mojo::GpuCapabilitiesPtr capabilities = | 92 mojo::GpuCapabilitiesPtr capabilities = |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 | 169 |
168 command_buffer_->SetSharedStateBuffer(backing.Pass()); | 170 command_buffer_->SetSharedStateBuffer(backing.Pass()); |
169 return true; | 171 return true; |
170 } | 172 } |
171 | 173 |
172 void CommandBufferDriver::SetGetBuffer(int32_t buffer) { | 174 void CommandBufferDriver::SetGetBuffer(int32_t buffer) { |
173 command_buffer_->SetGetBuffer(buffer); | 175 command_buffer_->SetGetBuffer(buffer); |
174 } | 176 } |
175 | 177 |
176 void CommandBufferDriver::Flush(int32_t put_offset) { | 178 void CommandBufferDriver::Flush(int32_t put_offset) { |
| 179 if (!context_) |
| 180 return; |
177 if (!context_->MakeCurrent(surface_.get())) { | 181 if (!context_->MakeCurrent(surface_.get())) { |
178 DLOG(WARNING) << "Context lost"; | 182 DLOG(WARNING) << "Context lost"; |
179 OnContextLost(gpu::error::kUnknown); | 183 OnContextLost(gpu::error::kUnknown); |
180 return; | 184 return; |
181 } | 185 } |
182 command_buffer_->Flush(put_offset); | 186 command_buffer_->Flush(put_offset); |
183 } | 187 } |
184 | 188 |
| 189 void CommandBufferDriver::DestroyWindow() { |
| 190 DestroyDecoder(); |
| 191 surface_ = nullptr; |
| 192 context_ = nullptr; |
| 193 destruct_callback_.Reset(); |
| 194 } |
| 195 |
185 void CommandBufferDriver::MakeProgress(int32_t last_get_offset) { | 196 void CommandBufferDriver::MakeProgress(int32_t last_get_offset) { |
186 // TODO(piman): handle out-of-order. | 197 // TODO(piman): handle out-of-order. |
187 sync_client_->DidMakeProgress( | 198 sync_client_->DidMakeProgress( |
188 mojo::CommandBufferState::From(command_buffer_->GetLastState())); | 199 mojo::CommandBufferState::From(command_buffer_->GetLastState())); |
189 } | 200 } |
190 | 201 |
191 void CommandBufferDriver::RegisterTransferBuffer( | 202 void CommandBufferDriver::RegisterTransferBuffer( |
192 int32_t id, | 203 int32_t id, |
193 mojo::ScopedSharedBufferHandle transfer_buffer, | 204 mojo::ScopedSharedBufferHandle transfer_buffer, |
194 uint32_t size) { | 205 uint32_t size) { |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 loss_observer_->DidLoseContext(reason); | 251 loss_observer_->DidLoseContext(reason); |
241 client_->DidLoseContext(); | 252 client_->DidLoseContext(); |
242 } | 253 } |
243 | 254 |
244 void CommandBufferDriver::OnUpdateVSyncParameters( | 255 void CommandBufferDriver::OnUpdateVSyncParameters( |
245 const base::TimeTicks timebase, | 256 const base::TimeTicks timebase, |
246 const base::TimeDelta interval) { | 257 const base::TimeDelta interval) { |
247 client_->UpdateVSyncParameters(timebase, interval); | 258 client_->UpdateVSyncParameters(timebase, interval); |
248 } | 259 } |
249 | 260 |
| 261 void CommandBufferDriver::DestroyDecoder() { |
| 262 if (decoder_) { |
| 263 bool have_context = decoder_->MakeCurrent(); |
| 264 decoder_->Destroy(have_context); |
| 265 decoder_.reset(); |
| 266 } |
| 267 } |
| 268 |
250 } // namespace gles2 | 269 } // namespace gles2 |
OLD | NEW |