[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 | #ifndef UI_SNAPSHOT_SNAPSHOT_H_ |
| 6 | #define UI_SNAPSHOT_SNAPSHOT_H_ |
| 7 | |
| 8 | #include <vector> |
| 9 | |
[email protected] | 75a3f1b | 2013-12-27 00:13:43 | [diff] [blame] | 10 | #include "base/callback_forward.h" |
| 11 | #include "base/memory/ref_counted.h" |
[email protected] | 24e4cac | 2014-01-15 09:54:59 | [diff] [blame] | 12 | #include "base/memory/ref_counted_memory.h" |
[email protected] | c9bc8f1 | 2012-12-15 22:20:09 | [diff] [blame] | 13 | #include "ui/gfx/native_widget_types.h" |
| 14 | #include "ui/snapshot/snapshot_export.h" |
| 15 | |
[email protected] | 75a3f1b | 2013-12-27 00:13:43 | [diff] [blame] | 16 | namespace base { |
| 17 | class TaskRunner; |
| 18 | } |
| 19 | |
[email protected] | c9bc8f1 | 2012-12-15 22:20:09 | [diff] [blame] | 20 | namespace gfx { |
| 21 | class Rect; |
[email protected] | 75a3f1b | 2013-12-27 00:13:43 | [diff] [blame] | 22 | class Image; |
| 23 | class Size; |
[email protected] | c9bc8f1 | 2012-12-15 22:20:09 | [diff] [blame] | 24 | } |
| 25 | |
| 26 | namespace ui { |
| 27 | |
[email protected] | 75a3f1b | 2013-12-27 00:13:43 | [diff] [blame] | 28 | // Grabs a snapshot of the window/view. No security checks are done. This is |
| 29 | // intended to be used for debugging purposes where no BrowserProcess instance |
| 30 | // is available (ie. tests). This function is synchronous, so it should NOT be |
[email protected] | 43ea25e3 | 2014-01-16 22:36:15 | [diff] [blame] | 31 | // used in a result of user action. Support for async vs synchronous |
| 32 | // GrabWindowSnapshot differs by platform. To be most general, use the |
| 33 | // synchronous function first and if it returns false call the async one. |
[email protected] | c9bc8f1 | 2012-12-15 22:20:09 | [diff] [blame] | 34 | SNAPSHOT_EXPORT bool GrabWindowSnapshot( |
| 35 | gfx::NativeWindow window, |
| 36 | std::vector<unsigned char>* png_representation, |
| 37 | const gfx::Rect& snapshot_bounds); |
| 38 | |
| 39 | SNAPSHOT_EXPORT bool GrabViewSnapshot( |
| 40 | gfx::NativeView view, |
| 41 | std::vector<unsigned char>* png_representation, |
| 42 | const gfx::Rect& snapshot_bounds); |
| 43 | |
[email protected] | 667568d | 2014-08-14 10:03:08 | [diff] [blame] | 44 | |
| 45 | // These functions take a snapshot of |source_rect|, specified in layer space |
| 46 | // coordinates (DIP for desktop, physical pixels for Android), and scale the |
| 47 | // snapshot to |target_size| (in physical pixels), asynchronously. |
[email protected] | 75a3f1b | 2013-12-27 00:13:43 | [diff] [blame] | 48 | typedef base::Callback<void(const gfx::Image& snapshot)> |
[email protected] | bff4507 | 2014-01-06 20:11:59 | [diff] [blame] | 49 | GrabWindowSnapshotAsyncCallback; |
[email protected] | c051d5a5 | 2014-01-08 23:54:51 | [diff] [blame] | 50 | SNAPSHOT_EXPORT void GrabWindowSnapshotAndScaleAsync( |
[email protected] | 75a3f1b | 2013-12-27 00:13:43 | [diff] [blame] | 51 | gfx::NativeWindow window, |
| 52 | const gfx::Rect& source_rect, |
| 53 | const gfx::Size& target_size, |
| 54 | scoped_refptr<base::TaskRunner> background_task_runner, |
[email protected] | bff4507 | 2014-01-06 20:11:59 | [diff] [blame] | 55 | const GrabWindowSnapshotAsyncCallback& callback); |
[email protected] | 24e4cac | 2014-01-15 09:54:59 | [diff] [blame] | 56 | |
| 57 | typedef base::Callback<void(scoped_refptr<base::RefCountedBytes> png_data)> |
| 58 | GrabWindowSnapshotAsyncPNGCallback; |
[email protected] | c051d5a5 | 2014-01-08 23:54:51 | [diff] [blame] | 59 | SNAPSHOT_EXPORT void GrabWindowSnapshotAsync( |
| 60 | gfx::NativeWindow window, |
| 61 | const gfx::Rect& source_rect, |
| 62 | scoped_refptr<base::TaskRunner> background_task_runner, |
[email protected] | 24e4cac | 2014-01-15 09:54:59 | [diff] [blame] | 63 | const GrabWindowSnapshotAsyncPNGCallback& callback); |
[email protected] | 43ea25e3 | 2014-01-16 22:36:15 | [diff] [blame] | 64 | SNAPSHOT_EXPORT void GrabViewSnapshotAsync( |
| 65 | gfx::NativeView view, |
| 66 | const gfx::Rect& source_rect, |
| 67 | scoped_refptr<base::TaskRunner> background_task_runner, |
| 68 | const GrabWindowSnapshotAsyncPNGCallback& callback); |
[email protected] | 75a3f1b | 2013-12-27 00:13:43 | [diff] [blame] | 69 | |
[email protected] | c9bc8f1 | 2012-12-15 22:20:09 | [diff] [blame] | 70 | } // namespace ui |
| 71 | |
| 72 | #endif // UI_SNAPSHOT_SNAPSHOT_H_ |