Commit Graph

10077 Commits

Author SHA1 Message Date
Aaron Hill 0fa16dfe69 avm2: Remove redundant 'depth' variable in XML parsing 2023-07-19 00:20:14 +02:00
Nathan Adams aa243dbe4c tests: Port Shumway's acid tests over 2023-07-18 23:48:21 +02:00
Nathan Adams a35ea3d9f2 wgpu: Sum up all center blur pixels before multiplying 2023-07-17 23:33:30 +02:00
Nathan Adams 18e343c6ad wgpu: Shift blur uvs over to the left of the kernel 2023-07-17 23:33:30 +02:00
Nathan Adams 8ecd9d0181 wgpu: Precompute left_weight in blur shader 2023-07-17 23:33:30 +02:00
Nathan Adams 13eda1361a wgpu: Use push constants for blur buffer, when supported 2023-07-17 23:33:30 +02:00
Nathan Adams 0076d65865 wgpu: Speed up blur filter by about 50% 2023-07-17 23:33:30 +02:00
MartySVK 6667ea1d94
avm2: Stub flash.globalization.CurrencyFormatter.format (#12108)
* fixes Rogue Soul 2

* return after stub_method
2023-07-17 21:00:43 +00:00
Crowdin Bot 50c819295c chore: Update translations from Crowdin 2023-07-17 21:15:43 +02:00
relrelb 151ad97686 avm1: Migrate `SharedObject` to `NativeObject` 2023-07-17 11:34:06 +03:00
renovate[bot] 268403faad chore(deps): lock file maintenance rust dependencies 2023-07-17 09:55:56 +03:00
nosamu de9ea9571b avm2: Implement SharedObject.size 2023-07-17 00:53:52 +02:00
nosamu fea0df192f avm1: Implement SharedObject.getSize() 2023-07-17 00:53:52 +02:00
MrCheeze e1819f7c00 tests: Add visual test for colored underlines.
Note that the underline's vertical position is wrong, meaning that the
expected.png will have to be updated whenever this is fixed.
2023-07-17 00:32:46 +02:00
MrCheeze 08e13b5056 core: Make underlines the same color as their text 2023-07-17 00:32:46 +02:00
Kornelius Rohrschneider ac5b3d9b2f core: Move use_new_invalid_bounds to Avm1 & Add documentation
The variable use_new_invalid_bounds has been moved from the
UpdateContext and the Player to the Avm1 struct because it is only used
for AVM1 code. A getter method and an activator method setting it to
true have been added as well.
The get_bounds function, which uses the variable, has been adapted to
use the getter and the activator.

Additionally, documentation has been added and improved.
The MovieClip now contains documentation about all MovieClip states and
the use_new_invalid_bounds documentation has been extended to explain
the logic of how the variable is set and used.
2023-07-17 00:08:02 +02:00
Kornelius Rohrschneider 48192efe8a core: Remove MovieClip::oldest_parent_swf_version
The MovieClip variable oldest_parent_swf_version and its getter method
have been removed because they were unnecessary, as the UpdateContext
already provides the root movie.
The call of the getter method has been replaced by
activation.context.swf.version().
2023-07-17 00:08:02 +02:00
Kornelius Rohrschneider a0493c770e core: Implement suggested changes to PR
The suggested changes in the feedback to the pull request have been
implemented.
Therefore, this commit consists of multiple smaller changes:

- The unload_movie method has been renamed to avm1_unload_movie.
- The movieclip_default_state test now doesn't test
  getTextSnapshot().getCount() because the underlying methods haven't
  been implemented in AVM1 yet.
  This should be reverted when they have been implemented or stubbed in
  AVM1.
2023-07-17 00:08:02 +02:00
Kornelius Rohrschneider bd67ce8661 tests: Add MovieClip state tests
Two tests testing the different states of a MovieClip have been added.

A MovieClip can be in different specific states (namely: default state,
initial loading state, error state, image state, success state and
unloaded state). A state of a MovieClip consists of the values of all
properties and the results of some getter functions of the MovieClip.
To make sure that all of these states are implemented correctly and will
continue to be so in the future, two MovieClip state tests have been
added.

The movieclip_default_state test tests the default state of a MovieClip
after it has been created with createEmptyMovieClip.

The movieclip_state_values test has MovieClips going through all other
states and tests if the values are correct in each.

These tests currently only test the MovieClip states when trying to load
a local file since Ruffle tests currently don’t support tests using
remote URLs. Test cases for remote URLs are still included and can be
used if Ruffle starts supporting remote URLs at some point.

A HelperTest, which can be used to find out about how the state of a
MovieClip changes when trying to load and unload it, has been included
as well.
2023-07-17 00:08:02 +02:00
Kornelius Rohrschneider c74a43e643 core: Add MovieClip unloaded state
An unload_movie method has been added to the MovieClip. It unloads the
MovieClip, which means that one frame after it has been called,
avm1_unload and the new transform_to_unloaded_state method get called
and the MovieClip enters the unloaded state in which some attributes
have certain values.
To do this, it creates and spawns a future which calls avm1_unload and
transform_to_unloaded_state (which actually makes the MovieClip enter
the unloaded state).
It uses the new MovieUnloader (which has been added to the Loader enum)
to pass the MovieClip to the asynchronous code. The MovieUnloader saves
a handle and the target clip, and the asynchronous code retrieves it
from the LoadManager.

unload_movie is now called when a MovieClip should be unloaded.
TODOs have been added, describing to check whether other avm1_unload
calls also need to be delayed by one frame and whether unload_movie also
needs to be called in other places.

Additionally, a spelling mistake has been corrected.
2023-07-17 00:08:02 +02:00
Kornelius Rohrschneider 8888aae60b tests: Add MovieClip invalid getBounds tests
The behaviour of when the results of getBounds / getRect calls on
MovieClips with invalid bounds are 6710886.35 and when they are
6710886.4 for each corner of the rectangle is rather complex.
To make sure it works correctly in every case and will continue to do so
in the future, eight tests testing the results of getBounds calls under
these circumstances have been added.

This needs to be tested in several tests because an internal state
determining the results can change irreversibly. Making sure that it
changes correctly on different occasions takes several tests.
2023-07-17 00:08:02 +02:00
Kornelius Rohrschneider d2ac9d32b4 core: Correct MovieClip default state
Previously, the MovieClip default state contained wrong values for
opaqueBackground, transform.pixelBounds and getRect & getBounds with
another default MovieClip as the parameter.
This has been corrected; the calculation of these values has been fixed.

To do that, a use_new_invalid_bounds_value variable has been added to
the UpdateContext and the Player (from which the UpdateContext is
created).
Additionally, an oldest_parent_swf_version variable has been added to
the MovieClip with a getter method for it. It is calculated and saved on
demand in the getter.
These variables are retrieved in the get_bounds function and used to set
use_new_invalid_bounds_value and to calculate the correct bounds.

Ruffle now uses the correct MovieClip default state.
2023-07-17 00:08:02 +02:00
Kornelius Rohrschneider 96e0f445bb core: Correct MovieClip image state
The set_cur_preload_frame and set_current_frame methods have been added
to the MovieClip.
If the Loader now loads an image, these methods are called to set the
MovieClip image state correctly.

Additionally, load_error_swf now uses set_cur_preload_frame instead of
the removed movie_not_available method.
2023-07-17 00:08:02 +02:00
Kornelius Rohrschneider 400edf5368 core: Add MovieClip initial loading state
A load_initial_loading_swf function has been added to the Loader. It
makes the MovieClip enter the initial loading state in which some
attributes have certain initial loading values to signal that the file
is currently being loaded and neither an error has occurred nor the
first frame has been successfully loaded yet.
The Loader calls the function when initialising the loading before it
gets an error or success.

Additionally, load_error_swf has been improved: If a local URL is
fetched on a WASM target, the _url property will now be correctly set as
in the flash player.

The documentation has been improved.
2023-07-17 00:08:02 +02:00
Kornelius Rohrschneider a0d0b8e638 core: Refactor & improve NavigatorBackend implementations
All NavigatorBackend implementations have been refactored, resulting in
improved code quality, less duplicated code, more consistent and easier
to understand procedures, additional error handling and better error
messages.

A resolve_url method has been added to the NavigatorBackend trait. It
takes a URL and and resolves it to the actual URL from which a file can
be fetched (including handling of relative links and pre-processing). It
has been implemented in each NavigatorBackend implementation.

Duplicated code has been put into new public functions in
core/src/backend/navigator.rs which are called by all NavigatorBackend
implementations.

ExternalNavigatorBackend:
- The navigate_to_url and fetch methods have been adapted to use
  resolve_url, removing redundant code.
- Error handling has been added in case that the URL can't be converted
  to a PathBuf.
- A TODO about differences between the flash player fetch and the
  Ruffle fetch implementation has been added.

WebNavigatorBackend:
- The previous resolve_url method exclusively to the WebNavigatorBackend
  has been replaced by the new resolve_url method. It is used by
  navigate_to_url and fetch.
- resolve_url now always pre-processes the URL if it's valid (even if no
  base_url exists) and explicitly returns whether the URL can be parsed.
- navigate_to_url now traces an explanatory error each if the URL can't
  be parsed or is local.
- fetch now returns an explanatory error each if the URL can't be parsed
  or is local (previously, a vague "Got JS error" has been returned).

TestNavigatorBackend & NullNavigatorBackend:
- fetch pre-processes the URL now (using the resolve_url implementation).
- If the URL isn't local, an explanatory error is returned (previously,
  it was just an "Invalid URL" error).
- If the URL can't be parsed, an explanatory error with the reason is
  returned (previously, it was just an "Invalid URL" error).

Additionally, error messages in all NavigatorBackend implementations
have been improved and made more consistent, e.g. if a local file can't
be read.
2023-07-17 00:08:02 +02:00
Kornelius Rohrschneider 687c0e7516 core: Complete MovieClip error state & Change uncompressed_len to i32
Previously, the MovieClip error state contained one TODO in order to be
completely implemented: The HeaderExt variable uncompressed_len needs to
be -1 in the error state, but its type has been u32.
The type has now been changed to i32, and the variable is set to -1 in
the default_error_header function. Therefore, the MovieClip error state
is now fully implemented.

Other connected functions and variables like SwfMovie::uncompressed_len
or MovieClip::total_bytes have been adjusted to this type change. Code
has been adjusted if needed where this value is used.
2023-07-17 00:08:02 +02:00
Kornelius Rohrschneider 893052c2a6 core: Add MovieClip error state
A load_error_swf function has been added to the Loader. It makes the
MovieClip enter the error state in which some attributes have certain
error values to signal that no valid file could be loaded. This happens
if no file could be loaded or if the loaded content is no valid
supported content.
The function creates an error state movie stub using the new
SwfMovie::error_movie function (which uses a new default_error_header
function) and configures remaining variables with the
movie_not_available method.
One TODO in order for the error state to be completely implemented has
been added.

Since the error state of the MovieClip includes the final URL of the SWF
file obtained after any redirects, the load_error_swf and
movie_loader_error functions (now) take an swf_url attribute.
To get this URL in case no file could be loaded, the
NavigatorBackend::fetch method has been changed to return an
ErrorResponse struct (including the url and the actual error) in the
error case. The Response struct returned in the success case has been
renamed to SuccessResponse.
All fetch implementations have been adapted accordingly. Code has been
adjusted to return the actual error where that's needed.

Documentation has been added and improved.
2023-07-17 00:08:02 +02:00
Kornelius Rohrschneider 5352c86202 core: Remove duplicated functions
Duplicated functions have been removed (and replaced by corresponding
calls to the other functions).
2023-07-17 00:08:02 +02:00
Kornelius Rohrschneider 2d629dbf72 core: Correct _framesloaded value if movie couldn't be loaded
If an SWF tries to load a movie that can't be loaded, the Flash Player
sets _framesloaded of the MovieClip to -1. This has previously not been
implemented in Ruffle.

A new movie_not_available function has been added to the MovieClip
class. It sets the cur_preload_frame variable to 0.
This function is now called in the movie_loader_error function of the
Loader class (if a movie can't be loaded).

The frames_loaded function (which returns _framesloaded of the
MovieClip, which is given to the SWF) now returns an i32 and not an u16
value. This allows it to return a negative value. Code has been adjusted
where an u16 value is expected (clamping negative values to 0).
frames_loaded now returns cur_preload_frame - 1. Previously, it has
returned cur_preload_frame - 1 and clamped it to zero, but since the -1,
in case cur_preload_frame is zero, is explicitly wanted, this has been
corrected.
2023-07-17 00:08:02 +02:00
Nathan Adams cd2d01bf6f wgpu: Fix crash when not using push constants 2023-07-16 00:31:50 +02:00
Nathan Adams 34c0d41fca web: Remove no longer needed depencency 'shx' 2023-07-15 23:48:04 +02:00
Nathan Adams be48ff357f web: Add build_wasm.js script to replace chained npm scripts 2023-07-15 23:48:04 +02:00
nosamu 48e37914cf web: Make isTouch indicate the source of the last PointerEvent
This allows the behavior of the context menu to change depending
on whether it was triggered by a touch or right-click.
2023-07-15 19:14:13 +02:00
nosamu e7689ac883 Revert "web: Make isTouch locally scoped to showContextMenu"
This completely broke touch detection
2023-07-15 19:14:13 +02:00
MrCheeze 901594b99f
avm2: Do not remove an EditText's selection on unfocus (fix #9006) + implement selectionBegin/selectionEnd/caretIndex (#9067)
* avm2: Do not remove an EditText's selection on unfocus (fix #9006)

There are significant differences between how selection and caret info
work between AVM1 and AVM2.

In AVM1, there is only a single, global selection, which applies to
whichever element is currently focused. Therefore changing the focus
necessarily erases any information of what was selected before. There
can also be no active selection at all.

In AVM2, every text field has its own independent selection info. It is
NOT optional, the default selection is just a caret at position 0. If a
field loses focus, the selection is not rendered, but it is still
present. Movies such as #9006 rely on the same selection still being
there once you give back focus to the field.

Ruffle's model of selections (an Option per text field) is different
from both the AVM1 model (an optional singleton) and the AVM2 model
(mandatory per text field). This fix does not change that, it is only a
narrow fix targeted at 9006.

* avm2: implement selectionBegin/selectionEnd/caretIndex and add a test.

The selection test validates a few situations, including the behaviour
when unfocusing that was fixed in the previous commit.

The test does not validate how the selection changes after replacing
text, as there are still some inaccuracies there.

* avm2: Additional selection fixes needed after merging with master.

1. The default caret for an AVM2 textbox is at the end of the textbox,
   not the beginning.
2. Selection should not be changed when focusing on a textbox in AVM2.
3. Fixed a test whose output.txt didn't actually match the flash player
   output.

* avm2: Make the selection AVM checks compatible with mixed AVM, and revert the on_focus_changed parameters

---------

Co-authored-by: Nathan Adams <dinnerbone@dinnerbone.com>
2023-07-15 16:17:45 +00:00
Nathan Adams 26cf380aa4 avm2: Fix Array.sort(function) 2023-07-15 17:53:05 +02:00
Lord-McSweeney 3e193214df swf: Ignore bad ConstantPool string reads 2023-07-15 12:10:36 +02:00
Lord-McSweeney 61a4ded851 swf: Ignore bad ActionTry opcodes 2023-07-15 12:10:36 +02:00
CUB3D e4bd1908bd chore: Fmt 2023-07-15 11:45:02 +02:00
CUB3D 14712b46c6 chore: Fix clippy lint 2023-07-15 11:45:02 +02:00
CUB3D d7a780f5ea core: Fix caching order, add test 2023-07-15 11:45:02 +02:00
CUB3D 27bc6e9609 avm1: Fix panic on writing self-referential SharedObjects 2023-07-15 11:45:02 +02:00
Abiel Deneke ae1853f639 tests: Add test for `Matrix3D.transformVectors` 2023-07-14 23:39:39 -04:00
Abiel Deneke 4afcadf4fd avm2: Implement `Matrix3D.transformVectors` 2023-07-14 23:39:39 -04:00
Nathan Adams ee7412d733 wgpu: Fix off-by-one in blur size calculation 2023-07-15 01:49:57 +02:00
michiel2005 6b423a7eef Ran cargo fmt 2023-07-14 16:51:07 -06:00
michiel2005 fc32dc3671 Removed some code that was double checking without any need. 2023-07-14 16:51:07 -06:00
michiel2005 c812a8af54 checked for movie equality in check_display_object_equality().
Makes code more readable.
2023-07-14 16:51:07 -06:00
michiel2005 4f605947e5 Well, we don't talk about this mistake. 2023-07-14 16:51:07 -06:00
michiel2005 2307bd7e74 Changed down_object to pressed and removed one issue in my code Lord-McSweeney found 2023-07-14 16:51:07 -06:00