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-20210407203837.patch (text/plain), 39.65 KB, created by
Said Abou-Hallawa
on 2021-04-07 20:38:38 PDT
(
hide
)
Description:
Patch
Filename:
MIME Type:
Creator:
Said Abou-Hallawa
Created:
2021-04-07 20:38:38 PDT
Size:
39.65 KB
patch
obsolete
>Subversion Revision: 275573 >diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog >index 25c107b44d65a36b454a36b9761f2ffa7438fa91..403292c4d8a8d0deea4868a16d0c474569cff77a 100644 >--- a/Source/WebCore/ChangeLog >+++ b/Source/WebCore/ChangeLog >@@ -1,3 +1,65 @@ >+2021-04-07 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::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): >+ * 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): >+ * 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::bytesPerRow 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-06 Jer Noble <jer.noble@apple.com> > > Unreviewed build fix after 275571: add declaration for new method (and make the constness match). >diff --git a/Source/WebKit/ChangeLog b/Source/WebKit/ChangeLog >index 259b18febfdf54aad9cb844f2c54031080688075..b7cf040268935bb4ee3c39037d5a0300ce748606 100644 >--- a/Source/WebKit/ChangeLog >+++ b/Source/WebKit/ChangeLog >@@ -1,3 +1,42 @@ >+2021-04-07 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): >+ (WebKit::ImageBufferShareableBitmapBackend::bytesPerRow const): Deleted. >+ * 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-06 Wenson Hsieh <wenson_hsieh@apple.com> > > Address some post-landing comments after r275491 >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..3da9c4531d003f27269f132ee704ced5340f7c2c 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,18 @@ > > 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 { }; >- >- CheckedSize numBytes = Checked<unsigned, RecordOverflow>(backendSize.height()) * bytesPerRow; >- if (numBytes.hasOverflowed()) >- return { }; >+ return IntSize(scaledSize); >+} > >- 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..5cf82ffed94b88eb722f01814badcc4965782986 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,14 @@ public: > > WEBCORE_EXPORT virtual ~ImageBufferBackend() = default; > >- WEBCORE_EXPORT static IntSize calculateBackendSize(const FloatSize&, float resolutionScale); >+ WEBCORE_EXPORT static IntSize calculateBackendSize(const Parameters&); >+ 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 +134,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..df97b47b37b8ce10a692933223a08b5ba355047a 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,46 @@ 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 Parameters& parameters) >+{ >+ IntSize backendSize = calculateBackendSize(parameters); >+ 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); >+ ASSERT(!backendSize.isEmpty()); >+ >+ unsigned bytesPerRow = calculateBytesPerRow(parameters); >+ >+ CheckedSize numBytes = Checked<unsigned, RecordOverflow>(backendSize.height()) * bytesPerRow; >+ ASSERT(!numBytes.hasOverflowed()); >+ >+ return numBytes.unsafeGet(); >+} >+ > 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()); >diff --git a/Source/WebCore/platform/graphics/cairo/ImageBufferCairoImageSurfaceBackend.h b/Source/WebCore/platform/graphics/cairo/ImageBufferCairoImageSurfaceBackend.h >index 865cc69b2d5338545f37e4193cb94f1980be73a4..0a38273a89864ceea57598821251b0c8f4ca227a 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 Parameters&); >+ 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 { return calculateBytesPerRow(m_parameters); } >+ > 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..fea2ee5eea5e88178492bc62fd52e8b00f0b14c4 100644 >--- a/Source/WebCore/platform/graphics/cg/ImageBufferCGBackend.cpp >+++ b/Source/WebCore/platform/graphics/cg/ImageBufferCGBackend.cpp >@@ -60,6 +60,17 @@ private: > RetainPtr<CGContextRef> m_context; > }; > >+unsigned ImageBufferCGBackend::calculateBytesPerRow(const Parameters& parameters) >+{ >+ IntSize backendSize = calculateBackendSize(parameters); >+ ASSERT(!backendSize.isEmpty()); >+ >+ Checked<unsigned, RecordOverflow> bytesPerRow = (Checked<unsigned, RecordOverflow>(backendSize.width()) * 4); >+ ASSERT(!bytesPerRow.hasOverflowed()); >+ >+ 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..847e1459553382893ff176ca5bc171fe8692df92 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 Parameters&); >+ > 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..32be9eda74701162fbbf927482f058c9fa3d480e 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,41 @@ 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); >+ ASSERT(!backendSize.isEmpty()); >+ >+ unsigned bytesPerRow = calculateBytesPerRow(parameters); >+ >+ CheckedSize numBytes = Checked<unsigned, RecordOverflow>(backendSize.height()) * bytesPerRow; >+ ASSERT(!numBytes.hasOverflowed()); >+ >+ return numBytes.unsafeGet(); >+} >+ > 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; > >diff --git a/Source/WebCore/platform/graphics/cg/ImageBufferCGBitmapBackend.h b/Source/WebCore/platform/graphics/cg/ImageBufferCGBitmapBackend.h >index 8f3323e7dcec6355acb7d5b99c20787715c86ba8..8043fc3f785f0bc205160e60fc15ba974be800f4 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 { return calculateBytesPerRow(m_parameters); } >+ > 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..d2a2dfe81357187d95e986760878848fd84d5bdf 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,30 @@ IntSize ImageBufferIOSurfaceBackend::calculateBackendSize(const FloatSize& size, > return backendSize; > } > >+unsigned ImageBufferIOSurfaceBackend::calculateBytesPerRow(const Parameters& parameters) >+{ >+ unsigned bytesPerRow = ImageBufferCGBackend::calculateBytesPerRow(parameters); >+ return IOSurfaceAlignProperty(kIOSurfaceBytesPerRow, bytesPerRow); >+} >+ >+size_t ImageBufferIOSurfaceBackend::calculateMemoryCost(const Parameters& parameters) >+{ >+ IntSize backendSize = calculateBackendSize(parameters); >+ ASSERT(!backendSize.isEmpty()); >+ >+ unsigned bytesPerRow = calculateBytesPerRow(parameters); >+ >+ CheckedSize numBytes = Checked<unsigned, RecordOverflow>(backendSize.height()) * bytesPerRow; >+ ASSERT(!numBytes.hasOverflowed()); >+ >+ return numBytes.unsafeGet(); >+} >+ >+size_t ImageBufferIOSurfaceBackend::calculateExternalMemoryCost(const Parameters& parameters) >+{ >+ return calculateMemoryCost(parameters); >+} >+ > RetainPtr<CGColorSpaceRef> ImageBufferIOSurfaceBackend::contextColorSpace(const GraphicsContext& context) > { > CGContextRef cgContext = context.platformContext(); >@@ -66,7 +90,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 +130,6 @@ ImageBufferIOSurfaceBackend::ImageBufferIOSurfaceBackend(const Parameters& param > > GraphicsContext& ImageBufferIOSurfaceBackend::context() const > { >- > GraphicsContext& context = m_surface->ensureGraphicsContext(); > if (m_needsSetupContext) { > m_needsSetupContext = false; >@@ -125,19 +148,9 @@ 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(); >+ return calculateBytesPerRow(m_parameters); > } > > RefPtr<NativeImage> ImageBufferIOSurfaceBackend::copyNativeImage(BackingStoreCopy) const >diff --git a/Source/WebCore/platform/graphics/cg/ImageBufferIOSurfaceBackend.h b/Source/WebCore/platform/graphics/cg/ImageBufferIOSurfaceBackend.h >index 4859df6fc525d85c328c145f079178356909e25d..491537120013d01155fb9842f8e088f50c29919a 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 Parameters&); >+ 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..39041c508cdb59609d282889f551a3bb24d91722 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,65 @@ 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) >+{ >+ IntSize backendSize = calculateBackendSize(parameters); >+ ASSERT(!backendSize.isEmpty()); >+ >+ Checked<unsigned, RecordOverflow> bytesPerRow = ShareableBitmap::calculateBytesPerRow(backendSize, configuration(parameters)); >+ ASSERT(!bytesPerRow.hasOverflowed()); >+ >+ return bytesPerRow.unsafeGet(); >+} >+ >+size_t ImageBufferShareableBitmapBackend::calculateMemoryCost(const Parameters& parameters) >+{ >+ IntSize backendSize = calculateBackendSize(parameters); >+ ASSERT(!backendSize.isEmpty()); >+ >+ unsigned bytesPerRow = calculateBytesPerRow(parameters); >+ >+ CheckedSize numBytes = Checked<unsigned, RecordOverflow>(backendSize.height()) * bytesPerRow; >+ ASSERT(!numBytes.hasOverflowed()); >+ >+ return numBytes.unsafeGet(); >+} >+ > 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; > >@@ -103,11 +149,6 @@ IntSize ImageBufferShareableBitmapBackend::backendSize() const > return m_bitmap->size(); > } > >-unsigned ImageBufferShareableBitmapBackend::bytesPerRow() const >-{ >- return m_bitmap->bytesPerRow(); >-} >- > RefPtr<NativeImage> ImageBufferShareableBitmapBackend::copyNativeImage(BackingStoreCopy) const > { > return NativeImage::create(m_bitmap->createPlatformImage()); >diff --git a/Source/WebKit/WebProcess/GPU/graphics/ImageBufferShareableBitmapBackend.h b/Source/WebKit/WebProcess/GPU/graphics/ImageBufferShareableBitmapBackend.h >index 512c78e554b7c431ea7ab3b785e74bae3047f33e..8442d0e6d21dda630ef40bd96407d05196d9d6bd 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&); >+ 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); > >@@ -62,7 +67,7 @@ public: > void putImageData(WebCore::AlphaPremultiplication inputFormat, const WebCore::ImageData&, const WebCore::IntRect& srcRect, const WebCore::IntPoint& destPoint, WebCore::AlphaPremultiplication destFormat) override; > > private: >- unsigned bytesPerRow() const override; >+ unsigned bytesPerRow() const override { return calculateBytesPerRow(m_parameters); } > > RefPtr<ShareableBitmap> m_bitmap; > std::unique_ptr<WebCore::GraphicsContext> m_context; >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..274a9ce37f3b4f8a7b4537e94f1949d5b6ccbb0e 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 >+{ >+ RELEASE_ASSERT_NOT_REACHED(); >+ return 0; >+} >+ > 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..2875b06aa5aed0226ce3041e58ba0c31a5d4df86 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 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
Flags:
ews-feeder
:
commit-queue-
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 224306
:
425450
|
425460
|
425465
|
425473
|
425476
|
425659
|
425715