blob: 64aebfa59ec97d1f46c6f723be0ff00db54cf156 [file] [log] [blame]
jvanverth@google.com8ffb7042012-12-13 19:53:18 +00001/*
2 * Copyright 2012 The Android Open Source Project
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#ifndef ANDROID_HWUI_PATH_RENDERER_H
9#define ANDROID_HWUI_PATH_RENDERER_H
10
jvanverth@google.com24b4f972012-12-18 14:13:46 +000011#include <SkTArray.h>
jvanverth@google.com8ffb7042012-12-13 19:53:18 +000012
13#include "Vertex.h"
14
jvanverth@google.com24b4f972012-12-18 14:13:46 +000015class SkMatrix;
16
jvanverth@google.com8ffb7042012-12-13 19:53:18 +000017namespace android {
18namespace uirenderer {
19
jvanverth@google.com8ffb7042012-12-13 19:53:18 +000020class VertexBuffer {
21public:
22 VertexBuffer():
23 mBuffer(0),
24 mSize(0),
25 mCleanupMethod(0)
26 {}
27
28 ~VertexBuffer() {
29 if (mCleanupMethod)
30 mCleanupMethod(mBuffer);
31 }
32
33 template <class TYPE>
34 TYPE* alloc(int size) {
35 mSize = size;
36 mBuffer = (void*)new TYPE[size];
37 mCleanupMethod = &(cleanup<TYPE>);
38
39 return (TYPE*)mBuffer;
40 }
41
42 void* getBuffer() { return mBuffer; }
43 unsigned int getSize() { return mSize; }
44
45private:
46 template <class TYPE>
47 static void cleanup(void* buffer) {
48 delete[] (TYPE*)buffer;
49 }
50
51 void* mBuffer;
52 unsigned int mSize;
53 void (*mCleanupMethod)(void*);
54};
55
56class PathRenderer {
57public:
jvanverth@google.com24b4f972012-12-18 14:13:46 +000058 static SkRect ComputePathBounds(const SkPath& path, const SkPaint* paint);
jvanverth@google.com8ffb7042012-12-13 19:53:18 +000059
jvanverth@google.com24b4f972012-12-18 14:13:46 +000060 static void ConvexPathVertices(const SkPath& path, const SkPaint* paint,
61 const SkMatrix* transform, VertexBuffer* vertexBuffer);
jvanverth@google.com8ffb7042012-12-13 19:53:18 +000062
63private:
jvanverth@google.com24b4f972012-12-18 14:13:46 +000064 static bool ConvexPathPerimeterVertices(const SkPath &path, bool forceClose,
65 float sqrInvScaleX, float sqrInvScaleY, SkTArray<Vertex, true>* outputVertices);
jvanverth@google.com8ffb7042012-12-13 19:53:18 +000066
67/*
68 endpoints a & b,
69 control c
70 */
jvanverth@google.com24b4f972012-12-18 14:13:46 +000071 static void RecursiveQuadraticBezierVertices(
jvanverth@google.com8ffb7042012-12-13 19:53:18 +000072 float ax, float ay,
73 float bx, float by,
74 float cx, float cy,
75 float sqrInvScaleX, float sqrInvScaleY,
jvanverth@google.com24b4f972012-12-18 14:13:46 +000076 SkTArray<Vertex, true>* outputVertices);
jvanverth@google.com8ffb7042012-12-13 19:53:18 +000077
78/*
79 endpoints p1, p2
80 control c1, c2
81 */
jvanverth@google.com24b4f972012-12-18 14:13:46 +000082 static void RecursiveCubicBezierVertices(
jvanverth@google.com8ffb7042012-12-13 19:53:18 +000083 float p1x, float p1y,
84 float c1x, float c1y,
85 float p2x, float p2y,
86 float c2x, float c2y,
87 float sqrInvScaleX, float sqrInvScaleY,
jvanverth@google.com24b4f972012-12-18 14:13:46 +000088 SkTArray<Vertex, true>* outputVertices);
jvanverth@google.com8ffb7042012-12-13 19:53:18 +000089};
90
91}; // namespace uirenderer
92}; // namespace android
93
94#endif // ANDROID_HWUI_PATH_RENDERER_H