blob: a215b7a85d1215ac1cc9b144e8fc8c9450746aeb [file] [log] [blame]
Chris Craik65cd6122012-12-10 17:56:27 -08001/*
2 * Copyright (C) 2012 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef ANDROID_HWUI_PATH_TESSELLATOR_H
18#define ANDROID_HWUI_PATH_TESSELLATOR_H
19
20#include <utils/Vector.h>
21
22#include "Matrix.h"
23#include "Rect.h"
24#include "Vertex.h"
ztenghui55bfb4e2013-12-03 10:38:55 -080025#include "VertexBuffer.h"
Chris Craik65cd6122012-12-10 17:56:27 -080026
27namespace android {
28namespace uirenderer {
29
Chris Craik65cd6122012-12-10 17:56:27 -080030class PathTessellator {
31public:
Chris Craikf0a59072013-11-19 18:00:46 -080032 static void expandBoundsForStroke(SkRect& bounds, const SkPaint* paint);
Chris Craik65cd6122012-12-10 17:56:27 -080033
Chris Craik15a07a22014-01-26 13:43:53 -080034 /**
35 * Populates a VertexBuffer with a tessellated approximation of the input convex path, as a single
36 * triangle strip. Note: joins are not currently supported.
37 *
38 * @param path The path to be approximated
39 * @param paint The paint the path will be drawn with, indicating AA, painting style
40 * (stroke vs fill), stroke width, stroke cap & join style, etc.
41 * @param transform The transform the path is to be drawn with, used to drive stretch-aware path
42 * vertex approximation, and correct AA ramp offsetting.
43 * @param vertexBuffer The output buffer
44 */
Chris Craik65cd6122012-12-10 17:56:27 -080045 static void tessellatePath(const SkPath& path, const SkPaint* paint,
Chris Craikd6b65f62014-01-01 14:45:21 -080046 const mat4& transform, VertexBuffer& vertexBuffer);
Chris Craik65cd6122012-12-10 17:56:27 -080047
Chris Craik15a07a22014-01-26 13:43:53 -080048 /**
49 * Populates a VertexBuffer with a tessellated approximation of points as a single triangle
50 * strip (with degenerate tris separating), respecting the shape defined by the paint cap.
51 *
52 * @param points The center vertices of the points to be drawn
53 * @param count The number of floats making up the point vertices
54 * @param paint The paint the points will be drawn with indicating AA, stroke width & cap
55 * @param transform The transform the points will be drawn with, used to drive stretch-aware path
56 * vertex approximation, and correct AA ramp offsetting
57 * @param bounds An output rectangle, which returns the total area covered by the output buffer
58 * @param vertexBuffer The output buffer
59 */
Chris Craikd218a922014-01-02 17:13:34 -080060 static void tessellatePoints(const float* points, int count, const SkPaint* paint,
Chris Craikd6b65f62014-01-01 14:45:21 -080061 const mat4& transform, SkRect& bounds, VertexBuffer& vertexBuffer);
Chris Craik6d29c8d2013-05-08 18:35:44 -070062
Chris Craik15a07a22014-01-26 13:43:53 -080063 /**
64 * Populates a VertexBuffer with a tessellated approximation of lines as a single triangle
65 * strip (with degenerate tris separating).
66 *
67 * @param points Pairs of endpoints defining the lines to be drawn
68 * @param count The number of floats making up the line vertices
69 * @param paint The paint the lines will be drawn with indicating AA, stroke width & cap
70 * @param transform The transform the points will be drawn with, used to drive stretch-aware path
71 * vertex approximation, and correct AA ramp offsetting
72 * @param bounds An output rectangle, which returns the total area covered by the output buffer
73 * @param vertexBuffer The output buffer
74 */
Chris Craikd218a922014-01-02 17:13:34 -080075 static void tessellateLines(const float* points, int count, const SkPaint* paint,
Chris Craikd6b65f62014-01-01 14:45:21 -080076 const mat4& transform, SkRect& bounds, VertexBuffer& vertexBuffer);
Chris Craik65cd6122012-12-10 17:56:27 -080077
Chris Craik15a07a22014-01-26 13:43:53 -080078 /**
79 * Approximates a convex, CW outline into a Vector of 2d vertices.
80 *
81 * @param path The outline to be approximated
82 * @param thresholdSquared The threshold of acceptable error (in pixels) when approximating
83 * @param outputVertices An empty Vector which will be populated with the output
84 */
85 static bool approximatePathOutlineVertices(const SkPath &path, float thresholdSquared,
86 Vector<Vertex> &outputVertices);
87
Chris Craik65cd6122012-12-10 17:56:27 -080088private:
89 static bool approximatePathOutlineVertices(const SkPath &path, bool forceClose,
Chris Craik15a07a22014-01-26 13:43:53 -080090 float sqrInvScaleX, float sqrInvScaleY, float thresholdSquared,
91 Vector<Vertex> &outputVertices);
Chris Craik65cd6122012-12-10 17:56:27 -080092
93/*
94 endpoints a & b,
95 control c
96 */
97 static void recursiveQuadraticBezierVertices(
98 float ax, float ay,
99 float bx, float by,
100 float cx, float cy,
Chris Craik15a07a22014-01-26 13:43:53 -0800101 float sqrInvScaleX, float sqrInvScaleY, float thresholdSquared,
Chris Craik65cd6122012-12-10 17:56:27 -0800102 Vector<Vertex> &outputVertices);
103
104/*
105 endpoints p1, p2
106 control c1, c2
107 */
108 static void recursiveCubicBezierVertices(
109 float p1x, float p1y,
110 float c1x, float c1y,
111 float p2x, float p2y,
112 float c2x, float c2y,
Chris Craik15a07a22014-01-26 13:43:53 -0800113 float sqrInvScaleX, float sqrInvScaleY, float thresholdSquared,
Chris Craik65cd6122012-12-10 17:56:27 -0800114 Vector<Vertex> &outputVertices);
115};
116
117}; // namespace uirenderer
118}; // namespace android
119
120#endif // ANDROID_HWUI_PATH_TESSELLATOR_H