Commit Graph

862 Commits

Author SHA1 Message Date
relrelb abb0e33431 chore: Use Rust's `OnceCell`/`OnceLock`
They were stabilized in Rust 1.70.0, which was released yesterday.
This removes the `once_cell` dependency.
2023-06-02 22:21:38 +03:00
Aaron Hill 8b257ef6da avm2: Always run `construct_frame` in `initialize_for_allocator`
When we create a DisplayObject from ActionScript, we should always
run `construct_frame` on it, regardless of what frame phase we
are currently in.

This fixes a regression in Fancy Pants World 4 Part 1, where entering
the first door produced an error.
2023-05-31 17:33:25 -05:00
relrelb df1cd29a12 tests: Expand `duplicate_movie_clip` 2023-05-30 23:10:36 +03:00
Aaron Hill d18df2d3f1 tests: Add non-power-of-2 texture test 2023-05-28 23:35:53 -05:00
Aaron Hill 0955ab40e6 avm2: Fix rounding behavior in BitmapData rectangle operations
Flash Player performs `x + width` and `y + height` as floating
point operations before `round_to_even`. This affects the extent
covered by a `Rectangle` in various BitmapData methods, as the sum
of two values might be large enough to be rounded up to a larger
value (when rounding `x` and `width` individually would have
produced a smaller overall extent).
2023-05-28 18:46:55 -05:00
Aaron Hill 3f93abffd5 avm2: Allow replacing and deleting XML attributes 2023-05-28 15:52:57 -05:00
Aaron Hill 14c6d1d959 avm2: Implement URLRequest.requestHeaders
These are directly set on the underlying navigator's HTTP
request type, and get printed out in our test navigator backend.

No validation of the header names is performed - on web, this will be
enforced by the browser.
2023-05-28 12:07:37 -05:00
Nathan Adams aeb089ac0f avm2: Move DisplayObject assignment into an initializer 2023-05-26 22:06:20 -05:00
Aaron Hill cf4ca543bd core: Use clone-on-write behavior for render list iteration
When we iterate over a render list (in order to call
`enter_frame`, `construct_frame, etc.) we need to be sure
that we iterate over all of the original `DisplayObjects`
in the list, even if the list is modified during iteration
(e.g. some ActionScript code calls `parent.addChildAt`).

Previously, `RenderIter` would repeatedly call `child_by_index`
on the original `DisplayObjectContainer`, up to the original
child count. If new DisplayObjects were inserted into the list
during iteration, we could miss some of the original DisplayObjects
in the list (as they are now at a greater position in the list).

To solve this, we now store the render list as an `Rc<Vec>`,
and use `Rc::make_mut` to modify it. See the comments
for more details.
2023-05-26 21:42:06 -05:00
Aaron Hill e98ff6a6d7 avm2: Add legacy handling for configureBackBuffer with SWF version < 30
With SWF version < 30, Context3D.configureBackBuffer throws
an error with a less informative message when the width/height
are out of range. Additionally, it seems to special case
the case width=0, height=0, antiAlias=0. enableDepthAndStencil=false,
and does *not* throw an error. This is relied on by Sniper Team.
2023-05-24 18:15:30 -05:00
Nathan Adams b9322ba93a desktop: Render game separately to UI, blit both onto surface 2023-05-24 23:50:48 +02:00
iwannabethedev 1e0714aaa1 core: Fix serialization of arrays with dynamic properties. 2023-05-23 19:46:24 -05:00
Aaron Hill 358beabf5a avm2: Add Matrix3D.[recompose,decompose,copyColumnTo,invert,determinant]
The Flash Player 'Matrix3D.recompose' method throws exceptions under
certain circumstances with the "quaternion" orientation style.
I haven't yet figured this out yet, so I've marked that case as a stub.

All of the implementations are based on the OpenFL code, with some
tweaks to match Flash Player's behavior.
2023-05-23 18:51:46 -05:00
Aaron Hill c53a903d35 avm2: Suppress events for selectable was_static TextFields
TextFields have a very unusual behavior - if they are selectable
and have `was_static`, they *block* the dispatch of mouse events when
they're targeted (not even the Stage will receive the event).
This only occurs when the TextField is actually targeted
(which requires mouseEnabled=true). With mouseEnabled=false,
the event will be dispatched with an ancestor as the target,
following the usual logic.

Also, TextFields now properly propagate mouse picks to
their parent if mouseEnabled=false. Previously, setting
mouseEnabled=false for a TextField made all mouse picks
cause a miss on it. This was the cause of the Turbo Kids
regression.

Fixes #10245
2023-05-23 17:57:06 -05:00
Nathan Adams afa78ebdfe avm1: Correctly send onUnload events for movies unloaded with GetURL2 - fixes #2422 2023-05-22 23:41:41 +02:00
Aaron Hill ace87861ce avm2: Make ByteArray.readMultiByte cut string off at null byte
We already had this behavior in `readUTF` and `readUTFBytes`,
but we need it in `readMultiByte` as well.
2023-05-22 16:01:50 -05:00
Aaron Hill b94f9f3043 avm2: Coerce function return value to declared return type
This can actually affect runtime behavior - if the return type is
declared as 'int', then an instance of a custom class will get
coerced to 0 when returned by the function.
'Plants vs Zombies Demo' relies on this - it has a function which
incorrectly returns an object instead of an array index, but the
value gets silently coerced to 0 under Flash Player.
2023-05-22 13:47:32 -05:00
iwannabethedev 18ea71959b tests: Add test for XML/XMLList hasSimpleContent/hasComplexContent 2023-05-22 06:17:37 -05:00
Aaron Hill 6ac4e5256d avm2: Check parent domain in export_class
The `export_class` function mirrors `export_definition`, and needs
to avoid exporting something already defined in a parent domain.
2023-05-21 17:37:54 -05:00
Aaron Hill 95b0b29310 avm2: Initial implementation of URLStream
This is based on URLLoader, and doesn't actualy 'stream' data -
it all becomes available once the request finishes. However, this
is good enough to get Sniper Team working.
2023-05-21 15:00:08 +02:00
TÖRÖK Attila 65117499fd chore: Bump regress and toml dependencies 2023-05-21 14:42:01 +02:00
TÖRÖK Attila e54f3fef8a tests: Make the audio backend tick every frame in the runner 2023-05-21 09:50:07 +02:00
iwannabethedev 7b12cb882f core: Fix error message in 'pixelDissolve()'. 2023-05-21 01:47:06 +02:00
iwannabethedev e74a543ebb core: Add visual test for 'pixelDissolve()' for AVM1. 2023-05-21 01:47:06 +02:00
iwannabethedev 9fa79a187e core: Fix wrong test print in test. 2023-05-21 01:47:06 +02:00
iwannabethedev 6f98d39c25 core: Implement 'pixelDissolve()' for AVM1. 2023-05-21 01:47:06 +02:00
iwannabethedev 1bd9f82496 core: Implements `BitmapData.pixelDissolve()` for AVM2.
The changes have automated tests for them.

The implementation has not been implemented or tested for AVM1 yet.
2023-05-21 01:47:06 +02:00
Aaron Hill ad77cb0209 core: Refactor Loader to properly load images
We now run all of the completion logic (including adding
the new DisplayObject as a child) in `Loader::movie_loader_complete`.
Previously, some of this logic was run from `Loader::preload_tick`,
which meant that loaded images did not have the logic run.

Also, `BitmapData` and `Bitmap` instances (with corresponding AVM2
objects) are now properly constructed for loaded images.
2023-05-20 18:35:10 -05:00
Toad06 b88e19ef6c avm1: Filter buttons that use a `keyPress` event 2023-05-21 01:13:26 +02:00
Aaron Hill 5d62ef90f2 wgpu: Use intermediate buffer for Context3DCommand::CopyBitmapToTexture
In a previous PR, I introduced an optimization that used
`copy_texture_to_texture` to copy directly from a BitmapData GPU
texture to a Stage3D GPU texture.

Unfortunately, this optimization is incorrect. A BitmapData GPU
texture can be modified at any time by normal AVM2 code - in
particular, in might be modified before we submit the encoded
`copy_texture_to_texture` command. This shows up in Sniper Team,
which re-uses BitmapData objects for multiple distinct textures.
The previous 'optimization' resulted in the wrong BitmapData contents
getting uploaded to a texture (since it was changed before the copy
command was submitted).
2023-05-20 17:38:26 -05:00
TÖRÖK Attila fa90ea9cc2 tests/visual: Save color and alpha difference in separate images
So the whole thing isn't invisible if the alpha channels matches.
Also only save the alpha difference if there is any.
2023-05-20 23:41:56 +02:00
TÖRÖK Attila 3d0b8cc849 tests/visual: Save actual image even if size is wrong
This should help with creating the initial expected image
when making new tests.
2023-05-20 23:41:56 +02:00
Aaron Hill 0864853d44 avm2: Allow passing `null` to `Context3D.setProgram`
This clears the vertex and fragment shader programs
(bringing the Context3D back to its initial state).
2023-05-20 16:23:03 -05:00
Tom Schuster 2493194d2f tests: Test XMLList set 2023-05-19 20:10:47 -05:00
Aaron Hill 6025878aab avm2: Respect SKIP_INVISIBLE for DisplayObject
Previously, we allowed mouse picks of certain invisible
DisplayObjects, even when HitTestOptions::SKIP_INVISIBLE
was set.
2023-05-19 08:12:00 -05:00
Aaron Hill 7619594b1c agal: Implement Float1 to vec4f conversion 2023-05-18 16:12:22 -05:00
Aaron Hill 7004e98b23 avm2: Don't validate Context3DVertexBufferFormat when buffer is null
This matches Flash Player's behavior - some SWFS try to pass in 'null'
for both the buffer and format.
2023-05-18 15:14:29 -05:00
Aaron Hill 75569e1311 avm2: Throw error for invalid Stage3D back buffer size 2023-05-16 17:36:22 -05:00
Aaron Hill bd2be88711 wgpu: Fix MSAA and depth buffer handling in SetRenderToTexture
When multisampling is enabled, we should create a new multisampled texture,
and use the existing texture as the resolve buffer. We also need to
call `update_has_depth_texture` to keep our pipeline aware of whether
or not we currently have a depth buffer attached.

Makes progress on #10641 (it has a stack overflow after
this PR, due to an unrelated issue).
2023-05-15 09:34:30 -05:00
iwannabethedev c86aed35a2 tests/core: Add test for BitmapData.draw() with ColorTransform. 2023-05-15 00:51:54 +02:00
Aaron Hill 729d5a2c65 avm2: Don't overwrite existing entry in `export_class`
This makes the behavior consistent with `export_definition`
2023-05-13 11:15:54 +03:00
Aaron Hill 3c6820c6e1 avm2: Check length and copy vector in Matrix3D constructor 2023-05-13 11:00:31 +03:00
iwannabethedev 93450b28b0 avm2: Add 'static length' for most types. 2023-05-11 22:16:55 +02:00
Aaron Hill e488cc9f7a wgpu: Allow unaligned writes to IndexBuffer3D
wgpu requires buffer copy sizes and offsets to be 4-byte aligned.
Unfortunately, ActionScript can perform 2-byte aligned uploads
into an IndexBuffer3D.

To support this, we now keep a copy of the IndexBuffer3D on the CPU.
When performing an upload to the buffer, we round the offset down
and the size up to the nearest 4-byte aligned value. The cpu buffer
is used to fill out the write with existing data, so that we don't
corrupt the contents of the GPU buffer.

To avoid introducing a new RefCell, I've changed IndexBuffer3D
to use a `Box` instead of an `Rc` to store the trait object.
This allows us to pass a mutable reference down to the backend.
2023-05-10 18:20:29 -05:00
Huw Pritchard b79b192a58 avm2: Implement PrintJobOptions 2023-05-09 20:51:44 -05:00
Aaron Hill 1908d85f65 avm2: Initialize `Object` instance vtable before other classes
Early class construction is tricky - `Object` defines properties
that need to get copied into subclass instance vtables, but `Class`
defines `prototype`, which needs to be copied into the *class* vtable
of `Object`.

To accomplish this, I've split out instance vtable initialization
into a separate `init_instance_vtable`. We call
`object_class.init_instance_vtable` before
`class_class.init_instance_vtable`, but do things in the opposite
order for `into_finished_class` (`class_class.into_finished_class` is
called before `object_class.into_finished_class`)
2023-05-07 07:46:30 -05:00
iwannabethedev 724df48186 avm2: Add AS 'length()' to XML. 2023-05-06 12:02:06 -05:00
friedkeenan 8d96626026 avm2: Add test for ApplicationDomain::getQualifiedDefinitionNames 2023-05-04 19:51:04 -05:00
Tom Schuster f6c0685992 avm2: Allow setting XML methods as properties 2023-05-04 19:34:14 -05:00
Toad06 ee7403952a avm1: Allow `button.enabled` to hold any value 2023-04-30 21:08:27 +03:00
Toad06 86c27078d3 avm1: `button.enabled = undefined` doesn't disable the button 2023-04-30 21:08:27 +03:00
Tom Schuster 69134d7d8d tests: Test XML.hasOwnProperty 2023-04-29 16:34:10 -05:00
relrelb 81dcc66c01 tests: Expand `as_broadcaster`
Verify that `AsBroadcaster` is actually a usable constructor.
2023-04-26 21:21:57 +03:00
Nathan Adams cc731a78ee avm2: Respect data, method and contentType in Loader.load() 2023-04-26 12:46:23 +02:00
Lord-McSweeney f412f62127 avm2/tests: use try_get_object in JSON/Add test for undefined receiver 2023-04-26 00:17:44 +02:00
Lord-McSweeney 58212ec280 avm2: Throw AVM errors for JSON operations (and add tests) 2023-04-26 00:17:44 +02:00
Aaron Hill 6eba8d07ee avm2: Implement MorphShape class and use it for MorphShape displayobject 2023-04-25 18:43:43 +02:00
Toad06 ad4dc943fa avm1: Fix some issues with buttons 2023-04-25 17:50:25 +02:00
Aaron Hill 4432c45eb3 avm2: Mark 'callee' property as non-enumerable on 'arguments' array
Some SWFs iterate over the 'arguments' array, and the 'callee' property
should not get enumerated.
2023-04-25 17:29:20 +02:00
relrelb ff7c458739 core: Accept borrowed strings in `NavigatorBackend::navigate_to_url`
This avoids some unnecessary clones.
2023-04-24 22:06:47 +03:00
Tom Schuster 8b3491fe53 tests: Update the XML abstract equality test 2023-04-23 22:07:54 -05:00
Aaron Hill 15af946cf1 avm2: Stop after first frame when movieclip doesn't extend MovieClip
It's possible to have a DefineSprite tag with multiple frames,
but with a corresponding SymbolClass that directly extends
`Sprite` (and therefore does *not* extend `MovieClip`). When this
happens, Flash Player stops after the first frame.
2023-04-23 16:48:38 -05:00
Aaron Hill 33e9713279 avm2: Fix get_super and set_super with normal methods
Doing `super.someNonGetter` gives you back a function object.
We were previously attempting to call normal methods as though
they were getters. Additionally, we were failing to properly
get the property from the superclass vtable.
2023-04-23 16:28:59 -05:00
Nathan Adams 4f4327b152 wgpu: Fix drawing a transparent bitmap with MSAA 2023-04-18 23:15:42 +02:00
Tom Schuster da689b7687 tests: Test XMLList.child 2023-04-11 14:49:32 -04:00
Nathan Adams 35f3a21110 core: Fix bitmapdata.floodFill() replacing X with X + test. Fixes #10642 2023-04-11 10:40:57 -04:00
Mike Welsh 89e9b15c60 tests: Improve test for `Graphics.beginBitmapFill` 2023-04-11 11:36:49 +02:00
Toad06 81d907b9f0 tests: `MovieClip.focusEnabled` in avm1 2023-04-09 14:11:24 -07:00
Tom Schuster 5289009959 tests: Add some tests for XML abstract equality 2023-04-09 12:02:20 -07:00
Mike Welsh 6ad5c30188 tests: Test for correct variables in `loadvariables_method` test 2023-04-08 13:37:25 -07:00
Mike Welsh 35810a8c7e tests: Add `log_fetch` option
Adds a `TestNavigatorBackend` that has the ability to log HTTP
requests for tests.
2023-04-08 13:37:25 -07:00
Mike Welsh a38f74d989 tests: Add `NavigatorTestBackend` 2023-04-08 13:37:25 -07:00
Tom Schuster d9e69563d3 avm2: Implement XMLList.copy 2023-04-07 12:29:49 -05:00
Udeshya 54a8672390
avm2: Trim xml text nodes when being parsed (#10341) 2023-04-06 22:41:46 -05:00
Aaron Hill 962cf92223 avm2: Implement Context3D.setSamplerStateAt
This fixes pixelated backgrounds in Fancy Pants World 4 Part 3
2023-04-05 16:44:07 -07:00
Toad06 5e165a0682 avm1: Fix some issues with `Selection.getFocus()` and `setFocus()` 2023-04-05 15:53:18 -07:00
Mike Welsh 83aff3c7ba tests: Add Julia fractal Stage3D test 2023-04-05 12:22:13 -07:00
Mike Welsh de80de731d tests: Add test for scrollRect within masker 2023-04-04 13:10:45 -07:00
Mike Welsh e21f3744b5 tests: Add visual test for TextField as mask 2023-04-04 13:10:45 -07:00
Nathan Adams 06bc4e1403 wgpu: Fix sync issue introduced in #9753 and added test 2023-04-04 11:11:57 -07:00
Mike Welsh 63aa67d196 tests: Add test for `Matrix3D.transformVector` and `deltaTransformVector` 2023-04-03 17:09:16 -07:00
Udeshya 34775965ea
avm2: Implement `Transform.pixelBounds` 2023-04-02 23:25:10 +00:00
AllinolCP f0a8e50be1 avm2: implement decodeURI 2023-04-02 14:49:07 -07:00
Tom Schuster 5a18a409f7 avm2: Only reject a single explicit namespace in XML 2023-04-02 16:09:03 -05:00
Toad06 35528913bf core: Make `ExternalInterface` support undefined values 2023-04-02 13:48:14 -07:00
Tom Schuster 86395f194f avm2: Strip BOM in ByteArray::toString 2023-04-01 12:48:22 -07:00
Aaron Hill 18f5ba18e9 core: Don't overwrite font descriptor with a duplicate
If a SWF contains multiple DefineFont tags with the same
font name (but different font IDs), the first tag will win
when a font is looked up by *name*. This affects the behavior
of EditText objects, which can have embedded HTML like
`<font face="MyFontName">` which performs a font lookup by name.

This fixes Fancy Pants World 4 Part 3, which contains two
DefineFont3 tags with the name FancyFont. The second font is
missing many glyphs, so using it causes us to be unable to
render the squiggle and life count text.
2023-03-31 22:47:00 -07:00
Nathan Adams fcaf462423 core: Fix set_pixels_from_byte_array respecting the bytearray position + tests 2023-03-31 21:32:15 -07:00
Mike Welsh 6fda813f0c tests: Add test for localToGlobal with zero scale object 2023-03-31 16:26:11 -07:00
Mike Welsh c7387eace4 tests: Add tests for hitTesting zero scale graphics 2023-03-31 16:26:11 -07:00
Nathan Adams 94e5aa8f34 core: Fix calculating dirty area of BitmapData.draw() with rotation 2023-03-31 16:57:52 +02:00
Nathan Adams f0ebefd624 tests: Add bitmapdata recursive draw test 2023-03-31 16:57:52 +02:00
Nathan Adams 78f9bb13d6 render: Fix PixelRegion::for_region_i32 for negative coordinates 2023-03-31 16:57:52 +02:00
Nathan Adams e614265c17 core: Move fill_rect from BitmapData to bitmap_data_operations, fixed a bug when using non-standard values, and added better tests for fill_rect showing the bug 2023-03-31 16:57:52 +02:00
Toad06 fea8e8c90a tests: `MovieClip.setMask` in avm1 2023-03-31 02:39:39 -07:00
Tom Schuster ce4ddee792 avm2: Shim flash.xml.XMLNode using XML 2023-03-31 00:11:52 -07:00
onkrot 5632ade09c avm2: Hookup `DisplayObject.opaqueBackground` 2023-03-29 23:11:01 -07:00
Tom Schuster d16a8726c9 tests: Add test for XML.childIndex 2023-03-29 14:40:29 -05:00
Tom Schuster bbf4363395 tests: Add test for XML.copy 2023-03-29 11:04:32 -05:00
Nathan Adams 42e23ce100 tests: Add tests for LoaderInfo properties that error 2023-03-28 11:57:00 +02:00