1e9709e831954c3427d5cb839e84221a177bfedebethannicholas/*
2e9709e831954c3427d5cb839e84221a177bfedebethannicholas * Copyright 2015 Google Inc.
3e9709e831954c3427d5cb839e84221a177bfedebethannicholas *
4e9709e831954c3427d5cb839e84221a177bfedebethannicholas * Use of this source code is governed by a BSD-style license that can be
5e9709e831954c3427d5cb839e84221a177bfedebethannicholas * found in the LICENSE file.
6e9709e831954c3427d5cb839e84221a177bfedebethannicholas */
7e9709e831954c3427d5cb839e84221a177bfedebethannicholas
8e9709e831954c3427d5cb839e84221a177bfedebethannicholas#ifndef GrTessellator_DEFINED
9e9709e831954c3427d5cb839e84221a177bfedebethannicholas#define GrTessellator_DEFINED
10e9709e831954c3427d5cb839e84221a177bfedebethannicholas
11f57372daf0562a187c24d427366ac6d0cb980c9bsenorblanco#include "GrColor.h"
126599efffeef3168dfc68dca99c30454c5c23b859senorblanco#include "SkPoint.h"
136599efffeef3168dfc68dca99c30454c5c23b859senorblanco
146599efffeef3168dfc68dca99c30454c5c23b859senorblancoclass SkPath;
156599efffeef3168dfc68dca99c30454c5c23b859senorblancostruct SkRect;
16e9709e831954c3427d5cb839e84221a177bfedebethannicholas
17e9709e831954c3427d5cb839e84221a177bfedebethannicholas/**
18e9709e831954c3427d5cb839e84221a177bfedebethannicholas * Provides utility functions for converting paths to a collection of triangles.
19e9709e831954c3427d5cb839e84221a177bfedebethannicholas */
20e9709e831954c3427d5cb839e84221a177bfedebethannicholas
21e9709e831954c3427d5cb839e84221a177bfedebethannicholas#define TESSELLATOR_WIREFRAME 0
22e9709e831954c3427d5cb839e84221a177bfedebethannicholas
23e9709e831954c3427d5cb839e84221a177bfedebethannicholasnamespace GrTessellator {
24e9709e831954c3427d5cb839e84221a177bfedebethannicholas
256599efffeef3168dfc68dca99c30454c5c23b859senorblancoclass VertexAllocator {
266599efffeef3168dfc68dca99c30454c5c23b859senorblancopublic:
27f57372daf0562a187c24d427366ac6d0cb980c9bsenorblanco    VertexAllocator(size_t stride) : fStride(stride) {}
286599efffeef3168dfc68dca99c30454c5c23b859senorblanco    virtual ~VertexAllocator() {}
29f57372daf0562a187c24d427366ac6d0cb980c9bsenorblanco    virtual void* lock(int vertexCount) = 0;
306599efffeef3168dfc68dca99c30454c5c23b859senorblanco    virtual void unlock(int actualCount) = 0;
31f57372daf0562a187c24d427366ac6d0cb980c9bsenorblanco    size_t stride() const { return fStride; }
32f57372daf0562a187c24d427366ac6d0cb980c9bsenorblancoprivate:
33f57372daf0562a187c24d427366ac6d0cb980c9bsenorblanco    size_t fStride;
346599efffeef3168dfc68dca99c30454c5c23b859senorblanco};
356599efffeef3168dfc68dca99c30454c5c23b859senorblanco
36e9709e831954c3427d5cb839e84221a177bfedebethannicholasstruct WindingVertex {
37e9709e831954c3427d5cb839e84221a177bfedebethannicholas    SkPoint fPos;
38e9709e831954c3427d5cb839e84221a177bfedebethannicholas    int fWinding;
39e9709e831954c3427d5cb839e84221a177bfedebethannicholas};
40e9709e831954c3427d5cb839e84221a177bfedebethannicholas
41e9709e831954c3427d5cb839e84221a177bfedebethannicholas// Triangulates a path to an array of vertices. Each triangle is represented as a set of three
42e9709e831954c3427d5cb839e84221a177bfedebethannicholas// WindingVertex entries, each of which contains the position and winding count (which is the same
43e9709e831954c3427d5cb839e84221a177bfedebethannicholas// for all three vertices of a triangle). The 'verts' out parameter is set to point to the resultant
44e9709e831954c3427d5cb839e84221a177bfedebethannicholas// vertex array. CALLER IS RESPONSIBLE for deleting this buffer to avoid a memory leak!
459d524f22bfde5dc3dc8f48e1be39bdebd3bb0304halcanaryint PathToVertices(const SkPath& path, SkScalar tolerance, const SkRect& clipBounds,
46e9709e831954c3427d5cb839e84221a177bfedebethannicholas                   WindingVertex** verts);
47e9709e831954c3427d5cb839e84221a177bfedebethannicholas
48f57372daf0562a187c24d427366ac6d0cb980c9bsenorblancoint PathToTriangles(const SkPath& path, SkScalar tolerance, const SkRect& clipBounds,
49f57372daf0562a187c24d427366ac6d0cb980c9bsenorblanco                    VertexAllocator*, bool antialias, const GrColor& color,
50f57372daf0562a187c24d427366ac6d0cb980c9bsenorblanco                    bool canTweakAlphaForCoverage, bool *isLinear);
51e9709e831954c3427d5cb839e84221a177bfedebethannicholas}
52e9709e831954c3427d5cb839e84221a177bfedebethannicholas
53e9709e831954c3427d5cb839e84221a177bfedebethannicholas#endif
54