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) { |
Ami GONE FROM CHROMIUM
2014/04/02 22:03:58
This name is bad now.
IsYUV()
?
hshi1
2014/04/02 22:17:05
WDYT of my new patch?
| |
16 return format == media::VideoFrame::YV12 || | 16 return format == media::VideoFrame::YV12 || |
17 format == media::VideoFrame::I420 || | |
17 format == media::VideoFrame::YV16 || | 18 format == media::VideoFrame::YV16 || |
18 format == media::VideoFrame::YV12J; | 19 format == media::VideoFrame::YV12J; |
19 } | 20 } |
20 | 21 |
21 static bool IsEitherYV12OrYV16OrNative(media::VideoFrame::Format format) { | 22 static bool IsEitherYV12OrYV16OrNative(media::VideoFrame::Format format) { |
22 return IsEitherYV12OrYV16(format) || | 23 return IsEitherYV12OrYV16(format) || |
23 format == media::VideoFrame::NATIVE_TEXTURE; | 24 format == media::VideoFrame::NATIVE_TEXTURE; |
24 } | 25 } |
25 | 26 |
26 static bool IsEitherYV12OrYV12AOrYV16(media::VideoFrame::Format format) { | 27 static bool IsEitherYV12OrYV12AOrYV16(media::VideoFrame::Format format) { |
27 return IsEitherYV12OrYV16(format) || | 28 return IsEitherYV12OrYV16(format) || |
28 format == media::VideoFrame::YV12A; | 29 format == media::VideoFrame::YV12A; |
29 } | 30 } |
30 | 31 |
31 static bool IsEitherYV12OrYV12AOrYV16OrNative( | 32 static bool IsEitherYV12OrYV12AOrYV16OrNative( |
32 media::VideoFrame::Format format) { | 33 media::VideoFrame::Format format) { |
33 return IsEitherYV12OrYV16OrNative(format) || | 34 return IsEitherYV12OrYV16OrNative(format) || |
34 format == media::VideoFrame::YV12A; | 35 format == media::VideoFrame::YV12A; |
35 } | 36 } |
36 | 37 |
37 // CanFastPaint is a helper method to determine the conditions for fast | 38 // CanFastPaint is a helper method to determine the conditions for fast |
38 // painting. The conditions are: | 39 // painting. The conditions are: |
39 // 1. No skew in canvas matrix. | 40 // 1. No skew in canvas matrix. |
40 // 2. No flipping nor mirroring. | 41 // 2. No flipping nor mirroring. |
41 // 3. Canvas has pixel format ARGB8888. | 42 // 3. Canvas has pixel format ARGB8888. |
42 // 4. Canvas is opaque. | 43 // 4. Canvas is opaque. |
43 // 5. Frame format is YV12 or YV16. | 44 // 5. Frame format is YV12, I420 or YV16. |
44 // | 45 // |
45 // TODO(hclam): The fast paint method should support flipping and mirroring. | 46 // TODO(hclam): The fast paint method should support flipping and mirroring. |
46 // Disable the flipping and mirroring checks once we have it. | 47 // Disable the flipping and mirroring checks once we have it. |
47 static bool CanFastPaint(SkCanvas* canvas, uint8 alpha, | 48 static bool CanFastPaint(SkCanvas* canvas, uint8 alpha, |
48 media::VideoFrame::Format format) { | 49 media::VideoFrame::Format format) { |
49 if (alpha != 0xFF || !IsEitherYV12OrYV16(format)) | 50 if (alpha != 0xFF || !IsEitherYV12OrYV16(format)) |
50 return false; | 51 return false; |
51 | 52 |
52 const SkMatrix& total_matrix = canvas->getTotalMatrix(); | 53 const SkMatrix& total_matrix = canvas->getTotalMatrix(); |
53 // Perform the following checks here: | 54 // Perform the following checks here: |
(...skipping 23 matching lines...) Expand all Loading... | |
77 SkCanvas* canvas, | 78 SkCanvas* canvas, |
78 const SkRect& dest_rect) { | 79 const SkRect& dest_rect) { |
79 DCHECK(IsEitherYV12OrYV16(video_frame->format())) << video_frame->format(); | 80 DCHECK(IsEitherYV12OrYV16(video_frame->format())) << video_frame->format(); |
80 DCHECK_EQ(video_frame->stride(media::VideoFrame::kUPlane), | 81 DCHECK_EQ(video_frame->stride(media::VideoFrame::kUPlane), |
81 video_frame->stride(media::VideoFrame::kVPlane)); | 82 video_frame->stride(media::VideoFrame::kVPlane)); |
82 | 83 |
83 const SkBitmap& bitmap = canvas->getDevice()->accessBitmap(true); | 84 const SkBitmap& bitmap = canvas->getDevice()->accessBitmap(true); |
84 media::YUVType yuv_type = media::YV16; | 85 media::YUVType yuv_type = media::YV16; |
85 int y_shift = 0; | 86 int y_shift = 0; |
86 if (video_frame->format() == media::VideoFrame::YV12 || | 87 if (video_frame->format() == media::VideoFrame::YV12 || |
88 video_frame->format() == media::VideoFrame::I420 || | |
87 video_frame->format() == media::VideoFrame::YV12A) { | 89 video_frame->format() == media::VideoFrame::YV12A) { |
88 yuv_type = media::YV12; | 90 yuv_type = media::YV12; |
89 y_shift = 1; | 91 y_shift = 1; |
90 } | 92 } |
91 | 93 |
92 if (video_frame->format() == media::VideoFrame::YV12J) { | 94 if (video_frame->format() == media::VideoFrame::YV12J) { |
93 yuv_type = media::YV12; | 95 yuv_type = media::YV12; |
94 y_shift = 1; | 96 y_shift = 1; |
95 } | 97 } |
96 | 98 |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
220 video_frame->visible_rect().x(); | 222 video_frame->visible_rect().x(); |
221 // For format YV12, there is one U, V value per 2x2 block. | 223 // For format YV12, there is one U, V value per 2x2 block. |
222 // For format YV16, there is one U, V value per 2x1 block. | 224 // For format YV16, there is one U, V value per 2x1 block. |
223 uv_offset = (video_frame->stride(media::VideoFrame::kUPlane) * | 225 uv_offset = (video_frame->stride(media::VideoFrame::kUPlane) * |
224 (video_frame->visible_rect().y() >> y_shift)) + | 226 (video_frame->visible_rect().y() >> y_shift)) + |
225 (video_frame->visible_rect().x() >> 1); | 227 (video_frame->visible_rect().x() >> 1); |
226 } | 228 } |
227 | 229 |
228 switch (video_frame->format()) { | 230 switch (video_frame->format()) { |
229 case media::VideoFrame::YV12: | 231 case media::VideoFrame::YV12: |
232 case media::VideoFrame::I420: | |
230 case media::VideoFrame::YV12J: | 233 case media::VideoFrame::YV12J: |
231 media::ConvertYUVToRGB32( | 234 media::ConvertYUVToRGB32( |
232 video_frame->data(media::VideoFrame::kYPlane) + y_offset, | 235 video_frame->data(media::VideoFrame::kYPlane) + y_offset, |
233 video_frame->data(media::VideoFrame::kUPlane) + uv_offset, | 236 video_frame->data(media::VideoFrame::kUPlane) + uv_offset, |
234 video_frame->data(media::VideoFrame::kVPlane) + uv_offset, | 237 video_frame->data(media::VideoFrame::kVPlane) + uv_offset, |
235 static_cast<uint8*>(bitmap->getPixels()), | 238 static_cast<uint8*>(bitmap->getPixels()), |
236 video_frame->visible_rect().width(), | 239 video_frame->visible_rect().width(), |
237 video_frame->visible_rect().height(), | 240 video_frame->visible_rect().height(), |
238 video_frame->stride(media::VideoFrame::kYPlane), | 241 video_frame->stride(media::VideoFrame::kYPlane), |
239 video_frame->stride(media::VideoFrame::kUPlane), | 242 video_frame->stride(media::VideoFrame::kUPlane), |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
324 ConvertVideoFrameToBitmap(video_frame, &last_frame_); | 327 ConvertVideoFrameToBitmap(video_frame, &last_frame_); |
325 last_frame_timestamp_ = video_frame->GetTimestamp(); | 328 last_frame_timestamp_ = video_frame->GetTimestamp(); |
326 } | 329 } |
327 | 330 |
328 // Do a slower paint using |last_frame_|. | 331 // Do a slower paint using |last_frame_|. |
329 paint.setFilterBitmap(true); | 332 paint.setFilterBitmap(true); |
330 canvas->drawBitmapRect(last_frame_, NULL, dest, &paint); | 333 canvas->drawBitmapRect(last_frame_, NULL, dest, &paint); |
331 } | 334 } |
332 | 335 |
333 } // namespace media | 336 } // namespace media |
OLD | NEW |