⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 243383 in webkit


Ignore:
Timestamp:
Mar 22, 2019, 9:54:54 AM (7 years ago)
Author:
Ryan Haddad
Message:

Unreviewed, rolling out r243356.

Causes assertion failures with WebGL layout tests on macOS and
iOS.

Reverted changeset:

"Web Inspector: Safari Canvas Inspector seems to show the
canvas being rendered twice per frame."
https://bugs.webkit.org/show_bug.cgi?id=196082
https://trac.webkit.org/changeset/243356

Location:
trunk
Files:
16 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r243380 r243383  
     12019-03-22  Ryan Haddad  <ryanhaddad@apple.com>
     2
     3        Unreviewed, rolling out r243356.
     4
     5        Causes assertion failures with WebGL layout tests on macOS and
     6        iOS.
     7
     8        Reverted changeset:
     9
     10        "Web Inspector: Safari Canvas Inspector seems to show the
     11        canvas being rendered twice per frame."
     12        https://bugs.webkit.org/show_bug.cgi?id=196082
     13        https://trac.webkit.org/changeset/243356
     14
    1152019-03-22  Antti Koivisto  <antti@apple.com>
    216
  • trunk/LayoutTests/inspector/canvas/recording-2d.html

    r243356 r243383  
    4040    bitmap = await createImageBitmap(image);
    4141
     42    document.body.appendChild(canvas);
     43
    4244    ctx.save();
    4345    cancelActions();
     
    5254}
    5355
    54 let requestAnimationFrameId = NaN;
     56let timeoutID = NaN;
    5557let saveCount = 1;
    5658
     
    6062    ctx.restore(); // Ensures the state is reset between test cases.
    6163
    62     cancelAnimationFrame(requestAnimationFrameId);
    63     requestAnimationFrameId = NaN;
     64    clearTimeout(timeoutID);
     65    timeoutID = NaN;
    6466
    6567    ctx.save(); // Ensures the state is reset between test cases.
     
    398400        frames[index++]();
    399401        if (index < frames.length)
    400             requestAnimationFrameId = requestAnimationFrame(executeFrameFunction);
     402            timeoutID = setTimeout(executeFrameFunction, 0);
    401403    };
    402404    executeFrameFunction();
  • trunk/LayoutTests/inspector/canvas/recording-bitmaprenderer.html

    r243356 r243383  
    2424    ctx = canvas.getContext("bitmaprenderer");
    2525
    26     cancelActions();
     26    document.body.appendChild(canvas);
    2727
    2828    runTest();
     
    3535}
    3636
    37 let requestAnimationFrameId = NaN;
     37let timeoutID = NaN;
    3838
    3939function cancelActions() {
    40     cancelAnimationFrame(requestAnimationFrameId);
    41     requestAnimationFrameId = NaN;
     40    clearTimeout(timeoutID);
     41    timeoutID = NaN;
    4242
    4343    createImageBitmap(transparentImage).then((transparentBitmap) => {
     
    6969        frames[index++]();
    7070        if (index < frames.length)
    71             requestAnimationFrameId = requestAnimationFrame(executeFrameFunction);
     71            timeoutID = setTimeout(executeFrameFunction, 0);
    7272    };
    7373    executeFrameFunction();
  • trunk/LayoutTests/inspector/canvas/recording-html-2d.html

    r243356 r243383  
    4040    imageBitmap = await createImageBitmap(image);
    4141
    42     cancelActions();
     42    document.body.appendChild(canvas);
    4343
    4444    context.strokeStyle = "red";
     
    5757}
    5858
    59 let requestAnimationFrameId = NaN;
    60 
    6159function cancelActions() {
    62     cancelAnimationFrame(requestAnimationFrameId);
    63     requestAnimationFrameId = NaN;
    64 
    65     context.resetTransform();
    66     context.beginPath();
    67     context.clearRect(0, 0, context.canvas.width, context.canvas.height);
    6860}
    6961
     
    10698        frames[index++]();
    10799        if (index < frames.length)
    108             requestAnimationFrameId = requestAnimationFrame(executeFrameFunction);
     100            timeoutID = setTimeout(executeFrameFunction, 0);
    109101    };
    110102    executeFrameFunction();
  • trunk/LayoutTests/inspector/canvas/recording-webgl.html

    r243356 r243383  
    5050    texture = context.createTexture();
    5151
    52     cancelActions();
     52    document.body.appendChild(context.canvas);
    5353
    5454    runTest();
     
    6161}
    6262
    63 let requestAnimationFrameId = NaN;
     63let timeoutID = NaN;
    6464
    6565function cancelActions() {
    66     cancelAnimationFrame(requestAnimationFrameId);
    67     requestAnimationFrameId = NaN;
     66    clearTimeout(timeoutID);
     67    timeoutID = NaN;
    6868
    6969    context.clearColor(0.0, 0.0, 0.0, 0.0);
     
    503503        frames[index++]();
    504504        if (index < frames.length)
    505             requestAnimationFrameId = requestAnimationFrame(executeFrameFunction);
     505            timeoutID = setTimeout(executeFrameFunction, 0);
    506506    };
    507507    executeFrameFunction();
  • trunk/LayoutTests/inspector/canvas/setRecordingAutoCaptureFrameCount.html

    r243356 r243383  
    77    window.internals.settings.setWebGLErrorsToConsoleEnabled(false);
    88
    9 let requestAnimationFrameId = NaN;
     9let timeoutID = NaN;
    1010
    1111function cancelActions() {
    12     cancelAnimationFrame(requestAnimationFrameId);
    13     requestAnimationFrameId = NaN;
     12    clearTimeout(timeoutID);
     13    timeoutID = NaN;
    1414}
    1515
     
    2020
    2121        if (index < frames.length)
    22             requestAnimationFrameId = requestAnimationFrame(executeFrameFunction);
     22            timeoutID = setTimeout(executeFrameFunction, 0);
    2323        else {
    2424            setTimeout(() => {
  • trunk/Source/WebCore/ChangeLog

    r243380 r243383  
     12019-03-22  Ryan Haddad  <ryanhaddad@apple.com>
     2
     3        Unreviewed, rolling out r243356.
     4
     5        Causes assertion failures with WebGL layout tests on macOS and
     6        iOS.
     7
     8        Reverted changeset:
     9
     10        "Web Inspector: Safari Canvas Inspector seems to show the
     11        canvas being rendered twice per frame."
     12        https://bugs.webkit.org/show_bug.cgi?id=196082
     13        https://trac.webkit.org/changeset/243356
     14
    1152019-03-22  Antti Koivisto  <antti@apple.com>
    216
  • trunk/Source/WebCore/html/HTMLCanvasElement.cpp

    r243356 r243383  
    669669void HTMLCanvasElement::paint(GraphicsContext& context, const LayoutRect& r)
    670670{
     671    if (UNLIKELY(m_context && m_context->callTracingActive()))
     672        InspectorInstrumentation::didFinishRecordingCanvasFrame(*m_context);
     673
    671674    // Clear the dirty rect
    672675    m_dirtyRect = FloatRect();
    673676
    674     if (!context.paintingDisabled()) {
    675         bool shouldPaint = true;
    676 
    677         if (m_context) {
    678             shouldPaint = paintsIntoCanvasBuffer() || document().printing();
    679             if (shouldPaint)
    680                 m_context->paintRenderingResultsToCanvas();
     677    if (context.paintingDisabled())
     678        return;
     679   
     680    if (m_context) {
     681        if (!paintsIntoCanvasBuffer() && !document().printing())
     682            return;
     683
     684        m_context->paintRenderingResultsToCanvas();
     685    }
     686
     687    if (hasCreatedImageBuffer()) {
     688        ImageBuffer* imageBuffer = buffer();
     689        if (imageBuffer) {
     690            if (m_presentedImage) {
     691                ImageOrientationDescription orientationDescription;
     692#if ENABLE(CSS_IMAGE_ORIENTATION)
     693                orientationDescription.setImageOrientationEnum(renderer()->style().imageOrientation());
     694#endif
     695                context.drawImage(*m_presentedImage, snappedIntRect(r), ImagePaintingOptions(orientationDescription));
     696            } else
     697                context.drawImageBuffer(*imageBuffer, snappedIntRect(r));
    681698        }
    682 
    683         if (shouldPaint) {
    684             if (hasCreatedImageBuffer()) {
    685                 ImageBuffer* imageBuffer = buffer();
    686                 if (imageBuffer) {
    687                     if (m_presentedImage) {
    688                         ImageOrientationDescription orientationDescription;
    689 #if ENABLE(CSS_IMAGE_ORIENTATION)
    690                         orientationDescription.setImageOrientationEnum(renderer()->style().imageOrientation());
    691 #endif
    692                         context.drawImage(*m_presentedImage, snappedIntRect(r), ImagePaintingOptions(orientationDescription));
    693                     } else
    694                         context.drawImageBuffer(*imageBuffer, snappedIntRect(r));
    695                 }
    696             }
    697 
    698             if (isGPUBased())
    699                 downcast<GPUBasedCanvasRenderingContext>(*m_context).markLayerComposited();
    700         }
    701     }
    702 
    703     if (UNLIKELY(m_context && m_context->callTracingActive()))
    704         InspectorInstrumentation::didFinishRecordingCanvasFrame(*m_context);
     699    }
     700
     701    if (isGPUBased())
     702        downcast<GPUBasedCanvasRenderingContext>(*m_context).markLayerComposited();
    705703}
    706704
  • trunk/Source/WebCore/html/canvas/WebGLRenderingContextBase.cpp

    r243356 r243383  
    662662    m_contextGroup->addContext(*this);
    663663   
    664     m_context->addClient(*this);
     664    m_context->setWebGLContext(this);
    665665
    666666    m_context->getIntegerv(GraphicsContext3D::MAX_VIEWPORT_DIMS, m_maxViewportDims);
     
    915915
    916916    if (m_context) {
    917         m_context->removeClient(*this);
    918917        m_context->setContextLostCallback(nullptr);
    919918        m_context->setErrorMessageCallback(nullptr);
     
    50445043}
    50455044
     5045void WebGLRenderingContextBase::recycleContext()
     5046{
     5047    printToConsole(MessageLevel::Error, "There are too many active WebGL contexts on this page, the oldest context will be lost.");
     5048    // Using SyntheticLostContext means the developer won't be able to force the restoration
     5049    // of the context by calling preventDefault() in a "webglcontextlost" event handler.
     5050    forceLostContext(SyntheticLostContext);
     5051    destroyGraphicsContext3D();
     5052}
     5053
    50465054void WebGLRenderingContextBase::loseContextImpl(WebGLRenderingContextBase::LostContextMode mode)
    50475055{
     
    62186226}
    62196227
     6228void WebGLRenderingContextBase::dispatchContextChangedEvent()
     6229{
     6230    auto* canvas = htmlCanvas();
     6231    if (!canvas)
     6232        return;
     6233
     6234    canvas->dispatchEvent(WebGLContextEvent::create(eventNames().webglcontextchangedEvent, Event::CanBubble::No, Event::IsCancelable::Yes, emptyString()));
     6235}
     6236
    62206237void WebGLRenderingContextBase::simulateContextChanged()
    62216238{
     
    64976514}
    64986515
    6499 void WebGLRenderingContextBase::didComposite()
    6500 {
    6501     if (UNLIKELY(callTracingActive()))
    6502         InspectorInstrumentation::didFinishRecordingCanvasFrame(*this);
    6503 }
    6504 
    6505 void WebGLRenderingContextBase::forceContextLost()
    6506 {
    6507     forceLostContext(WebGLRenderingContextBase::RealLostContext);
    6508 }
    6509 
    6510 void WebGLRenderingContextBase::recycleContext()
    6511 {
    6512     printToConsole(MessageLevel::Error, "There are too many active WebGL contexts on this page, the oldest context will be lost.");
    6513     // Using SyntheticLostContext means the developer won't be able to force the restoration
    6514     // of the context by calling preventDefault() in a "webglcontextlost" event handler.
    6515     forceLostContext(SyntheticLostContext);
    6516     destroyGraphicsContext3D();
    6517 }
    6518 
    6519 void WebGLRenderingContextBase::dispatchContextChangedNotification()
    6520 {
    6521     auto* canvas = htmlCanvas();
    6522     if (!canvas)
    6523         return;
    6524 
    6525     canvas->dispatchEvent(WebGLContextEvent::create(eventNames().webglcontextchangedEvent, Event::CanBubble::No, Event::IsCancelable::Yes, emptyString()));
    6526 }
    6527 
    6528 
    65296516} // namespace WebCore
    65306517
  • trunk/Source/WebCore/html/canvas/WebGLRenderingContextBase.h

    r243356 r243383  
    9595using WebGLCanvas = WTF::Variant<RefPtr<HTMLCanvasElement>, RefPtr<OffscreenCanvas>>;
    9696
    97 class WebGLRenderingContextBase : public GraphicsContext3D::Client, public GPUBasedCanvasRenderingContext, private ActivityStateChangeObserver {
     97class WebGLRenderingContextBase : public GPUBasedCanvasRenderingContext, private ActivityStateChangeObserver {
    9898public:
    9999    static std::unique_ptr<WebGLRenderingContextBase> create(CanvasBase&, WebGLContextAttributes&, const String&);
     
    331331    };
    332332    void forceLostContext(LostContextMode);
     333    void recycleContext();
    333334    void forceRestoreContext();
    334335    void loseContextImpl(LostContextMode);
     336    void dispatchContextChangedEvent();
    335337    WEBCORE_EXPORT void simulateContextChanged();
    336338
     
    357359    // Used for testing only, from Internals.
    358360    WEBCORE_EXPORT void setFailNextGPUStatusCheck();
    359 
    360     // GraphicsContext3D::Client
    361     void didComposite() override;
    362     void forceContextLost() override;
    363     void recycleContext() override;
    364     void dispatchContextChangedNotification() override;
    365361
    366362protected:
  • trunk/Source/WebCore/inspector/InspectorCanvas.cpp

    r243356 r243383  
    9090HTMLCanvasElement* InspectorCanvas::canvasElement()
    9191{
    92     if (is<HTMLCanvasElement>(m_context.canvasBase()))
    93         return &downcast<HTMLCanvasElement>(m_context.canvasBase());
     92    auto* canvasBase = &m_context.canvasBase();
     93    if (is<HTMLCanvasElement>(canvasBase))
     94        return downcast<HTMLCanvasElement>(canvasBase);
    9495    return nullptr;
    9596}
     
    137138{
    138139    if (!m_initialState) {
    139         // We should only construct the initial state for the first action of the recording.
    140         ASSERT(!m_frames && !m_currentActions);
    141 
    142140        m_initialState = buildInitialState();
    143141        m_bufferUsed += m_initialState->memoryCost();
     
    174172}
    175173
     174RefPtr<Inspector::Protocol::Recording::InitialState>&& InspectorCanvas::releaseInitialState()
     175{
     176    return WTFMove(m_initialState);
     177}
     178
     179RefPtr<JSON::ArrayOf<Inspector::Protocol::Recording::Frame>>&& InspectorCanvas::releaseFrames()
     180{
     181    appendActionSnapshotIfNeeded();
     182
     183    return WTFMove(m_frames);
     184}
     185
     186RefPtr<JSON::ArrayOf<JSON::Value>>&& InspectorCanvas::releaseData()
     187{
     188    m_indexedDuplicateData.clear();
     189    return WTFMove(m_serializedDuplicateData);
     190}
     191
    176192void InspectorCanvas::finalizeFrame()
    177193{
    178     appendActionSnapshotIfNeeded();
    179 
    180194    if (m_frames && m_frames->length() && !std::isnan(m_currentFrameStartTime)) {
    181195        auto currentFrame = static_cast<Inspector::Protocol::Recording::Frame*>(m_frames->get(m_frames->length() - 1).get());
     
    298312}
    299313
    300 Ref<Inspector::Protocol::Recording::Recording> InspectorCanvas::releaseObjectForRecording()
    301 {
    302     ASSERT(!m_currentActions);
    303     ASSERT(!m_actionNeedingSnapshot);
    304     ASSERT(!m_frames);
    305 
    306     // FIXME: <https://webkit.org/b/176008> Web Inspector: Record actions performed on WebGL2RenderingContext
    307 
    308     Inspector::Protocol::Recording::Type type;
    309     if (is<CanvasRenderingContext2D>(m_context))
    310         type = Inspector::Protocol::Recording::Type::Canvas2D;
    311     else if (is<ImageBitmapRenderingContext>(m_context))
    312         type = Inspector::Protocol::Recording::Type::CanvasBitmapRenderer;
    313 #if ENABLE(WEBGL)
    314     else if (is<WebGLRenderingContext>(m_context))
    315         type = Inspector::Protocol::Recording::Type::CanvasWebGL;
    316 #endif
    317     else {
    318         ASSERT_NOT_REACHED();
    319         type = Inspector::Protocol::Recording::Type::Canvas2D;
    320     }
    321 
    322     auto recording = Inspector::Protocol::Recording::Recording::create()
    323         .setVersion(Inspector::Protocol::Recording::VERSION)
    324         .setType(type)
    325         .setInitialState(m_initialState.releaseNonNull())
    326         .setData(m_serializedDuplicateData.releaseNonNull())
    327         .release();
    328 
    329     if (!m_recordingName.isEmpty())
    330         recording->setName(m_recordingName);
    331 
    332     resetRecordingData();
    333 
    334     return recording;
    335 }
    336 
    337 String InspectorCanvas::getCanvasContentAsDataURL(ErrorString& errorString)
    338 {
    339     // FIXME: <https://webkit.org/b/173621> Web Inspector: Support getting the content of WebMetal context;
    340     if (!is<CanvasRenderingContext2D>(m_context)
    341 #if ENABLE(WEBGL)
    342         && !is<WebGLRenderingContextBase>(m_context)
    343 #endif
    344         && !is<ImageBitmapRenderingContext>(m_context)) {
    345         errorString = "Unsupported canvas context type"_s;
    346         return emptyString();
    347     }
    348 
     314void InspectorCanvas::appendActionSnapshotIfNeeded()
     315{
     316    if (!m_actionNeedingSnapshot)
     317        return;
     318
     319    m_actionNeedingSnapshot->addItem(indexForData(getCanvasContentAsDataURL()));
     320    m_actionNeedingSnapshot = nullptr;
     321}
     322
     323String InspectorCanvas::getCanvasContentAsDataURL()
     324{
    349325    // FIXME: <https://webkit.org/b/180833> Web Inspector: support OffscreenCanvas for Canvas related operations
     326
    350327    auto* node = canvasElement();
    351     if (!node) {
    352         errorString = "Context isn't related to an HTMLCanvasElement"_s;
    353         return emptyString();
    354     }
     328    if (!node)
     329        return String();
    355330
    356331#if ENABLE(WEBGL)
     
    366341#endif
    367342
    368     if (result.hasException()) {
    369         errorString = result.releaseException().releaseMessage();
    370         return emptyString();
    371     }
     343    if (result.hasException())
     344        return String();
    372345
    373346    return result.releaseReturnValue().string;
    374 }
    375 
    376 void InspectorCanvas::appendActionSnapshotIfNeeded()
    377 {
    378     if (!m_actionNeedingSnapshot)
    379         return;
    380 
    381     m_bufferUsed -= m_actionNeedingSnapshot->memoryCost();
    382 
    383     ErrorString ignored;
    384     m_actionNeedingSnapshot->addItem(indexForData(getCanvasContentAsDataURL(ignored)));
    385 
    386     m_bufferUsed += m_actionNeedingSnapshot->memoryCost();
    387 
    388     m_actionNeedingSnapshot = nullptr;
    389347}
    390348
     
    604562        initialStatePayload->setParameters(WTFMove(parametersPayload));
    605563
    606     ErrorString ignored;
    607     initialStatePayload->setContent(getCanvasContentAsDataURL(ignored));
     564    initialStatePayload->setContent(getCanvasContentAsDataURL());
    608565
    609566    return initialStatePayload;
  • trunk/Source/WebCore/inspector/InspectorCanvas.h

    r243356 r243383  
    4545class ImageData;
    4646
    47 typedef String ErrorString;
    48 
    4947class InspectorCanvas final : public RefCounted<InspectorCanvas> {
    5048public:
     
    6159    void recordAction(const String&, Vector<RecordCanvasActionVariant>&& = { });
    6260
    63     Ref<JSON::ArrayOf<Inspector::Protocol::Recording::Frame>> releaseFrames() { return m_frames.releaseNonNull(); }
     61    RefPtr<Inspector::Protocol::Recording::InitialState>&& releaseInitialState();
     62    RefPtr<JSON::ArrayOf<Inspector::Protocol::Recording::Frame>>&& releaseFrames();
     63    RefPtr<JSON::ArrayOf<JSON::Value>>&& releaseData();
    6464
    6565    void finalizeFrame();
    6666    void markCurrentFrameIncomplete();
    6767
     68    const String& recordingName() const { return m_recordingName; }
    6869    void setRecordingName(const String& name) { m_recordingName = name; }
    6970
     
    7677
    7778    Ref<Inspector::Protocol::Canvas::Canvas> buildObjectForCanvas(bool captureBacktrace);
    78     Ref<Inspector::Protocol::Recording::Recording> releaseObjectForRecording();
    79 
    80     String getCanvasContentAsDataURL(ErrorString&);
    8179
    8280private:
    8381    InspectorCanvas(CanvasRenderingContext&);
    8482    void appendActionSnapshotIfNeeded();
     83    String getCanvasContentAsDataURL();
    8584
    8685    using DuplicateDataVariant = Variant<
  • trunk/Source/WebCore/inspector/agents/InspectorCanvasAgent.cpp

    r243356 r243383  
    2727#include "InspectorCanvasAgent.h"
    2828
    29 #include "ActiveDOMCallbackMicrotask.h"
    3029#include "CanvasRenderingContext.h"
    3130#include "CanvasRenderingContext2D.h"
     
    3938#include "JSExecState.h"
    4039#include "JSImageBitmapRenderingContext.h"
    41 #include "Microtasks.h"
    4240#include "OffscreenCanvas.h"
    4341#include "ScriptState.h"
     
    8179    , m_inspectedPage(context.inspectedPage)
    8280    , m_canvasDestroyedTimer(*this, &InspectorCanvasAgent::canvasDestroyedTimerFired)
     81    , m_canvasRecordingTimer(*this, &InspectorCanvasAgent::canvasRecordingTimerFired)
    8382{
    8483}
     
    149148void InspectorCanvasAgent::requestNode(ErrorString& errorString, const String& canvasId, int* nodeId)
    150149{
    151     auto inspectorCanvas = assertInspectorCanvas(errorString, canvasId);
     150    auto* inspectorCanvas = assertInspectorCanvas(errorString, canvasId);
    152151    if (!inspectorCanvas)
    153152        return;
     
    170169void InspectorCanvasAgent::requestContent(ErrorString& errorString, const String& canvasId, String* content)
    171170{
    172     auto inspectorCanvas = assertInspectorCanvas(errorString, canvasId);
    173     if (!inspectorCanvas)
    174         return;
    175 
    176     *content = inspectorCanvas->getCanvasContentAsDataURL(errorString);
     171    auto* inspectorCanvas = assertInspectorCanvas(errorString, canvasId);
     172    if (!inspectorCanvas)
     173        return;
     174
     175    // FIXME: <https://webkit.org/b/180833> Web Inspector: support OffscreenCanvas for Canvas related operations
     176
     177    if (auto* node = inspectorCanvas->canvasElement()) {
     178        if (is<CanvasRenderingContext2D>(inspectorCanvas->context()) || is<ImageBitmapRenderingContext>(inspectorCanvas->context())) {
     179            auto result = node->toDataURL("image/png"_s);
     180            if (result.hasException()) {
     181                errorString = result.releaseException().releaseMessage();
     182                return;
     183            }
     184            *content = result.releaseReturnValue().string;
     185            return;
     186        }
     187
     188#if ENABLE(WEBGL)
     189        if (is<WebGLRenderingContextBase>(inspectorCanvas->context())) {
     190            WebGLRenderingContextBase& contextWebGLBase = downcast<WebGLRenderingContextBase>(inspectorCanvas->context());
     191
     192            contextWebGLBase.setPreventBufferClearForInspector(true);
     193            auto result = node->toDataURL("image/png"_s);
     194            contextWebGLBase.setPreventBufferClearForInspector(false);
     195
     196            if (result.hasException()) {
     197                errorString = result.releaseException().releaseMessage();
     198                return;
     199            }
     200            *content = result.releaseReturnValue().string;
     201            return;
     202        }
     203#endif
     204    }
     205
     206    // FIXME: <https://webkit.org/b/173621> Web Inspector: Support getting the content of WebMetal context;
     207    errorString = "Unsupported canvas context type"_s;
    177208}
    178209
    179210void InspectorCanvasAgent::requestCSSCanvasClientNodes(ErrorString& errorString, const String& canvasId, RefPtr<JSON::ArrayOf<int>>& result)
    180211{
    181     auto inspectorCanvas = assertInspectorCanvas(errorString, canvasId);
     212    auto* inspectorCanvas = assertInspectorCanvas(errorString, canvasId);
    182213    if (!inspectorCanvas)
    183214        return;
     
    220251void InspectorCanvasAgent::resolveCanvasContext(ErrorString& errorString, const String& canvasId, const String* objectGroup, RefPtr<Inspector::Protocol::Runtime::RemoteObject>& result)
    221252{
    222     auto inspectorCanvas = assertInspectorCanvas(errorString, canvasId);
     253    auto* inspectorCanvas = assertInspectorCanvas(errorString, canvasId);
    223254    if (!inspectorCanvas)
    224255        return;
     
    249280void InspectorCanvasAgent::startRecording(ErrorString& errorString, const String& canvasId, const int* frameCount, const int* memoryLimit)
    250281{
    251     auto inspectorCanvas = assertInspectorCanvas(errorString, canvasId);
     282    auto* inspectorCanvas = assertInspectorCanvas(errorString, canvasId);
    252283    if (!inspectorCanvas)
    253284        return;
     
    268299void InspectorCanvasAgent::stopRecording(ErrorString& errorString, const String& canvasId)
    269300{
    270     auto inspectorCanvas = assertInspectorCanvas(errorString, canvasId);
     301    auto* inspectorCanvas = assertInspectorCanvas(errorString, canvasId);
    271302    if (!inspectorCanvas)
    272303        return;
     
    283314{
    284315#if ENABLE(WEBGL)
    285     auto inspectorProgram = assertInspectorProgram(errorString, programId);
     316    auto* inspectorProgram = assertInspectorProgram(errorString, programId);
    286317    if (!inspectorProgram)
    287318        return;
     
    305336{
    306337#if ENABLE(WEBGL)
    307     auto inspectorProgram = assertInspectorProgram(errorString, programId);
     338    auto* inspectorProgram = assertInspectorProgram(errorString, programId);
    308339    if (!inspectorProgram)
    309340        return;
     
    336367{
    337368#if ENABLE(WEBGL)
    338     auto inspectorProgram = assertInspectorProgram(errorString, programId);
     369    auto* inspectorProgram = assertInspectorProgram(errorString, programId);
    339370    if (!inspectorProgram)
    340371        return;
     
    351382{
    352383#if ENABLE(WEBGL)
    353     auto inspectorProgram = assertInspectorProgram(errorString, programId);
     384    auto* inspectorProgram = assertInspectorProgram(errorString, programId);
    354385    if (!inspectorProgram)
    355386        return;
     
    394425    }
    395426
    396     auto inspectorCanvas = findInspectorCanvas(*context);
     427    auto* inspectorCanvas = findInspectorCanvas(*context);
    397428    ASSERT(inspectorCanvas);
    398429    if (!inspectorCanvas)
     
    420451void InspectorCanvasAgent::didChangeCanvasMemory(CanvasRenderingContext& context)
    421452{
    422     auto inspectorCanvas = findInspectorCanvas(context);
     453    auto* inspectorCanvas = findInspectorCanvas(context);
    423454    ASSERT(inspectorCanvas);
    424455    if (!inspectorCanvas)
     
    433464void InspectorCanvasAgent::recordCanvasAction(CanvasRenderingContext& canvasRenderingContext, const String& name, Vector<RecordCanvasActionVariant>&& parameters)
    434465{
    435     auto inspectorCanvas = findInspectorCanvas(canvasRenderingContext);
     466    auto* inspectorCanvas = findInspectorCanvas(canvasRenderingContext);
    436467    ASSERT(inspectorCanvas);
    437468    if (!inspectorCanvas)
     
    442473        return;
    443474
    444     // Only enqueue a microtask for the first action of each frame. Any subsequent actions will be
    445     // covered by the initial microtask until the next frame.
    446     if (!inspectorCanvas->currentFrameHasData()) {
    447         if (auto* scriptExecutionContext = inspectorCanvas->context().canvasBase().scriptExecutionContext()) {
    448             auto& queue = MicrotaskQueue::mainThreadQueue();
    449             queue.append(std::make_unique<ActiveDOMCallbackMicrotask>(queue, *scriptExecutionContext, [&, protectedInspectorCanvas = inspectorCanvas.copyRef()] {
    450                 if (auto* canvasElement = protectedInspectorCanvas->canvasElement()) {
    451                     if (canvasElement->isDescendantOf(canvasElement->document()))
    452                         return;
    453                 }
    454 
    455                 if (protectedInspectorCanvas->context().callTracingActive())
    456                     didFinishRecordingCanvasFrame(protectedInspectorCanvas->context());
    457             }));
    458         }
    459     }
    460 
    461475    inspectorCanvas->recordAction(name, WTFMove(parameters));
     476
     477    if (!m_canvasRecordingTimer.isActive())
     478        m_canvasRecordingTimer.startOneShot(0_s);
    462479
    463480    if (!inspectorCanvas->hasBufferSpace())
     
    471488        return;
    472489
    473     auto inspectorCanvas = findInspectorCanvas(*context);
    474     ASSERT(inspectorCanvas);
     490    auto* inspectorCanvas = findInspectorCanvas(*context);
    475491    if (!inspectorCanvas)
    476492        return;
     
    489505void InspectorCanvasAgent::didFinishRecordingCanvasFrame(CanvasRenderingContext& context, bool forceDispatch)
    490506{
    491     auto inspectorCanvas = findInspectorCanvas(context);
     507    auto* inspectorCanvas = findInspectorCanvas(context);
    492508    ASSERT(inspectorCanvas);
    493509    if (!inspectorCanvas)
     
    500516        if (forceDispatch) {
    501517            m_frontendDispatcher->recordingFinished(inspectorCanvas->identifier(), nullptr);
     518
    502519            inspectorCanvas->resetRecordingData();
    503520        }
     
    515532        return;
    516533
    517     m_frontendDispatcher->recordingFinished(inspectorCanvas->identifier(), inspectorCanvas->releaseObjectForRecording());
     534    // FIXME: <https://webkit.org/b/176008> Web Inspector: Record actions performed on WebGL2RenderingContext
     535
     536    Inspector::Protocol::Recording::Type type;
     537    if (is<CanvasRenderingContext2D>(inspectorCanvas->context()))
     538        type = Inspector::Protocol::Recording::Type::Canvas2D;
     539    else if (is<ImageBitmapRenderingContext>(inspectorCanvas->context()))
     540        type = Inspector::Protocol::Recording::Type::CanvasBitmapRenderer;
     541#if ENABLE(WEBGL)
     542    else if (is<WebGLRenderingContext>(inspectorCanvas->context()))
     543        type = Inspector::Protocol::Recording::Type::CanvasWebGL;
     544#endif
     545    else {
     546        ASSERT_NOT_REACHED();
     547        type = Inspector::Protocol::Recording::Type::Canvas2D;
     548    }
     549
     550    auto recording = Inspector::Protocol::Recording::Recording::create()
     551        .setVersion(Inspector::Protocol::Recording::VERSION)
     552        .setType(type)
     553        .setInitialState(inspectorCanvas->releaseInitialState())
     554        .setData(inspectorCanvas->releaseData())
     555        .release();
     556
     557    const String& name = inspectorCanvas->recordingName();
     558    if (!name.isEmpty())
     559        recording->setName(name);
     560
     561    m_frontendDispatcher->recordingFinished(inspectorCanvas->identifier(), WTFMove(recording));
     562
     563    inspectorCanvas->resetRecordingData();
    518564}
    519565
    520566void InspectorCanvasAgent::consoleStartRecordingCanvas(CanvasRenderingContext& context, JSC::ExecState& exec, JSC::JSObject* options)
    521567{
    522     auto inspectorCanvas = findInspectorCanvas(context);
     568    auto* inspectorCanvas = findInspectorCanvas(context);
    523569    ASSERT(inspectorCanvas);
    524570    if (!inspectorCanvas)
     
    542588void InspectorCanvasAgent::didEnableExtension(WebGLRenderingContextBase& context, const String& extension)
    543589{
    544     auto inspectorCanvas = findInspectorCanvas(context);
     590    auto* inspectorCanvas = findInspectorCanvas(context);
    545591    ASSERT(inspectorCanvas);
    546592    if (!inspectorCanvas)
     
    552598void InspectorCanvasAgent::didCreateProgram(WebGLRenderingContextBase& context, WebGLProgram& program)
    553599{
    554     auto inspectorCanvas = findInspectorCanvas(context);
     600    auto* inspectorCanvas = findInspectorCanvas(context);
    555601    ASSERT(inspectorCanvas);
    556602    if (!inspectorCanvas)
     
    565611void InspectorCanvasAgent::willDeleteProgram(WebGLProgram& program)
    566612{
    567     auto inspectorProgram = findInspectorProgram(program);
     613    auto* inspectorProgram = findInspectorProgram(program);
    568614    if (!inspectorProgram)
    569615        return;
     
    575621bool InspectorCanvasAgent::isShaderProgramDisabled(WebGLProgram& program)
    576622{
    577     auto inspectorProgram = findInspectorProgram(program);
    578     ASSERT(inspectorProgram);
     623    auto* inspectorProgram = findInspectorProgram(program);
    579624    if (!inspectorProgram)
    580625        return false;
     
    585630bool InspectorCanvasAgent::isShaderProgramHighlighted(WebGLProgram& program)
    586631{
    587     auto inspectorProgram = findInspectorProgram(program);
    588     ASSERT(inspectorProgram);
     632    auto* inspectorProgram = findInspectorProgram(program);
    589633    if (!inspectorProgram)
    590634        return false;
     
    631675}
    632676
     677void InspectorCanvasAgent::canvasRecordingTimerFired()
     678{
     679    for (auto& inspectorCanvas : m_identifierToInspectorCanvas.values()) {
     680        if (!inspectorCanvas->context().callTracingActive())
     681            continue;
     682
     683        didFinishRecordingCanvasFrame(inspectorCanvas->context());
     684    }
     685}
     686
    633687void InspectorCanvasAgent::clearCanvasData()
    634688{
     
    637691
    638692    m_identifierToInspectorCanvas.clear();
     693    m_removedCanvasIdentifiers.clear();
    639694#if ENABLE(WEBGL)
    640695    m_identifierToInspectorProgram.clear();
    641     m_removedCanvasIdentifiers.clear();
    642 #endif
     696#endif
     697
     698    if (m_canvasRecordingTimer.isActive())
     699        m_canvasRecordingTimer.stop();
    643700
    644701    if (m_canvasDestroyedTimer.isActive())
     
    689746}
    690747
    691 RefPtr<InspectorCanvas> InspectorCanvasAgent::assertInspectorCanvas(ErrorString& errorString, const String& identifier)
    692 {
    693     auto inspectorCanvas = m_identifierToInspectorCanvas.get(identifier);
     748InspectorCanvas* InspectorCanvasAgent::assertInspectorCanvas(ErrorString& errorString, const String& identifier)
     749{
     750    RefPtr<InspectorCanvas> inspectorCanvas = m_identifierToInspectorCanvas.get(identifier);
    694751    if (!inspectorCanvas) {
    695752        errorString = "No canvas for given identifier."_s;
     
    697754    }
    698755
    699     return inspectorCanvas;
    700 }
    701 
    702 RefPtr<InspectorCanvas> InspectorCanvasAgent::findInspectorCanvas(CanvasRenderingContext& context)
     756    return inspectorCanvas.get();
     757}
     758
     759InspectorCanvas* InspectorCanvasAgent::findInspectorCanvas(CanvasRenderingContext& context)
    703760{
    704761    for (auto& inspectorCanvas : m_identifierToInspectorCanvas.values()) {
    705762        if (&inspectorCanvas->context() == &context)
    706             return inspectorCanvas;
     763            return inspectorCanvas.get();
    707764    }
    708765
     
    719776}
    720777
    721 RefPtr<InspectorShaderProgram> InspectorCanvasAgent::assertInspectorProgram(ErrorString& errorString, const String& identifier)
    722 {
    723     auto inspectorProgram = m_identifierToInspectorProgram.get(identifier);
     778InspectorShaderProgram* InspectorCanvasAgent::assertInspectorProgram(ErrorString& errorString, const String& identifier)
     779{
     780    RefPtr<InspectorShaderProgram> inspectorProgram = m_identifierToInspectorProgram.get(identifier);
    724781    if (!inspectorProgram) {
    725782        errorString = "No shader program for given identifier."_s;
     
    727784    }
    728785
    729     return inspectorProgram;
    730 }
    731 
    732 RefPtr<InspectorShaderProgram> InspectorCanvasAgent::findInspectorProgram(WebGLProgram& program)
     786    return inspectorProgram.get();
     787}
     788
     789InspectorShaderProgram* InspectorCanvasAgent::findInspectorProgram(WebGLProgram& program)
    733790{
    734791    for (auto& inspectorProgram : m_identifierToInspectorProgram.values()) {
    735792        if (&inspectorProgram->program() == &program)
    736             return inspectorProgram;
     793            return inspectorProgram.get();
    737794    }
    738795
  • trunk/Source/WebCore/inspector/agents/InspectorCanvasAgent.h

    r243356 r243383  
    113113
    114114    void canvasDestroyedTimerFired();
     115    void canvasRecordingTimerFired();
    115116    void clearCanvasData();
    116117    InspectorCanvas& bindCanvas(CanvasRenderingContext&, bool captureBacktrace);
    117118    String unbindCanvas(InspectorCanvas&);
    118     RefPtr<InspectorCanvas> assertInspectorCanvas(ErrorString&, const String& identifier);
    119     RefPtr<InspectorCanvas> findInspectorCanvas(CanvasRenderingContext&);
     119    InspectorCanvas* assertInspectorCanvas(ErrorString&, const String& identifier);
     120    InspectorCanvas* findInspectorCanvas(CanvasRenderingContext&);
    120121#if ENABLE(WEBGL)
    121122    String unbindProgram(InspectorShaderProgram&);
    122     RefPtr<InspectorShaderProgram> assertInspectorProgram(ErrorString&, const String& identifier);
    123     RefPtr<InspectorShaderProgram> findInspectorProgram(WebGLProgram&);
     123    InspectorShaderProgram* assertInspectorProgram(ErrorString&, const String& identifier);
     124    InspectorShaderProgram* findInspectorProgram(WebGLProgram&);
     125
     126    HashMap<String, RefPtr<InspectorShaderProgram>> m_identifierToInspectorProgram;
    124127#endif
    125128
     
    131134
    132135    HashMap<String, RefPtr<InspectorCanvas>> m_identifierToInspectorCanvas;
    133 #if ENABLE(WEBGL)
    134     HashMap<String, RefPtr<InspectorShaderProgram>> m_identifierToInspectorProgram;
    135 #endif
    136136    Vector<String> m_removedCanvasIdentifiers;
    137 
    138137    Optional<size_t> m_recordingAutoCaptureFrameCount;
    139 
    140138    Timer m_canvasDestroyedTimer;
     139    Timer m_canvasRecordingTimer;
    141140};
    142141
  • trunk/Source/WebCore/platform/graphics/GraphicsContext3D.h

    r243356 r243383  
    121121class GraphicsContext3D : public RefCounted<GraphicsContext3D> {
    122122public:
    123     class Client {
    124     public:
    125         virtual ~Client() { }
    126         virtual void didComposite() = 0;
    127         virtual void forceContextLost() = 0;
    128         virtual void recycleContext() = 0;
    129         virtual void dispatchContextChangedNotification() = 0;
    130     };
    131 
    132123    enum {
    133124        // WebGL 1 constants
     
    774765
    775766    bool makeContextCurrent();
    776 
    777     void addClient(Client& client) { m_clients.add(&client); }
    778     void removeClient(Client& client) { m_clients.remove(&client); }
     767    void setWebGLContext(WebGLRenderingContextBase* base) { m_webglContext = base; }
    779768
    780769    // With multisampling on, blit from multisampleFBO to regular FBO.
     
    15191508#endif
    15201509
    1521     HashSet<Client*> m_clients;
     1510    // FIXME: Layering violation.
     1511    WebGLRenderingContextBase* m_webglContext { nullptr };
    15221512
    15231513    bool m_isForWebGL2 { false };
  • trunk/Source/WebCore/platform/graphics/opengl/GraphicsContext3DOpenGLCommon.cpp

    r243356 r243383  
    20172017{
    20182018    m_layerComposited = true;
    2019 
    2020     for (auto* client : m_clients)
    2021         client->didComposite();
    20222019}
    20232020
     
    20292026void GraphicsContext3D::forceContextLost()
    20302027{
    2031     for (auto* client : m_clients)
    2032         client->forceContextLost();
     2028#if ENABLE(WEBGL)
     2029    if (m_webglContext)
     2030        m_webglContext->forceLostContext(WebGLRenderingContextBase::RealLostContext);
     2031#endif
    20332032}
    20342033
    20352034void GraphicsContext3D::recycleContext()
    20362035{
    2037     for (auto* client : m_clients)
    2038         client->recycleContext();
     2036#if ENABLE(WEBGL)
     2037    if (m_webglContext)
     2038        m_webglContext->recycleContext();
     2039#endif
    20392040}
    20402041
    20412042void GraphicsContext3D::dispatchContextChangedNotification()
    20422043{
    2043     for (auto* client : m_clients)
    2044         client->dispatchContextChangedNotification();
     2044#if ENABLE(WEBGL)
     2045    if (m_webglContext)
     2046        m_webglContext->dispatchContextChangedEvent();
     2047#endif
    20452048}
    20462049
Note: See TracChangeset for help on using the changeset viewer.