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

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

Issue 2276033002: Pass SkPaint instead of its alpha and mode in WebMediaPlayer::paint (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: android should compile Created 4 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
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/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 314 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 this, 325 this,
326 &SkCanvasVideoRenderer::ResetCache) {} 326 &SkCanvasVideoRenderer::ResetCache) {}
327 327
328 SkCanvasVideoRenderer::~SkCanvasVideoRenderer() { 328 SkCanvasVideoRenderer::~SkCanvasVideoRenderer() {
329 ResetCache(); 329 ResetCache();
330 } 330 }
331 331
332 void SkCanvasVideoRenderer::Paint(const scoped_refptr<VideoFrame>& video_frame, 332 void SkCanvasVideoRenderer::Paint(const scoped_refptr<VideoFrame>& video_frame,
333 SkCanvas* canvas, 333 SkCanvas* canvas,
334 const gfx::RectF& dest_rect, 334 const gfx::RectF& dest_rect,
335 uint8_t alpha, 335 SkPaint& paint,
336 SkXfermode::Mode mode,
337 VideoRotation video_rotation, 336 VideoRotation video_rotation,
338 const Context3D& context_3d) { 337 const Context3D& context_3d) {
339 DCHECK(thread_checker_.CalledOnValidThread()); 338 DCHECK(thread_checker_.CalledOnValidThread());
340 if (alpha == 0) { 339 if (paint.getAlpha() == 0) {
341 return; 340 return;
342 } 341 }
343 342
344 SkRect dest; 343 SkRect dest;
345 dest.set(dest_rect.x(), dest_rect.y(), dest_rect.right(), dest_rect.bottom()); 344 dest.set(dest_rect.x(), dest_rect.y(), dest_rect.right(), dest_rect.bottom());
346 345
347 SkPaint paint;
348 paint.setAlpha(alpha);
349
350 // Paint black rectangle if there isn't a frame available or the 346 // Paint black rectangle if there isn't a frame available or the
351 // frame has an unexpected format. 347 // frame has an unexpected format.
352 if (!video_frame.get() || video_frame->natural_size().IsEmpty() || 348 if (!video_frame.get() || video_frame->natural_size().IsEmpty() ||
353 !(media::IsYuvPlanar(video_frame->format()) || 349 !(media::IsYuvPlanar(video_frame->format()) ||
354 video_frame->HasTextures())) { 350 video_frame->HasTextures())) {
355 canvas->drawRect(dest, paint); 351 SkPaint blackWithAlphaPaint;
352 blackWithAlphaPaint.setAlpha(paint.getAlpha());
353 canvas->drawRect(dest, blackWithAlphaPaint);
356 canvas->flush(); 354 canvas->flush();
357 return; 355 return;
358 } 356 }
359 357
360 gpu::gles2::GLES2Interface* gl = context_3d.gl; 358 gpu::gles2::GLES2Interface* gl = context_3d.gl;
361 if (!UpdateLastImage(video_frame, context_3d)) 359 if (!UpdateLastImage(video_frame, context_3d))
362 return; 360 return;
363 361
364 paint.setXfermodeMode(mode); 362 SkPaint videoPaint;
365 paint.setFilterQuality(kLow_SkFilterQuality); 363 videoPaint.setAlpha(paint.getAlpha());
364 SkXfermode::Mode mode;
365 if (!SkXfermode::AsMode(paint.getXfermode(), &mode))
366 mode = SkXfermode::kSrcOver_Mode;
367 videoPaint.setXfermodeMode(mode);
368 videoPaint.setFilterQuality(paint.getFilterQuality());
366 369
367 const bool need_rotation = video_rotation != VIDEO_ROTATION_0; 370 const bool need_rotation = video_rotation != VIDEO_ROTATION_0;
368 const bool need_scaling = 371 const bool need_scaling =
369 dest_rect.size() != 372 dest_rect.size() !=
370 gfx::SizeF(gfx::SkISizeToSize(last_image_->dimensions())); 373 gfx::SizeF(gfx::SkISizeToSize(last_image_->dimensions()));
371 const bool need_translation = !dest_rect.origin().IsOrigin(); 374 const bool need_translation = !dest_rect.origin().IsOrigin();
372 bool need_transform = need_rotation || need_scaling || need_translation; 375 bool need_transform = need_rotation || need_scaling || need_translation;
373 if (need_transform) { 376 if (need_transform) {
374 canvas->save(); 377 canvas->save();
375 canvas->translate( 378 canvas->translate(
(...skipping 29 matching lines...) Expand all
405 } 408 }
406 409
407 // This is a workaround for crbug.com/524717. A texture backed image is not 410 // This is a workaround for crbug.com/524717. A texture backed image is not
408 // safe to access on another thread or GL context. So if we're drawing into a 411 // safe to access on another thread or GL context. So if we're drawing into a
409 // recording canvas we read the texture back into CPU memory and record that 412 // recording canvas we read the texture back into CPU memory and record that
410 // sw image into the SkPicture. The long term solution is for Skia to provide 413 // sw image into the SkPicture. The long term solution is for Skia to provide
411 // a SkPicture filter that makes a picture safe for multiple CPU raster 414 // a SkPicture filter that makes a picture safe for multiple CPU raster
412 // threads. (skbug.com/4321). 415 // threads. (skbug.com/4321).
413 if (canvas->imageInfo().colorType() == kUnknown_SkColorType) { 416 if (canvas->imageInfo().colorType() == kUnknown_SkColorType) {
414 sk_sp<SkImage> swImage = last_image_->makeNonTextureImage(); 417 sk_sp<SkImage> swImage = last_image_->makeNonTextureImage();
415 canvas->drawImage(swImage, 0, 0, &paint); 418 canvas->drawImage(swImage, 0, 0, &videoPaint);
416 } else { 419 } else {
417 canvas->drawImage(last_image_.get(), 0, 0, &paint); 420 canvas->drawImage(last_image_.get(), 0, 0, &videoPaint);
418 } 421 }
419 422
420 if (need_transform) 423 if (need_transform)
421 canvas->restore(); 424 canvas->restore();
422 // Make sure to flush so we can remove the videoframe from the generator. 425 // Make sure to flush so we can remove the videoframe from the generator.
423 canvas->flush(); 426 canvas->flush();
424 427
425 if (video_frame->HasTextures()) { 428 if (video_frame->HasTextures()) {
426 DCHECK(gl); 429 DCHECK(gl);
427 SyncTokenClientImpl client(gl); 430 SyncTokenClientImpl client(gl);
428 video_frame->UpdateReleaseSyncToken(&client); 431 video_frame->UpdateReleaseSyncToken(&client);
429 } 432 }
430 } 433 }
431 434
432 void SkCanvasVideoRenderer::Copy(const scoped_refptr<VideoFrame>& video_frame, 435 void SkCanvasVideoRenderer::Copy(const scoped_refptr<VideoFrame>& video_frame,
433 SkCanvas* canvas, 436 SkCanvas* canvas,
434 const Context3D& context_3d) { 437 const Context3D& context_3d) {
435 Paint(video_frame, canvas, gfx::RectF(video_frame->visible_rect()), 0xff, 438 SkPaint paint;
436 SkXfermode::kSrc_Mode, media::VIDEO_ROTATION_0, context_3d); 439 paint.setXfermodeMode(SkXfermode::kSrc_Mode);
440 paint.setFilterQuality(kLow_SkFilterQuality);
441 Paint(video_frame, canvas, gfx::RectF(video_frame->visible_rect()), paint,
442 media::VIDEO_ROTATION_0, context_3d);
437 } 443 }
438 444
439 namespace { 445 namespace {
440 446
441 // libyuv doesn't support 9- and 10-bit video frames yet. This function 447 // libyuv doesn't support 9- and 10-bit video frames yet. This function
442 // creates a regular 8-bit video frame which we can give to libyuv. 448 // creates a regular 8-bit video frame which we can give to libyuv.
443 scoped_refptr<VideoFrame> DownShiftHighbitVideoFrame( 449 scoped_refptr<VideoFrame> DownShiftHighbitVideoFrame(
444 const VideoFrame* video_frame) { 450 const VideoFrame* video_frame) {
445 VideoPixelFormat format; 451 VideoPixelFormat format;
446 int shift = 1; 452 int shift = 1;
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
748 if (!last_image_) // Couldn't create the SkImage. 754 if (!last_image_) // Couldn't create the SkImage.
749 return false; 755 return false;
750 last_timestamp_ = video_frame->timestamp(); 756 last_timestamp_ = video_frame->timestamp();
751 } 757 }
752 last_image_deleting_timer_.Reset(); 758 last_image_deleting_timer_.Reset();
753 DCHECK(!!last_image_); 759 DCHECK(!!last_image_);
754 return true; 760 return true;
755 } 761 }
756 762
757 } // namespace media 763 } // namespace media
OLDNEW
« no previous file with comments | « media/renderers/skcanvas_video_renderer.h ('k') | media/renderers/skcanvas_video_renderer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698