OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "cc/tiles/gpu_image_decode_controller.h" | 5 #include "cc/tiles/gpu_image_decode_controller.h" |
6 | 6 |
7 #include "cc/playback/draw_image.h" | 7 #include "cc/playback/draw_image.h" |
8 #include "cc/raster/tile_task_runner.h" | 8 #include "cc/raster/tile_task_runner.h" |
9 #include "cc/test/test_context_provider.h" | 9 #include "cc/test/test_context_provider.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 matrix.setScale(scale.width(), scale.height()); | 24 matrix.setScale(scale.width(), scale.height()); |
25 | 25 |
26 if (!is_decomposable) { | 26 if (!is_decomposable) { |
27 // Perspective is not decomposable, add it. | 27 // Perspective is not decomposable, add it. |
28 matrix[SkMatrix::kMPersp0] = 0.1f; | 28 matrix[SkMatrix::kMPersp0] = 0.1f; |
29 } | 29 } |
30 | 30 |
31 return matrix; | 31 return matrix; |
32 } | 32 } |
33 | 33 |
34 void ScheduleTask(ImageDecodeTask* task) { | |
35 task->WillSchedule(); | |
36 task->ScheduleOnOriginThread(nullptr); | |
37 task->DidSchedule(); | |
38 } | |
39 | |
40 void RunTask(ImageDecodeTask* task) { | 34 void RunTask(ImageDecodeTask* task) { |
41 task->WillRun(); | 35 task->WillRun(); |
42 task->RunOnWorkerThread(); | 36 task->RunOnWorkerThread(); |
43 task->DidRun(); | 37 task->DidRun(); |
44 } | 38 } |
45 | 39 |
46 void CompleteTask(ImageDecodeTask* task) { | 40 void CompleteTask(GpuImageDecodeController* controller, ImageDecodeTask* task) { |
47 task->WillComplete(); | 41 if (task->GetTaskTypeId() == TASK_TYPE_IMAGE_DECODE) |
48 task->CompleteOnOriginThread(nullptr); | 42 controller->ImageDecodeTaskCompleted(task); |
| 43 else if (task->GetTaskTypeId() == TASK_TYPE_IMAGE_UPLOAD) |
| 44 controller->ImageUploadTaskCompleted(task); |
| 45 |
49 task->DidComplete(); | 46 task->DidComplete(); |
50 } | 47 } |
51 | 48 |
52 void ProcessTask(ImageDecodeTask* task) { | 49 void ProcessTask(GpuImageDecodeController* controller, ImageDecodeTask* task) { |
53 ScheduleTask(task); | |
54 RunTask(task); | 50 RunTask(task); |
55 CompleteTask(task); | 51 CompleteTask(controller, task); |
56 } | 52 } |
57 | 53 |
58 TEST(GpuImageDecodeControllerTest, GetTaskForImageSameImage) { | 54 TEST(GpuImageDecodeControllerTest, GetTaskForImageSameImage) { |
59 auto context_provider = TestContextProvider::Create(); | 55 auto context_provider = TestContextProvider::Create(); |
60 context_provider->BindToCurrentThread(); | 56 context_provider->BindToCurrentThread(); |
61 GpuImageDecodeController controller(context_provider.get(), | 57 GpuImageDecodeController controller(context_provider.get(), |
62 ResourceFormat::RGBA_8888); | 58 ResourceFormat::RGBA_8888); |
63 skia::RefPtr<SkImage> image = CreateImage(100, 100); | 59 skia::RefPtr<SkImage> image = CreateImage(100, 100); |
64 bool is_decomposable = true; | 60 bool is_decomposable = true; |
65 SkFilterQuality quality = kHigh_SkFilterQuality; | 61 SkFilterQuality quality = kHigh_SkFilterQuality; |
(...skipping 10 matching lines...) Expand all Loading... |
76 | 72 |
77 DrawImage another_draw_image( | 73 DrawImage another_draw_image( |
78 image.get(), SkIRect::MakeWH(image->width(), image->height()), quality, | 74 image.get(), SkIRect::MakeWH(image->width(), image->height()), quality, |
79 CreateMatrix(SkSize::Make(1.5f, 1.5f), is_decomposable)); | 75 CreateMatrix(SkSize::Make(1.5f, 1.5f), is_decomposable)); |
80 scoped_refptr<ImageDecodeTask> another_task; | 76 scoped_refptr<ImageDecodeTask> another_task; |
81 need_unref = controller.GetTaskForImageAndRef( | 77 need_unref = controller.GetTaskForImageAndRef( |
82 another_draw_image, prepare_tiles_id, &another_task); | 78 another_draw_image, prepare_tiles_id, &another_task); |
83 EXPECT_TRUE(need_unref); | 79 EXPECT_TRUE(need_unref); |
84 EXPECT_TRUE(task.get() == another_task.get()); | 80 EXPECT_TRUE(task.get() == another_task.get()); |
85 | 81 |
86 ProcessTask(task->dependency().get()); | 82 ProcessTask(&controller, task->dependency().get()); |
87 ProcessTask(task.get()); | 83 ProcessTask(&controller, task.get()); |
88 | 84 |
89 controller.UnrefImage(draw_image); | 85 controller.UnrefImage(draw_image); |
90 controller.UnrefImage(draw_image); | 86 controller.UnrefImage(draw_image); |
91 } | 87 } |
92 | 88 |
93 TEST(GpuImageDecodeControllerTest, GetTaskForImageDifferentImage) { | 89 TEST(GpuImageDecodeControllerTest, GetTaskForImageDifferentImage) { |
94 auto context_provider = TestContextProvider::Create(); | 90 auto context_provider = TestContextProvider::Create(); |
95 context_provider->BindToCurrentThread(); | 91 context_provider->BindToCurrentThread(); |
96 GpuImageDecodeController controller(context_provider.get(), | 92 GpuImageDecodeController controller(context_provider.get(), |
97 ResourceFormat::RGBA_8888); | 93 ResourceFormat::RGBA_8888); |
(...skipping 17 matching lines...) Expand all Loading... |
115 second_image.get(), | 111 second_image.get(), |
116 SkIRect::MakeWH(second_image->width(), second_image->height()), quality, | 112 SkIRect::MakeWH(second_image->width(), second_image->height()), quality, |
117 CreateMatrix(SkSize::Make(0.25f, 0.25f), is_decomposable)); | 113 CreateMatrix(SkSize::Make(0.25f, 0.25f), is_decomposable)); |
118 scoped_refptr<ImageDecodeTask> second_task; | 114 scoped_refptr<ImageDecodeTask> second_task; |
119 need_unref = controller.GetTaskForImageAndRef(second_draw_image, | 115 need_unref = controller.GetTaskForImageAndRef(second_draw_image, |
120 prepare_tiles_id, &second_task); | 116 prepare_tiles_id, &second_task); |
121 EXPECT_TRUE(need_unref); | 117 EXPECT_TRUE(need_unref); |
122 EXPECT_TRUE(second_task); | 118 EXPECT_TRUE(second_task); |
123 EXPECT_TRUE(first_task.get() != second_task.get()); | 119 EXPECT_TRUE(first_task.get() != second_task.get()); |
124 | 120 |
125 ProcessTask(first_task->dependency().get()); | 121 ProcessTask(&controller, first_task->dependency().get()); |
126 ProcessTask(first_task.get()); | 122 ProcessTask(&controller, first_task.get()); |
127 ProcessTask(second_task->dependency().get()); | 123 ProcessTask(&controller, second_task->dependency().get()); |
128 ProcessTask(second_task.get()); | 124 ProcessTask(&controller, second_task.get()); |
129 | 125 |
130 controller.UnrefImage(first_draw_image); | 126 controller.UnrefImage(first_draw_image); |
131 controller.UnrefImage(second_draw_image); | 127 controller.UnrefImage(second_draw_image); |
132 } | 128 } |
133 | 129 |
134 TEST(GpuImageDecodeControllerTest, GetTaskForImageAlreadyDecoded) { | 130 TEST(GpuImageDecodeControllerTest, GetTaskForImageAlreadyDecoded) { |
135 auto context_provider = TestContextProvider::Create(); | 131 auto context_provider = TestContextProvider::Create(); |
136 context_provider->BindToCurrentThread(); | 132 context_provider->BindToCurrentThread(); |
137 GpuImageDecodeController controller(context_provider.get(), | 133 GpuImageDecodeController controller(context_provider.get(), |
138 ResourceFormat::RGBA_8888); | 134 ResourceFormat::RGBA_8888); |
139 bool is_decomposable = true; | 135 bool is_decomposable = true; |
140 uint64_t prepare_tiles_id = 1; | 136 uint64_t prepare_tiles_id = 1; |
141 SkFilterQuality quality = kHigh_SkFilterQuality; | 137 SkFilterQuality quality = kHigh_SkFilterQuality; |
142 | 138 |
143 skia::RefPtr<SkImage> image = CreateImage(100, 100); | 139 skia::RefPtr<SkImage> image = CreateImage(100, 100); |
144 DrawImage draw_image( | 140 DrawImage draw_image( |
145 image.get(), SkIRect::MakeWH(image->width(), image->height()), quality, | 141 image.get(), SkIRect::MakeWH(image->width(), image->height()), quality, |
146 CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable)); | 142 CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable)); |
147 scoped_refptr<ImageDecodeTask> task; | 143 scoped_refptr<ImageDecodeTask> task; |
148 bool need_unref = | 144 bool need_unref = |
149 controller.GetTaskForImageAndRef(draw_image, prepare_tiles_id, &task); | 145 controller.GetTaskForImageAndRef(draw_image, prepare_tiles_id, &task); |
150 EXPECT_TRUE(need_unref); | 146 EXPECT_TRUE(need_unref); |
151 EXPECT_TRUE(task); | 147 EXPECT_TRUE(task); |
152 EXPECT_TRUE(task->dependency()); | 148 EXPECT_TRUE(task->dependency()); |
153 | 149 |
154 ProcessTask(task->dependency().get()); | 150 ProcessTask(&controller, task->dependency().get()); |
155 ScheduleTask(task.get()); | |
156 RunTask(task.get()); | 151 RunTask(task.get()); |
157 | 152 |
158 scoped_refptr<ImageDecodeTask> another_task; | 153 scoped_refptr<ImageDecodeTask> another_task; |
159 need_unref = controller.GetTaskForImageAndRef(draw_image, prepare_tiles_id, | 154 need_unref = controller.GetTaskForImageAndRef(draw_image, prepare_tiles_id, |
160 &another_task); | 155 &another_task); |
161 EXPECT_TRUE(need_unref); | 156 EXPECT_TRUE(need_unref); |
162 EXPECT_FALSE(another_task); | 157 EXPECT_FALSE(another_task); |
163 | 158 |
164 CompleteTask(task.get()); | 159 CompleteTask(&controller, task.get()); |
165 | 160 |
166 controller.UnrefImage(draw_image); | 161 controller.UnrefImage(draw_image); |
167 controller.UnrefImage(draw_image); | 162 controller.UnrefImage(draw_image); |
168 } | 163 } |
169 | 164 |
170 TEST(GpuImageDecodeControllerTest, GetTaskForImageCanceledGetsNewTask) { | 165 TEST(GpuImageDecodeControllerTest, GetTaskForImageCanceledGetsNewTask) { |
171 auto context_provider = TestContextProvider::Create(); | 166 auto context_provider = TestContextProvider::Create(); |
172 context_provider->BindToCurrentThread(); | 167 context_provider->BindToCurrentThread(); |
173 GpuImageDecodeController controller(context_provider.get(), | 168 GpuImageDecodeController controller(context_provider.get(), |
174 ResourceFormat::RGBA_8888); | 169 ResourceFormat::RGBA_8888); |
175 bool is_decomposable = true; | 170 bool is_decomposable = true; |
176 uint64_t prepare_tiles_id = 1; | 171 uint64_t prepare_tiles_id = 1; |
177 SkFilterQuality quality = kHigh_SkFilterQuality; | 172 SkFilterQuality quality = kHigh_SkFilterQuality; |
178 | 173 |
179 skia::RefPtr<SkImage> image = CreateImage(100, 100); | 174 skia::RefPtr<SkImage> image = CreateImage(100, 100); |
180 DrawImage draw_image( | 175 DrawImage draw_image( |
181 image.get(), SkIRect::MakeWH(image->width(), image->height()), quality, | 176 image.get(), SkIRect::MakeWH(image->width(), image->height()), quality, |
182 CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable)); | 177 CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable)); |
183 scoped_refptr<ImageDecodeTask> task; | 178 scoped_refptr<ImageDecodeTask> task; |
184 bool need_unref = | 179 bool need_unref = |
185 controller.GetTaskForImageAndRef(draw_image, prepare_tiles_id, &task); | 180 controller.GetTaskForImageAndRef(draw_image, prepare_tiles_id, &task); |
186 EXPECT_TRUE(need_unref); | 181 EXPECT_TRUE(need_unref); |
187 EXPECT_TRUE(task); | 182 EXPECT_TRUE(task); |
188 | 183 |
189 ProcessTask(task->dependency().get()); | 184 ProcessTask(&controller, task->dependency().get()); |
190 ScheduleTask(task.get()); | |
191 | 185 |
192 scoped_refptr<ImageDecodeTask> another_task; | 186 scoped_refptr<ImageDecodeTask> another_task; |
193 need_unref = controller.GetTaskForImageAndRef(draw_image, prepare_tiles_id, | 187 need_unref = controller.GetTaskForImageAndRef(draw_image, prepare_tiles_id, |
194 &another_task); | 188 &another_task); |
195 EXPECT_TRUE(need_unref); | 189 EXPECT_TRUE(need_unref); |
196 EXPECT_TRUE(another_task.get() == task.get()); | 190 EXPECT_TRUE(another_task.get() == task.get()); |
197 | 191 |
198 // Didn't run the task, complete it (it was canceled). | 192 // Didn't run the task, complete it (it was canceled). |
199 CompleteTask(task.get()); | 193 CompleteTask(&controller, task.get()); |
200 | 194 |
201 // Fully cancel everything (so the raster would unref things). | 195 // Fully cancel everything (so the raster would unref things). |
202 controller.UnrefImage(draw_image); | 196 controller.UnrefImage(draw_image); |
203 controller.UnrefImage(draw_image); | 197 controller.UnrefImage(draw_image); |
204 | 198 |
205 // Here a new task is created. | 199 // Here a new task is created. |
206 scoped_refptr<ImageDecodeTask> third_task; | 200 scoped_refptr<ImageDecodeTask> third_task; |
207 need_unref = controller.GetTaskForImageAndRef(draw_image, prepare_tiles_id, | 201 need_unref = controller.GetTaskForImageAndRef(draw_image, prepare_tiles_id, |
208 &third_task); | 202 &third_task); |
209 EXPECT_TRUE(need_unref); | 203 EXPECT_TRUE(need_unref); |
210 EXPECT_TRUE(third_task); | 204 EXPECT_TRUE(third_task); |
211 EXPECT_FALSE(third_task.get() == task.get()); | 205 EXPECT_FALSE(third_task.get() == task.get()); |
212 | 206 |
213 ProcessTask(third_task->dependency().get()); | 207 ProcessTask(&controller, third_task->dependency().get()); |
214 ProcessTask(third_task.get()); | 208 ProcessTask(&controller, third_task.get()); |
215 | 209 |
216 controller.UnrefImage(draw_image); | 210 controller.UnrefImage(draw_image); |
217 } | 211 } |
218 | 212 |
219 TEST(GpuImageDecodeControllerTest, | 213 TEST(GpuImageDecodeControllerTest, |
220 GetTaskForImageCanceledWhileReffedGetsNewTask) { | 214 GetTaskForImageCanceledWhileReffedGetsNewTask) { |
221 auto context_provider = TestContextProvider::Create(); | 215 auto context_provider = TestContextProvider::Create(); |
222 context_provider->BindToCurrentThread(); | 216 context_provider->BindToCurrentThread(); |
223 GpuImageDecodeController controller(context_provider.get(), | 217 GpuImageDecodeController controller(context_provider.get(), |
224 ResourceFormat::RGBA_8888); | 218 ResourceFormat::RGBA_8888); |
225 bool is_decomposable = true; | 219 bool is_decomposable = true; |
226 uint64_t prepare_tiles_id = 1; | 220 uint64_t prepare_tiles_id = 1; |
227 SkFilterQuality quality = kHigh_SkFilterQuality; | 221 SkFilterQuality quality = kHigh_SkFilterQuality; |
228 | 222 |
229 skia::RefPtr<SkImage> image = CreateImage(100, 100); | 223 skia::RefPtr<SkImage> image = CreateImage(100, 100); |
230 DrawImage draw_image( | 224 DrawImage draw_image( |
231 image.get(), SkIRect::MakeWH(image->width(), image->height()), quality, | 225 image.get(), SkIRect::MakeWH(image->width(), image->height()), quality, |
232 CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable)); | 226 CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable)); |
233 scoped_refptr<ImageDecodeTask> task; | 227 scoped_refptr<ImageDecodeTask> task; |
234 bool need_unref = | 228 bool need_unref = |
235 controller.GetTaskForImageAndRef(draw_image, prepare_tiles_id, &task); | 229 controller.GetTaskForImageAndRef(draw_image, prepare_tiles_id, &task); |
236 EXPECT_TRUE(need_unref); | 230 EXPECT_TRUE(need_unref); |
237 EXPECT_TRUE(task); | 231 EXPECT_TRUE(task); |
238 | 232 |
239 ProcessTask(task->dependency().get()); | 233 ProcessTask(&controller, task->dependency().get()); |
240 ScheduleTask(task.get()); | |
241 | 234 |
242 scoped_refptr<ImageDecodeTask> another_task; | 235 scoped_refptr<ImageDecodeTask> another_task; |
243 need_unref = controller.GetTaskForImageAndRef(draw_image, prepare_tiles_id, | 236 need_unref = controller.GetTaskForImageAndRef(draw_image, prepare_tiles_id, |
244 &another_task); | 237 &another_task); |
245 EXPECT_TRUE(need_unref); | 238 EXPECT_TRUE(need_unref); |
246 EXPECT_TRUE(another_task.get() == task.get()); | 239 EXPECT_TRUE(another_task.get() == task.get()); |
247 | 240 |
248 // Didn't run the task, complete it (it was canceled). | 241 // Didn't run the task, complete it (it was canceled). |
249 CompleteTask(task.get()); | 242 CompleteTask(&controller, task.get()); |
250 | 243 |
251 // Note that here, everything is reffed, but a new task is created. This is | 244 // Note that here, everything is reffed, but a new task is created. This is |
252 // possible with repeated schedule/cancel operations. | 245 // possible with repeated schedule/cancel operations. |
253 scoped_refptr<ImageDecodeTask> third_task; | 246 scoped_refptr<ImageDecodeTask> third_task; |
254 need_unref = controller.GetTaskForImageAndRef(draw_image, prepare_tiles_id, | 247 need_unref = controller.GetTaskForImageAndRef(draw_image, prepare_tiles_id, |
255 &third_task); | 248 &third_task); |
256 EXPECT_TRUE(need_unref); | 249 EXPECT_TRUE(need_unref); |
257 EXPECT_TRUE(third_task); | 250 EXPECT_TRUE(third_task); |
258 EXPECT_FALSE(third_task.get() == task.get()); | 251 EXPECT_FALSE(third_task.get() == task.get()); |
259 | 252 |
260 ProcessTask(third_task->dependency().get()); | 253 ProcessTask(&controller, third_task->dependency().get()); |
261 ProcessTask(third_task.get()); | 254 ProcessTask(&controller, third_task.get()); |
262 | 255 |
263 // 3 Unrefs! | 256 // 3 Unrefs! |
264 controller.UnrefImage(draw_image); | 257 controller.UnrefImage(draw_image); |
265 controller.UnrefImage(draw_image); | 258 controller.UnrefImage(draw_image); |
266 controller.UnrefImage(draw_image); | 259 controller.UnrefImage(draw_image); |
267 } | 260 } |
268 | 261 |
269 TEST(GpuImageDecodeControllerTest, GetDecodedImageForDraw) { | 262 TEST(GpuImageDecodeControllerTest, GetDecodedImageForDraw) { |
270 auto context_provider = TestContextProvider::Create(); | 263 auto context_provider = TestContextProvider::Create(); |
271 context_provider->BindToCurrentThread(); | 264 context_provider->BindToCurrentThread(); |
272 GpuImageDecodeController controller(context_provider.get(), | 265 GpuImageDecodeController controller(context_provider.get(), |
273 ResourceFormat::RGBA_8888); | 266 ResourceFormat::RGBA_8888); |
274 bool is_decomposable = true; | 267 bool is_decomposable = true; |
275 uint64_t prepare_tiles_id = 1; | 268 uint64_t prepare_tiles_id = 1; |
276 SkFilterQuality quality = kHigh_SkFilterQuality; | 269 SkFilterQuality quality = kHigh_SkFilterQuality; |
277 | 270 |
278 skia::RefPtr<SkImage> image = CreateImage(100, 100); | 271 skia::RefPtr<SkImage> image = CreateImage(100, 100); |
279 DrawImage draw_image( | 272 DrawImage draw_image( |
280 image.get(), SkIRect::MakeWH(image->width(), image->height()), quality, | 273 image.get(), SkIRect::MakeWH(image->width(), image->height()), quality, |
281 CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable)); | 274 CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable)); |
282 scoped_refptr<ImageDecodeTask> task; | 275 scoped_refptr<ImageDecodeTask> task; |
283 bool need_unref = | 276 bool need_unref = |
284 controller.GetTaskForImageAndRef(draw_image, prepare_tiles_id, &task); | 277 controller.GetTaskForImageAndRef(draw_image, prepare_tiles_id, &task); |
285 EXPECT_TRUE(need_unref); | 278 EXPECT_TRUE(need_unref); |
286 EXPECT_TRUE(task); | 279 EXPECT_TRUE(task); |
287 | 280 |
288 ProcessTask(task->dependency().get()); | 281 ProcessTask(&controller, task->dependency().get()); |
289 ProcessTask(task.get()); | 282 ProcessTask(&controller, task.get()); |
290 | 283 |
291 // Must hold context lock before calling GetDecodedImageForDraw / | 284 // Must hold context lock before calling GetDecodedImageForDraw / |
292 // DrawWithImageFinished. | 285 // DrawWithImageFinished. |
293 ContextProvider::ScopedContextLock context_lock(context_provider.get()); | 286 ContextProvider::ScopedContextLock context_lock(context_provider.get()); |
294 DecodedDrawImage decoded_draw_image = | 287 DecodedDrawImage decoded_draw_image = |
295 controller.GetDecodedImageForDraw(draw_image); | 288 controller.GetDecodedImageForDraw(draw_image); |
296 EXPECT_TRUE(decoded_draw_image.image()); | 289 EXPECT_TRUE(decoded_draw_image.image()); |
297 EXPECT_TRUE(decoded_draw_image.image()->isTextureBacked()); | 290 EXPECT_TRUE(decoded_draw_image.image()->isTextureBacked()); |
298 EXPECT_FALSE(decoded_draw_image.is_at_raster_decode()); | 291 EXPECT_FALSE(decoded_draw_image.is_at_raster_decode()); |
299 | 292 |
(...skipping 13 matching lines...) Expand all Loading... |
313 skia::RefPtr<SkImage> image = CreateImage(1, 24000); | 306 skia::RefPtr<SkImage> image = CreateImage(1, 24000); |
314 DrawImage draw_image( | 307 DrawImage draw_image( |
315 image.get(), SkIRect::MakeWH(image->width(), image->height()), quality, | 308 image.get(), SkIRect::MakeWH(image->width(), image->height()), quality, |
316 CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable)); | 309 CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable)); |
317 scoped_refptr<ImageDecodeTask> task; | 310 scoped_refptr<ImageDecodeTask> task; |
318 bool need_unref = | 311 bool need_unref = |
319 controller.GetTaskForImageAndRef(draw_image, prepare_tiles_id, &task); | 312 controller.GetTaskForImageAndRef(draw_image, prepare_tiles_id, &task); |
320 EXPECT_TRUE(need_unref); | 313 EXPECT_TRUE(need_unref); |
321 EXPECT_TRUE(task); | 314 EXPECT_TRUE(task); |
322 | 315 |
323 ProcessTask(task->dependency().get()); | 316 ProcessTask(&controller, task->dependency().get()); |
324 ProcessTask(task.get()); | 317 ProcessTask(&controller, task.get()); |
325 | 318 |
326 // Must hold context lock before calling GetDecodedImageForDraw / | 319 // Must hold context lock before calling GetDecodedImageForDraw / |
327 // DrawWithImageFinished. | 320 // DrawWithImageFinished. |
328 ContextProvider::ScopedContextLock context_lock(context_provider.get()); | 321 ContextProvider::ScopedContextLock context_lock(context_provider.get()); |
329 DecodedDrawImage decoded_draw_image = | 322 DecodedDrawImage decoded_draw_image = |
330 controller.GetDecodedImageForDraw(draw_image); | 323 controller.GetDecodedImageForDraw(draw_image); |
331 EXPECT_TRUE(decoded_draw_image.image()); | 324 EXPECT_TRUE(decoded_draw_image.image()); |
332 EXPECT_FALSE(decoded_draw_image.image()->isTextureBacked()); | 325 EXPECT_FALSE(decoded_draw_image.image()->isTextureBacked()); |
333 EXPECT_FALSE(decoded_draw_image.is_at_raster_decode()); | 326 EXPECT_FALSE(decoded_draw_image.is_at_raster_decode()); |
334 | 327 |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
527 image.get(), SkIRect::MakeXYWH(0, 0, image->width(), image->height()), | 520 image.get(), SkIRect::MakeXYWH(0, 0, image->width(), image->height()), |
528 quality, CreateMatrix(SkSize::Make(1.f, 1.f), is_decomposable)); | 521 quality, CreateMatrix(SkSize::Make(1.f, 1.f), is_decomposable)); |
529 | 522 |
530 scoped_refptr<ImageDecodeTask> task; | 523 scoped_refptr<ImageDecodeTask> task; |
531 bool need_unref = | 524 bool need_unref = |
532 controller.GetTaskForImageAndRef(draw_image, prepare_tiles_id, &task); | 525 controller.GetTaskForImageAndRef(draw_image, prepare_tiles_id, &task); |
533 EXPECT_NE(0u, controller.GetBytesUsedForTesting()); | 526 EXPECT_NE(0u, controller.GetBytesUsedForTesting()); |
534 EXPECT_TRUE(task); | 527 EXPECT_TRUE(task); |
535 EXPECT_TRUE(need_unref); | 528 EXPECT_TRUE(need_unref); |
536 | 529 |
537 ScheduleTask(task->dependency().get()); | 530 CompleteTask(&controller, task->dependency().get()); |
538 CompleteTask(task->dependency().get()); | 531 CompleteTask(&controller, task.get()); |
539 ScheduleTask(task.get()); | |
540 CompleteTask(task.get()); | |
541 | 532 |
542 controller.UnrefImage(draw_image); | 533 controller.UnrefImage(draw_image); |
543 EXPECT_EQ(0u, controller.GetBytesUsedForTesting()); | 534 EXPECT_EQ(0u, controller.GetBytesUsedForTesting()); |
544 } | 535 } |
545 | 536 |
546 TEST(GpuImageDecodeControllerTest, ShouldAggressivelyFreeResources) { | 537 TEST(GpuImageDecodeControllerTest, ShouldAggressivelyFreeResources) { |
547 auto context_provider = TestContextProvider::Create(); | 538 auto context_provider = TestContextProvider::Create(); |
548 context_provider->BindToCurrentThread(); | 539 context_provider->BindToCurrentThread(); |
549 GpuImageDecodeController controller(context_provider.get(), | 540 GpuImageDecodeController controller(context_provider.get(), |
550 ResourceFormat::RGBA_8888); | 541 ResourceFormat::RGBA_8888); |
551 bool is_decomposable = true; | 542 bool is_decomposable = true; |
552 uint64_t prepare_tiles_id = 1; | 543 uint64_t prepare_tiles_id = 1; |
553 SkFilterQuality quality = kHigh_SkFilterQuality; | 544 SkFilterQuality quality = kHigh_SkFilterQuality; |
554 | 545 |
555 skia::RefPtr<SkImage> image = CreateImage(100, 100); | 546 skia::RefPtr<SkImage> image = CreateImage(100, 100); |
556 DrawImage draw_image( | 547 DrawImage draw_image( |
557 image.get(), SkIRect::MakeWH(image->width(), image->height()), quality, | 548 image.get(), SkIRect::MakeWH(image->width(), image->height()), quality, |
558 CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable)); | 549 CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable)); |
559 scoped_refptr<ImageDecodeTask> task; | 550 scoped_refptr<ImageDecodeTask> task; |
560 { | 551 { |
561 bool need_unref = | 552 bool need_unref = |
562 controller.GetTaskForImageAndRef(draw_image, prepare_tiles_id, &task); | 553 controller.GetTaskForImageAndRef(draw_image, prepare_tiles_id, &task); |
563 EXPECT_TRUE(need_unref); | 554 EXPECT_TRUE(need_unref); |
564 EXPECT_TRUE(task); | 555 EXPECT_TRUE(task); |
565 } | 556 } |
566 | 557 |
567 ProcessTask(task->dependency().get()); | 558 ProcessTask(&controller, task->dependency().get()); |
568 ProcessTask(task.get()); | 559 ProcessTask(&controller, task.get()); |
569 | 560 |
570 controller.UnrefImage(draw_image); | 561 controller.UnrefImage(draw_image); |
571 | 562 |
572 // We should now have data image in our cache. | 563 // We should now have data image in our cache. |
573 DCHECK_GT(controller.GetBytesUsedForTesting(), 0u); | 564 DCHECK_GT(controller.GetBytesUsedForTesting(), 0u); |
574 | 565 |
575 // Tell our controller to aggressively free resources. | 566 // Tell our controller to aggressively free resources. |
576 controller.SetShouldAggressivelyFreeResources(true); | 567 controller.SetShouldAggressivelyFreeResources(true); |
577 DCHECK_EQ(0u, controller.GetBytesUsedForTesting()); | 568 DCHECK_EQ(0u, controller.GetBytesUsedForTesting()); |
578 | 569 |
579 // Attempting to upload a new image should result in at-raster decode. | 570 // Attempting to upload a new image should result in at-raster decode. |
580 { | 571 { |
581 bool need_unref = | 572 bool need_unref = |
582 controller.GetTaskForImageAndRef(draw_image, prepare_tiles_id, &task); | 573 controller.GetTaskForImageAndRef(draw_image, prepare_tiles_id, &task); |
583 EXPECT_FALSE(need_unref); | 574 EXPECT_FALSE(need_unref); |
584 EXPECT_FALSE(task); | 575 EXPECT_FALSE(task); |
585 } | 576 } |
586 | 577 |
587 // We now tell the controller to not aggressively free resources. Uploads | 578 // We now tell the controller to not aggressively free resources. Uploads |
588 // should work again. | 579 // should work again. |
589 controller.SetShouldAggressivelyFreeResources(false); | 580 controller.SetShouldAggressivelyFreeResources(false); |
590 { | 581 { |
591 bool need_unref = | 582 bool need_unref = |
592 controller.GetTaskForImageAndRef(draw_image, prepare_tiles_id, &task); | 583 controller.GetTaskForImageAndRef(draw_image, prepare_tiles_id, &task); |
593 EXPECT_TRUE(need_unref); | 584 EXPECT_TRUE(need_unref); |
594 EXPECT_TRUE(task); | 585 EXPECT_TRUE(task); |
595 } | 586 } |
596 | 587 |
597 ProcessTask(task->dependency().get()); | 588 ProcessTask(&controller, task->dependency().get()); |
598 ProcessTask(task.get()); | 589 ProcessTask(&controller, task.get()); |
599 | 590 |
600 // The image should be in our cache after un-ref. | 591 // The image should be in our cache after un-ref. |
601 controller.UnrefImage(draw_image); | 592 controller.UnrefImage(draw_image); |
602 DCHECK_GT(controller.GetBytesUsedForTesting(), 0u); | 593 DCHECK_GT(controller.GetBytesUsedForTesting(), 0u); |
603 } | 594 } |
604 | 595 |
605 } // namespace | 596 } // namespace |
606 } // namespace cc | 597 } // namespace cc |
OLD | NEW |