• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 
24 namespace android {
25 namespace uirenderer {
26 
27 class Matrix4;
28 typedef Matrix4 mat4;
29 
30 class VertexBuffer {
31 public:
VertexBuffer()32     VertexBuffer():
33         mBuffer(0),
34         mSize(0),
35         mCleanupMethod(0)
36     {}
37 
~VertexBuffer()38     ~VertexBuffer() {
39         if (mCleanupMethod)
40             mCleanupMethod(mBuffer);
41     }
42 
43     template <class TYPE>
alloc(int size)44     TYPE* alloc(int size) {
45         mSize = size;
46         mBuffer = (void*)new TYPE[size];
47         mCleanupMethod = &(cleanup<TYPE>);
48 
49         return (TYPE*)mBuffer;
50     }
51 
getBuffer()52     void* getBuffer() { return mBuffer; }
getSize()53     unsigned int getSize() { return mSize; }
54 
55 private:
56     template <class TYPE>
cleanup(void * buffer)57     static void cleanup(void* buffer) {
58         delete[] (TYPE*)buffer;
59     }
60 
61     void* mBuffer;
62     unsigned int mSize;
63     void (*mCleanupMethod)(void*);
64 };
65 
66 class PathRenderer {
67 public:
68     static SkRect computePathBounds(const SkPath& path, const SkPaint* paint);
69 
70     static void convexPathVertices(const SkPath& path, const SkPaint* paint,
71             const mat4 *transform, VertexBuffer& vertexBuffer);
72 
73 private:
74     static bool convexPathPerimeterVertices(const SkPath &path, bool forceClose,
75         float sqrInvScaleX, float sqrInvScaleY, Vector<Vertex> &outputVertices);
76 
77 /*
78   endpoints a & b,
79   control c
80  */
81     static void recursiveQuadraticBezierVertices(
82             float ax, float ay,
83             float bx, float by,
84             float cx, float cy,
85             float sqrInvScaleX, float sqrInvScaleY,
86             Vector<Vertex> &outputVertices);
87 
88 /*
89   endpoints p1, p2
90   control c1, c2
91  */
92     static void recursiveCubicBezierVertices(
93             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);
99 };
100 
101 }; // namespace uirenderer
102 }; // namespace android
103 
104 #endif // ANDROID_HWUI_PATH_RENDERER_H
105