Commit 1d91e2b4 authored by Bo Liu's avatar Bo Liu Committed by Commit Bot

aw: Implement task queue for viz

Make TaskQueueWebView an abstract interface. The old implementation
becomes TaskQueueSingleThread, with some cleanups. Add new TaskQueueViz
which implements code required for viz thread scheduling tasks to render
thread without ability to block on it at any time.

Add a kVizForWebView to switch between the two implementations, and use
to distinguish the code paths in the future.

Nothing uses TaskQueueViz in this CL yet, but the viz prototype has been
rebased onto this and works.

Bug: 805739
Change-Id: I0fe6c935fa7b1536700bd84950397ac756c4209e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1729473
Commit-Queue: Bo <boliu@chromium.org>
Reviewed-by: default avatarEric Karl <ericrk@chromium.org>
Cr-Commit-Position: refs/heads/master@{#683530}
parent dac741fb
...@@ -42,6 +42,10 @@ namespace features { ...@@ -42,6 +42,10 @@ namespace features {
// Alphabetical: // Alphabetical:
// Viz for WebView architecture.
const base::Feature kVizForWebView{"VizForWebView",
base::FEATURE_DISABLED_BY_DEFAULT};
// Enable brotli compression support in WebView. // Enable brotli compression support in WebView.
const base::Feature kWebViewBrotliSupport{"WebViewBrotliSupport", const base::Feature kWebViewBrotliSupport{"WebViewBrotliSupport",
base::FEATURE_DISABLED_BY_DEFAULT}; base::FEATURE_DISABLED_BY_DEFAULT};
......
...@@ -14,6 +14,7 @@ namespace features { ...@@ -14,6 +14,7 @@ namespace features {
// alongside the definition of their values in the .cc file. // alongside the definition of their values in the .cc file.
// Alphabetical: // Alphabetical:
extern const base::Feature kVizForWebView;
extern const base::Feature kWebViewBrotliSupport; extern const base::Feature kWebViewBrotliSupport;
extern const base::Feature kWebViewConnectionlessSafeBrowsing; extern const base::Feature kWebViewConnectionlessSafeBrowsing;
extern const base::Feature kWebViewSniffMimeType; extern const base::Feature kWebViewSniffMimeType;
......
...@@ -3,6 +3,7 @@ include_rules = [ ...@@ -3,6 +3,7 @@ include_rules = [
"-android_webview/browser", "-android_webview/browser",
"+android_webview/browser/gfx", "+android_webview/browser/gfx",
"+android_webview/native_jni", "+android_webview/native_jni",
"+android_webview/browser/aw_feature_list.h",
"+android_webview/common/aw_switches.h", "+android_webview/common/aw_switches.h",
"+android_webview/public/browser", "+android_webview/public/browser",
] ]
......
...@@ -50,7 +50,12 @@ void TaskForwardingSequence::ScheduleTask( ...@@ -50,7 +50,12 @@ void TaskForwardingSequence::ScheduleTask(
void TaskForwardingSequence::ScheduleOrRetainTask( void TaskForwardingSequence::ScheduleOrRetainTask(
base::OnceClosure task, base::OnceClosure task,
std::vector<gpu::SyncToken> sync_token_fences) { std::vector<gpu::SyncToken> sync_token_fences) {
ScheduleTask(std::move(task), std::move(sync_token_fences)); uint32_t order_num = sync_point_order_data_->GenerateUnprocessedOrderNumber();
// Use a weak ptr because the task executor holds the tasks, and the
// sequence will be destroyed before the task executor.
task_queue_->ScheduleOrRetainTask(base::BindOnce(
&TaskForwardingSequence::RunTask, weak_ptr_factory_.GetWeakPtr(),
std::move(task), std::move(sync_token_fences), order_num));
} }
// Should not be called because tasks aren't reposted to wait for sync tokens, // Should not be called because tasks aren't reposted to wait for sync tokens,
......
...@@ -5,17 +5,10 @@ ...@@ -5,17 +5,10 @@
#ifndef ANDROID_WEBVIEW_BROWSER_GFX_TASK_QUEUE_WEB_VIEW_H_ #ifndef ANDROID_WEBVIEW_BROWSER_GFX_TASK_QUEUE_WEB_VIEW_H_
#define ANDROID_WEBVIEW_BROWSER_GFX_TASK_QUEUE_WEB_VIEW_H_ #define ANDROID_WEBVIEW_BROWSER_GFX_TASK_QUEUE_WEB_VIEW_H_
#include <stddef.h> #include "base/callback.h"
#include <memory>
#include <utility>
#include "base/containers/queue.h"
#include "base/lazy_instance.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/threading/thread_checker.h" #include "base/memory/scoped_refptr.h"
#include "base/threading/thread_local.h" #include "base/single_thread_task_runner.h"
#include "base/time/time.h"
namespace android_webview { namespace android_webview {
...@@ -25,12 +18,7 @@ class ScopedAllowGL { ...@@ -25,12 +18,7 @@ class ScopedAllowGL {
ScopedAllowGL(); ScopedAllowGL();
~ScopedAllowGL(); ~ScopedAllowGL();
static bool IsAllowed();
private: private:
static base::LazyInstance<base::ThreadLocalBoolean>::DestructorAtExit
allow_gl;
DISALLOW_COPY_AND_ASSIGN(ScopedAllowGL); DISALLOW_COPY_AND_ASSIGN(ScopedAllowGL);
}; };
...@@ -41,40 +29,38 @@ class TaskQueueWebView { ...@@ -41,40 +29,38 @@ class TaskQueueWebView {
public: public:
// Static method that makes sure this is only one copy of this class. // Static method that makes sure this is only one copy of this class.
static TaskQueueWebView* GetInstance(); static TaskQueueWebView* GetInstance();
~TaskQueueWebView();
// Methods only used when kVizForWebView is enabled, ie client is the viz
// thread.
virtual void InitializeVizThread(
const scoped_refptr<base::SingleThreadTaskRunner>& viz_task_runner) = 0;
// The calling OnceClosure unblocks the render thread, and disallows further
// calls to ScheduleTask.
using VizTask = base::OnceCallback<void(base::OnceClosure)>;
virtual void ScheduleOnVizAndBlock(VizTask viz_task) = 0;
// Called by TaskForwardingSequence. |out_of_order| indicates if task should // Called by TaskForwardingSequence. |out_of_order| indicates if task should
// be run ahead of already enqueued tasks. // be run ahead of already enqueued tasks.
void ScheduleTask(base::OnceClosure task, bool out_of_order); virtual void ScheduleTask(base::OnceClosure task, bool out_of_order) = 0;
// Called by TaskForwardingSequence.
virtual void ScheduleOrRetainTask(base::OnceClosure task) = 0;
// Called by DeferredGpuCommandService to schedule delayed tasks. // Called by DeferredGpuCommandService to schedule delayed tasks.
void ScheduleIdleTask(base::OnceClosure task); // This should not be called when kVizForWebView is enabled.
virtual void ScheduleIdleTask(base::OnceClosure task) = 0;
// Called by both DeferredGpuCommandService and // Called by both DeferredGpuCommandService and
// SkiaOutputSurfaceDisplayContext to post task to client thread. // SkiaOutputSurfaceDisplayContext to post task to client thread.
void ScheduleClientTask(base::OnceClosure task); virtual void ScheduleClientTask(base::OnceClosure task) = 0;
// Called by ScopedAllowGL and ScheduleTask().
void RunAllTasks();
void RunTasks();
private:
static TaskQueueWebView* CreateTaskQueueWebView();
TaskQueueWebView();
// Flush the idle queue until it is empty.
void PerformAllIdleWork();
// All access to task queue should happen on a single thread. protected:
THREAD_CHECKER(task_queue_thread_checker_); friend ScopedAllowGL;
base::circular_deque<base::OnceClosure> tasks_;
base::queue<std::pair<base::Time, base::OnceClosure>> idle_tasks_;
base::queue<base::OnceClosure> client_tasks_;
bool inside_run_tasks_ = false; virtual ~TaskQueueWebView() = default;
bool inside_run_idle_tasks_ = false;
DISALLOW_COPY_AND_ASSIGN(TaskQueueWebView); // Called by ScopedAllowGL.
virtual void RunAllTasks() = 0;
}; };
} // namespace android_webview } // namespace android_webview
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment