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

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: Fix build 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
« no previous file with comments | « no previous file | media/base/video_frame.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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:
34 switch (video_frame->mailbox_holder(0).texture_target) {
35 case GL_TEXTURE_2D:
36 return (video_frame->format() == media::PIXEL_FORMAT_XRGB)
sandersd (OOO until July 31) 2015/09/08 23:09:57 Indent.
danakj 2015/09/08 23:13:48 Please run git cl format on any patch that touches
Andre 2015/09/09 00:40:44 Done.
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:
ccameron 2015/09/08 23:09:09 I'm a little bit afraid we'll hit this on a non-Ma
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
28 class SyncPointClientImpl : public media::VideoFrame::SyncPointClient { 71 class SyncPointClientImpl : public media::VideoFrame::SyncPointClient {
29 public: 72 public:
30 explicit SyncPointClientImpl(gpu::gles2::GLES2Interface* gl, 73 explicit SyncPointClientImpl(gpu::gles2::GLES2Interface* gl,
31 uint32 sync_point) 74 uint32 sync_point)
32 : gl_(gl), sync_point_(sync_point) {} 75 : gl_(gl), sync_point_(sync_point) {}
33 ~SyncPointClientImpl() override {} 76 ~SyncPointClientImpl() override {}
34 uint32 InsertSyncPoint() override { 77 uint32 InsertSyncPoint() override {
35 if (sync_point_) 78 if (sync_point_)
36 return sync_point_; 79 return sync_point_;
37 return gl_->InsertSyncPointCHROMIUM(); 80 return gl_->InsertSyncPointCHROMIUM();
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 video_frame->UpdateReleaseSyncPoint(&client); 411 video_frame->UpdateReleaseSyncPoint(&client);
369 } 412 }
370 413
371 VideoFrameExternalResources VideoResourceUpdater::CreateForHardwarePlanes( 414 VideoFrameExternalResources VideoResourceUpdater::CreateForHardwarePlanes(
372 const scoped_refptr<media::VideoFrame>& video_frame) { 415 const scoped_refptr<media::VideoFrame>& video_frame) {
373 TRACE_EVENT0("cc", "VideoResourceUpdater::CreateForHardwarePlanes"); 416 TRACE_EVENT0("cc", "VideoResourceUpdater::CreateForHardwarePlanes");
374 DCHECK(video_frame->HasTextures()); 417 DCHECK(video_frame->HasTextures());
375 if (!context_provider_) 418 if (!context_provider_)
376 return VideoFrameExternalResources(); 419 return VideoFrameExternalResources();
377 420
378 const size_t textures = media::VideoFrame::NumPlanes(video_frame->format());
379 DCHECK_GE(textures, 1u);
380 VideoFrameExternalResources external_resources; 421 VideoFrameExternalResources external_resources;
381 external_resources.read_lock_fences_enabled = true; 422 external_resources.read_lock_fences_enabled = true;
382 switch (video_frame->format()) { 423
383 case media::PIXEL_FORMAT_ARGB: 424 external_resources.type = ResourceTypeForVideoFrame(video_frame.get());
384 case media::PIXEL_FORMAT_XRGB: 425 if (external_resources.type == VideoFrameExternalResources::NONE) {
385 case media::PIXEL_FORMAT_UYVY: 426 DLOG(ERROR) << "Unsupported Texture format"
386 DCHECK_EQ(1u, textures); 427 << media::VideoPixelFormatToString(video_frame->format());
387 switch (video_frame->mailbox_holder(0).texture_target) { 428 return external_resources;
388 case GL_TEXTURE_2D: 429 }
389 external_resources.type = 430
390 (video_frame->format() == media::PIXEL_FORMAT_XRGB) 431 const size_t num_planes = media::VideoFrame::NumPlanes(video_frame->format());
391 ? VideoFrameExternalResources::RGB_RESOURCE 432 for (size_t i = 0; i < num_planes; ++i) {
392 : VideoFrameExternalResources::RGBA_RESOURCE; 433 const gpu::MailboxHolder& mailbox_holder = video_frame->mailbox_holder(i);
393 break; 434 if (mailbox_holder.mailbox.IsZero())
ccameron 2015/09/08 23:09:09 IIUC, for NV12, num_planes will be 2, but we'll on
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; 435 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);
425
426 for (size_t i = 0; i < textures; ++i) {
427 const gpu::MailboxHolder& mailbox_holder = video_frame->mailbox_holder(i);
428 external_resources.mailboxes.push_back( 436 external_resources.mailboxes.push_back(
429 TextureMailbox(mailbox_holder.mailbox, mailbox_holder.texture_target, 437 TextureMailbox(mailbox_holder.mailbox, mailbox_holder.texture_target,
430 mailbox_holder.sync_point, video_frame->coded_size(), 438 mailbox_holder.sync_point, video_frame->coded_size(),
431 video_frame->metadata()->IsTrue( 439 video_frame->metadata()->IsTrue(
432 media::VideoFrameMetadata::ALLOW_OVERLAY))); 440 media::VideoFrameMetadata::ALLOW_OVERLAY)));
433 external_resources.release_callbacks.push_back( 441 external_resources.release_callbacks.push_back(
434 base::Bind(&ReturnTexture, AsWeakPtr(), video_frame)); 442 base::Bind(&ReturnTexture, AsWeakPtr(), video_frame));
435 } 443 }
436 return external_resources; 444 return external_resources;
437 } 445 }
(...skipping 27 matching lines...) Expand all
465 resource_it->ref_count = 0; 473 resource_it->ref_count = 0;
466 updater->DeleteResource(resource_it); 474 updater->DeleteResource(resource_it);
467 return; 475 return;
468 } 476 }
469 477
470 --resource_it->ref_count; 478 --resource_it->ref_count;
471 DCHECK_GE(resource_it->ref_count, 0); 479 DCHECK_GE(resource_it->ref_count, 0);
472 } 480 }
473 481
474 } // namespace cc 482 } // namespace cc
OLDNEW
« no previous file with comments | « no previous file | media/base/video_frame.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698