| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "webkit/glue/media/video_renderer_impl.h" | 5 #include "webkit/glue/media/video_renderer_impl.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 #include "webkit/glue/webmediaplayer_proxy.h" | 12 #include "webkit/glue/webmediaplayer_proxy.h" |
| 13 | 13 |
| 14 namespace webkit_glue { | 14 namespace webkit_glue { |
| 15 | 15 |
| 16 VideoRendererImpl::VideoRendererImpl(bool pts_logging) | 16 VideoRendererImpl::VideoRendererImpl(bool pts_logging) |
| 17 : last_converted_frame_(NULL), | 17 : last_converted_frame_(NULL), |
| 18 pts_logging_(pts_logging) { | 18 pts_logging_(pts_logging) { |
| 19 } | 19 } |
| 20 | 20 |
| 21 VideoRendererImpl::~VideoRendererImpl() {} | 21 VideoRendererImpl::~VideoRendererImpl() {} |
| 22 | 22 |
| 23 bool VideoRendererImpl::OnInitialize(media::VideoDecoder* decoder) { | 23 bool VideoRendererImpl::OnInitialize(media::VideoDecoder* decoder) { |
| 24 video_size_.SetSize(decoder->width(), decoder->height()); | 24 natural_size_ = decoder->natural_size(); |
| 25 bitmap_.setConfig(SkBitmap::kARGB_8888_Config, | 25 bitmap_.setConfig(SkBitmap::kARGB_8888_Config, |
| 26 decoder->width(), decoder->height()); | 26 natural_size_.width(), natural_size_.height()); |
| 27 bitmap_.allocPixels(); | 27 bitmap_.allocPixels(); |
| 28 bitmap_.eraseRGB(0x00, 0x00, 0x00); | 28 bitmap_.eraseRGB(0x00, 0x00, 0x00); |
| 29 bitmap_.setIsVolatile(true); | 29 bitmap_.setIsVolatile(true); |
| 30 return true; | 30 return true; |
| 31 } | 31 } |
| 32 | 32 |
| 33 void VideoRendererImpl::OnStop(media::FilterCallback* callback) { | 33 void VideoRendererImpl::OnStop(media::FilterCallback* callback) { |
| 34 if (callback) { | 34 if (callback) { |
| 35 callback->Run(); | 35 callback->Run(); |
| 36 delete callback; | 36 delete callback; |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 bitmap_.rowBytes(), | 155 bitmap_.rowBytes(), |
| 156 yuv_type); | 156 yuv_type); |
| 157 bitmap_.notifyPixelsChanged(); | 157 bitmap_.notifyPixelsChanged(); |
| 158 bitmap_.unlockPixels(); | 158 bitmap_.unlockPixels(); |
| 159 } | 159 } |
| 160 | 160 |
| 161 // 2. Paint the bitmap to canvas. | 161 // 2. Paint the bitmap to canvas. |
| 162 SkMatrix matrix; | 162 SkMatrix matrix; |
| 163 matrix.setTranslate(static_cast<SkScalar>(dest_rect.x()), | 163 matrix.setTranslate(static_cast<SkScalar>(dest_rect.x()), |
| 164 static_cast<SkScalar>(dest_rect.y())); | 164 static_cast<SkScalar>(dest_rect.y())); |
| 165 if (dest_rect.width() != video_size_.width() || | 165 if (dest_rect.width() != natural_size_.width() || |
| 166 dest_rect.height() != video_size_.height()) { | 166 dest_rect.height() != natural_size_.height()) { |
| 167 matrix.preScale(SkIntToScalar(dest_rect.width()) / | 167 matrix.preScale(SkIntToScalar(dest_rect.width()) / |
| 168 SkIntToScalar(video_size_.width()), | 168 SkIntToScalar(natural_size_.width()), |
| 169 SkIntToScalar(dest_rect.height()) / | 169 SkIntToScalar(dest_rect.height()) / |
| 170 SkIntToScalar(video_size_.height())); | 170 SkIntToScalar(natural_size_.height())); |
| 171 } | 171 } |
| 172 SkPaint paint; | 172 SkPaint paint; |
| 173 paint.setFlags(SkPaint::kFilterBitmap_Flag); | 173 paint.setFlags(SkPaint::kFilterBitmap_Flag); |
| 174 canvas->drawBitmapMatrix(bitmap_, matrix, &paint); | 174 canvas->drawBitmapMatrix(bitmap_, matrix, &paint); |
| 175 } | 175 } |
| 176 | 176 |
| 177 void VideoRendererImpl::FastPaint(media::VideoFrame* video_frame, | 177 void VideoRendererImpl::FastPaint(media::VideoFrame* video_frame, |
| 178 SkCanvas* canvas, | 178 SkCanvas* canvas, |
| 179 const gfx::Rect& dest_rect) { | 179 const gfx::Rect& dest_rect) { |
| 180 DCHECK(video_frame->format() == media::VideoFrame::YV12 || | 180 DCHECK(video_frame->format() == media::VideoFrame::YV12 || |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 video_frame->stride(media::VideoFrame::kUPlane), | 271 video_frame->stride(media::VideoFrame::kUPlane), |
| 272 bitmap.rowBytes(), | 272 bitmap.rowBytes(), |
| 273 yuv_type, | 273 yuv_type, |
| 274 media::ROTATE_0, | 274 media::ROTATE_0, |
| 275 media::FILTER_BILINEAR); | 275 media::FILTER_BILINEAR); |
| 276 bitmap.unlockPixels(); | 276 bitmap.unlockPixels(); |
| 277 } | 277 } |
| 278 } | 278 } |
| 279 | 279 |
| 280 } // namespace webkit_glue | 280 } // namespace webkit_glue |
| OLD | NEW |