Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(29)

Side by Side Diff: cc/resources/video_resource_updater.cc

Issue 1427543002: Modified old wait sync point functions to also accept new sync tokens. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase + autogen Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 case media::PIXEL_FORMAT_RGB24: 62 case media::PIXEL_FORMAT_RGB24:
63 case media::PIXEL_FORMAT_RGB32: 63 case media::PIXEL_FORMAT_RGB32:
64 case media::PIXEL_FORMAT_MJPEG: 64 case media::PIXEL_FORMAT_MJPEG:
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 SyncTokenClientImpl : public media::VideoFrame::SyncTokenClient {
73 public: 73 public:
74 explicit SyncPointClientImpl(gpu::gles2::GLES2Interface* gl, 74 explicit SyncTokenClientImpl(gpu::gles2::GLES2Interface* gl,
dcheng 2015/11/03 07:39:29 Nit: no explicit, it takes multiple arguments.
David Yen 2015/11/03 18:09:27 Done.
75 uint32 sync_point) 75 const gpu::SyncToken& sync_token)
76 : gl_(gl), sync_point_(sync_point) {} 76 : gl_(gl), sync_token_(sync_token) {}
77 ~SyncPointClientImpl() override {} 77 ~SyncTokenClientImpl() override {}
78 uint32 InsertSyncPoint() override { 78 uint32 InsertSyncPoint() override {
79 if (sync_point_) 79 if (sync_token_.HasData()) {
80 return sync_point_; 80 DCHECK(sync_token_.namespace_id() ==
dcheng 2015/11/03 07:39:29 Nit: DCHECK_EQ(gpu::CommandBufferNamespace::OLD_SY
David Yen 2015/11/03 18:09:28 Done.
81 gpu::CommandBufferNamespace::OLD_SYNC_POINTS);
82 return static_cast<uint32>(sync_token_.release_count());
dcheng 2015/11/03 07:39:29 Out of curiosity, why isn't release_count() just a
David Yen 2015/11/03 18:09:27 The new sync tokens need 64 bit releases to avoid
David Yen 2015/11/03 18:18:36 In case it is unclear, this function will eventual
83 }
81 return gl_->InsertSyncPointCHROMIUM(); 84 return gl_->InsertSyncPointCHROMIUM();
82 } 85 }
83 void WaitSyncPoint(uint32 sync_point) override { 86 void WaitSyncToken(const gpu::SyncToken& sync_token) override {
84 if (!sync_point) 87 if (sync_token.HasData()) {
85 return; 88 gl_->WaitSyncTokenCHROMIUM(sync_token.GetConstData());
86 gl_->WaitSyncPointCHROMIUM(sync_point); 89 if (sync_token_.HasData()) {
87 if (sync_point_) { 90 gl_->WaitSyncTokenCHROMIUM(sync_token_.GetConstData());
88 gl_->WaitSyncPointCHROMIUM(sync_point_); 91 sync_token_.Clear();
89 sync_point_ = 0; 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 gpu::SyncToken sync_token_;
96 }; 99 };
97 100
98 } // namespace 101 } // namespace
99 102
100 VideoResourceUpdater::PlaneResource::PlaneResource( 103 VideoResourceUpdater::PlaneResource::PlaneResource(
101 unsigned int resource_id, 104 unsigned int resource_id,
102 const gfx::Size& resource_size, 105 const gfx::Size& resource_size,
103 ResourceFormat resource_format, 106 ResourceFormat resource_format,
104 gpu::Mailbox mailbox) 107 gpu::Mailbox mailbox)
105 : resource_id(resource_id), 108 : resource_id(resource_id),
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 memcpy(dst, src, bytes_per_row); 377 memcpy(dst, src, bytes_per_row);
375 } 378 }
376 pixels = &upload_pixels_[0]; 379 pixels = &upload_pixels_[0];
377 } 380 }
378 381
379 resource_provider_->CopyToResource(plane_resource.resource_id, pixels, 382 resource_provider_->CopyToResource(plane_resource.resource_id, pixels,
380 resource_size_pixels); 383 resource_size_pixels);
381 SetPlaneResourceUniqueId(video_frame.get(), i, &plane_resource); 384 SetPlaneResourceUniqueId(video_frame.get(), i, &plane_resource);
382 } 385 }
383 386
384 external_resources.mailboxes.push_back( 387 external_resources.mailboxes.push_back(TextureMailbox(
385 TextureMailbox(plane_resource.mailbox, GL_TEXTURE_2D, 0)); 388 plane_resource.mailbox, gpu::SyncToken(), GL_TEXTURE_2D));
386 external_resources.release_callbacks.push_back( 389 external_resources.release_callbacks.push_back(
387 base::Bind(&RecycleResource, AsWeakPtr(), plane_resource.resource_id)); 390 base::Bind(&RecycleResource, AsWeakPtr(), plane_resource.resource_id));
388 } 391 }
389 392
390 external_resources.type = VideoFrameExternalResources::YUV_RESOURCE; 393 external_resources.type = VideoFrameExternalResources::YUV_RESOURCE;
391 return external_resources; 394 return external_resources;
392 } 395 }
393 396
394 // static 397 // static
395 void VideoResourceUpdater::ReturnTexture( 398 void VideoResourceUpdater::ReturnTexture(
396 base::WeakPtr<VideoResourceUpdater> updater, 399 base::WeakPtr<VideoResourceUpdater> updater,
397 const scoped_refptr<media::VideoFrame>& video_frame, 400 const scoped_refptr<media::VideoFrame>& video_frame,
398 uint32 sync_point, 401 const gpu::SyncToken& sync_token,
399 bool lost_resource, 402 bool lost_resource,
400 BlockingTaskRunner* main_thread_task_runner) { 403 BlockingTaskRunner* main_thread_task_runner) {
401 // TODO(dshwang) this case should be forwarded to the decoder as lost 404 // TODO(dshwang) this case should be forwarded to the decoder as lost
402 // resource. 405 // resource.
403 if (lost_resource || !updater.get()) 406 if (lost_resource || !updater.get())
404 return; 407 return;
405 // Update the release sync point in |video_frame| with |sync_point| 408 // Update the release sync point in |video_frame| with |sync_token|
406 // returned by the compositor and emit a WaitSyncPointCHROMIUM on 409 // returned by the compositor and emit a WaitSyncTokenCHROMIUM on
407 // |video_frame|'s previous sync point using the current GL context. 410 // |video_frame|'s previous sync point using the current GL context.
408 SyncPointClientImpl client(updater->context_provider_->ContextGL(), 411 SyncTokenClientImpl client(updater->context_provider_->ContextGL(),
409 sync_point); 412 sync_token);
410 video_frame->UpdateReleaseSyncPoint(&client); 413 video_frame->UpdateReleaseSyncToken(&client);
411 } 414 }
412 415
413 VideoFrameExternalResources VideoResourceUpdater::CreateForHardwarePlanes( 416 VideoFrameExternalResources VideoResourceUpdater::CreateForHardwarePlanes(
414 const scoped_refptr<media::VideoFrame>& video_frame) { 417 const scoped_refptr<media::VideoFrame>& video_frame) {
415 TRACE_EVENT0("cc", "VideoResourceUpdater::CreateForHardwarePlanes"); 418 TRACE_EVENT0("cc", "VideoResourceUpdater::CreateForHardwarePlanes");
416 DCHECK(video_frame->HasTextures()); 419 DCHECK(video_frame->HasTextures());
417 if (!context_provider_) 420 if (!context_provider_)
418 return VideoFrameExternalResources(); 421 return VideoFrameExternalResources();
419 422
420 VideoFrameExternalResources external_resources; 423 VideoFrameExternalResources external_resources;
421 external_resources.read_lock_fences_enabled = true; 424 external_resources.read_lock_fences_enabled = true;
422 425
423 external_resources.type = ResourceTypeForVideoFrame(video_frame.get()); 426 external_resources.type = ResourceTypeForVideoFrame(video_frame.get());
424 if (external_resources.type == VideoFrameExternalResources::NONE) { 427 if (external_resources.type == VideoFrameExternalResources::NONE) {
425 DLOG(ERROR) << "Unsupported Texture format" 428 DLOG(ERROR) << "Unsupported Texture format"
426 << media::VideoPixelFormatToString(video_frame->format()); 429 << media::VideoPixelFormatToString(video_frame->format());
427 return external_resources; 430 return external_resources;
428 } 431 }
429 432
430 const size_t num_planes = media::VideoFrame::NumPlanes(video_frame->format()); 433 const size_t num_planes = media::VideoFrame::NumPlanes(video_frame->format());
431 for (size_t i = 0; i < num_planes; ++i) { 434 for (size_t i = 0; i < num_planes; ++i) {
432 const gpu::MailboxHolder& mailbox_holder = video_frame->mailbox_holder(i); 435 const gpu::MailboxHolder& mailbox_holder = video_frame->mailbox_holder(i);
433 if (mailbox_holder.mailbox.IsZero()) 436 if (mailbox_holder.mailbox.IsZero())
434 break; 437 break;
435 external_resources.mailboxes.push_back( 438 external_resources.mailboxes.push_back(
436 TextureMailbox(mailbox_holder.mailbox, mailbox_holder.texture_target, 439 TextureMailbox(mailbox_holder.mailbox, mailbox_holder.sync_token,
437 mailbox_holder.sync_point, video_frame->coded_size(), 440 mailbox_holder.texture_target, video_frame->coded_size(),
438 video_frame->metadata()->IsTrue( 441 video_frame->metadata()->IsTrue(
439 media::VideoFrameMetadata::ALLOW_OVERLAY))); 442 media::VideoFrameMetadata::ALLOW_OVERLAY)));
440 external_resources.release_callbacks.push_back( 443 external_resources.release_callbacks.push_back(
441 base::Bind(&ReturnTexture, AsWeakPtr(), video_frame)); 444 base::Bind(&ReturnTexture, AsWeakPtr(), video_frame));
442 } 445 }
443 return external_resources; 446 return external_resources;
444 } 447 }
445 448
446 // static 449 // static
447 void VideoResourceUpdater::RecycleResource( 450 void VideoResourceUpdater::RecycleResource(
448 base::WeakPtr<VideoResourceUpdater> updater, 451 base::WeakPtr<VideoResourceUpdater> updater,
449 ResourceId resource_id, 452 ResourceId resource_id,
450 uint32 sync_point, 453 const gpu::SyncToken& sync_token,
451 bool lost_resource, 454 bool lost_resource,
452 BlockingTaskRunner* main_thread_task_runner) { 455 BlockingTaskRunner* main_thread_task_runner) {
453 if (!updater.get()) { 456 if (!updater.get()) {
454 // Resource was already deleted. 457 // Resource was already deleted.
455 return; 458 return;
456 } 459 }
457 460
458 const ResourceList::iterator resource_it = std::find_if( 461 const ResourceList::iterator resource_it = std::find_if(
459 updater->all_resources_.begin(), updater->all_resources_.end(), 462 updater->all_resources_.begin(), updater->all_resources_.end(),
460 [resource_id](const PlaneResource& plane_resource) { 463 [resource_id](const PlaneResource& plane_resource) {
461 return plane_resource.resource_id == resource_id; 464 return plane_resource.resource_id == resource_id;
462 }); 465 });
463 if (resource_it == updater->all_resources_.end()) 466 if (resource_it == updater->all_resources_.end())
464 return; 467 return;
465 468
466 ContextProvider* context_provider = updater->context_provider_; 469 ContextProvider* context_provider = updater->context_provider_;
467 if (context_provider && sync_point) { 470 if (context_provider && sync_token.HasData()) {
468 context_provider->ContextGL()->WaitSyncPointCHROMIUM(sync_point); 471 context_provider->ContextGL()->WaitSyncTokenCHROMIUM(
472 sync_token.GetConstData());
469 } 473 }
470 474
471 if (lost_resource) { 475 if (lost_resource) {
472 resource_it->ref_count = 0; 476 resource_it->ref_count = 0;
473 updater->DeleteResource(resource_it); 477 updater->DeleteResource(resource_it);
474 return; 478 return;
475 } 479 }
476 480
477 --resource_it->ref_count; 481 --resource_it->ref_count;
478 DCHECK_GE(resource_it->ref_count, 0); 482 DCHECK_GE(resource_it->ref_count, 0);
479 } 483 }
480 484
481 } // namespace cc 485 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698