Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(582)

Side by Side Diff: media/filters/skcanvas_video_renderer.cc

Issue 569313003: Pass YUV color space information to Skia in VideoImageGenerator. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@videoimagegenerator
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/libyuv/include/libyuv.h" 10 #include "third_party/libyuv/include/libyuv.h"
(...skipping 11 matching lines...) Expand all
22 SK_A32_SHIFT == 24 22 SK_A32_SHIFT == 24
23 #define LIBYUV_I420_TO_ARGB libyuv::I420ToABGR 23 #define LIBYUV_I420_TO_ARGB libyuv::I420ToABGR
24 #define LIBYUV_I422_TO_ARGB libyuv::I422ToABGR 24 #define LIBYUV_I422_TO_ARGB libyuv::I422ToABGR
25 #else 25 #else
26 #error Unexpected Skia ARGB_8888 layout! 26 #error Unexpected Skia ARGB_8888 layout!
27 #endif 27 #endif
28 28
29 namespace media { 29 namespace media {
30 30
31 static bool IsYUV(media::VideoFrame::Format format) { 31 static bool IsYUV(media::VideoFrame::Format format) {
32 return format == media::VideoFrame::YV12 || 32 return format == media::VideoFrame::YV12 ||
scherkus (not reviewing) 2014/09/16 00:35:08 can we switch-ify this so we future proof the code
rileya (GONE FROM CHROMIUM) 2014/09/16 00:58:32 Sgtm, done!
33 format == media::VideoFrame::YV16 || 33 format == media::VideoFrame::YV16 ||
34 format == media::VideoFrame::I420 || 34 format == media::VideoFrame::I420 ||
35 format == media::VideoFrame::YV12A || 35 format == media::VideoFrame::YV12A ||
36 format == media::VideoFrame::YV12J || 36 format == media::VideoFrame::YV12J ||
37 format == media::VideoFrame::YV24; 37 format == media::VideoFrame::YV24;
38 } 38 }
39 39
40 static bool IsYUVOrNative(media::VideoFrame::Format format) { 40 static bool IsYUVOrNative(media::VideoFrame::Format format) {
41 return IsYUV(format) || format == media::VideoFrame::NATIVE_TEXTURE; 41 return IsYUV(format) || format == media::VideoFrame::NATIVE_TEXTURE;
42 } 42 }
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 if (!pixels) 197 if (!pixels)
198 return true; 198 return true;
199 // If skia couldn't do the YUV conversion, we will. 199 // If skia couldn't do the YUV conversion, we will.
200 ConvertVideoFrameToRGBPixels(frame_, pixels, row_bytes); 200 ConvertVideoFrameToRGBPixels(frame_, pixels, row_bytes);
201 frame_ = NULL; 201 frame_ = NULL;
202 return true; 202 return true;
203 } 203 }
204 204
205 virtual bool onGetYUV8Planes(SkISize sizes[3], 205 virtual bool onGetYUV8Planes(SkISize sizes[3],
206 void* planes[3], 206 void* planes[3],
207 size_t row_bytes[3]) OVERRIDE { 207 size_t row_bytes[3],
208 SkYUVColorSpace* colorSpace) OVERRIDE {
scherkus (not reviewing) 2014/09/16 00:35:09 color_space
rileya (GONE FROM CHROMIUM) 2014/09/16 00:58:32 Done.
208 if (!frame_.get()) 209 if (!frame_.get())
209 return false; 210 return false;
210 // Currently Skia only supports JPEG color range YUV. 211
211 if (frame_->format() != VideoFrame::YV12J) 212 if (!IsYUV(frame_->format()))
212 return false; 213 return false;
214
215 if (colorSpace) {
scherkus (not reviewing) 2014/09/16 00:35:08 can skia tighten up the API to guarantee this is a
rileya (GONE FROM CHROMIUM) 2014/09/16 00:58:32 In current usage (I just plumbed it in the other d
216 if (frame_->format() == VideoFrame::YV12J)
scherkus (not reviewing) 2014/09/16 00:35:09 it's a stretch, but one day we might need 16/24-bi
rileya (GONE FROM CHROMIUM) 2014/09/16 00:58:32 Done.
217 *colorSpace = kJPEG_SkYUVColorSpace;
218 else
219 *colorSpace = kRec601_SkYUVColorSpace;
220 }
221
213 for (int plane = VideoFrame::kYPlane; plane <= VideoFrame::kVPlane; 222 for (int plane = VideoFrame::kYPlane; plane <= VideoFrame::kVPlane;
214 ++plane) { 223 ++plane) {
215 if (sizes) { 224 if (sizes) {
216 gfx::Size size; 225 gfx::Size size;
217 size = VideoFrame::PlaneSize( 226 size = VideoFrame::PlaneSize(
218 frame_->format(), plane, frame_->coded_size()); 227 frame_->format(), plane, frame_->coded_size());
219 sizes[plane].set(size.width(), size.height()); 228 sizes[plane].set(size.width(), size.height());
220 } 229 }
221 if (row_bytes) 230 if (row_bytes)
222 row_bytes[plane] = frame_->stride(plane); 231 row_bytes[plane] = frame_->stride(plane);
223 if (planes) 232 if (planes)
224 planes[plane] = frame_->data(plane); 233 planes[plane] = frame_->data(plane);
225 } 234 }
226 if (planes && row_bytes) 235 if (planes && row_bytes)
227 frame_ = NULL; 236 frame_ = NULL;
228 return true; 237 return true;
229 } 238 }
239
230 public: 240 public:
231
232 virtual void set_frame(const scoped_refptr<VideoFrame>& frame) { 241 virtual void set_frame(const scoped_refptr<VideoFrame>& frame) {
233 frame_ = frame; 242 frame_ = frame;
234 } 243 }
235 244
236 private: 245 private:
237 scoped_refptr<VideoFrame> frame_; 246 scoped_refptr<VideoFrame> frame_;
238 }; 247 };
239 248
240 SkCanvasVideoRenderer::SkCanvasVideoRenderer() 249 SkCanvasVideoRenderer::SkCanvasVideoRenderer()
241 : generator_(NULL), 250 : generator_(NULL), last_frame_timestamp_(media::kNoTimestamp()) {
242 last_frame_timestamp_(media::kNoTimestamp()) {
243 last_frame_.setIsVolatile(true); 251 last_frame_.setIsVolatile(true);
244 } 252 }
245 253
246 SkCanvasVideoRenderer::~SkCanvasVideoRenderer() {} 254 SkCanvasVideoRenderer::~SkCanvasVideoRenderer() {}
247 255
248 void SkCanvasVideoRenderer::Paint(const scoped_refptr<VideoFrame>& video_frame, 256 void SkCanvasVideoRenderer::Paint(const scoped_refptr<VideoFrame>& video_frame,
249 SkCanvas* canvas, 257 SkCanvas* canvas,
250 const gfx::RectF& dest_rect, 258 const gfx::RectF& dest_rect,
251 uint8 alpha, 259 uint8 alpha,
252 SkXfermode::Mode mode, 260 SkXfermode::Mode mode,
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 SkCanvas* canvas) { 321 SkCanvas* canvas) {
314 Paint(video_frame, 322 Paint(video_frame,
315 canvas, 323 canvas,
316 video_frame->visible_rect(), 324 video_frame->visible_rect(),
317 0xff, 325 0xff,
318 SkXfermode::kSrc_Mode, 326 SkXfermode::kSrc_Mode,
319 media::VIDEO_ROTATION_0); 327 media::VIDEO_ROTATION_0);
320 } 328 }
321 329
322 } // namespace media 330 } // namespace media
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698