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