| 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" |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 const int indexCount = (numXDivs + 1) * (numYDivs + 1) * 2 * 3; | 189 const int indexCount = (numXDivs + 1) * (numYDivs + 1) * 2 * 3; |
| 190 // allocate 2 times, one for verts, one for texs, plus indices | 190 // allocate 2 times, one for verts, one for texs, plus indices |
| 191 SkAutoMalloc storage(vCount * sizeof(SkPoint) * 2 + | 191 SkAutoMalloc storage(vCount * sizeof(SkPoint) * 2 + |
| 192 indexCount * sizeof(uint16_t)); | 192 indexCount * sizeof(uint16_t)); |
| 193 SkPoint* verts = (SkPoint*)storage.get(); | 193 SkPoint* verts = (SkPoint*)storage.get(); |
| 194 SkPoint* texs = verts + vCount; | 194 SkPoint* texs = verts + vCount; |
| 195 uint16_t* indices = (uint16_t*)(texs + vCount); | 195 uint16_t* indices = (uint16_t*)(texs + vCount); |
| 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 = nullptr; |
| 200 mesh.fIndices = NULL; | 200 mesh.fIndices = nullptr; |
| 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(int 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 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 238 | 238 |
| 239 SkShader* shader = SkShader::CreateBitmapShader(bitmap, | 239 SkShader* shader = SkShader::CreateBitmapShader(bitmap, |
| 240 SkShader::kClamp_TileMode, | 240 SkShader::kClamp_TileMode, |
| 241 SkShader::kClamp_TileMode); | 241 SkShader::kClamp_TileMode); |
| 242 SkPaint p; | 242 SkPaint p; |
| 243 if (paint) { | 243 if (paint) { |
| 244 p = *paint; | 244 p = *paint; |
| 245 } | 245 } |
| 246 p.setShader(shader)->unref(); | 246 p.setShader(shader)->unref(); |
| 247 canvas->drawVertices(SkCanvas::kTriangles_VertexMode, vCount, | 247 canvas->drawVertices(SkCanvas::kTriangles_VertexMode, vCount, |
| 248 mesh.fVerts, mesh.fTexs, mesh.fColors, NULL, | 248 mesh.fVerts, mesh.fTexs, mesh.fColors, nullptr, |
| 249 mesh.fIndices, indexCount, p); | 249 mesh.fIndices, indexCount, p); |
| 250 } | 250 } |
| 251 | 251 |
| 252 /////////////////////////////////////////////////////////////////////////////// | 252 /////////////////////////////////////////////////////////////////////////////// |
| 253 | 253 |
| 254 static void drawNineViaRects(SkCanvas* canvas, const SkRect& dst, | 254 static void drawNineViaRects(SkCanvas* canvas, const SkRect& dst, |
| 255 const SkBitmap& bitmap, const SkIRect& margins, | 255 const SkBitmap& bitmap, const SkIRect& margins, |
| 256 const SkPaint* paint) { | 256 const SkPaint* paint) { |
| 257 const int32_t srcX[4] = { | 257 const int32_t srcX[4] = { |
| 258 0, margins.fLeft, bitmap.width() - margins.fRight, bitmap.width() | 258 0, margins.fLeft, bitmap.width() - margins.fRight, bitmap.width() |
| (...skipping 67 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 |