Skip to content

Commit 61fddf5

Browse files
torokati44Herschel
authored andcommitted
core/display_object: Correctly draw videos that have different bounds than the size of their actual frame data
1 parent ff6adaf commit 61fddf5

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

core/src/display_object/video.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
use crate::avm1::{Object as Avm1Object, StageObject as Avm1StageObject};
44
use crate::avm2::{Object as Avm2Object, StageObject as Avm2StageObject};
5-
use crate::backend::render::BitmapHandle;
5+
use crate::backend::render::BitmapInfo;
66
use crate::backend::video::{EncodedFrame, VideoStreamHandle};
77
use crate::bounding_box::BoundingBox;
88
use crate::collect::CollectWrapper;
@@ -40,7 +40,7 @@ pub struct VideoData<'gc> {
4040
stream: VideoStream,
4141

4242
/// The last decoded frame in the video stream.
43-
decoded_frame: Option<(u32, CollectWrapper<BitmapHandle>)>,
43+
decoded_frame: Option<(u32, CollectWrapper<BitmapInfo>)>,
4444

4545
/// AVM representation of this video player.
4646
object: Option<AvmObject<'gc>>,
@@ -248,7 +248,6 @@ impl<'gc> Video<'gc> {
248248
context
249249
.video
250250
.decode_video_stream_frame(*stream, encframe, context.renderer)
251-
.map(|bi| bi.handle)
252251
}
253252
None => {
254253
if let Some((_old_id, old_frame)) = &read.decoded_frame {
@@ -415,9 +414,19 @@ impl<'gc> TDisplayObject<'gc> for Video<'gc> {
415414
context.transform_stack.push(&*self.transform());
416415

417416
if let Some((_frame_id, ref bitmap)) = self.0.read().decoded_frame {
417+
let mut transform = context.transform_stack.transform().clone();
418+
let bounds = self.self_bounds();
419+
420+
// The actual decoded frames might be different in size than the declared
421+
// bounds of the VideoStream tag, so a final scale adjustment has to be done.
422+
transform.matrix *= Matrix::scale(
423+
bounds.width().to_pixels() as f32 / bitmap.0.width as f32,
424+
bounds.height().to_pixels() as f32 / bitmap.0.height as f32,
425+
);
426+
418427
context
419428
.renderer
420-
.render_bitmap(bitmap.0, context.transform_stack.transform(), false);
429+
.render_bitmap(bitmap.0.handle, &transform, false);
421430
} else {
422431
log::warn!("Video has no decoded frame to render.");
423432
}

0 commit comments

Comments
 (0)