GrDrawTarget.h revision 73d98aace4f74acc39d8de33484c8aec8e917739
1ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com
2ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com/*
3ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Copyright 2010 Google Inc.
4ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com *
5ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Use of this source code is governed by a BSD-style license that can be
6ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * found in the LICENSE file.
7ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com */
8ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com
9ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com
10ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com
11ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com#ifndef GrDrawTarget_DEFINED
12ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com#define GrDrawTarget_DEFINED
13ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com
14aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.com#include "GrClip.h"
15ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com#include "GrColor.h"
169381363050ec9d3e724076a8e9152bfa9a8de1d1tomhudson@google.com#include "GrDrawState.h"
17aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.com#include "GrMatrix.h"
18ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com#include "GrRefCnt.h"
19ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com#include "GrSamplerState.h"
20d302f1401b3c9aea094804bad4e76de98782cfe8bsalomon@google.com#include "GrStencil.h"
21aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.com#include "GrTexture.h"
22ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com
2397c88c255cff3dbb8343c5d090526fdbedad6dd6Scroggo#include "SkXfermode.h"
2446f7afb9867200b568c21736da8a8bbb56b20e30bsalomon@google.com#include "SkTLazy.h"
2597c88c255cff3dbb8343c5d090526fdbedad6dd6Scroggo
26ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.comclass GrTexture;
27ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.comclass GrClipIterator;
28ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.comclass GrVertexBuffer;
29ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.comclass GrIndexBuffer;
30ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com
31ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.comclass GrDrawTarget : public GrRefCnt {
32ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.compublic:
33ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com    /**
3418c9c198f571997463d9a7134dbd88298e592ec2bsalomon@google.com     * Represents the draw target capabilities.
3518c9c198f571997463d9a7134dbd88298e592ec2bsalomon@google.com     */
3618c9c198f571997463d9a7134dbd88298e592ec2bsalomon@google.com    struct Caps {
3718c9c198f571997463d9a7134dbd88298e592ec2bsalomon@google.com        Caps() { memset(this, 0, sizeof(Caps)); }
3818c9c198f571997463d9a7134dbd88298e592ec2bsalomon@google.com        Caps(const Caps& c) { *this = c; }
3918c9c198f571997463d9a7134dbd88298e592ec2bsalomon@google.com        Caps& operator= (const Caps& c) {
4018c9c198f571997463d9a7134dbd88298e592ec2bsalomon@google.com            memcpy(this, &c, sizeof(Caps));
4118c9c198f571997463d9a7134dbd88298e592ec2bsalomon@google.com            return *this;
4218c9c198f571997463d9a7134dbd88298e592ec2bsalomon@google.com        }
4318c9c198f571997463d9a7134dbd88298e592ec2bsalomon@google.com        void print() const;
4418c9c198f571997463d9a7134dbd88298e592ec2bsalomon@google.com        bool f8BitPaletteSupport        : 1;
4518c9c198f571997463d9a7134dbd88298e592ec2bsalomon@google.com        bool fNPOTTextureTileSupport    : 1;
4618c9c198f571997463d9a7134dbd88298e592ec2bsalomon@google.com        bool fTwoSidedStencilSupport    : 1;
4718c9c198f571997463d9a7134dbd88298e592ec2bsalomon@google.com        bool fStencilWrapOpsSupport     : 1;
4818c9c198f571997463d9a7134dbd88298e592ec2bsalomon@google.com        bool fHWAALineSupport           : 1;
4918c9c198f571997463d9a7134dbd88298e592ec2bsalomon@google.com        bool fShaderDerivativeSupport   : 1;
50edfe1aac5c6f3a3f3830e86ddea8dbceeb0e6df4bsalomon@google.com        bool fGeometryShaderSupport     : 1;
5118c9c198f571997463d9a7134dbd88298e592ec2bsalomon@google.com        bool fFSAASupport               : 1;
5218c9c198f571997463d9a7134dbd88298e592ec2bsalomon@google.com        bool fDualSourceBlendingSupport : 1;
5318c9c198f571997463d9a7134dbd88298e592ec2bsalomon@google.com        bool fBufferLockSupport         : 1;
5418c9c198f571997463d9a7134dbd88298e592ec2bsalomon@google.com        int fMaxRenderTargetSize;
5518c9c198f571997463d9a7134dbd88298e592ec2bsalomon@google.com        int fMaxTextureSize;
5618c9c198f571997463d9a7134dbd88298e592ec2bsalomon@google.com    };
5718c9c198f571997463d9a7134dbd88298e592ec2bsalomon@google.com
588f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com    // for convenience
5939ee0ffa72fbd5df6d3ec6db4fdad0c1bc3946fdbsalomon@google.com    typedef GrDrawState::StageMask StageMask;
60ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com
61ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com    ///////////////////////////////////////////////////////////////////////////
62ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com
63ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com    GrDrawTarget();
6425fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com    virtual ~GrDrawTarget();
65ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com
66ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com    /**
6718c9c198f571997463d9a7134dbd88298e592ec2bsalomon@google.com     * Gets the capabilities of the draw target.
6818c9c198f571997463d9a7134dbd88298e592ec2bsalomon@google.com     */
6918c9c198f571997463d9a7134dbd88298e592ec2bsalomon@google.com    const Caps& getCaps() const { return fCaps; }
7018c9c198f571997463d9a7134dbd88298e592ec2bsalomon@google.com
7118c9c198f571997463d9a7134dbd88298e592ec2bsalomon@google.com    /**
72ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     * Sets the current clip to the region specified by clip. All draws will be
73ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     * clipped against this clip if kClip_StateBit is enabled.
74ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     *
755aaa69e4339e229adfb05e96084a8ec0a590238bbsalomon@google.com     * Setting the clip may (or may not) zero out the client's stencil bits.
765aaa69e4339e229adfb05e96084a8ec0a590238bbsalomon@google.com     *
77ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     * @param description of the clipping region
78ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     */
79ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com    void setClip(const GrClip& clip);
80ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com
81ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com    /**
82ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     * Gets the current clip.
83ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     *
84ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     * @return the clip.
85ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     */
86ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com    const GrClip& getClip() const;
87ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com
888f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com    const GrDrawState& getDrawState() const { return fCurrDrawState; }
898f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com    GrDrawState* drawState() { return &fCurrDrawState; }
903d0835b6ac0003c18147b6e9ca76a497b92d1d40bsalomon@google.com
913d0835b6ac0003c18147b6e9ca76a497b92d1d40bsalomon@google.com    /**
928f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com     * Shortcut for drawState()->preConcatSamplerMatrices() on all enabled
938f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com     * stages
943d0835b6ac0003c18147b6e9ca76a497b92d1d40bsalomon@google.com     *
953d0835b6ac0003c18147b6e9ca76a497b92d1d40bsalomon@google.com     * @param matrix  the matrix to concat
963d0835b6ac0003c18147b6e9ca76a497b92d1d40bsalomon@google.com     */
973d0835b6ac0003c18147b6e9ca76a497b92d1d40bsalomon@google.com    void preConcatEnabledSamplerMatrices(const GrMatrix& matrix) {
983d0835b6ac0003c18147b6e9ca76a497b92d1d40bsalomon@google.com        StageMask stageMask = this->enabledStages();
998f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com        this->drawState()->preConcatSamplerMatrices(stageMask, matrix);
1003d0835b6ac0003c18147b6e9ca76a497b92d1d40bsalomon@google.com    }
1013d0835b6ac0003c18147b6e9ca76a497b92d1d40bsalomon@google.com
1023d0835b6ac0003c18147b6e9ca76a497b92d1d40bsalomon@google.com    /**
10386c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com     * Determines if blending will require a read of a dst given the current
10486c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com     * state set on the draw target
105a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com     *
10686c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com     * @return true if the dst surface will be read at each pixel hit by the
10786c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com     *         a draw operation.
108a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com     */
10986c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com    bool drawWillReadDst() const;
110a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com
111a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com    /**
112a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com     * Color alpha and coverage are two inputs to the drawing pipeline. For some
113a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com     * blend modes it is safe to fold the coverage into constant or per-vertex
114a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com     * color alpha value. For other blend modes they must be handled separately.
115a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com     * Depending on features available in the underlying 3D API this may or may
116a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com     * not be possible.
117a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com     *
118a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com     * This function looks at the current blend on the draw target and the draw
119a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com     * target's capabilities to determine whether coverage can be handled
120a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com     * correctly.
121a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com     */
122a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com    bool canApplyCoverage() const;
123a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com
124a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com    /**
125a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com     * Determines whether incorporating partial pixel coverage into the constant
126a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com     * color specified by setColor or per-vertex colors will give the right
127a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com     * blending result.
128a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com     */
12986c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com    bool canTweakAlphaForCoverage() const;
130a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com
131a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com    /**
132a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com     * Given the current draw state, vertex layout, and hw support, will HW AA
133a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com     * lines be used (if line primitive type is drawn)? (Note that lines are
134a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com     * always 1 pixel wide)
135a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com     */
1369381363050ec9d3e724076a8e9152bfa9a8de1d1tomhudson@google.com    bool willUseHWAALines() const;
137a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com
1383d0835b6ac0003c18147b6e9ca76a497b92d1d40bsalomon@google.com    /**
139ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     * Used to save and restore the GrGpu's drawing state
140ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     */
141ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com    struct SavedDrawState {
142ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com    private:
14346f7afb9867200b568c21736da8a8bbb56b20e30bsalomon@google.com        SkTLazy<GrDrawState> fState;
144ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com        friend class GrDrawTarget;
145ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com    };
146ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com
147ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com    /**
148ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     * Saves the current draw state. The state can be restored at a later time
149ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     * with restoreDrawState.
150ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     *
151ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     * See also AutoStateRestore class.
152ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     *
153ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     * @param   state will hold the state after the function returns.
154ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     */
155ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com    void saveCurrentDrawState(SavedDrawState* state) const;
156ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com
157ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com    /**
158ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     * Restores previously saved draw state. The client guarantees that state
159ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     * was previously passed to saveCurrentDrawState and that the rendertarget
160ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     * and texture set at save are still valid.
161ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     *
162ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     * See also AutoStateRestore class.
163ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     *
164ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     * @param   state the previously saved state to restore.
165ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     */
166ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com    void restoreDrawState(const SavedDrawState& state);
167ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com
168ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com    /**
169ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     * Copies the draw state from another target to this target.
170ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     *
171ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     * @param srcTarget     draw target used as src of the draw state.
172ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     */
173ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com    void copyDrawState(const GrDrawTarget& srcTarget);
174ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com
175ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com    /**
1768531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com     * The format of vertices is represented as a bitfield of flags.
1778531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com     * Flags that indicate the layout of vertex data. Vertices always contain
1789381363050ec9d3e724076a8e9152bfa9a8de1d1tomhudson@google.com     * positions and may also contain up to GrDrawState::kMaxTexCoords sets
1799381363050ec9d3e724076a8e9152bfa9a8de1d1tomhudson@google.com     * of 2D texture * coordinates, per-vertex colors, and per-vertex coverage.
1809381363050ec9d3e724076a8e9152bfa9a8de1d1tomhudson@google.com     * Each stage can
181a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com     * use any of the texture coordinates as its input texture coordinates or it
182a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com     * may use the positions as texture coordinates.
1838531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com     *
1848531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com     * If no texture coordinates are specified for a stage then the stage is
1858531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com     * disabled.
186ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     *
1878531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com     * Only one type of texture coord can be specified per stage. For
1885782d712ffc31557d0cb12d5a220cebb783f6895bsalomon@google.com     * example StageTexCoordVertexLayoutBit(0, 2) and
1898531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com     * StagePosAsTexCoordVertexLayoutBit(0) cannot both be specified.
190ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     *
191a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com     * The order in memory is always (position, texture coord 0, ..., color,
192a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com     * coverage) with any unused fields omitted. Note that this means that if
193a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com     * only texture coordinates 1 is referenced then there is no texture
194a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com     * coordinates 0 and the order would be (position, texture coordinate 1
195a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com     * [, color][, coverage]).
1968531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com     */
1975782d712ffc31557d0cb12d5a220cebb783f6895bsalomon@google.com
1988531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com    /**
1998531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com     * Generates a bit indicating that a texture stage uses texture coordinates
2005782d712ffc31557d0cb12d5a220cebb783f6895bsalomon@google.com     *
2018531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com     * @param stage       the stage that will use texture coordinates.
2028531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com     * @param texCoordIdx the index of the texture coordinates to use
203ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     *
2048531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com     * @return the bit to add to a GrVertexLayout bitfield.
2058531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com     */
2068531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com    static int StageTexCoordVertexLayoutBit(int stage, int texCoordIdx) {
2079381363050ec9d3e724076a8e9152bfa9a8de1d1tomhudson@google.com        GrAssert(stage < GrDrawState::kNumStages);
2089381363050ec9d3e724076a8e9152bfa9a8de1d1tomhudson@google.com        GrAssert(texCoordIdx < GrDrawState::kMaxTexCoords);
2099381363050ec9d3e724076a8e9152bfa9a8de1d1tomhudson@google.com        return 1 << (stage + (texCoordIdx * GrDrawState::kNumStages));
2108531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com    }
21186afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com
2128531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.comprivate:
2139381363050ec9d3e724076a8e9152bfa9a8de1d1tomhudson@google.com    static const int TEX_COORD_BIT_CNT = GrDrawState::kNumStages *
2149381363050ec9d3e724076a8e9152bfa9a8de1d1tomhudson@google.com                                         GrDrawState::kMaxTexCoords;
21586c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com
2168531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.compublic:
2178531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com    /**
2188531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com     * Generates a bit indicating that a texture stage uses the position
2198531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com     * as its texture coordinate.
2208531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com     *
2215782d712ffc31557d0cb12d5a220cebb783f6895bsalomon@google.com     * @param stage       the stage that will use position as texture
2228531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com     *                    coordinates.
2238531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com     *
2248531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com     * @return the bit to add to a GrVertexLayout bitfield.
2258531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com     */
2268531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com    static int StagePosAsTexCoordVertexLayoutBit(int stage) {
2279381363050ec9d3e724076a8e9152bfa9a8de1d1tomhudson@google.com        GrAssert(stage < GrDrawState::kNumStages);
2285782d712ffc31557d0cb12d5a220cebb783f6895bsalomon@google.com        return (1 << (TEX_COORD_BIT_CNT + stage));
2298531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com    }
230a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com
2318531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.comprivate:
2329381363050ec9d3e724076a8e9152bfa9a8de1d1tomhudson@google.com    static const int STAGE_BIT_CNT = TEX_COORD_BIT_CNT +
2339381363050ec9d3e724076a8e9152bfa9a8de1d1tomhudson@google.com        GrDrawState::kNumStages;
2345782d712ffc31557d0cb12d5a220cebb783f6895bsalomon@google.com
2358531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.compublic:
2365782d712ffc31557d0cb12d5a220cebb783f6895bsalomon@google.com
2378531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com    /**
2388531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com     * Additional Bits that can be specified in GrVertexLayout.
239ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     */
240ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com    enum VertexLayoutBits {
241a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com        /* vertices have colors (GrColor) */
2428531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com        kColor_VertexLayoutBit              = 1 << (STAGE_BIT_CNT + 0),
2432401ae8fd3c1f6282f571b5a7e0a499e9f4c09abbsalomon@google.com        /* vertices have coverage (GrColor)
244e10f6fdf76fa9b627cbb8471b58b13c457af83e8bsalomon@google.com         */
245a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com        kCoverage_VertexLayoutBit           = 1 << (STAGE_BIT_CNT + 1),
246aeb2160b1dd34f8e640e8e56544fe407d4ff6311bsalomon@google.com        /* Use text vertices. (Pos and tex coords may be a different type for
247e10f6fdf76fa9b627cbb8471b58b13c457af83e8bsalomon@google.com         * text [GrGpuTextVertex vs GrPoint].)
248e10f6fdf76fa9b627cbb8471b58b13c457af83e8bsalomon@google.com         */
249a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com        kTextFormat_VertexLayoutBit         = 1 << (STAGE_BIT_CNT + 2),
250aeb2160b1dd34f8e640e8e56544fe407d4ff6311bsalomon@google.com
251e10f6fdf76fa9b627cbb8471b58b13c457af83e8bsalomon@google.com        /* Each vertex specificies an edge. Distance to the edge is used to
252cff56083942a9784331aa2fd62ddf806cccc31cbbsalomon@google.com         * compute a coverage. See GrDrawState::setVertexEdgeType().
253e10f6fdf76fa9b627cbb8471b58b13c457af83e8bsalomon@google.com         */
254a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com        kEdge_VertexLayoutBit               = 1 << (STAGE_BIT_CNT + 3),
255ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com        // for below assert
256d302f1401b3c9aea094804bad4e76de98782cfe8bsalomon@google.com        kDummyVertexLayoutBit,
257d302f1401b3c9aea094804bad4e76de98782cfe8bsalomon@google.com        kHighVertexLayoutBit = kDummyVertexLayoutBit - 1
258ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com    };
2598531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com    // make sure we haven't exceeded the number of bits in GrVertexLayout.
2604be283f3a82895530d1b70372cd48ddb1c663fd8bsalomon@google.com    GR_STATIC_ASSERT(kHighVertexLayoutBit < ((uint64_t)1 << 8*sizeof(GrVertexLayout)));
261ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com
262ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com    /**
263e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com     * There are three types of "sources" of geometry (vertices and indices) for
264e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com     * draw calls made on the target. When performing an indexed draw, the
265e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com     * indices and vertices can use different source types. Once a source is
266e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com     * specified it can be used for multiple drawIndexed and drawNonIndexed
267e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com     * calls. However, the time at which the geometry data is no longer editable
268e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com     * depends on the source type.
26925fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com     *
27025fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com     * Sometimes it is necessary to perform a draw while upstack code has
271e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com     * already specified geometry that it isn't finished with. So there are push
272e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com     * and pop methods. This allows the client to push the sources, draw
273e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com     * something using alternate sources, and then pop to restore the original
274e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com     * sources.
275e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com     *
276e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com     * Aside from pushes and pops, a source remains valid until another source
277e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com     * is set or resetVertexSource / resetIndexSource is called. Drawing from
278e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com     * a reset source is an error.
279e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com     *
280e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com     * The three types of sources are:
2811c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com     *
282e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com     * 1. A cpu array (set*SourceToArray). This is useful when the caller
283e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com     *    already provided vertex data in a format compatible with a
284e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com     *    GrVertexLayout. The data in the array is consumed at the time that
285e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com     *    set*SourceToArray is called and subsequent edits to the array will not
286e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com     *    be reflected in draws.
2871c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com     *
28825fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com     * 2. Reserve. This is most useful when the caller has data it must
28925fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com     *    transform before drawing and is not long-lived. The caller requests
29025fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com     *    that the draw target make room for some amount of vertex and/or index
29125fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com     *    data. The target provides ptrs to hold the vertex and/or index data.
29225fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com     *
29325fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com     *    The data is writable up until the next drawIndexed, drawNonIndexed,
294e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com     *    or pushGeometrySource. At this point the data is frozen and the ptrs
29525fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com     *    are no longer valid.
2961c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com     *
297e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com     *    Where the space is allocated and how it is uploaded to the GPU is
298e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com     *    subclass-dependent.
299e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com     *
3001c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com     * 3. Vertex and Index Buffers. This is most useful for geometry that will
301e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com     *    is long-lived. When the data in the buffer is consumed depends on the
302e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com     *    GrDrawTarget subclass. For deferred subclasses the caller has to
303e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com     *    guarantee that the data is still available in the buffers at playback.
304e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com     *    (TODO: Make this more automatic as we have done for read/write pixels)
3051c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com     */
3061c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com
3071c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com    /**
308e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com     * Reserves space for vertices and/or indices. Zero can be specifed as
309e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com     * either the vertex or index count if the caller desires to only reserve
310e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com     * space for only indices or only vertices. If zero is specifed for
311e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com     * vertexCount then the vertex source will be unmodified and likewise for
312e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com     * indexCount.
313ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     *
314e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com     * If the function returns true then the reserve suceeded and the vertices
315e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com     * and indices pointers will point to the space created.
316ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     *
317e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com     * If the target cannot make space for the request then this function will
318e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com     * return false. If vertexCount was non-zero then upon failure the vertex
319e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com     * source is reset and likewise for indexCount.
320ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     *
321e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com     * The pointers to the space allocated for vertices and indices remain valid
322e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com     * until a drawIndexed, drawNonIndexed, or push/popGeomtrySource is called.
323e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com     * At that point logically a snapshot of the data is made and the pointers
324e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com     * are invalid.
3251c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com     *
326ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     * @param vertexLayout the format of vertices (ignored if vertexCount == 0).
327e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com     * @param vertexCount  the number of vertices to reserve space for. Can be
328e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com     *                     0.
32925fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com     * @param indexCount   the number of indices to reserve space for. Can be 0.
330e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com     * @param vertices     will point to reserved vertex space if vertexCount is
331e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com     *                     non-zero. Illegal to pass NULL if vertexCount > 0.
33225fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com     * @param indices      will point to reserved index space if indexCount is
33325fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com     *                     non-zero. Illegal to pass NULL if indexCount > 0.
33425fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com     */
33597805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com     bool reserveVertexAndIndexSpace(GrVertexLayout vertexLayout,
33697805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com                                     int vertexCount,
33797805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com                                     int indexCount,
33897805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com                                     void** vertices,
33997805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com                                     void** indices);
34025fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com
341ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com    /**
342ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     * Provides hints to caller about the number of vertices and indices
343ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     * that can be allocated cheaply. This can be useful if caller is reserving
344ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     * space but doesn't know exactly how much geometry is needed.
345ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     *
346ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     * Also may hint whether the draw target should be flushed first. This is
347ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     * useful for deferred targets.
348ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     *
349ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     * @param vertexLayout layout of vertices caller would like to reserve
350ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     * @param vertexCount  in: hint about how many vertices the caller would
351ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     *                     like to allocate.
352ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     *                     out: a hint about the number of vertices that can be
353ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     *                     allocated cheaply. Negative means no hint.
354ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     *                     Ignored if NULL.
355ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     * @param indexCount   in: hint about how many indices the caller would
356ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     *                     like to allocate.
357ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     *                     out: a hint about the number of indices that can be
358ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     *                     allocated cheaply. Negative means no hint.
359ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     *                     Ignored if NULL.
360ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     *
361ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     * @return  true if target should be flushed based on the input values.
362ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     */
363ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com    virtual bool geometryHints(GrVertexLayout vertexLayout,
3641c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com                               int* vertexCount,
3651c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com                               int* indexCount) const;
366ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com
367ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com    /**
3681c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com     * Sets source of vertex data for the next draw. Array must contain
3691c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com     * the vertex data when this is called.
370ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     *
371ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     * @param array         cpu array containing vertex data.
3721c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com     * @param size          size of the vertex data.
3731c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com     * @param vertexCount   the number of vertices in the array.
374ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     */
3751c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com    void setVertexSourceToArray(GrVertexLayout vertexLayout,
3761c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com                                const void* vertexArray,
3771c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com                                int vertexCount);
378ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com
379ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com    /**
3801c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com     * Sets source of index data for the next indexed draw. Array must contain
3811c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com     * the indices when this is called.
382ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     *
3831c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com     * @param array         cpu array containing index data.
3841c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com     * @param indexCount    the number of indices in the array.
385ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     */
3861c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com    void setIndexSourceToArray(const void* indexArray, int indexCount);
387ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com
388ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com    /**
389ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     * Sets source of vertex data for the next draw. Data does not have to be
390ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     * in the buffer until drawIndexed or drawNonIndexed.
391ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     *
392ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     * @param buffer        vertex buffer containing vertex data. Must be
393ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     *                      unlocked before draw call.
394ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     * @param vertexLayout  layout of the vertex data in the buffer.
395ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     */
3961c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com    void setVertexSourceToBuffer(GrVertexLayout vertexLayout,
3971c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com                                 const GrVertexBuffer* buffer);
398ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com
399ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com    /**
400ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     * Sets source of index data for the next indexed draw. Data does not have
401ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     * to be in the buffer until drawIndexed or drawNonIndexed.
402ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     *
403ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     * @param buffer index buffer containing indices. Must be unlocked
404ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     *               before indexed draw call.
405ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     */
406ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com    void setIndexSourceToBuffer(const GrIndexBuffer* buffer);
40725fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com
40825fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com    /**
40925fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com     * Resets vertex source. Drawing from reset vertices is illegal. Set vertex
41025fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com     * source to reserved, array, or buffer before next draw. May be able to free
41125fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com     * up temporary storage allocated by setVertexSourceToArray or
41225fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com     * reserveVertexSpace.
41325fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com     */
41425fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com    void resetVertexSource();
41525fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com
41625fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com    /**
41725fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com     * Resets index source. Indexed Drawing from reset indices is illegal. Set
41825fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com     * index source to reserved, array, or buffer before next indexed draw. May
41925fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com     * be able to free up temporary storage allocated by setIndexSourceToArray
42025fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com     * or reserveIndexSpace.
42125fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com     */
42297805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com    void resetIndexSource();
42397805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com
42497805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com    /**
42597805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com     * Query to find out if the vertex or index source is reserved.
42697805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com     */
42797805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com    bool hasReservedVerticesOrIndices() const {
42873d98aace4f74acc39d8de33484c8aec8e917739bsalomon@google.com        return kReserved_GeometrySrcType == this->getGeomSrc().fVertexSrc ||
42997805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com        kReserved_GeometrySrcType == this->getGeomSrc().fIndexSrc;
43097805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com    }
431ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com
432ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com    /**
43325fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com     * Pushes and resets the vertex/index sources. Any reserved vertex / index
43425fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com     * data is finalized (i.e. cannot be updated after the matching pop but can
43525fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com     * be drawn from). Must be balanced by a pop.
43625fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com     */
43725fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com    void pushGeometrySource();
43825fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com
43925fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com    /**
44025fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com     * Pops the vertex / index sources from the matching push.
44125fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com     */
44225fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com    void popGeometrySource();
44325fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com
44425fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com    /**
445ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     * Draws indexed geometry using the current state and current vertex / index
446ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     * sources.
447ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     *
448ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     * @param type         The type of primitives to draw.
449ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     * @param startVertex  the vertex in the vertex array/buffer corresponding
450ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     *                     to index 0
451ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     * @param startIndex   first index to read from index src.
452ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     * @param vertexCount  one greater than the max index.
453ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     * @param indexCount   the number of index elements to read. The index count
454ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     *                     is effectively trimmed to the last completely
455ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     *                     specified primitive.
456ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     */
45725fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com    void drawIndexed(GrPrimitiveType type,
45825fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com                     int startVertex,
45925fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com                     int startIndex,
46025fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com                     int vertexCount,
46125fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com                     int indexCount);
462ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com
463ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com    /**
464ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     * Draws non-indexed geometry using the current state and current vertex
465ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     * sources.
466ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     *
467ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     * @param type         The type of primitives to draw.
468ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     * @param startVertex  the vertex in the vertex array/buffer corresponding
469ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     *                     to index 0
470ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     * @param vertexCount  one greater than the max index.
471ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     */
47225fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com    void drawNonIndexed(GrPrimitiveType type,
47325fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com                        int startVertex,
47425fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com                        int vertexCount);
475ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com
47686afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com    /**
47786afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com     * Helper function for drawing rects. This does not use the current index
47886afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com     * and vertex sources. After returning, the vertex and index sources may
47986afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com     * have changed. They should be reestablished before the next drawIndexed
48086afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com     * or drawNonIndexed. This cannot be called between reserving and releasing
48186afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com     * geometry. The GrDrawTarget subclass may be able to perform additional
482d302f1401b3c9aea094804bad4e76de98782cfe8bsalomon@google.com     * optimizations if drawRect is used rather than drawIndexed or
48386afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com     * drawNonIndexed.
48486afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com     * @param rect      the rect to draw
48586afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com     * @param matrix    optional matrix applied to rect (before viewMatrix)
48639ee0ffa72fbd5df6d3ec6db4fdad0c1bc3946fdbsalomon@google.com     * @param stageMask bitmask indicating which stages are enabled.
48739ee0ffa72fbd5df6d3ec6db4fdad0c1bc3946fdbsalomon@google.com     *                  Bit i indicates whether stage i is enabled.
48886afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com     * @param srcRects  specifies rects for stages enabled by stageEnableMask.
48986afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com     *                  if stageEnableMask bit i is 1, srcRects is not NULL,
49086afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com     *                  and srcRects[i] is not NULL, then srcRects[i] will be
49186afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com     *                  used as coordinates for stage i. Otherwise, if stage i
49286afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com     *                  is enabled then rect is used as the coordinates.
49386afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com     * @param srcMatrices   optional matrices applied to srcRects. If
49486afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com     *                      srcRect[i] is non-NULL and srcMatrices[i] is
49586afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com     *                      non-NULL then srcRect[i] will be transformed by
49686afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com     *                      srcMatrix[i]. srcMatrices can be NULL when no
49786afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com     *                      srcMatrices are desired.
49886afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com     */
499d302f1401b3c9aea094804bad4e76de98782cfe8bsalomon@google.com    virtual void drawRect(const GrRect& rect,
50086afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com                          const GrMatrix* matrix,
50139ee0ffa72fbd5df6d3ec6db4fdad0c1bc3946fdbsalomon@google.com                          StageMask stageMask,
50286afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com                          const GrRect* srcRects[],
50386afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com                          const GrMatrix* srcMatrices[]);
50486afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com
50586afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com    /**
506d302f1401b3c9aea094804bad4e76de98782cfe8bsalomon@google.com     * Helper for drawRect when the caller doesn't need separate src rects or
50786afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com     * matrices.
50886afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com     */
509d302f1401b3c9aea094804bad4e76de98782cfe8bsalomon@google.com    void drawSimpleRect(const GrRect& rect,
510d302f1401b3c9aea094804bad4e76de98782cfe8bsalomon@google.com                        const GrMatrix* matrix,
51139ee0ffa72fbd5df6d3ec6db4fdad0c1bc3946fdbsalomon@google.com                        StageMask stageEnableBitfield) {
512ffca400ef6f96a280c3e2c09210f950af64a1f24bsalomon@google.com         drawRect(rect, matrix, stageEnableBitfield, NULL, NULL);
51386afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com    }
51486afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com
5150b335c1ac100aeacf79a4c98a052286fd46661e7bsalomon@google.com    /**
5166aa25c3f555dc2a6711365d14279db3ec909e064bsalomon@google.com     * Clear the render target. Ignores the clip and all other draw state
5176aa25c3f555dc2a6711365d14279db3ec909e064bsalomon@google.com     * (blend mode, stages, etc). Clears the whole thing if rect is NULL,
5186aa25c3f555dc2a6711365d14279db3ec909e064bsalomon@google.com     * otherwise just the rect.
5190b335c1ac100aeacf79a4c98a052286fd46661e7bsalomon@google.com     */
5206aa25c3f555dc2a6711365d14279db3ec909e064bsalomon@google.com    virtual void clear(const GrIRect* rect, GrColor color) = 0;
5210b335c1ac100aeacf79a4c98a052286fd46661e7bsalomon@google.com
522ef3913bcbff265ff86116ae4f3dd2768dc42cccasenorblanco@chromium.org    /**
523ef3913bcbff265ff86116ae4f3dd2768dc42cccasenorblanco@chromium.org     * Returns the maximum number of edges that may be specified in a single
524ef3913bcbff265ff86116ae4f3dd2768dc42cccasenorblanco@chromium.org     * draw call when performing edge antialiasing.  This is usually limited
525ef3913bcbff265ff86116ae4f3dd2768dc42cccasenorblanco@chromium.org     * by the number of fragment uniforms which may be uploaded.  Must be a
526ef3913bcbff265ff86116ae4f3dd2768dc42cccasenorblanco@chromium.org     * minimum of six, since a triangle's vertices each belong to two boundary
527ef3913bcbff265ff86116ae4f3dd2768dc42cccasenorblanco@chromium.org     * edges which may be distinct.
528ef3913bcbff265ff86116ae4f3dd2768dc42cccasenorblanco@chromium.org     */
529ef3913bcbff265ff86116ae4f3dd2768dc42cccasenorblanco@chromium.org    virtual int getMaxEdges() const { return 6; }
530ef3913bcbff265ff86116ae4f3dd2768dc42cccasenorblanco@chromium.org
53125fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com    ////////////////////////////////////////////////////////////////////////////
532ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com
533ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com    class AutoStateRestore : ::GrNoncopyable {
534ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com    public:
53506afe7b5a1ef03bfc6494c51ab2a1f7a386de5c2bsalomon@google.com        AutoStateRestore();
536ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com        AutoStateRestore(GrDrawTarget* target);
537ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com        ~AutoStateRestore();
538ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com
53906afe7b5a1ef03bfc6494c51ab2a1f7a386de5c2bsalomon@google.com        /**
54006afe7b5a1ef03bfc6494c51ab2a1f7a386de5c2bsalomon@google.com         * if this object is already saving state for param target then
54106afe7b5a1ef03bfc6494c51ab2a1f7a386de5c2bsalomon@google.com         * this does nothing. Otherise, it restores previously saved state on
54206afe7b5a1ef03bfc6494c51ab2a1f7a386de5c2bsalomon@google.com         * previous target (if any) and saves current state on param target.
54306afe7b5a1ef03bfc6494c51ab2a1f7a386de5c2bsalomon@google.com         */
54406afe7b5a1ef03bfc6494c51ab2a1f7a386de5c2bsalomon@google.com        void set(GrDrawTarget* target);
54506afe7b5a1ef03bfc6494c51ab2a1f7a386de5c2bsalomon@google.com
546ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com    private:
547ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com        GrDrawTarget*       fDrawTarget;
548ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com        SavedDrawState      fDrawState;
549ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com    };
550ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com
55125fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com    ////////////////////////////////////////////////////////////////////////////
5521c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com
5537ac249bdc7a86bc44610e02abeeaa0c14ba8163absalomon@google.com    /**
5547ac249bdc7a86bc44610e02abeeaa0c14ba8163absalomon@google.com     * Sets the view matrix to I and preconcats all stage matrices enabled in
5557ac249bdc7a86bc44610e02abeeaa0c14ba8163absalomon@google.com     * mask by the view inverse. Destructor undoes these changes.
5567ac249bdc7a86bc44610e02abeeaa0c14ba8163absalomon@google.com     */
5577ac249bdc7a86bc44610e02abeeaa0c14ba8163absalomon@google.com    class AutoDeviceCoordDraw : ::GrNoncopyable {
5587ac249bdc7a86bc44610e02abeeaa0c14ba8163absalomon@google.com    public:
5593d0835b6ac0003c18147b6e9ca76a497b92d1d40bsalomon@google.com        AutoDeviceCoordDraw(GrDrawTarget* target, StageMask stageMask);
5607ac249bdc7a86bc44610e02abeeaa0c14ba8163absalomon@google.com        ~AutoDeviceCoordDraw();
5617ac249bdc7a86bc44610e02abeeaa0c14ba8163absalomon@google.com    private:
5623d0835b6ac0003c18147b6e9ca76a497b92d1d40bsalomon@google.com        GrDrawTarget*       fDrawTarget;
5633d0835b6ac0003c18147b6e9ca76a497b92d1d40bsalomon@google.com        GrMatrix            fViewMatrix;
5643d0835b6ac0003c18147b6e9ca76a497b92d1d40bsalomon@google.com        GrMatrix            fSamplerMatrices[GrDrawState::kNumStages];
5653d0835b6ac0003c18147b6e9ca76a497b92d1d40bsalomon@google.com        int                 fStageMask;
5667ac249bdc7a86bc44610e02abeeaa0c14ba8163absalomon@google.com    };
5677ac249bdc7a86bc44610e02abeeaa0c14ba8163absalomon@google.com
56825fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com    ////////////////////////////////////////////////////////////////////////////
5697ac249bdc7a86bc44610e02abeeaa0c14ba8163absalomon@google.com
570ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com    class AutoReleaseGeometry : ::GrNoncopyable {
571ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com    public:
572ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com        AutoReleaseGeometry(GrDrawTarget*  target,
573ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com                            GrVertexLayout vertexLayout,
57425fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com                            int            vertexCount,
57525fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com                            int            indexCount);
57625fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com        AutoReleaseGeometry();
57725fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com        ~AutoReleaseGeometry();
5785782d712ffc31557d0cb12d5a220cebb783f6895bsalomon@google.com        bool set(GrDrawTarget*  target,
5795782d712ffc31557d0cb12d5a220cebb783f6895bsalomon@google.com                 GrVertexLayout vertexLayout,
58025fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com                 int            vertexCount,
58125fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com                 int            indexCount);
582a47a48dca5045d71cbc5de343404045209a13e15bsalomon@google.com        bool succeeded() const { return NULL != fTarget; }
5836513cd06ae34f5d777b3aaea0b4533014d0a10f2bsalomon@google.com        void* vertices() const { GrAssert(this->succeeded()); return fVertices; }
5846513cd06ae34f5d777b3aaea0b4533014d0a10f2bsalomon@google.com        void* indices() const { GrAssert(this->succeeded()); return fIndices; }
585ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com        GrPoint* positions() const {
5866513cd06ae34f5d777b3aaea0b4533014d0a10f2bsalomon@google.com            return static_cast<GrPoint*>(this->vertices());
587ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com        }
588ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com
589ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com    private:
59025fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com        void reset();
59125fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com
592ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com        GrDrawTarget* fTarget;
593ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com        void*         fVertices;
594ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com        void*         fIndices;
595ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com    };
596ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com
59725fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com    ////////////////////////////////////////////////////////////////////////////
598ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com
599ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com    class AutoClipRestore : ::GrNoncopyable {
600ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com    public:
601ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com        AutoClipRestore(GrDrawTarget* target) {
602ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com            fTarget = target;
603ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com            fClip = fTarget->getClip();
604ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com        }
605ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com
606ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com        ~AutoClipRestore() {
607ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com            fTarget->setClip(fClip);
608ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com        }
609ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com    private:
610ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com        GrDrawTarget* fTarget;
611ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com        GrClip        fClip;
612ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com    };
61325fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com
61425fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com    ////////////////////////////////////////////////////////////////////////////
61525fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com
61625fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com    class AutoGeometryPush : ::GrNoncopyable {
61725fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com    public:
61825fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com        AutoGeometryPush(GrDrawTarget* target) {
61925fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com            GrAssert(NULL != target);
62025fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com            fTarget = target;
62125fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com            target->pushGeometrySource();
62225fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com        }
62325fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com        ~AutoGeometryPush() {
62425fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com            fTarget->popGeometrySource();
62525fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com        }
62625fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com    private:
62725fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com        GrDrawTarget* fTarget;
62825fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com    };
629ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com
630ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com    ////////////////////////////////////////////////////////////////////////////
6318531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com    // Helpers for picking apart vertex layouts
6325782d712ffc31557d0cb12d5a220cebb783f6895bsalomon@google.com
633ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com    /**
634ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     * Helper function to compute the size of a vertex from a vertex layout
635ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     * @return size of a single vertex.
636ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     */
637ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com    static size_t VertexSize(GrVertexLayout vertexLayout);
6385782d712ffc31557d0cb12d5a220cebb783f6895bsalomon@google.com
6398531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com    /**
6408531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com     * Helper function for determining the index of texture coordinates that
6418531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com     * is input for a texture stage. Note that a stage may instead use positions
6428531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com     * as texture coordinates, in which case the result of the function is
6438531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com     * indistinguishable from the case when the stage is disabled.
6448531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com     *
6458531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com     * @param stage         the stage to query
6468531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com     * @param vertexLayout  layout to query
6478531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com     *
6488531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com     * @return the texture coordinate index or -1 if the stage doesn't use
6498531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com     *         separate (non-position) texture coordinates.
6508531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com     */
6518531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com    static int VertexTexCoordsForStage(int stage, GrVertexLayout vertexLayout);
652ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com
653ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com    /**
654ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     * Helper function to compute the offset of texture coordinates in a vertex
655ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     * @return offset of texture coordinates in vertex layout or -1 if the
6565782d712ffc31557d0cb12d5a220cebb783f6895bsalomon@google.com     *         layout has no texture coordinates. Will be 0 if positions are
6578531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com     *         used as texture coordinates for the stage.
658ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     */
6598531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com    static int VertexStageCoordOffset(int stage, GrVertexLayout vertexLayout);
660ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com
661ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com    /**
662ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     * Helper function to compute the offset of the color in a vertex
663ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     * @return offset of color in vertex layout or -1 if the
664ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     *         layout has no color.
665ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     */
666ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com    static int VertexColorOffset(GrVertexLayout vertexLayout);
667ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com
668a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com    /**
669a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com     * Helper function to compute the offset of the coverage in a vertex
670a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com     * @return offset of coverage in vertex layout or -1 if the
671a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com     *         layout has no coverage.
672a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com     */
673a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com    static int VertexCoverageOffset(GrVertexLayout vertexLayout);
674a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com
675aeb2160b1dd34f8e640e8e56544fe407d4ff6311bsalomon@google.com     /**
676aeb2160b1dd34f8e640e8e56544fe407d4ff6311bsalomon@google.com      * Helper function to compute the offset of the edge pts in a vertex
677aeb2160b1dd34f8e640e8e56544fe407d4ff6311bsalomon@google.com      * @return offset of edge in vertex layout or -1 if the
678aeb2160b1dd34f8e640e8e56544fe407d4ff6311bsalomon@google.com      *         layout has no edge.
679aeb2160b1dd34f8e640e8e56544fe407d4ff6311bsalomon@google.com      */
680aeb2160b1dd34f8e640e8e56544fe407d4ff6311bsalomon@google.com     static int VertexEdgeOffset(GrVertexLayout vertexLayout);
681aeb2160b1dd34f8e640e8e56544fe407d4ff6311bsalomon@google.com
682ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com    /**
6835782d712ffc31557d0cb12d5a220cebb783f6895bsalomon@google.com     * Helper function to determine if vertex layout contains explicit texture
6848531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com     * coordinates of some index.
6858531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com     *
6868531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com     * @param coordIndex    the tex coord index to query
6878531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com     * @param vertexLayout  layout to query
6888531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com     *
6895782d712ffc31557d0cb12d5a220cebb783f6895bsalomon@google.com     * @return true if vertex specifies texture coordinates for the index,
6908531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com     *              false otherwise.
691ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     */
6925782d712ffc31557d0cb12d5a220cebb783f6895bsalomon@google.com    static bool VertexUsesTexCoordIdx(int coordIndex,
6938531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com                                      GrVertexLayout vertexLayout);
6945782d712ffc31557d0cb12d5a220cebb783f6895bsalomon@google.com
695ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com    /**
696ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     * Helper function to determine if vertex layout contains either explicit or
6978531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com     * implicit texture coordinates for a stage.
698ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     *
6998531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com     * @param stage         the stage to query
7008531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com     * @param vertexLayout  layout to query
7018531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com     *
7025782d712ffc31557d0cb12d5a220cebb783f6895bsalomon@google.com     * @return true if vertex specifies texture coordinates for the stage,
7038531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com     *              false otherwise.
704ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     */
7058531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com    static bool VertexUsesStage(int stage, GrVertexLayout vertexLayout);
706ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com
7078531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com    /**
7085782d712ffc31557d0cb12d5a220cebb783f6895bsalomon@google.com     * Helper function to compute the size of each vertex and the offsets of
7095782d712ffc31557d0cb12d5a220cebb783f6895bsalomon@google.com     * texture coordinates and color. Determines tex coord offsets by tex coord
7105782d712ffc31557d0cb12d5a220cebb783f6895bsalomon@google.com     * index rather than by stage. (Each stage can be mapped to any t.c. index
7118531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com     * by StageTexCoordVertexLayoutBit.)
7128531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com     *
7138531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com     * @param vertexLayout          the layout to query
7148531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com     * @param texCoordOffsetsByIdx  after return it is the offset of each
7158531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com     *                              tex coord index in the vertex or -1 if
716a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com     *                              index isn't used. (optional)
717a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com     * @param colorOffset           after return it is the offset of the
718a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com     *                              color field in each vertex, or -1 if
719a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com     *                              there aren't per-vertex colors. (optional)
720a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com     * @param coverageOffset        after return it is the offset of the
721a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com     *                              coverage field in each vertex, or -1 if
722a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com     *                              there aren't per-vertex coeverages.
723a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com     *                              (optional)
724a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com     * @param edgeOffset            after return it is the offset of the
725a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com     *                              edge eq field in each vertex, or -1 if
726a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com     *                              there aren't per-vertex edge equations.
727a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com     *                              (optional)
7288531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com     * @return size of a single vertex
7298531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com     */
7308531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com    static int VertexSizeAndOffsetsByIdx(GrVertexLayout vertexLayout,
7319381363050ec9d3e724076a8e9152bfa9a8de1d1tomhudson@google.com                   int texCoordOffsetsByIdx[GrDrawState::kMaxTexCoords],
7329381363050ec9d3e724076a8e9152bfa9a8de1d1tomhudson@google.com                   int *colorOffset,
7339381363050ec9d3e724076a8e9152bfa9a8de1d1tomhudson@google.com                   int *coverageOffset,
7349381363050ec9d3e724076a8e9152bfa9a8de1d1tomhudson@google.com                   int* edgeOffset);
7355782d712ffc31557d0cb12d5a220cebb783f6895bsalomon@google.com
7368531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com    /**
7375782d712ffc31557d0cb12d5a220cebb783f6895bsalomon@google.com     * Helper function to compute the size of each vertex and the offsets of
7385782d712ffc31557d0cb12d5a220cebb783f6895bsalomon@google.com     * texture coordinates and color. Determines tex coord offsets by stage
7395782d712ffc31557d0cb12d5a220cebb783f6895bsalomon@google.com     * rather than by index. (Each stage can be mapped to any t.c. index
7405782d712ffc31557d0cb12d5a220cebb783f6895bsalomon@google.com     * by StageTexCoordVertexLayoutBit.) If a stage uses positions for
7418531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com     * tex coords then that stage's offset will be 0 (positions are always at 0).
7428531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com     *
7438531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com     * @param vertexLayout              the layout to query
7448531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com     * @param texCoordOffsetsByStage    after return it is the offset of each
7458531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com     *                                  tex coord index in the vertex or -1 if
746a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com     *                                  index isn't used. (optional)
747a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com     * @param colorOffset               after return it is the offset of the
748a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com     *                                  color field in each vertex, or -1 if
749a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com     *                                  there aren't per-vertex colors.
750a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com     *                                  (optional)
751a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com     * @param coverageOffset            after return it is the offset of the
752a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com     *                                  coverage field in each vertex, or -1 if
753a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com     *                                  there aren't per-vertex coeverages.
754a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com     *                                  (optional)
755a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com     * @param edgeOffset                after return it is the offset of the
756a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com     *                                  edge eq field in each vertex, or -1 if
757a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com     *                                  there aren't per-vertex edge equations.
758a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com     *                                  (optional)
7598531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com     * @return size of a single vertex
7608531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com     */
7618531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com    static int VertexSizeAndOffsetsByStage(GrVertexLayout vertexLayout,
7629381363050ec9d3e724076a8e9152bfa9a8de1d1tomhudson@google.com                   int texCoordOffsetsByStage[GrDrawState::kNumStages],
7639381363050ec9d3e724076a8e9152bfa9a8de1d1tomhudson@google.com                   int* colorOffset,
7649381363050ec9d3e724076a8e9152bfa9a8de1d1tomhudson@google.com                   int* coverageOffset,
7659381363050ec9d3e724076a8e9152bfa9a8de1d1tomhudson@google.com                   int* edgeOffset);
76686afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com
76786afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com    /**
76886afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com     * Accessing positions, texture coords, or colors, of a vertex within an
76986afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com     * array is a hassle involving casts and simple math. These helpers exist
77086afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com     * to keep GrDrawTarget clients' code a bit nicer looking.
77186afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com     */
77286afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com
77386afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com    /**
77486afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com     * Gets a pointer to a GrPoint of a vertex's position or texture
77586afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com     * coordinate.
77686afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com     * @param vertices      the vetex array
77786afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com     * @param vertexIndex   the index of the vertex in the array
77886afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com     * @param vertexSize    the size of each vertex in the array
77986afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com     * @param offset        the offset in bytes of the vertex component.
78086afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com     *                      Defaults to zero (corresponding to vertex position)
78186afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com     * @return pointer to the vertex component as a GrPoint
78286afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com     */
783d302f1401b3c9aea094804bad4e76de98782cfe8bsalomon@google.com    static GrPoint* GetVertexPoint(void* vertices,
78486afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com                                   int vertexIndex,
78586afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com                                   int vertexSize,
78686afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com                                   int offset = 0) {
78786afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com        intptr_t start = GrTCast<intptr_t>(vertices);
788d302f1401b3c9aea094804bad4e76de98782cfe8bsalomon@google.com        return GrTCast<GrPoint*>(start + offset +
78986afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com                                 vertexIndex * vertexSize);
79086afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com    }
79186afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com    static const GrPoint* GetVertexPoint(const void* vertices,
79286afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com                                         int vertexIndex,
793d302f1401b3c9aea094804bad4e76de98782cfe8bsalomon@google.com                                         int vertexSize,
79486afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com                                         int offset = 0) {
79586afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com        intptr_t start = GrTCast<intptr_t>(vertices);
796d302f1401b3c9aea094804bad4e76de98782cfe8bsalomon@google.com        return GrTCast<const GrPoint*>(start + offset +
79786afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com                                       vertexIndex * vertexSize);
79886afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com    }
79986afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com
80086afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com    /**
80186afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com     * Gets a pointer to a GrColor inside a vertex within a vertex array.
80286afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com     * @param vertices      the vetex array
80386afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com     * @param vertexIndex   the index of the vertex in the array
80486afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com     * @param vertexSize    the size of each vertex in the array
80586afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com     * @param offset        the offset in bytes of the vertex color
80686afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com     * @return pointer to the vertex component as a GrColor
80786afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com     */
808d302f1401b3c9aea094804bad4e76de98782cfe8bsalomon@google.com    static GrColor* GetVertexColor(void* vertices,
80986afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com                                   int vertexIndex,
81086afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com                                   int vertexSize,
81186afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com                                   int offset) {
81286afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com        intptr_t start = GrTCast<intptr_t>(vertices);
813d302f1401b3c9aea094804bad4e76de98782cfe8bsalomon@google.com        return GrTCast<GrColor*>(start + offset +
81486afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com                                 vertexIndex * vertexSize);
81586afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com    }
81686afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com    static const GrColor* GetVertexColor(const void* vertices,
81786afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com                                         int vertexIndex,
818d302f1401b3c9aea094804bad4e76de98782cfe8bsalomon@google.com                                         int vertexSize,
81986afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com                                         int offset) {
82086afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com        const intptr_t start = GrTCast<intptr_t>(vertices);
821d302f1401b3c9aea094804bad4e76de98782cfe8bsalomon@google.com        return GrTCast<const GrColor*>(start + offset +
82286afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com                                       vertexIndex * vertexSize);
82386afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com    }
82486afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com
8255aaa69e4339e229adfb05e96084a8ec0a590238bbsalomon@google.com    static void VertexLayoutUnitTest();
8265aaa69e4339e229adfb05e96084a8ec0a590238bbsalomon@google.com
827ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.comprotected:
828471d471dcd7422e5dd9c822c1092b2ba4721dcfebsalomon@google.com
82986c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com    /**
83086c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com     * Optimizations for blending / coverage to be applied based on the current
83186c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com     * state.
83286c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com     * Subclasses that actually draw (as opposed to those that just buffer for
83386c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com     * playback) must implement the flags that replace the output color.
83486c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com     */
83586c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com    enum BlendOptFlags {
83686c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com        /**
83786c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com         * No optimization
83886c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com         */
83986c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com        kNone_BlendOpt = 0,
84086c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com        /**
84186c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com         * Don't draw at all
84286c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com         */
84386c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com        kSkipDraw_BlendOptFlag = 0x2,
84486c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com        /**
84586c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com         * Emit the src color, disable HW blending (replace dst with src)
84686c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com         */
84786c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com        kDisableBlend_BlendOptFlag = 0x4,
84886c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com        /**
84986c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com         * The coverage value does not have to be computed separately from
85086c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com         * alpha, the the output color can be the modulation of the two.
85186c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com         */
85286c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com        kCoverageAsAlpha_BlendOptFlag = 0x1,
85386c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com        /**
85486c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com         * Instead of emitting a src color, emit coverage in the alpha channel
85586c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com         * and r,g,b are "don't cares".
85686c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com         */
85786c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com        kEmitCoverage_BlendOptFlag = 0x10,
85886c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com        /**
85986c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com         * Emit transparent black instead of the src color, no need to compute
86086c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com         * coverage.
86186c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com         */
86286c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com        kEmitTransBlack_BlendOptFlag = 0x8,
86386c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com    };
86486c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com    GR_DECL_BITFIELD_OPS_FRIENDS(BlendOptFlags);
86586c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com
86686c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com    // Determines what optimizations can be applied based on the blend.
86786c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com    // The coeffecients may have to be tweaked in order for the optimization
86886c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com    // to work. srcCoeff and dstCoeff are optional params that receive the
86986c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com    // tweaked coeffecients.
87086c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com    // Normally the function looks at the current state to see if coverage
87186c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com    // is enabled. By setting forceCoverage the caller can speculatively
87286c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com    // determine the blend optimizations that would be used if there was
87386c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com    // partial pixel coverage
87486c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com    BlendOptFlags getBlendOpts(bool forceCoverage = false,
87586c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com                               GrBlendCoeff* srcCoeff = NULL,
87686c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com                               GrBlendCoeff* dstCoeff = NULL) const;
87786c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com
87886c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com    // determine if src alpha is guaranteed to be one for all src pixels
87986c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com    bool srcAlphaWillBeOne() const;
880471d471dcd7422e5dd9c822c1092b2ba4721dcfebsalomon@google.com
88125fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com    enum GeometrySrcType {
88225fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com        kNone_GeometrySrcType,     //<! src has not been specified
88325fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com        kReserved_GeometrySrcType, //<! src was set using reserve*Space
88425fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com        kArray_GeometrySrcType,    //<! src was set using set*SourceToArray
88525fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com        kBuffer_GeometrySrcType    //<! src was set using set*SourceToBuffer
88625fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com    };
88725fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com
88825fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com    struct GeometrySrcState {
88925fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com        GeometrySrcType         fVertexSrc;
89025fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com        union {
89125fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com            // valid if src type is buffer
89225fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com            const GrVertexBuffer*   fVertexBuffer;
89325fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com            // valid if src type is reserved or array
89425fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com            int                     fVertexCount;
89525fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com        };
89625fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com
89725fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com        GeometrySrcType         fIndexSrc;
89825fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com        union {
89925fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com            // valid if src type is buffer
90025fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com            const GrIndexBuffer*    fIndexBuffer;
90125fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com            // valid if src type is reserved or array
90225fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com            int                     fIndexCount;
90325fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com        };
90425fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com
90525fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com        GrVertexLayout          fVertexLayout;
90625fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com    };
90725fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com
908a47a48dca5045d71cbc5de343404045209a13e15bsalomon@google.com    // given a vertex layout and a draw state, will a stage be used?
909a47a48dca5045d71cbc5de343404045209a13e15bsalomon@google.com    static bool StageWillBeUsed(int stage, GrVertexLayout layout,
9109381363050ec9d3e724076a8e9152bfa9a8de1d1tomhudson@google.com                                const GrDrawState& state) {
9118f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com        return NULL != state.getTexture(stage) &&
9128f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com               VertexUsesStage(stage, layout);
913a47a48dca5045d71cbc5de343404045209a13e15bsalomon@google.com    }
914a47a48dca5045d71cbc5de343404045209a13e15bsalomon@google.com
915a47a48dca5045d71cbc5de343404045209a13e15bsalomon@google.com    bool isStageEnabled(int stage) const {
91625fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com        return StageWillBeUsed(stage, this->getGeomSrc().fVertexLayout,
91725fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com                               fCurrDrawState);
918a47a48dca5045d71cbc5de343404045209a13e15bsalomon@google.com    }
9195782d712ffc31557d0cb12d5a220cebb783f6895bsalomon@google.com
92039ee0ffa72fbd5df6d3ec6db4fdad0c1bc3946fdbsalomon@google.com    StageMask enabledStages() const {
92139ee0ffa72fbd5df6d3ec6db4fdad0c1bc3946fdbsalomon@google.com        StageMask mask = 0;
9229381363050ec9d3e724076a8e9152bfa9a8de1d1tomhudson@google.com        for (int s = 0; s < GrDrawState::kNumStages; ++s) {
923aeb2160b1dd34f8e640e8e56544fe407d4ff6311bsalomon@google.com            mask |= this->isStageEnabled(s) ? 1 : 0;
924aeb2160b1dd34f8e640e8e56544fe407d4ff6311bsalomon@google.com        }
925aeb2160b1dd34f8e640e8e56544fe407d4ff6311bsalomon@google.com        return mask;
926aeb2160b1dd34f8e640e8e56544fe407d4ff6311bsalomon@google.com    }
927aeb2160b1dd34f8e640e8e56544fe407d4ff6311bsalomon@google.com
928ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com    // Helpers for GrDrawTarget subclasses that won't have private access to
929ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com    // SavedDrawState but need to peek at the state values.
93046f7afb9867200b568c21736da8a8bbb56b20e30bsalomon@google.com    static GrDrawState& accessSavedDrawState(SavedDrawState& sds) {
93146f7afb9867200b568c21736da8a8bbb56b20e30bsalomon@google.com        return *sds.fState.get();
93246f7afb9867200b568c21736da8a8bbb56b20e30bsalomon@google.com    }
93346f7afb9867200b568c21736da8a8bbb56b20e30bsalomon@google.com    static const GrDrawState& accessSavedDrawState(const SavedDrawState& sds){
93446f7afb9867200b568c21736da8a8bbb56b20e30bsalomon@google.com        return *sds.fState.get();
93546f7afb9867200b568c21736da8a8bbb56b20e30bsalomon@google.com    }
936ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com
93797805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com    // A sublcass can optionally overload this function to be notified before
93897805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com    // vertex and index space is reserved.
93997805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com    virtual void willReserveVertexAndIndexSpace(GrVertexLayout vertexLayout,
94097805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com                                                int vertexCount,
94197805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com                                                int indexCount) {}
94297805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com
94397805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com
94425fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com    // implemented by subclass to allocate space for reserved geom
94525fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com    virtual bool onReserveVertexSpace(GrVertexLayout vertexLayout,
94625fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com                                      int vertexCount,
94725fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com                                      void** vertices) = 0;
94825fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com    virtual bool onReserveIndexSpace(int indexCount, void** indices) = 0;
94925fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com    // implemented by subclass to handle release of reserved geom space
95025fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com    virtual void releaseReservedVertexSpace() = 0;
95125fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com    virtual void releaseReservedIndexSpace() = 0;
95225fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com    // subclass must consume array contents when set
953bcdbbe61e1a3f89545b2c1461164f0f8bf5f0797bsalomon@google.com    virtual void onSetVertexSourceToArray(const void* vertexArray,
954bcdbbe61e1a3f89545b2c1461164f0f8bf5f0797bsalomon@google.com                                          int vertexCount) = 0;
955bcdbbe61e1a3f89545b2c1461164f0f8bf5f0797bsalomon@google.com    virtual void onSetIndexSourceToArray(const void* indexArray,
956bcdbbe61e1a3f89545b2c1461164f0f8bf5f0797bsalomon@google.com                                         int indexCount) = 0;
95725fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com    // subclass is notified that geom source will be set away from an array
95825fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com    virtual void releaseVertexArray() = 0;
95925fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com    virtual void releaseIndexArray() = 0;
96025fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com    // subclass overrides to be notified just before geo src state
96125fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com    // is pushed/popped.
96225fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com    virtual void geometrySourceWillPush() = 0;
96325fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com    virtual void geometrySourceWillPop(const GeometrySrcState& restoredState) = 0;
96425fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com    // subclass called to perform drawing
96525fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com    virtual void onDrawIndexed(GrPrimitiveType type,
96625fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com                               int startVertex,
96725fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com                               int startIndex,
96825fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com                               int vertexCount,
96925fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com                               int indexCount) = 0;
97025fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com    virtual void onDrawNonIndexed(GrPrimitiveType type,
97125fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com                                  int startVertex,
97225fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com                                  int vertexCount) = 0;
973dea2f8d86378b791a2de94384a18e29f13f65a3ebsalomon@google.com    // subclass overrides to be notified when clip is set. Must call
974dea2f8d86378b791a2de94384a18e29f13f65a3ebsalomon@google.com    // INHERITED::clipwillBeSet
975dea2f8d86378b791a2de94384a18e29f13f65a3ebsalomon@google.com    virtual void clipWillBeSet(const GrClip& clip);
9761c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com
97786afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com    // Helpers for drawRect, protected so subclasses that override drawRect
97886afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com    // can use them.
9793d0835b6ac0003c18147b6e9ca76a497b92d1d40bsalomon@google.com    static GrVertexLayout GetRectVertexLayout(StageMask stageEnableBitfield,
98086afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com                                              const GrRect* srcRects[]);
98186afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com
98286afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com    static void SetRectVertices(const GrRect& rect,
983d302f1401b3c9aea094804bad4e76de98782cfe8bsalomon@google.com                                const GrMatrix* matrix,
984d302f1401b3c9aea094804bad4e76de98782cfe8bsalomon@google.com                                const GrRect* srcRects[],
98586afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com                                const GrMatrix* srcMatrices[],
986d302f1401b3c9aea094804bad4e76de98782cfe8bsalomon@google.com                                GrVertexLayout layout,
98786afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com                                void* vertices);
98886afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com
98925fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com    // accessor for derived classes
99025fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com    const GeometrySrcState& getGeomSrc() const {
99125fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com        return fGeoSrcStateStack.back();
99225fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com    }
993ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com
994ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com    GrClip fClip;
995ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com
9969381363050ec9d3e724076a8e9152bfa9a8de1d1tomhudson@google.com    GrDrawState fCurrDrawState;
997ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com
99818c9c198f571997463d9a7134dbd88298e592ec2bsalomon@google.com    Caps fCaps;
99918c9c198f571997463d9a7134dbd88298e592ec2bsalomon@google.com
10004a018bb20bf969a38ec11d9506843f06366dfa7cbsalomon@google.com    // subclasses must call this in their destructors to ensure all vertex
10014a018bb20bf969a38ec11d9506843f06366dfa7cbsalomon@google.com    // and index sources have been released (including those held by
10024a018bb20bf969a38ec11d9506843f06366dfa7cbsalomon@google.com    // pushGeometrySource())
10034a018bb20bf969a38ec11d9506843f06366dfa7cbsalomon@google.com    void releaseGeometry();
1004e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com
100525fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.comprivate:
1006e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com    // helpers for reserving vertex and index space.
1007e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com    bool reserveVertexSpace(GrVertexLayout vertexLayout,
1008e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com                            int vertexCount,
1009e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com                            void** vertices);
1010e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com    bool reserveIndexSpace(int indexCount, void** indices);
1011e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com
1012e826262939dac3e67cb5ce66d4b9faeb8e2538e6bsalomon@google.com    // called by drawIndexed and drawNonIndexed. Use a negative indexCount to
1013e826262939dac3e67cb5ce66d4b9faeb8e2538e6bsalomon@google.com    // indicate non-indexed drawing.
1014e826262939dac3e67cb5ce66d4b9faeb8e2538e6bsalomon@google.com    bool checkDraw(GrPrimitiveType type, int startVertex,
1015e826262939dac3e67cb5ce66d4b9faeb8e2538e6bsalomon@google.com                   int startIndex, int vertexCount,
1016e826262939dac3e67cb5ce66d4b9faeb8e2538e6bsalomon@google.com                   int indexCount) const;
101725fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com    // called when setting a new vert/idx source to unref prev vb/ib
101825fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com    void releasePreviousVertexSource();
101925fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com    void releasePreviousIndexSource();
102025fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com
102125fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com    enum {
102225fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com        kPreallocGeoSrcStateStackCnt = 4,
1023ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com    };
102492669014aa7ab821cdc09cc9ad610316eb16b490bsalomon@google.com    SkSTArray<kPreallocGeoSrcStateStackCnt,
102592669014aa7ab821cdc09cc9ad610316eb16b490bsalomon@google.com              GeometrySrcState, true>           fGeoSrcStateStack;
102625fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com
1027ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com};
1028ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com
102986c1f71625970610e768d3bf26c933db2cd685babsalomon@google.comGR_MAKE_BITFIELD_OPS(GrDrawTarget::BlendOptFlags);
103086c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com
1031ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com#endif
1032