| 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 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 if (!compositor_) | 121 if (!compositor_) |
| 122 return false; | 122 return false; |
| 123 | 123 |
| 124 return true; | 124 return true; |
| 125 } | 125 } |
| 126 | 126 |
| 127 void DelegatedFrameHost::CopyFromCompositingSurface( | 127 void DelegatedFrameHost::CopyFromCompositingSurface( |
| 128 const gfx::Rect& src_subrect, | 128 const gfx::Rect& src_subrect, |
| 129 const gfx::Size& output_size, | 129 const gfx::Size& output_size, |
| 130 ReadbackRequestCallback& callback, | 130 ReadbackRequestCallback& callback, |
| 131 const SkColorType color_type) { | 131 const SkColorType preferred_color_type) { |
| 132 // Only ARGB888 and RGB565 supported as of now. | 132 // Only ARGB888 and RGB565 supported as of now. |
| 133 bool format_support = ((color_type == kAlpha_8_SkColorType) || | 133 bool format_support = ((preferred_color_type == kAlpha_8_SkColorType) || |
| 134 (color_type == kRGB_565_SkColorType) || | 134 (preferred_color_type == kRGB_565_SkColorType) || |
| 135 (color_type == kN32_SkColorType)); | 135 (preferred_color_type == kN32_SkColorType)); |
| 136 DCHECK(format_support); | 136 DCHECK(format_support); |
| 137 if (!CanCopyToBitmap()) { | 137 if (!CanCopyToBitmap()) { |
| 138 callback.Run(SkBitmap(), content::READBACK_SURFACE_UNAVAILABLE); | 138 callback.Run(SkBitmap(), content::READBACK_SURFACE_UNAVAILABLE); |
| 139 return; | 139 return; |
| 140 } | 140 } |
| 141 | 141 |
| 142 scoped_ptr<cc::CopyOutputRequest> request = | 142 scoped_ptr<cc::CopyOutputRequest> request = |
| 143 cc::CopyOutputRequest::CreateRequest(base::Bind( | 143 cc::CopyOutputRequest::CreateRequest( |
| 144 &DelegatedFrameHost::CopyFromCompositingSurfaceHasResult, | 144 base::Bind(&DelegatedFrameHost::CopyFromCompositingSurfaceHasResult, |
| 145 output_size, | 145 output_size, preferred_color_type, callback)); |
| 146 color_type, | |
| 147 callback)); | |
| 148 if (!src_subrect.IsEmpty()) | 146 if (!src_subrect.IsEmpty()) |
| 149 request->set_area(src_subrect); | 147 request->set_area(src_subrect); |
| 150 RequestCopyOfOutput(request.Pass()); | 148 RequestCopyOfOutput(request.Pass()); |
| 151 } | 149 } |
| 152 | 150 |
| 153 void DelegatedFrameHost::CopyFromCompositingSurfaceToVideoFrame( | 151 void DelegatedFrameHost::CopyFromCompositingSurfaceToVideoFrame( |
| 154 const gfx::Rect& src_subrect, | 152 const gfx::Rect& src_subrect, |
| 155 const scoped_refptr<media::VideoFrame>& target, | 153 const scoped_refptr<media::VideoFrame>& target, |
| 156 const base::Callback<void(bool)>& callback) { | 154 const base::Callback<void(bool)>& callback) { |
| 157 if (!CanCopyToVideoFrame()) { | 155 if (!CanCopyToVideoFrame()) { |
| (...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 575 // static | 573 // static |
| 576 void DelegatedFrameHost::PrepareTextureCopyOutputResult( | 574 void DelegatedFrameHost::PrepareTextureCopyOutputResult( |
| 577 const gfx::Size& dst_size_in_pixel, | 575 const gfx::Size& dst_size_in_pixel, |
| 578 const SkColorType color_type, | 576 const SkColorType color_type, |
| 579 ReadbackRequestCallback& callback, | 577 ReadbackRequestCallback& callback, |
| 580 scoped_ptr<cc::CopyOutputResult> result) { | 578 scoped_ptr<cc::CopyOutputResult> result) { |
| 581 DCHECK(result->HasTexture()); | 579 DCHECK(result->HasTexture()); |
| 582 base::ScopedClosureRunner scoped_callback_runner( | 580 base::ScopedClosureRunner scoped_callback_runner( |
| 583 base::Bind(callback, SkBitmap(), content::READBACK_FAILED)); | 581 base::Bind(callback, SkBitmap(), content::READBACK_FAILED)); |
| 584 | 582 |
| 585 // TODO(sikugu): We should be able to validate the format here using | 583 // TODO(siva.gunturi): We should be able to validate the format here using |
| 586 // GLHelper::IsReadbackConfigSupported before we processs the result. | 584 // GLHelper::IsReadbackConfigSupported before we processs the result. |
| 587 // See crbug.com/415682. | 585 // See crbug.com/415682 and crbug.com/415131. |
| 588 scoped_ptr<SkBitmap> bitmap(new SkBitmap); | 586 scoped_ptr<SkBitmap> bitmap(new SkBitmap); |
| 589 if (!bitmap->tryAllocPixels(SkImageInfo::Make(dst_size_in_pixel.width(), | 587 if (!bitmap->tryAllocPixels(SkImageInfo::Make( |
| 590 dst_size_in_pixel.height(), | 588 dst_size_in_pixel.width(), dst_size_in_pixel.height(), color_type, |
| 591 color_type, | 589 kOpaque_SkAlphaType))) { |
| 592 kOpaque_SkAlphaType))) | 590 scoped_callback_runner.Reset(base::Bind( |
| 591 callback, SkBitmap(), content::READBACK_BITMAP_ALLOCATION_FAILURE)); |
| 593 return; | 592 return; |
| 593 } |
| 594 | 594 |
| 595 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); | 595 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); |
| 596 GLHelper* gl_helper = factory->GetGLHelper(); | 596 GLHelper* gl_helper = factory->GetGLHelper(); |
| 597 if (!gl_helper) | 597 if (!gl_helper) |
| 598 return; | 598 return; |
| 599 | 599 |
| 600 scoped_ptr<SkAutoLockPixels> bitmap_pixels_lock( | 600 scoped_ptr<SkAutoLockPixels> bitmap_pixels_lock( |
| 601 new SkAutoLockPixels(*bitmap)); | 601 new SkAutoLockPixels(*bitmap)); |
| 602 uint8* pixels = static_cast<uint8*>(bitmap->getPixels()); | 602 uint8* pixels = static_cast<uint8*>(bitmap->getPixels()); |
| 603 | 603 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 620 callback, | 620 callback, |
| 621 base::Passed(&release_callback), | 621 base::Passed(&release_callback), |
| 622 base::Passed(&bitmap), | 622 base::Passed(&bitmap), |
| 623 base::Passed(&bitmap_pixels_lock)), | 623 base::Passed(&bitmap_pixels_lock)), |
| 624 GLHelper::SCALER_QUALITY_GOOD); | 624 GLHelper::SCALER_QUALITY_GOOD); |
| 625 } | 625 } |
| 626 | 626 |
| 627 // static | 627 // static |
| 628 void DelegatedFrameHost::PrepareBitmapCopyOutputResult( | 628 void DelegatedFrameHost::PrepareBitmapCopyOutputResult( |
| 629 const gfx::Size& dst_size_in_pixel, | 629 const gfx::Size& dst_size_in_pixel, |
| 630 const SkColorType color_type, | 630 const SkColorType preferred_color_type, |
| 631 ReadbackRequestCallback& callback, | 631 ReadbackRequestCallback& callback, |
| 632 scoped_ptr<cc::CopyOutputResult> result) { | 632 scoped_ptr<cc::CopyOutputResult> result) { |
| 633 SkColorType color_type = preferred_color_type; |
| 633 if (color_type != kN32_SkColorType && color_type != kAlpha_8_SkColorType) { | 634 if (color_type != kN32_SkColorType && color_type != kAlpha_8_SkColorType) { |
| 634 NOTIMPLEMENTED(); | 635 // Switch back to default colortype if format not supported. |
| 635 callback.Run(SkBitmap(), READBACK_FORMAT_NOT_SUPPORTED); | 636 color_type = kN32_SkColorType; |
| 636 return; | |
| 637 } | 637 } |
| 638 DCHECK(result->HasBitmap()); | 638 DCHECK(result->HasBitmap()); |
| 639 scoped_ptr<SkBitmap> source = result->TakeBitmap(); | 639 scoped_ptr<SkBitmap> source = result->TakeBitmap(); |
| 640 DCHECK(source); | 640 DCHECK(source); |
| 641 SkBitmap scaled_bitmap; | 641 SkBitmap scaled_bitmap; |
| 642 if (source->width() != dst_size_in_pixel.width() || | 642 if (source->width() != dst_size_in_pixel.width() || |
| 643 source->height() != dst_size_in_pixel.height()) { | 643 source->height() != dst_size_in_pixel.height()) { |
| 644 scaled_bitmap = | 644 scaled_bitmap = |
| 645 skia::ImageOperations::Resize(*source, | 645 skia::ImageOperations::Resize(*source, |
| 646 skia::ImageOperations::RESIZE_BEST, | 646 skia::ImageOperations::RESIZE_BEST, |
| 647 dst_size_in_pixel.width(), | 647 dst_size_in_pixel.width(), |
| 648 dst_size_in_pixel.height()); | 648 dst_size_in_pixel.height()); |
| 649 } else { | 649 } else { |
| 650 scaled_bitmap = *source; | 650 scaled_bitmap = *source; |
| 651 } | 651 } |
| 652 if (color_type == kN32_SkColorType) { | 652 if (color_type == kN32_SkColorType) { |
| 653 DCHECK_EQ(scaled_bitmap.colorType(), kN32_SkColorType); | 653 DCHECK_EQ(scaled_bitmap.colorType(), kN32_SkColorType); |
| 654 callback.Run(scaled_bitmap, READBACK_SUCCESS); | 654 callback.Run(scaled_bitmap, READBACK_SUCCESS); |
| 655 return; | 655 return; |
| 656 } | 656 } |
| 657 DCHECK_EQ(color_type, kAlpha_8_SkColorType); | 657 DCHECK_EQ(color_type, kAlpha_8_SkColorType); |
| 658 // The software path currently always returns N32 bitmap regardless of the | 658 // The software path currently always returns N32 bitmap regardless of the |
| 659 // |color_type| we ask for. | 659 // |color_type| we ask for. |
| 660 DCHECK_EQ(scaled_bitmap.colorType(), kN32_SkColorType); | 660 DCHECK_EQ(scaled_bitmap.colorType(), kN32_SkColorType); |
| 661 // Paint |scaledBitmap| to alpha-only |grayscale_bitmap|. | 661 // Paint |scaledBitmap| to alpha-only |grayscale_bitmap|. |
| 662 SkBitmap grayscale_bitmap; | 662 SkBitmap grayscale_bitmap; |
| 663 bool success = grayscale_bitmap.tryAllocPixels( | 663 bool success = grayscale_bitmap.tryAllocPixels( |
| 664 SkImageInfo::MakeA8(scaled_bitmap.width(), scaled_bitmap.height())); | 664 SkImageInfo::MakeA8(scaled_bitmap.width(), scaled_bitmap.height())); |
| 665 if (!success) { | 665 if (!success) { |
| 666 callback.Run(SkBitmap(), content::READBACK_MEMORY_ALLOCATION_FAILURE); | 666 callback.Run(SkBitmap(), content::READBACK_BITMAP_ALLOCATION_FAILURE); |
| 667 return; | 667 return; |
| 668 } | 668 } |
| 669 SkCanvas canvas(grayscale_bitmap); | 669 SkCanvas canvas(grayscale_bitmap); |
| 670 SkPaint paint; | 670 SkPaint paint; |
| 671 skia::RefPtr<SkColorFilter> filter = | 671 skia::RefPtr<SkColorFilter> filter = |
| 672 skia::AdoptRef(SkLumaColorFilter::Create()); | 672 skia::AdoptRef(SkLumaColorFilter::Create()); |
| 673 paint.setColorFilter(filter.get()); | 673 paint.setColorFilter(filter.get()); |
| 674 canvas.drawBitmap(scaled_bitmap, SkIntToScalar(0), SkIntToScalar(0), &paint); | 674 canvas.drawBitmap(scaled_bitmap, SkIntToScalar(0), SkIntToScalar(0), &paint); |
| 675 callback.Run(grayscale_bitmap, READBACK_SUCCESS); | 675 callback.Run(grayscale_bitmap, READBACK_SUCCESS); |
| 676 } | 676 } |
| (...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1005 cc::SurfaceManager* manager = factory->GetSurfaceManager(); | 1005 cc::SurfaceManager* manager = factory->GetSurfaceManager(); |
| 1006 new_layer->SetShowSurface( | 1006 new_layer->SetShowSurface( |
| 1007 surface_id_, base::Bind(&SatisfyCallback, base::Unretained(manager)), | 1007 surface_id_, base::Bind(&SatisfyCallback, base::Unretained(manager)), |
| 1008 base::Bind(&RequireCallback, base::Unretained(manager)), | 1008 base::Bind(&RequireCallback, base::Unretained(manager)), |
| 1009 current_surface_size_, current_scale_factor_, | 1009 current_surface_size_, current_scale_factor_, |
| 1010 current_frame_size_in_dip_); | 1010 current_frame_size_in_dip_); |
| 1011 } | 1011 } |
| 1012 } | 1012 } |
| 1013 | 1013 |
| 1014 } // namespace content | 1014 } // namespace content |
| OLD | NEW |