task_forwarding_sequence.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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_TASK_FORWARDING_SEQUENCE_H_
  5. #define ANDROID_WEBVIEW_BROWSER_GFX_TASK_FORWARDING_SEQUENCE_H_
  6. #include <stddef.h>
  7. #include <memory>
  8. #include <utility>
  9. #include "base/memory/raw_ptr.h"
  10. #include "gpu/command_buffer/service/single_task_sequence.h"
  11. namespace gpu {
  12. class SyncPointManager;
  13. }
  14. namespace android_webview {
  15. class TaskQueueWebView;
  16. // TaskForwardingSequence provides a SingleTaskSequence implementation that
  17. // satisfies WebView's threading requirements. It encapsulates a
  18. // SyncPointOrderData, and posts tasks to the WebView's global task queue:
  19. // TaskQueueWebView.
  20. class TaskForwardingSequence : public gpu::SingleTaskSequence {
  21. public:
  22. explicit TaskForwardingSequence(TaskQueueWebView* task_queue,
  23. gpu::SyncPointManager* sync_point_manager);
  24. TaskForwardingSequence(const TaskForwardingSequence&) = delete;
  25. TaskForwardingSequence& operator=(const TaskForwardingSequence&) = delete;
  26. ~TaskForwardingSequence() override;
  27. // SingleTaskSequence implementation.
  28. gpu::SequenceId GetSequenceId() override;
  29. // There is only one task queue. ShouldYield always return false.
  30. bool ShouldYield() override;
  31. void ScheduleTask(
  32. base::OnceClosure task,
  33. std::vector<gpu::SyncToken> sync_token_fences,
  34. ReportingCallback report_callback = ReportingCallback()) override;
  35. void ScheduleOrRetainTask(
  36. base::OnceClosure task,
  37. std::vector<gpu::SyncToken> sync_token_fences,
  38. ReportingCallback report_callback = ReportingCallback()) override;
  39. // Should not be called because tasks aren't reposted to wait for sync tokens,
  40. // or for yielding execution since ShouldYield() returns false.
  41. void ContinueTask(base::OnceClosure task) override;
  42. private:
  43. // Method to wrap scheduled task with the order number processing required for
  44. // sync tokens.
  45. static void RunTask(
  46. base::OnceClosure task,
  47. std::vector<gpu::SyncToken> sync_token_fences,
  48. uint32_t order_num,
  49. gpu::SyncPointManager* sync_point_manager,
  50. scoped_refptr<gpu::SyncPointOrderData> sync_point_order_data);
  51. // Raw pointer refer to the global instance.
  52. const raw_ptr<TaskQueueWebView> task_queue_;
  53. const raw_ptr<gpu::SyncPointManager> sync_point_manager_;
  54. scoped_refptr<gpu::SyncPointOrderData> sync_point_order_data_;
  55. };
  56. } // namespace android_webview
  57. #endif // ANDROID_WEBVIEW_BROWSER_GFX_TASK_FORWARDING_SEQUENCE_H_