Diff
Modified: trunk/Source/WebCore/ChangeLog (242593 => 242594)
--- trunk/Source/WebCore/ChangeLog 2019-03-07 08:06:36 UTC (rev 242593)
+++ trunk/Source/WebCore/ChangeLog 2019-03-07 08:41:25 UTC (rev 242594)
@@ -1,3 +1,49 @@
+2019-03-07 Devin Rousso <[email protected]>
+
+ Web Inspector: Canvas: lazily create the agent
+ https://bugs.webkit.org/show_bug.cgi?id=195241
+
+ Reviewed by Joseph Pecoraro.
+
+ No functionality change.
+
+ * html/canvas/CanvasRenderingContext.h:
+ * html/canvas/CanvasRenderingContext.cpp:
+ (WebCore::CanvasRenderingContext::instances): Added.
+ (WebCore::CanvasRenderingContext::instancesMutex): Added.
+ (WebCore::CanvasRenderingContext::CanvasRenderingContext):
+ (WebCore::CanvasRenderingContext::~CanvasRenderingContext):
+
+ * html/canvas/WebGLProgram.h:
+ * html/canvas/WebGLProgram.cpp:
+ (WebCore::WebGLProgram::instances): Added.
+ (WebCore::WebGLProgram::instancesMutex): Added.
+ (WebCore::WebGLProgram::WebGLProgram):
+ (WebCore::WebGLProgram::~WebGLProgram):
+ * html/canvas/WebGLRenderingContextBase.cpp:
+ (WebCore::WebGLRenderingContextBase::~WebGLRenderingContextBase):
+
+ * inspector/InspectorController.cpp:
+ (WebCore::InspectorController::InspectorController):
+ (WebCore::InspectorController::createLazyAgents):
+
+ * inspector/agents/InspectorCanvasAgent.h:
+ * inspector/agents/InspectorCanvasAgent.cpp:
+ (WebCore::InspectorCanvasAgent::enable):
+ (WebCore::InspectorCanvasAgent::disable):
+ (WebCore::InspectorCanvasAgent::frameNavigated):
+ (WebCore::InspectorCanvasAgent::didCreateCanvasRenderingContext):
+ (WebCore::InspectorCanvasAgent::canvasDestroyed):
+ (WebCore::InspectorCanvasAgent::didCreateProgram):
+ (WebCore::InspectorCanvasAgent::willDeleteProgram):
+ (WebCore::InspectorCanvasAgent::bindCanvas): Added.
+ (WebCore::InspectorCanvasAgent::canvasDestroyedTimerFired):
+
+ * inspector/InspectorInstrumentation.h:
+ (WebCore::InspectorInstrumentation::didCreateCanvasRenderingContext):
+ (WebCore::InspectorInstrumentation::didCreateProgram):
+ (WebCore::InspectorInstrumentation::willDeleteProgram):
+
2019-03-06 Ross Kirsling <[email protected]>
[Win] Remove -DUCHAR_TYPE=wchar_t stopgap and learn to live with char16_t.
Modified: trunk/Source/WebCore/html/canvas/CanvasRenderingContext.cpp (242593 => 242594)
--- trunk/Source/WebCore/html/canvas/CanvasRenderingContext.cpp 2019-03-07 08:06:36 UTC (rev 242593)
+++ trunk/Source/WebCore/html/canvas/CanvasRenderingContext.cpp 2019-03-07 08:41:25 UTC (rev 242594)
@@ -34,16 +34,44 @@
#include "Image.h"
#include "ImageBitmap.h"
#include "OffscreenCanvas.h"
+#include "SecurityOrigin.h"
+#include <wtf/HashSet.h>
+#include <wtf/Lock.h>
+#include <wtf/NeverDestroyed.h>
#include <wtf/URL.h>
-#include "SecurityOrigin.h"
namespace WebCore {
+HashSet<CanvasRenderingContext*>& CanvasRenderingContext::instances(const LockHolder&)
+{
+ static NeverDestroyed<HashSet<CanvasRenderingContext*>> instances;
+ return instances;
+}
+
+Lock& CanvasRenderingContext::instancesMutex()
+{
+ static LazyNeverDestroyed<Lock> mutex;
+ static std::once_flag initializeMutex;
+ std::call_once(initializeMutex, [] {
+ mutex.construct();
+ });
+ return mutex.get();
+}
+
CanvasRenderingContext::CanvasRenderingContext(CanvasBase& canvas)
: m_canvas(canvas)
{
+ LockHolder lock(instancesMutex());
+ instances(lock).add(this);
}
+CanvasRenderingContext::~CanvasRenderingContext()
+{
+ LockHolder lock(instancesMutex());
+ ASSERT(instances(lock).contains(this));
+ instances(lock).remove(this);
+}
+
void CanvasRenderingContext::ref()
{
m_canvas.refCanvasBase();
Modified: trunk/Source/WebCore/html/canvas/CanvasRenderingContext.h (242593 => 242594)
--- trunk/Source/WebCore/html/canvas/CanvasRenderingContext.h 2019-03-07 08:06:36 UTC (rev 242593)
+++ trunk/Source/WebCore/html/canvas/CanvasRenderingContext.h 2019-03-07 08:41:25 UTC (rev 242594)
@@ -28,6 +28,7 @@
#include "CanvasBase.h"
#include "GraphicsLayer.h"
#include "ScriptWrappable.h"
+#include <wtf/Forward.h>
#include <wtf/Noncopyable.h>
#include <wtf/text/StringHash.h>
@@ -44,8 +45,11 @@
class CanvasRenderingContext : public ScriptWrappable {
WTF_MAKE_NONCOPYABLE(CanvasRenderingContext); WTF_MAKE_FAST_ALLOCATED;
public:
- virtual ~CanvasRenderingContext() = default;
+ virtual ~CanvasRenderingContext();
+ static HashSet<CanvasRenderingContext*>& instances(const LockHolder&);
+ static Lock& instancesMutex();
+
void ref();
WEBCORE_EXPORT void deref();
Modified: trunk/Source/WebCore/html/canvas/WebGLProgram.cpp (242593 => 242594)
--- trunk/Source/WebCore/html/canvas/WebGLProgram.cpp 2019-03-07 08:06:36 UTC (rev 242593)
+++ trunk/Source/WebCore/html/canvas/WebGLProgram.cpp 2019-03-07 08:41:25 UTC (rev 242594)
@@ -31,9 +31,28 @@
#include "WebGLContextGroup.h"
#include "WebGLRenderingContextBase.h"
#include "WebGLShader.h"
+#include <wtf/HashMap.h>
+#include <wtf/Lock.h>
+#include <wtf/NeverDestroyed.h>
namespace WebCore {
+HashMap<WebGLProgram*, WebGLRenderingContextBase*>& WebGLProgram::instances(const LockHolder&)
+{
+ static NeverDestroyed<HashMap<WebGLProgram*, WebGLRenderingContextBase*>> instances;
+ return instances;
+}
+
+Lock& WebGLProgram::instancesMutex()
+{
+ static LazyNeverDestroyed<Lock> mutex;
+ static std::once_flag initializeMutex;
+ std::call_once(initializeMutex, [] {
+ mutex.construct();
+ });
+ return mutex.get();
+}
+
Ref<WebGLProgram> WebGLProgram::create(WebGLRenderingContextBase& ctx)
{
return adoptRef(*new WebGLProgram(ctx));
@@ -42,6 +61,11 @@
WebGLProgram::WebGLProgram(WebGLRenderingContextBase& ctx)
: WebGLSharedObject(ctx)
{
+ {
+ LockHolder lock(instancesMutex());
+ instances(lock).add(this, &ctx);
+ }
+
setObject(ctx.graphicsContext3D()->createProgram());
}
@@ -48,6 +72,12 @@
WebGLProgram::~WebGLProgram()
{
deleteObject(0);
+
+ {
+ LockHolder lock(instancesMutex());
+ ASSERT(instances(lock).contains(this));
+ instances(lock).remove(this);
+ }
}
void WebGLProgram::deleteObjectImpl(GraphicsContext3D* context3d, Platform3DObject obj)
Modified: trunk/Source/WebCore/html/canvas/WebGLProgram.h (242593 => 242594)
--- trunk/Source/WebCore/html/canvas/WebGLProgram.h 2019-03-07 08:06:36 UTC (rev 242593)
+++ trunk/Source/WebCore/html/canvas/WebGLProgram.h 2019-03-07 08:41:25 UTC (rev 242594)
@@ -26,6 +26,7 @@
#pragma once
#include "WebGLSharedObject.h"
+#include <wtf/Forward.h>
namespace WebCore {
@@ -36,6 +37,9 @@
static Ref<WebGLProgram> create(WebGLRenderingContextBase&);
virtual ~WebGLProgram();
+ static HashMap<WebGLProgram*, WebGLRenderingContextBase*>& instances(const LockHolder&);
+ static Lock& instancesMutex();
+
unsigned numActiveAttribLocations();
GC3Dint getActiveAttribLocation(GC3Duint index);
Modified: trunk/Source/WebCore/html/canvas/WebGLRenderingContextBase.cpp (242593 => 242594)
--- trunk/Source/WebCore/html/canvas/WebGLRenderingContextBase.cpp 2019-03-07 08:06:36 UTC (rev 242593)
+++ trunk/Source/WebCore/html/canvas/WebGLRenderingContextBase.cpp 2019-03-07 08:41:25 UTC (rev 242594)
@@ -98,7 +98,9 @@
#include <_javascript_Core/TypedArrayInlines.h>
#include <_javascript_Core/Uint32Array.h>
#include <wtf/CheckedArithmetic.h>
+#include <wtf/HashMap.h>
#include <wtf/HexNumber.h>
+#include <wtf/Lock.h>
#include <wtf/StdLibExtras.h>
#include <wtf/UniqueArray.h>
#include <wtf/text/CString.h>
@@ -891,6 +893,17 @@
destroyGraphicsContext3D();
m_contextGroup->removeContext(*this);
}
+
+ {
+ LockHolder lock(WebGLProgram::instancesMutex());
+ for (auto& entry : WebGLProgram::instances(lock)) {
+ if (entry.value == this) {
+ // Don't remove any WebGLProgram from the instances list, as they may still exist.
+ // Only remove the association with a WebGL context.
+ entry.value = nullptr;
+ }
+ }
+ }
}
void WebGLRenderingContextBase::destroyGraphicsContext3D()
Modified: trunk/Source/WebCore/inspector/InspectorController.cpp (242593 => 242594)
--- trunk/Source/WebCore/inspector/InspectorController.cpp 2019-03-07 08:06:36 UTC (rev 242593)
+++ trunk/Source/WebCore/inspector/InspectorController.cpp 2019-03-07 08:41:25 UTC (rev 242594)
@@ -146,10 +146,6 @@
m_agents.append(std::make_unique<InspectorTimelineAgent>(pageContext, scriptProfilerAgent, heapAgent, pageAgent));
- auto canvasAgentPtr = std::make_unique<InspectorCanvasAgent>(pageContext);
- m_instrumentingAgents->setInspectorCanvasAgent(canvasAgentPtr.get());
- m_agents.append(WTFMove(canvasAgentPtr));
-
ASSERT(m_injectedScriptManager->commandLineAPIHost());
if (CommandLineAPIHost* commandLineAPIHost = m_injectedScriptManager->commandLineAPIHost())
commandLineAPIHost->init(m_inspectorAgent, consoleAgent, m_domAgent, domStorageAgent, databaseAgent);
@@ -210,6 +206,7 @@
m_agents.append(std::make_unique<InspectorMemoryAgent>(pageContext));
#endif
m_agents.append(std::make_unique<PageAuditAgent>(pageContext));
+ m_agents.append(std::make_unique<InspectorCanvasAgent>(pageContext));
}
void InspectorController::inspectedPageDestroyed()
Modified: trunk/Source/WebCore/inspector/InspectorInstrumentation.h (242593 => 242594)
--- trunk/Source/WebCore/inspector/InspectorInstrumentation.h 2019-03-07 08:06:36 UTC (rev 242593)
+++ trunk/Source/WebCore/inspector/InspectorInstrumentation.h 2019-03-07 08:41:25 UTC (rev 242594)
@@ -1272,6 +1272,7 @@
inline void InspectorInstrumentation::didCreateCanvasRenderingContext(CanvasRenderingContext& context)
{
+ FAST_RETURN_IF_NO_FRONTENDS(void());
if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForContext(context.canvasBase().scriptExecutionContext()))
didCreateCanvasRenderingContextImpl(*instrumentingAgents, context);
}
@@ -1307,6 +1308,7 @@
inline void InspectorInstrumentation::didCreateProgram(WebGLRenderingContextBase& contextWebGLBase, WebGLProgram& program)
{
+ FAST_RETURN_IF_NO_FRONTENDS(void());
if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForContext(contextWebGLBase.canvasBase().scriptExecutionContext()))
didCreateProgramImpl(*instrumentingAgents, contextWebGLBase, program);
}
@@ -1313,6 +1315,7 @@
inline void InspectorInstrumentation::willDeleteProgram(WebGLRenderingContextBase& contextWebGLBase, WebGLProgram& program)
{
+ FAST_RETURN_IF_NO_FRONTENDS(void());
if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForContext(contextWebGLBase.canvasBase().scriptExecutionContext()))
willDeleteProgramImpl(*instrumentingAgents, program);
}
Modified: trunk/Source/WebCore/inspector/agents/InspectorCanvasAgent.cpp (242593 => 242594)
--- trunk/Source/WebCore/inspector/agents/InspectorCanvasAgent.cpp 2019-03-07 08:06:36 UTC (rev 242593)
+++ trunk/Source/WebCore/inspector/agents/InspectorCanvasAgent.cpp 2019-03-07 08:41:25 UTC (rev 242594)
@@ -31,8 +31,8 @@
#include "Document.h"
#include "Element.h"
#include "Frame.h"
+#include "HTMLCanvasElement.h"
#include "ImageBitmapRenderingContext.h"
-#include "InspectorDOMAgent.h"
#include "InstrumentingAgents.h"
#include "JSCanvasRenderingContext2D.h"
#include "JSExecState.h"
@@ -45,6 +45,8 @@
#include <_javascript_Core/InjectedScriptManager.h>
#include <_javascript_Core/InspectorProtocolObjects.h>
#include <_javascript_Core/JSCInlines.h>
+#include <wtf/HashSet.h>
+#include <wtf/Lock.h>
#if ENABLE(WEBGL)
#include "JSWebGLRenderingContext.h"
@@ -92,34 +94,43 @@
void InspectorCanvasAgent::enable(ErrorString&)
{
- if (m_enabled)
+ if (m_instrumentingAgents.inspectorCanvasAgent() == this)
return;
- m_recordingAutoCaptureFrameCount = WTF::nullopt;
+ m_instrumentingAgents.setInspectorCanvasAgent(this);
- m_enabled = true;
+ const auto canvasExistsInCurrentPage = [&] (CanvasRenderingContext* canvasRenderingContext) {
+ if (!canvasRenderingContext)
+ return false;
- const bool captureBacktrace = false;
- for (auto& inspectorCanvas : m_identifierToInspectorCanvas.values()) {
- m_frontendDispatcher->canvasAdded(inspectorCanvas->buildObjectForCanvas(captureBacktrace));
+ auto* scriptExecutionContext = canvasRenderingContext->canvasBase().scriptExecutionContext();
+ if (!is<Document>(scriptExecutionContext))
+ return false;
-#if ENABLE(WEBGL)
- if (is<WebGLRenderingContextBase>(inspectorCanvas->context())) {
- WebGLRenderingContextBase& contextWebGL = downcast<WebGLRenderingContextBase>(inspectorCanvas->context());
- if (Optional<Vector<String>> extensions = contextWebGL.getSupportedExtensions()) {
- for (const String& extension : *extensions) {
- if (contextWebGL.extensionIsEnabled(extension))
- m_frontendDispatcher->extensionEnabled(inspectorCanvas->identifier(), extension);
- }
- }
+ if (auto* inspectorPageAgent = m_instrumentingAgents.inspectorPageAgent()) {
+ // FIXME: <https://webkit.org/b/168475> Web Inspector: Correctly display iframe's WebSockets
+ auto* document = downcast<Document>(scriptExecutionContext);
+ return document->page() == &inspectorPageAgent->page();
}
-#endif
+
+ return false;
+ };
+
+ {
+ LockHolder lock(CanvasRenderingContext::instancesMutex());
+ for (auto* canvasRenderingContext : CanvasRenderingContext::instances(lock)) {
+ if (canvasExistsInCurrentPage(canvasRenderingContext))
+ bindCanvas(*canvasRenderingContext, false);
+ }
}
#if ENABLE(WEBGL)
- for (auto& inspectorProgram : m_identifierToInspectorProgram.values()) {
- auto& inspectorCanvas = inspectorProgram->canvas();
- m_frontendDispatcher->programCreated(inspectorCanvas.identifier(), inspectorProgram->identifier());
+ {
+ LockHolder lock(WebGLProgram::instancesMutex());
+ for (auto& entry : WebGLProgram::instances(lock)) {
+ if (canvasExistsInCurrentPage(entry.value))
+ didCreateProgram(*entry.value, *entry.key);
+ }
}
#endif
}
@@ -126,23 +137,22 @@
void InspectorCanvasAgent::disable(ErrorString&)
{
- if (!m_enabled)
- return;
+ m_instrumentingAgents.setInspectorCanvasAgent(nullptr);
+#if ENABLE(WEBGL)
+ m_identifierToInspectorProgram.clear();
+#endif
+
+ m_identifierToInspectorCanvas.clear();
+ m_removedCanvasIdentifiers.clear();
+
if (m_canvasDestroyedTimer.isActive())
m_canvasDestroyedTimer.stop();
- m_removedCanvasIdentifiers.clear();
-
if (m_canvasRecordingTimer.isActive())
m_canvasRecordingTimer.stop();
- for (auto& inspectorCanvas : m_identifierToInspectorCanvas.values())
- inspectorCanvas->resetRecordingData();
-
m_recordingAutoCaptureFrameCount = WTF::nullopt;
-
- m_enabled = false;
}
void InspectorCanvasAgent::requestNode(ErrorString& errorString, const String& canvasId, int* nodeId)
@@ -408,8 +418,7 @@
inspectorCanvas->context().canvasBase().removeObserver(*this);
String identifier = unbindCanvas(*inspectorCanvas);
- if (m_enabled)
- m_frontendDispatcher->canvasRemoved(identifier);
+ m_frontendDispatcher->canvasRemoved(identifier);
}
}
@@ -436,21 +445,12 @@
return;
}
- context.canvasBase().addObserver(*this);
+ auto& inspectorCanvas = bindCanvas(context, true);
- auto inspectorCanvas = InspectorCanvas::create(context);
- m_identifierToInspectorCanvas.set(inspectorCanvas->identifier(), inspectorCanvas.copyRef());
-
- if (!m_enabled)
- return;
-
- const bool captureBacktrace = true;
- m_frontendDispatcher->canvasAdded(inspectorCanvas->buildObjectForCanvas(captureBacktrace));
-
if (m_recordingAutoCaptureFrameCount) {
RecordingOptions recordingOptions;
recordingOptions.frameCount = m_recordingAutoCaptureFrameCount.value();
- startRecording(inspectorCanvas.get(), Inspector::Protocol::Recording::Initiator::AutoCapture, WTFMove(recordingOptions));
+ startRecording(inspectorCanvas, Inspector::Protocol::Recording::Initiator::AutoCapture, WTFMove(recordingOptions));
}
}
@@ -490,18 +490,14 @@
void InspectorCanvasAgent::canvasDestroyed(CanvasBase& canvasBase)
{
auto* context = canvasBase.renderingContext();
- ASSERT(context);
if (!context)
return;
auto* inspectorCanvas = findInspectorCanvas(*context);
- ASSERT(inspectorCanvas);
if (!inspectorCanvas)
return;
String identifier = unbindCanvas(*inspectorCanvas);
- if (!m_enabled)
- return;
// WebCore::CanvasObserver::canvasDestroyed is called in response to the GC destroying the CanvasBase.
// Due to the single-process model used in WebKit1, the event must be dispatched from a timer to prevent
@@ -615,9 +611,7 @@
auto inspectorProgram = InspectorShaderProgram::create(program, *inspectorCanvas);
String programIdentifier = inspectorProgram->identifier();
m_identifierToInspectorProgram.set(programIdentifier, WTFMove(inspectorProgram));
-
- if (m_enabled)
- m_frontendDispatcher->programCreated(inspectorCanvas->identifier(), programIdentifier);
+ m_frontendDispatcher->programCreated(inspectorCanvas->identifier(), programIdentifier);
}
void InspectorCanvasAgent::willDeleteProgram(WebGLProgram& program)
@@ -627,8 +621,7 @@
return;
String identifier = unbindProgram(*inspectorProgram);
- if (m_enabled)
- m_frontendDispatcher->programDeleted(identifier);
+ m_frontendDispatcher->programDeleted(identifier);
}
bool InspectorCanvasAgent::isShaderProgramDisabled(WebGLProgram& program)
@@ -681,10 +674,8 @@
if (!m_removedCanvasIdentifiers.size())
return;
- if (m_enabled) {
- for (auto& identifier : m_removedCanvasIdentifiers)
- m_frontendDispatcher->canvasRemoved(identifier);
- }
+ for (auto& identifier : m_removedCanvasIdentifiers)
+ m_frontendDispatcher->canvasRemoved(identifier);
m_removedCanvasIdentifiers.clear();
}
@@ -717,6 +708,30 @@
m_canvasDestroyedTimer.stop();
}
+InspectorCanvas& InspectorCanvasAgent::bindCanvas(CanvasRenderingContext& context, bool captureBacktrace)
+{
+ context.canvasBase().addObserver(*this);
+
+ auto inspectorCanvas = InspectorCanvas::create(context);
+ m_identifierToInspectorCanvas.set(inspectorCanvas->identifier(), inspectorCanvas.copyRef());
+
+ m_frontendDispatcher->canvasAdded(inspectorCanvas->buildObjectForCanvas(captureBacktrace));
+
+#if ENABLE(WEBGL)
+ if (is<WebGLRenderingContextBase>(inspectorCanvas->context())) {
+ WebGLRenderingContextBase& contextWebGL = downcast<WebGLRenderingContextBase>(inspectorCanvas->context());
+ if (Optional<Vector<String>> extensions = contextWebGL.getSupportedExtensions()) {
+ for (const String& extension : *extensions) {
+ if (contextWebGL.extensionIsEnabled(extension))
+ m_frontendDispatcher->extensionEnabled(inspectorCanvas->identifier(), extension);
+ }
+ }
+ }
+#endif
+
+ return inspectorCanvas;
+}
+
String InspectorCanvasAgent::unbindCanvas(InspectorCanvas& inspectorCanvas)
{
#if ENABLE(WEBGL)
Modified: trunk/Source/WebCore/inspector/agents/InspectorCanvasAgent.h (242593 => 242594)
--- trunk/Source/WebCore/inspector/agents/InspectorCanvasAgent.h 2019-03-07 08:06:36 UTC (rev 242593)
+++ trunk/Source/WebCore/inspector/agents/InspectorCanvasAgent.h 2019-03-07 08:41:25 UTC (rev 242594)
@@ -114,6 +114,7 @@
void canvasDestroyedTimerFired();
void canvasRecordingTimerFired();
void clearCanvasData();
+ InspectorCanvas& bindCanvas(CanvasRenderingContext&, bool captureBacktrace);
String unbindCanvas(InspectorCanvas&);
InspectorCanvas* assertInspectorCanvas(ErrorString&, const String& identifier);
InspectorCanvas* findInspectorCanvas(CanvasRenderingContext&);
@@ -133,8 +134,6 @@
Timer m_canvasDestroyedTimer;
Timer m_canvasRecordingTimer;
Optional<size_t> m_recordingAutoCaptureFrameCount;
-
- bool m_enabled { false };
};
} // namespace WebCore