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

Side by Side Diff: cc/resources/picture_unittest.cc

Issue 14230007: cc: Do GatherPixelRefs from skia at record time (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: unittests + enne's review Created 7 years, 8 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/resources/picture.h" 5 #include "cc/resources/picture.h"
6 6
7 #include "base/memory/ref_counted.h" 7 #include "base/memory/ref_counted.h"
8 #include "base/memory/scoped_ptr.h"
8 #include "cc/test/fake_content_layer_client.h" 9 #include "cc/test/fake_content_layer_client.h"
9 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
10 #include "third_party/skia/include/core/SkCanvas.h" 11 #include "third_party/skia/include/core/SkCanvas.h"
11 #include "third_party/skia/include/core/SkDevice.h" 12 #include "third_party/skia/include/core/SkDevice.h"
12 #include "third_party/skia/include/core/SkGraphics.h" 13 #include "third_party/skia/include/core/SkGraphics.h"
14 #include "third_party/skia/include/core/SkPixelRef.h"
13 #include "third_party/skia/include/core/SkTileGridPicture.h" 15 #include "third_party/skia/include/core/SkTileGridPicture.h"
14 #include "ui/gfx/rect.h" 16 #include "ui/gfx/rect.h"
15 #include "ui/gfx/skia_util.h" 17 #include "ui/gfx/skia_util.h"
16 18
17 namespace cc { 19 namespace cc {
18 namespace { 20 namespace {
19 21
22 class TestLazyPixelRef : public skia::LazyPixelRef {
23 public:
24 // Pure virtual implementation.
25 TestLazyPixelRef(int width, int height)
26 : pixels_(new char[4 * width * height]) {}
27 virtual SkFlattenable::Factory getFactory() OVERRIDE { return NULL; }
28 virtual void* onLockPixels(SkColorTable** color_table) OVERRIDE {
29 return pixels_.get();
30 }
31 virtual void onUnlockPixels() OVERRIDE {}
32 virtual bool PrepareToDecode(const PrepareParams& params) OVERRIDE {
33 return true;
34 }
35 virtual SkPixelRef* deepCopy(
36 SkBitmap::Config config,
37 const SkIRect* subset) OVERRIDE {
38 this->ref();
39 return this;
40 }
41 virtual void Decode() OVERRIDE {}
42 private:
43 scoped_ptr<char[]> pixels_;
44 };
45
20 void DrawPicture(unsigned char* buffer, 46 void DrawPicture(unsigned char* buffer,
21 gfx::Rect layer_rect, 47 gfx::Rect layer_rect,
22 scoped_refptr<Picture> picture) { 48 scoped_refptr<Picture> picture) {
23 SkBitmap bitmap; 49 SkBitmap bitmap;
24 bitmap.setConfig(SkBitmap::kARGB_8888_Config, 50 bitmap.setConfig(SkBitmap::kARGB_8888_Config,
25 layer_rect.width(), 51 layer_rect.width(),
26 layer_rect.height()); 52 layer_rect.height());
27 bitmap.setPixels(buffer); 53 bitmap.setPixels(buffer);
28 SkDevice device(bitmap); 54 SkDevice device(bitmap);
29 SkCanvas canvas(&device); 55 SkCanvas canvas(&device);
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 DrawPicture(two_rect_buffer_check, layer_rect, two_rect_picture_check); 139 DrawPicture(two_rect_buffer_check, layer_rect, two_rect_picture_check);
114 140
115 EXPECT_EQ(two_rect_picture->LayerRect(), 141 EXPECT_EQ(two_rect_picture->LayerRect(),
116 two_rect_picture_check->LayerRect()); 142 two_rect_picture_check->LayerRect());
117 EXPECT_EQ(two_rect_picture->OpaqueRect(), 143 EXPECT_EQ(two_rect_picture->OpaqueRect(),
118 two_rect_picture_check->OpaqueRect()); 144 two_rect_picture_check->OpaqueRect());
119 EXPECT_TRUE( 145 EXPECT_TRUE(
120 memcmp(two_rect_buffer, two_rect_buffer_check, 4 * 100 * 100) == 0); 146 memcmp(two_rect_buffer, two_rect_buffer_check, 4 * 100 * 100) == 0);
121 } 147 }
122 148
149 TEST(PictureTest, LazyPixelRefIterator) {
150 gfx::Rect layer_rect(2048, 2048);
151
152 SkTileGridPicture::TileGridInfo tile_grid_info;
153 tile_grid_info.fTileInterval = SkISize::Make(100, 100);
154 tile_grid_info.fMargin.setEmpty();
155 tile_grid_info.fOffset.setZero();
156
157 FakeContentLayerClient content_layer_client;
158
159 SkAutoTUnref<TestLazyPixelRef> lazy_pixel_ref;
160 lazy_pixel_ref.reset(new TestLazyPixelRef(32, 32));
161 lazy_pixel_ref->setURI("lazy");
162
163 SkBitmap lazy_bitmap;
164 lazy_bitmap.setConfig(SkBitmap::kARGB_8888_Config, 500, 500);
165 lazy_bitmap.setPixelRef(lazy_pixel_ref);
166
167 // Lazy pixel refs are found in the following grids:
168 // |---|---|---|---|
169 // | | x | | x |
170 // |---|---|---|---|
171 // | x | | x | |
172 // |---|---|---|---|
173 // | | x | | x |
174 // |---|---|---|---|
175 // | x | | x | |
176 // |---|---|---|---|
177 for (int y = 0; y < 4; ++y) {
178 for (int x = 0; x < 4; ++x) {
179 if ((x + y) & 1) {
180 content_layer_client.add_draw_bitmap(
181 lazy_bitmap,
182 gfx::Point(x * 512 + 6, y * 512 + 6));
183 }
184 }
185 }
186
187 scoped_refptr<Picture> picture = Picture::Create(layer_rect);
188 picture->Record(&content_layer_client, NULL, tile_grid_info);
189
190 // Default iterator does not have any pixel refs
191 {
192 Picture::LazyPixelRefIterator iterator;
193 EXPECT_FALSE(iterator);
194 // Incrementing an invalid iterator does not do anything.
195 EXPECT_FALSE(++iterator);
196 EXPECT_FALSE(++iterator);
197 EXPECT_FALSE(++iterator);
198 EXPECT_FALSE(++iterator);
199 }
200 for (int y = 0; y < 4; ++y) {
201 for (int x = 0; x < 4; ++x) {
202 Picture::LazyPixelRefIterator iterator(
203 gfx::Rect(x * 512, y * 512, 500, 500),
204 picture);
205 if ((x + y) & 1) {
206 EXPECT_TRUE(iterator) << x << " " << y;
207 EXPECT_FALSE(++iterator) << x << " " << y;
208 } else {
209 EXPECT_FALSE(iterator) << x << " " << y;
210 }
211 }
212 }
213 // Capture 4 pixel refs.
214 {
215 Picture::LazyPixelRefIterator iterator(
216 gfx::Rect(512, 512, 2048, 2048),
217 picture);
218 EXPECT_TRUE(iterator);
219 EXPECT_TRUE(++iterator);
220 EXPECT_TRUE(++iterator);
221 EXPECT_TRUE(++iterator);
222 EXPECT_FALSE(++iterator);
223 }
224
225 // Copy test.
226 Picture::LazyPixelRefIterator iterator(
227 gfx::Rect(512, 512, 2048, 2048),
228 picture);
229 EXPECT_TRUE(iterator);
230 EXPECT_TRUE(++iterator);
231
232 // copy now points to the same spot as iterator,
233 // but both can be incremented independently.
234 Picture::LazyPixelRefIterator copy = iterator;
235 EXPECT_TRUE(++iterator);
236 EXPECT_TRUE(++iterator);
237 EXPECT_FALSE(++iterator);
238
239 EXPECT_TRUE(copy);
240 EXPECT_TRUE(++copy);
241 EXPECT_TRUE(++copy);
242 EXPECT_FALSE(++copy);
243 }
244
123 } // namespace 245 } // namespace
124 } // namespace cc 246 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698