summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoremircan <emircan@chromium.org>2016-03-23 19:18:52 -0700
committerCommit bot <commit-bot@chromium.org>2016-03-24 02:20:36 +0000
commitaed06ff043b4d93701f2fd0c3c79f5bfd04395bb (patch)
tree21d80539436c3c92221e46fb76c574430af02854
parentd4e1aca665cc308f3f1ff02b569d94098df26d15 (diff)
downloadchromium_src-aed06ff043b4d93701f2fd0c3c79f5bfd04395bb.zip
chromium_src-aed06ff043b4d93701f2fd0c3c79f5bfd04395bb.tar.gz
chromium_src-aed06ff043b4d93701f2fd0c3c79f5bfd04395bb.tar.bz2
Add alpha channel stride on CanvasCaptureHandler
This CL adds stride support for cases where canvas has aligned alpha channel. Note that, this code is still temporary and will be replaced by libyuv::ARGBToA when available. BUG= 524218 TEST= http://software.hixie.ch/utilities/js/live-dom-viewer/?saved=3905 Review URL: https://codereview.chromium.org/1826923002 Cr-Commit-Position: refs/heads/master@{#383017}
-rw-r--r--content/renderer/media/canvas_capture_handler.cc33
1 files changed, 29 insertions, 4 deletions
diff --git a/content/renderer/media/canvas_capture_handler.cc b/content/renderer/media/canvas_capture_handler.cc
index 6056712..e0d6089e 100644
--- a/content/renderer/media/canvas_capture_handler.cc
+++ b/content/renderer/media/canvas_capture_handler.cc
@@ -21,6 +21,32 @@
#include "third_party/WebKit/public/platform/WebString.h"
#include "third_party/libyuv/include/libyuv.h"
+namespace {
+
+static void CopyAlphaChannelIntoVideoFrame(
+ const uint8_t* const source,
+ const scoped_refptr<media::VideoFrame>& dest_frame) {
+ const gfx::Size& size = dest_frame->coded_size();
+ const int stride = dest_frame->stride(media::VideoFrame::kAPlane);
+
+ if (stride == size.width()) {
+ for (int p = 0; p < size.GetArea(); ++p)
+ dest_frame->data(media::VideoFrame::kAPlane)[p] = source[p * 4 + 3];
+ return;
+ }
+
+ // Copy apha values one-by-one if the destination stride != source width.
+ for (int h = 0; h < size.height(); ++h) {
+ const uint8_t* const src_ptr = &source[4 * h * size.width()];
+ uint8_t* dest_ptr =
+ &dest_frame->data(media::VideoFrame::kAPlane)[h * stride];
+ for (int pixel_index = 0; pixel_index < 4 * size.width(); pixel_index += 4)
+ *(dest_ptr++) = src_ptr[pixel_index + 3];
+ }
+}
+
+} // namespace
+
namespace content {
// Implementation VideoCapturerSource that is owned by
@@ -203,8 +229,6 @@ void CanvasCaptureHandler::CreateNewFrame(const SkImage* image) {
gfx::Rect(size), size, timestamp - base::TimeTicks());
DCHECK(video_frame);
- // TODO(emircan): Use https://code.google.com/p/libyuv/issues/detail?id=572
- // when it becomes available.
libyuv::ARGBToI420(temp_data_.data(), row_bytes_,
video_frame->data(media::VideoFrame::kYPlane),
video_frame->stride(media::VideoFrame::kYPlane),
@@ -214,8 +238,9 @@ void CanvasCaptureHandler::CreateNewFrame(const SkImage* image) {
video_frame->stride(media::VideoFrame::kVPlane),
size.width(), size.height());
if (!isOpaque) {
- for (int p = 0; p < size.GetArea(); ++p)
- video_frame->data(media::VideoFrame::kAPlane)[p] = temp_data_[p * 4 + 3];
+ // TODO(emircan): Use https://code.google.com/p/libyuv/issues/detail?id=572
+ // when it becomes available.
+ CopyAlphaChannelIntoVideoFrame(temp_data_.data(), video_frame);
}
io_task_runner_->PostTask(