dandov | ecfff21 | 2014-08-04 10:02:00 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2014 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #include "SkPatchUtils.h" |
| 9 | |
dandov | b3c9d1c | 2014-08-12 08:34:29 -0700 | [diff] [blame] | 10 | #include "SkColorPriv.h" |
| 11 | #include "SkGeometry.h" |
| 12 | |
Mike Reed | 4ebb43e | 2017-04-05 11:06:15 -0400 | [diff] [blame] | 13 | namespace { |
| 14 | enum CubicCtrlPts { |
| 15 | kTopP0_CubicCtrlPts = 0, |
| 16 | kTopP1_CubicCtrlPts = 1, |
| 17 | kTopP2_CubicCtrlPts = 2, |
| 18 | kTopP3_CubicCtrlPts = 3, |
| 19 | |
| 20 | kRightP0_CubicCtrlPts = 3, |
| 21 | kRightP1_CubicCtrlPts = 4, |
| 22 | kRightP2_CubicCtrlPts = 5, |
| 23 | kRightP3_CubicCtrlPts = 6, |
| 24 | |
| 25 | kBottomP0_CubicCtrlPts = 9, |
| 26 | kBottomP1_CubicCtrlPts = 8, |
| 27 | kBottomP2_CubicCtrlPts = 7, |
| 28 | kBottomP3_CubicCtrlPts = 6, |
| 29 | |
| 30 | kLeftP0_CubicCtrlPts = 0, |
| 31 | kLeftP1_CubicCtrlPts = 11, |
| 32 | kLeftP2_CubicCtrlPts = 10, |
| 33 | kLeftP3_CubicCtrlPts = 9, |
| 34 | }; |
| 35 | |
| 36 | // Enum for corner also clockwise. |
| 37 | enum Corner { |
| 38 | kTopLeft_Corner = 0, |
| 39 | kTopRight_Corner, |
| 40 | kBottomRight_Corner, |
| 41 | kBottomLeft_Corner |
| 42 | }; |
| 43 | } |
| 44 | |
dandov | b3c9d1c | 2014-08-12 08:34:29 -0700 | [diff] [blame] | 45 | /** |
| 46 | * Evaluator to sample the values of a cubic bezier using forward differences. |
| 47 | * Forward differences is a method for evaluating a nth degree polynomial at a uniform step by only |
| 48 | * adding precalculated values. |
| 49 | * For a linear example we have the function f(t) = m*t+b, then the value of that function at t+h |
| 50 | * would be f(t+h) = m*(t+h)+b. If we want to know the uniform step that we must add to the first |
| 51 | * evaluation f(t) then we need to substract f(t+h) - f(t) = m*t + m*h + b - m*t + b = mh. After |
| 52 | * obtaining this value (mh) we could just add this constant step to our first sampled point |
| 53 | * to compute the next one. |
| 54 | * |
| 55 | * For the cubic case the first difference gives as a result a quadratic polynomial to which we can |
| 56 | * apply again forward differences and get linear function to which we can apply again forward |
| 57 | * differences to get a constant difference. This is why we keep an array of size 4, the 0th |
| 58 | * position keeps the sampled value while the next ones keep the quadratic, linear and constant |
| 59 | * difference values. |
| 60 | */ |
| 61 | |
| 62 | class FwDCubicEvaluator { |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 63 | |
dandov | b3c9d1c | 2014-08-12 08:34:29 -0700 | [diff] [blame] | 64 | public: |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 65 | |
dandov | b3c9d1c | 2014-08-12 08:34:29 -0700 | [diff] [blame] | 66 | /** |
| 67 | * Receives the 4 control points of the cubic bezier. |
| 68 | */ |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 69 | |
caryclark | 5ba2b96 | 2016-01-26 17:02:30 -0800 | [diff] [blame] | 70 | explicit FwDCubicEvaluator(const SkPoint points[4]) |
| 71 | : fCoefs(points) { |
dandov | b3c9d1c | 2014-08-12 08:34:29 -0700 | [diff] [blame] | 72 | memcpy(fPoints, points, 4 * sizeof(SkPoint)); |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 73 | |
dandov | b3c9d1c | 2014-08-12 08:34:29 -0700 | [diff] [blame] | 74 | this->restart(1); |
| 75 | } |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 76 | |
dandov | b3c9d1c | 2014-08-12 08:34:29 -0700 | [diff] [blame] | 77 | /** |
| 78 | * Restarts the forward differences evaluator to the first value of t = 0. |
| 79 | */ |
| 80 | void restart(int divisions) { |
| 81 | fDivisions = divisions; |
dandov | b3c9d1c | 2014-08-12 08:34:29 -0700 | [diff] [blame] | 82 | fCurrent = 0; |
| 83 | fMax = fDivisions + 1; |
caryclark | 5ba2b96 | 2016-01-26 17:02:30 -0800 | [diff] [blame] | 84 | Sk2s h = Sk2s(1.f / fDivisions); |
| 85 | Sk2s h2 = h * h; |
| 86 | Sk2s h3 = h2 * h; |
| 87 | Sk2s fwDiff3 = Sk2s(6) * fCoefs.fA * h3; |
| 88 | fFwDiff[3] = to_point(fwDiff3); |
| 89 | fFwDiff[2] = to_point(fwDiff3 + times_2(fCoefs.fB) * h2); |
| 90 | fFwDiff[1] = to_point(fCoefs.fA * h3 + fCoefs.fB * h2 + fCoefs.fC * h); |
| 91 | fFwDiff[0] = to_point(fCoefs.fD); |
dandov | b3c9d1c | 2014-08-12 08:34:29 -0700 | [diff] [blame] | 92 | } |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 93 | |
dandov | b3c9d1c | 2014-08-12 08:34:29 -0700 | [diff] [blame] | 94 | /** |
| 95 | * Check if the evaluator is still within the range of 0<=t<=1 |
| 96 | */ |
| 97 | bool done() const { |
| 98 | return fCurrent > fMax; |
| 99 | } |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 100 | |
dandov | b3c9d1c | 2014-08-12 08:34:29 -0700 | [diff] [blame] | 101 | /** |
| 102 | * Call next to obtain the SkPoint sampled and move to the next one. |
| 103 | */ |
| 104 | SkPoint next() { |
| 105 | SkPoint point = fFwDiff[0]; |
| 106 | fFwDiff[0] += fFwDiff[1]; |
| 107 | fFwDiff[1] += fFwDiff[2]; |
| 108 | fFwDiff[2] += fFwDiff[3]; |
| 109 | fCurrent++; |
| 110 | return point; |
| 111 | } |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 112 | |
dandov | b3c9d1c | 2014-08-12 08:34:29 -0700 | [diff] [blame] | 113 | const SkPoint* getCtrlPoints() const { |
| 114 | return fPoints; |
| 115 | } |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 116 | |
dandov | b3c9d1c | 2014-08-12 08:34:29 -0700 | [diff] [blame] | 117 | private: |
caryclark | 5ba2b96 | 2016-01-26 17:02:30 -0800 | [diff] [blame] | 118 | SkCubicCoeff fCoefs; |
dandov | b3c9d1c | 2014-08-12 08:34:29 -0700 | [diff] [blame] | 119 | int fMax, fCurrent, fDivisions; |
caryclark | 5ba2b96 | 2016-01-26 17:02:30 -0800 | [diff] [blame] | 120 | SkPoint fFwDiff[4], fPoints[4]; |
dandov | b3c9d1c | 2014-08-12 08:34:29 -0700 | [diff] [blame] | 121 | }; |
| 122 | |
| 123 | //////////////////////////////////////////////////////////////////////////////// |
| 124 | |
dandov | ecfff21 | 2014-08-04 10:02:00 -0700 | [diff] [blame] | 125 | // size in pixels of each partition per axis, adjust this knob |
dandov | b3c9d1c | 2014-08-12 08:34:29 -0700 | [diff] [blame] | 126 | static const int kPartitionSize = 10; |
dandov | ecfff21 | 2014-08-04 10:02:00 -0700 | [diff] [blame] | 127 | |
| 128 | /** |
| 129 | * Calculate the approximate arc length given a bezier curve's control points. |
| 130 | */ |
| 131 | static SkScalar approx_arc_length(SkPoint* points, int count) { |
| 132 | if (count < 2) { |
| 133 | return 0; |
| 134 | } |
| 135 | SkScalar arcLength = 0; |
| 136 | for (int i = 0; i < count - 1; i++) { |
| 137 | arcLength += SkPoint::Distance(points[i], points[i + 1]); |
| 138 | } |
| 139 | return arcLength; |
| 140 | } |
| 141 | |
dandov | b3c9d1c | 2014-08-12 08:34:29 -0700 | [diff] [blame] | 142 | static SkScalar bilerp(SkScalar tx, SkScalar ty, SkScalar c00, SkScalar c10, SkScalar c01, |
| 143 | SkScalar c11) { |
| 144 | SkScalar a = c00 * (1.f - tx) + c10 * tx; |
| 145 | SkScalar b = c01 * (1.f - tx) + c11 * tx; |
| 146 | return a * (1.f - ty) + b * ty; |
| 147 | } |
| 148 | |
| 149 | SkISize SkPatchUtils::GetLevelOfDetail(const SkPoint cubics[12], const SkMatrix* matrix) { |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 150 | |
dandov | ecfff21 | 2014-08-04 10:02:00 -0700 | [diff] [blame] | 151 | // Approximate length of each cubic. |
dandov | b3c9d1c | 2014-08-12 08:34:29 -0700 | [diff] [blame] | 152 | SkPoint pts[kNumPtsCubic]; |
Mike Reed | 4ebb43e | 2017-04-05 11:06:15 -0400 | [diff] [blame] | 153 | SkPatchUtils::GetTopCubic(cubics, pts); |
dandov | b3c9d1c | 2014-08-12 08:34:29 -0700 | [diff] [blame] | 154 | matrix->mapPoints(pts, kNumPtsCubic); |
| 155 | SkScalar topLength = approx_arc_length(pts, kNumPtsCubic); |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 156 | |
Mike Reed | 4ebb43e | 2017-04-05 11:06:15 -0400 | [diff] [blame] | 157 | SkPatchUtils::GetBottomCubic(cubics, pts); |
dandov | b3c9d1c | 2014-08-12 08:34:29 -0700 | [diff] [blame] | 158 | matrix->mapPoints(pts, kNumPtsCubic); |
| 159 | SkScalar bottomLength = approx_arc_length(pts, kNumPtsCubic); |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 160 | |
Mike Reed | 4ebb43e | 2017-04-05 11:06:15 -0400 | [diff] [blame] | 161 | SkPatchUtils::GetLeftCubic(cubics, pts); |
dandov | b3c9d1c | 2014-08-12 08:34:29 -0700 | [diff] [blame] | 162 | matrix->mapPoints(pts, kNumPtsCubic); |
| 163 | SkScalar leftLength = approx_arc_length(pts, kNumPtsCubic); |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 164 | |
Mike Reed | 4ebb43e | 2017-04-05 11:06:15 -0400 | [diff] [blame] | 165 | SkPatchUtils::GetRightCubic(cubics, pts); |
dandov | b3c9d1c | 2014-08-12 08:34:29 -0700 | [diff] [blame] | 166 | matrix->mapPoints(pts, kNumPtsCubic); |
| 167 | SkScalar rightLength = approx_arc_length(pts, kNumPtsCubic); |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 168 | |
dandov | ecfff21 | 2014-08-04 10:02:00 -0700 | [diff] [blame] | 169 | // Level of detail per axis, based on the larger side between top and bottom or left and right |
| 170 | int lodX = static_cast<int>(SkMaxScalar(topLength, bottomLength) / kPartitionSize); |
| 171 | int lodY = static_cast<int>(SkMaxScalar(leftLength, rightLength) / kPartitionSize); |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 172 | |
dandov | b3c9d1c | 2014-08-12 08:34:29 -0700 | [diff] [blame] | 173 | return SkISize::Make(SkMax32(8, lodX), SkMax32(8, lodY)); |
| 174 | } |
| 175 | |
Mike Reed | 4ebb43e | 2017-04-05 11:06:15 -0400 | [diff] [blame] | 176 | void SkPatchUtils::GetTopCubic(const SkPoint cubics[12], SkPoint points[4]) { |
dandov | b3c9d1c | 2014-08-12 08:34:29 -0700 | [diff] [blame] | 177 | points[0] = cubics[kTopP0_CubicCtrlPts]; |
| 178 | points[1] = cubics[kTopP1_CubicCtrlPts]; |
| 179 | points[2] = cubics[kTopP2_CubicCtrlPts]; |
| 180 | points[3] = cubics[kTopP3_CubicCtrlPts]; |
| 181 | } |
| 182 | |
Mike Reed | 4ebb43e | 2017-04-05 11:06:15 -0400 | [diff] [blame] | 183 | void SkPatchUtils::GetBottomCubic(const SkPoint cubics[12], SkPoint points[4]) { |
dandov | b3c9d1c | 2014-08-12 08:34:29 -0700 | [diff] [blame] | 184 | points[0] = cubics[kBottomP0_CubicCtrlPts]; |
| 185 | points[1] = cubics[kBottomP1_CubicCtrlPts]; |
| 186 | points[2] = cubics[kBottomP2_CubicCtrlPts]; |
| 187 | points[3] = cubics[kBottomP3_CubicCtrlPts]; |
| 188 | } |
| 189 | |
Mike Reed | 4ebb43e | 2017-04-05 11:06:15 -0400 | [diff] [blame] | 190 | void SkPatchUtils::GetLeftCubic(const SkPoint cubics[12], SkPoint points[4]) { |
dandov | b3c9d1c | 2014-08-12 08:34:29 -0700 | [diff] [blame] | 191 | points[0] = cubics[kLeftP0_CubicCtrlPts]; |
| 192 | points[1] = cubics[kLeftP1_CubicCtrlPts]; |
| 193 | points[2] = cubics[kLeftP2_CubicCtrlPts]; |
| 194 | points[3] = cubics[kLeftP3_CubicCtrlPts]; |
| 195 | } |
| 196 | |
Mike Reed | 4ebb43e | 2017-04-05 11:06:15 -0400 | [diff] [blame] | 197 | void SkPatchUtils::GetRightCubic(const SkPoint cubics[12], SkPoint points[4]) { |
dandov | b3c9d1c | 2014-08-12 08:34:29 -0700 | [diff] [blame] | 198 | points[0] = cubics[kRightP0_CubicCtrlPts]; |
| 199 | points[1] = cubics[kRightP1_CubicCtrlPts]; |
| 200 | points[2] = cubics[kRightP2_CubicCtrlPts]; |
| 201 | points[3] = cubics[kRightP3_CubicCtrlPts]; |
| 202 | } |
| 203 | |
Mike Reed | 795c5ea | 2017-03-17 14:29:05 -0400 | [diff] [blame] | 204 | sk_sp<SkVertices> SkPatchUtils::MakeVertices(const SkPoint cubics[12], const SkColor srcColors[4], |
| 205 | const SkPoint srcTexCoords[4], int lodX, int lodY) { |
| 206 | if (lodX < 1 || lodY < 1 || nullptr == cubics) { |
| 207 | return nullptr; |
| 208 | } |
| 209 | |
| 210 | // check for overflow in multiplication |
| 211 | const int64_t lodX64 = (lodX + 1), |
| 212 | lodY64 = (lodY + 1), |
| 213 | mult64 = lodX64 * lodY64; |
| 214 | if (mult64 > SK_MaxS32) { |
| 215 | return nullptr; |
| 216 | } |
| 217 | |
| 218 | int vertexCount = SkToS32(mult64); |
| 219 | // it is recommended to generate draw calls of no more than 65536 indices, so we never generate |
| 220 | // more than 60000 indices. To accomplish that we resize the LOD and vertex count |
| 221 | if (vertexCount > 10000 || lodX > 200 || lodY > 200) { |
| 222 | float weightX = static_cast<float>(lodX) / (lodX + lodY); |
| 223 | float weightY = static_cast<float>(lodY) / (lodX + lodY); |
| 224 | |
| 225 | // 200 comes from the 100 * 2 which is the max value of vertices because of the limit of |
| 226 | // 60000 indices ( sqrt(60000 / 6) that comes from data->fIndexCount = lodX * lodY * 6) |
| 227 | lodX = static_cast<int>(weightX * 200); |
| 228 | lodY = static_cast<int>(weightY * 200); |
| 229 | vertexCount = (lodX + 1) * (lodY + 1); |
| 230 | } |
| 231 | const int indexCount = lodX * lodY * 6; |
| 232 | uint32_t flags = 0; |
| 233 | if (srcTexCoords) { |
| 234 | flags |= SkVertices::kHasTexCoords_BuilderFlag; |
| 235 | } |
| 236 | if (srcColors) { |
| 237 | flags |= SkVertices::kHasColors_BuilderFlag; |
| 238 | } |
| 239 | |
Mike Reed | 887cdf1 | 2017-04-03 11:11:09 -0400 | [diff] [blame] | 240 | SkVertices::Builder builder(SkVertices::kTriangles_VertexMode, vertexCount, indexCount, flags); |
Mike Reed | 795c5ea | 2017-03-17 14:29:05 -0400 | [diff] [blame] | 241 | SkPoint* pos = builder.positions(); |
| 242 | SkPoint* texs = builder.texCoords(); |
| 243 | SkColor* colors = builder.colors(); |
| 244 | uint16_t* indices = builder.indices(); |
| 245 | |
| 246 | // if colors is not null then create array for colors |
| 247 | SkPMColor colorsPM[kNumCorners]; |
| 248 | if (srcColors) { |
| 249 | // premultiply colors to avoid color bleeding. |
| 250 | for (int i = 0; i < kNumCorners; i++) { |
| 251 | colorsPM[i] = SkPreMultiplyColor(srcColors[i]); |
| 252 | } |
| 253 | srcColors = colorsPM; |
| 254 | } |
| 255 | |
| 256 | SkPoint pts[kNumPtsCubic]; |
Mike Reed | 4ebb43e | 2017-04-05 11:06:15 -0400 | [diff] [blame] | 257 | SkPatchUtils::GetBottomCubic(cubics, pts); |
Mike Reed | 795c5ea | 2017-03-17 14:29:05 -0400 | [diff] [blame] | 258 | FwDCubicEvaluator fBottom(pts); |
Mike Reed | 4ebb43e | 2017-04-05 11:06:15 -0400 | [diff] [blame] | 259 | SkPatchUtils::GetTopCubic(cubics, pts); |
Mike Reed | 795c5ea | 2017-03-17 14:29:05 -0400 | [diff] [blame] | 260 | FwDCubicEvaluator fTop(pts); |
Mike Reed | 4ebb43e | 2017-04-05 11:06:15 -0400 | [diff] [blame] | 261 | SkPatchUtils::GetLeftCubic(cubics, pts); |
Mike Reed | 795c5ea | 2017-03-17 14:29:05 -0400 | [diff] [blame] | 262 | FwDCubicEvaluator fLeft(pts); |
Mike Reed | 4ebb43e | 2017-04-05 11:06:15 -0400 | [diff] [blame] | 263 | SkPatchUtils::GetRightCubic(cubics, pts); |
Mike Reed | 795c5ea | 2017-03-17 14:29:05 -0400 | [diff] [blame] | 264 | FwDCubicEvaluator fRight(pts); |
| 265 | |
| 266 | fBottom.restart(lodX); |
| 267 | fTop.restart(lodX); |
| 268 | |
| 269 | SkScalar u = 0.0f; |
| 270 | int stride = lodY + 1; |
| 271 | for (int x = 0; x <= lodX; x++) { |
| 272 | SkPoint bottom = fBottom.next(), top = fTop.next(); |
| 273 | fLeft.restart(lodY); |
| 274 | fRight.restart(lodY); |
| 275 | SkScalar v = 0.f; |
| 276 | for (int y = 0; y <= lodY; y++) { |
| 277 | int dataIndex = x * (lodY + 1) + y; |
| 278 | |
| 279 | SkPoint left = fLeft.next(), right = fRight.next(); |
| 280 | |
| 281 | SkPoint s0 = SkPoint::Make((1.0f - v) * top.x() + v * bottom.x(), |
| 282 | (1.0f - v) * top.y() + v * bottom.y()); |
| 283 | SkPoint s1 = SkPoint::Make((1.0f - u) * left.x() + u * right.x(), |
| 284 | (1.0f - u) * left.y() + u * right.y()); |
| 285 | SkPoint s2 = SkPoint::Make( |
| 286 | (1.0f - v) * ((1.0f - u) * fTop.getCtrlPoints()[0].x() |
| 287 | + u * fTop.getCtrlPoints()[3].x()) |
| 288 | + v * ((1.0f - u) * fBottom.getCtrlPoints()[0].x() |
| 289 | + u * fBottom.getCtrlPoints()[3].x()), |
| 290 | (1.0f - v) * ((1.0f - u) * fTop.getCtrlPoints()[0].y() |
| 291 | + u * fTop.getCtrlPoints()[3].y()) |
| 292 | + v * ((1.0f - u) * fBottom.getCtrlPoints()[0].y() |
| 293 | + u * fBottom.getCtrlPoints()[3].y())); |
| 294 | pos[dataIndex] = s0 + s1 - s2; |
| 295 | |
| 296 | if (colors) { |
| 297 | uint8_t a = uint8_t(bilerp(u, v, |
| 298 | SkScalar(SkColorGetA(colorsPM[kTopLeft_Corner])), |
| 299 | SkScalar(SkColorGetA(colorsPM[kTopRight_Corner])), |
| 300 | SkScalar(SkColorGetA(colorsPM[kBottomLeft_Corner])), |
| 301 | SkScalar(SkColorGetA(colorsPM[kBottomRight_Corner])))); |
| 302 | uint8_t r = uint8_t(bilerp(u, v, |
| 303 | SkScalar(SkColorGetR(colorsPM[kTopLeft_Corner])), |
| 304 | SkScalar(SkColorGetR(colorsPM[kTopRight_Corner])), |
| 305 | SkScalar(SkColorGetR(colorsPM[kBottomLeft_Corner])), |
| 306 | SkScalar(SkColorGetR(colorsPM[kBottomRight_Corner])))); |
| 307 | uint8_t g = uint8_t(bilerp(u, v, |
| 308 | SkScalar(SkColorGetG(colorsPM[kTopLeft_Corner])), |
| 309 | SkScalar(SkColorGetG(colorsPM[kTopRight_Corner])), |
| 310 | SkScalar(SkColorGetG(colorsPM[kBottomLeft_Corner])), |
| 311 | SkScalar(SkColorGetG(colorsPM[kBottomRight_Corner])))); |
| 312 | uint8_t b = uint8_t(bilerp(u, v, |
| 313 | SkScalar(SkColorGetB(colorsPM[kTopLeft_Corner])), |
| 314 | SkScalar(SkColorGetB(colorsPM[kTopRight_Corner])), |
| 315 | SkScalar(SkColorGetB(colorsPM[kBottomLeft_Corner])), |
| 316 | SkScalar(SkColorGetB(colorsPM[kBottomRight_Corner])))); |
| 317 | colors[dataIndex] = SkPackARGB32(a,r,g,b); |
| 318 | } |
| 319 | |
| 320 | if (texs) { |
| 321 | texs[dataIndex] = SkPoint::Make(bilerp(u, v, srcTexCoords[kTopLeft_Corner].x(), |
| 322 | srcTexCoords[kTopRight_Corner].x(), |
| 323 | srcTexCoords[kBottomLeft_Corner].x(), |
| 324 | srcTexCoords[kBottomRight_Corner].x()), |
| 325 | bilerp(u, v, srcTexCoords[kTopLeft_Corner].y(), |
| 326 | srcTexCoords[kTopRight_Corner].y(), |
| 327 | srcTexCoords[kBottomLeft_Corner].y(), |
| 328 | srcTexCoords[kBottomRight_Corner].y())); |
| 329 | |
| 330 | } |
| 331 | |
| 332 | if(x < lodX && y < lodY) { |
| 333 | int i = 6 * (x * lodY + y); |
| 334 | indices[i] = x * stride + y; |
| 335 | indices[i + 1] = x * stride + 1 + y; |
| 336 | indices[i + 2] = (x + 1) * stride + 1 + y; |
| 337 | indices[i + 3] = indices[i]; |
| 338 | indices[i + 4] = indices[i + 2]; |
| 339 | indices[i + 5] = (x + 1) * stride + y; |
| 340 | } |
| 341 | v = SkScalarClampMax(v + 1.f / lodY, 1); |
| 342 | } |
| 343 | u = SkScalarClampMax(u + 1.f / lodX, 1); |
| 344 | } |
| 345 | return builder.detach(); |
| 346 | } |