The element and its options
Capture uses the browser’s permission prompt when a SWF attaches a camera
to a Video, listens for microphone samples, or enables microphone loopback.
It requires a secure context (HTTPS or localhost); an embedding iframe must
allow camera and/or microphone for the devices it uses. Device names may be blank until the
user grants permission. Set allowcapture="false" on an element, or
configure({ allowCapture: false }) for new loads, to refuse capture.
Changing that attribute to false also stops the current capture; reload
before enabling it again. Replacing or destroying the player stops its
tracks, including a permission request that finishes later.
The element also takes salign, wmode, bgcolor, base, quality,
allownetworking, relativeurls and cache
(above). As in Flash’s plug-in, relative
URLs resolve against the page, or against base, where base="." is
the SWF’s directory and any other value is relative to the page. A player page
that shows SWFs from elsewhere sets relativeurls="movie" on the
element, or configure({ relativeUrls: "movie" }) for all of them, to
resolve them against each SWF’s own URL instead. Like base, the
attribute is read when a movie loads, not watched while it plays; Flash
tags have no such parameter, so for players replaceFlash makes only
configure sets it.
Flash ran a SWF, and everything it loaded, at its root SWF’s API version:
a class or member of a later Flash Player than the root’s version was not
there for its code, so an old SWF whose class named a getter of its own
isPlaying loaded, where a later root’s would refuse it (VerifyError
#1053). The player runs every SWF at the latest API version by default,
which shows all of them whatever the SWF’s version. apiversion="root"
on an element, or configure({ apiVersion: "root" }) for all of them,
runs each at its root’s, as Flash did: the root’s version from its
header, and what it loads at the same; its workers run at the latest, as
they did in AIR. A number names a
root’s SWF version instead, as apiversion="12", for a SWF whose real
root was another, such as one a wrapper of another version loaded; and
"latest" the default. An AIR application stays at the latest with
"root". Like base, it is read when a movie loads. Modules compiled
ahead of time are found only at the version they were compiled at
(--api, below).
Content often draws vector art into a BitmapData the stage’s size and shows
it through a Bitmap scaled to fit, as a map flattened for speed. Flash
stretches those pixels when the stage is shown larger, and so does the
player, so in a large window or on a dense screen such art looks blocky
beside vectors drawn directly. configure({ bitmapResolution: "display" })
shows such a bitmap at the screen’s resolution instead, up to 4 screen
pixels a stage pixel, for as long as scripts only draw display objects into
it and fill it since it was of one colour, and draws it again when the
scale it is shown at changes: it then looks as the vectors would. It departs
from Flash only on the screen: the bitmap itself, and every pixel scripts
read of it, are as with the option off. Anything else that changes the
bitmap, such as setPixel or copyPixels into it, shows it as Flash would from
then on. It costs texture memory, the square of the scale times the bitmap’s
(about 33 MB for a stage-sized bitmap shown at 3840 by 2160), at most 256 MB
for all of them by default (bitmapResolutionBudget on the renderer), the GPU
time of drawing that many more pixels when the SWF draws into a bitmap shown
so, and the art drawn, which the renderer keeps while the bitmap is shown to
draw it again. A bitmap is drawn at the screen’s resolution once a Bitmap
shows it, from what was drawn into it before: art changed between draws
before then, such as one Shape redrawn and drawn several times, leaves the
bitmap as Flash shows it; so does taking it off the stage for longer than
1,800 rendered frames (300 for one never shown), after which it shows as
Flash does until it is filled whole and drawn into again. It is off by
default,
"stage"; Bitmaps has the details.
It has load(url | bytes) and destroy(), which
gives back its GL context, audio and sockets. It fires load, error and
fscommand events, and with Stage3D on, stagelayout as the SWF starts
and whenever it sets its stage’s scaleMode or align (event.detail
holds both): a page may size the element to the SWF’s own size while it
asks for noScale, as an embedding at that size shows it.
Browsers hold a page’s sound until the user first clicks or presses a key
in it, where Flash Player’s plug-in played it at once. When a SWF’s sound
waits so, the element fires audioblocked and shows a “Click to unmute”
button over the stage; a click on it, or Enter or Space, lets the sound
play, as far in as a streamed soundtrack has gone meanwhile, and does not
reach the SWF. A click or key on the SWF itself lets the sound play too,
the SWF hearing it as usual. Either way the element fires
audiounblocked, as it does when the SWF that held the sound is
destroyed or another is loaded in its place; a SWF that plays no sound
shows no button. Each element on a page shows a button of its own, whose
click unmutes its own SWF.
unmuteprompt="false" on the element, or configure({ unmutePrompt: false }) for the page’s elements, leaves the button out, for a page that
shows its own: its click handler calls element.player?.audio?.resume(),
which a browser allows only while it handles the user’s click or key. The
desktop app’s window lets sound play at once.
A SWF goes full screen by setting Stage.displayState, as under Flash
Player’s plug-in: only with allowfullscreen="true" on the element
(allowfullscreeninteractive="true" for "fullScreenInteractive"), and
only from a mouse or key handler, as the browser’s Fullscreen API asks
too; otherwise the setter throws SecurityError #2152. The element then
covers the screen, the stage placed by its scale mode, or its
fullScreenSourceRect alone, fitted and centred. Esc leaves, and the SWF
gets its FullScreenEvent either way. replaceFlash carries both
parameters over. An AIR application needs neither attribute, but still
the click. A page that makes the element full screen itself
(element.requestFullscreen()) puts the stage in full screen too.
configure({ fullScreen }) takes a full screen of the embedder’s own
instead, as the desktop app’s window, which needs no click.
The player’s context menu has a “Show stats” item (“Hide stats” while it
shows), just above “About swf2es”, that shows a small performance meter
in the player’s top left corner. It shows the SWF’s frames played a
second against its frame rate (“fps”), how many of them a second reached
the screen (“shown”), the player’s ms in a frame (median and worst over
the last second), draw calls, the JS heap where the browser reports it,
and the WebAssembly memories. The two frame figures part where the
display or the drawing cannot keep up: a SWF faster than the display, or
one whose drawing slows the display’s frames, plays more than one frame
between two the browser shows and keeps its speed, and the frames in
between are never seen; so a 60 fps SWF on a display or GPU that
manages 30 a second shows “60.0 / 60 fps” and “30.0 fps” shown. Where
the host lags further still, the player plays one frame a display frame
and drops the time it cannot catch up, as Flash does, and “fps” falls
below the rate. Choosing the item is the viewer’s
choice and is kept in localStorage for every element of the origin; each
element applies it as its SWF starts, and the meter is off by default.
performancemeter="false" on an element, or configure({ performanceMeter: false }) for all of them, leaves the item out and
ignores the kept choice, hiding a meter it showed; removing the
attribute applies the choice again. A script can show or hide the meter
with element.performanceMeter = true or false whatever the item, for
the page alone: it keeps nothing, so a page that wants its own control
remembered (the play page’s Show stats button) writes the same key,
swf2es.performanceMeter set to "1". While the meter shows, the menu
also has “Move stats”, which moves it to the player element’s next
corner, from top left to top right, bottom left and bottom right (in a
letterboxed or noScale player, a corner may be in the bars beside the
stage); Flash’s menus have no submenus, nor has this one. The meter
never takes the pointer, in whichever corner. The corner is kept like
the choice to show it, under swf2es.performanceMeterCorner (none for
top left), and the opt-outs leave the item out too. A script moves it
with element.performanceMeterCorner = "top-left", "top-right",
"bottom-left" or "bottom-right", for the page alone. The element
fires performancemeterchange (event.detail.shown and
event.detail.corner) as the meter shows, hides or moves. While hidden
it costs nothing: it hears no frames, runs no timer and leaves the WebGL
context alone. While shown, it counts draw calls by wrapping the
context’s draw functions. Its background is 70% opaque, so the SWF shows
through, and each figure has a thin halo of the background colour to
keep it readable over white text or busy content; there is no backdrop
blur, which would cost the GPU every frame. A page can style it with the
custom properties --swf2es-meter-font, --swf2es-meter-color,
--swf2es-meter-background, --swf2es-meter-border,
--swf2es-meter-muted and --swf2es-meter-opacity (the background’s,
from 0 to 1; 1 makes it opaque) on the element; by default it takes the
browser’s light or dark colours. The opacity multiplies the background’s
own alpha: a page whose background is already translucent, as rgba(0, 0, 0, 0.6), sets --swf2es-meter-opacity: 1, or the box and the
figures’ halo come out fainter still (and none at all for
transparent). In a forced-colours (high contrast) mode, which drops
the halo, the box is opaque.
A page can measure the player itself, as the meter does, by
setting element.frameListener to a function. After each animation frame
the player calls it with a FrameStats object: time, the frame’s time
by performance.now(); frames, the SWF’s frames it played, often 0
where the display runs faster than the SWF; frameRate, the SWF’s rate
then; play, the ms those frames took (scripts, events, timeline and
sound); drew, whether it drew the stage; draw, the ms drawing took on
the CPU, with the little work just before it (keeping the text input’s
focus, choosing samples again after a quality change), and 0 where it did
not draw; and shown, false for the frames a timer plays while the page
gets no animation frames, which draw nothing. Tell a drawn frame by
drew, not by draw: a browser with a coarse clock (Safari’s, or
Firefox’s on a page that is not cross-origin isolated) may time a short
drawing as 0 ms. The same object comes each time, overwritten by the next
frame, so copy what you keep. There is one listener: setting it replaces
the one before. It holds across loads until set to null; without one
the player measures nothing, and the listener’s own time is not counted
as the player’s, so it does not change how frames are paced.
element.wasmMemory gives the bytes of the WebAssembly memories behind
the player: codegen, its compiler’s, and native, the bitmap kernels’,
tessellators’ and decoders’ on the page, which every player on it shares.
A Flash Worker’s thread holds its own, which are not counted.
element.gl is the WebGL context it draws with, for counting draw calls.
With Stage3D on, a back buffer may be from 32 to 16384 pixels a side in
every profile, as Flash Player 32 and AIR 51 take one on a desktop GPU,
so a SWF that sizes its back buffer to its stage plays on a 2K or 4K
screen. maxBackBufferWidth and maxBackBufferHeight read 16384
whatever the GPU. Where the GPU allows less, the back buffer is drawn at
the largest size it allows and stretched to the size asked for; AIR
would read the GPU’s own limit there and refuse larger sizes. In the
baselineConstrained profile AIR draws no back buffer larger than the
stage (Error #3710, or #3723 for SWFs before version 30); swf2es draws
it.
A back buffer configured with wantsBestResolution is drawn at the
screen’s pixels: its size times Stage.contentsScaleFactor, which is the
page’s devicePixelRatio (1 for an AIR application whose descriptor does
not ask for <requestedDisplayResolution>high</requestedDisplayResolution>,
as in AIR). backBufferWidth, backBufferHeight and drawToBitmapData
then count those pixels, the scissor rectangle stays in stage pixels, and
the canvas keeps its size on the page. The ratio holds the browser’s zoom
too, which Flash kept apart as browserZoomFactor (1 here), so
wantsBestResolutionOnBrowserZoom adds nothing; a best-resolution back
buffer follows the ratio as the page is zoomed or moved to another screen,
and must be cleared again. It costs the ratio squared in memory: a
1920 by 1080 back buffer at a ratio of 2 is 3840 by 2160, 33 MB for each
of its colour, depth and stencil, and the canvas’s two buffers, about
130 MB, and 265 MB more in multisampled buffers at 4x antialiasing; one of
3840 by 2160 at a ratio of 2 is four times all that.
Every Stage3D profile is served, from baselineConstrained to
standardExtended, requestContext3DMatchingProfiles taking the best
asked for, as Flash does on a desktop GPU. The standard profiles run AGAL 2
and 3 programs (conditionals, derivatives, depth output and their larger
register files), half-float textures and up to four colour outputs at once;
the packed 16-bit formats work in every profile. Instanced drawing, which
only AIR has, is not there yet.