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/android/sys_utils.h" | 9 #include "base/android/sys_utils.h" |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 #include "third_party/khronos/GLES2/gl2.h" | 59 #include "third_party/khronos/GLES2/gl2.h" |
60 #include "third_party/khronos/GLES2/gl2ext.h" | 60 #include "third_party/khronos/GLES2/gl2ext.h" |
61 #include "third_party/skia/include/core/SkCanvas.h" | 61 #include "third_party/skia/include/core/SkCanvas.h" |
62 #include "ui/base/android/window_android.h" | 62 #include "ui/base/android/window_android.h" |
63 #include "ui/base/android/window_android_compositor.h" | 63 #include "ui/base/android/window_android_compositor.h" |
64 #include "ui/events/gesture_detection/gesture_config_helper.h" | 64 #include "ui/events/gesture_detection/gesture_config_helper.h" |
65 #include "ui/events/gesture_detection/motion_event.h" | 65 #include "ui/events/gesture_detection/motion_event.h" |
66 #include "ui/gfx/android/device_display_info.h" | 66 #include "ui/gfx/android/device_display_info.h" |
67 #include "ui/gfx/android/java_bitmap.h" | 67 #include "ui/gfx/android/java_bitmap.h" |
68 #include "ui/gfx/display.h" | 68 #include "ui/gfx/display.h" |
| 69 #include "ui/gfx/point_conversions.h" |
69 #include "ui/gfx/screen.h" | 70 #include "ui/gfx/screen.h" |
70 #include "ui/gfx/size_conversions.h" | 71 #include "ui/gfx/size_conversions.h" |
71 | 72 |
72 namespace content { | 73 namespace content { |
73 | 74 |
74 namespace { | 75 namespace { |
75 | 76 |
76 const int kUndefinedOutputSurfaceId = -1; | 77 const int kUndefinedOutputSurfaceId = -1; |
77 | 78 |
78 // Used to accomodate finite precision when comparing scaled viewport and | 79 // Used to accomodate finite precision when comparing scaled viewport and |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
292 void RenderWidgetHostViewAndroid::GetScaledContentBitmap( | 293 void RenderWidgetHostViewAndroid::GetScaledContentBitmap( |
293 float scale, | 294 float scale, |
294 SkBitmap::Config bitmap_config, | 295 SkBitmap::Config bitmap_config, |
295 gfx::Rect src_subrect, | 296 gfx::Rect src_subrect, |
296 const base::Callback<void(bool, const SkBitmap&)>& result_callback) { | 297 const base::Callback<void(bool, const SkBitmap&)>& result_callback) { |
297 if (!IsSurfaceAvailableForCopy()) { | 298 if (!IsSurfaceAvailableForCopy()) { |
298 result_callback.Run(false, SkBitmap()); | 299 result_callback.Run(false, SkBitmap()); |
299 return; | 300 return; |
300 } | 301 } |
301 | 302 |
302 gfx::Size bounds = layer_->bounds(); | 303 gfx::Size dst_size; |
303 if (src_subrect.IsEmpty()) | 304 if (src_subrect.IsEmpty()) { |
304 src_subrect = gfx::Rect(bounds); | 305 dst_size = |
305 DCHECK_LE(src_subrect.width() + src_subrect.x(), bounds.width()); | 306 gfx::ToCeiledSize(ConvertSizeToPixel(scale, layer_->bounds())); |
306 DCHECK_LE(src_subrect.height() + src_subrect.y(), bounds.height()); | 307 src_subrect = gfx::Rect(layer_->bounds()); |
307 const gfx::Display& display = | 308 } else { |
308 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay(); | 309 dst_size = |
309 float device_scale_factor = display.device_scale_factor(); | 310 gfx::ToCeiledSize(ConvertSizeToPixel(scale, src_subrect.size())); |
310 DCHECK_GT(device_scale_factor, 0); | 311 } |
311 gfx::Size dst_size( | 312 |
312 gfx::ToCeiledSize(gfx::ScaleSize(bounds, scale / device_scale_factor))); | |
313 CopyFromCompositingSurface( | 313 CopyFromCompositingSurface( |
314 src_subrect, dst_size, result_callback, bitmap_config); | 314 src_subrect, dst_size, result_callback, bitmap_config); |
315 } | 315 } |
316 | 316 |
317 bool RenderWidgetHostViewAndroid::HasValidFrame() const { | 317 bool RenderWidgetHostViewAndroid::HasValidFrame() const { |
318 if (!content_view_core_) | 318 if (!content_view_core_) |
319 return false; | 319 return false; |
320 if (!layer_) | 320 if (!layer_) |
321 return false; | 321 return false; |
322 | 322 |
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
660 base::TimeTicks start_time = base::TimeTicks::Now(); | 660 base::TimeTicks start_time = base::TimeTicks::Now(); |
661 if (!using_synchronous_compositor_ && !IsSurfaceAvailableForCopy()) { | 661 if (!using_synchronous_compositor_ && !IsSurfaceAvailableForCopy()) { |
662 callback.Run(false, SkBitmap()); | 662 callback.Run(false, SkBitmap()); |
663 return; | 663 return; |
664 } | 664 } |
665 const gfx::Display& display = | 665 const gfx::Display& display = |
666 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay(); | 666 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay(); |
667 float device_scale_factor = display.device_scale_factor(); | 667 float device_scale_factor = display.device_scale_factor(); |
668 gfx::Size dst_size_in_pixel = | 668 gfx::Size dst_size_in_pixel = |
669 ConvertRectToPixel(device_scale_factor, gfx::Rect(dst_size)).size(); | 669 ConvertRectToPixel(device_scale_factor, gfx::Rect(dst_size)).size(); |
670 gfx::Rect src_subrect_in_pixel = | |
671 ConvertRectToPixel(device_scale_factor, src_subrect); | |
672 | 670 |
673 if (using_synchronous_compositor_) { | 671 if (using_synchronous_compositor_) { |
| 672 gfx::Rect src_subrect_in_pixel = |
| 673 ConvertRectToPixel(device_scale_factor, src_subrect); |
674 SynchronousCopyContents(src_subrect_in_pixel, dst_size_in_pixel, callback, | 674 SynchronousCopyContents(src_subrect_in_pixel, dst_size_in_pixel, callback, |
675 bitmap_config); | 675 bitmap_config); |
676 UMA_HISTOGRAM_TIMES("Compositing.CopyFromSurfaceTimeSynchronous", | 676 UMA_HISTOGRAM_TIMES("Compositing.CopyFromSurfaceTimeSynchronous", |
677 base::TimeTicks::Now() - start_time); | 677 base::TimeTicks::Now() - start_time); |
678 return; | 678 return; |
679 } | 679 } |
680 | 680 |
681 scoped_ptr<cc::CopyOutputRequest> request; | 681 scoped_ptr<cc::CopyOutputRequest> request; |
682 scoped_refptr<cc::Layer> readback_layer; | |
683 DCHECK(content_view_core_); | 682 DCHECK(content_view_core_); |
684 DCHECK(content_view_core_->GetWindowAndroid()); | 683 DCHECK(content_view_core_->GetWindowAndroid()); |
685 ui::WindowAndroidCompositor* compositor = | 684 ui::WindowAndroidCompositor* compositor = |
686 content_view_core_->GetWindowAndroid()->GetCompositor(); | 685 content_view_core_->GetWindowAndroid()->GetCompositor(); |
687 DCHECK(compositor); | 686 DCHECK(compositor); |
688 DCHECK(frame_provider_); | 687 DCHECK(frame_provider_); |
689 scoped_refptr<cc::DelegatedRendererLayer> delegated_layer = | 688 scoped_refptr<cc::DelegatedRendererLayer> delegated_layer = |
690 cc::DelegatedRendererLayer::Create(frame_provider_); | 689 cc::DelegatedRendererLayer::Create(frame_provider_); |
691 delegated_layer->SetBounds(content_size_in_layer_); | 690 delegated_layer->SetBounds(content_size_in_layer_); |
692 delegated_layer->SetHideLayerAndSubtree(true); | 691 delegated_layer->SetHideLayerAndSubtree(true); |
693 delegated_layer->SetIsDrawable(true); | 692 delegated_layer->SetIsDrawable(true); |
694 delegated_layer->SetContentsOpaque(true); | 693 delegated_layer->SetContentsOpaque(true); |
695 gfx::Transform layer_scale( | 694 gfx::Transform layer_scale( |
696 device_scale_factor, 0.f, 0.f, device_scale_factor, 0.f, 0.f); | 695 device_scale_factor, 0.f, 0.f, device_scale_factor, 0.f, 0.f); |
697 delegated_layer->SetTransform(layer_scale); | 696 delegated_layer->SetTransform(layer_scale); |
698 compositor->AttachLayerForReadback(delegated_layer); | 697 compositor->AttachLayerForReadback(delegated_layer); |
699 | 698 |
700 readback_layer = delegated_layer; | |
701 request = cc::CopyOutputRequest::CreateRequest( | 699 request = cc::CopyOutputRequest::CreateRequest( |
702 base::Bind(&RenderWidgetHostViewAndroid:: | 700 base::Bind(&RenderWidgetHostViewAndroid:: |
703 PrepareTextureCopyOutputResultForDelegatedReadback, | 701 PrepareTextureCopyOutputResultForDelegatedReadback, |
704 dst_size_in_pixel, | 702 dst_size_in_pixel, |
705 bitmap_config, | 703 bitmap_config, |
706 start_time, | 704 start_time, |
707 readback_layer, | 705 delegated_layer, |
708 callback)); | 706 callback)); |
709 request->set_area(src_subrect_in_pixel); | 707 request->set_area(src_subrect); |
710 readback_layer->RequestCopyOfOutput(request.Pass()); | 708 delegated_layer->RequestCopyOfOutput(request.Pass()); |
711 } | 709 } |
712 | 710 |
713 void RenderWidgetHostViewAndroid::CopyFromCompositingSurfaceToVideoFrame( | 711 void RenderWidgetHostViewAndroid::CopyFromCompositingSurfaceToVideoFrame( |
714 const gfx::Rect& src_subrect, | 712 const gfx::Rect& src_subrect, |
715 const scoped_refptr<media::VideoFrame>& target, | 713 const scoped_refptr<media::VideoFrame>& target, |
716 const base::Callback<void(bool)>& callback) { | 714 const base::Callback<void(bool)>& callback) { |
717 NOTIMPLEMENTED(); | 715 NOTIMPLEMENTED(); |
718 callback.Run(false); | 716 callback.Run(false); |
719 } | 717 } |
720 | 718 |
(...skipping 728 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1449 results->availableRect = display.work_area(); | 1447 results->availableRect = display.work_area(); |
1450 results->deviceScaleFactor = display.device_scale_factor(); | 1448 results->deviceScaleFactor = display.device_scale_factor(); |
1451 results->orientationAngle = display.RotationAsDegree(); | 1449 results->orientationAngle = display.RotationAsDegree(); |
1452 gfx::DeviceDisplayInfo info; | 1450 gfx::DeviceDisplayInfo info; |
1453 results->depth = info.GetBitsPerPixel(); | 1451 results->depth = info.GetBitsPerPixel(); |
1454 results->depthPerComponent = info.GetBitsPerComponent(); | 1452 results->depthPerComponent = info.GetBitsPerComponent(); |
1455 results->isMonochrome = (results->depthPerComponent == 0); | 1453 results->isMonochrome = (results->depthPerComponent == 0); |
1456 } | 1454 } |
1457 | 1455 |
1458 } // namespace content | 1456 } // namespace content |
OLD | NEW |