blob: 22a964ec606382708c3f5921d6a07e045a9bd6d6 [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"
dandovb3c9d1c2014-08-12 08:34:29 -070013
Mike Reed4ebb43e2017-04-05 11:06:15 -040014namespace {
15 enum CubicCtrlPts {
16 kTopP0_CubicCtrlPts = 0,
17 kTopP1_CubicCtrlPts = 1,
18 kTopP2_CubicCtrlPts = 2,
19 kTopP3_CubicCtrlPts = 3,
20
21 kRightP0_CubicCtrlPts = 3,
22 kRightP1_CubicCtrlPts = 4,
23 kRightP2_CubicCtrlPts = 5,
24 kRightP3_CubicCtrlPts = 6,
25
26 kBottomP0_CubicCtrlPts = 9,
27 kBottomP1_CubicCtrlPts = 8,
28 kBottomP2_CubicCtrlPts = 7,
29 kBottomP3_CubicCtrlPts = 6,
30
31 kLeftP0_CubicCtrlPts = 0,
32 kLeftP1_CubicCtrlPts = 11,
33 kLeftP2_CubicCtrlPts = 10,
34 kLeftP3_CubicCtrlPts = 9,
35 };
36
37 // Enum for corner also clockwise.
38 enum Corner {
39 kTopLeft_Corner = 0,
40 kTopRight_Corner,
41 kBottomRight_Corner,
42 kBottomLeft_Corner
43 };
44}
45
dandovb3c9d1c2014-08-12 08:34:29 -070046/**
47 * Evaluator to sample the values of a cubic bezier using forward differences.
48 * Forward differences is a method for evaluating a nth degree polynomial at a uniform step by only
49 * adding precalculated values.
50 * For a linear example we have the function f(t) = m*t+b, then the value of that function at t+h
51 * would be f(t+h) = m*(t+h)+b. If we want to know the uniform step that we must add to the first
52 * evaluation f(t) then we need to substract f(t+h) - f(t) = m*t + m*h + b - m*t + b = mh. After
53 * obtaining this value (mh) we could just add this constant step to our first sampled point
54 * to compute the next one.
55 *
56 * For the cubic case the first difference gives as a result a quadratic polynomial to which we can
57 * apply again forward differences and get linear function to which we can apply again forward
58 * differences to get a constant difference. This is why we keep an array of size 4, the 0th
59 * position keeps the sampled value while the next ones keep the quadratic, linear and constant
60 * difference values.
61 */
62
63class FwDCubicEvaluator {
halcanary9d524f22016-03-29 09:03:52 -070064
dandovb3c9d1c2014-08-12 08:34:29 -070065public:
halcanary9d524f22016-03-29 09:03:52 -070066
dandovb3c9d1c2014-08-12 08:34:29 -070067 /**
68 * Receives the 4 control points of the cubic bezier.
69 */
halcanary9d524f22016-03-29 09:03:52 -070070
caryclark5ba2b962016-01-26 17:02:30 -080071 explicit FwDCubicEvaluator(const SkPoint points[4])
72 : fCoefs(points) {
dandovb3c9d1c2014-08-12 08:34:29 -070073 memcpy(fPoints, points, 4 * sizeof(SkPoint));
halcanary9d524f22016-03-29 09:03:52 -070074
dandovb3c9d1c2014-08-12 08:34:29 -070075 this->restart(1);
76 }
halcanary9d524f22016-03-29 09:03:52 -070077
dandovb3c9d1c2014-08-12 08:34:29 -070078 /**
79 * Restarts the forward differences evaluator to the first value of t = 0.
80 */
81 void restart(int divisions) {
82 fDivisions = divisions;
dandovb3c9d1c2014-08-12 08:34:29 -070083 fCurrent = 0;
84 fMax = fDivisions + 1;
caryclark5ba2b962016-01-26 17:02:30 -080085 Sk2s h = Sk2s(1.f / fDivisions);
86 Sk2s h2 = h * h;
87 Sk2s h3 = h2 * h;
88 Sk2s fwDiff3 = Sk2s(6) * fCoefs.fA * h3;
89 fFwDiff[3] = to_point(fwDiff3);
90 fFwDiff[2] = to_point(fwDiff3 + times_2(fCoefs.fB) * h2);
91 fFwDiff[1] = to_point(fCoefs.fA * h3 + fCoefs.fB * h2 + fCoefs.fC * h);
92 fFwDiff[0] = to_point(fCoefs.fD);
dandovb3c9d1c2014-08-12 08:34:29 -070093 }
halcanary9d524f22016-03-29 09:03:52 -070094
dandovb3c9d1c2014-08-12 08:34:29 -070095 /**
96 * Check if the evaluator is still within the range of 0<=t<=1
97 */
98 bool done() const {
99 return fCurrent > fMax;
100 }
halcanary9d524f22016-03-29 09:03:52 -0700101
dandovb3c9d1c2014-08-12 08:34:29 -0700102 /**
103 * Call next to obtain the SkPoint sampled and move to the next one.
104 */
105 SkPoint next() {
106 SkPoint point = fFwDiff[0];
107 fFwDiff[0] += fFwDiff[1];
108 fFwDiff[1] += fFwDiff[2];
109 fFwDiff[2] += fFwDiff[3];
110 fCurrent++;
111 return point;
112 }
halcanary9d524f22016-03-29 09:03:52 -0700113
dandovb3c9d1c2014-08-12 08:34:29 -0700114 const SkPoint* getCtrlPoints() const {
115 return fPoints;
116 }
halcanary9d524f22016-03-29 09:03:52 -0700117
dandovb3c9d1c2014-08-12 08:34:29 -0700118private:
caryclark5ba2b962016-01-26 17:02:30 -0800119 SkCubicCoeff fCoefs;
dandovb3c9d1c2014-08-12 08:34:29 -0700120 int fMax, fCurrent, fDivisions;
caryclark5ba2b962016-01-26 17:02:30 -0800121 SkPoint fFwDiff[4], fPoints[4];
dandovb3c9d1c2014-08-12 08:34:29 -0700122};
123
124////////////////////////////////////////////////////////////////////////////////
125
dandovecfff212014-08-04 10:02:00 -0700126// size in pixels of each partition per axis, adjust this knob
dandovb3c9d1c2014-08-12 08:34:29 -0700127static const int kPartitionSize = 10;
dandovecfff212014-08-04 10:02:00 -0700128
129/**
Mike Reedf4f06ad2018-05-02 15:11:42 -0400130 * Calculate the approximate arc length given a bezier curve's control points.
131 * Returns -1 if bad calc (i.e. non-finite)
dandovecfff212014-08-04 10:02:00 -0700132 */
Mike Reedf4f06ad2018-05-02 15:11:42 -0400133static SkScalar approx_arc_length(const SkPoint points[], int count) {
dandovecfff212014-08-04 10:02:00 -0700134 if (count < 2) {
135 return 0;
136 }
137 SkScalar arcLength = 0;
138 for (int i = 0; i < count - 1; i++) {
139 arcLength += SkPoint::Distance(points[i], points[i + 1]);
140 }
Mike Reedf4f06ad2018-05-02 15:11:42 -0400141 return SkScalarIsFinite(arcLength) ? arcLength : -1;
dandovecfff212014-08-04 10:02:00 -0700142}
143
dandovb3c9d1c2014-08-12 08:34:29 -0700144static SkScalar bilerp(SkScalar tx, SkScalar ty, SkScalar c00, SkScalar c10, SkScalar c01,
Mike Reed435071e2017-05-23 11:22:56 -0400145 SkScalar c11) {
dandovb3c9d1c2014-08-12 08:34:29 -0700146 SkScalar a = c00 * (1.f - tx) + c10 * tx;
147 SkScalar b = c01 * (1.f - tx) + c11 * tx;
148 return a * (1.f - ty) + b * ty;
149}
150
Mike Reed435071e2017-05-23 11:22:56 -0400151static Sk4f bilerp(SkScalar tx, SkScalar ty,
152 const Sk4f& c00, const Sk4f& c10, const Sk4f& c01, const Sk4f& c11) {
153 Sk4f a = c00 * (1.f - tx) + c10 * tx;
154 Sk4f b = c01 * (1.f - tx) + c11 * tx;
155 return a * (1.f - ty) + b * ty;
156}
157
dandovb3c9d1c2014-08-12 08:34:29 -0700158SkISize SkPatchUtils::GetLevelOfDetail(const SkPoint cubics[12], const SkMatrix* matrix) {
dandovecfff212014-08-04 10:02:00 -0700159 // Approximate length of each cubic.
dandovb3c9d1c2014-08-12 08:34:29 -0700160 SkPoint pts[kNumPtsCubic];
Mike Reed4ebb43e2017-04-05 11:06:15 -0400161 SkPatchUtils::GetTopCubic(cubics, pts);
dandovb3c9d1c2014-08-12 08:34:29 -0700162 matrix->mapPoints(pts, kNumPtsCubic);
163 SkScalar topLength = approx_arc_length(pts, kNumPtsCubic);
halcanary9d524f22016-03-29 09:03:52 -0700164
Mike Reed4ebb43e2017-04-05 11:06:15 -0400165 SkPatchUtils::GetBottomCubic(cubics, pts);
dandovb3c9d1c2014-08-12 08:34:29 -0700166 matrix->mapPoints(pts, kNumPtsCubic);
167 SkScalar bottomLength = approx_arc_length(pts, kNumPtsCubic);
halcanary9d524f22016-03-29 09:03:52 -0700168
Mike Reed4ebb43e2017-04-05 11:06:15 -0400169 SkPatchUtils::GetLeftCubic(cubics, pts);
dandovb3c9d1c2014-08-12 08:34:29 -0700170 matrix->mapPoints(pts, kNumPtsCubic);
171 SkScalar leftLength = approx_arc_length(pts, kNumPtsCubic);
halcanary9d524f22016-03-29 09:03:52 -0700172
Mike Reed4ebb43e2017-04-05 11:06:15 -0400173 SkPatchUtils::GetRightCubic(cubics, pts);
dandovb3c9d1c2014-08-12 08:34:29 -0700174 matrix->mapPoints(pts, kNumPtsCubic);
175 SkScalar rightLength = approx_arc_length(pts, kNumPtsCubic);
halcanary9d524f22016-03-29 09:03:52 -0700176
Mike Reedf4f06ad2018-05-02 15:11:42 -0400177 if (topLength < 0 || bottomLength < 0 || leftLength < 0 || rightLength < 0) {
178 return {0, 0}; // negative length is a sentinel for bad length (i.e. non-finite)
179 }
180
dandovecfff212014-08-04 10:02:00 -0700181 // Level of detail per axis, based on the larger side between top and bottom or left and right
182 int lodX = static_cast<int>(SkMaxScalar(topLength, bottomLength) / kPartitionSize);
183 int lodY = static_cast<int>(SkMaxScalar(leftLength, rightLength) / kPartitionSize);
halcanary9d524f22016-03-29 09:03:52 -0700184
dandovb3c9d1c2014-08-12 08:34:29 -0700185 return SkISize::Make(SkMax32(8, lodX), SkMax32(8, lodY));
186}
187
Mike Reed4ebb43e2017-04-05 11:06:15 -0400188void SkPatchUtils::GetTopCubic(const SkPoint cubics[12], SkPoint points[4]) {
dandovb3c9d1c2014-08-12 08:34:29 -0700189 points[0] = cubics[kTopP0_CubicCtrlPts];
190 points[1] = cubics[kTopP1_CubicCtrlPts];
191 points[2] = cubics[kTopP2_CubicCtrlPts];
192 points[3] = cubics[kTopP3_CubicCtrlPts];
193}
194
Mike Reed4ebb43e2017-04-05 11:06:15 -0400195void SkPatchUtils::GetBottomCubic(const SkPoint cubics[12], SkPoint points[4]) {
dandovb3c9d1c2014-08-12 08:34:29 -0700196 points[0] = cubics[kBottomP0_CubicCtrlPts];
197 points[1] = cubics[kBottomP1_CubicCtrlPts];
198 points[2] = cubics[kBottomP2_CubicCtrlPts];
199 points[3] = cubics[kBottomP3_CubicCtrlPts];
200}
201
Mike Reed4ebb43e2017-04-05 11:06:15 -0400202void SkPatchUtils::GetLeftCubic(const SkPoint cubics[12], SkPoint points[4]) {
dandovb3c9d1c2014-08-12 08:34:29 -0700203 points[0] = cubics[kLeftP0_CubicCtrlPts];
204 points[1] = cubics[kLeftP1_CubicCtrlPts];
205 points[2] = cubics[kLeftP2_CubicCtrlPts];
206 points[3] = cubics[kLeftP3_CubicCtrlPts];
207}
208
Mike Reed4ebb43e2017-04-05 11:06:15 -0400209void SkPatchUtils::GetRightCubic(const SkPoint cubics[12], SkPoint points[4]) {
dandovb3c9d1c2014-08-12 08:34:29 -0700210 points[0] = cubics[kRightP0_CubicCtrlPts];
211 points[1] = cubics[kRightP1_CubicCtrlPts];
212 points[2] = cubics[kRightP2_CubicCtrlPts];
213 points[3] = cubics[kRightP3_CubicCtrlPts];
214}
215
Mike Reed435071e2017-05-23 11:22:56 -0400216#include "SkPM4fPriv.h"
Mike Reed435071e2017-05-23 11:22:56 -0400217#include "SkColorSpaceXform.h"
218
219struct SkRGBAf {
220 float fVec[4];
221
222 static SkRGBAf From4f(const Sk4f& x) {
223 SkRGBAf c;
224 x.store(c.fVec);
225 return c;
226 }
227
228 static SkRGBAf FromBGRA32(SkColor c) {
229 return From4f(swizzle_rb(SkNx_cast<float>(Sk4b::Load(&c)) * (1/255.0f)));
230 }
231
232 Sk4f to4f() const {
233 return Sk4f::Load(fVec);
234 }
235
236 SkColor toBGRA32() const {
237 SkColor color;
238 SkNx_cast<uint8_t>(swizzle_rb(this->to4f()) * Sk4f(255) + Sk4f(0.5f)).store(&color);
239 return color;
240 }
241
242 SkRGBAf premul() const {
243 float a = fVec[3];
244 return From4f(this->to4f() * Sk4f(a, a, a, 1));
245 }
246
247 SkRGBAf unpremul() const {
248 float a = fVec[3];
249 float inv = a ? 1/a : 0;
250 return From4f(this->to4f() * Sk4f(inv, inv, inv, 1));
251 }
252};
253
254static void skcolor_to_linear(SkRGBAf dst[], const SkColor src[], int count, SkColorSpace* cs,
255 bool doPremul) {
256 if (cs) {
257 auto srcCS = SkColorSpace::MakeSRGB();
Brian Osman36703d92017-12-12 14:09:31 -0500258 auto dstCS = cs->makeLinearGamma();
Mike Reed435071e2017-05-23 11:22:56 -0400259 auto op = doPremul ? SkColorSpaceXform::kPremul_AlphaOp
260 : SkColorSpaceXform::kPreserve_AlphaOp;
261 SkColorSpaceXform::Apply(dstCS.get(), SkColorSpaceXform::kRGBA_F32_ColorFormat, dst,
262 srcCS.get(), SkColorSpaceXform::kBGRA_8888_ColorFormat, src,
263 count, op);
264 } else {
265 for (int i = 0; i < count; ++i) {
266 dst[i] = SkRGBAf::FromBGRA32(src[i]);
267 if (doPremul) {
268 dst[i] = dst[i].premul();
269 }
270 }
271 }
272}
273
274static void linear_to_skcolor(SkColor dst[], const SkRGBAf src[], int count, SkColorSpace* cs) {
275 if (cs) {
Brian Osman36703d92017-12-12 14:09:31 -0500276 auto srcCS = cs->makeLinearGamma();
Mike Reed435071e2017-05-23 11:22:56 -0400277 auto dstCS = SkColorSpace::MakeSRGB();
278 SkColorSpaceXform::Apply(dstCS.get(), SkColorSpaceXform::kBGRA_8888_ColorFormat, dst,
279 srcCS.get(), SkColorSpaceXform::kRGBA_F32_ColorFormat, src,
280 count, SkColorSpaceXform::kPreserve_AlphaOp);
281 } else {
282 for (int i = 0; i < count; ++i) {
283 dst[i] = src[i].toBGRA32();
284 }
285 }
286}
287
288static void unpremul(SkRGBAf array[], int count) {
289 for (int i = 0; i < count; ++i) {
290 array[i] = array[i].unpremul();
291 }
292}
293
Mike Reed795c5ea2017-03-17 14:29:05 -0400294sk_sp<SkVertices> SkPatchUtils::MakeVertices(const SkPoint cubics[12], const SkColor srcColors[4],
Mike Reed435071e2017-05-23 11:22:56 -0400295 const SkPoint srcTexCoords[4], int lodX, int lodY,
296 bool interpColorsLinearly) {
Mike Reed795c5ea2017-03-17 14:29:05 -0400297 if (lodX < 1 || lodY < 1 || nullptr == cubics) {
298 return nullptr;
299 }
300
301 // check for overflow in multiplication
302 const int64_t lodX64 = (lodX + 1),
303 lodY64 = (lodY + 1),
304 mult64 = lodX64 * lodY64;
305 if (mult64 > SK_MaxS32) {
306 return nullptr;
307 }
308
309 int vertexCount = SkToS32(mult64);
310 // it is recommended to generate draw calls of no more than 65536 indices, so we never generate
311 // more than 60000 indices. To accomplish that we resize the LOD and vertex count
312 if (vertexCount > 10000 || lodX > 200 || lodY > 200) {
313 float weightX = static_cast<float>(lodX) / (lodX + lodY);
314 float weightY = static_cast<float>(lodY) / (lodX + lodY);
315
316 // 200 comes from the 100 * 2 which is the max value of vertices because of the limit of
317 // 60000 indices ( sqrt(60000 / 6) that comes from data->fIndexCount = lodX * lodY * 6)
318 lodX = static_cast<int>(weightX * 200);
319 lodY = static_cast<int>(weightY * 200);
320 vertexCount = (lodX + 1) * (lodY + 1);
321 }
322 const int indexCount = lodX * lodY * 6;
323 uint32_t flags = 0;
324 if (srcTexCoords) {
325 flags |= SkVertices::kHasTexCoords_BuilderFlag;
326 }
327 if (srcColors) {
328 flags |= SkVertices::kHasColors_BuilderFlag;
329 }
330
Florin Malita14a64302017-05-24 14:53:44 -0400331 SkSTArenaAlloc<2048> alloc;
Mike Reed435071e2017-05-23 11:22:56 -0400332 SkRGBAf* cornerColors = srcColors ? alloc.makeArray<SkRGBAf>(4) : nullptr;
333 SkRGBAf* tmpColors = srcColors ? alloc.makeArray<SkRGBAf>(vertexCount) : nullptr;
334 auto convertCS = interpColorsLinearly ? SkColorSpace::MakeSRGB() : nullptr;
335
Mike Reed887cdf12017-04-03 11:11:09 -0400336 SkVertices::Builder builder(SkVertices::kTriangles_VertexMode, vertexCount, indexCount, flags);
Mike Reed795c5ea2017-03-17 14:29:05 -0400337 SkPoint* pos = builder.positions();
338 SkPoint* texs = builder.texCoords();
Mike Reed795c5ea2017-03-17 14:29:05 -0400339 uint16_t* indices = builder.indices();
Mike Reed7346a1f2017-05-18 22:23:34 -0400340 bool is_opaque = false;
Mike Reed795c5ea2017-03-17 14:29:05 -0400341
Mike Reed435071e2017-05-23 11:22:56 -0400342 /*
343 * 1. Should we offer this as a runtime choice, as we do in gradients?
344 * 2. Since drawing the vertices wants premul, shoudl we extend SkVertices to store
345 * premul colors (as floats, w/ a colorspace)?
346 */
347 bool doPremul = true;
348 if (cornerColors) {
Mike Reed7346a1f2017-05-18 22:23:34 -0400349 SkColor c = ~0;
Mike Reed795c5ea2017-03-17 14:29:05 -0400350 for (int i = 0; i < kNumCorners; i++) {
Mike Reed7346a1f2017-05-18 22:23:34 -0400351 c &= srcColors[i];
Mike Reed795c5ea2017-03-17 14:29:05 -0400352 }
Mike Reed7346a1f2017-05-18 22:23:34 -0400353 is_opaque = (SkColorGetA(c) == 0xFF);
Mike Reed435071e2017-05-23 11:22:56 -0400354 if (is_opaque) {
355 doPremul = false; // no need
356 }
357
358 skcolor_to_linear(cornerColors, srcColors, kNumCorners, convertCS.get(), doPremul);
Mike Reed795c5ea2017-03-17 14:29:05 -0400359 }
360
361 SkPoint pts[kNumPtsCubic];
Mike Reed4ebb43e2017-04-05 11:06:15 -0400362 SkPatchUtils::GetBottomCubic(cubics, pts);
Mike Reed795c5ea2017-03-17 14:29:05 -0400363 FwDCubicEvaluator fBottom(pts);
Mike Reed4ebb43e2017-04-05 11:06:15 -0400364 SkPatchUtils::GetTopCubic(cubics, pts);
Mike Reed795c5ea2017-03-17 14:29:05 -0400365 FwDCubicEvaluator fTop(pts);
Mike Reed4ebb43e2017-04-05 11:06:15 -0400366 SkPatchUtils::GetLeftCubic(cubics, pts);
Mike Reed795c5ea2017-03-17 14:29:05 -0400367 FwDCubicEvaluator fLeft(pts);
Mike Reed4ebb43e2017-04-05 11:06:15 -0400368 SkPatchUtils::GetRightCubic(cubics, pts);
Mike Reed795c5ea2017-03-17 14:29:05 -0400369 FwDCubicEvaluator fRight(pts);
370
371 fBottom.restart(lodX);
372 fTop.restart(lodX);
373
374 SkScalar u = 0.0f;
375 int stride = lodY + 1;
376 for (int x = 0; x <= lodX; x++) {
377 SkPoint bottom = fBottom.next(), top = fTop.next();
378 fLeft.restart(lodY);
379 fRight.restart(lodY);
380 SkScalar v = 0.f;
381 for (int y = 0; y <= lodY; y++) {
382 int dataIndex = x * (lodY + 1) + y;
383
384 SkPoint left = fLeft.next(), right = fRight.next();
385
386 SkPoint s0 = SkPoint::Make((1.0f - v) * top.x() + v * bottom.x(),
387 (1.0f - v) * top.y() + v * bottom.y());
388 SkPoint s1 = SkPoint::Make((1.0f - u) * left.x() + u * right.x(),
389 (1.0f - u) * left.y() + u * right.y());
390 SkPoint s2 = SkPoint::Make(
391 (1.0f - v) * ((1.0f - u) * fTop.getCtrlPoints()[0].x()
392 + u * fTop.getCtrlPoints()[3].x())
393 + v * ((1.0f - u) * fBottom.getCtrlPoints()[0].x()
394 + u * fBottom.getCtrlPoints()[3].x()),
395 (1.0f - v) * ((1.0f - u) * fTop.getCtrlPoints()[0].y()
396 + u * fTop.getCtrlPoints()[3].y())
397 + v * ((1.0f - u) * fBottom.getCtrlPoints()[0].y()
398 + u * fBottom.getCtrlPoints()[3].y()));
399 pos[dataIndex] = s0 + s1 - s2;
400
Mike Reed435071e2017-05-23 11:22:56 -0400401 if (cornerColors) {
402 bilerp(u, v, cornerColors[kTopLeft_Corner].to4f(),
403 cornerColors[kTopRight_Corner].to4f(),
404 cornerColors[kBottomLeft_Corner].to4f(),
405 cornerColors[kBottomRight_Corner].to4f()).store(tmpColors[dataIndex].fVec);
406 if (is_opaque) {
407 tmpColors[dataIndex].fVec[3] = 1;
Mike Reed7346a1f2017-05-18 22:23:34 -0400408 }
Mike Reed795c5ea2017-03-17 14:29:05 -0400409 }
410
411 if (texs) {
412 texs[dataIndex] = SkPoint::Make(bilerp(u, v, srcTexCoords[kTopLeft_Corner].x(),
413 srcTexCoords[kTopRight_Corner].x(),
414 srcTexCoords[kBottomLeft_Corner].x(),
415 srcTexCoords[kBottomRight_Corner].x()),
416 bilerp(u, v, srcTexCoords[kTopLeft_Corner].y(),
417 srcTexCoords[kTopRight_Corner].y(),
418 srcTexCoords[kBottomLeft_Corner].y(),
419 srcTexCoords[kBottomRight_Corner].y()));
420
421 }
422
423 if(x < lodX && y < lodY) {
424 int i = 6 * (x * lodY + y);
425 indices[i] = x * stride + y;
426 indices[i + 1] = x * stride + 1 + y;
427 indices[i + 2] = (x + 1) * stride + 1 + y;
428 indices[i + 3] = indices[i];
429 indices[i + 4] = indices[i + 2];
430 indices[i + 5] = (x + 1) * stride + y;
431 }
432 v = SkScalarClampMax(v + 1.f / lodY, 1);
433 }
434 u = SkScalarClampMax(u + 1.f / lodX, 1);
435 }
Mike Reed435071e2017-05-23 11:22:56 -0400436
437 if (tmpColors) {
438 if (doPremul) {
439 unpremul(tmpColors, vertexCount);
440 }
441 linear_to_skcolor(builder.colors(), tmpColors, vertexCount, convertCS.get());
442 }
Mike Reed795c5ea2017-03-17 14:29:05 -0400443 return builder.detach();
444}