Chromium Code Reviews| Index: src/core/SkDevice.cpp |
| diff --git a/src/core/SkDevice.cpp b/src/core/SkDevice.cpp |
| index e71c889451df139dd8e92ed28d9e4a2b57ebf084..d5032483fd077a6b77fc969beb0cb9dd4a4d9dd4 100644 |
| --- a/src/core/SkDevice.cpp |
| +++ b/src/core/SkDevice.cpp |
| @@ -6,6 +6,7 @@ |
| */ |
| #include "SkDevice.h" |
| +#include "SkDraw.h" |
| #include "SkMetaData.h" |
| SkBaseDevice::SkBaseDevice() |
| @@ -77,6 +78,48 @@ void SkBaseDevice::drawDRRect(const SkDraw& draw, const SkRRect& outer, |
| this->drawPath(draw, path, paint, preMatrix, pathIsMutable); |
| } |
| +void SkBaseDevice::drawPatch(const SkDraw& draw, const SkPatch& patch, const SkPaint& paint) { |
| + SkPatch::VertexData data; |
| + |
| + SkPoint mapPts[12]; |
| + draw.fMatrix->mapPoints(mapPts, patch.getControlPoints(), 12); |
| + |
| + // Approximate length of each cubic. |
| + int topLength = SkSqrt32(mapPts[SkPatch::kTopP0_CubicCtrlPts] |
|
egdaniel
2014/08/01 13:28:52
This may be a good place for a function that calcs
dandov
2014/08/01 15:11:14
Created a function in SkGeometry that calculates a
|
| + .distanceToSqd(mapPts[SkPatch::kTopP1_CubicCtrlPts])) + |
|
bsalomon
2014/08/01 13:30:27
I'd just give up on trying to reduce sqrts and cal
|
| + SkSqrt32(mapPts[SkPatch::kTopP1_CubicCtrlPts] |
| + .distanceToSqd(mapPts[SkPatch::kTopP2_CubicCtrlPts])) + |
| + SkSqrt32(mapPts[SkPatch::kTopP2_CubicCtrlPts] |
| + .distanceToSqd(mapPts[SkPatch::kTopP3_CubicCtrlPts])); |
| + int bottomLength = SkSqrt32(mapPts[SkPatch::kBottomP0_CubicCtrlPts] |
| + .distanceToSqd(mapPts[SkPatch::kBottomP1_CubicCtrlPts])) + |
| + SkSqrt32(mapPts[SkPatch::kBottomP1_CubicCtrlPts] |
| + .distanceToSqd(mapPts[SkPatch::kBottomP2_CubicCtrlPts])) + |
| + SkSqrt32(mapPts[SkPatch::kBottomP2_CubicCtrlPts] |
| + .distanceToSqd(mapPts[SkPatch::kBottomP3_CubicCtrlPts])); |
| + int leftLength = SkSqrt32(mapPts[SkPatch::kLeftP0_CubicCtrlPts] |
| + .distanceToSqd(mapPts[SkPatch::kLeftP1_CubicCtrlPts])) + |
| + SkSqrt32(mapPts[SkPatch::kLeftP1_CubicCtrlPts] |
| + .distanceToSqd(mapPts[SkPatch::kLeftP2_CubicCtrlPts])) + |
| + SkSqrt32(mapPts[SkPatch::kLeftP2_CubicCtrlPts] |
| + .distanceToSqd(mapPts[SkPatch::kLeftP3_CubicCtrlPts])); |
| + int rightLength = SkSqrt32(mapPts[SkPatch::kRightP0_CubicCtrlPts] |
| + .distanceToSqd(mapPts[SkPatch::kRightP1_CubicCtrlPts])) + |
| + SkSqrt32(mapPts[SkPatch::kRightP1_CubicCtrlPts] |
| + .distanceToSqd(mapPts[SkPatch::kRightP2_CubicCtrlPts])) + |
| + SkSqrt32(mapPts[SkPatch::kRightP2_CubicCtrlPts] |
| + .distanceToSqd(mapPts[SkPatch::kRightP3_CubicCtrlPts])); |
| + |
| + // Level of detail per axis, based on the larger side between top and bottom or left and right |
| + int lodX = SkMaxScalar(topLength, bottomLength) / SkPatch::kPartitionSize; |
| + int lodY = SkMaxScalar(leftLength, rightLength) / SkPatch::kPartitionSize; |
| + |
| + // It automatically adjusts lodX and lodY in case it exceeds the number of indices. |
| + patch.getVertexData(&data, SkMax32(2, lodX), SkMax32(2, lodY)); |
| + this->drawVertices(draw, SkCanvas::kTriangles_VertexMode, data.fVertexCount, data.fPoints, |
| + data.fTexCoords, data.fColors, NULL, data.fIndices, data.fIndexCount, paint); |
| +} |
| + |
| bool SkBaseDevice::readPixels(const SkImageInfo& info, void* dstP, size_t rowBytes, int x, int y) { |
| #ifdef SK_DEBUG |
| SkASSERT(info.width() > 0 && info.height() > 0); |