OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright 2010, Google Inc. |
| 3 * All rights reserved. |
| 4 * |
| 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions are |
| 7 * met: |
| 8 * |
| 9 * * Redistributions of source code must retain the above copyright |
| 10 * notice, this list of conditions and the following disclaimer. |
| 11 * * Redistributions in binary form must reproduce the above |
| 12 * copyright notice, this list of conditions and the following disclaimer |
| 13 * in the documentation and/or other materials provided with the |
| 14 * distribution. |
| 15 * * Neither the name of Google Inc. nor the names of its |
| 16 * contributors may be used to endorse or promote products derived from |
| 17 * this software without specific prior written permission. |
| 18 * |
| 19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 23 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 30 */ |
| 31 |
| 32 // The main entry point for Loop and Blinn's GPU accelerated curve |
| 33 // rendering algorithm. |
| 34 |
| 35 #ifndef O3D_CORE_CROSS_GPU2D_PATH_PROCESSOR_H_ |
| 36 #define O3D_CORE_CROSS_GPU2D_PATH_PROCESSOR_H_ |
| 37 |
| 38 #include <vector> |
| 39 |
| 40 #include "base/basictypes.h" |
| 41 |
| 42 class SkPath; |
| 43 |
| 44 namespace o3d { |
| 45 namespace gpu2d { |
| 46 |
| 47 class Arena; |
| 48 class Contour; |
| 49 class PathCache; |
| 50 class Segment; |
| 51 |
| 52 // The PathProcessor turns an SkPath (assumed to contain one or more |
| 53 // closed regions) into a set of exterior and interior triangles, |
| 54 // stored in the PathCache. The exterior triangles have associated 3D |
| 55 // texture coordinates which are used to evaluate the curve's |
| 56 // inside/outside function on a per-pixel basis. The interior |
| 57 // triangles are filled with 100% opacity. |
| 58 // |
| 59 // Note that the fill style and management of multiple layers are |
| 60 // separate concerns, handled at a higher level with shaders and |
| 61 // polygon offsets. |
| 62 class PathProcessor { |
| 63 public: |
| 64 PathProcessor(); |
| 65 explicit PathProcessor(Arena* arena); |
| 66 ~PathProcessor(); |
| 67 |
| 68 // Transforms the given path into a triangle mesh for rendering |
| 69 // using Loop and Blinn's shader, placing the result into the given |
| 70 // PathCache. |
| 71 void Process(const SkPath& path, PathCache* cache); |
| 72 |
| 73 // Enables or disables verbose logging in debug mode. |
| 74 void set_verbose_logging(bool on_or_off); |
| 75 |
| 76 private: |
| 77 // Builds a list of contours for the given path. |
| 78 void BuildContours(const SkPath& path); |
| 79 |
| 80 // Determines whether the left or right side of each contour should |
| 81 // be filled. |
| 82 void DetermineSidesToFill(); |
| 83 |
| 84 // Determines whether the given (closed) contour is oriented |
| 85 // clockwise or counterclockwise. |
| 86 void DetermineOrientation(Contour* contour); |
| 87 |
| 88 // Subdivides the curves so that there are no overlaps of the |
| 89 // triangles associated with the curves' control points. |
| 90 void SubdivideCurves(); |
| 91 |
| 92 // Helper function used during curve subdivision. |
| 93 void ConditionallySubdivide(Segment* seg, |
| 94 std::vector<Segment*>* next_segments); |
| 95 |
| 96 // Tessellates the interior regions of the contours. |
| 97 void TessellateInterior(PathCache* cache); |
| 98 |
| 99 // For debugging the orientation computation. Returns all of the |
| 100 // segments overlapping the given Y coordinate. |
| 101 std::vector<Segment*> AllSegmentsOverlappingY(float y); |
| 102 |
| 103 // For debugging the curve subdivision algorithm. Subdivides the |
| 104 // curves using an alternate, slow (O(n^3)) algorithm. |
| 105 void SubdivideCurvesSlow(); |
| 106 |
| 107 // Arena from which to allocate temporary objects. |
| 108 Arena* arena_; |
| 109 |
| 110 // Whether to delete the arena upon deletion of the PathProcessor. |
| 111 bool should_delete_arena_; |
| 112 |
| 113 // The contours described by the path. |
| 114 std::vector<Contour*> contours_; |
| 115 |
| 116 // Whether or not to perform verbose logging in debug mode. |
| 117 bool verbose_logging_; |
| 118 |
| 119 DISALLOW_COPY_AND_ASSIGN(PathProcessor); |
| 120 }; |
| 121 |
| 122 } // namespace gpu2d |
| 123 } // namespace o3d |
| 124 |
| 125 #endif // O3D_CORE_CROSS_GPU2D_PATH_PROCESSOR_H_ |
| 126 |
OLD | NEW |