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

Side by Side Diff: media/base/video_frame.cc

Issue 132233041: Add gpu::MailboxHolder to hold state for a gpu::Mailbox (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: ff7262fa Rebase. Created 6 years, 10 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 | Annotate | Revision Log
« no previous file with comments | « media/base/video_frame.h ('k') | media/base/video_frame_unittest.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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "media/base/video_frame.h" 5 #include "media/base/video_frame.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/callback_helpers.h" 10 #include "base/callback_helpers.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/memory/aligned_memory.h" 12 #include "base/memory/aligned_memory.h"
13 #include "base/strings/string_piece.h" 13 #include "base/strings/string_piece.h"
14 #include "gpu/command_buffer/common/mailbox_holder.h"
14 #include "media/base/limits.h" 15 #include "media/base/limits.h"
15 #include "media/base/video_util.h" 16 #include "media/base/video_util.h"
16 #include "third_party/skia/include/core/SkBitmap.h" 17 #include "third_party/skia/include/core/SkBitmap.h"
17 18
18 namespace media { 19 namespace media {
19 20
20 // static 21 // static
21 scoped_refptr<VideoFrame> VideoFrame::CreateFrame( 22 scoped_refptr<VideoFrame> VideoFrame::CreateFrame(
22 VideoFrame::Format format, 23 VideoFrame::Format format,
23 const gfx::Size& coded_size, 24 const gfx::Size& coded_size,
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 visible_rect.right() <= coded_size.width() && 85 visible_rect.right() <= coded_size.width() &&
85 visible_rect.bottom() <= coded_size.height() && 86 visible_rect.bottom() <= coded_size.height() &&
86 !natural_size.IsEmpty() && 87 !natural_size.IsEmpty() &&
87 natural_size.GetArea() <= limits::kMaxCanvas && 88 natural_size.GetArea() <= limits::kMaxCanvas &&
88 natural_size.width() <= limits::kMaxDimension && 89 natural_size.width() <= limits::kMaxDimension &&
89 natural_size.height() <= limits::kMaxDimension); 90 natural_size.height() <= limits::kMaxDimension);
90 } 91 }
91 92
92 // static 93 // static
93 scoped_refptr<VideoFrame> VideoFrame::WrapNativeTexture( 94 scoped_refptr<VideoFrame> VideoFrame::WrapNativeTexture(
94 scoped_ptr<MailboxHolder> mailbox_holder, 95 scoped_ptr<gpu::MailboxHolder> mailbox_holder,
95 uint32 texture_target, 96 const ReleaseMailboxCB& mailbox_holder_release_cb,
96 const gfx::Size& coded_size, 97 const gfx::Size& coded_size,
97 const gfx::Rect& visible_rect, 98 const gfx::Rect& visible_rect,
98 const gfx::Size& natural_size, 99 const gfx::Size& natural_size,
99 base::TimeDelta timestamp, 100 base::TimeDelta timestamp,
100 const ReadPixelsCB& read_pixels_cb, 101 const ReadPixelsCB& read_pixels_cb) {
101 const base::Closure& no_longer_needed_cb) {
102 scoped_refptr<VideoFrame> frame(new VideoFrame(NATIVE_TEXTURE, 102 scoped_refptr<VideoFrame> frame(new VideoFrame(NATIVE_TEXTURE,
103 coded_size, 103 coded_size,
104 visible_rect, 104 visible_rect,
105 natural_size, 105 natural_size,
106 timestamp, 106 timestamp,
107 false)); 107 false));
108 frame->texture_mailbox_holder_ = mailbox_holder.Pass(); 108 frame->mailbox_holder_ = mailbox_holder.Pass();
109 frame->texture_target_ = texture_target; 109 frame->mailbox_holder_release_cb_ = mailbox_holder_release_cb;
110 frame->read_pixels_cb_ = read_pixels_cb; 110 frame->read_pixels_cb_ = read_pixels_cb;
111 frame->no_longer_needed_cb_ = no_longer_needed_cb;
112 111
113 return frame; 112 return frame;
114 } 113 }
115 114
116 void VideoFrame::ReadPixelsFromNativeTexture(const SkBitmap& pixels) { 115 void VideoFrame::ReadPixelsFromNativeTexture(const SkBitmap& pixels) {
117 DCHECK_EQ(format_, NATIVE_TEXTURE); 116 DCHECK_EQ(format_, NATIVE_TEXTURE);
118 if (!read_pixels_cb_.is_null()) 117 if (!read_pixels_cb_.is_null())
119 read_pixels_cb_.Run(pixels); 118 read_pixels_cb_.Run(pixels);
120 } 119 }
121 120
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 VideoFrame::VideoFrame(VideoFrame::Format format, 400 VideoFrame::VideoFrame(VideoFrame::Format format,
402 const gfx::Size& coded_size, 401 const gfx::Size& coded_size,
403 const gfx::Rect& visible_rect, 402 const gfx::Rect& visible_rect,
404 const gfx::Size& natural_size, 403 const gfx::Size& natural_size,
405 base::TimeDelta timestamp, 404 base::TimeDelta timestamp,
406 bool end_of_stream) 405 bool end_of_stream)
407 : format_(format), 406 : format_(format),
408 coded_size_(coded_size), 407 coded_size_(coded_size),
409 visible_rect_(visible_rect), 408 visible_rect_(visible_rect),
410 natural_size_(natural_size), 409 natural_size_(natural_size),
411 texture_target_(0),
412 shared_memory_handle_(base::SharedMemory::NULLHandle()), 410 shared_memory_handle_(base::SharedMemory::NULLHandle()),
413 timestamp_(timestamp), 411 timestamp_(timestamp),
414 end_of_stream_(end_of_stream) { 412 end_of_stream_(end_of_stream) {
415 memset(&strides_, 0, sizeof(strides_)); 413 memset(&strides_, 0, sizeof(strides_));
416 memset(&data_, 0, sizeof(data_)); 414 memset(&data_, 0, sizeof(data_));
417 } 415 }
418 416
419 VideoFrame::~VideoFrame() { 417 VideoFrame::~VideoFrame() {
418 if (!mailbox_holder_release_cb_.is_null()) {
419 base::ResetAndReturn(&mailbox_holder_release_cb_)
420 .Run(mailbox_holder_.Pass());
421 }
420 if (!no_longer_needed_cb_.is_null()) 422 if (!no_longer_needed_cb_.is_null())
421 base::ResetAndReturn(&no_longer_needed_cb_).Run(); 423 base::ResetAndReturn(&no_longer_needed_cb_).Run();
422 } 424 }
423 425
424 bool VideoFrame::IsValidPlane(size_t plane) const { 426 bool VideoFrame::IsValidPlane(size_t plane) const {
425 return (plane < NumPlanes(format_)); 427 return (plane < NumPlanes(format_));
426 } 428 }
427 429
428 int VideoFrame::stride(size_t plane) const { 430 int VideoFrame::stride(size_t plane) const {
429 DCHECK(IsValidPlane(plane)); 431 DCHECK(IsValidPlane(plane));
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
480 // Intentionally leave out non-production formats. 482 // Intentionally leave out non-production formats.
481 NOTREACHED() << "Unsupported video frame format: " << format_; 483 NOTREACHED() << "Unsupported video frame format: " << format_;
482 return 0; 484 return 0;
483 } 485 }
484 486
485 uint8* VideoFrame::data(size_t plane) const { 487 uint8* VideoFrame::data(size_t plane) const {
486 DCHECK(IsValidPlane(plane)); 488 DCHECK(IsValidPlane(plane));
487 return data_[plane]; 489 return data_[plane];
488 } 490 }
489 491
490 VideoFrame::MailboxHolder* VideoFrame::texture_mailbox() const { 492 gpu::MailboxHolder* VideoFrame::mailbox_holder() const {
491 DCHECK_EQ(format_, NATIVE_TEXTURE); 493 DCHECK_EQ(format_, NATIVE_TEXTURE);
492 return texture_mailbox_holder_.get(); 494 return mailbox_holder_.get();
493 }
494
495 uint32 VideoFrame::texture_target() const {
496 DCHECK_EQ(format_, NATIVE_TEXTURE);
497 return texture_target_;
498 } 495 }
499 496
500 base::SharedMemoryHandle VideoFrame::shared_memory_handle() const { 497 base::SharedMemoryHandle VideoFrame::shared_memory_handle() const {
501 return shared_memory_handle_; 498 return shared_memory_handle_;
502 } 499 }
503 500
504 void VideoFrame::HashFrameForTesting(base::MD5Context* context) { 501 void VideoFrame::HashFrameForTesting(base::MD5Context* context) {
505 for (int plane = 0; plane < kMaxPlanes; ++plane) { 502 for (int plane = 0; plane < kMaxPlanes; ++plane) {
506 if (!IsValidPlane(plane)) 503 if (!IsValidPlane(plane))
507 break; 504 break;
508 for (int row = 0; row < rows(plane); ++row) { 505 for (int row = 0; row < rows(plane); ++row) {
509 base::MD5Update(context, base::StringPiece( 506 base::MD5Update(context, base::StringPiece(
510 reinterpret_cast<char*>(data(plane) + stride(plane) * row), 507 reinterpret_cast<char*>(data(plane) + stride(plane) * row),
511 row_bytes(plane))); 508 row_bytes(plane)));
512 } 509 }
513 } 510 }
514 } 511 }
515 512
516 VideoFrame::MailboxHolder::MailboxHolder(
517 const gpu::Mailbox& mailbox,
518 unsigned sync_point,
519 const TextureNoLongerNeededCallback& release_callback)
520 : mailbox_(mailbox),
521 sync_point_(sync_point),
522 release_callback_(release_callback) {}
523
524 VideoFrame::MailboxHolder::~MailboxHolder() {
525 if (!release_callback_.is_null())
526 release_callback_.Run(sync_point_);
527 }
528
529 } // namespace media 513 } // namespace media
OLDNEW
« no previous file with comments | « media/base/video_frame.h ('k') | media/base/video_frame_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698