2
* Copyright (C) 2011 Google Inc. All rights reserved.
4
* Redistribution and use in source and binary forms, with or without
5
* modification, are permitted provided that the following conditions
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.
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.
26
// The main entry point for Loop and Blinn's GPU accelerated curve
27
// rendering algorithm.
29
#ifndef LoopBlinnPathProcessor_h
30
#define LoopBlinnPathProcessor_h
32
#include <wtf/Noncopyable.h>
33
#include <wtf/PassRefPtr.h>
34
#include <wtf/RefPtr.h>
35
#include <wtf/Vector.h>
39
// We use a namespace for classes which are simply implementation
40
// details of the algorithm but which we need to reference from the
42
namespace LoopBlinnPathProcessorImplementation {
47
} // namespace LoopBlinnPathProcessorImplementation
50
class LoopBlinnPathCache;
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.
60
// Note that the fill style and management of multiple layers are
61
// separate concerns, handled at a higher level with shaders and
63
class LoopBlinnPathProcessor {
65
LoopBlinnPathProcessor();
66
explicit LoopBlinnPathProcessor(PassRefPtr<PODArena>);
67
~LoopBlinnPathProcessor();
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&);
75
// Enables or disables verbose logging in debug mode.
76
void setVerboseLogging(bool onOrOff);
80
// Builds a list of contours for the given path.
81
void buildContours(const Path&);
83
// Determines whether the left or right side of each contour should
85
void determineSidesToFill();
87
// Determines whether the given (closed) contour is oriented
88
// clockwise or counterclockwise.
89
void determineOrientation(LoopBlinnPathProcessorImplementation::Contour*);
91
// Subdivides the curves so that there are no overlaps of the
92
// triangles associated with the curves' control points.
93
void subdivideCurves();
95
// Helper function used during curve subdivision.
96
void conditionallySubdivide(LoopBlinnPathProcessorImplementation::Segment*,
97
Vector<LoopBlinnPathProcessorImplementation::Segment*>& nextSegments);
99
// Tessellates the interior regions of the contours.
100
void tessellateInterior(LoopBlinnPathCache&);
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);
107
// For debugging the curve subdivision algorithm. Subdivides the
108
// curves using an alternate, slow (O(n^3)) algorithm.
109
void subdivideCurvesSlow();
112
// PODArena from which to allocate temporary objects.
113
RefPtr<PODArena> m_arena;
115
// The contours described by the path.
116
Vector<LoopBlinnPathProcessorImplementation::Contour*> m_contours;
119
// Whether or not to perform verbose logging in debug mode.
120
bool m_verboseLogging;
124
} // namespace WebCore
126
#endif // LoopBlinnPathProcessor_h