[email protected] | c9bc8f1 | 2012-12-15 22:20:09 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "ui/snapshot/snapshot.h" |
| 6 | |
[email protected] | f7c4c27 | 2013-10-31 07:36:00 | [diff] [blame] | 7 | #include "ui/base/android/view_android.h" |
| 8 | #include "ui/base/android/window_android.h" |
[email protected] | 9e3add1 | 2013-09-12 16:10:22 | [diff] [blame] | 9 | #include "ui/gfx/display.h" |
[email protected] | c9bc8f1 | 2012-12-15 22:20:09 | [diff] [blame] | 10 | #include "ui/gfx/rect.h" |
[email protected] | 9e3add1 | 2013-09-12 16:10:22 | [diff] [blame] | 11 | #include "ui/gfx/screen.h" |
[email protected] | c9bc8f1 | 2012-12-15 22:20:09 | [diff] [blame] | 12 | |
| 13 | namespace ui { |
| 14 | |
| 15 | bool GrabViewSnapshot(gfx::NativeView view, |
| 16 | std::vector<unsigned char>* png_representation, |
| 17 | const gfx::Rect& snapshot_bounds) { |
[email protected] | 9e3add1 | 2013-09-12 16:10:22 | [diff] [blame] | 18 | return GrabWindowSnapshot( |
| 19 | view->GetWindowAndroid(), png_representation, snapshot_bounds); |
[email protected] | c9bc8f1 | 2012-12-15 22:20:09 | [diff] [blame] | 20 | } |
| 21 | |
| 22 | bool GrabWindowSnapshot(gfx::NativeWindow window, |
| 23 | std::vector<unsigned char>* png_representation, |
| 24 | const gfx::Rect& snapshot_bounds) { |
[email protected] | 9e3add1 | 2013-09-12 16:10:22 | [diff] [blame] | 25 | gfx::Display display = |
| 26 | gfx::Screen::GetNativeScreen()->GetPrimaryDisplay(); |
| 27 | gfx::Rect scaled_bounds = |
| 28 | gfx::ScaleToEnclosingRect(snapshot_bounds, |
| 29 | display.device_scale_factor()); |
| 30 | return window->GrabSnapshot( |
| 31 | scaled_bounds.x(), scaled_bounds.y(), scaled_bounds.width(), |
| 32 | scaled_bounds.height(), png_representation); |
[email protected] | c9bc8f1 | 2012-12-15 22:20:09 | [diff] [blame] | 33 | } |
| 34 | |
| 35 | } // namespace ui |