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 if (src_subrect.IsEmpty()) | |
304 src_subrect = gfx::Rect(bounds); | |
305 DCHECK_LE(src_subrect.width() + src_subrect.x(), bounds.width()); | |
306 DCHECK_LE(src_subrect.height() + src_subrect.y(), bounds.height()); | |
307 const gfx::Display& display = | 303 const gfx::Display& display = |
308 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay(); | 304 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay(); |
309 float device_scale_factor = display.device_scale_factor(); | 305 float device_scale_factor = display.device_scale_factor(); |
310 DCHECK_GT(device_scale_factor, 0); | 306 DCHECK_GT(device_scale_factor, 0); |
311 gfx::Size dst_size( | 307 |
312 gfx::ToCeiledSize(gfx::ScaleSize(bounds, scale / device_scale_factor))); | 308 gfx::Size bounds = layer_->bounds(); |
309 | |
310 gfx::Size dst_size_in_dip(gfx::ToCeiledSize(gfx::ScaleSize(bounds, scale))); | |
311 | |
312 gfx::RectF src_subrect_in_dip_f(gfx::ScaleRect( | |
313 ConvertRectToDIP(device_scale_factor, src_subrect), scale)); | |
no sievers
2014/06/11 21:39:11
Why does the src_subrect get scaled by |scale|?
powei
2014/06/11 21:46:12
I think |src_subrect| assumes its space to be pre-
| |
314 | |
315 gfx::Rect src_subrect_in_dip( | |
316 gfx::ToFlooredPoint(src_subrect_in_dip_f.origin()), | |
317 gfx::ToCeiledSize(src_subrect_in_dip_f.size())); | |
318 | |
319 if (src_subrect_in_dip.IsEmpty()) | |
320 src_subrect_in_dip = gfx::Rect(dst_size_in_dip); | |
no sievers
2014/06/11 21:39:11
When does this happen?
powei
2014/06/11 21:46:11
It's a somewhat hacky convention that when |src_su
| |
321 | |
322 DCHECK_LE(src_subrect_in_dip.width() + src_subrect_in_dip.x(), | |
323 bounds.width()); | |
324 DCHECK_LE(src_subrect_in_dip.height() + src_subrect_in_dip.y(), | |
325 bounds.height()); | |
326 | |
313 CopyFromCompositingSurface( | 327 CopyFromCompositingSurface( |
314 src_subrect, dst_size, result_callback, bitmap_config); | 328 src_subrect_in_dip, dst_size_in_dip, result_callback, bitmap_config); |
315 } | 329 } |
316 | 330 |
317 bool RenderWidgetHostViewAndroid::HasValidFrame() const { | 331 bool RenderWidgetHostViewAndroid::HasValidFrame() const { |
318 if (!content_view_core_) | 332 if (!content_view_core_) |
319 return false; | 333 return false; |
320 if (!layer_) | 334 if (!layer_) |
321 return false; | 335 return false; |
322 | 336 |
323 if (texture_size_in_layer_.IsEmpty()) | 337 if (texture_size_in_layer_.IsEmpty()) |
324 return false; | 338 return false; |
(...skipping 1124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1449 results->availableRect = display.work_area(); | 1463 results->availableRect = display.work_area(); |
1450 results->deviceScaleFactor = display.device_scale_factor(); | 1464 results->deviceScaleFactor = display.device_scale_factor(); |
1451 results->orientationAngle = display.RotationAsDegree(); | 1465 results->orientationAngle = display.RotationAsDegree(); |
1452 gfx::DeviceDisplayInfo info; | 1466 gfx::DeviceDisplayInfo info; |
1453 results->depth = info.GetBitsPerPixel(); | 1467 results->depth = info.GetBitsPerPixel(); |
1454 results->depthPerComponent = info.GetBitsPerComponent(); | 1468 results->depthPerComponent = info.GetBitsPerComponent(); |
1455 results->isMonochrome = (results->depthPerComponent == 0); | 1469 results->isMonochrome = (results->depthPerComponent == 0); |
1456 } | 1470 } |
1457 | 1471 |
1458 } // namespace content | 1472 } // namespace content |
OLD | NEW |