snapshot.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. #ifndef UI_SNAPSHOT_SNAPSHOT_H_
  5. #define UI_SNAPSHOT_SNAPSHOT_H_
  6. #include "base/callback_forward.h"
  7. #include "base/memory/ref_counted.h"
  8. #include "base/memory/ref_counted_memory.h"
  9. #include "ui/gfx/native_widget_types.h"
  10. #include "ui/snapshot/snapshot_export.h"
  11. namespace gfx {
  12. class Rect;
  13. class Image;
  14. class Size;
  15. }
  16. namespace ui {
  17. // Grabs a snapshot of the window/view. No security checks are done. This is
  18. // intended to be used for debugging purposes where no BrowserProcess instance
  19. // is available (ie. tests). This function is synchronous, so it should NOT be
  20. // used in a result of user action. Support for async vs synchronous
  21. // GrabWindowSnapshot differs by platform. To be most general, use the
  22. // synchronous function first and if it returns false call the async one.
  23. SNAPSHOT_EXPORT bool GrabWindowSnapshot(gfx::NativeWindow window,
  24. const gfx::Rect& snapshot_bounds,
  25. gfx::Image* image);
  26. SNAPSHOT_EXPORT bool GrabViewSnapshot(gfx::NativeView view,
  27. const gfx::Rect& snapshot_bounds,
  28. gfx::Image* image);
  29. // These functions take a snapshot of |source_rect|, specified in layer space
  30. // coordinates (DIP for desktop, physical pixels for Android), and scale the
  31. // snapshot to |target_size| (in physical pixels), asynchronously.
  32. using GrabWindowSnapshotAsyncCallback =
  33. base::OnceCallback<void(gfx::Image snapshot)>;
  34. SNAPSHOT_EXPORT void GrabWindowSnapshotAndScaleAsync(
  35. gfx::NativeWindow window,
  36. const gfx::Rect& source_rect,
  37. const gfx::Size& target_size,
  38. GrabWindowSnapshotAsyncCallback callback);
  39. SNAPSHOT_EXPORT void GrabWindowSnapshotAsync(
  40. gfx::NativeWindow window,
  41. const gfx::Rect& source_rect,
  42. GrabWindowSnapshotAsyncCallback callback);
  43. SNAPSHOT_EXPORT void GrabViewSnapshotAsync(
  44. gfx::NativeView view,
  45. const gfx::Rect& source_rect,
  46. GrabWindowSnapshotAsyncCallback callback);
  47. using GrabWindowSnapshotAsyncPNGCallback =
  48. base::OnceCallback<void(scoped_refptr<base::RefCountedMemory> data)>;
  49. SNAPSHOT_EXPORT void GrabWindowSnapshotAsyncPNG(
  50. gfx::NativeWindow window,
  51. const gfx::Rect& source_rect,
  52. GrabWindowSnapshotAsyncPNGCallback callback);
  53. using GrabWindowSnapshotAsyncJPEGCallback =
  54. base::OnceCallback<void(scoped_refptr<base::RefCountedMemory> data)>;
  55. SNAPSHOT_EXPORT void GrabWindowSnapshotAsyncJPEG(
  56. gfx::NativeWindow window,
  57. const gfx::Rect& source_rect,
  58. GrabWindowSnapshotAsyncJPEGCallback callback);
  59. } // namespace ui
  60. #endif // UI_SNAPSHOT_SNAPSHOT_H_