1 /* 2 * Copyright (C) 2011 Google Inc. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY 15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY 18 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 19 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 20 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 21 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 */ 25 26 // The main entry point for Loop and Blinn's GPU accelerated curve 27 // rendering algorithm. 28 29 #ifndef LoopBlinnPathProcessor_h 30 #define LoopBlinnPathProcessor_h 31 32 #include <wtf/Noncopyable.h> 33 #include <wtf/PassRefPtr.h> 34 #include <wtf/RefPtr.h> 35 #include <wtf/Vector.h> 36 37 namespace WebCore { 38 39 // We use a namespace for classes which are simply implementation 40 // details of the algorithm but which we need to reference from the 41 // class definition. 42 namespace LoopBlinnPathProcessorImplementation { 43 44 class Contour; 45 class Segment; 46 47 } // namespace LoopBlinnPathProcessorImplementation 48 49 class Path; 50 class LoopBlinnPathCache; 51 class PODArena; 52 53 // The LoopBlinnPathProcessor turns a Path (assumed to contain one or 54 // more closed regions) into a set of exterior and interior triangles, 55 // stored in the LoopBlinnPathCache. The exterior triangles have 56 // associated 3D texture coordinates which are used to evaluate the 57 // curve's inside/outside function on a per-pixel basis. The interior 58 // triangles are filled with 100% opacity. 59 // 60 // Note that the fill style and management of multiple layers are 61 // separate concerns, handled at a higher level with shaders and 62 // polygon offsets. 63 class LoopBlinnPathProcessor { 64 public: 65 LoopBlinnPathProcessor(); 66 explicit LoopBlinnPathProcessor(PassRefPtr<PODArena>); 67 ~LoopBlinnPathProcessor(); 68 69 // Transforms the given path into a triangle mesh for rendering 70 // using Loop and Blinn's shader, placing the result into the given 71 // LoopBlinnPathCache. 72 void process(const Path&, LoopBlinnPathCache&); 73 74 #ifndef NDEBUG 75 // Enables or disables verbose logging in debug mode. 76 void setVerboseLogging(bool onOrOff); 77 #endif 78 79 private: 80 // Builds a list of contours for the given path. 81 void buildContours(const Path&); 82 83 // Determines whether the left or right side of each contour should 84 // be filled. 85 void determineSidesToFill(); 86 87 // Determines whether the given (closed) contour is oriented 88 // clockwise or counterclockwise. 89 void determineOrientation(LoopBlinnPathProcessorImplementation::Contour*); 90 91 // Subdivides the curves so that there are no overlaps of the 92 // triangles associated with the curves' control points. 93 void subdivideCurves(); 94 95 // Helper function used during curve subdivision. 96 void conditionallySubdivide(LoopBlinnPathProcessorImplementation::Segment*, 97 Vector<LoopBlinnPathProcessorImplementation::Segment*>& nextSegments); 98 99 // Tessellates the interior regions of the contours. 100 void tessellateInterior(LoopBlinnPathCache&); 101 102 #ifndef NDEBUG 103 // For debugging the orientation computation. Returns all of the 104 // segments overlapping the given Y coordinate. 105 Vector<LoopBlinnPathProcessorImplementation::Segment*> allSegmentsOverlappingY(LoopBlinnPathProcessorImplementation::Contour*, float x, float y); 106 107 // For debugging the curve subdivision algorithm. Subdivides the 108 // curves using an alternate, slow (O(n^3)) algorithm. 109 void subdivideCurvesSlow(); 110 #endif 111 112 // PODArena from which to allocate temporary objects. 113 RefPtr<PODArena> m_arena; 114 115 // The contours described by the path. 116 Vector<LoopBlinnPathProcessorImplementation::Contour*> m_contours; 117 118 #ifndef NDEBUG 119 // Whether or not to perform verbose logging in debug mode. 120 bool m_verboseLogging; 121 #endif 122 }; 123 124 } // namespace WebCore 125 126 #endif // LoopBlinnPathProcessor_h 127