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