8
8
import androidx .annotation .GuardedBy ;
9
9
import androidx .annotation .NonNull ;
10
10
import androidx .annotation .Nullable ;
11
- import androidx .core .util .Pools ;
12
11
import com .bumptech .glide .GlideContext ;
13
12
import com .bumptech .glide .Priority ;
14
13
import com .bumptech .glide .load .DataSource ;
21
20
import com .bumptech .glide .request .transition .Transition ;
22
21
import com .bumptech .glide .request .transition .TransitionFactory ;
23
22
import com .bumptech .glide .util .LogTime ;
24
- import com .bumptech .glide .util .Preconditions ;
25
- import com .bumptech .glide .util .Synthetic ;
26
23
import com .bumptech .glide .util .Util ;
27
- import com .bumptech .glide .util .pool .FactoryPools ;
28
24
import com .bumptech .glide .util .pool .StateVerifier ;
29
25
import java .util .List ;
30
26
import java .util .concurrent .Executor ;
35
31
*
36
32
* @param <R> The type of the resource that will be transcoded from the loaded resource.
37
33
*/
38
- @ SuppressWarnings ("SynchronizeOnNonFinalField" )
39
- public final class SingleRequest <R >
40
- implements Request , SizeReadyCallback , ResourceCallback , FactoryPools .Poolable {
34
+ public final class SingleRequest <R > implements Request , SizeReadyCallback , ResourceCallback {
41
35
/** Tag for logging internal events, not generally suitable for public use. */
42
36
private static final String TAG = "Request" ;
43
37
/** Tag for logging externally useful events (request completion, timing etc). */
44
38
private static final String GLIDE_TAG = "Glide" ;
45
39
46
- private static final Pools .Pool <SingleRequest <?>> POOL =
47
- FactoryPools .threadSafe (
48
- 150 ,
49
- new FactoryPools .Factory <SingleRequest <?>>() {
50
- @ Override
51
- public SingleRequest <?> create () {
52
- return new SingleRequest <Object >();
53
- }
54
- });
55
-
56
40
private static final boolean IS_VERBOSE_LOGGABLE = Log .isLoggable (TAG , Log .VERBOSE );
57
41
58
42
private enum Status {
@@ -76,52 +60,35 @@ private enum Status {
76
60
private final StateVerifier stateVerifier = StateVerifier .newInstance ();
77
61
78
62
/* Variables mutated only when a request is initialized or returned to the object pool. */
79
- private volatile Object requestLock ;
63
+ private final Object requestLock ;
80
64
81
- @ GuardedBy ("requestLock" )
82
- @ Nullable
83
- private RequestListener <R > targetListener ;
65
+ @ Nullable private final RequestListener <R > targetListener ;
84
66
85
- @ GuardedBy ("requestLock" )
86
- private RequestCoordinator requestCoordinator ;
67
+ private final RequestCoordinator requestCoordinator ;
87
68
88
- @ GuardedBy ("requestLock" )
89
- private Context context ;
69
+ private final Context context ;
90
70
91
- @ GuardedBy ("requestLock" )
92
- private GlideContext glideContext ;
71
+ private final GlideContext glideContext ;
93
72
94
- @ GuardedBy ("requestLock" )
95
- @ Nullable
96
- private Object model ;
73
+ @ Nullable private final Object model ;
97
74
98
- @ GuardedBy ("requestLock" )
99
- private Class <R > transcodeClass ;
75
+ private final Class <R > transcodeClass ;
100
76
101
- @ GuardedBy ("requestLock" )
102
- private BaseRequestOptions <?> requestOptions ;
77
+ private final BaseRequestOptions <?> requestOptions ;
103
78
104
- @ GuardedBy ("requestLock" )
105
- private int overrideWidth ;
79
+ private final int overrideWidth ;
106
80
107
- @ GuardedBy ("requestLock" )
108
- private int overrideHeight ;
81
+ private final int overrideHeight ;
109
82
110
- @ GuardedBy ("requestLock" )
111
- private Priority priority ;
83
+ private final Priority priority ;
112
84
113
- @ GuardedBy ("requestLock" )
114
- private Target <R > target ;
85
+ private final Target <R > target ;
115
86
116
- @ GuardedBy ("requestLock" )
117
- @ Nullable
118
- private List <RequestListener <R >> requestListeners ;
87
+ @ Nullable private final List <RequestListener <R >> requestListeners ;
119
88
120
- @ GuardedBy ("requestLock" )
121
- private TransitionFactory <? super R > animationFactory ;
89
+ private final TransitionFactory <? super R > animationFactory ;
122
90
123
- @ GuardedBy ("requestLock" )
124
- private Executor callbackExecutor ;
91
+ private final Executor callbackExecutor ;
125
92
126
93
@ GuardedBy ("requestLock" )
127
94
private Resource <R > resource ;
@@ -141,12 +108,15 @@ private enum Status {
141
108
private Status status ;
142
109
143
110
@ GuardedBy ("requestLock" )
111
+ @ Nullable
144
112
private Drawable errorDrawable ;
145
113
146
114
@ GuardedBy ("requestLock" )
115
+ @ Nullable
147
116
private Drawable placeholderDrawable ;
148
117
149
118
@ GuardedBy ("requestLock" )
119
+ @ Nullable
150
120
private Drawable fallbackDrawable ;
151
121
152
122
@ GuardedBy ("requestLock" )
@@ -163,7 +133,7 @@ private enum Status {
163
133
public static <R > SingleRequest <R > obtain (
164
134
Context context ,
165
135
GlideContext glideContext ,
166
- @ Nullable Object requestLock ,
136
+ Object requestLock ,
167
137
Object model ,
168
138
Class <R > transcodeClass ,
169
139
BaseRequestOptions <?> requestOptions ,
@@ -177,15 +147,7 @@ public static <R> SingleRequest<R> obtain(
177
147
Engine engine ,
178
148
TransitionFactory <? super R > animationFactory ,
179
149
Executor callbackExecutor ) {
180
- @ SuppressWarnings ("unchecked" )
181
- SingleRequest <R > request = (SingleRequest <R >) POOL .acquire ();
182
- if (request == null ) {
183
- request = new SingleRequest <>();
184
- }
185
- if (requestLock == null ) {
186
- requestLock = request ;
187
- }
188
- request .init (
150
+ return new SingleRequest <>(
189
151
context ,
190
152
glideContext ,
191
153
requestLock ,
@@ -202,93 +164,50 @@ public static <R> SingleRequest<R> obtain(
202
164
engine ,
203
165
animationFactory ,
204
166
callbackExecutor );
205
- return request ;
206
- }
207
-
208
- @ SuppressWarnings ("WeakerAccess" )
209
- @ Synthetic
210
- SingleRequest () {
211
- // just create, instances are reused with recycle/init
212
167
}
213
168
214
169
// We are in fact locking on the same lock that will be used for all subsequent method calls.
215
170
@ SuppressWarnings ("GuardedBy" )
216
- private void init (
171
+ private SingleRequest (
217
172
Context context ,
218
173
GlideContext glideContext ,
219
174
@ NonNull Object requestLock ,
220
- Object model ,
175
+ @ Nullable Object model ,
221
176
Class <R > transcodeClass ,
222
177
BaseRequestOptions <?> requestOptions ,
223
178
int overrideWidth ,
224
179
int overrideHeight ,
225
180
Priority priority ,
226
181
Target <R > target ,
227
- RequestListener <R > targetListener ,
182
+ @ Nullable RequestListener <R > targetListener ,
228
183
@ Nullable List <RequestListener <R >> requestListeners ,
229
184
RequestCoordinator requestCoordinator ,
230
185
Engine engine ,
231
186
TransitionFactory <? super R > animationFactory ,
232
187
Executor callbackExecutor ) {
233
- this .requestLock = Preconditions .checkNotNull (requestLock );
234
- synchronized (this .requestLock ) {
235
- this .context = context ;
236
- this .glideContext = glideContext ;
237
- this .model = model ;
238
- this .transcodeClass = transcodeClass ;
239
- this .requestOptions = requestOptions ;
240
- this .overrideWidth = overrideWidth ;
241
- this .overrideHeight = overrideHeight ;
242
- this .priority = priority ;
243
- this .target = target ;
244
- this .targetListener = targetListener ;
245
- this .requestListeners = requestListeners ;
246
- this .requestCoordinator = requestCoordinator ;
247
- this .engine = engine ;
248
- this .animationFactory = animationFactory ;
249
- this .callbackExecutor = callbackExecutor ;
250
- status = Status .PENDING ;
251
-
252
- if (requestOrigin == null && glideContext .isLoggingRequestOriginsEnabled ()) {
253
- requestOrigin = new RuntimeException ("Glide request origin trace" );
254
- }
188
+ this .requestLock = requestLock ;
189
+ this .context = context ;
190
+ this .glideContext = glideContext ;
191
+ this .model = model ;
192
+ this .transcodeClass = transcodeClass ;
193
+ this .requestOptions = requestOptions ;
194
+ this .overrideWidth = overrideWidth ;
195
+ this .overrideHeight = overrideHeight ;
196
+ this .priority = priority ;
197
+ this .target = target ;
198
+ this .targetListener = targetListener ;
199
+ this .requestListeners = requestListeners ;
200
+ this .requestCoordinator = requestCoordinator ;
201
+ this .engine = engine ;
202
+ this .animationFactory = animationFactory ;
203
+ this .callbackExecutor = callbackExecutor ;
204
+ status = Status .PENDING ;
205
+
206
+ if (requestOrigin == null && glideContext .isLoggingRequestOriginsEnabled ()) {
207
+ requestOrigin = new RuntimeException ("Glide request origin trace" );
255
208
}
256
209
}
257
210
258
- @ NonNull
259
- @ Override
260
- public StateVerifier getVerifier () {
261
- return stateVerifier ;
262
- }
263
-
264
- @ Override
265
- public void recycle () {
266
- synchronized (requestLock ) {
267
- assertNotCallingCallbacks ();
268
- context = null ;
269
- glideContext = null ;
270
- model = null ;
271
- transcodeClass = null ;
272
- requestOptions = null ;
273
- overrideWidth = -1 ;
274
- overrideHeight = -1 ;
275
- target = null ;
276
- requestListeners = null ;
277
- targetListener = null ;
278
- requestCoordinator = null ;
279
- animationFactory = null ;
280
- loadStatus = null ;
281
- errorDrawable = null ;
282
- placeholderDrawable = null ;
283
- fallbackDrawable = null ;
284
- width = -1 ;
285
- height = -1 ;
286
- requestOrigin = null ;
287
- POOL .release (this );
288
- }
289
- requestLock = null ;
290
- }
291
-
292
211
@ Override
293
212
public void begin () {
294
213
synchronized (requestLock ) {
@@ -438,6 +357,11 @@ public boolean isCleared() {
438
357
}
439
358
}
440
359
360
+ @ Override
361
+ public void recycle () {
362
+ // TODO: remove this method, it's a no-op.
363
+ }
364
+
441
365
@ GuardedBy ("requestLock" )
442
366
private Drawable getErrorDrawable () {
443
367
if (errorDrawable == null ) {
0 commit comments