Skip to content

Commit

Permalink
avm2: Use slot access in native code for DisplayObject
Browse files Browse the repository at this point in the history
  • Loading branch information
Lord-McSweeney authored and Lord-McSweeney committed Dec 10, 2024
1 parent e3a599a commit 57da4a7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 30 deletions.
35 changes: 9 additions & 26 deletions core/src/avm2/globals/flash/display/display_object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
use crate::avm2::activation::Activation;
use crate::avm2::error::{illegal_operation_error, make_error_2007, make_error_2008};
use crate::avm2::filters::FilterAvm2Ext;
use crate::avm2::globals::slots::{
flash_geom_point as point_slots, flash_geom_rectangle as rectangle_slots,
};
use crate::avm2::globals::flash::geom::transform::color_transform_from_transform_object;
use crate::avm2::globals::flash::geom::transform::matrix_from_transform_object;
use crate::avm2::globals::slots::flash_display_shader as shader_slots;
use crate::avm2::globals::slots::flash_geom_point as point_slots;
use crate::avm2::globals::slots::flash_geom_rectangle as rectangle_slots;
use crate::avm2::object::{Object, TObject};
use crate::avm2::parameters::ParametersExt;
use crate::avm2::value::Value;
Expand Down Expand Up @@ -754,28 +756,9 @@ pub fn set_transform<'gc>(
let transform = args.get_object(activation, 0, "transform")?;

// FIXME - consider 3D matrix and pixel bounds
let matrix = transform
.get_public_property("matrix", activation)?
.as_object();

let Some(matrix) = matrix else {
// FP seems to not do anything when setting to a Transform with a null matrix,
// but we don't actually support setting the matrix to null anyway
// (see the comment in `flash::geom::transform::set_matrix`)
return Ok(Value::Undefined);
};

let color_transform = transform
.get_public_property("colorTransform", activation)?
.as_object()
.expect("colorTransform should be non-null");

let matrix =
crate::avm2::globals::flash::geom::transform::object_to_matrix(matrix, activation)?;
let color_transform = crate::avm2::globals::flash::geom::transform::object_to_color_transform(
color_transform,
activation,
)?;
let matrix = matrix_from_transform_object(transform);

let color_transform = color_transform_from_transform_object(transform);

let dobj = this.as_display_object().unwrap();
let mut write = dobj.base_mut(activation.context.gc_context);
Expand Down Expand Up @@ -1108,7 +1091,7 @@ pub fn set_blend_shader<'gc>(
if let Some(dobj) = this.as_display_object() {
let Some(shader_data) = args
.get_object(activation, 0, "shader")?
.get_public_property("data", activation)?
.get_slot(shader_slots::_DATA)
.as_object()
else {
return Err(make_error_2007(activation, "data"));
Expand Down
17 changes: 13 additions & 4 deletions core/src/avm2/globals/flash/geom/transform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@ pub fn get_color_transform<'gc>(
this: Object<'gc>,
_args: &[Value<'gc>],
) -> Result<Value<'gc>, Error<'gc>> {
let display_object = get_display_object(this);
let display_object = display_object.base();
color_transform_to_object(display_object.color_transform(), activation)
let color_transform = color_transform_from_transform_object(this);
color_transform_to_object(&color_transform, activation)
}

pub fn set_color_transform<'gc>(
Expand All @@ -49,7 +48,7 @@ pub fn get_matrix<'gc>(
this: Object<'gc>,
_args: &[Value<'gc>],
) -> Result<Value<'gc>, Error<'gc>> {
let matrix = *get_display_object(this).base().matrix();
let matrix = matrix_from_transform_object(this);
matrix_to_object(matrix, activation)
}

Expand Down Expand Up @@ -110,6 +109,16 @@ pub fn get_concatenated_matrix<'gc>(
}
}

pub fn matrix_from_transform_object(transform_object: Object<'_>) -> Matrix {
*get_display_object(transform_object).base().matrix()
}

pub fn color_transform_from_transform_object(transform_object: Object<'_>) -> ColorTransform {
*get_display_object(transform_object)
.base()
.color_transform()
}

// FIXME - handle clamping. We're throwing away precision here in converting to an integer:
// is that what we should be doing?
pub fn object_to_color_transform<'gc>(
Expand Down

0 comments on commit 57da4a7

Please sign in to comment.