@@ -7,33 +7,35 @@ use crate::library::{Library, MovieLibrarySource};
7
7
use crate :: prelude:: * ;
8
8
use crate :: tag_utils:: SwfMovie ;
9
9
use core:: fmt;
10
- use gc_arena:: { Collect , Gc , GcCell , Mutation } ;
10
+ use gc_arena:: barrier:: unlock;
11
+ use gc_arena:: lock:: { Lock , RefLock } ;
12
+ use gc_arena:: { Collect , Gc , Mutation } ;
11
13
use ruffle_render:: backend:: ShapeHandle ;
12
14
use ruffle_render:: commands:: CommandHandler ;
13
- use std:: cell:: { Ref , RefCell , RefMut } ;
15
+ use std:: cell:: { Cell , Ref , RefCell , RefMut } ;
14
16
use std:: sync:: Arc ;
15
17
use swf:: { Fixed16 , Fixed8 } ;
16
18
17
19
#[ derive( Clone , Collect , Copy ) ]
18
20
#[ collect( no_drop) ]
19
- pub struct MorphShape < ' gc > ( GcCell < ' gc , MorphShapeData < ' gc > > ) ;
21
+ pub struct MorphShape < ' gc > ( Gc < ' gc , MorphShapeData < ' gc > > ) ;
20
22
21
23
impl fmt:: Debug for MorphShape < ' _ > {
22
24
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
23
25
f. debug_struct ( "MorphShape" )
24
- . field ( "ptr" , & self . 0 . as_ptr ( ) )
26
+ . field ( "ptr" , & Gc :: as_ptr ( self . 0 ) )
25
27
. finish ( )
26
28
}
27
29
}
28
30
29
31
#[ derive( Clone , Collect ) ]
30
32
#[ collect( no_drop) ]
31
33
pub struct MorphShapeData < ' gc > {
32
- base : DisplayObjectBase < ' gc > ,
33
- shared : Gc < ' gc , MorphShapeShared > ,
34
- ratio : u16 ,
34
+ base : RefLock < DisplayObjectBase < ' gc > > ,
35
+ shared : Lock < Gc < ' gc , MorphShapeShared > > ,
36
+ ratio : Cell < u16 > ,
35
37
/// The AVM2 representation of this MorphShape.
36
- object : Option < Avm2Object < ' gc > > ,
38
+ object : Lock < Option < Avm2Object < ' gc > > > ,
37
39
}
38
40
39
41
impl < ' gc > MorphShape < ' gc > {
@@ -43,46 +45,46 @@ impl<'gc> MorphShape<'gc> {
43
45
movie : Arc < SwfMovie > ,
44
46
) -> Self {
45
47
let shared = MorphShapeShared :: from_swf_tag ( & tag, movie) ;
46
- MorphShape ( GcCell :: new (
48
+ MorphShape ( Gc :: new (
47
49
gc_context,
48
50
MorphShapeData {
49
51
base : Default :: default ( ) ,
50
- shared : Gc :: new ( gc_context, shared) ,
51
- ratio : 0 ,
52
- object : None ,
52
+ shared : Lock :: new ( Gc :: new ( gc_context, shared) ) ,
53
+ ratio : Cell :: new ( 0 ) ,
54
+ object : Lock :: new ( None ) ,
53
55
} ,
54
56
) )
55
57
}
56
58
57
59
pub fn ratio ( self ) -> u16 {
58
- self . 0 . read ( ) . ratio
60
+ self . 0 . ratio . get ( )
59
61
}
60
62
61
- pub fn set_ratio ( & mut self , gc_context : & Mutation < ' gc > , ratio : u16 ) {
62
- self . 0 . write ( gc_context ) . ratio = ratio ;
63
+ pub fn set_ratio ( self , gc_context : & Mutation < ' gc > , ratio : u16 ) {
64
+ self . 0 . ratio . set ( ratio) ;
63
65
self . invalidate_cached_bitmap ( gc_context) ;
64
66
}
65
67
}
66
68
67
69
impl < ' gc > TDisplayObject < ' gc > for MorphShape < ' gc > {
68
70
fn base ( & self ) -> Ref < DisplayObjectBase < ' gc > > {
69
- Ref :: map ( self . 0 . read ( ) , |r| & r . base )
71
+ self . 0 . base . borrow ( )
70
72
}
71
73
72
74
fn base_mut < ' a > ( & ' a self , mc : & Mutation < ' gc > ) -> RefMut < ' a , DisplayObjectBase < ' gc > > {
73
- RefMut :: map ( self . 0 . write ( mc ) , |w| & mut w . base )
75
+ unlock ! ( Gc :: write ( mc , self . 0 ) , MorphShapeData , base) . borrow_mut ( )
74
76
}
75
77
76
78
fn instantiate ( & self , gc_context : & Mutation < ' gc > ) -> DisplayObject < ' gc > {
77
- Self ( GcCell :: new ( gc_context, self . 0 . read ( ) . clone ( ) ) ) . into ( )
79
+ Self ( Gc :: new ( gc_context, self . 0 . as_ref ( ) . clone ( ) ) ) . into ( )
78
80
}
79
81
80
82
fn as_ptr ( & self ) -> * const DisplayObjectPtr {
81
- self . 0 . as_ptr ( ) as * const DisplayObjectPtr
83
+ Gc :: as_ptr ( self . 0 ) as * const DisplayObjectPtr
82
84
}
83
85
84
86
fn id ( & self ) -> CharacterId {
85
- self . 0 . read ( ) . shared . id
87
+ self . 0 . shared . get ( ) . id
86
88
}
87
89
88
90
fn as_morph_shape ( & self ) -> Option < Self > {
@@ -95,7 +97,8 @@ impl<'gc> TDisplayObject<'gc> for MorphShape<'gc> {
95
97
. library_for_movie_mut ( self . movie ( ) )
96
98
. get_morph_shape ( id)
97
99
{
98
- self . 0 . write ( context. gc ( ) ) . shared = new_morph_shape. 0 . read ( ) . shared ;
100
+ unlock ! ( Gc :: write( context. gc( ) , self . 0 ) , MorphShapeData , shared)
101
+ . set ( new_morph_shape. 0 . shared . get ( ) )
99
102
} else {
100
103
tracing:: warn!( "PlaceObject: expected morph shape at character ID {}" , id) ;
101
104
}
@@ -108,14 +111,15 @@ impl<'gc> TDisplayObject<'gc> for MorphShape<'gc> {
108
111
109
112
fn object2 ( & self ) -> Avm2Value < ' gc > {
110
113
self . 0
111
- . read ( )
112
114
. object
115
+ . get ( )
113
116
. map ( Avm2Value :: from)
114
117
. unwrap_or ( Avm2Value :: Null )
115
118
}
116
119
117
120
fn set_object2 ( & self , context : & mut UpdateContext < ' gc > , to : Avm2Object < ' gc > ) {
118
- self . 0 . write ( context. gc ( ) ) . object = Some ( to) ;
121
+ let mc = context. gc ( ) ;
122
+ unlock ! ( Gc :: write( mc, self . 0 ) , MorphShapeData , object) . set ( Some ( to) )
119
123
}
120
124
121
125
/// Construct objects placed on this frame.
@@ -128,27 +132,25 @@ impl<'gc> TDisplayObject<'gc> for MorphShape<'gc> {
128
132
( * self ) . into ( ) ,
129
133
class,
130
134
) {
131
- Ok ( object) => self . 0 . write ( context. gc ( ) ) . object = Some ( object. into ( ) ) ,
135
+ Ok ( object) => self . set_object2 ( context, object. into ( ) ) ,
132
136
Err ( e) => tracing:: error!( "Got {} when constructing AVM2 side of MorphShape" , e) ,
133
137
} ;
134
138
self . on_construction_complete ( context) ;
135
139
}
136
140
}
137
141
138
142
fn render_self ( & self , context : & mut RenderContext ) {
139
- let this = self . 0 . read ( ) ;
140
- let ratio = this. ratio ;
141
- let shared = this. shared ;
143
+ let ratio = self . 0 . ratio . get ( ) ;
144
+ let shared = self . 0 . shared . get ( ) ;
142
145
let shape_handle = shared. get_shape ( context, context. library , ratio) ;
143
146
context
144
147
. commands
145
148
. render_shape ( shape_handle, context. transform_stack . transform ( ) ) ;
146
149
}
147
150
148
151
fn self_bounds ( & self ) -> Rectangle < Twips > {
149
- let this = self . 0 . read ( ) ;
150
- let ratio = this. ratio ;
151
- let shared = this. shared ;
152
+ let ratio = self . 0 . ratio . get ( ) ;
153
+ let shared = self . 0 . shared . get ( ) ;
152
154
let frame = shared. get_frame ( ratio) ;
153
155
frame. bounds . clone ( )
154
156
}
@@ -162,7 +164,7 @@ impl<'gc> TDisplayObject<'gc> for MorphShape<'gc> {
162
164
if ( !options. contains ( HitTestOptions :: SKIP_INVISIBLE ) || self . visible ( ) )
163
165
&& self . world_bounds ( ) . contains ( point)
164
166
{
165
- if let Some ( frame) = self . 0 . read ( ) . shared . frames . borrow ( ) . get ( & self . ratio ( ) ) {
167
+ if let Some ( frame) = self . 0 . shared . get ( ) . frames . borrow ( ) . get ( & self . ratio ( ) ) {
166
168
let Some ( local_matrix) = self . global_to_local_matrix ( ) else {
167
169
return false ;
168
170
} ;
@@ -180,7 +182,7 @@ impl<'gc> TDisplayObject<'gc> for MorphShape<'gc> {
180
182
}
181
183
182
184
fn movie ( & self ) -> Arc < SwfMovie > {
183
- self . 0 . read ( ) . shared . movie . clone ( )
185
+ self . 0 . shared . get ( ) . movie . clone ( )
184
186
}
185
187
}
186
188
0 commit comments