Commit 49215b9c authored by Fernando Serboncini's avatar Fernando Serboncini Committed by Commit Bot

Push frame on RAF for OffscreenCanvas

Only request a dispatcher's begin frame if the current frame hasn't
been uploaded by AnimationFrameProvider

Bug: 995235
Change-Id: I2c6d590d9eed535f4723a65721b3b81dd3f0d449
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1827741
Commit-Queue: Fernando Serboncini <fserb@chromium.org>
Reviewed-by: default avatarKhushal <khushalsagar@chromium.org>
Cr-Commit-Position: refs/heads/master@{#701132}
parent 47289305
......@@ -41,16 +41,18 @@ void WorkerAnimationFrameProvider::BeginFrame(
TRACE_EVENT0("blink", "WorkerAnimationFrameProvider::BeginFrame");
double time = (frame_time - base::TimeTicks()).InMillisecondsF();
Microtask::EnqueueMicrotask(WTF::Bind(
[](base::WeakPtr<WorkerAnimationFrameProvider> provider, double time) {
if (!provider)
return;
TRACE_EVENT0("blink",
"WorkerAnimationFrameProvider::RequestAnimationFrame");
provider->callback_collection_.ExecuteFrameCallbacks(time, time);
OffscreenCanvas::ScopedInsideWorkerRAF inside_raf_scope;
for (auto& offscreen_canvas : provider->offscreen_canvases_) {
offscreen_canvas->PushFrameIfNeeded();
inside_raf_scope.AddOffscreenCanvas(offscreen_canvas);
}
provider->callback_collection_.ExecuteFrameCallbacks(time, time);
},
weak_factory_.GetWeakPtr(), time));
}
......
......@@ -404,8 +404,7 @@ void OffscreenCanvas::DidDraw(const FloatRect& rect) {
if (HasPlaceholderCanvas()) {
needs_push_frame_ = true;
// TODO(fserb): perhaps we could avoid requesting begin frames here in cases
// where the draw is call from within a worker rAF?
if (!inside_worker_raf_)
GetOrCreateResourceDispatcher()->SetNeedsBeginFrame(true);
}
}
......@@ -423,13 +422,6 @@ bool OffscreenCanvas::PushFrameIfNeeded() {
return false;
}
bool OffscreenCanvas::ShouldAccelerate2dContext() const {
base::WeakPtr<WebGraphicsContext3DProviderWrapper> context_provider_wrapper =
SharedGpuContext::ContextProviderWrapper();
return context_provider_wrapper &&
context_provider_wrapper->Utils()->Accelerated2DCanvasFeatureEnabled();
}
bool OffscreenCanvas::PushFrame(scoped_refptr<CanvasResource> canvas_resource,
const SkIRect& damage_rect) {
TRACE_EVENT0("blink", "OffscreenCanvas::PushFrame");
......@@ -447,6 +439,13 @@ bool OffscreenCanvas::PushFrame(scoped_refptr<CanvasResource> canvas_resource,
return true;
}
bool OffscreenCanvas::ShouldAccelerate2dContext() const {
base::WeakPtr<WebGraphicsContext3DProviderWrapper> context_provider_wrapper =
SharedGpuContext::ContextProviderWrapper();
return context_provider_wrapper &&
context_provider_wrapper->Utils()->Accelerated2DCanvasFeatureEnabled();
}
FontSelector* OffscreenCanvas::GetFontSelector() {
if (auto* document = DynamicTo<Document>(GetExecutionContext())) {
return document->GetStyleEngine().GetFontSelector();
......
......@@ -179,6 +179,30 @@ class CORE_EXPORT OffscreenCanvas final
void Trace(blink::Visitor*) override;
class ScopedInsideWorkerRAF {
STACK_ALLOCATED();
public:
ScopedInsideWorkerRAF() {}
void AddOffscreenCanvas(OffscreenCanvas* canvas) {
DCHECK(!canvas->inside_worker_raf_);
canvas->inside_worker_raf_ = true;
canvases_.push_back(canvas);
}
~ScopedInsideWorkerRAF() {
for (auto canvas : canvases_) {
DCHECK(canvas->inside_worker_raf_);
canvas->inside_worker_raf_ = false;
canvas->PushFrameIfNeeded();
}
}
private:
HeapVector<Member<OffscreenCanvas>> canvases_;
};
private:
int32_t memory_usage_ = 0;
......@@ -195,7 +219,6 @@ class CORE_EXPORT OffscreenCanvas final
IntSize size_;
bool is_neutered_ = false;
bool origin_clean_ = true;
bool disable_reading_from_canvas_ = false;
......@@ -205,6 +228,7 @@ class CORE_EXPORT OffscreenCanvas final
bool needs_matrix_clip_restore_ = false;
bool needs_push_frame_ = false;
bool inside_worker_raf_ = false;
SkFilterQuality filter_quality_ = kLow_SkFilterQuality;
......
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