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

Side by Side Diff: ui/cc/TilingData.cpp

Issue 10701016: Initial import attempt, just to play with. Many things disabled/removed (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 5 months 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 | Annotate | Revision Log
« no previous file with comments | « ui/cc/TilingData.h ('k') | ui/cc/TrackingTextureAllocator.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright (c) 2010, Google Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 *
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
13 * distribution.
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31 #include "config.h"
32
33 #if USE(ACCELERATED_COMPOSITING) || ENABLE(ACCELERATED_2D_CANVAS)
34
35 #include "TilingData.h"
36
37 #include "FloatRect.h"
38 #include "IntRect.h"
39 #include <algorithm>
40
41 using namespace std;
42
43 namespace WebCore {
44
45 static int computeNumTiles(int maxTextureSize, int totalSize, int borderTexels)
46 {
47 if (maxTextureSize - 2 * borderTexels <= 0)
48 return totalSize > 0 && maxTextureSize >= totalSize ? 1 : 0;
49
50 int numTiles = max(1, 1 + (totalSize - 1 - 2 * borderTexels) / (maxTextureSi ze - 2 * borderTexels));
51 return totalSize > 0 ? numTiles : 0;
52 }
53
54 TilingData::TilingData(const IntSize& maxTextureSize, const IntSize& totalSize, bool hasBorderTexels)
55 : m_maxTextureSize(maxTextureSize)
56 , m_totalSize(totalSize)
57 , m_borderTexels(hasBorderTexels ? 1 : 0)
58 {
59 recomputeNumTiles();
60 }
61
62 void TilingData::setTotalSize(const IntSize& totalSize)
63 {
64 m_totalSize = totalSize;
65 recomputeNumTiles();
66 }
67
68 void TilingData::setMaxTextureSize(const IntSize& maxTextureSize)
69 {
70 m_maxTextureSize = maxTextureSize;
71 recomputeNumTiles();
72 }
73
74 void TilingData::setHasBorderTexels(bool hasBorderTexels)
75 {
76 m_borderTexels = hasBorderTexels ? 1 : 0;
77 recomputeNumTiles();
78 }
79
80 int TilingData::tileXIndexFromSrcCoord(int srcPos) const
81 {
82 if (numTilesX() <= 1)
83 return 0;
84
85 ASSERT(m_maxTextureSize.width() - 2 * m_borderTexels);
86 int x = (srcPos - m_borderTexels) / (m_maxTextureSize.width() - 2 * m_border Texels);
87 return min(max(x, 0), numTilesX() - 1);
88 }
89
90 int TilingData::tileYIndexFromSrcCoord(int srcPos) const
91 {
92 if (numTilesY() <= 1)
93 return 0;
94
95 ASSERT(m_maxTextureSize.height() - 2 * m_borderTexels);
96 int y = (srcPos - m_borderTexels) / (m_maxTextureSize.height() - 2 * m_borde rTexels);
97 return min(max(y, 0), numTilesY() - 1);
98 }
99
100 IntRect TilingData::tileBounds(int i, int j) const
101 {
102 assertTile(i, j);
103 int x = tilePositionX(i);
104 int y = tilePositionY(j);
105 int width = tileSizeX(i);
106 int height = tileSizeY(j);
107 ASSERT(x >= 0 && y >= 0 && width >= 0 && height >= 0);
108 ASSERT(x <= m_totalSize.width() && y <= m_totalSize.height());
109 return IntRect(x, y, width, height);
110 }
111
112 IntRect TilingData::tileBoundsWithBorder(int i, int j) const
113 {
114 IntRect bounds = tileBounds(i, j);
115
116 if (m_borderTexels) {
117 int x1 = bounds.x();
118 int x2 = bounds.maxX();
119 int y1 = bounds.y();
120 int y2 = bounds.maxY();
121
122 if (i > 0)
123 x1--;
124 if (i < (numTilesX() - 1))
125 x2++;
126 if (j > 0)
127 y1--;
128 if (j < (numTilesY() - 1))
129 y2++;
130
131 bounds = IntRect(x1, y1, x2 - x1, y2 - y1);
132 }
133
134 return bounds;
135 }
136
137 int TilingData::tilePositionX(int xIndex) const
138 {
139 ASSERT(xIndex >= 0 && xIndex < numTilesX());
140
141 int pos = 0;
142 for (int i = 0; i < xIndex; i++)
143 pos += tileSizeX(i);
144
145 return pos;
146 }
147
148 int TilingData::tilePositionY(int yIndex) const
149 {
150 ASSERT(yIndex >= 0 && yIndex < numTilesY());
151
152 int pos = 0;
153 for (int i = 0; i < yIndex; i++)
154 pos += tileSizeY(i);
155
156 return pos;
157 }
158
159 int TilingData::tileSizeX(int xIndex) const
160 {
161 ASSERT(xIndex >= 0 && xIndex < numTilesX());
162
163 if (!xIndex && m_numTilesX == 1)
164 return m_totalSize.width();
165 if (!xIndex && m_numTilesX > 1)
166 return m_maxTextureSize.width() - m_borderTexels;
167 if (xIndex < numTilesX() - 1)
168 return m_maxTextureSize.width() - 2 * m_borderTexels;
169 if (xIndex == numTilesX() - 1)
170 return m_totalSize.width() - tilePositionX(xIndex);
171
172 ASSERT_NOT_REACHED();
173 return 0;
174 }
175
176 int TilingData::tileSizeY(int yIndex) const
177 {
178 ASSERT(yIndex >= 0 && yIndex < numTilesY());
179
180 if (!yIndex && m_numTilesY == 1)
181 return m_totalSize.height();
182 if (!yIndex && m_numTilesY > 1)
183 return m_maxTextureSize.height() - m_borderTexels;
184 if (yIndex < numTilesY() - 1)
185 return m_maxTextureSize.height() - 2 * m_borderTexels;
186 if (yIndex == numTilesY() - 1)
187 return m_totalSize.height() - tilePositionY(yIndex);
188
189 ASSERT_NOT_REACHED();
190 return 0;
191 }
192
193 IntPoint TilingData::textureOffset(int xIndex, int yIndex) const
194 {
195 int left = (!xIndex || m_numTilesX == 1) ? 0 : m_borderTexels;
196 int top = (!yIndex || m_numTilesY == 1) ? 0 : m_borderTexels;
197
198 return IntPoint(left, top);
199 }
200
201 void TilingData::recomputeNumTiles()
202 {
203 m_numTilesX = computeNumTiles(m_maxTextureSize.width(), m_totalSize.width(), m_borderTexels);
204 m_numTilesY = computeNumTiles(m_maxTextureSize.height(), m_totalSize.height( ), m_borderTexels);
205 }
206
207 }
208
209 #endif
OLDNEW
« no previous file with comments | « ui/cc/TilingData.h ('k') | ui/cc/TrackingTextureAllocator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698