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

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

Issue 1307853003: Add support for converting I420 software frames into NV12 hardware frames (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@biplanar
Patch Set: Created 5 years, 3 months 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"
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:
Daniele Castagna 2015/08/31 16:28:14 Are we return VideoFrameExternalResources::IO_SURF
Andre 2015/08/31 18:29:31 That's right. It's also a better fit because it ha
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 case media::PIXEL_FORMAT_NV12:
51 DCHECK_EQ(static_cast<uint32_t>(GL_TEXTURE_RECTANGLE_ARB),
52 video_frame->mailbox_holder(0).texture_target);
53 return VideoFrameExternalResources::IO_SURFACE;
54 case media::PIXEL_FORMAT_YV12:
55 case media::PIXEL_FORMAT_YV16:
56 case media::PIXEL_FORMAT_YV24:
57 case media::PIXEL_FORMAT_YV12A:
58 case media::PIXEL_FORMAT_UNKNOWN:
59 break;
60 }
61 return VideoFrameExternalResources::NONE;
62 }
63
28 class SyncPointClientImpl : public media::VideoFrame::SyncPointClient { 64 class SyncPointClientImpl : public media::VideoFrame::SyncPointClient {
29 public: 65 public:
30 explicit SyncPointClientImpl(gpu::gles2::GLES2Interface* gl, 66 explicit SyncPointClientImpl(gpu::gles2::GLES2Interface* gl,
31 uint32 sync_point) 67 uint32 sync_point)
32 : gl_(gl), sync_point_(sync_point) {} 68 : gl_(gl), sync_point_(sync_point) {}
33 ~SyncPointClientImpl() override {} 69 ~SyncPointClientImpl() override {}
34 uint32 InsertSyncPoint() override { 70 uint32 InsertSyncPoint() override {
35 if (sync_point_) 71 if (sync_point_)
36 return sync_point_; 72 return sync_point_;
37 return gl_->InsertSyncPointCHROMIUM(); 73 return gl_->InsertSyncPointCHROMIUM();
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 video_frame->UpdateReleaseSyncPoint(&client); 404 video_frame->UpdateReleaseSyncPoint(&client);
369 } 405 }
370 406
371 VideoFrameExternalResources VideoResourceUpdater::CreateForHardwarePlanes( 407 VideoFrameExternalResources VideoResourceUpdater::CreateForHardwarePlanes(
372 const scoped_refptr<media::VideoFrame>& video_frame) { 408 const scoped_refptr<media::VideoFrame>& video_frame) {
373 TRACE_EVENT0("cc", "VideoResourceUpdater::CreateForHardwarePlanes"); 409 TRACE_EVENT0("cc", "VideoResourceUpdater::CreateForHardwarePlanes");
374 DCHECK(video_frame->HasTextures()); 410 DCHECK(video_frame->HasTextures());
375 if (!context_provider_) 411 if (!context_provider_)
376 return VideoFrameExternalResources(); 412 return VideoFrameExternalResources();
377 413
378 const size_t textures = media::VideoFrame::NumPlanes(video_frame->format());
379 DCHECK_GE(textures, 1u);
380 VideoFrameExternalResources external_resources; 414 VideoFrameExternalResources external_resources;
381 external_resources.read_lock_fences_enabled = true; 415 external_resources.read_lock_fences_enabled = true;
382 switch (video_frame->format()) { 416
383 case media::PIXEL_FORMAT_ARGB: 417 external_resources.type = ResourceTypeForVideoFrame(video_frame.get());
384 case media::PIXEL_FORMAT_XRGB: 418 if (external_resources.type == VideoFrameExternalResources::NONE) {
385 case media::PIXEL_FORMAT_UYVY: 419 DLOG(ERROR) << "Unsupported Texture format"
386 DCHECK_EQ(1u, textures); 420 << media::VideoPixelFormatToString(video_frame->format());
387 switch (video_frame->mailbox_holder(0).texture_target) { 421 return external_resources;
388 case GL_TEXTURE_2D: 422 }
389 external_resources.type = 423
390 (video_frame->format() == media::PIXEL_FORMAT_XRGB) 424 const size_t num_planes = media::VideoFrame::NumPlanes(video_frame->format());
391 ? VideoFrameExternalResources::RGB_RESOURCE 425 for (size_t i = 0; i < num_planes; ++i) {
392 : VideoFrameExternalResources::RGBA_RESOURCE; 426 const gpu::MailboxHolder& mailbox_holder = video_frame->mailbox_holder(i);
393 break; 427 if (mailbox_holder.mailbox.IsZero())
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; 428 break;
406 case media::PIXEL_FORMAT_I420:
407 external_resources.type = VideoFrameExternalResources::YUV_RESOURCE;
408 break;
409 case media::PIXEL_FORMAT_NV12:
410 case media::PIXEL_FORMAT_YV12:
411 case media::PIXEL_FORMAT_YV16:
412 case media::PIXEL_FORMAT_YV24:
413 case media::PIXEL_FORMAT_YV12A:
414 case media::PIXEL_FORMAT_UNKNOWN:
415 DLOG(ERROR) << "Unsupported Texture format"
416 << media::VideoPixelFormatToString(video_frame->format());
417 return external_resources;
418 }
419 DCHECK_NE(VideoFrameExternalResources::NONE, external_resources.type);
420
421 for (size_t i = 0; i < textures; ++i) {
422 const gpu::MailboxHolder& mailbox_holder = video_frame->mailbox_holder(i);
423 external_resources.mailboxes.push_back( 429 external_resources.mailboxes.push_back(
424 TextureMailbox(mailbox_holder.mailbox, mailbox_holder.texture_target, 430 TextureMailbox(mailbox_holder.mailbox, mailbox_holder.texture_target,
425 mailbox_holder.sync_point, video_frame->coded_size(), 431 mailbox_holder.sync_point, video_frame->coded_size(),
426 video_frame->metadata()->IsTrue( 432 video_frame->metadata()->IsTrue(
427 media::VideoFrameMetadata::ALLOW_OVERLAY))); 433 media::VideoFrameMetadata::ALLOW_OVERLAY)));
428 external_resources.release_callbacks.push_back( 434 external_resources.release_callbacks.push_back(
429 base::Bind(&ReturnTexture, AsWeakPtr(), video_frame)); 435 base::Bind(&ReturnTexture, AsWeakPtr(), video_frame));
430 } 436 }
431 return external_resources; 437 return external_resources;
432 } 438 }
(...skipping 27 matching lines...) Expand all
460 resource_it->ref_count = 0; 466 resource_it->ref_count = 0;
461 updater->DeleteResource(resource_it); 467 updater->DeleteResource(resource_it);
462 return; 468 return;
463 } 469 }
464 470
465 --resource_it->ref_count; 471 --resource_it->ref_count;
466 DCHECK_GE(resource_it->ref_count, 0); 472 DCHECK_GE(resource_it->ref_count, 0);
467 } 473 }
468 474
469 } // namespace cc 475 } // namespace cc
OLDNEW
« no previous file with comments | « no previous file | media/base/video_frame.cc » ('j') | media/video/gpu_memory_buffer_video_frame_pool.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698