1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173
|
/*
* Copyright (C) 2017 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#pragma once
#include "CanvasBase.h"
#include "CanvasObserver.h"
#include "InspectorCanvas.h"
#include "InspectorCanvasCallTracer.h"
#include "InspectorWebAgentBase.h"
#include "Timer.h"
#include <JavaScriptCore/InspectorBackendDispatchers.h>
#include <JavaScriptCore/InspectorFrontendDispatchers.h>
#include <initializer_list>
#include <wtf/CheckedPtr.h>
#include <wtf/Forward.h>
#include <wtf/RobinHoodHashMap.h>
#include <wtf/RobinHoodHashSet.h>
#include <wtf/TZoneMalloc.h>
#include <wtf/WeakPtr.h>
#include <wtf/text/WTFString.h>
namespace Inspector {
class InjectedScriptManager;
}
namespace WebCore {
class CanvasRenderingContext;
class ScriptExecutionContext;
#if ENABLE(WEBGL)
class InspectorShaderProgram;
class WebGLProgram;
class WebGLRenderingContextBase;
#endif // ENABLE(WEBGL)
class InspectorCanvasAgent : public InspectorAgentBase, public Inspector::CanvasBackendDispatcherHandler, public CanvasObserver, public CanMakeCheckedPtr<InspectorCanvasAgent> {
WTF_MAKE_NONCOPYABLE(InspectorCanvasAgent);
WTF_MAKE_TZONE_ALLOCATED(InspectorCanvasAgent);
WTF_OVERRIDE_DELETE_FOR_CHECKED_PTR(InspectorCanvasAgent);
public:
~InspectorCanvasAgent();
// InspectorAgentBase
void didCreateFrontendAndBackend(Inspector::FrontendRouter*, Inspector::BackendDispatcher*);
void willDestroyFrontendAndBackend(Inspector::DisconnectReason);
void discardAgent();
virtual bool enabled() const;
// CanvasBackendDispatcherHandler
Inspector::Protocol::ErrorStringOr<void> enable();
Inspector::Protocol::ErrorStringOr<void> disable();
Inspector::Protocol::ErrorStringOr<String> requestContent(const Inspector::Protocol::Canvas::CanvasId&);
Inspector::Protocol::ErrorStringOr<Ref<Inspector::Protocol::Runtime::RemoteObject>> resolveContext(const Inspector::Protocol::Canvas::CanvasId&, const String& objectGroup);
Inspector::Protocol::ErrorStringOr<void> setRecordingAutoCaptureFrameCount(int);
Inspector::Protocol::ErrorStringOr<void> startRecording(const Inspector::Protocol::Canvas::CanvasId&, std::optional<int>&& frameCount, std::optional<int>&& memoryLimit);
Inspector::Protocol::ErrorStringOr<void> stopRecording(const Inspector::Protocol::Canvas::CanvasId&);
#if ENABLE(WEBGL)
Inspector::Protocol::ErrorStringOr<String> requestShaderSource(const Inspector::Protocol::Canvas::ProgramId&, Inspector::Protocol::Canvas::ShaderType);
Inspector::Protocol::ErrorStringOr<void> updateShader(const Inspector::Protocol::Canvas::ProgramId&, Inspector::Protocol::Canvas::ShaderType, const String& source);
Inspector::Protocol::ErrorStringOr<void> setShaderProgramDisabled(const Inspector::Protocol::Canvas::ProgramId&, bool disabled);
Inspector::Protocol::ErrorStringOr<void> setShaderProgramHighlighted(const Inspector::Protocol::Canvas::ProgramId&, bool highlighted);
#endif // ENABLE(WEBGL)
// CanvasObserver
void canvasChanged(CanvasBase&, const FloatRect&) final;
void canvasResized(CanvasBase&) final { }
void canvasDestroyed(CanvasBase&) final;
// InspectorInstrumentation
void didCreateCanvasRenderingContext(CanvasRenderingContext&);
void didChangeCanvasSize(CanvasRenderingContext&);
void didChangeCanvasMemory(CanvasRenderingContext&);
void didFinishRecordingCanvasFrame(CanvasRenderingContext&, bool forceDispatch = false);
void consoleStartRecordingCanvas(CanvasRenderingContext&, JSC::JSGlobalObject&, JSC::JSObject* options);
void consoleStopRecordingCanvas(CanvasRenderingContext&);
#if ENABLE(WEBGL)
void didEnableExtension(WebGLRenderingContextBase&, const String&);
void didCreateWebGLProgram(WebGLRenderingContextBase&, WebGLProgram&);
void willDestroyWebGLProgram(WebGLProgram&);
bool isWebGLProgramDisabled(WebGLProgram&);
bool isWebGLProgramHighlighted(WebGLProgram&);
#endif // ENABLE(WEBGL)
// InspectorCanvasCallTracer
#define PROCESS_ARGUMENT_DECLARATION(ArgumentType) \
std::optional<InspectorCanvasCallTracer::ProcessedArgument> processArgument(CanvasRenderingContext&, ArgumentType); \
// end of PROCESS_ARGUMENT_DECLARATION
FOR_EACH_INSPECTOR_CANVAS_CALL_TRACER_ARGUMENT(PROCESS_ARGUMENT_DECLARATION)
#undef PROCESS_ARGUMENT_DECLARATION
void recordAction(CanvasRenderingContext&, String&&, InspectorCanvasCallTracer::ProcessedArguments&& = { });
protected:
InspectorCanvasAgent(WebAgentContext&);
virtual void internalEnable();
virtual void internalDisable();
void reset();
void unbindCanvas(InspectorCanvas&);
RefPtr<InspectorCanvas> assertInspectorCanvas(Inspector::Protocol::ErrorString&, const String& canvasId);
RefPtr<InspectorCanvas> findInspectorCanvas(CanvasRenderingContext&);
virtual bool matchesCurrentContext(ScriptExecutionContext*) const = 0;
std::unique_ptr<Inspector::CanvasFrontendDispatcher> m_frontendDispatcher;
MemoryCompactRobinHoodHashMap<String, RefPtr<InspectorCanvas>> m_identifierToInspectorCanvas;
private:
struct RecordingOptions {
std::optional<long> frameCount;
std::optional<long> memoryLimit;
std::optional<String> name;
};
void startRecording(InspectorCanvas&, Inspector::Protocol::Recording::Initiator, RecordingOptions&& = { });
void canvasDestroyedTimerFired();
#if ENABLE(WEBGL)
void programDestroyedTimerFired();
#endif // ENABLE(WEBGL)
InspectorCanvas& bindCanvas(CanvasRenderingContext&, bool captureBacktrace);
#if ENABLE(WEBGL)
void unbindProgram(InspectorShaderProgram&);
RefPtr<InspectorShaderProgram> assertInspectorProgram(Inspector::Protocol::ErrorString&, const String& programId);
RefPtr<InspectorShaderProgram> findInspectorProgram(WebGLProgram&);
#endif // ENABLE(WEBGL)
RefPtr<Inspector::CanvasBackendDispatcher> m_backendDispatcher;
Inspector::InjectedScriptManager& m_injectedScriptManager;
Vector<String> m_removedCanvasIdentifiers;
Timer m_canvasDestroyedTimer;
#if ENABLE(WEBGL)
MemoryCompactRobinHoodHashMap<String, RefPtr<InspectorShaderProgram>> m_identifierToInspectorProgram;
Vector<String> m_removedProgramIdentifiers;
Timer m_programDestroyedTimer;
#endif // ENABLE(WEBGL)
MemoryCompactRobinHoodHashSet<String> m_recordingCanvasIdentifiers;
std::optional<size_t> m_recordingAutoCaptureFrameCount;
};
} // namespace WebCore
|