Change ImageData to reference Uint8ClampedArray rather than CanvasPixelArray
authorkbr@google.com <kbr@google.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 24 Apr 2012 03:43:31 +0000 (03:43 +0000)
committerkbr@google.com <kbr@google.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 24 Apr 2012 03:43:31 +0000 (03:43 +0000)
https://bugs.webkit.org/show_bug.cgi?id=73011

Reviewed by Oliver Hunt.

Source/WebCore:

Changed ImageData to contain Uint8ClampedArray instead of ByteArray
per current HTML5 spec.

In order to avoid introducing large data copies, it was necessary to
switch a few other places in WebKit to use Uint8ClampedArray at the
same time, most notably the FilterEffect implementation, portions of
ImageBuffer, and a couple of places in the image encoders.

Note that the change in method name from "get" to "item" occurred
because JSC's autogenerated indexed getters reference a method
called "item". If desired, a convenience method could be
introduced to avoid the renamings in the FilterEffect classes.

With these changes, ByteArray and some custom code in JavaScriptCore
actually become unreferenced, and can be deleted. This deletion will
be done separately in Bug 83655, to keep the size of this patch
manageable.

Test: fast/canvas/imagedata-contains-uint8clampedarray.html

* bindings/js/JSImageDataCustom.cpp:
(WebCore::toJS):
* bindings/js/SerializedScriptValue.cpp:
(WebCore::CloneSerializer::dumpIfTerminal):
(WebCore::CloneDeserializer::readTerminal):
* bindings/v8/SerializedScriptValue.cpp:
* bindings/v8/custom/V8ImageDataCustom.cpp:
(WebCore::toV8):
* bridge/qt/qt_pixmapruntime.cpp:
(JSC::Bindings::QtPixmapToImageDataMethod::invoke):
* html/ImageData.cpp:
(WebCore::ImageData::create):
(WebCore::ImageData::ImageData):
* html/ImageData.h:
(ImageData):
(WebCore::ImageData::data):
* html/ImageData.idl:
* html/canvas/CanvasRenderingContext2D.cpp:
(WebCore::createEmptyImageData):
(WebCore::CanvasRenderingContext2D::getImageData):
(WebCore::CanvasRenderingContext2D::putImageData):
* platform/graphics/GraphicsContext3D.cpp:
(WebCore::GraphicsContext3D::extractImageData):
* platform/graphics/ImageBuffer.cpp:
(WebCore::ImageBuffer::genericConvertToLuminanceMask):
* platform/graphics/ImageBuffer.h:
* platform/graphics/ShadowBlur.cpp:
(WebCore::ShadowBlur::blurShadowBuffer):
* platform/graphics/cairo/ImageBufferCairo.cpp:
(WebCore::getImageData):
(WebCore::ImageBuffer::getUnmultipliedImageData):
(WebCore::ImageBuffer::getPremultipliedImageData):
(WebCore::ImageBuffer::putByteArray):
* platform/graphics/cg/ImageBufferCG.cpp:
(WebCore::ImageBuffer::getUnmultipliedImageData):
(WebCore::ImageBuffer::getPremultipliedImageData):
(WebCore::ImageBuffer::putByteArray):
(WebCore::ImageBuffer::toDataURL):
(WebCore::ImageDataToDataURL):
* platform/graphics/cg/ImageBufferDataCG.cpp:
(WebCore::ImageBufferData::getData):
(WebCore::ImageBufferData::putData):
* platform/graphics/cg/ImageBufferDataCG.h:
(ImageBufferData):
* platform/graphics/filters/FEBlend.cpp:
(WebCore::FEBlend::platformApplySoftware):
* platform/graphics/filters/FEColorMatrix.cpp:
(WebCore::effectType):
(WebCore::FEColorMatrix::platformApplySoftware):
* platform/graphics/filters/FEComponentTransfer.cpp:
(WebCore::FEComponentTransfer::platformApplySoftware):
* platform/graphics/filters/FEComposite.cpp:
(WebCore::FEComposite::platformArithmeticSoftware):
(WebCore::FEComposite::platformApplySoftware):
* platform/graphics/filters/FEComposite.h:
* platform/graphics/filters/FEConvolveMatrix.cpp:
(WebCore::setDestinationPixels):
(WebCore::FEConvolveMatrix::fastSetInteriorPixels):
(WebCore::FEConvolveMatrix::fastSetOuterPixels):
(WebCore::FEConvolveMatrix::platformApplySoftware):
* platform/graphics/filters/FEConvolveMatrix.h:
(PaintingData):
* platform/graphics/filters/FECustomFilter.cpp:
(WebCore::FECustomFilter::platformApplySoftware):
(WebCore::FECustomFilter::bindProgramAndBuffers):
* platform/graphics/filters/FECustomFilter.h:
(JSC):
(FECustomFilter):
* platform/graphics/filters/FEDisplacementMap.cpp:
(WebCore::FEDisplacementMap::platformApplySoftware):
* platform/graphics/filters/FEDropShadow.cpp:
(WebCore::FEDropShadow::platformApplySoftware):
* platform/graphics/filters/FEGaussianBlur.cpp:
(WebCore::boxBlur):
(WebCore::FEGaussianBlur::platformApplyGeneric):
(WebCore::FEGaussianBlur::platformApply):
(WebCore::FEGaussianBlur::platformApplySoftware):
* platform/graphics/filters/FEGaussianBlur.h:
(PlatformApplyParameters):
(FEGaussianBlur):
* platform/graphics/filters/FELighting.cpp:
(WebCore::FELighting::LightingData::topLeft):
(WebCore::FELighting::LightingData::topRow):
(WebCore::FELighting::LightingData::topRight):
(WebCore::FELighting::LightingData::leftColumn):
(WebCore::FELighting::LightingData::interior):
(WebCore::FELighting::LightingData::rightColumn):
(WebCore::FELighting::LightingData::bottomLeft):
(WebCore::FELighting::LightingData::bottomRow):
(WebCore::FELighting::LightingData::bottomRight):
(WebCore::FELighting::inlineSetPixel):
(WebCore::FELighting::drawLighting):
(WebCore::FELighting::platformApplySoftware):
* platform/graphics/filters/FELighting.h:
(LightingData):
(FELighting):
* platform/graphics/filters/FEMorphology.cpp:
(WebCore::FEMorphology::platformApplyGeneric):
(WebCore::FEMorphology::platformApplySoftware):
* platform/graphics/filters/FEMorphology.h:
(PaintingData):
* platform/graphics/filters/FETurbulence.cpp:
(WebCore::FETurbulence::fillRegion):
(WebCore::FETurbulence::platformApplySoftware):
* platform/graphics/filters/FETurbulence.h:
(FillRegionParameters):
(FETurbulence):
* platform/graphics/filters/FilterEffect.cpp:
(WebCore::FilterEffect::forceValidPreMultipliedPixels):
(WebCore::FilterEffect::asUnmultipliedImage):
(WebCore::FilterEffect::asPremultipliedImage):
(WebCore::FilterEffect::copyImageBytes):
(WebCore::FilterEffect::copyUnmultipliedImage):
(WebCore::FilterEffect::copyPremultipliedImage):
(WebCore::FilterEffect::createUnmultipliedImageResult):
(WebCore::FilterEffect::createPremultipliedImageResult):
* platform/graphics/filters/FilterEffect.h:
(FilterEffect):
* platform/graphics/filters/arm/FEGaussianBlurNEON.h:
(WebCore::FEGaussianBlur::platformApplyNeon):
* platform/graphics/opengl/GraphicsContext3DOpenGLCommon.cpp:
(WebCore::GraphicsContext3D::paintRenderingResultsToImageData):
* platform/graphics/qt/ImageBufferQt.cpp:
(WebCore::getImageData):
(WebCore::ImageBuffer::getUnmultipliedImageData):
(WebCore::ImageBuffer::getPremultipliedImageData):
(WebCore::ImageBuffer::putByteArray):
* platform/graphics/skia/ImageBufferSkia.cpp:
(WebCore::getImageData):
(WebCore::ImageBuffer::getUnmultipliedImageData):
(WebCore::ImageBuffer::getPremultipliedImageData):
(WebCore::ImageBuffer::putByteArray):
* platform/graphics/texmap/TextureMapperGL.cpp:
* platform/graphics/wince/ImageBufferWinCE.cpp:
(WebCore::getImageData):
(WebCore::ImageBuffer::getUnmultipliedImageData):
(WebCore::ImageBuffer::getPremultipliedImageData):
(WebCore::ImageBuffer::putByteArray):
* platform/graphics/wx/ImageBufferWx.cpp:
(WebCore::ImageBuffer::getUnmultipliedImageData):
(WebCore::ImageBuffer::getPremultipliedImageData):
(WebCore::ImageBuffer::putByteArray):
* platform/image-encoders/skia/JPEGImageEncoder.cpp:
(WebCore::JPEGImageEncoder::encode):
* platform/image-encoders/skia/PNGImageEncoder.cpp:
(WebCore::PNGImageEncoder::encode):
* platform/image-encoders/skia/WEBPImageEncoder.cpp:
(WebCore::WEBPImageEncoder::encode):

Source/WebKit/chromium:

* src/GraphicsContext3DChromium.cpp:
(WebCore::GraphicsContext3DPrivate::paintRenderingResultsToImageData):
* src/WebViewImpl.cpp:
(WebKit::WebViewImpl::doPixelReadbackToCanvas):

Source/WTF:

* wtf/ArrayBuffer.h:
(ArrayBuffer):
(WTF::ArrayBuffer::create):
(WTF::ArrayBuffer::createUninitialized):
(WTF):
(WTF::ArrayBufferContents::tryAllocate):
* wtf/TypedArrayBase.h:
(WTF::TypedArrayBase::createUninitialized):
(TypedArrayBase):
* wtf/Uint8ClampedArray.h:
(Uint8ClampedArray):
(WTF::Uint8ClampedArray::createUninitialized):
(WTF):
(WTF::Uint8ClampedArray::zeroFill):

LayoutTests:

* fast/canvas/imagedata-contains-uint8clampedarray-expected.txt: Added.
* fast/canvas/imagedata-contains-uint8clampedarray.html: Added.
* fast/dom/Window/script-tests/postmessage-clone.js:
* fast/dom/Window/window-postmessage-clone-expected.txt:
* platform/chromium/fast/dom/Window/window-postmessage-clone-expected.txt:
* platform/gtk/fast/dom/Window/window-postmessage-clone-expected.txt:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@114992 268f45cc-cd09-0410-ab3c-d52691b4dbfc

63 files changed:
LayoutTests/ChangeLog
LayoutTests/fast/canvas/imagedata-contains-uint8clampedarray-expected.txt [new file with mode: 0644]
LayoutTests/fast/canvas/imagedata-contains-uint8clampedarray.html [new file with mode: 0644]
LayoutTests/fast/dom/Window/script-tests/postmessage-clone.js
LayoutTests/fast/dom/Window/window-postmessage-clone-expected.txt
LayoutTests/platform/chromium/fast/dom/Window/window-postmessage-clone-expected.txt
LayoutTests/platform/gtk/fast/dom/Window/window-postmessage-clone-expected.txt
Source/WTF/ChangeLog
Source/WTF/wtf/ArrayBuffer.h
Source/WTF/wtf/TypedArrayBase.h
Source/WTF/wtf/Uint8ClampedArray.h
Source/WebCore/ChangeLog
Source/WebCore/bindings/js/JSImageDataCustom.cpp
Source/WebCore/bindings/js/SerializedScriptValue.cpp
Source/WebCore/bindings/v8/SerializedScriptValue.cpp
Source/WebCore/bindings/v8/custom/V8ImageDataCustom.cpp
Source/WebCore/bridge/qt/qt_pixmapruntime.cpp
Source/WebCore/html/ImageData.cpp
Source/WebCore/html/ImageData.h
Source/WebCore/html/ImageData.idl
Source/WebCore/html/canvas/CanvasRenderingContext2D.cpp
Source/WebCore/platform/graphics/GraphicsContext3D.cpp
Source/WebCore/platform/graphics/ImageBuffer.cpp
Source/WebCore/platform/graphics/ImageBuffer.h
Source/WebCore/platform/graphics/ShadowBlur.cpp
Source/WebCore/platform/graphics/cairo/ImageBufferCairo.cpp
Source/WebCore/platform/graphics/cg/ImageBufferCG.cpp
Source/WebCore/platform/graphics/cg/ImageBufferDataCG.cpp
Source/WebCore/platform/graphics/cg/ImageBufferDataCG.h
Source/WebCore/platform/graphics/filters/FEBlend.cpp
Source/WebCore/platform/graphics/filters/FEColorMatrix.cpp
Source/WebCore/platform/graphics/filters/FEComponentTransfer.cpp
Source/WebCore/platform/graphics/filters/FEComposite.cpp
Source/WebCore/platform/graphics/filters/FEComposite.h
Source/WebCore/platform/graphics/filters/FEConvolveMatrix.cpp
Source/WebCore/platform/graphics/filters/FEConvolveMatrix.h
Source/WebCore/platform/graphics/filters/FECustomFilter.cpp
Source/WebCore/platform/graphics/filters/FECustomFilter.h
Source/WebCore/platform/graphics/filters/FEDisplacementMap.cpp
Source/WebCore/platform/graphics/filters/FEDropShadow.cpp
Source/WebCore/platform/graphics/filters/FEGaussianBlur.cpp
Source/WebCore/platform/graphics/filters/FEGaussianBlur.h
Source/WebCore/platform/graphics/filters/FELighting.cpp
Source/WebCore/platform/graphics/filters/FELighting.h
Source/WebCore/platform/graphics/filters/FEMorphology.cpp
Source/WebCore/platform/graphics/filters/FEMorphology.h
Source/WebCore/platform/graphics/filters/FETurbulence.cpp
Source/WebCore/platform/graphics/filters/FETurbulence.h
Source/WebCore/platform/graphics/filters/FilterEffect.cpp
Source/WebCore/platform/graphics/filters/FilterEffect.h
Source/WebCore/platform/graphics/filters/arm/FEGaussianBlurNEON.h
Source/WebCore/platform/graphics/opengl/GraphicsContext3DOpenGLCommon.cpp
Source/WebCore/platform/graphics/qt/ImageBufferQt.cpp
Source/WebCore/platform/graphics/skia/ImageBufferSkia.cpp
Source/WebCore/platform/graphics/texmap/TextureMapperGL.cpp
Source/WebCore/platform/graphics/wince/ImageBufferWinCE.cpp
Source/WebCore/platform/graphics/wx/ImageBufferWx.cpp
Source/WebCore/platform/image-encoders/skia/JPEGImageEncoder.cpp
Source/WebCore/platform/image-encoders/skia/PNGImageEncoder.cpp
Source/WebCore/platform/image-encoders/skia/WEBPImageEncoder.cpp
Source/WebKit/chromium/ChangeLog
Source/WebKit/chromium/src/GraphicsContext3DChromium.cpp
Source/WebKit/chromium/src/WebViewImpl.cpp

index 31fc034..6ee8dfc 100644 (file)
@@ -1,3 +1,17 @@
+2012-04-23  Kenneth Russell  <kbr@google.com>
+
+        Change ImageData to reference Uint8ClampedArray rather than CanvasPixelArray
+        https://bugs.webkit.org/show_bug.cgi?id=73011
+
+        Reviewed by Oliver Hunt.
+
+        * fast/canvas/imagedata-contains-uint8clampedarray-expected.txt: Added.
+        * fast/canvas/imagedata-contains-uint8clampedarray.html: Added.
+        * fast/dom/Window/script-tests/postmessage-clone.js:
+        * fast/dom/Window/window-postmessage-clone-expected.txt:
+        * platform/chromium/fast/dom/Window/window-postmessage-clone-expected.txt:
+        * platform/gtk/fast/dom/Window/window-postmessage-clone-expected.txt:
+
 2012-04-23  Kent Tamura  <tkent@chromium.org>
 
         Unreviewed, fix wrong paths of js-test-*.js.
diff --git a/LayoutTests/fast/canvas/imagedata-contains-uint8clampedarray-expected.txt b/LayoutTests/fast/canvas/imagedata-contains-uint8clampedarray-expected.txt
new file mode 100644 (file)
index 0000000..7093c38
--- /dev/null
@@ -0,0 +1,10 @@
+Tests that ImageData contains a Uint8ClampedArray.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS imageData.data.constructor is Uint8ClampedArray
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/fast/canvas/imagedata-contains-uint8clampedarray.html b/LayoutTests/fast/canvas/imagedata-contains-uint8clampedarray.html
new file mode 100644 (file)
index 0000000..4700ae0
--- /dev/null
@@ -0,0 +1,20 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src="../js/resources/js-test-pre.js"></script>
+</head>
+<body>
+<script>
+description("Tests that ImageData contains a Uint8ClampedArray.");
+
+var canvas = document.createElement("canvas");
+canvas.width = 10;
+canvas.height = 10;
+var context = canvas.getContext("2d");
+
+var imageData = context.getImageData(0, 0, 1, 1);
+shouldBe('imageData.data.constructor', 'Uint8ClampedArray');
+</script>
+<script src="../js/resources/js-test-post.js"></script>
+</body>
+</html>
index 4439254..59d24b4 100644 (file)
@@ -59,9 +59,9 @@ var mutatedImageData = document.createElement("canvas").getContext("2d").createI
 for (var i = 0; i < imageData.data.length * 4; i++)
     mutatedImageData.data[i] = i % 256;
 tryPostMessage('imageData', false, imageData);
-tryPostMessage('imageData.data', true, null, DOMException.DATA_CLONE_ERR)
+tryPostMessage('imageData.data', false, imageData.data)
 tryPostMessage('mutatedImageData', false, imageData);
-tryPostMessage('mutatedImageData.data', true, null, DOMException.DATA_CLONE_ERR)
+tryPostMessage('mutatedImageData.data', false, imageData.data)
 for (var i = 0; i < imageData.data.length * 4; i++)
     mutatedImageData.data[i] = 0;
 
index 4aad7cf..adb7aed 100644 (file)
@@ -6,8 +6,6 @@ FAIL: 'postMessage((function(){}))' should throw but didn't
 FAIL: 'postMessage(var x = 0; try { eval("badref"); } catch(e) { x = e; } x)' should throw but didn't
 PASS: 'postMessage(window)' threw TypeError: Type error
 PASS: 'postMessage(({get a() { throw "x" }}))' threw x
-FAIL: 'postMessage(imageData.data)' should throw but didn't
-FAIL: 'postMessage(mutatedImageData.data)' should throw but didn't
 PASS: 'postMessage((function() {return {get a() { throw "accessor-exn"; }};})())' threw accessor-exn
 PASS: 'postMessage((function() {var obja = {get p() { throw "accessor-exn"; }}; return {get a() { return obja; }};})())' threw accessor-exn
 PASS: lastIndex initially correct: was 3
@@ -44,7 +42,9 @@ PASS: eventData is === to eventData[0]
 PASS: eventData.graph1 is === to eventData.graph2
 PASS: eventData[0] is === to eventData[1]
 PASS: eventData is [object ImageData] of type object
+PASS: eventData is [object Uint8ClampedArray] of type object
 PASS: eventData is [object ImageData] of type object
+PASS: eventData is [object Uint8ClampedArray] of type object
 PASS: eventData is 42 of type number
 PASS: eventData is 42 of type number
 PASS: evalThunk OK
index 716dd6d..f67faea 100644 (file)
@@ -4,8 +4,6 @@ PASS: 'postMessage((function(){}))' threw Error: DATA_CLONE_ERR: DOM Exception 2
 PASS: 'postMessage(var x = 0; try { eval("badref"); } catch(e) { x = e; } x)' threw Error: DATA_CLONE_ERR: DOM Exception 25
 PASS: 'postMessage(window)' threw Error: DATA_CLONE_ERR: DOM Exception 25
 PASS: 'postMessage(({get a() { throw "x" }}))' threw x
-PASS: 'postMessage(imageData.data)' threw Error: DATA_CLONE_ERR: DOM Exception 25
-PASS: 'postMessage(mutatedImageData.data)' threw Error: DATA_CLONE_ERR: DOM Exception 25
 PASS: 'postMessage((function() {return {get a() { throw "accessor-exn"; }};})())' threw accessor-exn
 PASS: 'postMessage((function() {var obja = {get p() { throw "accessor-exn"; }}; return {get a() { return obja; }};})())' threw accessor-exn
 PASS: lastIndex initially correct: was 3
@@ -40,7 +38,9 @@ PASS: eventData is === to eventData[0]
 PASS: eventData.graph1 is === to eventData.graph2
 PASS: eventData[0] is === to eventData[1]
 PASS: eventData is [object ImageData] of type object
+PASS: eventData is [object Uint8ClampedArray] of type object
 PASS: eventData is [object ImageData] of type object
+PASS: eventData is [object Uint8ClampedArray] of type object
 PASS: eventData is 42 of type number
 PASS: eventData is 42 of type number
 PASS: evalThunk OK
index 1dc1525..11a2440 100644 (file)
@@ -37,14 +37,14 @@ PASS: eventData is === to eventData.self
 PASS: eventData is === to eventData[0]
 PASS: eventData.graph1 is === to eventData.graph2
 PASS: eventData[0] is === to eventData[1]
-FAIL: 'postMessage(imageData.data)' should throw but didn't
-FAIL: 'postMessage(mutatedImageData.data)' should throw but didn't
 PASS: 'postMessage((function() {return {get a() { throw "accessor-exn"; }};})())' threw accessor-exn
 PASS: 'postMessage((function() {var obja = {get p() { throw "accessor-exn"; }}; return {get a() { return obja; }};})())' threw accessor-exn
 PASS: lastIndex initially correct: was 3
 PASS: sanity on file reference equality
 PASS: eventData is [object ImageData] of type object
+PASS: eventData is [object Uint8ClampedArray] of type object
 PASS: eventData is [object ImageData] of type object
+PASS: eventData is [object Uint8ClampedArray] of type object
 PASS: eventData is 42 of type number
 PASS: eventData is 42 of type number
 PASS: evalThunk OK
index 9b05e83..ab6bd14 100644 (file)
@@ -1,3 +1,25 @@
+2012-04-23  Kenneth Russell  <kbr@google.com>
+
+        Change ImageData to reference Uint8ClampedArray rather than CanvasPixelArray
+        https://bugs.webkit.org/show_bug.cgi?id=73011
+
+        Reviewed by Oliver Hunt.
+
+        * wtf/ArrayBuffer.h:
+        (ArrayBuffer):
+        (WTF::ArrayBuffer::create):
+        (WTF::ArrayBuffer::createUninitialized):
+        (WTF):
+        (WTF::ArrayBufferContents::tryAllocate):
+        * wtf/TypedArrayBase.h:
+        (WTF::TypedArrayBase::createUninitialized):
+        (TypedArrayBase):
+        * wtf/Uint8ClampedArray.h:
+        (Uint8ClampedArray):
+        (WTF::Uint8ClampedArray::createUninitialized):
+        (WTF):
+        (WTF::Uint8ClampedArray::zeroFill):
+
 2012-04-23  George Staikos  <staikos@webkit.org>
 
         Enable parallel GC for BlackBerry.
index 3257df3..d2c7249 100644 (file)
@@ -57,7 +57,12 @@ private:
 
     friend class ArrayBuffer;
 
-    static inline void tryAllocate(unsigned numElements, unsigned elementByteSize, ArrayBufferContents&);
+    enum InitializationPolicy {
+        ZeroInitialize,
+        DontInitialize
+    };
+
+    static inline void tryAllocate(unsigned numElements, unsigned elementByteSize, InitializationPolicy, ArrayBufferContents&);
     void transfer(ArrayBufferContents& other)
     {
         ASSERT(!other.m_data);
@@ -78,6 +83,9 @@ public:
     static inline PassRefPtr<ArrayBuffer> create(const void* source, unsigned byteLength);
     static inline PassRefPtr<ArrayBuffer> create(ArrayBufferContents&);
 
+    // Only for use by Uint8ClampedArray::createUninitialized.
+    static inline PassRefPtr<ArrayBuffer> createUninitialized(unsigned numElements, unsigned elementByteSize);
+
     inline void* data();
     inline const void* data() const;
     inline unsigned byteLength() const;
@@ -94,6 +102,8 @@ public:
     ~ArrayBuffer() { }
 
 private:
+    static inline PassRefPtr<ArrayBuffer> create(unsigned numElements, unsigned elementByteSize, ArrayBufferContents::InitializationPolicy);
+
     inline ArrayBuffer(ArrayBufferContents&);
     inline PassRefPtr<ArrayBuffer> sliceImpl(unsigned begin, unsigned end) const;
     inline unsigned clampIndex(int index) const;
@@ -115,11 +125,7 @@ int ArrayBuffer::clampValue(int x, int left, int right)
 
 PassRefPtr<ArrayBuffer> ArrayBuffer::create(unsigned numElements, unsigned elementByteSize)
 {
-    ArrayBufferContents contents;
-    ArrayBufferContents::tryAllocate(numElements, elementByteSize, contents);
-    if (!contents.m_data)
-        return 0;
-    return adoptRef(new ArrayBuffer(contents));
+    return create(numElements, elementByteSize, ArrayBufferContents::ZeroInitialize);
 }
 
 PassRefPtr<ArrayBuffer> ArrayBuffer::create(ArrayBuffer* other)
@@ -130,7 +136,7 @@ PassRefPtr<ArrayBuffer> ArrayBuffer::create(ArrayBuffer* other)
 PassRefPtr<ArrayBuffer> ArrayBuffer::create(const void* source, unsigned byteLength)
 {
     ArrayBufferContents contents;
-    ArrayBufferContents::tryAllocate(byteLength, 1, contents);
+    ArrayBufferContents::tryAllocate(byteLength, 1, ArrayBufferContents::ZeroInitialize, contents);
     if (!contents.m_data)
         return 0;
     RefPtr<ArrayBuffer> buffer = adoptRef(new ArrayBuffer(contents));
@@ -143,6 +149,20 @@ PassRefPtr<ArrayBuffer> ArrayBuffer::create(ArrayBufferContents& contents)
     return adoptRef(new ArrayBuffer(contents));
 }
 
+PassRefPtr<ArrayBuffer> ArrayBuffer::createUninitialized(unsigned numElements, unsigned elementByteSize)
+{
+    return create(numElements, elementByteSize, ArrayBufferContents::DontInitialize);
+}
+
+PassRefPtr<ArrayBuffer> ArrayBuffer::create(unsigned numElements, unsigned elementByteSize, ArrayBufferContents::InitializationPolicy policy)
+{
+    ArrayBufferContents contents;
+    ArrayBufferContents::tryAllocate(numElements, elementByteSize, policy, contents);
+    if (!contents.m_data)
+        return 0;
+    return adoptRef(new ArrayBuffer(contents));
+}
+
 ArrayBuffer::ArrayBuffer(ArrayBufferContents& contents)
     : m_firstView(0)
 {
@@ -188,7 +208,7 @@ unsigned ArrayBuffer::clampIndex(int index) const
     return clampValue(index, 0, currentLength);
 }
 
-void ArrayBufferContents::tryAllocate(unsigned numElements, unsigned elementByteSize, ArrayBufferContents& result)
+void ArrayBufferContents::tryAllocate(unsigned numElements, unsigned elementByteSize, ArrayBufferContents::InitializationPolicy policy, ArrayBufferContents& result)
 {
     // Do not allow 32-bit overflow of the total size.
     // FIXME: Why not? The tryFastCalloc function already checks its arguments,
@@ -201,7 +221,15 @@ void ArrayBufferContents::tryAllocate(unsigned numElements, unsigned elementByte
             return;
         }
     }
-    if (WTF::tryFastCalloc(numElements, elementByteSize).getValue(result.m_data)) {
+    bool allocationSucceeded = false;
+    if (policy == ZeroInitialize)
+        allocationSucceeded = WTF::tryFastCalloc(numElements, elementByteSize).getValue(result.m_data);
+    else {
+        ASSERT(policy == DontInitialize);
+        allocationSucceeded = WTF::tryFastMalloc(numElements * elementByteSize).getValue(result.m_data);
+    }
+
+    if (allocationSucceeded) {
         result.m_sizeInBytes = numElements * elementByteSize;
         return;
     }
index 7f98919..5ec7a19 100644 (file)
@@ -104,6 +104,15 @@ protected:
     }
 
     template <class Subclass>
+    static PassRefPtr<Subclass> createUninitialized(unsigned length)
+    {
+        RefPtr<ArrayBuffer> buffer = ArrayBuffer::createUninitialized(length, sizeof(T));
+        if (!buffer.get())
+            return 0;
+        return create<Subclass>(buffer, 0, length);
+    }
+
+    template <class Subclass>
     PassRefPtr<Subclass> subarrayImpl(int start, int end) const
     {
         unsigned offset, length;
index 718b260..d9f8249 100644 (file)
@@ -38,6 +38,16 @@ public:
     static inline PassRefPtr<Uint8ClampedArray> create(const unsigned char* array, unsigned length);
     static inline PassRefPtr<Uint8ClampedArray> create(PassRefPtr<ArrayBuffer>, unsigned byteOffset, unsigned length);
 
+    // Should only be used for WebCore-internal use (like filters and
+    // getImageData) when it is known the entire array will be filled.
+    // Do not return these results directly to JavaScript.
+    static inline PassRefPtr<Uint8ClampedArray> createUninitialized(unsigned length);
+
+    // It's only needed to potentially call this method if the array
+    // was created uninitialized -- the default initialization paths
+    // zero the allocated memory.
+    inline void zeroFill();
+
     // Can’t use "using" here due to a bug in the RVCT compiler.
     bool set(TypedArrayBase<unsigned char>* array, unsigned offset) { return TypedArrayBase<unsigned char>::set(array, offset); }
     inline void set(unsigned index, double value);
@@ -71,6 +81,16 @@ PassRefPtr<Uint8ClampedArray> Uint8ClampedArray::create(PassRefPtr<ArrayBuffer>
     return TypedArrayBase<unsigned char>::create<Uint8ClampedArray>(buffer, byteOffset, length);
 }
 
+PassRefPtr<Uint8ClampedArray> Uint8ClampedArray::createUninitialized(unsigned length)
+{
+    return TypedArrayBase<unsigned char>::createUninitialized<Uint8ClampedArray>(length);
+}
+
+void Uint8ClampedArray::zeroFill()
+{
+    zeroRange(0, length());
+}
+
 void Uint8ClampedArray::set(unsigned index, double value)
 {
     if (index >= m_length)
index affd9c9..38fe6a0 100644 (file)
@@ -1,3 +1,179 @@
+2012-04-23  Kenneth Russell  <kbr@google.com>
+
+        Change ImageData to reference Uint8ClampedArray rather than CanvasPixelArray
+        https://bugs.webkit.org/show_bug.cgi?id=73011
+
+        Reviewed by Oliver Hunt.
+
+        Changed ImageData to contain Uint8ClampedArray instead of ByteArray
+        per current HTML5 spec.
+
+        In order to avoid introducing large data copies, it was necessary to
+        switch a few other places in WebKit to use Uint8ClampedArray at the
+        same time, most notably the FilterEffect implementation, portions of
+        ImageBuffer, and a couple of places in the image encoders.
+
+        Note that the change in method name from "get" to "item" occurred
+        because JSC's autogenerated indexed getters reference a method
+        called "item". If desired, a convenience method could be
+        introduced to avoid the renamings in the FilterEffect classes.
+
+        With these changes, ByteArray and some custom code in JavaScriptCore
+        actually become unreferenced, and can be deleted. This deletion will
+        be done separately in Bug 83655, to keep the size of this patch
+        manageable.
+
+        Test: fast/canvas/imagedata-contains-uint8clampedarray.html
+
+        * bindings/js/JSImageDataCustom.cpp:
+        (WebCore::toJS):
+        * bindings/js/SerializedScriptValue.cpp:
+        (WebCore::CloneSerializer::dumpIfTerminal):
+        (WebCore::CloneDeserializer::readTerminal):
+        * bindings/v8/SerializedScriptValue.cpp:
+        * bindings/v8/custom/V8ImageDataCustom.cpp:
+        (WebCore::toV8):
+        * bridge/qt/qt_pixmapruntime.cpp:
+        (JSC::Bindings::QtPixmapToImageDataMethod::invoke):
+        * html/ImageData.cpp:
+        (WebCore::ImageData::create):
+        (WebCore::ImageData::ImageData):
+        * html/ImageData.h:
+        (ImageData):
+        (WebCore::ImageData::data):
+        * html/ImageData.idl:
+        * html/canvas/CanvasRenderingContext2D.cpp:
+        (WebCore::createEmptyImageData):
+        (WebCore::CanvasRenderingContext2D::getImageData):
+        (WebCore::CanvasRenderingContext2D::putImageData):
+        * platform/graphics/GraphicsContext3D.cpp:
+        (WebCore::GraphicsContext3D::extractImageData):
+        * platform/graphics/ImageBuffer.cpp:
+        (WebCore::ImageBuffer::genericConvertToLuminanceMask):
+        * platform/graphics/ImageBuffer.h:
+        * platform/graphics/ShadowBlur.cpp:
+        (WebCore::ShadowBlur::blurShadowBuffer):
+        * platform/graphics/cairo/ImageBufferCairo.cpp:
+        (WebCore::getImageData):
+        (WebCore::ImageBuffer::getUnmultipliedImageData):
+        (WebCore::ImageBuffer::getPremultipliedImageData):
+        (WebCore::ImageBuffer::putByteArray):
+        * platform/graphics/cg/ImageBufferCG.cpp:
+        (WebCore::ImageBuffer::getUnmultipliedImageData):
+        (WebCore::ImageBuffer::getPremultipliedImageData):
+        (WebCore::ImageBuffer::putByteArray):
+        (WebCore::ImageBuffer::toDataURL):
+        (WebCore::ImageDataToDataURL):
+        * platform/graphics/cg/ImageBufferDataCG.cpp:
+        (WebCore::ImageBufferData::getData):
+        (WebCore::ImageBufferData::putData):
+        * platform/graphics/cg/ImageBufferDataCG.h:
+        (ImageBufferData):
+        * platform/graphics/filters/FEBlend.cpp:
+        (WebCore::FEBlend::platformApplySoftware):
+        * platform/graphics/filters/FEColorMatrix.cpp:
+        (WebCore::effectType):
+        (WebCore::FEColorMatrix::platformApplySoftware):
+        * platform/graphics/filters/FEComponentTransfer.cpp:
+        (WebCore::FEComponentTransfer::platformApplySoftware):
+        * platform/graphics/filters/FEComposite.cpp:
+        (WebCore::FEComposite::platformArithmeticSoftware):
+        (WebCore::FEComposite::platformApplySoftware):
+        * platform/graphics/filters/FEComposite.h:
+        * platform/graphics/filters/FEConvolveMatrix.cpp:
+        (WebCore::setDestinationPixels):
+        (WebCore::FEConvolveMatrix::fastSetInteriorPixels):
+        (WebCore::FEConvolveMatrix::fastSetOuterPixels):
+        (WebCore::FEConvolveMatrix::platformApplySoftware):
+        * platform/graphics/filters/FEConvolveMatrix.h:
+        (PaintingData):
+        * platform/graphics/filters/FECustomFilter.cpp:
+        (WebCore::FECustomFilter::platformApplySoftware):
+        (WebCore::FECustomFilter::bindProgramAndBuffers):
+        * platform/graphics/filters/FECustomFilter.h:
+        (JSC):
+        (FECustomFilter):
+        * platform/graphics/filters/FEDisplacementMap.cpp:
+        (WebCore::FEDisplacementMap::platformApplySoftware):
+        * platform/graphics/filters/FEDropShadow.cpp:
+        (WebCore::FEDropShadow::platformApplySoftware):
+        * platform/graphics/filters/FEGaussianBlur.cpp:
+        (WebCore::boxBlur):
+        (WebCore::FEGaussianBlur::platformApplyGeneric):
+        (WebCore::FEGaussianBlur::platformApply):
+        (WebCore::FEGaussianBlur::platformApplySoftware):
+        * platform/graphics/filters/FEGaussianBlur.h:
+        (PlatformApplyParameters):
+        (FEGaussianBlur):
+        * platform/graphics/filters/FELighting.cpp:
+        (WebCore::FELighting::LightingData::topLeft):
+        (WebCore::FELighting::LightingData::topRow):
+        (WebCore::FELighting::LightingData::topRight):
+        (WebCore::FELighting::LightingData::leftColumn):
+        (WebCore::FELighting::LightingData::interior):
+        (WebCore::FELighting::LightingData::rightColumn):
+        (WebCore::FELighting::LightingData::bottomLeft):
+        (WebCore::FELighting::LightingData::bottomRow):
+        (WebCore::FELighting::LightingData::bottomRight):
+        (WebCore::FELighting::inlineSetPixel):
+        (WebCore::FELighting::drawLighting):
+        (WebCore::FELighting::platformApplySoftware):
+        * platform/graphics/filters/FELighting.h:
+        (LightingData):
+        (FELighting):
+        * platform/graphics/filters/FEMorphology.cpp:
+        (WebCore::FEMorphology::platformApplyGeneric):
+        (WebCore::FEMorphology::platformApplySoftware):
+        * platform/graphics/filters/FEMorphology.h:
+        (PaintingData):
+        * platform/graphics/filters/FETurbulence.cpp:
+        (WebCore::FETurbulence::fillRegion):
+        (WebCore::FETurbulence::platformApplySoftware):
+        * platform/graphics/filters/FETurbulence.h:
+        (FillRegionParameters):
+        (FETurbulence):
+        * platform/graphics/filters/FilterEffect.cpp:
+        (WebCore::FilterEffect::forceValidPreMultipliedPixels):
+        (WebCore::FilterEffect::asUnmultipliedImage):
+        (WebCore::FilterEffect::asPremultipliedImage):
+        (WebCore::FilterEffect::copyImageBytes):
+        (WebCore::FilterEffect::copyUnmultipliedImage):
+        (WebCore::FilterEffect::copyPremultipliedImage):
+        (WebCore::FilterEffect::createUnmultipliedImageResult):
+        (WebCore::FilterEffect::createPremultipliedImageResult):
+        * platform/graphics/filters/FilterEffect.h:
+        (FilterEffect):
+        * platform/graphics/filters/arm/FEGaussianBlurNEON.h:
+        (WebCore::FEGaussianBlur::platformApplyNeon):
+        * platform/graphics/opengl/GraphicsContext3DOpenGLCommon.cpp:
+        (WebCore::GraphicsContext3D::paintRenderingResultsToImageData):
+        * platform/graphics/qt/ImageBufferQt.cpp:
+        (WebCore::getImageData):
+        (WebCore::ImageBuffer::getUnmultipliedImageData):
+        (WebCore::ImageBuffer::getPremultipliedImageData):
+        (WebCore::ImageBuffer::putByteArray):
+        * platform/graphics/skia/ImageBufferSkia.cpp:
+        (WebCore::getImageData):
+        (WebCore::ImageBuffer::getUnmultipliedImageData):
+        (WebCore::ImageBuffer::getPremultipliedImageData):
+        (WebCore::ImageBuffer::putByteArray):
+        * platform/graphics/texmap/TextureMapperGL.cpp:
+        * platform/graphics/wince/ImageBufferWinCE.cpp:
+        (WebCore::getImageData):
+        (WebCore::ImageBuffer::getUnmultipliedImageData):
+        (WebCore::ImageBuffer::getPremultipliedImageData):
+        (WebCore::ImageBuffer::putByteArray):
+        * platform/graphics/wx/ImageBufferWx.cpp:
+        (WebCore::ImageBuffer::getUnmultipliedImageData):
+        (WebCore::ImageBuffer::getPremultipliedImageData):
+        (WebCore::ImageBuffer::putByteArray):
+        * platform/image-encoders/skia/JPEGImageEncoder.cpp:
+        (WebCore::JPEGImageEncoder::encode):
+        * platform/image-encoders/skia/PNGImageEncoder.cpp:
+        (WebCore::PNGImageEncoder::encode):
+        * platform/image-encoders/skia/WEBPImageEncoder.cpp:
+        (WebCore::WEBPImageEncoder::encode):
+
 2012-04-23  Ryan Sleevi  <rsleevi@chromium.org>
 
         [chromium] Remove deleted files from WebCore.gypi and fix typo
index d2ca476..d9d694e 100644 (file)
 
 #include "config.h"
 #include "JSImageData.h"
+#include "JSUint8ClampedArray.h"
 
 #include "ImageData.h"
 #include "PlatformString.h"
 
-#include <runtime/JSByteArray.h>
 #include <wtf/StdLibExtras.h>
 
 using namespace JSC;
@@ -47,10 +47,7 @@ JSValue toJS(ExecState* exec, JSDOMGlobalObject* globalObject, ImageData* imageD
     
     wrapper = CREATE_DOM_WRAPPER(exec, globalObject, ImageData, imageData);
     Identifier dataName(exec, "data");
-    Structure* cpaStructure = getCachedDOMStructure(globalObject, &JSByteArray::s_info);
-    if (!cpaStructure)
-        cpaStructure = cacheDOMStructure(globalObject, JSByteArray::createStructure(exec->globalData(), globalObject, jsNull(), &JSByteArray::s_info), &JSByteArray::s_info);
-    wrapper->putDirect(exec->globalData(), dataName, JSByteArray::create(exec, cpaStructure, imageData->data()->data()), DontDelete | ReadOnly);
+    wrapper->putDirect(exec->globalData(), dataName, toJS(exec, globalObject, imageData->data()), DontDelete | ReadOnly);
     exec->heap()->reportExtraMemoryCost(imageData->data()->length());
     
     return wrapper;
index 5d2d51d..7c716c0 100644 (file)
@@ -63,8 +63,8 @@
 #include <runtime/RegExp.h>
 #include <runtime/RegExpObject.h>
 #include <wtf/ArrayBuffer.h>
-#include <wtf/ByteArray.h>
 #include <wtf/HashTraits.h>
+#include <wtf/Uint8ClampedArray.h>
 #include <wtf/Vector.h>
 
 using namespace JSC;
@@ -609,7 +609,7 @@ private:
                 write(data->width());
                 write(data->height());
                 write(data->data()->length());
-                write(data->data()->data()->data(), data->data()->length());
+                write(data->data()->data(), data->data()->length());
                 return true;
             }
             if (obj->inherits(&RegExpObject::s_info)) {
@@ -1430,7 +1430,7 @@ private:
                 return jsNull();
             }
             RefPtr<ImageData> result = ImageData::create(IntSize(width, height));
-            memcpy(result->data()->data()->data(), m_ptr, length);
+            memcpy(result->data()->data(), m_ptr, length);
             m_ptr += length;
             return getJSValue(result.get());
         }
index f60d366..394617c 100644 (file)
@@ -34,7 +34,6 @@
 #include <wtf/ArrayBuffer.h>
 #include <wtf/ArrayBufferView.h>
 #include "Blob.h"
-#include <wtf/ByteArray.h>
 #include "CanvasPixelArray.h"
 #include "DataView.h"
 #include "ExceptionCode.h"
@@ -1006,7 +1005,7 @@ private:
         ImageData* imageData = V8ImageData::toNative(value.As<v8::Object>());
         if (!imageData)
             return;
-        WTF::ByteArray* pixelArray = imageData->data()->data();
+        Uint8ClampedArray* pixelArray = imageData->data();
         m_writer.writeImageData(imageData->width(), imageData->height(), pixelArray->data(), pixelArray->length());
     }
 
@@ -1582,7 +1581,7 @@ private:
         if (m_position + pixelDataLength > m_length)
             return false;
         RefPtr<ImageData> imageData = ImageData::create(IntSize(width, height));
-        WTF::ByteArray* pixelArray = imageData->data()->data();
+        Uint8ClampedArray* pixelArray = imageData->data();
         ASSERT(pixelArray);
         ASSERT(pixelArray->length() >= pixelDataLength);
         memcpy(pixelArray->data(), m_buffer + m_position, pixelDataLength);
index 2251b7d..ccdb86e 100644 (file)
@@ -31,7 +31,7 @@
 #include "config.h"
 #include "V8ImageData.h"
 
-#include "V8CanvasPixelArray.h"
+#include "V8Uint8ClampedArray.h"
 
 namespace WebCore {
 
@@ -41,7 +41,7 @@ v8::Handle<v8::Value> toV8(ImageData* impl, v8::Isolate* isolate)
         return v8::Null();
     v8::Handle<v8::Object> wrapper = V8ImageData::wrap(impl);
     if (!wrapper.IsEmpty()) {
-        // Create a V8 CanvasPixelArray object.
+        // Create a V8 Uint8ClampedArray object.
         v8::Handle<v8::Value> pixelArray = toV8(impl->data(), isolate);
         // Set the "data" property of the ImageData object to
         // the created v8 object, eliminating the C++ callback
index 9c1cdad..7e8d7a5 100644 (file)
@@ -92,9 +92,8 @@ public:
     {
         int width = instance->width();
         int height = instance->height();
-        RefPtr<ByteArray> byteArray = ByteArray::create(width * height * 4);
-        copyPixels(instance->toImage(), width, height, byteArray->data());
-        RefPtr<ImageData> imageData = ImageData::create(IntSize(width, height), byteArray);
+        RefPtr<ImageData> imageData = ImageData::create(IntSize(width, height));
+        copyPixels(instance->toImage(), width, height, imageData->data()->data());
         return toJS(exec, static_cast<JSDOMGlobalObject*>(exec->lexicalGlobalObject()), imageData.get());
     }
 private:
index ad24136..9015827 100644 (file)
@@ -33,24 +33,41 @@ namespace WebCore {
 
 PassRefPtr<ImageData> ImageData::create(const IntSize& size)
 {
+    Checked<int, RecordOverflow> dataSize = 4;
+    dataSize *= size.width();
+    dataSize *= size.height();
+    if (dataSize.hasOverflowed())
+        return 0;
+
     return adoptRef(new ImageData(size));
 }
 
-PassRefPtr<ImageData> ImageData::create(const IntSize& size, PassRefPtr<ByteArray> byteArray)
+PassRefPtr<ImageData> ImageData::create(const IntSize& size, PassRefPtr<Uint8ClampedArray> byteArray)
 {
+    Checked<int, RecordOverflow> dataSize = 4;
+    dataSize *= size.width();
+    dataSize *= size.height();
+    if (dataSize.hasOverflowed())
+        return 0;
+
+    if (dataSize.unsafeGet() < 0
+        || static_cast<unsigned>(dataSize.unsafeGet()) > byteArray->length())
+        return 0;
+
     return adoptRef(new ImageData(size, byteArray));
 }
 
 ImageData::ImageData(const IntSize& size)
     : m_size(size)
-    , m_data(CanvasPixelArray::create(size.width() * size.height() * 4))
+    , m_data(Uint8ClampedArray::createUninitialized(size.width() * size.height() * 4))
 {
 }
 
-ImageData::ImageData(const IntSize& size, PassRefPtr<ByteArray> byteArray)
+ImageData::ImageData(const IntSize& size, PassRefPtr<Uint8ClampedArray> byteArray)
     : m_size(size)
-    , m_data(CanvasPixelArray::create(byteArray))
+    , m_data(byteArray)
 {
+    ASSERT(static_cast<unsigned>(size.width() * size.height() * 4) <= m_data->length());
 }
 
 }
index 35d08e7..7616870 100644 (file)
 #ifndef ImageData_h
 #define ImageData_h
 
-#include "CanvasPixelArray.h"
 #include "IntSize.h"
-#include <wtf/ByteArray.h>
 #include <wtf/RefCounted.h>
 #include <wtf/RefPtr.h>
+#include <wtf/Uint8ClampedArray.h>
 
 namespace WebCore {
 
 class ImageData : public RefCounted<ImageData> {
 public:
     static PassRefPtr<ImageData> create(const IntSize&);
-    static PassRefPtr<ImageData> create(const IntSize&, PassRefPtr<ByteArray>);
+    static PassRefPtr<ImageData> create(const IntSize&, PassRefPtr<Uint8ClampedArray>);
 
     IntSize size() const { return m_size; }
     int width() const { return m_size.width(); }
     int height() const { return m_size.height(); }
-    CanvasPixelArray* data() const { return m_data.get(); }
+    Uint8ClampedArray* data() const { return m_data.get(); }
 
 private:
     ImageData(const IntSize&);
-    ImageData(const IntSize&, PassRefPtr<ByteArray>);
+    ImageData(const IntSize&, PassRefPtr<Uint8ClampedArray>);
 
     IntSize m_size;
-    RefPtr<CanvasPixelArray> m_data;
+    RefPtr<Uint8ClampedArray> m_data;
 };
 
 } // namespace WebCore
index c859454..f2ea0ca 100644 (file)
@@ -34,7 +34,7 @@ module html {
         readonly attribute long width;
         readonly attribute long height;
 #if !defined(LANGUAGE_JAVASCRIPT) || !LANGUAGE_JAVASCRIPT
-        readonly attribute CanvasPixelArray data;
+        readonly attribute Uint8ClampedArray data;
 #endif
     };
 
index 92a6e9e..65510eb 100644 (file)
 #include "TextMetrics.h"
 #include "TextRun.h"
 
-#include <wtf/ByteArray.h>
+#if USE(ACCELERATED_COMPOSITING)
+#include "RenderLayer.h"
+#endif
+
 #include <wtf/CheckedArithmetic.h>
 #include <wtf/MathExtras.h>
 #include <wtf/OwnPtr.h>
+#include <wtf/Uint8ClampedArray.h>
 #include <wtf/UnusedParam.h>
 
 #if USE(CG)
@@ -1740,7 +1744,7 @@ static PassRefPtr<ImageData> createEmptyImageData(const IntSize& size)
         return 0;
 
     RefPtr<ImageData> data = ImageData::create(size);
-    memset(data->data()->data()->data(), 0, data->data()->data()->length());
+    data->data()->zeroFill();
     return data.release();
 }
 
@@ -1829,7 +1833,7 @@ PassRefPtr<ImageData> CanvasRenderingContext2D::getImageData(ImageBuffer::Coordi
     if (!buffer)
         return createEmptyImageData(imageDataRect.size());
 
-    RefPtr<ByteArray> byteArray = buffer->getUnmultipliedImageData(imageDataRect, coordinateSystem);
+    RefPtr<Uint8ClampedArray> byteArray = buffer->getUnmultipliedImageData(imageDataRect, coordinateSystem);
     if (!byteArray)
         return 0;
 
@@ -1902,7 +1906,7 @@ void CanvasRenderingContext2D::putImageData(ImageData* data, ImageBuffer::Coordi
     IntRect sourceRect(destRect);
     sourceRect.move(-destOffset);
 
-    buffer->putByteArray(Unmultiplied, data->data()->data(), IntSize(data->width(), data->height()), sourceRect, IntPoint(destOffset), coordinateSystem);
+    buffer->putByteArray(Unmultiplied, data->data(), IntSize(data->width(), data->height()), sourceRect, IntPoint(destOffset), coordinateSystem);
 
     if (coordinateSystem == ImageBuffer::BackingStoreCoordinateSystem) {
         FloatRect dirtyRect = destRect;
index 03bbd03..a282e80 100644 (file)
@@ -202,7 +202,7 @@ bool GraphicsContext3D::extractImageData(ImageData* imageData,
     int height = imageData->height();
     int dataBytes = width * height * 4;
     data.resize(dataBytes);
-    if (!packPixels(imageData->data()->data()->data(),
+    if (!packPixels(imageData->data()->data(),
                     SourceFormatRGBA8,
                     width,
                     height,
index e4a9fd8..bc3d361 100644 (file)
@@ -72,16 +72,16 @@ void ImageBuffer::transformColorSpace(ColorSpace srcColorSpace, ColorSpace dstCo
 inline void ImageBuffer::genericConvertToLuminanceMask()
 {
     IntRect luminanceRect(IntPoint(), internalSize());
-    RefPtr<ByteArray> srcPixelArray = getUnmultipliedImageData(luminanceRect);
+    RefPtr<Uint8ClampedArray> srcPixelArray = getUnmultipliedImageData(luminanceRect);
     
     unsigned pixelArrayLength = srcPixelArray->length();
     for (unsigned pixelOffset = 0; pixelOffset < pixelArrayLength; pixelOffset += 4) {
-        unsigned char a = srcPixelArray->get(pixelOffset + 3);
+        unsigned char a = srcPixelArray->item(pixelOffset + 3);
         if (!a)
             continue;
-        unsigned char r = srcPixelArray->get(pixelOffset);
-        unsigned char g = srcPixelArray->get(pixelOffset + 1);
-        unsigned char b = srcPixelArray->get(pixelOffset + 2);
+        unsigned char r = srcPixelArray->item(pixelOffset);
+        unsigned char g = srcPixelArray->item(pixelOffset + 1);
+        unsigned char 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);
index ed8387f..d1988ab 100644 (file)
 #include "GraphicsTypes.h"
 #include "IntSize.h"
 #include "ImageBufferData.h"
-#include <wtf/ByteArray.h>
 #include <wtf/Forward.h>
 #include <wtf/OwnPtr.h>
 #include <wtf/PassOwnPtr.h>
 #include <wtf/PassRefPtr.h>
+#include <wtf/Uint8ClampedArray.h>
 #include <wtf/Vector.h>
 
 namespace WebCore {
@@ -98,10 +98,10 @@ namespace WebCore {
 
         enum CoordinateSystem { LogicalCoordinateSystem, BackingStoreCoordinateSystem };
 
-        PassRefPtr<ByteArray> getUnmultipliedImageData(const IntRect&, CoordinateSystem = LogicalCoordinateSystem) const;
-        PassRefPtr<ByteArray> getPremultipliedImageData(const IntRect&, CoordinateSystem = LogicalCoordinateSystem) const;
+        PassRefPtr<Uint8ClampedArray> getUnmultipliedImageData(const IntRect&, CoordinateSystem = LogicalCoordinateSystem) const;
+        PassRefPtr<Uint8ClampedArray> getPremultipliedImageData(const IntRect&, CoordinateSystem = LogicalCoordinateSystem) const;
 
-        void putByteArray(Multiply multiplied, ByteArray*, const IntSize& sourceSize, const IntRect& sourceRect, const IntPoint& destPoint, CoordinateSystem = LogicalCoordinateSystem);
+        void putByteArray(Multiply multiplied, Uint8ClampedArray*, const IntSize& sourceSize, const IntRect& sourceRect, const IntPoint& destPoint, CoordinateSystem = LogicalCoordinateSystem);
         
         void convertToLuminanceMask();
         
index 3b8a956..30f77e8 100644 (file)
@@ -826,7 +826,7 @@ void ShadowBlur::blurShadowBuffer(const IntSize& templateSize)
         return;
 
     IntRect blurRect(IntPoint(), templateSize);
-    RefPtr<ByteArray> layerData = m_layerImage->getUnmultipliedImageData(blurRect);
+    RefPtr<Uint8ClampedArray> layerData = m_layerImage->getUnmultipliedImageData(blurRect);
     blurLayerImage(layerData->data(), blurRect.size(), blurRect.width() * 4);
     m_layerImage->putByteArray(Unmultiplied, layerData.get(), blurRect.size(), blurRect, IntPoint());
 }
index c06318e..af157a2 100644 (file)
@@ -132,16 +132,16 @@ void ImageBuffer::platformTransformColorSpace(const Vector<int>& lookUpTable)
 }
 
 template <Multiply multiplied>
-PassRefPtr<ByteArray> getImageData(const IntRect& rect, const ImageBufferData& data, const IntSize& size)
+PassRefPtr<Uint8ClampedArray> getImageData(const IntRect& rect, const ImageBufferData& data, const IntSize& size)
 {
     ASSERT(cairo_surface_get_type(data.m_surface) == CAIRO_SURFACE_TYPE_IMAGE);
 
-    RefPtr<ByteArray> result = ByteArray::create(rect.width() * rect.height() * 4);
+    RefPtr<Uint8ClampedArray> result = Uint8ClampedArray::createUninitialized(rect.width() * rect.height() * 4);
     unsigned char* dataSrc = cairo_image_surface_get_data(data.m_surface);
     unsigned char* dataDst = result->data();
 
     if (rect.x() < 0 || rect.y() < 0 || (rect.x() + rect.width()) > size.width() || (rect.y() + rect.height()) > size.height())
-        memset(dataDst, 0, result->length());
+        result->zeroFill();
 
     int originx = rect.x();
     int destx = 0;
@@ -190,17 +190,17 @@ PassRefPtr<ByteArray> getImageData(const IntRect& rect, const ImageBufferData& d
     return result.release();
 }
 
-PassRefPtr<ByteArray> ImageBuffer::getUnmultipliedImageData(const IntRect& rect, CoordinateSystem) const
+PassRefPtr<Uint8ClampedArray> ImageBuffer::getUnmultipliedImageData(const IntRect& rect, CoordinateSystem) const
 {
     return getImageData<Unmultiplied>(rect, m_data, m_size);
 }
 
-PassRefPtr<ByteArray> ImageBuffer::getPremultipliedImageData(const IntRect& rect, CoordinateSystem) const
+PassRefPtr<Uint8ClampedArray> ImageBuffer::getPremultipliedImageData(const IntRect& rect, CoordinateSystem) const
 {
     return getImageData<Premultiplied>(rect, m_data, m_size);
 }
 
-void ImageBuffer::putByteArray(Multiply multiplied, ByteArray* source, const IntSize& sourceSize, const IntRect& sourceRect, const IntPoint& destPoint, CoordinateSystem)
+void ImageBuffer::putByteArray(Multiply multiplied, Uint8ClampedArray* source, const IntSize& sourceSize, const IntRect& sourceRect, const IntPoint& destPoint, CoordinateSystem)
 {
     ASSERT(cairo_surface_get_type(m_data.m_surface) == CAIRO_SURFACE_TYPE_IMAGE);
 
index 7e930d5..745f4a0 100644 (file)
@@ -306,7 +306,7 @@ void ImageBuffer::clip(GraphicsContext* contextToClip, const FloatRect& rect) co
     CGContextTranslateCTM(platformContextToClip, -rect.x(), -rect.y() - rect.height());
 }
 
-PassRefPtr<ByteArray> ImageBuffer::getUnmultipliedImageData(const IntRect& rect, CoordinateSystem coordinateSystem) const
+PassRefPtr<Uint8ClampedArray> ImageBuffer::getUnmultipliedImageData(const IntRect& rect, CoordinateSystem coordinateSystem) const
 {
     if (m_context->isAcceleratedContext()) {
         CGContextFlush(context()->platformContext());
@@ -317,7 +317,7 @@ PassRefPtr<ByteArray> ImageBuffer::getUnmultipliedImageData(const IntRect& rect,
     return m_data.getData(rect, internalSize(), m_context->isAcceleratedContext(), true, coordinateSystem == LogicalCoordinateSystem ? m_resolutionScale : 1);
 }
 
-PassRefPtr<ByteArray> ImageBuffer::getPremultipliedImageData(const IntRect& rect, CoordinateSystem coordinateSystem) const
+PassRefPtr<Uint8ClampedArray> ImageBuffer::getPremultipliedImageData(const IntRect& rect, CoordinateSystem coordinateSystem) const
 {
     if (m_context->isAcceleratedContext()) {
         CGContextFlush(context()->platformContext());
@@ -328,7 +328,7 @@ PassRefPtr<ByteArray> ImageBuffer::getPremultipliedImageData(const IntRect& rect
     return m_data.getData(rect, internalSize(), m_context->isAcceleratedContext(), false, coordinateSystem == LogicalCoordinateSystem ? m_resolutionScale : 1);
 }
 
-void ImageBuffer::putByteArray(Multiply multiplied, ByteArray* source, const IntSize& sourceSize, const IntRect& sourceRect, const IntPoint& destPoint, CoordinateSystem coordinateSystem)
+void ImageBuffer::putByteArray(Multiply multiplied, Uint8ClampedArray* source, const IntSize& sourceSize, const IntRect& sourceRect, const IntPoint& destPoint, CoordinateSystem coordinateSystem)
 {
     if (!m_context->isAcceleratedContext()) {
         m_data.putData(source, sourceSize, sourceRect, destPoint, internalSize(), m_context->isAcceleratedContext(), multiplied == Unmultiplied, coordinateSystem == LogicalCoordinateSystem ? m_resolutionScale : 1);
@@ -440,7 +440,7 @@ String ImageBuffer::toDataURL(const String& mimeType, const double* quality, Coo
     RetainPtr<CFStringRef> uti = utiFromMIMEType(mimeType);
     ASSERT(uti);
 
-    RefPtr<ByteArray> premultipliedData;
+    RefPtr<Uint8ClampedArray> premultipliedData;
     RetainPtr<CGImageRef> image;
 
     if (CFEqual(uti.get(), jpegUTI())) {
@@ -480,7 +480,7 @@ String ImageDataToDataURL(const ImageData& source, const String& mimeType, const
     RetainPtr<CGImageRef> image;
     RetainPtr<CGDataProviderRef> dataProvider;
 
-    unsigned char* data = source.data()->data()->data();
+    unsigned char* data = source.data()->data();
     RetainPtr<CFStringRef> uti = utiFromMIMEType(mimeType);
     ASSERT(uti);
     Vector<uint8_t> dataVector;
index de41a7d..9a5a3f1 100644 (file)
@@ -116,19 +116,19 @@ static void premultitplyScanline(void* data, size_t tileNumber)
 #endif // USE(IOSURFACE_CANVAS_BACKING_STORE)
 #endif // USE(ACCELERATE)
 
-PassRefPtr<ByteArray> ImageBufferData::getData(const IntRect& rect, const IntSize& size, bool accelerateRendering, bool unmultiplied, float resolutionScale) const
+PassRefPtr<Uint8ClampedArray> ImageBufferData::getData(const IntRect& rect, const IntSize& size, bool accelerateRendering, bool unmultiplied, float resolutionScale) const
 {
     float area = 4.0f * rect.width() * rect.height();
     if (area > static_cast<float>(std::numeric_limits<int>::max()))
         return 0;
 
-    RefPtr<ByteArray> result = ByteArray::create(rect.width() * rect.height() * 4);
+    RefPtr<Uint8ClampedArray> result = Uint8ClampedArray::createUninitialized(rect.width() * rect.height() * 4);
     unsigned char* data = result->data();
     
     int endx = ceilf(rect.maxX() * resolutionScale);
     int endy = ceilf(rect.maxY() * resolutionScale);
     if (rect.x() < 0 || rect.y() < 0 || endx > size.width() || endy > size.height())
-        memset(data, 0, result->length());
+        result->zeroFill();
     
     int originx = rect.x();
     int destx = 0;
@@ -342,7 +342,7 @@ PassRefPtr<ByteArray> ImageBufferData::getData(const IntRect& rect, const IntSiz
     return result.release();
 }
 
-void ImageBufferData::putData(ByteArray*& source, const IntSize& sourceSize, const IntRect& sourceRect, const IntPoint& destPoint, const IntSize& size, bool accelerateRendering, bool unmultiplied, float resolutionScale)
+void ImageBufferData::putData(Uint8ClampedArray*& source, const IntSize& sourceSize, const IntRect& sourceRect, const IntPoint& destPoint, const IntSize& size, bool accelerateRendering, bool unmultiplied, float resolutionScale)
 {
     ASSERT(sourceRect.width() > 0);
     ASSERT(sourceRect.height() > 0);
index 4a0e761..6233c6c 100644 (file)
  */
 
 #include "Image.h"
-#include <wtf/ByteArray.h>
 #include <wtf/CheckedArithmetic.h>
 #include <wtf/RefPtr.h>
 #include <wtf/RetainPtr.h>
+#include <wtf/Uint8ClampedArray.h>
 
 #if (PLATFORM(MAC) && USE(CA) && !defined(BUILDING_ON_LEOPARD) && !defined(BUILDING_ON_SNOW_LEOPARD))
 #define WTF_USE_IOSURFACE_CANVAS_BACKING_STORE 1
@@ -58,8 +58,8 @@ public:
     mutable double m_lastFlushTime;
 #endif
 
-    PassRefPtr<ByteArray> getData(const IntRect& rect, const IntSize& size, bool accelerateRendering, bool unmultiplied, float resolutionScale) const;
-    void putData(ByteArray*& source, const IntSize& sourceSize, const IntRect& sourceRect, const IntPoint& destPoint, const IntSize& size, bool accelerateRendering, bool unmultiplied, float resolutionScale);
+    PassRefPtr<Uint8ClampedArray> getData(const IntRect&, const IntSize&, bool accelerateRendering, bool unmultiplied, float resolutionScale) const;
+    void putData(Uint8ClampedArray*& source, const IntSize& sourceSize, const IntRect& sourceRect, const IntPoint& destPoint, const IntSize&, bool accelerateRendering, bool unmultiplied, float resolutionScale);
 };
 
 } // namespace WebCore
index 530636d..aa733d9 100644 (file)
@@ -31,7 +31,7 @@
 #include "RenderTreeAsText.h"
 #include "TextStream.h"
 
-#include <wtf/ByteArray.h>
+#include <wtf/Uint8ClampedArray.h>
 
 typedef unsigned char (*BlendType)(unsigned char colorA, unsigned char colorB, unsigned char alphaA, unsigned char alphaB);
 
@@ -94,24 +94,24 @@ void FEBlend::platformApplySoftware()
     ASSERT(m_mode > FEBLEND_MODE_UNKNOWN);
     ASSERT(m_mode <= FEBLEND_MODE_LIGHTEN);
 
-    ByteArray* dstPixelArray = createPremultipliedImageResult();
+    Uint8ClampedArray* dstPixelArray = createPremultipliedImageResult();
     if (!dstPixelArray)
         return;
 
     IntRect effectADrawingRect = requestedRegionOfInputImageData(in->absolutePaintRect());
-    RefPtr<ByteArray> srcPixelArrayA = in->asPremultipliedImage(effectADrawingRect);
+    RefPtr<Uint8ClampedArray> srcPixelArrayA = in->asPremultipliedImage(effectADrawingRect);
 
     IntRect effectBDrawingRect = requestedRegionOfInputImageData(in2->absolutePaintRect());
-    RefPtr<ByteArray> srcPixelArrayB = in2->asPremultipliedImage(effectBDrawingRect);
+    RefPtr<Uint8ClampedArray> srcPixelArrayB = in2->asPremultipliedImage(effectBDrawingRect);
 
     unsigned pixelArrayLength = srcPixelArrayA->length();
     ASSERT(pixelArrayLength == srcPixelArrayB->length());
     for (unsigned pixelOffset = 0; pixelOffset < pixelArrayLength; pixelOffset += 4) {
-        unsigned char alphaA = srcPixelArrayA->get(pixelOffset + 3);
-        unsigned char alphaB = srcPixelArrayB->get(pixelOffset + 3);
+        unsigned char alphaA = srcPixelArrayA->item(pixelOffset + 3);
+        unsigned char alphaB = srcPixelArrayB->item(pixelOffset + 3);
         for (unsigned channel = 0; channel < 3; ++channel) {
-            unsigned char colorA = srcPixelArrayA->get(pixelOffset + channel);
-            unsigned char colorB = srcPixelArrayB->get(pixelOffset + channel);
+            unsigned char colorA = srcPixelArrayA->item(pixelOffset + channel);
+            unsigned char colorB = srcPixelArrayB->item(pixelOffset + channel);
             unsigned char result;
 
             switch (m_mode) {
index 00b600a..bd4212d 100644 (file)
@@ -30,8 +30,8 @@
 #include "RenderTreeAsText.h"
 #include "TextStream.h"
 
-#include <wtf/ByteArray.h>
 #include <wtf/MathExtras.h>
+#include <wtf/Uint8ClampedArray.h>
 
 namespace WebCore {
 
@@ -125,14 +125,14 @@ inline void luminance(double& red, double& green, double& blue, double& alpha)
 }
 
 template<ColorMatrixType filterType>
-void effectType(ByteArray* pixelArray, const Vector<float>& values)
+void effectType(Uint8ClampedArray* pixelArray, const Vector<float>& values)
 {
     unsigned pixelArrayLength = pixelArray->length();
     for (unsigned pixelByteOffset = 0; pixelByteOffset < pixelArrayLength; pixelByteOffset += 4) {
-        double red = pixelArray->get(pixelByteOffset);
-        double green = pixelArray->get(pixelByteOffset + 1);
-        double blue = pixelArray->get(pixelByteOffset + 2);
-        double alpha = pixelArray->get(pixelByteOffset + 3);
+        double red = pixelArray->item(pixelByteOffset);
+        double green = pixelArray->item(pixelByteOffset + 1);
+        double blue = pixelArray->item(pixelByteOffset + 2);
+        double alpha = pixelArray->item(pixelByteOffset + 3);
 
         switch (filterType) {
             case FECOLORMATRIX_TYPE_MATRIX:
@@ -167,7 +167,7 @@ void FEColorMatrix::platformApplySoftware()
     resultImage->context()->drawImageBuffer(in->asImageBuffer(), ColorSpaceDeviceRGB, drawingRegionOfInputImage(in->absolutePaintRect()));
 
     IntRect imageRect(IntPoint(), absolutePaintRect().size());
-    RefPtr<ByteArray> pixelArray = resultImage->getUnmultipliedImageData(imageRect);
+    RefPtr<Uint8ClampedArray> pixelArray = resultImage->getUnmultipliedImageData(imageRect);
 
     switch (m_type) {
     case FECOLORMATRIX_TYPE_UNKNOWN:
index 8db62dc..651bac2 100644 (file)
@@ -31,9 +31,9 @@
 #include "RenderTreeAsText.h"
 #include "TextStream.h"
 
-#include <wtf/ByteArray.h>
 #include <wtf/MathExtras.h>
 #include <wtf/StdLibExtras.h>
+#include <wtf/Uint8ClampedArray.h>
 
 namespace WebCore {
 
@@ -154,7 +154,7 @@ void FEComponentTransfer::platformApplySoftware()
 {
     FilterEffect* in = inputEffect(0);
 
-    ByteArray* pixelArray = createUnmultipliedImageResult();
+    Uint8ClampedArray* pixelArray = createUnmultipliedImageResult();
     if (!pixelArray)
         return;
 
@@ -176,7 +176,7 @@ void FEComponentTransfer::platformApplySoftware()
     unsigned pixelArrayLength = pixelArray->length();
     for (unsigned pixelOffset = 0; pixelOffset < pixelArrayLength; pixelOffset += 4) {
         for (unsigned channel = 0; channel < 4; ++channel) {
-            unsigned char c = pixelArray->get(pixelOffset + channel);
+            unsigned char c = pixelArray->item(pixelOffset + channel);
             pixelArray->set(pixelOffset + channel, tables[channel][c]);
         }
     }
index 5be22f8..57101af 100644 (file)
@@ -32,7 +32,7 @@
 #include "RenderTreeAsText.h"
 #include "TextStream.h"
 
-#include <wtf/ByteArray.h>
+#include <wtf/Uint8ClampedArray.h>
 
 namespace WebCore {
 
@@ -179,7 +179,7 @@ static inline void arithmeticSoftware(unsigned char* source, unsigned char* dest
     computeArithmeticPixels<1, 1, 1, 1>(source, destination, pixelArrayLength, k1, k2, k3, k4);
 }
 
-inline void FEComposite::platformArithmeticSoftware(ByteArray* source, ByteArray* destination,
+inline void FEComposite::platformArithmeticSoftware(Uint8ClampedArray* source, Uint8ClampedArray* destination,
     float k1, float k2, float k3, float k4)
 {
     int length = source->length();
@@ -221,12 +221,12 @@ void FEComposite::platformApplySoftware()
     FilterEffect* in2 = inputEffect(1);
 
     if (m_type == FECOMPOSITE_OPERATOR_ARITHMETIC) {
-        ByteArray* dstPixelArray = createPremultipliedImageResult();
+        Uint8ClampedArray* dstPixelArray = createPremultipliedImageResult();
         if (!dstPixelArray)
             return;
 
         IntRect effectADrawingRect = requestedRegionOfInputImageData(in->absolutePaintRect());
-        RefPtr<ByteArray> srcPixelArray = in->asPremultipliedImage(effectADrawingRect);
+        RefPtr<Uint8ClampedArray> srcPixelArray = in->asPremultipliedImage(effectADrawingRect);
 
         IntRect effectBDrawingRect = requestedRegionOfInputImageData(in2->absolutePaintRect());
         in2->copyPremultipliedImage(dstPixelArray, effectBDrawingRect);
index 24ba307..42695f6 100644 (file)
@@ -74,7 +74,7 @@ protected:
 private:
     FEComposite(Filter*, const CompositeOperationType&, float, float, float, float);
 
-    inline void platformArithmeticSoftware(ByteArray* source, ByteArray* destination, float k1, float k2, float k3, float k4);
+    inline void platformArithmeticSoftware(Uint8ClampedArray* source, Uint8ClampedArray* destination, float k1, float k2, float k3, float k4);
     inline void platformArithmeticNeon(unsigned char* source, unsigned  char* destination, unsigned pixelArrayLength, float* kArray);
 
     CompositeOperationType m_type;
index cda5f19..0651e2d 100644 (file)
@@ -30,8 +30,8 @@
 #include "RenderTreeAsText.h"
 #include "TextStream.h"
 
-#include <wtf/ByteArray.h>
 #include <wtf/ParallelJobs.h>
+#include <wtf/Uint8ClampedArray.h>
 
 namespace WebCore {
 
@@ -223,14 +223,14 @@ static ALWAYS_INLINE unsigned char clampRGBAValue(float channel, unsigned char m
 }
 
 template<bool preserveAlphaValues>
-ALWAYS_INLINE void setDestinationPixels(ByteArray* image, int& pixel, float* totals, float divisor, float bias, ByteArray* src)
+ALWAYS_INLINE void setDestinationPixels(Uint8ClampedArray* image, int& pixel, float* totals, float divisor, float bias, Uint8ClampedArray* src)
 {
     unsigned char maxAlpha = preserveAlphaValues ? 255 : clampRGBAValue(totals[3] / divisor + bias);
     for (int i = 0; i < 3; ++i)
         image->set(pixel++, clampRGBAValue(totals[i] / divisor + bias, maxAlpha));
 
     if (preserveAlphaValues) {
-        image->set(pixel, src->get(pixel));
+        image->set(pixel, src->item(pixel));
         ++pixel;
     } else
         image->set(pixel++, maxAlpha);
@@ -267,11 +267,11 @@ ALWAYS_INLINE void FEConvolveMatrix::fastSetInteriorPixels(PaintingData& paintin
                 totals[3] = 0;
 
             while (kernelValue >= 0) {
-                totals[0] += m_kernelMatrix[kernelValue] * static_cast<float>(paintingData.srcPixelArray->get(kernelPixel++));
-                totals[1] += m_kernelMatrix[kernelValue] * static_cast<float>(paintingData.srcPixelArray->get(kernelPixel++));
-                totals[2] += m_kernelMatrix[kernelValue] * static_cast<float>(paintingData.srcPixelArray->get(kernelPixel++));
+                totals[0] += m_kernelMatrix[kernelValue] * static_cast<float>(paintingData.srcPixelArray->item(kernelPixel++));
+                totals[1] += m_kernelMatrix[kernelValue] * static_cast<float>(paintingData.srcPixelArray->item(kernelPixel++));
+                totals[2] += m_kernelMatrix[kernelValue] * static_cast<float>(paintingData.srcPixelArray->item(kernelPixel++));
                 if (!preserveAlphaValues)
-                    totals[3] += m_kernelMatrix[kernelValue] * static_cast<float>(paintingData.srcPixelArray->get(kernelPixel));
+                    totals[3] += m_kernelMatrix[kernelValue] * static_cast<float>(paintingData.srcPixelArray->item(kernelPixel));
                 ++kernelPixel;
                 --kernelValue;
                 if (!--width) {
@@ -350,12 +350,12 @@ void FEConvolveMatrix::fastSetOuterPixels(PaintingData& paintingData, int x1, in
             while (kernelValue >= 0) {
                 int pixelIndex = getPixelValue(paintingData, kernelPixelX, kernelPixelY);
                 if (pixelIndex >= 0) {
-                    totals[0] += m_kernelMatrix[kernelValue] * static_cast<float>(paintingData.srcPixelArray->get(pixelIndex));
-                    totals[1] += m_kernelMatrix[kernelValue] * static_cast<float>(paintingData.srcPixelArray->get(pixelIndex + 1));
-                    totals[2] += m_kernelMatrix[kernelValue] * static_cast<float>(paintingData.srcPixelArray->get(pixelIndex + 2));
+                    totals[0] += m_kernelMatrix[kernelValue] * static_cast<float>(paintingData.srcPixelArray->item(pixelIndex));
+                    totals[1] += m_kernelMatrix[kernelValue] * static_cast<float>(paintingData.srcPixelArray->item(pixelIndex + 1));
+                    totals[2] += m_kernelMatrix[kernelValue] * static_cast<float>(paintingData.srcPixelArray->item(pixelIndex + 2));
                 }
                 if (!preserveAlphaValues && pixelIndex >= 0)
-                    totals[3] += m_kernelMatrix[kernelValue] * static_cast<float>(paintingData.srcPixelArray->get(pixelIndex + 3));
+                    totals[3] += m_kernelMatrix[kernelValue] * static_cast<float>(paintingData.srcPixelArray->item(pixelIndex + 3));
                 ++kernelPixelX;
                 --kernelValue;
                 if (!--width) {
@@ -403,7 +403,7 @@ void FEConvolveMatrix::platformApplySoftware()
 {
     FilterEffect* in = inputEffect(0);
 
-    ByteArray* resultImage;
+    Uint8ClampedArray* resultImage;
     if (m_preserveAlpha)
         resultImage = createUnmultipliedImageResult();
     else
@@ -413,7 +413,7 @@ void FEConvolveMatrix::platformApplySoftware()
 
     IntRect effectDrawingRect = requestedRegionOfInputImageData(in->absolutePaintRect());
 
-    RefPtr<ByteArray> srcPixelArray;
+    RefPtr<Uint8ClampedArray> srcPixelArray;
     if (m_preserveAlpha)
         srcPixelArray = in->asUnmultipliedImage(effectDrawingRect);
     else
index 34baf6f..250613f 100644 (file)
@@ -82,8 +82,8 @@ public:
 private:
 
     struct PaintingData {
-        ByteArray* srcPixelArray;
-        ByteArray* dstPixelArray;
+        Uint8ClampedArray* srcPixelArray;
+        Uint8ClampedArray* dstPixelArray;
         int width;
         int height;
         float bias;
index 8fafe04..89223bb 100644 (file)
@@ -46,7 +46,7 @@
 #include "TilingData.h"
 #include "TransformationMatrix.h"
 
-#include <wtf/ByteArray.h>
+#include <wtf/Uint8ClampedArray.h>
 
 namespace WebCore {
 
@@ -95,13 +95,13 @@ PassRefPtr<FECustomFilter> FECustomFilter::create(Filter* filter, HostWindow* ho
 
 void FECustomFilter::platformApplySoftware()
 {
-    ByteArray* dstPixelArray = createPremultipliedImageResult();
+    Uint8ClampedArray* dstPixelArray = createPremultipliedImageResult();
     if (!dstPixelArray)
         return;
 
     FilterEffect* in = inputEffect(0);
     IntRect effectDrawingRect = requestedRegionOfInputImageData(in->absolutePaintRect());
-    RefPtr<ByteArray> srcPixelArray = in->asPremultipliedImage(effectDrawingRect);
+    RefPtr<Uint8ClampedArray> srcPixelArray = in->asPremultipliedImage(effectDrawingRect);
     
     IntSize newContextSize(effectDrawingRect.size());
     bool hadContext = m_context;
@@ -129,7 +129,7 @@ void FECustomFilter::platformApplySoftware()
     m_drawingBuffer->commit();
 
     RefPtr<ImageData> imageData = m_context->paintRenderingResultsToImageData(m_drawingBuffer.get());
-    ByteArray* gpuResult = imageData->data()->data();
+    Uint8ClampedArray* gpuResult = imageData->data();
     ASSERT(gpuResult->length() == dstPixelArray->length());
     memcpy(dstPixelArray->data(), gpuResult->data(), gpuResult->length());
 }
@@ -209,7 +209,7 @@ void FECustomFilter::bindProgramParameters()
     }
 }
 
-void FECustomFilter::bindProgramAndBuffers(ByteArray* srcPixelArray)
+void FECustomFilter::bindProgramAndBuffers(Uint8ClampedArray* srcPixelArray)
 {
     m_context->useProgram(m_shader->program());
     
index 496f044..5f5f027 100644 (file)
@@ -38,7 +38,7 @@
 #include <wtf/RefPtr.h>
 
 namespace JSC {
-class ByteArray;
+class Uint8ClampedArray;
 }
 
 namespace WebCore {
@@ -75,7 +75,7 @@ private:
     void bindVertexAttribute(int attributeLocation, unsigned size, unsigned& offset);
     void bindProgramNumberParameters(int uniformLocation, CustomFilterNumberParameter*);
     void bindProgramParameters();
-    void bindProgramAndBuffers(ByteArray* srcPixelArray);
+    void bindProgramAndBuffers(Uint8ClampedArray* srcPixelArray);
     
     HostWindow* m_hostWindow;
     
index b0eac44..7f554aa 100644 (file)
@@ -31,7 +31,7 @@
 #include "RenderTreeAsText.h"
 #include "TextStream.h"
 
-#include <wtf/ByteArray.h>
+#include <wtf/Uint8ClampedArray.h>
 
 namespace WebCore {
 
@@ -96,15 +96,15 @@ void FEDisplacementMap::platformApplySoftware()
     ASSERT(m_xChannelSelector != CHANNEL_UNKNOWN);
     ASSERT(m_yChannelSelector != CHANNEL_UNKNOWN);
 
-    ByteArray* dstPixelArray = createPremultipliedImageResult();
+    Uint8ClampedArray* dstPixelArray = createPremultipliedImageResult();
     if (!dstPixelArray)
         return;
 
     IntRect effectADrawingRect = requestedRegionOfInputImageData(in->absolutePaintRect());
-    RefPtr<ByteArray> srcPixelArrayA = in->asPremultipliedImage(effectADrawingRect);
+    RefPtr<Uint8ClampedArray> srcPixelArrayA = in->asPremultipliedImage(effectADrawingRect);
 
     IntRect effectBDrawingRect = requestedRegionOfInputImageData(in2->absolutePaintRect());
-    RefPtr<ByteArray> srcPixelArrayB = in2->asUnmultipliedImage(effectBDrawingRect);
+    RefPtr<Uint8ClampedArray> srcPixelArrayB = in2->asUnmultipliedImage(effectBDrawingRect);
 
     ASSERT(srcPixelArrayA->length() == srcPixelArrayB->length());
 
@@ -119,13 +119,13 @@ void FEDisplacementMap::platformApplySoftware()
         int line = y * stride;
         for (int x = 0; x < paintSize.width(); ++x) {
             int dstIndex = line + x * 4;
-            int srcX = x + static_cast<int>(scaleX * srcPixelArrayB->get(dstIndex + m_xChannelSelector - 1) + scaleAdjustmentX);
-            int srcY = y + static_cast<int>(scaleY * srcPixelArrayB->get(dstIndex + m_yChannelSelector - 1) + scaleAdjustmentY);
+            int srcX = x + static_cast<int>(scaleX * srcPixelArrayB->item(dstIndex + m_xChannelSelector - 1) + scaleAdjustmentX);
+            int srcY = y + static_cast<int>(scaleY * srcPixelArrayB->item(dstIndex + m_yChannelSelector - 1) + scaleAdjustmentY);
             for (unsigned channel = 0; channel < 4; ++channel) {
                 if (srcX < 0 || srcX >= paintSize.width() || srcY < 0 || srcY >= paintSize.height())
                     dstPixelArray->set(dstIndex + channel, static_cast<unsigned char>(0));
                 else {
-                    unsigned char pixelValue = srcPixelArrayA->get(srcY * stride + srcX * 4 + channel);
+                    unsigned char pixelValue = srcPixelArrayA->item(srcY * stride + srcX * 4 + channel);
                     dstPixelArray->set(dstIndex + channel, pixelValue);
                 }
             }
index 3dd5a27..34997f6 100644 (file)
@@ -29,8 +29,8 @@
 #include "RenderTreeAsText.h"
 #include "ShadowBlur.h"
 #include "TextStream.h"
-#include <wtf/ByteArray.h>
 #include <wtf/MathExtras.h>
+#include <wtf/Uint8ClampedArray.h>
 
 using namespace std;
 
@@ -104,7 +104,7 @@ void FEDropShadow::platformApplySoftware()
 
     // TODO: Direct pixel access to ImageBuffer would avoid copying the ImageData.
     IntRect shadowArea(IntPoint(), resultImage->internalSize());
-    RefPtr<ByteArray> srcPixelArray = resultImage->getPremultipliedImageData(shadowArea);
+    RefPtr<Uint8ClampedArray> srcPixelArray = resultImage->getPremultipliedImageData(shadowArea);
 
     contextShadow.blurLayerImage(srcPixelArray->data(), shadowArea.size(), 4 * shadowArea.size().width());
 
index 027642b..fc3baf8 100644 (file)
@@ -33,9 +33,9 @@
 #include "RenderTreeAsText.h"
 #include "TextStream.h"
 
-#include <wtf/ByteArray.h>
 #include <wtf/MathExtras.h>
 #include <wtf/ParallelJobs.h>
+#include <wtf/Uint8ClampedArray.h>
 
 using namespace std;
 
@@ -80,7 +80,7 @@ void FEGaussianBlur::setStdDeviationY(float y)
     m_stdY = y;
 }
 
-inline void boxBlur(ByteArray* srcPixelArray, ByteArray* dstPixelArray,
+inline void boxBlur(Uint8ClampedArray* srcPixelArray, Uint8ClampedArray* dstPixelArray,
                     unsigned dx, int dxLeft, int dxRight, int stride, int strideLine, int effectWidth, int effectHeight, bool alphaImage)
 {
     for (int y = 0; y < effectHeight; ++y) {
@@ -90,16 +90,16 @@ inline void boxBlur(ByteArray* srcPixelArray, ByteArray* dstPixelArray,
             // Fill the kernel
             int maxKernelSize = min(dxRight, effectWidth);
             for (int i = 0; i < maxKernelSize; ++i)
-                sum += srcPixelArray->get(line + i * stride + channel);
+                sum += srcPixelArray->item(line + i * stride + channel);
 
             // Blurring
             for (int x = 0; x < effectWidth; ++x) {
                 int pixelByteOffset = line + x * stride + channel;
                 dstPixelArray->set(pixelByteOffset, static_cast<unsigned char>(sum / dx));
                 if (x >= dxLeft)
-                    sum -= srcPixelArray->get(pixelByteOffset - dxLeft * stride);
+                    sum -= srcPixelArray->item(pixelByteOffset - dxLeft * stride);
                 if (x + dxRight < effectWidth)
-                    sum += srcPixelArray->get(pixelByteOffset + dxRight * stride);
+                    sum += srcPixelArray->item(pixelByteOffset + dxRight * stride);
             }
             if (alphaImage) // Source image is black, it just has different alpha values
                 break;
@@ -107,15 +107,15 @@ inline void boxBlur(ByteArray* srcPixelArray, ByteArray* dstPixelArray,
     }
 }
 
-inline void FEGaussianBlur::platformApplyGeneric(ByteArray* srcPixelArray, ByteArray* tmpPixelArray, unsigned kernelSizeX, unsigned kernelSizeY, IntSize& paintSize)
+inline void FEGaussianBlur::platformApplyGeneric(Uint8ClampedArray* srcPixelArray, Uint8ClampedArray* tmpPixelArray, unsigned kernelSizeX, unsigned kernelSizeY, IntSize& paintSize)
 {
     int stride = 4 * paintSize.width();
     int dxLeft = 0;
     int dxRight = 0;
     int dyLeft = 0;
     int dyRight = 0;
-    ByteArray* src = srcPixelArray;
-    ByteArray* dst = tmpPixelArray;
+    Uint8ClampedArray* src = srcPixelArray;
+    Uint8ClampedArray* dst = tmpPixelArray;
 
     for (int i = 0; i < 3; ++i) {
         if (kernelSizeX) {
@@ -151,7 +151,7 @@ void FEGaussianBlur::platformApplyWorker(PlatformApplyParameters* parameters)
 #endif
 }
 
-inline void FEGaussianBlur::platformApply(ByteArray* srcPixelArray, ByteArray* tmpPixelArray, unsigned kernelSizeX, unsigned kernelSizeY, IntSize& paintSize)
+inline void FEGaussianBlur::platformApply(Uint8ClampedArray* srcPixelArray, Uint8ClampedArray* tmpPixelArray, unsigned kernelSizeX, unsigned kernelSizeY, IntSize& paintSize)
 {
     int scanline = 4 * paintSize.width();
     int extraHeight = 3 * kernelSizeY * 0.5f;
@@ -185,8 +185,8 @@ inline void FEGaussianBlur::platformApply(ByteArray* srcPixelArray, ByteArray* t
                     }
 
                     int blockSize = (endY - startY) * scanline;
-                    params.srcPixelArray = ByteArray::create(blockSize);
-                    params.dstPixelArray = ByteArray::create(blockSize);
+                    params.srcPixelArray = Uint8ClampedArray::createUninitialized(blockSize);
+                    params.dstPixelArray = Uint8ClampedArray::createUninitialized(blockSize);
                     memcpy(params.srcPixelArray->data(), srcPixelArray->data() + startY * scanline, blockSize);
                 }
 
@@ -275,7 +275,7 @@ void FEGaussianBlur::platformApplySoftware()
 {
     FilterEffect* in = inputEffect(0);
 
-    ByteArray* srcPixelArray = createPremultipliedImageResult();
+    Uint8ClampedArray* srcPixelArray = createPremultipliedImageResult();
     if (!srcPixelArray)
         return;
 
@@ -292,8 +292,8 @@ void FEGaussianBlur::platformApplySoftware()
     calculateKernelSize(filter(), kernelSizeX, kernelSizeY, m_stdX, m_stdY);
 
     IntSize paintSize = absolutePaintRect().size();
-    RefPtr<ByteArray> tmpImageData = ByteArray::create(paintSize.width() * paintSize.height() * 4);
-    ByteArray* tmpPixelArray = tmpImageData.get();
+    RefPtr<Uint8ClampedArray> tmpImageData = Uint8ClampedArray::createUninitialized(paintSize.width() * paintSize.height() * 4);
+    Uint8ClampedArray* tmpPixelArray = tmpImageData.get();
 
     platformApply(srcPixelArray, tmpPixelArray, kernelSizeX, kernelSizeY, paintSize);
 }
index b295d36..c3db1f1 100644 (file)
@@ -57,8 +57,8 @@ private:
 
     struct PlatformApplyParameters {
         FEGaussianBlur* filter;
-        RefPtr<ByteArray> srcPixelArray;
-        RefPtr<ByteArray> dstPixelArray;
+        RefPtr<Uint8ClampedArray> srcPixelArray;
+        RefPtr<Uint8ClampedArray> dstPixelArray;
         int width;
         int height;
         unsigned kernelSizeX;
@@ -70,10 +70,10 @@ private:
     FEGaussianBlur(Filter*, float, float);
 
     static inline void kernelPosition(int boxBlur, unsigned& std, int& dLeft, int& dRight);
-    inline void platformApply(ByteArray* srcPixelArray, ByteArray* tmpPixelArray, unsigned kernelSizeX, unsigned kernelSizeY, IntSize& paintSize);
+    inline void platformApply(Uint8ClampedArray* srcPixelArray, Uint8ClampedArray* tmpPixelArray, unsigned kernelSizeX, unsigned kernelSizeY, IntSize& paintSize);
 
-    inline void platformApplyGeneric(ByteArray* srcPixelArray, ByteArray* tmpPixelArray, unsigned kernelSizeX, unsigned kernelSizeY, IntSize& paintSize);
-    inline void platformApplyNeon(ByteArray* srcPixelArray, ByteArray* tmpPixelArray, unsigned kernelSizeX, unsigned kernelSizeY, IntSize& paintSize);
+    inline void platformApplyGeneric(Uint8ClampedArray* srcPixelArray, Uint8ClampedArray* tmpPixelArray, unsigned kernelSizeX, unsigned kernelSizeY, IntSize& paintSize);
+    inline void platformApplyNeon(Uint8ClampedArray* srcPixelArray, Uint8ClampedArray* tmpPixelArray, unsigned kernelSizeX, unsigned kernelSizeY, IntSize& paintSize);
 #if USE(SKIA)
     virtual bool platformApplySkia();
 #endif
index e795d35..9d386fc 100644 (file)
@@ -61,114 +61,114 @@ const static float cFactor2div3 = -2 / 3.f;
 // << 1 is signed multiply by 2
 inline void FELighting::LightingData::topLeft(int offset, IntPoint& normalVector)
 {
-    int center = static_cast<int>(pixels->get(offset + cAlphaChannelOffset));
-    int right = static_cast<int>(pixels->get(offset + cPixelSize + cAlphaChannelOffset));
+    int center = static_cast<int>(pixels->item(offset + cAlphaChannelOffset));
+    int right = static_cast<int>(pixels->item(offset + cPixelSize + cAlphaChannelOffset));
     offset += widthMultipliedByPixelSize;
-    int bottom = static_cast<int>(pixels->get(offset + cAlphaChannelOffset));
-    int bottomRight = static_cast<int>(pixels->get(offset + cPixelSize + cAlphaChannelOffset));
+    int bottom = static_cast<int>(pixels->item(offset + cAlphaChannelOffset));
+    int bottomRight = static_cast<int>(pixels->item(offset + cPixelSize + cAlphaChannelOffset));
     normalVector.setX(-(center << 1) + (right << 1) - bottom + bottomRight);
     normalVector.setY(-(center << 1) - right + (bottom << 1) + bottomRight);
 }
 
 inline void FELighting::LightingData::topRow(int offset, IntPoint& normalVector)
 {
-    int left = static_cast<int>(pixels->get(offset - cPixelSize + cAlphaChannelOffset));
-    int center = static_cast<int>(pixels->get(offset + cAlphaChannelOffset));
-    int right = static_cast<int>(pixels->get(offset + cPixelSize + cAlphaChannelOffset));
+    int left = static_cast<int>(pixels->item(offset - cPixelSize + cAlphaChannelOffset));
+    int center = static_cast<int>(pixels->item(offset + cAlphaChannelOffset));
+    int right = static_cast<int>(pixels->item(offset + cPixelSize + cAlphaChannelOffset));
     offset += widthMultipliedByPixelSize;
-    int bottomLeft = static_cast<int>(pixels->get(offset - cPixelSize + cAlphaChannelOffset));
-    int bottom = static_cast<int>(pixels->get(offset + cAlphaChannelOffset));
-    int bottomRight = static_cast<int>(pixels->get(offset + cPixelSize + cAlphaChannelOffset));
+    int bottomLeft = static_cast<int>(pixels->item(offset - cPixelSize + cAlphaChannelOffset));
+    int bottom = static_cast<int>(pixels->item(offset + cAlphaChannelOffset));
+    int bottomRight = static_cast<int>(pixels->item(offset + cPixelSize + cAlphaChannelOffset));
     normalVector.setX(-(left << 1) + (right << 1) - bottomLeft + bottomRight);
     normalVector.setY(-left - (center << 1) - right + bottomLeft + (bottom << 1) + bottomRight);
 }
 
 inline void FELighting::LightingData::topRight(int offset, IntPoint& normalVector)
 {
-    int left = static_cast<int>(pixels->get(offset - cPixelSize + cAlphaChannelOffset));
-    int center = static_cast<int>(pixels->get(offset + cAlphaChannelOffset));
+    int left = static_cast<int>(pixels->item(offset - cPixelSize + cAlphaChannelOffset));
+    int center = static_cast<int>(pixels->item(offset + cAlphaChannelOffset));
     offset += widthMultipliedByPixelSize;
-    int bottomLeft = static_cast<int>(pixels->get(offset - cPixelSize + cAlphaChannelOffset));
-    int bottom = static_cast<int>(pixels->get(offset + cAlphaChannelOffset));
+    int bottomLeft = static_cast<int>(pixels->item(offset - cPixelSize + cAlphaChannelOffset));
+    int bottom = static_cast<int>(pixels->item(offset + cAlphaChannelOffset));
     normalVector.setX(-(left << 1) + (center << 1) - bottomLeft + bottom);
     normalVector.setY(-left - (center << 1) + bottomLeft + (bottom << 1));
 }
 
 inline void FELighting::LightingData::leftColumn(int offset, IntPoint& normalVector)
 {
-    int center = static_cast<int>(pixels->get(offset + cAlphaChannelOffset));
-    int right = static_cast<int>(pixels->get(offset + cPixelSize + cAlphaChannelOffset));
+    int center = static_cast<int>(pixels->item(offset + cAlphaChannelOffset));
+    int right = static_cast<int>(pixels->item(offset + cPixelSize + cAlphaChannelOffset));
     offset -= widthMultipliedByPixelSize;
-    int top = static_cast<int>(pixels->get(offset + cAlphaChannelOffset));
-    int topRight = static_cast<int>(pixels->get(offset + cPixelSize + cAlphaChannelOffset));
+    int top = static_cast<int>(pixels->item(offset + cAlphaChannelOffset));
+    int topRight = static_cast<int>(pixels->item(offset + cPixelSize + cAlphaChannelOffset));
     offset += widthMultipliedByPixelSize << 1;
-    int bottom = static_cast<int>(pixels->get(offset + cAlphaChannelOffset));
-    int bottomRight = static_cast<int>(pixels->get(offset + cPixelSize + cAlphaChannelOffset));
+    int bottom = static_cast<int>(pixels->item(offset + cAlphaChannelOffset));
+    int bottomRight = static_cast<int>(pixels->item(offset + cPixelSize + cAlphaChannelOffset));
     normalVector.setX(-top + topRight - (center << 1) + (right << 1) - bottom + bottomRight);
     normalVector.setY(-(top << 1) - topRight + (bottom << 1) + bottomRight);
 }
 
 inline void FELighting::LightingData::interior(int offset, IntPoint& normalVector)
 {
-    int left = static_cast<int>(pixels->get(offset - cPixelSize + cAlphaChannelOffset));
-    int right = static_cast<int>(pixels->get(offset + cPixelSize + cAlphaChannelOffset));
+    int left = static_cast<int>(pixels->item(offset - cPixelSize + cAlphaChannelOffset));
+    int right = static_cast<int>(pixels->item(offset + cPixelSize + cAlphaChannelOffset));
     offset -= widthMultipliedByPixelSize;
-    int topLeft = static_cast<int>(pixels->get(offset - cPixelSize + cAlphaChannelOffset));
-    int top = static_cast<int>(pixels->get(offset + cAlphaChannelOffset));
-    int topRight = static_cast<int>(pixels->get(offset + cPixelSize + cAlphaChannelOffset));
+    int topLeft = static_cast<int>(pixels->item(offset - cPixelSize + cAlphaChannelOffset));
+    int top = static_cast<int>(pixels->item(offset + cAlphaChannelOffset));
+    int topRight = static_cast<int>(pixels->item(offset + cPixelSize + cAlphaChannelOffset));
     offset += widthMultipliedByPixelSize << 1;
-    int bottomLeft = static_cast<int>(pixels->get(offset - cPixelSize + cAlphaChannelOffset));
-    int bottom = static_cast<int>(pixels->get(offset + cAlphaChannelOffset));
-    int bottomRight = static_cast<int>(pixels->get(offset + cPixelSize + cAlphaChannelOffset));
+    int bottomLeft = static_cast<int>(pixels->item(offset - cPixelSize + cAlphaChannelOffset));
+    int bottom = static_cast<int>(pixels->item(offset + cAlphaChannelOffset));
+    int bottomRight = static_cast<int>(pixels->item(offset + cPixelSize + cAlphaChannelOffset));
     normalVector.setX(-topLeft + topRight - (left << 1) + (right << 1) - bottomLeft + bottomRight);
     normalVector.setY(-topLeft - (top << 1) - topRight + bottomLeft + (bottom << 1) + bottomRight);
 }
 
 inline void FELighting::LightingData::rightColumn(int offset, IntPoint& normalVector)
 {
-    int left = static_cast<int>(pixels->get(offset - cPixelSize + cAlphaChannelOffset));
-    int center = static_cast<int>(pixels->get(offset + cAlphaChannelOffset));
+    int left = static_cast<int>(pixels->item(offset - cPixelSize + cAlphaChannelOffset));
+    int center = static_cast<int>(pixels->item(offset + cAlphaChannelOffset));
     offset -= widthMultipliedByPixelSize;
-    int topLeft = static_cast<int>(pixels->get(offset - cPixelSize + cAlphaChannelOffset));
-    int top = static_cast<int>(pixels->get(offset + cAlphaChannelOffset));
+    int topLeft = static_cast<int>(pixels->item(offset - cPixelSize + cAlphaChannelOffset));
+    int top = static_cast<int>(pixels->item(offset + cAlphaChannelOffset));
     offset += widthMultipliedByPixelSize << 1;
-    int bottomLeft = static_cast<int>(pixels->get(offset - cPixelSize + cAlphaChannelOffset));
-    int bottom = static_cast<int>(pixels->get(offset + cAlphaChannelOffset));
+    int bottomLeft = static_cast<int>(pixels->item(offset - cPixelSize + cAlphaChannelOffset));
+    int bottom = static_cast<int>(pixels->item(offset + cAlphaChannelOffset));
     normalVector.setX(-topLeft + top - (left << 1) + (center << 1) - bottomLeft + bottom);
     normalVector.setY(-topLeft - (top << 1) + bottomLeft + (bottom << 1));
 }
 
 inline void FELighting::LightingData::bottomLeft(int offset, IntPoint& normalVector)
 {
-    int center = static_cast<int>(pixels->get(offset + cAlphaChannelOffset));
-    int right = static_cast<int>(pixels->get(offset + cPixelSize + cAlphaChannelOffset));
+    int center = static_cast<int>(pixels->item(offset + cAlphaChannelOffset));
+    int right = static_cast<int>(pixels->item(offset + cPixelSize + cAlphaChannelOffset));
     offset -= widthMultipliedByPixelSize;
-    int top = static_cast<int>(pixels->get(offset + cAlphaChannelOffset));
-    int topRight = static_cast<int>(pixels->get(offset + cPixelSize + cAlphaChannelOffset));
+    int top = static_cast<int>(pixels->item(offset + cAlphaChannelOffset));
+    int topRight = static_cast<int>(pixels->item(offset + cPixelSize + cAlphaChannelOffset));
     normalVector.setX(-top + topRight - (center << 1) + (right << 1));
     normalVector.setY(-(top << 1) - topRight + (center << 1) + right);
 }
 
 inline void FELighting::LightingData::bottomRow(int offset, IntPoint& normalVector)
 {
-    int left = static_cast<int>(pixels->get(offset - cPixelSize + cAlphaChannelOffset));
-    int center = static_cast<int>(pixels->get(offset + cAlphaChannelOffset));
-    int right = static_cast<int>(pixels->get(offset + cPixelSize + cAlphaChannelOffset));
+    int left = static_cast<int>(pixels->item(offset - cPixelSize + cAlphaChannelOffset));
+    int center = static_cast<int>(pixels->item(offset + cAlphaChannelOffset));
+    int right = static_cast<int>(pixels->item(offset + cPixelSize + cAlphaChannelOffset));
     offset -= widthMultipliedByPixelSize;
-    int topLeft = static_cast<int>(pixels->get(offset - cPixelSize + cAlphaChannelOffset));
-    int top = static_cast<int>(pixels->get(offset + cAlphaChannelOffset));
-    int topRight = static_cast<int>(pixels->get(offset + cPixelSize + cAlphaChannelOffset));
+    int topLeft = static_cast<int>(pixels->item(offset - cPixelSize + cAlphaChannelOffset));
+    int top = static_cast<int>(pixels->item(offset + cAlphaChannelOffset));
+    int topRight = static_cast<int>(pixels->item(offset + cPixelSize + cAlphaChannelOffset));
     normalVector.setX(-topLeft + topRight - (left << 1) + (right << 1));
     normalVector.setY(-topLeft - (top << 1) - topRight + left + (center << 1) + right);
 }
 
 inline void FELighting::LightingData::bottomRight(int offset, IntPoint& normalVector)
 {
-    int left = static_cast<int>(pixels->get(offset - cPixelSize + cAlphaChannelOffset));
-    int center = static_cast<int>(pixels->get(offset + cAlphaChannelOffset));
+    int left = static_cast<int>(pixels->item(offset - cPixelSize + cAlphaChannelOffset));
+    int center = static_cast<int>(pixels->item(offset + cAlphaChannelOffset));
     offset -= widthMultipliedByPixelSize;
-    int topLeft = static_cast<int>(pixels->get(offset - cPixelSize + cAlphaChannelOffset));
-    int top = static_cast<int>(pixels->get(offset + cAlphaChannelOffset));
+    int topLeft = static_cast<int>(pixels->item(offset - cPixelSize + cAlphaChannelOffset));
+    int top = static_cast<int>(pixels->item(offset + cAlphaChannelOffset));
     normalVector.setX(-topLeft + top - (left << 1) + (center << 1));
     normalVector.setY(-topLeft - (top << 1) + left + (center << 1));
 }
@@ -176,7 +176,7 @@ inline void FELighting::LightingData::bottomRight(int offset, IntPoint& normalVe
 inline void FELighting::inlineSetPixel(int offset, LightingData& data, LightSource::PaintingData& paintingData,
                                        int lightX, int lightY, float factorX, float factorY, IntPoint& normal2DVector)
 {
-    m_lightSource->updatePaintingData(paintingData, lightX, lightY, static_cast<float>(data.pixels->get(offset + cAlphaChannelOffset)) * data.surfaceScale);
+    m_lightSource->updatePaintingData(paintingData, lightX, lightY, static_cast<float>(data.pixels->item(offset + cAlphaChannelOffset)) * data.surfaceScale);
 
     float lightStrength;
     if (!normal2DVector.x() && !normal2DVector.y()) {
@@ -290,7 +290,7 @@ inline void FELighting::platformApply(LightingData& data, LightSource::PaintingD
 #endif
 }
 
-bool FELighting::drawLighting(ByteArray* pixels, int width, int height)
+bool FELighting::drawLighting(Uint8ClampedArray* pixels, int width, int height)
 {
     LightSource::PaintingData paintingData;
     LightingData data;
@@ -373,9 +373,9 @@ bool FELighting::drawLighting(ByteArray* pixels, int width, int height)
             data.pixels->set(i, cOpaqueAlpha);
     } else {
         for (int i = 0; i < lastPixel; i += cPixelSize) {
-            unsigned char a1 = data.pixels->get(i);
-            unsigned char a2 = data.pixels->get(i + 1);
-            unsigned char a3 = data.pixels->get(i + 2);
+            unsigned char a1 = data.pixels->item(i);
+            unsigned char a2 = data.pixels->item(i + 1);
+            unsigned char a3 = data.pixels->item(i + 2);
             // alpha set to set to max(a1, a2, a3)
             data.pixels->set(i + 3, a1 >= a2 ? (a1 >= a3 ? a1 : a3) : (a2 >= a3 ? a2 : a3));
         }
@@ -388,7 +388,7 @@ void FELighting::platformApplySoftware()
 {
     FilterEffect* in = inputEffect(0);
 
-    ByteArray* srcPixelArray = createUnmultipliedImageResult();
+    Uint8ClampedArray* srcPixelArray = createUnmultipliedImageResult();
     if (!srcPixelArray)
         return;
 
index 5426f91..d0d2b36 100644 (file)
@@ -34,8 +34,8 @@
 #include "LightSource.h"
 #include "PointLightSource.h"
 #include "SpotLightSource.h"
-#include <wtf/ByteArray.h>
 #include <wtf/Platform.h>
+#include <wtf/Uint8ClampedArray.h>
 
 // Common base class for FEDiffuseLighting and FESpecularLighting
 
@@ -59,7 +59,7 @@ protected:
 
     struct LightingData {
         // This structure contains only read-only (SMP safe) data
-        ByteArray* pixels;
+        Uint8ClampedArray* pixels;
         float surfaceScale;
         int widthMultipliedByPixelSize;
         int widthDecreasedByOne;
@@ -92,7 +92,7 @@ protected:
 
     FELighting(Filter*, LightingType, const Color&, float, float, float, float, float, float, PassRefPtr<LightSource>);
 
-    bool drawLighting(ByteArray*, int, int);
+    bool drawLighting(Uint8ClampedArray*, int, int);
     inline void inlineSetPixel(int offset, LightingData&, LightSource::PaintingData&,
                                int lightX, int lightY, float factorX, float factorY, IntPoint& normalVector);
 
index 5ba4dfc..98d2a6a 100644 (file)
@@ -30,8 +30,8 @@
 #include "RenderTreeAsText.h"
 #include "TextStream.h"
 
-#include <wtf/ByteArray.h>
 #include <wtf/ParallelJobs.h>
+#include <wtf/Uint8ClampedArray.h>
 #include <wtf/Vector.h>
 
 using std::min;
@@ -106,8 +106,8 @@ bool FEMorphology::setRadiusY(float radiusY)
 
 void FEMorphology::platformApplyGeneric(PaintingData* paintingData, int yStart, int yEnd)
 {
-    ByteArray* srcPixelArray = paintingData->srcPixelArray;
-    ByteArray* dstPixelArray = paintingData->dstPixelArray;
+    Uint8ClampedArray* srcPixelArray = paintingData->srcPixelArray;
+    Uint8ClampedArray* dstPixelArray = paintingData->dstPixelArray;
     const int width = paintingData->width;
     const int height = paintingData->height;
     const int effectWidth = width * 4;
@@ -122,9 +122,9 @@ void FEMorphology::platformApplyGeneric(PaintingData* paintingData, int yStart,
             extrema.clear();
             // Compute extremas for each columns
             for (int x = 0; x <= radiusX; ++x) {
-                unsigned char columnExtrema = srcPixelArray->get(extremaStartY * effectWidth + 4 * x + clrChannel);
+                unsigned char columnExtrema = srcPixelArray->item(extremaStartY * effectWidth + 4 * x + clrChannel);
                 for (int eY = extremaStartY + 1; eY < extremaEndY; ++eY) {
-                    unsigned char pixel = srcPixelArray->get(eY * effectWidth + 4 * x + clrChannel);
+                    unsigned char pixel = srcPixelArray->item(eY * effectWidth + 4 * x + clrChannel);
                     if ((m_type == FEMORPHOLOGY_OPERATOR_ERODE && pixel <= columnExtrema)
                         || (m_type == FEMORPHOLOGY_OPERATOR_DILATE && pixel >= columnExtrema)) {
                         columnExtrema = pixel;
@@ -137,9 +137,9 @@ void FEMorphology::platformApplyGeneric(PaintingData* paintingData, int yStart,
             // Kernel is filled, get extrema of next column
             for (int x = 0; x < width; ++x) {
                 const int endX = min(x + radiusX, width - 1);
-                unsigned char columnExtrema = srcPixelArray->get(extremaStartY * effectWidth + endX * 4 + clrChannel);
+                unsigned char columnExtrema = srcPixelArray->item(extremaStartY * effectWidth + endX * 4 + clrChannel);
                 for (int i = extremaStartY + 1; i <= extremaEndY; ++i) {
-                    unsigned char pixel = srcPixelArray->get(i * effectWidth + endX * 4 + clrChannel);
+                    unsigned char pixel = srcPixelArray->item(i * effectWidth + endX * 4 + clrChannel);
                     if ((m_type == FEMORPHOLOGY_OPERATOR_ERODE && pixel <= columnExtrema)
                         || (m_type == FEMORPHOLOGY_OPERATOR_DILATE && pixel >= columnExtrema))
                         columnExtrema = pixel;
@@ -197,13 +197,13 @@ void FEMorphology::platformApplySoftware()
 {
     FilterEffect* in = inputEffect(0);
 
-    ByteArray* dstPixelArray = createPremultipliedImageResult();
+    Uint8ClampedArray* dstPixelArray = createPremultipliedImageResult();
     if (!dstPixelArray)
         return;
 
     setIsAlphaImage(in->isAlphaImage());
     if (m_radiusX <= 0 || m_radiusY <= 0) {
-        dstPixelArray->clear();
+        dstPixelArray->zeroFill();
         return;
     }
 
@@ -212,7 +212,7 @@ void FEMorphology::platformApplySoftware()
     int radiusY = static_cast<int>(floorf(filter->applyVerticalScale(m_radiusY)));
 
     IntRect effectDrawingRect = requestedRegionOfInputImageData(in->absolutePaintRect());
-    RefPtr<ByteArray> srcPixelArray = in->asPremultipliedImage(effectDrawingRect);
+    RefPtr<Uint8ClampedArray> srcPixelArray = in->asPremultipliedImage(effectDrawingRect);
 
     PaintingData paintingData;
     paintingData.srcPixelArray = srcPixelArray.get();
index 542d26b..19da635 100644 (file)
@@ -57,8 +57,8 @@ public:
     virtual TextStream& externalRepresentation(TextStream&, int indention) const;
 
     struct PaintingData {
-        ByteArray* srcPixelArray;
-        ByteArray* dstPixelArray;
+        Uint8ClampedArray* srcPixelArray;
+        Uint8ClampedArray* dstPixelArray;
         int width;
         int height;
         int radiusX;
index d5d64c1..03df56b 100644 (file)
@@ -31,9 +31,9 @@
 #include "RenderTreeAsText.h"
 #include "TextStream.h"
 
-#include <wtf/ByteArray.h>
 #include <wtf/MathExtras.h>
 #include <wtf/ParallelJobs.h>
+#include <wtf/Uint8ClampedArray.h>
 
 namespace WebCore {
 
@@ -330,7 +330,7 @@ unsigned char FETurbulence::calculateTurbulenceValueForPoint(int channel, Painti
     return static_cast<unsigned char>(turbulenceFunctionResult * 255);
 }
 
-inline void FETurbulence::fillRegion(ByteArray* pixelArray, PaintingData& paintingData, int startY, int endY)
+inline void FETurbulence::fillRegion(Uint8ClampedArray* pixelArray, PaintingData& paintingData, int startY, int endY)
 {
     IntRect filterRegion = absolutePaintRect();
     IntPoint point(0, filterRegion.y() + startY);
@@ -356,12 +356,12 @@ void FETurbulence::fillRegionWorker(FillRegionParameters* parameters)
 
 void FETurbulence::platformApplySoftware()
 {
-    ByteArray* pixelArray = createUnmultipliedImageResult();
+    Uint8ClampedArray* pixelArray = createUnmultipliedImageResult();
     if (!pixelArray)
         return;
 
     if (absolutePaintRect().isEmpty()) {
-        pixelArray->clear();
+        pixelArray->zeroFill();
         return;
     }
 
index 59257d0..47c8bee 100644 (file)
@@ -108,7 +108,7 @@ private:
 
     struct FillRegionParameters {
         FETurbulence* filter;
-        ByteArray* pixelArray;
+        Uint8ClampedArray* pixelArray;
         PaintingData* paintingData;
         int startY;
         int endY;
@@ -121,7 +121,7 @@ private:
     inline void initPaint(PaintingData&);
     float noise2D(int channel, PaintingData&, StitchData&, const FloatPoint&);
     unsigned char calculateTurbulenceValueForPoint(int channel, PaintingData&, StitchData&, const FloatPoint&);
-    inline void fillRegion(ByteArray*, PaintingData&, int, int);
+    inline void fillRegion(Uint8ClampedArray*, PaintingData&, int, int);
 
     TurbulenceType m_type;
     float m_baseFrequencyX;
index 89d581c..8dc9185 100644 (file)
@@ -27,7 +27,7 @@
 #include "Filter.h"
 #include "ImageBuffer.h"
 #include "TextStream.h"
-#include <wtf/ByteArray.h>
+#include <wtf/Uint8ClampedArray.h>
 
 namespace WebCore {
 
@@ -125,7 +125,7 @@ void FilterEffect::forceValidPreMultipliedPixels()
     if (!m_premultipliedImageResult)
         return;
 
-    ByteArray* imageArray = m_premultipliedImageResult.get();
+    Uint8ClampedArray* imageArray = m_premultipliedImageResult.get();
     unsigned char* pixelData = imageArray->data();
     int pixelArrayLength = imageArray->length();
 
@@ -173,23 +173,23 @@ ImageBuffer* FilterEffect::asImageBuffer()
     return m_imageBufferResult.get();
 }
 
-PassRefPtr<ByteArray> FilterEffect::asUnmultipliedImage(const IntRect& rect)
+PassRefPtr<Uint8ClampedArray> FilterEffect::asUnmultipliedImage(const IntRect& rect)
 {
     ASSERT(isFilterSizeValid(rect));
-    RefPtr<ByteArray> imageData = ByteArray::create(rect.width() * rect.height() * 4);
+    RefPtr<Uint8ClampedArray> imageData = Uint8ClampedArray::createUninitialized(rect.width() * rect.height() * 4);
     copyUnmultipliedImage(imageData.get(), rect);
     return imageData.release();
 }
 
-PassRefPtr<ByteArray> FilterEffect::asPremultipliedImage(const IntRect& rect)
+PassRefPtr<Uint8ClampedArray> FilterEffect::asPremultipliedImage(const IntRect& rect)
 {
     ASSERT(isFilterSizeValid(rect));
-    RefPtr<ByteArray> imageData = ByteArray::create(rect.width() * rect.height() * 4);
+    RefPtr<Uint8ClampedArray> imageData = Uint8ClampedArray::createUninitialized(rect.width() * rect.height() * 4);
     copyPremultipliedImage(imageData.get(), rect);
     return imageData.release();
 }
 
-inline void FilterEffect::copyImageBytes(ByteArray* source, ByteArray* destination, const IntRect& rect)
+inline void FilterEffect::copyImageBytes(Uint8ClampedArray* source, Uint8ClampedArray* destination, const IntRect& rect)
 {
     // Initialize the destination to transparent black, if not entirely covered by the source.
     if (rect.x() < 0 || rect.y() < 0 || rect.maxX() > m_absolutePaintRect.width() || rect.maxY() > m_absolutePaintRect.height())
@@ -233,7 +233,7 @@ inline void FilterEffect::copyImageBytes(ByteArray* source, ByteArray* destinati
     }
 }
 
-void FilterEffect::copyUnmultipliedImage(ByteArray* destination, const IntRect& rect)
+void FilterEffect::copyUnmultipliedImage(Uint8ClampedArray* destination, const IntRect& rect)
 {
     ASSERT(hasResult());
 
@@ -243,7 +243,7 @@ void FilterEffect::copyUnmultipliedImage(ByteArray* destination, const IntRect&
             m_unmultipliedImageResult = m_imageBufferResult->getUnmultipliedImageData(IntRect(IntPoint(), m_absolutePaintRect.size()));
         else {
             ASSERT(isFilterSizeValid(m_absolutePaintRect));
-            m_unmultipliedImageResult = ByteArray::create(m_absolutePaintRect.width() * m_absolutePaintRect.height() * 4);
+            m_unmultipliedImageResult = Uint8ClampedArray::createUninitialized(m_absolutePaintRect.width() * m_absolutePaintRect.height() * 4);
             unsigned char* sourceComponent = m_premultipliedImageResult->data();
             unsigned char* destinationComponent = m_unmultipliedImageResult->data();
             unsigned char* end = sourceComponent + (m_absolutePaintRect.width() * m_absolutePaintRect.height() * 4);
@@ -267,7 +267,7 @@ void FilterEffect::copyUnmultipliedImage(ByteArray* destination, const IntRect&
     copyImageBytes(m_unmultipliedImageResult.get(), destination, rect);
 }
 
-void FilterEffect::copyPremultipliedImage(ByteArray* destination, const IntRect& rect)
+void FilterEffect::copyPremultipliedImage(Uint8ClampedArray* destination, const IntRect& rect)
 {
     ASSERT(hasResult());
 
@@ -277,7 +277,7 @@ void FilterEffect::copyPremultipliedImage(ByteArray* destination, const IntRect&
             m_premultipliedImageResult = m_imageBufferResult->getPremultipliedImageData(IntRect(IntPoint(), m_absolutePaintRect.size()));
         else {
             ASSERT(isFilterSizeValid(m_absolutePaintRect));
-            m_premultipliedImageResult = ByteArray::create(m_absolutePaintRect.width() * m_absolutePaintRect.height() * 4);
+            m_premultipliedImageResult = Uint8ClampedArray::createUninitialized(m_absolutePaintRect.width() * m_absolutePaintRect.height() * 4);
             unsigned char* sourceComponent = m_unmultipliedImageResult->data();
             unsigned char* destinationComponent = m_premultipliedImageResult->data();
             unsigned char* end = sourceComponent + (m_absolutePaintRect.width() * m_absolutePaintRect.height() * 4);
@@ -308,7 +308,7 @@ ImageBuffer* FilterEffect::createImageBufferResult()
     return m_imageBufferResult.get();
 }
 
-ByteArray* FilterEffect::createUnmultipliedImageResult()
+Uint8ClampedArray* FilterEffect::createUnmultipliedImageResult()
 {
     // Only one result type is allowed.
     ASSERT(!hasResult());
@@ -316,11 +316,11 @@ ByteArray* FilterEffect::createUnmultipliedImageResult()
 
     if (m_absolutePaintRect.isEmpty())
         return 0;
-    m_unmultipliedImageResult = ByteArray::create(m_absolutePaintRect.width() * m_absolutePaintRect.height() * 4);
+    m_unmultipliedImageResult = Uint8ClampedArray::createUninitialized(m_absolutePaintRect.width() * m_absolutePaintRect.height() * 4);
     return m_unmultipliedImageResult.get();
 }
 
-ByteArray* FilterEffect::createPremultipliedImageResult()
+Uint8ClampedArray* FilterEffect::createPremultipliedImageResult()
 {
     // Only one result type is allowed.
     ASSERT(!hasResult());
@@ -328,7 +328,7 @@ ByteArray* FilterEffect::createPremultipliedImageResult()
 
     if (m_absolutePaintRect.isEmpty())
         return 0;
-    m_premultipliedImageResult = ByteArray::create(m_absolutePaintRect.width() * m_absolutePaintRect.height() * 4);
+    m_premultipliedImageResult = Uint8ClampedArray::createUninitialized(m_absolutePaintRect.width() * m_absolutePaintRect.height() * 4);
     return m_premultipliedImageResult.get();
 }
 
index 8b4ad6f..c99cd50 100644 (file)
 #include "FloatRect.h"
 #include "IntRect.h"
 
-#include <wtf/ByteArray.h>
 #include <wtf/PassOwnPtr.h>
 #include <wtf/RefCounted.h>
 #include <wtf/RefPtr.h>
+#include <wtf/Uint8ClampedArray.h>
 #include <wtf/Vector.h>
 
 static const float kMaxFilterSize = 5000.0f;
@@ -56,10 +56,10 @@ public:
 
     void clearResult();
     ImageBuffer* asImageBuffer();
-    PassRefPtr<ByteArray> asUnmultipliedImage(const IntRect&);
-    PassRefPtr<ByteArray> asPremultipliedImage(const IntRect&);
-    void copyUnmultipliedImage(ByteArray* destination, const IntRect&);
-    void copyPremultipliedImage(ByteArray* destination, const IntRect&);
+    PassRefPtr<Uint8ClampedArray> asUnmultipliedImage(const IntRect&);
+    PassRefPtr<Uint8ClampedArray> asPremultipliedImage(const IntRect&);
+    void copyUnmultipliedImage(Uint8ClampedArray* destination, const IntRect&);
+    void copyPremultipliedImage(Uint8ClampedArray* destination, const IntRect&);
 
     FilterEffectVector& inputEffects() { return m_inputEffects; }
     FilterEffect* inputEffect(unsigned) const;
@@ -133,8 +133,8 @@ protected:
     FilterEffect(Filter*);
 
     ImageBuffer* createImageBufferResult();
-    ByteArray* createUnmultipliedImageResult();
-    ByteArray* createPremultipliedImageResult();
+    Uint8ClampedArray* createUnmultipliedImageResult();
+    Uint8ClampedArray* createPremultipliedImageResult();
 
     // Return true if the filter will only operate correctly on valid RGBA values, with
     // alpha in [0,255] and each color component in [0, alpha].
@@ -145,8 +145,8 @@ protected:
 
 private:
     OwnPtr<ImageBuffer> m_imageBufferResult;
-    RefPtr<ByteArray> m_unmultipliedImageResult;
-    RefPtr<ByteArray> m_premultipliedImageResult;
+    RefPtr<Uint8ClampedArray> m_unmultipliedImageResult;
+    RefPtr<Uint8ClampedArray> m_premultipliedImageResult;
     FilterEffectVector m_inputEffects;
 
     bool m_alphaImage;
@@ -159,7 +159,7 @@ private:
     Filter* m_filter;
     
 private:
-    inline void copyImageBytes(ByteArray* source, ByteArray* destination, const IntRect&);
+    inline void copyImageBytes(Uint8ClampedArray* source, Uint8ClampedArray* destination, const IntRect&);
 
     // The following member variables are SVG specific and will move to RenderSVGResourceFilterPrimitive.
     // See bug https://bugs.webkit.org/show_bug.cgi?id=45614.
index 96037aa..1fb3752 100644 (file)
@@ -54,7 +54,7 @@ void neonDrawAllChannelGaussianBlur(unsigned char* source, unsigned char* destin
 void neonDrawAlphaChannelGaussianBlur(unsigned char* source, unsigned char* destination, FEGaussianBlurPaintingDataForNeon*);
 }
 
-inline void FEGaussianBlur::platformApplyNeon(ByteArray* srcPixelArray, ByteArray* tmpPixelArray, unsigned kernelSizeX, unsigned kernelSizeY, IntSize& paintSize)
+inline void FEGaussianBlur::platformApplyNeon(Uint8ClampedArray* srcPixelArray, Uint8ClampedArray* tmpPixelArray, unsigned kernelSizeX, unsigned kernelSizeY, IntSize& paintSize)
 {
     const int widthMultipliedByFour = 4 * paintSize.width();
     FEGaussianBlurPaintingDataForNeon argumentsX = {
@@ -89,7 +89,7 @@ inline void FEGaussianBlur::platformApplyNeon(ByteArray* srcPixelArray, ByteArra
             else
                 neonDrawAllChannelGaussianBlur(srcPixelArray->data(), tmpPixelArray->data(), &argumentsX);
         } else {
-            ByteArray* auxPixelArray = tmpPixelArray;
+            Uint8ClampedArray* auxPixelArray = tmpPixelArray;
             tmpPixelArray = srcPixelArray;
             srcPixelArray = auxPixelArray;
         }
@@ -102,7 +102,7 @@ inline void FEGaussianBlur::platformApplyNeon(ByteArray* srcPixelArray, ByteArra
             else
                 neonDrawAllChannelGaussianBlur(tmpPixelArray->data(), srcPixelArray->data(), &argumentsY);
         } else {
-            ByteArray* auxPixelArray = tmpPixelArray;
+            Uint8ClampedArray* auxPixelArray = tmpPixelArray;
             tmpPixelArray = srcPixelArray;
             srcPixelArray = auxPixelArray;
         }
index 90d2332..cb3a5b7 100644 (file)
@@ -150,7 +150,7 @@ PassRefPtr<ImageData> GraphicsContext3D::paintRenderingResultsToImageData(Drawin
         return 0;
 
     RefPtr<ImageData> imageData = ImageData::create(IntSize(m_currentWidth, m_currentHeight));
-    unsigned char* pixels = imageData->data()->data()->data();
+    unsigned char* pixels = imageData->data()->data();
     int totalBytes = 4 * m_currentWidth * m_currentHeight;
 
     readRenderingResults(pixels, totalBytes);
index 5242302..b9b9ebf 100644 (file)
@@ -189,17 +189,17 @@ void ImageBuffer::platformTransformColorSpace(const Vector<int>& lookUpTable)
 }
 
 template <Multiply multiplied>
-PassRefPtr<ByteArray> getImageData(const IntRect& rect, const ImageBufferData& imageData, const IntSize& size)
+PassRefPtr<Uint8ClampedArray> getImageData(const IntRect& rect, const ImageBufferData& imageData, const IntSize& size)
 {
     float area = 4.0f * rect.width() * rect.height();
     if (area > static_cast<float>(std::numeric_limits<int>::max()))
         return 0;
 
-    RefPtr<ByteArray> result = ByteArray::create(rect.width() * rect.height() * 4);
+    RefPtr<Uint8ClampedArray> result = Uint8ClampedArray::createUninitialized(rect.width() * rect.height() * 4);
     unsigned char* data = result->data();
 
     if (rect.x() < 0 || rect.y() < 0 || rect.maxX() > size.width() || rect.maxY() > size.height())
-        memset(data, 0, result->length());
+        result->zeroFill();
 
     int originx = rect.x();
     int destx = 0;
@@ -271,12 +271,12 @@ PassRefPtr<ByteArray> getImageData(const IntRect& rect, const ImageBufferData& i
     return result.release();
 }
 
-PassRefPtr<ByteArray> ImageBuffer::getUnmultipliedImageData(const IntRect& rect, CoordinateSystem) const
+PassRefPtr<Uint8ClampedArray> ImageBuffer::getUnmultipliedImageData(const IntRect& rect, CoordinateSystem) const
 {
     return getImageData<Unmultiplied>(rect, m_data, m_size);
 }
 
-PassRefPtr<ByteArray> ImageBuffer::getPremultipliedImageData(const IntRect& rect, CoordinateSystem) const
+PassRefPtr<Uint8ClampedArray> ImageBuffer::getPremultipliedImageData(const IntRect& rect, CoordinateSystem) const
 {
     return getImageData<Premultiplied>(rect, m_data, m_size);
 }
@@ -297,7 +297,7 @@ static inline unsigned int premultiplyABGRtoARGB(unsigned int x)
     return x;
 }
 
-void ImageBuffer::putByteArray(Multiply multiplied, ByteArray* source, const IntSize& sourceSize, const IntRect& sourceRect, const IntPoint& destPoint, CoordinateSystem)
+void ImageBuffer::putByteArray(Multiply multiplied, Uint8ClampedArray* source, const IntSize& sourceSize, const IntRect& sourceRect, const IntPoint& destPoint, CoordinateSystem)
 {
     ASSERT(sourceRect.width() > 0);
     ASSERT(sourceRect.height() > 0);
index 3644131..8ebf76e 100644 (file)
@@ -230,14 +230,14 @@ void ImageBuffer::platformTransformColorSpace(const Vector<int>& lookUpTable)
 }
 
 template <Multiply multiplied>
-PassRefPtr<ByteArray> getImageData(const IntRect& rect, SkCanvas* canvas,
+PassRefPtr<Uint8ClampedArray> getImageData(const IntRect& rect, SkCanvas* canvas,
                                    const IntSize& size)
 {
     float area = 4.0f * rect.width() * rect.height();
     if (area > static_cast<float>(std::numeric_limits<int>::max()))
         return 0;
 
-    RefPtr<ByteArray> result = ByteArray::create(rect.width() * rect.height() * 4);
+    RefPtr<Uint8ClampedArray> result = Uint8ClampedArray::createUninitialized(rect.width() * rect.height() * 4);
 
     unsigned char* data = result->data();
 
@@ -245,7 +245,7 @@ PassRefPtr<ByteArray> getImageData(const IntRect& rect, SkCanvas* canvas,
         || rect.y() < 0
         || rect.maxX() > size.width()
         || rect.maxY() > size.height())
-        memset(data, 0, result->length());
+        result->zeroFill();
 
     unsigned destBytesPerRow = 4 * rect.width();
     SkBitmap destBitmap;
@@ -262,17 +262,17 @@ PassRefPtr<ByteArray> getImageData(const IntRect& rect, SkCanvas* canvas,
     return result.release();
 }
 
-PassRefPtr<ByteArray> ImageBuffer::getUnmultipliedImageData(const IntRect& rect, CoordinateSystem) const
+PassRefPtr<Uint8ClampedArray> ImageBuffer::getUnmultipliedImageData(const IntRect& rect, CoordinateSystem) const
 {
     return getImageData<Unmultiplied>(rect, context()->platformContext()->canvas(), m_size);
 }
 
-PassRefPtr<ByteArray> ImageBuffer::getPremultipliedImageData(const IntRect& rect, CoordinateSystem) const
+PassRefPtr<Uint8ClampedArray> ImageBuffer::getPremultipliedImageData(const IntRect& rect, CoordinateSystem) const
 {
     return getImageData<Premultiplied>(rect, context()->platformContext()->canvas(), m_size);
 }
 
-void ImageBuffer::putByteArray(Multiply multiplied, ByteArray* source, const IntSize& sourceSize, const IntRect& sourceRect, const IntPoint& destPoint, CoordinateSystem)
+void ImageBuffer::putByteArray(Multiply multiplied, Uint8ClampedArray* source, const IntSize& sourceSize, const IntRect& sourceRect, const IntPoint& destPoint, CoordinateSystem)
 {
     SkCanvas* canvas = context()->platformContext()->canvas();
     ASSERT(sourceRect.width() > 0);
index 894ebbf..59eb4a6 100644 (file)
@@ -47,7 +47,6 @@
 #include "CairoUtilities.h"
 #include "RefPtrCairo.h"
 #include <cairo.h>
-#include <wtf/ByteArray.h>
 #endif
 
 #define GL_CMD(...) do { __VA_ARGS__; ASSERT_ARG(__VA_ARGS__, !glGetError()); } while (0)
index 28c7209..9c4225a 100644 (file)
@@ -121,9 +121,9 @@ void ImageBuffer::drawPattern(GraphicsContext* context, const FloatRect& srcRect
 }
 
 template <bool premultiplied>
-static PassRefPtr<ByteArray> getImageData(const IntRect& rect, const SharedBitmap* bitmap)
+static PassRefPtr<Uint8ClampedArray> getImageData(const IntRect& rect, const SharedBitmap* bitmap)
 {
-    RefPtr<ByteArray> imageData = ByteArray::create(rect.width() * rect.height() * 4);
+    RefPtr<Uint8ClampedArray> imageData = Uint8ClampedArray::createUninitialized(rect.width() * rect.height() * 4);
 
     const unsigned char* src = static_cast<const unsigned char*>(bitmap->bytes());
     if (!src)
@@ -135,7 +135,7 @@ static PassRefPtr<ByteArray> getImageData(const IntRect& rect, const SharedBitma
         return imageData.release();
 
     unsigned char* dst = imageData->data();
-    memset(dst, 0, imageData->length());
+    imageData->zeroFill();
     src += (sourceRect.y() * bitmap->width() + sourceRect.x()) * 4;
     dst += ((sourceRect.y() - rect.y()) * rect.width() + sourceRect.x() - rect.x()) * 4;
     int bytesToCopy = sourceRect.width() * 4;
@@ -170,17 +170,17 @@ static PassRefPtr<ByteArray> getImageData(const IntRect& rect, const SharedBitma
     return imageData.release();
 }
 
-PassRefPtr<ByteArray> ImageBuffer::getUnmultipliedImageData(const IntRect& rect, CoordinateSystem) const
+PassRefPtr<Uint8ClampedArray> ImageBuffer::getUnmultipliedImageData(const IntRect& rect, CoordinateSystem) const
 {
     return getImageData<false>(rect, m_data.m_bitmap.get());
 }
 
-PassRefPtr<ByteArray> ImageBuffer::getPremultipliedImageData(const IntRect& rect, CoordinateSystem) const
+PassRefPtr<Uint8ClampedArray> ImageBuffer::getPremultipliedImageData(const IntRect& rect, CoordinateSystem) const
 {
     return getImageData<true>(rect, m_data.m_bitmap.get());
 }
 
-void ImageBuffer::putByteArray(Multiply multiplied, ByteArray* source, const IntSize& sourceSize, const IntRect& sourceRect, const IntPoint& destPoint, CoordinateSystem)
+void ImageBuffer::putByteArray(Multiply multiplied, Uint8ClampedArray* source, const IntSize& sourceSize, const IntRect& sourceRect, const IntPoint& destPoint, CoordinateSystem)
 {
     SharedBitmap* bitmap = m_data.m_bitmap.get();
     unsigned char* dst = (unsigned char*)bitmap->bytes();
index 6b8e2d3..0cdbc7b 100644 (file)
@@ -122,19 +122,19 @@ GraphicsContext* ImageBuffer::context() const
     return m_context.get();
 }
 
-PassRefPtr<ByteArray> ImageBuffer::getUnmultipliedImageData(const IntRect& rect, CoordinateSystem) const
+PassRefPtr<Uint8ClampedArray> ImageBuffer::getUnmultipliedImageData(const IntRect& rect, CoordinateSystem) const
 {
     notImplemented();
     return 0;
 }
 
-PassRefPtr<ByteArray> ImageBuffer::getPremultipliedImageData(const IntRect& rect, CoordinateSystem) const
+PassRefPtr<Uint8ClampedArray> ImageBuffer::getPremultipliedImageData(const IntRect& rect, CoordinateSystem) const
 {
     notImplemented();
     return 0;
 }
 
-void ImageBuffer::putByteArray(Multiply multiplied, ByteArray* source, const IntSize& sourceSize, const IntRect& sourceRect, const IntPoint& destPoint, CoordinateSystem)
+void ImageBuffer::putByteArray(Multiply multiplied, Uint8ClampedArray* source, const IntSize& sourceSize, const IntRect& sourceRect, const IntPoint& destPoint, CoordinateSystem)
 {
     notImplemented();
 }
index 821e1da..22d514a 100644 (file)
@@ -195,7 +195,7 @@ bool JPEGImageEncoder::encode(const SkBitmap& bitmap, int quality, Vector<unsign
 
 bool JPEGImageEncoder::encode(const ImageData& imageData, int quality, Vector<unsigned char>* output)
 {
-    return encodePixels(imageData.size(), imageData.data()->data()->data(), false, quality, output);
+    return encodePixels(imageData.size(), imageData.data()->data(), false, quality, output);
 }
 
 } // namespace WebCore
index 5c1162b..eacaa7c 100644 (file)
@@ -126,7 +126,7 @@ bool PNGImageEncoder::encode(const SkBitmap& bitmap, Vector<unsigned char>* outp
 
 bool PNGImageEncoder::encode(const ImageData& imageData, Vector<unsigned char>* output)
 {
-    return encodePixels(imageData.size(), imageData.data()->data()->data(), false, output);
+    return encodePixels(imageData.size(), imageData.data()->data(), false, output);
 }
 
 } // namespace WebCore
index 9cb24fc..ebc299d 100644 (file)
@@ -130,7 +130,7 @@ bool WEBPImageEncoder::encode(const SkBitmap& bitmap, int quality, Vector<unsign
 
 bool WEBPImageEncoder::encode(const ImageData& imageData, int quality, Vector<unsigned char>* output)
 {
-    return encodePixels(imageData.size(), imageData.data()->data()->data(), false, quality, output);
+    return encodePixels(imageData.size(), imageData.data()->data(), false, quality, output);
 }
 
 } // namespace WebCore
index 2178cd5..7cb9afc 100644 (file)
@@ -1,3 +1,15 @@
+2012-04-23  Kenneth Russell  <kbr@google.com>
+
+        Change ImageData to reference Uint8ClampedArray rather than CanvasPixelArray
+        https://bugs.webkit.org/show_bug.cgi?id=73011
+
+        Reviewed by Oliver Hunt.
+
+        * src/GraphicsContext3DChromium.cpp:
+        (WebCore::GraphicsContext3DPrivate::paintRenderingResultsToImageData):
+        * src/WebViewImpl.cpp:
+        (WebKit::WebViewImpl::doPixelReadbackToCanvas):
+
 2012-04-23  Kent Tamura  <tkent@chromium.org>
 
         Crash when the page with a calendar picker is scrolled
index fbea64a..60919a2 100644 (file)
@@ -318,7 +318,7 @@ PassRefPtr<ImageData> GraphicsContext3DPrivate::paintRenderingResultsToImageData
     getDrawingParameters(drawingBuffer, m_impl.get(), &framebufferId, &width, &height);
 
     RefPtr<ImageData> imageData = ImageData::create(IntSize(width, height));
-    unsigned char* pixels = imageData->data()->data()->data();
+    unsigned char* pixels = imageData->data()->data();
     size_t bufferSize = 4 * width * height;
 
     m_impl->readBackFramebuffer(pixels, bufferSize, framebufferId, width, height);
index 45e9fbd..88e4bd8 100644 (file)
 #include <public/WebLayerTreeView.h>
 #include <public/WebPoint.h>
 #include <public/WebRect.h>
-#include <wtf/ByteArray.h>
 #include <wtf/CurrentTime.h>
 #include <wtf/MainThread.h>
 #include <wtf/RefPtr.h>
+#include <wtf/Uint8ClampedArray.h>
 
 #if ENABLE(GESTURE_EVENTS)
 #include "PlatformGestureEvent.h"
@@ -1477,7 +1477,7 @@ void WebViewImpl::doPixelReadbackToCanvas(WebCanvas* canvas, const IntRect& rect
     IntRect invertRect(rect.x(), bitmapHeight - rect.maxY(), rect.width(), rect.height());
 
     OwnPtr<ImageBuffer> imageBuffer(ImageBuffer::create(rect.size()));
-    RefPtr<ByteArray> pixelArray(ByteArray::create(rect.width() * rect.height() * 4));
+    RefPtr<Uint8ClampedArray> pixelArray(Uint8ClampedArray::createUninitialized(rect.width() * rect.height() * 4));
     if (imageBuffer && pixelArray) {
         m_layerTreeView.compositeAndReadback(pixelArray->data(), invertRect);
         imageBuffer->putByteArray(Premultiplied, pixelArray.get(), rect.size(), IntRect(IntPoint(), rect.size()), IntPoint());