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/libyuv/include/libyuv.h" | 10 #include "third_party/libyuv/include/libyuv.h" |
11 #include "third_party/skia/include/core/SkCanvas.h" | 11 #include "third_party/skia/include/core/SkCanvas.h" |
| 12 #include "third_party/skia/include/gpu/SkGr.h" |
| 13 #include "third_party/skia/src/gpu/effects/GrYUVtoRGBEffect.h" |
12 #include "ui/gfx/skbitmap_operations.h" | 14 #include "ui/gfx/skbitmap_operations.h" |
13 | 15 |
| 16 #include "skia/ext/refptr.h" |
| 17 |
14 // Skia internal format depends on a platform. On Android it is ABGR, on others | 18 // Skia internal format depends on a platform. On Android it is ABGR, on others |
15 // it is ARGB. | 19 // it is ARGB. |
16 #if SK_B32_SHIFT == 0 && SK_G32_SHIFT == 8 && SK_R32_SHIFT == 16 && \ | 20 #if SK_B32_SHIFT == 0 && SK_G32_SHIFT == 8 && SK_R32_SHIFT == 16 && \ |
17 SK_A32_SHIFT == 24 | 21 SK_A32_SHIFT == 24 |
18 #define LIBYUV_I420_TO_ARGB libyuv::I420ToARGB | 22 #define LIBYUV_I420_TO_ARGB libyuv::I420ToARGB |
19 #define LIBYUV_I422_TO_ARGB libyuv::I422ToARGB | 23 #define LIBYUV_I422_TO_ARGB libyuv::I422ToARGB |
20 #elif SK_R32_SHIFT == 0 && SK_G32_SHIFT == 8 && SK_B32_SHIFT == 16 && \ | 24 #elif SK_R32_SHIFT == 0 && SK_G32_SHIFT == 8 && SK_B32_SHIFT == 16 && \ |
21 SK_A32_SHIFT == 24 | 25 SK_A32_SHIFT == 24 |
22 #define LIBYUV_I420_TO_ARGB libyuv::I420ToABGR | 26 #define LIBYUV_I420_TO_ARGB libyuv::I420ToABGR |
23 #define LIBYUV_I422_TO_ARGB libyuv::I422ToABGR | 27 #define LIBYUV_I422_TO_ARGB libyuv::I422ToABGR |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 SkPaint paint; | 206 SkPaint paint; |
203 paint.setAlpha(alpha); | 207 paint.setAlpha(alpha); |
204 | 208 |
205 // Paint black rectangle if there isn't a frame available or the | 209 // Paint black rectangle if there isn't a frame available or the |
206 // frame has an unexpected format. | 210 // frame has an unexpected format. |
207 if (!video_frame || !IsYUVOrNative(video_frame->format())) { | 211 if (!video_frame || !IsYUVOrNative(video_frame->format())) { |
208 canvas->drawRect(dest, paint); | 212 canvas->drawRect(dest, paint); |
209 return; | 213 return; |
210 } | 214 } |
211 | 215 |
| 216 // If we have an accelerated canvas, then we can use Ganesh's YUV conversion |
| 217 // filter, this is far faster than carrying this out on the CPU. |
| 218 if (GrContext* gr = canvas->getGrContext()) { |
| 219 DCHECK(IsYUVOrNative(video_frame->format())) |
| 220 << video_frame->format(); |
| 221 if (IsYUV(video_frame->format())) { |
| 222 DCHECK_EQ(video_frame->stride(media::VideoFrame::kUPlane), |
| 223 video_frame->stride(media::VideoFrame::kVPlane)); |
| 224 } |
| 225 |
| 226 DCHECK(video_frame->format() == VideoFrame::YV12); |
| 227 |
| 228 |
| 229 // Wrap our planes in SkBitmaps. |
| 230 SkBitmap bmps[3]; |
| 231 bmps[0].installPixels( |
| 232 SkImageInfo::MakeA8(video_frame->coded_size().width(), |
| 233 video_frame->coded_size().height()), |
| 234 video_frame->data(VideoFrame::kYPlane), |
| 235 video_frame->row_bytes(VideoFrame::kYPlane)); |
| 236 bmps[1].installPixels( |
| 237 SkImageInfo::MakeA8(video_frame->coded_size().width() / 2, |
| 238 video_frame->coded_size().height() / 2), |
| 239 video_frame->data(VideoFrame::kUPlane), |
| 240 video_frame->row_bytes(VideoFrame::kUPlane)); |
| 241 bmps[2].installPixels( |
| 242 SkImageInfo::MakeA8(video_frame->coded_size().width() / 2, |
| 243 video_frame->coded_size().height() / 2), |
| 244 video_frame->data(VideoFrame::kVPlane), |
| 245 video_frame->row_bytes(VideoFrame::kVPlane)); |
| 246 |
| 247 for (int i = 0; i < 3; ++i) |
| 248 bmps[i].setIsVolatile(true); |
| 249 |
| 250 GrTexture* planes[3]; |
| 251 |
| 252 planes[0] = GrLockAndRefCachedBitmapTexture(gr, bmps[0], NULL); |
| 253 planes[1] = GrLockAndRefCachedBitmapTexture(gr, bmps[1], NULL); |
| 254 planes[2] = GrLockAndRefCachedBitmapTexture(gr, bmps[2], NULL); |
| 255 |
| 256 skia::RefPtr<GrEffect> effect = skia::AdoptRef<GrEffect>( |
| 257 GrYUVtoRGBEffect::Create(planes[0], planes[1], planes[2])); |
| 258 |
| 259 if (effect) { |
| 260 GrPaint gp; |
| 261 gp.addColorEffect(effect.get()); |
| 262 gr->drawPaint(gp); |
| 263 } |
| 264 |
| 265 GrUnlockAndUnrefCachedBitmapTexture(planes[0]); |
| 266 GrUnlockAndUnrefCachedBitmapTexture(planes[1]); |
| 267 GrUnlockAndUnrefCachedBitmapTexture(planes[2]); |
| 268 return; |
| 269 } |
| 270 |
212 // Check if we should convert and update |last_frame_|. | 271 // Check if we should convert and update |last_frame_|. |
213 if (last_frame_.isNull() || | 272 if (last_frame_.isNull() || |
214 video_frame->timestamp() != last_frame_timestamp_) { | 273 video_frame->timestamp() != last_frame_timestamp_) { |
215 ConvertVideoFrameToBitmap(video_frame, &last_frame_); | 274 ConvertVideoFrameToBitmap(video_frame, &last_frame_); |
216 | 275 |
217 switch (video_rotation) { | 276 switch (video_rotation) { |
218 case VIDEO_ROTATION_0: | 277 case VIDEO_ROTATION_0: |
219 break; | 278 break; |
220 case VIDEO_ROTATION_90: | 279 case VIDEO_ROTATION_90: |
221 last_frame_ = SkBitmapOperations::Rotate( | 280 last_frame_ = SkBitmapOperations::Rotate( |
(...skipping 23 matching lines...) Expand all Loading... |
245 SkCanvas* canvas) { | 304 SkCanvas* canvas) { |
246 Paint(video_frame, | 305 Paint(video_frame, |
247 canvas, | 306 canvas, |
248 video_frame->visible_rect(), | 307 video_frame->visible_rect(), |
249 0xff, | 308 0xff, |
250 SkXfermode::kSrc_Mode, | 309 SkXfermode::kSrc_Mode, |
251 media::VIDEO_ROTATION_0); | 310 media::VIDEO_ROTATION_0); |
252 } | 311 } |
253 | 312 |
254 } // namespace media | 313 } // namespace media |
OLD | NEW |