fast_ink_host.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. // Copyright 2017 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 ASH_FAST_INK_FAST_INK_HOST_H_
  5. #define ASH_FAST_INK_FAST_INK_HOST_H_
  6. #include <memory>
  7. #include <vector>
  8. #include "base/memory/weak_ptr.h"
  9. #include "components/viz/common/quads/compositor_frame_metadata.h"
  10. #include "components/viz/common/resources/resource_id.h"
  11. #include "ui/gfx/canvas.h"
  12. namespace gfx {
  13. class GpuMemoryBuffer;
  14. struct PresentationFeedback;
  15. } // namespace gfx
  16. namespace fast_ink {
  17. // FastInkHost is used to support low-latency rendering. It supports
  18. // 'auto-refresh' mode which provide minimum latency updates for the
  19. // associated window. 'auto-refresh' mode will take advantage of HW overlays
  20. // when possible and trigger continuous updates.
  21. class FastInkHost {
  22. public:
  23. // Convert the rect in window's coordinate to the buffer's coordinate. If the
  24. // window is rotated, the damaged_rect will also be rotated, for example. The
  25. // size is clamped by |buffer_size| to ensure it does not exceeds the buffer
  26. // size.
  27. static gfx::Rect BufferRectFromWindowRect(
  28. const gfx::Transform& window_to_buffer_transform,
  29. const gfx::Size& buffer_size,
  30. const gfx::Rect& damage_rect);
  31. using PresentationCallback =
  32. base::RepeatingCallback<void(const gfx::PresentationFeedback&)>;
  33. // Creates a FastInkView.
  34. FastInkHost(aura::Window* host_window,
  35. const PresentationCallback& presentation_callback);
  36. ~FastInkHost();
  37. FastInkHost(const FastInkHost&) = delete;
  38. FastInkHost& operator=(const FastInkHost&) = delete;
  39. // Update content and damage rectangles for surface. |auto_refresh| should
  40. // be set to true if continuous updates are expected within content rectangle.
  41. void UpdateSurface(const gfx::Rect& content_rect,
  42. const gfx::Rect& damage_rect,
  43. bool auto_refresh);
  44. aura::Window* host_window() { return host_window_; }
  45. const gfx::Transform& window_to_buffer_transform() const {
  46. return window_to_buffer_transform_;
  47. }
  48. gfx::GpuMemoryBuffer* gpu_memory_buffer() { return gpu_memory_buffer_.get(); }
  49. private:
  50. class LayerTreeFrameSinkHolder;
  51. struct Resource;
  52. void SubmitCompositorFrame();
  53. void SubmitPendingCompositorFrame();
  54. void ReclaimResource(std::unique_ptr<Resource> resource);
  55. void DidReceiveCompositorFrameAck();
  56. void DidPresentCompositorFrame(const gfx::PresentationFeedback& feedback);
  57. aura::Window* host_window_;
  58. const PresentationCallback presentation_callback_;
  59. gfx::Transform window_to_buffer_transform_;
  60. std::unique_ptr<gfx::GpuMemoryBuffer> gpu_memory_buffer_;
  61. // The size of |gpu_memory_buffer_|.
  62. gfx::Size buffer_size_;
  63. // The bounds of the content to be pushed in window coordinates.
  64. gfx::Rect content_rect_;
  65. // The damage rect in window coordinates.
  66. gfx::Rect damage_rect_;
  67. // When true it keeps pushing entire buffer with hw overlay option.
  68. bool auto_refresh_ = false;
  69. bool pending_compositor_frame_ = false;
  70. bool pending_compositor_frame_ack_ = false;
  71. viz::ResourceIdGenerator id_generator_;
  72. // Cached resources that can be reused.
  73. std::vector<std::unique_ptr<Resource>> returned_resources_;
  74. std::unique_ptr<LayerTreeFrameSinkHolder> frame_sink_holder_;
  75. base::WeakPtrFactory<FastInkHost> weak_ptr_factory_{this};
  76. };
  77. } // namespace fast_ink
  78. #endif // ASH_FAST_INK_FAST_INK_HOST_H_