OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "services/ui/gles2/command_buffer_local.h" |
| 6 |
| 7 #include "base/atomic_sequence_num.h" |
| 8 #include "base/bind.h" |
| 9 #include "base/memory/shared_memory.h" |
| 10 #include "base/synchronization/waitable_event.h" |
| 11 #include "base/threading/thread_task_runner_handle.h" |
| 12 #include "gpu/command_buffer/client/gpu_control_client.h" |
| 13 #include "gpu/command_buffer/common/gpu_memory_buffer_support.h" |
| 14 #include "gpu/command_buffer/common/sync_token.h" |
| 15 #include "gpu/command_buffer/service/command_buffer_service.h" |
| 16 #include "gpu/command_buffer/service/context_group.h" |
| 17 #include "gpu/command_buffer/service/image_manager.h" |
| 18 #include "gpu/command_buffer/service/memory_tracking.h" |
| 19 #include "gpu/command_buffer/service/shader_translator_cache.h" |
| 20 #include "gpu/command_buffer/service/transfer_buffer_manager.h" |
| 21 #include "mojo/public/cpp/system/platform_handle.h" |
| 22 #include "services/ui/common/gpu_type_converters.h" |
| 23 #include "services/ui/common/mojo_buffer_backing.h" |
| 24 #include "services/ui/common/mojo_gpu_memory_buffer.h" |
| 25 #include "services/ui/gles2/command_buffer_driver.h" |
| 26 #include "services/ui/gles2/command_buffer_local_client.h" |
| 27 #include "services/ui/gles2/gpu_memory_tracker.h" |
| 28 #include "services/ui/gles2/gpu_state.h" |
| 29 #include "ui/gfx/buffer_format_util.h" |
| 30 #include "ui/gfx/vsync_provider.h" |
| 31 #include "ui/gl/gl_context.h" |
| 32 #include "ui/gl/gl_image_shared_memory.h" |
| 33 #include "ui/gl/gl_surface.h" |
| 34 |
| 35 namespace ui { |
| 36 |
| 37 namespace { |
| 38 |
| 39 uint64_t g_next_command_buffer_id = 0; |
| 40 |
| 41 bool CreateAndMapSharedBuffer(size_t size, |
| 42 mojo::ScopedSharedBufferMapping* mapping, |
| 43 mojo::ScopedSharedBufferHandle* handle) { |
| 44 *handle = mojo::SharedBufferHandle::Create(size); |
| 45 if (!handle->is_valid()) |
| 46 return false; |
| 47 |
| 48 *mapping = (*handle)->Map(size); |
| 49 if (!*mapping) |
| 50 return false; |
| 51 |
| 52 return true; |
| 53 } |
| 54 |
| 55 void PostTask(const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, |
| 56 const base::Closure& callback) { |
| 57 task_runner->PostTask(FROM_HERE, callback); |
| 58 } |
| 59 } |
| 60 |
| 61 const unsigned int GL_READ_WRITE_CHROMIUM = 0x78F2; |
| 62 |
| 63 CommandBufferLocal::CommandBufferLocal(CommandBufferLocalClient* client, |
| 64 gfx::AcceleratedWidget widget, |
| 65 const scoped_refptr<GpuState>& gpu_state) |
| 66 : widget_(widget), |
| 67 gpu_state_(gpu_state), |
| 68 client_(client), |
| 69 client_thread_task_runner_(base::ThreadTaskRunnerHandle::Get()), |
| 70 gpu_control_client_(nullptr), |
| 71 next_transfer_buffer_id_(0), |
| 72 next_image_id_(0), |
| 73 next_fence_sync_release_(1), |
| 74 flushed_fence_sync_release_(0), |
| 75 lost_context_(false), |
| 76 sync_point_client_waiter_( |
| 77 gpu_state->sync_point_manager()->CreateSyncPointClientWaiter()), |
| 78 weak_factory_(this) { |
| 79 weak_ptr_ = weak_factory_.GetWeakPtr(); |
| 80 } |
| 81 |
| 82 void CommandBufferLocal::Destroy() { |
| 83 DCHECK(CalledOnValidThread()); |
| 84 // After this |Destroy()| call, this object will not be used by client anymore |
| 85 // and it will be deleted on the GPU thread. So we have to detach it from the |
| 86 // client thread first. |
| 87 DetachFromThread(); |
| 88 |
| 89 weak_factory_.InvalidateWeakPtrs(); |
| 90 // CommandBufferLocal is initialized on the GPU thread with |
| 91 // InitializeOnGpuThread(), so we need delete memebers on the GPU thread |
| 92 // too. Additionally we need to make sure we are deleted before returning, |
| 93 // otherwise we may attempt to use the AcceleratedWidget which has since been |
| 94 // destroyed. |
| 95 base::WaitableEvent event(base::WaitableEvent::ResetPolicy::MANUAL, |
| 96 base::WaitableEvent::InitialState::NOT_SIGNALED); |
| 97 gpu_state_->command_buffer_task_runner()->PostTask( |
| 98 driver_.get(), base::Bind(&CommandBufferLocal::DeleteOnGpuThread, |
| 99 base::Unretained(this), &event)); |
| 100 event.Wait(); |
| 101 } |
| 102 |
| 103 bool CommandBufferLocal::Initialize() { |
| 104 DCHECK(CalledOnValidThread()); |
| 105 base::ThreadRestrictions::ScopedAllowWait allow_wait; |
| 106 base::WaitableEvent event(base::WaitableEvent::ResetPolicy::MANUAL, |
| 107 base::WaitableEvent::InitialState::NOT_SIGNALED); |
| 108 bool result = false; |
| 109 gpu_state_->command_buffer_task_runner()->task_runner()->PostTask( |
| 110 FROM_HERE, |
| 111 base::Bind(&CommandBufferLocal::InitializeOnGpuThread, |
| 112 base::Unretained(this), base::Unretained(&event), |
| 113 base::Unretained(&result))); |
| 114 event.Wait(); |
| 115 return result; |
| 116 } |
| 117 |
| 118 gpu::CommandBuffer::State CommandBufferLocal::GetLastState() { |
| 119 DCHECK(CalledOnValidThread()); |
| 120 return last_state_; |
| 121 } |
| 122 |
| 123 int32_t CommandBufferLocal::GetLastToken() { |
| 124 DCHECK(CalledOnValidThread()); |
| 125 TryUpdateState(); |
| 126 return last_state_.token; |
| 127 } |
| 128 |
| 129 void CommandBufferLocal::Flush(int32_t put_offset) { |
| 130 DCHECK(CalledOnValidThread()); |
| 131 if (last_put_offset_ == put_offset) |
| 132 return; |
| 133 |
| 134 last_put_offset_ = put_offset; |
| 135 gpu::SyncPointManager* sync_point_manager = gpu_state_->sync_point_manager(); |
| 136 const uint32_t order_num = |
| 137 driver_->sync_point_order_data()->GenerateUnprocessedOrderNumber( |
| 138 sync_point_manager); |
| 139 gpu_state_->command_buffer_task_runner()->PostTask( |
| 140 driver_.get(), base::Bind(&CommandBufferLocal::FlushOnGpuThread, |
| 141 base::Unretained(this), put_offset, order_num)); |
| 142 flushed_fence_sync_release_ = next_fence_sync_release_ - 1; |
| 143 } |
| 144 |
| 145 void CommandBufferLocal::OrderingBarrier(int32_t put_offset) { |
| 146 DCHECK(CalledOnValidThread()); |
| 147 // TODO(penghuang): Implement this more efficiently. |
| 148 Flush(put_offset); |
| 149 } |
| 150 |
| 151 void CommandBufferLocal::WaitForTokenInRange(int32_t start, int32_t end) { |
| 152 DCHECK(CalledOnValidThread()); |
| 153 TryUpdateState(); |
| 154 while (!InRange(start, end, last_state_.token) && |
| 155 last_state_.error == gpu::error::kNoError) { |
| 156 MakeProgressAndUpdateState(); |
| 157 } |
| 158 } |
| 159 |
| 160 void CommandBufferLocal::WaitForGetOffsetInRange(int32_t start, int32_t end) { |
| 161 DCHECK(CalledOnValidThread()); |
| 162 TryUpdateState(); |
| 163 while (!InRange(start, end, last_state_.get_offset) && |
| 164 last_state_.error == gpu::error::kNoError) { |
| 165 MakeProgressAndUpdateState(); |
| 166 } |
| 167 } |
| 168 |
| 169 void CommandBufferLocal::SetGetBuffer(int32_t buffer) { |
| 170 DCHECK(CalledOnValidThread()); |
| 171 gpu_state_->command_buffer_task_runner()->PostTask( |
| 172 driver_.get(), base::Bind(&CommandBufferLocal::SetGetBufferOnGpuThread, |
| 173 base::Unretained(this), buffer)); |
| 174 last_put_offset_ = -1; |
| 175 } |
| 176 |
| 177 scoped_refptr<gpu::Buffer> CommandBufferLocal::CreateTransferBuffer( |
| 178 size_t size, |
| 179 int32_t* id) { |
| 180 DCHECK(CalledOnValidThread()); |
| 181 if (size >= std::numeric_limits<uint32_t>::max()) |
| 182 return nullptr; |
| 183 |
| 184 mojo::ScopedSharedBufferMapping mapping; |
| 185 mojo::ScopedSharedBufferHandle handle; |
| 186 if (!CreateAndMapSharedBuffer(size, &mapping, &handle)) { |
| 187 if (last_state_.error == gpu::error::kNoError) |
| 188 last_state_.error = gpu::error::kLostContext; |
| 189 return nullptr; |
| 190 } |
| 191 |
| 192 *id = ++next_transfer_buffer_id_; |
| 193 |
| 194 gpu_state_->command_buffer_task_runner()->PostTask( |
| 195 driver_.get(), |
| 196 base::Bind(&CommandBufferLocal::RegisterTransferBufferOnGpuThread, |
| 197 base::Unretained(this), *id, base::Passed(&handle), |
| 198 static_cast<uint32_t>(size))); |
| 199 std::unique_ptr<gpu::BufferBacking> backing( |
| 200 new ui::MojoBufferBacking(std::move(mapping), size)); |
| 201 scoped_refptr<gpu::Buffer> buffer(new gpu::Buffer(std::move(backing))); |
| 202 return buffer; |
| 203 } |
| 204 |
| 205 void CommandBufferLocal::DestroyTransferBuffer(int32_t id) { |
| 206 DCHECK(CalledOnValidThread()); |
| 207 gpu_state_->command_buffer_task_runner()->PostTask( |
| 208 driver_.get(), |
| 209 base::Bind(&CommandBufferLocal::DestroyTransferBufferOnGpuThread, |
| 210 base::Unretained(this), id)); |
| 211 } |
| 212 |
| 213 void CommandBufferLocal::SetGpuControlClient(gpu::GpuControlClient* client) { |
| 214 gpu_control_client_ = client; |
| 215 } |
| 216 |
| 217 gpu::Capabilities CommandBufferLocal::GetCapabilities() { |
| 218 DCHECK(CalledOnValidThread()); |
| 219 return capabilities_; |
| 220 } |
| 221 |
| 222 int32_t CommandBufferLocal::CreateImage(ClientBuffer buffer, |
| 223 size_t width, |
| 224 size_t height, |
| 225 unsigned internal_format) { |
| 226 DCHECK(CalledOnValidThread()); |
| 227 int32_t new_id = ++next_image_id_; |
| 228 gfx::Size size(static_cast<int32_t>(width), static_cast<int32_t>(height)); |
| 229 |
| 230 ui::MojoGpuMemoryBufferImpl* gpu_memory_buffer = |
| 231 ui::MojoGpuMemoryBufferImpl::FromClientBuffer(buffer); |
| 232 |
| 233 bool requires_sync_point = false; |
| 234 |
| 235 if (gpu_memory_buffer->GetBufferType() == gfx::SHARED_MEMORY_BUFFER) { |
| 236 gfx::GpuMemoryBufferHandle handle = gpu_memory_buffer->GetHandle(); |
| 237 // TODO(rjkroege): Verify that this is required and update appropriately. |
| 238 base::SharedMemoryHandle dupd_handle = |
| 239 base::SharedMemory::DuplicateHandle(handle.handle); |
| 240 #if defined(OS_WIN) |
| 241 HANDLE platform_file = dupd_handle.GetHandle(); |
| 242 #else |
| 243 int platform_file = dupd_handle.fd; |
| 244 #endif |
| 245 |
| 246 mojo::ScopedHandle scoped_handle = mojo::WrapPlatformFile(platform_file); |
| 247 const int32_t format = static_cast<int32_t>(gpu_memory_buffer->GetFormat()); |
| 248 gpu_state_->command_buffer_task_runner()->PostTask( |
| 249 driver_.get(), |
| 250 base::Bind(&CommandBufferLocal::CreateImageOnGpuThread, |
| 251 base::Unretained(this), new_id, base::Passed(&scoped_handle), |
| 252 handle.type, base::Passed(&size), format, internal_format)); |
| 253 #if defined(USE_OZONE) |
| 254 } else if (gpu_memory_buffer->GetBufferType() == gfx::OZONE_NATIVE_PIXMAP) { |
| 255 gpu_state_->command_buffer_task_runner()->PostTask( |
| 256 driver_.get(), |
| 257 base::Bind(&CommandBufferLocal::CreateImageNativeOzoneOnGpuThread, |
| 258 base::Unretained(this), new_id, |
| 259 gpu_memory_buffer->GetBufferType(), |
| 260 gpu_memory_buffer->GetSize(), gpu_memory_buffer->GetFormat(), |
| 261 internal_format, |
| 262 base::RetainedRef(gpu_memory_buffer->GetNativePixmap()))); |
| 263 #endif |
| 264 } else { |
| 265 NOTIMPLEMENTED(); |
| 266 return -1; |
| 267 } |
| 268 |
| 269 if (requires_sync_point) { |
| 270 NOTIMPLEMENTED() << "Require sync points"; |
| 271 // TODO(jam): need to support this if we support types other than |
| 272 // SHARED_MEMORY_BUFFER. |
| 273 // gpu_memory_buffer_manager->SetDestructionSyncPoint(gpu_memory_buffer, |
| 274 // InsertSyncPoint()); |
| 275 } |
| 276 |
| 277 return new_id; |
| 278 } |
| 279 |
| 280 void CommandBufferLocal::DestroyImage(int32_t id) { |
| 281 DCHECK(CalledOnValidThread()); |
| 282 gpu_state_->command_buffer_task_runner()->PostTask( |
| 283 driver_.get(), base::Bind(&CommandBufferLocal::DestroyImageOnGpuThread, |
| 284 base::Unretained(this), id)); |
| 285 } |
| 286 |
| 287 int32_t CommandBufferLocal::CreateGpuMemoryBufferImage(size_t width, |
| 288 size_t height, |
| 289 unsigned internal_format, |
| 290 unsigned usage) { |
| 291 DCHECK(CalledOnValidThread()); |
| 292 DCHECK_EQ(usage, static_cast<unsigned>(GL_READ_WRITE_CHROMIUM)); |
| 293 std::unique_ptr<gfx::GpuMemoryBuffer> buffer(MojoGpuMemoryBufferImpl::Create( |
| 294 gfx::Size(static_cast<int>(width), static_cast<int>(height)), |
| 295 gpu::DefaultBufferFormatForImageFormat(internal_format), |
| 296 gfx::BufferUsage::SCANOUT)); |
| 297 if (!buffer) |
| 298 return -1; |
| 299 return CreateImage(buffer->AsClientBuffer(), width, height, internal_format); |
| 300 } |
| 301 |
| 302 void CommandBufferLocal::SignalQuery(uint32_t query_id, |
| 303 const base::Closure& callback) { |
| 304 DCHECK(CalledOnValidThread()); |
| 305 |
| 306 gpu_state_->command_buffer_task_runner()->PostTask( |
| 307 driver_.get(), base::Bind(&CommandBufferLocal::SignalQueryOnGpuThread, |
| 308 base::Unretained(this), query_id, callback)); |
| 309 } |
| 310 |
| 311 void CommandBufferLocal::SetLock(base::Lock* lock) { |
| 312 DCHECK(CalledOnValidThread()); |
| 313 NOTIMPLEMENTED(); |
| 314 } |
| 315 |
| 316 void CommandBufferLocal::EnsureWorkVisible() { |
| 317 // This is only relevant for out-of-process command buffers. |
| 318 } |
| 319 |
| 320 gpu::CommandBufferNamespace CommandBufferLocal::GetNamespaceID() const { |
| 321 DCHECK(CalledOnValidThread()); |
| 322 return gpu::CommandBufferNamespace::MOJO_LOCAL; |
| 323 } |
| 324 |
| 325 gpu::CommandBufferId CommandBufferLocal::GetCommandBufferID() const { |
| 326 DCHECK(CalledOnValidThread()); |
| 327 return driver_->GetCommandBufferID(); |
| 328 } |
| 329 |
| 330 int32_t CommandBufferLocal::GetExtraCommandBufferData() const { |
| 331 DCHECK(CalledOnValidThread()); |
| 332 return 0; |
| 333 } |
| 334 |
| 335 uint64_t CommandBufferLocal::GenerateFenceSyncRelease() { |
| 336 DCHECK(CalledOnValidThread()); |
| 337 return next_fence_sync_release_++; |
| 338 } |
| 339 |
| 340 bool CommandBufferLocal::IsFenceSyncRelease(uint64_t release) { |
| 341 DCHECK(CalledOnValidThread()); |
| 342 return release != 0 && release < next_fence_sync_release_; |
| 343 } |
| 344 |
| 345 bool CommandBufferLocal::IsFenceSyncFlushed(uint64_t release) { |
| 346 DCHECK(CalledOnValidThread()); |
| 347 return release != 0 && release <= flushed_fence_sync_release_; |
| 348 } |
| 349 |
| 350 bool CommandBufferLocal::IsFenceSyncFlushReceived(uint64_t release) { |
| 351 DCHECK(CalledOnValidThread()); |
| 352 return IsFenceSyncFlushed(release); |
| 353 } |
| 354 |
| 355 void CommandBufferLocal::SignalSyncToken(const gpu::SyncToken& sync_token, |
| 356 const base::Closure& callback) { |
| 357 DCHECK(CalledOnValidThread()); |
| 358 scoped_refptr<gpu::SyncPointClientState> release_state = |
| 359 gpu_state_->sync_point_manager()->GetSyncPointClientState( |
| 360 sync_token.namespace_id(), sync_token.command_buffer_id()); |
| 361 if (!release_state || |
| 362 release_state->IsFenceSyncReleased(sync_token.release_count())) { |
| 363 callback.Run(); |
| 364 return; |
| 365 } |
| 366 |
| 367 sync_point_client_waiter_->WaitOutOfOrderNonThreadSafe( |
| 368 release_state.get(), sync_token.release_count(), |
| 369 client_thread_task_runner_, callback); |
| 370 } |
| 371 |
| 372 bool CommandBufferLocal::CanWaitUnverifiedSyncToken( |
| 373 const gpu::SyncToken* sync_token) { |
| 374 DCHECK(CalledOnValidThread()); |
| 375 // Right now, MOJO_LOCAL is only used by trusted code, so it is safe to wait |
| 376 // on a sync token in MOJO_LOCAL command buffer. |
| 377 return sync_token->namespace_id() == gpu::CommandBufferNamespace::MOJO_LOCAL; |
| 378 } |
| 379 |
| 380 void CommandBufferLocal::DidLoseContext(uint32_t reason) { |
| 381 if (client_) { |
| 382 driver_->set_client(nullptr); |
| 383 client_thread_task_runner_->PostTask( |
| 384 FROM_HERE, |
| 385 base::Bind(&CommandBufferLocal::DidLoseContextOnClientThread, |
| 386 weak_ptr_, reason)); |
| 387 } |
| 388 } |
| 389 |
| 390 void CommandBufferLocal::UpdateVSyncParameters( |
| 391 const base::TimeTicks& timebase, |
| 392 const base::TimeDelta& interval) { |
| 393 if (client_) { |
| 394 client_thread_task_runner_->PostTask( |
| 395 FROM_HERE, |
| 396 base::Bind(&CommandBufferLocal::UpdateVSyncParametersOnClientThread, |
| 397 weak_ptr_, timebase, interval)); |
| 398 } |
| 399 } |
| 400 |
| 401 void CommandBufferLocal::OnGpuCompletedSwapBuffers(gfx::SwapResult result) { |
| 402 if (client_) { |
| 403 client_thread_task_runner_->PostTask( |
| 404 FROM_HERE, |
| 405 base::Bind(&CommandBufferLocal::OnGpuCompletedSwapBuffersOnClientThread, |
| 406 weak_ptr_, result)); |
| 407 } |
| 408 } |
| 409 |
| 410 CommandBufferLocal::~CommandBufferLocal() {} |
| 411 |
| 412 void CommandBufferLocal::TryUpdateState() { |
| 413 if (last_state_.error == gpu::error::kNoError) |
| 414 shared_state()->Read(&last_state_); |
| 415 } |
| 416 |
| 417 void CommandBufferLocal::MakeProgressAndUpdateState() { |
| 418 base::ThreadRestrictions::ScopedAllowWait allow_wait; |
| 419 base::WaitableEvent event(base::WaitableEvent::ResetPolicy::MANUAL, |
| 420 base::WaitableEvent::InitialState::NOT_SIGNALED); |
| 421 gpu::CommandBuffer::State state; |
| 422 gpu_state_->command_buffer_task_runner()->PostTask( |
| 423 driver_.get(), |
| 424 base::Bind(&CommandBufferLocal::MakeProgressOnGpuThread, |
| 425 base::Unretained(this), base::Unretained(&event), |
| 426 base::Unretained(&state))); |
| 427 event.Wait(); |
| 428 if (state.generation - last_state_.generation < 0x80000000U) |
| 429 last_state_ = state; |
| 430 } |
| 431 |
| 432 void CommandBufferLocal::InitializeOnGpuThread(base::WaitableEvent* event, |
| 433 bool* result) { |
| 434 driver_.reset(new CommandBufferDriver( |
| 435 gpu::CommandBufferNamespace::MOJO_LOCAL, |
| 436 gpu::CommandBufferId::FromUnsafeValue(++g_next_command_buffer_id), |
| 437 widget_, gpu_state_)); |
| 438 driver_->set_client(this); |
| 439 const size_t kSharedStateSize = sizeof(gpu::CommandBufferSharedState); |
| 440 mojo::ScopedSharedBufferMapping mapping; |
| 441 mojo::ScopedSharedBufferHandle handle; |
| 442 *result = CreateAndMapSharedBuffer(kSharedStateSize, &shared_state_, &handle); |
| 443 |
| 444 if (!*result) { |
| 445 event->Signal(); |
| 446 return; |
| 447 } |
| 448 |
| 449 shared_state()->Initialize(); |
| 450 |
| 451 *result = |
| 452 driver_->Initialize(std::move(handle), mojo::Array<int32_t>::New(0)); |
| 453 if (*result) |
| 454 capabilities_ = driver_->GetCapabilities(); |
| 455 event->Signal(); |
| 456 } |
| 457 |
| 458 bool CommandBufferLocal::FlushOnGpuThread(int32_t put_offset, |
| 459 uint32_t order_num) { |
| 460 DCHECK(driver_->IsScheduled()); |
| 461 driver_->sync_point_order_data()->BeginProcessingOrderNumber(order_num); |
| 462 driver_->Flush(put_offset); |
| 463 |
| 464 // Return false if the Flush is not finished, so the CommandBufferTaskRunner |
| 465 // will not remove this task from the task queue. |
| 466 const bool complete = !driver_->HasUnprocessedCommands(); |
| 467 if (complete) |
| 468 driver_->sync_point_order_data()->FinishProcessingOrderNumber(order_num); |
| 469 return complete; |
| 470 } |
| 471 |
| 472 bool CommandBufferLocal::SetGetBufferOnGpuThread(int32_t buffer) { |
| 473 DCHECK(driver_->IsScheduled()); |
| 474 driver_->SetGetBuffer(buffer); |
| 475 return true; |
| 476 } |
| 477 |
| 478 bool CommandBufferLocal::RegisterTransferBufferOnGpuThread( |
| 479 int32_t id, |
| 480 mojo::ScopedSharedBufferHandle transfer_buffer, |
| 481 uint32_t size) { |
| 482 DCHECK(driver_->IsScheduled()); |
| 483 driver_->RegisterTransferBuffer(id, std::move(transfer_buffer), size); |
| 484 return true; |
| 485 } |
| 486 |
| 487 bool CommandBufferLocal::DestroyTransferBufferOnGpuThread(int32_t id) { |
| 488 DCHECK(driver_->IsScheduled()); |
| 489 driver_->DestroyTransferBuffer(id); |
| 490 return true; |
| 491 } |
| 492 |
| 493 bool CommandBufferLocal::CreateImageOnGpuThread( |
| 494 int32_t id, |
| 495 mojo::ScopedHandle memory_handle, |
| 496 int32_t type, |
| 497 const gfx::Size& size, |
| 498 int32_t format, |
| 499 int32_t internal_format) { |
| 500 DCHECK(driver_->IsScheduled()); |
| 501 driver_->CreateImage(id, std::move(memory_handle), type, std::move(size), |
| 502 format, internal_format); |
| 503 return true; |
| 504 } |
| 505 |
| 506 bool CommandBufferLocal::CreateImageNativeOzoneOnGpuThread( |
| 507 int32_t id, |
| 508 int32_t type, |
| 509 gfx::Size size, |
| 510 gfx::BufferFormat format, |
| 511 uint32_t internal_format, |
| 512 ui::NativePixmap* pixmap) { |
| 513 DCHECK(driver_->IsScheduled()); |
| 514 driver_->CreateImageNativeOzone(id, type, size, format, internal_format, |
| 515 pixmap); |
| 516 return true; |
| 517 } |
| 518 |
| 519 bool CommandBufferLocal::DestroyImageOnGpuThread(int32_t id) { |
| 520 DCHECK(driver_->IsScheduled()); |
| 521 driver_->DestroyImage(id); |
| 522 return true; |
| 523 } |
| 524 |
| 525 bool CommandBufferLocal::MakeProgressOnGpuThread( |
| 526 base::WaitableEvent* event, |
| 527 gpu::CommandBuffer::State* state) { |
| 528 DCHECK(driver_->IsScheduled()); |
| 529 *state = driver_->GetLastState(); |
| 530 event->Signal(); |
| 531 return true; |
| 532 } |
| 533 |
| 534 bool CommandBufferLocal::DeleteOnGpuThread(base::WaitableEvent* event) { |
| 535 delete this; |
| 536 event->Signal(); |
| 537 return true; |
| 538 } |
| 539 |
| 540 bool CommandBufferLocal::SignalQueryOnGpuThread(uint32_t query_id, |
| 541 const base::Closure& callback) { |
| 542 // |callback| should run on the client thread. |
| 543 driver_->SignalQuery( |
| 544 query_id, base::Bind(&PostTask, client_thread_task_runner_, callback)); |
| 545 return true; |
| 546 } |
| 547 |
| 548 void CommandBufferLocal::DidLoseContextOnClientThread(uint32_t reason) { |
| 549 DCHECK(gpu_control_client_); |
| 550 if (!lost_context_) |
| 551 gpu_control_client_->OnGpuControlLostContext(); |
| 552 lost_context_ = true; |
| 553 } |
| 554 |
| 555 void CommandBufferLocal::UpdateVSyncParametersOnClientThread( |
| 556 const base::TimeTicks& timebase, |
| 557 const base::TimeDelta& interval) { |
| 558 if (client_) |
| 559 client_->UpdateVSyncParameters(timebase, interval); |
| 560 } |
| 561 |
| 562 void CommandBufferLocal::OnGpuCompletedSwapBuffersOnClientThread( |
| 563 gfx::SwapResult result) { |
| 564 if (client_) |
| 565 client_->GpuCompletedSwapBuffers(result); |
| 566 } |
| 567 |
| 568 } // namespace ui |
OLD | NEW |