Skip to content

Commit

Permalink
Cherry-pick 03a60be. rdar://122127093
Browse files Browse the repository at this point in the history
    REGRESSION (271770@main): visionOS: Significant regression on MotionMark
    https://bugs.webkit.org/show_bug.cgi?id=269010
    rdar://122127093

    Reviewed by Simon Fraser.

    Before 271770@main, the dynamic content scaling image buffer was a sidecar, outside
    of the normal flow of the front/back buffer swapping. After that commit, it was moved
    inside the main image buffer, and thus is swapped like the base scale rendering.

    This had one unintended consequence: when we're discarding the back buffer
    (e.g. because it contains an IOSurface that is still in-use and can't be recycled),
    we will now *also* discard the dynamic content scaling image buffer, and, critically,
    its resource cache.

    The whole point of the resource cache is to maintain state between frames, so this is
    wildly counterproductive. Once you get into a state where you are discarding
    back buffers (which comes up frequently under load, like MotionMark), you're also
    losing all resource caching.

    Instead of trying to rearchitect the discarding code to avoid dropping the display
    list image buffer, just maintain the dynamic content scaling resource cache
    in a sidecar on the RemoteLayerBackingStore, like it was before, and pass it
    down to the image buffer.

    A subsequent patch will make a similar change for the remote rendering case.

    * Source/WebCore/SourcesCocoa.txt:
    * Source/WebCore/WebCore.xcodeproj/project.pbxproj:
    * Source/WebCore/platform/graphics/cocoa/IOSurface.h:
    * Source/WebCore/platform/graphics/re/DynamicContentScalingResourceCache.h: Added.
    (WebCore::DynamicContentScalingResourceCache::DynamicContentScalingResourceCache):
    * Source/WebCore/platform/graphics/re/DynamicContentScalingResourceCache.mm: Added.
    (WebCore::DynamicContentScalingResourceCache::create):
    * Source/WebKit/Shared/RemoteLayerTree/DynamicContentScalingBifurcatedImageBuffer.mm:
    * Source/WebKit/Shared/RemoteLayerTree/DynamicContentScalingImageBufferBackend.mm:
    * Source/WebKit/Shared/RemoteLayerTree/RemoteLayerWithInProcessRenderingBackingStore.h:
    * Source/WebKit/Shared/RemoteLayerTree/RemoteLayerWithInProcessRenderingBackingStore.mm:
    (WebKit::RemoteLayerWithInProcessRenderingBackingStore::ensureDynamicContentScalingResourceCache):
    (WebKit::RemoteLayerWithInProcessRenderingBackingStore::allocateBuffer):
    (WebKit::RemoteLayerWithInProcessRenderingBackingStore::allocateBuffer const): Deleted.

    * Source/WebCore/platform/graphics/ImageBuffer.h:
    * Source/WebCore/platform/graphics/ImageBufferBackend.h:
    Note that it is not safe in a unified-sources world to forward-declare WebCore::IOSurface
    because of the name conflict with ::IOSurface; we need to strictly order the declarations,
    which is easiest to achieve by just importing our header.

    Canonical link: https://commits.webkit.org/274319@main

Identifier: 272448.536@safari-7618.1.15.14-branch
  • Loading branch information
hortont424 authored and MyahCobbs committed Feb 9, 2024
1 parent c2875c8 commit b878483
Show file tree
Hide file tree
Showing 11 changed files with 148 additions and 9 deletions.
1 change: 1 addition & 0 deletions Source/WebCore/SourcesCocoa.txt
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,7 @@ platform/graphics/mac/controls/TextFieldMac.mm
platform/graphics/mac/controls/ToggleButtonMac.mm
platform/graphics/mac/controls/WebControlView.mm
platform/graphics/opentype/OpenTypeCG.cpp
platform/graphics/re/DynamicContentScalingResourceCache.mm
platform/image-decoders/avif/AVIFImageDecoder.cpp
platform/image-decoders/avif/AVIFImageReader.cpp
platform/image-decoders/jpegxl/JPEGXLImageDecoder.cpp
Expand Down
6 changes: 6 additions & 0 deletions Source/WebCore/WebCore.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -981,6 +981,7 @@
2D5646B01B8F8493003C4994 /* DictionaryPopupInfo.h in Headers */ = {isa = PBXBuildFile; fileRef = 2D5646AF1B8F8493003C4994 /* DictionaryPopupInfo.h */; settings = {ATTRIBUTES = (Private, ); }; };
2D5A5931152525D00036EE51 /* ImageOrientation.h in Headers */ = {isa = PBXBuildFile; fileRef = A8748D6612CC3763001FBA41 /* ImageOrientation.h */; settings = {ATTRIBUTES = (Private, ); }; };
2D5BC42716F882EE007048D0 /* SecurityPolicyViolationEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = 2D5BC42516F882BE007048D0 /* SecurityPolicyViolationEvent.h */; settings = {ATTRIBUTES = (Private, ); }; };
2D5C6FA42B59BEDD00888CDC /* DynamicContentScalingResourceCache.h in Headers */ = {isa = PBXBuildFile; fileRef = 2D5C6FA32B59BED700888CDC /* DynamicContentScalingResourceCache.h */; settings = {ATTRIBUTES = (Private, ); }; };
2D5C9D0019C7B52E00B3C5C1 /* PageOverlay.h in Headers */ = {isa = PBXBuildFile; fileRef = 2D5C9CFC19C7B52E00B3C5C1 /* PageOverlay.h */; settings = {ATTRIBUTES = (Private, ); }; };
2D5C9D0219C7B52E00B3C5C1 /* PageOverlayController.h in Headers */ = {isa = PBXBuildFile; fileRef = 2D5C9CFE19C7B52E00B3C5C1 /* PageOverlayController.h */; settings = {ATTRIBUTES = (Private, ); }; };
2D673E4A2A9CF37300E2B4F0 /* CryptoAlgorithmX25519.h in Headers */ = {isa = PBXBuildFile; fileRef = 2D673E492A9CF2B100E2B4F0 /* CryptoAlgorithmX25519.h */; };
Expand Down Expand Up @@ -9110,6 +9111,8 @@
2D56800123888603007ECB8A /* auto-hide-controller.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = "auto-hide-controller.js"; sourceTree = "<group>"; };
2D5BC42516F882BE007048D0 /* SecurityPolicyViolationEvent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SecurityPolicyViolationEvent.h; sourceTree = "<group>"; };
2D5BC42616F882BE007048D0 /* SecurityPolicyViolationEvent.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = SecurityPolicyViolationEvent.idl; sourceTree = "<group>"; };
2D5C6FA22B59BED700888CDC /* DynamicContentScalingResourceCache.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = DynamicContentScalingResourceCache.mm; sourceTree = "<group>"; };
2D5C6FA32B59BED700888CDC /* DynamicContentScalingResourceCache.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DynamicContentScalingResourceCache.h; sourceTree = "<group>"; };
2D5C9CFB19C7B52E00B3C5C1 /* PageOverlay.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PageOverlay.cpp; sourceTree = "<group>"; };
2D5C9CFC19C7B52E00B3C5C1 /* PageOverlay.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PageOverlay.h; sourceTree = "<group>"; };
2D5C9CFD19C7B52E00B3C5C1 /* PageOverlayController.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PageOverlayController.cpp; sourceTree = "<group>"; };
Expand Down Expand Up @@ -23393,6 +23396,8 @@
2DD797E62ABD176000EAB71A /* re */ = {
isa = PBXGroup;
children = (
2D5C6FA32B59BED700888CDC /* DynamicContentScalingResourceCache.h */,
2D5C6FA22B59BED700888CDC /* DynamicContentScalingResourceCache.mm */,
2DD797E72ABD17A200EAB71A /* DynamicContentScalingTypes.h */,
);
path = re;
Expand Down Expand Up @@ -38469,6 +38474,7 @@
93D6B7A82551D41F0058DD3A /* DummySpeechRecognitionProvider.h in Headers */,
93085DF826E822C7000EC6A7 /* DummyStorageProvider.h in Headers */,
2DABFA7F2B216C68001C33D7 /* DynamicContentScalingDisplayList.h in Headers */,
2D5C6FA42B59BEDD00888CDC /* DynamicContentScalingResourceCache.h in Headers */,
2DD797E82ABD17A200EAB71A /* DynamicContentScalingTypes.h in Headers */,
FD6ED2C8136B8E66003CF072 /* DynamicsCompressor.h in Headers */,
FD537357137B653B00008DCE /* DynamicsCompressorKernel.h in Headers */,
Expand Down
16 changes: 13 additions & 3 deletions Source/WebCore/platform/graphics/ImageBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@
#include <wtf/RefCounted.h>
#include <wtf/ThreadSafeWeakPtr.h>

#if ENABLE(RE_DYNAMIC_CONTENT_SCALING)
#include "DynamicContentScalingResourceCache.h"
#endif

#if HAVE(IOSURFACE)
#include "IOSurface.h"
#endif

namespace WTF {
class TextStream;
}
Expand All @@ -49,7 +57,6 @@ class DynamicContentScalingDisplayList;
class Filter;
class GraphicsClient;
#if HAVE(IOSURFACE)
class IOSurface;
class IOSurfacePool;
#endif
class ScriptExecutionContext;
Expand All @@ -66,9 +73,12 @@ struct ImageBufferCreationContext {
IOSurfacePool* surfacePool { nullptr };
PlatformDisplayID displayID { 0 };
#endif
WebCore::ProcessIdentity resourceOwner;
#if ENABLE(RE_DYNAMIC_CONTENT_SCALING)
DynamicContentScalingResourceCache dynamicContentScalingResourceCache;
#endif
ProcessIdentity resourceOwner;

ImageBufferCreationContext() = default; // To guarantee order in presence of ifdefs, use individual .property to initialize them.
ImageBufferCreationContext() = default;
};

struct ImageBufferParameters {
Expand Down
5 changes: 4 additions & 1 deletion Source/WebCore/platform/graphics/ImageBufferBackend.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@
#include <cairo.h>
#endif

#if HAVE(IOSURFACE)
#include "IOSurface.h"
#endif

namespace WTF {
class TextStream;
}
Expand All @@ -54,7 +58,6 @@ struct ImageBufferCreationContext;
class GraphicsContext;
class GraphicsContextGL;
#if HAVE(IOSURFACE)
class IOSurface;
class IOSurfacePool;
#endif
class Image;
Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/platform/graphics/cocoa/IOSurface.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
#include "DestinationColorSpace.h"
#include "IntSize.h"
#include "ProcessIdentity.h"
#include <CoreGraphics/CGImage.h>
#include <CoreGraphics/CoreGraphics.h>
#include <objc/objc.h>
#include <wtf/spi/cocoa/IOSurfaceSPI.h>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright (C) 2024 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

#if ENABLE(RE_DYNAMIC_CONTENT_SCALING)

#include <wtf/Forward.h>

namespace WebCore {

class DynamicContentScalingResourceCache : public RetainPtr<id> {
public:
WEBCORE_EXPORT static DynamicContentScalingResourceCache create();

DynamicContentScalingResourceCache()
: RetainPtr<id>()
{
}

DynamicContentScalingResourceCache(RetainPtr<id>&& object)
: RetainPtr<id>(WTFMove(object))
{
}
};

}

#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright (C) 2024 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. ``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
* 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

#import "config.h"
#import "DynamicContentScalingResourceCache.h"

#if ENABLE(RE_DYNAMIC_CONTENT_SCALING)

#import <CoreRE/RECGCommandsContext.h>
#import <wtf/cocoa/TypeCastsCocoa.h>

namespace WebCore {

DynamicContentScalingResourceCache DynamicContentScalingResourceCache::create()
{
return bridge_id_cast(adoptCF(RECGCommandsCacheCreate(nullptr)));
}

}

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#if ENABLE(RE_DYNAMIC_CONTENT_SCALING)

#import "DynamicContentScalingImageBufferBackend.h"
#import <CoreRE/RECGCommandsContext.h>
#import <WebCore/BifurcatedGraphicsContext.h>
#import <WebCore/DynamicContentScalingDisplayList.h>
#import <wtf/MachSendRight.h>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,13 @@ static CFDictionaryRef makeContextOptions(const DynamicContentScalingImageBuffer

DynamicContentScalingImageBufferBackend::DynamicContentScalingImageBufferBackend(const Parameters& parameters, const WebCore::ImageBufferCreationContext& creationContext, WebCore::RenderingMode renderingMode)
: ImageBufferCGBackend { parameters }
, m_resourceCache(bridge_id_cast(adoptCF(RECGCommandsCacheCreate(nullptr))))
, m_resourceCache(creationContext.dynamicContentScalingResourceCache)
, m_renderingMode(renderingMode)
{
// FIXME: We should make callers always specify a cache and have an assertion here instead
// of making a temporary one. RemoteLayerWithRemoteRenderingBackingStore currently does not.
if (!m_resourceCache)
m_resourceCache = bridge_id_cast(adoptCF(RECGCommandsCacheCreate(nullptr)));
}

std::optional<ImageBufferBackendHandle> DynamicContentScalingImageBufferBackend::createBackendHandle(SharedMemory::Protection) const
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#pragma once

#include "RemoteLayerBackingStore.h"
#include <WebCore/DynamicContentScalingResourceCache.h>

namespace WebKit {

Expand All @@ -52,14 +53,18 @@ class RemoteLayerWithInProcessRenderingBackingStore : public RemoteLayerBackingS
void dump(WTF::TextStream&) const final;

private:
RefPtr<WebCore::ImageBuffer> allocateBuffer() const;
RefPtr<WebCore::ImageBuffer> allocateBuffer();
SwapBuffersDisplayRequirement prepareBuffers();
WebCore::SetNonVolatileResult swapToValidFrontBuffer();

void ensureFrontBuffer();
bool hasFrontBuffer() const final;
bool frontBufferMayBeVolatile() const final;

#if ENABLE(RE_DYNAMIC_CONTENT_SCALING)
DynamicContentScalingResourceCache ensureDynamicContentScalingResourceCache();
#endif

struct Buffer {
RefPtr<WebCore::ImageBuffer> imageBuffer;
bool isCleared { false };
Expand All @@ -81,6 +86,10 @@ class RemoteLayerWithInProcessRenderingBackingStore : public RemoteLayerBackingS
Buffer m_frontBuffer;
Buffer m_backBuffer;
Buffer m_secondaryBackBuffer;

#if ENABLE(RE_DYNAMIC_CONTENT_SCALING)
WebCore::DynamicContentScalingResourceCache m_dynamicContentScalingResourceCache;
#endif
};

} // namespace WebKit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,13 @@
return frontBuffer->dynamicContentScalingDisplayList();
return std::nullopt;
}

DynamicContentScalingResourceCache RemoteLayerWithInProcessRenderingBackingStore::ensureDynamicContentScalingResourceCache()
{
if (!m_dynamicContentScalingResourceCache)
m_dynamicContentScalingResourceCache = DynamicContentScalingResourceCache::create();
return m_dynamicContentScalingResourceCache;
}
#endif

void RemoteLayerWithInProcessRenderingBackingStore::createContextAndPaintContents()
Expand Down Expand Up @@ -247,15 +254,17 @@ void flushAndCollectHandles(HashMap<RemoteImageBufferSetIdentifier, std::unique_
}
}

RefPtr<WebCore::ImageBuffer> RemoteLayerWithInProcessRenderingBackingStore::allocateBuffer() const
RefPtr<WebCore::ImageBuffer> RemoteLayerWithInProcessRenderingBackingStore::allocateBuffer()
{
auto purpose = m_layer->containsBitmapOnly() ? WebCore::RenderingPurpose::BitmapOnlyLayerBacking : WebCore::RenderingPurpose::LayerBacking;
ImageBufferCreationContext creationContext;
creationContext.surfacePool = &WebCore::IOSurfacePool::sharedPool();

#if ENABLE(RE_DYNAMIC_CONTENT_SCALING)
if (m_parameters.includeDisplayList == IncludeDisplayList::Yes)
if (m_parameters.includeDisplayList == IncludeDisplayList::Yes) {
creationContext.dynamicContentScalingResourceCache = ensureDynamicContentScalingResourceCache();
return allocateBufferInternal<DynamicContentScalingBifurcatedImageBuffer>(type(), size(), purpose, scale(), colorSpace(), pixelFormat(), creationContext);
}
#endif

return allocateBufferInternal<ImageBuffer>(type(), size(), purpose, scale(), colorSpace(), pixelFormat(), creationContext);
Expand Down

0 comments on commit b878483

Please sign in to comment.