| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this |
| 2 // source code is governed by a BSD-style license that can be found in the | 2 // source code is governed by a BSD-style license that can be found in the |
| 3 // LICENSE file. | 3 // LICENSE file. |
| 4 | 4 |
| 5 #include "media/base/buffers.h" | 5 #include "media/base/buffers.h" |
| 6 #include "media/base/yuv_convert.h" | 6 #include "media/base/yuv_convert.h" |
| 7 #include "webkit/glue/media/video_renderer_impl.h" | 7 #include "webkit/glue/media/video_renderer_impl.h" |
| 8 #include "webkit/glue/webmediaplayer_impl.h" | 8 #include "webkit/glue/webmediaplayer_impl.h" |
| 9 | 9 |
| 10 namespace webkit_glue { | 10 namespace webkit_glue { |
| 11 | 11 |
| 12 VideoRendererImpl::VideoRendererImpl(WebMediaPlayerImpl* delegate) | 12 VideoRendererImpl::VideoRendererImpl(WebMediaPlayerImpl::Proxy* proxy) |
| 13 : delegate_(delegate), | 13 : proxy_(proxy), |
| 14 last_converted_frame_(NULL) { | 14 last_converted_frame_(NULL) { |
| 15 // TODO(hclam): decide whether to do the following line in this thread or | 15 // TODO(hclam): decide whether to do the following line in this thread or |
| 16 // in the render thread. | 16 // in the render thread. |
| 17 delegate_->SetVideoRenderer(this); | 17 proxy->SetVideoRenderer(this); |
| 18 } | 18 } |
| 19 | 19 |
| 20 // static | 20 // static |
| 21 bool VideoRendererImpl::IsMediaFormatSupported( | 21 bool VideoRendererImpl::IsMediaFormatSupported( |
| 22 const media::MediaFormat& media_format) { | 22 const media::MediaFormat& media_format) { |
| 23 int width = 0; | 23 int width = 0; |
| 24 int height = 0; | 24 int height = 0; |
| 25 return ParseMediaFormat(media_format, &width, &height); | 25 return ParseMediaFormat(media_format, &width, &height); |
| 26 } | 26 } |
| 27 | 27 |
| 28 | |
| 29 bool VideoRendererImpl::OnInitialize(media::VideoDecoder* decoder) { | 28 bool VideoRendererImpl::OnInitialize(media::VideoDecoder* decoder) { |
| 30 int width = 0; | 29 int width = 0; |
| 31 int height = 0; | 30 int height = 0; |
| 32 if (!ParseMediaFormat(decoder->media_format(), &width, &height)) | 31 if (!ParseMediaFormat(decoder->media_format(), &width, &height)) |
| 33 return false; | 32 return false; |
| 34 | 33 |
| 35 video_size_.SetSize(width, height); | 34 video_size_.SetSize(width, height); |
| 36 bitmap_.setConfig(SkBitmap::kARGB_8888_Config, width, height); | 35 bitmap_.setConfig(SkBitmap::kARGB_8888_Config, width, height); |
| 37 if (bitmap_.allocPixels(NULL, NULL)) { | 36 if (bitmap_.allocPixels(NULL, NULL)) { |
| 38 bitmap_.eraseRGB(0x00, 0x00, 0x00); | 37 bitmap_.eraseRGB(0x00, 0x00, 0x00); |
| 39 return true; | 38 return true; |
| 40 } | 39 } |
| 41 | 40 |
| 42 NOTREACHED(); | 41 NOTREACHED(); |
| 43 return false; | 42 return false; |
| 44 } | 43 } |
| 45 | 44 |
| 46 void VideoRendererImpl::OnStop() { | 45 void VideoRendererImpl::OnStop() { |
| 47 delegate_->SetVideoRenderer(NULL); | 46 DCHECK(proxy_); |
| 47 proxy_->SetVideoRenderer(NULL); |
| 48 proxy_ = NULL; |
| 48 } | 49 } |
| 49 | 50 |
| 50 void VideoRendererImpl::OnFrameAvailable() { | 51 void VideoRendererImpl::OnFrameAvailable() { |
| 51 delegate_->PostRepaintTask(); | 52 DCHECK(proxy_); |
| 53 proxy_->Repaint(); |
| 52 } | 54 } |
| 53 | 55 |
| 54 void VideoRendererImpl::SetRect(const gfx::Rect& rect) { | 56 void VideoRendererImpl::SetRect(const gfx::Rect& rect) { |
| 55 } | 57 } |
| 56 | 58 |
| 57 // This method is always called on the renderer's thread. | 59 // This method is always called on the renderer's thread. |
| 58 void VideoRendererImpl::Paint(skia::PlatformCanvas* canvas, | 60 void VideoRendererImpl::Paint(skia::PlatformCanvas* canvas, |
| 59 const gfx::Rect& dest_rect) { | 61 const gfx::Rect& dest_rect) { |
| 60 scoped_refptr<media::VideoFrame> video_frame; | 62 scoped_refptr<media::VideoFrame> video_frame; |
| 61 GetCurrentFrame(&video_frame); | 63 GetCurrentFrame(&video_frame); |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 279 // Transform destination rect to local coordinates. | 281 // Transform destination rect to local coordinates. |
| 280 SkRect transformed_rect; | 282 SkRect transformed_rect; |
| 281 SkRect skia_dest_rect; | 283 SkRect skia_dest_rect; |
| 282 skia_dest_rect.iset(src_rect.x(), src_rect.y(), | 284 skia_dest_rect.iset(src_rect.x(), src_rect.y(), |
| 283 src_rect.right(), src_rect.bottom()); | 285 src_rect.right(), src_rect.bottom()); |
| 284 matrix.mapRect(&transformed_rect, skia_dest_rect); | 286 matrix.mapRect(&transformed_rect, skia_dest_rect); |
| 285 transformed_rect.round(dest_rect); | 287 transformed_rect.round(dest_rect); |
| 286 } | 288 } |
| 287 | 289 |
| 288 } // namespace webkit_glue | 290 } // namespace webkit_glue |
| OLD | NEW |