| 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_settings.h" |
| 8 | 9 |
| 9 namespace { | 10 namespace { |
| 10 // Dimensions of the tiles in this picture pile as well as the dimensions of | 11 // Dimensions of the tiles in this picture pile as well as the dimensions of |
| 11 // the base picture in each tile. | 12 // the base picture in each tile. |
| 12 const int kBasePictureSize = 3000; | 13 const int kBasePictureSize = 3000; |
| 14 const int kTileGridBorderPixels = 1; |
| 13 } | 15 } |
| 14 | 16 |
| 15 namespace cc { | 17 namespace cc { |
| 16 | 18 |
| 17 PicturePileBase::PicturePileBase() | 19 PicturePileBase::PicturePileBase() |
| 18 : min_contents_scale_(0) { | 20 : min_contents_scale_(0) { |
| 19 tiling_.SetMaxTextureSize(gfx::Size(kBasePictureSize, kBasePictureSize)); | 21 tiling_.SetMaxTextureSize(gfx::Size(kBasePictureSize, kBasePictureSize)); |
| 22 tile_grid_info_.fTileInterval.setEmpty(); |
| 23 tile_grid_info_.fMargin.setEmpty(); |
| 24 tile_grid_info_.fOffset.setZero(); |
| 20 } | 25 } |
| 21 | 26 |
| 22 PicturePileBase::~PicturePileBase() { | 27 PicturePileBase::~PicturePileBase() { |
| 23 } | 28 } |
| 24 | 29 |
| 25 void PicturePileBase::Resize(gfx::Size new_size) { | 30 void PicturePileBase::Resize(gfx::Size new_size) { |
| 26 if (size() == new_size) | 31 if (size() == new_size) |
| 27 return; | 32 return; |
| 28 | 33 |
| 29 gfx::Size old_size = size(); | 34 gfx::Size old_size = size(); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 60 // | 65 // |
| 61 // For example, if a 1/4 contents scale is used, then that would be 3 buffer | 66 // 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 | 67 // 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. | 68 // content can be snapped to a four pixel aligned grid. |
| 64 int buffer_pixels = static_cast<int>(ceil(1 / min_contents_scale) - 1); | 69 int buffer_pixels = static_cast<int>(ceil(1 / min_contents_scale) - 1); |
| 65 buffer_pixels = std::max(0, buffer_pixels); | 70 buffer_pixels = std::max(0, buffer_pixels); |
| 66 SetBufferPixels(buffer_pixels); | 71 SetBufferPixels(buffer_pixels); |
| 67 min_contents_scale_ = min_contents_scale; | 72 min_contents_scale_ = min_contents_scale; |
| 68 } | 73 } |
| 69 | 74 |
| 75 void PicturePileBase::ApplyLayerTreeSettings( |
| 76 const LayerTreeSettings& settings) { |
| 77 SetMinContentsScale(settings.minimumContentsScale); |
| 78 tile_grid_info_.fTileInterval.set( |
| 79 settings.defaultTileSize.width() - 2 * kTileGridBorderPixels, |
| 80 settings.defaultTileSize.height() - 2 * kTileGridBorderPixels); |
| 81 DCHECK_GT(tile_grid_info_.fTileInterval.width(), 0); |
| 82 DCHECK_GT(tile_grid_info_.fTileInterval.height(), 0); |
| 83 tile_grid_info_.fMargin.set(kTileGridBorderPixels, |
| 84 kTileGridBorderPixels); |
| 85 // Offset the tile grid coordinate space to take into account the fact |
| 86 // that the top-most and left-most tiles do not have top and left borders |
| 87 // respectively. |
| 88 tile_grid_info_.fOffset.set(-kTileGridBorderPixels, |
| 89 -kTileGridBorderPixels); |
| 90 } |
| 91 |
| 70 void PicturePileBase::SetBufferPixels(int new_buffer_pixels) { | 92 void PicturePileBase::SetBufferPixels(int new_buffer_pixels) { |
| 71 if (new_buffer_pixels == buffer_pixels()) | 93 if (new_buffer_pixels == buffer_pixels()) |
| 72 return; | 94 return; |
| 73 | 95 |
| 74 Clear(); | 96 Clear(); |
| 75 tiling_.SetBorderTexels(new_buffer_pixels); | 97 tiling_.SetBorderTexels(new_buffer_pixels); |
| 76 } | 98 } |
| 77 | 99 |
| 78 void PicturePileBase::Clear() { | 100 void PicturePileBase::Clear() { |
| 79 picture_list_map_.clear(); | 101 picture_list_map_.clear(); |
| 80 } | 102 } |
| 81 | 103 |
| 82 void PicturePileBase::PushPropertiesTo(PicturePileBase* other) { | 104 void PicturePileBase::PushPropertiesTo(PicturePileBase* other) { |
| 83 other->picture_list_map_ = picture_list_map_; | 105 other->picture_list_map_ = picture_list_map_; |
| 84 other->tiling_ = tiling_; | 106 other->tiling_ = tiling_; |
| 85 other->recorded_region_ = recorded_region_; | 107 other->recorded_region_ = recorded_region_; |
| 86 other->min_contents_scale_ = min_contents_scale_; | 108 other->min_contents_scale_ = min_contents_scale_; |
| 109 other->tile_grid_info_ = tile_grid_info_; |
| 87 } | 110 } |
| 88 | 111 |
| 89 void PicturePileBase::UpdateRecordedRegion() { | 112 void PicturePileBase::UpdateRecordedRegion() { |
| 90 recorded_region_.Clear(); | 113 recorded_region_.Clear(); |
| 91 for (int x = 0; x < num_tiles_x(); ++x) { | 114 for (int x = 0; x < num_tiles_x(); ++x) { |
| 92 for (int y = 0; y < num_tiles_y(); ++y) { | 115 for (int y = 0; y < num_tiles_y(); ++y) { |
| 93 if (!HasRecordingAt(x, y)) | 116 if (!HasRecordingAt(x, y)) |
| 94 continue; | 117 continue; |
| 95 recorded_region_.Union(tile_bounds(x, y)); | 118 recorded_region_.Union(tile_bounds(x, y)); |
| 96 } | 119 } |
| 97 } | 120 } |
| 98 } | 121 } |
| 99 | 122 |
| 100 bool PicturePileBase::HasRecordingAt(int x, int y) { | 123 bool PicturePileBase::HasRecordingAt(int x, int y) { |
| 101 PictureListMap::iterator found = | 124 PictureListMap::iterator found = |
| 102 picture_list_map_.find(PictureListMapKey(x, y)); | 125 picture_list_map_.find(PictureListMapKey(x, y)); |
| 103 if (found == picture_list_map_.end()) | 126 if (found == picture_list_map_.end()) |
| 104 return false; | 127 return false; |
| 105 DCHECK(!found->second.empty()); | 128 DCHECK(!found->second.empty()); |
| 106 return true; | 129 return true; |
| 107 } | 130 } |
| 108 | 131 |
| 109 } // namespace cc | 132 } // namespace cc |
| OLD | NEW |