Title: [277237] trunk/Source
Revision
277237
Author
wei...@apple.com
Date
2021-05-08 18:29:38 -0700 (Sat, 08 May 2021)

Log Message

Factor out pixel buffer from DOM specific ImageData class
https://bugs.webkit.org/show_bug.cgi?id=225554

Reviewed by Darin Adler.

Source/WebCore:

Prepare to fix layering violating use of DOM level ImageData being
used by platform code by factoring out the pixel storage into a new
PixelBuffer class. Since it will be a little more general that
ImageData is now (though ImageData will need to gain these soon)
PixelBuffer also captures the pixel format and color space the pixel
data represents.

While here, update ImageData::data() to return a reference rather than
a pointer to indicate it is never null and update all the callers.

* Headers.cmake:
* Sources.txt:
* WebCore.xcodeproj/project.pbxproj:
* bindings/js/JSImageDataCustom.cpp:
(WebCore::toJSNewlyCreated):
* bindings/js/SerializedScriptValue.cpp:
(WebCore::CloneSerializer::dumpImageBitmap):
(WebCore::CloneSerializer::dumpIfTerminal):
(WebCore::CloneDeserializer::readTerminal):
* html/ImageBitmap.cpp:
(WebCore::ImageBitmap::createPromise):
* html/ImageData.cpp:
(WebCore::ImageData::create):
(WebCore::ImageData::ImageData):
(WebCore::ImageData::deepClone const):
(WebCore::operator<<):
* html/ImageData.h:
(WebCore::ImageData::size const):
(WebCore::ImageData::width const):
(WebCore::ImageData::height const):
(WebCore::ImageData::data const):
(WebCore::ImageData::colorSpace const):
(WebCore::ImageData::format const):
* html/canvas/CanvasRenderingContext2DBase.cpp:
(WebCore::createEmptyImageData):
(WebCore::CanvasRenderingContext2DBase::putImageData):
* html/canvas/WebGLRenderingContextBase.cpp:
(WebCore::WebGLRenderingContextBase::texImageSourceHelper):
* inspector/InspectorCanvas.cpp:
(WebCore::InspectorCanvas::buildArrayForImageData):
* platform/graphics/GraphicsContextGL.cpp:
(WebCore::GraphicsContextGL::extractImageData):
* platform/graphics/ImageBufferBackend.cpp:
(WebCore::ImageBufferBackend::convertToLuminanceMask):
(WebCore::ImageBufferBackend::getImageData const):
(WebCore::ImageBufferBackend::putImageData):
* platform/graphics/PixelBuffer.cpp: Added.
(WebCore::PixelBuffer::PixelBuffer):
(WebCore::PixelBuffer::deepClone const):
* platform/graphics/PixelBuffer.h: Added.
(WebCore::PixelBuffer::colorSpace const):
(WebCore::PixelBuffer::format const):
(WebCore::PixelBuffer::size const):
(WebCore::PixelBuffer::data const):
* platform/graphics/ShadowBlur.cpp:
(WebCore::ShadowBlur::blurShadowBuffer):
* 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/FEColorMatrix.cpp:
(WebCore::FEColorMatrix::platformApplySoftware):
* platform/graphics/filters/FEComponentTransfer.cpp:
(WebCore::FEComponentTransfer::platformApplySoftware):
* platform/graphics/filters/FEComposite.cpp:
(WebCore::FEComposite::platformApplySoftware):
* platform/graphics/filters/FEConvolveMatrix.cpp:
(WebCore::FEConvolveMatrix::platformApplySoftware):
* platform/graphics/filters/FEDisplacementMap.cpp:
(WebCore::FEDisplacementMap::platformApplySoftware):
* platform/graphics/filters/FEDropShadow.cpp:
(WebCore::FEDropShadow::platformApplySoftware):
* platform/graphics/filters/FEGaussianBlur.cpp:
(WebCore::FEGaussianBlur::platformApplySoftware):
* platform/graphics/filters/FELighting.cpp:
(WebCore::FELighting::platformApplySoftware):
* platform/graphics/filters/FEMorphology.cpp:
(WebCore::FEMorphology::platformApplySoftware):
* platform/graphics/filters/FETurbulence.cpp:
(WebCore::FETurbulence::platformApplySoftware):
* platform/graphics/filters/FilterEffect.cpp:
(WebCore::FilterEffect::forceValidPreMultipliedPixels):
(WebCore::FilterEffect::copyConvertedImageBufferToDestination):
(WebCore::FilterEffect::copyConvertedImageDataToDestination):
(WebCore::FilterEffect::copyUnmultipliedResult):
(WebCore::FilterEffect::copyPremultipliedResult):
* rendering/shapes/Shape.cpp:
(WebCore::Shape::createRasterShape):

Source/WebKit:

Update for ImageData::data() returning a reference.

* GPUProcess/graphics/RemoteRenderingBackend.cpp:
(WebKit::RemoteRenderingBackend::populateGetImageDataSharedMemory):
* Shared/WebCoreArgumentCoders.cpp:
(IPC::ArgumentCoder<Ref<WebCore::ImageData>>::encode):
* WebProcess/GPU/graphics/RemoteImageBufferProxy.h:

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (277236 => 277237)


--- trunk/Source/WebCore/ChangeLog	2021-05-09 01:26:37 UTC (rev 277236)
+++ trunk/Source/WebCore/ChangeLog	2021-05-09 01:29:38 UTC (rev 277237)
@@ -1,3 +1,103 @@
+2021-05-08  Sam Weinig  <wei...@apple.com>
+
+        Factor out pixel buffer from DOM specific ImageData class
+        https://bugs.webkit.org/show_bug.cgi?id=225554
+
+        Reviewed by Darin Adler.
+
+        Prepare to fix layering violating use of DOM level ImageData being
+        used by platform code by factoring out the pixel storage into a new
+        PixelBuffer class. Since it will be a little more general that 
+        ImageData is now (though ImageData will need to gain these soon)
+        PixelBuffer also captures the pixel format and color space the pixel
+        data represents.
+
+        While here, update ImageData::data() to return a reference rather than
+        a pointer to indicate it is never null and update all the callers.
+
+        * Headers.cmake:
+        * Sources.txt:
+        * WebCore.xcodeproj/project.pbxproj:
+        * bindings/js/JSImageDataCustom.cpp:
+        (WebCore::toJSNewlyCreated):
+        * bindings/js/SerializedScriptValue.cpp:
+        (WebCore::CloneSerializer::dumpImageBitmap):
+        (WebCore::CloneSerializer::dumpIfTerminal):
+        (WebCore::CloneDeserializer::readTerminal):
+        * html/ImageBitmap.cpp:
+        (WebCore::ImageBitmap::createPromise):
+        * html/ImageData.cpp:
+        (WebCore::ImageData::create):
+        (WebCore::ImageData::ImageData):
+        (WebCore::ImageData::deepClone const):
+        (WebCore::operator<<):
+        * html/ImageData.h:
+        (WebCore::ImageData::size const):
+        (WebCore::ImageData::width const):
+        (WebCore::ImageData::height const):
+        (WebCore::ImageData::data const):
+        (WebCore::ImageData::colorSpace const):
+        (WebCore::ImageData::format const):
+        * html/canvas/CanvasRenderingContext2DBase.cpp:
+        (WebCore::createEmptyImageData):
+        (WebCore::CanvasRenderingContext2DBase::putImageData):
+        * html/canvas/WebGLRenderingContextBase.cpp:
+        (WebCore::WebGLRenderingContextBase::texImageSourceHelper):
+        * inspector/InspectorCanvas.cpp:
+        (WebCore::InspectorCanvas::buildArrayForImageData):
+        * platform/graphics/GraphicsContextGL.cpp:
+        (WebCore::GraphicsContextGL::extractImageData):
+        * platform/graphics/ImageBufferBackend.cpp:
+        (WebCore::ImageBufferBackend::convertToLuminanceMask):
+        (WebCore::ImageBufferBackend::getImageData const):
+        (WebCore::ImageBufferBackend::putImageData):
+        * platform/graphics/PixelBuffer.cpp: Added.
+        (WebCore::PixelBuffer::PixelBuffer):
+        (WebCore::PixelBuffer::deepClone const):
+        * platform/graphics/PixelBuffer.h: Added.
+        (WebCore::PixelBuffer::colorSpace const):
+        (WebCore::PixelBuffer::format const):
+        (WebCore::PixelBuffer::size const):
+        (WebCore::PixelBuffer::data const):
+        * platform/graphics/ShadowBlur.cpp:
+        (WebCore::ShadowBlur::blurShadowBuffer):
+        * 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/FEColorMatrix.cpp:
+        (WebCore::FEColorMatrix::platformApplySoftware):
+        * platform/graphics/filters/FEComponentTransfer.cpp:
+        (WebCore::FEComponentTransfer::platformApplySoftware):
+        * platform/graphics/filters/FEComposite.cpp:
+        (WebCore::FEComposite::platformApplySoftware):
+        * platform/graphics/filters/FEConvolveMatrix.cpp:
+        (WebCore::FEConvolveMatrix::platformApplySoftware):
+        * platform/graphics/filters/FEDisplacementMap.cpp:
+        (WebCore::FEDisplacementMap::platformApplySoftware):
+        * platform/graphics/filters/FEDropShadow.cpp:
+        (WebCore::FEDropShadow::platformApplySoftware):
+        * platform/graphics/filters/FEGaussianBlur.cpp:
+        (WebCore::FEGaussianBlur::platformApplySoftware):
+        * platform/graphics/filters/FELighting.cpp:
+        (WebCore::FELighting::platformApplySoftware):
+        * platform/graphics/filters/FEMorphology.cpp:
+        (WebCore::FEMorphology::platformApplySoftware):
+        * platform/graphics/filters/FETurbulence.cpp:
+        (WebCore::FETurbulence::platformApplySoftware):
+        * platform/graphics/filters/FilterEffect.cpp:
+        (WebCore::FilterEffect::forceValidPreMultipliedPixels):
+        (WebCore::FilterEffect::copyConvertedImageBufferToDestination):
+        (WebCore::FilterEffect::copyConvertedImageDataToDestination):
+        (WebCore::FilterEffect::copyUnmultipliedResult):
+        (WebCore::FilterEffect::copyPremultipliedResult):
+        * rendering/shapes/Shape.cpp:
+        (WebCore::Shape::createRasterShape):
+
 2021-05-08  Myles C. Maxfield  <mmaxfi...@apple.com>
 
         [Cocoa] Unify font collection handling between all Cocoa ports

Modified: trunk/Source/WebCore/Headers.cmake (277236 => 277237)


--- trunk/Source/WebCore/Headers.cmake	2021-05-09 01:26:37 UTC (rev 277236)
+++ trunk/Source/WebCore/Headers.cmake	2021-05-09 01:29:38 UTC (rev 277237)
@@ -1288,6 +1288,7 @@
     platform/graphics/Path.h
     platform/graphics/PathUtilities.h
     platform/graphics/Pattern.h
+    platform/graphics/PixelBuffer.h
     platform/graphics/PixelFormat.h
     platform/graphics/PlatformDisplay.h
     platform/graphics/PlatformImage.h

Modified: trunk/Source/WebCore/Sources.txt (277236 => 277237)


--- trunk/Source/WebCore/Sources.txt	2021-05-09 01:26:37 UTC (rev 277236)
+++ trunk/Source/WebCore/Sources.txt	2021-05-09 01:29:38 UTC (rev 277237)
@@ -2012,6 +2012,7 @@
 platform/graphics/PathTraversalState.cpp
 platform/graphics/PathUtilities.cpp
 platform/graphics/Pattern.cpp
+platform/graphics/PixelBuffer.cpp
 platform/graphics/PlatformTimeRanges.cpp
 platform/graphics/Region.cpp
 platform/graphics/RemoteGraphicsContextGLProxyBase.cpp

Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (277236 => 277237)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2021-05-09 01:26:37 UTC (rev 277236)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2021-05-09 01:29:38 UTC (rev 277237)
@@ -4145,6 +4145,7 @@
 		BCE659A90EA927B9007E4533 /* ThemeTypes.h in Headers */ = {isa = PBXBuildFile; fileRef = BCE659A80EA927B9007E4533 /* ThemeTypes.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		BCE659E60EA92FB2007E4533 /* ThemeMac.h in Headers */ = {isa = PBXBuildFile; fileRef = BCE659E50EA92FB2007E4533 /* ThemeMac.h */; };
 		BCE65BEB0EACDF16007E4533 /* Length.h in Headers */ = {isa = PBXBuildFile; fileRef = BCE65BE90EACDF16007E4533 /* Length.h */; settings = {ATTRIBUTES = (Private, ); }; };
+		BCE691E5264637FC00EBDC3A /* PixelBuffer.h in Headers */ = {isa = PBXBuildFile; fileRef = BC4839BA2646181A00A28B62 /* PixelBuffer.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		BCE789161120D6080060ECE5 /* InlineIterator.h in Headers */ = {isa = PBXBuildFile; fileRef = BCE789151120D6080060ECE5 /* InlineIterator.h */; };
 		BCE789861120E7A60060ECE5 /* BidiRun.h in Headers */ = {isa = PBXBuildFile; fileRef = BCE789851120E7A60060ECE5 /* BidiRun.h */; };
 		BCE93F451517C567008CCF74 /* RenderFragmentContainerSet.h in Headers */ = {isa = PBXBuildFile; fileRef = BCE93F441517C567008CCF74 /* RenderFragmentContainerSet.h */; };
@@ -14154,6 +14155,8 @@
 		BC46C1F90C0DDC8F0020CFC3 /* JSCSSPageRule.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = JSCSSPageRule.h; sourceTree = "<group>"; };
 		BC46C2040C0DDCA10020CFC3 /* JSCSSStyleRule.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = JSCSSStyleRule.cpp; sourceTree = "<group>"; };
 		BC46C2050C0DDCA10020CFC3 /* JSCSSStyleRule.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = JSCSSStyleRule.h; sourceTree = "<group>"; };
+		BC4839BA2646181A00A28B62 /* PixelBuffer.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PixelBuffer.h; sourceTree = "<group>"; };
+		BC4839BB2646181A00A28B62 /* PixelBuffer.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = PixelBuffer.cpp; sourceTree = "<group>"; };
 		BC4918C00BFEA050009D6316 /* JSHTMLFrameElement.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = JSHTMLFrameElement.cpp; sourceTree = "<group>"; };
 		BC4918C10BFEA050009D6316 /* JSHTMLFrameElement.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = JSHTMLFrameElement.h; sourceTree = "<group>"; };
 		BC4918C20BFEA050009D6316 /* JSHTMLIFrameElement.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = JSHTMLIFrameElement.cpp; sourceTree = "<group>"; };
@@ -27025,6 +27028,8 @@
 				2D5002FA1B56D7990020AAF7 /* PathUtilities.h */,
 				A8FA6E5C0E4CFDED00D5CF49 /* Pattern.cpp */,
 				A8FA6E5B0E4CFDED00D5CF49 /* Pattern.h */,
+				BC4839BB2646181A00A28B62 /* PixelBuffer.cpp */,
+				BC4839BA2646181A00A28B62 /* PixelBuffer.h */,
 				BCA55912263DBD79007F19B3 /* PixelFormat.h */,
 				726D56E1253AE0430002EF90 /* PlatformImage.h */,
 				72BAC3A623E17328008D741C /* PlatformImageBuffer.h */,
@@ -34433,6 +34438,7 @@
 				1D2F8E062344752300993B68 /* PictureInPictureWindow.h in Headers */,
 				5758597C23A1FCF300C74572 /* Pin.h in Headers */,
 				D0FF2A5E11F8C45A007E74E0 /* PingLoader.h in Headers */,
+				BCE691E5264637FC00EBDC3A /* PixelBuffer.h in Headers */,
 				CD7D33441C7A123F00041293 /* PixelBufferConformerCV.h in Headers */,
 				BCA55914263DBD79007F19B3 /* PixelFormat.h in Headers */,
 				CDEFA2281E7669E8000AE99C /* PlatformAudioData.h in Headers */,

Modified: trunk/Source/WebCore/bindings/js/JSImageDataCustom.cpp (277236 => 277237)


--- trunk/Source/WebCore/bindings/js/JSImageDataCustom.cpp	2021-05-09 01:26:37 UTC (rev 277236)
+++ trunk/Source/WebCore/bindings/js/JSImageDataCustom.cpp	2021-05-09 01:29:38 UTC (rev 277237)
@@ -40,13 +40,13 @@
 JSValue toJSNewlyCreated(JSGlobalObject* lexicalGlobalObject, JSDOMGlobalObject* globalObject, Ref<ImageData>&& imageData)
 {
     VM& vm = lexicalGlobalObject->vm();
-    auto* data = ""
+    auto& data = ""
     auto* wrapper = createWrapper<ImageData>(globalObject, WTFMove(imageData));
     Identifier dataName = Identifier::fromString(vm, "data");
     wrapper->putDirect(vm, dataName, toJS(lexicalGlobalObject, globalObject, data), PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly);
     // FIXME: Adopt reportExtraMemoryVisited, and switch to reportExtraMemoryAllocated.
     // https://bugs.webkit.org/show_bug.cgi?id=142595
-    vm.heap.deprecatedReportExtraMemory(data->length());
+    vm.heap.deprecatedReportExtraMemory(data.length());
     
     return wrapper;
 }

Modified: trunk/Source/WebCore/bindings/js/SerializedScriptValue.cpp (277236 => 277237)


--- trunk/Source/WebCore/bindings/js/SerializedScriptValue.cpp	2021-05-09 01:26:37 UTC (rev 277236)
+++ trunk/Source/WebCore/bindings/js/SerializedScriptValue.cpp	2021-05-09 01:29:38 UTC (rev 277237)
@@ -1082,7 +1082,7 @@
             return;
         }
 
-        RefPtr<ArrayBuffer> arrayBuffer = imageData->data()->possiblySharedBuffer();
+        auto arrayBuffer = imageData->data().possiblySharedBuffer();
         if (!arrayBuffer) {
             code = SerializationReturnCode::ValidationError;
             return;
@@ -1226,8 +1226,8 @@
                 write(ImageDataTag);
                 write(data->width());
                 write(data->height());
-                write(data->data()->length());
-                write(data->data()->data(), data->data()->length());
+                write(data->data().length());
+                write(data->data().data(), data->data().length());
                 return true;
             }
             if (auto* regExp = jsDynamicCast<RegExpObject*>(vm, obj)) {
@@ -3390,9 +3390,9 @@
                 return JSValue();
             }
             if (length)
-                memcpy(result->data()->data(), m_ptr, length);
+                memcpy(result->data().data(), m_ptr, length);
             else
-                result->data()->zeroFill();
+                result->data().zeroFill();
             m_ptr += length;
             return getJSValue(result.get());
         }

Modified: trunk/Source/WebCore/html/ImageBitmap.cpp (277236 => 277237)


--- trunk/Source/WebCore/html/ImageBitmap.cpp	2021-05-09 01:26:37 UTC (rev 277236)
+++ trunk/Source/WebCore/html/ImageBitmap.cpp	2021-05-09 01:29:38 UTC (rev 277237)
@@ -782,7 +782,7 @@
     //      internal slot.
     // 6.2. If IsDetachedBuffer(buffer) is true, then return p rejected with an
     //      "InvalidStateError" DOMException.
-    if (imageData->data()->isDetached()) {
+    if (imageData->data().isDetached()) {
         promise.reject(InvalidStateError, "ImageData's viewed buffer has been detached");
         return;
     }

Modified: trunk/Source/WebCore/html/ImageData.cpp (277236 => 277237)


--- trunk/Source/WebCore/html/ImageData.cpp	2021-05-09 01:26:37 UTC (rev 277236)
+++ trunk/Source/WebCore/html/ImageData.cpp	2021-05-09 01:29:38 UTC (rev 277237)
@@ -57,7 +57,7 @@
         return Exception { RangeError, "Out of memory"_s };
     }
     byteArray->zeroFill();
-    return adoptRef(*new ImageData(size, byteArray.releaseNonNull()));
+    return adoptRef(*new ImageData({ DestinationColorSpace::SRGB, PixelFormat::RGBA8, size, byteArray.releaseNonNull() }));
 }
 
 RefPtr<ImageData> ImageData::create(const IntSize& size)
@@ -68,7 +68,7 @@
     auto byteArray = Uint8ClampedArray::tryCreateUninitialized(dataSize.unsafeGet());
     if (!byteArray)
         return nullptr;
-    return adoptRef(*new ImageData(size, byteArray.releaseNonNull()));
+    return adoptRef(*new ImageData({ DestinationColorSpace::SRGB, PixelFormat::RGBA8, size, byteArray.releaseNonNull() }));
 }
 
 RefPtr<ImageData> ImageData::create(const IntSize& size, Ref<Uint8ClampedArray>&& byteArray)
@@ -76,7 +76,8 @@
     auto dataSize = ImageData::dataSize(size);
     if (dataSize.hasOverflowed() || dataSize.unsafeGet() > byteArray->length())
         return nullptr;
-    return adoptRef(*new ImageData(size, WTFMove(byteArray)));
+
+    return adoptRef(*new ImageData({ DestinationColorSpace::SRGB, PixelFormat::RGBA8, size, WTFMove(byteArray) }));
 }
 
 ExceptionOr<Ref<ImageData>> ImageData::create(Ref<Uint8ClampedArray>&& byteArray, unsigned sw, Optional<unsigned> sh)
@@ -99,22 +100,22 @@
     return result.releaseNonNull();
 }
 
-ImageData::ImageData(const IntSize& size, Ref<Uint8ClampedArray>&& byteArray)
-    : m_size(size)
-    , m_data(WTFMove(byteArray))
+ImageData::ImageData(PixelBuffer&& pixelBuffer)
+    : m_pixelBuffer(WTFMove(pixelBuffer))
 {
-    RELEASE_ASSERT_WITH_SECURITY_IMPLICATION((size.area() * 4).unsafeGet() <= m_data->length());
 }
 
+ImageData::~ImageData() = default;
+
 Ref<ImageData> ImageData::deepClone() const
 {
-    return adoptRef(*new ImageData(m_size, Uint8ClampedArray::create(m_data->data(), m_data->length())));
+    return adoptRef(*new ImageData(m_pixelBuffer.deepClone()));
 }
 
 TextStream& operator<<(TextStream& ts, const ImageData& imageData)
 {
     // Print out the address of the pixel data array
-    return ts << imageData.data();
+    return ts << &imageData.data();
 }
 
 }

Modified: trunk/Source/WebCore/html/ImageData.h (277236 => 277237)


--- trunk/Source/WebCore/html/ImageData.h	2021-05-09 01:26:37 UTC (rev 277236)
+++ trunk/Source/WebCore/html/ImageData.h	2021-05-09 01:29:38 UTC (rev 277237)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2008, 2009 Apple Inc. All rights reserved.
+ * Copyright (C) 2008-2021 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -29,9 +29,7 @@
 #pragma once
 
 #include "ExceptionOr.h"
-#include "IntSize.h"
-#include <_javascript_Core/TypedArrayInlines.h>
-#include <_javascript_Core/Uint8ClampedArray.h>
+#include "PixelBuffer.h"
 
 namespace WebCore {
 
@@ -41,21 +39,25 @@
     WEBCORE_EXPORT static RefPtr<ImageData> create(const IntSize&);
     WEBCORE_EXPORT static RefPtr<ImageData> create(const IntSize&, Ref<Uint8ClampedArray>&&);
     WEBCORE_EXPORT static ExceptionOr<Ref<ImageData>> create(Ref<Uint8ClampedArray>&&, unsigned sw, Optional<unsigned> sh);
+    WEBCORE_EXPORT ~ImageData();
 
-    IntSize size() const { return m_size; }
-    int width() const { return m_size.width(); }
-    int height() const { return m_size.height(); }
+    const IntSize& size() const { return m_pixelBuffer.size(); }
+    int width() const { return m_pixelBuffer.size().width(); }
+    int height() const { return m_pixelBuffer.size().height(); }
 
-    Uint8ClampedArray* data() const { return m_data.ptr(); }
+    Uint8ClampedArray& data() const { return m_pixelBuffer.data(); }
 
     Ref<ImageData> deepClone() const;
 
+    DestinationColorSpace colorSpace() const { return m_pixelBuffer.colorSpace(); }
+    PixelFormat format() const { return m_pixelBuffer.format(); }
+
 private:
-    ImageData(const IntSize&, Ref<Uint8ClampedArray>&&);
+    explicit ImageData(PixelBuffer&&);
+
     static Checked<unsigned, RecordOverflow> dataSize(const IntSize&);
 
-    IntSize m_size;
-    Ref<Uint8ClampedArray> m_data;
+    PixelBuffer m_pixelBuffer;
 };
 
 WEBCORE_EXPORT WTF::TextStream& operator<<(WTF::TextStream&, const ImageData&);

Modified: trunk/Source/WebCore/html/canvas/CanvasRenderingContext2DBase.cpp (277236 => 277237)


--- trunk/Source/WebCore/html/canvas/CanvasRenderingContext2DBase.cpp	2021-05-09 01:26:37 UTC (rev 277236)
+++ trunk/Source/WebCore/html/canvas/CanvasRenderingContext2DBase.cpp	2021-05-09 01:29:38 UTC (rev 277237)
@@ -2155,7 +2155,7 @@
 {
     auto data = ""
     if (data)
-        data->data()->zeroFill();
+        data->data().zeroFill();
     return data;
 }
 
@@ -2220,7 +2220,7 @@
     if (!buffer)
         return;
 
-    if (!data.data() || data.data()->isDetached())
+    if (data.data().isDetached())
         return;
 
     if (dirtyWidth < 0) {

Modified: trunk/Source/WebCore/html/canvas/WebGLRenderingContextBase.cpp (277236 => 277237)


--- trunk/Source/WebCore/html/canvas/WebGLRenderingContextBase.cpp	2021-05-09 01:26:37 UTC (rev 277236)
+++ trunk/Source/WebCore/html/canvas/WebGLRenderingContextBase.cpp	2021-05-09 01:29:38 UTC (rev 277237)
@@ -4749,7 +4749,7 @@
             texImageImpl(functionID, target, level, internalformat, xoffset, yoffset, zoffset, format, type, image.get(), GraphicsContextGL::DOMSource::Image, false, bitmap->premultiplyAlpha(), bitmap->forciblyPremultiplyAlpha(), sourceImageRect, depth, unpackImageHeight);
         return { };
     }, [&](const RefPtr<ImageData>& pixels) -> ExceptionOr<void> {
-        if (pixels->data()->isDetached()) {
+        if (pixels->data().isDetached()) {
             synthesizeGLError(GraphicsContextGL::INVALID_VALUE, functionName, "The source data has been detached.");
             return { };
         }
@@ -4778,7 +4778,7 @@
         // No conversion is needed if destination format is RGBA and type is USIGNED_BYTE and no Flip or Premultiply operation is required.
         if (!m_unpackFlipY && !m_unpackPremultiplyAlpha && format == GraphicsContextGL::RGBA && type == GraphicsContextGL::UNSIGNED_BYTE && !selectingSubRectangle && depth == 1) {
             needConversion = false;
-            byteLength = pixels->data()->byteLength();
+            byteLength = pixels->data().byteLength();
         } else {
             if (type == GraphicsContextGL::UNSIGNED_INT_10F_11F_11F_REV) {
                 // The UNSIGNED_INT_10F_11F_11F_REV type pack/unpack isn't implemented.
@@ -4794,11 +4794,11 @@
         if (functionID == TexImageFunctionID::TexImage2D) {
             texImage2DBase(target, level, internalformat,
                 adjustedSourceImageRect.width(), adjustedSourceImageRect.height(), 0,
-                format, type, byteLength, needConversion ? data.data() : pixels->data()->data());
+                format, type, byteLength, needConversion ? data.data() : pixels->data().data());
         } else if (functionID == TexImageFunctionID::TexSubImage2D) {
             texSubImage2DBase(target, level, xoffset, yoffset,
                 adjustedSourceImageRect.width(), adjustedSourceImageRect.height(),
-                format, format, type, byteLength, needConversion ? data.data() : pixels->data()->data());
+                format, format, type, byteLength, needConversion ? data.data() : pixels->data().data());
         } else {
 #if USE(ANGLE)
             // 3D functions.
@@ -4805,12 +4805,12 @@
             if (functionID == TexImageFunctionID::TexImage3D) {
                 m_context->texImage3D(target, level, internalformat,
                     adjustedSourceImageRect.width(), adjustedSourceImageRect.height(), depth, 0,
-                    format, type, makeGCGLSpan(needConversion ? data.data() : pixels->data()->data(), byteLength));
+                    format, type, makeGCGLSpan(needConversion ? data.data() : pixels->data().data(), byteLength));
             } else {
                 ASSERT(functionID == TexImageFunctionID::TexSubImage3D);
                 m_context->texSubImage3D(target, level, xoffset, yoffset, zoffset,
                     adjustedSourceImageRect.width(), adjustedSourceImageRect.height(), depth,
-                    format, type, makeGCGLSpan(needConversion ? data.data() : pixels->data()->data(), byteLength));
+                    format, type, makeGCGLSpan(needConversion ? data.data() : pixels->data().data(), byteLength));
             }
 #else
             // WebGL 2.0 is only supported with the ANGLE backend.

Modified: trunk/Source/WebCore/inspector/InspectorCanvas.cpp (277236 => 277237)


--- trunk/Source/WebCore/inspector/InspectorCanvas.cpp	2021-05-09 01:26:37 UTC (rev 277236)
+++ trunk/Source/WebCore/inspector/InspectorCanvas.cpp	2021-05-09 01:29:38 UTC (rev 277237)
@@ -1459,8 +1459,8 @@
 Ref<JSON::ArrayOf<JSON::Value>> InspectorCanvas::buildArrayForImageData(const ImageData& imageData)
 {
     auto data = ""
-    for (size_t i = 0; i < imageData.data()->length(); ++i)
-        data->addItem(imageData.data()->item(i));
+    for (size_t i = 0; i < imageData.data().length(); ++i)
+        data->addItem(imageData.data().item(i));
 
     auto array = JSON::ArrayOf<JSON::Value>::create();
     array->addItem(WTFMove(data));

Modified: trunk/Source/WebCore/platform/graphics/GraphicsContextGL.cpp (277236 => 277237)


--- trunk/Source/WebCore/platform/graphics/GraphicsContextGL.cpp	2021-05-09 01:26:37 UTC (rev 277236)
+++ trunk/Source/WebCore/platform/graphics/GraphicsContextGL.cpp	2021-05-09 01:29:38 UTC (rev 277237)
@@ -779,7 +779,7 @@
         return false;
     data.resize(packedSize);
 
-    if (!packPixels(imageData->data()->data(), sourceDataFormat, width, height, sourceImageSubRectangle, depth, 0, unpackImageHeight, format, type, premultiplyAlpha ? AlphaOp::DoPremultiply : AlphaOp::DoNothing, data.data(), flipY))
+    if (!packPixels(imageData->data().data(), 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/ImageBufferBackend.cpp (277236 => 277237)


--- trunk/Source/WebCore/platform/graphics/ImageBufferBackend.cpp	2021-05-09 01:26:37 UTC (rev 277236)
+++ trunk/Source/WebCore/platform/graphics/ImageBufferBackend.cpp	2021-05-09 01:29:38 UTC (rev 277237)
@@ -73,18 +73,18 @@
     if (!imageData)
         return;
 
-    auto* srcPixelArray = imageData->data();
-    unsigned pixelArrayLength = srcPixelArray->length();
+    auto& srcPixelArray = imageData->data();
+    unsigned pixelArrayLength = srcPixelArray.length();
     for (unsigned pixelOffset = 0; pixelOffset < pixelArrayLength; pixelOffset += 4) {
-        uint8_t a = srcPixelArray->item(pixelOffset + 3);
+        uint8_t a = srcPixelArray.item(pixelOffset + 3);
         if (!a)
             continue;
-        uint8_t r = srcPixelArray->item(pixelOffset);
-        uint8_t g = srcPixelArray->item(pixelOffset + 1);
-        uint8_t b = srcPixelArray->item(pixelOffset + 2);
+        uint8_t r = srcPixelArray.item(pixelOffset);
+        uint8_t g = srcPixelArray.item(pixelOffset + 1);
+        uint8_t b = srcPixelArray.item(pixelOffset + 2);
 
         double luma = (r * 0.2125 + g * 0.7154 + b * 0.0721) * ((double)a / 255.0);
-        srcPixelArray->set(pixelOffset + 3, luma);
+        srcPixelArray.set(pixelOffset + 3, luma);
     }
 
     putImageData(AlphaPremultiplication::Unpremultiplied, *imageData, logicalRect(), IntPoint::zero(), AlphaPremultiplication::Premultiplied);
@@ -241,10 +241,10 @@
         destRect.setY(-srcRectScaled.y());
 
     if (destRect.size() != srcRectScaled.size())
-        imageData->data()->zeroFill();
+        imageData->data().zeroFill();
 
     unsigned destBytesPerRow = 4 * srcRectScaled.width();
-    uint8_t* destRows = imageData->data()->data() + destRect.y() * destBytesPerRow + destRect.x() * 4;
+    uint8_t* destRows = imageData->data().data() + destRect.y() * destBytesPerRow + destRect.x() * 4;
 
     unsigned srcBytesPerRow = bytesPerRow();
     uint8_t* srcRows = reinterpret_cast<uint8_t*>(data) + srcRectClipped.y() * srcBytesPerRow + srcRectClipped.x() * 4;
@@ -278,7 +278,7 @@
     uint8_t* destRows = reinterpret_cast<uint8_t*>(data) + destRect.y() * destBytesPerRow + destRect.x() * 4;
 
     unsigned srcBytesPerRow = 4 * imageData.size().width();
-    uint8_t* srcRows = imageData.data()->data() + srcRectClipped.y() * srcBytesPerRow + srcRectClipped.x() * 4;
+    uint8_t* srcRows = imageData.data().data() + srcRectClipped.y() * srcBytesPerRow + srcRectClipped.x() * 4;
 
     copyImagePixels(
         inputFormat, PixelFormat::RGBA8, srcBytesPerRow, srcRows,

Added: trunk/Source/WebCore/platform/graphics/PixelBuffer.cpp (0 => 277237)


--- trunk/Source/WebCore/platform/graphics/PixelBuffer.cpp	                        (rev 0)
+++ trunk/Source/WebCore/platform/graphics/PixelBuffer.cpp	2021-05-09 01:29:38 UTC (rev 277237)
@@ -0,0 +1,49 @@
+/*
+ * 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 "PixelBuffer.h"
+
+#include <_javascript_Core/TypedArrayInlines.h>
+
+namespace WebCore {
+
+PixelBuffer::PixelBuffer(DestinationColorSpace colorSpace, PixelFormat format, const IntSize& size, Ref<JSC::Uint8ClampedArray>&& data)
+    : m_colorSpace { colorSpace }
+    , m_format { format }
+    , m_size { size }
+    , m_data { WTFMove(data) }
+{
+    RELEASE_ASSERT_WITH_SECURITY_IMPLICATION((m_size.area() * 4).unsafeGet() <= m_data->length());
+}
+
+PixelBuffer::~PixelBuffer() = default;
+
+PixelBuffer PixelBuffer::deepClone() const
+{
+    return { m_colorSpace, m_format, m_size, Uint8ClampedArray::create(m_data->data(), m_data->length()) };
+}
+
+}

Added: trunk/Source/WebCore/platform/graphics/PixelBuffer.h (0 => 277237)


--- trunk/Source/WebCore/platform/graphics/PixelBuffer.h	                        (rev 0)
+++ trunk/Source/WebCore/platform/graphics/PixelBuffer.h	2021-05-09 01:29:38 UTC (rev 277237)
@@ -0,0 +1,58 @@
+/*
+ * 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 "ColorSpace.h"
+#include "IntSize.h"
+#include "PixelFormat.h"
+#include <_javascript_Core/Uint8ClampedArray.h>
+
+namespace WebCore {
+
+class PixelBuffer {
+    WTF_MAKE_NONCOPYABLE(PixelBuffer);
+public:
+    PixelBuffer(DestinationColorSpace, PixelFormat, const IntSize&, Ref<JSC::Uint8ClampedArray>&&);
+    ~PixelBuffer();
+
+    PixelBuffer(PixelBuffer&&) = default;
+    PixelBuffer& operator=(PixelBuffer&&) = default;
+
+    DestinationColorSpace colorSpace() const { return m_colorSpace; }
+    PixelFormat format() const { return m_format; }
+    const IntSize& size() const { return m_size; }
+    JSC::Uint8ClampedArray& data() const { return m_data.get(); }
+
+    PixelBuffer deepClone() const;
+
+private:
+    DestinationColorSpace m_colorSpace;
+    PixelFormat m_format;
+    IntSize m_size;
+    Ref<JSC::Uint8ClampedArray> m_data;
+};
+
+}

Modified: trunk/Source/WebCore/platform/graphics/ShadowBlur.cpp (277236 => 277237)


--- trunk/Source/WebCore/platform/graphics/ShadowBlur.cpp	2021-05-09 01:26:37 UTC (rev 277236)
+++ trunk/Source/WebCore/platform/graphics/ShadowBlur.cpp	2021-05-09 01:29:38 UTC (rev 277237)
@@ -908,8 +908,7 @@
     if (!layerData)
         return;
 
-    auto* blurPixelArray = layerData->data();
-    blurLayerImage(blurPixelArray->data(), blurRect.size(), blurRect.width() * 4);
+    blurLayerImage(layerData->data().data(), blurRect.size(), blurRect.width() * 4);
     layerImage.putImageData(AlphaPremultiplication::Unpremultiplied, *layerData, blurRect);
 }
 

Modified: trunk/Source/WebCore/platform/graphics/angle/GraphicsContextGLANGLE.cpp (277236 => 277237)


--- trunk/Source/WebCore/platform/graphics/angle/GraphicsContextGLANGLE.cpp	2021-05-09 01:26:37 UTC (rev 277236)
+++ trunk/Source/WebCore/platform/graphics/angle/GraphicsContextGLANGLE.cpp	2021-05-09 01:29:38 UTC (rev 277237)
@@ -90,7 +90,7 @@
     ScopedPixelStorageMode packSkipPixels(GL_PACK_SKIP_PIXELS, 0, m_isForWebGL2);
     ScopedBufferBinding scopedPixelPackBufferReset(GL_PIXEL_PACK_BUFFER, 0, m_isForWebGL2);
 
-    gl::ReadnPixelsRobustANGLE(0, 0, imageData->width(), imageData->height(), GL_RGBA, GL_UNSIGNED_BYTE, imageData->data()->byteLength(), nullptr, nullptr, nullptr, imageData->data()->data());
+    gl::ReadnPixelsRobustANGLE(0, 0, imageData->width(), imageData->height(), GL_RGBA, GL_UNSIGNED_BYTE, imageData->data().byteLength(), nullptr, nullptr, nullptr, imageData->data().data());
     // 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.
@@ -97,7 +97,7 @@
     // https://bugs.webkit.org/show_bug.cgi?id=215804
 #if PLATFORM(MAC) || PLATFORM(IOS_FAMILY)
     if (!contextAttributes().alpha)
-        wipeAlphaChannelFromPixels(imageData->width(), imageData->height(), imageData->data()->data());
+        wipeAlphaChannelFromPixels(imageData->width(), imageData->height(), imageData->data().data());
 #endif
     return imageData;
 }

Modified: trunk/Source/WebCore/platform/graphics/cairo/GraphicsContextGLCairo.cpp (277236 => 277237)


--- trunk/Source/WebCore/platform/graphics/cairo/GraphicsContextGLCairo.cpp	2021-05-09 01:26:37 UTC (rev 277236)
+++ trunk/Source/WebCore/platform/graphics/cairo/GraphicsContextGLCairo.cpp	2021-05-09 01:29:38 UTC (rev 277237)
@@ -113,8 +113,8 @@
         return;
 
     // Convert RGBA to BGRA. BGRA is CAIRO_FORMAT_ARGB32 on little-endian architectures.
-    size_t totalBytes = imageData->data()->byteLength();
-    uint8_t* pixels = imageData->data()->data();
+    size_t totalBytes = imageData->data().byteLength();
+    uint8_t* pixels = imageData->data().data();
     for (size_t i = 0; i < totalBytes; i += 4)
         std::swap(pixels[i], pixels[i + 2]);
 
@@ -129,7 +129,7 @@
     auto imageSize = imageData->size();
 
     RefPtr<cairo_surface_t> imageSurface = adoptRef(cairo_image_surface_create_for_data(
-        imageData->data()->data(), CAIRO_FORMAT_ARGB32, imageData->width(), imageData->height(), imageData->width() * 4));
+        imageData->data().data(), CAIRO_FORMAT_ARGB32, imageData->width(), imageData->height(), imageData->width() * 4));
 
     auto image = NativeImage::create(WTFMove(imageSurface));
 

Modified: trunk/Source/WebCore/platform/graphics/cg/GraphicsContextGLCG.cpp (277236 => 277237)


--- trunk/Source/WebCore/platform/graphics/cg/GraphicsContextGLCG.cpp	2021-05-09 01:26:37 UTC (rev 277236)
+++ trunk/Source/WebCore/platform/graphics/cg/GraphicsContextGLCG.cpp	2021-05-09 01:29:38 UTC (rev 277237)
@@ -529,7 +529,7 @@
     auto imageSize = imageData->size();
     int rowBytes = imageSize.width() * 4;
         size_t dataSize = rowBytes * imageSize.height();
-    uint8_t* imagePixels = imageData->data()->data();
+    uint8_t* imagePixels = imageData->data().data();
         verifyImageBufferIsBigEnough(imagePixels, dataSize);
     RetainPtr<CGDataProviderRef> dataProvider = adoptCF(CGDataProviderCreateWithData(&imageData.leakRef(), imagePixels, dataSize, releaseImageData));
 

Modified: trunk/Source/WebCore/platform/graphics/cg/ImageBufferCGBackend.cpp (277236 => 277237)


--- trunk/Source/WebCore/platform/graphics/cg/ImageBufferCGBackend.cpp	2021-05-09 01:26:37 UTC (rev 277236)
+++ trunk/Source/WebCore/platform/graphics/cg/ImageBufferCGBackend.cpp	2021-05-09 01:29:38 UTC (rev 277237)
@@ -184,7 +184,6 @@
     ASSERT(uti);
 
     PlatformImagePtr image;
-    RefPtr<Uint8ClampedArray> protectedPixelArray;
 
     if (CFEqual(uti.get(), jpegUTI())) {
         // JPEGs don't have an alpha channel, so we have to manually composite on top of black.
@@ -192,7 +191,7 @@
         if (!imageData)
             return nullptr;
 
-        protectedPixelArray = makeRefPtr(imageData->data());
+        auto protectedPixelArray = makeRef(imageData->data());
         size_t dataSize = protectedPixelArray->byteLength();
         IntSize pixelArrayDimensions = imageData->size();
 

Modified: trunk/Source/WebCore/platform/graphics/cg/ImageBufferUtilitiesCG.cpp (277236 => 277237)


--- trunk/Source/WebCore/platform/graphics/cg/ImageBufferUtilitiesCG.cpp	2021-05-09 01:26:37 UTC (rev 277236)
+++ trunk/Source/WebCore/platform/graphics/cg/ImageBufferUtilitiesCG.cpp	2021-05-09 01:29:38 UTC (rev 277237)
@@ -126,7 +126,7 @@
     ASSERT(uti);
 
     CGImageAlphaInfo dataAlphaInfo = kCGImageAlphaLast;
-    unsigned char* data = ""
+    unsigned char* data = ""
     Vector<uint8_t> premultipliedData;
 
     if (CFEqual(uti.get(), jpegUTI())) {

Modified: trunk/Source/WebCore/platform/graphics/filters/FEColorMatrix.cpp (277236 => 277237)


--- trunk/Source/WebCore/platform/graphics/filters/FEColorMatrix.cpp	2021-05-09 01:26:37 UTC (rev 277236)
+++ trunk/Source/WebCore/platform/graphics/filters/FEColorMatrix.cpp	2021-05-09 01:29:38 UTC (rev 277237)
@@ -290,7 +290,7 @@
     if (!imageData)
         return;
 
-    auto* pixelArray = imageData->data();
+    auto& pixelArray = imageData->data();
     IntSize pixelArrayDimensions = imageData->size();
 
     Vector<float> values = normalizedFloats(m_values);
@@ -299,16 +299,16 @@
     case FECOLORMATRIX_TYPE_UNKNOWN:
         break;
     case FECOLORMATRIX_TYPE_MATRIX:
-        effectType<FECOLORMATRIX_TYPE_MATRIX>(*pixelArray, values, pixelArrayDimensions);
+        effectType<FECOLORMATRIX_TYPE_MATRIX>(pixelArray, values, pixelArrayDimensions);
         break;
     case FECOLORMATRIX_TYPE_SATURATE: 
-        effectType<FECOLORMATRIX_TYPE_SATURATE>(*pixelArray, values, pixelArrayDimensions);
+        effectType<FECOLORMATRIX_TYPE_SATURATE>(pixelArray, values, pixelArrayDimensions);
         break;
     case FECOLORMATRIX_TYPE_HUEROTATE:
-        effectType<FECOLORMATRIX_TYPE_HUEROTATE>(*pixelArray, values, pixelArrayDimensions);
+        effectType<FECOLORMATRIX_TYPE_HUEROTATE>(pixelArray, values, pixelArrayDimensions);
         break;
     case FECOLORMATRIX_TYPE_LUMINANCETOALPHA:
-        effectType<FECOLORMATRIX_TYPE_LUMINANCETOALPHA>(*pixelArray, values, pixelArrayDimensions);
+        effectType<FECOLORMATRIX_TYPE_LUMINANCETOALPHA>(pixelArray, values, pixelArrayDimensions);
         setIsAlphaImage(true);
         break;
     }

Modified: trunk/Source/WebCore/platform/graphics/filters/FEComponentTransfer.cpp (277236 => 277237)


--- trunk/Source/WebCore/platform/graphics/filters/FEComponentTransfer.cpp	2021-05-09 01:26:37 UTC (rev 277236)
+++ trunk/Source/WebCore/platform/graphics/filters/FEComponentTransfer.cpp	2021-05-09 01:29:38 UTC (rev 277237)
@@ -109,10 +109,11 @@
     FilterEffect* in = inputEffect(0);
 
     auto* imageResult = createUnmultipliedImageResult();
-    auto* pixelArray = imageResult ? imageResult->data() : nullptr;
-    if (!pixelArray)
+    if (!imageResult)
         return;
 
+    auto& pixelArray = imageResult->data();
+
     LookupTable redTable;
     LookupTable greenTable;
     LookupTable blueTable;
@@ -120,9 +121,9 @@
     computeLookupTables(redTable, greenTable, blueTable, alphaTable);
 
     IntRect drawingRect = requestedRegionOfInputImageData(in->absolutePaintRect());
-    in->copyUnmultipliedResult(*pixelArray, drawingRect, operatingColorSpace());
-    unsigned pixelArrayLength = pixelArray->length();
-    uint8_t* data = ""
+    in->copyUnmultipliedResult(pixelArray, drawingRect, operatingColorSpace());
+    unsigned pixelArrayLength = pixelArray.length();
+    uint8_t* data = ""
     for (unsigned pixelOffset = 0; pixelOffset < pixelArrayLength; pixelOffset += 4) {
         data[pixelOffset] = redTable[data[pixelOffset]];
         data[pixelOffset + 1] = greenTable[data[pixelOffset + 1]];

Modified: trunk/Source/WebCore/platform/graphics/filters/FEComposite.cpp (277236 => 277237)


--- trunk/Source/WebCore/platform/graphics/filters/FEComposite.cpp	2021-05-09 01:26:37 UTC (rev 277236)
+++ trunk/Source/WebCore/platform/graphics/filters/FEComposite.cpp	2021-05-09 01:29:38 UTC (rev 277237)
@@ -230,9 +230,10 @@
 
     if (m_type == FECOMPOSITE_OPERATOR_ARITHMETIC) {
         auto* resultImage = createPremultipliedImageResult();
-        auto* dstPixelArray = resultImage ? resultImage->data() : nullptr;
-        if (!dstPixelArray)
+        if (!resultImage)
             return;
+        
+        auto& dstPixelArray = resultImage->data();
 
         IntRect effectADrawingRect = requestedRegionOfInputImageData(in->absolutePaintRect());
         auto srcPixelArray = in->premultipliedResult(effectADrawingRect, operatingColorSpace());
@@ -240,9 +241,9 @@
             return;
 
         IntRect effectBDrawingRect = requestedRegionOfInputImageData(in2->absolutePaintRect());
-        in2->copyPremultipliedResult(*dstPixelArray, effectBDrawingRect, operatingColorSpace());
+        in2->copyPremultipliedResult(dstPixelArray, effectBDrawingRect, operatingColorSpace());
 
-        platformArithmeticSoftware(*srcPixelArray, *dstPixelArray, m_k1, m_k2, m_k3, m_k4);
+        platformArithmeticSoftware(*srcPixelArray, dstPixelArray, m_k1, m_k2, m_k3, m_k4);
         return;
     }
 

Modified: trunk/Source/WebCore/platform/graphics/filters/FEConvolveMatrix.cpp (277236 => 277237)


--- trunk/Source/WebCore/platform/graphics/filters/FEConvolveMatrix.cpp	2021-05-09 01:26:37 UTC (rev 277236)
+++ trunk/Source/WebCore/platform/graphics/filters/FEConvolveMatrix.cpp	2021-05-09 01:29:38 UTC (rev 277237)
@@ -376,10 +376,12 @@
         resultImage = createUnmultipliedImageResult();
     else
         resultImage = createPremultipliedImageResult();
-    auto* dstPixelArray = resultImage ? resultImage->data() : nullptr;
-    if (!dstPixelArray)
+
+    if (!resultImage)
         return;
 
+    auto& dstPixelArray = resultImage->data();
+
     IntRect effectDrawingRect = requestedRegionOfInputImageData(in->absolutePaintRect());
 
     RefPtr<Uint8ClampedArray> srcPixelArray;
@@ -395,7 +397,7 @@
 
     PaintingData paintingData = {
         *srcPixelArray,
-        *dstPixelArray,
+        dstPixelArray,
         paintSize.width(),
         paintSize.height(),
         m_bias * 255,

Modified: trunk/Source/WebCore/platform/graphics/filters/FEDisplacementMap.cpp (277236 => 277237)


--- trunk/Source/WebCore/platform/graphics/filters/FEDisplacementMap.cpp	2021-05-09 01:26:37 UTC (rev 277236)
+++ trunk/Source/WebCore/platform/graphics/filters/FEDisplacementMap.cpp	2021-05-09 01:29:38 UTC (rev 277237)
@@ -100,10 +100,11 @@
     ASSERT(m_yChannelSelector != CHANNEL_UNKNOWN);
 
     auto* resultImage = createPremultipliedImageResult();
-    auto* dstPixelArray = resultImage ? resultImage->data() : nullptr;
-    if (!dstPixelArray)
+    if (!resultImage)
         return;
 
+    auto& dstPixelArray = resultImage->data();
+
     IntRect effectADrawingRect = requestedRegionOfInputImageData(in->absolutePaintRect());
     auto inputImage = in->premultipliedResult(effectADrawingRect);
 
@@ -140,7 +141,7 @@
             int srcX = x + static_cast<int>(scaleForColorX * displacementImage->item(dstIndex + displacementChannelX) + scaledOffsetX);
             int srcY = y + static_cast<int>(scaleForColorY * displacementImage->item(dstIndex + displacementChannelY) + scaledOffsetY);
 
-            unsigned* dstPixelPtr = reinterpret_cast<unsigned*>(dstPixelArray->data() + dstIndex);
+            unsigned* dstPixelPtr = reinterpret_cast<unsigned*>(dstPixelArray.data() + dstIndex);
             if (srcX < 0 || srcX >= paintSize.width() || srcY < 0 || srcY >= paintSize.height()) {
                 *dstPixelPtr = 0;
                 continue;

Modified: trunk/Source/WebCore/platform/graphics/filters/FEDropShadow.cpp (277236 => 277237)


--- trunk/Source/WebCore/platform/graphics/filters/FEDropShadow.cpp	2021-05-09 01:26:37 UTC (rev 277236)
+++ trunk/Source/WebCore/platform/graphics/filters/FEDropShadow.cpp	2021-05-09 01:29:38 UTC (rev 277237)
@@ -105,8 +105,8 @@
     if (!imageData)
         return;
 
-    auto* srcPixelArray = imageData->data();
-    contextShadow.blurLayerImage(srcPixelArray->data(), imageData->size(), 4 * imageData->size().width());
+    auto& srcPixelArray = imageData->data();
+    contextShadow.blurLayerImage(srcPixelArray.data(), imageData->size(), 4 * imageData->size().width());
     
     resultImage->putImageData(AlphaPremultiplication::Premultiplied, *imageData, shadowArea);
 

Modified: trunk/Source/WebCore/platform/graphics/filters/FEGaussianBlur.cpp (277236 => 277237)


--- trunk/Source/WebCore/platform/graphics/filters/FEGaussianBlur.cpp	2021-05-09 01:26:37 UTC (rev 277236)
+++ trunk/Source/WebCore/platform/graphics/filters/FEGaussianBlur.cpp	2021-05-09 01:29:38 UTC (rev 277237)
@@ -524,14 +524,15 @@
     FilterEffect* in = inputEffect(0);
 
     auto* resultImage = createPremultipliedImageResult();
-    auto* dstPixelArray = resultImage ? resultImage->data() : nullptr;
-    if (!dstPixelArray)
+    if (!resultImage)
         return;
 
+    auto& dstPixelArray = resultImage->data();
+
     setIsAlphaImage(in->isAlphaImage());
 
     IntRect effectDrawingRect = requestedRegionOfInputImageData(in->absolutePaintRect());
-    in->copyPremultipliedResult(*dstPixelArray, effectDrawingRect, operatingColorSpace());
+    in->copyPremultipliedResult(dstPixelArray, effectDrawingRect, operatingColorSpace());
     if (!m_stdX && !m_stdY)
         return;
 
@@ -544,7 +545,7 @@
     if (!tmpImageData)
         return;
 
-    platformApply(*dstPixelArray, *tmpImageData, kernelSize.width(), kernelSize.height(), paintSize);
+    platformApply(dstPixelArray, *tmpImageData, kernelSize.width(), kernelSize.height(), paintSize);
 }
 
 IntOutsets FEGaussianBlur::outsets() const

Modified: trunk/Source/WebCore/platform/graphics/filters/FELighting.cpp (277236 => 277237)


--- trunk/Source/WebCore/platform/graphics/filters/FELighting.cpp	2021-05-09 01:26:37 UTC (rev 277236)
+++ trunk/Source/WebCore/platform/graphics/filters/FELighting.cpp	2021-05-09 01:29:38 UTC (rev 277237)
@@ -476,14 +476,15 @@
     FilterEffect* in = inputEffect(0);
 
     auto* resultImage = createPremultipliedImageResult();
-    auto* resutPixelArray = resultImage ? resultImage->data() : nullptr;
-    if (!resutPixelArray)
+    if (!resultImage)
         return;
 
+    auto& resultPixelArray = resultImage->data();
+
     setIsAlphaImage(false);
 
     IntRect effectDrawingRect = requestedRegionOfInputImageData(in->absolutePaintRect());
-    in->copyPremultipliedResult(*resutPixelArray, effectDrawingRect, operatingColorSpace());
+    in->copyPremultipliedResult(resultPixelArray, effectDrawingRect, operatingColorSpace());
     // FIXME: support kernelUnitLengths other than (1,1). The issue here is that the W3
     // standard has no test case for them, and other browsers (like Firefox) has strange
     // output for various kernelUnitLengths, and I am not sure they are reliable.
@@ -490,7 +491,7 @@
     // Anyway, feConvolveMatrix should also use the implementation
 
     IntSize absolutePaintSize = absolutePaintRect().size();
-    drawLighting(*resutPixelArray, absolutePaintSize.width(), absolutePaintSize.height());
+    drawLighting(resultPixelArray, absolutePaintSize.width(), absolutePaintSize.height());
 }
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/platform/graphics/filters/FEMorphology.cpp (277236 => 277237)


--- trunk/Source/WebCore/platform/graphics/filters/FEMorphology.cpp	2021-05-09 01:26:37 UTC (rev 277236)
+++ trunk/Source/WebCore/platform/graphics/filters/FEMorphology.cpp	2021-05-09 01:29:38 UTC (rev 277237)
@@ -244,16 +244,17 @@
     FilterEffect* in = inputEffect(0);
 
     auto* resultImage = createPremultipliedImageResult();
-    auto* dstPixelArray = resultImage ? resultImage->data() : nullptr;
-    if (!dstPixelArray)
+    if (!resultImage)
         return;
 
+    auto& destinationPixelArray = resultImage->data();
+
     setIsAlphaImage(in->isAlphaImage());
 
     IntRect effectDrawingRect = requestedRegionOfInputImageData(in->absolutePaintRect());
 
     IntSize radius = flooredIntSize(FloatSize(m_radiusX, m_radiusY));
-    if (platformApplyDegenerate(*dstPixelArray, effectDrawingRect, radius.width(), radius.height()))
+    if (platformApplyDegenerate(destinationPixelArray, effectDrawingRect, radius.width(), radius.height()))
         return;
 
     Filter& filter = this->filter();
@@ -265,12 +266,12 @@
     int radiusX = std::min(effectDrawingRect.width() - 1, radius.width());
     int radiusY = std::min(effectDrawingRect.height() - 1, radius.height());
 
-    if (platformApplyDegenerate(*dstPixelArray, effectDrawingRect, radiusX, radiusY))
+    if (platformApplyDegenerate(destinationPixelArray, effectDrawingRect, radiusX, radiusY))
         return;
     
     PaintingData paintingData;
     paintingData.srcPixelArray = srcPixelArray.get();
-    paintingData.dstPixelArray = dstPixelArray;
+    paintingData.dstPixelArray = &destinationPixelArray;
     paintingData.width = ceilf(effectDrawingRect.width() * filter.filterScale());
     paintingData.height = ceilf(effectDrawingRect.height() * filter.filterScale());
     paintingData.radiusX = ceilf(radiusX * filter.filterScale());

Modified: trunk/Source/WebCore/platform/graphics/filters/FETurbulence.cpp (277236 => 277237)


--- trunk/Source/WebCore/platform/graphics/filters/FETurbulence.cpp	2021-05-09 01:26:37 UTC (rev 277236)
+++ trunk/Source/WebCore/platform/graphics/filters/FETurbulence.cpp	2021-05-09 01:29:38 UTC (rev 277237)
@@ -397,15 +397,16 @@
 void FETurbulence::platformApplySoftware()
 {
     auto* resultImage = createUnmultipliedImageResult();
-    auto* pixelArray = resultImage ? resultImage->data() : nullptr;
-    if (!pixelArray)
+    if (!resultImage)
         return;
 
+    auto& pixelArray = resultImage->data();
+
     IntSize resultSize(absolutePaintRect().size());
     resultSize.scale(filter().filterScale());
 
     if (resultSize.isEmpty()) {
-        pixelArray->zeroFill();
+        pixelArray.zeroFill();
         return;
     }
 
@@ -440,7 +441,7 @@
             for (unsigned i = 0; i < numJobs; ++i) {
                 FillRegionParameters& params = parallelJobs.parameter(i);
                 params.filter = this;
-                params.pixelArray = pixelArray;
+                params.pixelArray = &pixelArray;
                 params.paintingData = &paintingData;
                 params.stitchData = stitchData;
                 params.startY = startY;
@@ -456,7 +457,7 @@
     }
 
     // Fallback to single threaded mode if there is no room for a new thread or the paint area is too small.
-    fillRegion(*pixelArray, paintingData, stitchData, 0, height);
+    fillRegion(pixelArray, paintingData, stitchData, 0, height);
 }
 
 static TextStream& operator<<(TextStream& ts, TurbulenceType type)

Modified: trunk/Source/WebCore/platform/graphics/filters/FilterEffect.cpp (277236 => 277237)


--- trunk/Source/WebCore/platform/graphics/filters/FilterEffect.cpp	2021-05-09 01:26:37 UTC (rev 277236)
+++ trunk/Source/WebCore/platform/graphics/filters/FilterEffect.cpp	2021-05-09 01:29:38 UTC (rev 277237)
@@ -201,9 +201,9 @@
     if (!m_premultipliedImageResult)
         return;
 
-    Uint8ClampedArray* imageArray = m_premultipliedImageResult->data();
-    uint8_t* pixelData = imageArray->data();
-    int pixelArrayLength = imageArray->length();
+    auto& imageArray = m_premultipliedImageResult->data();
+    uint8_t* pixelData = imageArray.data();
+    int pixelArrayLength = imageArray.length();
 
     // We must have four bytes per pixel, and complete pixels
     ASSERT(!(pixelArrayLength % 4));
@@ -464,7 +464,7 @@
     auto convertedImageData = convertImageBufferToColorSpace(colorSpace, *m_imageBufferResult, { IntPoint(), m_absolutePaintRect.size() }, outputFormat);
     if (!convertedImageData)
         return;
-    copyImageBytes(*convertedImageData->data(), destination, destRect);
+    copyImageBytes(convertedImageData->data(), destination, destRect);
 }
 
 void FilterEffect::copyConvertedImageDataToDestination(Uint8ClampedArray& destination, ImageData& imageData, DestinationColorSpace colorSpace, AlphaPremultiplication outputFormat, const IntRect& destRect)
@@ -474,7 +474,7 @@
     auto convertedImageData = convertImageDataToColorSpace(colorSpace, imageData, outputFormat);
     if (!convertedImageData)
         return;
-    copyImageBytes(*convertedImageData->data(), destination, destRect);
+    copyImageBytes(convertedImageData->data(), destination, destRect);
 }
 
 void FilterEffect::copyUnmultipliedResult(Uint8ClampedArray& destination, const IntRect& rect, Optional<DestinationColorSpace> colorSpace)
@@ -500,7 +500,7 @@
             m_unmultipliedImageResult = ImageData::create(inputSize);
             if (!m_unmultipliedImageResult)
                 return;
-            copyUnpremultiplyingAlpha(*m_premultipliedImageResult->data(), *m_unmultipliedImageResult->data(), inputSize);
+            copyUnpremultiplyingAlpha(m_premultipliedImageResult->data(), m_unmultipliedImageResult->data(), inputSize);
         }
     }
     if (requiresImageDataColorSpaceConversion(colorSpace)) {
@@ -507,7 +507,7 @@
         copyConvertedImageDataToDestination(destination, *m_unmultipliedImageResult, *colorSpace, AlphaPremultiplication::Unpremultiplied, rect);
         return;
     }
-    copyImageBytes(*m_unmultipliedImageResult->data(), destination, rect);
+    copyImageBytes(m_unmultipliedImageResult->data(), destination, rect);
 }
 
 void FilterEffect::copyPremultipliedResult(Uint8ClampedArray& destination, const IntRect& rect, Optional<DestinationColorSpace> colorSpace)
@@ -533,7 +533,7 @@
             m_premultipliedImageResult = ImageData::create(inputSize);
             if (!m_premultipliedImageResult)
                 return;
-            copyPremultiplyingAlpha(*m_unmultipliedImageResult->data(), *m_premultipliedImageResult->data(), inputSize);
+            copyPremultiplyingAlpha(m_unmultipliedImageResult->data(), m_premultipliedImageResult->data(), inputSize);
         }
     }
 
@@ -541,7 +541,7 @@
         copyConvertedImageDataToDestination(destination, *m_premultipliedImageResult, *colorSpace, AlphaPremultiplication::Premultiplied, rect);
         return;
     }
-    copyImageBytes(*m_premultipliedImageResult->data(), destination, rect);
+    copyImageBytes(m_premultipliedImageResult->data(), destination, rect);
 }
 
 ImageBuffer* FilterEffect::createImageBufferResult()

Modified: trunk/Source/WebCore/platform/graphics/opengl/GraphicsContextGLOpenGLBase.cpp (277236 => 277237)


--- trunk/Source/WebCore/platform/graphics/opengl/GraphicsContextGLOpenGLBase.cpp	2021-05-09 01:26:37 UTC (rev 277236)
+++ trunk/Source/WebCore/platform/graphics/opengl/GraphicsContextGLOpenGLBase.cpp	2021-05-09 01:29:38 UTC (rev 277237)
@@ -76,7 +76,7 @@
         mustRestorePackAlignment = true;
     }
 
-    ::glReadPixels(0, 0, imageData->width(), imageData->height(), GL_RGBA, GL_UNSIGNED_BYTE, imageData->data()->data());
+    ::glReadPixels(0, 0, imageData->width(), imageData->height(), GL_RGBA, GL_UNSIGNED_BYTE, imageData->data().data());
 
     if (mustRestorePackAlignment)
         ::glPixelStorei(GL_PACK_ALIGNMENT, packAlignment);

Modified: trunk/Source/WebCore/platform/graphics/opengl/GraphicsContextGLOpenGLES.cpp (277236 => 277237)


--- trunk/Source/WebCore/platform/graphics/opengl/GraphicsContextGLOpenGLES.cpp	2021-05-09 01:26:37 UTC (rev 277236)
+++ trunk/Source/WebCore/platform/graphics/opengl/GraphicsContextGLOpenGLES.cpp	2021-05-09 01:29:38 UTC (rev 277237)
@@ -79,7 +79,7 @@
         mustRestorePackAlignment = true;
     }
 
-    ::glReadPixels(0, 0, imageData->width(), imageData->height(), GL_RGBA, GL_UNSIGNED_BYTE, imageData->data()->data());
+    ::glReadPixels(0, 0, imageData->width(), imageData->height(), GL_RGBA, GL_UNSIGNED_BYTE, imageData->data().data());
 
     if (mustRestorePackAlignment)
         ::glPixelStorei(GL_PACK_ALIGNMENT, packAlignment);

Modified: trunk/Source/WebCore/rendering/shapes/Shape.cpp (277236 => 277237)


--- trunk/Source/WebCore/rendering/shapes/Shape.cpp	2021-05-09 01:26:37 UTC (rev 277236)
+++ trunk/Source/WebCore/rendering/shapes/Shape.cpp	2021-05-09 01:29:38 UTC (rev 277237)
@@ -201,11 +201,11 @@
     
     // We could get to a value where imageData could be nullptr. A case where ImageRect.size() is huge, imageData::create
     // can return a nullptr because data size has overflowed. Refer rdar://problem/61793884
-    if (!imageData || !imageData->data())
+    if (!imageData)
         return createShape();
 
-    auto* pixelArray = imageData->data();
-    unsigned pixelArrayLength = pixelArray->length();
+    auto& pixelArray = imageData->data();
+    unsigned pixelArrayLength = pixelArray.length();
     unsigned pixelArrayOffset = 3; // Each pixel is four bytes: RGBA.
     uint8_t alphaPixelThreshold = static_cast<uint8_t>(lroundf(clampTo<float>(threshold, 0, 1) * 255.0f));
 
@@ -216,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 = pixelArray.item(pixelArrayOffset);
                 bool alphaAboveThreshold = alpha > alphaPixelThreshold;
                 if (startX == -1 && alphaAboveThreshold) {
                     startX = x;

Modified: trunk/Source/WebKit/ChangeLog (277236 => 277237)


--- trunk/Source/WebKit/ChangeLog	2021-05-09 01:26:37 UTC (rev 277236)
+++ trunk/Source/WebKit/ChangeLog	2021-05-09 01:29:38 UTC (rev 277237)
@@ -1,3 +1,18 @@
+2021-05-08  Sam Weinig  <wei...@apple.com>
+
+        Factor out pixel buffer from DOM specific ImageData class
+        https://bugs.webkit.org/show_bug.cgi?id=225554
+
+        Reviewed by Darin Adler.
+
+        Update for ImageData::data() returning a reference.
+
+        * GPUProcess/graphics/RemoteRenderingBackend.cpp:
+        (WebKit::RemoteRenderingBackend::populateGetImageDataSharedMemory):
+        * Shared/WebCoreArgumentCoders.cpp:
+        (IPC::ArgumentCoder<Ref<WebCore::ImageData>>::encode):
+        * WebProcess/GPU/graphics/RemoteImageBufferProxy.h:
+
 2021-05-08  Alex Christensen  <achristen...@webkit.org>
 
         REGRESSION (r276797?): [ macOS/iOS ] TestWebKitAPI.URLSchemeHandler.Exceptions is flakey crashing

Modified: trunk/Source/WebKit/GPUProcess/graphics/RemoteRenderingBackend.cpp (277236 => 277237)


--- trunk/Source/WebKit/GPUProcess/graphics/RemoteRenderingBackend.cpp	2021-05-09 01:26:37 UTC (rev 277236)
+++ trunk/Source/WebKit/GPUProcess/graphics/RemoteRenderingBackend.cpp	2021-05-09 01:29:38 UTC (rev 277237)
@@ -367,9 +367,9 @@
 {
     MESSAGE_CHECK(m_getImageDataSharedMemory, "We can't run getImageData without a buffer to write into");
 
-    if (imageData && imageData->data()) {
-        MESSAGE_CHECK(imageData->data()->byteLength() <= m_getImageDataSharedMemory->size(), "Shmem for return of getImageData is too small");
-        memcpy(m_getImageDataSharedMemory->data(), imageData->data()->data(), imageData->data()->byteLength());
+    if (imageData) {
+        MESSAGE_CHECK(imageData->data().byteLength() <= m_getImageDataSharedMemory->size(), "Shmem for return of getImageData is too small");
+        memcpy(m_getImageDataSharedMemory->data(), imageData->data().data(), imageData->data().byteLength());
     } else
         memset(m_getImageDataSharedMemory->data(), 0, m_getImageDataSharedMemory->size());
 

Modified: trunk/Source/WebKit/Shared/WebCoreArgumentCoders.cpp (277236 => 277237)


--- trunk/Source/WebKit/Shared/WebCoreArgumentCoders.cpp	2021-05-09 01:26:37 UTC (rev 277236)
+++ trunk/Source/WebKit/Shared/WebCoreArgumentCoders.cpp	2021-05-09 01:29:38 UTC (rev 277237)
@@ -3119,9 +3119,9 @@
 {
     encoder << imageData->size();
 
-    auto rawData = imageData->data();
-    encoder << static_cast<uint64_t>(rawData->byteLength());
-    encoder.encodeFixedLengthData(rawData->data(), rawData->byteLength(), 1);
+    auto& rawData = imageData->data();
+    encoder << static_cast<uint64_t>(rawData.byteLength());
+    encoder.encodeFixedLengthData(rawData.data(), rawData.byteLength(), 1);
 }
 
 template

Modified: trunk/Source/WebKit/WebProcess/GPU/graphics/RemoteImageBufferProxy.h (277236 => 277237)


--- trunk/Source/WebKit/WebProcess/GPU/graphics/RemoteImageBufferProxy.h	2021-05-09 01:26:37 UTC (rev 277236)
+++ trunk/Source/WebKit/WebProcess/GPU/graphics/RemoteImageBufferProxy.h	2021-05-09 01:29:38 UTC (rev 277237)
@@ -200,9 +200,9 @@
             return nullptr;
 
         auto imageData = WebCore::ImageData::create(srcRect.size());
-        if (!imageData || !imageData->data())
+        if (!imageData)
             return nullptr;
-        size_t dataSize = imageData->data()->byteLength();
+        size_t dataSize = imageData->data().byteLength();
 
         IPC::Timeout timeout = 5_s;
         SharedMemory* sharedMemory = m_remoteRenderingBackendProxy->sharedMemoryForGetImageData(dataSize, timeout);
@@ -214,9 +214,9 @@
         mutableThis.flushDrawingContextAsync();
 
         if (m_remoteRenderingBackendProxy->waitForGetImageDataToComplete(timeout))
-            memcpy(imageData->data()->data(), sharedMemory->data(), dataSize);
+            memcpy(imageData->data().data(), sharedMemory->data(), dataSize);
         else
-            memset(imageData->data()->data(), 0, dataSize);
+            memset(imageData->data().data(), 0, dataSize);
         return imageData;
     }
 

Modified: trunk/Source/WebKit/WebProcess/GPU/graphics/RemoteRenderingBackendProxy.cpp (277236 => 277237)


--- trunk/Source/WebKit/WebProcess/GPU/graphics/RemoteRenderingBackendProxy.cpp	2021-05-09 01:26:37 UTC (rev 277236)
+++ trunk/Source/WebKit/WebProcess/GPU/graphics/RemoteRenderingBackendProxy.cpp	2021-05-09 01:29:38 UTC (rev 277237)
@@ -37,6 +37,7 @@
 #include "WebCoreArgumentCoders.h"
 #include "WebPage.h"
 #include "WebProcess.h"
+#include <_javascript_Core/TypedArrayInlines.h>
 
 namespace WebKit {
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to