Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(43)

Side by Side Diff: src/core/SkPatch.cpp

Issue 429343004: Stopped skipping tests in dm of SkPatch (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Dumped corners and colors and used enum for 12's and 4's Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright 2014 Google Inc. 2 * Copyright 2014 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkPatch.h" 8 #include "SkPatch.h"
9 9
10 #include "SkGeometry.h" 10 #include "SkGeometry.h"
11 #include "SkColorPriv.h" 11 #include "SkColorPriv.h"
12 #include "SkBuffer.h"
12 13
13 //////////////////////////////////////////////////////////////////////////////// 14 ////////////////////////////////////////////////////////////////////////////////
14 15
15 /** 16 /**
16 * Evaluator to sample the values of a cubic bezier using forward differences. 17 * Evaluator to sample the values of a cubic bezier using forward differences.
17 * Forward differences is a method for evaluating a nth degree polynomial at a u niform step by only 18 * Forward differences is a method for evaluating a nth degree polynomial at a u niform step by only
18 * adding precalculated values. 19 * adding precalculated values.
19 * For a linear example we have the function f(t) = m*t+b, then the value of tha t function at t+h 20 * For a linear example we have the function f(t) = m*t+b, then the value of tha t function at t+h
20 * would be f(t+h) = m*(t+h)+b. If we want to know the uniform step that we must add to the first 21 * would be f(t+h) = m*(t+h)+b. If we want to know the uniform step that we must add to the first
21 * evaluation f(t) then we need to substract f(t+h) - f(t) = m*t + m*h + b - m*t + b = mh. After 22 * evaluation f(t) then we need to substract f(t+h) - f(t) = m*t + m*h + b - m*t + b = mh. After
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 return fPoints; 111 return fPoints;
111 } 112 }
112 113
113 private: 114 private:
114 int fMax, fCurrent, fDivisions; 115 int fMax, fCurrent, fDivisions;
115 SkPoint fFwDiff[4], fCoefs[4], fPoints[4]; 116 SkPoint fFwDiff[4], fCoefs[4], fPoints[4];
116 }; 117 };
117 118
118 //////////////////////////////////////////////////////////////////////////////// 119 ////////////////////////////////////////////////////////////////////////////////
119 120
120 SkPatch::SkPatch(SkPoint points[12], SkColor colors[4]) { 121 SkPatch::SkPatch(const SkPoint points[SkPatch::kNumCtrlPts],
121 122 const SkColor colors[SkPatch::kNumColors]) {
122 for (int i = 0; i < 12; i++) { 123 this->reset(points, colors);
123 fCtrlPoints[i] = points[i];
124 }
125 for (int i = 0; i < 4; i++) {
126 fCornerColors[i] = colors[i];
127 }
128
129 } 124 }
130 125
131 uint8_t bilinear(SkScalar tx, SkScalar ty, SkScalar c00, SkScalar c10, SkScalar c01, SkScalar c11) { 126 uint8_t bilinear(SkScalar tx, SkScalar ty, SkScalar c00, SkScalar c10, SkScalar c01, SkScalar c11) {
132 SkScalar a = c00 * (1.f - tx) + c10 * tx; 127 SkScalar a = c00 * (1.f - tx) + c10 * tx;
133 SkScalar b = c01 * (1.f - tx) + c11 * tx; 128 SkScalar b = c01 * (1.f - tx) + c11 * tx;
134 return uint8_t(a * (1.f - ty) + b * ty); 129 return uint8_t(a * (1.f - ty) + b * ty);
135 } 130 }
136 131
137 bool SkPatch::getVertexData(SkPatch::VertexData* data, int lodX, int lodY) const { 132 bool SkPatch::getVertexData(SkPatch::VertexData* data, int lodX, int lodY) const {
138 133
139 if (lodX < 1 || lodY < 1) { 134 if (lodX < 1 || lodY < 1) {
140 return false; 135 return false;
141 } 136 }
142 137
143 // premultiply colors to avoid color bleeding. 138 // premultiply colors to avoid color bleeding.
144 SkPMColor colors[4]; 139 SkPMColor colors[SkPatch::kNumColors];
145 for (int i = 0; i < 4; i++) { 140 for (int i = 0; i < SkPatch::kNumColors; i++) {
146 colors[i] = SkPreMultiplyColor(fCornerColors[i]); 141 colors[i] = SkPreMultiplyColor(fCornerColors[i]);
147 } 142 }
148 143
149 // number of indices is limited by size of uint16_t, so we clamp it to avoid overflow 144 // number of indices is limited by size of uint16_t, so we clamp it to avoid overflow
150 data->fVertexCount = SkMin32((lodX + 1) * (lodY + 1), 65536); 145 data->fVertexCount = SkMin32((lodX + 1) * (lodY + 1), 65536);
151 lodX = SkMin32(lodX, 255); 146 lodX = SkMin32(lodX, 255);
152 lodY = SkMin32(lodY, 255); 147 lodY = SkMin32(lodY, 255);
153 data->fIndexCount = lodX * lodY * 6; 148 data->fIndexCount = lodX * lodY * 6;
154 149
155 data->fPoints = SkNEW_ARRAY(SkPoint, data->fVertexCount); 150 data->fPoints = SkNEW_ARRAY(SkPoint, data->fVertexCount);
156 data->fColors = SkNEW_ARRAY(uint32_t, data->fVertexCount); 151 data->fColors = SkNEW_ARRAY(uint32_t, data->fVertexCount);
157 data->fTexCoords = SkNEW_ARRAY(SkPoint, data->fVertexCount); 152 data->fTexCoords = SkNEW_ARRAY(SkPoint, data->fVertexCount);
158 data->fIndices = SkNEW_ARRAY(uint16_t, data->fIndexCount); 153 data->fIndices = SkNEW_ARRAY(uint16_t, data->fIndexCount);
159 154
160 SkPoint pts[4]; 155 SkPoint pts[SkPatch::kNumPtsCubic];
161 this->getBottomPoints(pts); 156 this->getBottomPoints(pts);
162 FwDCubicEvaluator fBottom(pts); 157 FwDCubicEvaluator fBottom(pts);
163 this->getTopPoints(pts); 158 this->getTopPoints(pts);
164 FwDCubicEvaluator fTop(pts); 159 FwDCubicEvaluator fTop(pts);
165 this->getLeftPoints(pts); 160 this->getLeftPoints(pts);
166 FwDCubicEvaluator fLeft(pts); 161 FwDCubicEvaluator fLeft(pts);
167 this->getRightPoints(pts); 162 this->getRightPoints(pts);
168 FwDCubicEvaluator fRight(pts); 163 FwDCubicEvaluator fRight(pts);
169 164
170 fBottom.restart(lodX); 165 fBottom.restart(lodX);
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 data->fIndices[i + 3] = data->fIndices[i]; 224 data->fIndices[i + 3] = data->fIndices[i];
230 data->fIndices[i + 4] = data->fIndices[i + 2]; 225 data->fIndices[i + 4] = data->fIndices[i + 2];
231 data->fIndices[i + 5] = (x + 1) * stride + y; 226 data->fIndices[i + 5] = (x + 1) * stride + y;
232 } 227 }
233 v = SkScalarClampMax(v + 1.f / lodY, 1); 228 v = SkScalarClampMax(v + 1.f / lodY, 1);
234 } 229 }
235 u = SkScalarClampMax(u + 1.f / lodX, 1); 230 u = SkScalarClampMax(u + 1.f / lodX, 1);
236 } 231 }
237 return true; 232 return true;
238 } 233 }
234
235 size_t SkPatch::writeToMemory(void* storage) const {
236 int byteCount = kNumCtrlPts * sizeof(SkPoint) + kNumColors * sizeof(SkColor );
237
238 if (NULL == storage) {
239 return SkAlign4(byteCount);
240 }
241
242 SkWBuffer buffer(storage);
243
244 buffer.write(fCtrlPoints, kNumCtrlPts * sizeof(SkPoint));
245 buffer.write(fCornerColors, kNumColors * sizeof(SkColor));
246
247 buffer.padToAlign4();
248 return buffer.pos();
249 }
250
251 size_t SkPatch::readFromMemory(const void* storage, size_t length) {
252 SkRBufferWithSizeCheck buffer(storage, length);
253
254 int byteCount = 0;
255
256 if (!buffer.read(fCtrlPoints, kNumCtrlPts * sizeof(SkPoint))) {
257 return byteCount;
258 }
259 byteCount += kNumCtrlPts * sizeof(SkPoint);
260
261 if (!buffer.read(fCornerColors, kNumColors * sizeof(SkColor))) {
262 return byteCount;
263 }
264 byteCount += kNumColors * sizeof(SkColor);
265
266 return byteCount;
267 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698