blob: f38e56104b3b82cc4bce0f65e3f41f50eb087f8c [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"
Brian Osmand25b7c12018-09-21 16:01:59 -040014#include "SkPM4f.h"
Hal Canaryc640d0d2018-06-13 09:59:02 -040015#include "SkTo.h"
dandovb3c9d1c2014-08-12 08:34:29 -070016
Mike Reed4ebb43e2017-04-05 11:06:15 -040017namespace {
18 enum CubicCtrlPts {
19 kTopP0_CubicCtrlPts = 0,
20 kTopP1_CubicCtrlPts = 1,
21 kTopP2_CubicCtrlPts = 2,
22 kTopP3_CubicCtrlPts = 3,
23
24 kRightP0_CubicCtrlPts = 3,
25 kRightP1_CubicCtrlPts = 4,
26 kRightP2_CubicCtrlPts = 5,
27 kRightP3_CubicCtrlPts = 6,
28
29 kBottomP0_CubicCtrlPts = 9,
30 kBottomP1_CubicCtrlPts = 8,
31 kBottomP2_CubicCtrlPts = 7,
32 kBottomP3_CubicCtrlPts = 6,
33
34 kLeftP0_CubicCtrlPts = 0,
35 kLeftP1_CubicCtrlPts = 11,
36 kLeftP2_CubicCtrlPts = 10,
37 kLeftP3_CubicCtrlPts = 9,
38 };
39
40 // Enum for corner also clockwise.
41 enum Corner {
42 kTopLeft_Corner = 0,
43 kTopRight_Corner,
44 kBottomRight_Corner,
45 kBottomLeft_Corner
46 };
47}
48
dandovb3c9d1c2014-08-12 08:34:29 -070049/**
50 * Evaluator to sample the values of a cubic bezier using forward differences.
51 * Forward differences is a method for evaluating a nth degree polynomial at a uniform step by only
52 * adding precalculated values.
53 * For a linear example we have the function f(t) = m*t+b, then the value of that function at t+h
54 * would be f(t+h) = m*(t+h)+b. If we want to know the uniform step that we must add to the first
55 * evaluation f(t) then we need to substract f(t+h) - f(t) = m*t + m*h + b - m*t + b = mh. After
56 * obtaining this value (mh) we could just add this constant step to our first sampled point
57 * to compute the next one.
58 *
59 * For the cubic case the first difference gives as a result a quadratic polynomial to which we can
60 * apply again forward differences and get linear function to which we can apply again forward
61 * differences to get a constant difference. This is why we keep an array of size 4, the 0th
62 * position keeps the sampled value while the next ones keep the quadratic, linear and constant
63 * difference values.
64 */
65
66class FwDCubicEvaluator {
halcanary9d524f22016-03-29 09:03:52 -070067
dandovb3c9d1c2014-08-12 08:34:29 -070068public:
halcanary9d524f22016-03-29 09:03:52 -070069
dandovb3c9d1c2014-08-12 08:34:29 -070070 /**
71 * Receives the 4 control points of the cubic bezier.
72 */
halcanary9d524f22016-03-29 09:03:52 -070073
caryclark5ba2b962016-01-26 17:02:30 -080074 explicit FwDCubicEvaluator(const SkPoint points[4])
75 : fCoefs(points) {
dandovb3c9d1c2014-08-12 08:34:29 -070076 memcpy(fPoints, points, 4 * sizeof(SkPoint));
halcanary9d524f22016-03-29 09:03:52 -070077
dandovb3c9d1c2014-08-12 08:34:29 -070078 this->restart(1);
79 }
halcanary9d524f22016-03-29 09:03:52 -070080
dandovb3c9d1c2014-08-12 08:34:29 -070081 /**
82 * Restarts the forward differences evaluator to the first value of t = 0.
83 */
84 void restart(int divisions) {
85 fDivisions = divisions;
dandovb3c9d1c2014-08-12 08:34:29 -070086 fCurrent = 0;
87 fMax = fDivisions + 1;
caryclark5ba2b962016-01-26 17:02:30 -080088 Sk2s h = Sk2s(1.f / fDivisions);
89 Sk2s h2 = h * h;
90 Sk2s h3 = h2 * h;
91 Sk2s fwDiff3 = Sk2s(6) * fCoefs.fA * h3;
92 fFwDiff[3] = to_point(fwDiff3);
93 fFwDiff[2] = to_point(fwDiff3 + times_2(fCoefs.fB) * h2);
94 fFwDiff[1] = to_point(fCoefs.fA * h3 + fCoefs.fB * h2 + fCoefs.fC * h);
95 fFwDiff[0] = to_point(fCoefs.fD);
dandovb3c9d1c2014-08-12 08:34:29 -070096 }
halcanary9d524f22016-03-29 09:03:52 -070097
dandovb3c9d1c2014-08-12 08:34:29 -070098 /**
99 * Check if the evaluator is still within the range of 0<=t<=1
100 */
101 bool done() const {
102 return fCurrent > fMax;
103 }
halcanary9d524f22016-03-29 09:03:52 -0700104
dandovb3c9d1c2014-08-12 08:34:29 -0700105 /**
106 * Call next to obtain the SkPoint sampled and move to the next one.
107 */
108 SkPoint next() {
109 SkPoint point = fFwDiff[0];
110 fFwDiff[0] += fFwDiff[1];
111 fFwDiff[1] += fFwDiff[2];
112 fFwDiff[2] += fFwDiff[3];
113 fCurrent++;
114 return point;
115 }
halcanary9d524f22016-03-29 09:03:52 -0700116
dandovb3c9d1c2014-08-12 08:34:29 -0700117 const SkPoint* getCtrlPoints() const {
118 return fPoints;
119 }
halcanary9d524f22016-03-29 09:03:52 -0700120
dandovb3c9d1c2014-08-12 08:34:29 -0700121private:
caryclark5ba2b962016-01-26 17:02:30 -0800122 SkCubicCoeff fCoefs;
dandovb3c9d1c2014-08-12 08:34:29 -0700123 int fMax, fCurrent, fDivisions;
caryclark5ba2b962016-01-26 17:02:30 -0800124 SkPoint fFwDiff[4], fPoints[4];
dandovb3c9d1c2014-08-12 08:34:29 -0700125};
126
127////////////////////////////////////////////////////////////////////////////////
128
dandovecfff212014-08-04 10:02:00 -0700129// size in pixels of each partition per axis, adjust this knob
dandovb3c9d1c2014-08-12 08:34:29 -0700130static const int kPartitionSize = 10;
dandovecfff212014-08-04 10:02:00 -0700131
132/**
Mike Reedf4f06ad2018-05-02 15:11:42 -0400133 * Calculate the approximate arc length given a bezier curve's control points.
134 * Returns -1 if bad calc (i.e. non-finite)
dandovecfff212014-08-04 10:02:00 -0700135 */
Mike Reedf4f06ad2018-05-02 15:11:42 -0400136static SkScalar approx_arc_length(const SkPoint points[], int count) {
dandovecfff212014-08-04 10:02:00 -0700137 if (count < 2) {
138 return 0;
139 }
140 SkScalar arcLength = 0;
141 for (int i = 0; i < count - 1; i++) {
142 arcLength += SkPoint::Distance(points[i], points[i + 1]);
143 }
Mike Reedf4f06ad2018-05-02 15:11:42 -0400144 return SkScalarIsFinite(arcLength) ? arcLength : -1;
dandovecfff212014-08-04 10:02:00 -0700145}
146
dandovb3c9d1c2014-08-12 08:34:29 -0700147static SkScalar bilerp(SkScalar tx, SkScalar ty, SkScalar c00, SkScalar c10, SkScalar c01,
Mike Reed435071e2017-05-23 11:22:56 -0400148 SkScalar c11) {
dandovb3c9d1c2014-08-12 08:34:29 -0700149 SkScalar a = c00 * (1.f - tx) + c10 * tx;
150 SkScalar b = c01 * (1.f - tx) + c11 * tx;
151 return a * (1.f - ty) + b * ty;
152}
153
Mike Reed435071e2017-05-23 11:22:56 -0400154static Sk4f bilerp(SkScalar tx, SkScalar ty,
155 const Sk4f& c00, const Sk4f& c10, const Sk4f& c01, const Sk4f& c11) {
156 Sk4f a = c00 * (1.f - tx) + c10 * tx;
157 Sk4f b = c01 * (1.f - tx) + c11 * tx;
158 return a * (1.f - ty) + b * ty;
159}
160
dandovb3c9d1c2014-08-12 08:34:29 -0700161SkISize SkPatchUtils::GetLevelOfDetail(const SkPoint cubics[12], const SkMatrix* matrix) {
dandovecfff212014-08-04 10:02:00 -0700162 // Approximate length of each cubic.
dandovb3c9d1c2014-08-12 08:34:29 -0700163 SkPoint pts[kNumPtsCubic];
Mike Reed4ebb43e2017-04-05 11:06:15 -0400164 SkPatchUtils::GetTopCubic(cubics, pts);
dandovb3c9d1c2014-08-12 08:34:29 -0700165 matrix->mapPoints(pts, kNumPtsCubic);
166 SkScalar topLength = approx_arc_length(pts, kNumPtsCubic);
halcanary9d524f22016-03-29 09:03:52 -0700167
Mike Reed4ebb43e2017-04-05 11:06:15 -0400168 SkPatchUtils::GetBottomCubic(cubics, pts);
dandovb3c9d1c2014-08-12 08:34:29 -0700169 matrix->mapPoints(pts, kNumPtsCubic);
170 SkScalar bottomLength = approx_arc_length(pts, kNumPtsCubic);
halcanary9d524f22016-03-29 09:03:52 -0700171
Mike Reed4ebb43e2017-04-05 11:06:15 -0400172 SkPatchUtils::GetLeftCubic(cubics, pts);
dandovb3c9d1c2014-08-12 08:34:29 -0700173 matrix->mapPoints(pts, kNumPtsCubic);
174 SkScalar leftLength = approx_arc_length(pts, kNumPtsCubic);
halcanary9d524f22016-03-29 09:03:52 -0700175
Mike Reed4ebb43e2017-04-05 11:06:15 -0400176 SkPatchUtils::GetRightCubic(cubics, pts);
dandovb3c9d1c2014-08-12 08:34:29 -0700177 matrix->mapPoints(pts, kNumPtsCubic);
178 SkScalar rightLength = approx_arc_length(pts, kNumPtsCubic);
halcanary9d524f22016-03-29 09:03:52 -0700179
Mike Reedf4f06ad2018-05-02 15:11:42 -0400180 if (topLength < 0 || bottomLength < 0 || leftLength < 0 || rightLength < 0) {
181 return {0, 0}; // negative length is a sentinel for bad length (i.e. non-finite)
182 }
183
dandovecfff212014-08-04 10:02:00 -0700184 // Level of detail per axis, based on the larger side between top and bottom or left and right
185 int lodX = static_cast<int>(SkMaxScalar(topLength, bottomLength) / kPartitionSize);
186 int lodY = static_cast<int>(SkMaxScalar(leftLength, rightLength) / kPartitionSize);
halcanary9d524f22016-03-29 09:03:52 -0700187
dandovb3c9d1c2014-08-12 08:34:29 -0700188 return SkISize::Make(SkMax32(8, lodX), SkMax32(8, lodY));
189}
190
Mike Reed4ebb43e2017-04-05 11:06:15 -0400191void SkPatchUtils::GetTopCubic(const SkPoint cubics[12], SkPoint points[4]) {
dandovb3c9d1c2014-08-12 08:34:29 -0700192 points[0] = cubics[kTopP0_CubicCtrlPts];
193 points[1] = cubics[kTopP1_CubicCtrlPts];
194 points[2] = cubics[kTopP2_CubicCtrlPts];
195 points[3] = cubics[kTopP3_CubicCtrlPts];
196}
197
Mike Reed4ebb43e2017-04-05 11:06:15 -0400198void SkPatchUtils::GetBottomCubic(const SkPoint cubics[12], SkPoint points[4]) {
dandovb3c9d1c2014-08-12 08:34:29 -0700199 points[0] = cubics[kBottomP0_CubicCtrlPts];
200 points[1] = cubics[kBottomP1_CubicCtrlPts];
201 points[2] = cubics[kBottomP2_CubicCtrlPts];
202 points[3] = cubics[kBottomP3_CubicCtrlPts];
203}
204
Mike Reed4ebb43e2017-04-05 11:06:15 -0400205void SkPatchUtils::GetLeftCubic(const SkPoint cubics[12], SkPoint points[4]) {
dandovb3c9d1c2014-08-12 08:34:29 -0700206 points[0] = cubics[kLeftP0_CubicCtrlPts];
207 points[1] = cubics[kLeftP1_CubicCtrlPts];
208 points[2] = cubics[kLeftP2_CubicCtrlPts];
209 points[3] = cubics[kLeftP3_CubicCtrlPts];
210}
211
Mike Reed4ebb43e2017-04-05 11:06:15 -0400212void SkPatchUtils::GetRightCubic(const SkPoint cubics[12], SkPoint points[4]) {
dandovb3c9d1c2014-08-12 08:34:29 -0700213 points[0] = cubics[kRightP0_CubicCtrlPts];
214 points[1] = cubics[kRightP1_CubicCtrlPts];
215 points[2] = cubics[kRightP2_CubicCtrlPts];
216 points[3] = cubics[kRightP3_CubicCtrlPts];
217}
218
Mike Reed435071e2017-05-23 11:22:56 -0400219#include "SkColorSpaceXform.h"
220
Brian Osmand25b7c12018-09-21 16:01:59 -0400221static void skcolor_to_float(SkPMColor4f dst[], const SkColor src[], int count, SkColorSpace* dstCS,
Brian Osmane0a99622018-07-09 16:12:27 -0400222 bool doPremul) {
Mike Kleine28a6b52018-07-25 13:05:17 -0400223 // Source is always sRGB SkColor.
224 auto srcCS = sk_srgb_singleton();
Brian Osmane0a99622018-07-09 16:12:27 -0400225
226 auto op = doPremul ? SkColorSpaceXform::kPremul_AlphaOp : SkColorSpaceXform::kPreserve_AlphaOp;
227 SkAssertResult(SkColorSpaceXform::Apply(dstCS, SkColorSpaceXform::kRGBA_F32_ColorFormat, dst,
228 srcCS, SkColorSpaceXform::kBGRA_8888_ColorFormat, src,
229 count, op));
Mike Reed435071e2017-05-23 11:22:56 -0400230}
231
Brian Osmand25b7c12018-09-21 16:01:59 -0400232static void float_to_skcolor(SkColor dst[], const SkPMColor4f src[], int count,
233 SkColorSpace* srcCS) {
Mike Kleine28a6b52018-07-25 13:05:17 -0400234 // Destination is always sRGB SkColor.
Brian Osmand25b7c12018-09-21 16:01:59 -0400235 // src colors are actually unpremul
Mike Kleine28a6b52018-07-25 13:05:17 -0400236 auto dstCS = sk_srgb_singleton();
Brian Osmane0a99622018-07-09 16:12:27 -0400237 SkAssertResult(SkColorSpaceXform::Apply(dstCS, SkColorSpaceXform::kBGRA_8888_ColorFormat, dst,
238 srcCS, SkColorSpaceXform::kRGBA_F32_ColorFormat, src,
239 count, SkColorSpaceXform::kPreserve_AlphaOp));
Mike Reed435071e2017-05-23 11:22:56 -0400240}
241
Brian Osmand25b7c12018-09-21 16:01:59 -0400242static void unpremul(SkPMColor4f array[], int count) {
243 // Technically, SkPMColor4f to SkColor4f, in-place
Mike Reed435071e2017-05-23 11:22:56 -0400244 for (int i = 0; i < count; ++i) {
Brian Osmand25b7c12018-09-21 16:01:59 -0400245 array[i] = array[i].unpremul().as<kPremul_SkAlphaType>();
Mike Reed435071e2017-05-23 11:22:56 -0400246 }
247}
248
Mike Reed795c5ea2017-03-17 14:29:05 -0400249sk_sp<SkVertices> SkPatchUtils::MakeVertices(const SkPoint cubics[12], const SkColor srcColors[4],
Mike Reed435071e2017-05-23 11:22:56 -0400250 const SkPoint srcTexCoords[4], int lodX, int lodY,
Brian Osmane0a99622018-07-09 16:12:27 -0400251 SkColorSpace* colorSpace) {
Mike Reed795c5ea2017-03-17 14:29:05 -0400252 if (lodX < 1 || lodY < 1 || nullptr == cubics) {
253 return nullptr;
254 }
255
256 // check for overflow in multiplication
257 const int64_t lodX64 = (lodX + 1),
258 lodY64 = (lodY + 1),
259 mult64 = lodX64 * lodY64;
260 if (mult64 > SK_MaxS32) {
261 return nullptr;
262 }
263
Mike Kleine28a6b52018-07-25 13:05:17 -0400264 // Treat null interpolation space as sRGB.
Brian Osmane0a99622018-07-09 16:12:27 -0400265 if (!colorSpace) {
Mike Kleine28a6b52018-07-25 13:05:17 -0400266 colorSpace = sk_srgb_singleton();
Brian Osmane0a99622018-07-09 16:12:27 -0400267 }
268
Mike Reed795c5ea2017-03-17 14:29:05 -0400269 int vertexCount = SkToS32(mult64);
270 // it is recommended to generate draw calls of no more than 65536 indices, so we never generate
271 // more than 60000 indices. To accomplish that we resize the LOD and vertex count
272 if (vertexCount > 10000 || lodX > 200 || lodY > 200) {
273 float weightX = static_cast<float>(lodX) / (lodX + lodY);
274 float weightY = static_cast<float>(lodY) / (lodX + lodY);
275
276 // 200 comes from the 100 * 2 which is the max value of vertices because of the limit of
277 // 60000 indices ( sqrt(60000 / 6) that comes from data->fIndexCount = lodX * lodY * 6)
Mike Reed70bebb02018-05-09 14:07:21 -0400278 // Need a min of 1 since we later divide by lod
279 lodX = std::max(1, sk_float_floor2int_no_saturate(weightX * 200));
280 lodY = std::max(1, sk_float_floor2int_no_saturate(weightY * 200));
Mike Reed795c5ea2017-03-17 14:29:05 -0400281 vertexCount = (lodX + 1) * (lodY + 1);
282 }
283 const int indexCount = lodX * lodY * 6;
284 uint32_t flags = 0;
285 if (srcTexCoords) {
286 flags |= SkVertices::kHasTexCoords_BuilderFlag;
287 }
288 if (srcColors) {
289 flags |= SkVertices::kHasColors_BuilderFlag;
290 }
291
Florin Malita14a64302017-05-24 14:53:44 -0400292 SkSTArenaAlloc<2048> alloc;
Brian Osmand25b7c12018-09-21 16:01:59 -0400293 SkPMColor4f* cornerColors = srcColors ? alloc.makeArray<SkPMColor4f>(4) : nullptr;
294 SkPMColor4f* tmpColors = srcColors ? alloc.makeArray<SkPMColor4f>(vertexCount) : nullptr;
Mike Reed435071e2017-05-23 11:22:56 -0400295
Mike Reed887cdf12017-04-03 11:11:09 -0400296 SkVertices::Builder builder(SkVertices::kTriangles_VertexMode, vertexCount, indexCount, flags);
Mike Reed795c5ea2017-03-17 14:29:05 -0400297 SkPoint* pos = builder.positions();
298 SkPoint* texs = builder.texCoords();
Mike Reed795c5ea2017-03-17 14:29:05 -0400299 uint16_t* indices = builder.indices();
Mike Reed7346a1f2017-05-18 22:23:34 -0400300 bool is_opaque = false;
Mike Reed795c5ea2017-03-17 14:29:05 -0400301
Mike Reed435071e2017-05-23 11:22:56 -0400302 /*
303 * 1. Should we offer this as a runtime choice, as we do in gradients?
304 * 2. Since drawing the vertices wants premul, shoudl we extend SkVertices to store
305 * premul colors (as floats, w/ a colorspace)?
306 */
307 bool doPremul = true;
308 if (cornerColors) {
Mike Reed7346a1f2017-05-18 22:23:34 -0400309 SkColor c = ~0;
Mike Reed795c5ea2017-03-17 14:29:05 -0400310 for (int i = 0; i < kNumCorners; i++) {
Mike Reed7346a1f2017-05-18 22:23:34 -0400311 c &= srcColors[i];
Mike Reed795c5ea2017-03-17 14:29:05 -0400312 }
Mike Reed7346a1f2017-05-18 22:23:34 -0400313 is_opaque = (SkColorGetA(c) == 0xFF);
Mike Reed435071e2017-05-23 11:22:56 -0400314 if (is_opaque) {
315 doPremul = false; // no need
316 }
317
Brian Osmane0a99622018-07-09 16:12:27 -0400318 skcolor_to_float(cornerColors, srcColors, kNumCorners, colorSpace, doPremul);
Mike Reed795c5ea2017-03-17 14:29:05 -0400319 }
320
321 SkPoint pts[kNumPtsCubic];
Mike Reed4ebb43e2017-04-05 11:06:15 -0400322 SkPatchUtils::GetBottomCubic(cubics, pts);
Mike Reed795c5ea2017-03-17 14:29:05 -0400323 FwDCubicEvaluator fBottom(pts);
Mike Reed4ebb43e2017-04-05 11:06:15 -0400324 SkPatchUtils::GetTopCubic(cubics, pts);
Mike Reed795c5ea2017-03-17 14:29:05 -0400325 FwDCubicEvaluator fTop(pts);
Mike Reed4ebb43e2017-04-05 11:06:15 -0400326 SkPatchUtils::GetLeftCubic(cubics, pts);
Mike Reed795c5ea2017-03-17 14:29:05 -0400327 FwDCubicEvaluator fLeft(pts);
Mike Reed4ebb43e2017-04-05 11:06:15 -0400328 SkPatchUtils::GetRightCubic(cubics, pts);
Mike Reed795c5ea2017-03-17 14:29:05 -0400329 FwDCubicEvaluator fRight(pts);
330
331 fBottom.restart(lodX);
332 fTop.restart(lodX);
333
334 SkScalar u = 0.0f;
335 int stride = lodY + 1;
336 for (int x = 0; x <= lodX; x++) {
337 SkPoint bottom = fBottom.next(), top = fTop.next();
338 fLeft.restart(lodY);
339 fRight.restart(lodY);
340 SkScalar v = 0.f;
341 for (int y = 0; y <= lodY; y++) {
342 int dataIndex = x * (lodY + 1) + y;
343
344 SkPoint left = fLeft.next(), right = fRight.next();
345
346 SkPoint s0 = SkPoint::Make((1.0f - v) * top.x() + v * bottom.x(),
347 (1.0f - v) * top.y() + v * bottom.y());
348 SkPoint s1 = SkPoint::Make((1.0f - u) * left.x() + u * right.x(),
349 (1.0f - u) * left.y() + u * right.y());
350 SkPoint s2 = SkPoint::Make(
351 (1.0f - v) * ((1.0f - u) * fTop.getCtrlPoints()[0].x()
352 + u * fTop.getCtrlPoints()[3].x())
353 + v * ((1.0f - u) * fBottom.getCtrlPoints()[0].x()
354 + u * fBottom.getCtrlPoints()[3].x()),
355 (1.0f - v) * ((1.0f - u) * fTop.getCtrlPoints()[0].y()
356 + u * fTop.getCtrlPoints()[3].y())
357 + v * ((1.0f - u) * fBottom.getCtrlPoints()[0].y()
358 + u * fBottom.getCtrlPoints()[3].y()));
359 pos[dataIndex] = s0 + s1 - s2;
360
Mike Reed435071e2017-05-23 11:22:56 -0400361 if (cornerColors) {
Brian Osman81cbd032018-09-21 11:09:15 -0400362 bilerp(u, v, Sk4f::Load(cornerColors[kTopLeft_Corner].vec()),
363 Sk4f::Load(cornerColors[kTopRight_Corner].vec()),
364 Sk4f::Load(cornerColors[kBottomLeft_Corner].vec()),
365 Sk4f::Load(cornerColors[kBottomRight_Corner].vec()))
366 .store(tmpColors[dataIndex].vec());
Mike Reed435071e2017-05-23 11:22:56 -0400367 if (is_opaque) {
Brian Osman81cbd032018-09-21 11:09:15 -0400368 tmpColors[dataIndex].fA = 1;
Mike Reed7346a1f2017-05-18 22:23:34 -0400369 }
Mike Reed795c5ea2017-03-17 14:29:05 -0400370 }
371
372 if (texs) {
373 texs[dataIndex] = SkPoint::Make(bilerp(u, v, srcTexCoords[kTopLeft_Corner].x(),
374 srcTexCoords[kTopRight_Corner].x(),
375 srcTexCoords[kBottomLeft_Corner].x(),
376 srcTexCoords[kBottomRight_Corner].x()),
377 bilerp(u, v, srcTexCoords[kTopLeft_Corner].y(),
378 srcTexCoords[kTopRight_Corner].y(),
379 srcTexCoords[kBottomLeft_Corner].y(),
380 srcTexCoords[kBottomRight_Corner].y()));
381
382 }
383
384 if(x < lodX && y < lodY) {
385 int i = 6 * (x * lodY + y);
386 indices[i] = x * stride + y;
387 indices[i + 1] = x * stride + 1 + y;
388 indices[i + 2] = (x + 1) * stride + 1 + y;
389 indices[i + 3] = indices[i];
390 indices[i + 4] = indices[i + 2];
391 indices[i + 5] = (x + 1) * stride + y;
392 }
393 v = SkScalarClampMax(v + 1.f / lodY, 1);
394 }
395 u = SkScalarClampMax(u + 1.f / lodX, 1);
396 }
Mike Reed435071e2017-05-23 11:22:56 -0400397
398 if (tmpColors) {
399 if (doPremul) {
400 unpremul(tmpColors, vertexCount);
401 }
Brian Osmane0a99622018-07-09 16:12:27 -0400402 float_to_skcolor(builder.colors(), tmpColors, vertexCount, colorSpace);
Mike Reed435071e2017-05-23 11:22:56 -0400403 }
Mike Reed795c5ea2017-03-17 14:29:05 -0400404 return builder.detach();
405}