Title: [252792] trunk/Source/WebCore
- Revision
- 252792
- Author
- [email protected]
- Date
- 2019-11-22 12:29:25 -0800 (Fri, 22 Nov 2019)
Log Message
Web Inspector: Canvas: adjust `InspectorCanvasAgent::recordCanvasAction` to actually check that the `CanvasRenderingContext` still exists
https://bugs.webkit.org/show_bug.cgi?id=204395
<rdar://problem/57347504>
Reviewed by Ryosuke Niwa.
The microtask we create to handle marking the end of a frame for a detached canvas doesn't
actually check that the `CanvasRenderingContext` still exists, such as if it gets GCd during
a recording.
Instead of creating a microtask per-canvas, create a microtask per-`InspectorCanvasAgent`
and save a list of `canvasId` that are actively recording, which can then be iterated to
handle marking the end of a frame for each once the microtask fires. If the `canvasId` can't
be re-found, then the related `CanvasRenderingContext` must have been removed.
* inspector/agents/InspectorCanvasAgent.cpp:
(WebCore::InspectorCanvasAgent::recordCanvasAction):
(WebCore::InspectorCanvasAgent::didFinishRecordingCanvasFrame):
(WebCore::InspectorCanvasAgent::reset):
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (252791 => 252792)
--- trunk/Source/WebCore/ChangeLog 2019-11-22 20:06:19 UTC (rev 252791)
+++ trunk/Source/WebCore/ChangeLog 2019-11-22 20:29:25 UTC (rev 252792)
@@ -1,3 +1,25 @@
+2019-11-22 Devin Rousso <[email protected]>
+
+ Web Inspector: Canvas: adjust `InspectorCanvasAgent::recordCanvasAction` to actually check that the `CanvasRenderingContext` still exists
+ https://bugs.webkit.org/show_bug.cgi?id=204395
+ <rdar://problem/57347504>
+
+ Reviewed by Ryosuke Niwa.
+
+ The microtask we create to handle marking the end of a frame for a detached canvas doesn't
+ actually check that the `CanvasRenderingContext` still exists, such as if it gets GCd during
+ a recording.
+
+ Instead of creating a microtask per-canvas, create a microtask per-`InspectorCanvasAgent`
+ and save a list of `canvasId` that are actively recording, which can then be iterated to
+ handle marking the end of a frame for each once the microtask fires. If the `canvasId` can't
+ be re-found, then the related `CanvasRenderingContext` must have been removed.
+
+ * inspector/agents/InspectorCanvasAgent.cpp:
+ (WebCore::InspectorCanvasAgent::recordCanvasAction):
+ (WebCore::InspectorCanvasAgent::didFinishRecordingCanvasFrame):
+ (WebCore::InspectorCanvasAgent::reset):
+
2019-11-22 Sihui Liu <[email protected]>
IndexedDB: lock-based implementation of suspension
Modified: trunk/Source/WebCore/inspector/agents/InspectorCanvasAgent.cpp (252791 => 252792)
--- trunk/Source/WebCore/inspector/agents/InspectorCanvasAgent.cpp 2019-11-22 20:06:19 UTC (rev 252791)
+++ trunk/Source/WebCore/inspector/agents/InspectorCanvasAgent.cpp 2019-11-22 20:29:25 UTC (rev 252792)
@@ -26,7 +26,6 @@
#include "config.h"
#include "InspectorCanvasAgent.h"
-#include "ActiveDOMCallbackMicrotask.h"
#include "CanvasRenderingContext.h"
#include "CanvasRenderingContext2D.h"
#include "Document.h"
@@ -40,7 +39,6 @@
#include "InspectorShaderProgram.h"
#include "InstrumentingAgents.h"
#include "JSExecState.h"
-#include "Microtasks.h"
#include "ScriptState.h"
#include "StringAdaptors.h"
#include <_javascript_Core/IdentifiersFactory.h>
@@ -450,24 +448,35 @@
if (!canvasRenderingContext.callTracingActive())
return;
- // Only enqueue a microtask for the first action of each frame. Any subsequent actions will be
- // covered by the initial microtask until the next frame.
- if (!inspectorCanvas->currentFrameHasData()) {
+ // Only enqueue one microtask for all actively recording canvases.
+ if (m_recordingCanvasIdentifiers.isEmpty()) {
if (auto* scriptExecutionContext = inspectorCanvas->scriptExecutionContext()) {
- auto& eventLoop = scriptExecutionContext->eventLoop();
- auto microtask = makeUnique<ActiveDOMCallbackMicrotask>(eventLoop.microtaskQueue(), *scriptExecutionContext, [&, protectedInspectorCanvas = inspectorCanvas.copyRef()] {
- if (auto* canvasElement = protectedInspectorCanvas->canvasElement()) {
- if (canvasElement->isDescendantOf(canvasElement->document()))
- return;
+ scriptExecutionContext->eventLoop().queueMicrotask([weakThis = makeWeakPtr(*this)] {
+ if (!weakThis)
+ return;
+
+ auto& canvasAgent = *weakThis;
+
+ for (auto& identifier : canvasAgent.m_recordingCanvasIdentifiers) {
+ auto inspectorCanvas = canvasAgent.m_identifierToInspectorCanvas.get(identifier);
+ if (!inspectorCanvas)
+ continue;
+
+ auto* canvasRenderingContext = inspectorCanvas->canvasContext();
+ ASSERT(canvasRenderingContext);
+ // FIXME: <https://webkit.org/b/201651> Web Inspector: Canvas: support canvas recordings for WebGPUDevice
+
+ if (canvasRenderingContext->callTracingActive())
+ canvasAgent.didFinishRecordingCanvasFrame(*canvasRenderingContext);
}
- if (canvasRenderingContext.callTracingActive())
- didFinishRecordingCanvasFrame(canvasRenderingContext);
+ canvasAgent.m_recordingCanvasIdentifiers.clear();
});
- eventLoop.queueMicrotaskCallback(WTFMove(microtask));
}
}
+ m_recordingCanvasIdentifiers.add(inspectorCanvas->identifier());
+
inspectorCanvas->recordAction(name, WTFMove(parameters));
if (!inspectorCanvas->hasBufferSpace())
@@ -516,6 +525,7 @@
if (forceDispatch) {
m_frontendDispatcher->recordingFinished(inspectorCanvas->identifier(), nullptr);
inspectorCanvas->resetRecordingData();
+ ASSERT(!m_recordingCanvasIdentifiers.contains(inspectorCanvas->identifier()));
}
return;
}
@@ -531,6 +541,8 @@
return;
m_frontendDispatcher->recordingFinished(inspectorCanvas->identifier(), inspectorCanvas->releaseObjectForRecording());
+
+ m_recordingCanvasIdentifiers.remove(inspectorCanvas->identifier());
}
void InspectorCanvasAgent::consoleStartRecordingCanvas(CanvasRenderingContext& context, JSC::JSGlobalObject& exec, JSC::JSObject* options)
@@ -742,6 +754,8 @@
m_removedProgramIdentifiers.clear();
if (m_programDestroyedTimer.isActive())
m_programDestroyedTimer.stop();
+
+ m_recordingCanvasIdentifiers.clear();
}
InspectorCanvas& InspectorCanvasAgent::bindCanvas(CanvasRenderingContext& context, bool captureBacktrace)
Modified: trunk/Source/WebCore/inspector/agents/InspectorCanvasAgent.h (252791 => 252792)
--- trunk/Source/WebCore/inspector/agents/InspectorCanvasAgent.h 2019-11-22 20:06:19 UTC (rev 252791)
+++ trunk/Source/WebCore/inspector/agents/InspectorCanvasAgent.h 2019-11-22 20:29:25 UTC (rev 252792)
@@ -34,6 +34,7 @@
#include <_javascript_Core/InspectorFrontendDispatchers.h>
#include <initializer_list>
#include <wtf/Forward.h>
+#include <wtf/WeakPtr.h>
namespace Inspector {
class InjectedScriptManager;
@@ -56,7 +57,7 @@
typedef String ErrorString;
-class InspectorCanvasAgent final : public InspectorAgentBase, public Inspector::CanvasBackendDispatcherHandler, public CanvasObserver {
+class InspectorCanvasAgent final : public InspectorAgentBase, public Inspector::CanvasBackendDispatcherHandler, public CanvasObserver, public CanMakeWeakPtr<InspectorCanvasAgent> {
WTF_MAKE_NONCOPYABLE(InspectorCanvasAgent);
WTF_MAKE_FAST_ALLOCATED;
public:
@@ -157,6 +158,8 @@
Vector<String> m_removedProgramIdentifiers;
Timer m_programDestroyedTimer;
+ HashSet<String> m_recordingCanvasIdentifiers;
+
Optional<size_t> m_recordingAutoCaptureFrameCount;
};
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes