diff options
author | 2017-03-20 14:22:58 +0000 | |
---|---|---|
committer | 2017-03-20 14:23:11 +0000 | |
commit | 006c8da9c65e234f102f671e5abd41f697864c89 (patch) | |
tree | 59b46b5d8618952ab3f07b62f4f6b5a96e0cf3ce /src | |
parent | 1c1c740d2775bb19e3791e528586a73dec638ecb (diff) |
Revert "remove unused SkMeshUtils and SkBoundaryPatch"
This reverts commit 5e21e0991968271ee37f446de7e08620ad1b50bb.
Reason for revert: Breaks Pdfium build see:
https://chromium-swarm.appspot.com/task?id=3504e60d4bc10810&refresh=10
Original change's description:
> remove unused SkMeshUtils and SkBoundaryPatch
>
> BUG=skia:6366
>
> Change-Id: Ibacd397e0a246dbeefde074c98712ada3848a7b6
> Reviewed-on: https://skia-review.googlesource.com/9852
> Reviewed-by: Mike Reed <reed@google.com>
> Commit-Queue: Mike Reed <reed@google.com>
>
TBR=djsollen@google.com,reed@google.com,reviews@skia.org
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=skia:6366
Change-Id: I2403bae0a17bce8eeec743c6f433bb51b214e669
Reviewed-on: https://skia-review.googlesource.com/9891
Reviewed-by: Stephan Altmueller <stephana@google.com>
Commit-Queue: Stephan Altmueller <stephana@google.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/utils/SkBoundaryPatch.cpp | 78 | ||||
-rw-r--r-- | src/utils/SkMeshUtils.cpp | 101 |
2 files changed, 179 insertions, 0 deletions
diff --git a/src/utils/SkBoundaryPatch.cpp b/src/utils/SkBoundaryPatch.cpp new file mode 100644 index 0000000000..0cfb09c2c7 --- /dev/null +++ b/src/utils/SkBoundaryPatch.cpp @@ -0,0 +1,78 @@ +/* + * Copyright 2011 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ +#include "SkBoundaryPatch.h" + +SkBoundaryPatch::SkBoundaryPatch() : fBoundary(nullptr) {} + +SkBoundaryPatch::~SkBoundaryPatch() { + SkSafeUnref(fBoundary); +} + +SkBoundary* SkBoundaryPatch::setBoundary(SkBoundary* b) { + SkRefCnt_SafeAssign(fBoundary, b); + return b; +} + +static SkPoint SkMakePoint(SkScalar x, SkScalar y) { + SkPoint pt; + pt.set(x, y); + return pt; +} + +static SkPoint SkPointInterp(const SkPoint& a, const SkPoint& b, SkScalar t) { + return SkMakePoint(SkScalarInterp(a.fX, b.fX, t), + SkScalarInterp(a.fY, b.fY, t)); +} + +SkPoint SkBoundaryPatch::eval(SkScalar unitU, SkScalar unitV) { + SkBoundary* b = fBoundary; + SkPoint u = SkPointInterp(b->eval(SkBoundary::kLeft, SK_Scalar1 - unitV), + b->eval(SkBoundary::kRight, unitV), + unitU); + SkPoint v = SkPointInterp(b->eval(SkBoundary::kTop, unitU), + b->eval(SkBoundary::kBottom, SK_Scalar1 - unitU), + unitV); + return SkMakePoint(SkScalarAve(u.fX, v.fX), + SkScalarAve(u.fY, v.fY)); +} + +bool SkBoundaryPatch::evalPatch(SkPoint verts[], int rows, int cols) { + if (rows < 2 || cols < 2) { + return false; + } + + const SkScalar invR = SkScalarInvert(SkIntToScalar(rows - 1)); + const SkScalar invC = SkScalarInvert(SkIntToScalar(cols - 1)); + + for (int y = 0; y < cols; y++) { + SkScalar yy = y * invC; + for (int x = 0; x < rows; x++) { + *verts++ = this->eval(x * invR, yy); + } + } + return true; +} + +//////////////////////////////////////////////////////////////////////// + +#include "SkGeometry.h" + +SkPoint SkLineBoundary::eval(Edge e, SkScalar t) { + SkASSERT((unsigned)e < 4); + return SkPointInterp(fPts[e], fPts[(e + 1) & 3], t); +} + +SkPoint SkCubicBoundary::eval(Edge e, SkScalar t) { + SkASSERT((unsigned)e < 4); + + // ensure our 4th cubic wraps to the start of the first + fPts[12] = fPts[0]; + + SkPoint loc; + SkEvalCubicAt(&fPts[e * 3], t, &loc, nullptr, nullptr); + return loc; +} diff --git a/src/utils/SkMeshUtils.cpp b/src/utils/SkMeshUtils.cpp new file mode 100644 index 0000000000..4c9c0d04c7 --- /dev/null +++ b/src/utils/SkMeshUtils.cpp @@ -0,0 +1,101 @@ +/* + * Copyright 2011 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ +#include "SkMeshUtils.h" +#include "SkCanvas.h" +#include "SkPaint.h" + +SkMeshIndices::SkMeshIndices() { + sk_bzero(this, sizeof(*this)); +} + +SkMeshIndices::~SkMeshIndices() { + sk_free(fStorage); +} + +bool SkMeshIndices::init(SkPoint tex[], uint16_t indices[], + int texW, int texH, int rows, int cols) { + if (rows < 2 || cols < 2) { + sk_free(fStorage); + fStorage = nullptr; + fTex = nullptr; + fIndices = nullptr; + fTexCount = fIndexCount = 0; + return false; + } + + sk_free(fStorage); + fStorage = nullptr; + + fTexCount = rows * cols; + rows -= 1; + cols -= 1; + fIndexCount = rows * cols * 6; + + if (tex) { + fTex = tex; + fIndices = indices; + } else { + fStorage = sk_malloc_throw(fTexCount * sizeof(SkPoint) + + fIndexCount * sizeof(uint16_t)); + fTex = (SkPoint*)fStorage; + fIndices = (uint16_t*)(fTex + fTexCount); + } + + // compute the indices + { + uint16_t* idx = fIndices; + int index = 0; + for (int y = 0; y < cols; y++) { + for (int x = 0; x < rows; x++) { + *idx++ = index; + *idx++ = index + rows + 1; + *idx++ = index + 1; + + *idx++ = index + 1; + *idx++ = index + rows + 1; + *idx++ = index + rows + 2; + + index += 1; + } + index += 1; + } + } + + // compute texture coordinates + { + SkPoint* tex = fTex; + const SkScalar dx = SkIntToScalar(texW) / rows; + const SkScalar dy = SkIntToScalar(texH) / cols; + for (int y = 0; y <= cols; y++) { + for (int x = 0; x <= rows; x++) { + tex->set(x*dx, y*dy); + tex += 1; + } + } + } + return true; +} + +/////////////////////////////////////////////////////////////////////////////// + +#include "SkShader.h" + +void SkMeshUtils::Draw(SkCanvas* canvas, const SkBitmap& bitmap, + int rows, int cols, const SkPoint verts[], + const SkColor colors[], const SkPaint& paint) { + SkMeshIndices idx; + + if (idx.init(bitmap.width(), bitmap.height(), rows, cols)) { + SkPaint p(paint); + p.setShader(SkShader::MakeBitmapShader(bitmap, + SkShader::kClamp_TileMode, + SkShader::kClamp_TileMode)); + canvas->drawVertices(SkCanvas::kTriangles_VertexMode, + rows * cols, verts, idx.tex(), colors, SkBlendMode::kModulate, + idx.indices(), idx.indexCount(), p); + } +} |