diff options
author | kbr@chromium.org <kbr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-26 00:26:00 +0000 |
---|---|---|
committer | kbr@chromium.org <kbr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-26 00:26:00 +0000 |
commit | 00d721c144d35882dfaf24b3869e95a8d6404ee5 (patch) | |
tree | 07243b1cb15a7fb0eddf54fce686c96cda594640 /o3d/core/cross/gpu2d/path_cache.h | |
parent | 0a46d19ce396112b8a42005d1369de30df3bc872 (diff) | |
download | chromium_src-00d721c144d35882dfaf24b3869e95a8d6404ee5.zip chromium_src-00d721c144d35882dfaf24b3869e95a8d6404ee5.tar.gz chromium_src-00d721c144d35882dfaf24b3869e95a8d6404ee5.tar.bz2 |
Added the bulk of the algorithm for GPU accelerated 2D vector curve
rendering from "Rendering Vector Art on the GPU" by Loop and Blinn,
GPU Gems 3, Chapter 25.
The main entry point to the algorithm is the PathProcessor, which
takes in a Skia path and converts it to two triangle meshes: one for
the exterior region of the shape containing the curve segments, and
one for the interior region of the shape which is filled with constant
(1.0) alpha.
The o3d.ProcessedPath class is the internal object which exposes the
needed entry points to JavaScript. However, o3djs.gpu2d is the
user-level entry point to the algorithm. This exposes a Path primitive
to which line, quadratic curve and cubic curve segments can be added,
and simple fills (currently only a solid color).
An SVG loader in samples/gpu2d/svgloader.js illustrates how content
might be imported at run time. Several samples and regression tests
demonstrate the current state of the implementation. More work is
planned.
Some small generalizations to the O3D code were necessary to support
two-dimensional vertices.
Note that I plan to submit gpu2d.js and/or svgloader.js for JavaScript
readability. I have run both through the JS compiler and have fixed as
many of the doc generation errors as possible in svgloader.js without
pulling this file into the o3djs namespace.
Tested in O3D on Windows and Mac OS X.
BUG=none
TEST=various SVG based tests
Review URL: http://codereview.chromium.org/652016
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@40079 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'o3d/core/cross/gpu2d/path_cache.h')
-rw-r--r-- | o3d/core/cross/gpu2d/path_cache.h | 120 |
1 files changed, 120 insertions, 0 deletions
diff --git a/o3d/core/cross/gpu2d/path_cache.h b/o3d/core/cross/gpu2d/path_cache.h new file mode 100644 index 0000000..93ba86c0 --- /dev/null +++ b/o3d/core/cross/gpu2d/path_cache.h @@ -0,0 +1,120 @@ +/* + * Copyright 2010, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef O3D_CORE_CROSS_GPU2D_PATH_CACHE_H_ +#define O3D_CORE_CROSS_GPU2D_PATH_CACHE_H_ + +#include <vector> + +#include "base/basictypes.h" + +namespace o3d { +namespace gpu2d { + +// A cache of the processed triangle mesh for a given path. Because +// these might be expensive to allocate (using malloc/free +// internally), it is recommended to try to reuse them when possible. + +// Uncomment the following to obtain debugging information for the edges facing +// the interior region of the mesh. +// #define O3D_CORE_CROSS_GPU2D_PATH_CACHE_DEBUG_INTERIOR_EDGES + +class PathCache { + public: + PathCache() { + } + + // The number of vertices in the mesh. + unsigned int num_vertices() const; + + // Get the base pointer to the vertex information. There are two + // coordinates per vertex. This pointer is valid until the cache is + // cleared or another vertex is added. Returns NULL if there are no + // vertices in the mesh. + const float* vertices() const; + + // Get the base pointer to the texture coordinate information. There + // are three coordinates per vertex. This pointer is valid until the + // cache is cleared or another vertex is added. Returns NULL if + // there are no vertices in the mesh. + const float* texcoords() const; + + // Adds a vertex's information to the cache. The first two arguments + // are the x and y coordinates of the vertex on the plane; the last + // three arguments are the cubic texture coordinates associated with + // this vertex. + void AddVertex(float x, float y, + float k, float l, float m); + + // The number of interior vertices. + unsigned int num_interior_vertices() const; + // Base pointer to the interior vertices; two coordinates per + // vertex, which can be drawn as GL_TRIANGLES. Returns NULL if there + // are no interior vertices in the mesh. + const float* interior_vertices() const; + // Adds an interior vertex to the cache. + void AddInteriorVertex(float x, float y); + + // Clears all of the stored vertex information in this cache. + void Clear(); + +#ifdef O3D_CORE_CROSS_GPU2D_PATH_CACHE_DEBUG_INTERIOR_EDGES + // The number of interior edge vertices + unsigned int num_interior_edge_vertices() const; + // Base pointer to the interior vertices; two coordinates per + // vertex, which can be drawn as GL_LINES. Returns NULL if there are + // no interior edge vertices in the mesh. + const float* interior_edge_vertices() const; + void AddInteriorEdgeVertex(float x, float y); +#endif // O3D_CORE_CROSS_GPU2D_PATH_CACHE_DEBUG_INTERIOR_EDGES + + private: + // The two-dimensional vertices of the triangle mesh. + std::vector<float> vertices_; + + // The three-dimensional cubic texture coordinates. + std::vector<float> texcoords_; + + std::vector<float> interior_vertices_; + +#ifdef O3D_CORE_CROSS_GPU2D_PATH_CACHE_DEBUG_INTERIOR_EDGES + // The following is only for debugging + std::vector<float> interior_edge_vertices_; +#endif // O3D_CORE_CROSS_GPU2D_PATH_CACHE_DEBUG_INTERIOR_EDGES + + DISALLOW_COPY_AND_ASSIGN(PathCache); +}; + +} // namespace gpu2d +} // namespace o3d + +#endif // O3D_CORE_CROSS_GPU2D_PATH_CACHE_H_ + |