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

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

Issue 2928433003: cc: Add scaling for checkered images. (Closed)
Patch Set: .. 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') | cc/tiles/tile_manager.cc » ('j') | 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 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 base::ConditionVariable run_cv_; 227 base::ConditionVariable run_cv_;
228 bool can_run_ = false; 228 bool can_run_ = false;
229 229
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 DrawImage CreateDiscardableDrawImage(gfx::Size size) {
238 return DrawImage(
239 PaintImage(PaintImage::kUnknownStableId, CreateDiscardableImage(size)),
240 SkIRect::MakeWH(size.width(), size.height()), kNone_SkFilterQuality,
241 SkMatrix::I(), gfx::ColorSpace());
242 }
243
237 class ImageControllerTest : public testing::Test { 244 class ImageControllerTest : public testing::Test {
238 public: 245 public:
239 ImageControllerTest() : task_runner_(base::SequencedTaskRunnerHandle::Get()) { 246 ImageControllerTest() : task_runner_(base::SequencedTaskRunnerHandle::Get()) {
240 image_ = CreateDiscardableImage(gfx::Size(1, 1)); 247 image_ = CreateDiscardableDrawImage(gfx::Size(1, 1));
241 } 248 }
242 ~ImageControllerTest() override = default; 249 ~ImageControllerTest() override = default;
243 250
244 void SetUp() override { 251 void SetUp() override {
245 worker_task_runner_ = make_scoped_refptr(new WorkerTaskRunner); 252 worker_task_runner_ = make_scoped_refptr(new WorkerTaskRunner);
246 controller_.reset( 253 controller_.reset(
247 new ImageController(task_runner_.get(), worker_task_runner_)); 254 new ImageController(task_runner_.get(), worker_task_runner_));
248 cache_ = TestableCache(); 255 cache_ = TestableCache();
249 controller_->SetImageDecodeCache(&cache_); 256 controller_->SetImageDecodeCache(&cache_);
250 } 257 }
251 258
252 void TearDown() override { 259 void TearDown() override {
253 controller_.reset(); 260 controller_.reset();
254 worker_task_runner_ = nullptr; 261 worker_task_runner_ = nullptr;
255 } 262 }
256 263
257 base::SequencedTaskRunner* task_runner() { return task_runner_.get(); } 264 base::SequencedTaskRunner* task_runner() { return task_runner_.get(); }
258 ImageController* controller() { return controller_.get(); } 265 ImageController* controller() { return controller_.get(); }
259 TestableCache* cache() { return &cache_; } 266 TestableCache* cache() { return &cache_; }
260 sk_sp<const SkImage> image() const { return image_; } 267 const DrawImage& image() const { return image_; }
261 268
262 // Timeout callback, which errors and exits the runloop. 269 // Timeout callback, which errors and exits the runloop.
263 static void Timeout(base::RunLoop* run_loop) { 270 static void Timeout(base::RunLoop* run_loop) {
264 ADD_FAILURE() << "Timeout."; 271 ADD_FAILURE() << "Timeout.";
265 run_loop->Quit(); 272 run_loop->Quit();
266 } 273 }
267 274
268 // Convenience method to run the run loop with a timeout. 275 // Convenience method to run the run loop with a timeout.
269 void RunOrTimeout(base::RunLoop* run_loop) { 276 void RunOrTimeout(base::RunLoop* run_loop) {
270 task_runner_->PostDelayedTask( 277 task_runner_->PostDelayedTask(
271 FROM_HERE, 278 FROM_HERE,
272 base::BindOnce(&ImageControllerTest::Timeout, 279 base::BindOnce(&ImageControllerTest::Timeout,
273 base::Unretained(run_loop)), 280 base::Unretained(run_loop)),
274 base::TimeDelta::FromSeconds(kDefaultTimeoutSeconds)); 281 base::TimeDelta::FromSeconds(kDefaultTimeoutSeconds));
275 run_loop->Run(); 282 run_loop->Run();
276 } 283 }
277 284
278 void ResetController() { controller_.reset(); } 285 void ResetController() { controller_.reset(); }
279 286
280 private: 287 private:
281 scoped_refptr<base::SequencedTaskRunner> task_runner_; 288 scoped_refptr<base::SequencedTaskRunner> task_runner_;
282 scoped_refptr<WorkerTaskRunner> worker_task_runner_; 289 scoped_refptr<WorkerTaskRunner> worker_task_runner_;
283 TestableCache cache_; 290 TestableCache cache_;
284 std::unique_ptr<ImageController> controller_; 291 std::unique_ptr<ImageController> controller_;
285 sk_sp<const SkImage> image_; 292 DrawImage image_;
286 }; 293 };
287 294
288 TEST_F(ImageControllerTest, NullControllerUnrefsImages) { 295 TEST_F(ImageControllerTest, NullControllerUnrefsImages) {
289 std::vector<DrawImage> images(10); 296 std::vector<DrawImage> images(10);
290 ImageDecodeCache::TracingInfo tracing_info; 297 ImageDecodeCache::TracingInfo tracing_info;
291 298
292 ASSERT_EQ(10u, images.size()); 299 ASSERT_EQ(10u, images.size());
293 auto tasks = 300 auto tasks =
294 controller()->SetPredecodeImages(std::move(images), tracing_info); 301 controller()->SetPredecodeImages(std::move(images), tracing_info);
295 EXPECT_EQ(0u, tasks.size()); 302 EXPECT_EQ(0u, tasks.size());
296 EXPECT_EQ(10, cache()->number_of_refs()); 303 EXPECT_EQ(10, cache()->number_of_refs());
297 304
298 controller()->SetImageDecodeCache(nullptr); 305 controller()->SetImageDecodeCache(nullptr);
299 EXPECT_EQ(0, cache()->number_of_refs()); 306 EXPECT_EQ(0, cache()->number_of_refs());
300 } 307 }
301 308
302 TEST_F(ImageControllerTest, QueueImageDecode) { 309 TEST_F(ImageControllerTest, QueueImageDecode) {
303 base::RunLoop run_loop; 310 base::RunLoop run_loop;
304 DecodeClient decode_client; 311 DecodeClient decode_client;
305 EXPECT_EQ(image()->bounds().width(), 1); 312 EXPECT_EQ(image().image()->bounds().width(), 1);
306 ImageController::ImageDecodeRequestId expected_id = 313 ImageController::ImageDecodeRequestId expected_id =
307 controller()->QueueImageDecode( 314 controller()->QueueImageDecode(
308 image(), 315 image(),
309 base::Bind(&DecodeClient::Callback, base::Unretained(&decode_client), 316 base::Bind(&DecodeClient::Callback, base::Unretained(&decode_client),
310 run_loop.QuitClosure())); 317 run_loop.QuitClosure()));
311 RunOrTimeout(&run_loop); 318 RunOrTimeout(&run_loop);
312 EXPECT_EQ(expected_id, decode_client.id()); 319 EXPECT_EQ(expected_id, decode_client.id());
313 EXPECT_EQ(ImageController::ImageDecodeResult::SUCCESS, 320 EXPECT_EQ(ImageController::ImageDecodeResult::SUCCESS,
314 decode_client.result()); 321 decode_client.result());
315 } 322 }
316 323
317 TEST_F(ImageControllerTest, QueueImageDecodeNonLazy) { 324 TEST_F(ImageControllerTest, QueueImageDecodeNonLazy) {
318 base::RunLoop run_loop; 325 base::RunLoop run_loop;
319 DecodeClient decode_client; 326 DecodeClient decode_client;
320 327
321 SkBitmap bitmap; 328 SkBitmap bitmap;
322 bitmap.allocN32Pixels(1, 1); 329 bitmap.allocN32Pixels(1, 1);
323 sk_sp<const SkImage> image = SkImage::MakeFromBitmap(bitmap); 330 DrawImage image = DrawImage(
331 PaintImage(PaintImage::kUnknownStableId, SkImage::MakeFromBitmap(bitmap)),
332 SkIRect::MakeWH(1, 1), kNone_SkFilterQuality, SkMatrix::I(),
333 gfx::ColorSpace());
324 334
325 ImageController::ImageDecodeRequestId expected_id = 335 ImageController::ImageDecodeRequestId expected_id =
326 controller()->QueueImageDecode( 336 controller()->QueueImageDecode(
327 image, 337 image,
328 base::Bind(&DecodeClient::Callback, base::Unretained(&decode_client), 338 base::Bind(&DecodeClient::Callback, base::Unretained(&decode_client),
329 run_loop.QuitClosure())); 339 run_loop.QuitClosure()));
330 RunOrTimeout(&run_loop); 340 RunOrTimeout(&run_loop);
331 EXPECT_EQ(expected_id, decode_client.id()); 341 EXPECT_EQ(expected_id, decode_client.id());
332 EXPECT_EQ(ImageController::ImageDecodeResult::DECODE_NOT_REQUIRED, 342 EXPECT_EQ(ImageController::ImageDecodeResult::DECODE_NOT_REQUIRED,
333 decode_client.result()); 343 decode_client.result());
334 } 344 }
335 345
336 TEST_F(ImageControllerTest, QueueImageDecodeTooLarge) { 346 TEST_F(ImageControllerTest, QueueImageDecodeTooLarge) {
337 base::RunLoop run_loop; 347 base::RunLoop run_loop;
338 DecodeClient decode_client; 348 DecodeClient decode_client;
339 349
340 sk_sp<const SkImage> image = CreateDiscardableImage(gfx::Size(2000, 2000)); 350 DrawImage image = CreateDiscardableDrawImage(gfx::Size(2000, 2000));
341 ImageController::ImageDecodeRequestId expected_id = 351 ImageController::ImageDecodeRequestId expected_id =
342 controller()->QueueImageDecode( 352 controller()->QueueImageDecode(
343 image, 353 image,
344 base::Bind(&DecodeClient::Callback, base::Unretained(&decode_client), 354 base::Bind(&DecodeClient::Callback, base::Unretained(&decode_client),
345 run_loop.QuitClosure())); 355 run_loop.QuitClosure()));
346 RunOrTimeout(&run_loop); 356 RunOrTimeout(&run_loop);
347 EXPECT_EQ(expected_id, decode_client.id()); 357 EXPECT_EQ(expected_id, decode_client.id());
348 EXPECT_EQ(ImageController::ImageDecodeResult::FAILURE, 358 EXPECT_EQ(ImageController::ImageDecodeResult::FAILURE,
349 decode_client.result()); 359 decode_client.result());
350 } 360 }
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
591 decode_client2.result()); 601 decode_client2.result());
592 602
593 // Reset the controller since the order of destruction is wrong in this test 603 // 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 604 // (|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.) 605 // SetImageDecodeCache(nullptr) or it can be done in the dtor of the cache.)
596 ResetController(); 606 ResetController();
597 } 607 }
598 608
599 } // namespace 609 } // namespace
600 } // namespace cc 610 } // namespace cc
OLDNEW
« no previous file with comments | « cc/tiles/image_controller.cc ('k') | cc/tiles/tile_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698