| 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 "ui/gfx/skbitmap_operations.h" |
| 12 | 13 |
| 13 // Skia internal format depends on a platform. On Android it is ABGR, on others | 14 // Skia internal format depends on a platform. On Android it is ABGR, on others |
| 14 // it is ARGB. | 15 // it is ARGB. |
| 15 #if SK_B32_SHIFT == 0 && SK_G32_SHIFT == 8 && SK_R32_SHIFT == 16 && \ | 16 #if SK_B32_SHIFT == 0 && SK_G32_SHIFT == 8 && SK_R32_SHIFT == 16 && \ |
| 16 SK_A32_SHIFT == 24 | 17 SK_A32_SHIFT == 24 |
| 17 #define LIBYUV_I420_TO_ARGB libyuv::I420ToARGB | 18 #define LIBYUV_I420_TO_ARGB libyuv::I420ToARGB |
| 18 #define LIBYUV_I422_TO_ARGB libyuv::I422ToARGB | 19 #define LIBYUV_I422_TO_ARGB libyuv::I422ToARGB |
| 19 #elif SK_R32_SHIFT == 0 && SK_G32_SHIFT == 8 && SK_B32_SHIFT == 16 && \ | 20 #elif SK_R32_SHIFT == 0 && SK_G32_SHIFT == 8 && SK_B32_SHIFT == 16 && \ |
| 20 SK_A32_SHIFT == 24 | 21 SK_A32_SHIFT == 24 |
| 21 #define LIBYUV_I420_TO_ARGB libyuv::I420ToABGR | 22 #define LIBYUV_I420_TO_ARGB libyuv::I420ToABGR |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 | 182 |
| 182 SkCanvasVideoRenderer::SkCanvasVideoRenderer() | 183 SkCanvasVideoRenderer::SkCanvasVideoRenderer() |
| 183 : last_frame_timestamp_(media::kNoTimestamp()) { | 184 : last_frame_timestamp_(media::kNoTimestamp()) { |
| 184 } | 185 } |
| 185 | 186 |
| 186 SkCanvasVideoRenderer::~SkCanvasVideoRenderer() {} | 187 SkCanvasVideoRenderer::~SkCanvasVideoRenderer() {} |
| 187 | 188 |
| 188 void SkCanvasVideoRenderer::Paint(media::VideoFrame* video_frame, | 189 void SkCanvasVideoRenderer::Paint(media::VideoFrame* video_frame, |
| 189 SkCanvas* canvas, | 190 SkCanvas* canvas, |
| 190 const gfx::RectF& dest_rect, | 191 const gfx::RectF& dest_rect, |
| 191 uint8 alpha) { | 192 uint8 alpha, |
| 193 VideoRotation video_rotation) { |
| 192 if (alpha == 0) { | 194 if (alpha == 0) { |
| 193 return; | 195 return; |
| 194 } | 196 } |
| 195 | 197 |
| 196 SkRect dest; | 198 SkRect dest; |
| 197 dest.set(dest_rect.x(), dest_rect.y(), dest_rect.right(), dest_rect.bottom()); | 199 dest.set(dest_rect.x(), dest_rect.y(), dest_rect.right(), dest_rect.bottom()); |
| 198 | 200 |
| 199 SkPaint paint; | 201 SkPaint paint; |
| 200 paint.setAlpha(alpha); | 202 paint.setAlpha(alpha); |
| 201 | 203 |
| 202 // Paint black rectangle if there isn't a frame available or the | 204 // Paint black rectangle if there isn't a frame available or the |
| 203 // frame has an unexpected format. | 205 // frame has an unexpected format. |
| 204 if (!video_frame || !IsYUVOrNative(video_frame->format())) { | 206 if (!video_frame || !IsYUVOrNative(video_frame->format())) { |
| 205 canvas->drawRect(dest, paint); | 207 canvas->drawRect(dest, paint); |
| 206 return; | 208 return; |
| 207 } | 209 } |
| 208 | 210 |
| 209 // Check if we should convert and update |last_frame_|. | 211 // Check if we should convert and update |last_frame_|. |
| 210 if (last_frame_.isNull() || | 212 if (last_frame_.isNull() || |
| 211 video_frame->timestamp() != last_frame_timestamp_) { | 213 video_frame->timestamp() != last_frame_timestamp_) { |
| 212 ConvertVideoFrameToBitmap(video_frame, &last_frame_); | 214 ConvertVideoFrameToBitmap(video_frame, &last_frame_); |
| 215 |
| 216 switch (video_rotation) { |
| 217 case VIDEO_ROTATION_0: |
| 218 break; |
| 219 case VIDEO_ROTATION_90: |
| 220 last_frame_ = SkBitmapOperations::Rotate( |
| 221 last_frame_, SkBitmapOperations::ROTATION_90_CW); |
| 222 break; |
| 223 case VIDEO_ROTATION_180: |
| 224 last_frame_ = SkBitmapOperations::Rotate( |
| 225 last_frame_, SkBitmapOperations::ROTATION_180_CW); |
| 226 break; |
| 227 case VIDEO_ROTATION_270: |
| 228 last_frame_ = SkBitmapOperations::Rotate( |
| 229 last_frame_, SkBitmapOperations::ROTATION_270_CW); |
| 230 break; |
| 231 } |
| 232 |
| 213 last_frame_timestamp_ = video_frame->timestamp(); | 233 last_frame_timestamp_ = video_frame->timestamp(); |
| 214 } | 234 } |
| 215 | 235 |
| 216 // Use SRC mode so we completely overwrite the buffer (in case we have alpha) | 236 // Use SRC mode so we completely overwrite the buffer (in case we have alpha) |
| 217 // this means we don't need the extra cost of clearing the buffer first. | 237 // this means we don't need the extra cost of clearing the buffer first. |
| 218 paint.setXfermode(SkXfermode::Create(SkXfermode::kSrc_Mode)); | 238 paint.setXfermode(SkXfermode::Create(SkXfermode::kSrc_Mode)); |
| 219 | 239 |
| 220 // Paint using |last_frame_|. | 240 // Paint using |last_frame_|. |
| 221 paint.setFilterLevel(SkPaint::kLow_FilterLevel); | 241 paint.setFilterLevel(SkPaint::kLow_FilterLevel); |
| 222 canvas->drawBitmapRect(last_frame_, NULL, dest, &paint); | 242 canvas->drawBitmapRect(last_frame_, NULL, dest, &paint); |
| 223 } | 243 } |
| 224 | 244 |
| 225 } // namespace media | 245 } // namespace media |
| OLD | NEW |