Skip to content

Commit

Permalink
Dynamic Content Scaling resource cache cannot cache images between la…
Browse files Browse the repository at this point in the history
…yers

https://bugs.webkit.org/show_bug.cgi?id=245920
rdar://100336143

Reviewed by Said Abou-Hallawa.

* Source/WebCore/SourcesCocoa.txt:
* Source/WebCore/WebCore.xcodeproj/project.pbxproj:
* Source/WebKit/GPUProcess/graphics/RemoteRenderingBackend.cpp:
(WebKit::RemoteRenderingBackend::allocateImageBuffer):
(WebKit::RemoteRenderingBackend::ensureDynamicContentScalingResourceCache):
* Source/WebKit/GPUProcess/graphics/RemoteRenderingBackend.h:
* Source/WebKit/Shared/RemoteLayerTree/DynamicContentScalingBifurcatedImageBuffer.h:
* Source/WebKit/Shared/RemoteLayerTree/DynamicContentScalingBifurcatedImageBuffer.mm:
* Source/WebKit/Shared/RemoteLayerTree/DynamicContentScalingImageBufferBackend.mm:
* Source/WebKit/Shared/RemoteLayerTree/RemoteLayerWithInProcessRenderingBackingStore.mm:
(WebKit::RemoteLayerWithInProcessRenderingBackingStore::allocateBuffer const):
* Source/WebKit/WebProcess/WebPage/RemoteLayerTree/RemoteLayerTreeContext.h:
* Source/WebKit/WebProcess/WebPage/RemoteLayerTree/RemoteLayerTreeContext.mm:
(WebKit::RemoteLayerTreeContext::ensureDynamicContentScalingResourceCache):
* Source/WebCore/platform/graphics/re/DynamicContentScalingResourceCache.h: Added.
(WebCore::DynamicContentScalingResourceCache::DynamicContentScalingResourceCache):
* Source/WebCore/platform/graphics/re/DynamicContentScalingResourceCache.mm: Added.
(WebCore::DynamicContentScalingResourceCache::create):
Move CGDisplayList's image cache object up to RemoteLayerTreeContext (in the in-process case)
and RemoteRenderingBackend (in the GPU-process case), so that resources can be cached
across multiple layers.

* Source/WebCore/platform/graphics/ImageBuffer.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/273240@main
  • Loading branch information
hortont424 committed Jan 19, 2024
1 parent ed4c804 commit e8c0db1
Show file tree
Hide file tree
Showing 14 changed files with 168 additions and 7 deletions.
1 change: 1 addition & 0 deletions Source/WebCore/SourcesCocoa.txt
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,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 @@ -983,6 +983,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 @@ -9122,6 +9123,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 @@ -23454,6 +23457,8 @@
2DD797E62ABD176000EAB71A /* re */ = {
isa = PBXGroup;
children = (
2D5C6FA32B59BED700888CDC /* DynamicContentScalingResourceCache.h */,
2D5C6FA22B59BED700888CDC /* DynamicContentScalingResourceCache.mm */,
2DD797E72ABD17A200EAB71A /* DynamicContentScalingTypes.h */,
);
path = re;
Expand Down Expand Up @@ -38535,6 +38540,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
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) 2023 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
13 changes: 12 additions & 1 deletion Source/WebKit/GPUProcess/graphics/RemoteRenderingBackend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,10 @@ RefPtr<ImageBuffer> RemoteRenderingBackend::allocateImageBuffer(const FloatSize&
RefPtr<ImageBuffer> imageBuffer;

#if ENABLE(RE_DYNAMIC_CONTENT_SCALING)
if (m_gpuConnectionToWebProcess->isDynamicContentScalingEnabled() && (purpose == RenderingPurpose::LayerBacking || purpose == RenderingPurpose::DOM))
if (m_gpuConnectionToWebProcess->isDynamicContentScalingEnabled() && (purpose == RenderingPurpose::LayerBacking || purpose == RenderingPurpose::DOM)) {
creationContext.dynamicContentScalingResourceCache = ensureDynamicContentScalingResourceCache();
imageBuffer = allocateImageBufferInternal<DynamicContentScalingBifurcatedImageBuffer>(logicalSize, renderingMode, purpose, resolutionScale, colorSpace, pixelFormat, creationContext, imageBufferIdentifier);
}
#endif

if (!imageBuffer)
Expand Down Expand Up @@ -577,6 +579,15 @@ void RemoteRenderingBackend::terminateWebProcess(ASCIILiteral message)
}
}

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

} // namespace WebKit

#undef MESSAGE_CHECK
Expand Down
7 changes: 7 additions & 0 deletions Source/WebKit/GPUProcess/graphics/RemoteRenderingBackend.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,10 @@ class RemoteRenderingBackend : private IPC::MessageSender, public IPC::StreamMes
void createDisplayListRecorder(RefPtr<WebCore::ImageBuffer>, WebCore::RenderingResourceIdentifier);
void releaseDisplayListRecorder(WebCore::RenderingResourceIdentifier);

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

Ref<IPC::StreamConnectionWorkQueue> m_workQueue;
Ref<IPC::StreamServerConnection> m_streamConnection;
RemoteResourceCache m_remoteResourceCache;
Expand All @@ -187,6 +191,9 @@ class RemoteRenderingBackend : private IPC::MessageSender, public IPC::StreamMes
#if HAVE(IOSURFACE)
Ref<WebCore::IOSurfacePool> m_ioSurfacePool;
#endif
#if ENABLE(RE_DYNAMIC_CONTENT_SCALING)
WebCore::DynamicContentScalingResourceCache m_dynamicContentScalingResourceCache;
#endif

HashMap<WebCore::RenderingResourceIdentifier, IPC::ScopedActiveMessageReceiveQueue<RemoteDisplayListRecorder>> m_remoteDisplayLists WTF_GUARDED_BY_CAPABILITY(workQueue());
HashMap<WebCore::RenderingResourceIdentifier, IPC::ScopedActiveMessageReceiveQueue<RemoteImageBuffer>> m_remoteImageBuffers WTF_GUARDED_BY_CAPABILITY(workQueue());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ class DynamicContentScalingBifurcatedImageBuffer : public WebCore::ImageBuffer {

WebCore::GraphicsContext& context() const final;

static WebCore::DynamicContentScalingResourceCache createResourceCache();

protected:
std::optional<WebCore::DynamicContentScalingDisplayList> dynamicContentScalingDisplayList() final;

Expand Down
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,7 +84,7 @@ 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)
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,11 @@
creationContext.surfacePool = &WebCore::IOSurfacePool::sharedPool();

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

return allocateBufferInternal<ImageBuffer>(type(), size(), purpose, scale(), colorSpace(), pixelFormat(), creationContext);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ class RemoteLayerTreeContext : public WebCore::GraphicsLayerFactory {
bool useDynamicContentScalingDisplayListsForDOMRendering() const { return m_useDynamicContentScalingDisplayListsForDOMRendering; }
void setUseDynamicContentScalingDisplayListsForDOMRendering(bool useDynamicContentScalingDisplayLists) { m_useDynamicContentScalingDisplayListsForDOMRendering = useDynamicContentScalingDisplayLists; }

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

void gpuProcessConnectionWasDestroyed();

#if PLATFORM(IOS_FAMILY)
Expand Down Expand Up @@ -123,6 +127,10 @@ class RemoteLayerTreeContext : public WebCore::GraphicsLayerFactory {

RemoteLayerTreeTransaction* m_currentTransaction { nullptr };

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

bool m_nextRenderingUpdateRequiresSynchronousImageDecoding { false };
bool m_useDynamicContentScalingDisplayListsForDOMRendering { false };
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@
#import <wtf/SetForScope.h>
#import <wtf/SystemTracing.h>

#if ENABLE(RE_DYNAMIC_CONTENT_SCALING)
#import "DynamicContentScalingBifurcatedImageBuffer.h"
#endif

namespace WebKit {
using namespace WebCore;

Expand Down Expand Up @@ -239,4 +243,16 @@
m_backingStoreCollection->gpuProcessConnectionWasDestroyed();
}

#if ENABLE(RE_DYNAMIC_CONTENT_SCALING)

DynamicContentScalingResourceCache RemoteLayerTreeContext::ensureDynamicContentScalingResourceCache()
{
if (!m_dynamicContentScalingResourceCache)
m_dynamicContentScalingResourceCache = DynamicContentScalingResourceCache::create();
return m_dynamicContentScalingResourceCache;
}

#endif


} // namespace WebKit

0 comments on commit e8c0db1

Please sign in to comment.