Commit Graph

6628 Commits

Author SHA1 Message Date
Aaron Hill 8d8a7600d8 avm2: Partially implement `URLLoader` and related classes
This PR implements the `URLLoader` class, allowing AVM2 scripts
to load data from a URL. This requires several other related
classes (`URLLoaderDataFormat`, `URLRequest`, `IOError`) to be
implemented as well.

Currently implemented:
* Fetching from URLs using the 'navigator' backend
* The `text` and `binary` data formats (which store data
in a `String` or `ByteArray` respectively)
* The `open`, `complete`, and `ioError` events
* The `bytesLoaded`, `bytesTotal`, and `data` properties

Not yet implemented:
* The HTTP and security events
* All of the properties of `IOError`
* The properties on `URLRequest` (besides `url`)
* The "variables" data format

This should be enough to get some basic uses of `URLLoader` working
(e.g. simple GET requests to a particular website).

Note that in Flash's `playerglobal`, the `URLLoader` class is just
a think wrapper around the more general `URLStream`. However,
implementing `URLStream` will require changes to `Navigator``
to support notifications when data arrives in the stream. When
that happens, we should be able to re-use a large amount of the
code in this PR.
2022-05-20 11:41:17 -07:00
Toad06 7130c6c1c1 tests: Remove `Value::from_bool` 2022-05-19 20:24:53 -06:00
Toad06 39e46e5bd3 avm1: Remove `Value::from_bool` 2022-05-19 20:24:53 -06:00
Mike Welsh c503f78e13 canvas: Remove `pixelated_property_value`
This is no longer used with the removal of the SVG paths in #6975.
2022-05-19 16:12:54 -07:00
Mike Welsh a10c2ff9c7 canvas: Remove Firefox hack for additive alpha color transforms
This was added in fecb981 to workaround an issue with additive
alpha color transforms in Firefox. This seems to have been fixed
and is no longer necessary, so Firefox can use the normal code
path.
2022-05-19 16:12:54 -07:00
TÖRÖK Attila 81749f900b avm2: Implement GradientType, InterpolationMethod, SpreadMethod in flash.display 2022-05-19 23:47:55 +02:00
Mike Welsh de99dcd37b core: Add `BitmapFormat::bytes_per_pixel` 2022-05-19 10:43:54 -07:00
Mike Welsh 48f7ff5f4d core: Add `Bitmap::to_rgba` 2022-05-19 10:43:54 -07:00
Mike Welsh e710f3fa0e core: Clean up `render::Bitmap`
* Make `BitmapFormat` a fieldless enum and move `data` to its own
   field for ease of use.
 * Make `Bitmap` fields private.
2022-05-19 10:43:54 -07:00
Mike Welsh 6615ed17f9 core: Verify bitmap length after decoding
Guarantee bitmap data after decoding has the expected length for
the given width+height+format. This eases the burden from backends
to worry about this. Pad or truncate the data if it doesn't have
the expected size.
2022-05-19 10:43:54 -07:00
Mike Welsh b88e77573d core: Handle greyscale PNGs
`render::decode_png` now handles greyscale or greyscale+alpha PNGs.
2022-05-19 10:43:54 -07:00
Toad06 78dcfe604d tests: `action_enumerate` can handle paths 2022-05-18 19:30:48 -07:00
Toad06 b50f1201e1 avm1: `action_enumerate` can handle paths 2022-05-18 19:30:48 -07:00
TÖRÖK Attila 135833e400 chore: Add a note to cargo config about RUSTFLAGS in the web build 2022-05-17 13:07:40 -07:00
TÖRÖK Attila 71f7f28fb0 chore: Allow unknown_lints in both WASM modules 2022-05-17 13:07:40 -07:00
relrelb 4021cb54a4 ci: Run cargo in locked mode
Per https://doc.rust-lang.org/cargo/commands/cargo-test.html#manifest-options,
`cargo --locked` assumes that `Cargo.lock` is up-to-date, and otherwise
exits with an error.
Besides the nice validation, this might hopefully speed-up CI a bit.

This could be done on Web as well, but I'm not sure what's the best
way of doing it.
2022-05-17 12:47:50 -07:00
relrelb f3af11db9c canvas: Remove some unused dependencies
They're now unused thanks to #6975.
Also remove the `crate-type` field from `Cargo.toml`. I'm not sure
exactly what it does and why it was introduced, but seems working
without it.
2022-05-17 09:51:13 -07:00
Mike Welsh 62d62d9667 chore: Allow unknown_lints in web build
The web build script in `core\package.json` sets the `RUSTFLAGS`
env var, which overrides any settings in `.cargo/config.toml`.

Add `-Aunknown_lints` to these `RUSTFLAGs` to squelch a stray
`unused_macro_rules` warning.
2022-05-17 08:36:41 -07:00
dependabot[bot] 4dc9fd7adf build(deps): bump syn from 1.0.94 to 1.0.95
Bumps [syn](https://github.com/dtolnay/syn) from 1.0.94 to 1.0.95.
- [Release notes](https://github.com/dtolnay/syn/releases)
- [Commits](https://github.com/dtolnay/syn/compare/1.0.94...1.0.95)

---
updated-dependencies:
- dependency-name: syn
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-05-16 17:45:21 -07:00
Mike Welsh 2f99d039cc canvas: Remove `BitmapDataStorage::ImageElement`
Remove the `ImageElement` data path for storing bitmaps, as the
asynciness of this is difficult to manage when we need to render
bitmaps immediately. This code path was only being used for JPEG
images that could be decoded by the browser (no alpha).

Instead, always use canvases for bitmap storage. This simplifies
the code and solves some issues with bitmaps not being rendered
properly, although it is likely a little slower toe decode these
JPEGs on the Rust side.
2022-05-16 17:13:48 -07:00
Mike Welsh d0aa7b4df2 canvas: Remove SVG rendering path
Remove `CanvasDrawCommand::DrawImage` and all associated machinery
that generates an SVG.
2022-05-16 17:13:48 -07:00
Mike Welsh ce044409e4 canvas: Use canvas drawing commands for gradients
Most gradients are "simply transformed" and can be rendered
directly using canvas commands. But even for complex transforms,
we can push the gradient's transform to the canvas, then
un-transform the path using the inverse of the gradient transform.
2022-05-16 17:13:48 -07:00
David Wendt 1809ca611b avm2: Make dispatch list initialization lazy, so that it can run before constructors if necessary.
Due to various quirks of how timeline-initiated symbols interact with AVM2, it is possible for user code to gain a reference to uninitialized objects (especially `SimpleButton` which doesn't initialize until after `exitFrame`). It is still possible to attach event handlers to them that fire correctly, and movies expect to be able to.
2022-05-16 17:13:35 -07:00
dependabot[bot] ede81be427 build(deps): bump isahc from 1.7.1 to 1.7.2
Bumps [isahc](https://github.com/sagebind/isahc) from 1.7.1 to 1.7.2.
- [Release notes](https://github.com/sagebind/isahc/releases)
- [Commits](https://github.com/sagebind/isahc/compare/1.7.1...1.7.2)

---
updated-dependencies:
- dependency-name: isahc
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-05-16 13:55:00 -07:00
dependabot[bot] fc4cd11959 build(deps): bump syn from 1.0.92 to 1.0.94
Bumps [syn](https://github.com/dtolnay/syn) from 1.0.92 to 1.0.94.
- [Release notes](https://github.com/dtolnay/syn/releases)
- [Commits](https://github.com/dtolnay/syn/compare/1.0.92...1.0.94)

---
updated-dependencies:
- dependency-name: syn
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-05-16 13:54:32 -07:00
dependabot[bot] 786e5b5bb7 build(deps): bump rayon from 1.5.2 to 1.5.3
Bumps [rayon](https://github.com/rayon-rs/rayon) from 1.5.2 to 1.5.3.
- [Release notes](https://github.com/rayon-rs/rayon/releases)
- [Changelog](https://github.com/rayon-rs/rayon/blob/master/RELEASES.md)
- [Commits](https://github.com/rayon-rs/rayon/compare/v1.5.2...v1.5.3)

---
updated-dependencies:
- dependency-name: rayon
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-05-16 13:54:13 -07:00
dependabot[bot] 27da91b7a0 build(deps): bump clap from 3.1.17 to 3.1.18
Bumps [clap](https://github.com/clap-rs/clap) from 3.1.17 to 3.1.18.
- [Release notes](https://github.com/clap-rs/clap/releases)
- [Changelog](https://github.com/clap-rs/clap/blob/master/CHANGELOG.md)
- [Commits](https://github.com/clap-rs/clap/compare/v3.1.17...v3.1.18)

---
updated-dependencies:
- dependency-name: clap
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-05-16 13:54:02 -07:00
Mike Welsh eb38b2fb00 tests: Add test for SWF5 function scope 2022-05-14 22:29:44 -07:00
Mike Welsh d1b65d9092 avm1: Pass ExecutionReason to `Object::call_method`
Internal function calls such as `toString` and event handlers
always used the base clip from the function itself, so add an
`ExecutionReason::InternalCall` to signify this and pass it along
to `call_method`.
2022-05-14 22:29:44 -07:00
Mike Welsh 4904b2cc97 avm1: Fix scope of function calls in SWFv5 vs. SWFv6+
Fix various scope behavior when executing a function:

 * For function calls in SWFv6+, functions are proper closures and
   close over the SWF version, base clip, and scope of their
   defining function.
 * Function calls in SWFv5 are not closures, and use the version,
   base clip, and scope of `this` when the function is called.

Fixes #5502.
2022-05-14 22:29:44 -07:00
Aaron Hill a453aa73af avm2: Don't consider declared return type for unchecked functions check
Testing under Flash shows that methods can be considered 'unchecked'
(allowing them to be called with more arguments than declared
parameters) even if they have a declared return type.

This is relied on by SteamBirds, which registers an event handler
which takes 0 parameters and an explicitly declared return type
2022-05-13 09:32:05 -07:00
Aaron Hill 8ff720dd9d
avm1: Allow new `unused_macro_rules` lint on `declare_properties`
This was recently added in https://github.com/rust-lang/rust/pull/96150
Some of the `__version` rules are currently unused, but I assume
that we still want to keep them for potential future use.
2022-05-13 09:31:46 -07:00
TÖRÖK Attila c40c0d7ef9 webgl: Use clamp(x, 0.0, 1.0) instead of saturate(x)
The latter seems to not exist
2022-05-13 09:31:21 -07:00
Mike Welsh edad1569fb webgl: Clamp alpha in shaders (fix #6954) 2022-05-12 14:50:25 -07:00
Mike Welsh 121c2577b4 wgpu: Clamp alpha in shaders (fix #6954) 2022-05-12 14:50:25 -07:00
relrelb cab49ae6e1 swf: Introduce `Color::WHITE`
And use it where possible, to improve code readablity.
2022-05-12 12:12:06 -07:00
relrelb 0b0f8a1a7a swf: Introduce `Color::BLACK`
And use it where possible, to improve code readablity.
2022-05-12 12:12:06 -07:00
Aaron Hill 938d80146c avm2: Implement `TextField.background` getter/setter
There's already a `has_background` field on the underlying object
data, so we can just map this property to it.
2022-05-11 15:42:19 -07:00
Aaron Hill e39cfa8027 Define `String.fromCharCode` as both a public and AS3 method
This is relied on by SteamBirds
(https://www.kongregate.com/games/weasello/steambirds)
2022-05-11 15:42:19 -07:00
relrelb 84b865018d swf: Mark some `SwfStr` functions as const 2022-05-10 09:34:57 +03:00
Mike Welsh f550abd18d web: Fix some warnings
Fix warnings caused by desktop-only code.
2022-05-09 22:28:43 -07:00
Mike Welsh 6547fcdf99 avm1: Remove `avm1::globals::display_object` module
This module is now mostly empty, so move the items up to `globals`.
`getDepth` was the only shared method, so declare this property
inline in each display object type. `Video` was also incorrectly
declaring `getDepth`.
2022-05-09 17:39:49 -07:00
Mike Welsh a97ae38008 avm1: Remove `toString` from display objects
`MovieClip` and others do not have a `toString`; instead, stage
objects are special cased to return their path when coerced to
string.
2022-05-09 17:39:49 -07:00
Mike Welsh 35d2f69396 avm1: Improve `StageObject::get_local_stored`
* Avoid an extraneous check to `ScriptObject::has_own_property`.
 * Avoid magic property branches if property name does not start
   with `_`.
2022-05-09 17:39:49 -07:00
Mike Welsh a940a0d357 tests: Add test for #768 2022-05-09 17:39:49 -07:00
Mike Welsh 2683686014 avm1: `_root`, `_parent`, `_global` are magic properties (fix #768)
Remove `_root`, `_parent` and `_global` from `MovieClip.prototype`.
Instead, these are "magic" properties similar to `_x` and `_y`.
Add `StageObject::resolve_path_property` to handle these, alongside
the `_levelN` property.

Fixes #768.
2022-05-09 17:39:49 -07:00
Mike Welsh 9d5e461278 core: Add WStr::eq_with_case 2022-05-09 17:39:49 -07:00
relrelb 4f05d1852d web: Prefer using `Element` over `HTMLElement`
`Element` is a slightly more general type, which is more common than
`HTMLElement`, and it satisfies our needs in most cases.
2022-05-09 15:00:14 -07:00
relrelb 781d091d42 swf: Return concrete data types in `Reader` methods
Where possible, return the specific data type instead of the generic
`Tag` type. Most reader methods do this already, so this brings the
rest in-line.
2022-05-09 14:59:38 -07:00
dependabot[bot] 7352aca3bc build(deps): bump jpeg-decoder from 0.2.5 to 0.2.6
Bumps [jpeg-decoder](https://github.com/image-rs/jpeg-decoder) from 0.2.5 to 0.2.6.
- [Release notes](https://github.com/image-rs/jpeg-decoder/releases)
- [Changelog](https://github.com/image-rs/jpeg-decoder/blob/master/CHANGELOG.md)
- [Commits](https://github.com/image-rs/jpeg-decoder/compare/v0.2.5...v0.2.6)

---
updated-dependencies:
- dependency-name: jpeg-decoder
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-05-09 13:46:12 -07:00