OLD | NEW |
1 // Copyright (c) 2010 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 "media/base/video_frame.h" | 7 #include "media/base/video_frame.h" |
8 #include "media/base/yuv_convert.h" | 8 #include "media/base/yuv_convert.h" |
9 #include "webkit/glue/webmediaplayer_impl.h" | 9 #include "webkit/glue/webmediaplayer_impl.h" |
10 | 10 |
11 namespace webkit_glue { | 11 namespace webkit_glue { |
(...skipping 30 matching lines...) Expand all Loading... |
42 | 42 |
43 void VideoRendererImpl::SetWebMediaPlayerImplProxy( | 43 void VideoRendererImpl::SetWebMediaPlayerImplProxy( |
44 WebMediaPlayerImpl::Proxy* proxy) { | 44 WebMediaPlayerImpl::Proxy* proxy) { |
45 proxy_ = proxy; | 45 proxy_ = proxy; |
46 } | 46 } |
47 | 47 |
48 void VideoRendererImpl::SetRect(const gfx::Rect& rect) { | 48 void VideoRendererImpl::SetRect(const gfx::Rect& rect) { |
49 } | 49 } |
50 | 50 |
51 // This method is always called on the renderer's thread. | 51 // This method is always called on the renderer's thread. |
52 void VideoRendererImpl::Paint(skia::PlatformCanvas* canvas, | 52 void VideoRendererImpl::Paint(SkCanvas* canvas, |
53 const gfx::Rect& dest_rect) { | 53 const gfx::Rect& dest_rect) { |
54 scoped_refptr<media::VideoFrame> video_frame; | 54 scoped_refptr<media::VideoFrame> video_frame; |
55 GetCurrentFrame(&video_frame); | 55 GetCurrentFrame(&video_frame); |
56 if (!video_frame) { | 56 if (!video_frame) { |
57 SkPaint paint; | 57 SkPaint paint; |
58 paint.setColor(SK_ColorBLACK); | 58 paint.setColor(SK_ColorBLACK); |
59 canvas->drawRectCoords( | 59 canvas->drawRectCoords( |
60 static_cast<float>(dest_rect.x()), | 60 static_cast<float>(dest_rect.x()), |
61 static_cast<float>(dest_rect.y()), | 61 static_cast<float>(dest_rect.y()), |
62 static_cast<float>(dest_rect.right()), | 62 static_cast<float>(dest_rect.right()), |
(...skipping 28 matching lines...) Expand all Loading... |
91 } | 91 } |
92 | 92 |
93 // CanFastPaint is a helper method to determine the conditions for fast | 93 // CanFastPaint is a helper method to determine the conditions for fast |
94 // painting. The conditions are: | 94 // painting. The conditions are: |
95 // 1. No skew in canvas matrix. | 95 // 1. No skew in canvas matrix. |
96 // 2. No flipping nor mirroring. | 96 // 2. No flipping nor mirroring. |
97 // 3. Canvas has pixel format ARGB8888. | 97 // 3. Canvas has pixel format ARGB8888. |
98 // 4. Canvas is opaque. | 98 // 4. Canvas is opaque. |
99 // TODO(hclam): The fast paint method should support flipping and mirroring. | 99 // TODO(hclam): The fast paint method should support flipping and mirroring. |
100 // Disable the flipping and mirroring checks once we have it. | 100 // Disable the flipping and mirroring checks once we have it. |
101 bool VideoRendererImpl::CanFastPaint(skia::PlatformCanvas* canvas, | 101 bool VideoRendererImpl::CanFastPaint(SkCanvas* canvas, |
102 const gfx::Rect& dest_rect) { | 102 const gfx::Rect& dest_rect) { |
103 // Fast paint does not handle opacity value other than 1.0. Hence use slow | 103 // Fast paint does not handle opacity value other than 1.0. Hence use slow |
104 // paint if opacity is not 1.0. Since alpha = opacity * 0xFF, we check that | 104 // paint if opacity is not 1.0. Since alpha = opacity * 0xFF, we check that |
105 // alpha != 0xFF. | 105 // alpha != 0xFF. |
106 // | 106 // |
107 // Additonal notes: If opacity = 0.0, the chrome display engine does not try | 107 // Additonal notes: If opacity = 0.0, the chrome display engine does not try |
108 // to render the video. So, this method is never called. However, if the | 108 // to render the video. So, this method is never called. However, if the |
109 // opacity = 0.0001, alpha is again 0, but the display engine tries to render | 109 // opacity = 0.0001, alpha is again 0, but the display engine tries to render |
110 // the video. If we use Fast paint, the video shows up with opacity = 1.0. | 110 // the video. If we use Fast paint, the video shows up with opacity = 1.0. |
111 // Hence we use slow paint also in the case where alpha = 0. It would be ideal | 111 // Hence we use slow paint also in the case where alpha = 0. It would be ideal |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 if (config == SkBitmap::kARGB_8888_Config && device->isOpaque() && | 145 if (config == SkBitmap::kARGB_8888_Config && device->isOpaque() && |
146 device_rect.contains(total_clip.getBounds())) { | 146 device_rect.contains(total_clip.getBounds())) { |
147 return true; | 147 return true; |
148 } | 148 } |
149 } | 149 } |
150 | 150 |
151 return false; | 151 return false; |
152 } | 152 } |
153 | 153 |
154 void VideoRendererImpl::SlowPaint(media::VideoFrame* video_frame, | 154 void VideoRendererImpl::SlowPaint(media::VideoFrame* video_frame, |
155 skia::PlatformCanvas* canvas, | 155 SkCanvas* canvas, |
156 const gfx::Rect& dest_rect) { | 156 const gfx::Rect& dest_rect) { |
157 // 1. Convert YUV frame to RGB. | 157 // 1. Convert YUV frame to RGB. |
158 base::TimeDelta timestamp = video_frame->GetTimestamp(); | 158 base::TimeDelta timestamp = video_frame->GetTimestamp(); |
159 if (video_frame != last_converted_frame_ || | 159 if (video_frame != last_converted_frame_ || |
160 timestamp != last_converted_timestamp_) { | 160 timestamp != last_converted_timestamp_) { |
161 last_converted_frame_ = video_frame; | 161 last_converted_frame_ = video_frame; |
162 last_converted_timestamp_ = timestamp; | 162 last_converted_timestamp_ = timestamp; |
163 DCHECK(video_frame->format() == media::VideoFrame::YV12 || | 163 DCHECK(video_frame->format() == media::VideoFrame::YV12 || |
164 video_frame->format() == media::VideoFrame::YV16); | 164 video_frame->format() == media::VideoFrame::YV16); |
165 DCHECK(video_frame->stride(media::VideoFrame::kUPlane) == | 165 DCHECK(video_frame->stride(media::VideoFrame::kUPlane) == |
(...skipping 26 matching lines...) Expand all Loading... |
192 SkIntToScalar(video_size_.width()), | 192 SkIntToScalar(video_size_.width()), |
193 SkIntToScalar(dest_rect.height()) / | 193 SkIntToScalar(dest_rect.height()) / |
194 SkIntToScalar(video_size_.height())); | 194 SkIntToScalar(video_size_.height())); |
195 } | 195 } |
196 SkPaint paint; | 196 SkPaint paint; |
197 paint.setFlags(SkPaint::kFilterBitmap_Flag); | 197 paint.setFlags(SkPaint::kFilterBitmap_Flag); |
198 canvas->drawBitmapMatrix(bitmap_, matrix, &paint); | 198 canvas->drawBitmapMatrix(bitmap_, matrix, &paint); |
199 } | 199 } |
200 | 200 |
201 void VideoRendererImpl::FastPaint(media::VideoFrame* video_frame, | 201 void VideoRendererImpl::FastPaint(media::VideoFrame* video_frame, |
202 skia::PlatformCanvas* canvas, | 202 SkCanvas* canvas, |
203 const gfx::Rect& dest_rect) { | 203 const gfx::Rect& dest_rect) { |
204 DCHECK(video_frame->format() == media::VideoFrame::YV12 || | 204 DCHECK(video_frame->format() == media::VideoFrame::YV12 || |
205 video_frame->format() == media::VideoFrame::YV16); | 205 video_frame->format() == media::VideoFrame::YV16); |
206 DCHECK(video_frame->stride(media::VideoFrame::kUPlane) == | 206 DCHECK(video_frame->stride(media::VideoFrame::kUPlane) == |
207 video_frame->stride(media::VideoFrame::kVPlane)); | 207 video_frame->stride(media::VideoFrame::kVPlane)); |
208 DCHECK(video_frame->planes() == media::VideoFrame::kNumYUVPlanes); | 208 DCHECK(video_frame->planes() == media::VideoFrame::kNumYUVPlanes); |
209 const SkBitmap& bitmap = canvas->getDevice()->accessBitmap(true); | 209 const SkBitmap& bitmap = canvas->getDevice()->accessBitmap(true); |
210 media::YUVType yuv_type = (video_frame->format() == media::VideoFrame::YV12) ? | 210 media::YUVType yuv_type = (video_frame->format() == media::VideoFrame::YV12) ? |
211 media::YV12 : media::YV16; | 211 media::YV12 : media::YV16; |
212 int y_shift = yuv_type; // 1 for YV12, 0 for YV16. | 212 int y_shift = yuv_type; // 1 for YV12, 0 for YV16. |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
307 // Transform destination rect to local coordinates. | 307 // Transform destination rect to local coordinates. |
308 SkRect transformed_rect; | 308 SkRect transformed_rect; |
309 SkRect skia_dest_rect; | 309 SkRect skia_dest_rect; |
310 skia_dest_rect.iset(src_rect.x(), src_rect.y(), | 310 skia_dest_rect.iset(src_rect.x(), src_rect.y(), |
311 src_rect.right(), src_rect.bottom()); | 311 src_rect.right(), src_rect.bottom()); |
312 matrix.mapRect(&transformed_rect, skia_dest_rect); | 312 matrix.mapRect(&transformed_rect, skia_dest_rect); |
313 transformed_rect.round(dest_rect); | 313 transformed_rect.round(dest_rect); |
314 } | 314 } |
315 | 315 |
316 } // namespace webkit_glue | 316 } // namespace webkit_glue |
OLD | NEW |