Skip to content

Commit

Permalink
avm2: Use slot access in avm2_to_gradient_filter and `get_gradient_…
Browse files Browse the repository at this point in the history
…colors`
  • Loading branch information
Lord-McSweeney authored and Lord-McSweeney committed Dec 13, 2024
1 parent ed89aac commit 7cc8743
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 19 deletions.
31 changes: 13 additions & 18 deletions core/src/avm2/filters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use crate::avm2::globals::slots::flash_filters_convolution_filter as convolution
use crate::avm2::globals::slots::flash_filters_displacement_map_filter as displacement_map_filter_slots;
use crate::avm2::globals::slots::flash_filters_drop_shadow_filter as drop_shadow_filter_slots;
use crate::avm2::globals::slots::flash_filters_glow_filter as glow_filter_slots;
use crate::avm2::globals::slots::flash_filters_gradient_bevel_filter as gradient_filter_slots;
use crate::avm2::globals::slots::flash_filters_shader_filter as shader_filter_slots;
use crate::avm2::globals::slots::flash_geom_point as point_slots;
use crate::avm2::object::{ArrayObject, ClassObject, Object, TObject};
Expand Down Expand Up @@ -698,28 +699,28 @@ fn avm2_to_gradient_filter<'gc>(
object: Object<'gc>,
) -> Result<GradientFilter, Error<'gc>> {
let angle = object
.get_public_property("angle", activation)?
.get_slot(gradient_filter_slots::ANGLE)
.coerce_to_number(activation)?;
let blur_x = object
.get_public_property("blurX", activation)?
.get_slot(gradient_filter_slots::BLUR_X)
.coerce_to_number(activation)?;
let blur_y = object
.get_public_property("blurY", activation)?
.get_slot(gradient_filter_slots::BLUR_Y)
.coerce_to_number(activation)?;
let distance = object
.get_public_property("distance", activation)?
.get_slot(gradient_filter_slots::DISTANCE)
.coerce_to_number(activation)?;
let knockout = object
.get_public_property("knockout", activation)?
.get_slot(gradient_filter_slots::KNOCKOUT)
.coerce_to_boolean();
let quality = object
.get_public_property("quality", activation)?
.get_slot(gradient_filter_slots::QUALITY)
.coerce_to_u32(activation)?;
let strength = object
.get_public_property("strength", activation)?
.get_slot(gradient_filter_slots::STRENGTH)
.coerce_to_number(activation)?;
let bevel_type = object
.get_public_property("type", activation)?
.get_slot(gradient_filter_slots::TYPE)
.coerce_to_string(activation)?;
let colors = get_gradient_colors(activation, object)?;
let mut flags = GradientFilterFlags::COMPOSITE_SOURCE;
Expand Down Expand Up @@ -856,19 +857,13 @@ fn get_gradient_colors<'gc>(
object: Object<'gc>,
) -> Result<Vec<GradientRecord>, Error<'gc>> {
let mut colors = vec![];
if let Some(colors_object) = object
.get_public_property("colors", activation)?
.as_object()
{
if let Some(colors_object) = object.get_slot(gradient_filter_slots::COLORS).as_object() {
if let Some(colors_array) = colors_object.as_array_storage() {
if let Some(alphas_object) = object
.get_public_property("alphas", activation)?
.as_object()
if let Some(alphas_object) = object.get_slot(gradient_filter_slots::ALPHAS).as_object()
{
if let Some(alphas_array) = alphas_object.as_array_storage() {
if let Some(ratios_object) = object
.get_public_property("ratios", activation)?
.as_object()
if let Some(ratios_object) =
object.get_slot(gradient_filter_slots::RATIOS).as_object()
{
if let Some(ratios_array) = ratios_object.as_array_storage() {
// Flash only keeps the elements from any array until the lowest index in each array
Expand Down
25 changes: 25 additions & 0 deletions core/src/avm2/globals/flash/filters/GradientBevelFilter.as
Original file line number Diff line number Diff line change
@@ -1,15 +1,40 @@
package flash.filters {
public final class GradientBevelFilter extends BitmapFilter {
// NOTE if reordering these fields, make sure to use the same order in
// GradientGlowFilter; filter code assumes the slot layouts are identical

// FIXME these should all be getters/setters to match Flash
[Ruffle(InternalSlot)]
public var alphas : Array;

[Ruffle(InternalSlot)]
public var angle : Number;

[Ruffle(InternalSlot)]
public var blurX : Number;

[Ruffle(InternalSlot)]
public var blurY : Number;

[Ruffle(InternalSlot)]
public var colors : Array;

[Ruffle(InternalSlot)]
public var distance : Number;

[Ruffle(InternalSlot)]
public var knockout : Boolean;

[Ruffle(InternalSlot)]
public var quality : int;

[Ruffle(InternalSlot)]
public var ratios : Array;

[Ruffle(InternalSlot)]
public var strength : Number;

[Ruffle(InternalSlot)]
public var type : String;

public function GradientBevelFilter(
Expand Down
8 changes: 7 additions & 1 deletion core/src/avm2/globals/flash/filters/GradientGlowFilter.as
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
package flash.filters {
public final class GradientGlowFilter extends BitmapFilter {
// NOTE if reordering these fields, make sure to use the same order in
// GradientBevelFilter; filter code assumes the slot layouts are identical
// (these aren't annotated with [Ruffle(InternalSlot)] because we use the
// slots from GradientBevelFilter to access them)

// FIXME these should all be getters/setters to match Flash
public var alphas : Array;
public var angle : Number;
public var blurX : Number;
Expand Down Expand Up @@ -43,4 +49,4 @@
return new GradientGlowFilter(this.distance, this.angle, this.colors, this.alphas, this.ratios, this.blurX, this.blurY, this.strength, this.quality, this.type, this.knockout);
}
}
}
}

0 comments on commit 7cc8743

Please sign in to comment.