Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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[12], const SkColor colors[4]) { |
| 121 | 122 |
| 122 for (int i = 0; i < 12; i++) { | 123 for (int i = 0; i < 12; i++) { |
| 123 fCtrlPoints[i] = points[i]; | 124 fCtrlPoints[i] = points[i]; |
| 124 } | 125 } |
| 125 for (int i = 0; i < 4; i++) { | 126 for (int i = 0; i < 4; i++) { |
| 126 fCornerColors[i] = colors[i]; | 127 fCornerColors[i] = colors[i]; |
| 127 } | 128 } |
| 128 | 129 |
| 129 } | 130 } |
| 130 | 131 |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 229 data->fIndices[i + 3] = data->fIndices[i]; | 230 data->fIndices[i + 3] = data->fIndices[i]; |
| 230 data->fIndices[i + 4] = data->fIndices[i + 2]; | 231 data->fIndices[i + 4] = data->fIndices[i + 2]; |
| 231 data->fIndices[i + 5] = (x + 1) * stride + y; | 232 data->fIndices[i + 5] = (x + 1) * stride + y; |
| 232 } | 233 } |
| 233 v = SkScalarClampMax(v + 1.f / lodY, 1); | 234 v = SkScalarClampMax(v + 1.f / lodY, 1); |
| 234 } | 235 } |
| 235 u = SkScalarClampMax(u + 1.f / lodX, 1); | 236 u = SkScalarClampMax(u + 1.f / lodX, 1); |
| 236 } | 237 } |
| 237 return true; | 238 return true; |
| 238 } | 239 } |
| 240 | |
| 241 size_t SkPatch::writeToMemory(void* storage) const { | |
|
robertphillips
2014/08/04 18:44:18
12 -> kNumControlPts ?
4 -> kNumCornerColors ?
dandov
2014/08/04 19:59:27
Added constants and use them where they are needed
| |
| 242 int byteCount = 12 * sizeof(SkPoint) + 4 * sizeof(SkColor); | |
| 243 | |
| 244 if (NULL == storage) { | |
| 245 return SkAlign4(byteCount); | |
| 246 } | |
| 247 | |
| 248 SkWBuffer buffer(storage); | |
| 249 | |
| 250 buffer.write(fCtrlPoints, 12 * sizeof(SkPoint)); | |
| 251 buffer.write(fCornerColors, 4 * sizeof(SkColor)); | |
| 252 | |
| 253 buffer.padToAlign4(); | |
| 254 return buffer.pos(); | |
| 255 } | |
| 256 | |
| 257 size_t SkPatch::readFromMemory(const void* storage, size_t length) { | |
| 258 SkRBufferWithSizeCheck buffer(storage, length); | |
| 259 | |
| 260 int byteCount = 0; | |
| 261 | |
|
robertphillips
2014/08/04 18:44:18
Can we not just read into fCtrlPoints & fCornerCol
dandov
2014/08/04 19:59:27
Done.
| |
| 262 SkPoint pts[12]; | |
| 263 if (!buffer.read(pts, 12 * sizeof(SkPoint))) { | |
| 264 return byteCount; | |
| 265 } | |
| 266 for (int i = 0; i < 12; i++) { | |
| 267 fCtrlPoints[i] = pts[i]; | |
|
mtklein
2014/08/04 18:23:03
Is this redundant with this->reset(pts, colors) be
dandov
2014/08/04 19:59:27
Done. Changed it to read directly into fCtrlPoints
| |
| 268 } | |
| 269 byteCount += 12 * sizeof(SkPoint); | |
| 270 | |
| 271 SkColor colors[4]; | |
| 272 if (!buffer.read(colors, 4 * sizeof(SkColor))) { | |
| 273 return byteCount; | |
| 274 } | |
| 275 for (int i = 0; i < 12; i++) { | |
| 276 fCtrlPoints[i] = pts[i]; | |
|
mtklein
2014/08/04 18:23:03
Did you mean to copy the colors here?
dandov
2014/08/04 19:59:27
Also redundant because of this->reset, removed it
| |
| 277 } | |
| 278 byteCount += 12 * sizeof(SkPoint); | |
| 279 | |
| 280 this->reset(pts, colors); | |
| 281 | |
| 282 return byteCount; | |
| 283 } | |
| OLD | NEW |