Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create GraphicsClient for the graphics specific subset of ChromeClient that needs to be accessed from worker threads. #6875

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions Source/WebCore/Headers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -1361,6 +1361,7 @@ set(WebCore_PRIVATE_FRAMEWORK_HEADERS
platform/FileMonitor.h
platform/FileStreamClient.h
platform/FloatConversion.h
platform/GraphicsClient.h
platform/HostWindow.h
platform/KeyboardScrollingAnimator.h
platform/KeyboardScroll.h
Expand Down
4 changes: 4 additions & 0 deletions Source/WebCore/WebCore.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3741,6 +3741,7 @@
A7D20F6D107F438B00A80392 /* WebGLActiveInfo.h in Headers */ = {isa = PBXBuildFile; fileRef = A7D20F6B107F438B00A80392 /* WebGLActiveInfo.h */; };
A7D6B3490F61104500B79FD1 /* WorkerScriptLoader.h in Headers */ = {isa = PBXBuildFile; fileRef = A7D6B3470F61104500B79FD1 /* WorkerScriptLoader.h */; settings = {ATTRIBUTES = (Private, ); }; };
A7D6B3490F61104500FF9FD1 /* WorkerFontLoadRequest.h in Headers */ = {isa = PBXBuildFile; fileRef = A7D6B3470F61104500FF9FD1 /* WorkerFontLoadRequest.h */; settings = {ATTRIBUTES = (Private, ); }; };
A7D8E64A28C80F2A0019F92F /* GraphicsClient.h in Headers */ = {isa = PBXBuildFile; fileRef = A7D8E64928C80F2A0019F92F /* GraphicsClient.h */; settings = {ATTRIBUTES = (Private, ); }; };
A7DBF8DE1276919C006B6008 /* TextCheckingHelper.h in Headers */ = {isa = PBXBuildFile; fileRef = A7DBF8DC1276919C006B6008 /* TextCheckingHelper.h */; };
A80D67080E9E9DEB00E420F0 /* GraphicsContextPlatformPrivateCG.h in Headers */ = {isa = PBXBuildFile; fileRef = A80D67070E9E9DEB00E420F0 /* GraphicsContextPlatformPrivateCG.h */; };
A80E6CE60A1989CA007FB8C5 /* CSSPrimitiveValue.h in Headers */ = {isa = PBXBuildFile; fileRef = A80E6CBC0A1989CA007FB8C5 /* CSSPrimitiveValue.h */; settings = {ATTRIBUTES = (Private, ); }; };
Expand Down Expand Up @@ -14621,6 +14622,7 @@
A7D6B3470F61104500FF9FD1 /* WorkerFontLoadRequest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WorkerFontLoadRequest.h; sourceTree = "<group>"; };
A7D6B3480F61104500B79FD1 /* WorkerScriptLoader.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WorkerScriptLoader.cpp; sourceTree = "<group>"; };
A7D6B3480F61104500FF9FD1 /* WorkerFontLoadRequest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WorkerFontLoadRequest.cpp; sourceTree = "<group>"; };
A7D8E64928C80F2A0019F92F /* GraphicsClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GraphicsClient.h; sourceTree = "<group>"; };
A7DBF8DB1276919C006B6008 /* TextCheckingHelper.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = TextCheckingHelper.cpp; sourceTree = "<group>"; };
A7DBF8DC1276919C006B6008 /* TextCheckingHelper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TextCheckingHelper.h; sourceTree = "<group>"; };
A80A38FD0E50CC8200A25EBC /* PatternCG.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PatternCG.cpp; sourceTree = "<group>"; };
Expand Down Expand Up @@ -31058,6 +31060,7 @@
BC073BA90C399B1F000F5979 /* FloatConversion.h */,
4190F3A1249D152700531C57 /* FrameRateMonitor.cpp */,
4190F3A3249D152800531C57 /* FrameRateMonitor.h */,
A7D8E64928C80F2A0019F92F /* GraphicsClient.h */,
A8748BDF12CBF2DC001FBA41 /* HashTools.h */,
BC3BC29B0E91AB0F00835588 /* HostWindow.h */,
0FE27FC62717ADF70003AAAE /* KeyboardScroll.cpp */,
Expand Down Expand Up @@ -35985,6 +35988,7 @@
2D481F04146B5C6B00AA7834 /* GradientImage.h in Headers */,
BC19CDF2276FFC6D0053F734 /* GradientRendererCG.h in Headers */,
7BB680BA25BA1BE4002B8738 /* GraphicsChecksMac.h in Headers */,
A7D8E64A28C80F2A0019F92F /* GraphicsClient.h in Headers */,
B2A015A90AF6CD53006BCE0E /* GraphicsContext.h in Headers */,
934907E4125BBBC8007F23A0 /* GraphicsContextCG.h in Headers */,
313DE87023A96973008FC47B /* GraphicsContextGL.h in Headers */,
Expand Down
3 changes: 2 additions & 1 deletion Source/WebCore/html/HTMLCanvasElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
#include "GraphicsContext.h"
#include "HTMLNames.h"
#include "HTMLParserIdioms.h"
#include "HostWindow.h"
#include "ImageBitmapRenderingContext.h"
#include "ImageBitmapRenderingContextSettings.h"
#include "ImageBuffer.h"
Expand Down Expand Up @@ -1019,7 +1020,7 @@ void HTMLCanvasElement::createImageBuffer() const
return std::pair { DestinationColorSpace::SRGB(), PixelFormat::BGRA8 };
}();
ImageBuffer::CreationContext context = { };
context.hostWindow = hostWindow;
context.graphicsClient = hostWindow;
context.avoidIOSurfaceSizeCheckInWebProcessForTesting = m_avoidBackendSizeCheckForTesting;
setImageBuffer(ImageBuffer::create(size(), RenderingPurpose::Canvas, 1, colorSpace, pixelFormat, bufferOptions, context));

Expand Down
14 changes: 11 additions & 3 deletions Source/WebCore/html/ImageBitmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include "HTMLCanvasElement.h"
#include "HTMLImageElement.h"
#include "HTMLVideoElement.h"
#include "HostWindow.h"
#include "ImageBitmapOptions.h"
#include "ImageBuffer.h"
#include "ImageData.h"
Expand Down Expand Up @@ -92,15 +93,17 @@ RefPtr<ImageBuffer> ImageBitmap::createImageBuffer(ScriptExecutionContext& scrip

auto bufferOptions = bufferOptionsForRendingMode(renderingMode);

GraphicsClient* client = nullptr;
if (scriptExecutionContext.isDocument()) {
auto& document = downcast<Document>(scriptExecutionContext);
if (document.view() && document.view()->root()) {
auto hostWindow = document.view()->root()->hostWindow();
return ImageBuffer::create(size, RenderingPurpose::Canvas, resolutionScale, *imageBufferColorSpace, PixelFormat::BGRA8, bufferOptions, { hostWindow });
client = document.view()->root()->hostWindow();
}
}

// FIXME <https://webkit.org/b/218482> Enable worker based ImageBitmap and OffscreenCanvas drawing to use GPU Process rendering
if (client)
return ImageBuffer::create(size, RenderingPurpose::Canvas, resolutionScale, *imageBufferColorSpace, PixelFormat::BGRA8, bufferOptions, { client });

return ImageBuffer::create(size, RenderingPurpose::Unspecified, resolutionScale, *imageBufferColorSpace, PixelFormat::BGRA8, bufferOptions);
}

Expand All @@ -113,6 +116,11 @@ void ImageBitmap::createPromise(ScriptExecutionContext& scriptExecutionContext,
);
}

RefPtr<ImageBuffer> ImageBitmap::createImageBuffer(ScriptExecutionContext& scriptExecutionContext, const FloatSize& size, DestinationColorSpace colorSpace, float resolutionScale)
{
return createImageBuffer(scriptExecutionContext, size, bufferRenderingMode, colorSpace, resolutionScale);
}

Vector<std::optional<ImageBitmapBacking>> ImageBitmap::detachBitmaps(Vector<RefPtr<ImageBitmap>>&& bitmaps)
{
return WTF::map(WTFMove(bitmaps), [](auto&& bitmap) {
Expand Down
1 change: 1 addition & 0 deletions Source/WebCore/html/ImageBitmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ class ImageBitmap final : public ScriptWrappable, public RefCounted<ImageBitmap>
static void createPromise(ScriptExecutionContext&, Source&&, ImageBitmapOptions&&, int sx, int sy, int sw, int sh, Promise&&);

static RefPtr<ImageBuffer> createImageBuffer(ScriptExecutionContext&, const FloatSize&, RenderingMode, DestinationColorSpace, float resolutionScale = 1);
static RefPtr<ImageBuffer> createImageBuffer(ScriptExecutionContext&, const FloatSize&, DestinationColorSpace, float resolutionScale = 1);

static Ref<ImageBitmap> create(ScriptExecutionContext&, const IntSize&, DestinationColorSpace);
static Ref<ImageBitmap> create(std::optional<ImageBitmapBacking>&&);
Expand Down
50 changes: 50 additions & 0 deletions Source/WebCore/platform/GraphicsClient.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright (C) 2022 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

#include "PlatformScreen.h"

namespace WebCore {

class DestinationColorSpace;
class ImageBuffer;

enum class PixelFormat : uint8_t;
enum class RenderingMode : bool;
enum class RenderingPurpose : uint8_t;

class GraphicsClient {
WTF_MAKE_NONCOPYABLE(GraphicsClient); WTF_MAKE_FAST_ALLOCATED;
public:
GraphicsClient() = default;
virtual ~GraphicsClient() = default;

virtual PlatformDisplayID displayID() const = 0;

virtual RefPtr<ImageBuffer> createImageBuffer(const FloatSize&, RenderingMode, RenderingPurpose, float resolutionScale, const DestinationColorSpace&, PixelFormat, bool avoidBackendSizeCheck = false) const = 0;
};

} // namespace WebCore
12 changes: 2 additions & 10 deletions Source/WebCore/platform/HostWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,19 @@

#pragma once

#include "GraphicsClient.h"
#include "Widget.h"

namespace WebCore {

class Cursor;
class DestinationColorSpace;
class GraphicsContextGL;
class ImageBuffer;

enum class PixelFormat : uint8_t;
enum class RenderingMode : bool;
enum class RenderingPurpose : uint8_t;

struct GraphicsContextGLAttributes;

using FramesPerSecond = unsigned;

class HostWindow {
class HostWindow : public GraphicsClient {
WTF_MAKE_NONCOPYABLE(HostWindow); WTF_MAKE_FAST_ALLOCATED;
public:
HostWindow() = default;
Expand All @@ -66,8 +61,6 @@ class HostWindow {
virtual IntPoint accessibilityScreenToRootView(const IntPoint&) const = 0;
virtual IntRect rootViewToAccessibilityScreen(const IntRect&) const = 0;

virtual RefPtr<ImageBuffer> createImageBuffer(const FloatSize&, RenderingMode, RenderingPurpose, float resolutionScale, const DestinationColorSpace&, PixelFormat, bool avoidBackendSizeCheck = false) const = 0;

#if ENABLE(WEBGL)
virtual RefPtr<GraphicsContextGL> createGraphicsContextGL(const GraphicsContextGLAttributes&) const = 0;
#endif
Expand All @@ -80,7 +73,6 @@ class HostWindow {

virtual void setCursorHiddenUntilMouseMoves(bool) = 0;

virtual PlatformDisplayID displayID() const = 0;
virtual void windowScreenDidChange(PlatformDisplayID, std::optional<FramesPerSecond> nominalFramesPerSecond) = 0;

virtual FloatSize screenSize() const = 0;
Expand Down
4 changes: 2 additions & 2 deletions Source/WebCore/platform/graphics/ImageBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ RefPtr<ImageBuffer> ImageBuffer::create(const FloatSize& size, RenderingPurpose
imageBuffer = DisplayList::ImageBuffer::create<UnacceleratedImageBufferBackend>(size, resolutionScale, colorSpace, pixelFormat, purpose, creationContext);
}

if (creationContext.hostWindow && !imageBuffer) {
if (creationContext.graphicsClient && !imageBuffer) {
auto renderingMode = options.contains(ImageBufferOptions::Accelerated) ? RenderingMode::Accelerated : RenderingMode::Unaccelerated;
imageBuffer = creationContext.hostWindow->createImageBuffer(size, renderingMode, purpose, resolutionScale, colorSpace, pixelFormat, creationContext.avoidIOSurfaceSizeCheckInWebProcessForTesting);
imageBuffer = creationContext.graphicsClient->createImageBuffer(size, renderingMode, purpose, resolutionScale, colorSpace, pixelFormat, creationContext.avoidIOSurfaceSizeCheckInWebProcessForTesting);
}

if (imageBuffer)
Expand Down
8 changes: 4 additions & 4 deletions Source/WebCore/platform/graphics/ImageBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
namespace WebCore {

class Filter;
class HostWindow;
class GraphicsClient;
#if HAVE(IOSURFACE)
class IOSurfacePool;
#endif
Expand All @@ -52,7 +52,7 @@ class ImageBuffer : public ThreadSafeRefCounted<ImageBuffer, WTF::DestructionThr
public:
struct CreationContext {
// clang 13.1.6 throws errors if we use default initializers here.
HostWindow* hostWindow;
GraphicsClient* graphicsClient;
#if HAVE(IOSURFACE)
IOSurfacePool* surfacePool;
#endif
Expand All @@ -63,7 +63,7 @@ class ImageBuffer : public ThreadSafeRefCounted<ImageBuffer, WTF::DestructionThr
UseCGDisplayListImageCache useCGDisplayListImageCache;
#endif

CreationContext(HostWindow* window = nullptr
CreationContext(GraphicsClient* client = nullptr
#if HAVE(IOSURFACE)
, IOSurfacePool* pool = nullptr
#endif
Expand All @@ -72,7 +72,7 @@ class ImageBuffer : public ThreadSafeRefCounted<ImageBuffer, WTF::DestructionThr
, UseCGDisplayListImageCache useCGDisplayListImageCache = UseCGDisplayListImageCache::No
#endif
)
: hostWindow(window)
: graphicsClient(client)
#if HAVE(IOSURFACE)
, surfacePool(pool)
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

#if HAVE(IOSURFACE)

#include "GraphicsClient.h"
#include "GraphicsContextCG.h"
#include "IOSurface.h"
#include "IOSurfacePool.h"
Expand Down Expand Up @@ -93,7 +94,7 @@ std::unique_ptr<ImageBufferIOSurfaceBackend> ImageBufferIOSurfaceBackend::create
if (!surface)
return nullptr;

RetainPtr<CGContextRef> cgContext = surface->ensurePlatformContext(creationContext.hostWindow);
RetainPtr<CGContextRef> cgContext = surface->ensurePlatformContext(creationContext.graphicsClient ? creationContext.graphicsClient->displayID() : 0);
if (!cgContext)
return nullptr;

Expand Down
4 changes: 2 additions & 2 deletions Source/WebCore/platform/graphics/cocoa/IOSurface.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ class TextStream;
namespace WebCore {

class GraphicsContext;
class HostWindow;
class IOSurfacePool;

enum class PixelFormat : uint8_t;
enum class SetNonVolatileResult : uint8_t;

using IOSurfaceSeed = uint32_t;
using PlatformDisplayID = uint32_t;

class IOSurface final {
WTF_MAKE_FAST_ALLOCATED;
Expand Down Expand Up @@ -130,7 +130,7 @@ class IOSurface final {
#endif
IOSurfaceRef surface() const { return m_surface.get(); }
WEBCORE_EXPORT GraphicsContext& ensureGraphicsContext();
WEBCORE_EXPORT CGContextRef ensurePlatformContext(const HostWindow* = nullptr);
WEBCORE_EXPORT CGContextRef ensurePlatformContext(PlatformDisplayID = 0);

// Querying volatility can be expensive, so in cases where the surface is
// going to be used immediately, use the return value of setVolatile to
Expand Down
8 changes: 4 additions & 4 deletions Source/WebCore/platform/graphics/cocoa/IOSurface.mm
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ static IntSize computeMaximumSurfaceSize()
return adoptCF(CGBitmapContextCreate(NULL, width, height, configuration.bitsPerComponent, bytesPerRow, m_colorSpace->platformColorSpace(), configuration.bitmapInfo));
}

CGContextRef IOSurface::ensurePlatformContext(const HostWindow* hostWindow)
CGContextRef IOSurface::ensurePlatformContext(PlatformDisplayID displayID)
{
if (m_cgContext)
return m_cgContext.get();
Expand All @@ -373,14 +373,14 @@ static IntSize computeMaximumSurfaceSize()

#if PLATFORM(MAC)
if (auto displayMask = primaryOpenGLDisplayMask()) {
if (hostWindow && hostWindow->displayID())
displayMask = displayMaskForDisplay(hostWindow->displayID());
if (displayID)
displayMask = displayMaskForDisplay(displayID);
ALLOW_DEPRECATED_DECLARATIONS_BEGIN
CGIOSurfaceContextSetDisplayMask(m_cgContext.get(), displayMask);
ALLOW_DEPRECATED_DECLARATIONS_END
}
#else
UNUSED_PARAM(hostWindow);
UNUSED_PARAM(displayID);
#endif
#if HAVE(CG_CONTEXT_SET_OWNER_IDENTITY)
if (m_resourceOwner && CGContextSetOwnerIdentity)
Expand Down
1 change: 1 addition & 0 deletions Source/WebCore/rendering/style/StyleFilterImage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "CachedImage.h"
#include "CachedResourceLoader.h"
#include "ComputedStyleExtractor.h"
#include "HostWindow.h"
#include "ImageBuffer.h"
#include "NullGraphicsContext.h"
#include "RenderElement.h"
Expand Down