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/renderers/skcanvas_video_renderer.h" | 5 #include "media/renderers/skcanvas_video_renderer.h" |
| 6 | 6 |
| 7 #include <limits> | 7 #include <limits> |
| 8 | 8 |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "gpu/GLES2/gl2extchromium.h" | 10 #include "gpu/GLES2/gl2extchromium.h" |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 216 void* pixels, | 216 void* pixels, |
| 217 size_t row_bytes, | 217 size_t row_bytes, |
| 218 SkPMColor ctable[], | 218 SkPMColor ctable[], |
| 219 int* ctable_count) override { | 219 int* ctable_count) override { |
| 220 // If skia couldn't do the YUV conversion on GPU, we will on CPU. | 220 // If skia couldn't do the YUV conversion on GPU, we will on CPU. |
| 221 SkCanvasVideoRenderer::ConvertVideoFrameToRGBPixels(frame_.get(), pixels, | 221 SkCanvasVideoRenderer::ConvertVideoFrameToRGBPixels(frame_.get(), pixels, |
| 222 row_bytes); | 222 row_bytes); |
| 223 return true; | 223 return true; |
| 224 } | 224 } |
| 225 | 225 |
| 226 bool onGetYUV8Planes(SkISize sizes[3], | 226 bool onQueryYUV8(SkYUVSizeInfo* sizeInfo, SkYUVColorSpace* color_space) const |
| 227 void* planes[3], | 227 override { |
| 228 size_t row_bytes[3], | |
| 229 SkYUVColorSpace* color_space) override { | |
| 230 if (!media::IsYuvPlanar(frame_->format()) || | 228 if (!media::IsYuvPlanar(frame_->format()) || |
| 231 // TODO(rileya): Skia currently doesn't support YUVA conversion. Remove | 229 // TODO(rileya): Skia currently doesn't support YUVA conversion. Remove |
| 232 // this case once it does. As-is we will fall back on the pure-software | 230 // this case once it does. As-is we will fall back on the pure-software |
| 233 // path in this case. | 231 // path in this case. |
| 234 frame_->format() == PIXEL_FORMAT_YV12A) { | 232 frame_->format() == PIXEL_FORMAT_YV12A) { |
| 235 return false; | 233 return false; |
| 236 } | 234 } |
| 237 | 235 |
| 238 if (color_space) { | 236 if (color_space) { |
| 239 if (CheckColorSpace(frame_.get(), COLOR_SPACE_JPEG)) | 237 if (CheckColorSpace(frame_.get(), COLOR_SPACE_JPEG)) |
| 240 *color_space = kJPEG_SkYUVColorSpace; | 238 *color_space = kJPEG_SkYUVColorSpace; |
| 241 else if (CheckColorSpace(frame_.get(), COLOR_SPACE_HD_REC709)) | 239 else if (CheckColorSpace(frame_.get(), COLOR_SPACE_HD_REC709)) |
| 242 *color_space = kRec709_SkYUVColorSpace; | 240 *color_space = kRec709_SkYUVColorSpace; |
| 243 else | 241 else |
| 244 *color_space = kRec601_SkYUVColorSpace; | 242 *color_space = kRec601_SkYUVColorSpace; |
| 245 } | 243 } |
| 246 | 244 |
| 247 for (int plane = VideoFrame::kYPlane; plane <= VideoFrame::kVPlane; | 245 for (int plane = VideoFrame::kYPlane; plane <= VideoFrame::kVPlane; |
| 248 ++plane) { | 246 ++plane) { |
| 249 if (sizes) { | 247 const gfx::Size size = |
| 250 const gfx::Size size = | 248 VideoFrame::PlaneSize(frame_->format(), plane, |
| 251 VideoFrame::PlaneSize(frame_->format(), plane, | 249 gfx::Size(frame_->visible_rect().width(), |
| 252 gfx::Size(frame_->visible_rect().width(), | 250 frame_->visible_rect().height())); |
| 253 frame_->visible_rect().height())); | 251 sizeInfo->fSizes[plane].set(size.width(), size.height()); |
|
scroggo_chromium
2016/02/22 21:10:31
I think the indentation is wrong here?
msarett
2016/02/22 21:42:44
Yes it is! Done.
| |
| 254 sizes[plane].set(size.width(), size.height()); | 252 sizeInfo->fWidthBytes[plane] = size.width(); |
| 255 } | 253 } |
| 256 if (row_bytes && planes) { | |
| 257 size_t offset; | |
| 258 const int y_shift = | |
| 259 (frame_->format() == media::PIXEL_FORMAT_YV16) ? 0 : 1; | |
| 260 if (plane == VideoFrame::kYPlane) { | |
| 261 offset = (frame_->stride(VideoFrame::kYPlane) * | |
| 262 frame_->visible_rect().y()) + | |
| 263 frame_->visible_rect().x(); | |
| 264 } else { | |
| 265 offset = (frame_->stride(VideoFrame::kUPlane) * | |
| 266 (frame_->visible_rect().y() >> y_shift)) + | |
| 267 (frame_->visible_rect().x() >> 1); | |
| 268 } | |
| 269 | 254 |
| 270 // Copy the frame to the supplied memory. | 255 return true; |
| 271 // TODO: Find a way (API change?) to avoid this copy. | 256 } |
| 272 char* out_line = static_cast<char*>(planes[plane]); | 257 |
| 273 int out_line_stride = row_bytes[plane]; | 258 bool onGetYUV8Planes(const SkYUVSizeInfo& sizeInfo, void* planes[3]) override |
| 274 uint8_t* in_line = frame_->data(plane) + offset; | 259 { |
| 275 int in_line_stride = frame_->stride(plane); | 260 if (!media::IsYuvPlanar(frame_->format()) || |
| 276 int plane_height = sizes[plane].height(); | 261 // TODO(rileya): Skia currently doesn't support YUVA conversion. Remove |
| 277 if (in_line_stride == out_line_stride) { | 262 // this case once it does. As-is we will fall back on the pure-software |
| 278 memcpy(out_line, in_line, plane_height * in_line_stride); | 263 // path in this case. |
| 279 } else { | 264 frame_->format() == PIXEL_FORMAT_YV12A) { |
| 280 // Different line padding so need to copy one line at a time. | 265 return false; |
|
scroggo_chromium
2016/02/22 21:10:32
It seems like we should never reach this case if q
msarett
2016/02/22 21:42:44
I'm not aware of anyone who calls this without cal
| |
| 281 int bytes_to_copy_per_line = out_line_stride < in_line_stride | 266 } |
| 282 ? out_line_stride | 267 |
| 283 : in_line_stride; | 268 for (int plane = VideoFrame::kYPlane; plane <= VideoFrame::kVPlane; |
| 284 for (int line_no = 0; line_no < plane_height; line_no++) { | 269 ++plane) { |
| 285 memcpy(out_line, in_line, bytes_to_copy_per_line); | 270 const gfx::Size size = |
| 286 in_line += in_line_stride; | 271 VideoFrame::PlaneSize(frame_->format(), plane, |
| 287 out_line += out_line_stride; | 272 gfx::Size(frame_->visible_rect().width(), |
| 288 } | 273 frame_->visible_rect().height())); |
| 274 if (size.width() != sizeInfo.fSizes[plane].width() || | |
| 275 size.height() != sizeInfo.fSizes[plane].height()) { | |
| 276 return false; | |
| 277 } | |
| 278 | |
| 279 size_t offset; | |
| 280 const int y_shift = | |
| 281 (frame_->format() == media::PIXEL_FORMAT_YV16) ? 0 : 1; | |
| 282 if (plane == VideoFrame::kYPlane) { | |
| 283 offset = (frame_->stride(VideoFrame::kYPlane) * | |
| 284 frame_->visible_rect().y()) + | |
| 285 frame_->visible_rect().x(); | |
| 286 } else { | |
| 287 offset = (frame_->stride(VideoFrame::kUPlane) * | |
| 288 (frame_->visible_rect().y() >> y_shift)) + | |
| 289 (frame_->visible_rect().x() >> 1); | |
| 290 } | |
| 291 | |
| 292 // Copy the frame to the supplied memory. | |
| 293 // TODO: Find a way (API change?) to avoid this copy. | |
| 294 char* out_line = static_cast<char*>(planes[plane]); | |
| 295 int out_line_stride = sizeInfo.fWidthBytes[plane]; | |
| 296 uint8_t* in_line = frame_->data(plane) + offset; | |
| 297 int in_line_stride = frame_->stride(plane); | |
| 298 int plane_height = sizeInfo.fSizes[plane].height(); | |
| 299 if (in_line_stride == out_line_stride) { | |
| 300 memcpy(out_line, in_line, plane_height * in_line_stride); | |
| 301 } else { | |
| 302 // Different line padding so need to copy one line at a time. | |
| 303 int bytes_to_copy_per_line = out_line_stride < in_line_stride | |
| 304 ? out_line_stride | |
| 305 : in_line_stride; | |
| 306 for (int line_no = 0; line_no < plane_height; line_no++) { | |
| 307 memcpy(out_line, in_line, bytes_to_copy_per_line); | |
| 308 in_line += in_line_stride; | |
| 309 out_line += out_line_stride; | |
| 289 } | 310 } |
| 290 } | 311 } |
| 291 } | 312 } |
| 292 return true; | 313 return true; |
| 293 } | 314 } |
| 294 | 315 |
| 295 private: | 316 private: |
| 296 scoped_refptr<VideoFrame> frame_; | 317 scoped_refptr<VideoFrame> frame_; |
| 297 | 318 |
| 298 DISALLOW_IMPLICIT_CONSTRUCTORS(VideoImageGenerator); | 319 DISALLOW_IMPLICIT_CONSTRUCTORS(VideoImageGenerator); |
| (...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 659 } | 680 } |
| 660 | 681 |
| 661 void SkCanvasVideoRenderer::ResetCache() { | 682 void SkCanvasVideoRenderer::ResetCache() { |
| 662 DCHECK(thread_checker_.CalledOnValidThread()); | 683 DCHECK(thread_checker_.CalledOnValidThread()); |
| 663 // Clear cached values. | 684 // Clear cached values. |
| 664 last_image_ = nullptr; | 685 last_image_ = nullptr; |
| 665 last_timestamp_ = kNoTimestamp(); | 686 last_timestamp_ = kNoTimestamp(); |
| 666 } | 687 } |
| 667 | 688 |
| 668 } // namespace media | 689 } // namespace media |
| OLD | NEW |