blob: 28a5b9031edb3667d333a9567874bac1bae3cd83 [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 Craikcb4d6002012-09-25 12:00:29 -070074 static void convexPathPerimeterVertices(
Chris Craik710f46d2012-09-17 17:25:49 -070075 const SkPath &path,
Chris Craikcb4d6002012-09-25 12:00:29 -070076 float sqrInvScaleX, float sqrInvScaleY,
Chris Craik710f46d2012-09-17 17:25:49 -070077 Vector<Vertex> &outputVertices);
78
79/*
80 endpoints a & b,
81 control c
82 */
83 static void recursiveQuadraticBezierVertices(
Chris Craikcb4d6002012-09-25 12:00:29 -070084 float ax, float ay,
85 float bx, float by,
86 float cx, float cy,
87 float sqrInvScaleX, float sqrInvScaleY,
88 Vector<Vertex> &outputVertices);
Chris Craik710f46d2012-09-17 17:25:49 -070089
90/*
91 endpoints p1, p2
92 control c1, c2
93 */
94 static void recursiveCubicBezierVertices(
Chris Craikcb4d6002012-09-25 12:00:29 -070095 float p1x, float p1y,
96 float c1x, float c1y,
97 float p2x, float p2y,
98 float c2x, float c2y,
99 float sqrInvScaleX, float sqrInvScaleY,
100 Vector<Vertex> &outputVertices);
Chris Craik710f46d2012-09-17 17:25:49 -0700101};
102
103}; // namespace uirenderer
104}; // namespace android
105
106#endif // ANDROID_HWUI_PATH_RENDERER_H