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