Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(98)

Side by Side Diff: cc/base/tiling_data.cc

Issue 2445363002: cc: Add functions for getting absolute tile indices.
Patch Set: Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « cc/base/tiling_data.h ('k') | cc/base/tiling_data_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2010 The Chromium Authors. All rights reserved. 1 // Copyright 2010 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/base/tiling_data.h" 5 #include "cc/base/tiling_data.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "ui/gfx/geometry/rect.h" 9 #include "ui/gfx/geometry/rect.h"
10 #include "ui/gfx/geometry/vector2d.h" 10 #include "ui/gfx/geometry/vector2d.h"
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 int TilingData::TileYIndexFromSrcCoord(int src_position) const { 84 int TilingData::TileYIndexFromSrcCoord(int src_position) const {
85 if (num_tiles_y_ <= 1) 85 if (num_tiles_y_ <= 1)
86 return 0; 86 return 0;
87 87
88 DCHECK_GT(max_texture_size_.height() - 2 * border_texels_, 0); 88 DCHECK_GT(max_texture_size_.height() - 2 * border_texels_, 0);
89 int y = (src_position - border_texels_) / 89 int y = (src_position - border_texels_) /
90 (max_texture_size_.height() - 2 * border_texels_); 90 (max_texture_size_.height() - 2 * border_texels_);
91 return std::min(std::max(y, 0), num_tiles_y_ - 1); 91 return std::min(std::max(y, 0), num_tiles_y_ - 1);
92 } 92 }
93 93
94 int TilingData::TileAbsoluteXIndexFromSrcCoord(int src_position) const {
95 int inner_tile_width = max_texture_size_.width() - 2 * border_texels_;
96 if (inner_tile_width <= 0)
97 return 0;
98
99 int max_width = inner_tile_width * num_tiles_x_ + 2 * border_texels_;
100 if (src_position >= 0 && src_position < max_width)
101 return TileXIndexFromSrcCoord(src_position);
102
103 if (src_position >= max_width)
104 return num_tiles_x_ + (src_position - max_width) / inner_tile_width;
105
106 return (src_position + 1) / inner_tile_width - 1;
107 }
108
109 int TilingData::TileAbsoluteYIndexFromSrcCoord(int src_position) const {
110 int inner_tile_height = max_texture_size_.height() - 2 * border_texels_;
111 if (inner_tile_height <= 0)
112 return 0;
113
114 int max_height = inner_tile_height * num_tiles_y_ + 2 * border_texels_;
115 if (src_position >= 0 && src_position < max_height)
116 return TileYIndexFromSrcCoord(src_position);
117
118 if (src_position >= max_height)
119 return num_tiles_y_ + (src_position - max_height) / inner_tile_height;
120
121 return (src_position + 1) / inner_tile_height - 1;
122 }
123
94 int TilingData::FirstBorderTileXIndexFromSrcCoord(int src_position) const { 124 int TilingData::FirstBorderTileXIndexFromSrcCoord(int src_position) const {
95 if (num_tiles_x_ <= 1) 125 if (num_tiles_x_ <= 1)
96 return 0; 126 return 0;
97 127
98 DCHECK_GT(max_texture_size_.width() - 2 * border_texels_, 0); 128 DCHECK_GT(max_texture_size_.width() - 2 * border_texels_, 0);
99 int inner_tile_size = max_texture_size_.width() - 2 * border_texels_; 129 int inner_tile_size = max_texture_size_.width() - 2 * border_texels_;
100 int x = (src_position - 2 * border_texels_) / inner_tile_size; 130 int x = (src_position - 2 * border_texels_) / inner_tile_size;
101 return std::min(std::max(x, 0), num_tiles_x_ - 1); 131 return std::min(std::max(x, 0), num_tiles_x_ - 1);
102 } 132 }
103 133
(...skipping 501 matching lines...) Expand 10 before | Expand all | Expand 10 after
605 return *this; 635 return *this;
606 } 636 }
607 637
608 index_x_ = reverse_spiral_iterator_.index_x(); 638 index_x_ = reverse_spiral_iterator_.index_x();
609 index_y_ = reverse_spiral_iterator_.index_y(); 639 index_y_ = reverse_spiral_iterator_.index_y();
610 640
611 return *this; 641 return *this;
612 } 642 }
613 643
614 } // namespace cc 644 } // namespace cc
OLDNEW
« no previous file with comments | « cc/base/tiling_data.h ('k') | cc/base/tiling_data_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698