Chromium Code Reviews| 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 "cc/picture_pile_base.h" | 5 #include "cc/picture_pile_base.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "cc/layer_tree_host.h" | |
| 9 #include "cc/layer_tree_host_impl.h" | |
| 8 | 10 |
| 9 namespace { | 11 namespace { |
| 10 // Dimensions of the tiles in this picture pile as well as the dimensions of | 12 // Dimensions of the tiles in this picture pile as well as the dimensions of |
| 11 // the base picture in each tile. | 13 // the base picture in each tile. |
| 12 const int kBasePictureSize = 3000; | 14 const int kBasePictureSize = 3000; |
| 15 const int kDefaultTileGridInterval = 254; | |
|
enne (OOO)
2013/02/25 23:59:15
This should never get used, right? If possible, I'
| |
| 16 const int kDefaultTileGridBorderPixels = 1; | |
| 13 } | 17 } |
| 14 | 18 |
| 15 namespace cc { | 19 namespace cc { |
| 16 | 20 |
| 17 PicturePileBase::PicturePileBase() | 21 PicturePileBase::PicturePileBase() |
| 18 : min_contents_scale_(0) { | 22 : min_contents_scale_(0) { |
| 19 tiling_.SetMaxTextureSize(gfx::Size(kBasePictureSize, kBasePictureSize)); | 23 tiling_.SetMaxTextureSize(gfx::Size(kBasePictureSize, kBasePictureSize)); |
| 24 tile_grid_info_.fTileInterval.set(kDefaultTileGridInterval, | |
| 25 kDefaultTileGridInterval); | |
| 26 tile_grid_info_.fMargin.set(kDefaultTileGridBorderPixels, | |
| 27 kDefaultTileGridBorderPixels); | |
| 28 tile_grid_info_.fOffset.set(-kDefaultTileGridBorderPixels, | |
| 29 -kDefaultTileGridBorderPixels); | |
| 20 } | 30 } |
| 21 | 31 |
| 22 PicturePileBase::~PicturePileBase() { | 32 PicturePileBase::~PicturePileBase() { |
| 23 } | 33 } |
| 24 | 34 |
| 25 void PicturePileBase::Resize(gfx::Size new_size) { | 35 void PicturePileBase::Resize(gfx::Size new_size) { |
| 26 if (size() == new_size) | 36 if (size() == new_size) |
| 27 return; | 37 return; |
| 28 | 38 |
| 29 gfx::Size old_size = size(); | 39 gfx::Size old_size = size(); |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 60 // | 70 // |
| 61 // For example, if a 1/4 contents scale is used, then that would be 3 buffer | 71 // For example, if a 1/4 contents scale is used, then that would be 3 buffer |
| 62 // pixels, since that's the minimum number of pixels to add so that resulting | 72 // pixels, since that's the minimum number of pixels to add so that resulting |
| 63 // content can be snapped to a four pixel aligned grid. | 73 // content can be snapped to a four pixel aligned grid. |
| 64 int buffer_pixels = static_cast<int>(ceil(1 / min_contents_scale) - 1); | 74 int buffer_pixels = static_cast<int>(ceil(1 / min_contents_scale) - 1); |
| 65 buffer_pixels = std::max(0, buffer_pixels); | 75 buffer_pixels = std::max(0, buffer_pixels); |
| 66 SetBufferPixels(buffer_pixels); | 76 SetBufferPixels(buffer_pixels); |
| 67 min_contents_scale_ = min_contents_scale; | 77 min_contents_scale_ = min_contents_scale; |
| 68 } | 78 } |
| 69 | 79 |
| 80 void PicturePileBase::ApplyLayerTreeSettings(LayerTreeHost* host) { | |
| 81 ApplyLayerTreeSettings(host->settings(), host->deviceScaleFactor()); | |
| 82 } | |
| 83 | |
| 84 void PicturePileBase::ApplyLayerTreeSettings(LayerTreeHostImpl* host_impl) { | |
| 85 ApplyLayerTreeSettings(host_impl->settings(), | |
| 86 host_impl->deviceScaleFactor()); | |
| 87 } | |
| 88 | |
| 89 void PicturePileBase::ApplyLayerTreeSettings( | |
| 90 const LayerTreeSettings& settings, float deviceScaleFactor) { | |
| 91 SetMinContentsScale(settings.minimumContentsScale); | |
| 92 tile_grid_info_.fTileInterval.set( | |
| 93 settings.defaultTileSize.width() - 2 * kDefaultTileGridBorderPixels, | |
| 94 settings.defaultTileSize.height() - 2 * kDefaultTileGridBorderPixels); | |
| 95 DCHECK_GT(tile_grid_info_.fTileInterval.width(), 0); | |
| 96 DCHECK_GT(tile_grid_info_.fTileInterval.height(), 0); | |
| 97 tile_grid_info_.fMargin.set(kDefaultTileGridBorderPixels, | |
| 98 kDefaultTileGridBorderPixels); | |
| 99 // Offset the tile grid coordinate space to take into account the fact | |
| 100 // that the top-most and left-most tiles do not have top and left borders | |
| 101 // respectively. | |
| 102 tile_grid_info_.fOffset.set(-kDefaultTileGridBorderPixels, | |
| 103 -kDefaultTileGridBorderPixels); | |
| 104 } | |
| 105 | |
| 70 void PicturePileBase::SetBufferPixels(int new_buffer_pixels) { | 106 void PicturePileBase::SetBufferPixels(int new_buffer_pixels) { |
| 71 if (new_buffer_pixels == buffer_pixels()) | 107 if (new_buffer_pixels == buffer_pixels()) |
| 72 return; | 108 return; |
| 73 | 109 |
| 74 Clear(); | 110 Clear(); |
| 75 tiling_.SetBorderTexels(new_buffer_pixels); | 111 tiling_.SetBorderTexels(new_buffer_pixels); |
| 76 } | 112 } |
| 77 | 113 |
| 78 void PicturePileBase::Clear() { | 114 void PicturePileBase::Clear() { |
| 79 picture_list_map_.clear(); | 115 picture_list_map_.clear(); |
| 80 } | 116 } |
| 81 | 117 |
| 82 void PicturePileBase::PushPropertiesTo(PicturePileBase* other) { | 118 void PicturePileBase::PushPropertiesTo(PicturePileBase* other) { |
| 83 other->picture_list_map_ = picture_list_map_; | 119 other->picture_list_map_ = picture_list_map_; |
| 84 other->tiling_ = tiling_; | 120 other->tiling_ = tiling_; |
| 85 other->recorded_region_ = recorded_region_; | 121 other->recorded_region_ = recorded_region_; |
| 86 other->min_contents_scale_ = min_contents_scale_; | 122 other->min_contents_scale_ = min_contents_scale_; |
| 123 other->tile_grid_info_ = tile_grid_info_; | |
| 87 } | 124 } |
| 88 | 125 |
| 89 void PicturePileBase::UpdateRecordedRegion() { | 126 void PicturePileBase::UpdateRecordedRegion() { |
| 90 recorded_region_.Clear(); | 127 recorded_region_.Clear(); |
| 91 for (int x = 0; x < num_tiles_x(); ++x) { | 128 for (int x = 0; x < num_tiles_x(); ++x) { |
| 92 for (int y = 0; y < num_tiles_y(); ++y) { | 129 for (int y = 0; y < num_tiles_y(); ++y) { |
| 93 if (!HasRecordingAt(x, y)) | 130 if (!HasRecordingAt(x, y)) |
| 94 continue; | 131 continue; |
| 95 recorded_region_.Union(tile_bounds(x, y)); | 132 recorded_region_.Union(tile_bounds(x, y)); |
| 96 } | 133 } |
| 97 } | 134 } |
| 98 } | 135 } |
| 99 | 136 |
| 100 bool PicturePileBase::HasRecordingAt(int x, int y) { | 137 bool PicturePileBase::HasRecordingAt(int x, int y) { |
| 101 PictureListMap::iterator found = | 138 PictureListMap::iterator found = |
| 102 picture_list_map_.find(PictureListMapKey(x, y)); | 139 picture_list_map_.find(PictureListMapKey(x, y)); |
| 103 if (found == picture_list_map_.end()) | 140 if (found == picture_list_map_.end()) |
| 104 return false; | 141 return false; |
| 105 DCHECK(!found->second.empty()); | 142 DCHECK(!found->second.empty()); |
| 106 return true; | 143 return true; |
| 107 } | 144 } |
| 108 | 145 |
| 109 } // namespace cc | 146 } // namespace cc |
| OLD | NEW |