Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | |
michael@0 | 2 | /* |
michael@0 | 3 | * Copyright 2011 Google Inc. |
michael@0 | 4 | * |
michael@0 | 5 | * Use of this source code is governed by a BSD-style license that can be |
michael@0 | 6 | * found in the LICENSE file. |
michael@0 | 7 | */ |
michael@0 | 8 | #include "SkBoundaryPatch.h" |
michael@0 | 9 | |
michael@0 | 10 | SkBoundaryPatch::SkBoundaryPatch() : fBoundary(NULL) {} |
michael@0 | 11 | |
michael@0 | 12 | SkBoundaryPatch::~SkBoundaryPatch() { |
michael@0 | 13 | SkSafeUnref(fBoundary); |
michael@0 | 14 | } |
michael@0 | 15 | |
michael@0 | 16 | SkBoundary* SkBoundaryPatch::setBoundary(SkBoundary* b) { |
michael@0 | 17 | SkRefCnt_SafeAssign(fBoundary, b); |
michael@0 | 18 | return b; |
michael@0 | 19 | } |
michael@0 | 20 | |
michael@0 | 21 | static SkPoint SkMakePoint(SkScalar x, SkScalar y) { |
michael@0 | 22 | SkPoint pt; |
michael@0 | 23 | pt.set(x, y); |
michael@0 | 24 | return pt; |
michael@0 | 25 | } |
michael@0 | 26 | |
michael@0 | 27 | static SkPoint SkPointInterp(const SkPoint& a, const SkPoint& b, SkScalar t) { |
michael@0 | 28 | return SkMakePoint(SkScalarInterp(a.fX, b.fX, t), |
michael@0 | 29 | SkScalarInterp(a.fY, b.fY, t)); |
michael@0 | 30 | } |
michael@0 | 31 | |
michael@0 | 32 | SkPoint SkBoundaryPatch::eval(SkScalar unitU, SkScalar unitV) { |
michael@0 | 33 | SkBoundary* b = fBoundary; |
michael@0 | 34 | SkPoint u = SkPointInterp(b->eval(SkBoundary::kLeft, SK_Scalar1 - unitV), |
michael@0 | 35 | b->eval(SkBoundary::kRight, unitV), |
michael@0 | 36 | unitU); |
michael@0 | 37 | SkPoint v = SkPointInterp(b->eval(SkBoundary::kTop, unitU), |
michael@0 | 38 | b->eval(SkBoundary::kBottom, SK_Scalar1 - unitU), |
michael@0 | 39 | unitV); |
michael@0 | 40 | return SkMakePoint(SkScalarAve(u.fX, v.fX), |
michael@0 | 41 | SkScalarAve(u.fY, v.fY)); |
michael@0 | 42 | } |
michael@0 | 43 | |
michael@0 | 44 | bool SkBoundaryPatch::evalPatch(SkPoint verts[], int rows, int cols) { |
michael@0 | 45 | if (rows < 2 || cols < 2) { |
michael@0 | 46 | return false; |
michael@0 | 47 | } |
michael@0 | 48 | |
michael@0 | 49 | const SkScalar invR = SkScalarInvert(SkIntToScalar(rows - 1)); |
michael@0 | 50 | const SkScalar invC = SkScalarInvert(SkIntToScalar(cols - 1)); |
michael@0 | 51 | |
michael@0 | 52 | for (int y = 0; y < cols; y++) { |
michael@0 | 53 | SkScalar yy = y * invC; |
michael@0 | 54 | for (int x = 0; x < rows; x++) { |
michael@0 | 55 | *verts++ = this->eval(x * invR, yy); |
michael@0 | 56 | } |
michael@0 | 57 | } |
michael@0 | 58 | return true; |
michael@0 | 59 | } |
michael@0 | 60 | |
michael@0 | 61 | //////////////////////////////////////////////////////////////////////// |
michael@0 | 62 | |
michael@0 | 63 | #include "SkGeometry.h" |
michael@0 | 64 | |
michael@0 | 65 | SkPoint SkLineBoundary::eval(Edge e, SkScalar t) { |
michael@0 | 66 | SkASSERT((unsigned)e < 4); |
michael@0 | 67 | return SkPointInterp(fPts[e], fPts[(e + 1) & 3], t); |
michael@0 | 68 | } |
michael@0 | 69 | |
michael@0 | 70 | SkPoint SkCubicBoundary::eval(Edge e, SkScalar t) { |
michael@0 | 71 | SkASSERT((unsigned)e < 4); |
michael@0 | 72 | |
michael@0 | 73 | // ensure our 4th cubic wraps to the start of the first |
michael@0 | 74 | fPts[12] = fPts[0]; |
michael@0 | 75 | |
michael@0 | 76 | SkPoint loc; |
michael@0 | 77 | SkEvalCubicAt(&fPts[e * 3], t, &loc, NULL, NULL); |
michael@0 | 78 | return loc; |
michael@0 | 79 | } |