Commit 7eb68f62 authored by Miguel Casas's avatar Miguel Casas Committed by Commit Bot

canvas: clean up start/stop listening for DidProcessTask

Bit of a cleanup accesory to crrev.com/c/1308043: a new pair
of private methods (StartListeningForDidProcessTask() and
StopListeningForDidProcessTask() ) are added. They work together
with the associate renamed flag
s/finalize_frame_scheduled_/listening_for_did_process_task_/
to listen for ProcessTask events (WillProcessTask/DidProcessTask).

This is a cleanup of things in preparation for the next CL
in the chain: crrev.com/c/1308043.

No new functionality intended.

Bug: 839970
Change-Id: I0bad9e3bfc80b02865c34ba4c20d37f71ecb83a9
Reviewed-on: https://chromium-review.googlesource.com/c/1308754Reviewed-by: default avatarFernando Serboncini <fserb@chromium.org>
Commit-Queue: Miguel Casas <mcasas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#604912}
parent 5a3040f9
......@@ -99,8 +99,7 @@ WTF::String CanvasRenderingContext::PixelFormatAsString() const {
}
void CanvasRenderingContext::Dispose() {
if (finalize_frame_scheduled_)
Platform::Current()->CurrentThread()->RemoveTaskObserver(this);
StopListeningForDidProcessTask();
// HTMLCanvasElement and CanvasRenderingContext have a circular reference.
// When the pair is no longer reachable, their destruction order is non-
......@@ -116,25 +115,22 @@ void CanvasRenderingContext::Dispose() {
void CanvasRenderingContext::DidDraw(const SkIRect& dirty_rect) {
Host()->DidDraw(SkRect::Make(dirty_rect));
NeedsFinalizeFrame();
StartListeningForDidProcessTask();
}
void CanvasRenderingContext::DidDraw() {
Host()->DidDraw();
NeedsFinalizeFrame();
StartListeningForDidProcessTask();
}
void CanvasRenderingContext::NeedsFinalizeFrame() {
if (!finalize_frame_scheduled_) {
finalize_frame_scheduled_ = true;
Platform::Current()->CurrentThread()->AddTaskObserver(this);
}
StartListeningForDidProcessTask();
}
void CanvasRenderingContext::DidProcessTask(
const base::PendingTask& pending_task) {
Platform::Current()->CurrentThread()->RemoveTaskObserver(this);
finalize_frame_scheduled_ = false;
const base::PendingTask& /* pending_task */) {
StopListeningForDidProcessTask();
// The end of a script task that drew content to the canvas is the point
// at which the current frame may be considered complete.
if (Host())
......@@ -202,4 +198,20 @@ void CanvasRenderingContext::Trace(blink::Visitor* visitor) {
ScriptWrappable::Trace(visitor);
}
void CanvasRenderingContext::StartListeningForDidProcessTask() {
if (listening_for_did_process_task_)
return;
listening_for_did_process_task_ = true;
Platform::Current()->CurrentThread()->AddTaskObserver(this);
}
void CanvasRenderingContext::StopListeningForDidProcessTask() {
if (!listening_for_did_process_task_)
return;
Platform::Current()->CurrentThread()->RemoveTaskObserver(this);
listening_for_did_process_task_ = false;
}
} // namespace blink
......@@ -207,7 +207,10 @@ class CORE_EXPORT CanvasRenderingContext : public ScriptWrappable,
HashSet<String> dirty_urls_;
CanvasColorParams color_params_;
CanvasContextCreationAttributesCore creation_attributes_;
bool finalize_frame_scheduled_ = false;
void StartListeningForDidProcessTask();
void StopListeningForDidProcessTask();
bool listening_for_did_process_task_ = false;
DISALLOW_COPY_AND_ASSIGN(CanvasRenderingContext);
};
......
......@@ -372,7 +372,7 @@ class MODULES_EXPORT BaseRenderingContext2D : public GarbageCollectedMixin,
mutable UsageCounters usage_counters_;
virtual void NeedsFinalizeFrame(){};
virtual void NeedsFinalizeFrame() {}
float GetFontBaseline(const SimpleFontData&) const;
......
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