jvanverth@google.com | 8ffb704 | 2012-12-13 19:53:18 +0000 | [diff] [blame^] | 1 | /* |
| 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 | |
| 15 | namespace android { |
| 16 | namespace uirenderer { |
| 17 | |
| 18 | class Matrix4; |
| 19 | typedef Matrix4 mat4; |
| 20 | |
| 21 | class VertexBuffer { |
| 22 | public: |
| 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 | |
| 46 | private: |
| 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 | |
| 57 | class PathRenderer { |
| 58 | public: |
| 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 | |
| 64 | private: |
| 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 |