Diff
Modified: trunk/Source/WebCore/ChangeLog (277449 => 277450)
--- trunk/Source/WebCore/ChangeLog 2021-05-13 20:47:38 UTC (rev 277449)
+++ trunk/Source/WebCore/ChangeLog 2021-05-13 20:54:21 UTC (rev 277450)
@@ -1,3 +1,77 @@
+2021-05-13 Sam Weinig <wei...@apple.com>
+
+ Split pixel buffer format data out into a new PixelBufferFormat struct
+ https://bugs.webkit.org/show_bug.cgi?id=225707
+
+ Reviewed by Darin Adler.
+
+ Splits out PixelBufferFormat into a new struct and adopts it by PixelBufferConversionView,
+ ConstPixelBufferConversionView and PixelBuffer. This also means that PixelBuffer now
+ tracks the alpha format of the underlying buffer which will come in handy.
+
+ * Headers.cmake:
+ * Sources.txt:
+ * WebCore.xcodeproj/project.pbxproj:
+ Add new files.
+
+ * platform/graphics/AlphaPremultiplication.cpp: Added.
+ (WebCore::operator<<):
+ Add AlphaPremultiplication.cpp and move TextStream support
+ here from GraphicsTypes.cpp.
+
+ * platform/graphics/GraphicsTypes.cpp:
+ Move AlphaPremultiplication TextStream to the more appropriate
+ AlphaPremultiplication.cpp.
+
+ * html/ImageData.cpp:
+ (WebCore::ImageData::create):
+ * html/ImageData.h:
+ (WebCore::ImageData::colorSpace const): Deleted.
+ (WebCore::ImageData::format const): Deleted.
+ * platform/graphics/ImageBufferBackend.cpp:
+ (WebCore::ImageBufferBackend::toBGRAData const):
+ (WebCore::ImageBufferBackend::getPixelBuffer const):
+ (WebCore::ImageBufferBackend::putPixelBuffer):
+ * platform/graphics/ImageBufferBackend.h:
+ * platform/graphics/PixelBuffer.cpp:
+ (WebCore::PixelBuffer::computeBufferSize):
+ (WebCore::PixelBuffer::tryCreateForDecoding):
+ (WebCore::PixelBuffer::tryCreate):
+ (WebCore::PixelBuffer::PixelBuffer):
+ (WebCore::PixelBuffer::deepClone const):
+ (WebCore::operator<<):
+ * platform/graphics/PixelBuffer.h:
+ (WebCore::PixelBuffer::format const):
+ (WebCore::PixelBuffer::encode const):
+ (WebCore::PixelBuffer::decode):
+ (WebCore::PixelBuffer::colorSpace const): Deleted.
+ * platform/graphics/PixelBufferConversion.cpp:
+ (WebCore::convertImagePixelsAccelerated):
+ (WebCore::convertImagePixels):
+ * platform/graphics/PixelBufferConversion.h:
+ * platform/graphics/PixelBufferFormat.cpp: Added.
+ (WebCore::operator<<):
+ * platform/graphics/PixelBufferFormat.h: Added.
+ (WebCore::PixelBufferFormat::encode const):
+ (WebCore::PixelBufferFormat::decode):
+ * platform/graphics/PixelFormat.cpp: Added.
+ (WebCore::operator<<):
+ * platform/graphics/PixelFormat.h:
+ * platform/graphics/angle/GraphicsContextGLANGLE.cpp:
+ (WebCore::GraphicsContextGLOpenGL::readPixelsForPaintResults):
+ * platform/graphics/cg/GraphicsContextGLCG.cpp:
+ (WebCore::GraphicsContextGLOpenGL::paintToCanvas):
+ * platform/graphics/cg/ImageBufferCGBackend.cpp:
+ (WebCore::ImageBufferCGBackend::toCFData const):
+ * platform/graphics/cg/ImageBufferUtilitiesCG.cpp:
+ (WebCore::cfData):
+ * platform/graphics/filters/FilterEffect.cpp:
+ (WebCore::FilterEffect::copyUnmultipliedResult):
+ (WebCore::FilterEffect::copyPremultipliedResult):
+ (WebCore::FilterEffect::createUnmultipliedImageResult):
+ (WebCore::FilterEffect::createPremultipliedImageResult):
+ Adopt PixelBufferFormat.
+
2021-05-13 Chris Dumez <cdu...@apple.com>
Rename FileSystem::directoryName() to FileSystem::parentPath()
Modified: trunk/Source/WebCore/Headers.cmake (277449 => 277450)
--- trunk/Source/WebCore/Headers.cmake 2021-05-13 20:47:38 UTC (rev 277449)
+++ trunk/Source/WebCore/Headers.cmake 2021-05-13 20:54:21 UTC (rev 277450)
@@ -1290,6 +1290,7 @@
platform/graphics/PathUtilities.h
platform/graphics/Pattern.h
platform/graphics/PixelBuffer.h
+ platform/graphics/PixelBufferFormat.h
platform/graphics/PixelFormat.h
platform/graphics/PlatformDisplay.h
platform/graphics/PlatformImage.h
Modified: trunk/Source/WebCore/Sources.txt (277449 => 277450)
--- trunk/Source/WebCore/Sources.txt 2021-05-13 20:47:38 UTC (rev 277449)
+++ trunk/Source/WebCore/Sources.txt 2021-05-13 20:54:21 UTC (rev 277450)
@@ -1938,6 +1938,7 @@
platform/gamepad/EmptyGamepadProvider.cpp
platform/gamepad/GamepadConstants.cpp
platform/gamepad/GamepadProvider.cpp
+platform/graphics/AlphaPremultiplication.cpp
platform/graphics/AnimationFrameRate.cpp
platform/graphics/BitmapImage.cpp
platform/graphics/Color.cpp
@@ -2015,6 +2016,8 @@
platform/graphics/Pattern.cpp
platform/graphics/PixelBuffer.cpp
platform/graphics/PixelBufferConversion.cpp
+platform/graphics/PixelBufferFormat.cpp
+platform/graphics/PixelFormat.cpp
platform/graphics/PlatformTimeRanges.cpp
platform/graphics/Region.cpp
platform/graphics/RemoteGraphicsContextGLProxyBase.cpp
Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (277449 => 277450)
--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2021-05-13 20:47:38 UTC (rev 277449)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2021-05-13 20:54:21 UTC (rev 277450)
@@ -4058,6 +4058,8 @@
BC6049CC0DB560C200204739 /* CSSCanvasValue.h in Headers */ = {isa = PBXBuildFile; fileRef = BC6049CB0DB560C200204739 /* CSSCanvasValue.h */; };
BC60D6E90D28D83400B9918F /* DOMException.h in Headers */ = {isa = PBXBuildFile; fileRef = BC60D6E80D28D83400B9918F /* DOMException.h */; settings = {ATTRIBUTES = (Private, ); }; };
BC60D7C10D29A46300B9918F /* JSDOMException.h in Headers */ = {isa = PBXBuildFile; fileRef = BC60D7BF0D29A46300B9918F /* JSDOMException.h */; };
+ BC635E8C264C2CAE000EF33A /* PixelBufferFormat.h in Headers */ = {isa = PBXBuildFile; fileRef = BC635E8B264C2CAE000EF33A /* PixelBufferFormat.h */; settings = {ATTRIBUTES = (Private, ); }; };
+ BC635E8E264C2CE7000EF33A /* PixelBufferConversion.h in Headers */ = {isa = PBXBuildFile; fileRef = BC0CA74C264AED0A004FDC62 /* PixelBufferConversion.h */; };
BC64640A11D7F304006455B0 /* DOMStringMap.h in Headers */ = {isa = PBXBuildFile; fileRef = BC64640811D7F304006455B0 /* DOMStringMap.h */; };
BC64641C11D7F416006455B0 /* DatasetDOMStringMap.h in Headers */ = {isa = PBXBuildFile; fileRef = BC64641A11D7F416006455B0 /* DatasetDOMStringMap.h */; };
BC64649811D82349006455B0 /* JSDOMStringMap.h in Headers */ = {isa = PBXBuildFile; fileRef = BC64649611D82349006455B0 /* JSDOMStringMap.h */; };
@@ -14247,6 +14249,10 @@
BC60D6EB0D28D99900B9918F /* DOMException.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = DOMException.idl; sourceTree = "<group>"; };
BC60D7BE0D29A46300B9918F /* JSDOMException.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSDOMException.cpp; sourceTree = "<group>"; };
BC60D7BF0D29A46300B9918F /* JSDOMException.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSDOMException.h; sourceTree = "<group>"; };
+ BC635E8B264C2CAE000EF33A /* PixelBufferFormat.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PixelBufferFormat.h; sourceTree = "<group>"; };
+ BC635E8F264C2ECE000EF33A /* PixelBufferFormat.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = PixelBufferFormat.cpp; sourceTree = "<group>"; };
+ BC635E90264C469F000EF33A /* PixelFormat.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = PixelFormat.cpp; sourceTree = "<group>"; };
+ BC635E91264C4760000EF33A /* AlphaPremultiplication.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = AlphaPremultiplication.cpp; sourceTree = "<group>"; };
BC64640811D7F304006455B0 /* DOMStringMap.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DOMStringMap.h; sourceTree = "<group>"; };
BC64641A11D7F416006455B0 /* DatasetDOMStringMap.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DatasetDOMStringMap.h; sourceTree = "<group>"; };
BC64641B11D7F416006455B0 /* DatasetDOMStringMap.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DatasetDOMStringMap.cpp; sourceTree = "<group>"; };
@@ -26850,6 +26856,7 @@
FBC220DD1237FBEB00BCF788 /* opengl */,
3721493318F0B6D600156EDC /* opentype */,
49E911B20EF86D27009D0CAF /* transforms */,
+ BC635E91264C4760000EF33A /* AlphaPremultiplication.cpp */,
7299BC6423D686A600CC6883 /* AlphaPremultiplication.h */,
0F7E475325EEB79B0013F909 /* ANGLEWebKitBridge.cpp */,
0F7E475425EEB79B0013F909 /* ANGLEWebKitBridge.h */,
@@ -27059,6 +27066,9 @@
BC4839BA2646181A00A28B62 /* PixelBuffer.h */,
BC0CA74D264AED0A004FDC62 /* PixelBufferConversion.cpp */,
BC0CA74C264AED0A004FDC62 /* PixelBufferConversion.h */,
+ BC635E8F264C2ECE000EF33A /* PixelBufferFormat.cpp */,
+ BC635E8B264C2CAE000EF33A /* PixelBufferFormat.h */,
+ BC635E90264C469F000EF33A /* PixelFormat.cpp */,
BCA55912263DBD79007F19B3 /* PixelFormat.h */,
726D56E1253AE0430002EF90 /* PlatformImage.h */,
72BAC3A623E17328008D741C /* PlatformImageBuffer.h */,
@@ -34471,6 +34481,8 @@
D0FF2A5E11F8C45A007E74E0 /* PingLoader.h in Headers */,
BCE691E5264637FC00EBDC3A /* PixelBuffer.h in Headers */,
CD7D33441C7A123F00041293 /* PixelBufferConformerCV.h in Headers */,
+ BC635E8E264C2CE7000EF33A /* PixelBufferConversion.h in Headers */,
+ BC635E8C264C2CAE000EF33A /* PixelBufferFormat.h in Headers */,
BCA55914263DBD79007F19B3 /* PixelFormat.h in Headers */,
CDEFA2281E7669E8000AE99C /* PlatformAudioData.h in Headers */,
499B3EDD128DB50200E726C2 /* PlatformCAAnimation.h in Headers */,
Modified: trunk/Source/WebCore/html/ImageData.cpp (277449 => 277450)
--- trunk/Source/WebCore/html/ImageData.cpp 2021-05-13 20:47:38 UTC (rev 277449)
+++ trunk/Source/WebCore/html/ImageData.cpp 2021-05-13 20:54:21 UTC (rev 277450)
@@ -63,7 +63,8 @@
auto byteArray = Uint8ClampedArray::tryCreateUninitialized(dataSize.unsafeGet());
if (!byteArray)
return nullptr;
- return adoptRef(*new ImageData({ DestinationColorSpace::SRGB, PixelFormat::RGBA8, size, byteArray.releaseNonNull() }));
+
+ return adoptRef(*new ImageData({ { AlphaPremultiplication::Unpremultiplied, PixelFormat::RGBA8, DestinationColorSpace::SRGB }, size, byteArray.releaseNonNull() }));
}
RefPtr<ImageData> ImageData::create(const IntSize& size, Ref<Uint8ClampedArray>&& byteArray)
@@ -72,7 +73,7 @@
if (dataSize.hasOverflowed() || dataSize.unsafeGet() > byteArray->length())
return nullptr;
- return adoptRef(*new ImageData({ DestinationColorSpace::SRGB, PixelFormat::RGBA8, size, WTFMove(byteArray) }));
+ return adoptRef(*new ImageData({ { AlphaPremultiplication::Unpremultiplied, PixelFormat::RGBA8, DestinationColorSpace::SRGB }, size, WTFMove(byteArray) }));
}
ExceptionOr<Ref<ImageData>> ImageData::create(unsigned sw, unsigned sh)
@@ -89,7 +90,7 @@
return Exception { RangeError, "Out of memory"_s };
}
byteArray->zeroFill();
- return adoptRef(*new ImageData({ DestinationColorSpace::SRGB, PixelFormat::RGBA8, size, byteArray.releaseNonNull() }));
+ return adoptRef(*new ImageData({ { AlphaPremultiplication::Unpremultiplied, PixelFormat::RGBA8, DestinationColorSpace::SRGB }, size, byteArray.releaseNonNull() }));
}
ExceptionOr<Ref<ImageData>> ImageData::create(Ref<Uint8ClampedArray>&& byteArray, unsigned sw, Optional<unsigned> sh)
Modified: trunk/Source/WebCore/html/ImageData.h (277449 => 277450)
--- trunk/Source/WebCore/html/ImageData.h 2021-05-13 20:47:38 UTC (rev 277449)
+++ trunk/Source/WebCore/html/ImageData.h 2021-05-13 20:54:21 UTC (rev 277450)
@@ -51,9 +51,6 @@
Ref<ImageData> deepClone() const;
- DestinationColorSpace colorSpace() const { return m_pixelBuffer.colorSpace(); }
- PixelFormat format() const { return m_pixelBuffer.format(); }
-
const PixelBuffer& pixelBuffer() const { return m_pixelBuffer; }
private:
Copied: trunk/Source/WebCore/platform/graphics/AlphaPremultiplication.cpp (from rev 277449, trunk/Source/WebCore/platform/graphics/PixelFormat.h) (0 => 277450)
--- trunk/Source/WebCore/platform/graphics/AlphaPremultiplication.cpp (rev 0)
+++ trunk/Source/WebCore/platform/graphics/AlphaPremultiplication.cpp 2021-05-13 20:54:21 UTC (rev 277450)
@@ -0,0 +1,46 @@
+/*
+ * Copyright (C) 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
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "AlphaPremultiplication.h"
+
+#include <wtf/text/TextStream.h>
+
+namespace WebCore {
+
+TextStream& operator<<(TextStream& ts, AlphaPremultiplication premultiplication)
+{
+ switch (premultiplication) {
+ case AlphaPremultiplication::Premultiplied:
+ ts << "premultiplied";
+ break;
+ case AlphaPremultiplication::Unpremultiplied:
+ ts << "unpremultiplied";
+ break;
+ }
+ return ts;
+}
+
+}
Modified: trunk/Source/WebCore/platform/graphics/AlphaPremultiplication.h (277449 => 277450)
--- trunk/Source/WebCore/platform/graphics/AlphaPremultiplication.h 2021-05-13 20:47:38 UTC (rev 277449)
+++ trunk/Source/WebCore/platform/graphics/AlphaPremultiplication.h 2021-05-13 20:54:21 UTC (rev 277450)
@@ -40,6 +40,7 @@
}
namespace WTF {
+
template<> struct EnumTraits<WebCore::AlphaPremultiplication> {
using values = EnumValues<
WebCore::AlphaPremultiplication,
@@ -47,4 +48,5 @@
WebCore::AlphaPremultiplication::Unpremultiplied
>;
};
+
}
Modified: trunk/Source/WebCore/platform/graphics/GraphicsTypes.cpp (277449 => 277450)
--- trunk/Source/WebCore/platform/graphics/GraphicsTypes.cpp 2021-05-13 20:47:38 UTC (rev 277449)
+++ trunk/Source/WebCore/platform/graphics/GraphicsTypes.cpp 2021-05-13 20:54:21 UTC (rev 277450)
@@ -182,17 +182,4 @@
return ts;
}
-TextStream& operator<<(TextStream& ts, AlphaPremultiplication premultiplication)
-{
- switch (premultiplication) {
- case AlphaPremultiplication::Premultiplied:
- ts << "premultiplied";
- break;
- case AlphaPremultiplication::Unpremultiplied:
- ts << "unpremultiplied";
- break;
- }
- return ts;
-}
-
} // namespace WebCore
Modified: trunk/Source/WebCore/platform/graphics/ImageBufferBackend.cpp (277449 => 277450)
--- trunk/Source/WebCore/platform/graphics/ImageBufferBackend.cpp 2021-05-13 20:47:38 UTC (rev 277449)
+++ trunk/Source/WebCore/platform/graphics/ImageBufferBackend.cpp 2021-05-13 20:54:21 UTC (rev 277450)
@@ -95,17 +95,16 @@
{
Vector<uint8_t> result(4 * logicalSize().area().unsafeGet());
+ PixelBufferFormat sourceFormat { AlphaPremultiplication::Premultiplied, pixelFormat(), DestinationColorSpace::SRGB };
+ PixelBufferFormat destinationFormat { AlphaPremultiplication::Unpremultiplied, PixelFormat::BGRA8, DestinationColorSpace::SRGB };
+
ConstPixelBufferConversionView source;
- source.alphaFormat = AlphaPremultiplication::Premultiplied;
- source.colorSpace = DestinationColorSpace::SRGB;
- source.pixelFormat = pixelFormat();
+ source.format = sourceFormat;
source.bytesPerRow = bytesPerRow();
source.rows = reinterpret_cast<const uint8_t*>(data);
PixelBufferConversionView destination;
- destination.alphaFormat = AlphaPremultiplication::Unpremultiplied;
- destination.colorSpace = DestinationColorSpace::SRGB;
- destination.pixelFormat = PixelFormat::BGRA8;
+ destination.format = destinationFormat;
destination.bytesPerRow = logicalSize().width() * 4;
destination.rows = result.data();
@@ -118,9 +117,9 @@
{
auto sourceRectScaled = toBackendCoordinates(sourceRect);
- auto destinationPixelFormat = PixelFormat::RGBA8;
+ PixelBufferFormat destinationFormat { destinationAlphaFormat, PixelFormat::RGBA8, DestinationColorSpace::SRGB };
- auto pixelBuffer = PixelBuffer::tryCreate(DestinationColorSpace::SRGB, destinationPixelFormat, sourceRectScaled.size());
+ auto pixelBuffer = PixelBuffer::tryCreate(destinationFormat, sourceRectScaled.size());
if (!pixelBuffer)
return WTF::nullopt;
@@ -142,17 +141,15 @@
unsigned destinationBytesPerRow = 4 * sourceRectScaled.width();
uint8_t* destinationRows = pixelBuffer->data().data() + destinationRect.y() * destinationBytesPerRow + destinationRect.x() * 4;
+ PixelBufferFormat sourceFormat { AlphaPremultiplication::Premultiplied, pixelFormat(), DestinationColorSpace::SRGB };
+
ConstPixelBufferConversionView source;
- source.alphaFormat = AlphaPremultiplication::Premultiplied;
- source.colorSpace = DestinationColorSpace::SRGB;
- source.pixelFormat = pixelFormat();
+ source.format = sourceFormat;
source.bytesPerRow = sourceBytesPerRow;
source.rows = sourceRows;
PixelBufferConversionView destination;
- destination.alphaFormat = destinationAlphaFormat;
- destination.colorSpace = DestinationColorSpace::SRGB;
- destination.pixelFormat = destinationPixelFormat;
+ destination.format = destinationFormat;
destination.bytesPerRow = destinationBytesPerRow;
destination.rows = destinationRows;
@@ -164,7 +161,7 @@
void ImageBufferBackend::putPixelBuffer(AlphaPremultiplication sourceAlphaFormat, const PixelBuffer& pixelBuffer, const IntRect& sourceRect, const IntPoint& destinationPoint, AlphaPremultiplication destinationAlphaFormat, void* data)
{
// FIXME: Add support for non-RGBA8 pixel formats.
- ASSERT(pixelBuffer.format() == PixelFormat::RGBA8);
+ ASSERT(pixelBuffer.format().pixelFormat == PixelFormat::RGBA8);
auto sourceRectScaled = toBackendCoordinates(sourceRect);
auto destinationPointScaled = toBackendCoordinates(destinationPoint);
@@ -188,17 +185,16 @@
unsigned destinationBytesPerRow = bytesPerRow();
uint8_t* destinationRows = reinterpret_cast<uint8_t*>(data) + destinationRect.y() * destinationBytesPerRow + destinationRect.x() * 4;
+ PixelBufferFormat sourceFormat { sourceAlphaFormat, PixelFormat::RGBA8, DestinationColorSpace::SRGB };
+ PixelBufferFormat destinationFormat { destinationAlphaFormat, pixelFormat(), DestinationColorSpace::SRGB };
+
ConstPixelBufferConversionView source;
- source.alphaFormat = sourceAlphaFormat;
- source.colorSpace = DestinationColorSpace::SRGB;
- source.pixelFormat = PixelFormat::RGBA8;
+ source.format = sourceFormat;
source.bytesPerRow = sourceBytesPerRow;
source.rows = sourceRows;
PixelBufferConversionView destination;
- destination.alphaFormat = destinationAlphaFormat;
- destination.colorSpace = DestinationColorSpace::SRGB;
- destination.pixelFormat = pixelFormat();
+ destination.format = destinationFormat;
destination.bytesPerRow = destinationBytesPerRow;
destination.rows = destinationRows;
Modified: trunk/Source/WebCore/platform/graphics/ImageBufferBackend.h (277449 => 277450)
--- trunk/Source/WebCore/platform/graphics/ImageBufferBackend.h 2021-05-13 20:47:38 UTC (rev 277449)
+++ trunk/Source/WebCore/platform/graphics/ImageBufferBackend.h 2021-05-13 20:54:21 UTC (rev 277450)
@@ -162,9 +162,9 @@
template<> struct EnumTraits<WebCore::PreserveResolution> {
using values = EnumValues<
- WebCore::PreserveResolution,
- WebCore::PreserveResolution::No,
- WebCore::PreserveResolution::Yes
+ WebCore::PreserveResolution,
+ WebCore::PreserveResolution::No,
+ WebCore::PreserveResolution::Yes
>;
};
Modified: trunk/Source/WebCore/platform/graphics/PixelBuffer.cpp (277449 => 277450)
--- trunk/Source/WebCore/platform/graphics/PixelBuffer.cpp 2021-05-13 20:47:38 UTC (rev 277449)
+++ trunk/Source/WebCore/platform/graphics/PixelBuffer.cpp 2021-05-13 20:54:21 UTC (rev 277450)
@@ -31,10 +31,10 @@
namespace WebCore {
-Checked<unsigned, RecordOverflow> PixelBuffer::computeBufferSize(PixelFormat format, const IntSize& size)
+Checked<unsigned, RecordOverflow> PixelBuffer::computeBufferSize(const PixelBufferFormat& format, const IntSize& size)
{
// NOTE: Only 8-bit formats are currently supported.
- ASSERT_UNUSED(format, format == PixelFormat::RGBA8 || format == PixelFormat::BGRA8);
+ ASSERT_UNUSED(format, format.pixelFormat == PixelFormat::RGBA8 || format.pixelFormat == PixelFormat::BGRA8);
constexpr unsigned bytesPerPixel = 4;
@@ -41,21 +41,21 @@
return size.area<RecordOverflow>() * bytesPerPixel;
}
-Optional<PixelBuffer> PixelBuffer::tryCreateForDecoding(DestinationColorSpace colorSpace, PixelFormat format, const IntSize& size, unsigned dataByteLength)
+Optional<PixelBuffer> PixelBuffer::tryCreateForDecoding(const PixelBufferFormat& format, const IntSize& size, unsigned dataByteLength)
{
- ASSERT(format == PixelFormat::RGBA8 || format == PixelFormat::BGRA8);
+ ASSERT(format.pixelFormat == PixelFormat::RGBA8 || format.pixelFormat == PixelFormat::BGRA8);
ASSERT(computeBufferSize(format, size).unsafeGet() == dataByteLength);
auto pixelArray = Uint8ClampedArray::tryCreateUninitialized(dataByteLength);
if (!pixelArray)
return WTF::nullopt;
- return { { colorSpace, format, size, pixelArray.releaseNonNull() } };
+ return { { format, size, pixelArray.releaseNonNull() } };
}
-Optional<PixelBuffer> PixelBuffer::tryCreate(DestinationColorSpace colorSpace, PixelFormat format, const IntSize& size)
+Optional<PixelBuffer> PixelBuffer::tryCreate(const PixelBufferFormat& format, const IntSize& size)
{
// NOTE: Only 8-bit formats are currently supported.
- ASSERT(format == PixelFormat::RGBA8 || format == PixelFormat::BGRA8);
+ ASSERT(format.pixelFormat == PixelFormat::RGBA8 || format.pixelFormat == PixelFormat::BGRA8);
auto bufferSize = computeBufferSize(format, size);
if (bufferSize.hasOverflowed())
@@ -63,12 +63,11 @@
auto pixelArray = Uint8ClampedArray::tryCreateUninitialized(bufferSize.unsafeGet());
if (!pixelArray)
return WTF::nullopt;
- return { { colorSpace, format, size, pixelArray.releaseNonNull() } };
+ return { { format, size, pixelArray.releaseNonNull() } };
}
-PixelBuffer::PixelBuffer(DestinationColorSpace colorSpace, PixelFormat format, const IntSize& size, Ref<JSC::Uint8ClampedArray>&& data)
- : m_colorSpace { colorSpace }
- , m_format { format }
+PixelBuffer::PixelBuffer(const PixelBufferFormat& format, const IntSize& size, Ref<JSC::Uint8ClampedArray>&& data)
+ : m_format { format }
, m_size { size }
, m_data { WTFMove(data) }
{
@@ -79,12 +78,12 @@
PixelBuffer PixelBuffer::deepClone() const
{
- return { m_colorSpace, m_format, m_size, Uint8ClampedArray::create(m_data->data(), m_data->length()) };
+ return { m_format, m_size, Uint8ClampedArray::create(m_data->data(), m_data->length()) };
}
TextStream& operator<<(TextStream& ts, const PixelBuffer& pixelBuffer)
{
- return ts << &pixelBuffer.data();
+ return ts << &pixelBuffer.data() << "format ( " << pixelBuffer.format() << ")";
}
}
Modified: trunk/Source/WebCore/platform/graphics/PixelBuffer.h (277449 => 277450)
--- trunk/Source/WebCore/platform/graphics/PixelBuffer.h 2021-05-13 20:47:38 UTC (rev 277449)
+++ trunk/Source/WebCore/platform/graphics/PixelBuffer.h 2021-05-13 20:54:21 UTC (rev 277450)
@@ -25,8 +25,10 @@
#pragma once
+#include "AlphaPremultiplication.h"
#include "ColorSpace.h"
#include "IntSize.h"
+#include "PixelBufferFormat.h"
#include "PixelFormat.h"
#include <_javascript_Core/Uint8ClampedArray.h>
@@ -39,16 +41,15 @@
class PixelBuffer {
WTF_MAKE_NONCOPYABLE(PixelBuffer);
public:
- WEBCORE_EXPORT static Optional<PixelBuffer> tryCreate(DestinationColorSpace, PixelFormat, const IntSize&);
+ WEBCORE_EXPORT static Optional<PixelBuffer> tryCreate(const PixelBufferFormat&, const IntSize&);
- PixelBuffer(DestinationColorSpace, PixelFormat, const IntSize&, Ref<JSC::Uint8ClampedArray>&&);
+ PixelBuffer(const PixelBufferFormat&, const IntSize&, Ref<JSC::Uint8ClampedArray>&&);
WEBCORE_EXPORT ~PixelBuffer();
PixelBuffer(PixelBuffer&&) = default;
PixelBuffer& operator=(PixelBuffer&&) = default;
- DestinationColorSpace colorSpace() const { return m_colorSpace; }
- PixelFormat format() const { return m_format; }
+ const PixelBufferFormat& format() const { return m_format; }
const IntSize& size() const { return m_size; }
JSC::Uint8ClampedArray& data() const { return m_data.get(); }
@@ -58,12 +59,11 @@
template<class Decoder> static Optional<PixelBuffer> decode(Decoder&);
private:
- WEBCORE_EXPORT static Optional<PixelBuffer> tryCreateForDecoding(DestinationColorSpace, PixelFormat, const IntSize&, unsigned dataByteLength);
+ WEBCORE_EXPORT static Optional<PixelBuffer> tryCreateForDecoding(const PixelBufferFormat&, const IntSize&, unsigned dataByteLength);
- WEBCORE_EXPORT static Checked<unsigned, RecordOverflow> computeBufferSize(PixelFormat, const IntSize&);
+ WEBCORE_EXPORT static Checked<unsigned, RecordOverflow> computeBufferSize(const PixelBufferFormat&, const IntSize&);
- DestinationColorSpace m_colorSpace;
- PixelFormat m_format;
+ PixelBufferFormat m_format;
IntSize m_size;
Ref<JSC::Uint8ClampedArray> m_data;
};
@@ -74,7 +74,6 @@
{
ASSERT(m_data->byteLength() == (m_size.area().unsafeGet() * 4));
- encoder << m_colorSpace;
encoder << m_format;
encoder << m_size;
encoder.encodeFixedLengthData(m_data->data(), m_data->byteLength(), 1);
@@ -82,16 +81,12 @@
template<class Decoder> Optional<PixelBuffer> PixelBuffer::decode(Decoder& decoder)
{
- DestinationColorSpace colorSpace;
- if (!decoder.decode(colorSpace))
- return WTF::nullopt;
-
- PixelFormat format;
+ PixelBufferFormat format;
if (!decoder.decode(format))
return WTF::nullopt;
// FIXME: Support non-8 bit formats.
- if (!(format == PixelFormat::RGBA8 || format == PixelFormat::BGRA8))
+ if (!(format.pixelFormat == PixelFormat::RGBA8 || format.pixelFormat == PixelFormat::BGRA8))
return WTF::nullopt;
IntSize size;
@@ -106,7 +101,7 @@
if (!decoder.template bufferIsLargeEnoughToContain<uint8_t>(bufferSize))
return WTF::nullopt;
- auto result = PixelBuffer::tryCreateForDecoding(colorSpace, format, size, bufferSize);
+ auto result = PixelBuffer::tryCreateForDecoding(format, size, bufferSize);
if (!result)
return WTF::nullopt;
Modified: trunk/Source/WebCore/platform/graphics/PixelBufferConversion.cpp (277449 => 277450)
--- trunk/Source/WebCore/platform/graphics/PixelBufferConversion.cpp 2021-05-13 20:47:38 UTC (rev 277449)
+++ trunk/Source/WebCore/platform/graphics/PixelBufferConversion.cpp 2021-05-13 20:54:21 UTC (rev 277450)
@@ -56,14 +56,14 @@
auto sourceVImageBuffer = makeVImageBuffer(source, destinationSize);
auto destinationVImageBuffer = makeVImageBuffer(destination, destinationSize);
- if (source.alphaFormat != destination.alphaFormat) {
- if (destination.alphaFormat == AlphaPremultiplication::Unpremultiplied) {
- if (source.pixelFormat == PixelFormat::RGBA8)
+ if (source.format.alphaFormat != destination.format.alphaFormat) {
+ if (destination.format.alphaFormat == AlphaPremultiplication::Unpremultiplied) {
+ if (source.format.pixelFormat == PixelFormat::RGBA8)
vImageUnpremultiplyData_RGBA8888(&sourceVImageBuffer, &destinationVImageBuffer, kvImageNoFlags);
else
vImageUnpremultiplyData_BGRA8888(&sourceVImageBuffer, &destinationVImageBuffer, kvImageNoFlags);
} else {
- if (source.pixelFormat == PixelFormat::RGBA8)
+ if (source.format.pixelFormat == PixelFormat::RGBA8)
vImagePremultiplyData_RGBA8888(&sourceVImageBuffer, &destinationVImageBuffer, kvImageNoFlags);
else
vImagePremultiplyData_BGRA8888(&sourceVImageBuffer, &destinationVImageBuffer, kvImageNoFlags);
@@ -72,7 +72,7 @@
sourceVImageBuffer = destinationVImageBuffer;
}
- if (source.pixelFormat != destination.pixelFormat) {
+ if (source.format.pixelFormat != destination.format.pixelFormat) {
// Swap pixel channels BGRA <-> RGBA.
const uint8_t map[4] = { 2, 1, 0, 3 };
vImagePermuteChannels_ARGB8888(&sourceVImageBuffer, &destinationVImageBuffer, map, kvImageNoFlags);
@@ -181,16 +181,16 @@
void convertImagePixels(const ConstPixelBufferConversionView& source, const PixelBufferConversionView& destination, const IntSize& destinationSize)
{
// We don't currently support converting pixel data with non-8-bit buffers.
- ASSERT(source.pixelFormat == PixelFormat::RGBA8 || source.pixelFormat == PixelFormat::BGRA8);
- ASSERT(destination.pixelFormat == PixelFormat::RGBA8 || destination.pixelFormat == PixelFormat::BGRA8);
+ ASSERT(source.format.pixelFormat == PixelFormat::RGBA8 || source.format.pixelFormat == PixelFormat::BGRA8);
+ ASSERT(destination.format.pixelFormat == PixelFormat::RGBA8 || destination.format.pixelFormat == PixelFormat::BGRA8);
// We don't currently support converting pixel data between different color spaces.
- ASSERT(source.colorSpace == destination.colorSpace);
+ ASSERT(source.format.colorSpace == destination.format.colorSpace);
#if USE(ACCELERATE)
- if (source.alphaFormat == destination.alphaFormat && source.pixelFormat == destination.pixelFormat) {
+ if (source.format.alphaFormat == destination.format.alphaFormat && source.format.pixelFormat == destination.format.pixelFormat) {
// FIXME: Can thes both just use per-row memcpy?
- if (source.alphaFormat == AlphaPremultiplication::Premultiplied)
+ if (source.format.alphaFormat == AlphaPremultiplication::Premultiplied)
convertImagePixelsUnaccelerated<convertSinglePixelPremultipliedToPremultiplied<PixelFormatConversion::None>>(source, destination, destinationSize);
else
convertImagePixelsUnaccelerated<convertSinglePixelUnpremultipliedToUnpremultiplied<PixelFormatConversion::None>>(source, destination, destinationSize);
@@ -197,29 +197,29 @@
} else
convertImagePixelsAccelerated(source, destination, destinationSize);
#else
- if (source.alphaFormat == destination.alphaFormat) {
- if (source.pixelFormat == destination.pixelFormat) {
- if (source.alphaFormat == AlphaPremultiplication::Premultiplied)
+ if (source.format.alphaFormat == destination.format.alphaFormat) {
+ if (source.format.pixelFormat == destination.format.pixelFormat) {
+ if (source.format.alphaFormat == AlphaPremultiplication::Premultiplied)
convertImagePixelsUnaccelerated<convertSinglePixelPremultipliedToPremultiplied<PixelFormatConversion::None>>(source, destination, destinationSize);
else
convertImagePixelsUnaccelerated<convertSinglePixelUnpremultipliedToUnpremultiplied<PixelFormatConversion::None>>(source, destination, destinationSize);
} else {
- if (destination.alphaFormat == AlphaPremultiplication::Premultiplied)
+ if (destination.format.alphaFormat == AlphaPremultiplication::Premultiplied)
convertImagePixelsUnaccelerated<convertSinglePixelPremultipliedToPremultiplied<PixelFormatConversion::Permute>>(source, destination, destinationSize);
else
convertImagePixelsUnaccelerated<convertSinglePixelUnpremultipliedToUnpremultiplied<PixelFormatConversion::Permute>>(source, destination, destinationSize);
}
} else {
- if (source.pixelFormat == destination.pixelFormat) {
- if (source.alphaFormat == AlphaPremultiplication::Premultiplied)
+ if (source.format.pixelFormat == destination.format.pixelFormat) {
+ if (source.format.alphaFormat == AlphaPremultiplication::Premultiplied)
convertImagePixelsUnaccelerated<convertSinglePixelPremultipliedToUnpremultiplied<PixelFormatConversion::None>>(source, destination, destinationSize);
else
convertImagePixelsUnaccelerated<convertSinglePixelUnpremultipliedToPremultiplied<PixelFormatConversion::None>>(source, destination, destinationSize);
} else {
- if (destination.alphaFormat == AlphaPremultiplication::Unpremultiplied)
+ if (destination.format.alphaFormat == AlphaPremultiplication::Premultiplied)
+ convertImagePixelsUnaccelerated<convertSinglePixelUnpremultipliedToPremultiplied<PixelFormatConversion::Permute>>(source, destination, destinationSize);
+ else
convertImagePixelsUnaccelerated<convertSinglePixelPremultipliedToUnpremultiplied<PixelFormatConversion::Permute>>(source, destination, destinationSize);
- else
- convertImagePixelsUnaccelerated<convertSinglePixelUnpremultipliedToPremultiplied<PixelFormatConversion::Permute>>(source, destination, destinationSize);
}
}
#endif
Modified: trunk/Source/WebCore/platform/graphics/PixelBufferConversion.h (277449 => 277450)
--- trunk/Source/WebCore/platform/graphics/PixelBufferConversion.h 2021-05-13 20:47:38 UTC (rev 277449)
+++ trunk/Source/WebCore/platform/graphics/PixelBufferConversion.h 2021-05-13 20:54:21 UTC (rev 277450)
@@ -25,26 +25,20 @@
#pragma once
+#include "PixelBufferFormat.h"
+
namespace WebCore {
class IntSize;
-enum class AlphaPremultiplication : uint8_t;
-enum class DestinationColorSpace : uint8_t;
-enum class PixelFormat : uint8_t;
-
struct PixelBufferConversionView {
- AlphaPremultiplication alphaFormat;
- DestinationColorSpace colorSpace;
- PixelFormat pixelFormat;
+ PixelBufferFormat format;
unsigned bytesPerRow;
uint8_t* rows;
};
struct ConstPixelBufferConversionView {
- AlphaPremultiplication alphaFormat;
- DestinationColorSpace colorSpace;
- PixelFormat pixelFormat;
+ PixelBufferFormat format;
unsigned bytesPerRow;
const uint8_t* rows;
};
Copied: trunk/Source/WebCore/platform/graphics/PixelBufferFormat.cpp (from rev 277449, trunk/Source/WebCore/platform/graphics/PixelFormat.h) (0 => 277450)
--- trunk/Source/WebCore/platform/graphics/PixelBufferFormat.cpp (rev 0)
+++ trunk/Source/WebCore/platform/graphics/PixelBufferFormat.cpp 2021-05-13 20:54:21 UTC (rev 277450)
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 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
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "PixelBufferFormat.h"
+
+#include <wtf/text/TextStream.h>
+
+namespace WebCore {
+
+TextStream& operator<<(TextStream& ts, const PixelBufferFormat& pixelBuffer)
+{
+ return ts << pixelBuffer.alphaFormat << ' ' << pixelBuffer.pixelFormat << ' ' << pixelBuffer.colorSpace;
+}
+
+}
Copied: trunk/Source/WebCore/platform/graphics/PixelBufferFormat.h (from rev 277449, trunk/Source/WebCore/platform/graphics/PixelBufferConversion.h) (0 => 277450)
--- trunk/Source/WebCore/platform/graphics/PixelBufferFormat.h (rev 0)
+++ trunk/Source/WebCore/platform/graphics/PixelBufferFormat.h 2021-05-13 20:54:21 UTC (rev 277450)
@@ -0,0 +1,68 @@
+/*
+ * Copyright (C) 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
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#include "AlphaPremultiplication.h"
+#include "ColorSpace.h"
+#include "PixelFormat.h"
+#include <wtf/Forward.h>
+
+namespace WebCore {
+
+struct PixelBufferFormat {
+ AlphaPremultiplication alphaFormat;
+ PixelFormat pixelFormat;
+ DestinationColorSpace colorSpace;
+
+ template<class Encoder> void encode(Encoder&) const;
+ template<class Decoder> static Optional<PixelBufferFormat> decode(Decoder&);
+};
+
+WEBCORE_EXPORT TextStream& operator<<(TextStream&, const PixelBufferFormat&);
+
+template<class Encoder> void PixelBufferFormat::encode(Encoder& encoder) const
+{
+ encoder << alphaFormat << pixelFormat << colorSpace;
+}
+
+template<class Decoder> Optional<PixelBufferFormat> PixelBufferFormat::decode(Decoder& decoder)
+{
+ AlphaPremultiplication alphaFormat;
+ if (!decoder.decode(alphaFormat))
+ return WTF::nullopt;
+
+ PixelFormat pixelFormat;
+ if (!decoder.decode(pixelFormat))
+ return WTF::nullopt;
+
+ DestinationColorSpace colorSpace;
+ if (!decoder.decode(colorSpace))
+ return WTF::nullopt;
+
+ return { { alphaFormat, pixelFormat, colorSpace } };
+}
+
+}
Copied: trunk/Source/WebCore/platform/graphics/PixelFormat.cpp (from rev 277449, trunk/Source/WebCore/platform/graphics/PixelFormat.h) (0 => 277450)
--- trunk/Source/WebCore/platform/graphics/PixelFormat.cpp (rev 0)
+++ trunk/Source/WebCore/platform/graphics/PixelFormat.cpp 2021-05-13 20:54:21 UTC (rev 277450)
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 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
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "PixelFormat.h"
+
+#include <wtf/text/TextStream.h>
+
+namespace WebCore {
+
+TextStream& operator<<(TextStream& ts, PixelFormat pixelFormat)
+{
+ switch (pixelFormat) {
+ case PixelFormat::RGBA8:
+ ts << "RGBA8";
+ break;
+ case PixelFormat::BGRA8:
+ ts << "BGRA8";
+ break;
+ case PixelFormat::RGB10:
+ ts << "RGB10";
+ break;
+ case PixelFormat::RGB10A8:
+ ts << "RGB10A8";
+ break;
+ }
+ return ts;
+}
+
+}
Modified: trunk/Source/WebCore/platform/graphics/PixelFormat.h (277449 => 277450)
--- trunk/Source/WebCore/platform/graphics/PixelFormat.h 2021-05-13 20:47:38 UTC (rev 277449)
+++ trunk/Source/WebCore/platform/graphics/PixelFormat.h 2021-05-13 20:54:21 UTC (rev 277450)
@@ -26,6 +26,7 @@
#pragma once
#include <wtf/EnumTraits.h>
+#include <wtf/Forward.h>
namespace WebCore {
@@ -36,6 +37,8 @@
RGB10A8,
};
+WEBCORE_EXPORT TextStream& operator<<(TextStream&, PixelFormat);
+
}
namespace WTF {
Modified: trunk/Source/WebCore/platform/graphics/angle/GraphicsContextGLANGLE.cpp (277449 => 277450)
--- trunk/Source/WebCore/platform/graphics/angle/GraphicsContextGLANGLE.cpp 2021-05-13 20:47:38 UTC (rev 277449)
+++ trunk/Source/WebCore/platform/graphics/angle/GraphicsContextGLANGLE.cpp 2021-05-13 20:54:21 UTC (rev 277450)
@@ -79,7 +79,8 @@
Optional<PixelBuffer> GraphicsContextGLOpenGL::readPixelsForPaintResults()
{
- auto pixelBuffer = PixelBuffer::tryCreate(DestinationColorSpace::SRGB, PixelFormat::RGBA8, getInternalFramebufferSize());
+ PixelBufferFormat format { AlphaPremultiplication::Unpremultiplied, PixelFormat::RGBA8, DestinationColorSpace::SRGB };
+ auto pixelBuffer = PixelBuffer::tryCreate(format, getInternalFramebufferSize());
if (!pixelBuffer)
return WTF::nullopt;
ScopedPixelStorageMode packAlignment(GL_PACK_ALIGNMENT);
Modified: trunk/Source/WebCore/platform/graphics/cg/GraphicsContextGLCG.cpp (277449 => 277450)
--- trunk/Source/WebCore/platform/graphics/cg/GraphicsContextGLCG.cpp 2021-05-13 20:47:38 UTC (rev 277449)
+++ trunk/Source/WebCore/platform/graphics/cg/GraphicsContextGLCG.cpp 2021-05-13 20:54:21 UTC (rev 277450)
@@ -532,7 +532,7 @@
}));
auto imageSize = pixelBuffer.size();
- auto image = NativeImage::create(adoptCF(CGImageCreate(imageSize.width(), imageSize.height(), 8, 32, 4 * imageSize.width(), cachedCGColorSpace(pixelBuffer.colorSpace()), bitmapInfo, dataProvider.get(), 0, false, kCGRenderingIntentDefault)));
+ auto image = NativeImage::create(adoptCF(CGImageCreate(imageSize.width(), imageSize.height(), 8, 32, 4 * imageSize.width(), cachedCGColorSpace(pixelBuffer.format().colorSpace), bitmapInfo, dataProvider.get(), 0, false, kCGRenderingIntentDefault)));
// CSS styling may cause the canvas's content to be resized on
// the page. Go back to the Canvas to figure out the correct
Modified: trunk/Source/WebCore/platform/graphics/cg/ImageBufferCGBackend.cpp (277449 => 277450)
--- trunk/Source/WebCore/platform/graphics/cg/ImageBufferCGBackend.cpp 2021-05-13 20:47:38 UTC (rev 277449)
+++ trunk/Source/WebCore/platform/graphics/cg/ImageBufferCGBackend.cpp 2021-05-13 20:54:21 UTC (rev 277450)
@@ -201,7 +201,7 @@
return nullptr;
auto imageSize = pixelBuffer->size();
- image = adoptCF(CGImageCreate(imageSize.width(), imageSize.height(), 8, 32, 4 * imageSize.width(), cachedCGColorSpace(pixelBuffer->colorSpace()), kCGBitmapByteOrderDefault | kCGImageAlphaNoneSkipLast, dataProvider.get(), 0, false, kCGRenderingIntentDefault));
+ image = adoptCF(CGImageCreate(imageSize.width(), imageSize.height(), 8, 32, 4 * imageSize.width(), cachedCGColorSpace(pixelBuffer->format().colorSpace), kCGBitmapByteOrderDefault | kCGImageAlphaNoneSkipLast, dataProvider.get(), 0, false, kCGRenderingIntentDefault));
} else if (resolutionScale() == 1 || preserveResolution == PreserveResolution::Yes) {
auto nativeImage = copyNativeImage(CopyBackingStore);
if (!nativeImage)
Modified: trunk/Source/WebCore/platform/graphics/cg/ImageBufferUtilitiesCG.cpp (277449 => 277450)
--- trunk/Source/WebCore/platform/graphics/cg/ImageBufferUtilitiesCG.cpp 2021-05-13 20:47:38 UTC (rev 277449)
+++ trunk/Source/WebCore/platform/graphics/cg/ImageBufferUtilitiesCG.cpp 2021-05-13 20:54:21 UTC (rev 277450)
@@ -163,7 +163,7 @@
return nullptr;
auto imageSize = source.size();
- auto image = adoptCF(CGImageCreate(imageSize.width(), imageSize.height(), 8, 32, 4 * imageSize.width(), cachedCGColorSpace(source.colorSpace()), kCGBitmapByteOrderDefault | dataAlphaInfo, dataProvider.get(), 0, false, kCGRenderingIntentDefault));
+ auto image = adoptCF(CGImageCreate(imageSize.width(), imageSize.height(), 8, 32, 4 * imageSize.width(), cachedCGColorSpace(source.format().colorSpace), kCGBitmapByteOrderDefault | dataAlphaInfo, dataProvider.get(), 0, false, kCGRenderingIntentDefault));
auto cfData = adoptCF(CFDataCreateMutable(kCFAllocatorDefault, 0));
if (!encodeImage(image.get(), uti.get(), quality, cfData.get()))
Modified: trunk/Source/WebCore/platform/graphics/filters/FilterEffect.cpp (277449 => 277450)
--- trunk/Source/WebCore/platform/graphics/filters/FilterEffect.cpp 2021-05-13 20:47:38 UTC (rev 277449)
+++ trunk/Source/WebCore/platform/graphics/filters/FilterEffect.cpp 2021-05-13 20:54:21 UTC (rev 277450)
@@ -505,7 +505,8 @@
IntSize inputSize(m_absolutePaintRect.size());
ASSERT(!ImageBuffer::sizeNeedsClamping(inputSize));
inputSize.scale(m_filter.filterScale());
- m_unmultipliedImageResult = PixelBuffer::tryCreate(DestinationColorSpace::SRGB, PixelFormat::RGBA8, inputSize);
+ PixelBufferFormat format { AlphaPremultiplication::Unpremultiplied, PixelFormat::RGBA8, DestinationColorSpace::SRGB };
+ m_unmultipliedImageResult = PixelBuffer::tryCreate(format, inputSize);
if (!m_unmultipliedImageResult)
return;
copyUnpremultiplyingAlpha(m_premultipliedImageResult->data(), m_unmultipliedImageResult->data(), inputSize);
@@ -538,7 +539,8 @@
IntSize inputSize(m_absolutePaintRect.size());
ASSERT(!ImageBuffer::sizeNeedsClamping(inputSize));
inputSize.scale(m_filter.filterScale());
- m_premultipliedImageResult = PixelBuffer::tryCreate(DestinationColorSpace::SRGB, PixelFormat::RGBA8, inputSize);
+ PixelBufferFormat format { AlphaPremultiplication::Premultiplied, PixelFormat::RGBA8, DestinationColorSpace::SRGB };
+ m_premultipliedImageResult = PixelBuffer::tryCreate(format, inputSize);
if (!m_premultipliedImageResult)
return;
copyPremultiplyingAlpha(m_unmultipliedImageResult->data(), m_premultipliedImageResult->data(), inputSize);
@@ -580,7 +582,8 @@
IntSize resultSize(m_absolutePaintRect.size());
ASSERT(!ImageBuffer::sizeNeedsClamping(resultSize));
resultSize.scale(m_filter.filterScale());
- m_unmultipliedImageResult = PixelBuffer::tryCreate(DestinationColorSpace::SRGB, PixelFormat::RGBA8, resultSize);
+ PixelBufferFormat format { AlphaPremultiplication::Unpremultiplied, PixelFormat::RGBA8, DestinationColorSpace::SRGB };
+ m_unmultipliedImageResult = PixelBuffer::tryCreate(format, resultSize);
return m_unmultipliedImageResult;
}
@@ -598,7 +601,8 @@
IntSize resultSize(m_absolutePaintRect.size());
ASSERT(!ImageBuffer::sizeNeedsClamping(resultSize));
resultSize.scale(m_filter.filterScale());
- m_premultipliedImageResult = PixelBuffer::tryCreate(DestinationColorSpace::SRGB, PixelFormat::RGBA8, resultSize);
+ PixelBufferFormat format { AlphaPremultiplication::Premultiplied, PixelFormat::RGBA8, DestinationColorSpace::SRGB };
+ m_premultipliedImageResult = PixelBuffer::tryCreate(format, resultSize);
return m_premultipliedImageResult;
}
Modified: trunk/Source/WebCore/platform/graphics/opengl/GraphicsContextGLOpenGLBase.cpp (277449 => 277450)
--- trunk/Source/WebCore/platform/graphics/opengl/GraphicsContextGLOpenGLBase.cpp 2021-05-13 20:47:38 UTC (rev 277449)
+++ trunk/Source/WebCore/platform/graphics/opengl/GraphicsContextGLOpenGLBase.cpp 2021-05-13 20:54:21 UTC (rev 277450)
@@ -63,7 +63,8 @@
Optional<PixelBuffer> GraphicsContextGLOpenGL::readPixelsForPaintResults()
{
- auto pixelBuffer = PixelBuffer::tryCreate(DestinationColorSpace::SRGB, PixelFormat::RGBA8, getInternalFramebufferSize());
+ PixelBufferFormat format { AlphaPremultiplication::Unpremultiplied, PixelFormat::RGBA8, DestinationColorSpace::SRGB };
+ auto pixelBuffer = PixelBuffer::tryCreate(format, getInternalFramebufferSize());
if (!pixelBuffer)
return WTF::nullopt;
Modified: trunk/Source/WebCore/platform/graphics/opengl/GraphicsContextGLOpenGLES.cpp (277449 => 277450)
--- trunk/Source/WebCore/platform/graphics/opengl/GraphicsContextGLOpenGLES.cpp 2021-05-13 20:47:38 UTC (rev 277449)
+++ trunk/Source/WebCore/platform/graphics/opengl/GraphicsContextGLOpenGLES.cpp 2021-05-13 20:54:21 UTC (rev 277450)
@@ -66,7 +66,8 @@
Optional<PixelBuffer> GraphicsContextGLOpenGL::readPixelsForPaintResults()
{
- auto pixelBuffer = PixelBuffer::tryCreate(DestinationColorSpace::SRGB, PixelFormat::RGBA8, getInternalFramebufferSize());
+ PixelBufferFormat format { AlphaPremultiplication::Unpremultiplied, PixelFormat::RGBA8, DestinationColorSpace::SRGB };
+ auto pixelBuffer = PixelBuffer::tryCreate(format, getInternalFramebufferSize());
if (!pixelBuffer)
return WTF::nullopt;
Modified: trunk/Source/WebKit/ChangeLog (277449 => 277450)
--- trunk/Source/WebKit/ChangeLog 2021-05-13 20:47:38 UTC (rev 277449)
+++ trunk/Source/WebKit/ChangeLog 2021-05-13 20:54:21 UTC (rev 277450)
@@ -1,3 +1,13 @@
+2021-05-13 Sam Weinig <wei...@apple.com>
+
+ Split pixel buffer format data out into a new PixelBufferFormat struct
+ https://bugs.webkit.org/show_bug.cgi?id=225707
+
+ Reviewed by Darin Adler.
+
+ * WebProcess/GPU/graphics/RemoteImageBufferProxy.h:
+ Adopt PixelBufferFormat.
+
2021-05-13 Chris Dumez <cdu...@apple.com>
Rename FileSystem::directoryName() to FileSystem::parentPath()
Modified: trunk/Source/WebKit/WebProcess/GPU/graphics/RemoteImageBufferProxy.h (277449 => 277450)
--- trunk/Source/WebKit/WebProcess/GPU/graphics/RemoteImageBufferProxy.h 2021-05-13 20:47:38 UTC (rev 277449)
+++ trunk/Source/WebKit/WebProcess/GPU/graphics/RemoteImageBufferProxy.h 2021-05-13 20:54:21 UTC (rev 277450)
@@ -199,7 +199,8 @@
if (UNLIKELY(!m_remoteRenderingBackendProxy))
return WTF::nullopt;
- auto pixelBuffer = WebCore::PixelBuffer::tryCreate(WebCore::DestinationColorSpace::SRGB, WebCore::PixelFormat::RGBA8, srcRect.size());
+ WebCore::PixelBufferFormat destinationFormat { outputFormat, WebCore::PixelFormat::RGBA8, WebCore::DestinationColorSpace::SRGB };
+ auto pixelBuffer = WebCore::PixelBuffer::tryCreate(destinationFormat, srcRect.size());
if (!pixelBuffer)
return WTF::nullopt;
size_t dataSize = pixelBuffer->data().byteLength();