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/task.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 | 11 |
12 namespace cc { | 12 namespace cc { |
13 namespace { | 13 namespace { |
14 | 14 |
15 skia::RefPtr<SkImage> CreateImage(int width, int height) { | 15 skia::RefPtr<SkImage> CreateImage(int width, int height) { |
16 SkImageInfo info = SkImageInfo::MakeN32Premul(width, height); | 16 SkImageInfo info = SkImageInfo::MakeN32Premul(width, height); |
17 SkBitmap bitmap; | 17 SkBitmap bitmap; |
18 bitmap.allocPixels(info); | 18 bitmap.allocPixels(info); |
19 return skia::AdoptRef(SkImage::NewFromBitmap(bitmap)); | 19 return skia::AdoptRef(SkImage::NewFromBitmap(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 RunTask(ImageDecodeTask* task) { | 34 void RunTask(Task* task) { |
35 task->WillRun(); | 35 task->WillRun(); |
36 task->RunOnWorkerThread(); | 36 task->RunOnWorkerThread(); |
37 task->DidRun(); | 37 task->DidRun(); |
38 } | 38 } |
39 | 39 |
40 void CompleteTask(GpuImageDecodeController* controller, ImageDecodeTask* task) { | 40 void CompleteTask(GpuImageDecodeController* controller, Task* task) { |
41 if (task->GetTaskTypeId() == TASK_TYPE_IMAGE_DECODE) | 41 if (task->GetTaskType() == TASK_TYPE_IMAGE_DECODE) |
42 controller->ImageDecodeTaskCompleted(task); | 42 controller->ImageDecodeTaskCompleted(task); |
43 else if (task->GetTaskTypeId() == TASK_TYPE_IMAGE_UPLOAD) | 43 else if (task->GetTaskType() == TASK_TYPE_IMAGE_UPLOAD) |
44 controller->ImageUploadTaskCompleted(task); | 44 controller->ImageUploadTaskCompleted(task); |
45 | 45 |
46 task->DidComplete(); | 46 task->DidComplete(); |
47 } | 47 } |
48 | 48 |
49 void ProcessTask(GpuImageDecodeController* controller, ImageDecodeTask* task) { | 49 void ProcessTask(GpuImageDecodeController* controller, Task* task) { |
50 RunTask(task); | 50 RunTask(task); |
51 CompleteTask(controller, task); | 51 CompleteTask(controller, task); |
52 } | 52 } |
53 | 53 |
54 TEST(GpuImageDecodeControllerTest, GetTaskForImageSameImage) { | 54 TEST(GpuImageDecodeControllerTest, GetTaskForImageSameImage) { |
55 auto context_provider = TestContextProvider::Create(); | 55 auto context_provider = TestContextProvider::Create(); |
56 context_provider->BindToCurrentThread(); | 56 context_provider->BindToCurrentThread(); |
57 GpuImageDecodeController controller(context_provider.get(), | 57 GpuImageDecodeController controller(context_provider.get(), |
58 ResourceFormat::RGBA_8888); | 58 ResourceFormat::RGBA_8888); |
59 skia::RefPtr<SkImage> image = CreateImage(100, 100); | 59 skia::RefPtr<SkImage> image = CreateImage(100, 100); |
60 bool is_decomposable = true; | 60 bool is_decomposable = true; |
61 SkFilterQuality quality = kHigh_SkFilterQuality; | 61 SkFilterQuality quality = kHigh_SkFilterQuality; |
62 uint64_t prepare_tiles_id = 1; | 62 uint64_t prepare_tiles_id = 1; |
63 | 63 |
64 DrawImage draw_image( | 64 DrawImage draw_image( |
65 image.get(), SkIRect::MakeWH(image->width(), image->height()), quality, | 65 image.get(), SkIRect::MakeWH(image->width(), image->height()), quality, |
66 CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable)); | 66 CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable)); |
67 scoped_refptr<ImageDecodeTask> task; | 67 scoped_refptr<Task> task; |
68 bool need_unref = | 68 bool need_unref = |
69 controller.GetTaskForImageAndRef(draw_image, prepare_tiles_id, &task); | 69 controller.GetTaskForImageAndRef(draw_image, prepare_tiles_id, &task); |
70 EXPECT_TRUE(need_unref); | 70 EXPECT_TRUE(need_unref); |
71 EXPECT_TRUE(task); | 71 EXPECT_TRUE(task); |
72 | 72 |
73 DrawImage another_draw_image( | 73 DrawImage another_draw_image( |
74 image.get(), SkIRect::MakeWH(image->width(), image->height()), quality, | 74 image.get(), SkIRect::MakeWH(image->width(), image->height()), quality, |
75 CreateMatrix(SkSize::Make(1.5f, 1.5f), is_decomposable)); | 75 CreateMatrix(SkSize::Make(1.5f, 1.5f), is_decomposable)); |
76 scoped_refptr<ImageDecodeTask> another_task; | 76 scoped_refptr<Task> another_task; |
77 need_unref = controller.GetTaskForImageAndRef( | 77 need_unref = controller.GetTaskForImageAndRef( |
78 another_draw_image, prepare_tiles_id, &another_task); | 78 another_draw_image, prepare_tiles_id, &another_task); |
79 EXPECT_TRUE(need_unref); | 79 EXPECT_TRUE(need_unref); |
80 EXPECT_TRUE(task.get() == another_task.get()); | 80 EXPECT_TRUE(task.get() == another_task.get()); |
81 | 81 |
82 ProcessTask(&controller, task->dependency().get()); | 82 ProcessTask(&controller, task->dependencies()[0].get()); |
83 ProcessTask(&controller, task.get()); | 83 ProcessTask(&controller, task.get()); |
84 | 84 |
85 controller.UnrefImage(draw_image); | 85 controller.UnrefImage(draw_image); |
86 controller.UnrefImage(draw_image); | 86 controller.UnrefImage(draw_image); |
87 } | 87 } |
88 | 88 |
89 TEST(GpuImageDecodeControllerTest, GetTaskForImageDifferentImage) { | 89 TEST(GpuImageDecodeControllerTest, GetTaskForImageDifferentImage) { |
90 auto context_provider = TestContextProvider::Create(); | 90 auto context_provider = TestContextProvider::Create(); |
91 context_provider->BindToCurrentThread(); | 91 context_provider->BindToCurrentThread(); |
92 GpuImageDecodeController controller(context_provider.get(), | 92 GpuImageDecodeController controller(context_provider.get(), |
93 ResourceFormat::RGBA_8888); | 93 ResourceFormat::RGBA_8888); |
94 bool is_decomposable = true; | 94 bool is_decomposable = true; |
95 uint64_t prepare_tiles_id = 1; | 95 uint64_t prepare_tiles_id = 1; |
96 SkFilterQuality quality = kHigh_SkFilterQuality; | 96 SkFilterQuality quality = kHigh_SkFilterQuality; |
97 | 97 |
98 skia::RefPtr<SkImage> first_image = CreateImage(100, 100); | 98 skia::RefPtr<SkImage> first_image = CreateImage(100, 100); |
99 DrawImage first_draw_image( | 99 DrawImage first_draw_image( |
100 first_image.get(), | 100 first_image.get(), |
101 SkIRect::MakeWH(first_image->width(), first_image->height()), quality, | 101 SkIRect::MakeWH(first_image->width(), first_image->height()), quality, |
102 CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable)); | 102 CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable)); |
103 scoped_refptr<ImageDecodeTask> first_task; | 103 scoped_refptr<Task> first_task; |
104 bool need_unref = controller.GetTaskForImageAndRef( | 104 bool need_unref = controller.GetTaskForImageAndRef( |
105 first_draw_image, prepare_tiles_id, &first_task); | 105 first_draw_image, prepare_tiles_id, &first_task); |
106 EXPECT_TRUE(need_unref); | 106 EXPECT_TRUE(need_unref); |
107 EXPECT_TRUE(first_task); | 107 EXPECT_TRUE(first_task); |
108 | 108 |
109 skia::RefPtr<SkImage> second_image = CreateImage(100, 100); | 109 skia::RefPtr<SkImage> second_image = CreateImage(100, 100); |
110 DrawImage second_draw_image( | 110 DrawImage second_draw_image( |
111 second_image.get(), | 111 second_image.get(), |
112 SkIRect::MakeWH(second_image->width(), second_image->height()), quality, | 112 SkIRect::MakeWH(second_image->width(), second_image->height()), quality, |
113 CreateMatrix(SkSize::Make(0.25f, 0.25f), is_decomposable)); | 113 CreateMatrix(SkSize::Make(0.25f, 0.25f), is_decomposable)); |
114 scoped_refptr<ImageDecodeTask> second_task; | 114 scoped_refptr<Task> second_task; |
115 need_unref = controller.GetTaskForImageAndRef(second_draw_image, | 115 need_unref = controller.GetTaskForImageAndRef(second_draw_image, |
116 prepare_tiles_id, &second_task); | 116 prepare_tiles_id, &second_task); |
117 EXPECT_TRUE(need_unref); | 117 EXPECT_TRUE(need_unref); |
118 EXPECT_TRUE(second_task); | 118 EXPECT_TRUE(second_task); |
119 EXPECT_TRUE(first_task.get() != second_task.get()); | 119 EXPECT_TRUE(first_task.get() != second_task.get()); |
120 | 120 |
121 ProcessTask(&controller, first_task->dependency().get()); | 121 ProcessTask(&controller, first_task->dependencies()[0].get()); |
122 ProcessTask(&controller, first_task.get()); | 122 ProcessTask(&controller, first_task.get()); |
123 ProcessTask(&controller, second_task->dependency().get()); | 123 ProcessTask(&controller, second_task->dependencies()[0].get()); |
124 ProcessTask(&controller, second_task.get()); | 124 ProcessTask(&controller, second_task.get()); |
125 | 125 |
126 controller.UnrefImage(first_draw_image); | 126 controller.UnrefImage(first_draw_image); |
127 controller.UnrefImage(second_draw_image); | 127 controller.UnrefImage(second_draw_image); |
128 } | 128 } |
129 | 129 |
130 TEST(GpuImageDecodeControllerTest, GetTaskForImageAlreadyDecoded) { | 130 TEST(GpuImageDecodeControllerTest, GetTaskForImageAlreadyDecoded) { |
131 auto context_provider = TestContextProvider::Create(); | 131 auto context_provider = TestContextProvider::Create(); |
132 context_provider->BindToCurrentThread(); | 132 context_provider->BindToCurrentThread(); |
133 GpuImageDecodeController controller(context_provider.get(), | 133 GpuImageDecodeController controller(context_provider.get(), |
134 ResourceFormat::RGBA_8888); | 134 ResourceFormat::RGBA_8888); |
135 bool is_decomposable = true; | 135 bool is_decomposable = true; |
136 uint64_t prepare_tiles_id = 1; | 136 uint64_t prepare_tiles_id = 1; |
137 SkFilterQuality quality = kHigh_SkFilterQuality; | 137 SkFilterQuality quality = kHigh_SkFilterQuality; |
138 | 138 |
139 skia::RefPtr<SkImage> image = CreateImage(100, 100); | 139 skia::RefPtr<SkImage> image = CreateImage(100, 100); |
140 DrawImage draw_image( | 140 DrawImage draw_image( |
141 image.get(), SkIRect::MakeWH(image->width(), image->height()), quality, | 141 image.get(), SkIRect::MakeWH(image->width(), image->height()), quality, |
142 CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable)); | 142 CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable)); |
143 scoped_refptr<ImageDecodeTask> task; | 143 scoped_refptr<Task> task; |
144 bool need_unref = | 144 bool need_unref = |
145 controller.GetTaskForImageAndRef(draw_image, prepare_tiles_id, &task); | 145 controller.GetTaskForImageAndRef(draw_image, prepare_tiles_id, &task); |
146 EXPECT_TRUE(need_unref); | 146 EXPECT_TRUE(need_unref); |
147 EXPECT_TRUE(task); | 147 EXPECT_TRUE(task); |
148 EXPECT_TRUE(task->dependency()); | 148 EXPECT_EQ(task->dependencies().size(), 1u); |
| 149 EXPECT_TRUE(task->dependencies()[0]); |
149 | 150 |
150 ProcessTask(&controller, task->dependency().get()); | 151 ProcessTask(&controller, task->dependencies()[0].get()); |
151 RunTask(task.get()); | 152 RunTask(task.get()); |
152 | 153 |
153 scoped_refptr<ImageDecodeTask> another_task; | 154 scoped_refptr<Task> another_task; |
154 need_unref = controller.GetTaskForImageAndRef(draw_image, prepare_tiles_id, | 155 need_unref = controller.GetTaskForImageAndRef(draw_image, prepare_tiles_id, |
155 &another_task); | 156 &another_task); |
156 EXPECT_TRUE(need_unref); | 157 EXPECT_TRUE(need_unref); |
157 EXPECT_FALSE(another_task); | 158 EXPECT_FALSE(another_task); |
158 | 159 |
159 CompleteTask(&controller, task.get()); | 160 CompleteTask(&controller, task.get()); |
160 | 161 |
161 controller.UnrefImage(draw_image); | 162 controller.UnrefImage(draw_image); |
162 controller.UnrefImage(draw_image); | 163 controller.UnrefImage(draw_image); |
163 } | 164 } |
164 | 165 |
165 TEST(GpuImageDecodeControllerTest, GetTaskForImageCanceledGetsNewTask) { | 166 TEST(GpuImageDecodeControllerTest, GetTaskForImageCanceledGetsNewTask) { |
166 auto context_provider = TestContextProvider::Create(); | 167 auto context_provider = TestContextProvider::Create(); |
167 context_provider->BindToCurrentThread(); | 168 context_provider->BindToCurrentThread(); |
168 GpuImageDecodeController controller(context_provider.get(), | 169 GpuImageDecodeController controller(context_provider.get(), |
169 ResourceFormat::RGBA_8888); | 170 ResourceFormat::RGBA_8888); |
170 bool is_decomposable = true; | 171 bool is_decomposable = true; |
171 uint64_t prepare_tiles_id = 1; | 172 uint64_t prepare_tiles_id = 1; |
172 SkFilterQuality quality = kHigh_SkFilterQuality; | 173 SkFilterQuality quality = kHigh_SkFilterQuality; |
173 | 174 |
174 skia::RefPtr<SkImage> image = CreateImage(100, 100); | 175 skia::RefPtr<SkImage> image = CreateImage(100, 100); |
175 DrawImage draw_image( | 176 DrawImage draw_image( |
176 image.get(), SkIRect::MakeWH(image->width(), image->height()), quality, | 177 image.get(), SkIRect::MakeWH(image->width(), image->height()), quality, |
177 CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable)); | 178 CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable)); |
178 scoped_refptr<ImageDecodeTask> task; | 179 scoped_refptr<Task> task; |
179 bool need_unref = | 180 bool need_unref = |
180 controller.GetTaskForImageAndRef(draw_image, prepare_tiles_id, &task); | 181 controller.GetTaskForImageAndRef(draw_image, prepare_tiles_id, &task); |
181 EXPECT_TRUE(need_unref); | 182 EXPECT_TRUE(need_unref); |
182 EXPECT_TRUE(task); | 183 EXPECT_TRUE(task); |
183 | 184 |
184 ProcessTask(&controller, task->dependency().get()); | 185 ProcessTask(&controller, task->dependencies()[0].get()); |
185 | 186 |
186 scoped_refptr<ImageDecodeTask> another_task; | 187 scoped_refptr<Task> another_task; |
187 need_unref = controller.GetTaskForImageAndRef(draw_image, prepare_tiles_id, | 188 need_unref = controller.GetTaskForImageAndRef(draw_image, prepare_tiles_id, |
188 &another_task); | 189 &another_task); |
189 EXPECT_TRUE(need_unref); | 190 EXPECT_TRUE(need_unref); |
190 EXPECT_TRUE(another_task.get() == task.get()); | 191 EXPECT_TRUE(another_task.get() == task.get()); |
191 | 192 |
192 // Didn't run the task, complete it (it was canceled). | 193 // Didn't run the task, complete it (it was canceled). |
193 CompleteTask(&controller, task.get()); | 194 CompleteTask(&controller, task.get()); |
194 | 195 |
195 // Fully cancel everything (so the raster would unref things). | 196 // Fully cancel everything (so the raster would unref things). |
196 controller.UnrefImage(draw_image); | 197 controller.UnrefImage(draw_image); |
197 controller.UnrefImage(draw_image); | 198 controller.UnrefImage(draw_image); |
198 | 199 |
199 // Here a new task is created. | 200 // Here a new task is created. |
200 scoped_refptr<ImageDecodeTask> third_task; | 201 scoped_refptr<Task> third_task; |
201 need_unref = controller.GetTaskForImageAndRef(draw_image, prepare_tiles_id, | 202 need_unref = controller.GetTaskForImageAndRef(draw_image, prepare_tiles_id, |
202 &third_task); | 203 &third_task); |
203 EXPECT_TRUE(need_unref); | 204 EXPECT_TRUE(need_unref); |
204 EXPECT_TRUE(third_task); | 205 EXPECT_TRUE(third_task); |
205 EXPECT_FALSE(third_task.get() == task.get()); | 206 EXPECT_FALSE(third_task.get() == task.get()); |
206 | 207 |
207 ProcessTask(&controller, third_task->dependency().get()); | 208 ProcessTask(&controller, third_task->dependencies()[0].get()); |
208 ProcessTask(&controller, third_task.get()); | 209 ProcessTask(&controller, third_task.get()); |
209 | 210 |
210 controller.UnrefImage(draw_image); | 211 controller.UnrefImage(draw_image); |
211 } | 212 } |
212 | 213 |
213 TEST(GpuImageDecodeControllerTest, | 214 TEST(GpuImageDecodeControllerTest, |
214 GetTaskForImageCanceledWhileReffedGetsNewTask) { | 215 GetTaskForImageCanceledWhileReffedGetsNewTask) { |
215 auto context_provider = TestContextProvider::Create(); | 216 auto context_provider = TestContextProvider::Create(); |
216 context_provider->BindToCurrentThread(); | 217 context_provider->BindToCurrentThread(); |
217 GpuImageDecodeController controller(context_provider.get(), | 218 GpuImageDecodeController controller(context_provider.get(), |
218 ResourceFormat::RGBA_8888); | 219 ResourceFormat::RGBA_8888); |
219 bool is_decomposable = true; | 220 bool is_decomposable = true; |
220 uint64_t prepare_tiles_id = 1; | 221 uint64_t prepare_tiles_id = 1; |
221 SkFilterQuality quality = kHigh_SkFilterQuality; | 222 SkFilterQuality quality = kHigh_SkFilterQuality; |
222 | 223 |
223 skia::RefPtr<SkImage> image = CreateImage(100, 100); | 224 skia::RefPtr<SkImage> image = CreateImage(100, 100); |
224 DrawImage draw_image( | 225 DrawImage draw_image( |
225 image.get(), SkIRect::MakeWH(image->width(), image->height()), quality, | 226 image.get(), SkIRect::MakeWH(image->width(), image->height()), quality, |
226 CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable)); | 227 CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable)); |
227 scoped_refptr<ImageDecodeTask> task; | 228 scoped_refptr<Task> task; |
228 bool need_unref = | 229 bool need_unref = |
229 controller.GetTaskForImageAndRef(draw_image, prepare_tiles_id, &task); | 230 controller.GetTaskForImageAndRef(draw_image, prepare_tiles_id, &task); |
230 EXPECT_TRUE(need_unref); | 231 EXPECT_TRUE(need_unref); |
231 EXPECT_TRUE(task); | 232 EXPECT_TRUE(task); |
232 | 233 |
233 ProcessTask(&controller, task->dependency().get()); | 234 ProcessTask(&controller, task->dependencies()[0].get()); |
234 | 235 |
235 scoped_refptr<ImageDecodeTask> another_task; | 236 scoped_refptr<Task> another_task; |
236 need_unref = controller.GetTaskForImageAndRef(draw_image, prepare_tiles_id, | 237 need_unref = controller.GetTaskForImageAndRef(draw_image, prepare_tiles_id, |
237 &another_task); | 238 &another_task); |
238 EXPECT_TRUE(need_unref); | 239 EXPECT_TRUE(need_unref); |
239 EXPECT_TRUE(another_task.get() == task.get()); | 240 EXPECT_TRUE(another_task.get() == task.get()); |
240 | 241 |
241 // Didn't run the task, complete it (it was canceled). | 242 // Didn't run the task, complete it (it was canceled). |
242 CompleteTask(&controller, task.get()); | 243 CompleteTask(&controller, task.get()); |
243 | 244 |
244 // Note that here, everything is reffed, but a new task is created. This is | 245 // Note that here, everything is reffed, but a new task is created. This is |
245 // possible with repeated schedule/cancel operations. | 246 // possible with repeated schedule/cancel operations. |
246 scoped_refptr<ImageDecodeTask> third_task; | 247 scoped_refptr<Task> third_task; |
247 need_unref = controller.GetTaskForImageAndRef(draw_image, prepare_tiles_id, | 248 need_unref = controller.GetTaskForImageAndRef(draw_image, prepare_tiles_id, |
248 &third_task); | 249 &third_task); |
249 EXPECT_TRUE(need_unref); | 250 EXPECT_TRUE(need_unref); |
250 EXPECT_TRUE(third_task); | 251 EXPECT_TRUE(third_task); |
251 EXPECT_FALSE(third_task.get() == task.get()); | 252 EXPECT_FALSE(third_task.get() == task.get()); |
252 | 253 |
253 ProcessTask(&controller, third_task->dependency().get()); | 254 ProcessTask(&controller, third_task->dependencies()[0].get()); |
254 ProcessTask(&controller, third_task.get()); | 255 ProcessTask(&controller, third_task.get()); |
255 | 256 |
256 // 3 Unrefs! | 257 // 3 Unrefs! |
257 controller.UnrefImage(draw_image); | 258 controller.UnrefImage(draw_image); |
258 controller.UnrefImage(draw_image); | 259 controller.UnrefImage(draw_image); |
259 controller.UnrefImage(draw_image); | 260 controller.UnrefImage(draw_image); |
260 } | 261 } |
261 | 262 |
262 TEST(GpuImageDecodeControllerTest, GetDecodedImageForDraw) { | 263 TEST(GpuImageDecodeControllerTest, GetDecodedImageForDraw) { |
263 auto context_provider = TestContextProvider::Create(); | 264 auto context_provider = TestContextProvider::Create(); |
264 context_provider->BindToCurrentThread(); | 265 context_provider->BindToCurrentThread(); |
265 GpuImageDecodeController controller(context_provider.get(), | 266 GpuImageDecodeController controller(context_provider.get(), |
266 ResourceFormat::RGBA_8888); | 267 ResourceFormat::RGBA_8888); |
267 bool is_decomposable = true; | 268 bool is_decomposable = true; |
268 uint64_t prepare_tiles_id = 1; | 269 uint64_t prepare_tiles_id = 1; |
269 SkFilterQuality quality = kHigh_SkFilterQuality; | 270 SkFilterQuality quality = kHigh_SkFilterQuality; |
270 | 271 |
271 skia::RefPtr<SkImage> image = CreateImage(100, 100); | 272 skia::RefPtr<SkImage> image = CreateImage(100, 100); |
272 DrawImage draw_image( | 273 DrawImage draw_image( |
273 image.get(), SkIRect::MakeWH(image->width(), image->height()), quality, | 274 image.get(), SkIRect::MakeWH(image->width(), image->height()), quality, |
274 CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable)); | 275 CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable)); |
275 scoped_refptr<ImageDecodeTask> task; | 276 scoped_refptr<Task> task; |
276 bool need_unref = | 277 bool need_unref = |
277 controller.GetTaskForImageAndRef(draw_image, prepare_tiles_id, &task); | 278 controller.GetTaskForImageAndRef(draw_image, prepare_tiles_id, &task); |
278 EXPECT_TRUE(need_unref); | 279 EXPECT_TRUE(need_unref); |
279 EXPECT_TRUE(task); | 280 EXPECT_TRUE(task); |
280 | 281 |
281 ProcessTask(&controller, task->dependency().get()); | 282 ProcessTask(&controller, task->dependencies()[0].get()); |
282 ProcessTask(&controller, task.get()); | 283 ProcessTask(&controller, task.get()); |
283 | 284 |
284 // Must hold context lock before calling GetDecodedImageForDraw / | 285 // Must hold context lock before calling GetDecodedImageForDraw / |
285 // DrawWithImageFinished. | 286 // DrawWithImageFinished. |
286 ContextProvider::ScopedContextLock context_lock(context_provider.get()); | 287 ContextProvider::ScopedContextLock context_lock(context_provider.get()); |
287 DecodedDrawImage decoded_draw_image = | 288 DecodedDrawImage decoded_draw_image = |
288 controller.GetDecodedImageForDraw(draw_image); | 289 controller.GetDecodedImageForDraw(draw_image); |
289 EXPECT_TRUE(decoded_draw_image.image()); | 290 EXPECT_TRUE(decoded_draw_image.image()); |
290 EXPECT_TRUE(decoded_draw_image.image()->isTextureBacked()); | 291 EXPECT_TRUE(decoded_draw_image.image()->isTextureBacked()); |
291 EXPECT_FALSE(decoded_draw_image.is_at_raster_decode()); | 292 EXPECT_FALSE(decoded_draw_image.is_at_raster_decode()); |
292 | 293 |
293 controller.DrawWithImageFinished(draw_image, decoded_draw_image); | 294 controller.DrawWithImageFinished(draw_image, decoded_draw_image); |
294 controller.UnrefImage(draw_image); | 295 controller.UnrefImage(draw_image); |
295 } | 296 } |
296 | 297 |
297 TEST(GpuImageDecodeControllerTest, GetLargeDecodedImageForDraw) { | 298 TEST(GpuImageDecodeControllerTest, GetLargeDecodedImageForDraw) { |
298 auto context_provider = TestContextProvider::Create(); | 299 auto context_provider = TestContextProvider::Create(); |
299 context_provider->BindToCurrentThread(); | 300 context_provider->BindToCurrentThread(); |
300 GpuImageDecodeController controller(context_provider.get(), | 301 GpuImageDecodeController controller(context_provider.get(), |
301 ResourceFormat::RGBA_8888); | 302 ResourceFormat::RGBA_8888); |
302 bool is_decomposable = true; | 303 bool is_decomposable = true; |
303 uint64_t prepare_tiles_id = 1; | 304 uint64_t prepare_tiles_id = 1; |
304 SkFilterQuality quality = kHigh_SkFilterQuality; | 305 SkFilterQuality quality = kHigh_SkFilterQuality; |
305 | 306 |
306 skia::RefPtr<SkImage> image = CreateImage(1, 24000); | 307 skia::RefPtr<SkImage> image = CreateImage(1, 24000); |
307 DrawImage draw_image( | 308 DrawImage draw_image( |
308 image.get(), SkIRect::MakeWH(image->width(), image->height()), quality, | 309 image.get(), SkIRect::MakeWH(image->width(), image->height()), quality, |
309 CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable)); | 310 CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable)); |
310 scoped_refptr<ImageDecodeTask> task; | 311 scoped_refptr<Task> task; |
311 bool need_unref = | 312 bool need_unref = |
312 controller.GetTaskForImageAndRef(draw_image, prepare_tiles_id, &task); | 313 controller.GetTaskForImageAndRef(draw_image, prepare_tiles_id, &task); |
313 EXPECT_TRUE(need_unref); | 314 EXPECT_TRUE(need_unref); |
314 EXPECT_TRUE(task); | 315 EXPECT_TRUE(task); |
315 | 316 |
316 ProcessTask(&controller, task->dependency().get()); | 317 ProcessTask(&controller, task->dependencies()[0].get()); |
317 ProcessTask(&controller, task.get()); | 318 ProcessTask(&controller, task.get()); |
318 | 319 |
319 // Must hold context lock before calling GetDecodedImageForDraw / | 320 // Must hold context lock before calling GetDecodedImageForDraw / |
320 // DrawWithImageFinished. | 321 // DrawWithImageFinished. |
321 ContextProvider::ScopedContextLock context_lock(context_provider.get()); | 322 ContextProvider::ScopedContextLock context_lock(context_provider.get()); |
322 DecodedDrawImage decoded_draw_image = | 323 DecodedDrawImage decoded_draw_image = |
323 controller.GetDecodedImageForDraw(draw_image); | 324 controller.GetDecodedImageForDraw(draw_image); |
324 EXPECT_TRUE(decoded_draw_image.image()); | 325 EXPECT_TRUE(decoded_draw_image.image()); |
325 EXPECT_FALSE(decoded_draw_image.image()->isTextureBacked()); | 326 EXPECT_FALSE(decoded_draw_image.image()->isTextureBacked()); |
326 EXPECT_FALSE(decoded_draw_image.is_at_raster_decode()); | 327 EXPECT_FALSE(decoded_draw_image.is_at_raster_decode()); |
(...skipping 12 matching lines...) Expand all Loading... |
339 SkFilterQuality quality = kHigh_SkFilterQuality; | 340 SkFilterQuality quality = kHigh_SkFilterQuality; |
340 | 341 |
341 controller.SetCachedItemLimitForTesting(0); | 342 controller.SetCachedItemLimitForTesting(0); |
342 controller.SetCachedBytesLimitForTesting(0); | 343 controller.SetCachedBytesLimitForTesting(0); |
343 | 344 |
344 skia::RefPtr<SkImage> image = CreateImage(100, 100); | 345 skia::RefPtr<SkImage> image = CreateImage(100, 100); |
345 DrawImage draw_image( | 346 DrawImage draw_image( |
346 image.get(), SkIRect::MakeWH(image->width(), image->height()), quality, | 347 image.get(), SkIRect::MakeWH(image->width(), image->height()), quality, |
347 CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable)); | 348 CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable)); |
348 | 349 |
349 scoped_refptr<ImageDecodeTask> task; | 350 scoped_refptr<Task> task; |
350 bool need_unref = | 351 bool need_unref = |
351 controller.GetTaskForImageAndRef(draw_image, prepare_tiles_id, &task); | 352 controller.GetTaskForImageAndRef(draw_image, prepare_tiles_id, &task); |
352 EXPECT_FALSE(need_unref); | 353 EXPECT_FALSE(need_unref); |
353 EXPECT_FALSE(task); | 354 EXPECT_FALSE(task); |
354 | 355 |
355 // Must hold context lock before calling GetDecodedImageForDraw / | 356 // Must hold context lock before calling GetDecodedImageForDraw / |
356 // DrawWithImageFinished. | 357 // DrawWithImageFinished. |
357 ContextProvider::ScopedContextLock context_lock(context_provider.get()); | 358 ContextProvider::ScopedContextLock context_lock(context_provider.get()); |
358 DecodedDrawImage decoded_draw_image = | 359 DecodedDrawImage decoded_draw_image = |
359 controller.GetDecodedImageForDraw(draw_image); | 360 controller.GetDecodedImageForDraw(draw_image); |
(...skipping 14 matching lines...) Expand all Loading... |
374 SkFilterQuality quality = kHigh_SkFilterQuality; | 375 SkFilterQuality quality = kHigh_SkFilterQuality; |
375 | 376 |
376 controller.SetCachedItemLimitForTesting(0); | 377 controller.SetCachedItemLimitForTesting(0); |
377 controller.SetCachedBytesLimitForTesting(0); | 378 controller.SetCachedBytesLimitForTesting(0); |
378 | 379 |
379 skia::RefPtr<SkImage> image = CreateImage(100, 100); | 380 skia::RefPtr<SkImage> image = CreateImage(100, 100); |
380 DrawImage draw_image( | 381 DrawImage draw_image( |
381 image.get(), SkIRect::MakeWH(image->width(), image->height()), quality, | 382 image.get(), SkIRect::MakeWH(image->width(), image->height()), quality, |
382 CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable)); | 383 CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable)); |
383 | 384 |
384 scoped_refptr<ImageDecodeTask> task; | 385 scoped_refptr<Task> task; |
385 bool need_unref = | 386 bool need_unref = |
386 controller.GetTaskForImageAndRef(draw_image, prepare_tiles_id, &task); | 387 controller.GetTaskForImageAndRef(draw_image, prepare_tiles_id, &task); |
387 EXPECT_FALSE(need_unref); | 388 EXPECT_FALSE(need_unref); |
388 EXPECT_FALSE(task); | 389 EXPECT_FALSE(task); |
389 | 390 |
390 // Must hold context lock before calling GetDecodedImageForDraw / | 391 // Must hold context lock before calling GetDecodedImageForDraw / |
391 // DrawWithImageFinished. | 392 // DrawWithImageFinished. |
392 ContextProvider::ScopedContextLock context_lock(context_provider.get()); | 393 ContextProvider::ScopedContextLock context_lock(context_provider.get()); |
393 DecodedDrawImage decoded_draw_image = | 394 DecodedDrawImage decoded_draw_image = |
394 controller.GetDecodedImageForDraw(draw_image); | 395 controller.GetDecodedImageForDraw(draw_image); |
395 EXPECT_TRUE(decoded_draw_image.image()); | 396 EXPECT_TRUE(decoded_draw_image.image()); |
396 EXPECT_TRUE(decoded_draw_image.image()->isTextureBacked()); | 397 EXPECT_TRUE(decoded_draw_image.image()->isTextureBacked()); |
397 EXPECT_TRUE(decoded_draw_image.is_at_raster_decode()); | 398 EXPECT_TRUE(decoded_draw_image.is_at_raster_decode()); |
398 | 399 |
399 controller.SetCachedItemLimitForTesting(1000); | 400 controller.SetCachedItemLimitForTesting(1000); |
400 controller.SetCachedBytesLimitForTesting(96 * 1024 * 1024); | 401 controller.SetCachedBytesLimitForTesting(96 * 1024 * 1024); |
401 | 402 |
402 // Finish our draw after increasing the memory limit, image should be added to | 403 // Finish our draw after increasing the memory limit, image should be added to |
403 // cache. | 404 // cache. |
404 controller.DrawWithImageFinished(draw_image, decoded_draw_image); | 405 controller.DrawWithImageFinished(draw_image, decoded_draw_image); |
405 | 406 |
406 scoped_refptr<ImageDecodeTask> another_task; | 407 scoped_refptr<Task> another_task; |
407 bool another_task_needs_unref = | 408 bool another_task_needs_unref = |
408 controller.GetTaskForImageAndRef(draw_image, prepare_tiles_id, &task); | 409 controller.GetTaskForImageAndRef(draw_image, prepare_tiles_id, &task); |
409 EXPECT_TRUE(another_task_needs_unref); | 410 EXPECT_TRUE(another_task_needs_unref); |
410 EXPECT_FALSE(another_task); | 411 EXPECT_FALSE(another_task); |
411 controller.UnrefImage(draw_image); | 412 controller.UnrefImage(draw_image); |
412 } | 413 } |
413 | 414 |
414 TEST(GpuImageDecodeControllerTest, | 415 TEST(GpuImageDecodeControllerTest, |
415 GetDecodedImageForDrawAtRasterDecodeMultipleTimes) { | 416 GetDecodedImageForDrawAtRasterDecodeMultipleTimes) { |
416 auto context_provider = TestContextProvider::Create(); | 417 auto context_provider = TestContextProvider::Create(); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
453 ResourceFormat::RGBA_8888); | 454 ResourceFormat::RGBA_8888); |
454 bool is_decomposable = true; | 455 bool is_decomposable = true; |
455 uint64_t prepare_tiles_id = 1; | 456 uint64_t prepare_tiles_id = 1; |
456 SkFilterQuality quality = kHigh_SkFilterQuality; | 457 SkFilterQuality quality = kHigh_SkFilterQuality; |
457 | 458 |
458 skia::RefPtr<SkImage> image = CreateImage(100, 100); | 459 skia::RefPtr<SkImage> image = CreateImage(100, 100); |
459 DrawImage draw_image( | 460 DrawImage draw_image( |
460 image.get(), SkIRect::MakeWH(image->width(), image->height()), quality, | 461 image.get(), SkIRect::MakeWH(image->width(), image->height()), quality, |
461 CreateMatrix(SkSize::Make(0.f, 0.f), is_decomposable)); | 462 CreateMatrix(SkSize::Make(0.f, 0.f), is_decomposable)); |
462 | 463 |
463 scoped_refptr<ImageDecodeTask> task; | 464 scoped_refptr<Task> task; |
464 bool need_unref = | 465 bool need_unref = |
465 controller.GetTaskForImageAndRef(draw_image, prepare_tiles_id, &task); | 466 controller.GetTaskForImageAndRef(draw_image, prepare_tiles_id, &task); |
466 EXPECT_FALSE(task); | 467 EXPECT_FALSE(task); |
467 EXPECT_FALSE(need_unref); | 468 EXPECT_FALSE(need_unref); |
468 | 469 |
469 // Must hold context lock before calling GetDecodedImageForDraw / | 470 // Must hold context lock before calling GetDecodedImageForDraw / |
470 // DrawWithImageFinished. | 471 // DrawWithImageFinished. |
471 ContextProvider::ScopedContextLock context_lock(context_provider.get()); | 472 ContextProvider::ScopedContextLock context_lock(context_provider.get()); |
472 DecodedDrawImage decoded_draw_image = | 473 DecodedDrawImage decoded_draw_image = |
473 controller.GetDecodedImageForDraw(draw_image); | 474 controller.GetDecodedImageForDraw(draw_image); |
474 EXPECT_FALSE(decoded_draw_image.image()); | 475 EXPECT_FALSE(decoded_draw_image.image()); |
475 | 476 |
476 controller.DrawWithImageFinished(draw_image, decoded_draw_image); | 477 controller.DrawWithImageFinished(draw_image, decoded_draw_image); |
477 } | 478 } |
478 | 479 |
479 TEST(GpuImageDecodeControllerTest, NonOverlappingSrcRectImagesAreSkipped) { | 480 TEST(GpuImageDecodeControllerTest, NonOverlappingSrcRectImagesAreSkipped) { |
480 auto context_provider = TestContextProvider::Create(); | 481 auto context_provider = TestContextProvider::Create(); |
481 context_provider->BindToCurrentThread(); | 482 context_provider->BindToCurrentThread(); |
482 GpuImageDecodeController controller(context_provider.get(), | 483 GpuImageDecodeController controller(context_provider.get(), |
483 ResourceFormat::RGBA_8888); | 484 ResourceFormat::RGBA_8888); |
484 bool is_decomposable = true; | 485 bool is_decomposable = true; |
485 uint64_t prepare_tiles_id = 1; | 486 uint64_t prepare_tiles_id = 1; |
486 SkFilterQuality quality = kHigh_SkFilterQuality; | 487 SkFilterQuality quality = kHigh_SkFilterQuality; |
487 | 488 |
488 skia::RefPtr<SkImage> image = CreateImage(100, 100); | 489 skia::RefPtr<SkImage> image = CreateImage(100, 100); |
489 DrawImage draw_image( | 490 DrawImage draw_image( |
490 image.get(), SkIRect::MakeXYWH(150, 150, image->width(), image->height()), | 491 image.get(), SkIRect::MakeXYWH(150, 150, image->width(), image->height()), |
491 quality, CreateMatrix(SkSize::Make(1.f, 1.f), is_decomposable)); | 492 quality, CreateMatrix(SkSize::Make(1.f, 1.f), is_decomposable)); |
492 | 493 |
493 scoped_refptr<ImageDecodeTask> task; | 494 scoped_refptr<Task> task; |
494 bool need_unref = | 495 bool need_unref = |
495 controller.GetTaskForImageAndRef(draw_image, prepare_tiles_id, &task); | 496 controller.GetTaskForImageAndRef(draw_image, prepare_tiles_id, &task); |
496 EXPECT_FALSE(task); | 497 EXPECT_FALSE(task); |
497 EXPECT_FALSE(need_unref); | 498 EXPECT_FALSE(need_unref); |
498 | 499 |
499 // Must hold context lock before calling GetDecodedImageForDraw / | 500 // Must hold context lock before calling GetDecodedImageForDraw / |
500 // DrawWithImageFinished. | 501 // DrawWithImageFinished. |
501 ContextProvider::ScopedContextLock context_lock(context_provider.get()); | 502 ContextProvider::ScopedContextLock context_lock(context_provider.get()); |
502 DecodedDrawImage decoded_draw_image = | 503 DecodedDrawImage decoded_draw_image = |
503 controller.GetDecodedImageForDraw(draw_image); | 504 controller.GetDecodedImageForDraw(draw_image); |
504 EXPECT_FALSE(decoded_draw_image.image()); | 505 EXPECT_FALSE(decoded_draw_image.image()); |
505 | 506 |
506 controller.DrawWithImageFinished(draw_image, decoded_draw_image); | 507 controller.DrawWithImageFinished(draw_image, decoded_draw_image); |
507 } | 508 } |
508 | 509 |
509 TEST(GpuImageDecodeControllerTest, CanceledTasksDoNotCountAgainstBudget) { | 510 TEST(GpuImageDecodeControllerTest, CanceledTasksDoNotCountAgainstBudget) { |
510 auto context_provider = TestContextProvider::Create(); | 511 auto context_provider = TestContextProvider::Create(); |
511 context_provider->BindToCurrentThread(); | 512 context_provider->BindToCurrentThread(); |
512 GpuImageDecodeController controller(context_provider.get(), | 513 GpuImageDecodeController controller(context_provider.get(), |
513 ResourceFormat::RGBA_8888); | 514 ResourceFormat::RGBA_8888); |
514 bool is_decomposable = true; | 515 bool is_decomposable = true; |
515 uint64_t prepare_tiles_id = 1; | 516 uint64_t prepare_tiles_id = 1; |
516 SkFilterQuality quality = kHigh_SkFilterQuality; | 517 SkFilterQuality quality = kHigh_SkFilterQuality; |
517 | 518 |
518 skia::RefPtr<SkImage> image = CreateImage(100, 100); | 519 skia::RefPtr<SkImage> image = CreateImage(100, 100); |
519 DrawImage draw_image( | 520 DrawImage draw_image( |
520 image.get(), SkIRect::MakeXYWH(0, 0, image->width(), image->height()), | 521 image.get(), SkIRect::MakeXYWH(0, 0, image->width(), image->height()), |
521 quality, CreateMatrix(SkSize::Make(1.f, 1.f), is_decomposable)); | 522 quality, CreateMatrix(SkSize::Make(1.f, 1.f), is_decomposable)); |
522 | 523 |
523 scoped_refptr<ImageDecodeTask> task; | 524 scoped_refptr<Task> task; |
524 bool need_unref = | 525 bool need_unref = |
525 controller.GetTaskForImageAndRef(draw_image, prepare_tiles_id, &task); | 526 controller.GetTaskForImageAndRef(draw_image, prepare_tiles_id, &task); |
526 EXPECT_NE(0u, controller.GetBytesUsedForTesting()); | 527 EXPECT_NE(0u, controller.GetBytesUsedForTesting()); |
527 EXPECT_TRUE(task); | 528 EXPECT_TRUE(task); |
528 EXPECT_TRUE(need_unref); | 529 EXPECT_TRUE(need_unref); |
529 | 530 |
530 CompleteTask(&controller, task->dependency().get()); | 531 CompleteTask(&controller, task->dependencies()[0].get()); |
531 CompleteTask(&controller, task.get()); | 532 CompleteTask(&controller, task.get()); |
532 | 533 |
533 controller.UnrefImage(draw_image); | 534 controller.UnrefImage(draw_image); |
534 EXPECT_EQ(0u, controller.GetBytesUsedForTesting()); | 535 EXPECT_EQ(0u, controller.GetBytesUsedForTesting()); |
535 } | 536 } |
536 | 537 |
537 TEST(GpuImageDecodeControllerTest, ShouldAggressivelyFreeResources) { | 538 TEST(GpuImageDecodeControllerTest, ShouldAggressivelyFreeResources) { |
538 auto context_provider = TestContextProvider::Create(); | 539 auto context_provider = TestContextProvider::Create(); |
539 context_provider->BindToCurrentThread(); | 540 context_provider->BindToCurrentThread(); |
540 GpuImageDecodeController controller(context_provider.get(), | 541 GpuImageDecodeController controller(context_provider.get(), |
541 ResourceFormat::RGBA_8888); | 542 ResourceFormat::RGBA_8888); |
542 bool is_decomposable = true; | 543 bool is_decomposable = true; |
543 uint64_t prepare_tiles_id = 1; | 544 uint64_t prepare_tiles_id = 1; |
544 SkFilterQuality quality = kHigh_SkFilterQuality; | 545 SkFilterQuality quality = kHigh_SkFilterQuality; |
545 | 546 |
546 skia::RefPtr<SkImage> image = CreateImage(100, 100); | 547 skia::RefPtr<SkImage> image = CreateImage(100, 100); |
547 DrawImage draw_image( | 548 DrawImage draw_image( |
548 image.get(), SkIRect::MakeWH(image->width(), image->height()), quality, | 549 image.get(), SkIRect::MakeWH(image->width(), image->height()), quality, |
549 CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable)); | 550 CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable)); |
550 scoped_refptr<ImageDecodeTask> task; | 551 scoped_refptr<Task> task; |
551 { | 552 { |
552 bool need_unref = | 553 bool need_unref = |
553 controller.GetTaskForImageAndRef(draw_image, prepare_tiles_id, &task); | 554 controller.GetTaskForImageAndRef(draw_image, prepare_tiles_id, &task); |
554 EXPECT_TRUE(need_unref); | 555 EXPECT_TRUE(need_unref); |
555 EXPECT_TRUE(task); | 556 EXPECT_TRUE(task); |
556 } | 557 } |
557 | 558 |
558 ProcessTask(&controller, task->dependency().get()); | 559 ProcessTask(&controller, task->dependencies()[0].get()); |
559 ProcessTask(&controller, task.get()); | 560 ProcessTask(&controller, task.get()); |
560 | 561 |
561 controller.UnrefImage(draw_image); | 562 controller.UnrefImage(draw_image); |
562 | 563 |
563 // We should now have data image in our cache. | 564 // We should now have data image in our cache. |
564 DCHECK_GT(controller.GetBytesUsedForTesting(), 0u); | 565 DCHECK_GT(controller.GetBytesUsedForTesting(), 0u); |
565 | 566 |
566 // Tell our controller to aggressively free resources. | 567 // Tell our controller to aggressively free resources. |
567 controller.SetShouldAggressivelyFreeResources(true); | 568 controller.SetShouldAggressivelyFreeResources(true); |
568 DCHECK_EQ(0u, controller.GetBytesUsedForTesting()); | 569 DCHECK_EQ(0u, controller.GetBytesUsedForTesting()); |
569 | 570 |
570 // Attempting to upload a new image should result in at-raster decode. | 571 // Attempting to upload a new image should result in at-raster decode. |
571 { | 572 { |
572 bool need_unref = | 573 bool need_unref = |
573 controller.GetTaskForImageAndRef(draw_image, prepare_tiles_id, &task); | 574 controller.GetTaskForImageAndRef(draw_image, prepare_tiles_id, &task); |
574 EXPECT_FALSE(need_unref); | 575 EXPECT_FALSE(need_unref); |
575 EXPECT_FALSE(task); | 576 EXPECT_FALSE(task); |
576 } | 577 } |
577 | 578 |
578 // We now tell the controller to not aggressively free resources. Uploads | 579 // We now tell the controller to not aggressively free resources. Uploads |
579 // should work again. | 580 // should work again. |
580 controller.SetShouldAggressivelyFreeResources(false); | 581 controller.SetShouldAggressivelyFreeResources(false); |
581 { | 582 { |
582 bool need_unref = | 583 bool need_unref = |
583 controller.GetTaskForImageAndRef(draw_image, prepare_tiles_id, &task); | 584 controller.GetTaskForImageAndRef(draw_image, prepare_tiles_id, &task); |
584 EXPECT_TRUE(need_unref); | 585 EXPECT_TRUE(need_unref); |
585 EXPECT_TRUE(task); | 586 EXPECT_TRUE(task); |
586 } | 587 } |
587 | 588 |
588 ProcessTask(&controller, task->dependency().get()); | 589 ProcessTask(&controller, task->dependencies()[0].get()); |
589 ProcessTask(&controller, task.get()); | 590 ProcessTask(&controller, task.get()); |
590 | 591 |
591 // The image should be in our cache after un-ref. | 592 // The image should be in our cache after un-ref. |
592 controller.UnrefImage(draw_image); | 593 controller.UnrefImage(draw_image); |
593 DCHECK_GT(controller.GetBytesUsedForTesting(), 0u); | 594 DCHECK_GT(controller.GetBytesUsedForTesting(), 0u); |
594 } | 595 } |
595 | 596 |
596 } // namespace | 597 } // namespace |
597 } // namespace cc | 598 } // namespace cc |
OLD | NEW |