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 "cc/resources/video_resource_updater.h" | 5 #include "cc/resources/video_resource_updater.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/trace_event/trace_event.h" | 10 #include "base/trace_event/trace_event.h" |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 case media::PIXEL_FORMAT_MT21: | 65 case media::PIXEL_FORMAT_MT21: |
66 case media::PIXEL_FORMAT_UNKNOWN: | 66 case media::PIXEL_FORMAT_UNKNOWN: |
67 break; | 67 break; |
68 } | 68 } |
69 return VideoFrameExternalResources::NONE; | 69 return VideoFrameExternalResources::NONE; |
70 } | 70 } |
71 | 71 |
72 class SyncPointClientImpl : public media::VideoFrame::SyncPointClient { | 72 class SyncPointClientImpl : public media::VideoFrame::SyncPointClient { |
73 public: | 73 public: |
74 explicit SyncPointClientImpl(gpu::gles2::GLES2Interface* gl, | 74 explicit SyncPointClientImpl(gpu::gles2::GLES2Interface* gl, |
75 uint32 sync_point) | 75 uint32 sync_point, |
76 : gl_(gl), sync_point_(sync_point) {} | 76 const gpu::SyncToken& sync_token) |
| 77 : gl_(gl), sync_point_(sync_point), sync_token_(sync_token) {} |
77 ~SyncPointClientImpl() override {} | 78 ~SyncPointClientImpl() override {} |
78 uint32 InsertSyncPoint() override { | 79 uint32 InsertSyncPoint() override { |
79 if (sync_point_) | 80 if (sync_point_) |
80 return sync_point_; | 81 return sync_point_; |
81 return gl_->InsertSyncPointCHROMIUM(); | 82 return gl_->InsertSyncPointCHROMIUM(); |
82 } | 83 } |
83 void WaitSyncPoint(uint32 sync_point) override { | 84 void WaitSyncPoint(uint32 sync_point, |
84 if (!sync_point) | 85 const gpu::SyncToken& sync_token) override { |
85 return; | 86 if (sync_point || sync_token.HasData()) { |
86 gl_->WaitSyncPointCHROMIUM(sync_point); | 87 gl_->WaitSyncPointCHROMIUM(sync_point, sync_token.GetConstData()); |
87 if (sync_point_) { | 88 if (sync_point_ || sync_token_.HasData()) { |
88 gl_->WaitSyncPointCHROMIUM(sync_point_); | 89 gl_->WaitSyncPointCHROMIUM(sync_point_, sync_token_.GetConstData()); |
89 sync_point_ = 0; | 90 sync_point_ = 0; |
| 91 sync_token_.Clear(); |
| 92 } |
90 } | 93 } |
91 } | 94 } |
92 | 95 |
93 private: | 96 private: |
94 gpu::gles2::GLES2Interface* gl_; | 97 gpu::gles2::GLES2Interface* gl_; |
95 uint32 sync_point_; | 98 uint32 sync_point_; |
| 99 gpu::SyncToken sync_token_; |
96 }; | 100 }; |
97 | 101 |
98 } // namespace | 102 } // namespace |
99 | 103 |
100 VideoResourceUpdater::PlaneResource::PlaneResource( | 104 VideoResourceUpdater::PlaneResource::PlaneResource( |
101 unsigned int resource_id, | 105 unsigned int resource_id, |
102 const gfx::Size& resource_size, | 106 const gfx::Size& resource_size, |
103 ResourceFormat resource_format, | 107 ResourceFormat resource_format, |
104 gpu::Mailbox mailbox) | 108 gpu::Mailbox mailbox) |
105 : resource_id(resource_id), | 109 : resource_id(resource_id), |
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
374 memcpy(dst, src, bytes_per_row); | 378 memcpy(dst, src, bytes_per_row); |
375 } | 379 } |
376 pixels = &upload_pixels_[0]; | 380 pixels = &upload_pixels_[0]; |
377 } | 381 } |
378 | 382 |
379 resource_provider_->CopyToResource(plane_resource.resource_id, pixels, | 383 resource_provider_->CopyToResource(plane_resource.resource_id, pixels, |
380 resource_size_pixels); | 384 resource_size_pixels); |
381 SetPlaneResourceUniqueId(video_frame.get(), i, &plane_resource); | 385 SetPlaneResourceUniqueId(video_frame.get(), i, &plane_resource); |
382 } | 386 } |
383 | 387 |
384 external_resources.mailboxes.push_back( | 388 external_resources.mailboxes.push_back(TextureMailbox( |
385 TextureMailbox(plane_resource.mailbox, GL_TEXTURE_2D, 0)); | 389 plane_resource.mailbox, GL_TEXTURE_2D, 0, gpu::SyncToken())); |
386 external_resources.release_callbacks.push_back( | 390 external_resources.release_callbacks.push_back( |
387 base::Bind(&RecycleResource, AsWeakPtr(), plane_resource.resource_id)); | 391 base::Bind(&RecycleResource, AsWeakPtr(), plane_resource.resource_id)); |
388 } | 392 } |
389 | 393 |
390 external_resources.type = VideoFrameExternalResources::YUV_RESOURCE; | 394 external_resources.type = VideoFrameExternalResources::YUV_RESOURCE; |
391 return external_resources; | 395 return external_resources; |
392 } | 396 } |
393 | 397 |
394 // static | 398 // static |
395 void VideoResourceUpdater::ReturnTexture( | 399 void VideoResourceUpdater::ReturnTexture( |
396 base::WeakPtr<VideoResourceUpdater> updater, | 400 base::WeakPtr<VideoResourceUpdater> updater, |
397 const scoped_refptr<media::VideoFrame>& video_frame, | 401 const scoped_refptr<media::VideoFrame>& video_frame, |
398 uint32 sync_point, | 402 uint32 sync_point, |
| 403 const gpu::SyncToken& sync_token, |
399 bool lost_resource, | 404 bool lost_resource, |
400 BlockingTaskRunner* main_thread_task_runner) { | 405 BlockingTaskRunner* main_thread_task_runner) { |
401 // TODO(dshwang) this case should be forwarded to the decoder as lost | 406 // TODO(dshwang) this case should be forwarded to the decoder as lost |
402 // resource. | 407 // resource. |
403 if (lost_resource || !updater.get()) | 408 if (lost_resource || !updater.get()) |
404 return; | 409 return; |
405 // Update the release sync point in |video_frame| with |sync_point| | 410 // Update the release sync point in |video_frame| with |sync_point| |
406 // returned by the compositor and emit a WaitSyncPointCHROMIUM on | 411 // returned by the compositor and emit a WaitSyncPointCHROMIUM on |
407 // |video_frame|'s previous sync point using the current GL context. | 412 // |video_frame|'s previous sync point using the current GL context. |
408 SyncPointClientImpl client(updater->context_provider_->ContextGL(), | 413 SyncPointClientImpl client(updater->context_provider_->ContextGL(), |
409 sync_point); | 414 sync_point, sync_token); |
410 video_frame->UpdateReleaseSyncPoint(&client); | 415 video_frame->UpdateReleaseSyncPoint(&client); |
411 } | 416 } |
412 | 417 |
413 VideoFrameExternalResources VideoResourceUpdater::CreateForHardwarePlanes( | 418 VideoFrameExternalResources VideoResourceUpdater::CreateForHardwarePlanes( |
414 const scoped_refptr<media::VideoFrame>& video_frame) { | 419 const scoped_refptr<media::VideoFrame>& video_frame) { |
415 TRACE_EVENT0("cc", "VideoResourceUpdater::CreateForHardwarePlanes"); | 420 TRACE_EVENT0("cc", "VideoResourceUpdater::CreateForHardwarePlanes"); |
416 DCHECK(video_frame->HasTextures()); | 421 DCHECK(video_frame->HasTextures()); |
417 if (!context_provider_) | 422 if (!context_provider_) |
418 return VideoFrameExternalResources(); | 423 return VideoFrameExternalResources(); |
419 | 424 |
420 VideoFrameExternalResources external_resources; | 425 VideoFrameExternalResources external_resources; |
421 external_resources.read_lock_fences_enabled = true; | 426 external_resources.read_lock_fences_enabled = true; |
422 | 427 |
423 external_resources.type = ResourceTypeForVideoFrame(video_frame.get()); | 428 external_resources.type = ResourceTypeForVideoFrame(video_frame.get()); |
424 if (external_resources.type == VideoFrameExternalResources::NONE) { | 429 if (external_resources.type == VideoFrameExternalResources::NONE) { |
425 DLOG(ERROR) << "Unsupported Texture format" | 430 DLOG(ERROR) << "Unsupported Texture format" |
426 << media::VideoPixelFormatToString(video_frame->format()); | 431 << media::VideoPixelFormatToString(video_frame->format()); |
427 return external_resources; | 432 return external_resources; |
428 } | 433 } |
429 | 434 |
430 const size_t num_planes = media::VideoFrame::NumPlanes(video_frame->format()); | 435 const size_t num_planes = media::VideoFrame::NumPlanes(video_frame->format()); |
431 for (size_t i = 0; i < num_planes; ++i) { | 436 for (size_t i = 0; i < num_planes; ++i) { |
432 const gpu::MailboxHolder& mailbox_holder = video_frame->mailbox_holder(i); | 437 const gpu::MailboxHolder& mailbox_holder = video_frame->mailbox_holder(i); |
433 if (mailbox_holder.mailbox.IsZero()) | 438 if (mailbox_holder.mailbox.IsZero()) |
434 break; | 439 break; |
435 external_resources.mailboxes.push_back( | 440 external_resources.mailboxes.push_back( |
436 TextureMailbox(mailbox_holder.mailbox, mailbox_holder.texture_target, | 441 TextureMailbox(mailbox_holder.mailbox, mailbox_holder.texture_target, |
437 mailbox_holder.sync_point, video_frame->coded_size(), | 442 mailbox_holder.sync_point, mailbox_holder.sync_token, |
| 443 video_frame->coded_size(), |
438 video_frame->metadata()->IsTrue( | 444 video_frame->metadata()->IsTrue( |
439 media::VideoFrameMetadata::ALLOW_OVERLAY))); | 445 media::VideoFrameMetadata::ALLOW_OVERLAY))); |
440 external_resources.release_callbacks.push_back( | 446 external_resources.release_callbacks.push_back( |
441 base::Bind(&ReturnTexture, AsWeakPtr(), video_frame)); | 447 base::Bind(&ReturnTexture, AsWeakPtr(), video_frame)); |
442 } | 448 } |
443 return external_resources; | 449 return external_resources; |
444 } | 450 } |
445 | 451 |
446 // static | 452 // static |
447 void VideoResourceUpdater::RecycleResource( | 453 void VideoResourceUpdater::RecycleResource( |
448 base::WeakPtr<VideoResourceUpdater> updater, | 454 base::WeakPtr<VideoResourceUpdater> updater, |
449 ResourceId resource_id, | 455 ResourceId resource_id, |
450 uint32 sync_point, | 456 uint32 sync_point, |
| 457 const gpu::SyncToken& sync_token, |
451 bool lost_resource, | 458 bool lost_resource, |
452 BlockingTaskRunner* main_thread_task_runner) { | 459 BlockingTaskRunner* main_thread_task_runner) { |
453 if (!updater.get()) { | 460 if (!updater.get()) { |
454 // Resource was already deleted. | 461 // Resource was already deleted. |
455 return; | 462 return; |
456 } | 463 } |
457 | 464 |
458 const ResourceList::iterator resource_it = std::find_if( | 465 const ResourceList::iterator resource_it = std::find_if( |
459 updater->all_resources_.begin(), updater->all_resources_.end(), | 466 updater->all_resources_.begin(), updater->all_resources_.end(), |
460 [resource_id](const PlaneResource& plane_resource) { | 467 [resource_id](const PlaneResource& plane_resource) { |
461 return plane_resource.resource_id == resource_id; | 468 return plane_resource.resource_id == resource_id; |
462 }); | 469 }); |
463 if (resource_it == updater->all_resources_.end()) | 470 if (resource_it == updater->all_resources_.end()) |
464 return; | 471 return; |
465 | 472 |
466 ContextProvider* context_provider = updater->context_provider_; | 473 ContextProvider* context_provider = updater->context_provider_; |
467 if (context_provider && sync_point) { | 474 if (context_provider && (sync_point || sync_token.HasData())) { |
468 context_provider->ContextGL()->WaitSyncPointCHROMIUM(sync_point); | 475 context_provider->ContextGL()->WaitSyncPointCHROMIUM( |
| 476 sync_point, sync_token.GetConstData()); |
469 } | 477 } |
470 | 478 |
471 if (lost_resource) { | 479 if (lost_resource) { |
472 resource_it->ref_count = 0; | 480 resource_it->ref_count = 0; |
473 updater->DeleteResource(resource_it); | 481 updater->DeleteResource(resource_it); |
474 return; | 482 return; |
475 } | 483 } |
476 | 484 |
477 --resource_it->ref_count; | 485 --resource_it->ref_count; |
478 DCHECK_GE(resource_it->ref_count, 0); | 486 DCHECK_GE(resource_it->ref_count, 0); |
479 } | 487 } |
480 | 488 |
481 } // namespace cc | 489 } // namespace cc |
OLD | NEW |