| 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 <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 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 422 rotated_dest_size = | 422 rotated_dest_size = |
| 423 gfx::SizeF(rotated_dest_size.height(), rotated_dest_size.width()); | 423 gfx::SizeF(rotated_dest_size.height(), rotated_dest_size.width()); |
| 424 } | 424 } |
| 425 canvas->scale( | 425 canvas->scale( |
| 426 SkFloatToScalar(rotated_dest_size.width() / last_image_->width()), | 426 SkFloatToScalar(rotated_dest_size.width() / last_image_->width()), |
| 427 SkFloatToScalar(rotated_dest_size.height() / last_image_->height())); | 427 SkFloatToScalar(rotated_dest_size.height() / last_image_->height())); |
| 428 canvas->translate(-SkFloatToScalar(last_image_->width() * 0.5f), | 428 canvas->translate(-SkFloatToScalar(last_image_->width() * 0.5f), |
| 429 -SkFloatToScalar(last_image_->height() * 0.5f)); | 429 -SkFloatToScalar(last_image_->height() * 0.5f)); |
| 430 } | 430 } |
| 431 | 431 |
| 432 // This is a workaround for crbug.com/524717. SkBitmaps are read back before a | 432 // This is a workaround for crbug.com/524717. A texture backed image is not |
| 433 // SkPicture is sent to multiple threads while SkImages are not. The long term | 433 // safe to access on another thread or GL context. So if we're drawing into a |
| 434 // solution is for Skia to provide a SkPicture filter that makes a picture | 434 // recording canvas we read the texture back into CPU memory and record that |
| 435 // safe for multiple CPU raster threads (skbug.com/4321). We limit the | 435 // sw image into the SkPicture. The long term solution is for Skia to provide |
| 436 // workaround to cases where the src frame is a texture and the canvas is | 436 // a SkPicture filter that makes a picture safe for multiple CPU raster |
| 437 // recording. | 437 // threads. (skbug.com/4321). |
| 438 if (last_image_.get()->getTexture() && | 438 if (canvas->imageInfo().colorType() == kUnknown_SkColorType) { |
| 439 canvas->imageInfo().colorType() == kUnknown_SkColorType) { | 439 sk_sp<SkImage> swImage = last_image_->makeNonTextureImage(); |
| 440 SkBitmap bmp; | 440 canvas->drawImage(swImage, 0, 0, &paint); |
| 441 GrWrapTextureInBitmap(last_image_.get()->getTexture(), | |
| 442 last_image_.get()->width(), | |
| 443 last_image_.get()->height(), true, &bmp); | |
| 444 // Even though the bitmap is logically immutable we do not mark it as such | |
| 445 // because doing so would defer readback until rasterization, which will be | |
| 446 // on another thread and is therefore unsafe. | |
| 447 canvas->drawBitmap(bmp, 0, 0, &paint); | |
| 448 } else { | 441 } else { |
| 449 canvas->drawImage(last_image_.get(), 0, 0, &paint); | 442 canvas->drawImage(last_image_.get(), 0, 0, &paint); |
| 450 } | 443 } |
| 451 | 444 |
| 452 if (need_transform) | 445 if (need_transform) |
| 453 canvas->restore(); | 446 canvas->restore(); |
| 454 // Make sure to flush so we can remove the videoframe from the generator. | 447 // Make sure to flush so we can remove the videoframe from the generator. |
| 455 canvas->flush(); | 448 canvas->flush(); |
| 456 | 449 |
| 457 if (video_frame->HasTextures()) { | 450 if (video_frame->HasTextures()) { |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 679 } | 672 } |
| 680 | 673 |
| 681 void SkCanvasVideoRenderer::ResetCache() { | 674 void SkCanvasVideoRenderer::ResetCache() { |
| 682 DCHECK(thread_checker_.CalledOnValidThread()); | 675 DCHECK(thread_checker_.CalledOnValidThread()); |
| 683 // Clear cached values. | 676 // Clear cached values. |
| 684 last_image_ = nullptr; | 677 last_image_ = nullptr; |
| 685 last_timestamp_ = kNoTimestamp(); | 678 last_timestamp_ = kNoTimestamp(); |
| 686 } | 679 } |
| 687 | 680 |
| 688 } // namespace media | 681 } // namespace media |
| OLD | NEW |