| Differences between
and this patch
- Source/WebCore/ChangeLog +88 lines
Lines 1-3 Source/WebCore/ChangeLog_sec1
1
2021-05-14  Sam Weinig  <weinig@apple.com>
2
3
        Add support for creating/accessing/setting non-sRGB ImageData via canvas
4
        https://bugs.webkit.org/show_bug.cgi?id=225841
5
6
        Reviewed by NOBODY (OOPS!).
7
8
        Test: fast/canvas/canvas-color-space-display-p3-ImageData.html
9
10
        [WIP]
11
12
        * CMakeLists.txt:
13
        * DerivedSources-input.xcfilelist:
14
        * DerivedSources-output.xcfilelist:
15
        * DerivedSources.make:
16
        * Sources.txt:
17
        * WebCore.xcodeproj/project.pbxproj:
18
        * bindings/js/SerializedScriptValue.cpp:
19
        (WebCore::typedArrayElementSize):
20
        (WebCore::CloneSerializer::dumpIfTerminal):
21
        (WebCore::CloneSerializer::write):
22
        (WebCore::CloneDeserializer::read):
23
        (WebCore::CloneDeserializer::getJSValue):
24
        (WebCore::CloneDeserializer::readImageBitmap):
25
        (WebCore::CloneDeserializer::readTerminal):
26
        * html/ImageData.cpp:
27
        (WebCore::computeDataSize):
28
        (WebCore::ImageData::computeColorSpace):
29
        (WebCore::ImageData::create):
30
        (WebCore::ImageData::createUninitialized):
31
        (WebCore::ImageData::ImageData):
32
        (WebCore::ImageData::pixelBuffer const):
33
        (WebCore::ImageData::dataSize): Deleted.
34
        (WebCore::ImageData::deepClone const): Deleted.
35
        * html/ImageData.h:
36
        (WebCore::ImageData::size const):
37
        (WebCore::ImageData::width const):
38
        (WebCore::ImageData::height const):
39
        (WebCore::ImageData::data const):
40
        (WebCore::ImageData::colorSpace const):
41
        (WebCore::ImageData::pixelBuffer const): Deleted.
42
        * html/ImageData.idl:
43
        * html/ImageDataSettings.h: Added.
44
        * html/ImageDataSettings.idl: Added.
45
        * html/OffscreenCanvas.cpp:
46
        (WebCore::OffscreenCanvas::getContext):
47
        * html/canvas/CanvasImageData.idl:
48
        * html/canvas/CanvasRenderingContext2D.cpp:
49
        (WebCore::CanvasRenderingContext2D::CanvasRenderingContext2D):
50
        (WebCore::CanvasRenderingContext2D::pixelFormat const): Deleted.
51
        (WebCore::CanvasRenderingContext2D::colorSpace const): Deleted.
52
        * html/canvas/CanvasRenderingContext2D.h:
53
        * html/canvas/CanvasRenderingContext2DBase.cpp:
54
        (WebCore::CanvasRenderingContext2DBase::CanvasRenderingContext2DBase):
55
        (WebCore::initializeEmptyImageData):
56
        (WebCore::CanvasRenderingContext2DBase::createImageData const):
57
        (WebCore::CanvasRenderingContext2DBase::getImageData const):
58
        (WebCore::CanvasRenderingContext2DBase::pixelFormat const):
59
        (WebCore::CanvasRenderingContext2DBase::colorSpace const):
60
        (WebCore::createEmptyImageData): Deleted.
61
        * html/canvas/CanvasRenderingContext2DBase.h:
62
        (WebCore::CanvasRenderingContext2DBase::getContextAttributes const):
63
        * html/canvas/OffscreenCanvasRenderingContext2D.cpp:
64
        (WebCore::OffscreenCanvasRenderingContext2D::OffscreenCanvasRenderingContext2D):
65
        * html/canvas/OffscreenCanvasRenderingContext2D.h:
66
        * html/canvas/PaintRenderingContext2D.cpp:
67
        (WebCore::PaintRenderingContext2D::PaintRenderingContext2D):
68
        * html/canvas/PredefinedColorSpace.cpp:
69
        (WebCore::toPredefinedColorSpace):
70
        * html/canvas/PredefinedColorSpace.h:
71
        * inspector/InspectorCanvas.cpp:
72
        (WebCore::InspectorCanvas::processArgument):
73
        * inspector/InspectorCanvasCallTracer.cpp:
74
        * inspector/InspectorCanvasCallTracer.h:
75
        * platform/graphics/ImageBufferBackend.cpp:
76
        (WebCore::ImageBufferBackend::getPixelBuffer const):
77
        (WebCore::ImageBufferBackend::putPixelBuffer):
78
        * platform/graphics/PixelBuffer.cpp:
79
        (WebCore::PixelBuffer::tryCreate):
80
        (WebCore::PixelBuffer::PixelBuffer):
81
        * platform/graphics/PixelBuffer.h:
82
        (WebCore::PixelBuffer::takeData):
83
        * platform/graphics/PixelBufferConversion.cpp:
84
        (WebCore::convertImagePixelsAccelerated):
85
        * testing/Internals.cpp:
86
        (WebCore::Internals::videoSampleAvailable):
87
        (WebCore::Internals::loadArtworkImage):
88
1
2021-05-14  Sam Weinig  <weinig@apple.com>
89
2021-05-14  Sam Weinig  <weinig@apple.com>
2
90
3
        Use PixelBufferFormat to specify ImageBuffer::getPixelData destination format allowing for more control over data conversion
91
        Use PixelBufferFormat to specify ImageBuffer::getPixelData destination format allowing for more control over data conversion
- Source/WebCore/CMakeLists.txt +1 lines
Lines 1024-1029 set(WebCore_NON_SVG_IDL_FILES Source/WebCore/CMakeLists.txt_sec1
1024
    html/ImageBitmap.idl
1024
    html/ImageBitmap.idl
1025
    html/ImageBitmapOptions.idl
1025
    html/ImageBitmapOptions.idl
1026
    html/ImageData.idl
1026
    html/ImageData.idl
1027
    html/ImageDataSettings.idl
1027
    html/MediaController.idl
1028
    html/MediaController.idl
1028
    html/MediaEncryptedEvent.idl
1029
    html/MediaEncryptedEvent.idl
1029
    html/MediaError.idl
1030
    html/MediaError.idl
- Source/WebCore/DerivedSources-input.xcfilelist +1 lines
Lines 1036-1041 $(PROJECT_DIR)/html/HTMLVideoElement.idl Source/WebCore/DerivedSources-input.xcfilelist_sec1
1036
$(PROJECT_DIR)/html/ImageBitmap.idl
1036
$(PROJECT_DIR)/html/ImageBitmap.idl
1037
$(PROJECT_DIR)/html/ImageBitmapOptions.idl
1037
$(PROJECT_DIR)/html/ImageBitmapOptions.idl
1038
$(PROJECT_DIR)/html/ImageData.idl
1038
$(PROJECT_DIR)/html/ImageData.idl
1039
$(PROJECT_DIR)/html/ImageDataSettings.idl
1039
$(PROJECT_DIR)/html/MediaController.idl
1040
$(PROJECT_DIR)/html/MediaController.idl
1040
$(PROJECT_DIR)/html/MediaEncryptedEvent.idl
1041
$(PROJECT_DIR)/html/MediaEncryptedEvent.idl
1041
$(PROJECT_DIR)/html/MediaError.idl
1042
$(PROJECT_DIR)/html/MediaError.idl
- Source/WebCore/DerivedSources-output.xcfilelist +2 lines
Lines 1180-1185 $(BUILT_PRODUCTS_DIR)/DerivedSources/Web Source/WebCore/DerivedSources-output.xcfilelist_sec1
1180
$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSImageBitmapRenderingContextSettings.h
1180
$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSImageBitmapRenderingContextSettings.h
1181
$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSImageData.cpp
1181
$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSImageData.cpp
1182
$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSImageData.h
1182
$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSImageData.h
1183
$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSImageDataSettings.cpp
1184
$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSImageDataSettings.h
1183
$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSImageSmoothingQuality.cpp
1185
$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSImageSmoothingQuality.cpp
1184
$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSImageSmoothingQuality.h
1186
$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSImageSmoothingQuality.h
1185
$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSInnerHTML.cpp
1187
$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSInnerHTML.cpp
- Source/WebCore/DerivedSources.make +1 lines
Lines 897-902 JS_BINDING_IDLS := \ Source/WebCore/DerivedSources.make_sec1
897
    $(WebCore)/html/ImageBitmap.idl \
897
    $(WebCore)/html/ImageBitmap.idl \
898
    $(WebCore)/html/ImageBitmapOptions.idl \
898
    $(WebCore)/html/ImageBitmapOptions.idl \
899
    $(WebCore)/html/ImageData.idl \
899
    $(WebCore)/html/ImageData.idl \
900
    $(WebCore)/html/ImageDataSettings.idl \
900
    $(WebCore)/html/MediaController.idl \
901
    $(WebCore)/html/MediaController.idl \
901
    $(WebCore)/html/MediaEncryptedEvent.idl \
902
    $(WebCore)/html/MediaEncryptedEvent.idl \
902
    $(WebCore)/html/MediaError.idl \
903
    $(WebCore)/html/MediaError.idl \
- Source/WebCore/Sources.txt +1 lines
Lines 3210-3215 JSImageBitmapOptions.cpp Source/WebCore/Sources.txt_sec1
3210
JSImageBitmapRenderingContext.cpp
3210
JSImageBitmapRenderingContext.cpp
3211
JSImageBitmapRenderingContextSettings.cpp
3211
JSImageBitmapRenderingContextSettings.cpp
3212
JSImageData.cpp
3212
JSImageData.cpp
3213
JSImageDataSettings.cpp
3213
JSImageSmoothingQuality.cpp
3214
JSImageSmoothingQuality.cpp
3214
JSInputEvent.cpp
3215
JSInputEvent.cpp
3215
JSInspectorAuditAccessibilityObject.cpp
3216
JSInspectorAuditAccessibilityObject.cpp
- Source/WebCore/WebCore.xcodeproj/project.pbxproj +6 lines
Lines 4100-4105 Source/WebCore/WebCore.xcodeproj/project.pbxproj_sec1
4100
		BC96DB430F3A880E00573CB3 /* RenderBoxModelObject.h in Headers */ = {isa = PBXBuildFile; fileRef = BC96DB420F3A880E00573CB3 /* RenderBoxModelObject.h */; settings = {ATTRIBUTES = (Private, ); }; };
4100
		BC96DB430F3A880E00573CB3 /* RenderBoxModelObject.h in Headers */ = {isa = PBXBuildFile; fileRef = BC96DB420F3A880E00573CB3 /* RenderBoxModelObject.h */; settings = {ATTRIBUTES = (Private, ); }; };
4101
		BC97E23A109144950010D361 /* HTMLAllCollection.h in Headers */ = {isa = PBXBuildFile; fileRef = BC97E238109144950010D361 /* HTMLAllCollection.h */; };
4101
		BC97E23A109144950010D361 /* HTMLAllCollection.h in Headers */ = {isa = PBXBuildFile; fileRef = BC97E238109144950010D361 /* HTMLAllCollection.h */; };
4102
		BC97E413109154FA0010D361 /* JSHTMLAllCollection.h in Headers */ = {isa = PBXBuildFile; fileRef = BC97E411109154FA0010D361 /* JSHTMLAllCollection.h */; };
4102
		BC97E413109154FA0010D361 /* JSHTMLAllCollection.h in Headers */ = {isa = PBXBuildFile; fileRef = BC97E411109154FA0010D361 /* JSHTMLAllCollection.h */; };
4103
		BCA088F5264E1C08003E2A6C /* ImageDataSettings.h in Headers */ = {isa = PBXBuildFile; fileRef = BCA088F2264E1BF9003E2A6C /* ImageDataSettings.h */; settings = {ATTRIBUTES = (Private, ); }; };
4103
		BCA169A30BFD55B40019CA76 /* JSHTMLTableCaptionElement.h in Headers */ = {isa = PBXBuildFile; fileRef = BCA169A10BFD55B40019CA76 /* JSHTMLTableCaptionElement.h */; };
4104
		BCA169A30BFD55B40019CA76 /* JSHTMLTableCaptionElement.h in Headers */ = {isa = PBXBuildFile; fileRef = BCA169A10BFD55B40019CA76 /* JSHTMLTableCaptionElement.h */; };
4104
		BCA257151293C010007A263D /* VerticalPositionCache.h in Headers */ = {isa = PBXBuildFile; fileRef = BCA257141293C010007A263D /* VerticalPositionCache.h */; };
4105
		BCA257151293C010007A263D /* VerticalPositionCache.h in Headers */ = {isa = PBXBuildFile; fileRef = BCA257141293C010007A263D /* VerticalPositionCache.h */; };
4105
		BCA2B061105047600043BD1C /* UserScript.h in Headers */ = {isa = PBXBuildFile; fileRef = BCA2B0601050475F0043BD1C /* UserScript.h */; settings = {ATTRIBUTES = (Private, ); }; };
4106
		BCA2B061105047600043BD1C /* UserScript.h in Headers */ = {isa = PBXBuildFile; fileRef = BCA2B0601050475F0043BD1C /* UserScript.h */; settings = {ATTRIBUTES = (Private, ); }; };
Lines 14334-14339 Source/WebCore/WebCore.xcodeproj/project.pbxproj_sec2
14334
		BC9A6142146859D9006057FD /* EventNames.in */ = {isa = PBXFileReference; lastKnownFileType = text; path = EventNames.in; sourceTree = "<group>"; };
14335
		BC9A6142146859D9006057FD /* EventNames.in */ = {isa = PBXFileReference; lastKnownFileType = text; path = EventNames.in; sourceTree = "<group>"; };
14335
		BC9A6145146859D9006057FD /* make_event_factory.pl */ = {isa = PBXFileReference; lastKnownFileType = text.script.perl; path = make_event_factory.pl; sourceTree = "<group>"; };
14336
		BC9A6145146859D9006057FD /* make_event_factory.pl */ = {isa = PBXFileReference; lastKnownFileType = text.script.perl; path = make_event_factory.pl; sourceTree = "<group>"; };
14336
		BC9A6146146859D9006057FD /* make_names.pl */ = {isa = PBXFileReference; lastKnownFileType = text.script.perl; path = make_names.pl; sourceTree = "<group>"; };
14337
		BC9A6146146859D9006057FD /* make_names.pl */ = {isa = PBXFileReference; lastKnownFileType = text.script.perl; path = make_names.pl; sourceTree = "<group>"; };
14338
		BCA088F2264E1BF9003E2A6C /* ImageDataSettings.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ImageDataSettings.h; sourceTree = "<group>"; };
14339
		BCA088F4264E1BF9003E2A6C /* ImageDataSettings.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = ImageDataSettings.idl; sourceTree = "<group>"; };
14337
		BCA169A00BFD55B40019CA76 /* JSHTMLTableCaptionElement.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = JSHTMLTableCaptionElement.cpp; sourceTree = "<group>"; };
14340
		BCA169A00BFD55B40019CA76 /* JSHTMLTableCaptionElement.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = JSHTMLTableCaptionElement.cpp; sourceTree = "<group>"; };
14338
		BCA169A10BFD55B40019CA76 /* JSHTMLTableCaptionElement.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = JSHTMLTableCaptionElement.h; sourceTree = "<group>"; };
14341
		BCA169A10BFD55B40019CA76 /* JSHTMLTableCaptionElement.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = JSHTMLTableCaptionElement.h; sourceTree = "<group>"; };
14339
		BCA257141293C010007A263D /* VerticalPositionCache.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VerticalPositionCache.h; sourceTree = "<group>"; };
14342
		BCA257141293C010007A263D /* VerticalPositionCache.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VerticalPositionCache.h; sourceTree = "<group>"; };
Lines 23940-23945 Source/WebCore/WebCore.xcodeproj/project.pbxproj_sec3
23940
				A77979130D6B9D0C003851B9 /* ImageData.cpp */,
23943
				A77979130D6B9D0C003851B9 /* ImageData.cpp */,
23941
				A77979140D6B9D0C003851B9 /* ImageData.h */,
23944
				A77979140D6B9D0C003851B9 /* ImageData.h */,
23942
				A77979150D6B9D0C003851B9 /* ImageData.idl */,
23945
				A77979150D6B9D0C003851B9 /* ImageData.idl */,
23946
				BCA088F2264E1BF9003E2A6C /* ImageDataSettings.h */,
23947
				BCA088F4264E1BF9003E2A6C /* ImageDataSettings.idl */,
23943
				97205AB11239291000B17380 /* ImageDocument.cpp */,
23948
				97205AB11239291000B17380 /* ImageDocument.cpp */,
23944
				97205AB21239291000B17380 /* ImageDocument.h */,
23949
				97205AB21239291000B17380 /* ImageDocument.h */,
23945
				F55B3D8D1251F12D003EF269 /* ImageInputType.cpp */,
23950
				F55B3D8D1251F12D003EF269 /* ImageInputType.cpp */,
Lines 32919-32924 Source/WebCore/WebCore.xcodeproj/project.pbxproj_sec4
32919
				B2A10D910B3818BD00099AA4 /* ImageBufferPipe.h in Headers */,
32924
				B2A10D910B3818BD00099AA4 /* ImageBufferPipe.h in Headers */,
32920
				CD3E21DD2183444A00E66F55 /* ImageBufferUtilitiesCG.h in Headers */,
32925
				CD3E21DD2183444A00E66F55 /* ImageBufferUtilitiesCG.h in Headers */,
32921
				A779791A0D6B9D0C003851B9 /* ImageData.h in Headers */,
32926
				A779791A0D6B9D0C003851B9 /* ImageData.h in Headers */,
32927
				BCA088F5264E1C08003E2A6C /* ImageDataSettings.h in Headers */,
32922
				CD19FEA81F573972000C42FB /* ImageDecoder.h in Headers */,
32928
				CD19FEA81F573972000C42FB /* ImageDecoder.h in Headers */,
32923
				CD19FEAE1F574B6D000C42FB /* ImageDecoderAVFObjC.h in Headers */,
32929
				CD19FEAE1F574B6D000C42FB /* ImageDecoderAVFObjC.h in Headers */,
32924
				555B87ED1CAAF0AB00349425 /* ImageDecoderCG.h in Headers */,
32930
				555B87ED1CAAF0AB00349425 /* ImageDecoderCG.h in Headers */,
- Source/WebCore/bindings/js/SerializedScriptValue.cpp -12 / +6 lines
Lines 3141-3170 private: Source/WebCore/bindings/js/SerializedScriptValue.cpp_sec1
3141
            return JSValue();
3141
            return JSValue();
3142
        }
3142
        }
3143
3143
3144
        auto array = Uint8ClampedArray::tryCreate(WTFMove(arrayBuffer), 0, arrayBuffer->byteLength());
3145
        if (!array) {
3146
            fail();
3147
            return JSValue();
3148
        }
3149
3150
        IntSize logicalSize = IntSize(logicalWidth, logicalHeight);
3144
        IntSize logicalSize = IntSize(logicalWidth, logicalHeight);
3151
        IntSize imageDataSize = logicalSize;
3145
        IntSize imageDataSize = logicalSize;
3152
        imageDataSize.scale(resolutionScale);
3146
        imageDataSize.scale(resolutionScale);
3153
3147
3154
        // FIXME: Creating this ImageData is not necessary. We should skip right to creating a PixelBuffer directly.
3148
        auto buffer = ImageBitmap::createImageBuffer(*scriptExecutionContextFromExecState(m_lexicalGlobalObject), logicalSize, RenderingMode::Unaccelerated, resolutionScale);
3155
        auto imageData = ImageData::create(imageDataSize, array.releaseNonNull());
3149
        if (!buffer) {
3156
        if (!imageData) {
3157
            fail();
3150
            fail();
3158
            return JSValue();
3151
            return JSValue();
3159
        }
3152
        }
3160
3153
3161
        auto buffer = ImageBitmap::createImageBuffer(*scriptExecutionContextFromExecState(m_lexicalGlobalObject), logicalSize, RenderingMode::Unaccelerated, resolutionScale);
3154
        PixelBufferFormat format { AlphaPremultiplication::Premultiplied, PixelFormat::RGBA8, DestinationColorSpace::SRGB };
3162
        if (!buffer) {
3155
        auto pixelBuffer = PixelBuffer::tryCreate(format, imageDataSize, arrayBuffer.releaseNonNull());
3156
        if (!pixelBuffer) {
3163
            fail();
3157
            fail();
3164
            return JSValue();
3158
            return JSValue();
3165
        }
3159
        }
3166
3160
3167
        buffer->putPixelBuffer(imageData->pixelBuffer(), { IntPoint::zero(), logicalSize });
3161
        buffer->putPixelBuffer(WTFMove(*pixelBuffer), { IntPoint::zero(), logicalSize });
3168
3162
3169
        auto bitmap = ImageBitmap::create(ImageBitmapBacking(WTFMove(buffer), OptionSet<SerializationState>::fromRaw(serializationState)));
3163
        auto bitmap = ImageBitmap::create(ImageBitmapBacking(WTFMove(buffer), OptionSet<SerializationState>::fromRaw(serializationState)));
3170
        return getJSValue(bitmap);
3164
        return getJSValue(bitmap);
- Source/WebCore/html/ImageData.cpp -20 / +55 lines
Lines 35-41 Source/WebCore/html/ImageData.cpp_sec1
35
35
36
namespace WebCore {
36
namespace WebCore {
37
37
38
Checked<unsigned, RecordOverflow> ImageData::dataSize(const IntSize& size)
38
static Checked<unsigned, RecordOverflow> computeDataSize(const IntSize& size)
39
{
39
{
40
    Checked<unsigned, RecordOverflow> checkedDataSize = 4;
40
    Checked<unsigned, RecordOverflow> checkedDataSize = 4;
41
    checkedDataSize *= static_cast<unsigned>(size.width());
41
    checkedDataSize *= static_cast<unsigned>(size.width());
Lines 43-51 Checked<unsigned, RecordOverflow> ImageD Source/WebCore/html/ImageData.cpp_sec2
43
    return checkedDataSize;
43
    return checkedDataSize;
44
}
44
}
45
45
46
PredefinedColorSpace ImageData::computeColorSpace(Optional<ImageDataSettings> settings, PredefinedColorSpace defaultColorSpace)
47
{
48
    if (settings && settings->colorSpace)
49
        return *settings->colorSpace;
50
    return defaultColorSpace;
51
}
52
46
Ref<ImageData> ImageData::create(PixelBuffer&& pixelBuffer)
53
Ref<ImageData> ImageData::create(PixelBuffer&& pixelBuffer)
47
{
54
{
48
    return adoptRef(*new ImageData(WTFMove(pixelBuffer)));
55
    auto colorSpace = toPredefinedColorSpace(pixelBuffer.format().colorSpace);
56
    RELEASE_ASSERT(colorSpace);
57
    return adoptRef(*new ImageData(pixelBuffer.size(), pixelBuffer.takeData(), *colorSpace));
49
}
58
}
50
59
51
RefPtr<ImageData> ImageData::create(Optional<PixelBuffer>&& pixelBuffer)
60
RefPtr<ImageData> ImageData::create(Optional<PixelBuffer>&& pixelBuffer)
Lines 57-99 RefPtr<ImageData> ImageData::create(Opti Source/WebCore/html/ImageData.cpp_sec3
57
66
58
RefPtr<ImageData> ImageData::create(const IntSize& size)
67
RefPtr<ImageData> ImageData::create(const IntSize& size)
59
{
68
{
60
    auto dataSize = ImageData::dataSize(size);
69
    auto dataSize = computeDataSize(size);
61
    if (dataSize.hasOverflowed())
70
    if (dataSize.hasOverflowed())
62
        return nullptr;
71
        return nullptr;
63
    auto byteArray = Uint8ClampedArray::tryCreateUninitialized(dataSize.unsafeGet());
72
    auto byteArray = Uint8ClampedArray::tryCreateUninitialized(dataSize.unsafeGet());
64
    if (!byteArray)
73
    if (!byteArray)
65
        return nullptr;
74
        return nullptr;
66
    
75
    return adoptRef(*new ImageData(size, byteArray.releaseNonNull(), PredefinedColorSpace::SRGB));
67
    return adoptRef(*new ImageData({ { AlphaPremultiplication::Unpremultiplied, PixelFormat::RGBA8, DestinationColorSpace::SRGB }, size, byteArray.releaseNonNull() }));
68
}
76
}
69
77
70
RefPtr<ImageData> ImageData::create(const IntSize& size, Ref<Uint8ClampedArray>&& byteArray)
78
RefPtr<ImageData> ImageData::create(const IntSize& size, Ref<Uint8ClampedArray>&& byteArray, PredefinedColorSpace colorSpace)
71
{
79
{
72
    auto dataSize = ImageData::dataSize(size);
80
    auto dataSize = computeDataSize(size);
73
    if (dataSize.hasOverflowed() || dataSize.unsafeGet() > byteArray->length())
81
    if (dataSize.hasOverflowed() || dataSize.unsafeGet() != byteArray->length())
74
        return nullptr;
82
        return nullptr;
75
83
76
    return adoptRef(*new ImageData({ { AlphaPremultiplication::Unpremultiplied, PixelFormat::RGBA8, DestinationColorSpace::SRGB }, size, WTFMove(byteArray) }));
84
    return adoptRef(*new ImageData(size, WTFMove(byteArray), colorSpace));
77
}
85
}
78
86
79
ExceptionOr<Ref<ImageData>> ImageData::create(unsigned sw, unsigned sh)
87
ExceptionOr<Ref<ImageData>> ImageData::createUninitialized(unsigned rows, unsigned pixelsPerRow, PredefinedColorSpace defaultColorSpace, Optional<ImageDataSettings> settings)
88
{
89
    IntSize size(rows, pixelsPerRow);
90
    auto dataSize = computeDataSize(size);
91
    if (dataSize.hasOverflowed())
92
        return Exception { RangeError, "Cannot allocate a buffer of this size"_s };
93
94
    auto byteArray = Uint8ClampedArray::tryCreateUninitialized(dataSize.unsafeGet());
95
    if (!byteArray) {
96
        // FIXME: Does this need to be a "real" out of memory error with setOutOfMemoryError called on it?
97
        return Exception { RangeError, "Out of memory"_s };
98
    }
99
100
    auto colorSpace = computeColorSpace(settings, defaultColorSpace);
101
    return adoptRef(*new ImageData(size, byteArray.releaseNonNull(), colorSpace));
102
}
103
104
ExceptionOr<Ref<ImageData>> ImageData::create(unsigned sw, unsigned sh, Optional<ImageDataSettings> settings)
80
{
105
{
81
    if (!sw || !sh)
106
    if (!sw || !sh)
82
        return Exception { IndexSizeError };
107
        return Exception { IndexSizeError };
108
83
    IntSize size(sw, sh);
109
    IntSize size(sw, sh);
84
    auto dataSize = ImageData::dataSize(size);
110
    auto dataSize = computeDataSize(size);
85
    if (dataSize.hasOverflowed())
111
    if (dataSize.hasOverflowed())
86
        return Exception { RangeError, "Cannot allocate a buffer of this size"_s };
112
        return Exception { RangeError, "Cannot allocate a buffer of this size"_s };
113
87
    auto byteArray = Uint8ClampedArray::tryCreateUninitialized(dataSize.unsafeGet());
114
    auto byteArray = Uint8ClampedArray::tryCreateUninitialized(dataSize.unsafeGet());
88
    if (!byteArray) {
115
    if (!byteArray) {
89
        // FIXME: Does this need to be a "real" out of memory error with setOutOfMemoryError called on it?
116
        // FIXME: Does this need to be a "real" out of memory error with setOutOfMemoryError called on it?
90
        return Exception { RangeError, "Out of memory"_s };
117
        return Exception { RangeError, "Out of memory"_s };
91
    }
118
    }
92
    byteArray->zeroFill();
119
    byteArray->zeroFill();
93
    return adoptRef(*new ImageData({ { AlphaPremultiplication::Unpremultiplied, PixelFormat::RGBA8, DestinationColorSpace::SRGB }, size, byteArray.releaseNonNull() }));
120
121
    auto colorSpace = computeColorSpace(settings);
122
    return adoptRef(*new ImageData(size, byteArray.releaseNonNull(), colorSpace));
94
}
123
}
95
124
96
ExceptionOr<Ref<ImageData>> ImageData::create(Ref<Uint8ClampedArray>&& byteArray, unsigned sw, Optional<unsigned> sh)
125
ExceptionOr<Ref<ImageData>> ImageData::create(Ref<Uint8ClampedArray>&& byteArray, unsigned sw, Optional<unsigned> sh, Optional<ImageDataSettings> settings)
97
{
126
{
98
    unsigned length = byteArray->length();
127
    unsigned length = byteArray->length();
99
    if (!length || length % 4)
128
    if (!length || length % 4)
Lines 107-128 ExceptionOr<Ref<ImageData>> ImageData::c Source/WebCore/html/ImageData.cpp_sec4
107
    if (sh && sh.value() != height)
136
    if (sh && sh.value() != height)
108
        return Exception { IndexSizeError, "sh value is not equal to height"_s };
137
        return Exception { IndexSizeError, "sh value is not equal to height"_s };
109
138
110
    auto result = create(IntSize(sw, height), WTFMove(byteArray));
139
    IntSize size(sw, height);
111
    if (!result)
140
    auto dataSize = computeDataSize(size);
141
    if (dataSize.hasOverflowed() || dataSize.unsafeGet() != byteArray->length())
112
        return Exception { RangeError };
142
        return Exception { RangeError };
113
    return result.releaseNonNull();
143
144
    auto colorSpace = computeColorSpace(settings);
145
    return adoptRef(*new ImageData(size, WTFMove(byteArray), colorSpace));
114
}
146
}
115
147
116
ImageData::ImageData(PixelBuffer&& pixelBuffer)
148
ImageData::ImageData(const IntSize& size, Ref<JSC::Uint8ClampedArray>&& data, PredefinedColorSpace colorSpace)
117
    : m_pixelBuffer(WTFMove(pixelBuffer))
149
    : m_size(size)
150
    , m_data(WTFMove(data))
151
    , m_colorSpace(colorSpace)
118
{
152
{
119
}
153
}
120
154
121
ImageData::~ImageData() = default;
155
ImageData::~ImageData() = default;
122
156
123
Ref<ImageData> ImageData::deepClone() const
157
PixelBuffer ImageData::pixelBuffer() const
124
{
158
{
125
    return adoptRef(*new ImageData(m_pixelBuffer.deepClone()));
159
    PixelBufferFormat format { AlphaPremultiplication::Unpremultiplied, PixelFormat::RGBA8, toDestinationColorSpace(m_colorSpace) };
160
    return { format, m_size, m_data.get() };
126
}
161
}
127
162
128
TextStream& operator<<(TextStream& ts, const ImageData& imageData)
163
TextStream& operator<<(TextStream& ts, const ImageData& imageData)
- Source/WebCore/html/ImageData.h -14 / +22 lines
Lines 29-35 Source/WebCore/html/ImageData.h_sec1
29
#pragma once
29
#pragma once
30
30
31
#include "ExceptionOr.h"
31
#include "ExceptionOr.h"
32
#include "ImageDataSettings.h"
33
#include "IntSize.h"
32
#include "PixelBuffer.h"
34
#include "PixelBuffer.h"
35
#include "PredefinedColorSpace.h"
36
#include <JavaScriptCore/Uint8ClampedArray.h>
37
#include <wtf/Forward.h>
33
38
34
namespace WebCore {
39
namespace WebCore {
35
40
Lines 38-66 public: Source/WebCore/html/ImageData.h_sec2
38
    WEBCORE_EXPORT static Ref<ImageData> create(PixelBuffer&&);
43
    WEBCORE_EXPORT static Ref<ImageData> create(PixelBuffer&&);
39
    WEBCORE_EXPORT static RefPtr<ImageData> create(Optional<PixelBuffer>&&);
44
    WEBCORE_EXPORT static RefPtr<ImageData> create(Optional<PixelBuffer>&&);
40
    WEBCORE_EXPORT static RefPtr<ImageData> create(const IntSize&);
45
    WEBCORE_EXPORT static RefPtr<ImageData> create(const IntSize&);
41
    WEBCORE_EXPORT static RefPtr<ImageData> create(const IntSize&, Ref<Uint8ClampedArray>&&);
46
    WEBCORE_EXPORT static RefPtr<ImageData> create(const IntSize&, Ref<Uint8ClampedArray>&&, PredefinedColorSpace);
42
    WEBCORE_EXPORT static ExceptionOr<Ref<ImageData>> create(unsigned sw, unsigned sh);
47
    WEBCORE_EXPORT static ExceptionOr<Ref<ImageData>> createUninitialized(unsigned rows, unsigned pixelsPerRow, PredefinedColorSpace defaultColorSpace, Optional<ImageDataSettings> = WTF::nullopt);
43
    WEBCORE_EXPORT static ExceptionOr<Ref<ImageData>> create(Ref<Uint8ClampedArray>&&, unsigned sw, Optional<unsigned> sh);
48
    WEBCORE_EXPORT static ExceptionOr<Ref<ImageData>> create(unsigned sw, unsigned sh, Optional<ImageDataSettings>);
49
    WEBCORE_EXPORT static ExceptionOr<Ref<ImageData>> create(Ref<Uint8ClampedArray>&&, unsigned sw, Optional<unsigned> sh, Optional<ImageDataSettings>);
50
44
    WEBCORE_EXPORT ~ImageData();
51
    WEBCORE_EXPORT ~ImageData();
45
52
46
    const IntSize& size() const { return m_pixelBuffer.size(); }
53
    static PredefinedColorSpace computeColorSpace(Optional<ImageDataSettings>, PredefinedColorSpace defaultColorSpace = PredefinedColorSpace::SRGB);
47
    int width() const { return m_pixelBuffer.size().width(); }
48
    int height() const { return m_pixelBuffer.size().height(); }
49
54
50
    Uint8ClampedArray& data() const { return m_pixelBuffer.data(); }
55
    const IntSize& size() const { return m_size; }
51
56
52
    Ref<ImageData> deepClone() const;
57
    int width() const { return m_size.width(); }
58
    int height() const { return m_size.height(); }
59
    Uint8ClampedArray& data() const { return m_data.get(); }
60
    PredefinedColorSpace colorSpace() const { return m_colorSpace; }
53
61
54
    const PixelBuffer& pixelBuffer() const { return m_pixelBuffer; }
62
    PixelBuffer pixelBuffer() const;
55
63
56
private:
64
private:
57
    explicit ImageData(PixelBuffer&&);
65
    explicit ImageData(const IntSize&, Ref<JSC::Uint8ClampedArray>&&, PredefinedColorSpace);
58
59
    static Checked<unsigned, RecordOverflow> dataSize(const IntSize&);
60
66
61
    PixelBuffer m_pixelBuffer;
67
    IntSize m_size;
68
    Ref<JSC::Uint8ClampedArray> m_data;
69
    PredefinedColorSpace m_colorSpace;
62
};
70
};
63
71
64
WEBCORE_EXPORT WTF::TextStream& operator<<(WTF::TextStream&, const ImageData&);
72
WEBCORE_EXPORT TextStream& operator<<(TextStream&, const ImageData&);
65
73
66
} // namespace WebCore
74
} // namespace WebCore
- Source/WebCore/html/ImageData.idl -3 / +4 lines
Lines 1-5 Source/WebCore/html/ImageData.idl_sec1
1
/*
1
/*
2
 * Copyright (C) 2008-2009, 2016 Apple Inc. All rights reserved.
2
 * Copyright (C) 2008-2021 Apple Inc. All rights reserved.
3
 *
3
 *
4
 * Redistribution and use in source and binary forms, with or without
4
 * Redistribution and use in source and binary forms, with or without
5
 * modification, are permitted provided that the following conditions
5
 * modification, are permitted provided that the following conditions
Lines 32-41 Source/WebCore/html/ImageData.idl_sec2
32
    Exposed=(Window,Worker),
32
    Exposed=(Window,Worker),
33
    ImplementationLacksVTable
33
    ImplementationLacksVTable
34
] interface ImageData {
34
] interface ImageData {
35
    constructor(unsigned long sw, unsigned long sh);
35
    constructor(unsigned long sw, unsigned long sh, optional ImageDataSettings settings);
36
    constructor(Uint8ClampedArray data, unsigned long sw, optional unsigned long sh);
36
    constructor(Uint8ClampedArray data, unsigned long sw, optional unsigned long sh, optional ImageDataSettings settings);
37
37
38
    readonly attribute unsigned long width;
38
    readonly attribute unsigned long width;
39
    readonly attribute unsigned long height;
39
    readonly attribute unsigned long height;
40
    readonly attribute Uint8ClampedArray data;
40
    readonly attribute Uint8ClampedArray data;
41
    [EnabledBySetting=CanvasColorSpace] readonly attribute PredefinedColorSpace colorSpace;
41
};
42
};
- Source/WebCore/html/ImageDataSettings.h +37 lines
Line 0 Source/WebCore/html/ImageDataSettings.h_sec1
1
/*
2
 * Copyright (C) 2021 Apple Inc. All rights reserved.
3
 *
4
 * Redistribution and use in source and binary forms, with or without
5
 * modification, are permitted provided that the following conditions
6
 * are met:
7
 * 1. Redistributions of source code must retain the above copyright
8
 *    notice, this list of conditions and the following disclaimer.
9
 * 2. Redistributions in binary form must reproduce the above copyright
10
 *    notice, this list of conditions and the following disclaimer in the
11
 *    documentation and/or other materials provided with the distribution.
12
 *
13
 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23
 * THE POSSIBILITY OF SUCH DAMAGE.
24
 */
25
26
#pragma once
27
28
#include "PredefinedColorSpace.h"
29
#include <wtf/Optional.h>
30
31
namespace WebCore {
32
33
struct ImageDataSettings {
34
    Optional<PredefinedColorSpace> colorSpace;
35
};
36
37
} // namespace WebCore
- Source/WebCore/html/ImageDataSettings.idl +29 lines
Line 0 Source/WebCore/html/ImageDataSettings.idl_sec1
1
/*
2
 * Copyright (C) 2021 Apple Inc. All rights reserved.
3
 *
4
 * Redistribution and use in source and binary forms, with or without
5
 * modification, are permitted provided that the following conditions
6
 * are met:
7
 * 1. Redistributions of source code must retain the above copyright
8
 *    notice, this list of conditions and the following disclaimer.
9
 * 2. Redistributions in binary form must reproduce the above copyright
10
 *    notice, this list of conditions and the following disclaimer in the
11
 *    documentation and/or other materials provided with the distribution.
12
 *
13
 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23
 * THE POSSIBILITY OF SUCH DAMAGE.
24
 */
25
26
// https://html.spec.whatwg.org/multipage/canvas.html#imagedatasettings
27
dictionary ImageDataSettings {
28
    [EnabledBySetting=CanvasColorSpace] PredefinedColorSpace colorSpace;
29
};
- Source/WebCore/html/OffscreenCanvas.cpp -1 / +5 lines
Lines 213-219 ExceptionOr<Optional<OffscreenRenderingC Source/WebCore/html/OffscreenCanvas.cpp_sec1
213
            return { { RefPtr<OffscreenCanvasRenderingContext2D> { &downcast<OffscreenCanvasRenderingContext2D>(*m_context) } } };
213
            return { { RefPtr<OffscreenCanvasRenderingContext2D> { &downcast<OffscreenCanvasRenderingContext2D>(*m_context) } } };
214
        }
214
        }
215
215
216
        m_context = makeUnique<OffscreenCanvasRenderingContext2D>(*this);
216
        auto scope = DECLARE_THROW_SCOPE(state.vm());
217
        auto settings = convert<IDLDictionary<CanvasRenderingContext2DSettings>>(state, !arguments.isEmpty() ? arguments[0].get() : JSC::jsUndefined());
218
        RETURN_IF_EXCEPTION(scope, Exception { ExistingExceptionError });
219
220
        m_context = makeUnique<OffscreenCanvasRenderingContext2D>(*this, WTFMove(settings));
217
        if (!m_context)
221
        if (!m_context)
218
            return { { WTF::nullopt } };
222
            return { { WTF::nullopt } };
219
223
- Source/WebCore/html/canvas/CanvasImageData.idl -3 / +3 lines
Lines 1-5 Source/WebCore/html/canvas/CanvasImageData.idl_sec1
1
/*
1
/*
2
 * Copyright (C) 2017 Apple Inc. All rights reserved.
2
 * Copyright (C) 2017-2021 Apple Inc. All rights reserved.
3
 *
3
 *
4
 * Redistribution and use in source and binary forms, with or without
4
 * Redistribution and use in source and binary forms, with or without
5
 * modification, are permitted provided that the following conditions
5
 * modification, are permitted provided that the following conditions
Lines 26-34 Source/WebCore/html/canvas/CanvasImageData.idl_sec2
26
// https://html.spec.whatwg.org/multipage/canvas.html#canvasimagedata
26
// https://html.spec.whatwg.org/multipage/canvas.html#canvasimagedata
27
interface mixin CanvasImageData {
27
interface mixin CanvasImageData {
28
    // pixel manipulation
28
    // pixel manipulation
29
    ImageData createImageData([EnforceRange] long sw, [EnforceRange] long sh);
29
    ImageData createImageData([EnforceRange] long sw, [EnforceRange] long sh, optional ImageDataSettings settings);
30
    ImageData createImageData(ImageData imagedata);
30
    ImageData createImageData(ImageData imagedata);
31
    ImageData getImageData([EnforceRange] long sx, [EnforceRange] long sy, [EnforceRange] long sw, [EnforceRange] long sh);
31
    ImageData getImageData([EnforceRange] long sx, [EnforceRange] long sy, [EnforceRange] long sw, [EnforceRange] long sh, optional ImageDataSettings settings);
32
    undefined putImageData(ImageData imagedata, [EnforceRange] long dx, [EnforceRange] long dy);
32
    undefined putImageData(ImageData imagedata, [EnforceRange] long dx, [EnforceRange] long dy);
33
    undefined putImageData(ImageData imagedata, [EnforceRange] long dx, [EnforceRange] long dy, [EnforceRange] long dirtyX, [EnforceRange] long dirtyY, [EnforceRange] long dirtyWidth, [EnforceRange] long dirtyHeight);
33
    undefined putImageData(ImageData imagedata, [EnforceRange] long dx, [EnforceRange] long dy, [EnforceRange] long dirtyX, [EnforceRange] long dirtyY, [EnforceRange] long dirtyWidth, [EnforceRange] long dirtyHeight);
34
};
34
};
- Source/WebCore/html/canvas/CanvasRenderingContext2D.cpp -13 / +1 lines
Lines 79-86 std::unique_ptr<CanvasRenderingContext2D Source/WebCore/html/canvas/CanvasRenderingContext2D.cpp_sec1
79
}
79
}
80
80
81
CanvasRenderingContext2D::CanvasRenderingContext2D(CanvasBase& canvas, CanvasRenderingContext2DSettings&& settings, bool usesCSSCompatibilityParseMode)
81
CanvasRenderingContext2D::CanvasRenderingContext2D(CanvasBase& canvas, CanvasRenderingContext2DSettings&& settings, bool usesCSSCompatibilityParseMode)
82
    : CanvasRenderingContext2DBase(canvas, usesCSSCompatibilityParseMode)
82
    : CanvasRenderingContext2DBase(canvas, WTFMove(settings), usesCSSCompatibilityParseMode)
83
    , m_settings { WTFMove(settings) }
84
{
83
{
85
}
84
}
86
85
Lines 246-260 void CanvasRenderingContext2D::drawTextI Source/WebCore/html/canvas/CanvasRenderingContext2D.cpp_sec2
246
    drawTextUnchecked(textRun, x, y, fill, maxWidth);
245
    drawTextUnchecked(textRun, x, y, fill, maxWidth);
247
}
246
}
248
247
249
PixelFormat CanvasRenderingContext2D::pixelFormat() const
250
{
251
    // FIXME: Take m_settings.alpha into account here and add PixelFormat::BGRX8.
252
    return PixelFormat::BGRA8;
253
}
254
255
DestinationColorSpace CanvasRenderingContext2D::colorSpace() const
256
{
257
    return toDestinationColorSpace(m_settings.colorSpace);
258
}
259
260
} // namespace WebCore
248
} // namespace WebCore
- Source/WebCore/html/canvas/CanvasRenderingContext2D.h -7 lines
Lines 26-32 Source/WebCore/html/canvas/CanvasRenderingContext2D.h_sec1
26
#pragma once
26
#pragma once
27
27
28
#include "CanvasRenderingContext2DBase.h"
28
#include "CanvasRenderingContext2DBase.h"
29
#include "CanvasRenderingContext2DSettings.h"
30
#include "HTMLCanvasElement.h"
29
#include "HTMLCanvasElement.h"
31
#include <memory>
30
#include <memory>
32
31
Lines 43-50 public: Source/WebCore/html/canvas/CanvasRenderingContext2D.h_sec2
43
42
44
    HTMLCanvasElement& canvas() const { return downcast<HTMLCanvasElement>(canvasBase()); }
43
    HTMLCanvasElement& canvas() const { return downcast<HTMLCanvasElement>(canvasBase()); }
45
44
46
    const CanvasRenderingContext2DSettings& getContextAttributes() const { return m_settings; }
47
48
    void drawFocusIfNeeded(Element&);
45
    void drawFocusIfNeeded(Element&);
49
    void drawFocusIfNeeded(Path2D&, Element&);
46
    void drawFocusIfNeeded(Path2D&, Element&);
50
47
Lines 61-68 private: Source/WebCore/html/canvas/CanvasRenderingContext2D.h_sec3
61
58
62
    bool is2d() const final { return true; }
59
    bool is2d() const final { return true; }
63
    const FontProxy* fontProxy() final;
60
    const FontProxy* fontProxy() final;
64
    PixelFormat pixelFormat() const final;
65
    DestinationColorSpace colorSpace() const final;
66
61
67
    void setFontWithoutUpdatingStyle(const String&);
62
    void setFontWithoutUpdatingStyle(const String&);
68
63
Lines 71-78 private: Source/WebCore/html/canvas/CanvasRenderingContext2D.h_sec4
71
    void drawFocusIfNeededInternal(const Path&, Element&);
66
    void drawFocusIfNeededInternal(const Path&, Element&);
72
67
73
    TextDirection toTextDirection(CanvasRenderingContext2DBase::Direction, const RenderStyle** computedStyle = nullptr) const;
68
    TextDirection toTextDirection(CanvasRenderingContext2DBase::Direction, const RenderStyle** computedStyle = nullptr) const;
74
75
    CanvasRenderingContext2DSettings m_settings;
76
};
69
};
77
70
78
} // namespace WebCore
71
} // namespace WebCore
- Source/WebCore/html/canvas/CanvasRenderingContext2DBase.cpp -18 / +50 lines
Lines 224-233 static TextBaseline fromCanvasTextBaseli Source/WebCore/html/canvas/CanvasRenderingContext2DBase.cpp_sec1
224
    return TopTextBaseline;
224
    return TopTextBaseline;
225
}
225
}
226
226
227
CanvasRenderingContext2DBase::CanvasRenderingContext2DBase(CanvasBase& canvas, bool usesCSSCompatibilityParseMode)
227
CanvasRenderingContext2DBase::CanvasRenderingContext2DBase(CanvasBase& canvas, CanvasRenderingContext2DSettings&& settings, bool usesCSSCompatibilityParseMode)
228
    : CanvasRenderingContext(canvas)
228
    : CanvasRenderingContext(canvas)
229
    , m_stateStack(1)
229
    , m_stateStack(1)
230
    , m_usesCSSCompatibilityParseMode(usesCSSCompatibilityParseMode)
230
    , m_usesCSSCompatibilityParseMode(usesCSSCompatibilityParseMode)
231
    , m_settings(WTFMove(settings))
231
{
232
{
232
}
233
}
233
234
Lines 2151-2189 bool CanvasRenderingContext2DBase::needs Source/WebCore/html/canvas/CanvasRenderingContext2DBase.cpp_sec2
2151
    return false;
2152
    return false;
2152
}
2153
}
2153
2154
2154
static RefPtr<ImageData> createEmptyImageData(const IntSize& size)
2155
static void initializeEmptyImageData(const ImageData& imageData)
2155
{
2156
{
2156
    auto data = ImageData::create(size);
2157
    // FIXME: Add support for initializing the ImageData when settings.alpha is false, requiring
2157
    if (data)
2158
    // every 4th byte to be 0xFF.
2158
        data->data().zeroFill();
2159
2159
    return data;
2160
    imageData.data().zeroFill();
2160
}
2161
}
2161
2162
2162
RefPtr<ImageData> CanvasRenderingContext2DBase::createImageData(ImageData& imageData) const
2163
ExceptionOr<Ref<ImageData>> CanvasRenderingContext2DBase::createImageData(ImageData& imageData) const
2163
{
2164
{
2164
    return createEmptyImageData(imageData.size());
2165
    auto newImageData = ImageData::createUninitialized(imageData.width(), imageData.height(), imageData.colorSpace());
2166
    if (newImageData.hasException())
2167
        return newImageData.releaseException();
2168
2169
    initializeEmptyImageData(newImageData.returnValue());
2170
2171
    return newImageData;
2165
}
2172
}
2166
2173
2167
ExceptionOr<RefPtr<ImageData>> CanvasRenderingContext2DBase::createImageData(int sw, int sh) const
2174
ExceptionOr<Ref<ImageData>> CanvasRenderingContext2DBase::createImageData(int sw, int sh, Optional<ImageDataSettings> settings) const
2168
{
2175
{
2169
    if (!sw || !sh)
2176
    if (!sw || !sh)
2170
        return Exception { IndexSizeError };
2177
        return Exception { IndexSizeError };
2171
2178
2172
    IntSize size { std::abs(sw), std::abs(sh) };
2179
    auto imageData = ImageData::createUninitialized(std::abs(sw), std::abs(sh), m_settings.colorSpace, settings);
2173
    return createEmptyImageData(size);
2180
    if (imageData.hasException())
2181
        return imageData.releaseException();
2182
2183
    initializeEmptyImageData(imageData.returnValue());
2184
2185
    return imageData;
2174
}
2186
}
2175
2187
2176
ExceptionOr<RefPtr<ImageData>> CanvasRenderingContext2DBase::getImageData(int sx, int sy, int sw, int sh) const
2188
ExceptionOr<Ref<ImageData>> CanvasRenderingContext2DBase::getImageData(int sx, int sy, int sw, int sh, Optional<ImageDataSettings> settings) const
2177
{
2189
{
2190
    if (!sw || !sh)
2191
        return Exception { IndexSizeError };
2192
2178
    if (!canvasBase().originClean()) {
2193
    if (!canvasBase().originClean()) {
2179
        static NeverDestroyed<String> consoleMessage(MAKE_STATIC_STRING_IMPL("Unable to get image data from canvas because the canvas has been tainted by cross-origin data."));
2194
        static NeverDestroyed<String> consoleMessage(MAKE_STATIC_STRING_IMPL("Unable to get image data from canvas because the canvas has been tainted by cross-origin data."));
2180
        canvasBase().scriptExecutionContext()->addConsoleMessage(MessageSource::Security, MessageLevel::Error, consoleMessage);
2195
        canvasBase().scriptExecutionContext()->addConsoleMessage(MessageSource::Security, MessageLevel::Error, consoleMessage);
2181
        return Exception { SecurityError };
2196
        return Exception { SecurityError };
2182
    }
2197
    }
2183
2198
2184
    if (!sw || !sh)
2185
        return Exception { IndexSizeError };
2186
2187
    if (sw < 0) {
2199
    if (sw < 0) {
2188
        sx += sw;
2200
        sx += sw;
2189
        sw = -sw;
2201
        sw = -sw;
Lines 2196-2205 ExceptionOr<RefPtr<ImageData>> CanvasRen Source/WebCore/html/canvas/CanvasRenderingContext2DBase.cpp_sec3
2196
    IntRect imageDataRect { sx, sy, sw, sh };
2208
    IntRect imageDataRect { sx, sy, sw, sh };
2197
2209
2198
    ImageBuffer* buffer = canvasBase().buffer();
2210
    ImageBuffer* buffer = canvasBase().buffer();
2199
    if (!buffer)
2211
    if (!buffer) {
2200
        return createEmptyImageData(imageDataRect.size());
2212
        auto imageData = ImageData::createUninitialized(imageDataRect.width(), imageDataRect.height(), m_settings.colorSpace, settings);
2213
        if (imageData.hasException())
2214
            return imageData.releaseException();
2215
2216
        initializeEmptyImageData(imageData.returnValue());
2217
        
2218
        return imageData;
2219
    }
2201
2220
2202
    PixelBufferFormat format { AlphaPremultiplication::Unpremultiplied, PixelFormat::RGBA8, DestinationColorSpace::SRGB };
2221
    auto computedColorSpace = ImageData::computeColorSpace(settings, m_settings.colorSpace);
2222
2223
    PixelBufferFormat format { AlphaPremultiplication::Unpremultiplied, PixelFormat::RGBA8, toDestinationColorSpace(computedColorSpace) };
2203
    auto pixelBuffer = buffer->getPixelBuffer(format, imageDataRect);
2224
    auto pixelBuffer = buffer->getPixelBuffer(format, imageDataRect);
2204
    if (!pixelBuffer) {
2225
    if (!pixelBuffer) {
2205
        canvasBase().scriptExecutionContext()->addConsoleMessage(MessageSource::Rendering, MessageLevel::Error,
2226
        canvasBase().scriptExecutionContext()->addConsoleMessage(MessageSource::Rendering, MessageLevel::Error,
Lines 2611-2614 FloatPoint CanvasRenderingContext2DBase: Source/WebCore/html/canvas/CanvasRenderingContext2DBase.cpp_sec4
2611
    return offset;
2632
    return offset;
2612
}
2633
}
2613
2634
2635
PixelFormat CanvasRenderingContext2DBase::pixelFormat() const
2636
{
2637
    // FIXME: Take m_settings.alpha into account here and add PixelFormat::BGRX8.
2638
    return PixelFormat::BGRA8;
2639
}
2640
2641
DestinationColorSpace CanvasRenderingContext2DBase::colorSpace() const
2642
{
2643
    return toDestinationColorSpace(m_settings.colorSpace);
2644
}
2645
2614
} // namespace WebCore
2646
} // namespace WebCore
- Source/WebCore/html/canvas/CanvasRenderingContext2DBase.h -4 / +12 lines
Lines 32-37 Source/WebCore/html/canvas/CanvasRenderingContext2DBase.h_sec1
32
#include "CanvasLineJoin.h"
32
#include "CanvasLineJoin.h"
33
#include "CanvasPath.h"
33
#include "CanvasPath.h"
34
#include "CanvasRenderingContext.h"
34
#include "CanvasRenderingContext.h"
35
#include "CanvasRenderingContext2DSettings.h"
35
#include "CanvasStyle.h"
36
#include "CanvasStyle.h"
36
#include "CanvasTextAlign.h"
37
#include "CanvasTextAlign.h"
37
#include "CanvasTextBaseline.h"
38
#include "CanvasTextBaseline.h"
Lines 42-47 Source/WebCore/html/canvas/CanvasRenderingContext2DBase.h_sec2
42
#include "GraphicsContext.h"
43
#include "GraphicsContext.h"
43
#include "GraphicsTypes.h"
44
#include "GraphicsTypes.h"
44
#include "ImageBuffer.h"
45
#include "ImageBuffer.h"
46
#include "ImageDataSettings.h"
45
#include "ImageSmoothingQuality.h"
47
#include "ImageSmoothingQuality.h"
46
#include "Path.h"
48
#include "Path.h"
47
#include "PlatformLayer.h"
49
#include "PlatformLayer.h"
Lines 78-88 using CanvasImageSource = Variant<RefPtr Source/WebCore/html/canvas/CanvasRenderingContext2DBase.h_sec3
78
class CanvasRenderingContext2DBase : public CanvasRenderingContext, public CanvasPath {
80
class CanvasRenderingContext2DBase : public CanvasRenderingContext, public CanvasPath {
79
    WTF_MAKE_ISO_ALLOCATED(CanvasRenderingContext2DBase);
81
    WTF_MAKE_ISO_ALLOCATED(CanvasRenderingContext2DBase);
80
protected:
82
protected:
81
    CanvasRenderingContext2DBase(CanvasBase&, bool usesCSSCompatibilityParseMode);
83
    CanvasRenderingContext2DBase(CanvasBase&, CanvasRenderingContext2DSettings&&, bool usesCSSCompatibilityParseMode);
82
84
83
public:
85
public:
84
    virtual ~CanvasRenderingContext2DBase();
86
    virtual ~CanvasRenderingContext2DBase();
85
87
88
    const CanvasRenderingContext2DSettings& getContextAttributes() const { return m_settings; }
89
86
    float lineWidth() const { return state().lineWidth; }
90
    float lineWidth() const { return state().lineWidth; }
87
    void setLineWidth(float);
91
    void setLineWidth(float);
88
92
Lines 188-196 public: Source/WebCore/html/canvas/CanvasRenderingContext2DBase.h_sec4
188
    ExceptionOr<Ref<CanvasGradient>> createRadialGradient(float x0, float y0, float r0, float x1, float y1, float r1);
192
    ExceptionOr<Ref<CanvasGradient>> createRadialGradient(float x0, float y0, float r0, float x1, float y1, float r1);
189
    ExceptionOr<RefPtr<CanvasPattern>> createPattern(CanvasImageSource&&, const String& repetition);
193
    ExceptionOr<RefPtr<CanvasPattern>> createPattern(CanvasImageSource&&, const String& repetition);
190
194
191
    RefPtr<ImageData> createImageData(ImageData&) const;
195
    ExceptionOr<Ref<ImageData>> createImageData(ImageData&) const;
192
    ExceptionOr<RefPtr<ImageData>> createImageData(int width, int height) const;
196
    ExceptionOr<Ref<ImageData>> createImageData(int width, int height, Optional<ImageDataSettings>) const;
193
    ExceptionOr<RefPtr<ImageData>> getImageData(int sx, int sy, int sw, int sh) const;
197
    ExceptionOr<Ref<ImageData>> getImageData(int sx, int sy, int sw, int sh, Optional<ImageDataSettings>) const;
194
    void putImageData(ImageData&, int dx, int dy);
198
    void putImageData(ImageData&, int dx, int dy);
195
    void putImageData(ImageData&, int dx, int dy, int dirtyX, int dirtyY, int dirtyWidth, int dirtyHeight);
199
    void putImageData(ImageData&, int dx, int dy, int dirtyX, int dirtyY, int dirtyWidth, int dirtyHeight);
196
200
Lines 328-333 private: Source/WebCore/html/canvas/CanvasRenderingContext2DBase.h_sec5
328
    bool isEntireBackingStoreDirty() const;
332
    bool isEntireBackingStoreDirty() const;
329
    FloatRect backingStoreBounds() const { return FloatRect { { }, FloatSize { canvasBase().size() } }; }
333
    FloatRect backingStoreBounds() const { return FloatRect { { }, FloatSize { canvasBase().size() } }; }
330
334
335
    PixelFormat pixelFormat() const final;
336
    DestinationColorSpace colorSpace() const final;
337
331
    void unwindStateStack();
338
    void unwindStateStack();
332
    void realizeSavesLoop();
339
    void realizeSavesLoop();
333
340
Lines 395-400 private: Source/WebCore/html/canvas/CanvasRenderingContext2DBase.h_sec6
395
    bool m_usesCSSCompatibilityParseMode;
402
    bool m_usesCSSCompatibilityParseMode;
396
    bool m_usesDisplayListDrawing { false };
403
    bool m_usesDisplayListDrawing { false };
397
    mutable std::unique_ptr<DisplayList::DrawingContext> m_recordingContext;
404
    mutable std::unique_ptr<DisplayList::DrawingContext> m_recordingContext;
405
    CanvasRenderingContext2DSettings m_settings;
398
};
406
};
399
407
400
} // namespace WebCore
408
} // namespace WebCore
- Source/WebCore/html/canvas/OffscreenCanvasRenderingContext2D.cpp -2 / +2 lines
Lines 48-55 namespace WebCore { Source/WebCore/html/canvas/OffscreenCanvasRenderingContext2D.cpp_sec1
48
48
49
WTF_MAKE_ISO_ALLOCATED_IMPL(OffscreenCanvasRenderingContext2D);
49
WTF_MAKE_ISO_ALLOCATED_IMPL(OffscreenCanvasRenderingContext2D);
50
50
51
OffscreenCanvasRenderingContext2D::OffscreenCanvasRenderingContext2D(CanvasBase& canvas)
51
OffscreenCanvasRenderingContext2D::OffscreenCanvasRenderingContext2D(CanvasBase& canvas, CanvasRenderingContext2DSettings&& settings)
52
    : CanvasRenderingContext2DBase(canvas, false)
52
    : CanvasRenderingContext2DBase(canvas, WTFMove(settings), false)
53
{
53
{
54
}
54
}
55
55
- Source/WebCore/html/canvas/OffscreenCanvasRenderingContext2D.h -1 / +1 lines
Lines 36-42 namespace WebCore { Source/WebCore/html/canvas/OffscreenCanvasRenderingContext2D.h_sec1
36
class OffscreenCanvasRenderingContext2D final : public CanvasRenderingContext2DBase {
36
class OffscreenCanvasRenderingContext2D final : public CanvasRenderingContext2DBase {
37
    WTF_MAKE_ISO_ALLOCATED(OffscreenCanvasRenderingContext2D);
37
    WTF_MAKE_ISO_ALLOCATED(OffscreenCanvasRenderingContext2D);
38
public:
38
public:
39
    OffscreenCanvasRenderingContext2D(CanvasBase&);
39
    OffscreenCanvasRenderingContext2D(CanvasBase&, CanvasRenderingContext2DSettings&&);
40
    virtual ~OffscreenCanvasRenderingContext2D();
40
    virtual ~OffscreenCanvasRenderingContext2D();
41
41
42
    OffscreenCanvas& canvas() const { return downcast<OffscreenCanvas>(canvasBase()); }
42
    OffscreenCanvas& canvas() const { return downcast<OffscreenCanvas>(canvasBase()); }
- Source/WebCore/html/canvas/PaintRenderingContext2D.cpp -1 / +1 lines
Lines 40-46 std::unique_ptr<PaintRenderingContext2D> Source/WebCore/html/canvas/PaintRenderingContext2D.cpp_sec1
40
}
40
}
41
41
42
PaintRenderingContext2D::PaintRenderingContext2D(CanvasBase& canvas)
42
PaintRenderingContext2D::PaintRenderingContext2D(CanvasBase& canvas)
43
    : CanvasRenderingContext2DBase(canvas, false)
43
    : CanvasRenderingContext2DBase(canvas, { }, false)
44
{
44
{
45
}
45
}
46
46
- Source/WebCore/html/canvas/PredefinedColorSpace.cpp +19 lines
Lines 45-48 DestinationColorSpace toDestinationColor Source/WebCore/html/canvas/PredefinedColorSpace.cpp_sec1
45
    return DestinationColorSpace::SRGB;
45
    return DestinationColorSpace::SRGB;
46
}
46
}
47
47
48
Optional<PredefinedColorSpace> toPredefinedColorSpace(DestinationColorSpace colorSpace)
49
{
50
    switch (colorSpace) {
51
    case DestinationColorSpace::SRGB:
52
        return PredefinedColorSpace::SRGB;
53
#if ENABLE(DESTINATION_COLOR_SPACE_LINEAR_SRGB)
54
    case DestinationColorSpace::LinearSRGB:
55
        return WTF::nullopt;
56
#endif
57
#if ENABLE(DESTINATION_COLOR_SPACE_DISPLAY_P3)
58
    case DestinationColorSpace::DisplayP3:
59
        return PredefinedColorSpace::DisplayP3;
60
#endif
61
    }
62
63
    ASSERT_NOT_REACHED();
64
    return WTF::nullopt;
65
}
66
48
}
67
}
- Source/WebCore/html/canvas/PredefinedColorSpace.h +2 lines
Lines 26-31 Source/WebCore/html/canvas/PredefinedColorSpace.h_sec1
26
#pragma once
26
#pragma once
27
27
28
#include <wtf/EnumTraits.h>
28
#include <wtf/EnumTraits.h>
29
#include <wtf/Optional.h>
29
30
30
namespace WebCore {
31
namespace WebCore {
31
32
Lines 39-44 enum class PredefinedColorSpace { Source/WebCore/html/canvas/PredefinedColorSpace.h_sec2
39
};
40
};
40
41
41
DestinationColorSpace toDestinationColorSpace(PredefinedColorSpace);
42
DestinationColorSpace toDestinationColorSpace(PredefinedColorSpace);
43
Optional<PredefinedColorSpace> toPredefinedColorSpace(DestinationColorSpace);
42
44
43
}
45
}
44
46
- Source/WebCore/inspector/InspectorCanvas.cpp +6 lines
Lines 428-433 Optional<InspectorCanvasCallTracer::Proc Source/WebCore/inspector/InspectorCanvas.cpp_sec1
428
    return {{ valueIndexForData(argument), RecordingSwizzleType::ImageData }};
428
    return {{ valueIndexForData(argument), RecordingSwizzleType::ImageData }};
429
}
429
}
430
430
431
Optional<InspectorCanvasCallTracer::ProcessedArgument> InspectorCanvas::processArgument(ImageDataSettings&)
432
{
433
    // FIXME: Implement.
434
    return WTF::nullopt;
435
}
436
431
Optional<InspectorCanvasCallTracer::ProcessedArgument> InspectorCanvas::processArgument(ImageSmoothingQuality argument)
437
Optional<InspectorCanvasCallTracer::ProcessedArgument> InspectorCanvas::processArgument(ImageSmoothingQuality argument)
432
{
438
{
433
    return {{ valueIndexForData(convertEnumerationToString(argument)), RecordingSwizzleType::String }};
439
    return {{ valueIndexForData(convertEnumerationToString(argument)), RecordingSwizzleType::String }};
- Source/WebCore/inspector/InspectorCanvasCallTracer.cpp +1 lines
Lines 37-42 Source/WebCore/inspector/InspectorCanvasCallTracer.cpp_sec1
37
#include "HTMLImageElement.h"
37
#include "HTMLImageElement.h"
38
#include "HTMLVideoElement.h"
38
#include "HTMLVideoElement.h"
39
#include "ImageData.h"
39
#include "ImageData.h"
40
#include "ImageDataSettings.h"
40
#include "InspectorCanvasAgent.h"
41
#include "InspectorCanvasAgent.h"
41
#include "InspectorInstrumentation.h"
42
#include "InspectorInstrumentation.h"
42
#include "InstrumentingAgents.h"
43
#include "InstrumentingAgents.h"
- Source/WebCore/inspector/InspectorCanvasCallTracer.h +2 lines
Lines 70-75 class WebGLTransformFeedback; Source/WebCore/inspector/InspectorCanvasCallTracer.h_sec1
70
class WebGLUniformLocation;
70
class WebGLUniformLocation;
71
class WebGLVertexArrayObject;
71
class WebGLVertexArrayObject;
72
struct DOMMatrix2DInit;
72
struct DOMMatrix2DInit;
73
struct ImageDataSettings;
73
enum class RecordingSwizzleType : int;
74
enum class RecordingSwizzleType : int;
74
enum class CanvasDirection;
75
enum class CanvasDirection;
75
enum class CanvasFillRule;
76
enum class CanvasFillRule;
Lines 150-155 enum ImageSmoothingQuality; Source/WebCore/inspector/InspectorCanvasCallTracer.h_sec2
150
    macro(HTMLImageElement*) \
151
    macro(HTMLImageElement*) \
151
    macro(ImageBitmap*) \
152
    macro(ImageBitmap*) \
152
    macro(ImageData*) \
153
    macro(ImageData*) \
154
    macro(ImageDataSettings&) \
153
    macro(ImageSmoothingQuality) \
155
    macro(ImageSmoothingQuality) \
154
    macro(Optional<float>&) \
156
    macro(Optional<float>&) \
155
    macro(Path2D*) \
157
    macro(Path2D*) \
- Source/WebCore/platform/graphics/ImageBufferBackend.cpp -33 / +19 lines
Lines 116-121 Vector<uint8_t> ImageBufferBackend::toBG Source/WebCore/platform/graphics/ImageBufferBackend.cpp_sec1
116
116
117
Optional<PixelBuffer> ImageBufferBackend::getPixelBuffer(const PixelBufferFormat& destinationFormat, const IntRect& sourceRect, void* data) const
117
Optional<PixelBuffer> ImageBufferBackend::getPixelBuffer(const PixelBufferFormat& destinationFormat, const IntRect& sourceRect, void* data) const
118
{
118
{
119
    // FIXME: Add support for non 8-bit pixel formats.
120
    ASSERT(destinationFormat.pixelFormat == PixelFormat::RGBA8 || destinationFormat.pixelFormat == PixelFormat::BGRA8);
121
119
    auto sourceRectScaled = toBackendCoordinates(sourceRect);
122
    auto sourceRectScaled = toBackendCoordinates(sourceRect);
120
123
121
    auto pixelBuffer = PixelBuffer::tryCreate(destinationFormat, sourceRectScaled.size());
124
    auto pixelBuffer = PixelBuffer::tryCreate(destinationFormat, sourceRectScaled.size());
Lines 134-156 Optional<PixelBuffer> ImageBufferBackend Source/WebCore/platform/graphics/ImageBufferBackend.cpp_sec2
134
    if (destinationRect.size() != sourceRectScaled.size())
137
    if (destinationRect.size() != sourceRectScaled.size())
135
        pixelBuffer->data().zeroFill();
138
        pixelBuffer->data().zeroFill();
136
139
137
    unsigned sourceBytesPerRow = bytesPerRow();
138
    const uint8_t* sourceRows = reinterpret_cast<uint8_t*>(data) + sourceRectClipped.y() * sourceBytesPerRow + sourceRectClipped.x() * 4;
139
140
    unsigned destinationBytesPerRow = 4 * sourceRectScaled.width();
141
    uint8_t* destinationRows = pixelBuffer->data().data() + destinationRect.y() * destinationBytesPerRow + destinationRect.x() * 4;
142
143
    PixelBufferFormat sourceFormat { AlphaPremultiplication::Premultiplied, pixelFormat(), DestinationColorSpace::SRGB };
144
145
    ConstPixelBufferConversionView source;
140
    ConstPixelBufferConversionView source;
146
    source.format = sourceFormat;
141
    source.format = { AlphaPremultiplication::Premultiplied, pixelFormat(), colorSpace() };
147
    source.bytesPerRow = sourceBytesPerRow;
142
    source.bytesPerRow = bytesPerRow();
148
    source.rows = sourceRows;
143
    source.rows = reinterpret_cast<uint8_t*>(data) + sourceRectClipped.y() * source.bytesPerRow + sourceRectClipped.x() * 4;
149
    
144
    
150
    PixelBufferConversionView destination;
145
    PixelBufferConversionView destination;
151
    destination.format = destinationFormat;
146
    destination.format = destinationFormat;
152
    destination.bytesPerRow = destinationBytesPerRow;
147
    destination.bytesPerRow = 4 * sourceRectScaled.width();
153
    destination.rows = destinationRows;
148
    destination.rows = pixelBuffer->data().data() + destinationRect.y() * destination.bytesPerRow + destinationRect.x() * 4;
154
149
155
    convertImagePixels(source, destination, destinationRect.size());
150
    convertImagePixels(source, destination, destinationRect.size());
156
151
Lines 159-172 Optional<PixelBuffer> ImageBufferBackend Source/WebCore/platform/graphics/ImageBufferBackend.cpp_sec3
159
154
160
void ImageBufferBackend::putPixelBuffer(const PixelBuffer& sourcePixelBuffer, const IntRect& sourceRect, const IntPoint& destinationPoint, AlphaPremultiplication destinationAlphaFormat, void* data)
155
void ImageBufferBackend::putPixelBuffer(const PixelBuffer& sourcePixelBuffer, const IntRect& sourceRect, const IntPoint& destinationPoint, AlphaPremultiplication destinationAlphaFormat, void* data)
161
{
156
{
162
    // FIXME: Add support for non-RGBA8 pixel formats.
157
    // FIXME: Add support for non 8-bit pixel formats.
163
    ASSERT(sourcePixelBuffer.format().pixelFormat == PixelFormat::RGBA8);
158
    ASSERT(sourcePixelBuffer.format().pixelFormat == PixelFormat::RGBA8 || sourcePixelBuffer.format().pixelFormat == PixelFormat::BGRA8);
164
159
165
    auto sourceRectScaled = toBackendCoordinates(sourceRect);
160
    auto sourceRectScaled = toBackendCoordinates(sourceRect);
166
    auto destinationPointScaled = toBackendCoordinates(destinationPoint);
161
    auto destinationPointScaled = toBackendCoordinates(destinationPoint);
167
162
168
    IntRect sourceRectClipped = intersection({ IntPoint::zero(), sourcePixelBuffer.size() }, sourceRectScaled);
163
    auto sourceRectClipped = intersection({ IntPoint::zero(), sourcePixelBuffer.size() }, sourceRectScaled);
169
    IntRect destinationRect = sourceRectClipped;
164
    auto destinationRect = sourceRectClipped;
170
    destinationRect.moveBy(destinationPointScaled);
165
    destinationRect.moveBy(destinationPointScaled);
171
166
172
    if (sourceRectScaled.x() < 0)
167
    if (sourceRectScaled.x() < 0)
Lines 178-201 void ImageBufferBackend::putPixelBuffer( Source/WebCore/platform/graphics/ImageBufferBackend.cpp_sec4
178
    destinationRect.intersect(backendRect());
173
    destinationRect.intersect(backendRect());
179
    sourceRectClipped.setSize(destinationRect.size());
174
    sourceRectClipped.setSize(destinationRect.size());
180
175
181
    unsigned sourceBytesPerRow = 4 * sourcePixelBuffer.size().width();
182
    const uint8_t* sourceRows = sourcePixelBuffer.data().data() + sourceRectClipped.y() * sourceBytesPerRow + sourceRectClipped.x() * 4;
183
184
    unsigned destinationBytesPerRow = bytesPerRow();
185
    uint8_t* destinationRows = reinterpret_cast<uint8_t*>(data) + destinationRect.y() * destinationBytesPerRow + destinationRect.x() * 4;
186
187
    PixelBufferFormat sourceFormat = sourcePixelBuffer.format();
188
    PixelBufferFormat destinationFormat { destinationAlphaFormat, pixelFormat(), DestinationColorSpace::SRGB };
189
190
    ConstPixelBufferConversionView source;
176
    ConstPixelBufferConversionView source;
191
    source.format = sourceFormat;
177
    source.format = sourcePixelBuffer.format();
192
    source.bytesPerRow = sourceBytesPerRow;
178
    source.bytesPerRow = 4 * sourcePixelBuffer.size().width();
193
    source.rows = sourceRows;
179
    source.rows = sourcePixelBuffer.data().data() + sourceRectClipped.y() * source.bytesPerRow + sourceRectClipped.x() * 4;
194
    
180
195
    PixelBufferConversionView destination;
181
    PixelBufferConversionView destination;
196
    destination.format = destinationFormat;
182
    destination.format = { destinationAlphaFormat, pixelFormat(), colorSpace() };
197
    destination.bytesPerRow = destinationBytesPerRow;
183
    destination.bytesPerRow = bytesPerRow();
198
    destination.rows = destinationRows;
184
    destination.rows = reinterpret_cast<uint8_t*>(data) + destinationRect.y() * destination.bytesPerRow + destinationRect.x() * 4;
199
185
200
    convertImagePixels(source, destination, destinationRect.size());
186
    convertImagePixels(source, destination, destinationRect.size());
201
}
187
}
- Source/WebCore/platform/graphics/PixelBuffer.cpp +24 lines
Lines 66-71 Optional<PixelBuffer> PixelBuffer::tryCr Source/WebCore/platform/graphics/PixelBuffer.cpp_sec1
66
    return { { format, size, pixelArray.releaseNonNull() } };
66
    return { { format, size, pixelArray.releaseNonNull() } };
67
}
67
}
68
68
69
Optional<PixelBuffer> PixelBuffer::tryCreate(const PixelBufferFormat& format, const IntSize& size, Ref<JSC::ArrayBuffer>&& arrayBuffer)
70
{
71
    // NOTE: Only 8-bit formats are currently supported.
72
    ASSERT(format.pixelFormat == PixelFormat::RGBA8 || format.pixelFormat == PixelFormat::BGRA8);
73
74
    auto bufferSize = computeBufferSize(format, size);
75
    if (bufferSize.hasOverflowed())
76
        return WTF::nullopt;
77
    if (bufferSize.unsafeGet() != arrayBuffer->byteLength())
78
        return WTF::nullopt;
79
    auto pixelArray = Uint8ClampedArray::tryCreate(WTFMove(arrayBuffer), 0, bufferSize.unsafeGet());
80
    if (!pixelArray)
81
        return WTF::nullopt;
82
    return { { format, size, pixelArray.releaseNonNull() } };
83
}
84
69
PixelBuffer::PixelBuffer(const PixelBufferFormat& format, const IntSize& size, Ref<JSC::Uint8ClampedArray>&& data)
85
PixelBuffer::PixelBuffer(const PixelBufferFormat& format, const IntSize& size, Ref<JSC::Uint8ClampedArray>&& data)
70
    : m_format { format }
86
    : m_format { format }
71
    , m_size { size }
87
    , m_size { size }
Lines 74-79 PixelBuffer::PixelBuffer(const PixelBuff Source/WebCore/platform/graphics/PixelBuffer.cpp_sec2
74
    RELEASE_ASSERT_WITH_SECURITY_IMPLICATION((m_size.area() * 4).unsafeGet() <= m_data->length());
90
    RELEASE_ASSERT_WITH_SECURITY_IMPLICATION((m_size.area() * 4).unsafeGet() <= m_data->length());
75
}
91
}
76
92
93
PixelBuffer::PixelBuffer(const PixelBufferFormat& format, const IntSize& size, JSC::Uint8ClampedArray& data)
94
    : m_format { format }
95
    , m_size { size }
96
    , m_data { data }
97
{
98
    RELEASE_ASSERT_WITH_SECURITY_IMPLICATION((m_size.area() * 4).unsafeGet() <= m_data->length());
99
}
100
77
PixelBuffer::~PixelBuffer() = default;
101
PixelBuffer::~PixelBuffer() = default;
78
102
79
PixelBuffer PixelBuffer::deepClone() const
103
PixelBuffer PixelBuffer::deepClone() const
- Source/WebCore/platform/graphics/PixelBuffer.h +4 lines
Lines 42-49 class PixelBuffer { Source/WebCore/platform/graphics/PixelBuffer.h_sec1
42
    WTF_MAKE_NONCOPYABLE(PixelBuffer);
42
    WTF_MAKE_NONCOPYABLE(PixelBuffer);
43
public:
43
public:
44
    WEBCORE_EXPORT static Optional<PixelBuffer> tryCreate(const PixelBufferFormat&, const IntSize&);
44
    WEBCORE_EXPORT static Optional<PixelBuffer> tryCreate(const PixelBufferFormat&, const IntSize&);
45
    WEBCORE_EXPORT static Optional<PixelBuffer> tryCreate(const PixelBufferFormat&, const IntSize&, Ref<JSC::ArrayBuffer>&&);
45
46
46
    PixelBuffer(const PixelBufferFormat&, const IntSize&, Ref<JSC::Uint8ClampedArray>&&);
47
    PixelBuffer(const PixelBufferFormat&, const IntSize&, Ref<JSC::Uint8ClampedArray>&&);
48
    PixelBuffer(const PixelBufferFormat&, const IntSize&, JSC::Uint8ClampedArray&);
47
    WEBCORE_EXPORT ~PixelBuffer();
49
    WEBCORE_EXPORT ~PixelBuffer();
48
50
49
    PixelBuffer(PixelBuffer&&) = default;
51
    PixelBuffer(PixelBuffer&&) = default;
Lines 53-58 public: Source/WebCore/platform/graphics/PixelBuffer.h_sec2
53
    const IntSize& size() const { return m_size; }
55
    const IntSize& size() const { return m_size; }
54
    JSC::Uint8ClampedArray& data() const { return m_data.get(); }
56
    JSC::Uint8ClampedArray& data() const { return m_data.get(); }
55
57
58
    Ref<JSC::Uint8ClampedArray>&& takeData() { return WTFMove(m_data); }
59
56
    PixelBuffer deepClone() const;
60
    PixelBuffer deepClone() const;
57
61
58
    template<class Encoder> void encode(Encoder&) const;
62
    template<class Encoder> void encode(Encoder&) const;
- Source/WebCore/platform/graphics/PixelBufferConversion.cpp -1 / +1 lines
Lines 106-112 static void convertImagePixelsAccelerate Source/WebCore/platform/graphics/PixelBufferConversion.cpp_sec1
106
106
107
        vImage_Error converterCreateError = kvImageNoError;
107
        vImage_Error converterCreateError = kvImageNoError;
108
        auto converter = adoptCF(vImageConverter_CreateWithCGImageFormat(&sourceCGImageFormat, &destinationCGImageFormat, nullptr, kvImageNoFlags, &converterCreateError));
108
        auto converter = adoptCF(vImageConverter_CreateWithCGImageFormat(&sourceCGImageFormat, &destinationCGImageFormat, nullptr, kvImageNoFlags, &converterCreateError));
109
        ASSERT_WITH_MESSAGE_UNUSED(converterCreateError, converterCreateError != kvImageNoError, "vImageConverter creation failed with error: %zd", converterCreateError);
109
        ASSERT_WITH_MESSAGE_UNUSED(converterCreateError, converterCreateError == kvImageNoError, "vImageConverter creation failed with error: %zd", converterCreateError);
110
110
111
        vImage_Error converterConvertError = vImageConvert_AnyToAny(converter.get(), &sourceVImageBuffer, &destinationVImageBuffer, nullptr, kvImageNoFlags);
111
        vImage_Error converterConvertError = vImageConvert_AnyToAny(converter.get(), &sourceVImageBuffer, &destinationVImageBuffer, nullptr, kvImageNoFlags);
112
        ASSERT_WITH_MESSAGE_UNUSED(converterConvertError, converterConvertError == kvImageNoError, "vImageConvert_AnyToAny failed conversion with error: %zd", converterConvertError);
112
        ASSERT_WITH_MESSAGE_UNUSED(converterConvertError, converterConvertError == kvImageNoError, "vImageConvert_AnyToAny failed conversion with error: %zd", converterConvertError);
- Source/WebCore/platform/graphics/filters/FilterEffect.cpp -7 / +7 lines
Lines 468-474 Optional<PixelBuffer> FilterEffect::conv Source/WebCore/platform/graphics/filters/FilterEffect.cpp_sec1
468
    // Color space conversion happens internally when drawing from one image buffer to another
468
    // Color space conversion happens internally when drawing from one image buffer to another
469
    convertedBuffer->context().drawImageBuffer(inputBuffer, rect);
469
    convertedBuffer->context().drawImageBuffer(inputBuffer, rect);
470
    
470
    
471
    PixelBufferFormat format { outputAlphaFormat, PixelFormat::RGBA8, DestinationColorSpace::SRGB };
471
    PixelBufferFormat format { outputAlphaFormat, PixelFormat::RGBA8, targetColorSpace };
472
    return convertedBuffer->getPixelBuffer(format, rect);
472
    return convertedBuffer->getPixelBuffer(format, rect);
473
}
473
}
474
474
Lines 504-510 void FilterEffect::copyUnmultipliedResul Source/WebCore/platform/graphics/filters/FilterEffect.cpp_sec2
504
                copyConvertedImageBufferToDestination(destination, *colorSpace, AlphaPremultiplication::Unpremultiplied, rect);
504
                copyConvertedImageBufferToDestination(destination, *colorSpace, AlphaPremultiplication::Unpremultiplied, rect);
505
                return;
505
                return;
506
            }
506
            }
507
            PixelBufferFormat format { AlphaPremultiplication::Unpremultiplied, PixelFormat::RGBA8, DestinationColorSpace::SRGB };
507
            PixelBufferFormat format { AlphaPremultiplication::Unpremultiplied, PixelFormat::RGBA8, m_imageBufferResult->colorSpace() };
508
            m_unmultipliedImageResult = m_imageBufferResult->getPixelBuffer(format, { IntPoint(), m_absolutePaintRect.size() });
508
            m_unmultipliedImageResult = m_imageBufferResult->getPixelBuffer(format, { IntPoint(), m_absolutePaintRect.size() });
509
            if (!m_unmultipliedImageResult)
509
            if (!m_unmultipliedImageResult)
510
                return;
510
                return;
Lines 512-518 void FilterEffect::copyUnmultipliedResul Source/WebCore/platform/graphics/filters/FilterEffect.cpp_sec3
512
            IntSize inputSize(m_absolutePaintRect.size());
512
            IntSize inputSize(m_absolutePaintRect.size());
513
            ASSERT(!ImageBuffer::sizeNeedsClamping(inputSize));
513
            ASSERT(!ImageBuffer::sizeNeedsClamping(inputSize));
514
            inputSize.scale(m_filter.filterScale());
514
            inputSize.scale(m_filter.filterScale());
515
            PixelBufferFormat format { AlphaPremultiplication::Unpremultiplied, PixelFormat::RGBA8, DestinationColorSpace::SRGB };
515
            PixelBufferFormat format { AlphaPremultiplication::Unpremultiplied, PixelFormat::RGBA8, m_imageBufferResult->colorSpace() };
516
            m_unmultipliedImageResult = PixelBuffer::tryCreate(format, inputSize);
516
            m_unmultipliedImageResult = PixelBuffer::tryCreate(format, inputSize);
517
            if (!m_unmultipliedImageResult)
517
            if (!m_unmultipliedImageResult)
518
                return;
518
                return;
Lines 539-545 void FilterEffect::copyPremultipliedResu Source/WebCore/platform/graphics/filters/FilterEffect.cpp_sec4
539
                copyConvertedImageBufferToDestination(destination, *colorSpace, AlphaPremultiplication::Premultiplied, rect);
539
                copyConvertedImageBufferToDestination(destination, *colorSpace, AlphaPremultiplication::Premultiplied, rect);
540
                return;
540
                return;
541
            }
541
            }
542
            PixelBufferFormat format { AlphaPremultiplication::Premultiplied, PixelFormat::RGBA8, DestinationColorSpace::SRGB };
542
            PixelBufferFormat format { AlphaPremultiplication::Premultiplied, PixelFormat::RGBA8, m_imageBufferResult->colorSpace() };
543
            m_premultipliedImageResult = m_imageBufferResult->getPixelBuffer(format, { IntPoint(), m_absolutePaintRect.size() });
543
            m_premultipliedImageResult = m_imageBufferResult->getPixelBuffer(format, { IntPoint(), m_absolutePaintRect.size() });
544
            if (!m_premultipliedImageResult)
544
            if (!m_premultipliedImageResult)
545
                return;
545
                return;
Lines 547-553 void FilterEffect::copyPremultipliedResu Source/WebCore/platform/graphics/filters/FilterEffect.cpp_sec5
547
            IntSize inputSize(m_absolutePaintRect.size());
547
            IntSize inputSize(m_absolutePaintRect.size());
548
            ASSERT(!ImageBuffer::sizeNeedsClamping(inputSize));
548
            ASSERT(!ImageBuffer::sizeNeedsClamping(inputSize));
549
            inputSize.scale(m_filter.filterScale());
549
            inputSize.scale(m_filter.filterScale());
550
            PixelBufferFormat format { AlphaPremultiplication::Premultiplied, PixelFormat::RGBA8, DestinationColorSpace::SRGB };
550
            PixelBufferFormat format { AlphaPremultiplication::Premultiplied, PixelFormat::RGBA8, m_imageBufferResult->colorSpace() };
551
            m_premultipliedImageResult = PixelBuffer::tryCreate(format, inputSize);
551
            m_premultipliedImageResult = PixelBuffer::tryCreate(format, inputSize);
552
            if (!m_premultipliedImageResult)
552
            if (!m_premultipliedImageResult)
553
                return;
553
                return;
Lines 590-596 Optional<PixelBuffer>& FilterEffect::cre Source/WebCore/platform/graphics/filters/FilterEffect.cpp_sec6
590
    IntSize resultSize(m_absolutePaintRect.size());
590
    IntSize resultSize(m_absolutePaintRect.size());
591
    ASSERT(!ImageBuffer::sizeNeedsClamping(resultSize));
591
    ASSERT(!ImageBuffer::sizeNeedsClamping(resultSize));
592
    resultSize.scale(m_filter.filterScale());
592
    resultSize.scale(m_filter.filterScale());
593
    PixelBufferFormat format { AlphaPremultiplication::Unpremultiplied, PixelFormat::RGBA8, DestinationColorSpace::SRGB };
593
    PixelBufferFormat format { AlphaPremultiplication::Unpremultiplied, PixelFormat::RGBA8, m_resultColorSpace };
594
    m_unmultipliedImageResult = PixelBuffer::tryCreate(format, resultSize);
594
    m_unmultipliedImageResult = PixelBuffer::tryCreate(format, resultSize);
595
    return m_unmultipliedImageResult;
595
    return m_unmultipliedImageResult;
596
}
596
}
Lines 609-615 Optional<PixelBuffer>& FilterEffect::cre Source/WebCore/platform/graphics/filters/FilterEffect.cpp_sec7
609
    IntSize resultSize(m_absolutePaintRect.size());
609
    IntSize resultSize(m_absolutePaintRect.size());
610
    ASSERT(!ImageBuffer::sizeNeedsClamping(resultSize));
610
    ASSERT(!ImageBuffer::sizeNeedsClamping(resultSize));
611
    resultSize.scale(m_filter.filterScale());
611
    resultSize.scale(m_filter.filterScale());
612
    PixelBufferFormat format { AlphaPremultiplication::Premultiplied, PixelFormat::RGBA8, DestinationColorSpace::SRGB };
612
    PixelBufferFormat format { AlphaPremultiplication::Premultiplied, PixelFormat::RGBA8, m_resultColorSpace };
613
    m_premultipliedImageResult = PixelBuffer::tryCreate(format, resultSize);
613
    m_premultipliedImageResult = PixelBuffer::tryCreate(format, resultSize);
614
    return m_premultipliedImageResult;
614
    return m_premultipliedImageResult;
615
}
615
}
- Source/WebCore/testing/Internals.cpp -2 / +2 lines
Lines 5339-5345 void Internals::videoSampleAvailable(Med Source/WebCore/testing/Internals.cpp_sec1
5339
    if (!rgba)
5339
    if (!rgba)
5340
        return;
5340
        return;
5341
    
5341
    
5342
    auto imageData = ImageData::create(rgba.releaseNonNull(), videoSettings.width(), videoSettings.height());
5342
    auto imageData = ImageData::create(rgba.releaseNonNull(), videoSettings.width(), videoSettings.height(), { { PredefinedColorSpace::SRGB } });
5343
    if (!imageData.hasException())
5343
    if (!imageData.hasException())
5344
        m_nextTrackFramePromise->resolve(imageData.releaseReturnValue());
5344
        m_nextTrackFramePromise->resolve(imageData.releaseReturnValue());
5345
    else
5345
    else
Lines 6211-6217 void Internals::loadArtworkImage(String& Source/WebCore/testing/Internals.cpp_sec2
6211
    m_artworkImagePromise = makeUnique<ArtworkImagePromise>(WTFMove(promise));
6211
    m_artworkImagePromise = makeUnique<ArtworkImagePromise>(WTFMove(promise));
6212
    m_artworkLoader = makeUnique<ArtworkImageLoader>(*contextDocument(), url, [this](Image* image) {
6212
    m_artworkLoader = makeUnique<ArtworkImageLoader>(*contextDocument(), url, [this](Image* image) {
6213
        if (image) {
6213
        if (image) {
6214
            auto imageData = ImageData::create(unsigned(image->width()), unsigned(image->height()));
6214
            auto imageData = ImageData::create(static_cast<unsigned>(image->width()), static_cast<unsigned>(image->height()), { { PredefinedColorSpace::SRGB } });
6215
            if (!imageData.hasException())
6215
            if (!imageData.hasException())
6216
                m_artworkImagePromise->resolve(imageData.releaseReturnValue());
6216
                m_artworkImagePromise->resolve(imageData.releaseReturnValue());
6217
            else
6217
            else
- LayoutTests/ChangeLog +22 lines
Lines 1-3 LayoutTests/ChangeLog_sec1
1
2021-05-14  Sam Weinig  <weinig@apple.com>
2
3
        Add support for creating/accessing/setting non-sRGB ImageData via canvas
4
        https://bugs.webkit.org/show_bug.cgi?id=225841
5
6
        Reviewed by NOBODY (OOPS!).
7
8
        * TestExpectations:
9
        Remove wide-gamut-canvas now that they should pass.
10
11
        * fast/canvas/canvas-color-space-display-p3-ImageData-expected.txt: Added.
12
        * fast/canvas/canvas-color-space-display-p3-ImageData.html: Added.
13
        Add new test exercising getImageData and putImageData with non-sRGB canvases
14
        and non-sRGB ImageData.
15
 
16
        * fast/canvas/canvas-imageData-expected.txt:
17
        Update results for updated error messages, which are a bit worse due additional
18
        ambiguity in signatures.
19
20
        * platform/glib/TestExpectations:
21
        Mark new test as failing on glib due to lack of display-p3 support.
22
1
2021-05-14  Eric Carlson  <eric.carlson@apple.com>
23
2021-05-14  Eric Carlson  <eric.carlson@apple.com>
2
24
3
        [GPUP] a media element with a data url and "crossorigin='anonymous'" doesn't load
25
        [GPUP] a media element with a data url and "crossorigin='anonymous'" doesn't load
- LayoutTests/TestExpectations -3 lines
Lines 3995-4003 imported/w3c/web-platform-tests/html/can LayoutTests/TestExpectations_sec1
3995
imported/w3c/web-platform-tests/html/canvas/element/drawing-images-to-the-canvas/image-orientation/drawImage-from-element-swap-width-height.tentative.html [ ImageOnlyFailure ]
3995
imported/w3c/web-platform-tests/html/canvas/element/drawing-images-to-the-canvas/image-orientation/drawImage-from-element-swap-width-height.tentative.html [ ImageOnlyFailure ]
3996
imported/w3c/web-platform-tests/html/canvas/element/drawing-images-to-the-canvas/image-orientation/drawImage-from-element.tentative.html [ ImageOnlyFailure ]
3996
imported/w3c/web-platform-tests/html/canvas/element/drawing-images-to-the-canvas/image-orientation/drawImage-from-element.tentative.html [ ImageOnlyFailure ]
3997
3997
3998
# Sometimes prints weird output at the beginning of the tests.
3999
imported/w3c/web-platform-tests/html/canvas/element/wide-gamut-canvas [ Failure Pass ]
4000
4001
# CSS Masonry Layout not supported.
3998
# CSS Masonry Layout not supported.
4002
imported/w3c/web-platform-tests/css/css-grid/masonry.tentative [ Skip ]
3999
imported/w3c/web-platform-tests/css/css-grid/masonry.tentative [ Skip ]
4003
webkit.org/b/202115 imported/w3c/web-platform-tests/css/css-grid/subgrid [ Skip ]
4000
webkit.org/b/202115 imported/w3c/web-platform-tests/css/css-grid/subgrid [ Skip ]
- LayoutTests/fast/canvas/canvas-color-space-display-p3-ImageData-expected.txt +159 lines
Line 0 LayoutTests/fast/canvas/canvas-color-space-display-p3-ImageData-expected.txt_sec1
1
Test that pixel access functions work with non-SRGB color spaces.
2
3
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
4
5
6
PASS imageDataCreatedFromDisplayP3Canvas.colorSpace is "display-p3"
7
PASS imageDataCreatedFromDisplayP3CanvasOverridingColorSpaceSRGB.colorSpace is "srgb"
8
PASS imageDataCreatedFromDisplayP3CanvasOverridingColorSpaceDisplayP3.colorSpace is "display-p3"
9
PASS imageDataCreatedFromSRGBCanvas.colorSpace is "srgb"
10
PASS imageDataCreatedFromSRGBCanvasOverridingColorSpaceSRGB.colorSpace is "srgb"
11
PASS imageDataCreatedFromSRGBCanvasOverridingColorSpaceDisplayP3.colorSpace is "display-p3"
12
PASS imageDataCreatedFromImageDataConstructor.colorSpace is "srgb"
13
PASS imageDataCreatedFromImageDataConstructorSettingColorSpaceToSRGB.colorSpace is "srgb"
14
PASS imageDataCreatedFromImageDataConstructorSettingColorSpaceToDisplayP3.colorSpace is "display-p3"
15
PASS imageDataCreatedFromImageDataConstructorPassingBuffer.colorSpace is "srgb"
16
PASS imageDataCreatedFromImageDataConstructorPassingBufferSettingColorSpaceToSRGB.colorSpace is "srgb"
17
PASS imageDataCreatedFromImageDataConstructorPassingBufferSettingColorSpaceToDisplayP3.colorSpace is "display-p3"
18
19
Testing a display-p3 canvas with color(display-p3 0 1 0) drawn into it
20
21
Test getImageData with no specified color space, on a display-p3 canvas (canvas has color(display-p3 0 1 0) drawn in it)
22
PASS data.colorSpace is "display-p3"
23
PASS data.data[0] is 0
24
PASS data.data[1] is 255
25
PASS data.data[2] is 0
26
PASS data.data[3] is 255
27
Test getImageData with srgb specified, on a display-p3 canvas (canvas has color(display-p3 0 1 0) drawn in it)
28
PASS data.colorSpace is "srgb"
29
PASS data.data[0] is 0
30
PASS data.data[1] is 255
31
PASS data.data[2] is 0
32
PASS data.data[3] is 255
33
Test getImageData with display-p3 specified, on a display-p3 canvas (canvas has color(display-p3 0 1 0) drawn in it)
34
PASS data.colorSpace is "display-p3"
35
PASS data.data[0] is 0
36
PASS data.data[1] is 255
37
PASS data.data[2] is 0
38
PASS data.data[3] is 255
39
40
Testing a display-p3 canvas with color(srgb 0 1 0) drawn into it
41
42
Test getImageData with no specified color space, on a display-p3 canvas (canvas has color(srgb 0 1 0) drawn in it)
43
PASS data.colorSpace is "display-p3"
44
PASS data.data[0] is 117
45
PASS data.data[1] is 251
46
PASS data.data[2] is 76
47
PASS data.data[3] is 255
48
Test getImageData with srgb specified, on a display-p3 canvas (canvas has color(srgb 0 1 0) drawn in it)
49
PASS data.colorSpace is "srgb"
50
PASS data.data[0] is 3
51
PASS data.data[1] is 255
52
PASS data.data[2] is 0
53
PASS data.data[3] is 255
54
Test getImageData with display-p3 specified, on a display-p3 canvas (canvas has color(srgb 0 1 0) drawn in it)
55
PASS data.colorSpace is "display-p3"
56
PASS data.data[0] is 117
57
PASS data.data[1] is 251
58
PASS data.data[2] is 76
59
PASS data.data[3] is 255
60
61
Testing a srgb canvas with color(display-p3 0 1 0) drawn into it
62
63
Test getImageData with no specified color space, on a srgb canvas (canvas has color(display-p3 0 1 0) drawn in it)
64
PASS data.colorSpace is "srgb"
65
PASS data.data[0] is 0
66
PASS data.data[1] is 255
67
PASS data.data[2] is 0
68
PASS data.data[3] is 255
69
Test getImageData with srgb specified, on a srgb canvas (canvas has color(display-p3 0 1 0) drawn in it)
70
PASS data.colorSpace is "srgb"
71
PASS data.data[0] is 0
72
PASS data.data[1] is 255
73
PASS data.data[2] is 0
74
PASS data.data[3] is 255
75
Test getImageData with display-p3 specified, on a srgb canvas (canvas has color(display-p3 0 1 0) drawn in it)
76
PASS data.colorSpace is "display-p3"
77
PASS data.data[0] is 117
78
PASS data.data[1] is 251
79
PASS data.data[2] is 76
80
PASS data.data[3] is 255
81
82
Testing a srgb canvas with color(srgb-p3 0 1 0) drawn into it
83
84
Test getImageData with no specified color space, on a srgb canvas (canvas has color(srgb 0 1 0) drawn in it)
85
PASS data.colorSpace is "srgb"
86
PASS data.data[0] is 0
87
PASS data.data[1] is 255
88
PASS data.data[2] is 0
89
PASS data.data[3] is 255
90
Test getImageData with srgb specified, on a srgb canvas (canvas has color(srgb 0 1 0) drawn in it)
91
PASS data.colorSpace is "srgb"
92
PASS data.data[0] is 0
93
PASS data.data[1] is 255
94
PASS data.data[2] is 0
95
PASS data.data[3] is 255
96
Test getImageData with display-p3 specified, on a srgb canvas (canvas has color(srgb 0 1 0) drawn in it)
97
PASS data.colorSpace is "display-p3"
98
PASS data.data[0] is 117
99
PASS data.data[1] is 251
100
PASS data.data[2] is 76
101
PASS data.data[3] is 255
102
103
104
Testing a display-p3 canvas with display-p3 ImageData drawn into it
105
106
PASS data.colorSpace is "srgb"
107
PASS data.data[0] is 0
108
PASS data.data[1] is 255
109
PASS data.data[2] is 0
110
PASS data.data[3] is 255
111
PASS data.colorSpace is "display-p3"
112
PASS data.data[0] is 0
113
PASS data.data[1] is 255
114
PASS data.data[2] is 0
115
PASS data.data[3] is 255
116
117
Testing a display-p3 canvas with srgb ImageData drawn into it
118
119
PASS data.colorSpace is "srgb"
120
PASS data.data[0] is 3
121
PASS data.data[1] is 255
122
PASS data.data[2] is 0
123
PASS data.data[3] is 255
124
PASS data.colorSpace is "display-p3"
125
PASS data.data[0] is 117
126
PASS data.data[1] is 251
127
PASS data.data[2] is 76
128
PASS data.data[3] is 255
129
130
Testing a srgb canvas with display-p3 ImageData drawn into it
131
132
PASS data.colorSpace is "srgb"
133
PASS data.data[0] is 0
134
PASS data.data[1] is 255
135
PASS data.data[2] is 0
136
PASS data.data[3] is 255
137
PASS data.colorSpace is "display-p3"
138
PASS data.data[0] is 117
139
PASS data.data[1] is 251
140
PASS data.data[2] is 76
141
PASS data.data[3] is 255
142
143
Testing a srgb canvas with srgb ImageData drawn into it
144
145
PASS data.colorSpace is "srgb"
146
PASS data.data[0] is 0
147
PASS data.data[1] is 255
148
PASS data.data[2] is 0
149
PASS data.data[3] is 255
150
PASS data.colorSpace is "display-p3"
151
PASS data.data[0] is 117
152
PASS data.data[1] is 251
153
PASS data.data[2] is 76
154
PASS data.data[3] is 255
155
156
PASS successfullyParsed is true
157
158
TEST COMPLETE
159
- LayoutTests/fast/canvas/canvas-color-space-display-p3-ImageData.html +290 lines
Line 0 LayoutTests/fast/canvas/canvas-color-space-display-p3-ImageData.html_sec1
1
<!DOCTYPE html>
2
<html>
3
<head>
4
<script src="../../resources/js-test-pre.js"></script>
5
</head>
6
<body>
7
<script>
8
description("Test that pixel access functions work with non-SRGB color spaces.");
9
10
let canvasDisplayP3 = document.createElement("canvas");
11
let contextDisplayP3 = canvasDisplayP3.getContext("2d", { colorSpace: "display-p3" });
12
13
let canvasSRGB = document.createElement("canvas");
14
let contextSRGB = canvasSRGB.getContext("2d", { colorSpace: "srgb" });
15
16
const imageDataCreatedFromDisplayP3Canvas = contextDisplayP3.createImageData(50, 50);
17
shouldBe("imageDataCreatedFromDisplayP3Canvas.colorSpace", `"display-p3"`);
18
19
const imageDataCreatedFromDisplayP3CanvasOverridingColorSpaceSRGB = contextDisplayP3.createImageData(50, 50, { colorSpace: "srgb" });
20
shouldBe("imageDataCreatedFromDisplayP3CanvasOverridingColorSpaceSRGB.colorSpace", `"srgb"`);
21
22
const imageDataCreatedFromDisplayP3CanvasOverridingColorSpaceDisplayP3 = contextDisplayP3.createImageData(50, 50, { colorSpace: "display-p3" });
23
shouldBe("imageDataCreatedFromDisplayP3CanvasOverridingColorSpaceDisplayP3.colorSpace", `"display-p3"`);
24
25
const imageDataCreatedFromSRGBCanvas = contextSRGB.createImageData(50, 50);
26
shouldBe("imageDataCreatedFromSRGBCanvas.colorSpace", `"srgb"`);
27
28
const imageDataCreatedFromSRGBCanvasOverridingColorSpaceSRGB = contextSRGB.createImageData(50, 50, { colorSpace: "srgb" });
29
shouldBe("imageDataCreatedFromSRGBCanvasOverridingColorSpaceSRGB.colorSpace", `"srgb"`);
30
31
const imageDataCreatedFromSRGBCanvasOverridingColorSpaceDisplayP3 = contextSRGB.createImageData(50, 50, { colorSpace: "display-p3" });
32
shouldBe("imageDataCreatedFromSRGBCanvasOverridingColorSpaceDisplayP3.colorSpace", `"display-p3"`);
33
34
const imageDataCreatedFromImageDataConstructor = new ImageData(50, 50, { colorSpace: "srgb" });
35
shouldBe("imageDataCreatedFromImageDataConstructor.colorSpace", `"srgb"`);
36
37
const imageDataCreatedFromImageDataConstructorSettingColorSpaceToSRGB = new ImageData(50, 50, { colorSpace: "srgb" });
38
shouldBe("imageDataCreatedFromImageDataConstructorSettingColorSpaceToSRGB.colorSpace", `"srgb"`);
39
40
const imageDataCreatedFromImageDataConstructorSettingColorSpaceToDisplayP3 = new ImageData(50, 50, { colorSpace: "display-p3" });
41
shouldBe("imageDataCreatedFromImageDataConstructorSettingColorSpaceToDisplayP3.colorSpace", `"display-p3"`);
42
43
const imageDataCreatedFromImageDataConstructorPassingBuffer = new ImageData(new Uint8ClampedArray(400), 10, 10, { colorSpace: "srgb" });
44
shouldBe("imageDataCreatedFromImageDataConstructorPassingBuffer.colorSpace", `"srgb"`);
45
46
const imageDataCreatedFromImageDataConstructorPassingBufferSettingColorSpaceToSRGB = new ImageData(new Uint8ClampedArray(400), 10, 10, { colorSpace: "srgb" });
47
shouldBe("imageDataCreatedFromImageDataConstructorPassingBufferSettingColorSpaceToSRGB.colorSpace", `"srgb"`);
48
49
const imageDataCreatedFromImageDataConstructorPassingBufferSettingColorSpaceToDisplayP3 = new ImageData(new Uint8ClampedArray(400), 10, 10, { colorSpace: "display-p3" });
50
shouldBe("imageDataCreatedFromImageDataConstructorPassingBufferSettingColorSpaceToDisplayP3.colorSpace", `"display-p3"`);
51
52
var data = { };
53
54
// NOTE:
55
// color(srgb 0 1 0) converted to display-p3 is color(display-p3 0.4584 0.98526 0.29829) or [117, 251, 76, 255] in byte form.
56
57
debug("");
58
debug("Testing a display-p3 canvas with color(display-p3 0 1 0) drawn into it");
59
debug("");
60
61
contextDisplayP3.fillStyle = "color(display-p3 0 1 0)";
62
contextDisplayP3.fillRect(0, 0, 50, 50);
63
64
// No specified color space will default to the canvas' color space, in this case, display-p3
65
debug("Test getImageData with no specified color space, on a display-p3 canvas (canvas has color(display-p3 0 1 0) drawn in it)");
66
data = contextDisplayP3.getImageData(0, 0, 1, 1);
67
shouldBe("data.colorSpace", `"display-p3"`)
68
shouldBe("data.data[0]", "0");
69
shouldBe("data.data[1]", "255");
70
shouldBe("data.data[2]", "0");
71
shouldBe("data.data[3]", "255");
72
73
debug("Test getImageData with srgb specified, on a display-p3 canvas (canvas has color(display-p3 0 1 0) drawn in it)");
74
// NOTE: color(display-p3 0 1 0) is outside the range of sRGB, so it clipped to 255.
75
data = contextDisplayP3.getImageData(0, 0, 1, 1, { colorSpace: "srgb" });
76
shouldBe("data.colorSpace", `"srgb"`)
77
shouldBe("data.data[0]", "0");
78
shouldBe("data.data[1]", "255");
79
shouldBe("data.data[2]", "0");
80
shouldBe("data.data[3]", "255");
81
82
debug("Test getImageData with display-p3 specified, on a display-p3 canvas (canvas has color(display-p3 0 1 0) drawn in it)");
83
data = contextDisplayP3.getImageData(0, 0, 1, 1, { colorSpace: "display-p3" });
84
shouldBe("data.colorSpace", `"display-p3"`)
85
shouldBe("data.data[0]", "0");
86
shouldBe("data.data[1]", "255");
87
shouldBe("data.data[2]", "0");
88
shouldBe("data.data[3]", "255");
89
90
debug("");
91
debug("Testing a display-p3 canvas with color(srgb 0 1 0) drawn into it");
92
debug("");
93
94
contextDisplayP3.fillStyle = "color(srgb 0 1 0)";
95
contextDisplayP3.fillRect(0, 0, 50, 50);
96
97
// No specified color space will default to the canvas' color space, in this case, display-p3
98
debug("Test getImageData with no specified color space, on a display-p3 canvas (canvas has color(srgb 0 1 0) drawn in it)");
99
data = contextDisplayP3.getImageData(0, 0, 1, 1);
100
shouldBe("data.colorSpace", `"display-p3"`)
101
shouldBe("data.data[0]", "117");
102
shouldBe("data.data[1]", "251");
103
shouldBe("data.data[2]", "76");
104
shouldBe("data.data[3]", "255");
105
106
debug("Test getImageData with srgb specified, on a display-p3 canvas (canvas has color(srgb 0 1 0) drawn in it)");
107
data = contextDisplayP3.getImageData(0, 0, 1, 1, { colorSpace: "srgb" });
108
shouldBe("data.colorSpace", `"srgb"`)
109
// NOTE: This 3 is odd, but due to lack of precision in 8-bit round-tripping.
110
shouldBe("data.data[0]", "3");
111
shouldBe("data.data[1]", "255");
112
shouldBe("data.data[2]", "0");
113
shouldBe("data.data[3]", "255");
114
115
debug("Test getImageData with display-p3 specified, on a display-p3 canvas (canvas has color(srgb 0 1 0) drawn in it)");
116
data = contextDisplayP3.getImageData(0, 0, 1, 1, { colorSpace: "display-p3" });
117
shouldBe("data.colorSpace", `"display-p3"`)
118
shouldBe("data.data[0]", "117");
119
shouldBe("data.data[1]", "251");
120
shouldBe("data.data[2]", "76");
121
shouldBe("data.data[3]", "255");
122
123
debug("");
124
debug("Testing a srgb canvas with color(display-p3 0 1 0) drawn into it");
125
debug("");
126
127
contextSRGB.fillStyle = "color(display-p3 0 1 0)";
128
contextSRGB.fillRect(0, 0, 50, 50);
129
130
// No specified color space will default to the canvas' color space, in this case, srgb
131
debug("Test getImageData with no specified color space, on a srgb canvas (canvas has color(display-p3 0 1 0) drawn in it)");
132
data = contextSRGB.getImageData(0, 0, 1, 1);
133
shouldBe("data.colorSpace", `"srgb"`)
134
shouldBe("data.data[0]", "0");
135
shouldBe("data.data[1]", "255");
136
shouldBe("data.data[2]", "0");
137
shouldBe("data.data[3]", "255");
138
139
debug("Test getImageData with srgb specified, on a srgb canvas (canvas has color(display-p3 0 1 0) drawn in it)");
140
data = contextSRGB.getImageData(0, 0, 1, 1, { colorSpace: "srgb" });
141
shouldBe("data.colorSpace", `"srgb"`)
142
shouldBe("data.data[0]", "0");
143
shouldBe("data.data[1]", "255");
144
shouldBe("data.data[2]", "0");
145
shouldBe("data.data[3]", "255");
146
147
debug("Test getImageData with display-p3 specified, on a srgb canvas (canvas has color(display-p3 0 1 0) drawn in it)");
148
data = contextSRGB.getImageData(0, 0, 1, 1, { colorSpace: "display-p3" });
149
shouldBe("data.colorSpace", `"display-p3"`)
150
shouldBe("data.data[0]", "117");
151
shouldBe("data.data[1]", "251");
152
shouldBe("data.data[2]", "76");
153
shouldBe("data.data[3]", "255");
154
155
debug("");
156
debug("Testing a srgb canvas with color(srgb-p3 0 1 0) drawn into it");
157
debug("");
158
159
contextSRGB.fillStyle = "color(srgb 0 1 0)";
160
contextSRGB.fillRect(0, 0, 50, 50);
161
162
// No specified color space will default to the canvas' color space, in this case, srgb
163
debug("Test getImageData with no specified color space, on a srgb canvas (canvas has color(srgb 0 1 0) drawn in it)");
164
data = contextSRGB.getImageData(0, 0, 1, 1);
165
shouldBe("data.colorSpace", `"srgb"`)
166
shouldBe("data.data[0]", "0");
167
shouldBe("data.data[1]", "255");
168
shouldBe("data.data[2]", "0");
169
shouldBe("data.data[3]", "255");
170
171
debug("Test getImageData with srgb specified, on a srgb canvas (canvas has color(srgb 0 1 0) drawn in it)");
172
data = contextSRGB.getImageData(0, 0, 1, 1, { colorSpace: "srgb" });
173
shouldBe("data.colorSpace", `"srgb"`)
174
shouldBe("data.data[0]", "0");
175
shouldBe("data.data[1]", "255");
176
shouldBe("data.data[2]", "0");
177
shouldBe("data.data[3]", "255");
178
179
debug("Test getImageData with display-p3 specified, on a srgb canvas (canvas has color(srgb 0 1 0) drawn in it)");
180
data = contextSRGB.getImageData(0, 0, 1, 1, { colorSpace: "display-p3" });
181
shouldBe("data.colorSpace", `"display-p3"`)
182
shouldBe("data.data[0]", "117");
183
shouldBe("data.data[1]", "251");
184
shouldBe("data.data[2]", "76");
185
shouldBe("data.data[3]", "255");
186
187
188
debug("");
189
190
191
const imageDataDisplayP3ToPut = new ImageData(1, 1, { colorSpace: "display-p3" });
192
imageDataDisplayP3ToPut.data[0] = 0;
193
imageDataDisplayP3ToPut.data[1] = 255;
194
imageDataDisplayP3ToPut.data[2] = 0;
195
imageDataDisplayP3ToPut.data[3] = 255;
196
197
const imageDataSRGBToPut = new ImageData(1, 1, { colorSpace: "srgb" });
198
imageDataSRGBToPut.data[0] = 0;
199
imageDataSRGBToPut.data[1] = 255;
200
imageDataSRGBToPut.data[2] = 0;
201
imageDataSRGBToPut.data[3] = 255;
202
203
204
debug("");
205
debug("Testing a display-p3 canvas with display-p3 ImageData drawn into it");
206
debug("");
207
208
contextDisplayP3.putImageData(imageDataDisplayP3ToPut, 0, 0);
209
210
data = contextDisplayP3.getImageData(0, 0, 1, 1, { colorSpace: "srgb" });
211
shouldBe("data.colorSpace", `"srgb"`)
212
shouldBe("data.data[0]", "0");
213
shouldBe("data.data[1]", "255");
214
shouldBe("data.data[2]", "0");
215
shouldBe("data.data[3]", "255");
216
217
data = contextDisplayP3.getImageData(0, 0, 1, 1, { colorSpace: "display-p3" });
218
shouldBe("data.colorSpace", `"display-p3"`)
219
shouldBe("data.data[0]", "0");
220
shouldBe("data.data[1]", "255");
221
shouldBe("data.data[2]", "0");
222
shouldBe("data.data[3]", "255");
223
224
debug("");
225
debug("Testing a display-p3 canvas with srgb ImageData drawn into it");
226
debug("");
227
228
contextDisplayP3.putImageData(imageDataSRGBToPut, 0, 0);
229
230
data = contextDisplayP3.getImageData(0, 0, 1, 1, { colorSpace: "srgb" });
231
shouldBe("data.colorSpace", `"srgb"`)
232
// NOTE: This 3 is odd, but due to lack of precision in 8-bit round-tripping.
233
shouldBe("data.data[0]", "3");
234
shouldBe("data.data[1]", "255");
235
shouldBe("data.data[2]", "0");
236
shouldBe("data.data[3]", "255");
237
238
data = contextDisplayP3.getImageData(0, 0, 1, 1, { colorSpace: "display-p3" });
239
shouldBe("data.colorSpace", `"display-p3"`)
240
shouldBe("data.data[0]", "117");
241
shouldBe("data.data[1]", "251");
242
shouldBe("data.data[2]", "76");
243
shouldBe("data.data[3]", "255");
244
245
debug("");
246
debug("Testing a srgb canvas with display-p3 ImageData drawn into it");
247
debug("");
248
249
contextSRGB.putImageData(imageDataDisplayP3ToPut, 0, 0);
250
251
data = contextSRGB.getImageData(0, 0, 1, 1, { colorSpace: "srgb" });
252
shouldBe("data.colorSpace", `"srgb"`)
253
shouldBe("data.data[0]", "0");
254
shouldBe("data.data[1]", "255");
255
shouldBe("data.data[2]", "0");
256
shouldBe("data.data[3]", "255");
257
258
data = contextSRGB.getImageData(0, 0, 1, 1, { colorSpace: "display-p3" });
259
shouldBe("data.colorSpace", `"display-p3"`)
260
shouldBe("data.data[0]", "117");
261
shouldBe("data.data[1]", "251");
262
shouldBe("data.data[2]", "76");
263
shouldBe("data.data[3]", "255");
264
265
266
debug("");
267
debug("Testing a srgb canvas with srgb ImageData drawn into it");
268
debug("");
269
270
contextSRGB.putImageData(imageDataSRGBToPut, 0, 0);
271
272
data = contextSRGB.getImageData(0, 0, 1, 1, { colorSpace: "srgb" });
273
shouldBe("data.colorSpace", `"srgb"`)
274
shouldBe("data.data[0]", "0");
275
shouldBe("data.data[1]", "255");
276
shouldBe("data.data[2]", "0");
277
shouldBe("data.data[3]", "255");
278
279
data = contextSRGB.getImageData(0, 0, 1, 1, { colorSpace: "display-p3" });
280
shouldBe("data.colorSpace", `"display-p3"`)
281
shouldBe("data.data[0]", "117");
282
shouldBe("data.data[1]", "251");
283
shouldBe("data.data[2]", "76");
284
shouldBe("data.data[3]", "255");
285
286
debug("");
287
</script>
288
<script src="../../resources/js-test-post.js"></script>
289
</body>
290
</html>
- LayoutTests/fast/canvas/canvas-imageData-expected.txt -9 / +9 lines
Lines 14-33 PASS new ImageData(-20, 20) threw except LayoutTests/fast/canvas/canvas-imageData-expected.txt_sec1
14
PASS new ImageData(20, -20) threw exception RangeError: Cannot allocate a buffer of this size.
14
PASS new ImageData(20, -20) threw exception RangeError: Cannot allocate a buffer of this size.
15
PASS new ImageData(null, 20) threw exception IndexSizeError: The index is not in the allowed range..
15
PASS new ImageData(null, 20) threw exception IndexSizeError: The index is not in the allowed range..
16
PASS new ImageData(32768, 32768) threw exception RangeError: Cannot allocate a buffer of this size.
16
PASS new ImageData(32768, 32768) threw exception RangeError: Cannot allocate a buffer of this size.
17
PASS new ImageData(null, 20, 20) threw exception TypeError: Argument 1 ('data') to the ImageData constructor must be an instance of Uint8ClampedArray.
17
PASS new ImageData(null, 20, 20) threw exception TypeError: Type error.
18
PASS new ImageData(imageData, 20, 20) threw exception TypeError: Argument 1 ('data') to the ImageData constructor must be an instance of Uint8ClampedArray.
18
PASS new ImageData(imageData, 20, 20) threw exception TypeError: Type error.
19
PASS new ImageData(imageData, 0) threw exception IndexSizeError: The index is not in the allowed range..
19
PASS new ImageData(imageData, 0) threw exception IndexSizeError: The index is not in the allowed range..
20
PASS new ImageData(imageData, 20, 0) threw exception TypeError: Argument 1 ('data') to the ImageData constructor must be an instance of Uint8ClampedArray.
20
PASS new ImageData(imageData, 20, 0) threw exception TypeError: Type error.
21
PASS new ImageData(imageData, 0, 20) threw exception TypeError: Argument 1 ('data') to the ImageData constructor must be an instance of Uint8ClampedArray.
21
PASS new ImageData(imageData, 0, 20) threw exception TypeError: Type error.
22
PASS new ImageData(imageData, 10, 5) threw exception TypeError: Argument 1 ('data') to the ImageData constructor must be an instance of Uint8ClampedArray.
22
PASS new ImageData(imageData, 10, 5) threw exception TypeError: Type error.
23
PASS new ImageData(imageData.data, 10, 5) threw exception IndexSizeError: sh value is not equal to height.
23
PASS new ImageData(imageData.data, 10, 5) threw exception IndexSizeError: sh value is not equal to height.
24
PASS new ImageData(imageData.data, -10, 5) threw exception IndexSizeError: Length is not a multiple of sw.
24
PASS new ImageData(imageData.data, -10, 5) threw exception IndexSizeError: Length is not a multiple of sw.
25
PASS new ImageData(imageData.data, 10, -10) threw exception IndexSizeError: sh value is not equal to height.
25
PASS new ImageData(imageData.data, 10, -10) threw exception IndexSizeError: sh value is not equal to height.
26
PASS new ImageData(new Uint8ClampedArray([1,2,3,4,5,6,7,8]),536870913,2); threw exception IndexSizeError: Length is not a multiple of sw.
26
PASS new ImageData(new Uint8ClampedArray([1,2,3,4,5,6,7,8]),536870913,2); threw exception IndexSizeError: Length is not a multiple of sw.
27
PASS new ImageData({},2,2); threw exception TypeError: Argument 1 ('data') to the ImageData constructor must be an instance of Uint8ClampedArray.
27
PASS new ImageData({},2,2); threw exception TypeError: Type error.
28
PASS new ImageData(undefined,2,2); threw exception TypeError: Argument 1 ('data') to the ImageData constructor must be an instance of Uint8ClampedArray.
28
PASS new ImageData(undefined,2,2); threw exception TypeError: Type error.
29
PASS new ImageData("none",2,2); threw exception TypeError: Argument 1 ('data') to the ImageData constructor must be an instance of Uint8ClampedArray.
29
PASS new ImageData("none",2,2); threw exception TypeError: Type error.
30
PASS new ImageData(0,2,2); threw exception TypeError: Argument 1 ('data') to the ImageData constructor must be an instance of Uint8ClampedArray.
30
PASS new ImageData(0,2,2); threw exception TypeError: Type error.
31
PASS new ImageData(imageData.data, 32768, 32768) threw exception IndexSizeError: Length is not a multiple of sw.
31
PASS new ImageData(imageData.data, 32768, 32768) threw exception IndexSizeError: Length is not a multiple of sw.
32
PASS new ImageData(imageData.data, Infinity, Infinity) threw exception IndexSizeError: Length is not a multiple of sw.
32
PASS new ImageData(imageData.data, Infinity, Infinity) threw exception IndexSizeError: Length is not a multiple of sw.
33
PASS new ImageData(imageData.data, NaN, NaN) threw exception IndexSizeError: Length is not a multiple of sw.
33
PASS new ImageData(imageData.data, NaN, NaN) threw exception IndexSizeError: Length is not a multiple of sw.
- LayoutTests/imported/w3c/ChangeLog +10 lines
Lines 1-3 LayoutTests/imported/w3c/ChangeLog_sec1
1
2021-05-14  Sam Weinig  <weinig@apple.com>
2
3
        Add support for creating/accessing/setting non-sRGB ImageData via canvas
4
        https://bugs.webkit.org/show_bug.cgi?id=225841
5
6
        Reviewed by NOBODY (OOPS!).
7
8
        * web-platform-tests/html/canvas/element/wide-gamut-canvas/2d.color.space.p3.to.p3-expected.txt:
9
        Update result to passing.
10
1
2021-05-14  Darin Adler  <darin@apple.com>
11
2021-05-14  Darin Adler  <darin@apple.com>
2
12
3
        output element doesn't react properly to node tree mutations
13
        output element doesn't react properly to node tree mutations
- LayoutTests/imported/w3c/web-platform-tests/html/canvas/element/wide-gamut-canvas/2d.color.space.p3.to.p3-expected.txt -1 / +1 lines
Lines 2-6 LayoutTests/imported/w3c/web-platform-tests/html/canvas/element/wide-gamut-canvas/2d.color.space.p3.to.p3-expected.txt_sec1
2
test getImageData with display-p3 and uint8 from display p3 uint8 canvas
2
test getImageData with display-p3 and uint8 from display p3 uint8 canvas
3
Actual output:
3
Actual output:
4
4
5
FAIL test getImageData with display-p3 and uint8 from display p3 uint8 canvas assert_approx_equals: expected 62 +/- 2 but got 50
5
PASS test getImageData with display-p3 and uint8 from display p3 uint8 canvas
6
6
- LayoutTests/platform/glib/TestExpectations +1 lines
Lines 2358-2363 fast/replaced/pdf-as-embed-with-no-mime- LayoutTests/platform/glib/TestExpectations_sec1
2358
webkit.org/b/224112 media/video-as-img-output-pts.html [ Timeout Pass ]
2358
webkit.org/b/224112 media/video-as-img-output-pts.html [ Timeout Pass ]
2359
2359
2360
webkit.org/b/225423 fast/canvas/canvas-color-space-display-p3.html [ ImageOnlyFailure ]
2360
webkit.org/b/225423 fast/canvas/canvas-color-space-display-p3.html [ ImageOnlyFailure ]
2361
webkit.org/b/225423 fast/canvas/canvas-color-space-display-p3-ImageData.html [ Failure ]
2361
webkit.org/b/225423 fast/canvas/canvas-composite-text-alpha.html [ Failure ]
2362
webkit.org/b/225423 fast/canvas/canvas-composite-text-alpha.html [ Failure ]
2362
2363
2363
# Failing after r277073.
2364
# Failing after r277073.
- LayoutTests/storage/indexeddb/modern/objectstore-autoincrement-types-expected.txt +2 lines
Lines 26-31 PASS key is 3 LayoutTests/storage/indexeddb/modern/objectstore-autoincrement-types-expected.txt_sec1
26
PASS request.result.primaryKey is imageData.primaryKey
26
PASS request.result.primaryKey is imageData.primaryKey
27
PASS request.result.width is imageData.width
27
PASS request.result.width is imageData.width
28
PASS request.result.height is imageData.height
28
PASS request.result.height is imageData.height
29
PASS request.result.colorSpace is imageData.colorSpace
29
PASS key is 4
30
PASS key is 4
30
PASS request.result.primaryKey is fileList.primaryKey
31
PASS request.result.primaryKey is fileList.primaryKey
31
PASS request.result.length is fileList.length
32
PASS request.result.length is fileList.length
Lines 40-45 PASS request.result[1].type is file.type LayoutTests/storage/indexeddb/modern/objectstore-autoincrement-types-expected.txt_sec2
40
PASS request.result[2].primaryKey is imageData.primaryKey
41
PASS request.result[2].primaryKey is imageData.primaryKey
41
PASS request.result[2].width is imageData.width
42
PASS request.result[2].width is imageData.width
42
PASS request.result[2].height is imageData.height
43
PASS request.result[2].height is imageData.height
44
PASS request.result[2].colorSpace is imageData.colorSpace
43
PASS request.result[3].primaryKey is fileList.primaryKey
45
PASS request.result[3].primaryKey is fileList.primaryKey
44
PASS request.result[3].length is fileList.length
46
PASS request.result[3].length is fileList.length
45
PASS successfullyParsed is true
47
PASS successfullyParsed is true

Return to Bug 225841