fast_ink_view.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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_VIEW_H_
  5. #define ASH_FAST_INK_FAST_INK_VIEW_H_
  6. #include <memory>
  7. #include <vector>
  8. #include "ash/fast_ink/fast_ink_host.h"
  9. #include "ui/aura/window.h"
  10. #include "ui/gfx/canvas.h"
  11. #include "ui/views/view.h"
  12. #include "ui/views/widget/unique_widget_ptr.h"
  13. namespace gfx {
  14. class GpuMemoryBuffer;
  15. } // namespace gfx
  16. namespace fast_ink {
  17. // FastInkView is a view supporting low-latency rendering by using FastInkHost.
  18. // The view's widget must have the same bounds as a root window (covers the
  19. // entire display). FastInkHost for more details.
  20. class FastInkView : public views::View {
  21. public:
  22. ~FastInkView() override;
  23. FastInkView(const FastInkView&) = delete;
  24. FastInkView& operator=(const FastInkView&) = delete;
  25. // Function to create a container Widget, pass ownership of |fast_ink_view|
  26. // as the contents view to the Widget. fast_ink_view fills the bounds of the
  27. // root_window.
  28. static views::UniqueWidgetPtr CreateWidgetWithContents(
  29. std::unique_ptr<FastInkView> fast_ink_view,
  30. aura::Window* container);
  31. // Update content and damage rectangles for surface. See
  32. // FastInkHost::UpdateSurface for more detials.
  33. void UpdateSurface(const gfx::Rect& content_rect,
  34. const gfx::Rect& damage_rect,
  35. bool auto_refresh);
  36. virtual FastInkHost::PresentationCallback GetPresentationCallback();
  37. protected:
  38. // Helper class that provides flicker free painting to a GPU memory buffer.
  39. class ScopedPaint {
  40. public:
  41. ScopedPaint(FastInkView* view, const gfx::Rect& damage_rect_in_window);
  42. ScopedPaint(const ScopedPaint&) = delete;
  43. ScopedPaint& operator=(const ScopedPaint&) = delete;
  44. ~ScopedPaint();
  45. gfx::Canvas& canvas() { return canvas_; }
  46. private:
  47. gfx::GpuMemoryBuffer* const gpu_memory_buffer_;
  48. // Damage rect in the buffer coordinates.
  49. const gfx::Rect damage_rect_;
  50. gfx::Canvas canvas_;
  51. };
  52. FastInkView();
  53. void SetFastInkHost(std::unique_ptr<FastInkHost> host);
  54. FastInkHost* host() { return host_.get(); }
  55. private:
  56. std::unique_ptr<FastInkHost> host_;
  57. };
  58. } // namespace fast_ink
  59. #endif // ASH_FAST_INK_FAST_INK_VIEW_H_