| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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_layer_tiling.h" | 5 #include "cc/resources/picture_layer_tiling.h" |
| 6 | 6 |
| 7 #include <limits> | 7 #include <limits> |
| 8 | 8 |
| 9 #include "cc/base/math_util.h" | 9 #include "cc/base/math_util.h" |
| 10 #include "cc/resources/picture_layer_tiling_set.h" | 10 #include "cc/resources/picture_layer_tiling_set.h" |
| 11 #include "cc/test/fake_picture_layer_tiling_client.h" | 11 #include "cc/test/fake_picture_layer_tiling_client.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 13 #include "ui/gfx/rect_conversions.h" | 13 #include "ui/gfx/rect_conversions.h" |
| 14 #include "ui/gfx/size_conversions.h" | 14 #include "ui/gfx/size_conversions.h" |
| 15 | 15 |
| 16 namespace cc { | 16 namespace cc { |
| 17 namespace { | 17 namespace { |
| 18 | 18 |
| 19 static gfx::Rect ViewportInLayerSpace( | 19 static gfx::Rect ViewportInLayerSpace( |
| 20 const gfx::Transform& transform, | 20 const gfx::Transform& transform, |
| 21 const gfx::Size& device_viewport) { | 21 gfx::Size device_viewport) { |
| 22 | 22 |
| 23 gfx::Transform inverse; | 23 gfx::Transform inverse; |
| 24 if (!transform.GetInverse(&inverse)) | 24 if (!transform.GetInverse(&inverse)) |
| 25 return gfx::Rect(); | 25 return gfx::Rect(); |
| 26 | 26 |
| 27 gfx::RectF viewport_in_layer_space = MathUtil::ProjectClippedRect( | 27 gfx::RectF viewport_in_layer_space = MathUtil::ProjectClippedRect( |
| 28 inverse, gfx::RectF(gfx::Point(0, 0), device_viewport)); | 28 inverse, gfx::RectF(gfx::Point(0, 0), device_viewport)); |
| 29 | 29 |
| 30 return ToEnclosingRect(viewport_in_layer_space); | 30 return ToEnclosingRect(viewport_in_layer_space); |
| 31 } | 31 } |
| 32 | 32 |
| 33 class TestablePictureLayerTiling : public PictureLayerTiling { | 33 class TestablePictureLayerTiling : public PictureLayerTiling { |
| 34 public: | 34 public: |
| 35 using PictureLayerTiling::SetLiveTilesRect; | 35 using PictureLayerTiling::SetLiveTilesRect; |
| 36 using PictureLayerTiling::TileAt; | 36 using PictureLayerTiling::TileAt; |
| 37 | 37 |
| 38 static scoped_ptr<TestablePictureLayerTiling> Create( | 38 static scoped_ptr<TestablePictureLayerTiling> Create( |
| 39 float contents_scale, | 39 float contents_scale, |
| 40 const gfx::Size& layer_bounds, | 40 gfx::Size layer_bounds, |
| 41 PictureLayerTilingClient* client) { | 41 PictureLayerTilingClient* client) { |
| 42 return make_scoped_ptr(new TestablePictureLayerTiling( | 42 return make_scoped_ptr(new TestablePictureLayerTiling( |
| 43 contents_scale, | 43 contents_scale, |
| 44 layer_bounds, | 44 layer_bounds, |
| 45 client)); | 45 client)); |
| 46 } | 46 } |
| 47 | 47 |
| 48 protected: | 48 protected: |
| 49 TestablePictureLayerTiling(float contents_scale, | 49 TestablePictureLayerTiling(float contents_scale, |
| 50 const gfx::Size& layer_bounds, | 50 gfx::Size layer_bounds, |
| 51 PictureLayerTilingClient* client) | 51 PictureLayerTilingClient* client) |
| 52 : PictureLayerTiling(contents_scale, layer_bounds, client) { } | 52 : PictureLayerTiling(contents_scale, layer_bounds, client) { } |
| 53 }; | 53 }; |
| 54 | 54 |
| 55 class PictureLayerTilingIteratorTest : public testing::Test { | 55 class PictureLayerTilingIteratorTest : public testing::Test { |
| 56 public: | 56 public: |
| 57 PictureLayerTilingIteratorTest() {} | 57 PictureLayerTilingIteratorTest() {} |
| 58 virtual ~PictureLayerTilingIteratorTest() {} | 58 virtual ~PictureLayerTilingIteratorTest() {} |
| 59 | 59 |
| 60 void Initialize(const gfx::Size& tile_size, | 60 void Initialize(gfx::Size tile_size, |
| 61 float contents_scale, | 61 float contents_scale, |
| 62 const gfx::Size& layer_bounds) { | 62 gfx::Size layer_bounds) { |
| 63 client_.SetTileSize(tile_size); | 63 client_.SetTileSize(tile_size); |
| 64 tiling_ = TestablePictureLayerTiling::Create(contents_scale, | 64 tiling_ = TestablePictureLayerTiling::Create(contents_scale, |
| 65 layer_bounds, | 65 layer_bounds, |
| 66 &client_); | 66 &client_); |
| 67 } | 67 } |
| 68 | 68 |
| 69 void SetLiveRectAndVerifyTiles(const gfx::Rect& live_tiles_rect) { | 69 void SetLiveRectAndVerifyTiles(const gfx::Rect& live_tiles_rect) { |
| 70 tiling_->SetLiveTilesRect(live_tiles_rect); | 70 tiling_->SetLiveTilesRect(live_tiles_rect); |
| 71 | 71 |
| 72 std::vector<Tile*> tiles = tiling_->AllTilesForTesting(); | 72 std::vector<Tile*> tiles = tiling_->AllTilesForTesting(); |
| (...skipping 1335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1408 EXPECT_GT(priority.time_to_visible_in_seconds, 0.f); | 1408 EXPECT_GT(priority.time_to_visible_in_seconds, 0.f); |
| 1409 | 1409 |
| 1410 priority = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); | 1410 priority = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); |
| 1411 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 1411 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); |
| 1412 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), | 1412 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), |
| 1413 priority.time_to_visible_in_seconds); | 1413 priority.time_to_visible_in_seconds); |
| 1414 } | 1414 } |
| 1415 | 1415 |
| 1416 } // namespace | 1416 } // namespace |
| 1417 } // namespace cc | 1417 } // namespace cc |
| OLD | NEW |