| 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 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 void* pixels, | 220 void* pixels, |
| 221 size_t row_bytes, | 221 size_t row_bytes, |
| 222 SkPMColor ctable[], | 222 SkPMColor ctable[], |
| 223 int* ctable_count) override { | 223 int* ctable_count) override { |
| 224 // If skia couldn't do the YUV conversion on GPU, we will on CPU. | 224 // If skia couldn't do the YUV conversion on GPU, we will on CPU. |
| 225 SkCanvasVideoRenderer::ConvertVideoFrameToRGBPixels(frame_.get(), pixels, | 225 SkCanvasVideoRenderer::ConvertVideoFrameToRGBPixels(frame_.get(), pixels, |
| 226 row_bytes); | 226 row_bytes); |
| 227 return true; | 227 return true; |
| 228 } | 228 } |
| 229 | 229 |
| 230 bool onGetYUV8Planes(SkISize sizes[3], | 230 bool onQueryYUV8(SkYUVSizeInfo* sizeInfo, |
| 231 void* planes[3], | 231 SkYUVColorSpace* color_space) const override { |
| 232 size_t row_bytes[3], | |
| 233 SkYUVColorSpace* color_space) override { | |
| 234 if (!media::IsYuvPlanar(frame_->format()) || | 232 if (!media::IsYuvPlanar(frame_->format()) || |
| 235 // TODO(rileya): Skia currently doesn't support YUVA conversion. Remove | 233 // TODO(rileya): Skia currently doesn't support YUVA conversion. Remove |
| 236 // this case once it does. As-is we will fall back on the pure-software | 234 // this case once it does. As-is we will fall back on the pure-software |
| 237 // path in this case. | 235 // path in this case. |
| 238 frame_->format() == PIXEL_FORMAT_YV12A) { | 236 frame_->format() == PIXEL_FORMAT_YV12A) { |
| 239 return false; | 237 return false; |
| 240 } | 238 } |
| 241 | 239 |
| 242 if (color_space) { | 240 if (color_space) { |
| 243 if (CheckColorSpace(frame_.get(), COLOR_SPACE_JPEG)) | 241 if (CheckColorSpace(frame_.get(), COLOR_SPACE_JPEG)) |
| 244 *color_space = kJPEG_SkYUVColorSpace; | 242 *color_space = kJPEG_SkYUVColorSpace; |
| 245 else if (CheckColorSpace(frame_.get(), COLOR_SPACE_HD_REC709)) | 243 else if (CheckColorSpace(frame_.get(), COLOR_SPACE_HD_REC709)) |
| 246 *color_space = kRec709_SkYUVColorSpace; | 244 *color_space = kRec709_SkYUVColorSpace; |
| 247 else | 245 else |
| 248 *color_space = kRec601_SkYUVColorSpace; | 246 *color_space = kRec601_SkYUVColorSpace; |
| 249 } | 247 } |
| 250 | 248 |
| 251 for (int plane = VideoFrame::kYPlane; plane <= VideoFrame::kVPlane; | 249 for (int plane = VideoFrame::kYPlane; plane <= VideoFrame::kVPlane; |
| 252 ++plane) { | 250 ++plane) { |
| 253 if (sizes) { | 251 const gfx::Size size = VideoFrame::PlaneSize( |
| 254 const gfx::Size size = | 252 frame_->format(), plane, gfx::Size(frame_->visible_rect().width(), |
| 255 VideoFrame::PlaneSize(frame_->format(), plane, | 253 frame_->visible_rect().height())); |
| 256 gfx::Size(frame_->visible_rect().width(), | 254 sizeInfo->fSizes[plane].set(size.width(), size.height()); |
| 257 frame_->visible_rect().height())); | 255 sizeInfo->fWidthBytes[plane] = size.width(); |
| 258 sizes[plane].set(size.width(), size.height()); | 256 } |
| 257 |
| 258 return true; |
| 259 } |
| 260 |
| 261 bool onGetYUV8Planes(const SkYUVSizeInfo& sizeInfo, |
| 262 void* planes[3]) override { |
| 263 media::VideoPixelFormat format = frame_->format(); |
| 264 DCHECK(media::IsYuvPlanar(format) && format != PIXEL_FORMAT_YV12A); |
| 265 |
| 266 for (int plane = VideoFrame::kYPlane; plane <= VideoFrame::kVPlane; |
| 267 ++plane) { |
| 268 const gfx::Size size = VideoFrame::PlaneSize( |
| 269 frame_->format(), plane, gfx::Size(frame_->visible_rect().width(), |
| 270 frame_->visible_rect().height())); |
| 271 if (size.width() != sizeInfo.fSizes[plane].width() || |
| 272 size.height() != sizeInfo.fSizes[plane].height()) { |
| 273 return false; |
| 259 } | 274 } |
| 260 if (row_bytes && planes) { | |
| 261 size_t offset; | |
| 262 const int y_shift = | |
| 263 (frame_->format() == media::PIXEL_FORMAT_YV16) ? 0 : 1; | |
| 264 if (plane == VideoFrame::kYPlane) { | |
| 265 offset = (frame_->stride(VideoFrame::kYPlane) * | |
| 266 frame_->visible_rect().y()) + | |
| 267 frame_->visible_rect().x(); | |
| 268 } else { | |
| 269 offset = (frame_->stride(VideoFrame::kUPlane) * | |
| 270 (frame_->visible_rect().y() >> y_shift)) + | |
| 271 (frame_->visible_rect().x() >> 1); | |
| 272 } | |
| 273 | 275 |
| 274 // Copy the frame to the supplied memory. | 276 size_t offset; |
| 275 // TODO: Find a way (API change?) to avoid this copy. | 277 const int y_shift = |
| 276 char* out_line = static_cast<char*>(planes[plane]); | 278 (frame_->format() == media::PIXEL_FORMAT_YV16) ? 0 : 1; |
| 277 int out_line_stride = row_bytes[plane]; | 279 if (plane == VideoFrame::kYPlane) { |
| 278 uint8_t* in_line = frame_->data(plane) + offset; | 280 offset = |
| 279 int in_line_stride = frame_->stride(plane); | 281 (frame_->stride(VideoFrame::kYPlane) * frame_->visible_rect().y()) + |
| 280 int plane_height = sizes[plane].height(); | 282 frame_->visible_rect().x(); |
| 281 if (in_line_stride == out_line_stride) { | 283 } else { |
| 282 memcpy(out_line, in_line, plane_height * in_line_stride); | 284 offset = (frame_->stride(VideoFrame::kUPlane) * |
| 283 } else { | 285 (frame_->visible_rect().y() >> y_shift)) + |
| 284 // Different line padding so need to copy one line at a time. | 286 (frame_->visible_rect().x() >> 1); |
| 285 int bytes_to_copy_per_line = out_line_stride < in_line_stride | 287 } |
| 286 ? out_line_stride | 288 |
| 287 : in_line_stride; | 289 // Copy the frame to the supplied memory. |
| 288 for (int line_no = 0; line_no < plane_height; line_no++) { | 290 // TODO: Find a way (API change?) to avoid this copy. |
| 289 memcpy(out_line, in_line, bytes_to_copy_per_line); | 291 char* out_line = static_cast<char*>(planes[plane]); |
| 290 in_line += in_line_stride; | 292 int out_line_stride = sizeInfo.fWidthBytes[plane]; |
| 291 out_line += out_line_stride; | 293 uint8_t* in_line = frame_->data(plane) + offset; |
| 292 } | 294 int in_line_stride = frame_->stride(plane); |
| 295 int plane_height = sizeInfo.fSizes[plane].height(); |
| 296 if (in_line_stride == out_line_stride) { |
| 297 memcpy(out_line, in_line, plane_height * in_line_stride); |
| 298 } else { |
| 299 // Different line padding so need to copy one line at a time. |
| 300 int bytes_to_copy_per_line = |
| 301 out_line_stride < in_line_stride ? out_line_stride : in_line_stride; |
| 302 for (int line_no = 0; line_no < plane_height; line_no++) { |
| 303 memcpy(out_line, in_line, bytes_to_copy_per_line); |
| 304 in_line += in_line_stride; |
| 305 out_line += out_line_stride; |
| 293 } | 306 } |
| 294 } | 307 } |
| 295 } | 308 } |
| 296 return true; | 309 return true; |
| 297 } | 310 } |
| 298 | 311 |
| 299 private: | 312 private: |
| 300 scoped_refptr<VideoFrame> frame_; | 313 scoped_refptr<VideoFrame> frame_; |
| 301 | 314 |
| 302 DISALLOW_IMPLICIT_CONSTRUCTORS(VideoImageGenerator); | 315 DISALLOW_IMPLICIT_CONSTRUCTORS(VideoImageGenerator); |
| (...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 663 } | 676 } |
| 664 | 677 |
| 665 void SkCanvasVideoRenderer::ResetCache() { | 678 void SkCanvasVideoRenderer::ResetCache() { |
| 666 DCHECK(thread_checker_.CalledOnValidThread()); | 679 DCHECK(thread_checker_.CalledOnValidThread()); |
| 667 // Clear cached values. | 680 // Clear cached values. |
| 668 last_image_ = nullptr; | 681 last_image_ = nullptr; |
| 669 last_timestamp_ = kNoTimestamp(); | 682 last_timestamp_ = kNoTimestamp(); |
| 670 } | 683 } |
| 671 | 684 |
| 672 } // namespace media | 685 } // namespace media |
| OLD | NEW |