Skip to content
SiteEmail

Canvas elements are partially supported for usage via the CanvasRenderingContext2D API. A CanvasRenderingContext2D object can be created by calling the getContext("2d") method on a <canvas> element.

CanvasRenderingContext2D is hardware-accelerated, and its resources are stored on the GPU. If these rendering resources are lost or recreated, prior drawing commands are not automatically replayed, and thus the canvas context is reset. For example, switching the render target format recreates the canvas texture to update its format, which causes a context reset.

Keeping the format as the default renoir::PixelFormat::PF_R8G8B8A8 will prevent the canvas texture from being updated, and will not cause a context reset when switching render targets.

If your Prysm integration forces you to set the render target before painting the frame, you can avoid a context reset by first setting it on a dummy render target texture with the desired format before advancing the view.

The notable sections from the HTMLCanvasElement and CanvasRenderingContext2D specifications that are missing or not fully supported are:

  • CanvasPattern as fillStyle and strokeStyle
    • Supported only for fillRect() method.
  • CanvasGradient as fillStyle and strokeStyle
    • Gradients are not supported for strokeRect(), fillText(), strokeText().
    • Radial gradients created from createRadialGradient() are only supported when using single origin in the following way createRadialGradient(x, y, 0, x, y, radius)
    • Conic gradients created from createConicGradient() are not supported.
    • Linear gradients are supported for fillRect(), fill() and stroke().
  • drawFocusIfNeeded() method not supported
  • clip() method not supported
  • Line dashes are not supported
  • Shadows are not supported
  • direction property only supports default value ltr
  • globalCompositeOperation property only supports default value source-over
AttributeCurrent statusNotes
widthYES
heightYES
MethodCurrent statusNotes
captureStream(frameRate)NO
getContext(contextType, contextAttributes)PARTIALOnly “2d” contextType is supported for creating a CanvasRenderingContext2D object. Optional contextAttributes are not supported.
toBlob(callback, type, quality)NO
toDataURL(type, encoderOptions)NO
transferControlToOffscreen()NO

CanvasRenderingContext2D attributes support

Section titled “CanvasRenderingContext2D attributes support”
AttributeCurrent statusNotes
canvasYES
globalAlphaYES
globalCompositeOperationPARTIALOnly default value source-over supported.
fillStylePARTIALSupported only for certain methods of the CanvasRenderingContext2D API. Refer to the method of interest in the CanvasRenderingContext2D methods table.
strokeStylePARTIALSupported only for certain methods of the CanvasRenderingContext2D API. Refer to the method of interest in the CanvasRenderingContext2D methods table.
lineWidthYES
lineCapYES
lineJoinYES
miterLimitYES
fontYES
textAlignYES
textBaselineYES
lineDashOffsetNO
shadowOffsetXNO
shadowOffsetYNO
shadowBlurNO
shadowColorNO
directionPARTIALOnly default value ltr supported.
filterNO
fontKerningNO
fontStretchNO
fontVariantCapsNO
imageSmoothingEnabledNO
imageSmoothingQualityNO
letterSpacingNO
textRenderingNO
wordSpacingNO
MethodCurrent statusNotes
createLinearGradient(x0, y0, x1, y1)PARTIALLinear gradients are not supported for strokeRect(), fillText(), strokeText().
createRadialGradient(x0, y0, r0, x1, y1, r1)NO
createConicGradient(startAngle, x, y)NO
createPattern(image, repetition)PARTIALSupports HTMLImageElement or HTMLCanvasElement as image.
save()YES
restore()YES
clearRect(x, y, width, height)YES
fillRect(x, y, width, height)YES
strokeRect(x, y, width, height)PARTIALDoes not support CanvasGradient as strokeStyle. Does not support CanvasPattern as strokeStyle.
fillText(text, x, y, maxWidth)PARTIALDoes not support optional parameter maxWidth. Does not support CanvasGradient as fillStyle. Does not support CanvasPattern as fillStyle.
strokeText(text, x, y, maxWidth)PARTIALDoes not support optional parameter maxWidth. Does not support CanvasGradient as strokeStyle. Does not support CanvasPattern as strokeStyle.
measureText(text)PARTIALReturned TextMetrics object contains actualBoundingBoxLeft, actualBoundingBoxRight, actualBoundingBoxAscent, actualBoundingBoxDescent and width properties only.
drawImage(image, sx, sy, sWidth, sHeight, dx, dy, dWidth, dHeight)PARTIALSupports HTMLImageElement, HTMLCanvasElement and HTMLVideoElement as image
scale(x, y)YES
rotate(angle)YES
translate(x, y)YES
transform(a, b, c, d, e, f)YES
setTransform(a, b, c, d, e, f)YES
beginPath()YES
closePath()YES
fill()PARTIALOnly linear CanvasGradients are supported as fillStyle. CanvasPatterns are not supported as fillStyle.
stroke()PARTIALOnly linear CanvasGradients are supported as strokeStyle. CanvasPatterns are not supported as strokeStyle.
drawFocusIfNeeded(element)NO
clip()NO
moveTo(x, y)YES
lineTo(x, y)YES
quadraticCurveTo(cpx, cpy, x, y)YES
bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y)YES
arcTo(x1, y1, x2, y2, radius)YES
rect(x, y, width, height)YES
arc(x, y, radius, startAngle, endAngle, counterclockwise)YES
setLineDash(segments)NO
getLineDash()NO
createImageData(width, height, settings)NO
createImageData(imagedata)NO
getContextAttributes()NO
getImageData(sx, sy, sw, sh, settings)NO
getTransform()NO
isContextLost()NO
isPointInPath(path, x, y, fillRule)NO
isPointInStroke(path, x, y)NO
putImageData(imageData, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight)NO
reset()NO
resetTransform()NO
roundRect(x, y, width, height, radii)NO
scrollPathIntoView(path)NO