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

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

Issue 619343003: Optimize to copy from rotated video to canvas. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 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 310 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 // Check if we should convert and update |last_frame_|. 321 // Check if we should convert and update |last_frame_|.
322 if (last_frame_.isNull() || 322 if (last_frame_.isNull() ||
323 video_frame->timestamp() != last_frame_timestamp_) { 323 video_frame->timestamp() != last_frame_timestamp_) {
324 generator_ = new VideoImageGenerator(video_frame); 324 generator_ = new VideoImageGenerator(video_frame);
325 325
326 // Note: This takes ownership of |generator_|. 326 // Note: This takes ownership of |generator_|.
327 if (!SkInstallDiscardablePixelRef(generator_, &last_frame_)) { 327 if (!SkInstallDiscardablePixelRef(generator_, &last_frame_)) {
328 NOTREACHED(); 328 NOTREACHED();
329 } 329 }
330 330
331 // TODO(rileya): Perform this rotation on the canvas, rather than allocating
332 // a new bitmap and copying.
333 switch (video_rotation) {
334 case VIDEO_ROTATION_0:
335 break;
336 case VIDEO_ROTATION_90:
337 last_frame_ = SkBitmapOperations::Rotate(
338 last_frame_, SkBitmapOperations::ROTATION_90_CW);
339 break;
340 case VIDEO_ROTATION_180:
341 last_frame_ = SkBitmapOperations::Rotate(
342 last_frame_, SkBitmapOperations::ROTATION_180_CW);
343 break;
344 case VIDEO_ROTATION_270:
345 last_frame_ = SkBitmapOperations::Rotate(
346 last_frame_, SkBitmapOperations::ROTATION_270_CW);
347 break;
348 }
349
350 // We copied the frame into a new bitmap and threw out the old one, so we
351 // no longer have a |generator_| around. This should be removed when the
352 // above TODO is addressed.
353 if (video_rotation != VIDEO_ROTATION_0)
354 generator_ = NULL;
355
356 last_frame_timestamp_ = video_frame->timestamp(); 331 last_frame_timestamp_ = video_frame->timestamp();
357 } else if (generator_) { 332 } else if (generator_) {
358 generator_->set_frame(video_frame); 333 generator_->set_frame(video_frame);
359 } 334 }
360 335
361 paint.setXfermodeMode(mode); 336 paint.setXfermodeMode(mode);
337 paint.setFilterLevel(SkPaint::kLow_FilterLevel);
362 338
363 // Paint using |last_frame_|. 339 SkScalar angle = SkFloatToScalar(0.0f);
364 paint.setFilterLevel(SkPaint::kLow_FilterLevel); 340 switch (video_rotation) {
365 canvas->drawBitmapRect(last_frame_, NULL, dest, &paint); 341 case VIDEO_ROTATION_0:
342 break;
343 case VIDEO_ROTATION_90:
344 angle = SkFloatToScalar(90.0f);
345 break;
346 case VIDEO_ROTATION_180:
347 angle = SkFloatToScalar(180.0f);
348 break;
349 case VIDEO_ROTATION_270:
350 angle = SkFloatToScalar(270.0f);
351 break;
352 }
353 if (video_rotation != VIDEO_ROTATION_0) {
354 canvas->save();
355 canvas->translate(SkFloatToScalar(dest_rect.width() * 0.5f),
356 SkFloatToScalar(dest_rect.height() * 0.5f));
357 canvas->rotate(angle);
358 canvas->translate(-SkFloatToScalar(dest_rect.width() * 0.5f),
359 -SkFloatToScalar(dest_rect.height() * 0.5f));
360 }
361 canvas->drawBitmap(last_frame_, 0, 0, &paint);
362 if (video_rotation != VIDEO_ROTATION_0)
363 canvas->restore();
dshwang 2014/10/02 19:17:30 This code is almost copy&paste from https://code.g
366 canvas->flush(); 364 canvas->flush();
367 } 365 }
368 366
369 void SkCanvasVideoRenderer::Copy(const scoped_refptr<VideoFrame>& video_frame, 367 void SkCanvasVideoRenderer::Copy(const scoped_refptr<VideoFrame>& video_frame,
370 SkCanvas* canvas) { 368 SkCanvas* canvas) {
371 Paint(video_frame, 369 Paint(video_frame,
372 canvas, 370 canvas,
373 video_frame->visible_rect(), 371 video_frame->visible_rect(),
374 0xff, 372 0xff,
375 SkXfermode::kSrc_Mode, 373 SkXfermode::kSrc_Mode,
376 media::VIDEO_ROTATION_0); 374 media::VIDEO_ROTATION_0);
377 } 375 }
378 376
379 } // namespace media 377 } // 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