Index: src/utils/SkPatchUtils.cpp |
diff --git a/src/utils/SkPatchUtils.cpp b/src/utils/SkPatchUtils.cpp |
new file mode 100644 |
index 0000000000000000000000000000000000000000..5e6a516006b9707e445ddec23649b65fa5bab700 |
--- /dev/null |
+++ b/src/utils/SkPatchUtils.cpp |
@@ -0,0 +1,40 @@ |
+/* |
+ * Copyright 2014 Google Inc. |
+ * |
+ * Use of this source code is governed by a BSD-style license that can be |
+ * found in the LICENSE file. |
+ */ |
+ |
+#include "SkPatchUtils.h" |
+ |
+#include "SkGeometry.h" |
+ |
+SkIPoint SkPatchUtils::GetLevelOfDetail(const SkPatch& patch, const SkMatrix* matrix) { |
+ |
+ SkPoint mapPts[12]; |
+ matrix->mapPoints(mapPts, patch.getControlPoints(), 12); |
+ |
+ // Approximate length of each cubic. |
+ SkPoint pts[4]; |
+ patch.getTopPoints(pts); |
+ matrix->mapPoints(pts, 4); |
+ int topLength = approx_arc_length(pts, 4); |
+ |
+ patch.getBottomPoints(pts); |
+ matrix->mapPoints(pts, 4); |
+ int bottomLength = approx_arc_length(pts, 4); |
+ |
+ patch.getLeftPoints(pts); |
+ matrix->mapPoints(pts, 4); |
+ int leftLength = approx_arc_length(pts, 4); |
+ |
+ patch.getRightPoints(pts); |
+ matrix->mapPoints(pts, 4); |
+ int rightLength = approx_arc_length(pts, 4); |
+ |
+ // Level of detail per axis, based on the larger side between top and bottom or left and right |
+ int lodX = SkMaxScalar(topLength, bottomLength) / kPartitionSize; |
+ int lodY = SkMaxScalar(leftLength, rightLength) / kPartitionSize; |
+ |
+ return SkIPoint::Make(SkMax32(4, lodX), SkMax32(4, lodY)); |
+} |