From 63bc0c082725c0f045a88d829ea1fe204465f146 Mon Sep 17 00:00:00 2001 From: Lord-McSweeney Date: Thu, 12 Dec 2024 00:18:10 -0800 Subject: [PATCH] avm2: Use slot access in `avm2_to_gradient_filter` and `get_gradient_colors` --- core/src/avm2/filters.rs | 40 +++++++++++---- .../flash/filters/GradientBevelFilter.as | 25 +++++++++ .../flash/filters/GradientGlowFilter.as | 51 ++++++++++++++----- 3 files changed, 93 insertions(+), 23 deletions(-) diff --git a/core/src/avm2/filters.rs b/core/src/avm2/filters.rs index 6852470af701..6cf25c452932 100644 --- a/core/src/avm2/filters.rs +++ b/core/src/avm2/filters.rs @@ -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}; @@ -697,29 +699,45 @@ fn avm2_to_gradient_filter<'gc>( activation: &mut Activation<'_, 'gc>, object: Object<'gc>, ) -> Result> { + #[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; @@ -857,17 +875,17 @@ fn get_gradient_colors<'gc>( ) -> Result, 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() { diff --git a/core/src/avm2/globals/flash/filters/GradientBevelFilter.as b/core/src/avm2/globals/flash/filters/GradientBevelFilter.as index 5c59d7c4751a..d9539fbb5c2a 100644 --- a/core/src/avm2/globals/flash/filters/GradientBevelFilter.as +++ b/core/src/avm2/globals/flash/filters/GradientBevelFilter.as @@ -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( diff --git a/core/src/avm2/globals/flash/filters/GradientGlowFilter.as b/core/src/avm2/globals/flash/filters/GradientGlowFilter.as index 9fce4d9a7746..8eeecc713bda 100644 --- a/core/src/avm2/globals/flash/filters/GradientGlowFilter.as +++ b/core/src/avm2/globals/flash/filters/GradientGlowFilter.as @@ -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, @@ -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); } } -} \ No newline at end of file +}