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 { ...@@ -99,8 +99,7 @@ WTF::String CanvasRenderingContext::PixelFormatAsString() const {
} }
void CanvasRenderingContext::Dispose() { void CanvasRenderingContext::Dispose() {
if (finalize_frame_scheduled_) StopListeningForDidProcessTask();
Platform::Current()->CurrentThread()->RemoveTaskObserver(this);
// HTMLCanvasElement and CanvasRenderingContext have a circular reference. // HTMLCanvasElement and CanvasRenderingContext have a circular reference.
// When the pair is no longer reachable, their destruction order is non- // When the pair is no longer reachable, their destruction order is non-
...@@ -116,25 +115,22 @@ void CanvasRenderingContext::Dispose() { ...@@ -116,25 +115,22 @@ void CanvasRenderingContext::Dispose() {
void CanvasRenderingContext::DidDraw(const SkIRect& dirty_rect) { void CanvasRenderingContext::DidDraw(const SkIRect& dirty_rect) {
Host()->DidDraw(SkRect::Make(dirty_rect)); Host()->DidDraw(SkRect::Make(dirty_rect));
NeedsFinalizeFrame(); StartListeningForDidProcessTask();
} }
void CanvasRenderingContext::DidDraw() { void CanvasRenderingContext::DidDraw() {
Host()->DidDraw(); Host()->DidDraw();
NeedsFinalizeFrame(); StartListeningForDidProcessTask();
} }
void CanvasRenderingContext::NeedsFinalizeFrame() { void CanvasRenderingContext::NeedsFinalizeFrame() {
if (!finalize_frame_scheduled_) { StartListeningForDidProcessTask();
finalize_frame_scheduled_ = true;
Platform::Current()->CurrentThread()->AddTaskObserver(this);
}
} }
void CanvasRenderingContext::DidProcessTask( void CanvasRenderingContext::DidProcessTask(
const base::PendingTask& pending_task) { const base::PendingTask& /* pending_task */) {
Platform::Current()->CurrentThread()->RemoveTaskObserver(this); StopListeningForDidProcessTask();
finalize_frame_scheduled_ = false;
// The end of a script task that drew content to the canvas is the point // The end of a script task that drew content to the canvas is the point
// at which the current frame may be considered complete. // at which the current frame may be considered complete.
if (Host()) if (Host())
...@@ -202,4 +198,20 @@ void CanvasRenderingContext::Trace(blink::Visitor* visitor) { ...@@ -202,4 +198,20 @@ void CanvasRenderingContext::Trace(blink::Visitor* visitor) {
ScriptWrappable::Trace(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 } // namespace blink
...@@ -207,7 +207,10 @@ class CORE_EXPORT CanvasRenderingContext : public ScriptWrappable, ...@@ -207,7 +207,10 @@ class CORE_EXPORT CanvasRenderingContext : public ScriptWrappable,
HashSet<String> dirty_urls_; HashSet<String> dirty_urls_;
CanvasColorParams color_params_; CanvasColorParams color_params_;
CanvasContextCreationAttributesCore creation_attributes_; CanvasContextCreationAttributesCore creation_attributes_;
bool finalize_frame_scheduled_ = false;
void StartListeningForDidProcessTask();
void StopListeningForDidProcessTask();
bool listening_for_did_process_task_ = false;
DISALLOW_COPY_AND_ASSIGN(CanvasRenderingContext); DISALLOW_COPY_AND_ASSIGN(CanvasRenderingContext);
}; };
......
...@@ -372,7 +372,7 @@ class MODULES_EXPORT BaseRenderingContext2D : public GarbageCollectedMixin, ...@@ -372,7 +372,7 @@ class MODULES_EXPORT BaseRenderingContext2D : public GarbageCollectedMixin,
mutable UsageCounters usage_counters_; mutable UsageCounters usage_counters_;
virtual void NeedsFinalizeFrame(){}; virtual void NeedsFinalizeFrame() {}
float GetFontBaseline(const SimpleFontData&) const; 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