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 #ifndef UI_SNAPSHOT_SNAPSHOT_H_ | 5 #ifndef UI_SNAPSHOT_SNAPSHOT_H_ |
6 #define UI_SNAPSHOT_SNAPSHOT_H_ | 6 #define UI_SNAPSHOT_SNAPSHOT_H_ |
7 | 7 |
| 8 #include <stdint.h> |
8 #include <vector> | 9 #include <vector> |
9 | 10 |
10 #include "base/callback_forward.h" | 11 #include "base/callback_forward.h" |
11 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
12 #include "base/memory/ref_counted_memory.h" | 13 #include "base/memory/ref_counted_memory.h" |
13 #include "ui/gfx/native_widget_types.h" | 14 #include "ui/gfx/native_widget_types.h" |
14 #include "ui/snapshot/snapshot_export.h" | 15 #include "ui/snapshot/snapshot_export.h" |
15 | 16 |
16 namespace base { | 17 namespace base { |
17 class TaskRunner; | 18 class TaskRunner; |
18 } | 19 } |
19 | 20 |
20 namespace gfx { | 21 namespace gfx { |
21 class Rect; | 22 class Rect; |
22 class Image; | 23 class Image; |
23 class Size; | 24 class Size; |
24 } | 25 } |
25 | 26 |
26 namespace ui { | 27 namespace ui { |
27 | 28 |
| 29 enum class SnapshotEncoding { PNG, JPEG }; |
| 30 constexpr SnapshotEncoding kSnapshotEncodingDefault = SnapshotEncoding::PNG; |
| 31 |
| 32 using SnapshotQuality = uint8_t; |
| 33 constexpr SnapshotQuality kSnapshotQualityMin = 0; |
| 34 constexpr SnapshotQuality kSnapshotQualityDefault = 80; |
| 35 constexpr SnapshotQuality kSnapshotQualityMax = 100; |
| 36 |
28 // Grabs a snapshot of the window/view. No security checks are done. This is | 37 // 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 | 38 // 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 | 39 // is available (ie. tests). This function is synchronous, so it should NOT be |
31 // used in a result of user action. Support for async vs synchronous | 40 // used in a result of user action. Support for async vs synchronous |
32 // GrabWindowSnapshot differs by platform. To be most general, use the | 41 // GrabWindowSnapshot differs by platform. To be most general, use the |
33 // synchronous function first and if it returns false call the async one. | 42 // synchronous function first and if it returns false call the async one. |
34 SNAPSHOT_EXPORT bool GrabWindowSnapshot( | 43 SNAPSHOT_EXPORT bool GrabWindowSnapshot( |
35 gfx::NativeWindow window, | 44 gfx::NativeWindow window, |
36 std::vector<unsigned char>* png_representation, | 45 std::vector<unsigned char>* encoded_data, |
37 const gfx::Rect& snapshot_bounds); | 46 const gfx::Rect& snapshot_bounds, |
| 47 SnapshotEncoding encoding = kSnapshotEncodingDefault, |
| 48 SnapshotQuality quality = kSnapshotQualityDefault); |
38 | 49 |
39 SNAPSHOT_EXPORT bool GrabViewSnapshot( | 50 SNAPSHOT_EXPORT bool GrabViewSnapshot( |
40 gfx::NativeView view, | 51 gfx::NativeView view, |
41 std::vector<unsigned char>* png_representation, | 52 std::vector<unsigned char>* encoded_data, |
42 const gfx::Rect& snapshot_bounds); | 53 const gfx::Rect& snapshot_bounds, |
43 | 54 SnapshotEncoding encoding = kSnapshotEncodingDefault, |
| 55 SnapshotQuality quality = kSnapshotQualityDefault); |
44 | 56 |
45 // These functions take a snapshot of |source_rect|, specified in layer space | 57 // These functions take a snapshot of |source_rect|, specified in layer space |
46 // coordinates (DIP for desktop, physical pixels for Android), and scale the | 58 // coordinates (DIP for desktop, physical pixels for Android), and scale the |
47 // snapshot to |target_size| (in physical pixels), asynchronously. | 59 // snapshot to |target_size| (in physical pixels), asynchronously. |
48 typedef base::Callback<void(const gfx::Image& snapshot)> | 60 typedef base::Callback<void(const gfx::Image& snapshot)> |
49 GrabWindowSnapshotAsyncCallback; | 61 GrabWindowSnapshotAsyncCallback; |
50 SNAPSHOT_EXPORT void GrabWindowSnapshotAndScaleAsync( | 62 SNAPSHOT_EXPORT void GrabWindowSnapshotAndScaleAsync( |
51 gfx::NativeWindow window, | 63 gfx::NativeWindow window, |
52 const gfx::Rect& source_rect, | 64 const gfx::Rect& source_rect, |
53 const gfx::Size& target_size, | 65 const gfx::Size& target_size, |
54 scoped_refptr<base::TaskRunner> background_task_runner, | 66 scoped_refptr<base::TaskRunner> background_task_runner, |
55 const GrabWindowSnapshotAsyncCallback& callback); | 67 const GrabWindowSnapshotAsyncCallback& callback); |
56 | 68 |
57 typedef base::Callback<void(scoped_refptr<base::RefCountedBytes> png_data)> | 69 typedef base::Callback<void(scoped_refptr<base::RefCountedBytes> encoded_data)> |
58 GrabWindowSnapshotAsyncPNGCallback; | 70 GrabWindowSnapshotAsyncEncodedCallback; |
59 SNAPSHOT_EXPORT void GrabWindowSnapshotAsync( | 71 SNAPSHOT_EXPORT void GrabWindowSnapshotAsync( |
60 gfx::NativeWindow window, | 72 gfx::NativeWindow window, |
61 const gfx::Rect& source_rect, | 73 const gfx::Rect& source_rect, |
62 scoped_refptr<base::TaskRunner> background_task_runner, | 74 scoped_refptr<base::TaskRunner> background_task_runner, |
63 const GrabWindowSnapshotAsyncPNGCallback& callback); | 75 const GrabWindowSnapshotAsyncEncodedCallback& callback, |
| 76 SnapshotEncoding encoding = kSnapshotEncodingDefault, |
| 77 SnapshotQuality quality = kSnapshotQualityDefault); |
64 SNAPSHOT_EXPORT void GrabViewSnapshotAsync( | 78 SNAPSHOT_EXPORT void GrabViewSnapshotAsync( |
65 gfx::NativeView view, | 79 gfx::NativeView view, |
66 const gfx::Rect& source_rect, | 80 const gfx::Rect& source_rect, |
67 scoped_refptr<base::TaskRunner> background_task_runner, | 81 scoped_refptr<base::TaskRunner> background_task_runner, |
68 const GrabWindowSnapshotAsyncPNGCallback& callback); | 82 const GrabWindowSnapshotAsyncEncodedCallback& callback, |
| 83 SnapshotEncoding encoding = kSnapshotEncodingDefault, |
| 84 SnapshotQuality quality = kSnapshotQualityDefault); |
69 | 85 |
70 } // namespace ui | 86 } // namespace ui |
71 | 87 |
72 #endif // UI_SNAPSHOT_SNAPSHOT_H_ | 88 #endif // UI_SNAPSHOT_SNAPSHOT_H_ |
OLD | NEW |