root_frame_sink_proxy.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. // Copyright 2019 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 ANDROID_WEBVIEW_BROWSER_GFX_ROOT_FRAME_SINK_PROXY_H_
  5. #define ANDROID_WEBVIEW_BROWSER_GFX_ROOT_FRAME_SINK_PROXY_H_
  6. #include "android_webview/browser/gfx/root_frame_sink.h"
  7. #include "base/memory/raw_ptr.h"
  8. #include "base/task/single_thread_task_runner.h"
  9. #include "base/threading/thread_checker.h"
  10. namespace viz {
  11. struct BeginFrameArgs;
  12. }
  13. namespace android_webview {
  14. class RootFrameSinkProxyClient {
  15. public:
  16. virtual void Invalidate() = 0;
  17. virtual void ReturnResourcesFromViz(
  18. viz::FrameSinkId frame_sink_id,
  19. uint32_t layer_tree_frame_sink_id,
  20. std::vector<viz::ReturnedResource> resources) = 0;
  21. virtual void OnCompositorFrameTransitionDirectiveProcessed(
  22. viz::FrameSinkId frame_sink_id,
  23. uint32_t layer_tree_frame_sink_id,
  24. uint32_t sequence_id) = 0;
  25. };
  26. // Per-AwContents object. Straddles UI and Viz thread. Public methods should be
  27. // called on the UI thread unless otherwise specified. Mostly used for creating
  28. // RootFrameSink and routing calls to it.
  29. class RootFrameSinkProxy : public viz::BeginFrameObserverBase {
  30. public:
  31. RootFrameSinkProxy(
  32. const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner,
  33. RootFrameSinkProxyClient* client,
  34. viz::BeginFrameSource* begin_frame_source);
  35. RootFrameSinkProxy(const RootFrameSinkProxy&) = delete;
  36. RootFrameSinkProxy& operator=(const RootFrameSinkProxy&) = delete;
  37. ~RootFrameSinkProxy() override;
  38. void AddChildFrameSinkId(const viz::FrameSinkId& frame_sink_id);
  39. void RemoveChildFrameSinkId(const viz::FrameSinkId& frame_sink_id);
  40. void OnInputEvent();
  41. // The returned callback can only be called on viz thread.
  42. RootFrameSinkGetter GetRootFrameSinkCallback();
  43. private:
  44. class RootFrameSinkClientImpl;
  45. static scoped_refptr<RootFrameSink> GetRootFrameSinkHelper(
  46. base::WeakPtr<RootFrameSinkProxy> proxy);
  47. void InitializeOnViz();
  48. void DestroyOnViz();
  49. void AddChildFrameSinkIdOnViz(const viz::FrameSinkId& frame_sink_id);
  50. void RemoveChildFrameSinkIdOnViz(const viz::FrameSinkId& frame_sink_id);
  51. void BeginFrameOnViz(const viz::BeginFrameArgs& args,
  52. bool had_input_event,
  53. bool* invalidate);
  54. void SetNeedsBeginFramesOnViz(bool needs_begin_frames);
  55. void SetNeedsBeginFramesOnUI(bool needs_begin_frames);
  56. void SetBeginFrameSourcePausedOnViz(bool paused);
  57. void InvalidateOnViz();
  58. void InvalidateOnUI();
  59. void ReturnResourcesOnViz(viz::FrameSinkId frame_sink_id,
  60. uint32_t layer_tree_frame_sink_id,
  61. std::vector<viz::ReturnedResource> resources);
  62. void OnCompositorFrameTransitionDirectiveProcessedOnViz(
  63. viz::FrameSinkId frame_sink_id,
  64. uint32_t layer_tree_frame_sink_id,
  65. uint32_t sequence_id);
  66. void ReturnResourcesOnUI(viz::FrameSinkId frame_sink_id,
  67. uint32_t layer_tree_frame_sink_id,
  68. std::vector<viz::ReturnedResource> resources);
  69. void OnCompositorFrameTransitionDirectiveProcessedOnUI(
  70. viz::FrameSinkId frame_sink_id,
  71. uint32_t layer_tree_frame_sink_id,
  72. uint32_t sequence_id);
  73. bool BeginFrame(const viz::BeginFrameArgs& args);
  74. bool OnBeginFrameDerivedImpl(const viz::BeginFrameArgs& args) override;
  75. void OnBeginFrameSourcePausedChanged(bool paused) override;
  76. const scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_;
  77. const scoped_refptr<base::SingleThreadTaskRunner> viz_task_runner_;
  78. const raw_ptr<RootFrameSinkProxyClient> client_;
  79. std::unique_ptr<RootFrameSinkClient> root_frame_sink_client_;
  80. scoped_refptr<RootFrameSink> without_gpu_;
  81. const raw_ptr<viz::BeginFrameSource> begin_frame_source_;
  82. bool had_input_event_ = false;
  83. bool observing_bfs_ = false;
  84. THREAD_CHECKER(ui_thread_checker_);
  85. THREAD_CHECKER(viz_thread_checker_);
  86. base::WeakPtrFactory<RootFrameSinkProxy> weak_ptr_factory_{this};
  87. base::WeakPtrFactory<RootFrameSinkProxy> weak_ptr_factory_on_viz_{this};
  88. };
  89. } // namespace android_webview
  90. #endif // ANDROID_WEBVIEW_BROWSER_GFX_ROOT_FRAME_SINK_PROXY_H_