blob: a17ce9b6e33044d7c918c8f3a4395c1438df27d2 [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
11#include <utils/Vector.h>
12
13#include "Vertex.h"
14
15namespace android {
16namespace uirenderer {
17
18class Matrix4;
19typedef Matrix4 mat4;
20
21class VertexBuffer {
22public:
23 VertexBuffer():
24 mBuffer(0),
25 mSize(0),
26 mCleanupMethod(0)
27 {}
28
29 ~VertexBuffer() {
30 if (mCleanupMethod)
31 mCleanupMethod(mBuffer);
32 }
33
34 template <class TYPE>
35 TYPE* alloc(int size) {
36 mSize = size;
37 mBuffer = (void*)new TYPE[size];
38 mCleanupMethod = &(cleanup<TYPE>);
39
40 return (TYPE*)mBuffer;
41 }
42
43 void* getBuffer() { return mBuffer; }
44 unsigned int getSize() { return mSize; }
45
46private:
47 template <class TYPE>
48 static void cleanup(void* buffer) {
49 delete[] (TYPE*)buffer;
50 }
51
52 void* mBuffer;
53 unsigned int mSize;
54 void (*mCleanupMethod)(void*);
55};
56
57class PathRenderer {
58public:
59 static SkRect computePathBounds(const SkPath& path, const SkPaint* paint);
60
61 static void convexPathVertices(const SkPath& path, const SkPaint* paint,
62 const mat4 *transform, VertexBuffer& vertexBuffer);
63
64private:
65 static bool convexPathPerimeterVertices(const SkPath &path, bool forceClose,
66 float sqrInvScaleX, float sqrInvScaleY, Vector<Vertex> &outputVertices);
67
68/*
69 endpoints a & b,
70 control c
71 */
72 static void recursiveQuadraticBezierVertices(
73 float ax, float ay,
74 float bx, float by,
75 float cx, float cy,
76 float sqrInvScaleX, float sqrInvScaleY,
77 Vector<Vertex> &outputVertices);
78
79/*
80 endpoints p1, p2
81 control c1, c2
82 */
83 static void recursiveCubicBezierVertices(
84 float p1x, float p1y,
85 float c1x, float c1y,
86 float p2x, float p2y,
87 float c2x, float c2y,
88 float sqrInvScaleX, float sqrInvScaleY,
89 Vector<Vertex> &outputVertices);
90};
91
92}; // namespace uirenderer
93}; // namespace android
94
95#endif // ANDROID_HWUI_PATH_RENDERER_H