| 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 <GLES3/gl3.h> | 7 #include <GLES3/gl3.h> |
| 8 #include <limits> | 8 #include <limits> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 334 this, | 334 this, |
| 335 &SkCanvasVideoRenderer::ResetCache) {} | 335 &SkCanvasVideoRenderer::ResetCache) {} |
| 336 | 336 |
| 337 SkCanvasVideoRenderer::~SkCanvasVideoRenderer() { | 337 SkCanvasVideoRenderer::~SkCanvasVideoRenderer() { |
| 338 ResetCache(); | 338 ResetCache(); |
| 339 } | 339 } |
| 340 | 340 |
| 341 void SkCanvasVideoRenderer::Paint(const scoped_refptr<VideoFrame>& video_frame, | 341 void SkCanvasVideoRenderer::Paint(const scoped_refptr<VideoFrame>& video_frame, |
| 342 cc::PaintCanvas* canvas, | 342 cc::PaintCanvas* canvas, |
| 343 const gfx::RectF& dest_rect, | 343 const gfx::RectF& dest_rect, |
| 344 cc::PaintFlags& paint, | 344 cc::PaintFlags& flags, |
| 345 VideoRotation video_rotation, | 345 VideoRotation video_rotation, |
| 346 const Context3D& context_3d) { | 346 const Context3D& context_3d) { |
| 347 DCHECK(thread_checker_.CalledOnValidThread()); | 347 DCHECK(thread_checker_.CalledOnValidThread()); |
| 348 if (paint.getAlpha() == 0) { | 348 if (flags.getAlpha() == 0) { |
| 349 return; | 349 return; |
| 350 } | 350 } |
| 351 | 351 |
| 352 SkRect dest; | 352 SkRect dest; |
| 353 dest.set(dest_rect.x(), dest_rect.y(), dest_rect.right(), dest_rect.bottom()); | 353 dest.set(dest_rect.x(), dest_rect.y(), dest_rect.right(), dest_rect.bottom()); |
| 354 | 354 |
| 355 // Paint black rectangle if there isn't a frame available or the | 355 // Paint black rectangle if there isn't a frame available or the |
| 356 // frame has an unexpected format. | 356 // frame has an unexpected format. |
| 357 if (!video_frame.get() || video_frame->natural_size().IsEmpty() || | 357 if (!video_frame.get() || video_frame->natural_size().IsEmpty() || |
| 358 !(media::IsYuvPlanar(video_frame->format()) || | 358 !(media::IsYuvPlanar(video_frame->format()) || |
| 359 video_frame->format() == media::PIXEL_FORMAT_Y16 || | 359 video_frame->format() == media::PIXEL_FORMAT_Y16 || |
| 360 video_frame->HasTextures())) { | 360 video_frame->HasTextures())) { |
| 361 cc::PaintFlags black_with_alpha_flags; | 361 cc::PaintFlags black_with_alpha_flags; |
| 362 black_with_alpha_flags.setAlpha(paint.getAlpha()); | 362 black_with_alpha_flags.setAlpha(flags.getAlpha()); |
| 363 canvas->drawRect(dest, black_with_alpha_flags); | 363 canvas->drawRect(dest, black_with_alpha_flags); |
| 364 canvas->flush(); | 364 canvas->flush(); |
| 365 return; | 365 return; |
| 366 } | 366 } |
| 367 | 367 |
| 368 gpu::gles2::GLES2Interface* gl = context_3d.gl; | 368 gpu::gles2::GLES2Interface* gl = context_3d.gl; |
| 369 if (!UpdateLastImage(video_frame, context_3d)) | 369 if (!UpdateLastImage(video_frame, context_3d)) |
| 370 return; | 370 return; |
| 371 | 371 |
| 372 cc::PaintFlags video_flags; | 372 cc::PaintFlags video_flags; |
| 373 video_flags.setAlpha(paint.getAlpha()); | 373 video_flags.setAlpha(flags.getAlpha()); |
| 374 video_flags.setBlendMode(paint.getBlendMode()); | 374 video_flags.setBlendMode(flags.getBlendMode()); |
| 375 video_flags.setFilterQuality(paint.getFilterQuality()); | 375 video_flags.setFilterQuality(flags.getFilterQuality()); |
| 376 | 376 |
| 377 const bool need_rotation = video_rotation != VIDEO_ROTATION_0; | 377 const bool need_rotation = video_rotation != VIDEO_ROTATION_0; |
| 378 const bool need_scaling = | 378 const bool need_scaling = |
| 379 dest_rect.size() != | 379 dest_rect.size() != |
| 380 gfx::SizeF(gfx::SkISizeToSize(last_image_->dimensions())); | 380 gfx::SizeF(gfx::SkISizeToSize(last_image_->dimensions())); |
| 381 const bool need_translation = !dest_rect.origin().IsOrigin(); | 381 const bool need_translation = !dest_rect.origin().IsOrigin(); |
| 382 bool need_transform = need_rotation || need_scaling || need_translation; | 382 bool need_transform = need_rotation || need_scaling || need_translation; |
| 383 if (need_transform) { | 383 if (need_transform) { |
| 384 canvas->save(); | 384 canvas->save(); |
| 385 canvas->translate( | 385 canvas->translate( |
| (...skipping 575 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 961 last_image_->bounds().contains(visible_rect)) { | 961 last_image_->bounds().contains(visible_rect)) { |
| 962 last_image_ = last_image_->makeSubset(visible_rect); | 962 last_image_ = last_image_->makeSubset(visible_rect); |
| 963 } | 963 } |
| 964 } | 964 } |
| 965 | 965 |
| 966 SkISize SkCanvasVideoRenderer::LastImageDimensionsForTesting() { | 966 SkISize SkCanvasVideoRenderer::LastImageDimensionsForTesting() { |
| 967 return last_image_dimensions_for_testing_; | 967 return last_image_dimensions_for_testing_; |
| 968 } | 968 } |
| 969 | 969 |
| 970 } // namespace media | 970 } // namespace media |
| OLD | NEW |