blob: e9f347bda495ff6449d98bcda57284b0290f165a [file] [log] [blame]
Chris Craik710f46d2012-09-17 17:25:49 -07001/*
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_RENDERER_H
18#define ANDROID_HWUI_PATH_RENDERER_H
19
20#include <utils/Vector.h>
21
22#include "Vertex.h"
23
24namespace android {
25namespace uirenderer {
26
27class Matrix4;
28typedef Matrix4 mat4;
29
30class VertexBuffer {
31public:
32 VertexBuffer():
33 mBuffer(0),
34 mSize(0),
35 mCleanupMethod(0)
36 {}
37
Chris Craikcb4d6002012-09-25 12:00:29 -070038 ~VertexBuffer() {
Chris Craik710f46d2012-09-17 17:25:49 -070039 if (mCleanupMethod)
40 mCleanupMethod(mBuffer);
41 }
42
43 template <class TYPE>
Chris Craikcb4d6002012-09-25 12:00:29 -070044 TYPE* alloc(int size) {
Chris Craik710f46d2012-09-17 17:25:49 -070045 mSize = size;
46 mBuffer = (void*)new TYPE[size];
47 mCleanupMethod = &(cleanup<TYPE>);
48
49 return (TYPE*)mBuffer;
50 }
51
52 void* getBuffer() { return mBuffer; }
53 unsigned int getSize() { return mSize; }
54
55private:
56 template <class TYPE>
Chris Craikcb4d6002012-09-25 12:00:29 -070057 static void cleanup(void* buffer) {
Chris Craik710f46d2012-09-17 17:25:49 -070058 delete[] (TYPE*)buffer;
59 }
60
61 void* mBuffer;
62 unsigned int mSize;
63 void (*mCleanupMethod)(void*);
64};
65
66class PathRenderer {
67public:
Chris Craikcb4d6002012-09-25 12:00:29 -070068 static SkRect computePathBounds(const SkPath& path, const SkPaint* paint);
Chris Craik710f46d2012-09-17 17:25:49 -070069
Chris Craikcb4d6002012-09-25 12:00:29 -070070 static void convexPathVertices(const SkPath& path, const SkPaint* paint,
71 const mat4 *transform, VertexBuffer& vertexBuffer);
Chris Craik710f46d2012-09-17 17:25:49 -070072
73private:
Chris Craik780c1282012-10-04 14:10:49 -070074 static bool convexPathPerimeterVertices(const SkPath &path, bool forceClose,
75 float sqrInvScaleX, float sqrInvScaleY, Vector<Vertex> &outputVertices);
Chris Craik710f46d2012-09-17 17:25:49 -070076
77/*
78 endpoints a & b,
79 control c
80 */
81 static void recursiveQuadraticBezierVertices(
Chris Craikcb4d6002012-09-25 12:00:29 -070082 float ax, float ay,
83 float bx, float by,
84 float cx, float cy,
85 float sqrInvScaleX, float sqrInvScaleY,
86 Vector<Vertex> &outputVertices);
Chris Craik710f46d2012-09-17 17:25:49 -070087
88/*
89 endpoints p1, p2
90 control c1, c2
91 */
92 static void recursiveCubicBezierVertices(
Chris Craikcb4d6002012-09-25 12:00:29 -070093 float p1x, float p1y,
94 float c1x, float c1y,
95 float p2x, float p2y,
96 float c2x, float c2y,
97 float sqrInvScaleX, float sqrInvScaleY,
98 Vector<Vertex> &outputVertices);
Chris Craik710f46d2012-09-17 17:25:49 -070099};
100
101}; // namespace uirenderer
102}; // namespace android
103
104#endif // ANDROID_HWUI_PATH_RENDERER_H