From adda66723ef5e149fe9c796979b7b4f0f98b74ae Mon Sep 17 00:00:00 2001 From: Nathan Adams Date: Fri, 11 Aug 2023 17:18:51 +0200 Subject: [PATCH] core: Use filters to calculate render sizes of objects --- core/src/display_object.rs | 31 +++++++++++++++---- core/src/display_object/avm2_button.rs | 17 ++++++++-- .../contains_grown_filter/test.toml | 1 - 3 files changed, 39 insertions(+), 10 deletions(-) diff --git a/core/src/display_object.rs b/core/src/display_object.rs index 82dc40d39..dbf85ca94 100644 --- a/core/src/display_object.rs +++ b/core/src/display_object.rs @@ -772,7 +772,11 @@ pub fn render_base<'gc>(this: DisplayObject<'gc>, context: &mut RenderContext<'_ let cache_info = if context.use_bitmap_cache && this.is_bitmap_cached() { let mut cache_info: Option = None; let base_transform = context.transform_stack.transform(); - let bounds: Rectangle = this.render_bounds_with_transform(&base_transform.matrix); + let bounds: Rectangle = this.render_bounds_with_transform( + &base_transform.matrix, + false, // we want to do the filter growth for this object ourselves, to know the offsets + &context.stage.view_matrix(), + ); let name = this.name(); let mut filters: Vec = this.filters(); let swf_version = this.swf_version(); @@ -965,8 +969,11 @@ pub fn render_base<'gc>(this: DisplayObject<'gc>, context: &mut RenderContext<'_ if let Some(background) = this.opaque_background() { // This is intended for use with cacheAsBitmap, but can be set for non-cached objects too // It wants the entire bounding box to be cleared before any draws happen - let bounds: Rectangle = - this.render_bounds_with_transform(&context.transform_stack.transform().matrix); + let bounds: Rectangle = this.render_bounds_with_transform( + &context.transform_stack.transform().matrix, + true, + &context.stage.view_matrix(), + ); context.commands.draw_rect( background, Matrix::create_box( @@ -1173,17 +1180,29 @@ pub trait TDisplayObject<'gc>: /// This differs from the bounds that are exposed to Flash, in two main ways: /// - It may be larger if filters are applied which will increase the size of what's shown /// - It does not respect scroll rects - fn render_bounds_with_transform(&self, matrix: &Matrix) -> Rectangle { + fn render_bounds_with_transform( + &self, + matrix: &Matrix, + include_own_filters: bool, + view_matrix: &Matrix, + ) -> Rectangle { let mut bounds = *matrix * self.self_bounds(); if let Some(ctr) = self.as_container() { for child in ctr.iter_render_list() { let matrix = *matrix * *child.base().matrix(); - bounds = bounds.union(&child.render_bounds_with_transform(&matrix)); + bounds = + bounds.union(&child.render_bounds_with_transform(&matrix, true, view_matrix)); } } - // TODO: make it expand with filter sizes here + if include_own_filters { + let filters = self.filters(); + for mut filter in filters { + filter.scale(view_matrix.a, view_matrix.d); + bounds = filter.calculate_dest_rect(bounds); + } + } bounds } diff --git a/core/src/display_object/avm2_button.rs b/core/src/display_object/avm2_button.rs index 5019a4832..fcfaeb96a 100644 --- a/core/src/display_object/avm2_button.rs +++ b/core/src/display_object/avm2_button.rs @@ -637,16 +637,27 @@ impl<'gc> TDisplayObject<'gc> for Avm2Button<'gc> { bounds } - fn render_bounds_with_transform(&self, matrix: &Matrix) -> Rectangle { + fn render_bounds_with_transform( + &self, + matrix: &Matrix, + include_own_filters: bool, + view_matrix: &Matrix, + ) -> Rectangle { let mut bounds = *matrix * self.self_bounds(); let state = self.0.read().state; if let Some(child) = self.get_state_child(state.into()) { let matrix = *matrix * *child.base().matrix(); - bounds = bounds.union(&child.render_bounds_with_transform(&matrix)); + bounds = bounds.union(&child.render_bounds_with_transform(&matrix, true, view_matrix)); } - // TODO: make it expand with filter sizes here + if include_own_filters { + let filters = self.filters(); + for mut filter in filters { + filter.scale(view_matrix.a, view_matrix.d); + bounds = filter.calculate_dest_rect(bounds); + } + } bounds } diff --git a/tests/tests/swfs/visual/cache_as_bitmap/contains_grown_filter/test.toml b/tests/tests/swfs/visual/cache_as_bitmap/contains_grown_filter/test.toml index 93524bbb5..00c2ef7b3 100644 --- a/tests/tests/swfs/visual/cache_as_bitmap/contains_grown_filter/test.toml +++ b/tests/tests/swfs/visual/cache_as_bitmap/contains_grown_filter/test.toml @@ -1,5 +1,4 @@ num_frames = 1 -known_failure = true [image_comparisons.output] tolerance = 5