task_queue_webview.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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_QUEUE_WEBVIEW_H_
  5. #define ANDROID_WEBVIEW_BROWSER_GFX_TASK_QUEUE_WEBVIEW_H_
  6. #include "base/callback.h"
  7. #include "base/memory/scoped_refptr.h"
  8. #include "base/task/single_thread_task_runner.h"
  9. namespace android_webview {
  10. // In WebView, there is a single task queue that runs all tasks instead of
  11. // thread task runners. This is the class actually scheduling and running tasks
  12. // for WebView. This is used by both CommandBuffer and SkiaDDL.
  13. class TaskQueueWebView {
  14. public:
  15. // Static method that makes sure this is only one copy of this class.
  16. static TaskQueueWebView* GetInstance();
  17. // Methods only used when kVizForWebView is enabled, ie client is the viz
  18. // thread.
  19. virtual void InitializeVizThread(
  20. const scoped_refptr<base::SingleThreadTaskRunner>& viz_task_runner) = 0;
  21. // The calling OnceClosure unblocks the render thread, and disallows further
  22. // calls to ScheduleTask.
  23. using VizTask = base::OnceCallback<void(base::OnceClosure)>;
  24. virtual void ScheduleOnVizAndBlock(VizTask viz_task) = 0;
  25. // Called by TaskForwardingSequence. |out_of_order| indicates if task should
  26. // be run ahead of already enqueued tasks.
  27. virtual void ScheduleTask(base::OnceClosure task, bool out_of_order) = 0;
  28. // Called by TaskForwardingSequence.
  29. virtual void ScheduleOrRetainTask(base::OnceClosure task) = 0;
  30. // Called by DeferredGpuCommandService to schedule delayed tasks.
  31. // This should not be called when kVizForWebView is enabled.
  32. virtual void ScheduleIdleTask(base::OnceClosure task) = 0;
  33. // Called by both DeferredGpuCommandService and
  34. // SkiaOutputSurfaceDisplayContext to post task to client thread.
  35. void ScheduleClientTask(base::OnceClosure task) {
  36. GetClientTaskRunner()->PostTask(FROM_HERE, std::move(task));
  37. }
  38. virtual scoped_refptr<base::TaskRunner> GetClientTaskRunner() = 0;
  39. protected:
  40. virtual ~TaskQueueWebView() = default;
  41. };
  42. } // namespace android_webview
  43. #endif // ANDROID_WEBVIEW_BROWSER_GFX_TASK_QUEUE_WEBVIEW_H_