Diff
Modified: trunk/Source/WebCore/ChangeLog (275904 => 275905)
--- trunk/Source/WebCore/ChangeLog 2021-04-13 20:09:32 UTC (rev 275904)
+++ trunk/Source/WebCore/ChangeLog 2021-04-13 20:19:18 UTC (rev 275905)
@@ -1,3 +1,67 @@
+2021-04-13 Said Abou-Hallawa <s...@apple.com>
+
+ [GPU Process] Make ImageBuffer calculate its memoryCost() from its size
+ https://bugs.webkit.org/show_bug.cgi?id=224306
+
+ Reviewed by Simon Fraser.
+
+ Instead of round-trip processes to get the backend memoryCost(), we can
+ calculate it from the size and the bytes alignment of each row in the
+ backend. These are static values so in the case of RemoteImageBufferProxy,
+ there is no need to ensure the backend is created in GPUP and it is mapped
+ in the Web Process.
+
+ * platform/graphics/ConcreteImageBuffer.h:
+ * platform/graphics/ImageBufferBackend.cpp:
+ (WebCore::ImageBufferBackend::calculateBackendSize):
+ (WebCore::ImageBufferBackend::calculateMemoryCost):
+ (WebCore::ImageBufferBackend::ImageBufferBackend):
+ * platform/graphics/ImageBufferBackend.h:
+ (WebCore::ImageBufferBackend::calculateExternalMemoryCost):
+ (WebCore::ImageBufferBackend::memoryCost const): Deleted.
+ (WebCore::ImageBufferBackend::externalMemoryCost const): Deleted.
+ (WebCore::ImageBufferBackend::bytesPerRow const): Deleted.
+ - This is the general case of the backend which is 4-bytes aligned rows.
+ - calculateSafeBackendSize() returns the size whose bytesPerRow does not
+ overflow unsigned and whose memoryCost does not not overflow size_t.
+
+ * platform/graphics/cairo/ImageBufferCairoImageSurfaceBackend.cpp:
+ (WebCore::ImageBufferCairoImageSurfaceBackend::calculateSafeBackendSize):
+ (WebCore::ImageBufferCairoImageSurfaceBackend::calculateBytesPerRow):
+ (WebCore::ImageBufferCairoImageSurfaceBackend::calculateMemoryCost):
+ (WebCore::ImageBufferCairoImageSurfaceBackend::create):
+ (WebCore::ImageBufferCairoImageSurfaceBackend::bytesPerRow const):
+ * platform/graphics/cairo/ImageBufferCairoImageSurfaceBackend.h:
+ cairo_format_stride_for_width() is used to calculate the bytesPerRow()
+ for Cairo port.
+
+ * platform/graphics/cg/ImageBufferCGBackend.cpp:
+ (WebCore::ImageBufferCGBackend::calculateBytesPerRow):
+ * platform/graphics/cg/ImageBufferCGBackend.h:
+ This is the CG case when the backend is 4-bytes aligned rows.
+
+ * platform/graphics/cg/ImageBufferCGBitmapBackend.cpp:
+ (WebCore::ImageBufferCGBitmapBackend::calculateSafeBackendSize):
+ (WebCore::ImageBufferCGBitmapBackend::calculateMemoryCost):
+ (WebCore::ImageBufferCGBitmapBackend::create):
+ (WebCore::ImageBufferCGBitmapBackend::bytesPerRow const):
+ * platform/graphics/cg/ImageBufferCGBitmapBackend.h:
+ This is the CG bitmap case where the backend is 4-bytes aligned rows.
+
+ * platform/graphics/cg/ImageBufferIOSurfaceBackend.cpp:
+ (WebCore::ImageBufferIOSurfaceBackend::calculateSafeBackendSize):
+ (WebCore::ImageBufferIOSurfaceBackend::calculateBytesPerRow):
+ (WebCore::ImageBufferIOSurfaceBackend::calculateMemoryCost):
+ (WebCore::ImageBufferIOSurfaceBackend::calculateExternalMemoryCost):
+ (WebCore::ImageBufferIOSurfaceBackend::create):
+ (WebCore::ImageBufferIOSurfaceBackend::context const):
+ (WebCore::ImageBufferIOSurfaceBackend::calculateBackendSize): Deleted.
+ (WebCore::ImageBufferIOSurfaceBackend::memoryCost const): Deleted.
+ (WebCore::ImageBufferIOSurfaceBackend::externalMemoryCost const): Deleted.
+ * platform/graphics/cg/ImageBufferIOSurfaceBackend.h:
+ IOSurfaceAlignProperty() is used to align the CG bytesPerRow to the proper
+ IOSurface alignment.
+
2021-04-13 Razvan Caliman <rcali...@apple.com>
Web Inspector: Forced color scheme should reset on page refresh
Modified: trunk/Source/WebCore/platform/graphics/ConcreteImageBuffer.h (275904 => 275905)
--- trunk/Source/WebCore/platform/graphics/ConcreteImageBuffer.h 2021-04-13 20:09:32 UTC (rev 275904)
+++ trunk/Source/WebCore/platform/graphics/ConcreteImageBuffer.h 2021-04-13 20:19:18 UTC (rev 275905)
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2020 Apple Inc. All rights reserved.
+ * Copyright (C) 2020-2021 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -111,16 +111,12 @@
size_t memoryCost() const override
{
- if (auto* backend = ensureBackendCreated())
- return m_backend->memoryCost();
- return 0;
+ return BackendType::calculateMemoryCost(m_parameters);
}
size_t externalMemoryCost() const override
{
- if (auto* backend = ensureBackendCreated())
- return m_backend->externalMemoryCost();
- return 0;
+ return BackendType::calculateExternalMemoryCost(m_parameters);
}
RefPtr<NativeImage> copyNativeImage(BackingStoreCopy copyBehavior = CopyBackingStore) const override
Modified: trunk/Source/WebCore/platform/graphics/ImageBufferBackend.cpp (275904 => 275905)
--- trunk/Source/WebCore/platform/graphics/ImageBufferBackend.cpp 2021-04-13 20:09:32 UTC (rev 275904)
+++ trunk/Source/WebCore/platform/graphics/ImageBufferBackend.cpp 2021-04-13 20:19:18 UTC (rev 275905)
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2020 Apple Inc. All rights reserved.
+ * Copyright (C) 2020-2021 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -31,28 +31,25 @@
namespace WebCore {
-ImageBufferBackend::ImageBufferBackend(const Parameters& parameters)
- : m_parameters(parameters)
+IntSize ImageBufferBackend::calculateBackendSize(const Parameters& parameters)
{
-}
-
-IntSize ImageBufferBackend::calculateBackendSize(const FloatSize& size, float resolutionScale)
-{
- FloatSize scaledSize = { ceilf(resolutionScale * size.width()), ceilf(resolutionScale * size.height()) };
+ FloatSize scaledSize = { ceilf(parameters.resolutionScale * parameters.logicalSize.width()), ceilf(parameters.resolutionScale * parameters.logicalSize.height()) };
if (scaledSize.isEmpty() || !scaledSize.isExpressibleAsIntSize())
return { };
- IntSize backendSize = IntSize(scaledSize);
+ return IntSize(scaledSize);
+}
- Checked<unsigned, RecordOverflow> bytesPerRow = 4 * Checked<unsigned, RecordOverflow>(backendSize.width());
- if (bytesPerRow.hasOverflowed())
- return { };
-
+size_t ImageBufferBackend::calculateMemoryCost(const IntSize& backendSize, unsigned bytesPerRow)
+{
+ ASSERT(!backendSize.isEmpty());
CheckedSize numBytes = Checked<unsigned, RecordOverflow>(backendSize.height()) * bytesPerRow;
- if (numBytes.hasOverflowed())
- return { };
+ return numBytes.unsafeGet();
+}
- return backendSize;
+ImageBufferBackend::ImageBufferBackend(const Parameters& parameters)
+ : m_parameters(parameters)
+{
}
RefPtr<NativeImage> ImageBufferBackend::sinkIntoNativeImage()
Modified: trunk/Source/WebCore/platform/graphics/ImageBufferBackend.h (275904 => 275905)
--- trunk/Source/WebCore/platform/graphics/ImageBufferBackend.h 2021-04-13 20:09:32 UTC (rev 275904)
+++ trunk/Source/WebCore/platform/graphics/ImageBufferBackend.h 2021-04-13 20:19:18 UTC (rev 275905)
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2020 Apple Inc. All rights reserved.
+ * Copyright (C) 2020-2021 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -87,7 +87,9 @@
WEBCORE_EXPORT virtual ~ImageBufferBackend() = default;
- WEBCORE_EXPORT static IntSize calculateBackendSize(const FloatSize&, float resolutionScale);
+ WEBCORE_EXPORT static IntSize calculateBackendSize(const Parameters&);
+ WEBCORE_EXPORT static size_t calculateMemoryCost(const IntSize& backendSize, unsigned bytesPerRow);
+ static size_t calculateExternalMemoryCost(const Parameters&) { return 0; }
virtual GraphicsContext& context() const = 0;
virtual void flushContext() { }
@@ -94,9 +96,6 @@
virtual IntSize backendSize() const { return { }; }
- virtual size_t memoryCost() const { return 4 * backendSize().area().unsafeGet(); }
- virtual size_t externalMemoryCost() const { return 0; }
-
virtual RefPtr<NativeImage> copyNativeImage(BackingStoreCopy) const = 0;
virtual RefPtr<Image> copyImage(BackingStoreCopy, PreserveResolution) const = 0;
@@ -136,7 +135,7 @@
protected:
WEBCORE_EXPORT ImageBufferBackend(const Parameters&);
- virtual unsigned bytesPerRow() const { return 4 * backendSize().width(); }
+ virtual unsigned bytesPerRow() const = 0;
template<typename T>
T toBackendCoordinates(T t) const
Modified: trunk/Source/WebCore/platform/graphics/cairo/ImageBufferCairoImageSurfaceBackend.cpp (275904 => 275905)
--- trunk/Source/WebCore/platform/graphics/cairo/ImageBufferCairoImageSurfaceBackend.cpp 2021-04-13 20:09:32 UTC (rev 275904)
+++ trunk/Source/WebCore/platform/graphics/cairo/ImageBufferCairoImageSurfaceBackend.cpp 2021-04-13 20:19:18 UTC (rev 275905)
@@ -3,7 +3,7 @@
* Copyright (C) 2007 Holger Hans Peter Freyther <ze...@selfish.org>
* Copyright (C) 2008, 2009 Dirk Schulze <k...@webkit.org>
* Copyright (C) 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserved.
- * Copyright (C) 2020 Apple Inc. All rights reserved.
+ * Copyright (C) 2020-2021 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -41,6 +41,30 @@
WTF_MAKE_ISO_ALLOCATED_IMPL(ImageBufferCairoImageSurfaceBackend);
+IntSize ImageBufferCairoImageSurfaceBackend::calculateSafeBackendSize(const Parameters& parameters)
+{
+ IntSize backendSize = calculateBackendSize(parameters);
+ if (backendSize.isEmpty())
+ return { };
+
+ if (backendSize.width() > cairoMaxImageSize || backendSize.height() > cairoMaxImageSize)
+ return { };
+
+ return backendSize;
+}
+
+unsigned ImageBufferCairoImageSurfaceBackend::calculateBytesPerRow(const IntSize& backendSize)
+{
+ ASSERT(!backendSize.isEmpty());
+ return cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, backendSize.width());
+}
+
+size_t ImageBufferCairoImageSurfaceBackend::calculateMemoryCost(const Parameters& parameters)
+{
+ IntSize backendSize = calculateBackendSize(parameters);
+ return ImageBufferBackend::calculateMemoryCost(backendSize, calculateBytesPerRow(backendSize));
+}
+
std::unique_ptr<ImageBufferCairoImageSurfaceBackend> ImageBufferCairoImageSurfaceBackend::create(const Parameters& parameters, const HostWindow*)
{
ASSERT(parameters.pixelFormat == PixelFormat::BGRA8);
@@ -47,8 +71,8 @@
static cairo_user_data_key_t s_surfaceDataKey;
- IntSize backendSize = calculateBackendSize(parameters.logicalSize, parameters.resolutionScale);
- if (backendSize.isEmpty() || backendSize.width() > cairoMaxImageSize || backendSize.height() > cairoMaxImageSize)
+ IntSize backendSize = calculateSafeBackendSize(parameters);
+ if (backendSize.isEmpty())
return nullptr;
int stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, backendSize.width());
@@ -77,6 +101,12 @@
ASSERT(cairo_surface_get_type(m_surface.get()) == CAIRO_SURFACE_TYPE_IMAGE);
}
+unsigned ImageBufferCairoImageSurfaceBackend::bytesPerRow() const
+{
+ IntSize backendSize = calculateBackendSize(m_parameters);
+ return calculateBytesPerRow(backendSize);
+}
+
void ImageBufferCairoImageSurfaceBackend::platformTransformColorSpace(const std::array<uint8_t, 256>& lookUpTable)
{
unsigned char* dataSrc = ""
Modified: trunk/Source/WebCore/platform/graphics/cairo/ImageBufferCairoImageSurfaceBackend.h (275904 => 275905)
--- trunk/Source/WebCore/platform/graphics/cairo/ImageBufferCairoImageSurfaceBackend.h 2021-04-13 20:09:32 UTC (rev 275904)
+++ trunk/Source/WebCore/platform/graphics/cairo/ImageBufferCairoImageSurfaceBackend.h 2021-04-13 20:19:18 UTC (rev 275905)
@@ -3,7 +3,7 @@
* Copyright (C) 2007 Holger Hans Peter Freyther <ze...@selfish.org>
* Copyright (C) 2008, 2009 Dirk Schulze <k...@webkit.org>
* Copyright (C) 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserved.
- * Copyright (C) 2020 Apple Inc. All rights reserved.
+ * Copyright (C) 2020-2021 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -40,6 +40,10 @@
WTF_MAKE_ISO_ALLOCATED(ImageBufferCairoImageSurfaceBackend);
WTF_MAKE_NONCOPYABLE(ImageBufferCairoImageSurfaceBackend);
public:
+ static IntSize calculateSafeBackendSize(const Parameters&);
+ static unsigned calculateBytesPerRow(const IntSize& backendSize);
+ static size_t calculateMemoryCost(const Parameters&);
+
static std::unique_ptr<ImageBufferCairoImageSurfaceBackend> create(const Parameters&, const HostWindow*);
static std::unique_ptr<ImageBufferCairoImageSurfaceBackend> create(const Parameters&, const GraphicsContext&);
@@ -46,6 +50,8 @@
private:
ImageBufferCairoImageSurfaceBackend(const Parameters&, RefPtr<cairo_surface_t>&&);
+ unsigned bytesPerRow() const override;
+
void platformTransformColorSpace(const std::array<uint8_t, 256>& lookUpTable) override;
};
Modified: trunk/Source/WebCore/platform/graphics/cg/ImageBufferCGBackend.cpp (275904 => 275905)
--- trunk/Source/WebCore/platform/graphics/cg/ImageBufferCGBackend.cpp 2021-04-13 20:09:32 UTC (rev 275904)
+++ trunk/Source/WebCore/platform/graphics/cg/ImageBufferCGBackend.cpp 2021-04-13 20:19:18 UTC (rev 275905)
@@ -60,6 +60,13 @@
RetainPtr<CGContextRef> m_context;
};
+unsigned ImageBufferCGBackend::calculateBytesPerRow(const IntSize& backendSize)
+{
+ ASSERT(!backendSize.isEmpty());
+ Checked<unsigned, RecordOverflow> bytesPerRow = (Checked<unsigned, RecordOverflow>(backendSize.width()) * 4);
+ return bytesPerRow.unsafeGet();
+}
+
RetainPtr<CGColorSpaceRef> ImageBufferCGBackend::contextColorSpace(const GraphicsContext& context)
{
#if PLATFORM(COCOA)
Modified: trunk/Source/WebCore/platform/graphics/cg/ImageBufferCGBackend.h (275904 => 275905)
--- trunk/Source/WebCore/platform/graphics/cg/ImageBufferCGBackend.h 2021-04-13 20:09:32 UTC (rev 275904)
+++ trunk/Source/WebCore/platform/graphics/cg/ImageBufferCGBackend.h 2021-04-13 20:19:18 UTC (rev 275905)
@@ -33,6 +33,8 @@
class WEBCORE_EXPORT ImageBufferCGBackend : public ImageBufferBackend {
public:
+ static unsigned calculateBytesPerRow(const IntSize& backendSize);
+
RefPtr<Image> copyImage(BackingStoreCopy = CopyBackingStore, PreserveResolution = PreserveResolution::No) const override;
RefPtr<Image> sinkIntoImage(PreserveResolution) override;
Modified: trunk/Source/WebCore/platform/graphics/cg/ImageBufferCGBitmapBackend.cpp (275904 => 275905)
--- trunk/Source/WebCore/platform/graphics/cg/ImageBufferCGBitmapBackend.cpp 2021-04-13 20:09:32 UTC (rev 275904)
+++ trunk/Source/WebCore/platform/graphics/cg/ImageBufferCGBitmapBackend.cpp 2021-04-13 20:19:18 UTC (rev 275905)
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2020 Apple Inc. All rights reserved.
+ * Copyright (C) 2020-2021 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -39,11 +39,34 @@
WTF_MAKE_ISO_ALLOCATED_IMPL(ImageBufferCGBitmapBackend);
+IntSize ImageBufferCGBitmapBackend::calculateSafeBackendSize(const Parameters& parameters)
+{
+ IntSize backendSize = calculateBackendSize(parameters);
+ if (backendSize.isEmpty())
+ return backendSize;
+
+ Checked<unsigned, RecordOverflow> bytesPerRow = 4 * Checked<unsigned, RecordOverflow>(backendSize.width());
+ if (bytesPerRow.hasOverflowed())
+ return { };
+
+ CheckedSize numBytes = Checked<unsigned, RecordOverflow>(backendSize.height()) * bytesPerRow;
+ if (numBytes.hasOverflowed())
+ return { };
+
+ return backendSize;
+}
+
+size_t ImageBufferCGBitmapBackend::calculateMemoryCost(const Parameters& parameters)
+{
+ IntSize backendSize = calculateBackendSize(parameters);
+ return ImageBufferBackend::calculateMemoryCost(backendSize, calculateBytesPerRow(backendSize));
+}
+
std::unique_ptr<ImageBufferCGBitmapBackend> ImageBufferCGBitmapBackend::create(const Parameters& parameters, CGColorSpaceRef cgColorSpace, const HostWindow*)
{
ASSERT(parameters.pixelFormat == PixelFormat::BGRA8);
- IntSize backendSize = calculateBackendSize(parameters.logicalSize, parameters.resolutionScale);
+ IntSize backendSize = calculateSafeBackendSize(parameters);
if (backendSize.isEmpty())
return nullptr;
@@ -109,6 +132,12 @@
return { static_cast<int>(CGBitmapContextGetWidth(cgContext)), static_cast<int>(CGBitmapContextGetHeight(cgContext)) };
}
+unsigned ImageBufferCGBitmapBackend::bytesPerRow() const
+{
+ IntSize backendSize = calculateBackendSize(m_parameters);
+ return calculateBytesPerRow(backendSize);
+}
+
RefPtr<NativeImage> ImageBufferCGBitmapBackend::copyNativeImage(BackingStoreCopy copyBehavior) const
{
switch (copyBehavior) {
Modified: trunk/Source/WebCore/platform/graphics/cg/ImageBufferCGBitmapBackend.h (275904 => 275905)
--- trunk/Source/WebCore/platform/graphics/cg/ImageBufferCGBitmapBackend.h 2021-04-13 20:09:32 UTC (rev 275904)
+++ trunk/Source/WebCore/platform/graphics/cg/ImageBufferCGBitmapBackend.h 2021-04-13 20:19:18 UTC (rev 275905)
@@ -36,6 +36,9 @@
WTF_MAKE_ISO_ALLOCATED(ImageBufferCGBitmapBackend);
WTF_MAKE_NONCOPYABLE(ImageBufferCGBitmapBackend);
public:
+ static IntSize calculateSafeBackendSize(const Parameters&);
+ static size_t calculateMemoryCost(const Parameters&);
+
static std::unique_ptr<ImageBufferCGBitmapBackend> create(const Parameters&, CGColorSpaceRef, const HostWindow*);
static std::unique_ptr<ImageBufferCGBitmapBackend> create(const Parameters&, const HostWindow*);
static std::unique_ptr<ImageBufferCGBitmapBackend> create(const Parameters&, const GraphicsContext&);
@@ -56,6 +59,8 @@
private:
ImageBufferCGBitmapBackend(const Parameters&, void* data, RetainPtr<CGDataProviderRef>&&, std::unique_ptr<GraphicsContext>&&);
+ unsigned bytesPerRow() const override;
+
void* m_data;
RetainPtr<CGDataProviderRef> m_dataProvider;
std::unique_ptr<GraphicsContext> m_context;
Modified: trunk/Source/WebCore/platform/graphics/cg/ImageBufferIOSurfaceBackend.cpp (275904 => 275905)
--- trunk/Source/WebCore/platform/graphics/cg/ImageBufferIOSurfaceBackend.cpp 2021-04-13 20:09:32 UTC (rev 275904)
+++ trunk/Source/WebCore/platform/graphics/cg/ImageBufferIOSurfaceBackend.cpp 2021-04-13 20:19:18 UTC (rev 275905)
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2020 Apple Inc. All rights reserved.
+ * Copyright (C) 2020-2021 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -41,9 +41,9 @@
WTF_MAKE_ISO_ALLOCATED_IMPL(ImageBufferIOSurfaceBackend);
-IntSize ImageBufferIOSurfaceBackend::calculateBackendSize(const FloatSize& size, float resolutionScale)
+IntSize ImageBufferIOSurfaceBackend::calculateSafeBackendSize(const Parameters& parameters)
{
- IntSize backendSize = ImageBufferCGBackend::calculateBackendSize(size, resolutionScale);
+ IntSize backendSize = calculateBackendSize(parameters);
if (backendSize.isEmpty())
return { };
@@ -54,6 +54,23 @@
return backendSize;
}
+unsigned ImageBufferIOSurfaceBackend::calculateBytesPerRow(const IntSize& backendSize)
+{
+ unsigned bytesPerRow = ImageBufferCGBackend::calculateBytesPerRow(backendSize);
+ return IOSurfaceAlignProperty(kIOSurfaceBytesPerRow, bytesPerRow);
+}
+
+size_t ImageBufferIOSurfaceBackend::calculateMemoryCost(const Parameters& parameters)
+{
+ IntSize backendSize = calculateBackendSize(parameters);
+ return ImageBufferBackend::calculateMemoryCost(backendSize, calculateBytesPerRow(backendSize));
+}
+
+size_t ImageBufferIOSurfaceBackend::calculateExternalMemoryCost(const Parameters& parameters)
+{
+ return calculateMemoryCost(parameters);
+}
+
RetainPtr<CGColorSpaceRef> ImageBufferIOSurfaceBackend::contextColorSpace(const GraphicsContext& context)
{
CGContextRef cgContext = context.platformContext();
@@ -66,7 +83,7 @@
std::unique_ptr<ImageBufferIOSurfaceBackend> ImageBufferIOSurfaceBackend::create(const Parameters& parameters, CGColorSpaceRef cgColorSpace, const HostWindow* hostWindow)
{
- IntSize backendSize = calculateBackendSize(parameters.logicalSize, parameters.resolutionScale);
+ IntSize backendSize = calculateSafeBackendSize(parameters);
if (backendSize.isEmpty())
return nullptr;
@@ -106,7 +123,6 @@
GraphicsContext& ImageBufferIOSurfaceBackend::context() const
{
-
GraphicsContext& context = m_surface->ensureGraphicsContext();
if (m_needsSetupContext) {
m_needsSetupContext = false;
@@ -125,16 +141,6 @@
return m_surface->size();
}
-size_t ImageBufferIOSurfaceBackend::memoryCost() const
-{
- return m_surface->totalBytes();
-}
-
-size_t ImageBufferIOSurfaceBackend::externalMemoryCost() const
-{
- return memoryCost();
-}
-
unsigned ImageBufferIOSurfaceBackend::bytesPerRow() const
{
return m_surface->bytesPerRow();
Modified: trunk/Source/WebCore/platform/graphics/cg/ImageBufferIOSurfaceBackend.h (275904 => 275905)
--- trunk/Source/WebCore/platform/graphics/cg/ImageBufferIOSurfaceBackend.h 2021-04-13 20:09:32 UTC (rev 275904)
+++ trunk/Source/WebCore/platform/graphics/cg/ImageBufferIOSurfaceBackend.h 2021-04-13 20:19:18 UTC (rev 275905)
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2020 Apple Inc. All rights reserved.
+ * Copyright (C) 2020-2021 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -37,8 +37,11 @@
WTF_MAKE_ISO_ALLOCATED(ImageBufferIOSurfaceBackend);
WTF_MAKE_NONCOPYABLE(ImageBufferIOSurfaceBackend);
public:
- static IntSize calculateBackendSize(const FloatSize& logicalSize, float resolutionScale);
-
+ static IntSize calculateSafeBackendSize(const Parameters&);
+ static unsigned calculateBytesPerRow(const IntSize& backendSize);
+ static size_t calculateMemoryCost(const Parameters&);
+ static size_t calculateExternalMemoryCost(const Parameters&);
+
static std::unique_ptr<ImageBufferIOSurfaceBackend> create(const Parameters&, CGColorSpaceRef, const HostWindow*);
static std::unique_ptr<ImageBufferIOSurfaceBackend> create(const Parameters&, const HostWindow*);
static std::unique_ptr<ImageBufferIOSurfaceBackend> create(const Parameters&, const GraphicsContext&);
@@ -50,9 +53,6 @@
IntSize backendSize() const override;
- size_t memoryCost() const override;
- size_t externalMemoryCost() const override;
-
RefPtr<NativeImage> copyNativeImage(BackingStoreCopy = CopyBackingStore) const override;
RefPtr<NativeImage> sinkIntoNativeImage() override;
Modified: trunk/Source/WebKit/ChangeLog (275904 => 275905)
--- trunk/Source/WebKit/ChangeLog 2021-04-13 20:09:32 UTC (rev 275904)
+++ trunk/Source/WebKit/ChangeLog 2021-04-13 20:19:18 UTC (rev 275905)
@@ -1,3 +1,41 @@
+2021-04-13 Said Abou-Hallawa <s...@apple.com>
+
+ [GPU Process] Make ImageBuffer calculate its memoryCost() from its size
+ https://bugs.webkit.org/show_bug.cgi?id=224306
+
+ Reviewed by Simon Fraser.
+
+ * Shared/ShareableBitmap.h:
+ Make ShareableBitmap::calculateBytesPerRow() public.
+
+ * WebProcess/GPU/graphics/ImageBufferShareableBitmapBackend.cpp:
+ (WebKit::ImageBufferShareableBitmapBackend::configuration):
+ (WebKit::ImageBufferShareableBitmapBackend::calculateSafeBackendSize):
+ (WebKit::ImageBufferShareableBitmapBackend::calculateBytesPerRow):
+ (WebKit::ImageBufferShareableBitmapBackend::calculateMemoryCost):
+ (WebKit::ImageBufferShareableBitmapBackend::create):
+ * WebProcess/GPU/graphics/ImageBufferShareableBitmapBackend.h:
+ ShareableBitmap::calculateBytesPerRow() is used to get the bytesPerRow()
+ by giving it the scaled backend size.
+
+ * WebProcess/GPU/graphics/RemoteImageBufferProxy.h:
+ (WebKit::RemoteImageBufferProxy::create):
+ Use the new name of the function calculateSafeBackendSize().
+
+ * WebProcess/GPU/graphics/cocoa/ImageBufferShareableIOSurfaceBackend.cpp:
+ (WebKit::ImageBufferShareableIOSurfaceBackend::calculateSafeBackendSize):
+ (WebKit::ImageBufferShareableIOSurfaceBackend::calculateMemoryCost):
+ (WebKit::ImageBufferShareableIOSurfaceBackend::calculateExternalMemoryCost):
+ (WebKit::ImageBufferShareableIOSurfaceBackend::bytesPerRow const):
+ * WebProcess/GPU/graphics/cocoa/ImageBufferShareableIOSurfaceBackend.h:
+ Implement these static functions and make them call the corresponding
+ functions from ImageBufferIOSurfaceBackend because this class is derived
+ from ImageBufferBackend.
+
+ * WebProcess/GPU/graphics/cocoa/ImageBufferShareableMappedIOSurfaceBackend.cpp:
+ (WebKit::ImageBufferShareableMappedIOSurfaceBackend::create):
+ Use the new name of the function calculateSafeBackendSize().
+
2021-04-13 Alex Christensen <achristen...@webkit.org>
Revert r275172
Modified: trunk/Source/WebKit/Shared/ShareableBitmap.h (275904 => 275905)
--- trunk/Source/WebKit/Shared/ShareableBitmap.h 2021-04-13 20:09:32 UTC (rev 275904)
+++ trunk/Source/WebKit/Shared/ShareableBitmap.h 2021-04-13 20:19:18 UTC (rev 275905)
@@ -89,6 +89,10 @@
Configuration m_configuration;
};
+ static Checked<unsigned, RecordOverflow> numBytesForSize(WebCore::IntSize, const ShareableBitmap::Configuration&);
+ static Checked<unsigned, RecordOverflow> calculateBytesPerRow(WebCore::IntSize, const Configuration&);
+ static Checked<unsigned, RecordOverflow> calculateBytesPerPixel(const Configuration&);
+
// Create a shareable bitmap that uses malloced memory.
static RefPtr<ShareableBitmap> create(const WebCore::IntSize&, Configuration);
@@ -151,10 +155,6 @@
ShareableBitmap(const WebCore::IntSize&, Configuration, void*);
ShareableBitmap(const WebCore::IntSize&, Configuration, RefPtr<SharedMemory>);
- static Checked<unsigned, RecordOverflow> numBytesForSize(WebCore::IntSize, const ShareableBitmap::Configuration&);
- static Checked<unsigned, RecordOverflow> calculateBytesPerRow(WebCore::IntSize, const Configuration&);
- static Checked<unsigned, RecordOverflow> calculateBytesPerPixel(const Configuration&);
-
#if USE(CG)
RetainPtr<CGImageRef> createCGImage(CGDataProviderRef) const;
static void releaseBitmapContextData(void* typelessBitmap, void* typelessData);
Modified: trunk/Source/WebKit/WebProcess/GPU/graphics/ImageBufferShareableBitmapBackend.cpp (275904 => 275905)
--- trunk/Source/WebKit/WebProcess/GPU/graphics/ImageBufferShareableBitmapBackend.cpp 2021-04-13 20:09:32 UTC (rev 275904)
+++ trunk/Source/WebKit/WebProcess/GPU/graphics/ImageBufferShareableBitmapBackend.cpp 2021-04-13 20:19:18 UTC (rev 275905)
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2020 Apple Inc. All rights reserved.
+ * Copyright (C) 2020-2021 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -43,19 +43,54 @@
WTF_MAKE_ISO_ALLOCATED_IMPL(ImageBufferShareableBitmapBackend);
+ShareableBitmap::Configuration ImageBufferShareableBitmapBackend::configuration(const Parameters& parameters)
+{
+ ShareableBitmap::Configuration configuration;
+#if PLATFORM(COCOA)
+ configuration.colorSpace = { cachedCGColorSpace(parameters.colorSpace) };
+#endif
+ return configuration;
+}
+
+IntSize ImageBufferShareableBitmapBackend::calculateSafeBackendSize(const Parameters& parameters)
+{
+ IntSize backendSize = calculateBackendSize(parameters);
+ if (backendSize.isEmpty())
+ return { };
+
+ Checked<unsigned, RecordOverflow> bytesPerRow = ShareableBitmap::calculateBytesPerRow(backendSize, configuration(parameters));
+ if (bytesPerRow.hasOverflowed())
+ return { };
+
+ CheckedSize numBytes = Checked<unsigned, RecordOverflow>(backendSize.height()) * bytesPerRow;
+ if (numBytes.hasOverflowed())
+ return { };
+
+ return backendSize;
+}
+
+unsigned ImageBufferShareableBitmapBackend::calculateBytesPerRow(const Parameters& parameters, const IntSize& backendSize)
+{
+ ASSERT(!backendSize.isEmpty());
+ Checked<unsigned, RecordOverflow> bytesPerRow = ShareableBitmap::calculateBytesPerRow(backendSize, configuration(parameters));
+ return bytesPerRow.unsafeGet();
+}
+
+size_t ImageBufferShareableBitmapBackend::calculateMemoryCost(const Parameters& parameters)
+{
+ IntSize backendSize = calculateBackendSize(parameters);
+ return ImageBufferBackend::calculateMemoryCost(backendSize, calculateBytesPerRow(parameters, backendSize));
+}
+
std::unique_ptr<ImageBufferShareableBitmapBackend> ImageBufferShareableBitmapBackend::create(const Parameters& parameters, const HostWindow*)
{
ASSERT(parameters.pixelFormat == PixelFormat::BGRA8);
- IntSize backendSize = calculateBackendSize(parameters.logicalSize, parameters.resolutionScale);
+ IntSize backendSize = calculateSafeBackendSize(parameters);
if (backendSize.isEmpty())
return nullptr;
- ShareableBitmap::Configuration configuration;
-#if PLATFORM(COCOA)
- configuration.colorSpace = { cachedCGColorSpace(parameters.colorSpace) };
-#endif
- auto bitmap = ShareableBitmap::createShareable(backendSize, configuration);
+ auto bitmap = ShareableBitmap::createShareable(backendSize, configuration(parameters));
if (!bitmap)
return nullptr;
Modified: trunk/Source/WebKit/WebProcess/GPU/graphics/ImageBufferShareableBitmapBackend.h (275904 => 275905)
--- trunk/Source/WebKit/WebProcess/GPU/graphics/ImageBufferShareableBitmapBackend.h 2021-04-13 20:09:32 UTC (rev 275904)
+++ trunk/Source/WebKit/WebProcess/GPU/graphics/ImageBufferShareableBitmapBackend.h 2021-04-13 20:19:18 UTC (rev 275905)
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2020 Apple Inc. All rights reserved.
+ * Copyright (C) 2020-2021 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -43,6 +43,11 @@
WTF_MAKE_ISO_ALLOCATED(ImageBufferShareableBitmapBackend);
WTF_MAKE_NONCOPYABLE(ImageBufferShareableBitmapBackend);
public:
+ static ShareableBitmap::Configuration configuration(const Parameters&);
+ static WebCore::IntSize calculateSafeBackendSize(const Parameters&);
+ static unsigned calculateBytesPerRow(const Parameters&, const WebCore::IntSize& backendSize);
+ static size_t calculateMemoryCost(const Parameters&);
+
static std::unique_ptr<ImageBufferShareableBitmapBackend> create(const Parameters&, const WebCore::HostWindow*);
static std::unique_ptr<ImageBufferShareableBitmapBackend> create(const Parameters&, ImageBufferBackendHandle);
Modified: trunk/Source/WebKit/WebProcess/GPU/graphics/RemoteImageBufferProxy.h (275904 => 275905)
--- trunk/Source/WebKit/WebProcess/GPU/graphics/RemoteImageBufferProxy.h 2021-04-13 20:09:32 UTC (rev 275904)
+++ trunk/Source/WebKit/WebProcess/GPU/graphics/RemoteImageBufferProxy.h 2021-04-13 20:19:18 UTC (rev 275905)
@@ -55,10 +55,9 @@
public:
static RefPtr<RemoteImageBufferProxy> create(const WebCore::FloatSize& size, float resolutionScale, WebCore::DestinationColorSpace colorSpace, WebCore::PixelFormat pixelFormat, RemoteRenderingBackendProxy& remoteRenderingBackendProxy)
{
- if (BackendType::calculateBackendSize(size, resolutionScale).isEmpty())
+ auto parameters = WebCore::ImageBufferBackend::Parameters { size, resolutionScale, colorSpace, pixelFormat };
+ if (BackendType::calculateSafeBackendSize(parameters).isEmpty())
return nullptr;
-
- auto parameters = WebCore::ImageBufferBackend::Parameters { size, resolutionScale, colorSpace, pixelFormat };
return adoptRef(new RemoteImageBufferProxy(parameters, remoteRenderingBackendProxy));
}
Modified: trunk/Source/WebKit/WebProcess/GPU/graphics/cocoa/ImageBufferShareableIOSurfaceBackend.cpp (275904 => 275905)
--- trunk/Source/WebKit/WebProcess/GPU/graphics/cocoa/ImageBufferShareableIOSurfaceBackend.cpp 2021-04-13 20:09:32 UTC (rev 275904)
+++ trunk/Source/WebKit/WebProcess/GPU/graphics/cocoa/ImageBufferShareableIOSurfaceBackend.cpp 2021-04-13 20:19:18 UTC (rev 275905)
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2020 Apple Inc. All rights reserved.
+ * Copyright (C) 2020-2021 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -29,6 +29,7 @@
#if HAVE(IOSURFACE)
#include <WebCore/GraphicsContextCG.h>
+#include <WebCore/ImageBufferIOSurfaceBackend.h>
#include <wtf/IsoMallocInlines.h>
#include <wtf/StdLibExtras.h>
@@ -37,6 +38,21 @@
WTF_MAKE_ISO_ALLOCATED_IMPL(ImageBufferShareableIOSurfaceBackend);
+IntSize ImageBufferShareableIOSurfaceBackend::calculateSafeBackendSize(const Parameters& parameters)
+{
+ return ImageBufferIOSurfaceBackend::calculateSafeBackendSize(parameters);
+}
+
+size_t ImageBufferShareableIOSurfaceBackend::calculateMemoryCost(const Parameters& parameters)
+{
+ return ImageBufferIOSurfaceBackend::calculateMemoryCost(parameters);
+}
+
+size_t ImageBufferShareableIOSurfaceBackend::calculateExternalMemoryCost(const Parameters& parameters)
+{
+ return ImageBufferIOSurfaceBackend::calculateExternalMemoryCost(parameters);
+}
+
std::unique_ptr<ImageBufferShareableIOSurfaceBackend> ImageBufferShareableIOSurfaceBackend::create(const Parameters& parameters, ImageBufferBackendHandle handle)
{
if (!WTF::holds_alternative<MachSendRight>(handle)) {
@@ -58,6 +74,12 @@
return *(GraphicsContext*)nullptr;
}
+unsigned ImageBufferShareableIOSurfaceBackend::bytesPerRow() const
+{
+ IntSize backendSize = calculateBackendSize(m_parameters);
+ return ImageBufferIOSurfaceBackend::calculateBytesPerRow(backendSize);
+}
+
RefPtr<NativeImage> ImageBufferShareableIOSurfaceBackend::copyNativeImage(BackingStoreCopy) const
{
RELEASE_ASSERT_NOT_REACHED();
Modified: trunk/Source/WebKit/WebProcess/GPU/graphics/cocoa/ImageBufferShareableIOSurfaceBackend.h (275904 => 275905)
--- trunk/Source/WebKit/WebProcess/GPU/graphics/cocoa/ImageBufferShareableIOSurfaceBackend.h 2021-04-13 20:09:32 UTC (rev 275904)
+++ trunk/Source/WebKit/WebProcess/GPU/graphics/cocoa/ImageBufferShareableIOSurfaceBackend.h 2021-04-13 20:19:18 UTC (rev 275905)
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2020 Apple Inc. All rights reserved.
+ * Copyright (C) 2020-2021 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -38,6 +38,10 @@
WTF_MAKE_ISO_ALLOCATED(ImageBufferShareableIOSurfaceBackend);
WTF_MAKE_NONCOPYABLE(ImageBufferShareableIOSurfaceBackend);
public:
+ static WebCore::IntSize calculateSafeBackendSize(const Parameters&);
+ static size_t calculateMemoryCost(const Parameters&);
+ static size_t calculateExternalMemoryCost(const Parameters&);
+
static std::unique_ptr<ImageBufferShareableIOSurfaceBackend> create(const Parameters&, ImageBufferBackendHandle);
ImageBufferShareableIOSurfaceBackend(const Parameters& parameters, ImageBufferBackendHandle&& handle)
@@ -64,6 +68,8 @@
static constexpr WebCore::RenderingMode renderingMode = WebCore::RenderingMode::Accelerated;
private:
+ unsigned bytesPerRow() const override;
+
ImageBufferBackendHandle m_handle;
};
Modified: trunk/Source/WebKit/WebProcess/GPU/graphics/cocoa/ImageBufferShareableMappedIOSurfaceBackend.cpp (275904 => 275905)
--- trunk/Source/WebKit/WebProcess/GPU/graphics/cocoa/ImageBufferShareableMappedIOSurfaceBackend.cpp 2021-04-13 20:09:32 UTC (rev 275904)
+++ trunk/Source/WebKit/WebProcess/GPU/graphics/cocoa/ImageBufferShareableMappedIOSurfaceBackend.cpp 2021-04-13 20:19:18 UTC (rev 275905)
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2020 Apple Inc. All rights reserved.
+ * Copyright (C) 2020-2021 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -41,7 +41,7 @@
std::unique_ptr<ImageBufferShareableMappedIOSurfaceBackend> ImageBufferShareableMappedIOSurfaceBackend::create(const Parameters& parameters, const HostWindow*)
{
- IntSize backendSize = calculateBackendSize(parameters.logicalSize, parameters.resolutionScale);
+ IntSize backendSize = calculateSafeBackendSize(parameters);
if (backendSize.isEmpty())
return nullptr;