| 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" |
| 11 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
| 12 #include "cc/paint/paint_canvas.h" | 12 #include "cc/paint/paint_canvas.h" |
| 13 #include "cc/paint/paint_flags.h" | 13 #include "cc/paint/paint_flags.h" |
| 14 #include "cc/paint/paint_image.h" |
| 14 #include "gpu/GLES2/gl2extchromium.h" | 15 #include "gpu/GLES2/gl2extchromium.h" |
| 15 #include "gpu/command_buffer/client/gles2_interface.h" | 16 #include "gpu/command_buffer/client/gles2_interface.h" |
| 16 #include "gpu/command_buffer/common/mailbox_holder.h" | 17 #include "gpu/command_buffer/common/mailbox_holder.h" |
| 17 #include "media/base/data_buffer.h" | 18 #include "media/base/data_buffer.h" |
| 18 #include "media/base/video_frame.h" | 19 #include "media/base/video_frame.h" |
| 19 #include "skia/ext/texture_handle.h" | 20 #include "skia/ext/texture_handle.h" |
| 20 #include "third_party/libyuv/include/libyuv.h" | 21 #include "third_party/libyuv/include/libyuv.h" |
| 21 #include "third_party/skia/include/core/SkImage.h" | 22 #include "third_party/skia/include/core/SkImage.h" |
| 22 #include "third_party/skia/include/core/SkImageGenerator.h" | 23 #include "third_party/skia/include/core/SkImageGenerator.h" |
| 23 #include "third_party/skia/include/gpu/GrContext.h" | 24 #include "third_party/skia/include/gpu/GrContext.h" |
| (...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 409 canvas->translate(-SkFloatToScalar(last_image_->width() * 0.5f), | 410 canvas->translate(-SkFloatToScalar(last_image_->width() * 0.5f), |
| 410 -SkFloatToScalar(last_image_->height() * 0.5f)); | 411 -SkFloatToScalar(last_image_->height() * 0.5f)); |
| 411 } | 412 } |
| 412 | 413 |
| 413 // This is a workaround for crbug.com/524717. A texture backed image is not | 414 // This is a workaround for crbug.com/524717. A texture backed image is not |
| 414 // safe to access on another thread or GL context. So if we're drawing into a | 415 // safe to access on another thread or GL context. So if we're drawing into a |
| 415 // recording canvas we read the texture back into CPU memory and record that | 416 // recording canvas we read the texture back into CPU memory and record that |
| 416 // sw image into the SkPicture. The long term solution is for Skia to provide | 417 // sw image into the SkPicture. The long term solution is for Skia to provide |
| 417 // a SkPicture filter that makes a picture safe for multiple CPU raster | 418 // a SkPicture filter that makes a picture safe for multiple CPU raster |
| 418 // threads. (skbug.com/4321). | 419 // threads. (skbug.com/4321). |
| 419 if (canvas->imageInfo().colorType() == kUnknown_SkColorType) { | 420 sk_sp<const SkImage> image; |
| 420 sk_sp<SkImage> swImage = last_image_->makeNonTextureImage(); | 421 if (canvas->imageInfo().colorType() == kUnknown_SkColorType) |
| 421 canvas->drawImage(swImage, 0, 0, &video_flags); | 422 image = last_image_->makeNonTextureImage(); |
| 422 } else { | 423 else |
| 423 canvas->drawImage(last_image_, 0, 0, &video_flags); | 424 image = last_image_; |
| 424 } | 425 canvas->drawImage( |
| 426 cc::PaintImage(std::move(image), cc::PaintImage::AnimationType::VIDEO, |
| 427 cc::PaintImage::CompletionState::DONE), |
| 428 0, 0, &video_flags); |
| 425 | 429 |
| 426 if (need_transform) | 430 if (need_transform) |
| 427 canvas->restore(); | 431 canvas->restore(); |
| 428 // Make sure to flush so we can remove the videoframe from the generator. | 432 // Make sure to flush so we can remove the videoframe from the generator. |
| 429 canvas->flush(); | 433 canvas->flush(); |
| 430 | 434 |
| 431 if (video_frame->HasTextures()) { | 435 if (video_frame->HasTextures()) { |
| 432 DCHECK(gl); | 436 DCHECK(gl); |
| 433 SyncTokenClientImpl client(gl); | 437 SyncTokenClientImpl client(gl); |
| 434 video_frame->UpdateReleaseSyncToken(&client); | 438 video_frame->UpdateReleaseSyncToken(&client); |
| (...skipping 522 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 957 last_image_->bounds().contains(visible_rect)) { | 961 last_image_->bounds().contains(visible_rect)) { |
| 958 last_image_ = last_image_->makeSubset(visible_rect); | 962 last_image_ = last_image_->makeSubset(visible_rect); |
| 959 } | 963 } |
| 960 } | 964 } |
| 961 | 965 |
| 962 SkISize SkCanvasVideoRenderer::LastImageDimensionsForTesting() { | 966 SkISize SkCanvasVideoRenderer::LastImageDimensionsForTesting() { |
| 963 return last_image_dimensions_for_testing_; | 967 return last_image_dimensions_for_testing_; |
| 964 } | 968 } |
| 965 | 969 |
| 966 } // namespace media | 970 } // namespace media |
| OLD | NEW |