Diff
Modified: trunk/Source/WebCore/Headers.cmake (295226 => 295227)
--- trunk/Source/WebCore/Headers.cmake 2022-06-03 20:39:35 UTC (rev 295226)
+++ trunk/Source/WebCore/Headers.cmake 2022-06-03 20:52:52 UTC (rev 295227)
@@ -1447,6 +1447,7 @@
platform/graphics/CopyImageOptions.h
platform/graphics/BifurcatedGraphicsContext.h
platform/graphics/BitmapImage.h
+ platform/graphics/ByteArrayPixelBuffer.h
platform/graphics/Color.h
platform/graphics/ColorComponents.h
platform/graphics/ColorConversion.h
Modified: trunk/Source/WebCore/Sources.txt (295226 => 295227)
--- trunk/Source/WebCore/Sources.txt 2022-06-03 20:39:35 UTC (rev 295226)
+++ trunk/Source/WebCore/Sources.txt 2022-06-03 20:52:52 UTC (rev 295227)
@@ -2017,6 +2017,7 @@
platform/graphics/AnimationFrameRate.cpp
platform/graphics/BifurcatedGraphicsContext.cpp
platform/graphics/BitmapImage.cpp
+platform/graphics/ByteArrayPixelBuffer.cpp
platform/graphics/Color.cpp
platform/graphics/ColorBlending.cpp
platform/graphics/ColorConversion.cpp
Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (295226 => 295227)
--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2022-06-03 20:39:35 UTC (rev 295226)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2022-06-03 20:52:52 UTC (rev 295227)
@@ -2379,6 +2379,7 @@
72B8B0352753438600F752AA /* FilterFunction.h in Headers */ = {isa = PBXBuildFile; fileRef = 7262D756272A174100C56A09 /* FilterFunction.h */; settings = {ATTRIBUTES = (Private, ); }; };
72B8B0362753441400F752AA /* FilterImage.h in Headers */ = {isa = PBXBuildFile; fileRef = 72435EF4273D07670005E7EE /* FilterImage.h */; settings = {ATTRIBUTES = (Private, ); }; };
72BAC3AE23E1F0B0008D741C /* ImageBufferBackend.h in Headers */ = {isa = PBXBuildFile; fileRef = 72BAC3A523E17328008D741C /* ImageBufferBackend.h */; settings = {ATTRIBUTES = (Private, ); }; };
+ 72C11DAD2849425800E826DD /* ByteArrayPixelBuffer.h in Headers */ = {isa = PBXBuildFile; fileRef = 72C11DAC28492A9200E826DD /* ByteArrayPixelBuffer.h */; settings = {ATTRIBUTES = (Private, ); }; };
72D73644278461A000398663 /* FilterResults.h in Headers */ = {isa = PBXBuildFile; fileRef = 7211B5D6276536820076FEF8 /* FilterResults.h */; settings = {ATTRIBUTES = (Private, ); }; };
72E5768B281B2B5500A75432 /* CopyImageOptions.h in Headers */ = {isa = PBXBuildFile; fileRef = 72E5768A281B292600A75432 /* CopyImageOptions.h */; settings = {ATTRIBUTES = (Private, ); }; };
72F667E1260C26AC00EE36AD /* DiagnosticLoggingDomain.h in Headers */ = {isa = PBXBuildFile; fileRef = 72F667DF260C264400EE36AD /* DiagnosticLoggingDomain.h */; settings = {ATTRIBUTES = (Private, ); }; };
@@ -11493,6 +11494,8 @@
72BAC3AB23E1E544008D741C /* ImageBufferIOSurfaceBackend.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ImageBufferIOSurfaceBackend.h; sourceTree = "<group>"; };
72BAC3AC23E1E545008D741C /* ImageBufferCGBackend.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ImageBufferCGBackend.cpp; sourceTree = "<group>"; };
72BAC3AD23E1E545008D741C /* ImageBufferCGBackend.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ImageBufferCGBackend.h; sourceTree = "<group>"; };
+ 72C11DAB28492A9200E826DD /* ByteArrayPixelBuffer.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = ByteArrayPixelBuffer.cpp; sourceTree = "<group>"; };
+ 72C11DAC28492A9200E826DD /* ByteArrayPixelBuffer.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ByteArrayPixelBuffer.h; sourceTree = "<group>"; };
72C18A3F230B04B7006847C7 /* ImagePaintingOptions.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ImagePaintingOptions.h; sourceTree = "<group>"; };
72E417611A2E8D2F004C562A /* JSEXTsRGB.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSEXTsRGB.cpp; sourceTree = "<group>"; };
72E417621A2E8D2F004C562A /* JSEXTsRGB.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSEXTsRGB.h; sourceTree = "<group>"; };
@@ -29125,6 +29128,8 @@
2DD87149265F4365005F997C /* BifurcatedGraphicsContext.h */,
A89943270B42338700D7C802 /* BitmapImage.cpp */,
A89943260B42338700D7C802 /* BitmapImage.h */,
+ 72C11DAB28492A9200E826DD /* ByteArrayPixelBuffer.cpp */,
+ 72C11DAC28492A9200E826DD /* ByteArrayPixelBuffer.h */,
B27535380B053814002CE64F /* Color.cpp */,
B27535390B053814002CE64F /* Color.h */,
7C1B4A6524A997590033727F /* ColorBlending.cpp */,
@@ -35325,6 +35330,7 @@
517138F81BF128BB000D5F01 /* IndexValueStore.h in Headers */,
CD063F831E23FA8900812BE3 /* InitDataRegistry.h in Headers */,
E4F819C626FB4EBF0094E162 /* InlineBoxPainter.h in Headers */,
+ 72C11DAD2849425800E826DD /* ByteArrayPixelBuffer.h in Headers */,
E30592641E27A3AD00D57C98 /* InlineClassicScript.h in Headers */,
6FE198172178397C00446F08 /* InlineContentBreaker.h in Headers */,
111FA1C826F0F30F003B8F16 /* InlineDamage.h in Headers */,
Modified: trunk/Source/WebCore/bindings/js/SerializedScriptValue.cpp (295226 => 295227)
--- trunk/Source/WebCore/bindings/js/SerializedScriptValue.cpp 2022-06-03 20:39:35 UTC (rev 295226)
+++ trunk/Source/WebCore/bindings/js/SerializedScriptValue.cpp 2022-06-03 20:52:52 UTC (rev 295227)
@@ -28,6 +28,7 @@
#include "SerializedScriptValue.h"
#include "BlobRegistry.h"
+#include "ByteArrayPixelBuffer.h"
#include "CryptoKeyAES.h"
#include "CryptoKeyEC.h"
#include "CryptoKeyHMAC.h"
@@ -1111,12 +1112,12 @@
PixelBufferFormat format { AlphaPremultiplication::Premultiplied, PixelFormat::RGBA8, buffer->colorSpace() };
const IntSize& logicalSize = buffer->truncatedLogicalSize();
auto pixelBuffer = buffer->getPixelBuffer(format, { IntPoint::zero(), logicalSize });
- if (!pixelBuffer) {
+ if (!is<ByteArrayPixelBuffer>(pixelBuffer)) {
code = SerializationReturnCode::ValidationError;
return;
}
- auto arrayBuffer = pixelBuffer->data().possiblySharedBuffer();
+ auto arrayBuffer = downcast<ByteArrayPixelBuffer>(*pixelBuffer).data().possiblySharedBuffer();
if (!arrayBuffer) {
code = SerializationReturnCode::ValidationError;
return;
@@ -3388,7 +3389,7 @@
}
PixelBufferFormat format { AlphaPremultiplication::Premultiplied, PixelFormat::RGBA8, colorSpace };
- auto pixelBuffer = PixelBuffer::tryCreate(format, imageDataSize, arrayBuffer.releaseNonNull());
+ auto pixelBuffer = ByteArrayPixelBuffer::tryCreate(format, imageDataSize, arrayBuffer.releaseNonNull());
if (!pixelBuffer) {
fail();
return JSValue();
Modified: trunk/Source/WebCore/html/HTMLCanvasElement.cpp (295226 => 295227)
--- trunk/Source/WebCore/html/HTMLCanvasElement.cpp 2022-06-03 20:39:35 UTC (rev 295226)
+++ trunk/Source/WebCore/html/HTMLCanvasElement.cpp 2022-06-03 20:52:52 UTC (rev 295227)
@@ -763,13 +763,20 @@
RefPtr<ImageData> HTMLCanvasElement::getImageData()
{
#if ENABLE(WEBGL)
- if (is<WebGLRenderingContextBase>(m_context)) {
- if (RuntimeEnabledFeatures::sharedFeatures().webAPIStatisticsEnabled())
- ResourceLoadObserver::shared().logCanvasRead(document());
- return ImageData::create(downcast<WebGLRenderingContextBase>(*m_context).paintRenderingResultsToPixelBuffer());
- }
+ if (!is<WebGLRenderingContextBase>(m_context))
+ return nullptr;
+
+ if (RuntimeEnabledFeatures::sharedFeatures().webAPIStatisticsEnabled())
+ ResourceLoadObserver::shared().logCanvasRead(document());
+
+ auto pixelBuffer = downcast<WebGLRenderingContextBase>(*m_context).paintRenderingResultsToPixelBuffer();
+ if (!is<ByteArrayPixelBuffer>(pixelBuffer))
+ return nullptr;
+
+ return ImageData::create(static_reference_cast<ByteArrayPixelBuffer>(pixelBuffer.releaseNonNull()));
+#else
+ return nullptr;
#endif
- return nullptr;
}
#if ENABLE(MEDIA_STREAM)
Modified: trunk/Source/WebCore/html/ImageData.cpp (295226 => 295227)
--- trunk/Source/WebCore/html/ImageData.cpp 2022-06-03 20:39:35 UTC (rev 295226)
+++ trunk/Source/WebCore/html/ImageData.cpp 2022-06-03 20:52:52 UTC (rev 295227)
@@ -50,13 +50,13 @@
return defaultColorSpace;
}
-Ref<ImageData> ImageData::create(Ref<PixelBuffer>&& pixelBuffer)
+Ref<ImageData> ImageData::create(Ref<ByteArrayPixelBuffer>&& pixelBuffer)
{
auto colorSpace = toPredefinedColorSpace(pixelBuffer->format().colorSpace);
return adoptRef(*new ImageData(pixelBuffer->size(), pixelBuffer->takeData(), *colorSpace));
}
-RefPtr<ImageData> ImageData::create(RefPtr<PixelBuffer>&& pixelBuffer)
+RefPtr<ImageData> ImageData::create(RefPtr<ByteArrayPixelBuffer>&& pixelBuffer)
{
if (!pixelBuffer)
return nullptr;
@@ -153,10 +153,10 @@
ImageData::~ImageData() = default;
-Ref<PixelBuffer> ImageData::pixelBuffer() const
+Ref<ByteArrayPixelBuffer> ImageData::pixelBuffer() const
{
PixelBufferFormat format { AlphaPremultiplication::Unpremultiplied, PixelFormat::RGBA8, toDestinationColorSpace(m_colorSpace) };
- return PixelBuffer::create(format, m_size, m_data.get());
+ return ByteArrayPixelBuffer::create(format, m_size, m_data.get());
}
TextStream& operator<<(TextStream& ts, const ImageData& imageData)
Modified: trunk/Source/WebCore/html/ImageData.h (295226 => 295227)
--- trunk/Source/WebCore/html/ImageData.h 2022-06-03 20:39:35 UTC (rev 295226)
+++ trunk/Source/WebCore/html/ImageData.h 2022-06-03 20:52:52 UTC (rev 295227)
@@ -28,10 +28,10 @@
#pragma once
+#include "ByteArrayPixelBuffer.h"
#include "ExceptionOr.h"
#include "ImageDataSettings.h"
#include "IntSize.h"
-#include "PixelBuffer.h"
#include "PredefinedColorSpace.h"
#include <_javascript_Core/Forward.h>
#include <wtf/Forward.h>
@@ -40,8 +40,8 @@
class ImageData : public RefCounted<ImageData> {
public:
- WEBCORE_EXPORT static Ref<ImageData> create(Ref<PixelBuffer>&&);
- WEBCORE_EXPORT static RefPtr<ImageData> create(RefPtr<PixelBuffer>&&);
+ WEBCORE_EXPORT static Ref<ImageData> create(Ref<ByteArrayPixelBuffer>&&);
+ WEBCORE_EXPORT static RefPtr<ImageData> create(RefPtr<ByteArrayPixelBuffer>&&);
WEBCORE_EXPORT static RefPtr<ImageData> create(const IntSize&);
WEBCORE_EXPORT static RefPtr<ImageData> create(const IntSize&, Ref<Uint8ClampedArray>&&, PredefinedColorSpace);
WEBCORE_EXPORT static ExceptionOr<Ref<ImageData>> createUninitialized(unsigned rows, unsigned pixelsPerRow, PredefinedColorSpace defaultColorSpace, std::optional<ImageDataSettings> = std::nullopt);
@@ -59,7 +59,7 @@
Uint8ClampedArray& data() const { return m_data.get(); }
PredefinedColorSpace colorSpace() const { return m_colorSpace; }
- Ref<PixelBuffer> pixelBuffer() const;
+ Ref<ByteArrayPixelBuffer> pixelBuffer() const;
private:
explicit ImageData(const IntSize&, Ref<JSC::Uint8ClampedArray>&&, PredefinedColorSpace);
Modified: trunk/Source/WebCore/html/canvas/CanvasRenderingContext2DBase.cpp (295226 => 295227)
--- trunk/Source/WebCore/html/canvas/CanvasRenderingContext2DBase.cpp 2022-06-03 20:39:35 UTC (rev 295226)
+++ trunk/Source/WebCore/html/canvas/CanvasRenderingContext2DBase.cpp 2022-06-03 20:52:52 UTC (rev 295227)
@@ -2188,7 +2188,7 @@
PixelBufferFormat format { AlphaPremultiplication::Unpremultiplied, PixelFormat::RGBA8, toDestinationColorSpace(computedColorSpace) };
auto pixelBuffer = buffer->getPixelBuffer(format, imageDataRect);
- if (!pixelBuffer) {
+ if (!is<ByteArrayPixelBuffer>(pixelBuffer)) {
canvasBase().scriptExecutionContext()->addConsoleMessage(MessageSource::Rendering, MessageLevel::Error,
makeString("Unable to get image data from canvas. Requested size was ", imageDataRect.width(), " x ", imageDataRect.height()));
return Exception { InvalidStateError };
@@ -2196,7 +2196,7 @@
ASSERT(pixelBuffer->format().colorSpace == toDestinationColorSpace(computedColorSpace));
- return { { ImageData::create(pixelBuffer.releaseNonNull()) } };
+ return { { ImageData::create(static_reference_cast<ByteArrayPixelBuffer>(pixelBuffer.releaseNonNull())) } };
}
void CanvasRenderingContext2DBase::putImageData(ImageData& data, int dx, int dy)
Modified: trunk/Source/WebCore/page/PageColorSampler.cpp (295226 => 295227)
--- trunk/Source/WebCore/page/PageColorSampler.cpp 2022-06-03 20:39:35 UTC (rev 295226)
+++ trunk/Source/WebCore/page/PageColorSampler.cpp 2022-06-03 20:52:52 UTC (rev 295227)
@@ -128,10 +128,10 @@
if (!pixelBuffer)
return std::nullopt;
- if (pixelBuffer->data().length() < 4)
+ if (pixelBuffer->sizeInBytes() < 4)
return std::nullopt;
- auto snapshotData = pixelBuffer->data().data();
+ auto snapshotData = pixelBuffer->bytes();
return convertColor<Lab<float>>(SRGBA<uint8_t> { snapshotData[2], snapshotData[1], snapshotData[0], snapshotData[3] });
}
Added: trunk/Source/WebCore/platform/graphics/ByteArrayPixelBuffer.cpp (0 => 295227)
--- trunk/Source/WebCore/platform/graphics/ByteArrayPixelBuffer.cpp (rev 0)
+++ trunk/Source/WebCore/platform/graphics/ByteArrayPixelBuffer.cpp 2022-06-03 20:52:52 UTC (rev 295227)
@@ -0,0 +1,95 @@
+/*
+ * Copyright (C) 2022 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. 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 "ByteArrayPixelBuffer.h"
+
+#include <_javascript_Core/TypedArrayInlines.h>
+
+namespace WebCore {
+
+Ref<ByteArrayPixelBuffer> ByteArrayPixelBuffer::create(const PixelBufferFormat& format, const IntSize& size, JSC::Uint8ClampedArray& data)
+{
+ return adoptRef(*new ByteArrayPixelBuffer(format, size, { data }));
+}
+
+RefPtr<ByteArrayPixelBuffer> ByteArrayPixelBuffer::tryCreate(const PixelBufferFormat& format, const IntSize& size)
+{
+ ASSERT(supportedPixelFormat(format.pixelFormat));
+
+ auto bufferSize = computeBufferSize(format, size);
+ if (bufferSize.hasOverflowed())
+ return nullptr;
+ if (bufferSize > std::numeric_limits<int32_t>::max())
+ return nullptr;
+
+ auto data = ""
+ if (!data)
+ return nullptr;
+
+ return create(format, size, data.releaseNonNull());
+}
+
+RefPtr<ByteArrayPixelBuffer> ByteArrayPixelBuffer::tryCreate(const PixelBufferFormat& format, const IntSize& size, Ref<JSC::ArrayBuffer>&& arrayBuffer)
+{
+ ASSERT(supportedPixelFormat(format.pixelFormat));
+
+ auto bufferSize = computeBufferSize(format, size);
+ if (bufferSize.hasOverflowed())
+ return nullptr;
+ if (bufferSize != arrayBuffer->byteLength())
+ return nullptr;
+
+ auto data = "" 0, bufferSize);
+ if (!data)
+ return nullptr;
+
+ return create(format, size, data.releaseNonNull());
+}
+
+RefPtr<ByteArrayPixelBuffer> ByteArrayPixelBuffer::tryCreate(const PixelBufferFormat& format, const IntSize& size, unsigned dataByteLength)
+{
+ ASSERT(supportedPixelFormat(format.pixelFormat));
+ ASSERT(computeBufferSize(format, size) == dataByteLength);
+
+ auto data = ""
+ if (!data)
+ return nullptr;
+
+ return create(format, size, data.releaseNonNull());
+}
+
+ByteArrayPixelBuffer::ByteArrayPixelBuffer(const PixelBufferFormat& format, const IntSize& size, Ref<JSC::Uint8ClampedArray>&& data)
+ : PixelBuffer(format, size, data->data(), data->byteLength())
+ , m_data(WTFMove(data))
+{
+}
+
+RefPtr<PixelBuffer> ByteArrayPixelBuffer::createScratchPixelBuffer(const IntSize& size) const
+{
+ return ByteArrayPixelBuffer::tryCreate(m_format, size);
+}
+
+} // namespace WebCore
Added: trunk/Source/WebCore/platform/graphics/ByteArrayPixelBuffer.h (0 => 295227)
--- trunk/Source/WebCore/platform/graphics/ByteArrayPixelBuffer.h (rev 0)
+++ trunk/Source/WebCore/platform/graphics/ByteArrayPixelBuffer.h 2022-06-03 20:52:52 UTC (rev 295227)
@@ -0,0 +1,105 @@
+/*
+ * Copyright (C) 2022 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#include "PixelBuffer.h"
+#include <_javascript_Core/Uint8ClampedArray.h>
+
+namespace WebCore {
+
+class ByteArrayPixelBuffer : public PixelBuffer {
+public:
+ WEBCORE_EXPORT static Ref<ByteArrayPixelBuffer> create(const PixelBufferFormat&, const IntSize&, JSC::Uint8ClampedArray&);
+
+ WEBCORE_EXPORT static RefPtr<ByteArrayPixelBuffer> tryCreate(const PixelBufferFormat&, const IntSize&);
+ WEBCORE_EXPORT static RefPtr<ByteArrayPixelBuffer> tryCreate(const PixelBufferFormat&, const IntSize&, Ref<JSC::ArrayBuffer>&&);
+
+ JSC::Uint8ClampedArray& data() const { return m_data.get(); }
+ Ref<JSC::Uint8ClampedArray>&& takeData() { return WTFMove(m_data); }
+
+ RefPtr<PixelBuffer> createScratchPixelBuffer(const IntSize&) const override;
+
+ template<class Encoder> void encode(Encoder&) const;
+ template<class Decoder> static std::optional<Ref<ByteArrayPixelBuffer>> decode(Decoder&);
+
+private:
+ WEBCORE_EXPORT static RefPtr<ByteArrayPixelBuffer> tryCreate(const PixelBufferFormat&, const IntSize&, unsigned dataByteLength);
+
+ ByteArrayPixelBuffer(const PixelBufferFormat&, const IntSize&, Ref<JSC::Uint8ClampedArray>&&);
+
+ bool isByteArrayPixelBuffer() const override { return true; }
+
+ Ref<JSC::Uint8ClampedArray> m_data;
+};
+
+template<class Encoder> void ByteArrayPixelBuffer::encode(Encoder& encoder) const
+{
+ ASSERT(m_data->byteLength() == (m_size.area() * 4));
+
+ encoder << m_format;
+ encoder << m_size;
+ encoder.encodeFixedLengthData(m_data->data(), m_data->byteLength(), 1);
+}
+
+template<class Decoder> std::optional<Ref<ByteArrayPixelBuffer>> ByteArrayPixelBuffer::decode(Decoder& decoder)
+{
+ std::optional<PixelBufferFormat> format;
+ decoder >> format;
+ if (!format)
+ return std::nullopt;
+
+ // FIXME: Support non-8 bit formats.
+ if (!(format->pixelFormat == PixelFormat::RGBA8 || format->pixelFormat == PixelFormat::BGRA8))
+ return std::nullopt;
+
+ std::optional<IntSize> size;
+ decoder >> size;
+ if (!size)
+ return std::nullopt;
+
+ auto computedBufferSize = PixelBuffer::computeBufferSize(*format, *size);
+ if (computedBufferSize.hasOverflowed())
+ return std::nullopt;
+
+ auto bufferSize = computedBufferSize;
+ if (!decoder.template bufferIsLargeEnoughToContain<uint8_t>(bufferSize))
+ return std::nullopt;
+
+ auto result = ByteArrayPixelBuffer::tryCreate(WTFMove(*format), *size, bufferSize);
+ if (!result)
+ return std::nullopt;
+
+ if (!decoder.decodeFixedLengthData(result->m_data->data(), result->m_data->byteLength(), 1))
+ return std::nullopt;
+
+ return result.releaseNonNull();
+}
+
+} // namespace WebCore
+
+SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::ByteArrayPixelBuffer)
+ static bool isType(const WebCore::PixelBuffer& pixelBuffer) { return pixelBuffer.isByteArrayPixelBuffer(); }
+SPECIALIZE_TYPE_TRAITS_END()
Modified: trunk/Source/WebCore/platform/graphics/GraphicsContextGL.cpp (295226 => 295227)
--- trunk/Source/WebCore/platform/graphics/GraphicsContextGL.cpp 2022-06-03 20:39:35 UTC (rev 295226)
+++ trunk/Source/WebCore/platform/graphics/GraphicsContextGL.cpp 2022-06-03 20:52:52 UTC (rev 295227)
@@ -570,7 +570,7 @@
return false;
data.resize(packedSize);
- if (!packPixels(pixelBuffer.data().data(), sourceDataFormat, width, height, sourceImageSubRectangle, depth, 0, unpackImageHeight, format, type, premultiplyAlpha ? AlphaOp::DoPremultiply : AlphaOp::DoNothing, data.data(), flipY))
+ if (!packPixels(pixelBuffer.bytes(), sourceDataFormat, width, height, sourceImageSubRectangle, depth, 0, unpackImageHeight, format, type, premultiplyAlpha ? AlphaOp::DoPremultiply : AlphaOp::DoNothing, data.data(), flipY))
return false;
return true;
Modified: trunk/Source/WebCore/platform/graphics/ImageBufferAllocator.cpp (295226 => 295227)
--- trunk/Source/WebCore/platform/graphics/ImageBufferAllocator.cpp 2022-06-03 20:39:35 UTC (rev 295226)
+++ trunk/Source/WebCore/platform/graphics/ImageBufferAllocator.cpp 2022-06-03 20:52:52 UTC (rev 295227)
@@ -26,8 +26,8 @@
#include "config.h"
#include "ImageBufferAllocator.h"
+#include "ByteArrayPixelBuffer.h"
#include "ImageBuffer.h"
-#include "PixelBuffer.h"
namespace WebCore {
@@ -40,7 +40,7 @@
RefPtr<PixelBuffer> ImageBufferAllocator::createPixelBuffer(const PixelBufferFormat& format, const IntSize& size) const
{
- return PixelBuffer::tryCreate(format, size);
+ return ByteArrayPixelBuffer::tryCreate(format, size);
}
} // namespace WebCore
Modified: trunk/Source/WebCore/platform/graphics/ImageBufferBackend.cpp (295226 => 295227)
--- trunk/Source/WebCore/platform/graphics/ImageBufferBackend.cpp 2022-06-03 20:39:35 UTC (rev 295226)
+++ trunk/Source/WebCore/platform/graphics/ImageBufferBackend.cpp 2022-06-03 20:52:52 UTC (rev 295227)
@@ -72,18 +72,17 @@
if (!pixelBuffer)
return;
- auto& pixelArray = pixelBuffer->data();
- unsigned pixelArrayLength = pixelArray.length();
+ unsigned pixelArrayLength = pixelBuffer->sizeInBytes();
for (unsigned pixelOffset = 0; pixelOffset < pixelArrayLength; pixelOffset += 4) {
- uint8_t a = pixelArray.item(pixelOffset + 3);
+ uint8_t a = pixelBuffer->item(pixelOffset + 3);
if (!a)
continue;
- uint8_t r = pixelArray.item(pixelOffset);
- uint8_t g = pixelArray.item(pixelOffset + 1);
- uint8_t b = pixelArray.item(pixelOffset + 2);
+ uint8_t r = pixelBuffer->item(pixelOffset);
+ uint8_t g = pixelBuffer->item(pixelOffset + 1);
+ uint8_t b = pixelBuffer->item(pixelOffset + 2);
double luma = (r * 0.2125 + g * 0.7154 + b * 0.0721) * ((double)a / 255.0);
- pixelArray.set(pixelOffset + 3, luma);
+ pixelBuffer->set(pixelOffset + 3, luma);
}
putPixelBuffer(*pixelBuffer, logicalRect(), IntPoint::zero(), AlphaPremultiplication::Premultiplied);
@@ -109,7 +108,7 @@
destinationRect.setY(-sourceRectScaled.y());
if (destinationRect.size() != sourceRectScaled.size())
- pixelBuffer->data().zeroFill();
+ pixelBuffer->zeroFill();
ConstPixelBufferConversionView source {
{ AlphaPremultiplication::Premultiplied, pixelFormat(), colorSpace() },
@@ -120,7 +119,7 @@
PixelBufferConversionView destination {
destinationFormat,
static_cast<unsigned>(4 * sourceRectScaled.width()),
- pixelBuffer->data().data() + destinationRect.y() * destination.bytesPerRow + destinationRect.x() * 4
+ pixelBuffer->bytes() + destinationRect.y() * destination.bytesPerRow + destinationRect.x() * 4
};
convertImagePixels(source, destination, destinationRect.size());
@@ -149,7 +148,7 @@
ConstPixelBufferConversionView source {
sourcePixelBuffer.format(),
static_cast<unsigned>(4 * sourcePixelBuffer.size().width()),
- sourcePixelBuffer.data().data() + sourceRectClipped.y() * source.bytesPerRow + sourceRectClipped.x() * 4
+ sourcePixelBuffer.bytes() + sourceRectClipped.y() * source.bytesPerRow + sourceRectClipped.x() * 4
};
PixelBufferConversionView destination {
Modified: trunk/Source/WebCore/platform/graphics/PixelBuffer.cpp (295226 => 295227)
--- trunk/Source/WebCore/platform/graphics/PixelBuffer.cpp 2022-06-03 20:39:35 UTC (rev 295226)
+++ trunk/Source/WebCore/platform/graphics/PixelBuffer.cpp 2022-06-03 20:52:52 UTC (rev 295227)
@@ -42,7 +42,7 @@
case PixelFormat::RGB10A8:
return false;
}
-
+
ASSERT_NOT_REACHED();
return false;
}
@@ -56,119 +56,45 @@
return size.area<RecordOverflow>() * bytesPerPixel;
}
-RefPtr<PixelBuffer> PixelBuffer::tryCreateForDecoding(const PixelBufferFormat& format, const IntSize& size, unsigned dataByteLength)
+PixelBuffer::PixelBuffer(const PixelBufferFormat& format, const IntSize& size, uint8_t* bytes, size_t sizeInBytes)
+ : m_format(format)
+ , m_size(size)
+ , m_bytes(bytes)
+ , m_sizeInBytes(sizeInBytes)
{
- ASSERT(supportedPixelFormat(format.pixelFormat));
- ASSERT(computeBufferSize(format, size) == dataByteLength);
-
- auto pixelArray = Uint8ClampedArray::tryCreateUninitialized(dataByteLength);
- if (!pixelArray)
- return nullptr;
- return adoptRef(new PixelBuffer(format, size, pixelArray.releaseNonNull()));
+ RELEASE_ASSERT_WITH_SECURITY_IMPLICATION((m_size.area() * 4) <= m_sizeInBytes);
}
-RefPtr<PixelBuffer> PixelBuffer::tryCreate(const PixelBufferFormat& format, const IntSize& size)
-{
- ASSERT(supportedPixelFormat(format.pixelFormat));
-
- auto bufferSize = computeBufferSize(format, size);
- if (bufferSize.hasOverflowed())
- return nullptr;
- if (bufferSize > std::numeric_limits<int32_t>::max())
- return nullptr;
- auto pixelArray = Uint8ClampedArray::tryCreateUninitialized(bufferSize);
- if (!pixelArray)
- return nullptr;
- return adoptRef(new PixelBuffer(format, size, pixelArray.releaseNonNull()));
-}
-
-RefPtr<PixelBuffer> PixelBuffer::tryCreate(const PixelBufferFormat& format, const IntSize& size, Ref<JSC::ArrayBuffer>&& arrayBuffer)
-{
- ASSERT(supportedPixelFormat(format.pixelFormat));
-
- auto bufferSize = computeBufferSize(format, size);
- if (bufferSize.hasOverflowed())
- return nullptr;
- if (bufferSize != arrayBuffer->byteLength())
- return nullptr;
- auto pixelArray = Uint8ClampedArray::tryCreate(WTFMove(arrayBuffer), 0, bufferSize);
- if (!pixelArray)
- return nullptr;
- return adoptRef(new PixelBuffer(format, size, pixelArray.releaseNonNull()));
-}
-
-Ref<PixelBuffer> PixelBuffer::create(const PixelBufferFormat& format, const IntSize& size, JSC::Uint8ClampedArray& data)
-{
- return adoptRef(*new PixelBuffer(format, size, { data }));
-}
-
-PixelBuffer::PixelBuffer(const PixelBufferFormat& format, const IntSize& size, Ref<JSC::Uint8ClampedArray>&& data)
- : m_format { format }
- , m_size { size }
- , m_data { WTFMove(data) }
-{
- RELEASE_ASSERT_WITH_SECURITY_IMPLICATION((m_size.area() * 4) <= m_data->length());
-}
-
-PixelBuffer::PixelBuffer(const PixelBufferFormat& format, const IntSize& size, JSC::Uint8ClampedArray& data)
- : m_format { format }
- , m_size { size }
- , m_data { data }
-{
- RELEASE_ASSERT_WITH_SECURITY_IMPLICATION((m_size.area() * 4) <= m_data->length());
-}
-
PixelBuffer::~PixelBuffer() = default;
-uint8_t* PixelBuffer::bytes() const
-{
- return m_data->data();
-}
-
-size_t PixelBuffer::sizeInBytes() const
-{
- ASSERT(m_data->byteLength() == m_size.area() * 4);
- return m_data->byteLength();
-}
-
bool PixelBuffer::setRange(const uint8_t* data, size_t dataByteLength, size_t byteOffset)
{
- if (!isSumSmallerThanOrEqual(byteOffset, dataByteLength, sizeInBytes()))
+ if (!isSumSmallerThanOrEqual(byteOffset, dataByteLength, m_sizeInBytes))
return false;
- memmove(bytes() + byteOffset, data, dataByteLength);
+ memmove(m_bytes + byteOffset, data, dataByteLength);
return true;
}
bool PixelBuffer::zeroRange(size_t byteOffset, size_t rangeByteLength)
{
- if (!isSumSmallerThanOrEqual(byteOffset, rangeByteLength, sizeInBytes()))
+ if (!isSumSmallerThanOrEqual(byteOffset, rangeByteLength, m_sizeInBytes))
return false;
- memset(bytes() + byteOffset, 0, rangeByteLength);
+ memset(m_bytes + byteOffset, 0, rangeByteLength);
return true;
}
uint8_t PixelBuffer::item(size_t index) const
{
- RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(index < sizeInBytes());
- return bytes()[index];
+ RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(index < m_sizeInBytes);
+ return m_bytes[index];
}
void PixelBuffer::set(size_t index, double value)
{
- RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(index < sizeInBytes());
- bytes()[index] = JSC::Uint8ClampedAdaptor::toNativeFromDouble(value);
+ RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(index < m_sizeInBytes);
+ m_bytes[index] = JSC::Uint8ClampedAdaptor::toNativeFromDouble(value);
}
-RefPtr<PixelBuffer> PixelBuffer::createScratchPixelBuffer(const IntSize& size) const
-{
- return PixelBuffer::tryCreate(m_format, size);
-}
-
-TextStream& operator<<(TextStream& ts, const PixelBuffer& pixelBuffer)
-{
- return ts << &pixelBuffer.data() << "format ( " << pixelBuffer.format() << ")";
-}
-
} // namespace WebCore
Modified: trunk/Source/WebCore/platform/graphics/PixelBuffer.h (295226 => 295227)
--- trunk/Source/WebCore/platform/graphics/PixelBuffer.h 2022-06-03 20:39:35 UTC (rev 295226)
+++ trunk/Source/WebCore/platform/graphics/PixelBuffer.h 2022-06-03 20:52:52 UTC (rev 295227)
@@ -27,7 +27,6 @@
#include "IntSize.h"
#include "PixelBufferFormat.h"
-#include <_javascript_Core/Uint8ClampedArray.h>
#include <wtf/RefCounted.h>
namespace WTF {
@@ -41,89 +40,34 @@
public:
WEBCORE_EXPORT static bool supportedPixelFormat(PixelFormat);
- WEBCORE_EXPORT static RefPtr<PixelBuffer> tryCreate(const PixelBufferFormat&, const IntSize&);
- WEBCORE_EXPORT static RefPtr<PixelBuffer> tryCreate(const PixelBufferFormat&, const IntSize&, Ref<JSC::ArrayBuffer>&&);
- WEBCORE_EXPORT static Ref<PixelBuffer> create(const PixelBufferFormat&, const IntSize&, JSC::Uint8ClampedArray&);
+ WEBCORE_EXPORT virtual ~PixelBuffer();
- WEBCORE_EXPORT ~PixelBuffer();
-
const PixelBufferFormat& format() const { return m_format; }
const IntSize& size() const { return m_size; }
- JSC::Uint8ClampedArray& data() const { return m_data.get(); }
- Ref<JSC::Uint8ClampedArray>&& takeData() { return WTFMove(m_data); }
+ uint8_t* bytes() const { return m_bytes; }
+ size_t sizeInBytes() const { return m_sizeInBytes; }
- uint8_t* bytes() const;
- size_t sizeInBytes() const;
+ virtual bool isByteArrayPixelBuffer() const { return false; }
+ virtual RefPtr<PixelBuffer> createScratchPixelBuffer(const IntSize&) const = 0;
bool setRange(const uint8_t* data, size_t dataByteLength, size_t byteOffset);
bool zeroRange(size_t byteOffset, size_t rangeByteLength);
void zeroFill() { zeroRange(0, sizeInBytes()); }
- uint8_t item(size_t index) const;
+ WEBCORE_EXPORT uint8_t item(size_t index) const;
void set(size_t index, double value);
- RefPtr<PixelBuffer> createScratchPixelBuffer(const IntSize&) const;
-
- template<class Encoder> void encode(Encoder&) const;
- template<class Decoder> static std::optional<Ref<PixelBuffer>> decode(Decoder&);
-
-private:
- WEBCORE_EXPORT static RefPtr<PixelBuffer> tryCreateForDecoding(const PixelBufferFormat&, const IntSize&, unsigned dataByteLength);
-
+protected:
+ WEBCORE_EXPORT PixelBuffer(const PixelBufferFormat&, const IntSize&, uint8_t* bytes, size_t sizeInBytes);
+
WEBCORE_EXPORT static CheckedUint32 computeBufferSize(const PixelBufferFormat&, const IntSize&);
- PixelBuffer(const PixelBufferFormat&, const IntSize&, Ref<JSC::Uint8ClampedArray>&&);
- PixelBuffer(const PixelBufferFormat&, const IntSize&, JSC::Uint8ClampedArray&);
-
PixelBufferFormat m_format;
IntSize m_size;
- Ref<JSC::Uint8ClampedArray> m_data;
+
+ uint8_t* m_bytes { nullptr };
+ size_t m_sizeInBytes { 0 };
};
-WEBCORE_EXPORT WTF::TextStream& operator<<(WTF::TextStream&, const PixelBuffer&);
-
-template<class Encoder> void PixelBuffer::encode(Encoder& encoder) const
-{
- ASSERT(m_data->byteLength() == (m_size.area() * 4));
-
- encoder << m_format;
- encoder << m_size;
- encoder.encodeFixedLengthData(m_data->data(), m_data->byteLength(), 1);
-}
-
-template<class Decoder> std::optional<Ref<PixelBuffer>> PixelBuffer::decode(Decoder& decoder)
-{
- std::optional<PixelBufferFormat> format;
- decoder >> format;
- if (!format)
- return std::nullopt;
-
- // FIXME: Support non-8 bit formats.
- if (!(format->pixelFormat == PixelFormat::RGBA8 || format->pixelFormat == PixelFormat::BGRA8))
- return std::nullopt;
-
- std::optional<IntSize> size;
- decoder >> size;
- if (!size)
- return std::nullopt;
-
- auto computedBufferSize = PixelBuffer::computeBufferSize(*format, *size);
- if (computedBufferSize.hasOverflowed())
- return std::nullopt;
-
- auto bufferSize = computedBufferSize;
- if (!decoder.template bufferIsLargeEnoughToContain<uint8_t>(bufferSize))
- return std::nullopt;
-
- auto result = PixelBuffer::tryCreateForDecoding(WTFMove(*format), *size, bufferSize);
- if (!result)
- return std::nullopt;
-
- if (!decoder.decodeFixedLengthData(result->m_data->data(), result->m_data->byteLength(), 1))
- return std::nullopt;
-
- return result.releaseNonNull();
-}
-
} // namespace WebCore
Modified: trunk/Source/WebCore/platform/graphics/ShadowBlur.cpp (295226 => 295227)
--- trunk/Source/WebCore/platform/graphics/ShadowBlur.cpp 2022-06-03 20:39:35 UTC (rev 295226)
+++ trunk/Source/WebCore/platform/graphics/ShadowBlur.cpp 2022-06-03 20:52:52 UTC (rev 295227)
@@ -899,7 +899,7 @@
if (!layerData)
return;
- blurLayerImage(layerData->data().data(), blurRect.size(), blurRect.width() * 4);
+ blurLayerImage(layerData->bytes(), blurRect.size(), blurRect.width() * 4);
layerImage.putPixelBuffer(*layerData, blurRect);
}
Modified: trunk/Source/WebCore/platform/graphics/angle/GraphicsContextGLANGLE.cpp (295226 => 295227)
--- trunk/Source/WebCore/platform/graphics/angle/GraphicsContextGLANGLE.cpp 2022-06-03 20:39:35 UTC (rev 295226)
+++ trunk/Source/WebCore/platform/graphics/angle/GraphicsContextGLANGLE.cpp 2022-06-03 20:52:52 UTC (rev 295227)
@@ -31,12 +31,12 @@
#include "ANGLEHeaders.h"
#include "ANGLEUtilities.h"
+#include "ByteArrayPixelBuffer.h"
#include "ImageBuffer.h"
#include "IntRect.h"
#include "IntSize.h"
#include "Logging.h"
#include "NotImplemented.h"
-#include "PixelBuffer.h"
#include "RuntimeApplicationChecks.h"
#include <algorithm>
#include <cstring>
@@ -192,7 +192,7 @@
RefPtr<PixelBuffer> GraphicsContextGLANGLE::readPixelsForPaintResults()
{
PixelBufferFormat format { AlphaPremultiplication::Unpremultiplied, PixelFormat::RGBA8, DestinationColorSpace::SRGB() };
- auto pixelBuffer = PixelBuffer::tryCreate(format, getInternalFramebufferSize());
+ auto pixelBuffer = ByteArrayPixelBuffer::tryCreate(format, getInternalFramebufferSize());
if (!pixelBuffer)
return nullptr;
ScopedPixelStorageMode packAlignment(GL_PACK_ALIGNMENT);
@@ -203,7 +203,7 @@
ScopedPixelStorageMode packSkipPixels(GL_PACK_SKIP_PIXELS, 0, m_isForWebGL2);
ScopedBufferBinding scopedPixelPackBufferReset(GL_PIXEL_PACK_BUFFER, 0, m_isForWebGL2);
- GL_ReadnPixelsRobustANGLE(0, 0, pixelBuffer->size().width(), pixelBuffer->size().height(), GL_RGBA, GL_UNSIGNED_BYTE, pixelBuffer->data().byteLength(), nullptr, nullptr, nullptr, pixelBuffer->data().data());
+ GL_ReadnPixelsRobustANGLE(0, 0, pixelBuffer->size().width(), pixelBuffer->size().height(), GL_RGBA, GL_UNSIGNED_BYTE, pixelBuffer->sizeInBytes(), nullptr, nullptr, nullptr, pixelBuffer->bytes());
// FIXME: Rendering to GL_RGB textures with a IOSurface bound to the texture image leaves
// the alpha in the IOSurface in incorrect state. Also ANGLE GL_ReadPixels will in some
// cases expose the non-255 values.
@@ -210,7 +210,7 @@
// https://bugs.webkit.org/show_bug.cgi?id=215804
#if PLATFORM(MAC) || PLATFORM(IOS_FAMILY)
if (!contextAttributes().alpha)
- wipeAlphaChannelFromPixels(pixelBuffer->size().width(), pixelBuffer->size().height(), pixelBuffer->data().data());
+ wipeAlphaChannelFromPixels(pixelBuffer->size().width(), pixelBuffer->size().height(), pixelBuffer->bytes());
#endif
return pixelBuffer;
}
@@ -3001,7 +3001,7 @@
// FIXME: Make PixelBufferConversions support negative rowBytes and in-place conversions.
const auto size = results->size();
const size_t rowStride = size.width() * 4;
- uint8_t* top = results->data().data();
+ uint8_t* top = results->bytes();
uint8_t* bottom = top + (size.height() - 1) * rowStride;
std::unique_ptr<uint8_t[]> temp(new uint8_t[rowStride]);
for (; top < bottom; top += rowStride, bottom -= rowStride) {
Modified: trunk/Source/WebCore/platform/graphics/cg/GraphicsContextGLCG.cpp (295226 => 295227)
--- trunk/Source/WebCore/platform/graphics/cg/GraphicsContextGLCG.cpp 2022-06-03 20:39:35 UTC (rev 295226)
+++ trunk/Source/WebCore/platform/graphics/cg/GraphicsContextGLCG.cpp 2022-06-03 20:52:52 UTC (rev 295227)
@@ -521,14 +521,14 @@
else
bitmapInfo |= kCGImageAlphaLast;
- Ref pixelArray = pixelBuffer->data();
- auto dataSize = pixelArray->byteLength();
- auto data = ""
+ Ref protectedPixelBuffer = pixelBuffer;
+ auto dataSize = pixelBuffer->sizeInBytes();
+ auto data = ""
verifyImageBufferIsBigEnough(data, dataSize);
- auto dataProvider = adoptCF(CGDataProviderCreateWithData(&pixelArray.leakRef(), data, dataSize, [] (void* context, const void*, size_t) {
- static_cast<JSC::Uint8ClampedArray*>(context)->deref();
+ auto dataProvider = adoptCF(CGDataProviderCreateWithData(&protectedPixelBuffer.leakRef(), data, dataSize, [] (void* context, const void*, size_t) {
+ static_cast<PixelBuffer*>(context)->deref();
}));
auto imageSize = pixelBuffer->size();
Modified: trunk/Source/WebCore/platform/graphics/cg/ImageBufferCGBackend.cpp (295226 => 295227)
--- trunk/Source/WebCore/platform/graphics/cg/ImageBufferCGBackend.cpp 2022-06-03 20:39:35 UTC (rev 295226)
+++ trunk/Source/WebCore/platform/graphics/cg/ImageBufferCGBackend.cpp 2022-06-03 20:52:52 UTC (rev 295227)
@@ -159,14 +159,14 @@
if (!pixelBuffer)
return nullptr;
- Ref pixelArray = pixelBuffer->data();
- auto dataSize = pixelArray->byteLength();
- auto data = ""
+ Ref protectedPixelBuffer = *pixelBuffer;
+ auto dataSize = pixelBuffer->sizeInBytes();
+ auto data = ""
verifyImageBufferIsBigEnough(data, dataSize);
- auto dataProvider = adoptCF(CGDataProviderCreateWithData(&pixelArray.leakRef(), data, dataSize, [] (void* context, const void*, size_t) {
- static_cast<JSC::Uint8ClampedArray*>(context)->deref();
+ auto dataProvider = adoptCF(CGDataProviderCreateWithData(&protectedPixelBuffer.leakRef(), data, dataSize, [] (void* context, const void*, size_t) {
+ static_cast<PixelBuffer*>(context)->deref();
}));
if (!dataProvider)
return nullptr;
Modified: trunk/Source/WebCore/platform/graphics/cg/ImageBufferUtilitiesCG.cpp (295226 => 295227)
--- trunk/Source/WebCore/platform/graphics/cg/ImageBufferUtilitiesCG.cpp 2022-06-03 20:39:35 UTC (rev 295226)
+++ trunk/Source/WebCore/platform/graphics/cg/ImageBufferUtilitiesCG.cpp 2022-06-03 20:52:52 UTC (rev 295227)
@@ -139,8 +139,8 @@
CGImageAlphaInfo dataAlphaInfo = kCGImageAlphaLast;
- auto data = ""
- auto dataSize = source.data().byteLength();
+ auto data = ""
+ auto dataSize = source.sizeInBytes();
Vector<uint8_t> premultipliedData;
Modified: trunk/Source/WebCore/platform/graphics/cv/VideoFrameCV.mm (295226 => 295227)
--- trunk/Source/WebCore/platform/graphics/cv/VideoFrameCV.mm 2022-06-03 20:39:35 UTC (rev 295226)
+++ trunk/Source/WebCore/platform/graphics/cv/VideoFrameCV.mm 2022-06-03 20:52:52 UTC (rev 295227)
@@ -56,20 +56,19 @@
auto width = size.width();
auto height = size.height();
- auto data = ""
- auto dataBaseAddress = data->data();
- auto leakedData = &data.leakRef();
+ auto dataBaseAddress = pixelBuffer->bytes();
+ auto leakedBuffer = &pixelBuffer.leakRef();
auto derefBuffer = [] (void* context, const void*) {
- static_cast<JSC::Uint8ClampedArray*>(context)->deref();
+ static_cast<PixelBuffer*>(context)->deref();
};
CVPixelBufferRef cvPixelBufferRaw = nullptr;
- auto status = CVPixelBufferCreateWithBytes(kCFAllocatorDefault, width, height, kCVPixelFormatType_32BGRA, dataBaseAddress, width * 4, derefBuffer, leakedData, nullptr, &cvPixelBufferRaw);
+ auto status = CVPixelBufferCreateWithBytes(kCFAllocatorDefault, width, height, kCVPixelFormatType_32BGRA, dataBaseAddress, width * 4, derefBuffer, leakedBuffer, nullptr, &cvPixelBufferRaw);
auto cvPixelBuffer = adoptCF(cvPixelBufferRaw);
if (!cvPixelBuffer) {
- derefBuffer(leakedData, nullptr);
+ derefBuffer(leakedBuffer, nullptr);
return nullptr;
}
ASSERT_UNUSED(status, !status);
Modified: trunk/Source/WebCore/platform/graphics/filters/FilterImage.cpp (295226 => 295227)
--- trunk/Source/WebCore/platform/graphics/filters/FilterImage.cpp 2022-06-03 20:39:35 UTC (rev 295226)
+++ trunk/Source/WebCore/platform/graphics/filters/FilterImage.cpp 2022-06-03 20:52:52 UTC (rev 295227)
@@ -122,8 +122,8 @@
auto destinationSize = destinationPixelBuffer.size();
unsigned rowBytes = destinationSize.width() * 4;
- ConstPixelBufferConversionView source { sourcePixelBuffer.format(), rowBytes, sourcePixelBuffer.data().data() };
- PixelBufferConversionView destination { destinationPixelBuffer.format(), rowBytes, destinationPixelBuffer.data().data() };
+ ConstPixelBufferConversionView source { sourcePixelBuffer.format(), rowBytes, sourcePixelBuffer.bytes() };
+ PixelBufferConversionView destination { destinationPixelBuffer.format(), rowBytes, destinationPixelBuffer.bytes() };
convertImagePixels(source, destination, destinationSize);
}
@@ -130,9 +130,6 @@
static void copyImageBytes(const PixelBuffer& sourcePixelBuffer, PixelBuffer& destinationPixelBuffer, const IntRect& sourceRect)
{
- auto& source = sourcePixelBuffer.data();
- auto& destination = destinationPixelBuffer.data();
-
auto sourcePixelBufferRect = IntRect { { }, sourcePixelBuffer.size() };
auto destinationPixelBufferRect = IntRect { { }, destinationPixelBuffer.size() };
@@ -150,7 +147,7 @@
// Initialize the destination to transparent black, if not entirely covered by the source.
if (destinationRect.size() != destinationPixelBufferRect.size())
- destination.zeroFill();
+ destinationPixelBuffer.zeroFill();
// Early return if the rect does not intersect with the source.
if (destinationRect.isEmpty())
@@ -159,8 +156,8 @@
int size = sourceRectClipped.width() * 4;
int destinationBytesPerRow = destinationPixelBufferRect.width() * 4;
int sourceBytesPerRow = sourcePixelBufferRect.width() * 4;
- uint8_t* destinationPixel = destination.data() + destinationRect.y() * destinationBytesPerRow + destinationRect.x() * 4;
- const uint8_t* sourcePixel = source.data() + sourceRectClipped.y() * sourceBytesPerRow + sourceRectClipped.x() * 4;
+ uint8_t* destinationPixel = destinationPixelBuffer.bytes() + destinationRect.y() * destinationBytesPerRow + destinationRect.x() * 4;
+ const uint8_t* sourcePixel = sourcePixelBuffer.bytes() + sourceRectClipped.y() * sourceBytesPerRow + sourceRectClipped.x() * 4;
for (int y = 0; y < sourceRectClipped.height(); ++y) {
memcpy(destinationPixel, sourcePixel, size);
Modified: trunk/Source/WebCore/platform/graphics/gstreamer/VideoFrameGStreamer.cpp (295226 => 295227)
--- trunk/Source/WebCore/platform/graphics/gstreamer/VideoFrameGStreamer.cpp 2022-06-03 20:39:35 UTC (rev 295226)
+++ trunk/Source/WebCore/platform/graphics/gstreamer/VideoFrameGStreamer.cpp 2022-06-03 20:52:52 UTC (rev 295227)
@@ -36,13 +36,12 @@
auto size = pixelBuffer->size();
- auto data = ""
- auto sizeInBytes = data->byteLength();
- auto dataBaseAddress = data->data();
- auto leakedData = &data.leakRef();
+ auto sizeInBytes = pixelBuffer->sizeInBytes();
+ auto dataBaseAddress = pixelBuffer->bytes();
+ auto leakedPixelBuffer = &pixelBuffer.leakRef();
- auto buffer = adoptGRef(gst_buffer_new_wrapped_full(GST_MEMORY_FLAG_READONLY, dataBaseAddress, sizeInBytes, 0, sizeInBytes, leakedData, [](gpointer userData) {
- static_cast<JSC::Uint8ClampedArray*>(userData)->deref();
+ auto buffer = adoptGRef(gst_buffer_new_wrapped_full(GST_MEMORY_FLAG_READONLY, dataBaseAddress, sizeInBytes, 0, sizeInBytes, leakedPixelBuffer, [](gpointer userData) {
+ static_cast<PixelBuffer*>(userData)->deref();
}));
auto width = size.width();
Modified: trunk/Source/WebCore/platform/graphics/opengl/GraphicsContextGLOpenGL.cpp (295226 => 295227)
--- trunk/Source/WebCore/platform/graphics/opengl/GraphicsContextGLOpenGL.cpp 2022-06-03 20:39:35 UTC (rev 295226)
+++ trunk/Source/WebCore/platform/graphics/opengl/GraphicsContextGLOpenGL.cpp 2022-06-03 20:52:52 UTC (rev 295227)
@@ -3140,7 +3140,7 @@
// FIXME: Make PixelBufferConversions support negative rowBytes and in-place conversions.
const auto size = results->size();
const size_t rowStride = size.width() * 4;
- uint8_t* top = results->data().data();
+ uint8_t* top = results->bytes();
uint8_t* bottom = top + (size.height() - 1) * rowStride;
std::unique_ptr<uint8_t[]> temp(new uint8_t[rowStride]);
for (; top < bottom; top += rowStride, bottom -= rowStride) {
Modified: trunk/Source/WebCore/platform/graphics/opengl/GraphicsContextGLOpenGLBase.cpp (295226 => 295227)
--- trunk/Source/WebCore/platform/graphics/opengl/GraphicsContextGLOpenGLBase.cpp 2022-06-03 20:39:35 UTC (rev 295226)
+++ trunk/Source/WebCore/platform/graphics/opengl/GraphicsContextGLOpenGLBase.cpp 2022-06-03 20:52:52 UTC (rev 295227)
@@ -29,12 +29,12 @@
#if ENABLE(WEBGL) && USE(OPENGL)
+#include "ByteArrayPixelBuffer.h"
#include "ExtensionsGLOpenGL.h"
#include "IntRect.h"
#include "IntSize.h"
#include "Logging.h"
#include "NotImplemented.h"
-#include "PixelBuffer.h"
#include "TemporaryOpenGLSetting.h"
#include <algorithm>
#include <cstring>
@@ -64,7 +64,7 @@
RefPtr<PixelBuffer> GraphicsContextGLOpenGL::readPixelsForPaintResults()
{
PixelBufferFormat format { AlphaPremultiplication::Unpremultiplied, PixelFormat::RGBA8, DestinationColorSpace::SRGB() };
- auto pixelBuffer = PixelBuffer::tryCreate(format, getInternalFramebufferSize());
+ auto pixelBuffer = ByteArrayPixelBuffer::tryCreate(format, getInternalFramebufferSize());
if (!pixelBuffer)
return nullptr;
@@ -76,7 +76,7 @@
mustRestorePackAlignment = true;
}
- ::glReadPixels(0, 0, pixelBuffer->size().width(), pixelBuffer->size().height(), GL_RGBA, GL_UNSIGNED_BYTE, pixelBuffer->data().data());
+ ::glReadPixels(0, 0, pixelBuffer->size().width(), pixelBuffer->size().height(), GL_RGBA, GL_UNSIGNED_BYTE, pixelBuffer->bytes());
if (mustRestorePackAlignment)
::glPixelStorei(GL_PACK_ALIGNMENT, packAlignment);
Modified: trunk/Source/WebCore/platform/graphics/opengl/GraphicsContextGLOpenGLES.cpp (295226 => 295227)
--- trunk/Source/WebCore/platform/graphics/opengl/GraphicsContextGLOpenGLES.cpp 2022-06-03 20:39:35 UTC (rev 295226)
+++ trunk/Source/WebCore/platform/graphics/opengl/GraphicsContextGLOpenGLES.cpp 2022-06-03 20:52:52 UTC (rev 295227)
@@ -31,11 +31,11 @@
#if ENABLE(WEBGL) && USE(OPENGL_ES)
+#include "ByteArrayPixelBuffer.h"
#include "ExtensionsGLOpenGLES.h"
#include "IntRect.h"
#include "IntSize.h"
#include "NotImplemented.h"
-#include "PixelBuffer.h"
#include <ANGLE/ShaderLang.h>
@@ -67,7 +67,7 @@
RefPtr<PixelBuffer> GraphicsContextGLOpenGL::readPixelsForPaintResults()
{
PixelBufferFormat format { AlphaPremultiplication::Unpremultiplied, PixelFormat::RGBA8, DestinationColorSpace::SRGB() };
- auto pixelBuffer = PixelBuffer::tryCreate(format, getInternalFramebufferSize());
+ auto pixelBuffer = ByteArrayPixelBuffer::tryCreate(format, getInternalFramebufferSize());
if (!pixelBuffer)
return nullptr;
@@ -79,7 +79,7 @@
mustRestorePackAlignment = true;
}
- ::glReadPixels(0, 0, pixelBuffer->size().width(), pixelBuffer->size().height(), GL_RGBA, GL_UNSIGNED_BYTE, pixelBuffer->data().data());
+ ::glReadPixels(0, 0, pixelBuffer->size().width(), pixelBuffer->size().height(), GL_RGBA, GL_UNSIGNED_BYTE, pixelBuffer->bytes());
if (mustRestorePackAlignment)
::glPixelStorei(GL_PACK_ALIGNMENT, packAlignment);
Modified: trunk/Source/WebCore/rendering/shapes/Shape.cpp (295226 => 295227)
--- trunk/Source/WebCore/rendering/shapes/Shape.cpp 2022-06-03 20:39:35 UTC (rev 295226)
+++ trunk/Source/WebCore/rendering/shapes/Shape.cpp 2022-06-03 20:52:52 UTC (rev 295227)
@@ -200,13 +200,12 @@
PixelBufferFormat format { AlphaPremultiplication::Unpremultiplied, PixelFormat::RGBA8, DestinationColorSpace::SRGB() };
auto pixelBuffer = imageBuffer->getPixelBuffer(format, { IntPoint(), imageRect.size() });
- // We could get to a value where PixelBuffer could be nullopt. A case where ImageRect.size() is huge, PixelBuffer::tryCreate
- // can return a nullopt because data size has overflowed. Refer rdar://problem/61793884
+ // We could get to a value where PixelBuffer could be nullptr because ImageRect.size()
+ // is huge and the data size overflows. Refer rdar://problem/61793884.
if (!pixelBuffer)
return createShape();
- auto& pixelArray = pixelBuffer->data();
- unsigned pixelArrayLength = pixelArray.length();
+ unsigned pixelArrayLength = pixelBuffer->sizeInBytes();
unsigned pixelArrayOffset = 3; // Each pixel is four bytes: RGBA.
uint8_t alphaPixelThreshold = static_cast<uint8_t>(lroundf(clampTo<float>(threshold, 0, 1) * 255.0f));
@@ -217,7 +216,7 @@
for (int y = minBufferY; y < maxBufferY; ++y) {
int startX = -1;
for (int x = 0; x < imageRect.width(); ++x, pixelArrayOffset += 4) {
- uint8_t alpha = pixelArray.item(pixelArrayOffset);
+ uint8_t alpha = pixelBuffer->item(pixelArrayOffset);
bool alphaAboveThreshold = alpha > alphaPixelThreshold;
if (startX == -1 && alphaAboveThreshold) {
startX = x;
Modified: trunk/Source/WebKit/GPUProcess/graphics/RemoteGraphicsContextGL.cpp (295226 => 295227)
--- trunk/Source/WebKit/GPUProcess/graphics/RemoteGraphicsContextGL.cpp 2022-06-03 20:39:35 UTC (rev 295226)
+++ trunk/Source/WebKit/GPUProcess/graphics/RemoteGraphicsContextGL.cpp 2022-06-03 20:52:52 UTC (rev 295227)
@@ -251,8 +251,8 @@
// FIXME: This should not be needed. Maybe ArrayBufferView should be ThreadSafeRefCounted as it is used in accross multiple threads.
// The call below is synchronous and we transfer the ownership of the `pixelBuffer`.
- if (pixelBuffer)
- pixelBuffer->data().disableThreadingChecks();
+ if (is<ByteArrayPixelBuffer>(pixelBuffer))
+ downcast<ByteArrayPixelBuffer>(*pixelBuffer).data().disableThreadingChecks();
m_renderingBackend->dispatch([&, contextAttributes = m_context->contextAttributes()]() mutable {
if (auto imageBuffer = m_renderingBackend->remoteResourceCache().cachedImageBuffer(target)) {
// Here we do not try to play back pending commands for imageBuffer. Currently this call is only made for empty
Modified: trunk/Source/WebKit/GPUProcess/graphics/RemoteRenderingBackend.cpp (295226 => 295227)
--- trunk/Source/WebKit/GPUProcess/graphics/RemoteRenderingBackend.cpp 2022-06-03 20:39:35 UTC (rev 295226)
+++ trunk/Source/WebKit/GPUProcess/graphics/RemoteRenderingBackend.cpp 2022-06-03 20:52:52 UTC (rev 295227)
@@ -212,8 +212,8 @@
if (auto imageBuffer = m_remoteResourceCache.cachedImageBuffer(qualifiedImageBuffer)) {
auto pixelBuffer = imageBuffer->getPixelBuffer(destinationFormat, srcRect);
if (pixelBuffer) {
- MESSAGE_CHECK(pixelBuffer->data().byteLength() <= m_getPixelBufferSharedMemory->size(), "Shmem for return of getPixelBuffer is too small");
- memcpy(m_getPixelBufferSharedMemory->data(), pixelBuffer->data().data(), pixelBuffer->data().byteLength());
+ MESSAGE_CHECK(pixelBuffer->sizeInBytes() <= m_getPixelBufferSharedMemory->size(), "Shmem for return of getPixelBuffer is too small");
+ memcpy(m_getPixelBufferSharedMemory->data(), pixelBuffer->bytes(), pixelBuffer->sizeInBytes());
} else
memset(m_getPixelBufferSharedMemory->data(), 0, m_getPixelBufferSharedMemory->size());
}
Modified: trunk/Source/WebKit/Platform/IPC/PixelBufferReference.h (295226 => 295227)
--- trunk/Source/WebKit/Platform/IPC/PixelBufferReference.h 2022-06-03 20:39:35 UTC (rev 295226)
+++ trunk/Source/WebKit/Platform/IPC/PixelBufferReference.h 2022-06-03 20:52:52 UTC (rev 295227)
@@ -25,7 +25,7 @@
#pragma once
-#include <WebCore/PixelBuffer.h>
+#include <WebCore/ByteArrayPixelBuffer.h>
namespace IPC {
@@ -48,13 +48,19 @@
template<class Encoder>
void PixelBufferReference::encode(Encoder& encoder) const
{
- m_pixelBuffer->encode(encoder);
+ if (!is<WebCore::ByteArrayPixelBuffer>(m_pixelBuffer)) {
+ ASSERT_NOT_REACHED();
+ return;
+ }
+ downcast<WebCore::ByteArrayPixelBuffer>(m_pixelBuffer.get()).encode(encoder);
}
template<class Decoder>
std::optional<PixelBufferReference> PixelBufferReference::decode(Decoder& decoder)
{
- return WebCore::PixelBuffer::decode(decoder);
+ if (auto pixelBuffer = WebCore::ByteArrayPixelBuffer::decode(decoder))
+ return { { WTFMove(*pixelBuffer) } };
+ return std::nullopt;
}
} // namespace IPC
Modified: trunk/Source/WebKit/WebProcess/GPU/graphics/RemoteImageBufferProxy.h (295226 => 295227)
--- trunk/Source/WebKit/WebProcess/GPU/graphics/RemoteImageBufferProxy.h 2022-06-03 20:39:35 UTC (rev 295226)
+++ trunk/Source/WebKit/WebProcess/GPU/graphics/RemoteImageBufferProxy.h 2022-06-03 20:52:52 UTC (rev 295227)
@@ -243,8 +243,7 @@
auto pixelBuffer = allocator.createPixelBuffer(destinationFormat, srcRect.size());
if (!pixelBuffer)
return nullptr;
- auto& data = ""
- if (!m_remoteRenderingBackendProxy->getPixelBufferForImageBuffer(m_renderingResourceIdentifier, destinationFormat, srcRect, { data.data(), data.byteLength() }))
+ if (!m_remoteRenderingBackendProxy->getPixelBufferForImageBuffer(m_renderingResourceIdentifier, destinationFormat, srcRect, { pixelBuffer->bytes(), pixelBuffer->sizeInBytes() }))
return nullptr;
return pixelBuffer;
}
Modified: trunk/Tools/TestWebKitAPI/Tests/WebCore/ImageBufferTests.cpp (295226 => 295227)
--- trunk/Tools/TestWebKitAPI/Tests/WebCore/ImageBufferTests.cpp 2022-06-03 20:39:35 UTC (rev 295226)
+++ trunk/Tools/TestWebKitAPI/Tests/WebCore/ImageBufferTests.cpp 2022-06-03 20:52:52 UTC (rev 295227)
@@ -40,8 +40,7 @@
{
PixelBufferFormat format { AlphaPremultiplication::Unpremultiplied, PixelFormat::RGBA8, DestinationColorSpace::SRGB() };
auto frontPixelBuffer = imageBuffer.getPixelBuffer(format, { x, y, 1, 1 });
- auto& data = ""
- auto got = Color { SRGBA<uint8_t> { data.item(0), data.item(1), data.item(2), data.item(3) } };
+ auto got = Color { SRGBA<uint8_t> { frontPixelBuffer->item(0), frontPixelBuffer->item(1), frontPixelBuffer->item(2), frontPixelBuffer->item(3) } };
if (got != expected)
return ::testing::AssertionFailure() << "color is not expected. Got: " << got << ", expected: " << expected << ".";
return ::testing::AssertionSuccess();