| 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 <algorithm> | 7 #include <algorithm> | 
| 8 #include <cmath> | 8 #include <cmath> | 
| 9 #include <limits> | 9 #include <limits> | 
| 10 #include <set> | 10 #include <set> | 
| 11 | 11 | 
| 12 #include "base/logging.h" | 12 #include "base/logging.h" | 
| 13 #include "base/trace_event/trace_event.h" | 13 #include "base/trace_event/trace_event.h" | 
| 14 #include "base/trace_event/trace_event_argument.h" | 14 #include "base/trace_event/trace_event_argument.h" | 
| 15 #include "cc/base/math_util.h" | 15 #include "cc/base/math_util.h" | 
| 16 #include "cc/resources/tile.h" | 16 #include "cc/resources/tile.h" | 
| 17 #include "cc/resources/tile_priority.h" | 17 #include "cc/resources/tile_priority.h" | 
| 18 #include "ui/gfx/geometry/point_conversions.h" | 18 #include "ui/gfx/geometry/point_conversions.h" | 
| 19 #include "ui/gfx/geometry/rect_conversions.h" | 19 #include "ui/gfx/geometry/rect_conversions.h" | 
| 20 #include "ui/gfx/geometry/safe_integer_conversions.h" | 20 #include "ui/gfx/geometry/safe_integer_conversions.h" | 
| 21 #include "ui/gfx/geometry/size_conversions.h" | 21 #include "ui/gfx/geometry/size_conversions.h" | 
| 22 | 22 | 
| 23 namespace cc { | 23 namespace cc { | 
| 24 namespace { | 24 namespace { | 
| 25 | 25 | 
| 26 const float kSoonBorderDistanceInScreenPixels = 312.f; | 26 const float kSoonBorderDistanceViewportPercentage = 0.15f; | 
|  | 27 const float kMaxSoonBorderDistanceInScreenPixels = 312.f; | 
| 27 | 28 | 
| 28 }  // namespace | 29 }  // namespace | 
| 29 | 30 | 
| 30 scoped_ptr<PictureLayerTiling> PictureLayerTiling::Create( | 31 scoped_ptr<PictureLayerTiling> PictureLayerTiling::Create( | 
| 31     float contents_scale, | 32     float contents_scale, | 
| 32     scoped_refptr<RasterSource> raster_source, | 33     scoped_refptr<RasterSource> raster_source, | 
| 33     PictureLayerTilingClient* client, | 34     PictureLayerTilingClient* client, | 
| 34     size_t max_tiles_for_interest_area, | 35     size_t max_tiles_for_interest_area, | 
| 35     float skewport_target_time_in_seconds, | 36     float skewport_target_time_in_seconds, | 
| 36     int skewport_extrapolation_limit_in_content_pixels) { | 37     int skewport_extrapolation_limit_in_content_pixels) { | 
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 76 | 77 | 
| 77   tiling_data_.SetTilingSize(content_bounds); | 78   tiling_data_.SetTilingSize(content_bounds); | 
| 78   tiling_data_.SetMaxTextureSize(tile_size); | 79   tiling_data_.SetMaxTextureSize(tile_size); | 
| 79 } | 80 } | 
| 80 | 81 | 
| 81 PictureLayerTiling::~PictureLayerTiling() { | 82 PictureLayerTiling::~PictureLayerTiling() { | 
| 82   for (TileMap::const_iterator it = tiles_.begin(); it != tiles_.end(); ++it) | 83   for (TileMap::const_iterator it = tiles_.begin(); it != tiles_.end(); ++it) | 
| 83     it->second->set_shared(false); | 84     it->second->set_shared(false); | 
| 84 } | 85 } | 
| 85 | 86 | 
|  | 87 // static | 
|  | 88 float PictureLayerTiling::CalculateSoonBorderDistance( | 
|  | 89     const gfx::Rect& visible_rect_in_content_space, | 
|  | 90     float content_to_screen_scale) { | 
|  | 91   float max_dimension = std::max(visible_rect_in_content_space.width(), | 
|  | 92                                  visible_rect_in_content_space.height()); | 
|  | 93   return std::min( | 
|  | 94       kMaxSoonBorderDistanceInScreenPixels / content_to_screen_scale, | 
|  | 95       max_dimension * kSoonBorderDistanceViewportPercentage); | 
|  | 96 } | 
|  | 97 | 
| 86 Tile* PictureLayerTiling::CreateTile(int i, | 98 Tile* PictureLayerTiling::CreateTile(int i, | 
| 87                                      int j, | 99                                      int j, | 
| 88                                      const PictureLayerTiling* twin_tiling, | 100                                      const PictureLayerTiling* twin_tiling, | 
| 89                                      PictureLayerTiling* recycled_twin) { | 101                                      PictureLayerTiling* recycled_twin) { | 
| 90   // Can't have both a (pending or active) twin and a recycled twin tiling. | 102   // Can't have both a (pending or active) twin and a recycled twin tiling. | 
| 91   DCHECK_IMPLIES(twin_tiling, !recycled_twin); | 103   DCHECK_IMPLIES(twin_tiling, !recycled_twin); | 
| 92   DCHECK_IMPLIES(recycled_twin, !twin_tiling); | 104   DCHECK_IMPLIES(recycled_twin, !twin_tiling); | 
| 93   TileMapKey key(i, j); | 105   TileMapKey key(i, j); | 
| 94   DCHECK(tiles_.find(key) == tiles_.end()); | 106   DCHECK(tiles_.find(key) == tiles_.end()); | 
| 95 | 107 | 
| (...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 598                                        &expansion_cache_); | 610                                        &expansion_cache_); | 
| 599 | 611 | 
| 600   DCHECK(eventually_rect.IsEmpty() || | 612   DCHECK(eventually_rect.IsEmpty() || | 
| 601          gfx::Rect(tiling_size()).Contains(eventually_rect)) | 613          gfx::Rect(tiling_size()).Contains(eventually_rect)) | 
| 602       << "tiling_size: " << tiling_size().ToString() | 614       << "tiling_size: " << tiling_size().ToString() | 
| 603       << " eventually_rect: " << eventually_rect.ToString(); | 615       << " eventually_rect: " << eventually_rect.ToString(); | 
| 604 | 616 | 
| 605   // Calculate the soon border rect. | 617   // Calculate the soon border rect. | 
| 606   float content_to_screen_scale = ideal_contents_scale / contents_scale_; | 618   float content_to_screen_scale = ideal_contents_scale / contents_scale_; | 
| 607   gfx::Rect soon_border_rect = visible_rect_in_content_space; | 619   gfx::Rect soon_border_rect = visible_rect_in_content_space; | 
| 608   float border = kSoonBorderDistanceInScreenPixels / content_to_screen_scale; | 620   float border = CalculateSoonBorderDistance(visible_rect_in_content_space, | 
|  | 621                                              content_to_screen_scale); | 
| 609   soon_border_rect.Inset(-border, -border, -border, -border); | 622   soon_border_rect.Inset(-border, -border, -border, -border); | 
| 610 | 623 | 
| 611   last_impl_frame_time_in_seconds_ = current_frame_time_in_seconds; | 624   last_impl_frame_time_in_seconds_ = current_frame_time_in_seconds; | 
| 612   last_viewport_in_layer_space_ = viewport_in_layer_space; | 625   last_viewport_in_layer_space_ = viewport_in_layer_space; | 
| 613   last_visible_rect_in_content_space_ = visible_rect_in_content_space; | 626   last_visible_rect_in_content_space_ = visible_rect_in_content_space; | 
| 614 | 627 | 
| 615   SetLiveTilesRect(eventually_rect); | 628   SetLiveTilesRect(eventually_rect); | 
| 616   UpdateTilePriorityRects( | 629   UpdateTilePriorityRects( | 
| 617       content_to_screen_scale, visible_rect_in_content_space, skewport, | 630       content_to_screen_scale, visible_rect_in_content_space, skewport, | 
| 618       soon_border_rect, eventually_rect, occlusion_in_layer_space); | 631       soon_border_rect, eventually_rect, occlusion_in_layer_space); | 
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 859       tree, | 872       tree, | 
| 860       TilePriority(resolution_, TilePriority::EVENTUALLY, distance_to_visible)); | 873       TilePriority(resolution_, TilePriority::EVENTUALLY, distance_to_visible)); | 
| 861 } | 874 } | 
| 862 | 875 | 
| 863 void PictureLayerTiling::GetAllTilesForTracing( | 876 void PictureLayerTiling::GetAllTilesForTracing( | 
| 864     std::set<const Tile*>* tiles) const { | 877     std::set<const Tile*>* tiles) const { | 
| 865   for (TileMap::const_iterator it = tiles_.begin(); it != tiles_.end(); ++it) | 878   for (TileMap::const_iterator it = tiles_.begin(); it != tiles_.end(); ++it) | 
| 866     tiles->insert(it->second.get()); | 879     tiles->insert(it->second.get()); | 
| 867 } | 880 } | 
| 868 | 881 | 
| 869 void PictureLayerTiling::AsValueInto(base::debug::TracedValue* state) const { | 882 void PictureLayerTiling::AsValueInto( | 
|  | 883     base::trace_event::TracedValue* state) const { | 
| 870   state->SetInteger("num_tiles", tiles_.size()); | 884   state->SetInteger("num_tiles", tiles_.size()); | 
| 871   state->SetDouble("content_scale", contents_scale_); | 885   state->SetDouble("content_scale", contents_scale_); | 
| 872   MathUtil::AddToTracedValue("tiling_size", tiling_size(), state); | 886   MathUtil::AddToTracedValue("tiling_size", tiling_size(), state); | 
| 873 } | 887 } | 
| 874 | 888 | 
| 875 size_t PictureLayerTiling::GPUMemoryUsageInBytes() const { | 889 size_t PictureLayerTiling::GPUMemoryUsageInBytes() const { | 
| 876   size_t amount = 0; | 890   size_t amount = 0; | 
| 877   for (TileMap::const_iterator it = tiles_.begin(); it != tiles_.end(); ++it) { | 891   for (TileMap::const_iterator it = tiles_.begin(); it != tiles_.end(); ++it) { | 
| 878     const Tile* tile = it->second.get(); | 892     const Tile* tile = it->second.get(); | 
| 879     amount += tile->GPUMemoryUsageInBytes(); | 893     amount += tile->GPUMemoryUsageInBytes(); | 
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1026       break; | 1040       break; | 
| 1027   } | 1041   } | 
| 1028 | 1042 | 
| 1029   gfx::Rect result(origin_x, origin_y, width, height); | 1043   gfx::Rect result(origin_x, origin_y, width, height); | 
| 1030   if (cache) | 1044   if (cache) | 
| 1031     cache->previous_result = result; | 1045     cache->previous_result = result; | 
| 1032   return result; | 1046   return result; | 
| 1033 } | 1047 } | 
| 1034 | 1048 | 
| 1035 }  // namespace cc | 1049 }  // namespace cc | 
| OLD | NEW | 
|---|