Chris Craik | 710f46d | 2012-09-17 17:25:49 -0700 | [diff] [blame^] | 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: |
| 32 | VertexBuffer(): |
| 33 | mBuffer(0), |
| 34 | mSize(0), |
| 35 | mCleanupMethod(0) |
| 36 | {} |
| 37 | |
| 38 | ~VertexBuffer() |
| 39 | { |
| 40 | if (mCleanupMethod) |
| 41 | mCleanupMethod(mBuffer); |
| 42 | } |
| 43 | |
| 44 | template <class TYPE> |
| 45 | TYPE* alloc(int size) |
| 46 | { |
| 47 | mSize = size; |
| 48 | mBuffer = (void*)new TYPE[size]; |
| 49 | mCleanupMethod = &(cleanup<TYPE>); |
| 50 | |
| 51 | return (TYPE*)mBuffer; |
| 52 | } |
| 53 | |
| 54 | void* getBuffer() { return mBuffer; } |
| 55 | unsigned int getSize() { return mSize; } |
| 56 | |
| 57 | private: |
| 58 | template <class TYPE> |
| 59 | static void cleanup(void* buffer) |
| 60 | { |
| 61 | delete[] (TYPE*)buffer; |
| 62 | } |
| 63 | |
| 64 | void* mBuffer; |
| 65 | unsigned int mSize; |
| 66 | void (*mCleanupMethod)(void*); |
| 67 | }; |
| 68 | |
| 69 | class PathRenderer { |
| 70 | public: |
| 71 | static void computeInverseScales( |
| 72 | const mat4 *transform, float &inverseScaleX, float& inverseScaleY); |
| 73 | |
| 74 | static void convexPathFillVertices( |
| 75 | const SkPath &path, const mat4 *transform, |
| 76 | VertexBuffer &vertexBuffer, bool isAA); |
| 77 | |
| 78 | private: |
| 79 | static void convexPathVertices( |
| 80 | const SkPath &path, |
| 81 | float thresholdx, float thresholdy, |
| 82 | Vector<Vertex> &outputVertices); |
| 83 | |
| 84 | /* |
| 85 | endpoints a & b, |
| 86 | control c |
| 87 | */ |
| 88 | static void recursiveQuadraticBezierVertices( |
| 89 | float ax, float ay, |
| 90 | float bx, float by, |
| 91 | float cx, float cy, |
| 92 | float thresholdx, float thresholdy, |
| 93 | Vector<Vertex> &outputVertices); |
| 94 | |
| 95 | /* |
| 96 | endpoints p1, p2 |
| 97 | control c1, c2 |
| 98 | */ |
| 99 | static void recursiveCubicBezierVertices( |
| 100 | float p1x, float p1y, |
| 101 | float c1x, float c1y, |
| 102 | float p2x, float p2y, |
| 103 | float c2x, float c2y, |
| 104 | float thresholdx, float thresholdy, |
| 105 | Vector<Vertex> &outputVertices); |
| 106 | }; |
| 107 | |
| 108 | }; // namespace uirenderer |
| 109 | }; // namespace android |
| 110 | |
| 111 | #endif // ANDROID_HWUI_PATH_RENDERER_H |