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.h" | 8 #include "cc/test/simple_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" |
11 #include "third_party/skia/include/core/SkRefCnt.h" | 11 #include "third_party/skia/include/core/SkRefCnt.h" |
12 | 12 |
13 namespace cc { | 13 namespace cc { |
14 namespace { | 14 namespace { |
15 | 15 |
16 sk_sp<SkImage> CreateImage(int width, int height) { | 16 sk_sp<SkImage> CreateImage(int width, int height) { |
17 SkBitmap bitmap; | 17 SkBitmap bitmap; |
18 bitmap.allocPixels(SkImageInfo::MakeN32Premul(width, height)); | 18 bitmap.allocPixels(SkImageInfo::MakeN32Premul(width, height)); |
19 return SkImage::MakeFromBitmap(bitmap); | 19 return SkImage::MakeFromBitmap(bitmap); |
20 } | 20 } |
21 | 21 |
22 SkMatrix CreateMatrix(const SkSize& scale, bool is_decomposable) { | 22 SkMatrix CreateMatrix(const SkSize& scale, bool is_decomposable) { |
23 SkMatrix matrix; | 23 SkMatrix matrix; |
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(TileTask* task) { | |
35 task->state().DidSchedule(); | |
36 } | |
37 | |
38 // Before running the task it must be scheduled. Call ScheduleTask() before | |
39 // calling this function. | |
40 void RunTask(TileTask* task) { | |
41 task->state().DidStart(); | |
42 task->RunOnWorkerThread(); | |
43 task->state().DidFinish(); | |
44 } | |
45 | |
46 void CompleteTask(TileTask* task) { | |
47 DCHECK(task->state().IsFinished() || task->state().IsCanceled()); | |
48 task->OnTaskCompleted(); | |
49 } | |
50 | |
51 void CancelTask(TileTask* task) { | |
52 task->state().DidCancel(); | |
53 } | |
54 | |
55 void ProcessTask(TileTask* task) { | |
56 ScheduleTask(task); | |
57 RunTask(task); | |
58 CompleteTask(task); | |
59 } | |
60 | |
61 TEST(GpuImageDecodeControllerTest, GetTaskForImageSameImage) { | 34 TEST(GpuImageDecodeControllerTest, GetTaskForImageSameImage) { |
62 auto context_provider = TestContextProvider::Create(); | 35 auto context_provider = TestContextProvider::Create(); |
63 context_provider->BindToCurrentThread(); | 36 context_provider->BindToCurrentThread(); |
64 GpuImageDecodeController controller(context_provider.get(), | 37 GpuImageDecodeController controller(context_provider.get(), |
65 ResourceFormat::RGBA_8888); | 38 ResourceFormat::RGBA_8888); |
66 sk_sp<SkImage> image = CreateImage(100, 100); | 39 sk_sp<SkImage> image = CreateImage(100, 100); |
67 bool is_decomposable = true; | 40 bool is_decomposable = true; |
68 SkFilterQuality quality = kHigh_SkFilterQuality; | 41 SkFilterQuality quality = kHigh_SkFilterQuality; |
69 | 42 |
70 DrawImage draw_image(image, SkIRect::MakeWH(image->width(), image->height()), | 43 DrawImage draw_image(image, SkIRect::MakeWH(image->width(), image->height()), |
71 quality, | 44 quality, |
72 CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable)); | 45 CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable)); |
73 scoped_refptr<TileTask> task; | 46 scoped_refptr<TileTask> task; |
74 bool need_unref = controller.GetTaskForImageAndRef( | 47 bool need_unref = controller.GetTaskForImageAndRef( |
75 draw_image, ImageDecodeController::TracingInfo(), &task); | 48 draw_image, ImageDecodeController::TracingInfo(), &task); |
76 EXPECT_TRUE(need_unref); | 49 EXPECT_TRUE(need_unref); |
77 EXPECT_TRUE(task); | 50 EXPECT_TRUE(task); |
78 | 51 |
79 DrawImage another_draw_image( | 52 DrawImage another_draw_image( |
80 image, SkIRect::MakeWH(image->width(), image->height()), quality, | 53 image, SkIRect::MakeWH(image->width(), image->height()), quality, |
81 CreateMatrix(SkSize::Make(1.5f, 1.5f), is_decomposable)); | 54 CreateMatrix(SkSize::Make(1.5f, 1.5f), is_decomposable)); |
82 scoped_refptr<TileTask> another_task; | 55 scoped_refptr<TileTask> another_task; |
83 need_unref = controller.GetTaskForImageAndRef( | 56 need_unref = controller.GetTaskForImageAndRef( |
84 another_draw_image, ImageDecodeController::TracingInfo(), &another_task); | 57 another_draw_image, ImageDecodeController::TracingInfo(), &another_task); |
85 EXPECT_TRUE(need_unref); | 58 EXPECT_TRUE(need_unref); |
86 EXPECT_TRUE(task.get() == another_task.get()); | 59 EXPECT_TRUE(task.get() == another_task.get()); |
87 | 60 |
88 ProcessTask(task->dependencies()[0].get()); | 61 SimpleTaskRunner::ProcessTask(task->dependencies()[0].get()); |
89 ProcessTask(task.get()); | 62 SimpleTaskRunner::ProcessTask(task.get()); |
90 | 63 |
91 controller.UnrefImage(draw_image); | 64 controller.UnrefImage(draw_image); |
92 controller.UnrefImage(draw_image); | 65 controller.UnrefImage(draw_image); |
93 } | 66 } |
94 | 67 |
95 TEST(GpuImageDecodeControllerTest, GetTaskForImageDifferentImage) { | 68 TEST(GpuImageDecodeControllerTest, GetTaskForImageDifferentImage) { |
96 auto context_provider = TestContextProvider::Create(); | 69 auto context_provider = TestContextProvider::Create(); |
97 context_provider->BindToCurrentThread(); | 70 context_provider->BindToCurrentThread(); |
98 GpuImageDecodeController controller(context_provider.get(), | 71 GpuImageDecodeController controller(context_provider.get(), |
99 ResourceFormat::RGBA_8888); | 72 ResourceFormat::RGBA_8888); |
(...skipping 15 matching lines...) Expand all Loading... |
115 second_image, | 88 second_image, |
116 SkIRect::MakeWH(second_image->width(), second_image->height()), quality, | 89 SkIRect::MakeWH(second_image->width(), second_image->height()), quality, |
117 CreateMatrix(SkSize::Make(0.25f, 0.25f), is_decomposable)); | 90 CreateMatrix(SkSize::Make(0.25f, 0.25f), is_decomposable)); |
118 scoped_refptr<TileTask> second_task; | 91 scoped_refptr<TileTask> second_task; |
119 need_unref = controller.GetTaskForImageAndRef( | 92 need_unref = controller.GetTaskForImageAndRef( |
120 second_draw_image, ImageDecodeController::TracingInfo(), &second_task); | 93 second_draw_image, ImageDecodeController::TracingInfo(), &second_task); |
121 EXPECT_TRUE(need_unref); | 94 EXPECT_TRUE(need_unref); |
122 EXPECT_TRUE(second_task); | 95 EXPECT_TRUE(second_task); |
123 EXPECT_TRUE(first_task.get() != second_task.get()); | 96 EXPECT_TRUE(first_task.get() != second_task.get()); |
124 | 97 |
125 ProcessTask(first_task->dependencies()[0].get()); | 98 SimpleTaskRunner::ProcessTask(first_task->dependencies()[0].get()); |
126 ProcessTask(first_task.get()); | 99 SimpleTaskRunner::ProcessTask(first_task.get()); |
127 ProcessTask(second_task->dependencies()[0].get()); | 100 SimpleTaskRunner::ProcessTask(second_task->dependencies()[0].get()); |
128 ProcessTask(second_task.get()); | 101 SimpleTaskRunner::ProcessTask(second_task.get()); |
129 | 102 |
130 controller.UnrefImage(first_draw_image); | 103 controller.UnrefImage(first_draw_image); |
131 controller.UnrefImage(second_draw_image); | 104 controller.UnrefImage(second_draw_image); |
132 } | 105 } |
133 | 106 |
134 TEST(GpuImageDecodeControllerTest, GetTaskForImageAlreadyDecodedAndLocked) { | 107 TEST(GpuImageDecodeControllerTest, GetTaskForImageAlreadyDecodedAndLocked) { |
135 auto context_provider = TestContextProvider::Create(); | 108 auto context_provider = TestContextProvider::Create(); |
136 context_provider->BindToCurrentThread(); | 109 context_provider->BindToCurrentThread(); |
137 GpuImageDecodeController controller(context_provider.get(), | 110 GpuImageDecodeController controller(context_provider.get(), |
138 ResourceFormat::RGBA_8888); | 111 ResourceFormat::RGBA_8888); |
139 bool is_decomposable = true; | 112 bool is_decomposable = true; |
140 SkFilterQuality quality = kHigh_SkFilterQuality; | 113 SkFilterQuality quality = kHigh_SkFilterQuality; |
141 | 114 |
142 sk_sp<SkImage> image = CreateImage(100, 100); | 115 sk_sp<SkImage> image = CreateImage(100, 100); |
143 DrawImage draw_image(image, SkIRect::MakeWH(image->width(), image->height()), | 116 DrawImage draw_image(image, SkIRect::MakeWH(image->width(), image->height()), |
144 quality, | 117 quality, |
145 CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable)); | 118 CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable)); |
146 scoped_refptr<TileTask> task; | 119 scoped_refptr<TileTask> task; |
147 bool need_unref = controller.GetTaskForImageAndRef( | 120 bool need_unref = controller.GetTaskForImageAndRef( |
148 draw_image, ImageDecodeController::TracingInfo(), &task); | 121 draw_image, ImageDecodeController::TracingInfo(), &task); |
149 EXPECT_TRUE(need_unref); | 122 EXPECT_TRUE(need_unref); |
150 EXPECT_TRUE(task); | 123 EXPECT_TRUE(task); |
151 EXPECT_EQ(task->dependencies().size(), 1u); | 124 EXPECT_EQ(task->dependencies().size(), 1u); |
152 EXPECT_TRUE(task->dependencies()[0]); | 125 EXPECT_TRUE(task->dependencies()[0]); |
153 | 126 |
154 // Run the decode but don't complete it (this will keep the decode locked). | 127 // Run the decode but don't complete it (this will keep the decode locked). |
155 ScheduleTask(task->dependencies()[0].get()); | 128 SimpleTaskRunner::ScheduleTask(task->dependencies()[0].get()); |
156 RunTask(task->dependencies()[0].get()); | 129 SimpleTaskRunner::RunTask(task->dependencies()[0].get()); |
157 | 130 |
158 // Cancel the upload. | 131 // Cancel the upload. |
159 CancelTask(task.get()); | 132 SimpleTaskRunner::CancelTask(task.get()); |
160 CompleteTask(task.get()); | 133 SimpleTaskRunner::CompleteTask(task.get()); |
161 | 134 |
162 // Get the image again - we should have an upload task, but no dependent | 135 // Get the image again - we should have an upload task, but no dependent |
163 // decode task, as the decode was already locked. | 136 // decode task, as the decode was already locked. |
164 scoped_refptr<TileTask> another_task; | 137 scoped_refptr<TileTask> another_task; |
165 need_unref = controller.GetTaskForImageAndRef( | 138 need_unref = controller.GetTaskForImageAndRef( |
166 draw_image, ImageDecodeController::TracingInfo(), &another_task); | 139 draw_image, ImageDecodeController::TracingInfo(), &another_task); |
167 EXPECT_TRUE(need_unref); | 140 EXPECT_TRUE(need_unref); |
168 EXPECT_TRUE(another_task); | 141 EXPECT_TRUE(another_task); |
169 EXPECT_EQ(another_task->dependencies().size(), 0u); | 142 EXPECT_EQ(another_task->dependencies().size(), 0u); |
170 | 143 |
171 ProcessTask(another_task.get()); | 144 SimpleTaskRunner::ProcessTask(another_task.get()); |
172 | 145 |
173 // Finally, complete the original decode task. | 146 // Finally, complete the original decode task. |
174 CompleteTask(task->dependencies()[0].get()); | 147 SimpleTaskRunner::CompleteTask(task->dependencies()[0].get()); |
175 | 148 |
176 controller.UnrefImage(draw_image); | 149 controller.UnrefImage(draw_image); |
177 controller.UnrefImage(draw_image); | 150 controller.UnrefImage(draw_image); |
178 } | 151 } |
179 | 152 |
180 TEST(GpuImageDecodeControllerTest, GetTaskForImageAlreadyDecodedNotLocked) { | 153 TEST(GpuImageDecodeControllerTest, GetTaskForImageAlreadyDecodedNotLocked) { |
181 auto context_provider = TestContextProvider::Create(); | 154 auto context_provider = TestContextProvider::Create(); |
182 context_provider->BindToCurrentThread(); | 155 context_provider->BindToCurrentThread(); |
183 GpuImageDecodeController controller(context_provider.get(), | 156 GpuImageDecodeController controller(context_provider.get(), |
184 ResourceFormat::RGBA_8888); | 157 ResourceFormat::RGBA_8888); |
185 bool is_decomposable = true; | 158 bool is_decomposable = true; |
186 SkFilterQuality quality = kHigh_SkFilterQuality; | 159 SkFilterQuality quality = kHigh_SkFilterQuality; |
187 | 160 |
188 sk_sp<SkImage> image = CreateImage(100, 100); | 161 sk_sp<SkImage> image = CreateImage(100, 100); |
189 DrawImage draw_image(image, SkIRect::MakeWH(image->width(), image->height()), | 162 DrawImage draw_image(image, SkIRect::MakeWH(image->width(), image->height()), |
190 quality, | 163 quality, |
191 CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable)); | 164 CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable)); |
192 scoped_refptr<TileTask> task; | 165 scoped_refptr<TileTask> task; |
193 bool need_unref = controller.GetTaskForImageAndRef( | 166 bool need_unref = controller.GetTaskForImageAndRef( |
194 draw_image, ImageDecodeController::TracingInfo(), &task); | 167 draw_image, ImageDecodeController::TracingInfo(), &task); |
195 EXPECT_TRUE(need_unref); | 168 EXPECT_TRUE(need_unref); |
196 EXPECT_TRUE(task); | 169 EXPECT_TRUE(task); |
197 EXPECT_EQ(task->dependencies().size(), 1u); | 170 EXPECT_EQ(task->dependencies().size(), 1u); |
198 EXPECT_TRUE(task->dependencies()[0]); | 171 EXPECT_TRUE(task->dependencies()[0]); |
199 | 172 |
200 // Run the decode. | 173 // Run the decode. |
201 ProcessTask(task->dependencies()[0].get()); | 174 SimpleTaskRunner::ProcessTask(task->dependencies()[0].get()); |
202 | 175 |
203 // Cancel the upload. | 176 // Cancel the upload. |
204 CancelTask(task.get()); | 177 SimpleTaskRunner::CancelTask(task.get()); |
205 CompleteTask(task.get()); | 178 SimpleTaskRunner::CompleteTask(task.get()); |
206 | 179 |
207 // Unref the image. | 180 // Unref the image. |
208 controller.UnrefImage(draw_image); | 181 controller.UnrefImage(draw_image); |
209 | 182 |
210 // Get the image again - we should have an upload task and a dependent decode | 183 // Get the image again - we should have an upload task and a dependent decode |
211 // task - this dependent task will typically just re-lock the image. | 184 // task - this dependent task will typically just re-lock the image. |
212 scoped_refptr<TileTask> another_task; | 185 scoped_refptr<TileTask> another_task; |
213 need_unref = controller.GetTaskForImageAndRef( | 186 need_unref = controller.GetTaskForImageAndRef( |
214 draw_image, ImageDecodeController::TracingInfo(), &another_task); | 187 draw_image, ImageDecodeController::TracingInfo(), &another_task); |
215 EXPECT_TRUE(need_unref); | 188 EXPECT_TRUE(need_unref); |
216 EXPECT_TRUE(another_task); | 189 EXPECT_TRUE(another_task); |
217 EXPECT_EQ(another_task->dependencies().size(), 1u); | 190 EXPECT_EQ(another_task->dependencies().size(), 1u); |
218 EXPECT_TRUE(task->dependencies()[0]); | 191 EXPECT_TRUE(task->dependencies()[0]); |
219 | 192 |
220 ProcessTask(another_task->dependencies()[0].get()); | 193 SimpleTaskRunner::ProcessTask(another_task->dependencies()[0].get()); |
221 ProcessTask(another_task.get()); | 194 SimpleTaskRunner::ProcessTask(another_task.get()); |
222 | 195 |
223 controller.UnrefImage(draw_image); | 196 controller.UnrefImage(draw_image); |
224 } | 197 } |
225 | 198 |
226 TEST(GpuImageDecodeControllerTest, GetTaskForImageAlreadyUploaded) { | 199 TEST(GpuImageDecodeControllerTest, GetTaskForImageAlreadyUploaded) { |
227 auto context_provider = TestContextProvider::Create(); | 200 auto context_provider = TestContextProvider::Create(); |
228 context_provider->BindToCurrentThread(); | 201 context_provider->BindToCurrentThread(); |
229 GpuImageDecodeController controller(context_provider.get(), | 202 GpuImageDecodeController controller(context_provider.get(), |
230 ResourceFormat::RGBA_8888); | 203 ResourceFormat::RGBA_8888); |
231 bool is_decomposable = true; | 204 bool is_decomposable = true; |
232 SkFilterQuality quality = kHigh_SkFilterQuality; | 205 SkFilterQuality quality = kHigh_SkFilterQuality; |
233 | 206 |
234 sk_sp<SkImage> image = CreateImage(100, 100); | 207 sk_sp<SkImage> image = CreateImage(100, 100); |
235 DrawImage draw_image(image, SkIRect::MakeWH(image->width(), image->height()), | 208 DrawImage draw_image(image, SkIRect::MakeWH(image->width(), image->height()), |
236 quality, | 209 quality, |
237 CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable)); | 210 CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable)); |
238 scoped_refptr<TileTask> task; | 211 scoped_refptr<TileTask> task; |
239 bool need_unref = controller.GetTaskForImageAndRef( | 212 bool need_unref = controller.GetTaskForImageAndRef( |
240 draw_image, ImageDecodeController::TracingInfo(), &task); | 213 draw_image, ImageDecodeController::TracingInfo(), &task); |
241 EXPECT_TRUE(need_unref); | 214 EXPECT_TRUE(need_unref); |
242 EXPECT_TRUE(task); | 215 EXPECT_TRUE(task); |
243 EXPECT_EQ(task->dependencies().size(), 1u); | 216 EXPECT_EQ(task->dependencies().size(), 1u); |
244 EXPECT_TRUE(task->dependencies()[0]); | 217 EXPECT_TRUE(task->dependencies()[0]); |
245 | 218 |
246 ProcessTask(task->dependencies()[0].get()); | 219 SimpleTaskRunner::ProcessTask(task->dependencies()[0].get()); |
247 ScheduleTask(task.get()); | 220 SimpleTaskRunner::ScheduleTask(task.get()); |
248 RunTask(task.get()); | 221 SimpleTaskRunner::RunTask(task.get()); |
249 | 222 |
250 scoped_refptr<TileTask> another_task; | 223 scoped_refptr<TileTask> another_task; |
251 need_unref = controller.GetTaskForImageAndRef( | 224 need_unref = controller.GetTaskForImageAndRef( |
252 draw_image, ImageDecodeController::TracingInfo(), &another_task); | 225 draw_image, ImageDecodeController::TracingInfo(), &another_task); |
253 EXPECT_TRUE(need_unref); | 226 EXPECT_TRUE(need_unref); |
254 EXPECT_FALSE(another_task); | 227 EXPECT_FALSE(another_task); |
255 | 228 |
256 CompleteTask(task.get()); | 229 SimpleTaskRunner::CompleteTask(task.get()); |
257 | 230 |
258 controller.UnrefImage(draw_image); | 231 controller.UnrefImage(draw_image); |
259 controller.UnrefImage(draw_image); | 232 controller.UnrefImage(draw_image); |
260 } | 233 } |
261 | 234 |
262 TEST(GpuImageDecodeControllerTest, GetTaskForImageCanceledGetsNewTask) { | 235 TEST(GpuImageDecodeControllerTest, GetTaskForImageCanceledGetsNewTask) { |
263 auto context_provider = TestContextProvider::Create(); | 236 auto context_provider = TestContextProvider::Create(); |
264 context_provider->BindToCurrentThread(); | 237 context_provider->BindToCurrentThread(); |
265 GpuImageDecodeController controller(context_provider.get(), | 238 GpuImageDecodeController controller(context_provider.get(), |
266 ResourceFormat::RGBA_8888); | 239 ResourceFormat::RGBA_8888); |
267 bool is_decomposable = true; | 240 bool is_decomposable = true; |
268 SkFilterQuality quality = kHigh_SkFilterQuality; | 241 SkFilterQuality quality = kHigh_SkFilterQuality; |
269 | 242 |
270 sk_sp<SkImage> image = CreateImage(100, 100); | 243 sk_sp<SkImage> image = CreateImage(100, 100); |
271 DrawImage draw_image(image, SkIRect::MakeWH(image->width(), image->height()), | 244 DrawImage draw_image(image, SkIRect::MakeWH(image->width(), image->height()), |
272 quality, | 245 quality, |
273 CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable)); | 246 CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable)); |
274 scoped_refptr<TileTask> task; | 247 scoped_refptr<TileTask> task; |
275 bool need_unref = controller.GetTaskForImageAndRef( | 248 bool need_unref = controller.GetTaskForImageAndRef( |
276 draw_image, ImageDecodeController::TracingInfo(), &task); | 249 draw_image, ImageDecodeController::TracingInfo(), &task); |
277 EXPECT_TRUE(need_unref); | 250 EXPECT_TRUE(need_unref); |
278 EXPECT_TRUE(task); | 251 EXPECT_TRUE(task); |
279 | 252 |
280 ProcessTask(task->dependencies()[0].get()); | 253 SimpleTaskRunner::ProcessTask(task->dependencies()[0].get()); |
281 | 254 |
282 scoped_refptr<TileTask> another_task; | 255 scoped_refptr<TileTask> another_task; |
283 need_unref = controller.GetTaskForImageAndRef( | 256 need_unref = controller.GetTaskForImageAndRef( |
284 draw_image, ImageDecodeController::TracingInfo(), &another_task); | 257 draw_image, ImageDecodeController::TracingInfo(), &another_task); |
285 EXPECT_TRUE(need_unref); | 258 EXPECT_TRUE(need_unref); |
286 EXPECT_TRUE(another_task.get() == task.get()); | 259 EXPECT_TRUE(another_task.get() == task.get()); |
287 | 260 |
288 // Didn't run the task, so cancel it. | 261 // Didn't run the task, so cancel it. |
289 CancelTask(task.get()); | 262 SimpleTaskRunner::CancelTask(task.get()); |
290 CompleteTask(task.get()); | 263 SimpleTaskRunner::CompleteTask(task.get()); |
291 | 264 |
292 // Fully cancel everything (so the raster would unref things). | 265 // Fully cancel everything (so the raster would unref things). |
293 controller.UnrefImage(draw_image); | 266 controller.UnrefImage(draw_image); |
294 controller.UnrefImage(draw_image); | 267 controller.UnrefImage(draw_image); |
295 | 268 |
296 // Here a new task is created. | 269 // Here a new task is created. |
297 scoped_refptr<TileTask> third_task; | 270 scoped_refptr<TileTask> third_task; |
298 need_unref = controller.GetTaskForImageAndRef( | 271 need_unref = controller.GetTaskForImageAndRef( |
299 draw_image, ImageDecodeController::TracingInfo(), &third_task); | 272 draw_image, ImageDecodeController::TracingInfo(), &third_task); |
300 EXPECT_TRUE(need_unref); | 273 EXPECT_TRUE(need_unref); |
301 EXPECT_TRUE(third_task); | 274 EXPECT_TRUE(third_task); |
302 EXPECT_FALSE(third_task.get() == task.get()); | 275 EXPECT_FALSE(third_task.get() == task.get()); |
303 | 276 |
304 ProcessTask(third_task->dependencies()[0].get()); | 277 SimpleTaskRunner::ProcessTask(third_task->dependencies()[0].get()); |
305 ProcessTask(third_task.get()); | 278 SimpleTaskRunner::ProcessTask(third_task.get()); |
306 | 279 |
307 controller.UnrefImage(draw_image); | 280 controller.UnrefImage(draw_image); |
308 } | 281 } |
309 | 282 |
310 TEST(GpuImageDecodeControllerTest, | 283 TEST(GpuImageDecodeControllerTest, |
311 GetTaskForImageCanceledWhileReffedGetsNewTask) { | 284 GetTaskForImageCanceledWhileReffedGetsNewTask) { |
312 auto context_provider = TestContextProvider::Create(); | 285 auto context_provider = TestContextProvider::Create(); |
313 context_provider->BindToCurrentThread(); | 286 context_provider->BindToCurrentThread(); |
314 GpuImageDecodeController controller(context_provider.get(), | 287 GpuImageDecodeController controller(context_provider.get(), |
315 ResourceFormat::RGBA_8888); | 288 ResourceFormat::RGBA_8888); |
316 bool is_decomposable = true; | 289 bool is_decomposable = true; |
317 SkFilterQuality quality = kHigh_SkFilterQuality; | 290 SkFilterQuality quality = kHigh_SkFilterQuality; |
318 | 291 |
319 sk_sp<SkImage> image = CreateImage(100, 100); | 292 sk_sp<SkImage> image = CreateImage(100, 100); |
320 DrawImage draw_image(image, SkIRect::MakeWH(image->width(), image->height()), | 293 DrawImage draw_image(image, SkIRect::MakeWH(image->width(), image->height()), |
321 quality, | 294 quality, |
322 CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable)); | 295 CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable)); |
323 scoped_refptr<TileTask> task; | 296 scoped_refptr<TileTask> task; |
324 bool need_unref = controller.GetTaskForImageAndRef( | 297 bool need_unref = controller.GetTaskForImageAndRef( |
325 draw_image, ImageDecodeController::TracingInfo(), &task); | 298 draw_image, ImageDecodeController::TracingInfo(), &task); |
326 EXPECT_TRUE(need_unref); | 299 EXPECT_TRUE(need_unref); |
327 EXPECT_TRUE(task); | 300 EXPECT_TRUE(task); |
328 | 301 |
329 ProcessTask(task->dependencies()[0].get()); | 302 SimpleTaskRunner::ProcessTask(task->dependencies()[0].get()); |
330 | 303 |
331 scoped_refptr<TileTask> another_task; | 304 scoped_refptr<TileTask> another_task; |
332 need_unref = controller.GetTaskForImageAndRef( | 305 need_unref = controller.GetTaskForImageAndRef( |
333 draw_image, ImageDecodeController::TracingInfo(), &another_task); | 306 draw_image, ImageDecodeController::TracingInfo(), &another_task); |
334 EXPECT_TRUE(need_unref); | 307 EXPECT_TRUE(need_unref); |
335 EXPECT_TRUE(another_task.get() == task.get()); | 308 EXPECT_TRUE(another_task.get() == task.get()); |
336 | 309 |
337 // Didn't run the task, so cancel it. | 310 // Didn't run the task, so cancel it. |
338 CancelTask(task.get()); | 311 SimpleTaskRunner::CancelTask(task.get()); |
339 CompleteTask(task.get()); | 312 SimpleTaskRunner::CompleteTask(task.get()); |
340 | 313 |
341 // Note that here, everything is reffed, but a new task is created. This is | 314 // Note that here, everything is reffed, but a new task is created. This is |
342 // possible with repeated schedule/cancel operations. | 315 // possible with repeated schedule/cancel operations. |
343 scoped_refptr<TileTask> third_task; | 316 scoped_refptr<TileTask> third_task; |
344 need_unref = controller.GetTaskForImageAndRef( | 317 need_unref = controller.GetTaskForImageAndRef( |
345 draw_image, ImageDecodeController::TracingInfo(), &third_task); | 318 draw_image, ImageDecodeController::TracingInfo(), &third_task); |
346 EXPECT_TRUE(need_unref); | 319 EXPECT_TRUE(need_unref); |
347 EXPECT_TRUE(third_task); | 320 EXPECT_TRUE(third_task); |
348 EXPECT_FALSE(third_task.get() == task.get()); | 321 EXPECT_FALSE(third_task.get() == task.get()); |
349 | 322 |
350 ProcessTask(third_task->dependencies()[0].get()); | 323 SimpleTaskRunner::ProcessTask(third_task->dependencies()[0].get()); |
351 ProcessTask(third_task.get()); | 324 SimpleTaskRunner::ProcessTask(third_task.get()); |
352 | 325 |
353 // 3 Unrefs! | 326 // 3 Unrefs! |
354 controller.UnrefImage(draw_image); | 327 controller.UnrefImage(draw_image); |
355 controller.UnrefImage(draw_image); | 328 controller.UnrefImage(draw_image); |
356 controller.UnrefImage(draw_image); | 329 controller.UnrefImage(draw_image); |
357 } | 330 } |
358 | 331 |
359 TEST(GpuImageDecodeControllerTest, NoTaskForImageAlreadyFailedDecoding) { | 332 TEST(GpuImageDecodeControllerTest, NoTaskForImageAlreadyFailedDecoding) { |
360 auto context_provider = TestContextProvider::Create(); | 333 auto context_provider = TestContextProvider::Create(); |
361 context_provider->BindToCurrentThread(); | 334 context_provider->BindToCurrentThread(); |
362 GpuImageDecodeController controller(context_provider.get(), | 335 GpuImageDecodeController controller(context_provider.get(), |
363 ResourceFormat::RGBA_8888); | 336 ResourceFormat::RGBA_8888); |
364 bool is_decomposable = true; | 337 bool is_decomposable = true; |
365 SkFilterQuality quality = kHigh_SkFilterQuality; | 338 SkFilterQuality quality = kHigh_SkFilterQuality; |
366 | 339 |
367 sk_sp<SkImage> image = CreateImage(100, 100); | 340 sk_sp<SkImage> image = CreateImage(100, 100); |
368 DrawImage draw_image(image, SkIRect::MakeWH(image->width(), image->height()), | 341 DrawImage draw_image(image, SkIRect::MakeWH(image->width(), image->height()), |
369 quality, | 342 quality, |
370 CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable)); | 343 CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable)); |
371 scoped_refptr<TileTask> task; | 344 scoped_refptr<TileTask> task; |
372 bool need_unref = controller.GetTaskForImageAndRef( | 345 bool need_unref = controller.GetTaskForImageAndRef( |
373 draw_image, ImageDecodeController::TracingInfo(), &task); | 346 draw_image, ImageDecodeController::TracingInfo(), &task); |
374 EXPECT_TRUE(need_unref); | 347 EXPECT_TRUE(need_unref); |
375 EXPECT_TRUE(task); | 348 EXPECT_TRUE(task); |
376 | 349 |
377 ProcessTask(task->dependencies()[0].get()); | 350 SimpleTaskRunner::ProcessTask(task->dependencies()[0].get()); |
378 // Didn't run the task, so cancel it. | 351 // Didn't run the task, so cancel it. |
379 CancelTask(task.get()); | 352 SimpleTaskRunner::CancelTask(task.get()); |
380 CompleteTask(task.get()); | 353 SimpleTaskRunner::CompleteTask(task.get()); |
381 | 354 |
382 controller.SetImageDecodingFailedForTesting(draw_image); | 355 controller.SetImageDecodingFailedForTesting(draw_image); |
383 | 356 |
384 scoped_refptr<TileTask> another_task; | 357 scoped_refptr<TileTask> another_task; |
385 need_unref = controller.GetTaskForImageAndRef( | 358 need_unref = controller.GetTaskForImageAndRef( |
386 draw_image, ImageDecodeController::TracingInfo(), &another_task); | 359 draw_image, ImageDecodeController::TracingInfo(), &another_task); |
387 EXPECT_FALSE(need_unref); | 360 EXPECT_FALSE(need_unref); |
388 EXPECT_EQ(another_task.get(), nullptr); | 361 EXPECT_EQ(another_task.get(), nullptr); |
389 | 362 |
390 controller.UnrefImage(draw_image); | 363 controller.UnrefImage(draw_image); |
(...skipping 10 matching lines...) Expand all Loading... |
401 sk_sp<SkImage> image = CreateImage(100, 100); | 374 sk_sp<SkImage> image = CreateImage(100, 100); |
402 DrawImage draw_image(image, SkIRect::MakeWH(image->width(), image->height()), | 375 DrawImage draw_image(image, SkIRect::MakeWH(image->width(), image->height()), |
403 quality, | 376 quality, |
404 CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable)); | 377 CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable)); |
405 scoped_refptr<TileTask> task; | 378 scoped_refptr<TileTask> task; |
406 bool need_unref = controller.GetTaskForImageAndRef( | 379 bool need_unref = controller.GetTaskForImageAndRef( |
407 draw_image, ImageDecodeController::TracingInfo(), &task); | 380 draw_image, ImageDecodeController::TracingInfo(), &task); |
408 EXPECT_TRUE(need_unref); | 381 EXPECT_TRUE(need_unref); |
409 EXPECT_TRUE(task); | 382 EXPECT_TRUE(task); |
410 | 383 |
411 ProcessTask(task->dependencies()[0].get()); | 384 SimpleTaskRunner::ProcessTask(task->dependencies()[0].get()); |
412 ProcessTask(task.get()); | 385 SimpleTaskRunner::ProcessTask(task.get()); |
413 | 386 |
414 // Must hold context lock before calling GetDecodedImageForDraw / | 387 // Must hold context lock before calling GetDecodedImageForDraw / |
415 // DrawWithImageFinished. | 388 // DrawWithImageFinished. |
416 ContextProvider::ScopedContextLock context_lock(context_provider.get()); | 389 ContextProvider::ScopedContextLock context_lock(context_provider.get()); |
417 DecodedDrawImage decoded_draw_image = | 390 DecodedDrawImage decoded_draw_image = |
418 controller.GetDecodedImageForDraw(draw_image); | 391 controller.GetDecodedImageForDraw(draw_image); |
419 EXPECT_TRUE(decoded_draw_image.image()); | 392 EXPECT_TRUE(decoded_draw_image.image()); |
420 EXPECT_TRUE(decoded_draw_image.image()->isTextureBacked()); | 393 EXPECT_TRUE(decoded_draw_image.image()->isTextureBacked()); |
421 EXPECT_FALSE(decoded_draw_image.is_at_raster_decode()); | 394 EXPECT_FALSE(decoded_draw_image.is_at_raster_decode()); |
422 | 395 |
(...skipping 12 matching lines...) Expand all Loading... |
435 sk_sp<SkImage> image = CreateImage(1, 24000); | 408 sk_sp<SkImage> image = CreateImage(1, 24000); |
436 DrawImage draw_image(image, SkIRect::MakeWH(image->width(), image->height()), | 409 DrawImage draw_image(image, SkIRect::MakeWH(image->width(), image->height()), |
437 quality, | 410 quality, |
438 CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable)); | 411 CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable)); |
439 scoped_refptr<TileTask> task; | 412 scoped_refptr<TileTask> task; |
440 bool need_unref = controller.GetTaskForImageAndRef( | 413 bool need_unref = controller.GetTaskForImageAndRef( |
441 draw_image, ImageDecodeController::TracingInfo(), &task); | 414 draw_image, ImageDecodeController::TracingInfo(), &task); |
442 EXPECT_TRUE(need_unref); | 415 EXPECT_TRUE(need_unref); |
443 EXPECT_TRUE(task); | 416 EXPECT_TRUE(task); |
444 | 417 |
445 ProcessTask(task->dependencies()[0].get()); | 418 SimpleTaskRunner::ProcessTask(task->dependencies()[0].get()); |
446 ProcessTask(task.get()); | 419 SimpleTaskRunner::ProcessTask(task.get()); |
447 | 420 |
448 // Must hold context lock before calling GetDecodedImageForDraw / | 421 // Must hold context lock before calling GetDecodedImageForDraw / |
449 // DrawWithImageFinished. | 422 // DrawWithImageFinished. |
450 ContextProvider::ScopedContextLock context_lock(context_provider.get()); | 423 ContextProvider::ScopedContextLock context_lock(context_provider.get()); |
451 DecodedDrawImage decoded_draw_image = | 424 DecodedDrawImage decoded_draw_image = |
452 controller.GetDecodedImageForDraw(draw_image); | 425 controller.GetDecodedImageForDraw(draw_image); |
453 EXPECT_TRUE(decoded_draw_image.image()); | 426 EXPECT_TRUE(decoded_draw_image.image()); |
454 EXPECT_FALSE(decoded_draw_image.image()->isTextureBacked()); | 427 EXPECT_FALSE(decoded_draw_image.image()->isTextureBacked()); |
455 EXPECT_FALSE(decoded_draw_image.is_at_raster_decode()); | 428 EXPECT_FALSE(decoded_draw_image.is_at_raster_decode()); |
456 | 429 |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
644 image, SkIRect::MakeXYWH(0, 0, image->width(), image->height()), quality, | 617 image, SkIRect::MakeXYWH(0, 0, image->width(), image->height()), quality, |
645 CreateMatrix(SkSize::Make(1.f, 1.f), is_decomposable)); | 618 CreateMatrix(SkSize::Make(1.f, 1.f), is_decomposable)); |
646 | 619 |
647 scoped_refptr<TileTask> task; | 620 scoped_refptr<TileTask> task; |
648 bool need_unref = controller.GetTaskForImageAndRef( | 621 bool need_unref = controller.GetTaskForImageAndRef( |
649 draw_image, ImageDecodeController::TracingInfo(), &task); | 622 draw_image, ImageDecodeController::TracingInfo(), &task); |
650 EXPECT_NE(0u, controller.GetBytesUsedForTesting()); | 623 EXPECT_NE(0u, controller.GetBytesUsedForTesting()); |
651 EXPECT_TRUE(task); | 624 EXPECT_TRUE(task); |
652 EXPECT_TRUE(need_unref); | 625 EXPECT_TRUE(need_unref); |
653 | 626 |
654 CancelTask(task->dependencies()[0].get()); | 627 SimpleTaskRunner::CancelTask(task->dependencies()[0].get()); |
655 CompleteTask(task->dependencies()[0].get()); | 628 SimpleTaskRunner::CompleteTask(task->dependencies()[0].get()); |
656 CancelTask(task.get()); | 629 SimpleTaskRunner::CancelTask(task.get()); |
657 CompleteTask(task.get()); | 630 SimpleTaskRunner::CompleteTask(task.get()); |
658 | 631 |
659 controller.UnrefImage(draw_image); | 632 controller.UnrefImage(draw_image); |
660 EXPECT_EQ(0u, controller.GetBytesUsedForTesting()); | 633 EXPECT_EQ(0u, controller.GetBytesUsedForTesting()); |
661 } | 634 } |
662 | 635 |
663 TEST(GpuImageDecodeControllerTest, ShouldAggressivelyFreeResources) { | 636 TEST(GpuImageDecodeControllerTest, ShouldAggressivelyFreeResources) { |
664 auto context_provider = TestContextProvider::Create(); | 637 auto context_provider = TestContextProvider::Create(); |
665 context_provider->BindToCurrentThread(); | 638 context_provider->BindToCurrentThread(); |
666 GpuImageDecodeController controller(context_provider.get(), | 639 GpuImageDecodeController controller(context_provider.get(), |
667 ResourceFormat::RGBA_8888); | 640 ResourceFormat::RGBA_8888); |
668 bool is_decomposable = true; | 641 bool is_decomposable = true; |
669 SkFilterQuality quality = kHigh_SkFilterQuality; | 642 SkFilterQuality quality = kHigh_SkFilterQuality; |
670 | 643 |
671 sk_sp<SkImage> image = CreateImage(100, 100); | 644 sk_sp<SkImage> image = CreateImage(100, 100); |
672 DrawImage draw_image(image, SkIRect::MakeWH(image->width(), image->height()), | 645 DrawImage draw_image(image, SkIRect::MakeWH(image->width(), image->height()), |
673 quality, | 646 quality, |
674 CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable)); | 647 CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable)); |
675 scoped_refptr<TileTask> task; | 648 scoped_refptr<TileTask> task; |
676 { | 649 { |
677 bool need_unref = controller.GetTaskForImageAndRef( | 650 bool need_unref = controller.GetTaskForImageAndRef( |
678 draw_image, ImageDecodeController::TracingInfo(), &task); | 651 draw_image, ImageDecodeController::TracingInfo(), &task); |
679 EXPECT_TRUE(need_unref); | 652 EXPECT_TRUE(need_unref); |
680 EXPECT_TRUE(task); | 653 EXPECT_TRUE(task); |
681 } | 654 } |
682 | 655 |
683 ProcessTask(task->dependencies()[0].get()); | 656 SimpleTaskRunner::ProcessTask(task->dependencies()[0].get()); |
684 ProcessTask(task.get()); | 657 SimpleTaskRunner::ProcessTask(task.get()); |
685 | 658 |
686 controller.UnrefImage(draw_image); | 659 controller.UnrefImage(draw_image); |
687 | 660 |
688 // We should now have data image in our cache. | 661 // We should now have data image in our cache. |
689 DCHECK_GT(controller.GetBytesUsedForTesting(), 0u); | 662 DCHECK_GT(controller.GetBytesUsedForTesting(), 0u); |
690 | 663 |
691 // Tell our controller to aggressively free resources. | 664 // Tell our controller to aggressively free resources. |
692 controller.SetShouldAggressivelyFreeResources(true); | 665 controller.SetShouldAggressivelyFreeResources(true); |
693 DCHECK_EQ(0u, controller.GetBytesUsedForTesting()); | 666 DCHECK_EQ(0u, controller.GetBytesUsedForTesting()); |
694 | 667 |
695 // Attempting to upload a new image should result in at-raster decode. | 668 // Attempting to upload a new image should result in at-raster decode. |
696 { | 669 { |
697 bool need_unref = controller.GetTaskForImageAndRef( | 670 bool need_unref = controller.GetTaskForImageAndRef( |
698 draw_image, ImageDecodeController::TracingInfo(), &task); | 671 draw_image, ImageDecodeController::TracingInfo(), &task); |
699 EXPECT_FALSE(need_unref); | 672 EXPECT_FALSE(need_unref); |
700 EXPECT_FALSE(task); | 673 EXPECT_FALSE(task); |
701 } | 674 } |
702 | 675 |
703 // We now tell the controller to not aggressively free resources. Uploads | 676 // We now tell the controller to not aggressively free resources. Uploads |
704 // should work again. | 677 // should work again. |
705 controller.SetShouldAggressivelyFreeResources(false); | 678 controller.SetShouldAggressivelyFreeResources(false); |
706 { | 679 { |
707 bool need_unref = controller.GetTaskForImageAndRef( | 680 bool need_unref = controller.GetTaskForImageAndRef( |
708 draw_image, ImageDecodeController::TracingInfo(), &task); | 681 draw_image, ImageDecodeController::TracingInfo(), &task); |
709 EXPECT_TRUE(need_unref); | 682 EXPECT_TRUE(need_unref); |
710 EXPECT_TRUE(task); | 683 EXPECT_TRUE(task); |
711 } | 684 } |
712 | 685 |
713 ProcessTask(task->dependencies()[0].get()); | 686 SimpleTaskRunner::ProcessTask(task->dependencies()[0].get()); |
714 ProcessTask(task.get()); | 687 SimpleTaskRunner::ProcessTask(task.get()); |
715 | 688 |
716 // The image should be in our cache after un-ref. | 689 // The image should be in our cache after un-ref. |
717 controller.UnrefImage(draw_image); | 690 controller.UnrefImage(draw_image); |
718 DCHECK_GT(controller.GetBytesUsedForTesting(), 0u); | 691 DCHECK_GT(controller.GetBytesUsedForTesting(), 0u); |
719 } | 692 } |
720 | 693 |
721 } // namespace | 694 } // namespace |
722 } // namespace cc | 695 } // namespace cc |
OLD | NEW |