| OLD | NEW |
| 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 "base/memory/scoped_ptr.h" | 5 #include "base/memory/scoped_ptr.h" |
| 6 #include "cc/playback/display_list_raster_source.h" | 6 #include "cc/playback/display_list_raster_source.h" |
| 7 #include "cc/test/fake_display_list_recording_source.h" | 7 #include "cc/test/fake_display_list_recording_source.h" |
| 8 #include "cc/test/skia_common.h" | 8 #include "cc/test/skia_common.h" |
| 9 #include "skia/ext/refptr.h" | 9 #include "skia/ext/refptr.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 gfx::Point(260, 260)); | 193 gfx::Point(260, 260)); |
| 194 recording_source->SetGatherPixelRefs(true); | 194 recording_source->SetGatherPixelRefs(true); |
| 195 recording_source->Rerecord(); | 195 recording_source->Rerecord(); |
| 196 | 196 |
| 197 scoped_refptr<DisplayListRasterSource> raster = | 197 scoped_refptr<DisplayListRasterSource> raster = |
| 198 DisplayListRasterSource::CreateFromDisplayListRecordingSource( | 198 DisplayListRasterSource::CreateFromDisplayListRecordingSource( |
| 199 recording_source.get(), false); | 199 recording_source.get(), false); |
| 200 | 200 |
| 201 // Tile sized iterators. These should find only one pixel ref. | 201 // Tile sized iterators. These should find only one pixel ref. |
| 202 { | 202 { |
| 203 std::vector<SkPixelRef*> pixel_refs; | 203 std::vector<skia::PositionPixelRef> pixel_refs; |
| 204 raster->GatherPixelRefs(gfx::Rect(0, 0, 256, 256), 1.0, &pixel_refs); | 204 raster->GatherPixelRefs(gfx::Rect(0, 0, 256, 256), 1.0, &pixel_refs); |
| 205 EXPECT_EQ(1u, pixel_refs.size()); | 205 EXPECT_EQ(1u, pixel_refs.size()); |
| 206 EXPECT_EQ(discardable_bitmap[0][0].pixelRef(), pixel_refs[0]); | 206 EXPECT_EQ(discardable_bitmap[0][0].pixelRef(), pixel_refs[0].pixel_ref); |
| 207 EXPECT_EQ(gfx::RectF(32, 32).ToString(), |
| 208 gfx::SkRectToRectF(pixel_refs[0].pixel_ref_rect).ToString()); |
| 207 } | 209 } |
| 208 { | 210 { |
| 209 std::vector<SkPixelRef*> pixel_refs; | 211 std::vector<skia::PositionPixelRef> pixel_refs; |
| 210 raster->GatherPixelRefs(gfx::Rect(0, 0, 512, 512), 2.0, &pixel_refs); | 212 raster->GatherPixelRefs(gfx::Rect(0, 0, 512, 512), 2.0, &pixel_refs); |
| 211 EXPECT_EQ(1u, pixel_refs.size()); | 213 EXPECT_EQ(1u, pixel_refs.size()); |
| 212 EXPECT_EQ(discardable_bitmap[0][0].pixelRef(), pixel_refs[0]); | 214 EXPECT_EQ(discardable_bitmap[0][0].pixelRef(), pixel_refs[0].pixel_ref); |
| 215 EXPECT_EQ(gfx::RectF(32, 32).ToString(), |
| 216 gfx::SkRectToRectF(pixel_refs[0].pixel_ref_rect).ToString()); |
| 213 } | 217 } |
| 214 { | 218 { |
| 215 std::vector<SkPixelRef*> pixel_refs; | 219 std::vector<skia::PositionPixelRef> pixel_refs; |
| 216 raster->GatherPixelRefs(gfx::Rect(0, 0, 128, 128), 0.5, &pixel_refs); | 220 raster->GatherPixelRefs(gfx::Rect(0, 0, 128, 128), 0.5, &pixel_refs); |
| 217 EXPECT_EQ(1u, pixel_refs.size()); | 221 EXPECT_EQ(1u, pixel_refs.size()); |
| 218 EXPECT_EQ(discardable_bitmap[0][0].pixelRef(), pixel_refs[0]); | 222 EXPECT_EQ(discardable_bitmap[0][0].pixelRef(), pixel_refs[0].pixel_ref); |
| 223 EXPECT_EQ(gfx::RectF(32, 32).ToString(), |
| 224 gfx::SkRectToRectF(pixel_refs[0].pixel_ref_rect).ToString()); |
| 219 } | 225 } |
| 220 // Shifted tile sized iterators. These should find only one pixel ref. | 226 // Shifted tile sized iterators. These should find only one pixel ref. |
| 221 { | 227 { |
| 222 std::vector<SkPixelRef*> pixel_refs; | 228 std::vector<skia::PositionPixelRef> pixel_refs; |
| 223 raster->GatherPixelRefs(gfx::Rect(260, 260, 256, 256), 1.0, &pixel_refs); | 229 raster->GatherPixelRefs(gfx::Rect(260, 260, 256, 256), 1.0, &pixel_refs); |
| 224 EXPECT_EQ(1u, pixel_refs.size()); | 230 EXPECT_EQ(1u, pixel_refs.size()); |
| 225 EXPECT_EQ(discardable_bitmap[1][1].pixelRef(), pixel_refs[0]); | 231 EXPECT_EQ(discardable_bitmap[1][1].pixelRef(), pixel_refs[0].pixel_ref); |
| 232 EXPECT_EQ(gfx::RectF(260, 260, 32, 32).ToString(), |
| 233 gfx::SkRectToRectF(pixel_refs[0].pixel_ref_rect).ToString()); |
| 226 } | 234 } |
| 227 { | 235 { |
| 228 std::vector<SkPixelRef*> pixel_refs; | 236 std::vector<skia::PositionPixelRef> pixel_refs; |
| 229 raster->GatherPixelRefs(gfx::Rect(520, 520, 512, 512), 2.0, &pixel_refs); | 237 raster->GatherPixelRefs(gfx::Rect(520, 520, 512, 512), 2.0, &pixel_refs); |
| 230 EXPECT_EQ(1u, pixel_refs.size()); | 238 EXPECT_EQ(1u, pixel_refs.size()); |
| 231 EXPECT_EQ(discardable_bitmap[1][1].pixelRef(), pixel_refs[0]); | 239 EXPECT_EQ(discardable_bitmap[1][1].pixelRef(), pixel_refs[0].pixel_ref); |
| 240 EXPECT_EQ(gfx::RectF(260, 260, 32, 32).ToString(), |
| 241 gfx::SkRectToRectF(pixel_refs[0].pixel_ref_rect).ToString()); |
| 232 } | 242 } |
| 233 { | 243 { |
| 234 std::vector<SkPixelRef*> pixel_refs; | 244 std::vector<skia::PositionPixelRef> pixel_refs; |
| 235 raster->GatherPixelRefs(gfx::Rect(130, 130, 128, 128), 0.5, &pixel_refs); | 245 raster->GatherPixelRefs(gfx::Rect(130, 130, 128, 128), 0.5, &pixel_refs); |
| 236 EXPECT_EQ(1u, pixel_refs.size()); | 246 EXPECT_EQ(1u, pixel_refs.size()); |
| 237 EXPECT_EQ(discardable_bitmap[1][1].pixelRef(), pixel_refs[0]); | 247 EXPECT_EQ(discardable_bitmap[1][1].pixelRef(), pixel_refs[0].pixel_ref); |
| 248 EXPECT_EQ(gfx::RectF(260, 260, 32, 32).ToString(), |
| 249 gfx::SkRectToRectF(pixel_refs[0].pixel_ref_rect).ToString()); |
| 238 } | 250 } |
| 239 // Ensure there's no discardable pixel refs in the empty cell | 251 // Ensure there's no discardable pixel refs in the empty cell |
| 240 { | 252 { |
| 241 std::vector<SkPixelRef*> pixel_refs; | 253 std::vector<skia::PositionPixelRef> pixel_refs; |
| 242 raster->GatherPixelRefs(gfx::Rect(0, 256, 256, 256), 1.0, &pixel_refs); | 254 raster->GatherPixelRefs(gfx::Rect(0, 256, 256, 256), 1.0, &pixel_refs); |
| 243 EXPECT_EQ(0u, pixel_refs.size()); | 255 EXPECT_EQ(0u, pixel_refs.size()); |
| 244 } | 256 } |
| 245 // Layer sized iterators. These should find three pixel ref. | 257 // Layer sized iterators. These should find three pixel ref. |
| 246 { | 258 { |
| 247 std::vector<SkPixelRef*> pixel_refs; | 259 std::vector<skia::PositionPixelRef> pixel_refs; |
| 248 raster->GatherPixelRefs(gfx::Rect(0, 0, 512, 512), 1.0, &pixel_refs); | 260 raster->GatherPixelRefs(gfx::Rect(0, 0, 512, 512), 1.0, &pixel_refs); |
| 249 EXPECT_EQ(3u, pixel_refs.size()); | 261 EXPECT_EQ(3u, pixel_refs.size()); |
| 250 EXPECT_EQ(discardable_bitmap[0][0].pixelRef(), pixel_refs[0]); | 262 EXPECT_EQ(discardable_bitmap[0][0].pixelRef(), pixel_refs[0].pixel_ref); |
| 251 EXPECT_EQ(discardable_bitmap[0][1].pixelRef(), pixel_refs[1]); | 263 EXPECT_EQ(discardable_bitmap[0][1].pixelRef(), pixel_refs[1].pixel_ref); |
| 252 EXPECT_EQ(discardable_bitmap[1][1].pixelRef(), pixel_refs[2]); | 264 EXPECT_EQ(discardable_bitmap[1][1].pixelRef(), pixel_refs[2].pixel_ref); |
| 265 EXPECT_EQ(gfx::RectF(32, 32).ToString(), |
| 266 gfx::SkRectToRectF(pixel_refs[0].pixel_ref_rect).ToString()); |
| 267 EXPECT_EQ(gfx::RectF(260, 0, 32, 32).ToString(), |
| 268 gfx::SkRectToRectF(pixel_refs[1].pixel_ref_rect).ToString()); |
| 269 EXPECT_EQ(gfx::RectF(260, 260, 32, 32).ToString(), |
| 270 gfx::SkRectToRectF(pixel_refs[2].pixel_ref_rect).ToString()); |
| 253 } | 271 } |
| 254 { | 272 { |
| 255 std::vector<SkPixelRef*> pixel_refs; | 273 std::vector<skia::PositionPixelRef> pixel_refs; |
| 256 raster->GatherPixelRefs(gfx::Rect(0, 0, 1024, 1024), 2.0, &pixel_refs); | 274 raster->GatherPixelRefs(gfx::Rect(0, 0, 1024, 1024), 2.0, &pixel_refs); |
| 257 EXPECT_EQ(3u, pixel_refs.size()); | 275 EXPECT_EQ(3u, pixel_refs.size()); |
| 258 EXPECT_EQ(discardable_bitmap[0][0].pixelRef(), pixel_refs[0]); | 276 EXPECT_EQ(discardable_bitmap[0][0].pixelRef(), pixel_refs[0].pixel_ref); |
| 259 EXPECT_EQ(discardable_bitmap[0][1].pixelRef(), pixel_refs[1]); | 277 EXPECT_EQ(discardable_bitmap[0][1].pixelRef(), pixel_refs[1].pixel_ref); |
| 260 EXPECT_EQ(discardable_bitmap[1][1].pixelRef(), pixel_refs[2]); | 278 EXPECT_EQ(discardable_bitmap[1][1].pixelRef(), pixel_refs[2].pixel_ref); |
| 279 EXPECT_EQ(gfx::RectF(32, 32).ToString(), |
| 280 gfx::SkRectToRectF(pixel_refs[0].pixel_ref_rect).ToString()); |
| 281 EXPECT_EQ(gfx::RectF(260, 0, 32, 32).ToString(), |
| 282 gfx::SkRectToRectF(pixel_refs[1].pixel_ref_rect).ToString()); |
| 283 EXPECT_EQ(gfx::RectF(260, 260, 32, 32).ToString(), |
| 284 gfx::SkRectToRectF(pixel_refs[2].pixel_ref_rect).ToString()); |
| 261 } | 285 } |
| 262 { | 286 { |
| 263 std::vector<SkPixelRef*> pixel_refs; | 287 std::vector<skia::PositionPixelRef> pixel_refs; |
| 264 raster->GatherPixelRefs(gfx::Rect(0, 0, 256, 256), 0.5, &pixel_refs); | 288 raster->GatherPixelRefs(gfx::Rect(0, 0, 256, 256), 0.5, &pixel_refs); |
| 265 EXPECT_EQ(3u, pixel_refs.size()); | 289 EXPECT_EQ(3u, pixel_refs.size()); |
| 266 EXPECT_EQ(discardable_bitmap[0][0].pixelRef(), pixel_refs[0]); | 290 EXPECT_EQ(discardable_bitmap[0][0].pixelRef(), pixel_refs[0].pixel_ref); |
| 267 EXPECT_EQ(discardable_bitmap[0][1].pixelRef(), pixel_refs[1]); | 291 EXPECT_EQ(discardable_bitmap[0][1].pixelRef(), pixel_refs[1].pixel_ref); |
| 268 EXPECT_EQ(discardable_bitmap[1][1].pixelRef(), pixel_refs[2]); | 292 EXPECT_EQ(discardable_bitmap[1][1].pixelRef(), pixel_refs[2].pixel_ref); |
| 293 EXPECT_EQ(gfx::RectF(32, 32).ToString(), |
| 294 gfx::SkRectToRectF(pixel_refs[0].pixel_ref_rect).ToString()); |
| 295 EXPECT_EQ(gfx::RectF(260, 0, 32, 32).ToString(), |
| 296 gfx::SkRectToRectF(pixel_refs[1].pixel_ref_rect).ToString()); |
| 297 EXPECT_EQ(gfx::RectF(260, 260, 32, 32).ToString(), |
| 298 gfx::SkRectToRectF(pixel_refs[2].pixel_ref_rect).ToString()); |
| 269 } | 299 } |
| 270 } | 300 } |
| 271 | 301 |
| 272 TEST(DisplayListRasterSourceTest, RasterFullContents) { | 302 TEST(DisplayListRasterSourceTest, RasterFullContents) { |
| 273 gfx::Size layer_bounds(3, 5); | 303 gfx::Size layer_bounds(3, 5); |
| 274 float contents_scale = 1.5f; | 304 float contents_scale = 1.5f; |
| 275 float raster_divisions = 2.f; | 305 float raster_divisions = 2.f; |
| 276 | 306 |
| 277 scoped_ptr<FakeDisplayListRecordingSource> recording_source = | 307 scoped_ptr<FakeDisplayListRecordingSource> recording_source = |
| 278 FakeDisplayListRecordingSource::CreateFilledRecordingSource(layer_bounds); | 308 FakeDisplayListRecordingSource::CreateFilledRecordingSource(layer_bounds); |
| (...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 564 scoped_refptr<DisplayListRasterSource> raster = | 594 scoped_refptr<DisplayListRasterSource> raster = |
| 565 DisplayListRasterSource::CreateFromDisplayListRecordingSource( | 595 DisplayListRasterSource::CreateFromDisplayListRecordingSource( |
| 566 recording_source.get(), false); | 596 recording_source.get(), false); |
| 567 size_t total_memory_usage = raster->GetPictureMemoryUsage(); | 597 size_t total_memory_usage = raster->GetPictureMemoryUsage(); |
| 568 EXPECT_GE(total_memory_usage, kReportedMemoryUsageInBytes); | 598 EXPECT_GE(total_memory_usage, kReportedMemoryUsageInBytes); |
| 569 EXPECT_LT(total_memory_usage, 2 * kReportedMemoryUsageInBytes); | 599 EXPECT_LT(total_memory_usage, 2 * kReportedMemoryUsageInBytes); |
| 570 } | 600 } |
| 571 | 601 |
| 572 } // namespace | 602 } // namespace |
| 573 } // namespace cc | 603 } // namespace cc |
| OLD | NEW |