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" | |
9 #include "cc/test/test_context_provider.h" | 8 #include "cc/test/test_context_provider.h" |
| 9 #include "cc/test/test_tile_task_runner.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 size_t kGpuMemoryLimitBytes = 96 * 1024 * 1024; | 16 size_t kGpuMemoryLimitBytes = 96 * 1024 * 1024; |
17 class TestGpuImageDecodeController : public GpuImageDecodeController { | 17 class TestGpuImageDecodeController : public GpuImageDecodeController { |
18 public: | 18 public: |
19 explicit TestGpuImageDecodeController(ContextProvider* context) | 19 explicit TestGpuImageDecodeController(ContextProvider* context) |
(...skipping 13 matching lines...) Expand all Loading... |
33 matrix.setScale(scale.width(), scale.height()); | 33 matrix.setScale(scale.width(), scale.height()); |
34 | 34 |
35 if (!is_decomposable) { | 35 if (!is_decomposable) { |
36 // Perspective is not decomposable, add it. | 36 // Perspective is not decomposable, add it. |
37 matrix[SkMatrix::kMPersp0] = 0.1f; | 37 matrix[SkMatrix::kMPersp0] = 0.1f; |
38 } | 38 } |
39 | 39 |
40 return matrix; | 40 return matrix; |
41 } | 41 } |
42 | 42 |
43 void ScheduleTask(TileTask* task) { | |
44 task->state().DidSchedule(); | |
45 } | |
46 | |
47 // Before running the task it must be scheduled. Call ScheduleTask() before | |
48 // calling this function. | |
49 void RunTask(TileTask* task) { | |
50 task->state().DidStart(); | |
51 task->RunOnWorkerThread(); | |
52 task->state().DidFinish(); | |
53 } | |
54 | |
55 void CompleteTask(TileTask* task) { | |
56 DCHECK(task->state().IsFinished() || task->state().IsCanceled()); | |
57 task->OnTaskCompleted(); | |
58 } | |
59 | |
60 void CancelTask(TileTask* task) { | |
61 task->state().DidCancel(); | |
62 } | |
63 | |
64 void ProcessTask(TileTask* task) { | |
65 ScheduleTask(task); | |
66 RunTask(task); | |
67 CompleteTask(task); | |
68 } | |
69 | |
70 TEST(GpuImageDecodeControllerTest, GetTaskForImageSameImage) { | 43 TEST(GpuImageDecodeControllerTest, GetTaskForImageSameImage) { |
71 auto context_provider = TestContextProvider::Create(); | 44 auto context_provider = TestContextProvider::Create(); |
72 context_provider->BindToCurrentThread(); | 45 context_provider->BindToCurrentThread(); |
73 TestGpuImageDecodeController controller(context_provider.get()); | 46 TestGpuImageDecodeController controller(context_provider.get()); |
74 sk_sp<SkImage> image = CreateImage(100, 100); | 47 sk_sp<SkImage> image = CreateImage(100, 100); |
75 bool is_decomposable = true; | 48 bool is_decomposable = true; |
76 SkFilterQuality quality = kHigh_SkFilterQuality; | 49 SkFilterQuality quality = kHigh_SkFilterQuality; |
77 | 50 |
78 DrawImage draw_image(image, SkIRect::MakeWH(image->width(), image->height()), | 51 DrawImage draw_image(image, SkIRect::MakeWH(image->width(), image->height()), |
79 quality, | 52 quality, |
80 CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable)); | 53 CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable)); |
81 scoped_refptr<TileTask> task; | 54 scoped_refptr<TileTask> task; |
82 bool need_unref = controller.GetTaskForImageAndRef( | 55 bool need_unref = controller.GetTaskForImageAndRef( |
83 draw_image, ImageDecodeController::TracingInfo(), &task); | 56 draw_image, ImageDecodeController::TracingInfo(), &task); |
84 EXPECT_TRUE(need_unref); | 57 EXPECT_TRUE(need_unref); |
85 EXPECT_TRUE(task); | 58 EXPECT_TRUE(task); |
86 | 59 |
87 DrawImage another_draw_image( | 60 DrawImage another_draw_image( |
88 image, SkIRect::MakeWH(image->width(), image->height()), quality, | 61 image, SkIRect::MakeWH(image->width(), image->height()), quality, |
89 CreateMatrix(SkSize::Make(1.5f, 1.5f), is_decomposable)); | 62 CreateMatrix(SkSize::Make(1.5f, 1.5f), is_decomposable)); |
90 scoped_refptr<TileTask> another_task; | 63 scoped_refptr<TileTask> another_task; |
91 need_unref = controller.GetTaskForImageAndRef( | 64 need_unref = controller.GetTaskForImageAndRef( |
92 another_draw_image, ImageDecodeController::TracingInfo(), &another_task); | 65 another_draw_image, ImageDecodeController::TracingInfo(), &another_task); |
93 EXPECT_TRUE(need_unref); | 66 EXPECT_TRUE(need_unref); |
94 EXPECT_TRUE(task.get() == another_task.get()); | 67 EXPECT_TRUE(task.get() == another_task.get()); |
95 | 68 |
96 ProcessTask(task->dependencies()[0].get()); | 69 TestTileTaskRunner::ProcessTask(task->dependencies()[0].get()); |
97 ProcessTask(task.get()); | 70 TestTileTaskRunner::ProcessTask(task.get()); |
98 | 71 |
99 controller.UnrefImage(draw_image); | 72 controller.UnrefImage(draw_image); |
100 controller.UnrefImage(draw_image); | 73 controller.UnrefImage(draw_image); |
101 } | 74 } |
102 | 75 |
103 TEST(GpuImageDecodeControllerTest, GetTaskForImageDifferentImage) { | 76 TEST(GpuImageDecodeControllerTest, GetTaskForImageDifferentImage) { |
104 auto context_provider = TestContextProvider::Create(); | 77 auto context_provider = TestContextProvider::Create(); |
105 context_provider->BindToCurrentThread(); | 78 context_provider->BindToCurrentThread(); |
106 TestGpuImageDecodeController controller(context_provider.get()); | 79 TestGpuImageDecodeController controller(context_provider.get()); |
107 bool is_decomposable = true; | 80 bool is_decomposable = true; |
(...skipping 14 matching lines...) Expand all Loading... |
122 second_image, | 95 second_image, |
123 SkIRect::MakeWH(second_image->width(), second_image->height()), quality, | 96 SkIRect::MakeWH(second_image->width(), second_image->height()), quality, |
124 CreateMatrix(SkSize::Make(0.25f, 0.25f), is_decomposable)); | 97 CreateMatrix(SkSize::Make(0.25f, 0.25f), is_decomposable)); |
125 scoped_refptr<TileTask> second_task; | 98 scoped_refptr<TileTask> second_task; |
126 need_unref = controller.GetTaskForImageAndRef( | 99 need_unref = controller.GetTaskForImageAndRef( |
127 second_draw_image, ImageDecodeController::TracingInfo(), &second_task); | 100 second_draw_image, ImageDecodeController::TracingInfo(), &second_task); |
128 EXPECT_TRUE(need_unref); | 101 EXPECT_TRUE(need_unref); |
129 EXPECT_TRUE(second_task); | 102 EXPECT_TRUE(second_task); |
130 EXPECT_TRUE(first_task.get() != second_task.get()); | 103 EXPECT_TRUE(first_task.get() != second_task.get()); |
131 | 104 |
132 ProcessTask(first_task->dependencies()[0].get()); | 105 TestTileTaskRunner::ProcessTask(first_task->dependencies()[0].get()); |
133 ProcessTask(first_task.get()); | 106 TestTileTaskRunner::ProcessTask(first_task.get()); |
134 ProcessTask(second_task->dependencies()[0].get()); | 107 TestTileTaskRunner::ProcessTask(second_task->dependencies()[0].get()); |
135 ProcessTask(second_task.get()); | 108 TestTileTaskRunner::ProcessTask(second_task.get()); |
136 | 109 |
137 controller.UnrefImage(first_draw_image); | 110 controller.UnrefImage(first_draw_image); |
138 controller.UnrefImage(second_draw_image); | 111 controller.UnrefImage(second_draw_image); |
139 } | 112 } |
140 | 113 |
141 TEST(GpuImageDecodeControllerTest, GetTaskForImageAlreadyDecodedAndLocked) { | 114 TEST(GpuImageDecodeControllerTest, GetTaskForImageAlreadyDecodedAndLocked) { |
142 auto context_provider = TestContextProvider::Create(); | 115 auto context_provider = TestContextProvider::Create(); |
143 context_provider->BindToCurrentThread(); | 116 context_provider->BindToCurrentThread(); |
144 TestGpuImageDecodeController controller(context_provider.get()); | 117 TestGpuImageDecodeController controller(context_provider.get()); |
145 bool is_decomposable = true; | 118 bool is_decomposable = true; |
146 SkFilterQuality quality = kHigh_SkFilterQuality; | 119 SkFilterQuality quality = kHigh_SkFilterQuality; |
147 | 120 |
148 sk_sp<SkImage> image = CreateImage(100, 100); | 121 sk_sp<SkImage> image = CreateImage(100, 100); |
149 DrawImage draw_image(image, SkIRect::MakeWH(image->width(), image->height()), | 122 DrawImage draw_image(image, SkIRect::MakeWH(image->width(), image->height()), |
150 quality, | 123 quality, |
151 CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable)); | 124 CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable)); |
152 scoped_refptr<TileTask> task; | 125 scoped_refptr<TileTask> task; |
153 bool need_unref = controller.GetTaskForImageAndRef( | 126 bool need_unref = controller.GetTaskForImageAndRef( |
154 draw_image, ImageDecodeController::TracingInfo(), &task); | 127 draw_image, ImageDecodeController::TracingInfo(), &task); |
155 EXPECT_TRUE(need_unref); | 128 EXPECT_TRUE(need_unref); |
156 EXPECT_TRUE(task); | 129 EXPECT_TRUE(task); |
157 EXPECT_EQ(task->dependencies().size(), 1u); | 130 EXPECT_EQ(task->dependencies().size(), 1u); |
158 EXPECT_TRUE(task->dependencies()[0]); | 131 EXPECT_TRUE(task->dependencies()[0]); |
159 | 132 |
160 // Run the decode but don't complete it (this will keep the decode locked). | 133 // Run the decode but don't complete it (this will keep the decode locked). |
161 ScheduleTask(task->dependencies()[0].get()); | 134 TestTileTaskRunner::ScheduleTask(task->dependencies()[0].get()); |
162 RunTask(task->dependencies()[0].get()); | 135 TestTileTaskRunner::RunTask(task->dependencies()[0].get()); |
163 | 136 |
164 // Cancel the upload. | 137 // Cancel the upload. |
165 CancelTask(task.get()); | 138 TestTileTaskRunner::CancelTask(task.get()); |
166 CompleteTask(task.get()); | 139 TestTileTaskRunner::CompleteTask(task.get()); |
167 | 140 |
168 // Get the image again - we should have an upload task, but no dependent | 141 // Get the image again - we should have an upload task, but no dependent |
169 // decode task, as the decode was already locked. | 142 // decode task, as the decode was already locked. |
170 scoped_refptr<TileTask> another_task; | 143 scoped_refptr<TileTask> another_task; |
171 need_unref = controller.GetTaskForImageAndRef( | 144 need_unref = controller.GetTaskForImageAndRef( |
172 draw_image, ImageDecodeController::TracingInfo(), &another_task); | 145 draw_image, ImageDecodeController::TracingInfo(), &another_task); |
173 EXPECT_TRUE(need_unref); | 146 EXPECT_TRUE(need_unref); |
174 EXPECT_TRUE(another_task); | 147 EXPECT_TRUE(another_task); |
175 EXPECT_EQ(another_task->dependencies().size(), 0u); | 148 EXPECT_EQ(another_task->dependencies().size(), 0u); |
176 | 149 |
177 ProcessTask(another_task.get()); | 150 TestTileTaskRunner::ProcessTask(another_task.get()); |
178 | 151 |
179 // Finally, complete the original decode task. | 152 // Finally, complete the original decode task. |
180 CompleteTask(task->dependencies()[0].get()); | 153 TestTileTaskRunner::CompleteTask(task->dependencies()[0].get()); |
181 | 154 |
182 controller.UnrefImage(draw_image); | 155 controller.UnrefImage(draw_image); |
183 controller.UnrefImage(draw_image); | 156 controller.UnrefImage(draw_image); |
184 } | 157 } |
185 | 158 |
186 TEST(GpuImageDecodeControllerTest, GetTaskForImageAlreadyDecodedNotLocked) { | 159 TEST(GpuImageDecodeControllerTest, GetTaskForImageAlreadyDecodedNotLocked) { |
187 auto context_provider = TestContextProvider::Create(); | 160 auto context_provider = TestContextProvider::Create(); |
188 context_provider->BindToCurrentThread(); | 161 context_provider->BindToCurrentThread(); |
189 TestGpuImageDecodeController controller(context_provider.get()); | 162 TestGpuImageDecodeController controller(context_provider.get()); |
190 bool is_decomposable = true; | 163 bool is_decomposable = true; |
191 SkFilterQuality quality = kHigh_SkFilterQuality; | 164 SkFilterQuality quality = kHigh_SkFilterQuality; |
192 | 165 |
193 sk_sp<SkImage> image = CreateImage(100, 100); | 166 sk_sp<SkImage> image = CreateImage(100, 100); |
194 DrawImage draw_image(image, SkIRect::MakeWH(image->width(), image->height()), | 167 DrawImage draw_image(image, SkIRect::MakeWH(image->width(), image->height()), |
195 quality, | 168 quality, |
196 CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable)); | 169 CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable)); |
197 scoped_refptr<TileTask> task; | 170 scoped_refptr<TileTask> task; |
198 bool need_unref = controller.GetTaskForImageAndRef( | 171 bool need_unref = controller.GetTaskForImageAndRef( |
199 draw_image, ImageDecodeController::TracingInfo(), &task); | 172 draw_image, ImageDecodeController::TracingInfo(), &task); |
200 EXPECT_TRUE(need_unref); | 173 EXPECT_TRUE(need_unref); |
201 EXPECT_TRUE(task); | 174 EXPECT_TRUE(task); |
202 EXPECT_EQ(task->dependencies().size(), 1u); | 175 EXPECT_EQ(task->dependencies().size(), 1u); |
203 EXPECT_TRUE(task->dependencies()[0]); | 176 EXPECT_TRUE(task->dependencies()[0]); |
204 | 177 |
205 // Run the decode. | 178 // Run the decode. |
206 ProcessTask(task->dependencies()[0].get()); | 179 TestTileTaskRunner::ProcessTask(task->dependencies()[0].get()); |
207 | 180 |
208 // Cancel the upload. | 181 // Cancel the upload. |
209 CancelTask(task.get()); | 182 TestTileTaskRunner::CancelTask(task.get()); |
210 CompleteTask(task.get()); | 183 TestTileTaskRunner::CompleteTask(task.get()); |
211 | 184 |
212 // Unref the image. | 185 // Unref the image. |
213 controller.UnrefImage(draw_image); | 186 controller.UnrefImage(draw_image); |
214 | 187 |
215 // Get the image again - we should have an upload task and a dependent decode | 188 // Get the image again - we should have an upload task and a dependent decode |
216 // task - this dependent task will typically just re-lock the image. | 189 // task - this dependent task will typically just re-lock the image. |
217 scoped_refptr<TileTask> another_task; | 190 scoped_refptr<TileTask> another_task; |
218 need_unref = controller.GetTaskForImageAndRef( | 191 need_unref = controller.GetTaskForImageAndRef( |
219 draw_image, ImageDecodeController::TracingInfo(), &another_task); | 192 draw_image, ImageDecodeController::TracingInfo(), &another_task); |
220 EXPECT_TRUE(need_unref); | 193 EXPECT_TRUE(need_unref); |
221 EXPECT_TRUE(another_task); | 194 EXPECT_TRUE(another_task); |
222 EXPECT_EQ(another_task->dependencies().size(), 1u); | 195 EXPECT_EQ(another_task->dependencies().size(), 1u); |
223 EXPECT_TRUE(task->dependencies()[0]); | 196 EXPECT_TRUE(task->dependencies()[0]); |
224 | 197 |
225 ProcessTask(another_task->dependencies()[0].get()); | 198 TestTileTaskRunner::ProcessTask(another_task->dependencies()[0].get()); |
226 ProcessTask(another_task.get()); | 199 TestTileTaskRunner::ProcessTask(another_task.get()); |
227 | 200 |
228 controller.UnrefImage(draw_image); | 201 controller.UnrefImage(draw_image); |
229 } | 202 } |
230 | 203 |
231 TEST(GpuImageDecodeControllerTest, GetTaskForImageAlreadyUploaded) { | 204 TEST(GpuImageDecodeControllerTest, GetTaskForImageAlreadyUploaded) { |
232 auto context_provider = TestContextProvider::Create(); | 205 auto context_provider = TestContextProvider::Create(); |
233 context_provider->BindToCurrentThread(); | 206 context_provider->BindToCurrentThread(); |
234 TestGpuImageDecodeController controller(context_provider.get()); | 207 TestGpuImageDecodeController controller(context_provider.get()); |
235 bool is_decomposable = true; | 208 bool is_decomposable = true; |
236 SkFilterQuality quality = kHigh_SkFilterQuality; | 209 SkFilterQuality quality = kHigh_SkFilterQuality; |
237 | 210 |
238 sk_sp<SkImage> image = CreateImage(100, 100); | 211 sk_sp<SkImage> image = CreateImage(100, 100); |
239 DrawImage draw_image(image, SkIRect::MakeWH(image->width(), image->height()), | 212 DrawImage draw_image(image, SkIRect::MakeWH(image->width(), image->height()), |
240 quality, | 213 quality, |
241 CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable)); | 214 CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable)); |
242 scoped_refptr<TileTask> task; | 215 scoped_refptr<TileTask> task; |
243 bool need_unref = controller.GetTaskForImageAndRef( | 216 bool need_unref = controller.GetTaskForImageAndRef( |
244 draw_image, ImageDecodeController::TracingInfo(), &task); | 217 draw_image, ImageDecodeController::TracingInfo(), &task); |
245 EXPECT_TRUE(need_unref); | 218 EXPECT_TRUE(need_unref); |
246 EXPECT_TRUE(task); | 219 EXPECT_TRUE(task); |
247 EXPECT_EQ(task->dependencies().size(), 1u); | 220 EXPECT_EQ(task->dependencies().size(), 1u); |
248 EXPECT_TRUE(task->dependencies()[0]); | 221 EXPECT_TRUE(task->dependencies()[0]); |
249 | 222 |
250 ProcessTask(task->dependencies()[0].get()); | 223 TestTileTaskRunner::ProcessTask(task->dependencies()[0].get()); |
251 ScheduleTask(task.get()); | 224 TestTileTaskRunner::ScheduleTask(task.get()); |
252 RunTask(task.get()); | 225 TestTileTaskRunner::RunTask(task.get()); |
253 | 226 |
254 scoped_refptr<TileTask> another_task; | 227 scoped_refptr<TileTask> another_task; |
255 need_unref = controller.GetTaskForImageAndRef( | 228 need_unref = controller.GetTaskForImageAndRef( |
256 draw_image, ImageDecodeController::TracingInfo(), &another_task); | 229 draw_image, ImageDecodeController::TracingInfo(), &another_task); |
257 EXPECT_TRUE(need_unref); | 230 EXPECT_TRUE(need_unref); |
258 EXPECT_FALSE(another_task); | 231 EXPECT_FALSE(another_task); |
259 | 232 |
260 CompleteTask(task.get()); | 233 TestTileTaskRunner::CompleteTask(task.get()); |
261 | 234 |
262 controller.UnrefImage(draw_image); | 235 controller.UnrefImage(draw_image); |
263 controller.UnrefImage(draw_image); | 236 controller.UnrefImage(draw_image); |
264 } | 237 } |
265 | 238 |
266 TEST(GpuImageDecodeControllerTest, GetTaskForImageCanceledGetsNewTask) { | 239 TEST(GpuImageDecodeControllerTest, GetTaskForImageCanceledGetsNewTask) { |
267 auto context_provider = TestContextProvider::Create(); | 240 auto context_provider = TestContextProvider::Create(); |
268 context_provider->BindToCurrentThread(); | 241 context_provider->BindToCurrentThread(); |
269 TestGpuImageDecodeController controller(context_provider.get()); | 242 TestGpuImageDecodeController controller(context_provider.get()); |
270 bool is_decomposable = true; | 243 bool is_decomposable = true; |
271 SkFilterQuality quality = kHigh_SkFilterQuality; | 244 SkFilterQuality quality = kHigh_SkFilterQuality; |
272 | 245 |
273 sk_sp<SkImage> image = CreateImage(100, 100); | 246 sk_sp<SkImage> image = CreateImage(100, 100); |
274 DrawImage draw_image(image, SkIRect::MakeWH(image->width(), image->height()), | 247 DrawImage draw_image(image, SkIRect::MakeWH(image->width(), image->height()), |
275 quality, | 248 quality, |
276 CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable)); | 249 CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable)); |
277 scoped_refptr<TileTask> task; | 250 scoped_refptr<TileTask> task; |
278 bool need_unref = controller.GetTaskForImageAndRef( | 251 bool need_unref = controller.GetTaskForImageAndRef( |
279 draw_image, ImageDecodeController::TracingInfo(), &task); | 252 draw_image, ImageDecodeController::TracingInfo(), &task); |
280 EXPECT_TRUE(need_unref); | 253 EXPECT_TRUE(need_unref); |
281 EXPECT_TRUE(task); | 254 EXPECT_TRUE(task); |
282 | 255 |
283 ProcessTask(task->dependencies()[0].get()); | 256 TestTileTaskRunner::ProcessTask(task->dependencies()[0].get()); |
284 | 257 |
285 scoped_refptr<TileTask> another_task; | 258 scoped_refptr<TileTask> another_task; |
286 need_unref = controller.GetTaskForImageAndRef( | 259 need_unref = controller.GetTaskForImageAndRef( |
287 draw_image, ImageDecodeController::TracingInfo(), &another_task); | 260 draw_image, ImageDecodeController::TracingInfo(), &another_task); |
288 EXPECT_TRUE(need_unref); | 261 EXPECT_TRUE(need_unref); |
289 EXPECT_TRUE(another_task.get() == task.get()); | 262 EXPECT_TRUE(another_task.get() == task.get()); |
290 | 263 |
291 // Didn't run the task, so cancel it. | 264 // Didn't run the task, so cancel it. |
292 CancelTask(task.get()); | 265 TestTileTaskRunner::CancelTask(task.get()); |
293 CompleteTask(task.get()); | 266 TestTileTaskRunner::CompleteTask(task.get()); |
294 | 267 |
295 // Fully cancel everything (so the raster would unref things). | 268 // Fully cancel everything (so the raster would unref things). |
296 controller.UnrefImage(draw_image); | 269 controller.UnrefImage(draw_image); |
297 controller.UnrefImage(draw_image); | 270 controller.UnrefImage(draw_image); |
298 | 271 |
299 // Here a new task is created. | 272 // Here a new task is created. |
300 scoped_refptr<TileTask> third_task; | 273 scoped_refptr<TileTask> third_task; |
301 need_unref = controller.GetTaskForImageAndRef( | 274 need_unref = controller.GetTaskForImageAndRef( |
302 draw_image, ImageDecodeController::TracingInfo(), &third_task); | 275 draw_image, ImageDecodeController::TracingInfo(), &third_task); |
303 EXPECT_TRUE(need_unref); | 276 EXPECT_TRUE(need_unref); |
304 EXPECT_TRUE(third_task); | 277 EXPECT_TRUE(third_task); |
305 EXPECT_FALSE(third_task.get() == task.get()); | 278 EXPECT_FALSE(third_task.get() == task.get()); |
306 | 279 |
307 ProcessTask(third_task->dependencies()[0].get()); | 280 TestTileTaskRunner::ProcessTask(third_task->dependencies()[0].get()); |
308 ProcessTask(third_task.get()); | 281 TestTileTaskRunner::ProcessTask(third_task.get()); |
309 | 282 |
310 controller.UnrefImage(draw_image); | 283 controller.UnrefImage(draw_image); |
311 } | 284 } |
312 | 285 |
313 TEST(GpuImageDecodeControllerTest, | 286 TEST(GpuImageDecodeControllerTest, |
314 GetTaskForImageCanceledWhileReffedGetsNewTask) { | 287 GetTaskForImageCanceledWhileReffedGetsNewTask) { |
315 auto context_provider = TestContextProvider::Create(); | 288 auto context_provider = TestContextProvider::Create(); |
316 context_provider->BindToCurrentThread(); | 289 context_provider->BindToCurrentThread(); |
317 TestGpuImageDecodeController controller(context_provider.get()); | 290 TestGpuImageDecodeController controller(context_provider.get()); |
318 bool is_decomposable = true; | 291 bool is_decomposable = true; |
319 SkFilterQuality quality = kHigh_SkFilterQuality; | 292 SkFilterQuality quality = kHigh_SkFilterQuality; |
320 | 293 |
321 sk_sp<SkImage> image = CreateImage(100, 100); | 294 sk_sp<SkImage> image = CreateImage(100, 100); |
322 DrawImage draw_image(image, SkIRect::MakeWH(image->width(), image->height()), | 295 DrawImage draw_image(image, SkIRect::MakeWH(image->width(), image->height()), |
323 quality, | 296 quality, |
324 CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable)); | 297 CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable)); |
325 scoped_refptr<TileTask> task; | 298 scoped_refptr<TileTask> task; |
326 bool need_unref = controller.GetTaskForImageAndRef( | 299 bool need_unref = controller.GetTaskForImageAndRef( |
327 draw_image, ImageDecodeController::TracingInfo(), &task); | 300 draw_image, ImageDecodeController::TracingInfo(), &task); |
328 EXPECT_TRUE(need_unref); | 301 EXPECT_TRUE(need_unref); |
329 EXPECT_TRUE(task); | 302 EXPECT_TRUE(task); |
330 | 303 |
331 ProcessTask(task->dependencies()[0].get()); | 304 TestTileTaskRunner::ProcessTask(task->dependencies()[0].get()); |
332 | 305 |
333 scoped_refptr<TileTask> another_task; | 306 scoped_refptr<TileTask> another_task; |
334 need_unref = controller.GetTaskForImageAndRef( | 307 need_unref = controller.GetTaskForImageAndRef( |
335 draw_image, ImageDecodeController::TracingInfo(), &another_task); | 308 draw_image, ImageDecodeController::TracingInfo(), &another_task); |
336 EXPECT_TRUE(need_unref); | 309 EXPECT_TRUE(need_unref); |
337 EXPECT_TRUE(another_task.get() == task.get()); | 310 EXPECT_TRUE(another_task.get() == task.get()); |
338 | 311 |
339 // Didn't run the task, so cancel it. | 312 // Didn't run the task, so cancel it. |
340 CancelTask(task.get()); | 313 TestTileTaskRunner::CancelTask(task.get()); |
341 CompleteTask(task.get()); | 314 TestTileTaskRunner::CompleteTask(task.get()); |
342 | 315 |
343 // Note that here, everything is reffed, but a new task is created. This is | 316 // Note that here, everything is reffed, but a new task is created. This is |
344 // possible with repeated schedule/cancel operations. | 317 // possible with repeated schedule/cancel operations. |
345 scoped_refptr<TileTask> third_task; | 318 scoped_refptr<TileTask> third_task; |
346 need_unref = controller.GetTaskForImageAndRef( | 319 need_unref = controller.GetTaskForImageAndRef( |
347 draw_image, ImageDecodeController::TracingInfo(), &third_task); | 320 draw_image, ImageDecodeController::TracingInfo(), &third_task); |
348 EXPECT_TRUE(need_unref); | 321 EXPECT_TRUE(need_unref); |
349 EXPECT_TRUE(third_task); | 322 EXPECT_TRUE(third_task); |
350 EXPECT_FALSE(third_task.get() == task.get()); | 323 EXPECT_FALSE(third_task.get() == task.get()); |
351 | 324 |
352 ProcessTask(third_task->dependencies()[0].get()); | 325 TestTileTaskRunner::ProcessTask(third_task->dependencies()[0].get()); |
353 ProcessTask(third_task.get()); | 326 TestTileTaskRunner::ProcessTask(third_task.get()); |
354 | 327 |
355 // 3 Unrefs! | 328 // 3 Unrefs! |
356 controller.UnrefImage(draw_image); | 329 controller.UnrefImage(draw_image); |
357 controller.UnrefImage(draw_image); | 330 controller.UnrefImage(draw_image); |
358 controller.UnrefImage(draw_image); | 331 controller.UnrefImage(draw_image); |
359 } | 332 } |
360 | 333 |
361 TEST(GpuImageDecodeControllerTest, NoTaskForImageAlreadyFailedDecoding) { | 334 TEST(GpuImageDecodeControllerTest, NoTaskForImageAlreadyFailedDecoding) { |
362 auto context_provider = TestContextProvider::Create(); | 335 auto context_provider = TestContextProvider::Create(); |
363 context_provider->BindToCurrentThread(); | 336 context_provider->BindToCurrentThread(); |
364 TestGpuImageDecodeController controller(context_provider.get()); | 337 TestGpuImageDecodeController controller(context_provider.get()); |
365 bool is_decomposable = true; | 338 bool is_decomposable = true; |
366 SkFilterQuality quality = kHigh_SkFilterQuality; | 339 SkFilterQuality quality = kHigh_SkFilterQuality; |
367 | 340 |
368 sk_sp<SkImage> image = CreateImage(100, 100); | 341 sk_sp<SkImage> image = CreateImage(100, 100); |
369 DrawImage draw_image(image, SkIRect::MakeWH(image->width(), image->height()), | 342 DrawImage draw_image(image, SkIRect::MakeWH(image->width(), image->height()), |
370 quality, | 343 quality, |
371 CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable)); | 344 CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable)); |
372 scoped_refptr<TileTask> task; | 345 scoped_refptr<TileTask> task; |
373 bool need_unref = controller.GetTaskForImageAndRef( | 346 bool need_unref = controller.GetTaskForImageAndRef( |
374 draw_image, ImageDecodeController::TracingInfo(), &task); | 347 draw_image, ImageDecodeController::TracingInfo(), &task); |
375 EXPECT_TRUE(need_unref); | 348 EXPECT_TRUE(need_unref); |
376 EXPECT_TRUE(task); | 349 EXPECT_TRUE(task); |
377 | 350 |
378 ProcessTask(task->dependencies()[0].get()); | 351 TestTileTaskRunner::ProcessTask(task->dependencies()[0].get()); |
379 // Didn't run the task, so cancel it. | 352 // Didn't run the task, so cancel it. |
380 CancelTask(task.get()); | 353 TestTileTaskRunner::CancelTask(task.get()); |
381 CompleteTask(task.get()); | 354 TestTileTaskRunner::CompleteTask(task.get()); |
382 | 355 |
383 controller.SetImageDecodingFailedForTesting(draw_image); | 356 controller.SetImageDecodingFailedForTesting(draw_image); |
384 | 357 |
385 scoped_refptr<TileTask> another_task; | 358 scoped_refptr<TileTask> another_task; |
386 need_unref = controller.GetTaskForImageAndRef( | 359 need_unref = controller.GetTaskForImageAndRef( |
387 draw_image, ImageDecodeController::TracingInfo(), &another_task); | 360 draw_image, ImageDecodeController::TracingInfo(), &another_task); |
388 EXPECT_FALSE(need_unref); | 361 EXPECT_FALSE(need_unref); |
389 EXPECT_EQ(another_task.get(), nullptr); | 362 EXPECT_EQ(another_task.get(), nullptr); |
390 | 363 |
391 controller.UnrefImage(draw_image); | 364 controller.UnrefImage(draw_image); |
392 } | 365 } |
393 | 366 |
394 TEST(GpuImageDecodeControllerTest, GetDecodedImageForDraw) { | 367 TEST(GpuImageDecodeControllerTest, GetDecodedImageForDraw) { |
395 auto context_provider = TestContextProvider::Create(); | 368 auto context_provider = TestContextProvider::Create(); |
396 context_provider->BindToCurrentThread(); | 369 context_provider->BindToCurrentThread(); |
397 TestGpuImageDecodeController controller(context_provider.get()); | 370 TestGpuImageDecodeController controller(context_provider.get()); |
398 bool is_decomposable = true; | 371 bool is_decomposable = true; |
399 SkFilterQuality quality = kHigh_SkFilterQuality; | 372 SkFilterQuality quality = kHigh_SkFilterQuality; |
400 | 373 |
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 TestTileTaskRunner::ProcessTask(task->dependencies()[0].get()); |
412 ProcessTask(task.get()); | 385 TestTileTaskRunner::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 EXPECT_FALSE(controller.DiscardableIsLockedForTesting(draw_image)); | 395 EXPECT_FALSE(controller.DiscardableIsLockedForTesting(draw_image)); |
(...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 TestTileTaskRunner::ProcessTask(task->dependencies()[0].get()); |
446 ProcessTask(task.get()); | 419 TestTileTaskRunner::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 EXPECT_TRUE(controller.DiscardableIsLockedForTesting(draw_image)); | 429 EXPECT_TRUE(controller.DiscardableIsLockedForTesting(draw_image)); |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
680 image, SkIRect::MakeXYWH(0, 0, image->width(), image->height()), quality, | 653 image, SkIRect::MakeXYWH(0, 0, image->width(), image->height()), quality, |
681 CreateMatrix(SkSize::Make(1.f, 1.f), is_decomposable)); | 654 CreateMatrix(SkSize::Make(1.f, 1.f), is_decomposable)); |
682 | 655 |
683 scoped_refptr<TileTask> task; | 656 scoped_refptr<TileTask> task; |
684 bool need_unref = controller.GetTaskForImageAndRef( | 657 bool need_unref = controller.GetTaskForImageAndRef( |
685 draw_image, ImageDecodeController::TracingInfo(), &task); | 658 draw_image, ImageDecodeController::TracingInfo(), &task); |
686 EXPECT_NE(0u, controller.GetBytesUsedForTesting()); | 659 EXPECT_NE(0u, controller.GetBytesUsedForTesting()); |
687 EXPECT_TRUE(task); | 660 EXPECT_TRUE(task); |
688 EXPECT_TRUE(need_unref); | 661 EXPECT_TRUE(need_unref); |
689 | 662 |
690 CancelTask(task->dependencies()[0].get()); | 663 TestTileTaskRunner::CancelTask(task->dependencies()[0].get()); |
691 CompleteTask(task->dependencies()[0].get()); | 664 TestTileTaskRunner::CompleteTask(task->dependencies()[0].get()); |
692 CancelTask(task.get()); | 665 TestTileTaskRunner::CancelTask(task.get()); |
693 CompleteTask(task.get()); | 666 TestTileTaskRunner::CompleteTask(task.get()); |
694 | 667 |
695 controller.UnrefImage(draw_image); | 668 controller.UnrefImage(draw_image); |
696 EXPECT_EQ(0u, controller.GetBytesUsedForTesting()); | 669 EXPECT_EQ(0u, controller.GetBytesUsedForTesting()); |
697 } | 670 } |
698 | 671 |
699 TEST(GpuImageDecodeControllerTest, ShouldAggressivelyFreeResources) { | 672 TEST(GpuImageDecodeControllerTest, ShouldAggressivelyFreeResources) { |
700 auto context_provider = TestContextProvider::Create(); | 673 auto context_provider = TestContextProvider::Create(); |
701 context_provider->BindToCurrentThread(); | 674 context_provider->BindToCurrentThread(); |
702 TestGpuImageDecodeController controller(context_provider.get()); | 675 TestGpuImageDecodeController controller(context_provider.get()); |
703 bool is_decomposable = true; | 676 bool is_decomposable = true; |
704 SkFilterQuality quality = kHigh_SkFilterQuality; | 677 SkFilterQuality quality = kHigh_SkFilterQuality; |
705 | 678 |
706 sk_sp<SkImage> image = CreateImage(100, 100); | 679 sk_sp<SkImage> image = CreateImage(100, 100); |
707 DrawImage draw_image(image, SkIRect::MakeWH(image->width(), image->height()), | 680 DrawImage draw_image(image, SkIRect::MakeWH(image->width(), image->height()), |
708 quality, | 681 quality, |
709 CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable)); | 682 CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable)); |
710 scoped_refptr<TileTask> task; | 683 scoped_refptr<TileTask> task; |
711 { | 684 { |
712 bool need_unref = controller.GetTaskForImageAndRef( | 685 bool need_unref = controller.GetTaskForImageAndRef( |
713 draw_image, ImageDecodeController::TracingInfo(), &task); | 686 draw_image, ImageDecodeController::TracingInfo(), &task); |
714 EXPECT_TRUE(need_unref); | 687 EXPECT_TRUE(need_unref); |
715 EXPECT_TRUE(task); | 688 EXPECT_TRUE(task); |
716 } | 689 } |
717 | 690 |
718 ProcessTask(task->dependencies()[0].get()); | 691 TestTileTaskRunner::ProcessTask(task->dependencies()[0].get()); |
719 ProcessTask(task.get()); | 692 TestTileTaskRunner::ProcessTask(task.get()); |
720 | 693 |
721 controller.UnrefImage(draw_image); | 694 controller.UnrefImage(draw_image); |
722 | 695 |
723 // We should now have data image in our cache. | 696 // We should now have data image in our cache. |
724 DCHECK_GT(controller.GetBytesUsedForTesting(), 0u); | 697 DCHECK_GT(controller.GetBytesUsedForTesting(), 0u); |
725 | 698 |
726 // Tell our controller to aggressively free resources. | 699 // Tell our controller to aggressively free resources. |
727 controller.SetShouldAggressivelyFreeResources(true); | 700 controller.SetShouldAggressivelyFreeResources(true); |
728 DCHECK_EQ(0u, controller.GetBytesUsedForTesting()); | 701 DCHECK_EQ(0u, controller.GetBytesUsedForTesting()); |
729 | 702 |
730 // Attempting to upload a new image should result in at-raster decode. | 703 // Attempting to upload a new image should result in at-raster decode. |
731 { | 704 { |
732 bool need_unref = controller.GetTaskForImageAndRef( | 705 bool need_unref = controller.GetTaskForImageAndRef( |
733 draw_image, ImageDecodeController::TracingInfo(), &task); | 706 draw_image, ImageDecodeController::TracingInfo(), &task); |
734 EXPECT_FALSE(need_unref); | 707 EXPECT_FALSE(need_unref); |
735 EXPECT_FALSE(task); | 708 EXPECT_FALSE(task); |
736 } | 709 } |
737 | 710 |
738 // We now tell the controller to not aggressively free resources. Uploads | 711 // We now tell the controller to not aggressively free resources. Uploads |
739 // should work again. | 712 // should work again. |
740 controller.SetShouldAggressivelyFreeResources(false); | 713 controller.SetShouldAggressivelyFreeResources(false); |
741 { | 714 { |
742 bool need_unref = controller.GetTaskForImageAndRef( | 715 bool need_unref = controller.GetTaskForImageAndRef( |
743 draw_image, ImageDecodeController::TracingInfo(), &task); | 716 draw_image, ImageDecodeController::TracingInfo(), &task); |
744 EXPECT_TRUE(need_unref); | 717 EXPECT_TRUE(need_unref); |
745 EXPECT_TRUE(task); | 718 EXPECT_TRUE(task); |
746 } | 719 } |
747 | 720 |
748 ProcessTask(task->dependencies()[0].get()); | 721 TestTileTaskRunner::ProcessTask(task->dependencies()[0].get()); |
749 ProcessTask(task.get()); | 722 TestTileTaskRunner::ProcessTask(task.get()); |
750 | 723 |
751 // The image should be in our cache after un-ref. | 724 // The image should be in our cache after un-ref. |
752 controller.UnrefImage(draw_image); | 725 controller.UnrefImage(draw_image); |
753 DCHECK_GT(controller.GetBytesUsedForTesting(), 0u); | 726 DCHECK_GT(controller.GetBytesUsedForTesting(), 0u); |
754 } | 727 } |
755 | 728 |
756 } // namespace | 729 } // namespace |
757 } // namespace cc | 730 } // namespace cc |
OLD | NEW |