WebKit Bugzilla
New
Browse
Search+
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
[patch]
Patch
bug-224306-20210411170237.patch (text/plain), 39.14 KB, created by
Said Abou-Hallawa
on 2021-04-11 17:02:38 PDT
(
hide
)
Description:
Patch
Filename:
MIME Type:
Creator:
Said Abou-Hallawa
Created:
2021-04-11 17:02:38 PDT
Size:
39.14 KB
patch
obsolete
>Subversion Revision: 275810 >diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog >index 4656fba5ae49bd823f7bcd0b5e80cd2e644f5495..6444a14feeb4fc60858ac76c9ef1b7133dd81b58 100644 >--- a/Source/WebCore/ChangeLog >+++ b/Source/WebCore/ChangeLog >@@ -1,3 +1,67 @@ >+2021-04-11 Said Abou-Hallawa <said@apple.com> >+ >+ [GPU Process] Make ImageBuffer calculate its memoryCost() from its size >+ https://bugs.webkit.org/show_bug.cgi?id=224306 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ 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-11 Darin Adler <darin@apple.com> > > [Mac] Add a missing null check to slider thumb focus rendering >diff --git a/Source/WebKit/ChangeLog b/Source/WebKit/ChangeLog >index 18c9fde36e0913b69eef87ef0277b352cecb1ad5..eb48694d1b0d147897a97765bafdec06b9274d64 100644 >--- a/Source/WebKit/ChangeLog >+++ b/Source/WebKit/ChangeLog >@@ -1,3 +1,41 @@ >+2021-04-11 Said Abou-Hallawa <said@apple.com> >+ >+ [GPU Process] Make ImageBuffer calculate its memoryCost() from its size >+ https://bugs.webkit.org/show_bug.cgi?id=224306 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ * 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-11 Sam Weinig <weinig@apple.com> > > Simplify WebKitTestRunner preference reset to be more like DRT >diff --git a/Source/WebCore/platform/graphics/ConcreteImageBuffer.h b/Source/WebCore/platform/graphics/ConcreteImageBuffer.h >index 3a5114b7320b7c90d9204976ce402ff008ee57b0..d0f00ecc92a0e87ea8fb9172e489a796ad01b223 100644 >--- a/Source/WebCore/platform/graphics/ConcreteImageBuffer.h >+++ b/Source/WebCore/platform/graphics/ConcreteImageBuffer.h >@@ -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 @@ protected: > > 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 >diff --git a/Source/WebCore/platform/graphics/ImageBufferBackend.cpp b/Source/WebCore/platform/graphics/ImageBufferBackend.cpp >index 3794de77be63a999a3b971c78bfdce1d4caa2b0b..2e66650f96af2738327ea9221e943646392b9a37 100644 >--- a/Source/WebCore/platform/graphics/ImageBufferBackend.cpp >+++ b/Source/WebCore/platform/graphics/ImageBufferBackend.cpp >@@ -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); >- >- Checked<unsigned, RecordOverflow> bytesPerRow = 4 * Checked<unsigned, RecordOverflow>(backendSize.width()); >- if (bytesPerRow.hasOverflowed()) >- return { }; >+ return IntSize(scaledSize); >+} > >+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() >diff --git a/Source/WebCore/platform/graphics/ImageBufferBackend.h b/Source/WebCore/platform/graphics/ImageBufferBackend.h >index 31ce97757b5d2f9800b15763ce16be1c7869f16c..dce4b7a1db911c13466038d13774a39fa93aab16 100644 >--- a/Source/WebCore/platform/graphics/ImageBufferBackend.h >+++ b/Source/WebCore/platform/graphics/ImageBufferBackend.h >@@ -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,16 +87,15 @@ public: > > 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() { } > > 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 @@ public: > 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 >diff --git a/Source/WebCore/platform/graphics/cairo/ImageBufferCairoImageSurfaceBackend.cpp b/Source/WebCore/platform/graphics/cairo/ImageBufferCairoImageSurfaceBackend.cpp >index 47a45dcc2e82dd6d0cacb5126606abf7195c1041..17b7973ba14568eae98f4193cabaeb244c154da4 100644 >--- a/Source/WebCore/platform/graphics/cairo/ImageBufferCairoImageSurfaceBackend.cpp >+++ b/Source/WebCore/platform/graphics/cairo/ImageBufferCairoImageSurfaceBackend.cpp >@@ -3,7 +3,7 @@ > * Copyright (C) 2007 Holger Hans Peter Freyther <zecke@selfish.org> > * Copyright (C) 2008, 2009 Dirk Schulze <krit@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,14 +41,38 @@ namespace WebCore { > > 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); > > 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 @@ ImageBufferCairoImageSurfaceBackend::ImageBufferCairoImageSurfaceBackend(const P > 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 = cairo_image_surface_get_data(m_surface.get()); >diff --git a/Source/WebCore/platform/graphics/cairo/ImageBufferCairoImageSurfaceBackend.h b/Source/WebCore/platform/graphics/cairo/ImageBufferCairoImageSurfaceBackend.h >index 865cc69b2d5338545f37e4193cb94f1980be73a4..bde99e34f60aa34634cb2b62807538feb64497f8 100644 >--- a/Source/WebCore/platform/graphics/cairo/ImageBufferCairoImageSurfaceBackend.h >+++ b/Source/WebCore/platform/graphics/cairo/ImageBufferCairoImageSurfaceBackend.h >@@ -3,7 +3,7 @@ > * Copyright (C) 2007 Holger Hans Peter Freyther <zecke@selfish.org> > * Copyright (C) 2008, 2009 Dirk Schulze <krit@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,12 +40,18 @@ class ImageBufferCairoImageSurfaceBackend : public ImageBufferCairoSurfaceBacken > 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&); > > private: > ImageBufferCairoImageSurfaceBackend(const Parameters&, RefPtr<cairo_surface_t>&&); > >+ unsigned bytesPerRow() const override; >+ > void platformTransformColorSpace(const std::array<uint8_t, 256>& lookUpTable) override; > }; > >diff --git a/Source/WebCore/platform/graphics/cg/ImageBufferCGBackend.cpp b/Source/WebCore/platform/graphics/cg/ImageBufferCGBackend.cpp >index c5c28421fdbc078d38dd4e8038c1f33e2af405f2..c4a3921f46d43d72914ef57b3a6728270cdc0060 100644 >--- a/Source/WebCore/platform/graphics/cg/ImageBufferCGBackend.cpp >+++ b/Source/WebCore/platform/graphics/cg/ImageBufferCGBackend.cpp >@@ -60,6 +60,13 @@ private: > 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) >diff --git a/Source/WebCore/platform/graphics/cg/ImageBufferCGBackend.h b/Source/WebCore/platform/graphics/cg/ImageBufferCGBackend.h >index b26ae084347b9e233404600c2ea4a4a28b1e1ba7..54746860ded7e40a41423d9c6a0acee4d9c32863 100644 >--- a/Source/WebCore/platform/graphics/cg/ImageBufferCGBackend.h >+++ b/Source/WebCore/platform/graphics/cg/ImageBufferCGBackend.h >@@ -33,6 +33,8 @@ namespace WebCore { > > 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; > >diff --git a/Source/WebCore/platform/graphics/cg/ImageBufferCGBitmapBackend.cpp b/Source/WebCore/platform/graphics/cg/ImageBufferCGBitmapBackend.cpp >index 9d538befcd8e038f1a1a97a2a7784130f328ca45..1e4d824912324784a840def508bafb19c211eb9a 100644 >--- a/Source/WebCore/platform/graphics/cg/ImageBufferCGBitmapBackend.cpp >+++ b/Source/WebCore/platform/graphics/cg/ImageBufferCGBitmapBackend.cpp >@@ -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 @@ namespace WebCore { > > 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 @@ IntSize ImageBufferCGBitmapBackend::backendSize() const > 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) { >diff --git a/Source/WebCore/platform/graphics/cg/ImageBufferCGBitmapBackend.h b/Source/WebCore/platform/graphics/cg/ImageBufferCGBitmapBackend.h >index 8f3323e7dcec6355acb7d5b99c20787715c86ba8..790d342878fc037d45518fa29a6cd6eccd638a49 100644 >--- a/Source/WebCore/platform/graphics/cg/ImageBufferCGBitmapBackend.h >+++ b/Source/WebCore/platform/graphics/cg/ImageBufferCGBitmapBackend.h >@@ -36,6 +36,9 @@ class ImageBufferCGBitmapBackend : public ImageBufferCGBackend { > 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 @@ public: > 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; >diff --git a/Source/WebCore/platform/graphics/cg/ImageBufferIOSurfaceBackend.cpp b/Source/WebCore/platform/graphics/cg/ImageBufferIOSurfaceBackend.cpp >index 6c3b7c74b46e126e79d9f16220b3a2fad9edd9a1..8dfecb903168e72bf81bb80470aabb1b79c46877 100644 >--- a/Source/WebCore/platform/graphics/cg/ImageBufferIOSurfaceBackend.cpp >+++ b/Source/WebCore/platform/graphics/cg/ImageBufferIOSurfaceBackend.cpp >@@ -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 @@ namespace WebCore { > > 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 @@ IntSize ImageBufferIOSurfaceBackend::calculateBackendSize(const FloatSize& size, > 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 @@ RetainPtr<CGColorSpaceRef> ImageBufferIOSurfaceBackend::contextColorSpace(const > > 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 @@ ImageBufferIOSurfaceBackend::ImageBufferIOSurfaceBackend(const Parameters& param > > GraphicsContext& ImageBufferIOSurfaceBackend::context() const > { >- > GraphicsContext& context = m_surface->ensureGraphicsContext(); > if (m_needsSetupContext) { > m_needsSetupContext = false; >@@ -125,16 +141,6 @@ IntSize ImageBufferIOSurfaceBackend::backendSize() const > 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(); >diff --git a/Source/WebCore/platform/graphics/cg/ImageBufferIOSurfaceBackend.h b/Source/WebCore/platform/graphics/cg/ImageBufferIOSurfaceBackend.h >index 4859df6fc525d85c328c145f079178356909e25d..b9d15690411c888f9e00a63986b5565a12893d3a 100644 >--- a/Source/WebCore/platform/graphics/cg/ImageBufferIOSurfaceBackend.h >+++ b/Source/WebCore/platform/graphics/cg/ImageBufferIOSurfaceBackend.h >@@ -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 @@ class WEBCORE_EXPORT ImageBufferIOSurfaceBackend : public ImageBufferCGBackend { > 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 @@ public: > > 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; > >diff --git a/Source/WebKit/Shared/ShareableBitmap.h b/Source/WebKit/Shared/ShareableBitmap.h >index c7193bccb9feb061fb44cd295e6b3bd4b7e3bd91..45db88f6e44d895bfac178c593252d1a54abcf6e 100644 >--- a/Source/WebKit/Shared/ShareableBitmap.h >+++ b/Source/WebKit/Shared/ShareableBitmap.h >@@ -89,6 +89,10 @@ public: > 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 @@ private: > 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); >diff --git a/Source/WebKit/WebProcess/GPU/graphics/ImageBufferShareableBitmapBackend.cpp b/Source/WebKit/WebProcess/GPU/graphics/ImageBufferShareableBitmapBackend.cpp >index e19a9abcc50a42c10626b30e9bdfed07e39e0a9b..162d03bd487e40c11e989b399ec28289f5919bd8 100644 >--- a/Source/WebKit/WebProcess/GPU/graphics/ImageBufferShareableBitmapBackend.cpp >+++ b/Source/WebKit/WebProcess/GPU/graphics/ImageBufferShareableBitmapBackend.cpp >@@ -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 @@ using namespace WebCore; > > 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; > >diff --git a/Source/WebKit/WebProcess/GPU/graphics/ImageBufferShareableBitmapBackend.h b/Source/WebKit/WebProcess/GPU/graphics/ImageBufferShareableBitmapBackend.h >index 512c78e554b7c431ea7ab3b785e74bae3047f33e..5d1f4c99a452892eb511c67e0f9eca30a2d3c4f6 100644 >--- a/Source/WebKit/WebProcess/GPU/graphics/ImageBufferShareableBitmapBackend.h >+++ b/Source/WebKit/WebProcess/GPU/graphics/ImageBufferShareableBitmapBackend.h >@@ -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 @@ class ImageBufferShareableBitmapBackend : public WebCore::PlatformImageBufferBac > 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); > >diff --git a/Source/WebKit/WebProcess/GPU/graphics/RemoteImageBufferProxy.h b/Source/WebKit/WebProcess/GPU/graphics/RemoteImageBufferProxy.h >index 2b6bff1047f117096718cde9dc71a4cf90bf5eef..8315ddc1aa67e43df36a97d846045e147532ab75 100644 >--- a/Source/WebKit/WebProcess/GPU/graphics/RemoteImageBufferProxy.h >+++ b/Source/WebKit/WebProcess/GPU/graphics/RemoteImageBufferProxy.h >@@ -55,10 +55,9 @@ class RemoteImageBufferProxy : public WebCore::DisplayList::ImageBuffer<BackendT > 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()) >- return nullptr; >- > auto parameters = WebCore::ImageBufferBackend::Parameters { size, resolutionScale, colorSpace, pixelFormat }; >+ if (BackendType::calculateSafeBackendSize(parameters).isEmpty()) >+ return nullptr; > return adoptRef(new RemoteImageBufferProxy(parameters, remoteRenderingBackendProxy)); > } > >diff --git a/Source/WebKit/WebProcess/GPU/graphics/cocoa/ImageBufferShareableIOSurfaceBackend.cpp b/Source/WebKit/WebProcess/GPU/graphics/cocoa/ImageBufferShareableIOSurfaceBackend.cpp >index 57c7f7d5a24597d2b6b2ff3eb50d7f56974950a9..7a0f891d62120edec2c5f7abd872ea6b65c84f99 100644 >--- a/Source/WebKit/WebProcess/GPU/graphics/cocoa/ImageBufferShareableIOSurfaceBackend.cpp >+++ b/Source/WebKit/WebProcess/GPU/graphics/cocoa/ImageBufferShareableIOSurfaceBackend.cpp >@@ -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 @@ using namespace WebCore; > > 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 @@ GraphicsContext& ImageBufferShareableIOSurfaceBackend::context() const > 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(); >diff --git a/Source/WebKit/WebProcess/GPU/graphics/cocoa/ImageBufferShareableIOSurfaceBackend.h b/Source/WebKit/WebProcess/GPU/graphics/cocoa/ImageBufferShareableIOSurfaceBackend.h >index d5e00e42098a4b370682a497be389c0d38953ca8..1686254ee9acbc0a75f312b167537a2d2aa0dd32 100644 >--- a/Source/WebKit/WebProcess/GPU/graphics/cocoa/ImageBufferShareableIOSurfaceBackend.h >+++ b/Source/WebKit/WebProcess/GPU/graphics/cocoa/ImageBufferShareableIOSurfaceBackend.h >@@ -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 @@ class ImageBufferShareableIOSurfaceBackend final : public WebCore::ImageBufferBa > 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 @@ public: > static constexpr WebCore::RenderingMode renderingMode = WebCore::RenderingMode::Accelerated; > > private: >+ unsigned bytesPerRow() const override; >+ > ImageBufferBackendHandle m_handle; > }; > >diff --git a/Source/WebKit/WebProcess/GPU/graphics/cocoa/ImageBufferShareableMappedIOSurfaceBackend.cpp b/Source/WebKit/WebProcess/GPU/graphics/cocoa/ImageBufferShareableMappedIOSurfaceBackend.cpp >index 2e20eda773cbb73c3d0fb37b85a8133644766333..43beb51734a8a281e069e17fb739c0d22d68c1fb 100644 >--- a/Source/WebKit/WebProcess/GPU/graphics/cocoa/ImageBufferShareableMappedIOSurfaceBackend.cpp >+++ b/Source/WebKit/WebProcess/GPU/graphics/cocoa/ImageBufferShareableMappedIOSurfaceBackend.cpp >@@ -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 @@ WTF_MAKE_ISO_ALLOCATED_IMPL(ImageBufferShareableMappedIOSurfaceBackend); > > 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; >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 224306
:
425450
|
425460
|
425465
|
425473
|
425476
|
425659
| 425715