OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "content/browser/compositor/delegated_frame_host.h" | 5 #include "content/browser/compositor/delegated_frame_host.h" |
6 | 6 |
7 #include "base/callback_helpers.h" | 7 #include "base/callback_helpers.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "cc/output/compositor_frame.h" | 9 #include "cc/output/compositor_frame.h" |
10 #include "cc/output/compositor_frame_ack.h" | 10 #include "cc/output/compositor_frame_ack.h" |
(...skipping 565 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
576 void DelegatedFrameHost::PrepareTextureCopyOutputResult( | 576 void DelegatedFrameHost::PrepareTextureCopyOutputResult( |
577 const gfx::Size& dst_size_in_pixel, | 577 const gfx::Size& dst_size_in_pixel, |
578 const SkColorType color_type, | 578 const SkColorType color_type, |
579 ReadbackRequestCallback& callback, | 579 ReadbackRequestCallback& callback, |
580 scoped_ptr<cc::CopyOutputResult> result) { | 580 scoped_ptr<cc::CopyOutputResult> result) { |
581 DCHECK(result->HasTexture()); | 581 DCHECK(result->HasTexture()); |
582 base::ScopedClosureRunner scoped_callback_runner( | 582 base::ScopedClosureRunner scoped_callback_runner( |
583 base::Bind(callback, SkBitmap(), content::READBACK_FAILED)); | 583 base::Bind(callback, SkBitmap(), content::READBACK_FAILED)); |
584 | 584 |
585 // TODO(sikugu): We should be able to validate the format here using | 585 // TODO(sikugu): We should be able to validate the format here using |
586 // GLHelper::IsReadbackConfigSupported before we processs the result. | 586 // GLHelper::IsReadbackConfigSupported before we processs the result. |
no sievers
2015/05/06 23:08:03
What keeps us from doing this here? And falling ba
sivag
2015/05/07 14:14:20
Actually this fails in the browser tests, where so
| |
587 // See crbug.com/415682. | 587 // See crbug.com/415682. |
588 scoped_ptr<SkBitmap> bitmap(new SkBitmap); | 588 scoped_ptr<SkBitmap> bitmap(new SkBitmap); |
589 if (!bitmap->tryAllocPixels(SkImageInfo::Make(dst_size_in_pixel.width(), | 589 if (!bitmap->tryAllocPixels(SkImageInfo::Make( |
590 dst_size_in_pixel.height(), | 590 dst_size_in_pixel.width(), dst_size_in_pixel.height(), color_type, |
591 color_type, | 591 kOpaque_SkAlphaType))) { |
592 kOpaque_SkAlphaType))) | 592 scoped_callback_runner.Reset(base::Bind( |
593 callback, SkBitmap(), content::READBACK_BITMAP_ALLOCATION_FAILURE)); | |
593 return; | 594 return; |
595 } | |
594 | 596 |
595 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); | 597 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); |
596 GLHelper* gl_helper = factory->GetGLHelper(); | 598 GLHelper* gl_helper = factory->GetGLHelper(); |
597 if (!gl_helper) | 599 if (!gl_helper) |
598 return; | 600 return; |
599 | 601 |
600 scoped_ptr<SkAutoLockPixels> bitmap_pixels_lock( | 602 scoped_ptr<SkAutoLockPixels> bitmap_pixels_lock( |
601 new SkAutoLockPixels(*bitmap)); | 603 new SkAutoLockPixels(*bitmap)); |
602 uint8* pixels = static_cast<uint8*>(bitmap->getPixels()); | 604 uint8* pixels = static_cast<uint8*>(bitmap->getPixels()); |
603 | 605 |
(...skipping 16 matching lines...) Expand all Loading... | |
620 callback, | 622 callback, |
621 base::Passed(&release_callback), | 623 base::Passed(&release_callback), |
622 base::Passed(&bitmap), | 624 base::Passed(&bitmap), |
623 base::Passed(&bitmap_pixels_lock)), | 625 base::Passed(&bitmap_pixels_lock)), |
624 GLHelper::SCALER_QUALITY_FAST); | 626 GLHelper::SCALER_QUALITY_FAST); |
625 } | 627 } |
626 | 628 |
627 // static | 629 // static |
628 void DelegatedFrameHost::PrepareBitmapCopyOutputResult( | 630 void DelegatedFrameHost::PrepareBitmapCopyOutputResult( |
629 const gfx::Size& dst_size_in_pixel, | 631 const gfx::Size& dst_size_in_pixel, |
630 const SkColorType color_type, | 632 const SkColorType request_color_type, |
631 ReadbackRequestCallback& callback, | 633 ReadbackRequestCallback& callback, |
632 scoped_ptr<cc::CopyOutputResult> result) { | 634 scoped_ptr<cc::CopyOutputResult> result) { |
635 SkColorType color_type = request_color_type; | |
633 if (color_type != kN32_SkColorType && color_type != kAlpha_8_SkColorType) { | 636 if (color_type != kN32_SkColorType && color_type != kAlpha_8_SkColorType) { |
634 NOTIMPLEMENTED(); | 637 // Switch back to default colortype if format not supported. |
635 callback.Run(SkBitmap(), READBACK_FORMAT_NOT_SUPPORTED); | 638 color_type = kN32_SkColorType; |
636 return; | |
637 } | 639 } |
638 DCHECK(result->HasBitmap()); | 640 DCHECK(result->HasBitmap()); |
639 scoped_ptr<SkBitmap> source = result->TakeBitmap(); | 641 scoped_ptr<SkBitmap> source = result->TakeBitmap(); |
640 DCHECK(source); | 642 DCHECK(source); |
641 SkBitmap scaled_bitmap; | 643 SkBitmap scaled_bitmap; |
642 if (source->width() != dst_size_in_pixel.width() || | 644 if (source->width() != dst_size_in_pixel.width() || |
643 source->height() != dst_size_in_pixel.height()) { | 645 source->height() != dst_size_in_pixel.height()) { |
644 scaled_bitmap = | 646 scaled_bitmap = |
645 skia::ImageOperations::Resize(*source, | 647 skia::ImageOperations::Resize(*source, |
646 skia::ImageOperations::RESIZE_BEST, | 648 skia::ImageOperations::RESIZE_BEST, |
647 dst_size_in_pixel.width(), | 649 dst_size_in_pixel.width(), |
648 dst_size_in_pixel.height()); | 650 dst_size_in_pixel.height()); |
649 } else { | 651 } else { |
650 scaled_bitmap = *source; | 652 scaled_bitmap = *source; |
651 } | 653 } |
652 if (color_type == kN32_SkColorType) { | 654 if (color_type == kN32_SkColorType) { |
653 DCHECK_EQ(scaled_bitmap.colorType(), kN32_SkColorType); | 655 DCHECK_EQ(scaled_bitmap.colorType(), kN32_SkColorType); |
654 callback.Run(scaled_bitmap, READBACK_SUCCESS); | 656 callback.Run(scaled_bitmap, READBACK_SUCCESS); |
655 return; | 657 return; |
656 } | 658 } |
657 DCHECK_EQ(color_type, kAlpha_8_SkColorType); | 659 DCHECK_EQ(color_type, kAlpha_8_SkColorType); |
658 // The software path currently always returns N32 bitmap regardless of the | 660 // The software path currently always returns N32 bitmap regardless of the |
659 // |color_type| we ask for. | 661 // |color_type| we ask for. |
660 DCHECK_EQ(scaled_bitmap.colorType(), kN32_SkColorType); | 662 DCHECK_EQ(scaled_bitmap.colorType(), kN32_SkColorType); |
661 // Paint |scaledBitmap| to alpha-only |grayscale_bitmap|. | 663 // Paint |scaledBitmap| to alpha-only |grayscale_bitmap|. |
662 SkBitmap grayscale_bitmap; | 664 SkBitmap grayscale_bitmap; |
663 bool success = grayscale_bitmap.tryAllocPixels( | 665 bool success = grayscale_bitmap.tryAllocPixels( |
664 SkImageInfo::MakeA8(scaled_bitmap.width(), scaled_bitmap.height())); | 666 SkImageInfo::MakeA8(scaled_bitmap.width(), scaled_bitmap.height())); |
665 if (!success) { | 667 if (!success) { |
666 callback.Run(SkBitmap(), content::READBACK_MEMORY_ALLOCATION_FAILURE); | 668 callback.Run(SkBitmap(), content::READBACK_BITMAP_ALLOCATION_FAILURE); |
667 return; | 669 return; |
668 } | 670 } |
669 SkCanvas canvas(grayscale_bitmap); | 671 SkCanvas canvas(grayscale_bitmap); |
670 SkPaint paint; | 672 SkPaint paint; |
671 skia::RefPtr<SkColorFilter> filter = | 673 skia::RefPtr<SkColorFilter> filter = |
672 skia::AdoptRef(SkLumaColorFilter::Create()); | 674 skia::AdoptRef(SkLumaColorFilter::Create()); |
673 paint.setColorFilter(filter.get()); | 675 paint.setColorFilter(filter.get()); |
674 canvas.drawBitmap(scaled_bitmap, SkIntToScalar(0), SkIntToScalar(0), &paint); | 676 canvas.drawBitmap(scaled_bitmap, SkIntToScalar(0), SkIntToScalar(0), &paint); |
675 callback.Run(grayscale_bitmap, READBACK_SUCCESS); | 677 callback.Run(grayscale_bitmap, READBACK_SUCCESS); |
676 } | 678 } |
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1005 cc::SurfaceManager* manager = factory->GetSurfaceManager(); | 1007 cc::SurfaceManager* manager = factory->GetSurfaceManager(); |
1006 new_layer->SetShowSurface( | 1008 new_layer->SetShowSurface( |
1007 surface_id_, base::Bind(&SatisfyCallback, base::Unretained(manager)), | 1009 surface_id_, base::Bind(&SatisfyCallback, base::Unretained(manager)), |
1008 base::Bind(&RequireCallback, base::Unretained(manager)), | 1010 base::Bind(&RequireCallback, base::Unretained(manager)), |
1009 current_surface_size_, current_scale_factor_, | 1011 current_surface_size_, current_scale_factor_, |
1010 current_frame_size_in_dip_); | 1012 current_frame_size_in_dip_); |
1011 } | 1013 } |
1012 } | 1014 } |
1013 | 1015 |
1014 } // namespace content | 1016 } // namespace content |
OLD | NEW |