blob: f3e3b768bafb58fe7f30ef5ae183c5b9c5dc9f83 [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
Mike Kleina85838c2018-09-20 14:35:34 -040010#include "SkArenaAlloc.h"
Cary Clarka4083c92017-09-15 11:59:23 -040011#include "SkColorData.h"
Mike Kleine28a6b52018-07-25 13:05:17 -040012#include "SkColorSpacePriv.h"
dandovb3c9d1c2014-08-12 08:34:29 -070013#include "SkGeometry.h"
Hal Canaryc640d0d2018-06-13 09:59:02 -040014#include "SkTo.h"
dandovb3c9d1c2014-08-12 08:34:29 -070015
Mike Reed4ebb43e2017-04-05 11:06:15 -040016namespace {
17 enum CubicCtrlPts {
18 kTopP0_CubicCtrlPts = 0,
19 kTopP1_CubicCtrlPts = 1,
20 kTopP2_CubicCtrlPts = 2,
21 kTopP3_CubicCtrlPts = 3,
22
23 kRightP0_CubicCtrlPts = 3,
24 kRightP1_CubicCtrlPts = 4,
25 kRightP2_CubicCtrlPts = 5,
26 kRightP3_CubicCtrlPts = 6,
27
28 kBottomP0_CubicCtrlPts = 9,
29 kBottomP1_CubicCtrlPts = 8,
30 kBottomP2_CubicCtrlPts = 7,
31 kBottomP3_CubicCtrlPts = 6,
32
33 kLeftP0_CubicCtrlPts = 0,
34 kLeftP1_CubicCtrlPts = 11,
35 kLeftP2_CubicCtrlPts = 10,
36 kLeftP3_CubicCtrlPts = 9,
37 };
38
39 // Enum for corner also clockwise.
40 enum Corner {
41 kTopLeft_Corner = 0,
42 kTopRight_Corner,
43 kBottomRight_Corner,
44 kBottomLeft_Corner
45 };
46}
47
dandovb3c9d1c2014-08-12 08:34:29 -070048/**
49 * Evaluator to sample the values of a cubic bezier using forward differences.
50 * Forward differences is a method for evaluating a nth degree polynomial at a uniform step by only
51 * adding precalculated values.
52 * For a linear example we have the function f(t) = m*t+b, then the value of that function at t+h
53 * would be f(t+h) = m*(t+h)+b. If we want to know the uniform step that we must add to the first
54 * evaluation f(t) then we need to substract f(t+h) - f(t) = m*t + m*h + b - m*t + b = mh. After
55 * obtaining this value (mh) we could just add this constant step to our first sampled point
56 * to compute the next one.
57 *
58 * For the cubic case the first difference gives as a result a quadratic polynomial to which we can
59 * apply again forward differences and get linear function to which we can apply again forward
60 * differences to get a constant difference. This is why we keep an array of size 4, the 0th
61 * position keeps the sampled value while the next ones keep the quadratic, linear and constant
62 * difference values.
63 */
64
65class FwDCubicEvaluator {
halcanary9d524f22016-03-29 09:03:52 -070066
dandovb3c9d1c2014-08-12 08:34:29 -070067public:
halcanary9d524f22016-03-29 09:03:52 -070068
dandovb3c9d1c2014-08-12 08:34:29 -070069 /**
70 * Receives the 4 control points of the cubic bezier.
71 */
halcanary9d524f22016-03-29 09:03:52 -070072
caryclark5ba2b962016-01-26 17:02:30 -080073 explicit FwDCubicEvaluator(const SkPoint points[4])
74 : fCoefs(points) {
dandovb3c9d1c2014-08-12 08:34:29 -070075 memcpy(fPoints, points, 4 * sizeof(SkPoint));
halcanary9d524f22016-03-29 09:03:52 -070076
dandovb3c9d1c2014-08-12 08:34:29 -070077 this->restart(1);
78 }
halcanary9d524f22016-03-29 09:03:52 -070079
dandovb3c9d1c2014-08-12 08:34:29 -070080 /**
81 * Restarts the forward differences evaluator to the first value of t = 0.
82 */
83 void restart(int divisions) {
84 fDivisions = divisions;
dandovb3c9d1c2014-08-12 08:34:29 -070085 fCurrent = 0;
86 fMax = fDivisions + 1;
caryclark5ba2b962016-01-26 17:02:30 -080087 Sk2s h = Sk2s(1.f / fDivisions);
88 Sk2s h2 = h * h;
89 Sk2s h3 = h2 * h;
90 Sk2s fwDiff3 = Sk2s(6) * fCoefs.fA * h3;
91 fFwDiff[3] = to_point(fwDiff3);
92 fFwDiff[2] = to_point(fwDiff3 + times_2(fCoefs.fB) * h2);
93 fFwDiff[1] = to_point(fCoefs.fA * h3 + fCoefs.fB * h2 + fCoefs.fC * h);
94 fFwDiff[0] = to_point(fCoefs.fD);
dandovb3c9d1c2014-08-12 08:34:29 -070095 }
halcanary9d524f22016-03-29 09:03:52 -070096
dandovb3c9d1c2014-08-12 08:34:29 -070097 /**
98 * Check if the evaluator is still within the range of 0<=t<=1
99 */
100 bool done() const {
101 return fCurrent > fMax;
102 }
halcanary9d524f22016-03-29 09:03:52 -0700103
dandovb3c9d1c2014-08-12 08:34:29 -0700104 /**
105 * Call next to obtain the SkPoint sampled and move to the next one.
106 */
107 SkPoint next() {
108 SkPoint point = fFwDiff[0];
109 fFwDiff[0] += fFwDiff[1];
110 fFwDiff[1] += fFwDiff[2];
111 fFwDiff[2] += fFwDiff[3];
112 fCurrent++;
113 return point;
114 }
halcanary9d524f22016-03-29 09:03:52 -0700115
dandovb3c9d1c2014-08-12 08:34:29 -0700116 const SkPoint* getCtrlPoints() const {
117 return fPoints;
118 }
halcanary9d524f22016-03-29 09:03:52 -0700119
dandovb3c9d1c2014-08-12 08:34:29 -0700120private:
caryclark5ba2b962016-01-26 17:02:30 -0800121 SkCubicCoeff fCoefs;
dandovb3c9d1c2014-08-12 08:34:29 -0700122 int fMax, fCurrent, fDivisions;
caryclark5ba2b962016-01-26 17:02:30 -0800123 SkPoint fFwDiff[4], fPoints[4];
dandovb3c9d1c2014-08-12 08:34:29 -0700124};
125
126////////////////////////////////////////////////////////////////////////////////
127
dandovecfff212014-08-04 10:02:00 -0700128// size in pixels of each partition per axis, adjust this knob
dandovb3c9d1c2014-08-12 08:34:29 -0700129static const int kPartitionSize = 10;
dandovecfff212014-08-04 10:02:00 -0700130
131/**
Mike Reedf4f06ad2018-05-02 15:11:42 -0400132 * Calculate the approximate arc length given a bezier curve's control points.
133 * Returns -1 if bad calc (i.e. non-finite)
dandovecfff212014-08-04 10:02:00 -0700134 */
Mike Reedf4f06ad2018-05-02 15:11:42 -0400135static SkScalar approx_arc_length(const SkPoint points[], int count) {
dandovecfff212014-08-04 10:02:00 -0700136 if (count < 2) {
137 return 0;
138 }
139 SkScalar arcLength = 0;
140 for (int i = 0; i < count - 1; i++) {
141 arcLength += SkPoint::Distance(points[i], points[i + 1]);
142 }
Mike Reedf4f06ad2018-05-02 15:11:42 -0400143 return SkScalarIsFinite(arcLength) ? arcLength : -1;
dandovecfff212014-08-04 10:02:00 -0700144}
145
dandovb3c9d1c2014-08-12 08:34:29 -0700146static SkScalar bilerp(SkScalar tx, SkScalar ty, SkScalar c00, SkScalar c10, SkScalar c01,
Mike Reed435071e2017-05-23 11:22:56 -0400147 SkScalar c11) {
dandovb3c9d1c2014-08-12 08:34:29 -0700148 SkScalar a = c00 * (1.f - tx) + c10 * tx;
149 SkScalar b = c01 * (1.f - tx) + c11 * tx;
150 return a * (1.f - ty) + b * ty;
151}
152
Mike Reed435071e2017-05-23 11:22:56 -0400153static Sk4f bilerp(SkScalar tx, SkScalar ty,
154 const Sk4f& c00, const Sk4f& c10, const Sk4f& c01, const Sk4f& c11) {
155 Sk4f a = c00 * (1.f - tx) + c10 * tx;
156 Sk4f b = c01 * (1.f - tx) + c11 * tx;
157 return a * (1.f - ty) + b * ty;
158}
159
dandovb3c9d1c2014-08-12 08:34:29 -0700160SkISize SkPatchUtils::GetLevelOfDetail(const SkPoint cubics[12], const SkMatrix* matrix) {
dandovecfff212014-08-04 10:02:00 -0700161 // Approximate length of each cubic.
dandovb3c9d1c2014-08-12 08:34:29 -0700162 SkPoint pts[kNumPtsCubic];
Mike Reed4ebb43e2017-04-05 11:06:15 -0400163 SkPatchUtils::GetTopCubic(cubics, pts);
dandovb3c9d1c2014-08-12 08:34:29 -0700164 matrix->mapPoints(pts, kNumPtsCubic);
165 SkScalar topLength = approx_arc_length(pts, kNumPtsCubic);
halcanary9d524f22016-03-29 09:03:52 -0700166
Mike Reed4ebb43e2017-04-05 11:06:15 -0400167 SkPatchUtils::GetBottomCubic(cubics, pts);
dandovb3c9d1c2014-08-12 08:34:29 -0700168 matrix->mapPoints(pts, kNumPtsCubic);
169 SkScalar bottomLength = approx_arc_length(pts, kNumPtsCubic);
halcanary9d524f22016-03-29 09:03:52 -0700170
Mike Reed4ebb43e2017-04-05 11:06:15 -0400171 SkPatchUtils::GetLeftCubic(cubics, pts);
dandovb3c9d1c2014-08-12 08:34:29 -0700172 matrix->mapPoints(pts, kNumPtsCubic);
173 SkScalar leftLength = approx_arc_length(pts, kNumPtsCubic);
halcanary9d524f22016-03-29 09:03:52 -0700174
Mike Reed4ebb43e2017-04-05 11:06:15 -0400175 SkPatchUtils::GetRightCubic(cubics, pts);
dandovb3c9d1c2014-08-12 08:34:29 -0700176 matrix->mapPoints(pts, kNumPtsCubic);
177 SkScalar rightLength = approx_arc_length(pts, kNumPtsCubic);
halcanary9d524f22016-03-29 09:03:52 -0700178
Mike Reedf4f06ad2018-05-02 15:11:42 -0400179 if (topLength < 0 || bottomLength < 0 || leftLength < 0 || rightLength < 0) {
180 return {0, 0}; // negative length is a sentinel for bad length (i.e. non-finite)
181 }
182
dandovecfff212014-08-04 10:02:00 -0700183 // Level of detail per axis, based on the larger side between top and bottom or left and right
184 int lodX = static_cast<int>(SkMaxScalar(topLength, bottomLength) / kPartitionSize);
185 int lodY = static_cast<int>(SkMaxScalar(leftLength, rightLength) / kPartitionSize);
halcanary9d524f22016-03-29 09:03:52 -0700186
dandovb3c9d1c2014-08-12 08:34:29 -0700187 return SkISize::Make(SkMax32(8, lodX), SkMax32(8, lodY));
188}
189
Mike Reed4ebb43e2017-04-05 11:06:15 -0400190void SkPatchUtils::GetTopCubic(const SkPoint cubics[12], SkPoint points[4]) {
dandovb3c9d1c2014-08-12 08:34:29 -0700191 points[0] = cubics[kTopP0_CubicCtrlPts];
192 points[1] = cubics[kTopP1_CubicCtrlPts];
193 points[2] = cubics[kTopP2_CubicCtrlPts];
194 points[3] = cubics[kTopP3_CubicCtrlPts];
195}
196
Mike Reed4ebb43e2017-04-05 11:06:15 -0400197void SkPatchUtils::GetBottomCubic(const SkPoint cubics[12], SkPoint points[4]) {
dandovb3c9d1c2014-08-12 08:34:29 -0700198 points[0] = cubics[kBottomP0_CubicCtrlPts];
199 points[1] = cubics[kBottomP1_CubicCtrlPts];
200 points[2] = cubics[kBottomP2_CubicCtrlPts];
201 points[3] = cubics[kBottomP3_CubicCtrlPts];
202}
203
Mike Reed4ebb43e2017-04-05 11:06:15 -0400204void SkPatchUtils::GetLeftCubic(const SkPoint cubics[12], SkPoint points[4]) {
dandovb3c9d1c2014-08-12 08:34:29 -0700205 points[0] = cubics[kLeftP0_CubicCtrlPts];
206 points[1] = cubics[kLeftP1_CubicCtrlPts];
207 points[2] = cubics[kLeftP2_CubicCtrlPts];
208 points[3] = cubics[kLeftP3_CubicCtrlPts];
209}
210
Mike Reed4ebb43e2017-04-05 11:06:15 -0400211void SkPatchUtils::GetRightCubic(const SkPoint cubics[12], SkPoint points[4]) {
dandovb3c9d1c2014-08-12 08:34:29 -0700212 points[0] = cubics[kRightP0_CubicCtrlPts];
213 points[1] = cubics[kRightP1_CubicCtrlPts];
214 points[2] = cubics[kRightP2_CubicCtrlPts];
215 points[3] = cubics[kRightP3_CubicCtrlPts];
216}
217
Mike Reed435071e2017-05-23 11:22:56 -0400218#include "SkColorSpaceXform.h"
219
Brian Osman81cbd032018-09-21 11:09:15 -0400220static void skcolor_to_float(SkColor4f dst[], const SkColor src[], int count, SkColorSpace* dstCS,
Brian Osmane0a99622018-07-09 16:12:27 -0400221 bool doPremul) {
Mike Kleine28a6b52018-07-25 13:05:17 -0400222 // Source is always sRGB SkColor.
223 auto srcCS = sk_srgb_singleton();
Brian Osmane0a99622018-07-09 16:12:27 -0400224
225 auto op = doPremul ? SkColorSpaceXform::kPremul_AlphaOp : SkColorSpaceXform::kPreserve_AlphaOp;
226 SkAssertResult(SkColorSpaceXform::Apply(dstCS, SkColorSpaceXform::kRGBA_F32_ColorFormat, dst,
227 srcCS, SkColorSpaceXform::kBGRA_8888_ColorFormat, src,
228 count, op));
Mike Reed435071e2017-05-23 11:22:56 -0400229}
230
Brian Osman81cbd032018-09-21 11:09:15 -0400231static void float_to_skcolor(SkColor dst[], const SkColor4f src[], int count, SkColorSpace* srcCS) {
Mike Kleine28a6b52018-07-25 13:05:17 -0400232 // Destination is always sRGB SkColor.
233 auto dstCS = sk_srgb_singleton();
Brian Osmane0a99622018-07-09 16:12:27 -0400234 SkAssertResult(SkColorSpaceXform::Apply(dstCS, SkColorSpaceXform::kBGRA_8888_ColorFormat, dst,
235 srcCS, SkColorSpaceXform::kRGBA_F32_ColorFormat, src,
236 count, SkColorSpaceXform::kPreserve_AlphaOp));
Mike Reed435071e2017-05-23 11:22:56 -0400237}
238
Brian Osman81cbd032018-09-21 11:09:15 -0400239static void unpremul(SkColor4f array[], int count) {
Mike Reed435071e2017-05-23 11:22:56 -0400240 for (int i = 0; i < count; ++i) {
241 array[i] = array[i].unpremul();
242 }
243}
244
Mike Reed795c5ea2017-03-17 14:29:05 -0400245sk_sp<SkVertices> SkPatchUtils::MakeVertices(const SkPoint cubics[12], const SkColor srcColors[4],
Mike Reed435071e2017-05-23 11:22:56 -0400246 const SkPoint srcTexCoords[4], int lodX, int lodY,
Brian Osmane0a99622018-07-09 16:12:27 -0400247 SkColorSpace* colorSpace) {
Mike Reed795c5ea2017-03-17 14:29:05 -0400248 if (lodX < 1 || lodY < 1 || nullptr == cubics) {
249 return nullptr;
250 }
251
252 // check for overflow in multiplication
253 const int64_t lodX64 = (lodX + 1),
254 lodY64 = (lodY + 1),
255 mult64 = lodX64 * lodY64;
256 if (mult64 > SK_MaxS32) {
257 return nullptr;
258 }
259
Mike Kleine28a6b52018-07-25 13:05:17 -0400260 // Treat null interpolation space as sRGB.
Brian Osmane0a99622018-07-09 16:12:27 -0400261 if (!colorSpace) {
Mike Kleine28a6b52018-07-25 13:05:17 -0400262 colorSpace = sk_srgb_singleton();
Brian Osmane0a99622018-07-09 16:12:27 -0400263 }
264
Mike Reed795c5ea2017-03-17 14:29:05 -0400265 int vertexCount = SkToS32(mult64);
266 // it is recommended to generate draw calls of no more than 65536 indices, so we never generate
267 // more than 60000 indices. To accomplish that we resize the LOD and vertex count
268 if (vertexCount > 10000 || lodX > 200 || lodY > 200) {
269 float weightX = static_cast<float>(lodX) / (lodX + lodY);
270 float weightY = static_cast<float>(lodY) / (lodX + lodY);
271
272 // 200 comes from the 100 * 2 which is the max value of vertices because of the limit of
273 // 60000 indices ( sqrt(60000 / 6) that comes from data->fIndexCount = lodX * lodY * 6)
Mike Reed70bebb02018-05-09 14:07:21 -0400274 // Need a min of 1 since we later divide by lod
275 lodX = std::max(1, sk_float_floor2int_no_saturate(weightX * 200));
276 lodY = std::max(1, sk_float_floor2int_no_saturate(weightY * 200));
Mike Reed795c5ea2017-03-17 14:29:05 -0400277 vertexCount = (lodX + 1) * (lodY + 1);
278 }
279 const int indexCount = lodX * lodY * 6;
280 uint32_t flags = 0;
281 if (srcTexCoords) {
282 flags |= SkVertices::kHasTexCoords_BuilderFlag;
283 }
284 if (srcColors) {
285 flags |= SkVertices::kHasColors_BuilderFlag;
286 }
287
Florin Malita14a64302017-05-24 14:53:44 -0400288 SkSTArenaAlloc<2048> alloc;
Brian Osman81cbd032018-09-21 11:09:15 -0400289 SkColor4f* cornerColors = srcColors ? alloc.makeArray<SkColor4f>(4) : nullptr;
290 SkColor4f* tmpColors = srcColors ? alloc.makeArray<SkColor4f>(vertexCount) : nullptr;
Mike Reed435071e2017-05-23 11:22:56 -0400291
Mike Reed887cdf12017-04-03 11:11:09 -0400292 SkVertices::Builder builder(SkVertices::kTriangles_VertexMode, vertexCount, indexCount, flags);
Mike Reed795c5ea2017-03-17 14:29:05 -0400293 SkPoint* pos = builder.positions();
294 SkPoint* texs = builder.texCoords();
Mike Reed795c5ea2017-03-17 14:29:05 -0400295 uint16_t* indices = builder.indices();
Mike Reed7346a1f2017-05-18 22:23:34 -0400296 bool is_opaque = false;
Mike Reed795c5ea2017-03-17 14:29:05 -0400297
Mike Reed435071e2017-05-23 11:22:56 -0400298 /*
299 * 1. Should we offer this as a runtime choice, as we do in gradients?
300 * 2. Since drawing the vertices wants premul, shoudl we extend SkVertices to store
301 * premul colors (as floats, w/ a colorspace)?
302 */
303 bool doPremul = true;
304 if (cornerColors) {
Mike Reed7346a1f2017-05-18 22:23:34 -0400305 SkColor c = ~0;
Mike Reed795c5ea2017-03-17 14:29:05 -0400306 for (int i = 0; i < kNumCorners; i++) {
Mike Reed7346a1f2017-05-18 22:23:34 -0400307 c &= srcColors[i];
Mike Reed795c5ea2017-03-17 14:29:05 -0400308 }
Mike Reed7346a1f2017-05-18 22:23:34 -0400309 is_opaque = (SkColorGetA(c) == 0xFF);
Mike Reed435071e2017-05-23 11:22:56 -0400310 if (is_opaque) {
311 doPremul = false; // no need
312 }
313
Brian Osmane0a99622018-07-09 16:12:27 -0400314 skcolor_to_float(cornerColors, srcColors, kNumCorners, colorSpace, doPremul);
Mike Reed795c5ea2017-03-17 14:29:05 -0400315 }
316
317 SkPoint pts[kNumPtsCubic];
Mike Reed4ebb43e2017-04-05 11:06:15 -0400318 SkPatchUtils::GetBottomCubic(cubics, pts);
Mike Reed795c5ea2017-03-17 14:29:05 -0400319 FwDCubicEvaluator fBottom(pts);
Mike Reed4ebb43e2017-04-05 11:06:15 -0400320 SkPatchUtils::GetTopCubic(cubics, pts);
Mike Reed795c5ea2017-03-17 14:29:05 -0400321 FwDCubicEvaluator fTop(pts);
Mike Reed4ebb43e2017-04-05 11:06:15 -0400322 SkPatchUtils::GetLeftCubic(cubics, pts);
Mike Reed795c5ea2017-03-17 14:29:05 -0400323 FwDCubicEvaluator fLeft(pts);
Mike Reed4ebb43e2017-04-05 11:06:15 -0400324 SkPatchUtils::GetRightCubic(cubics, pts);
Mike Reed795c5ea2017-03-17 14:29:05 -0400325 FwDCubicEvaluator fRight(pts);
326
327 fBottom.restart(lodX);
328 fTop.restart(lodX);
329
330 SkScalar u = 0.0f;
331 int stride = lodY + 1;
332 for (int x = 0; x <= lodX; x++) {
333 SkPoint bottom = fBottom.next(), top = fTop.next();
334 fLeft.restart(lodY);
335 fRight.restart(lodY);
336 SkScalar v = 0.f;
337 for (int y = 0; y <= lodY; y++) {
338 int dataIndex = x * (lodY + 1) + y;
339
340 SkPoint left = fLeft.next(), right = fRight.next();
341
342 SkPoint s0 = SkPoint::Make((1.0f - v) * top.x() + v * bottom.x(),
343 (1.0f - v) * top.y() + v * bottom.y());
344 SkPoint s1 = SkPoint::Make((1.0f - u) * left.x() + u * right.x(),
345 (1.0f - u) * left.y() + u * right.y());
346 SkPoint s2 = SkPoint::Make(
347 (1.0f - v) * ((1.0f - u) * fTop.getCtrlPoints()[0].x()
348 + u * fTop.getCtrlPoints()[3].x())
349 + v * ((1.0f - u) * fBottom.getCtrlPoints()[0].x()
350 + u * fBottom.getCtrlPoints()[3].x()),
351 (1.0f - v) * ((1.0f - u) * fTop.getCtrlPoints()[0].y()
352 + u * fTop.getCtrlPoints()[3].y())
353 + v * ((1.0f - u) * fBottom.getCtrlPoints()[0].y()
354 + u * fBottom.getCtrlPoints()[3].y()));
355 pos[dataIndex] = s0 + s1 - s2;
356
Mike Reed435071e2017-05-23 11:22:56 -0400357 if (cornerColors) {
Brian Osman81cbd032018-09-21 11:09:15 -0400358 bilerp(u, v, Sk4f::Load(cornerColors[kTopLeft_Corner].vec()),
359 Sk4f::Load(cornerColors[kTopRight_Corner].vec()),
360 Sk4f::Load(cornerColors[kBottomLeft_Corner].vec()),
361 Sk4f::Load(cornerColors[kBottomRight_Corner].vec()))
362 .store(tmpColors[dataIndex].vec());
Mike Reed435071e2017-05-23 11:22:56 -0400363 if (is_opaque) {
Brian Osman81cbd032018-09-21 11:09:15 -0400364 tmpColors[dataIndex].fA = 1;
Mike Reed7346a1f2017-05-18 22:23:34 -0400365 }
Mike Reed795c5ea2017-03-17 14:29:05 -0400366 }
367
368 if (texs) {
369 texs[dataIndex] = SkPoint::Make(bilerp(u, v, srcTexCoords[kTopLeft_Corner].x(),
370 srcTexCoords[kTopRight_Corner].x(),
371 srcTexCoords[kBottomLeft_Corner].x(),
372 srcTexCoords[kBottomRight_Corner].x()),
373 bilerp(u, v, srcTexCoords[kTopLeft_Corner].y(),
374 srcTexCoords[kTopRight_Corner].y(),
375 srcTexCoords[kBottomLeft_Corner].y(),
376 srcTexCoords[kBottomRight_Corner].y()));
377
378 }
379
380 if(x < lodX && y < lodY) {
381 int i = 6 * (x * lodY + y);
382 indices[i] = x * stride + y;
383 indices[i + 1] = x * stride + 1 + y;
384 indices[i + 2] = (x + 1) * stride + 1 + y;
385 indices[i + 3] = indices[i];
386 indices[i + 4] = indices[i + 2];
387 indices[i + 5] = (x + 1) * stride + y;
388 }
389 v = SkScalarClampMax(v + 1.f / lodY, 1);
390 }
391 u = SkScalarClampMax(u + 1.f / lodX, 1);
392 }
Mike Reed435071e2017-05-23 11:22:56 -0400393
394 if (tmpColors) {
395 if (doPremul) {
396 unpremul(tmpColors, vertexCount);
397 }
Brian Osmane0a99622018-07-09 16:12:27 -0400398 float_to_skcolor(builder.colors(), tmpColors, vertexCount, colorSpace);
Mike Reed435071e2017-05-23 11:22:56 -0400399 }
Mike Reed795c5ea2017-03-17 14:29:05 -0400400 return builder.detach();
401}