diff --git a/dom/canvas/ImageBitmapRenderingContext.cpp b/dom/canvas/ImageBitmapRenderingContext.cpp index b03962b542a61..72892e5dbc30f 100644 --- a/dom/canvas/ImageBitmapRenderingContext.cpp +++ b/dom/canvas/ImageBitmapRenderingContext.cpp @@ -418,6 +418,66 @@ return } if ( +mCanvasElement +) +{ +mCanvasElement +- +> +SetSize +( +mImage +- +> +GetSize +( +) +aRv +) +; +} +else +if +( +mOffscreenCanvas +) +{ +mOffscreenCanvas +- +> +SetSize +( +mImage +- +> +GetSize +( +) +aRv +) +; +} +if +( +NS_WARN_IF +( +aRv +. +Failed +( +) +) +) +{ +mImage += +nullptr +; +return +; +} +if +( aImageBitmap - > @@ -487,6 +547,52 @@ mHeight = aHeight ; +if +( +mOffscreenCanvas +) +{ +OffscreenCanvasDisplayData +data +; +data +. +mSize += +{ +mWidth +mHeight +} +; +data +. +mIsOpaque += +GetIsOpaque +( +) +; +data +. +mIsAlphaPremult += +true +; +data +. +mDoPaintCallbacks += +false +; +mOffscreenCanvas +- +> +UpdateDisplayData +( +data +) +; +} return NS_OK ; diff --git a/dom/canvas/OffscreenCanvas.cpp b/dom/canvas/OffscreenCanvas.cpp index ad328fa10d3e5..523c9ab6888f1 100644 --- a/dom/canvas/OffscreenCanvas.cpp +++ b/dom/canvas/OffscreenCanvas.cpp @@ -817,6 +817,97 @@ void OffscreenCanvas : : +SetSize +( +const +nsIntSize +& +aSize +ErrorResult +& +aRv +) +{ +if +( +mNeutered +) +{ +aRv +. +ThrowInvalidStateError +( +" +Cannot +set +dimensions +of +placeholder +canvas +transferred +to +worker +. +" +) +; +return +; +} +if +( +NS_WARN_IF +( +aSize +. +IsEmpty +( +) +) +) +{ +aRv +. +ThrowRangeError +( +" +OffscreenCanvas +size +is +empty +must +be +non +- +empty +. +" +) +; +return +; +} +mWidth += +aSize +. +width +; +mHeight += +aSize +. +height +; +CanvasAttrChanged +( +) +; +} +void +OffscreenCanvas +: +: GetContext ( JSContext diff --git a/dom/canvas/OffscreenCanvas.h b/dom/canvas/OffscreenCanvas.h index 2486a4e450a1d..7da36d7e52381 100644 --- a/dom/canvas/OffscreenCanvas.h +++ b/dom/canvas/OffscreenCanvas.h @@ -647,6 +647,18 @@ mNeutered mCurrentContext ; } +void +SetSize +( +const +nsIntSize +& +aSize +ErrorResult +& +aRv +) +; nsIPrincipal * GetExpandedReader diff --git a/dom/canvas/test/test_bitmaprenderer.html b/dom/canvas/test/test_bitmaprenderer.html index d9a61ab2a859a..132ce90a52fc1 100644 --- a/dom/canvas/test/test_bitmaprenderer.html +++ b/dom/canvas/test/test_bitmaprenderer.html @@ -341,8 +341,8 @@ = createCanvas ( -90 -90 +canvasWidth +canvasHeight ) ; var @@ -384,8 +384,8 @@ ( 0 0 -90 -90 +canvasWidth +canvasHeight ) ; ctx @@ -689,23 +689,25 @@ ; } function -scaleTest +createSolidGreenBitmap ( +width +height ) { -var -canvas1 +const +canvas = createCanvas ( -64 -64 +width +height ) ; -var +const ctx = -canvas1 +canvas . getContext ( @@ -729,124 +731,67 @@ ( 0 0 -64 -64 -) -; -var -canvas2 -= -createCanvas -( -64 -64 +width +height ) ; -var -ctx2 +const +bitmap = -canvas2 -. -getContext +createImageBitmap ( -" -2d -" +canvas ) ; -ctx2 +document . -fillStyle -= -" -# -00FF00 -" -; -ctx2 +body . -fillRect -( -0 -0 -64 -64 -) -; -var -p1 -= -createImageBitmap +removeChild ( -canvas1 +canvas ) ; -var -p2 -= -createImageBitmap -( -canvas2 -) +return +bitmap ; -Promise -. -all -( -[ -p1 -p2 -] -) -. -then -( +} async function +scaleTestCase ( -bitmaps +name +refWidth +refHeight +testWidth +testHeight +canvasWidth +canvasHeight ) { -document -. -body -. -removeChild -( -canvas1 -) -; -document -. -body -. -removeChild +const +refBitmap += +await +createSolidGreenBitmap ( -canvas2 +refWidth +refHeight ) ; -/ -/ -Create -a -large -canvas -then -shrink -. -var -canvas3 +const +refCanvas = createCanvas ( -128 -128 +refWidth +refHeight ) ; -var -ctx3 +const +refCtx = -canvas3 +refCanvas . getContext ( @@ -855,39 +800,67 @@ " ) ; -ctx3 +refCtx . transferFromImageBitmap ( -bitmaps -[ -0 -] +refBitmap ) ; -var -snapshotLargeRef -= -await -snapshotWindow +is ( -window -) -; -canvas3 +refCanvas . width -= -32 +refWidth +name ++ +" +: +refCanvas +width +" ++ +refCanvas +. +width ++ +" +is +ref +" ++ +refWidth +) ; -canvas3 +is +( +refCanvas . height -= -32 +refHeight +name ++ +" +: +refCanvas +height +" ++ +refCanvas +. +height ++ +" +is +ref +" ++ +refHeight +) ; -var -snapshotSmall +const +refSnapshot = await snapshotWindow @@ -901,31 +874,32 @@ . removeChild ( -canvas3 +refCanvas ) ; -/ -/ -Create -a -small +const +bitmap += +await +createSolidGreenBitmap +( +testWidth +testHeight +) +; +const canvas -then -grow -. -var -canvas4 = createCanvas ( -32 -32 +canvasWidth +canvasHeight ) ; -var -ctx4 +const +ctx = -canvas4 +canvas . getContext ( @@ -934,39 +908,151 @@ " ) ; -ctx4 +ctx . transferFromImageBitmap ( -bitmaps -[ -1 -] +bitmap ) ; -var -snapshotSmallRef -= -await -snapshotWindow +is ( -window +canvas +. +width +testWidth +name ++ +" +: +canvas +width +" ++ +canvas +. +width ++ +" +is +bitmap +" ++ +testWidth +) +; +is +( +canvas +. +height +testHeight +name ++ +" +: +canvas +height +" ++ +canvas +. +height ++ +" +is +bitmap +" ++ +testHeight ) ; -canvas4 +if +( +refWidth +! += += +testWidth +) +{ +canvas . width = -128 +refWidth ; -canvas4 +is +( +canvas +. +width +refWidth +name ++ +" +: +canvas +width +" ++ +canvas +. +width ++ +" +is +ref +" ++ +refWidth +) +; +} +if +( +refHeight +! += += +testHeight +) +{ +canvas . height = -128 +refHeight ; -var -snapshotLarge +is +( +canvas +. +height +refHeight +name ++ +" +: +canvas +height +" ++ +canvas +. +height ++ +" +is +ref +" ++ +refHeight +) +; +} +const +snapshot = await snapshotWindow @@ -980,27 +1066,30 @@ . removeChild ( -canvas4 +canvas ) ; -var -resultsLarge +const +results = compareSnapshots ( -snapshotLarge -snapshotLargeRef +snapshot +refSnapshot true ) ; ok ( -resultsLarge +results [ 0 ] +name ++ " -Screenshots +: +screenshots should be the @@ -1008,36 +1097,190 @@ " ) ; -var -resultsSmall -= -compareSnapshots +return +Promise +. +resolve ( -snapshotSmall -snapshotSmallRef -true ) ; -ok +} +async +function +scaleTest +( +) +{ +await +scaleTestCase ( -resultsSmall -[ -0 -] " -Screenshots -should -be -the -same +grow_unscaled " +64 +64 +64 +64 +32 +32 ) ; -runTestOnWorker +/ +/ +Canvas +grows +no +scaling +. +await +scaleTestCase ( +" +grow_downscaled +" +64 +64 +128 +128 +32 +32 ) ; -} +/ +/ +Canvas +grows +scales +down +. +await +scaleTestCase +( +" +grow_upscaled +" +64 +64 +32 +32 +16 +16 +) +; +/ +/ +Canvas +grows +scales +up +. +await +scaleTestCase +( +" +same_downscaled +" +64 +64 +128 +128 +128 +128 +) +; +/ +/ +Canvas +unchanged +scales +down +. +await +scaleTestCase +( +" +same_upscaled +" +64 +64 +32 +32 +32 +32 +) +; +/ +/ +Canvas +unchanged +scales +up +. +await +scaleTestCase +( +" +shrink_unscaled +" +64 +64 +64 +64 +128 +128 +) +; +/ +/ +Canvas +shrinks +no +scaling +. +await +scaleTestCase +( +" +shrink_downscaled +" +64 +64 +128 +128 +256 +256 +) +; +/ +/ +Canvas +shrinks +scales +down +. +await +scaleTestCase +( +" +shrink_upscaled +" +64 +64 +32 +32 +256 +256 +) +; +/ +/ +Canvas +shrinks +scales +up +. +runTestOnWorker +( ) ; } diff --git a/dom/html/HTMLCanvasElement.cpp b/dom/html/HTMLCanvasElement.cpp index 787d9c0eeaae3..03e7395681555 100644 --- a/dom/html/HTMLCanvasElement.cpp +++ b/dom/html/HTMLCanvasElement.cpp @@ -5430,6 +5430,129 @@ void HTMLCanvasElement : : +SetSize +( +const +nsIntSize +& +aSize +ErrorResult +& +aRv +) +{ +if +( +mOffscreenCanvas +) +{ +aRv +. +ThrowInvalidStateError +( +" +Cannot +set +width +of +placeholder +canvas +transferred +to +" +" +OffscreenCanvas +. +" +) +; +return +; +} +if +( +NS_WARN_IF +( +aSize +. +IsEmpty +( +) +) +) +{ +aRv +. +ThrowRangeError +( +" +Canvas +size +is +empty +must +be +non +- +empty +. +" +) +; +return +; +} +SetUnsignedIntAttr +( +nsGkAtoms +: +: +width +aSize +. +width +DEFAULT_CANVAS_WIDTH +aRv +) +; +MOZ_ASSERT +( +! +aRv +. +Failed +( +) +) +; +SetUnsignedIntAttr +( +nsGkAtoms +: +: +height +aSize +. +height +DEFAULT_CANVAS_HEIGHT +aRv +) +; +MOZ_ASSERT +( +! +aRv +. +Failed +( +) +) +; +} +void +HTMLCanvasElement +: +: FlushOffscreenCanvas ( ) diff --git a/dom/html/HTMLCanvasElement.h b/dom/html/HTMLCanvasElement.h index 8c02289b1367f..2987ec2ac839c 100644 --- a/dom/html/HTMLCanvasElement.h +++ b/dom/html/HTMLCanvasElement.h @@ -642,6 +642,18 @@ GetSize ( ) ; +void +SetSize +( +const +nsIntSize +& +aSize +ErrorResult +& +aRv +) +; bool IsWriteOnly ( diff --git a/layout/generic/nsHTMLCanvasFrame.cpp b/layout/generic/nsHTMLCanvasFrame.cpp index dec84b7561c56..c540a202085be 100644 --- a/layout/generic/nsHTMLCanvasFrame.cpp +++ b/layout/generic/nsHTMLCanvasFrame.cpp @@ -1518,19 +1518,6 @@ IsValid return ; } -gfx -: -: -IntSize -size -= -surface -- -> -GetSize -( -) -; transform = gfxUtils @@ -1543,10 +1530,10 @@ gfxRect ( 0 0 -size +canvasSizeInPx . width -size +canvasSizeInPx . height ) @@ -1575,10 +1562,10 @@ Rect ( 0 0 -size +canvasSizeInPx . width -size +canvasSizeInPx . height ) diff --git a/testing/web-platform/meta/imagebitmap-renderingcontext/bitmaprenderer-as-imagesource.html.ini b/testing/web-platform/meta/imagebitmap-renderingcontext/bitmaprenderer-as-imagesource.html.ini deleted file mode 100644 index d9960d82ba8e1..0000000000000 --- a/testing/web-platform/meta/imagebitmap-renderingcontext/bitmaprenderer-as-imagesource.html.ini +++ /dev/null @@ -1,24 +0,0 @@ -[ -bitmaprenderer -- -as -- -imagesource -. -html -] -[ -Test -that -createImageBitmap -from -a -bitmaprenderer -canvas -produces -correct -result -] -expected -: -FAIL