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

Side by Side Diff: cc/tiles/decoded_image_tracker_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/decoded_image_tracker.cc ('k') | cc/tiles/image_controller.h » ('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 <vector> 5 #include <vector>
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "cc/test/skia_common.h"
8 #include "cc/tiles/decoded_image_tracker.h" 9 #include "cc/tiles/decoded_image_tracker.h"
9 #include "cc/tiles/image_controller.h" 10 #include "cc/tiles/image_controller.h"
10 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
11 12
12 namespace cc { 13 namespace cc {
13 14
14 class TestImageController : public ImageController { 15 class TestImageController : public ImageController {
15 public: 16 public:
16 TestImageController() : ImageController(nullptr, nullptr) {} 17 TestImageController() : ImageController(nullptr, nullptr) {}
17 18
18 void UnlockImageDecode(ImageDecodeRequestId id) override { 19 void UnlockImageDecode(ImageDecodeRequestId id) override {
19 auto it = std::find(locked_ids_.begin(), locked_ids_.end(), id); 20 auto it = std::find(locked_ids_.begin(), locked_ids_.end(), id);
20 ASSERT_FALSE(it == locked_ids_.end()); 21 ASSERT_FALSE(it == locked_ids_.end());
21 locked_ids_.erase(it); 22 locked_ids_.erase(it);
22 } 23 }
23 24
24 ImageDecodeRequestId QueueImageDecode( 25 ImageDecodeRequestId QueueImageDecode(
25 sk_sp<const SkImage> image, 26 const DrawImage& image,
26 const ImageDecodedCallback& callback) override { 27 const ImageDecodedCallback& callback) override {
27 auto id = next_id_++; 28 auto id = next_id_++;
28 locked_ids_.push_back(id); 29 locked_ids_.push_back(id);
29 callback.Run(id, ImageDecodeResult::SUCCESS); 30 callback.Run(id, ImageDecodeResult::SUCCESS);
30 return id; 31 return id;
31 } 32 }
32 33
33 size_t num_locked_images() { return locked_ids_.size(); } 34 size_t num_locked_images() { return locked_ids_.size(); }
34 35
35 private: 36 private:
(...skipping 13 matching lines...) Expand all
49 } 50 }
50 51
51 private: 52 private:
52 TestImageController image_controller_; 53 TestImageController image_controller_;
53 DecodedImageTracker decoded_image_tracker_; 54 DecodedImageTracker decoded_image_tracker_;
54 }; 55 };
55 56
56 TEST_F(DecodedImageTrackerTest, QueueImageLocksImages) { 57 TEST_F(DecodedImageTrackerTest, QueueImageLocksImages) {
57 bool locked = false; 58 bool locked = false;
58 decoded_image_tracker()->QueueImageDecode( 59 decoded_image_tracker()->QueueImageDecode(
59 PaintImage(), 60 PaintImage(PaintImage::GetNextId(),
61 CreateDiscardableImage(gfx::Size(1, 1))),
60 base::Bind([](bool* locked, bool success) { *locked = true; }, 62 base::Bind([](bool* locked, bool success) { *locked = true; },
61 base::Unretained(&locked))); 63 base::Unretained(&locked)));
62 EXPECT_TRUE(locked); 64 EXPECT_TRUE(locked);
63 EXPECT_EQ(1u, image_controller()->num_locked_images()); 65 EXPECT_EQ(1u, image_controller()->num_locked_images());
64 } 66 }
65 67
66 TEST_F(DecodedImageTrackerTest, NotifyFrameFinishedUnlocksImages) { 68 TEST_F(DecodedImageTrackerTest, NotifyFrameFinishedUnlocksImages) {
67 bool locked = false; 69 bool locked = false;
68 decoded_image_tracker()->QueueImageDecode( 70 decoded_image_tracker()->QueueImageDecode(
69 PaintImage(), 71 PaintImage(PaintImage::GetNextId(),
72 CreateDiscardableImage(gfx::Size(1, 1))),
70 base::Bind([](bool* locked, bool success) { *locked = true; }, 73 base::Bind([](bool* locked, bool success) { *locked = true; },
71 base::Unretained(&locked))); 74 base::Unretained(&locked)));
72 EXPECT_TRUE(locked); 75 EXPECT_TRUE(locked);
73 EXPECT_EQ(1u, image_controller()->num_locked_images()); 76 EXPECT_EQ(1u, image_controller()->num_locked_images());
74 77
75 decoded_image_tracker()->NotifyFrameFinished(); 78 decoded_image_tracker()->NotifyFrameFinished();
76 EXPECT_EQ(1u, image_controller()->num_locked_images()); 79 EXPECT_EQ(1u, image_controller()->num_locked_images());
77 80
78 locked = false; 81 locked = false;
79 decoded_image_tracker()->QueueImageDecode( 82 decoded_image_tracker()->QueueImageDecode(
80 PaintImage(), 83 PaintImage(PaintImage::GetNextId(),
84 CreateDiscardableImage(gfx::Size(1, 1))),
81 base::Bind([](bool* locked, bool success) { *locked = true; }, 85 base::Bind([](bool* locked, bool success) { *locked = true; },
82 base::Unretained(&locked))); 86 base::Unretained(&locked)));
83 EXPECT_TRUE(locked); 87 EXPECT_TRUE(locked);
84 EXPECT_EQ(2u, image_controller()->num_locked_images()); 88 EXPECT_EQ(2u, image_controller()->num_locked_images());
85 89
86 decoded_image_tracker()->NotifyFrameFinished(); 90 decoded_image_tracker()->NotifyFrameFinished();
87 EXPECT_EQ(1u, image_controller()->num_locked_images()); 91 EXPECT_EQ(1u, image_controller()->num_locked_images());
88 92
89 decoded_image_tracker()->NotifyFrameFinished(); 93 decoded_image_tracker()->NotifyFrameFinished();
90 EXPECT_EQ(0u, image_controller()->num_locked_images()); 94 EXPECT_EQ(0u, image_controller()->num_locked_images());
91 } 95 }
92 96
93 } // namespace cc 97 } // namespace cc
OLDNEW
« no previous file with comments | « cc/tiles/decoded_image_tracker.cc ('k') | cc/tiles/image_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698