Skip to content

Commit

Permalink
Bug 1850871 - Resize canvas in ImageBitmapRenderingContext::TransferF…
Browse files Browse the repository at this point in the history
…romImageBitmap. r=gfx-reviewers,lsalzman

This patch makes it so that when a new ImageBitmap is provided to an
ImageBitmapRenderingContext, we resize its owning canvas rather than
crop or scale the given ImageBitmap to fit inside the canvas dimensions.

See discussion in whatwg/html#7833.

Differential Revision: https://phabricator.services.mozilla.com/D188126

UltraBlame original commit: cbd593a4819d1bc653fae6d21f86b25c9b1bdd58
  • Loading branch information
marco-c committed Oct 17, 2023
1 parent 79f08d4 commit aa6a065
Show file tree
Hide file tree
Showing 8 changed files with 774 additions and 224 deletions.
106 changes: 106 additions & 0 deletions dom/canvas/ImageBitmapRenderingContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
-
>
Expand Down Expand Up @@ -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
;
Expand Down
91 changes: 91 additions & 0 deletions dom/canvas/OffscreenCanvas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions dom/canvas/OffscreenCanvas.h
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,18 @@ mNeutered
mCurrentContext
;
}
void
SetSize
(
const
nsIntSize
&
aSize
ErrorResult
&
aRv
)
;
nsIPrincipal
*
GetExpandedReader
Expand Down
Loading

0 comments on commit aa6a065

Please sign in to comment.