OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2006 The Android Open Source Project | 3 * Copyright 2006 The Android Open Source Project |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 | 9 |
10 #include "SkNinePatch.h" | 10 #include "SkNinePatch.h" |
11 #include "SkCanvas.h" | 11 #include "SkCanvas.h" |
12 #include "SkShader.h" | 12 #include "SkShader.h" |
13 | 13 |
14 static const uint16_t g3x3Indices[] = { | 14 static const uint16_t g3x3Indices[] = { |
15 0, 5, 1, 0, 4, 5, | 15 0, 5, 1, 0, 4, 5, |
16 1, 6, 2, 1, 5, 6, | 16 1, 6, 2, 1, 5, 6, |
17 2, 7, 3, 2, 6, 7, | 17 2, 7, 3, 2, 6, 7, |
18 | 18 |
19 4, 9, 5, 4, 8, 9, | 19 4, 9, 5, 4, 8, 9, |
20 5, 10, 6, 5, 9, 10, | 20 5, 10, 6, 5, 9, 10, |
21 6, 11, 7, 6, 10, 11, | 21 6, 11, 7, 6, 10, 11, |
22 | 22 |
23 8, 13, 9, 8, 12, 13, | 23 8, 13, 9, 8, 12, 13, |
24 9, 14, 10, 9, 13, 14, | 24 9, 14, 10, 9, 13, 14, |
25 10, 15, 11, 10, 14, 15 | 25 10, 15, 11, 10, 14, 15 |
26 }; | 26 }; |
27 | 27 |
28 static int fillIndices(uint16_t indices[], int xCount, int yCount) { | 28 static size_t fillIndices(uint16_t indices[], int xCount, int yCount) { |
29 uint16_t* startIndices = indices; | 29 uint16_t* startIndices = indices; |
30 | 30 |
31 int n = 0; | 31 int n = 0; |
32 for (int y = 0; y < yCount; y++) { | 32 for (int y = 0; y < yCount; y++) { |
33 for (int x = 0; x < xCount; x++) { | 33 for (int x = 0; x < xCount; x++) { |
34 *indices++ = n; | 34 *indices++ = n; |
35 *indices++ = n + xCount + 2; | 35 *indices++ = n + xCount + 2; |
36 *indices++ = n + 1; | 36 *indices++ = n + 1; |
37 | 37 |
38 *indices++ = n; | 38 *indices++ = n; |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 | 196 |
197 mesh.fVerts = verts; | 197 mesh.fVerts = verts; |
198 mesh.fTexs = texs; | 198 mesh.fTexs = texs; |
199 mesh.fColors = NULL; | 199 mesh.fColors = NULL; |
200 mesh.fIndices = NULL; | 200 mesh.fIndices = NULL; |
201 | 201 |
202 // we use <= for YDivs, since the prebuild indices work for 3x2 and 3x1 too | 202 // we use <= for YDivs, since the prebuild indices work for 3x2 and 3x1 too |
203 if (numXDivs == 2 && numYDivs <= 2) { | 203 if (numXDivs == 2 && numYDivs <= 2) { |
204 mesh.fIndices = g3x3Indices; | 204 mesh.fIndices = g3x3Indices; |
205 } else { | 205 } else { |
206 SkDEBUGCODE(int n =) fillIndices(indices, numXDivs + 1, numYDivs + 1); | 206 SkDEBUGCODE(size_t n =) fillIndices(indices, numXDivs + 1, numYDivs + 1)
; |
207 SkASSERT(n == indexCount); | 207 SkASSERT(n == indexCount); |
208 mesh.fIndices = indices; | 208 mesh.fIndices = indices; |
209 } | 209 } |
210 | 210 |
211 SkScalar vy = bounds.fTop; | 211 SkScalar vy = bounds.fTop; |
212 fillRow(verts, texs, vy, 0, bounds, xDivs, numXDivs, | 212 fillRow(verts, texs, vy, 0, bounds, xDivs, numXDivs, |
213 stretchX, bitmap.width()); | 213 stretchX, bitmap.width()); |
214 verts += numXDivs + 2; | 214 verts += numXDivs + 2; |
215 texs += numXDivs + 2; | 215 texs += numXDivs + 2; |
216 for (int y = 0; y < numYDivs; y++) { | 216 for (int y = 0; y < numYDivs; y++) { |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
326 (margins.fTop + margins.fBottom); | 326 (margins.fTop + margins.fBottom); |
327 yDivs[1] = yDivs[0]; | 327 yDivs[1] = yDivs[0]; |
328 } | 328 } |
329 | 329 |
330 SkNinePatch::DrawMesh(canvas, bounds, bitmap, | 330 SkNinePatch::DrawMesh(canvas, bounds, bitmap, |
331 xDivs, 2, yDivs, 2, paint); | 331 xDivs, 2, yDivs, 2, paint); |
332 } else { | 332 } else { |
333 drawNineViaRects(canvas, bounds, bitmap, margins, paint); | 333 drawNineViaRects(canvas, bounds, bitmap, margins, paint); |
334 } | 334 } |
335 } | 335 } |
OLD | NEW |