OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2010, Google Inc. All rights reserved. | 2 * Copyright (c) 2010, Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 26 matching lines...) Expand all Loading... |
37 #include "FloatRect.h" | 37 #include "FloatRect.h" |
38 #include "IntRect.h" | 38 #include "IntRect.h" |
39 #include <algorithm> | 39 #include <algorithm> |
40 | 40 |
41 using namespace std; | 41 using namespace std; |
42 | 42 |
43 namespace WebCore { | 43 namespace WebCore { |
44 | 44 |
45 static int computeNumTiles(int maxTextureSize, int totalSize, int borderTexels) | 45 static int computeNumTiles(int maxTextureSize, int totalSize, int borderTexels) |
46 { | 46 { |
47 int totalSizeWithBorder = totalSize + 2 * borderTexels; | 47 if (maxTextureSize - 2 * borderTexels <= 0) |
| 48 return totalSize > 0 && maxTextureSize >= totalSize ? 1 : 0; |
48 | 49 |
49 if (maxTextureSize - 2 * borderTexels <= 0) | 50 int numTiles = max(1, 1 + (totalSize - 1 - 2 * borderTexels) / (maxTextureSi
ze - 2 * borderTexels)); |
50 return 0; | |
51 | |
52 int numTiles = max(1, 1 + (totalSizeWithBorder - 1 - 2 * borderTexels) / (ma
xTextureSize - 2 * borderTexels)); | |
53 return totalSize > 0 ? numTiles : 0; | 51 return totalSize > 0 ? numTiles : 0; |
54 } | 52 } |
55 | 53 |
56 TilingData::TilingData(int maxTextureSize, int totalSizeX, int totalSizeY, bool
hasBorderTexels) | 54 TilingData::TilingData(int maxTextureSize, int totalSizeX, int totalSizeY, bool
hasBorderTexels) |
57 : m_maxTextureSize(maxTextureSize) | 55 : m_maxTextureSize(maxTextureSize) |
58 , m_totalSizeX(totalSizeX) | 56 , m_totalSizeX(totalSizeX) |
59 , m_totalSizeY(totalSizeY) | 57 , m_totalSizeY(totalSizeY) |
60 , m_borderTexels(hasBorderTexels ? 1 : 0) | 58 , m_borderTexels(hasBorderTexels ? 1 : 0) |
61 { | 59 { |
62 recomputeNumTiles(); | 60 recomputeNumTiles(); |
(...skipping 11 matching lines...) Expand all Loading... |
74 m_maxTextureSize = maxTextureSize; | 72 m_maxTextureSize = maxTextureSize; |
75 recomputeNumTiles(); | 73 recomputeNumTiles(); |
76 } | 74 } |
77 | 75 |
78 int TilingData::tileXIndexFromSrcCoord(int srcPos) const | 76 int TilingData::tileXIndexFromSrcCoord(int srcPos) const |
79 { | 77 { |
80 if (numTilesX() <= 1) | 78 if (numTilesX() <= 1) |
81 return 0; | 79 return 0; |
82 | 80 |
83 ASSERT(m_maxTextureSize - 2 * m_borderTexels); | 81 ASSERT(m_maxTextureSize - 2 * m_borderTexels); |
84 int x = srcPos / (m_maxTextureSize - 2 * m_borderTexels); | 82 int x = (srcPos - m_borderTexels) / (m_maxTextureSize - 2 * m_borderTexels); |
85 return min(max(x, 0), numTilesX() - 1); | 83 return min(max(x, 0), numTilesX() - 1); |
86 } | 84 } |
87 | 85 |
88 int TilingData::tileYIndexFromSrcCoord(int srcPos) const | 86 int TilingData::tileYIndexFromSrcCoord(int srcPos) const |
89 { | 87 { |
90 if (numTilesY() <= 1) | 88 if (numTilesY() <= 1) |
91 return 0; | 89 return 0; |
92 | 90 |
93 ASSERT(m_maxTextureSize - 2 * m_borderTexels); | 91 ASSERT(m_maxTextureSize - 2 * m_borderTexels); |
94 int y = srcPos / (m_maxTextureSize - 2 * m_borderTexels); | 92 int y = (srcPos - m_borderTexels) / (m_maxTextureSize - 2 * m_borderTexels); |
95 return min(max(y, 0), numTilesY() - 1); | 93 return min(max(y, 0), numTilesY() - 1); |
96 } | 94 } |
97 | 95 |
98 IntRect TilingData::tileBounds(int tile) const | 96 IntRect TilingData::tileBounds(int tile) const |
99 { | 97 { |
100 assertTile(tile); | 98 assertTile(tile); |
101 int ix = tileXIndex(tile); | 99 int ix = tileXIndex(tile); |
102 int iy = tileYIndex(tile); | 100 int iy = tileYIndex(tile); |
103 int x = tilePositionX(ix); | 101 int x = tilePositionX(ix); |
104 int y = tilePositionY(iy); | 102 int y = tilePositionY(iy); |
(...skipping 22 matching lines...) Expand all Loading... |
127 y1--; | 125 y1--; |
128 if (tileYIndex(tile) < (numTilesY() - 1)) | 126 if (tileYIndex(tile) < (numTilesY() - 1)) |
129 y2++; | 127 y2++; |
130 | 128 |
131 bounds = IntRect(x1, y1, x2 - x1, y2 - y1); | 129 bounds = IntRect(x1, y1, x2 - x1, y2 - y1); |
132 } | 130 } |
133 | 131 |
134 return bounds; | 132 return bounds; |
135 } | 133 } |
136 | 134 |
137 IntRect TilingData::tileBoundsWithOuterBorder(int tile) const | |
138 { | |
139 IntRect bounds = tileBounds(tile); | |
140 | |
141 if (m_borderTexels) | |
142 bounds.inflate(1); | |
143 | |
144 return bounds; | |
145 } | |
146 | |
147 FloatRect TilingData::tileBoundsNormalized(int tile) const | 135 FloatRect TilingData::tileBoundsNormalized(int tile) const |
148 { | 136 { |
149 assertTile(tile); | 137 assertTile(tile); |
150 FloatRect bounds(tileBounds(tile)); | 138 FloatRect bounds(tileBounds(tile)); |
151 bounds.scale(1.0f / m_totalSizeX, 1.0f / m_totalSizeY); | 139 bounds.scale(1.0f / m_totalSizeX, 1.0f / m_totalSizeY); |
152 return bounds; | 140 return bounds; |
153 } | 141 } |
154 | 142 |
155 int TilingData::tilePositionX(int xIndex) const | 143 int TilingData::tilePositionX(int xIndex) const |
156 { | 144 { |
(...skipping 16 matching lines...) Expand all Loading... |
173 | 161 |
174 return pos; | 162 return pos; |
175 } | 163 } |
176 | 164 |
177 int TilingData::tileSizeX(int xIndex) const | 165 int TilingData::tileSizeX(int xIndex) const |
178 { | 166 { |
179 ASSERT(xIndex >= 0 && xIndex < numTilesX()); | 167 ASSERT(xIndex >= 0 && xIndex < numTilesX()); |
180 | 168 |
181 if (!xIndex && m_numTilesX == 1) | 169 if (!xIndex && m_numTilesX == 1) |
182 return m_totalSizeX; | 170 return m_totalSizeX; |
| 171 if (!xIndex && m_numTilesX > 1) |
| 172 return m_maxTextureSize - m_borderTexels; |
183 if (xIndex < numTilesX() - 1) | 173 if (xIndex < numTilesX() - 1) |
184 return m_maxTextureSize - 2 * m_borderTexels; | 174 return m_maxTextureSize - 2 * m_borderTexels; |
185 if (xIndex == numTilesX() - 1) | 175 if (xIndex == numTilesX() - 1) |
186 return m_totalSizeX - tilePositionX(xIndex); | 176 return m_totalSizeX - tilePositionX(xIndex); |
187 | 177 |
188 ASSERT_NOT_REACHED(); | 178 ASSERT_NOT_REACHED(); |
189 return 0; | 179 return 0; |
190 } | 180 } |
191 | 181 |
192 int TilingData::tileSizeY(int yIndex) const | 182 int TilingData::tileSizeY(int yIndex) const |
193 { | 183 { |
194 ASSERT(yIndex >= 0 && yIndex < numTilesY()); | 184 ASSERT(yIndex >= 0 && yIndex < numTilesY()); |
195 | 185 |
196 if (!yIndex && m_numTilesY == 1) | 186 if (!yIndex && m_numTilesY == 1) |
197 return m_totalSizeY; | 187 return m_totalSizeY; |
| 188 if (!yIndex && m_numTilesY > 1) |
| 189 return m_maxTextureSize - m_borderTexels; |
198 if (yIndex < numTilesY() - 1) | 190 if (yIndex < numTilesY() - 1) |
199 return m_maxTextureSize - 2 * m_borderTexels; | 191 return m_maxTextureSize - 2 * m_borderTexels; |
200 if (yIndex == numTilesY() - 1) | 192 if (yIndex == numTilesY() - 1) |
201 return m_totalSizeY - tilePositionY(yIndex); | 193 return m_totalSizeY - tilePositionY(yIndex); |
202 | 194 |
203 ASSERT_NOT_REACHED(); | 195 ASSERT_NOT_REACHED(); |
204 return 0; | 196 return 0; |
205 } | 197 } |
206 | 198 |
207 IntRect TilingData::overlappedTileIndices(const WebCore::IntRect &srcRect) const | 199 IntRect TilingData::overlappedTileIndices(const WebCore::IntRect &srcRect) const |
(...skipping 23 matching lines...) Expand all Loading... |
231 return; | 223 return; |
232 } | 224 } |
233 | 225 |
234 float srcRectIntersectedNormX = (srcRectIntersected.x() - srcRect.x()) / src
Rect.width(); | 226 float srcRectIntersectedNormX = (srcRectIntersected.x() - srcRect.x()) / src
Rect.width(); |
235 float srcRectIntersectedNormY = (srcRectIntersected.y() - srcRect.y()) / src
Rect.height(); | 227 float srcRectIntersectedNormY = (srcRectIntersected.y() - srcRect.y()) / src
Rect.height(); |
236 float srcRectIntersectedNormW = srcRectIntersected.width() / srcRect.width()
; | 228 float srcRectIntersectedNormW = srcRectIntersected.width() / srcRect.width()
; |
237 float srcRectIntersectedNormH = srcRectIntersected.height() / srcRect.height
(); | 229 float srcRectIntersectedNormH = srcRectIntersected.height() / srcRect.height
(); |
238 | 230 |
239 *newSrc = srcRectIntersected; | 231 *newSrc = srcRectIntersected; |
240 newSrc->move( | 232 newSrc->move( |
241 -tileBounds.x() + m_borderTexels, | 233 -tileBounds.x() + ((tileXIndex(tile) > 0) ? m_borderTexels : 0), |
242 -tileBounds.y() + m_borderTexels); | 234 -tileBounds.y() + ((tileYIndex(tile) > 0) ? m_borderTexels : 0)); |
243 | 235 |
244 *newDst = FloatRect( | 236 *newDst = FloatRect( |
245 srcRectIntersectedNormX * dstRect.width() + dstRect.x(), | 237 srcRectIntersectedNormX * dstRect.width() + dstRect.x(), |
246 srcRectIntersectedNormY * dstRect.height() + dstRect.y(), | 238 srcRectIntersectedNormY * dstRect.height() + dstRect.y(), |
247 srcRectIntersectedNormW * dstRect.width(), | 239 srcRectIntersectedNormW * dstRect.width(), |
248 srcRectIntersectedNormH * dstRect.height()); | 240 srcRectIntersectedNormH * dstRect.height()); |
249 } | 241 } |
250 | 242 |
251 IntPoint TilingData::textureOffset() const | 243 IntPoint TilingData::textureOffset(int xIndex, int yIndex) const |
252 { | 244 { |
253 return IntPoint(m_borderTexels, m_borderTexels); | 245 int left = (!xIndex || m_numTilesX == 1) ? 0 : m_borderTexels; |
| 246 int top = (!yIndex || m_numTilesY == 1) ? 0 : m_borderTexels; |
| 247 |
| 248 return IntPoint(left, top); |
254 } | 249 } |
255 | 250 |
256 void TilingData::recomputeNumTiles() | 251 void TilingData::recomputeNumTiles() |
257 { | 252 { |
258 m_numTilesX = computeNumTiles(m_maxTextureSize, m_totalSizeX, m_borderTexels
); | 253 m_numTilesX = computeNumTiles(m_maxTextureSize, m_totalSizeX, m_borderTexels
); |
259 m_numTilesY = computeNumTiles(m_maxTextureSize, m_totalSizeY, m_borderTexels
); | 254 m_numTilesY = computeNumTiles(m_maxTextureSize, m_totalSizeY, m_borderTexels
); |
260 } | 255 } |
261 | 256 |
262 } | 257 } |
263 | 258 |
264 #endif | 259 #endif |
OLD | NEW |