Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(276)

Side by Side Diff: cc/tiles/image_controller_unittest.cc

Issue 2926513003: Use PaintImage in cc QueueImageDecode
Patch Set: rebase Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « cc/tiles/image_controller.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/image_controller.h" 5 #include "cc/tiles/image_controller.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/optional.h" 10 #include "base/optional.h"
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 DISALLOW_COPY_AND_ASSIGN(BlockingTask); 230 DISALLOW_COPY_AND_ASSIGN(BlockingTask);
231 }; 231 };
232 232
233 // For tests that exercise image controller's thread, this is the timeout value 233 // For tests that exercise image controller's thread, this is the timeout value
234 // to allow the worker thread to do its work. 234 // to allow the worker thread to do its work.
235 int kDefaultTimeoutSeconds = 10; 235 int kDefaultTimeoutSeconds = 10;
236 236
237 class ImageControllerTest : public testing::Test { 237 class ImageControllerTest : public testing::Test {
238 public: 238 public:
239 ImageControllerTest() : task_runner_(base::SequencedTaskRunnerHandle::Get()) { 239 ImageControllerTest() : task_runner_(base::SequencedTaskRunnerHandle::Get()) {
240 image_ = CreateDiscardableImage(gfx::Size(1, 1)); 240 image_ = PaintImage(PaintImage::GetNextId(),
241 CreateDiscardableImage(gfx::Size(1, 1)));
241 } 242 }
242 ~ImageControllerTest() override = default; 243 ~ImageControllerTest() override = default;
243 244
244 void SetUp() override { 245 void SetUp() override {
245 worker_task_runner_ = make_scoped_refptr(new WorkerTaskRunner); 246 worker_task_runner_ = make_scoped_refptr(new WorkerTaskRunner);
246 controller_.reset( 247 controller_.reset(
247 new ImageController(task_runner_.get(), worker_task_runner_)); 248 new ImageController(task_runner_.get(), worker_task_runner_));
248 cache_ = TestableCache(); 249 cache_ = TestableCache();
249 controller_->SetImageDecodeCache(&cache_); 250 controller_->SetImageDecodeCache(&cache_);
250 } 251 }
251 252
252 void TearDown() override { 253 void TearDown() override {
253 controller_.reset(); 254 controller_.reset();
254 worker_task_runner_ = nullptr; 255 worker_task_runner_ = nullptr;
255 } 256 }
256 257
257 base::SequencedTaskRunner* task_runner() { return task_runner_.get(); } 258 base::SequencedTaskRunner* task_runner() { return task_runner_.get(); }
258 ImageController* controller() { return controller_.get(); } 259 ImageController* controller() { return controller_.get(); }
259 TestableCache* cache() { return &cache_; } 260 TestableCache* cache() { return &cache_; }
260 sk_sp<const SkImage> image() const { return image_; } 261 PaintImage image() const { return image_; }
261 262
262 // Timeout callback, which errors and exits the runloop. 263 // Timeout callback, which errors and exits the runloop.
263 static void Timeout(base::RunLoop* run_loop) { 264 static void Timeout(base::RunLoop* run_loop) {
264 ADD_FAILURE() << "Timeout."; 265 ADD_FAILURE() << "Timeout.";
265 run_loop->Quit(); 266 run_loop->Quit();
266 } 267 }
267 268
268 // Convenience method to run the run loop with a timeout. 269 // Convenience method to run the run loop with a timeout.
269 void RunOrTimeout(base::RunLoop* run_loop) { 270 void RunOrTimeout(base::RunLoop* run_loop) {
270 task_runner_->PostDelayedTask( 271 task_runner_->PostDelayedTask(
271 FROM_HERE, 272 FROM_HERE,
272 base::BindOnce(&ImageControllerTest::Timeout, 273 base::BindOnce(&ImageControllerTest::Timeout,
273 base::Unretained(run_loop)), 274 base::Unretained(run_loop)),
274 base::TimeDelta::FromSeconds(kDefaultTimeoutSeconds)); 275 base::TimeDelta::FromSeconds(kDefaultTimeoutSeconds));
275 run_loop->Run(); 276 run_loop->Run();
276 } 277 }
277 278
278 void ResetController() { controller_.reset(); } 279 void ResetController() { controller_.reset(); }
279 280
280 private: 281 private:
281 scoped_refptr<base::SequencedTaskRunner> task_runner_; 282 scoped_refptr<base::SequencedTaskRunner> task_runner_;
282 scoped_refptr<WorkerTaskRunner> worker_task_runner_; 283 scoped_refptr<WorkerTaskRunner> worker_task_runner_;
283 TestableCache cache_; 284 TestableCache cache_;
284 std::unique_ptr<ImageController> controller_; 285 std::unique_ptr<ImageController> controller_;
285 sk_sp<const SkImage> image_; 286 PaintImage image_;
286 }; 287 };
287 288
288 TEST_F(ImageControllerTest, NullControllerUnrefsImages) { 289 TEST_F(ImageControllerTest, NullControllerUnrefsImages) {
289 std::vector<DrawImage> images(10); 290 std::vector<DrawImage> images(10);
290 ImageDecodeCache::TracingInfo tracing_info; 291 ImageDecodeCache::TracingInfo tracing_info;
291 292
292 ASSERT_EQ(10u, images.size()); 293 ASSERT_EQ(10u, images.size());
293 auto tasks = 294 auto tasks =
294 controller()->SetPredecodeImages(std::move(images), tracing_info); 295 controller()->SetPredecodeImages(std::move(images), tracing_info);
295 EXPECT_EQ(0u, tasks.size()); 296 EXPECT_EQ(0u, tasks.size());
296 EXPECT_EQ(10, cache()->number_of_refs()); 297 EXPECT_EQ(10, cache()->number_of_refs());
297 298
298 controller()->SetImageDecodeCache(nullptr); 299 controller()->SetImageDecodeCache(nullptr);
299 EXPECT_EQ(0, cache()->number_of_refs()); 300 EXPECT_EQ(0, cache()->number_of_refs());
300 } 301 }
301 302
302 TEST_F(ImageControllerTest, QueueImageDecode) { 303 TEST_F(ImageControllerTest, QueueImageDecode) {
303 base::RunLoop run_loop; 304 base::RunLoop run_loop;
304 DecodeClient decode_client; 305 DecodeClient decode_client;
305 EXPECT_EQ(image()->bounds().width(), 1); 306 EXPECT_EQ(image().sk_image()->bounds().width(), 1);
306 ImageController::ImageDecodeRequestId expected_id = 307 ImageController::ImageDecodeRequestId expected_id =
307 controller()->QueueImageDecode( 308 controller()->QueueImageDecode(
308 image(), 309 image(),
309 base::Bind(&DecodeClient::Callback, base::Unretained(&decode_client), 310 base::Bind(&DecodeClient::Callback, base::Unretained(&decode_client),
310 run_loop.QuitClosure())); 311 run_loop.QuitClosure()));
311 RunOrTimeout(&run_loop); 312 RunOrTimeout(&run_loop);
312 EXPECT_EQ(expected_id, decode_client.id()); 313 EXPECT_EQ(expected_id, decode_client.id());
313 EXPECT_EQ(ImageController::ImageDecodeResult::SUCCESS, 314 EXPECT_EQ(ImageController::ImageDecodeResult::SUCCESS,
314 decode_client.result()); 315 decode_client.result());
315 } 316 }
316 317
317 TEST_F(ImageControllerTest, QueueImageDecodeNonLazy) { 318 TEST_F(ImageControllerTest, QueueImageDecodeNonLazy) {
318 base::RunLoop run_loop; 319 base::RunLoop run_loop;
319 DecodeClient decode_client; 320 DecodeClient decode_client;
320 321
321 SkBitmap bitmap; 322 SkBitmap bitmap;
322 bitmap.allocN32Pixels(1, 1); 323 bitmap.allocN32Pixels(1, 1);
323 sk_sp<const SkImage> image = SkImage::MakeFromBitmap(bitmap); 324 PaintImage image(PaintImage::GetNextId(), SkImage::MakeFromBitmap(bitmap));
324 325
325 ImageController::ImageDecodeRequestId expected_id = 326 ImageController::ImageDecodeRequestId expected_id =
326 controller()->QueueImageDecode( 327 controller()->QueueImageDecode(
327 image, 328 image,
328 base::Bind(&DecodeClient::Callback, base::Unretained(&decode_client), 329 base::Bind(&DecodeClient::Callback, base::Unretained(&decode_client),
329 run_loop.QuitClosure())); 330 run_loop.QuitClosure()));
330 RunOrTimeout(&run_loop); 331 RunOrTimeout(&run_loop);
331 EXPECT_EQ(expected_id, decode_client.id()); 332 EXPECT_EQ(expected_id, decode_client.id());
332 EXPECT_EQ(ImageController::ImageDecodeResult::DECODE_NOT_REQUIRED, 333 EXPECT_EQ(ImageController::ImageDecodeResult::DECODE_NOT_REQUIRED,
333 decode_client.result()); 334 decode_client.result());
334 } 335 }
335 336
336 TEST_F(ImageControllerTest, QueueImageDecodeTooLarge) { 337 TEST_F(ImageControllerTest, QueueImageDecodeTooLarge) {
337 base::RunLoop run_loop; 338 base::RunLoop run_loop;
338 DecodeClient decode_client; 339 DecodeClient decode_client;
340 PaintImage image(PaintImage::GetNextId(),
341 CreateDiscardableImage(gfx::Size(2000, 2000)));
339 342
340 sk_sp<const SkImage> image = CreateDiscardableImage(gfx::Size(2000, 2000));
341 ImageController::ImageDecodeRequestId expected_id = 343 ImageController::ImageDecodeRequestId expected_id =
342 controller()->QueueImageDecode( 344 controller()->QueueImageDecode(
343 image, 345 image,
344 base::Bind(&DecodeClient::Callback, base::Unretained(&decode_client), 346 base::Bind(&DecodeClient::Callback, base::Unretained(&decode_client),
345 run_loop.QuitClosure())); 347 run_loop.QuitClosure()));
346 RunOrTimeout(&run_loop); 348 RunOrTimeout(&run_loop);
347 EXPECT_EQ(expected_id, decode_client.id()); 349 EXPECT_EQ(expected_id, decode_client.id());
348 EXPECT_EQ(ImageController::ImageDecodeResult::FAILURE, 350 EXPECT_EQ(ImageController::ImageDecodeResult::FAILURE,
349 decode_client.result()); 351 decode_client.result());
350 } 352 }
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
591 decode_client2.result()); 593 decode_client2.result());
592 594
593 // Reset the controller since the order of destruction is wrong in this test 595 // Reset the controller since the order of destruction is wrong in this test
594 // (|other_cache| should outlive the controller. This is normally done via 596 // (|other_cache| should outlive the controller. This is normally done via
595 // SetImageDecodeCache(nullptr) or it can be done in the dtor of the cache.) 597 // SetImageDecodeCache(nullptr) or it can be done in the dtor of the cache.)
596 ResetController(); 598 ResetController();
597 } 599 }
598 600
599 } // namespace 601 } // namespace
600 } // namespace cc 602 } // namespace cc
OLDNEW
« no previous file with comments | « cc/tiles/image_controller.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698