blob: a28abdf807e73621887697823876508bd2f953af [file] [log] [blame]
dandovecfff212014-08-04 10:02:00 -07001/*
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
Cary Clarka4083c92017-09-15 11:59:23 -040010#include "SkColorData.h"
dandovb3c9d1c2014-08-12 08:34:29 -070011#include "SkGeometry.h"
Mike Reed435071e2017-05-23 11:22:56 -040012#include "SkPM4f.h"
Hal Canaryc640d0d2018-06-13 09:59:02 -040013#include "SkTo.h"
dandovb3c9d1c2014-08-12 08:34:29 -070014
Mike Reed4ebb43e2017-04-05 11:06:15 -040015namespace {
16 enum CubicCtrlPts {
17 kTopP0_CubicCtrlPts = 0,
18 kTopP1_CubicCtrlPts = 1,
19 kTopP2_CubicCtrlPts = 2,
20 kTopP3_CubicCtrlPts = 3,
21
22 kRightP0_CubicCtrlPts = 3,
23 kRightP1_CubicCtrlPts = 4,
24 kRightP2_CubicCtrlPts = 5,
25 kRightP3_CubicCtrlPts = 6,
26
27 kBottomP0_CubicCtrlPts = 9,
28 kBottomP1_CubicCtrlPts = 8,
29 kBottomP2_CubicCtrlPts = 7,
30 kBottomP3_CubicCtrlPts = 6,
31
32 kLeftP0_CubicCtrlPts = 0,
33 kLeftP1_CubicCtrlPts = 11,
34 kLeftP2_CubicCtrlPts = 10,
35 kLeftP3_CubicCtrlPts = 9,
36 };
37
38 // Enum for corner also clockwise.
39 enum Corner {
40 kTopLeft_Corner = 0,
41 kTopRight_Corner,
42 kBottomRight_Corner,
43 kBottomLeft_Corner
44 };
45}
46
dandovb3c9d1c2014-08-12 08:34:29 -070047/**
48 * Evaluator to sample the values of a cubic bezier using forward differences.
49 * Forward differences is a method for evaluating a nth degree polynomial at a uniform step by only
50 * adding precalculated values.
51 * For a linear example we have the function f(t) = m*t+b, then the value of that function at t+h
52 * would be f(t+h) = m*(t+h)+b. If we want to know the uniform step that we must add to the first
53 * evaluation f(t) then we need to substract f(t+h) - f(t) = m*t + m*h + b - m*t + b = mh. After
54 * obtaining this value (mh) we could just add this constant step to our first sampled point
55 * to compute the next one.
56 *
57 * For the cubic case the first difference gives as a result a quadratic polynomial to which we can
58 * apply again forward differences and get linear function to which we can apply again forward
59 * differences to get a constant difference. This is why we keep an array of size 4, the 0th
60 * position keeps the sampled value while the next ones keep the quadratic, linear and constant
61 * difference values.
62 */
63
64class FwDCubicEvaluator {
halcanary9d524f22016-03-29 09:03:52 -070065
dandovb3c9d1c2014-08-12 08:34:29 -070066public:
halcanary9d524f22016-03-29 09:03:52 -070067
dandovb3c9d1c2014-08-12 08:34:29 -070068 /**
69 * Receives the 4 control points of the cubic bezier.
70 */
halcanary9d524f22016-03-29 09:03:52 -070071
caryclark5ba2b962016-01-26 17:02:30 -080072 explicit FwDCubicEvaluator(const SkPoint points[4])
73 : fCoefs(points) {
dandovb3c9d1c2014-08-12 08:34:29 -070074 memcpy(fPoints, points, 4 * sizeof(SkPoint));
halcanary9d524f22016-03-29 09:03:52 -070075
dandovb3c9d1c2014-08-12 08:34:29 -070076 this->restart(1);
77 }
halcanary9d524f22016-03-29 09:03:52 -070078
dandovb3c9d1c2014-08-12 08:34:29 -070079 /**
80 * Restarts the forward differences evaluator to the first value of t = 0.
81 */
82 void restart(int divisions) {
83 fDivisions = divisions;
dandovb3c9d1c2014-08-12 08:34:29 -070084 fCurrent = 0;
85 fMax = fDivisions + 1;
caryclark5ba2b962016-01-26 17:02:30 -080086 Sk2s h = Sk2s(1.f / fDivisions);
87 Sk2s h2 = h * h;
88 Sk2s h3 = h2 * h;
89 Sk2s fwDiff3 = Sk2s(6) * fCoefs.fA * h3;
90 fFwDiff[3] = to_point(fwDiff3);
91 fFwDiff[2] = to_point(fwDiff3 + times_2(fCoefs.fB) * h2);
92 fFwDiff[1] = to_point(fCoefs.fA * h3 + fCoefs.fB * h2 + fCoefs.fC * h);
93 fFwDiff[0] = to_point(fCoefs.fD);
dandovb3c9d1c2014-08-12 08:34:29 -070094 }
halcanary9d524f22016-03-29 09:03:52 -070095
dandovb3c9d1c2014-08-12 08:34:29 -070096 /**
97 * Check if the evaluator is still within the range of 0<=t<=1
98 */
99 bool done() const {
100 return fCurrent > fMax;
101 }
halcanary9d524f22016-03-29 09:03:52 -0700102
dandovb3c9d1c2014-08-12 08:34:29 -0700103 /**
104 * Call next to obtain the SkPoint sampled and move to the next one.
105 */
106 SkPoint next() {
107 SkPoint point = fFwDiff[0];
108 fFwDiff[0] += fFwDiff[1];
109 fFwDiff[1] += fFwDiff[2];
110 fFwDiff[2] += fFwDiff[3];
111 fCurrent++;
112 return point;
113 }
halcanary9d524f22016-03-29 09:03:52 -0700114
dandovb3c9d1c2014-08-12 08:34:29 -0700115 const SkPoint* getCtrlPoints() const {
116 return fPoints;
117 }
halcanary9d524f22016-03-29 09:03:52 -0700118
dandovb3c9d1c2014-08-12 08:34:29 -0700119private:
caryclark5ba2b962016-01-26 17:02:30 -0800120 SkCubicCoeff fCoefs;
dandovb3c9d1c2014-08-12 08:34:29 -0700121 int fMax, fCurrent, fDivisions;
caryclark5ba2b962016-01-26 17:02:30 -0800122 SkPoint fFwDiff[4], fPoints[4];
dandovb3c9d1c2014-08-12 08:34:29 -0700123};
124
125////////////////////////////////////////////////////////////////////////////////
126
dandovecfff212014-08-04 10:02:00 -0700127// size in pixels of each partition per axis, adjust this knob
dandovb3c9d1c2014-08-12 08:34:29 -0700128static const int kPartitionSize = 10;
dandovecfff212014-08-04 10:02:00 -0700129
130/**
Mike Reedf4f06ad2018-05-02 15:11:42 -0400131 * Calculate the approximate arc length given a bezier curve's control points.
132 * Returns -1 if bad calc (i.e. non-finite)
dandovecfff212014-08-04 10:02:00 -0700133 */
Mike Reedf4f06ad2018-05-02 15:11:42 -0400134static SkScalar approx_arc_length(const SkPoint points[], int count) {
dandovecfff212014-08-04 10:02:00 -0700135 if (count < 2) {
136 return 0;
137 }
138 SkScalar arcLength = 0;
139 for (int i = 0; i < count - 1; i++) {
140 arcLength += SkPoint::Distance(points[i], points[i + 1]);
141 }
Mike Reedf4f06ad2018-05-02 15:11:42 -0400142 return SkScalarIsFinite(arcLength) ? arcLength : -1;
dandovecfff212014-08-04 10:02:00 -0700143}
144
dandovb3c9d1c2014-08-12 08:34:29 -0700145static SkScalar bilerp(SkScalar tx, SkScalar ty, SkScalar c00, SkScalar c10, SkScalar c01,
Mike Reed435071e2017-05-23 11:22:56 -0400146 SkScalar c11) {
dandovb3c9d1c2014-08-12 08:34:29 -0700147 SkScalar a = c00 * (1.f - tx) + c10 * tx;
148 SkScalar b = c01 * (1.f - tx) + c11 * tx;
149 return a * (1.f - ty) + b * ty;
150}
151
Mike Reed435071e2017-05-23 11:22:56 -0400152static Sk4f bilerp(SkScalar tx, SkScalar ty,
153 const Sk4f& c00, const Sk4f& c10, const Sk4f& c01, const Sk4f& c11) {
154 Sk4f a = c00 * (1.f - tx) + c10 * tx;
155 Sk4f b = c01 * (1.f - tx) + c11 * tx;
156 return a * (1.f - ty) + b * ty;
157}
158
dandovb3c9d1c2014-08-12 08:34:29 -0700159SkISize SkPatchUtils::GetLevelOfDetail(const SkPoint cubics[12], const SkMatrix* matrix) {
dandovecfff212014-08-04 10:02:00 -0700160 // Approximate length of each cubic.
dandovb3c9d1c2014-08-12 08:34:29 -0700161 SkPoint pts[kNumPtsCubic];
Mike Reed4ebb43e2017-04-05 11:06:15 -0400162 SkPatchUtils::GetTopCubic(cubics, pts);
dandovb3c9d1c2014-08-12 08:34:29 -0700163 matrix->mapPoints(pts, kNumPtsCubic);
164 SkScalar topLength = approx_arc_length(pts, kNumPtsCubic);
halcanary9d524f22016-03-29 09:03:52 -0700165
Mike Reed4ebb43e2017-04-05 11:06:15 -0400166 SkPatchUtils::GetBottomCubic(cubics, pts);
dandovb3c9d1c2014-08-12 08:34:29 -0700167 matrix->mapPoints(pts, kNumPtsCubic);
168 SkScalar bottomLength = approx_arc_length(pts, kNumPtsCubic);
halcanary9d524f22016-03-29 09:03:52 -0700169
Mike Reed4ebb43e2017-04-05 11:06:15 -0400170 SkPatchUtils::GetLeftCubic(cubics, pts);
dandovb3c9d1c2014-08-12 08:34:29 -0700171 matrix->mapPoints(pts, kNumPtsCubic);
172 SkScalar leftLength = approx_arc_length(pts, kNumPtsCubic);
halcanary9d524f22016-03-29 09:03:52 -0700173
Mike Reed4ebb43e2017-04-05 11:06:15 -0400174 SkPatchUtils::GetRightCubic(cubics, pts);
dandovb3c9d1c2014-08-12 08:34:29 -0700175 matrix->mapPoints(pts, kNumPtsCubic);
176 SkScalar rightLength = approx_arc_length(pts, kNumPtsCubic);
halcanary9d524f22016-03-29 09:03:52 -0700177
Mike Reedf4f06ad2018-05-02 15:11:42 -0400178 if (topLength < 0 || bottomLength < 0 || leftLength < 0 || rightLength < 0) {
179 return {0, 0}; // negative length is a sentinel for bad length (i.e. non-finite)
180 }
181
dandovecfff212014-08-04 10:02:00 -0700182 // Level of detail per axis, based on the larger side between top and bottom or left and right
183 int lodX = static_cast<int>(SkMaxScalar(topLength, bottomLength) / kPartitionSize);
184 int lodY = static_cast<int>(SkMaxScalar(leftLength, rightLength) / kPartitionSize);
halcanary9d524f22016-03-29 09:03:52 -0700185
dandovb3c9d1c2014-08-12 08:34:29 -0700186 return SkISize::Make(SkMax32(8, lodX), SkMax32(8, lodY));
187}
188
Mike Reed4ebb43e2017-04-05 11:06:15 -0400189void SkPatchUtils::GetTopCubic(const SkPoint cubics[12], SkPoint points[4]) {
dandovb3c9d1c2014-08-12 08:34:29 -0700190 points[0] = cubics[kTopP0_CubicCtrlPts];
191 points[1] = cubics[kTopP1_CubicCtrlPts];
192 points[2] = cubics[kTopP2_CubicCtrlPts];
193 points[3] = cubics[kTopP3_CubicCtrlPts];
194}
195
Mike Reed4ebb43e2017-04-05 11:06:15 -0400196void SkPatchUtils::GetBottomCubic(const SkPoint cubics[12], SkPoint points[4]) {
dandovb3c9d1c2014-08-12 08:34:29 -0700197 points[0] = cubics[kBottomP0_CubicCtrlPts];
198 points[1] = cubics[kBottomP1_CubicCtrlPts];
199 points[2] = cubics[kBottomP2_CubicCtrlPts];
200 points[3] = cubics[kBottomP3_CubicCtrlPts];
201}
202
Mike Reed4ebb43e2017-04-05 11:06:15 -0400203void SkPatchUtils::GetLeftCubic(const SkPoint cubics[12], SkPoint points[4]) {
dandovb3c9d1c2014-08-12 08:34:29 -0700204 points[0] = cubics[kLeftP0_CubicCtrlPts];
205 points[1] = cubics[kLeftP1_CubicCtrlPts];
206 points[2] = cubics[kLeftP2_CubicCtrlPts];
207 points[3] = cubics[kLeftP3_CubicCtrlPts];
208}
209
Mike Reed4ebb43e2017-04-05 11:06:15 -0400210void SkPatchUtils::GetRightCubic(const SkPoint cubics[12], SkPoint points[4]) {
dandovb3c9d1c2014-08-12 08:34:29 -0700211 points[0] = cubics[kRightP0_CubicCtrlPts];
212 points[1] = cubics[kRightP1_CubicCtrlPts];
213 points[2] = cubics[kRightP2_CubicCtrlPts];
214 points[3] = cubics[kRightP3_CubicCtrlPts];
215}
216
Mike Reed435071e2017-05-23 11:22:56 -0400217#include "SkPM4fPriv.h"
Mike Reed435071e2017-05-23 11:22:56 -0400218#include "SkColorSpaceXform.h"
219
220struct SkRGBAf {
221 float fVec[4];
222
223 static SkRGBAf From4f(const Sk4f& x) {
224 SkRGBAf c;
225 x.store(c.fVec);
226 return c;
227 }
228
229 static SkRGBAf FromBGRA32(SkColor c) {
230 return From4f(swizzle_rb(SkNx_cast<float>(Sk4b::Load(&c)) * (1/255.0f)));
231 }
232
233 Sk4f to4f() const {
234 return Sk4f::Load(fVec);
235 }
236
237 SkColor toBGRA32() const {
238 SkColor color;
239 SkNx_cast<uint8_t>(swizzle_rb(this->to4f()) * Sk4f(255) + Sk4f(0.5f)).store(&color);
240 return color;
241 }
242
243 SkRGBAf premul() const {
244 float a = fVec[3];
245 return From4f(this->to4f() * Sk4f(a, a, a, 1));
246 }
247
248 SkRGBAf unpremul() const {
249 float a = fVec[3];
250 float inv = a ? 1/a : 0;
251 return From4f(this->to4f() * Sk4f(inv, inv, inv, 1));
252 }
253};
254
255static void skcolor_to_linear(SkRGBAf dst[], const SkColor src[], int count, SkColorSpace* cs,
256 bool doPremul) {
257 if (cs) {
258 auto srcCS = SkColorSpace::MakeSRGB();
Brian Osman36703d92017-12-12 14:09:31 -0500259 auto dstCS = cs->makeLinearGamma();
Mike Reed435071e2017-05-23 11:22:56 -0400260 auto op = doPremul ? SkColorSpaceXform::kPremul_AlphaOp
261 : SkColorSpaceXform::kPreserve_AlphaOp;
262 SkColorSpaceXform::Apply(dstCS.get(), SkColorSpaceXform::kRGBA_F32_ColorFormat, dst,
263 srcCS.get(), SkColorSpaceXform::kBGRA_8888_ColorFormat, src,
264 count, op);
265 } else {
266 for (int i = 0; i < count; ++i) {
267 dst[i] = SkRGBAf::FromBGRA32(src[i]);
268 if (doPremul) {
269 dst[i] = dst[i].premul();
270 }
271 }
272 }
273}
274
275static void linear_to_skcolor(SkColor dst[], const SkRGBAf src[], int count, SkColorSpace* cs) {
276 if (cs) {
Brian Osman36703d92017-12-12 14:09:31 -0500277 auto srcCS = cs->makeLinearGamma();
Mike Reed435071e2017-05-23 11:22:56 -0400278 auto dstCS = SkColorSpace::MakeSRGB();
279 SkColorSpaceXform::Apply(dstCS.get(), SkColorSpaceXform::kBGRA_8888_ColorFormat, dst,
280 srcCS.get(), SkColorSpaceXform::kRGBA_F32_ColorFormat, src,
281 count, SkColorSpaceXform::kPreserve_AlphaOp);
282 } else {
283 for (int i = 0; i < count; ++i) {
284 dst[i] = src[i].toBGRA32();
285 }
286 }
287}
288
289static void unpremul(SkRGBAf array[], int count) {
290 for (int i = 0; i < count; ++i) {
291 array[i] = array[i].unpremul();
292 }
293}
294
Mike Reed795c5ea2017-03-17 14:29:05 -0400295sk_sp<SkVertices> SkPatchUtils::MakeVertices(const SkPoint cubics[12], const SkColor srcColors[4],
Mike Reed435071e2017-05-23 11:22:56 -0400296 const SkPoint srcTexCoords[4], int lodX, int lodY,
297 bool interpColorsLinearly) {
Mike Reed795c5ea2017-03-17 14:29:05 -0400298 if (lodX < 1 || lodY < 1 || nullptr == cubics) {
299 return nullptr;
300 }
301
302 // check for overflow in multiplication
303 const int64_t lodX64 = (lodX + 1),
304 lodY64 = (lodY + 1),
305 mult64 = lodX64 * lodY64;
306 if (mult64 > SK_MaxS32) {
307 return nullptr;
308 }
309
310 int vertexCount = SkToS32(mult64);
311 // it is recommended to generate draw calls of no more than 65536 indices, so we never generate
312 // more than 60000 indices. To accomplish that we resize the LOD and vertex count
313 if (vertexCount > 10000 || lodX > 200 || lodY > 200) {
314 float weightX = static_cast<float>(lodX) / (lodX + lodY);
315 float weightY = static_cast<float>(lodY) / (lodX + lodY);
316
317 // 200 comes from the 100 * 2 which is the max value of vertices because of the limit of
318 // 60000 indices ( sqrt(60000 / 6) that comes from data->fIndexCount = lodX * lodY * 6)
Mike Reed70bebb02018-05-09 14:07:21 -0400319 // Need a min of 1 since we later divide by lod
320 lodX = std::max(1, sk_float_floor2int_no_saturate(weightX * 200));
321 lodY = std::max(1, sk_float_floor2int_no_saturate(weightY * 200));
Mike Reed795c5ea2017-03-17 14:29:05 -0400322 vertexCount = (lodX + 1) * (lodY + 1);
323 }
324 const int indexCount = lodX * lodY * 6;
325 uint32_t flags = 0;
326 if (srcTexCoords) {
327 flags |= SkVertices::kHasTexCoords_BuilderFlag;
328 }
329 if (srcColors) {
330 flags |= SkVertices::kHasColors_BuilderFlag;
331 }
332
Florin Malita14a64302017-05-24 14:53:44 -0400333 SkSTArenaAlloc<2048> alloc;
Mike Reed435071e2017-05-23 11:22:56 -0400334 SkRGBAf* cornerColors = srcColors ? alloc.makeArray<SkRGBAf>(4) : nullptr;
335 SkRGBAf* tmpColors = srcColors ? alloc.makeArray<SkRGBAf>(vertexCount) : nullptr;
336 auto convertCS = interpColorsLinearly ? SkColorSpace::MakeSRGB() : nullptr;
337
Mike Reed887cdf12017-04-03 11:11:09 -0400338 SkVertices::Builder builder(SkVertices::kTriangles_VertexMode, vertexCount, indexCount, flags);
Mike Reed795c5ea2017-03-17 14:29:05 -0400339 SkPoint* pos = builder.positions();
340 SkPoint* texs = builder.texCoords();
Mike Reed795c5ea2017-03-17 14:29:05 -0400341 uint16_t* indices = builder.indices();
Mike Reed7346a1f2017-05-18 22:23:34 -0400342 bool is_opaque = false;
Mike Reed795c5ea2017-03-17 14:29:05 -0400343
Mike Reed435071e2017-05-23 11:22:56 -0400344 /*
345 * 1. Should we offer this as a runtime choice, as we do in gradients?
346 * 2. Since drawing the vertices wants premul, shoudl we extend SkVertices to store
347 * premul colors (as floats, w/ a colorspace)?
348 */
349 bool doPremul = true;
350 if (cornerColors) {
Mike Reed7346a1f2017-05-18 22:23:34 -0400351 SkColor c = ~0;
Mike Reed795c5ea2017-03-17 14:29:05 -0400352 for (int i = 0; i < kNumCorners; i++) {
Mike Reed7346a1f2017-05-18 22:23:34 -0400353 c &= srcColors[i];
Mike Reed795c5ea2017-03-17 14:29:05 -0400354 }
Mike Reed7346a1f2017-05-18 22:23:34 -0400355 is_opaque = (SkColorGetA(c) == 0xFF);
Mike Reed435071e2017-05-23 11:22:56 -0400356 if (is_opaque) {
357 doPremul = false; // no need
358 }
359
360 skcolor_to_linear(cornerColors, srcColors, kNumCorners, convertCS.get(), doPremul);
Mike Reed795c5ea2017-03-17 14:29:05 -0400361 }
362
363 SkPoint pts[kNumPtsCubic];
Mike Reed4ebb43e2017-04-05 11:06:15 -0400364 SkPatchUtils::GetBottomCubic(cubics, pts);
Mike Reed795c5ea2017-03-17 14:29:05 -0400365 FwDCubicEvaluator fBottom(pts);
Mike Reed4ebb43e2017-04-05 11:06:15 -0400366 SkPatchUtils::GetTopCubic(cubics, pts);
Mike Reed795c5ea2017-03-17 14:29:05 -0400367 FwDCubicEvaluator fTop(pts);
Mike Reed4ebb43e2017-04-05 11:06:15 -0400368 SkPatchUtils::GetLeftCubic(cubics, pts);
Mike Reed795c5ea2017-03-17 14:29:05 -0400369 FwDCubicEvaluator fLeft(pts);
Mike Reed4ebb43e2017-04-05 11:06:15 -0400370 SkPatchUtils::GetRightCubic(cubics, pts);
Mike Reed795c5ea2017-03-17 14:29:05 -0400371 FwDCubicEvaluator fRight(pts);
372
373 fBottom.restart(lodX);
374 fTop.restart(lodX);
375
376 SkScalar u = 0.0f;
377 int stride = lodY + 1;
378 for (int x = 0; x <= lodX; x++) {
379 SkPoint bottom = fBottom.next(), top = fTop.next();
380 fLeft.restart(lodY);
381 fRight.restart(lodY);
382 SkScalar v = 0.f;
383 for (int y = 0; y <= lodY; y++) {
384 int dataIndex = x * (lodY + 1) + y;
385
386 SkPoint left = fLeft.next(), right = fRight.next();
387
388 SkPoint s0 = SkPoint::Make((1.0f - v) * top.x() + v * bottom.x(),
389 (1.0f - v) * top.y() + v * bottom.y());
390 SkPoint s1 = SkPoint::Make((1.0f - u) * left.x() + u * right.x(),
391 (1.0f - u) * left.y() + u * right.y());
392 SkPoint s2 = SkPoint::Make(
393 (1.0f - v) * ((1.0f - u) * fTop.getCtrlPoints()[0].x()
394 + u * fTop.getCtrlPoints()[3].x())
395 + v * ((1.0f - u) * fBottom.getCtrlPoints()[0].x()
396 + u * fBottom.getCtrlPoints()[3].x()),
397 (1.0f - v) * ((1.0f - u) * fTop.getCtrlPoints()[0].y()
398 + u * fTop.getCtrlPoints()[3].y())
399 + v * ((1.0f - u) * fBottom.getCtrlPoints()[0].y()
400 + u * fBottom.getCtrlPoints()[3].y()));
401 pos[dataIndex] = s0 + s1 - s2;
402
Mike Reed435071e2017-05-23 11:22:56 -0400403 if (cornerColors) {
404 bilerp(u, v, cornerColors[kTopLeft_Corner].to4f(),
405 cornerColors[kTopRight_Corner].to4f(),
406 cornerColors[kBottomLeft_Corner].to4f(),
407 cornerColors[kBottomRight_Corner].to4f()).store(tmpColors[dataIndex].fVec);
408 if (is_opaque) {
409 tmpColors[dataIndex].fVec[3] = 1;
Mike Reed7346a1f2017-05-18 22:23:34 -0400410 }
Mike Reed795c5ea2017-03-17 14:29:05 -0400411 }
412
413 if (texs) {
414 texs[dataIndex] = SkPoint::Make(bilerp(u, v, srcTexCoords[kTopLeft_Corner].x(),
415 srcTexCoords[kTopRight_Corner].x(),
416 srcTexCoords[kBottomLeft_Corner].x(),
417 srcTexCoords[kBottomRight_Corner].x()),
418 bilerp(u, v, srcTexCoords[kTopLeft_Corner].y(),
419 srcTexCoords[kTopRight_Corner].y(),
420 srcTexCoords[kBottomLeft_Corner].y(),
421 srcTexCoords[kBottomRight_Corner].y()));
422
423 }
424
425 if(x < lodX && y < lodY) {
426 int i = 6 * (x * lodY + y);
427 indices[i] = x * stride + y;
428 indices[i + 1] = x * stride + 1 + y;
429 indices[i + 2] = (x + 1) * stride + 1 + y;
430 indices[i + 3] = indices[i];
431 indices[i + 4] = indices[i + 2];
432 indices[i + 5] = (x + 1) * stride + y;
433 }
434 v = SkScalarClampMax(v + 1.f / lodY, 1);
435 }
436 u = SkScalarClampMax(u + 1.f / lodX, 1);
437 }
Mike Reed435071e2017-05-23 11:22:56 -0400438
439 if (tmpColors) {
440 if (doPremul) {
441 unpremul(tmpColors, vertexCount);
442 }
443 linear_to_skcolor(builder.colors(), tmpColors, vertexCount, convertCS.get());
444 }
Mike Reed795c5ea2017-03-17 14:29:05 -0400445 return builder.detach();
446}