Chromium Code Reviews| 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/skia/include/core/SkCanvas.h" | 10 #include "third_party/skia/include/core/SkCanvas.h" |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 102 // Project the clip rect to the original video frame, obtains the | 102 // Project the clip rect to the original video frame, obtains the |
| 103 // dimensions of the projected clip rect, "left" and "top" of the rect. | 103 // dimensions of the projected clip rect, "left" and "top" of the rect. |
| 104 // The math here are all integer math so we won't have rounding error and | 104 // The math here are all integer math so we won't have rounding error and |
| 105 // write outside of the canvas. | 105 // write outside of the canvas. |
| 106 // We have the assumptions of dest_rect.width() and dest_rect.height() | 106 // We have the assumptions of dest_rect.width() and dest_rect.height() |
| 107 // being non-zero, these are valid assumptions since finding intersection | 107 // being non-zero, these are valid assumptions since finding intersection |
| 108 // above rejects empty rectangle so we just do a DCHECK here. | 108 // above rejects empty rectangle so we just do a DCHECK here. |
| 109 DCHECK_NE(0, dest_rect.width()); | 109 DCHECK_NE(0, dest_rect.width()); |
| 110 DCHECK_NE(0, dest_rect.height()); | 110 DCHECK_NE(0, dest_rect.height()); |
| 111 size_t frame_clip_width = local_dest_irect.width() * | 111 size_t frame_clip_width = local_dest_irect.width() * |
| 112 video_frame->data_size().width() / local_dest_irect_saved.width(); | 112 video_frame->visible_rect().width() / local_dest_irect_saved.width(); |
| 113 size_t frame_clip_height = local_dest_irect.height() * | 113 size_t frame_clip_height = local_dest_irect.height() * |
| 114 video_frame->data_size().height() / local_dest_irect_saved.height(); | 114 video_frame->visible_rect().height() / local_dest_irect_saved.height(); |
| 115 | 115 |
| 116 // Project the "left" and "top" of the final destination rect to local | 116 // Project the "left" and "top" of the final destination rect to local |
| 117 // coordinates of the video frame, use these values to find the offsets | 117 // coordinates of the video frame, use these values to find the offsets |
| 118 // in the video frame to start reading. | 118 // in the video frame to start reading. |
| 119 size_t frame_clip_left = | 119 size_t frame_clip_left = |
| 120 video_frame->visible_rect().x() + | |
| 120 (local_dest_irect.fLeft - local_dest_irect_saved.fLeft) * | 121 (local_dest_irect.fLeft - local_dest_irect_saved.fLeft) * |
| 121 video_frame->data_size().width() / local_dest_irect_saved.width(); | 122 video_frame->visible_rect().width() / local_dest_irect_saved.width(); |
| 122 size_t frame_clip_top = | 123 size_t frame_clip_top = |
| 124 video_frame->visible_rect().y() + | |
| 123 (local_dest_irect.fTop - local_dest_irect_saved.fTop) * | 125 (local_dest_irect.fTop - local_dest_irect_saved.fTop) * |
| 124 video_frame->data_size().height() / local_dest_irect_saved.height(); | 126 video_frame->visible_rect().height() / local_dest_irect_saved.height(); |
|
Ami GONE FROM CHROMIUM
2012/10/25 00:43:07
Can you add testing for this stuff in the unittest
| |
| 125 | 127 |
| 126 // Use the "left" and "top" of the destination rect to locate the offset | 128 // Use the "left" and "top" of the destination rect to locate the offset |
| 127 // in Y, U and V planes. | 129 // in Y, U and V planes. |
| 128 size_t y_offset = video_frame->stride(media::VideoFrame::kYPlane) * | 130 size_t y_offset = (video_frame->stride(media::VideoFrame::kYPlane) * |
| 129 frame_clip_top + frame_clip_left; | 131 frame_clip_top) + frame_clip_left; |
| 130 | 132 |
| 131 // For format YV12, there is one U, V value per 2x2 block. | 133 // For format YV12, there is one U, V value per 2x2 block. |
| 132 // For format YV16, there is one u, V value per 2x1 block. | 134 // For format YV16, there is one u, V value per 2x1 block. |
| 133 size_t uv_offset = (video_frame->stride(media::VideoFrame::kUPlane) * | 135 size_t uv_offset = (video_frame->stride(media::VideoFrame::kUPlane) * |
| 134 (frame_clip_top >> y_shift)) + (frame_clip_left >> 1); | 136 (frame_clip_top >> y_shift)) + (frame_clip_left >> 1); |
| 135 uint8* frame_clip_y = | 137 uint8* frame_clip_y = |
| 136 video_frame->data(media::VideoFrame::kYPlane) + y_offset; | 138 video_frame->data(media::VideoFrame::kYPlane) + y_offset; |
| 137 uint8* frame_clip_u = | 139 uint8* frame_clip_u = |
| 138 video_frame->data(media::VideoFrame::kUPlane) + uv_offset; | 140 video_frame->data(media::VideoFrame::kUPlane) + uv_offset; |
| 139 uint8* frame_clip_v = | 141 uint8* frame_clip_v = |
| 140 video_frame->data(media::VideoFrame::kVPlane) + uv_offset; | 142 video_frame->data(media::VideoFrame::kVPlane) + uv_offset; |
| 141 | 143 |
| 142 // TODO(hclam): do rotation and mirroring here. | 144 // TODO(hcfam): do rotation and mirroring here. |
|
Ami GONE FROM CHROMIUM
2012/10/25 00:43:07
lolwat
| |
| 143 // TODO(fbarchard): switch filtering based on performance. | 145 // TODO(fbarchard): switch filtering based on performance. |
| 144 bitmap.lockPixels(); | 146 bitmap.lockPixels(); |
| 145 media::ScaleYUVToRGB32(frame_clip_y, | 147 media::ScaleYUVToRGB32(frame_clip_y, |
| 146 frame_clip_u, | 148 frame_clip_u, |
| 147 frame_clip_v, | 149 frame_clip_v, |
| 148 dest_rect_pointer, | 150 dest_rect_pointer, |
| 149 frame_clip_width, | 151 frame_clip_width, |
| 150 frame_clip_height, | 152 frame_clip_height, |
| 151 local_dest_irect.width(), | 153 local_dest_irect.width(), |
| 152 local_dest_irect.height(), | 154 local_dest_irect.height(), |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 167 SkBitmap* bitmap) { | 169 SkBitmap* bitmap) { |
| 168 DCHECK(IsEitherYV12OrYV16OrNative(video_frame->format())) | 170 DCHECK(IsEitherYV12OrYV16OrNative(video_frame->format())) |
| 169 << video_frame->format(); | 171 << video_frame->format(); |
| 170 if (IsEitherYV12OrYV16(video_frame->format())) { | 172 if (IsEitherYV12OrYV16(video_frame->format())) { |
| 171 DCHECK_EQ(video_frame->stride(media::VideoFrame::kUPlane), | 173 DCHECK_EQ(video_frame->stride(media::VideoFrame::kUPlane), |
| 172 video_frame->stride(media::VideoFrame::kVPlane)); | 174 video_frame->stride(media::VideoFrame::kVPlane)); |
| 173 } | 175 } |
| 174 | 176 |
| 175 // Check if |bitmap| needs to be (re)allocated. | 177 // Check if |bitmap| needs to be (re)allocated. |
| 176 if (bitmap->isNull() || | 178 if (bitmap->isNull() || |
| 177 bitmap->width() != video_frame->data_size().width() || | 179 bitmap->width() != video_frame->visible_rect().width() || |
| 178 bitmap->height() != video_frame->data_size().height()) { | 180 bitmap->height() != video_frame->visible_rect().height()) { |
| 179 bitmap->setConfig(SkBitmap::kARGB_8888_Config, | 181 bitmap->setConfig(SkBitmap::kARGB_8888_Config, |
| 180 video_frame->data_size().width(), | 182 video_frame->visible_rect().width(), |
| 181 video_frame->data_size().height()); | 183 video_frame->visible_rect().height()); |
| 182 bitmap->allocPixels(); | 184 bitmap->allocPixels(); |
| 183 bitmap->setIsVolatile(true); | 185 bitmap->setIsVolatile(true); |
| 184 } | 186 } |
| 185 | 187 |
| 188 media::YUVType yuv_type = (video_frame->format() == media::VideoFrame::YV12) ? | |
|
Ami GONE FROM CHROMIUM
2012/10/25 00:43:07
This thunk is wrong for the native texture case, w
sheu
2012/10/25 01:53:54
Done.
| |
| 189 media::YV12 : media::YV16; | |
| 190 int y_shift = yuv_type; // 1 for YV12, 0 for YV16. | |
| 191 | |
| 192 // Use the "left" and "top" of the destination rect to locate the offset | |
| 193 // in Y, U and V planes. | |
| 194 size_t y_offset = (video_frame->stride(media::VideoFrame::kYPlane) * | |
| 195 video_frame->visible_rect().y()) + | |
| 196 video_frame->visible_rect().x(); | |
| 197 | |
| 198 // For format YV12, there is one U, V value per 2x2 block. | |
| 199 // For format YV16, there is one u, V value per 2x1 block. | |
| 200 size_t uv_offset = (video_frame->stride(media::VideoFrame::kUPlane) * | |
| 201 (video_frame->visible_rect().y() >> y_shift)) + | |
| 202 (video_frame->visible_rect().x() >> 1); | |
| 203 uint8* frame_clip_y = | |
| 204 video_frame->data(media::VideoFrame::kYPlane) + y_offset; | |
| 205 uint8* frame_clip_u = | |
| 206 video_frame->data(media::VideoFrame::kUPlane) + uv_offset; | |
| 207 uint8* frame_clip_v = | |
| 208 video_frame->data(media::VideoFrame::kVPlane) + uv_offset; | |
|
Ami GONE FROM CHROMIUM
2012/10/25 00:43:07
I think this thunk is correct (% needing to move p
sheu
2012/10/25 01:53:54
Done.
| |
| 209 | |
| 186 bitmap->lockPixels(); | 210 bitmap->lockPixels(); |
| 187 if (IsEitherYV12OrYV16(video_frame->format())) { | 211 if (IsEitherYV12OrYV16(video_frame->format())) { |
| 188 media::YUVType yuv_type = | 212 media::YUVType yuv_type = |
| 189 (video_frame->format() == media::VideoFrame::YV12) ? | 213 (video_frame->format() == media::VideoFrame::YV12) ? |
| 190 media::YV12 : media::YV16; | 214 media::YV12 : media::YV16; |
| 191 media::ConvertYUVToRGB32(video_frame->data(media::VideoFrame::kYPlane), | 215 media::ConvertYUVToRGB32(frame_clip_y, |
| 192 video_frame->data(media::VideoFrame::kUPlane), | 216 frame_clip_u, |
| 193 video_frame->data(media::VideoFrame::kVPlane), | 217 frame_clip_v, |
| 194 static_cast<uint8*>(bitmap->getPixels()), | 218 static_cast<uint8*>(bitmap->getPixels()), |
| 195 video_frame->data_size().width(), | 219 video_frame->visible_rect().width(), |
| 196 video_frame->data_size().height(), | 220 video_frame->visible_rect().height(), |
| 197 video_frame->stride(media::VideoFrame::kYPlane), | 221 video_frame->stride(media::VideoFrame::kYPlane), |
| 198 video_frame->stride(media::VideoFrame::kUPlane), | 222 video_frame->stride(media::VideoFrame::kUPlane), |
| 199 bitmap->rowBytes(), | 223 bitmap->rowBytes(), |
| 200 yuv_type); | 224 yuv_type); |
| 201 } else { | 225 } else { |
| 202 DCHECK_EQ(video_frame->format(), media::VideoFrame::NATIVE_TEXTURE); | 226 DCHECK_EQ(video_frame->format(), media::VideoFrame::NATIVE_TEXTURE); |
| 203 video_frame->ReadPixelsFromNativeTexture(bitmap->getPixels()); | 227 video_frame->ReadPixelsFromNativeTexture(bitmap->getPixels()); |
| 204 } | 228 } |
| 205 bitmap->notifyPixelsChanged(); | 229 bitmap->notifyPixelsChanged(); |
| 206 bitmap->unlockPixels(); | 230 bitmap->unlockPixels(); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 245 ConvertVideoFrameToBitmap(video_frame, &last_frame_); | 269 ConvertVideoFrameToBitmap(video_frame, &last_frame_); |
| 246 last_frame_timestamp_ = video_frame->GetTimestamp(); | 270 last_frame_timestamp_ = video_frame->GetTimestamp(); |
| 247 } | 271 } |
| 248 | 272 |
| 249 // Do a slower paint using |last_frame_|. | 273 // Do a slower paint using |last_frame_|. |
| 250 paint.setFilterBitmap(true); | 274 paint.setFilterBitmap(true); |
| 251 canvas->drawBitmapRect(last_frame_, NULL, dest, &paint); | 275 canvas->drawBitmapRect(last_frame_, NULL, dest, &paint); |
| 252 } | 276 } |
| 253 | 277 |
| 254 } // namespace media | 278 } // namespace media |
| OLD | NEW |