| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
| 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 #include "SkMeshUtils.h" | 8 #include "SkMeshUtils.h" |
| 9 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
| 10 #include "SkPaint.h" | 10 #include "SkPaint.h" |
| 11 | 11 |
| 12 SkMeshIndices::SkMeshIndices() { | 12 SkMeshIndices::SkMeshIndices() { |
| 13 sk_bzero(this, sizeof(*this)); | 13 sk_bzero(this, sizeof(*this)); |
| 14 } | 14 } |
| 15 | 15 |
| 16 SkMeshIndices::~SkMeshIndices() { | 16 SkMeshIndices::~SkMeshIndices() { |
| 17 sk_free(fStorage); | 17 sk_free(fStorage); |
| 18 } | 18 } |
| 19 | 19 |
| 20 bool SkMeshIndices::init(SkPoint tex[], uint16_t indices[], | 20 bool SkMeshIndices::init(SkPoint tex[], uint16_t indices[], |
| 21 int texW, int texH, int rows, int cols) { | 21 int texW, int texH, int rows, int cols) { |
| 22 if (rows < 2 || cols < 2) { | 22 if (rows < 2 || cols < 2) { |
| 23 sk_free(fStorage); | 23 sk_free(fStorage); |
| 24 fStorage = NULL; | 24 fStorage = nullptr; |
| 25 fTex = NULL; | 25 fTex = nullptr; |
| 26 fIndices = NULL; | 26 fIndices = nullptr; |
| 27 fTexCount = fIndexCount = 0; | 27 fTexCount = fIndexCount = 0; |
| 28 return false; | 28 return false; |
| 29 } | 29 } |
| 30 | 30 |
| 31 sk_free(fStorage); | 31 sk_free(fStorage); |
| 32 fStorage = NULL; | 32 fStorage = nullptr; |
| 33 | 33 |
| 34 fTexCount = rows * cols; | 34 fTexCount = rows * cols; |
| 35 rows -= 1; | 35 rows -= 1; |
| 36 cols -= 1; | 36 cols -= 1; |
| 37 fIndexCount = rows * cols * 6; | 37 fIndexCount = rows * cols * 6; |
| 38 | 38 |
| 39 if (tex) { | 39 if (tex) { |
| 40 fTex = tex; | 40 fTex = tex; |
| 41 fIndices = indices; | 41 fIndices = indices; |
| 42 } else { | 42 } else { |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 int rows, int cols, const SkPoint verts[], | 89 int rows, int cols, const SkPoint verts[], |
| 90 const SkColor colors[], const SkPaint& paint) { | 90 const SkColor colors[], const SkPaint& paint) { |
| 91 SkMeshIndices idx; | 91 SkMeshIndices idx; |
| 92 | 92 |
| 93 if (idx.init(bitmap.width(), bitmap.height(), rows, cols)) { | 93 if (idx.init(bitmap.width(), bitmap.height(), rows, cols)) { |
| 94 SkPaint p(paint); | 94 SkPaint p(paint); |
| 95 p.setShader(SkShader::CreateBitmapShader(bitmap, | 95 p.setShader(SkShader::CreateBitmapShader(bitmap, |
| 96 SkShader::kClamp_TileMode, | 96 SkShader::kClamp_TileMode, |
| 97 SkShader::kClamp_TileMode))->unref(); | 97 SkShader::kClamp_TileMode))->unref(); |
| 98 canvas->drawVertices(SkCanvas::kTriangles_VertexMode, | 98 canvas->drawVertices(SkCanvas::kTriangles_VertexMode, |
| 99 rows * cols, verts, idx.tex(), colors, NULL, | 99 rows * cols, verts, idx.tex(), colors, nullptr, |
| 100 idx.indices(), idx.indexCount(), p); | 100 idx.indices(), idx.indexCount(), p); |
| 101 } | 101 } |
| 102 } | 102 } |
| OLD | NEW |