| OLD | NEW |
| 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/filters/skcanvas_video_renderer.h" | 5 #include "media/filters/skcanvas_video_renderer.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "media/base/video_frame.h" | 8 #include "media/base/video_frame.h" |
| 9 #include "media/base/yuv_convert.h" | 9 #include "media/base/yuv_convert.h" |
| 10 #include "third_party/skia/include/core/SkCanvas.h" | 10 #include "third_party/skia/include/core/SkCanvas.h" |
| 11 #include "third_party/skia/include/core/SkDevice.h" | 11 #include "third_party/skia/include/core/SkDevice.h" |
| 12 | 12 |
| 13 namespace media { | 13 namespace media { |
| 14 | 14 |
| 15 static bool IsEitherYV12OrYV16(media::VideoFrame::Format format) { | 15 static bool IsEitherYV12OrYV16(media::VideoFrame::Format format) { |
| 16 return format == media::VideoFrame::YV12 || format == media::VideoFrame::YV16; | 16 return format == media::VideoFrame::YV12 || |
| 17 format == media::VideoFrame::YV16 || |
| 18 format == media::VideoFrame::YV12J; |
| 17 } | 19 } |
| 18 | 20 |
| 19 static bool IsEitherYV12OrYV16OrNative(media::VideoFrame::Format format) { | 21 static bool IsEitherYV12OrYV16OrNative(media::VideoFrame::Format format) { |
| 20 return IsEitherYV12OrYV16(format) || | 22 return IsEitherYV12OrYV16(format) || |
| 21 format == media::VideoFrame::NATIVE_TEXTURE; | 23 format == media::VideoFrame::NATIVE_TEXTURE; |
| 22 } | 24 } |
| 23 | 25 |
| 24 static bool IsEitherYV12OrYV12AOrYV16(media::VideoFrame::Format format) { | 26 static bool IsEitherYV12OrYV12AOrYV16(media::VideoFrame::Format format) { |
| 25 return IsEitherYV12OrYV16(format) || | 27 return IsEitherYV12OrYV16(format) || |
| 26 format == media::VideoFrame::YV12A; | 28 format == media::VideoFrame::YV12A; |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 | 82 |
| 81 const SkBitmap& bitmap = canvas->getDevice()->accessBitmap(true); | 83 const SkBitmap& bitmap = canvas->getDevice()->accessBitmap(true); |
| 82 media::YUVType yuv_type = media::YV16; | 84 media::YUVType yuv_type = media::YV16; |
| 83 int y_shift = 0; | 85 int y_shift = 0; |
| 84 if (video_frame->format() == media::VideoFrame::YV12 || | 86 if (video_frame->format() == media::VideoFrame::YV12 || |
| 85 video_frame->format() == media::VideoFrame::YV12A) { | 87 video_frame->format() == media::VideoFrame::YV12A) { |
| 86 yuv_type = media::YV12; | 88 yuv_type = media::YV12; |
| 87 y_shift = 1; | 89 y_shift = 1; |
| 88 } | 90 } |
| 89 | 91 |
| 92 if (video_frame->format() == media::VideoFrame::YV12J) { |
| 93 yuv_type = media::YV12; |
| 94 y_shift = 1; |
| 95 } |
| 96 |
| 90 // Transform the destination rectangle to local coordinates. | 97 // Transform the destination rectangle to local coordinates. |
| 91 const SkMatrix& local_matrix = canvas->getTotalMatrix(); | 98 const SkMatrix& local_matrix = canvas->getTotalMatrix(); |
| 92 SkRect local_dest_rect; | 99 SkRect local_dest_rect; |
| 93 local_matrix.mapRect(&local_dest_rect, dest_rect); | 100 local_matrix.mapRect(&local_dest_rect, dest_rect); |
| 94 | 101 |
| 95 // After projecting the destination rectangle to local coordinates, round | 102 // After projecting the destination rectangle to local coordinates, round |
| 96 // the projected rectangle to integer values, this will give us pixel values | 103 // the projected rectangle to integer values, this will give us pixel values |
| 97 // of the rectangle. | 104 // of the rectangle. |
| 98 SkIRect local_dest_irect, local_dest_irect_saved; | 105 SkIRect local_dest_irect, local_dest_irect_saved; |
| 99 local_dest_rect.round(&local_dest_irect); | 106 local_dest_rect.round(&local_dest_irect); |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 // in Y, U and V planes. | 217 // in Y, U and V planes. |
| 211 y_offset = (video_frame->stride(media::VideoFrame::kYPlane) * | 218 y_offset = (video_frame->stride(media::VideoFrame::kYPlane) * |
| 212 video_frame->visible_rect().y()) + | 219 video_frame->visible_rect().y()) + |
| 213 video_frame->visible_rect().x(); | 220 video_frame->visible_rect().x(); |
| 214 // For format YV12, there is one U, V value per 2x2 block. | 221 // For format YV12, there is one U, V value per 2x2 block. |
| 215 // For format YV16, there is one U, V value per 2x1 block. | 222 // For format YV16, there is one U, V value per 2x1 block. |
| 216 uv_offset = (video_frame->stride(media::VideoFrame::kUPlane) * | 223 uv_offset = (video_frame->stride(media::VideoFrame::kUPlane) * |
| 217 (video_frame->visible_rect().y() >> y_shift)) + | 224 (video_frame->visible_rect().y() >> y_shift)) + |
| 218 (video_frame->visible_rect().x() >> 1); | 225 (video_frame->visible_rect().x() >> 1); |
| 219 } | 226 } |
| 227 |
| 220 switch (video_frame->format()) { | 228 switch (video_frame->format()) { |
| 221 case media::VideoFrame::YV12: | 229 case media::VideoFrame::YV12: |
| 230 case media::VideoFrame::YV12J: |
| 222 media::ConvertYUVToRGB32( | 231 media::ConvertYUVToRGB32( |
| 223 video_frame->data(media::VideoFrame::kYPlane) + y_offset, | 232 video_frame->data(media::VideoFrame::kYPlane) + y_offset, |
| 224 video_frame->data(media::VideoFrame::kUPlane) + uv_offset, | 233 video_frame->data(media::VideoFrame::kUPlane) + uv_offset, |
| 225 video_frame->data(media::VideoFrame::kVPlane) + uv_offset, | 234 video_frame->data(media::VideoFrame::kVPlane) + uv_offset, |
| 226 static_cast<uint8*>(bitmap->getPixels()), | 235 static_cast<uint8*>(bitmap->getPixels()), |
| 227 video_frame->visible_rect().width(), | 236 video_frame->visible_rect().width(), |
| 228 video_frame->visible_rect().height(), | 237 video_frame->visible_rect().height(), |
| 229 video_frame->stride(media::VideoFrame::kYPlane), | 238 video_frame->stride(media::VideoFrame::kYPlane), |
| 230 video_frame->stride(media::VideoFrame::kUPlane), | 239 video_frame->stride(media::VideoFrame::kUPlane), |
| 231 bitmap->rowBytes(), | 240 bitmap->rowBytes(), |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 315 ConvertVideoFrameToBitmap(video_frame, &last_frame_); | 324 ConvertVideoFrameToBitmap(video_frame, &last_frame_); |
| 316 last_frame_timestamp_ = video_frame->GetTimestamp(); | 325 last_frame_timestamp_ = video_frame->GetTimestamp(); |
| 317 } | 326 } |
| 318 | 327 |
| 319 // Do a slower paint using |last_frame_|. | 328 // Do a slower paint using |last_frame_|. |
| 320 paint.setFilterBitmap(true); | 329 paint.setFilterBitmap(true); |
| 321 canvas->drawBitmapRect(last_frame_, NULL, dest, &paint); | 330 canvas->drawBitmapRect(last_frame_, NULL, dest, &paint); |
| 322 } | 331 } |
| 323 | 332 |
| 324 } // namespace media | 333 } // namespace media |
| OLD | NEW |