@@ -5,57 +5,58 @@ use crate::avm1::object::NativeObject;
5
5
use crate :: avm1:: property_decl:: { define_properties_on, Declaration } ;
6
6
use crate :: avm1:: { Activation , Error , Object , ScriptObject , TObject , Value } ;
7
7
use crate :: string:: StringContext ;
8
- use gc_arena:: { Collect , GcCell , Mutation } ;
9
- use std:: ops :: Deref ;
8
+ use gc_arena:: { Collect , Gc , Mutation } ;
9
+ use std:: cell :: Cell ;
10
10
use swf:: { Color , Fixed16 , Fixed8 , GlowFilterFlags } ;
11
11
12
12
#[ derive( Clone , Debug , Collect ) ]
13
13
#[ collect( require_static) ]
14
14
struct GlowFilterData {
15
- color : Color ,
16
- quality : i32 ,
17
- inner : bool ,
18
- knockout : bool ,
19
- blur_x : f64 ,
20
- blur_y : f64 ,
15
+ color : Cell < Color > ,
16
+ quality : Cell < i32 > ,
17
+ inner : Cell < bool > ,
18
+ knockout : Cell < bool > ,
19
+ blur_x : Cell < f64 > ,
20
+ blur_y : Cell < f64 > ,
21
21
// TODO: Introduce unsigned `Fixed8`?
22
- strength : u16 ,
22
+ strength : Cell < u16 > ,
23
23
}
24
24
25
25
impl Default for GlowFilterData {
26
26
fn default ( ) -> Self {
27
27
Self {
28
- color : Color :: RED ,
29
- quality : 1 ,
30
- inner : false ,
31
- knockout : false ,
32
- blur_x : 6.0 ,
33
- blur_y : 6.0 ,
34
- strength : 2 << 8 ,
28
+ color : Cell :: new ( Color :: RED ) ,
29
+ quality : Cell :: new ( 1 ) ,
30
+ inner : Cell :: new ( false ) ,
31
+ knockout : Cell :: new ( false ) ,
32
+ blur_x : Cell :: new ( 6.0 ) ,
33
+ blur_y : Cell :: new ( 6.0 ) ,
34
+ strength : Cell :: new ( 2 << 8 ) ,
35
35
}
36
36
}
37
37
}
38
38
39
39
impl GlowFilterData {
40
40
pub fn strength ( & self ) -> f64 {
41
- f64:: from ( self . strength ) / 256.0
41
+ f64:: from ( self . strength . get ( ) ) / 256.0
42
42
}
43
43
44
- pub fn set_strength ( & mut self , strength : f64 ) {
45
- self . strength = ( ( strength * 256.0 ) as u16 ) . clamp ( 0 , 0xFF00 )
44
+ pub fn set_strength ( & self , strength : f64 ) {
45
+ let strength = ( ( strength * 256.0 ) as u16 ) . clamp ( 0 , 0xFF00 ) ;
46
+ self . strength . set ( strength) ;
46
47
}
47
48
}
48
49
49
50
impl From < & GlowFilterData > for swf:: GlowFilter {
50
51
fn from ( filter : & GlowFilterData ) -> swf:: GlowFilter {
51
52
let mut flags = GlowFilterFlags :: COMPOSITE_SOURCE ;
52
- flags |= GlowFilterFlags :: from_passes ( filter. quality as u8 ) ;
53
- flags. set ( GlowFilterFlags :: KNOCKOUT , filter. knockout ) ;
54
- flags. set ( GlowFilterFlags :: INNER_GLOW , filter. inner ) ;
53
+ flags |= GlowFilterFlags :: from_passes ( filter. quality . get ( ) as u8 ) ;
54
+ flags. set ( GlowFilterFlags :: KNOCKOUT , filter. knockout . get ( ) ) ;
55
+ flags. set ( GlowFilterFlags :: INNER_GLOW , filter. inner . get ( ) ) ;
55
56
swf:: GlowFilter {
56
- color : filter. color ,
57
- blur_x : Fixed16 :: from_f64 ( filter. blur_x ) ,
58
- blur_y : Fixed16 :: from_f64 ( filter. blur_y ) ,
57
+ color : filter. color . get ( ) ,
58
+ blur_x : Fixed16 :: from_f64 ( filter. blur_x . get ( ) ) ,
59
+ blur_y : Fixed16 :: from_f64 ( filter. blur_y . get ( ) ) ,
59
60
strength : Fixed8 :: from_f64 ( filter. strength ( ) ) ,
60
61
flags,
61
62
}
@@ -67,25 +68,25 @@ impl From<swf::GlowFilter> for GlowFilterData {
67
68
let inner = filter. is_inner ( ) ;
68
69
let knockout = filter. is_knockout ( ) ;
69
70
Self {
70
- color : filter. color ,
71
- quality : filter. num_passes ( ) . into ( ) ,
72
- strength : ( filter. strength . to_f64 ( ) * 256.0 ) as u16 ,
73
- knockout,
74
- blur_x : filter. blur_x . into ( ) ,
75
- blur_y : filter. blur_y . into ( ) ,
76
- inner,
71
+ color : Cell :: new ( filter. color ) ,
72
+ quality : Cell :: new ( filter. num_passes ( ) . into ( ) ) ,
73
+ strength : Cell :: new ( ( filter. strength . to_f64 ( ) * 256.0 ) as u16 ) ,
74
+ knockout : Cell :: new ( knockout ) ,
75
+ blur_x : Cell :: new ( filter. blur_x . into ( ) ) ,
76
+ blur_y : Cell :: new ( filter. blur_y . into ( ) ) ,
77
+ inner : Cell :: new ( inner ) ,
77
78
}
78
79
}
79
80
}
80
81
81
82
#[ derive( Copy , Clone , Debug , Collect ) ]
82
83
#[ collect( no_drop) ]
83
84
#[ repr( transparent) ]
84
- pub struct GlowFilter < ' gc > ( GcCell < ' gc , GlowFilterData > ) ;
85
+ pub struct GlowFilter < ' gc > ( Gc < ' gc , GlowFilterData > ) ;
85
86
86
87
impl < ' gc > GlowFilter < ' gc > {
87
88
fn new ( activation : & mut Activation < ' _ , ' gc > , args : & [ Value < ' gc > ] ) -> Result < Self , Error < ' gc > > {
88
- let glow_filter = Self ( GcCell :: new ( activation. gc ( ) , Default :: default ( ) ) ) ;
89
+ let glow_filter = Self ( Gc :: new ( activation. gc ( ) , Default :: default ( ) ) ) ;
89
90
glow_filter. set_color ( activation, args. get ( 0 ) ) ?;
90
91
glow_filter. set_alpha ( activation, args. get ( 1 ) ) ?;
91
92
glow_filter. set_blur_x ( activation, args. get ( 2 ) ) ?;
@@ -98,145 +99,145 @@ impl<'gc> GlowFilter<'gc> {
98
99
}
99
100
100
101
pub fn from_filter ( gc_context : & Mutation < ' gc > , filter : swf:: GlowFilter ) -> Self {
101
- Self ( GcCell :: new ( gc_context, filter. into ( ) ) )
102
+ Self ( Gc :: new ( gc_context, filter. into ( ) ) )
102
103
}
103
104
104
- pub ( crate ) fn duplicate ( & self , gc_context : & Mutation < ' gc > ) -> Self {
105
- Self ( GcCell :: new ( gc_context, self . 0 . read ( ) . clone ( ) ) )
105
+ pub ( crate ) fn duplicate ( self , gc_context : & Mutation < ' gc > ) -> Self {
106
+ Self ( Gc :: new ( gc_context, self . 0 . as_ref ( ) . clone ( ) ) )
106
107
}
107
108
108
- fn color ( & self ) -> i32 {
109
- self . 0 . read ( ) . color . to_rgb ( ) as i32
109
+ fn color ( self ) -> i32 {
110
+ self . 0 . color . get ( ) . to_rgb ( ) as i32
110
111
}
111
112
112
113
fn set_color (
113
- & self ,
114
+ self ,
114
115
activation : & mut Activation < ' _ , ' gc > ,
115
116
value : Option < & Value < ' gc > > ,
116
117
) -> Result < ( ) , Error < ' gc > > {
117
118
if let Some ( value) = value {
118
119
let value = value. coerce_to_u32 ( activation) ?;
119
- let mut write = self . 0 . write ( activation . gc ( ) ) ;
120
- write . color = Color :: from_rgb ( value, write . color . a ) ;
120
+ let color = self . 0 . color . get ( ) ;
121
+ self . 0 . color . set ( Color :: from_rgb ( value, color. a ) ) ;
121
122
}
122
123
Ok ( ( ) )
123
124
}
124
125
125
- fn alpha ( & self ) -> f64 {
126
- f64:: from ( self . 0 . read ( ) . color . a ) / 255.0
126
+ fn alpha ( self ) -> f64 {
127
+ f64:: from ( self . 0 . color . get ( ) . a ) / 255.0
127
128
}
128
129
129
130
fn set_alpha (
130
- & self ,
131
+ self ,
131
132
activation : & mut Activation < ' _ , ' gc > ,
132
133
value : Option < & Value < ' gc > > ,
133
134
) -> Result < ( ) , Error < ' gc > > {
134
135
if let Some ( value) = value {
135
136
let alpha = ( value. coerce_to_f64 ( activation) ? * 255.0 ) as u8 ;
136
- self . 0 . write ( activation. gc ( ) ) . color . a = alpha;
137
+ let mut color = self . 0 . color . get ( ) ;
138
+ color. a = alpha;
139
+ self . 0 . color . set ( color) ;
137
140
}
138
141
Ok ( ( ) )
139
142
}
140
143
141
- fn quality ( & self ) -> i32 {
142
- self . 0 . read ( ) . quality
144
+ fn quality ( self ) -> i32 {
145
+ self . 0 . quality . get ( )
143
146
}
144
147
145
148
fn set_quality (
146
- & self ,
149
+ self ,
147
150
activation : & mut Activation < ' _ , ' gc > ,
148
151
value : Option < & Value < ' gc > > ,
149
152
) -> Result < ( ) , Error < ' gc > > {
150
153
if let Some ( value) = value {
151
154
let quality = value. coerce_to_i32 ( activation) ?. clamp ( 0 , 15 ) ;
152
- self . 0 . write ( activation . gc ( ) ) . quality = quality ;
155
+ self . 0 . quality . set ( quality) ;
153
156
}
154
157
Ok ( ( ) )
155
158
}
156
159
157
- fn inner ( & self ) -> bool {
158
- self . 0 . read ( ) . inner
160
+ fn inner ( self ) -> bool {
161
+ self . 0 . inner . get ( )
159
162
}
160
163
161
164
fn set_inner (
162
- & self ,
165
+ self ,
163
166
activation : & mut Activation < ' _ , ' gc > ,
164
167
value : Option < & Value < ' gc > > ,
165
168
) -> Result < ( ) , Error < ' gc > > {
166
169
if let Some ( value) = value {
167
170
let inner = value. as_bool ( activation. swf_version ( ) ) ;
168
- self . 0 . write ( activation . gc ( ) ) . inner = inner ;
171
+ self . 0 . inner . set ( inner) ;
169
172
}
170
173
Ok ( ( ) )
171
174
}
172
175
173
- fn knockout ( & self ) -> bool {
174
- self . 0 . read ( ) . knockout
176
+ fn knockout ( self ) -> bool {
177
+ self . 0 . knockout . get ( )
175
178
}
176
179
177
180
fn set_knockout (
178
- & self ,
181
+ self ,
179
182
activation : & mut Activation < ' _ , ' gc > ,
180
183
value : Option < & Value < ' gc > > ,
181
184
) -> Result < ( ) , Error < ' gc > > {
182
185
if let Some ( value) = value {
183
186
let knockout = value. as_bool ( activation. swf_version ( ) ) ;
184
- self . 0 . write ( activation . gc ( ) ) . knockout = knockout ;
187
+ self . 0 . knockout . set ( knockout) ;
185
188
}
186
189
Ok ( ( ) )
187
190
}
188
191
189
- fn blur_x ( & self ) -> f64 {
190
- self . 0 . read ( ) . blur_x
192
+ fn blur_x ( self ) -> f64 {
193
+ self . 0 . blur_x . get ( )
191
194
}
192
195
193
196
fn set_blur_x (
194
- & self ,
197
+ self ,
195
198
activation : & mut Activation < ' _ , ' gc > ,
196
199
value : Option < & Value < ' gc > > ,
197
200
) -> Result < ( ) , Error < ' gc > > {
198
201
if let Some ( value) = value {
199
202
let blur_x = value. coerce_to_f64 ( activation) ?. clamp ( 0.0 , 255.0 ) ;
200
- self . 0 . write ( activation . gc ( ) ) . blur_x = blur_x ;
203
+ self . 0 . blur_x . set ( blur_x) ;
201
204
}
202
205
Ok ( ( ) )
203
206
}
204
207
205
- fn blur_y ( & self ) -> f64 {
206
- self . 0 . read ( ) . blur_y
208
+ fn blur_y ( self ) -> f64 {
209
+ self . 0 . blur_y . get ( )
207
210
}
208
211
209
212
fn set_blur_y (
210
- & self ,
213
+ self ,
211
214
activation : & mut Activation < ' _ , ' gc > ,
212
215
value : Option < & Value < ' gc > > ,
213
216
) -> Result < ( ) , Error < ' gc > > {
214
217
if let Some ( value) = value {
215
218
let blur_y = value. coerce_to_f64 ( activation) ?. clamp ( 0.0 , 255.0 ) ;
216
- self . 0 . write ( activation . gc ( ) ) . blur_y = blur_y ;
219
+ self . 0 . blur_y . set ( blur_y) ;
217
220
}
218
221
Ok ( ( ) )
219
222
}
220
223
221
- fn strength ( & self ) -> f64 {
222
- self . 0 . read ( ) . strength ( )
224
+ fn strength ( self ) -> f64 {
225
+ self . 0 . strength ( )
223
226
}
224
227
225
228
fn set_strength (
226
- & self ,
229
+ self ,
227
230
activation : & mut Activation < ' _ , ' gc > ,
228
231
value : Option < & Value < ' gc > > ,
229
232
) -> Result < ( ) , Error < ' gc > > {
230
233
if let Some ( value) = value {
231
- self . 0
232
- . write ( activation. gc ( ) )
233
- . set_strength ( value. coerce_to_f64 ( activation) ?) ;
234
+ self . 0 . set_strength ( value. coerce_to_f64 ( activation) ?) ;
234
235
}
235
236
Ok ( ( ) )
236
237
}
237
238
238
- pub fn filter ( & self ) -> swf:: GlowFilter {
239
- self . 0 . read ( ) . deref ( ) . into ( )
239
+ pub fn filter ( self ) -> swf:: GlowFilter {
240
+ self . 0 . as_ref ( ) . into ( )
240
241
}
241
242
}
242
243
0 commit comments