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 "content/browser/renderer_host/render_widget_host_view_android.h" | 5 #include "content/browser/renderer_host/render_widget_host_view_android.h" |
6 | 6 |
7 #include <android/bitmap.h> | 7 #include <android/bitmap.h> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 647 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
658 callback.Run(false, SkBitmap()); | 658 callback.Run(false, SkBitmap()); |
659 return; | 659 return; |
660 } | 660 } |
661 const gfx::Display& display = | 661 const gfx::Display& display = |
662 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay(); | 662 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay(); |
663 float device_scale_factor = display.device_scale_factor(); | 663 float device_scale_factor = display.device_scale_factor(); |
664 | 664 |
665 DCHECK_EQ(device_scale_factor, | 665 DCHECK_EQ(device_scale_factor, |
666 ui::GetImageScale(GetScaleFactorForView(this))); | 666 ui::GetImageScale(GetScaleFactorForView(this))); |
667 | 667 |
668 const gfx::Size& dst_size_in_pixel = ConvertViewSizeToPixel(this, dst_size); | 668 const gfx::Size& dst_size_in_pixel = ConvertViewSizeToPixel(this, dst_size); |
sivag
2014/01/28 13:41:50
When we pass the const gfx::Size& dst_size to the
no sievers
2014/01/28 22:35:30
The API is in view bounds and it should match what
| |
669 gfx::Rect src_subrect_in_pixel = | 669 gfx::Rect src_subrect_in_pixel = |
670 ConvertRectToPixel(device_scale_factor, src_subrect); | 670 ConvertRectToPixel(device_scale_factor, src_subrect); |
671 | 671 |
672 if (using_synchronous_compositor_) { | 672 if (using_synchronous_compositor_) { |
673 SynchronousCopyContents(src_subrect_in_pixel, dst_size_in_pixel, callback); | 673 SynchronousCopyContents(src_subrect_in_pixel, dst_size_in_pixel, callback, |
674 bitmap_config); | |
674 UMA_HISTOGRAM_TIMES("Compositing.CopyFromSurfaceTimeSynchronous", | 675 UMA_HISTOGRAM_TIMES("Compositing.CopyFromSurfaceTimeSynchronous", |
675 base::TimeTicks::Now() - start_time); | 676 base::TimeTicks::Now() - start_time); |
676 return; | 677 return; |
677 } | 678 } |
678 scoped_ptr<cc::CopyOutputRequest> request; | 679 scoped_ptr<cc::CopyOutputRequest> request; |
679 if (src_subrect_in_pixel.size() == dst_size_in_pixel) { | 680 if ((src_subrect_in_pixel.size() == dst_size_in_pixel) && |
681 (bitmap_config == SkBitmap::kARGB_8888_Config)) { | |
680 request = cc::CopyOutputRequest::CreateBitmapRequest(base::Bind( | 682 request = cc::CopyOutputRequest::CreateBitmapRequest(base::Bind( |
681 &RenderWidgetHostViewAndroid::PrepareBitmapCopyOutputResult, | 683 &RenderWidgetHostViewAndroid::PrepareBitmapCopyOutputResult, |
682 dst_size_in_pixel, | 684 dst_size_in_pixel, |
685 bitmap_config, | |
683 start_time, | 686 start_time, |
684 callback)); | 687 callback)); |
685 } else { | 688 } else { |
686 request = cc::CopyOutputRequest::CreateRequest(base::Bind( | 689 request = cc::CopyOutputRequest::CreateRequest(base::Bind( |
687 &RenderWidgetHostViewAndroid::PrepareTextureCopyOutputResult, | 690 &RenderWidgetHostViewAndroid::PrepareTextureCopyOutputResult, |
688 dst_size_in_pixel, | 691 dst_size_in_pixel, |
689 bitmap_config, | 692 bitmap_config, |
690 start_time, | 693 start_time, |
691 callback)); | 694 callback)); |
692 } | 695 } |
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
901 } | 904 } |
902 } | 905 } |
903 | 906 |
904 void RenderWidgetHostViewAndroid::SetOverlayVideoMode(bool enabled) { | 907 void RenderWidgetHostViewAndroid::SetOverlayVideoMode(bool enabled) { |
905 layer_->SetContentsOpaque(!enabled); | 908 layer_->SetContentsOpaque(!enabled); |
906 } | 909 } |
907 | 910 |
908 void RenderWidgetHostViewAndroid::SynchronousCopyContents( | 911 void RenderWidgetHostViewAndroid::SynchronousCopyContents( |
909 const gfx::Rect& src_subrect_in_pixel, | 912 const gfx::Rect& src_subrect_in_pixel, |
910 const gfx::Size& dst_size_in_pixel, | 913 const gfx::Size& dst_size_in_pixel, |
911 const base::Callback<void(bool, const SkBitmap&)>& callback) { | 914 const base::Callback<void(bool, const SkBitmap&)>& callback, |
915 const SkBitmap::Config config) { | |
912 SynchronousCompositor* compositor = | 916 SynchronousCompositor* compositor = |
913 SynchronousCompositorImpl::FromID(host_->GetProcess()->GetID(), | 917 SynchronousCompositorImpl::FromID(host_->GetProcess()->GetID(), |
914 host_->GetRoutingID()); | 918 host_->GetRoutingID()); |
915 if (!compositor) { | 919 if (!compositor) { |
916 callback.Run(false, SkBitmap()); | 920 callback.Run(false, SkBitmap()); |
917 return; | 921 return; |
918 } | 922 } |
919 | 923 |
920 SkBitmap bitmap; | 924 SkBitmap bitmap; |
921 bitmap.setConfig(SkBitmap::kARGB_8888_Config, | 925 bitmap.setConfig(config, |
922 dst_size_in_pixel.width(), | 926 dst_size_in_pixel.width(), |
923 dst_size_in_pixel.height()); | 927 dst_size_in_pixel.height()); |
924 bitmap.allocPixels(); | 928 bitmap.allocPixels(); |
925 SkCanvas canvas(bitmap); | 929 SkCanvas canvas(bitmap); |
926 canvas.scale( | 930 canvas.scale( |
927 (float)dst_size_in_pixel.width() / (float)src_subrect_in_pixel.width(), | 931 (float)dst_size_in_pixel.width() / (float)src_subrect_in_pixel.width(), |
928 (float)dst_size_in_pixel.height() / (float)src_subrect_in_pixel.height()); | 932 (float)dst_size_in_pixel.height() / (float)src_subrect_in_pixel.height()); |
929 compositor->DemandDrawSw(&canvas); | 933 compositor->DemandDrawSw(&canvas); |
930 callback.Run(true, bitmap); | 934 callback.Run(true, bitmap); |
931 } | 935 } |
(...skipping 527 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1459 callback, | 1463 callback, |
1460 base::Passed(&release_callback), | 1464 base::Passed(&release_callback), |
1461 base::Passed(&bitmap), | 1465 base::Passed(&bitmap), |
1462 start_time, | 1466 start_time, |
1463 base::Passed(&bitmap_pixels_lock))); | 1467 base::Passed(&bitmap_pixels_lock))); |
1464 } | 1468 } |
1465 | 1469 |
1466 // static | 1470 // static |
1467 void RenderWidgetHostViewAndroid::PrepareBitmapCopyOutputResult( | 1471 void RenderWidgetHostViewAndroid::PrepareBitmapCopyOutputResult( |
1468 const gfx::Size& dst_size_in_pixel, | 1472 const gfx::Size& dst_size_in_pixel, |
1473 const SkBitmap::Config config, | |
1469 const base::TimeTicks& start_time, | 1474 const base::TimeTicks& start_time, |
1470 const base::Callback<void(bool, const SkBitmap&)>& callback, | 1475 const base::Callback<void(bool, const SkBitmap&)>& callback, |
1471 scoped_ptr<cc::CopyOutputResult> result) { | 1476 scoped_ptr<cc::CopyOutputResult> result) { |
1477 if (config != SkBitmap::kARGB_8888_Config) { | |
1478 NOTIMPLEMENTED(); | |
1479 callback.Run(false, SkBitmap()); | |
1480 return; | |
1481 } | |
1472 DCHECK(result->HasBitmap()); | 1482 DCHECK(result->HasBitmap()); |
1473 base::ScopedClosureRunner scoped_callback_runner( | 1483 base::ScopedClosureRunner scoped_callback_runner( |
1474 base::Bind(callback, false, SkBitmap())); | 1484 base::Bind(callback, false, SkBitmap())); |
1475 | 1485 |
1476 if (!result->HasBitmap() || result->IsEmpty() || result->size().IsEmpty()) | 1486 if (!result->HasBitmap() || result->IsEmpty() || result->size().IsEmpty()) |
1477 return; | 1487 return; |
1478 | 1488 |
1479 scoped_ptr<SkBitmap> source = result->TakeBitmap(); | 1489 scoped_ptr<SkBitmap> source = result->TakeBitmap(); |
1480 DCHECK(source); | 1490 DCHECK(source); |
1481 if (!source) | 1491 if (!source) |
(...skipping 28 matching lines...) Expand all Loading... | |
1510 // RenderWidgetHostView, public: | 1520 // RenderWidgetHostView, public: |
1511 | 1521 |
1512 // static | 1522 // static |
1513 RenderWidgetHostView* | 1523 RenderWidgetHostView* |
1514 RenderWidgetHostView::CreateViewForWidget(RenderWidgetHost* widget) { | 1524 RenderWidgetHostView::CreateViewForWidget(RenderWidgetHost* widget) { |
1515 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(widget); | 1525 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(widget); |
1516 return new RenderWidgetHostViewAndroid(rwhi, NULL); | 1526 return new RenderWidgetHostViewAndroid(rwhi, NULL); |
1517 } | 1527 } |
1518 | 1528 |
1519 } // namespace content | 1529 } // namespace content |
OLD | NEW |