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 #ifndef LoopBlinnPathCache_h
27 #define LoopBlinnPathCache_h
29 #include <wtf/Noncopyable.h>
30 #include <wtf/Vector.h>
34 // A cache of the processed triangle mesh for a given path. Because these
35 // might be expensive to allocate (using malloc/free internally), it is
36 // recommended to try to reuse them when possible.
38 // Uncomment the following to obtain debugging information for the edges
39 // facing the interior region of the mesh.
40 // #define LOOP_BLINN_PATH_CACHE_DEBUG_INTERIOR_EDGES
42 class LoopBlinnPathCache {
43 WTF_MAKE_NONCOPYABLE(LoopBlinnPathCache);
46 ~LoopBlinnPathCache();
48 unsigned numberOfVertices() const { return m_vertices.size() / 2; }
50 // Get the base pointer to the vertex information. There are two
51 // coordinates per vertex. This pointer is valid until the cache is
52 // cleared or another vertex is added. Returns 0 if there are no
53 // vertices in the mesh.
54 const float* vertices() const
56 if (!numberOfVertices())
58 return m_vertices.data();
61 // Get the base pointer to the texture coordinate information. There
62 // are three coordinates per vertex. This pointer is valid until the
63 // cache is cleared or another vertex is added. Returns 0 if
64 // there are no vertices in the mesh.
65 const float* texcoords() const
67 if (!numberOfVertices())
69 return m_texcoords.data();
72 // Adds a vertex's information to the cache. The first two arguments
73 // are the x and y coordinates of the vertex on the plane; the last
74 // three arguments are the cubic texture coordinates associated with
76 void addVertex(float x, float y,
77 float /*k*/, float /*l*/, float /*m*/);
79 unsigned numberOfInteriorVertices() const { return m_interiorVertices.size() / 2; }
81 // Base pointer to the interior vertices; two coordinates per
82 // vertex, which can be drawn as GL_TRIANGLES. Returns 0 if there
83 // are no interior vertices in the mesh.
84 const float* interiorVertices() const
86 if (!numberOfInteriorVertices())
88 return m_interiorVertices.data();
91 void addInteriorVertex(float x, float y);
93 // Clears all of the stored vertex information in this cache.
96 #ifdef LOOP_BLINN_PATH_CACHE_DEBUG_INTERIOR_EDGES
97 // The number of interior edge vertices
98 unsigned numberOfInteriorEdgeVertices() const;
99 // Base pointer to the interior vertices; two coordinates per
100 // vertex, which can be drawn as GL_LINES. Returns 0 if there are
101 // no interior edge vertices in the mesh.
102 const float* interiorEdgeVertices() const;
103 void addInteriorEdgeVertex(float x, float y);
104 #endif // LOOP_BLINN_PATH_CACHE_DEBUG_INTERIOR_EDGES
107 // The two-dimensional vertices of the triangle mesh.
108 Vector<float> m_vertices;
110 // The three-dimensional cubic texture coordinates.
111 Vector<float> m_texcoords;
113 Vector<float> m_interiorVertices;
115 #ifdef LOOP_BLINN_PATH_CACHE_DEBUG_INTERIOR_EDGES
116 // The following is only for debugging
117 Vector<float> m_interiorEdgeVertices;
118 #endif // LOOP_BLINN_PATH_CACHE_DEBUG_INTERIOR_EDGES
121 } // namespace WebCore
123 #endif // LoopBlinnPathCache_h