| 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" |
| 11 #include "cc/base/math_util.h" | 11 #include "cc/base/math_util.h" |
| 12 #include "cc/output/gl_renderer.h" | 12 #include "cc/output/gl_renderer.h" |
| 13 #include "cc/resources/resource_provider.h" | 13 #include "cc/resources/resource_provider.h" |
| 14 #include "gpu/GLES2/gl2extchromium.h" | 14 #include "gpu/GLES2/gl2extchromium.h" |
| 15 #include "gpu/command_buffer/client/gles2_interface.h" | 15 #include "gpu/command_buffer/client/gles2_interface.h" |
| 16 #include "media/base/video_frame.h" | 16 #include "media/base/video_frame.h" |
| 17 #include "media/blink/skcanvas_video_renderer.h" | 17 #include "media/blink/skcanvas_video_renderer.h" |
| 18 #include "third_party/khronos/GLES2/gl2.h" | 18 #include "third_party/khronos/GLES2/gl2.h" |
| 19 #include "third_party/khronos/GLES2/gl2ext.h" | 19 #include "third_party/khronos/GLES2/gl2ext.h" |
| 20 #include "ui/gfx/geometry/size_conversions.h" | 20 #include "ui/gfx/geometry/size_conversions.h" |
| 21 | 21 |
| 22 namespace cc { | 22 namespace cc { |
| 23 | 23 |
| 24 namespace { | 24 namespace { |
| 25 | 25 |
| 26 const ResourceFormat kRGBResourceFormat = RGBA_8888; | 26 const ResourceFormat kRGBResourceFormat = RGBA_8888; |
| 27 | 27 |
| 28 VideoFrameExternalResources::ResourceType ResourceTypeForVideoFrame( | |
| 29 media::VideoFrame* video_frame) { | |
| 30 switch (video_frame->format()) { | |
| 31 case media::PIXEL_FORMAT_ARGB: | |
| 32 case media::PIXEL_FORMAT_XRGB: | |
| 33 case media::PIXEL_FORMAT_UYVY: | |
| 34 switch (video_frame->mailbox_holder(0).texture_target) { | |
| 35 case GL_TEXTURE_2D: | |
| 36 return (video_frame->format() == media::PIXEL_FORMAT_XRGB) | |
| 37 ? VideoFrameExternalResources::RGB_RESOURCE | |
| 38 : VideoFrameExternalResources::RGBA_RESOURCE; | |
| 39 case GL_TEXTURE_EXTERNAL_OES: | |
| 40 return VideoFrameExternalResources::STREAM_TEXTURE_RESOURCE; | |
| 41 case GL_TEXTURE_RECTANGLE_ARB: | |
| 42 return VideoFrameExternalResources::IO_SURFACE; | |
| 43 default: | |
| 44 NOTREACHED(); | |
| 45 break; | |
| 46 } | |
| 47 break; | |
| 48 case media::PIXEL_FORMAT_I420: | |
| 49 return VideoFrameExternalResources::YUV_RESOURCE; | |
| 50 break; | |
| 51 case media::PIXEL_FORMAT_NV12: | |
| 52 DCHECK_EQ(static_cast<uint32_t>(GL_TEXTURE_RECTANGLE_ARB), | |
| 53 video_frame->mailbox_holder(0).texture_target); | |
| 54 return VideoFrameExternalResources::IO_SURFACE; | |
| 55 break; | |
| 56 case media::PIXEL_FORMAT_YV12: | |
| 57 case media::PIXEL_FORMAT_YV16: | |
| 58 case media::PIXEL_FORMAT_YV24: | |
| 59 case media::PIXEL_FORMAT_YV12A: | |
| 60 case media::PIXEL_FORMAT_NV21: | |
| 61 case media::PIXEL_FORMAT_YUY2: | |
| 62 case media::PIXEL_FORMAT_RGB24: | |
| 63 case media::PIXEL_FORMAT_RGB32: | |
| 64 case media::PIXEL_FORMAT_MJPEG: | |
| 65 case media::PIXEL_FORMAT_UNKNOWN: | |
| 66 break; | |
| 67 } | |
| 68 return VideoFrameExternalResources::NONE; | |
| 69 } | |
| 70 | |
| 71 class SyncPointClientImpl : public media::VideoFrame::SyncPointClient { | 28 class SyncPointClientImpl : public media::VideoFrame::SyncPointClient { |
| 72 public: | 29 public: |
| 73 explicit SyncPointClientImpl(gpu::gles2::GLES2Interface* gl, | 30 explicit SyncPointClientImpl(gpu::gles2::GLES2Interface* gl, |
| 74 uint32 sync_point) | 31 uint32 sync_point) |
| 75 : gl_(gl), sync_point_(sync_point) {} | 32 : gl_(gl), sync_point_(sync_point) {} |
| 76 ~SyncPointClientImpl() override {} | 33 ~SyncPointClientImpl() override {} |
| 77 uint32 InsertSyncPoint() override { | 34 uint32 InsertSyncPoint() override { |
| 78 if (sync_point_) | 35 if (sync_point_) |
| 79 return sync_point_; | 36 return sync_point_; |
| 80 return gl_->InsertSyncPointCHROMIUM(); | 37 return gl_->InsertSyncPointCHROMIUM(); |
| (...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 411 video_frame->UpdateReleaseSyncPoint(&client); | 368 video_frame->UpdateReleaseSyncPoint(&client); |
| 412 } | 369 } |
| 413 | 370 |
| 414 VideoFrameExternalResources VideoResourceUpdater::CreateForHardwarePlanes( | 371 VideoFrameExternalResources VideoResourceUpdater::CreateForHardwarePlanes( |
| 415 const scoped_refptr<media::VideoFrame>& video_frame) { | 372 const scoped_refptr<media::VideoFrame>& video_frame) { |
| 416 TRACE_EVENT0("cc", "VideoResourceUpdater::CreateForHardwarePlanes"); | 373 TRACE_EVENT0("cc", "VideoResourceUpdater::CreateForHardwarePlanes"); |
| 417 DCHECK(video_frame->HasTextures()); | 374 DCHECK(video_frame->HasTextures()); |
| 418 if (!context_provider_) | 375 if (!context_provider_) |
| 419 return VideoFrameExternalResources(); | 376 return VideoFrameExternalResources(); |
| 420 | 377 |
| 378 const size_t textures = media::VideoFrame::NumPlanes(video_frame->format()); |
| 379 DCHECK_GE(textures, 1u); |
| 421 VideoFrameExternalResources external_resources; | 380 VideoFrameExternalResources external_resources; |
| 422 external_resources.read_lock_fences_enabled = true; | 381 external_resources.read_lock_fences_enabled = true; |
| 382 switch (video_frame->format()) { |
| 383 case media::PIXEL_FORMAT_ARGB: |
| 384 case media::PIXEL_FORMAT_XRGB: |
| 385 case media::PIXEL_FORMAT_UYVY: |
| 386 DCHECK_EQ(1u, textures); |
| 387 switch (video_frame->mailbox_holder(0).texture_target) { |
| 388 case GL_TEXTURE_2D: |
| 389 external_resources.type = |
| 390 (video_frame->format() == media::PIXEL_FORMAT_XRGB) |
| 391 ? VideoFrameExternalResources::RGB_RESOURCE |
| 392 : VideoFrameExternalResources::RGBA_RESOURCE; |
| 393 break; |
| 394 case GL_TEXTURE_EXTERNAL_OES: |
| 395 external_resources.type = |
| 396 VideoFrameExternalResources::STREAM_TEXTURE_RESOURCE; |
| 397 break; |
| 398 case GL_TEXTURE_RECTANGLE_ARB: |
| 399 external_resources.type = VideoFrameExternalResources::IO_SURFACE; |
| 400 break; |
| 401 default: |
| 402 NOTREACHED(); |
| 403 return VideoFrameExternalResources(); |
| 404 } |
| 405 break; |
| 406 case media::PIXEL_FORMAT_I420: |
| 407 external_resources.type = VideoFrameExternalResources::YUV_RESOURCE; |
| 408 break; |
| 409 case media::PIXEL_FORMAT_YV12: |
| 410 case media::PIXEL_FORMAT_YV16: |
| 411 case media::PIXEL_FORMAT_YV24: |
| 412 case media::PIXEL_FORMAT_YV12A: |
| 413 case media::PIXEL_FORMAT_NV12: |
| 414 case media::PIXEL_FORMAT_NV21: |
| 415 case media::PIXEL_FORMAT_YUY2: |
| 416 case media::PIXEL_FORMAT_RGB24: |
| 417 case media::PIXEL_FORMAT_RGB32: |
| 418 case media::PIXEL_FORMAT_MJPEG: |
| 419 case media::PIXEL_FORMAT_UNKNOWN: |
| 420 DLOG(ERROR) << "Unsupported Texture format" |
| 421 << media::VideoPixelFormatToString(video_frame->format()); |
| 422 return external_resources; |
| 423 } |
| 424 DCHECK_NE(VideoFrameExternalResources::NONE, external_resources.type); |
| 423 | 425 |
| 424 external_resources.type = ResourceTypeForVideoFrame(video_frame.get()); | 426 for (size_t i = 0; i < textures; ++i) { |
| 425 if (external_resources.type == VideoFrameExternalResources::NONE) { | |
| 426 DLOG(ERROR) << "Unsupported Texture format" | |
| 427 << media::VideoPixelFormatToString(video_frame->format()); | |
| 428 return external_resources; | |
| 429 } | |
| 430 | |
| 431 const size_t num_planes = media::VideoFrame::NumPlanes(video_frame->format()); | |
| 432 for (size_t i = 0; i < num_planes; ++i) { | |
| 433 const gpu::MailboxHolder& mailbox_holder = video_frame->mailbox_holder(i); | 427 const gpu::MailboxHolder& mailbox_holder = video_frame->mailbox_holder(i); |
| 434 if (mailbox_holder.mailbox.IsZero()) | |
| 435 break; | |
| 436 external_resources.mailboxes.push_back( | 428 external_resources.mailboxes.push_back( |
| 437 TextureMailbox(mailbox_holder.mailbox, mailbox_holder.texture_target, | 429 TextureMailbox(mailbox_holder.mailbox, mailbox_holder.texture_target, |
| 438 mailbox_holder.sync_point, video_frame->coded_size(), | 430 mailbox_holder.sync_point, video_frame->coded_size(), |
| 439 video_frame->metadata()->IsTrue( | 431 video_frame->metadata()->IsTrue( |
| 440 media::VideoFrameMetadata::ALLOW_OVERLAY))); | 432 media::VideoFrameMetadata::ALLOW_OVERLAY))); |
| 441 external_resources.release_callbacks.push_back( | 433 external_resources.release_callbacks.push_back( |
| 442 base::Bind(&ReturnTexture, AsWeakPtr(), video_frame)); | 434 base::Bind(&ReturnTexture, AsWeakPtr(), video_frame)); |
| 443 } | 435 } |
| 444 return external_resources; | 436 return external_resources; |
| 445 } | 437 } |
| (...skipping 27 matching lines...) Expand all Loading... |
| 473 resource_it->ref_count = 0; | 465 resource_it->ref_count = 0; |
| 474 updater->DeleteResource(resource_it); | 466 updater->DeleteResource(resource_it); |
| 475 return; | 467 return; |
| 476 } | 468 } |
| 477 | 469 |
| 478 --resource_it->ref_count; | 470 --resource_it->ref_count; |
| 479 DCHECK_GE(resource_it->ref_count, 0); | 471 DCHECK_GE(resource_it->ref_count, 0); |
| 480 } | 472 } |
| 481 | 473 |
| 482 } // namespace cc | 474 } // namespace cc |
| OLD | NEW |