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 ceb0187 commit f59b90c
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 23 deletions.
40 changes: 29 additions & 11 deletions core/src/avm2/filters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ 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_bevel_filter_slots;
use crate::avm2::globals::slots::flash_filters_gradient_glow_filter as gradient_glow_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 @@ -697,29 +699,45 @@ fn avm2_to_gradient_filter<'gc>(
activation: &mut Activation<'_, 'gc>,
object: Object<'gc>,
) -> Result<GradientFilter, Error<'gc>> {
#[allow(clippy::assertions_on_constants)]
{
assert!(gradient_bevel_filter_slots::ANGLE == gradient_glow_filter_slots::ANGLE);
assert!(gradient_bevel_filter_slots::BLUR_X == gradient_glow_filter_slots::BLUR_X);
assert!(gradient_bevel_filter_slots::BLUR_Y == gradient_glow_filter_slots::BLUR_Y);
assert!(gradient_bevel_filter_slots::DISTANCE == gradient_glow_filter_slots::DISTANCE);
assert!(gradient_bevel_filter_slots::KNOCKOUT == gradient_glow_filter_slots::KNOCKOUT);
assert!(gradient_bevel_filter_slots::QUALITY == gradient_glow_filter_slots::QUALITY);
assert!(gradient_bevel_filter_slots::STRENGTH == gradient_glow_filter_slots::STRENGTH);
assert!(gradient_bevel_filter_slots::TYPE == gradient_glow_filter_slots::TYPE);

assert!(gradient_bevel_filter_slots::COLORS == gradient_glow_filter_slots::COLORS);
assert!(gradient_bevel_filter_slots::ALPHAS == gradient_glow_filter_slots::ALPHAS);
assert!(gradient_bevel_filter_slots::RATIOS == gradient_glow_filter_slots::RATIOS);
}

let angle = object
.get_public_property("angle", activation)?
.get_slot(gradient_bevel_filter_slots::ANGLE)
.coerce_to_number(activation)?;
let blur_x = object
.get_public_property("blurX", activation)?
.get_slot(gradient_bevel_filter_slots::BLUR_X)
.coerce_to_number(activation)?;
let blur_y = object
.get_public_property("blurY", activation)?
.get_slot(gradient_bevel_filter_slots::BLUR_Y)
.coerce_to_number(activation)?;
let distance = object
.get_public_property("distance", activation)?
.get_slot(gradient_bevel_filter_slots::DISTANCE)
.coerce_to_number(activation)?;
let knockout = object
.get_public_property("knockout", activation)?
.get_slot(gradient_bevel_filter_slots::KNOCKOUT)
.coerce_to_boolean();
let quality = object
.get_public_property("quality", activation)?
.get_slot(gradient_bevel_filter_slots::QUALITY)
.coerce_to_u32(activation)?;
let strength = object
.get_public_property("strength", activation)?
.get_slot(gradient_bevel_filter_slots::STRENGTH)
.coerce_to_number(activation)?;
let bevel_type = object
.get_public_property("type", activation)?
.get_slot(gradient_bevel_filter_slots::TYPE)
.coerce_to_string(activation)?;
let colors = get_gradient_colors(activation, object)?;
let mut flags = GradientFilterFlags::COMPOSITE_SOURCE;
Expand Down Expand Up @@ -857,17 +875,17 @@ fn get_gradient_colors<'gc>(
) -> Result<Vec<GradientRecord>, Error<'gc>> {
let mut colors = vec![];
if let Some(colors_object) = object
.get_public_property("colors", activation)?
.get_slot(gradient_bevel_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)?
.get_slot(gradient_bevel_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)?
.get_slot(gradient_bevel_filter_slots::RATIOS)
.as_object()
{
if let Some(ratios_array) = ratios_object.as_array_storage() {
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
51 changes: 39 additions & 12 deletions core/src/avm2/globals/flash/filters/GradientGlowFilter.as
Original file line number Diff line number Diff line change
@@ -1,16 +1,43 @@
package flash.filters {
public final class GradientGlowFilter extends BitmapFilter {
public var alphas : Array;
public var angle : Number;
public var blurX : Number;
public var blurY : Number;
public var colors : Array;
public var distance : Number;
public var knockout : Boolean;
public var quality : int;
public var ratios : Array;
public var strength : Number;
public var type : String;
// 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
[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 GradientGlowFilter(
distance:Number = 4.0,
Expand Down Expand Up @@ -43,4 +70,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 f59b90c

Please sign in to comment.