GrDrawTarget.h revision d62e88e5af39347a8fc2a5abdf5feb67d7ea256d
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
148d67c0711b52226db59158a0cfce09f35badd96absalomon@google.com#include "GrClipData.h"
159381363050ec9d3e724076a8e9152bfa9a8de1d1tomhudson@google.com#include "GrDrawState.h"
16934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com#include "GrIndexBuffer.h"
17b9086a026844e4cfd08b219e49ce3f12294cba98bsalomon@google.com#include "SkMatrix.h"
18ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com#include "GrRefCnt.h"
19ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com
208d67c0711b52226db59158a0cfce09f35badd96absalomon@google.com#include "SkClipStack.h"
2112b4e27ae1a29460e91a59f38122483e1faec697sugoi@google.com#include "SkPath.h"
2246f7afb9867200b568c21736da8a8bbb56b20e30bsalomon@google.com#include "SkTLazy.h"
23a2d71482db8b6d752a51c96da74768d7dfc27932robertphillips@google.com#include "SkTArray.h"
248d67c0711b52226db59158a0cfce09f35badd96absalomon@google.com#include "SkXfermode.h"
2597c88c255cff3dbb8343c5d090526fdbedad6dd6Scroggo
26a2d71482db8b6d752a51c96da74768d7dfc27932robertphillips@google.comclass GrClipData;
2764aef2bacd1f5c25ffd9347aabd6265c9b60c0f4bsalomon@google.comclass GrPath;
28ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.comclass GrVertexBuffer;
295f74cf8c49701f514b69dc6f1a8b5c0ffd78af0asugoi@google.comclass SkStrokeRec;
3012b4e27ae1a29460e91a59f38122483e1faec697sugoi@google.com
31ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.comclass GrDrawTarget : public GrRefCnt {
32f66018798099750e639a8fa131fece492a050997bsalomon@google.comprotected:
33f66018798099750e639a8fa131fece492a050997bsalomon@google.com    /** This helper class allows GrDrawTarget subclasses to set the caps values without having to be
34f66018798099750e639a8fa131fece492a050997bsalomon@google.com        made a friend of GrDrawTarget::Caps. */
35f66018798099750e639a8fa131fece492a050997bsalomon@google.com    class CapsInternals {
36f66018798099750e639a8fa131fece492a050997bsalomon@google.com    public:
3718c9c198f571997463d9a7134dbd88298e592ec2bsalomon@google.com        bool f8BitPaletteSupport        : 1;
3818c9c198f571997463d9a7134dbd88298e592ec2bsalomon@google.com        bool fNPOTTextureTileSupport    : 1;
3918c9c198f571997463d9a7134dbd88298e592ec2bsalomon@google.com        bool fTwoSidedStencilSupport    : 1;
4018c9c198f571997463d9a7134dbd88298e592ec2bsalomon@google.com        bool fStencilWrapOpsSupport     : 1;
4118c9c198f571997463d9a7134dbd88298e592ec2bsalomon@google.com        bool fHWAALineSupport           : 1;
4218c9c198f571997463d9a7134dbd88298e592ec2bsalomon@google.com        bool fShaderDerivativeSupport   : 1;
43edfe1aac5c6f3a3f3830e86ddea8dbceeb0e6df4bsalomon@google.com        bool fGeometryShaderSupport     : 1;
4418c9c198f571997463d9a7134dbd88298e592ec2bsalomon@google.com        bool fFSAASupport               : 1;
4518c9c198f571997463d9a7134dbd88298e592ec2bsalomon@google.com        bool fDualSourceBlendingSupport : 1;
4618c9c198f571997463d9a7134dbd88298e592ec2bsalomon@google.com        bool fBufferLockSupport         : 1;
4764aef2bacd1f5c25ffd9347aabd6265c9b60c0f4bsalomon@google.com        bool fPathStencilingSupport     : 1;
4818c9c198f571997463d9a7134dbd88298e592ec2bsalomon@google.com        int fMaxRenderTargetSize;
4918c9c198f571997463d9a7134dbd88298e592ec2bsalomon@google.com        int fMaxTextureSize;
5018c9c198f571997463d9a7134dbd88298e592ec2bsalomon@google.com    };
5118c9c198f571997463d9a7134dbd88298e592ec2bsalomon@google.com
52d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com    class DrawInfo;
53d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com
54f66018798099750e639a8fa131fece492a050997bsalomon@google.compublic:
55f66018798099750e639a8fa131fece492a050997bsalomon@google.com    SK_DECLARE_INST_COUNT(GrDrawTarget)
56f66018798099750e639a8fa131fece492a050997bsalomon@google.com
57f66018798099750e639a8fa131fece492a050997bsalomon@google.com    /**
58f66018798099750e639a8fa131fece492a050997bsalomon@google.com     * Represents the draw target capabilities.
59f66018798099750e639a8fa131fece492a050997bsalomon@google.com     */
60f66018798099750e639a8fa131fece492a050997bsalomon@google.com    class Caps {
61f66018798099750e639a8fa131fece492a050997bsalomon@google.com    public:
62f66018798099750e639a8fa131fece492a050997bsalomon@google.com        Caps() { memset(this, 0, sizeof(Caps)); }
63f66018798099750e639a8fa131fece492a050997bsalomon@google.com        Caps(const Caps& c) { *this = c; }
64f66018798099750e639a8fa131fece492a050997bsalomon@google.com        Caps& operator= (const Caps& c) {
65f66018798099750e639a8fa131fece492a050997bsalomon@google.com            memcpy(this, &c, sizeof(Caps));
66f66018798099750e639a8fa131fece492a050997bsalomon@google.com            return *this;
67f66018798099750e639a8fa131fece492a050997bsalomon@google.com        }
68f66018798099750e639a8fa131fece492a050997bsalomon@google.com        void print() const;
69f66018798099750e639a8fa131fece492a050997bsalomon@google.com
70f66018798099750e639a8fa131fece492a050997bsalomon@google.com        bool eightBitPaletteSupport() const { return fInternals.f8BitPaletteSupport; }
71f66018798099750e639a8fa131fece492a050997bsalomon@google.com        bool npotTextureTileSupport() const { return fInternals.fNPOTTextureTileSupport; }
72f66018798099750e639a8fa131fece492a050997bsalomon@google.com        bool twoSidedStencilSupport() const { return fInternals.fTwoSidedStencilSupport; }
73f66018798099750e639a8fa131fece492a050997bsalomon@google.com        bool stencilWrapOpsSupport() const { return  fInternals.fStencilWrapOpsSupport; }
74f66018798099750e639a8fa131fece492a050997bsalomon@google.com        bool hwAALineSupport() const { return fInternals.fHWAALineSupport; }
75f66018798099750e639a8fa131fece492a050997bsalomon@google.com        bool shaderDerivativeSupport() const { return fInternals.fShaderDerivativeSupport; }
76f66018798099750e639a8fa131fece492a050997bsalomon@google.com        bool geometryShaderSupport() const { return fInternals.fGeometryShaderSupport; }
77f66018798099750e639a8fa131fece492a050997bsalomon@google.com        bool fsaaSupport() const { return fInternals.fFSAASupport; }
78f66018798099750e639a8fa131fece492a050997bsalomon@google.com        bool dualSourceBlendingSupport() const { return fInternals.fDualSourceBlendingSupport; }
79f66018798099750e639a8fa131fece492a050997bsalomon@google.com        bool bufferLockSupport() const { return fInternals.fBufferLockSupport; }
80f66018798099750e639a8fa131fece492a050997bsalomon@google.com        bool pathStencilingSupport() const { return fInternals.fPathStencilingSupport; }
81f66018798099750e639a8fa131fece492a050997bsalomon@google.com
82f66018798099750e639a8fa131fece492a050997bsalomon@google.com        int maxRenderTargetSize() const { return fInternals.fMaxRenderTargetSize; }
83f66018798099750e639a8fa131fece492a050997bsalomon@google.com        int maxTextureSize() const { return fInternals.fMaxTextureSize; }
84f66018798099750e639a8fa131fece492a050997bsalomon@google.com    private:
85f66018798099750e639a8fa131fece492a050997bsalomon@google.com        CapsInternals fInternals;
860d82fe5a4be4aef5b9ce7ca6f4864b72c73452a9bsalomon@google.com        friend class GrDrawTarget; // to set values of fInternals
87f66018798099750e639a8fa131fece492a050997bsalomon@google.com    };
88f66018798099750e639a8fa131fece492a050997bsalomon@google.com
89ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com    ///////////////////////////////////////////////////////////////////////////
90ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com
91ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com    GrDrawTarget();
9225fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com    virtual ~GrDrawTarget();
93ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com
94ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com    /**
9518c9c198f571997463d9a7134dbd88298e592ec2bsalomon@google.com     * Gets the capabilities of the draw target.
9618c9c198f571997463d9a7134dbd88298e592ec2bsalomon@google.com     */
9718c9c198f571997463d9a7134dbd88298e592ec2bsalomon@google.com    const Caps& getCaps() const { return fCaps; }
9818c9c198f571997463d9a7134dbd88298e592ec2bsalomon@google.com
9918c9c198f571997463d9a7134dbd88298e592ec2bsalomon@google.com    /**
100ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     * Sets the current clip to the region specified by clip. All draws will be
101ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     * clipped against this clip if kClip_StateBit is enabled.
102ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     *
1035aaa69e4339e229adfb05e96084a8ec0a590238bbsalomon@google.com     * Setting the clip may (or may not) zero out the client's stencil bits.
1045aaa69e4339e229adfb05e96084a8ec0a590238bbsalomon@google.com     *
105ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     * @param description of the clipping region
106ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     */
107beb1af78d016d2700c350487a383c6bcfa7e2e20robertphillips@google.com    void setClip(const GrClipData* clip);
108ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com
109ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com    /**
110ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     * Gets the current clip.
111ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     *
112ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     * @return the clip.
113ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     */
114beb1af78d016d2700c350487a383c6bcfa7e2e20robertphillips@google.com    const GrClipData* getClip() const;
115ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com
116a5d056ae0b04021dfb44c2c7a3d6a34e060261b8bsalomon@google.com    /**
117a5d056ae0b04021dfb44c2c7a3d6a34e060261b8bsalomon@google.com     * Sets the draw state object for the draw target. Note that this does not
118a5d056ae0b04021dfb44c2c7a3d6a34e060261b8bsalomon@google.com     * make a copy. The GrDrawTarget will take a reference to passed object.
119a5d056ae0b04021dfb44c2c7a3d6a34e060261b8bsalomon@google.com     * Passing NULL will cause the GrDrawTarget to use its own internal draw
120a5d056ae0b04021dfb44c2c7a3d6a34e060261b8bsalomon@google.com     * state object rather than an externally provided one.
121a5d056ae0b04021dfb44c2c7a3d6a34e060261b8bsalomon@google.com     */
122a5d056ae0b04021dfb44c2c7a3d6a34e060261b8bsalomon@google.com    void setDrawState(GrDrawState*  drawState);
123a5d056ae0b04021dfb44c2c7a3d6a34e060261b8bsalomon@google.com
124a5d056ae0b04021dfb44c2c7a3d6a34e060261b8bsalomon@google.com    /**
125a5d056ae0b04021dfb44c2c7a3d6a34e060261b8bsalomon@google.com     * Read-only access to the GrDrawTarget's current draw state.
126a5d056ae0b04021dfb44c2c7a3d6a34e060261b8bsalomon@google.com     */
127a5d056ae0b04021dfb44c2c7a3d6a34e060261b8bsalomon@google.com    const GrDrawState& getDrawState() const { return *fDrawState; }
128a5d056ae0b04021dfb44c2c7a3d6a34e060261b8bsalomon@google.com
129a5d056ae0b04021dfb44c2c7a3d6a34e060261b8bsalomon@google.com    /**
130a5d056ae0b04021dfb44c2c7a3d6a34e060261b8bsalomon@google.com     * Read-write access to the GrDrawTarget's current draw state. Note that
131a5d056ae0b04021dfb44c2c7a3d6a34e060261b8bsalomon@google.com     * this doesn't ref.
132a5d056ae0b04021dfb44c2c7a3d6a34e060261b8bsalomon@google.com     */
133a5d056ae0b04021dfb44c2c7a3d6a34e060261b8bsalomon@google.com    GrDrawState* drawState() { return fDrawState; }
1343d0835b6ac0003c18147b6e9ca76a497b92d1d40bsalomon@google.com
1353d0835b6ac0003c18147b6e9ca76a497b92d1d40bsalomon@google.com    /**
136a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com     * Color alpha and coverage are two inputs to the drawing pipeline. For some
137a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com     * blend modes it is safe to fold the coverage into constant or per-vertex
138a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com     * color alpha value. For other blend modes they must be handled separately.
139a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com     * Depending on features available in the underlying 3D API this may or may
140a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com     * not be possible.
141a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com     *
142e79c815bca39fa552983b7a8107219aa5084acdbbsalomon@google.com     * This function considers the current draw state and the draw target's
143e79c815bca39fa552983b7a8107219aa5084acdbbsalomon@google.com     * capabilities to determine whether coverage can be handled correctly. The
144e79c815bca39fa552983b7a8107219aa5084acdbbsalomon@google.com     * following assumptions are made:
145e79c815bca39fa552983b7a8107219aa5084acdbbsalomon@google.com     *    1. The caller intends to somehow specify coverage. This can be
146e79c815bca39fa552983b7a8107219aa5084acdbbsalomon@google.com     *       specified either by enabling a coverage stage on the GrDrawState or
147e79c815bca39fa552983b7a8107219aa5084acdbbsalomon@google.com     *       via the vertex layout.
148d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com     *    2. Other than enabling coverage stages, the current configuration of
149e79c815bca39fa552983b7a8107219aa5084acdbbsalomon@google.com     *       the target's GrDrawState is as it will be at draw time.
150e79c815bca39fa552983b7a8107219aa5084acdbbsalomon@google.com     *    3. If a vertex source has not yet been specified then all stages with
151e79c815bca39fa552983b7a8107219aa5084acdbbsalomon@google.com     *       non-NULL textures will be referenced by the vertex layout.
152a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com     */
153a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com    bool canApplyCoverage() const;
154a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com
155a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com    /**
156a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com     * Determines whether incorporating partial pixel coverage into the constant
157a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com     * color specified by setColor or per-vertex colors will give the right
158e79c815bca39fa552983b7a8107219aa5084acdbbsalomon@google.com     * blending result. If a vertex source has not yet been specified then
159e79c815bca39fa552983b7a8107219aa5084acdbbsalomon@google.com     * the function assumes that all stages with non-NULL textures will be
160e79c815bca39fa552983b7a8107219aa5084acdbbsalomon@google.com     * referenced by the vertex layout.
161a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com     */
16286c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com    bool canTweakAlphaForCoverage() const;
163a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com
164a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com    /**
165d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com     * Given the current draw state and hw support, will HW AA lines be used
166e79c815bca39fa552983b7a8107219aa5084acdbbsalomon@google.com     * (if line primitive type is drawn)? If a vertex source has not yet been
167e79c815bca39fa552983b7a8107219aa5084acdbbsalomon@google.com     * specified then  the function assumes that all stages with non-NULL
168e79c815bca39fa552983b7a8107219aa5084acdbbsalomon@google.com     * textures will be referenced by the vertex layout.
169a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com     */
1709381363050ec9d3e724076a8e9152bfa9a8de1d1tomhudson@google.com    bool willUseHWAALines() const;
171a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com
1723d0835b6ac0003c18147b6e9ca76a497b92d1d40bsalomon@google.com    /**
173e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com     * There are three types of "sources" of geometry (vertices and indices) for
174e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com     * draw calls made on the target. When performing an indexed draw, the
175e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com     * indices and vertices can use different source types. Once a source is
176934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com     * specified it can be used for multiple draws. However, the time at which
177934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com     * the geometry data is no longer editable depends on the source type.
17825fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com     *
17925fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com     * Sometimes it is necessary to perform a draw while upstack code has
180e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com     * already specified geometry that it isn't finished with. So there are push
181e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com     * and pop methods. This allows the client to push the sources, draw
182e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com     * something using alternate sources, and then pop to restore the original
183e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com     * sources.
184e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com     *
185e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com     * Aside from pushes and pops, a source remains valid until another source
186e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com     * is set or resetVertexSource / resetIndexSource is called. Drawing from
187e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com     * a reset source is an error.
188e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com     *
189e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com     * The three types of sources are:
1901c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com     *
191e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com     * 1. A cpu array (set*SourceToArray). This is useful when the caller
192e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com     *    already provided vertex data in a format compatible with a
193e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com     *    GrVertexLayout. The data in the array is consumed at the time that
194e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com     *    set*SourceToArray is called and subsequent edits to the array will not
195e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com     *    be reflected in draws.
1961c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com     *
19725fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com     * 2. Reserve. This is most useful when the caller has data it must
19825fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com     *    transform before drawing and is not long-lived. The caller requests
19925fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com     *    that the draw target make room for some amount of vertex and/or index
20025fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com     *    data. The target provides ptrs to hold the vertex and/or index data.
20125fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com     *
202d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com     *    The data is writable up until the next drawIndexed, drawNonIndexed,
203934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com     *    drawIndexedInstances, or pushGeometrySource. At this point the data is
204934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com     *    frozen and the ptrs are no longer valid.
2051c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com     *
206e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com     *    Where the space is allocated and how it is uploaded to the GPU is
207e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com     *    subclass-dependent.
208e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com     *
2091c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com     * 3. Vertex and Index Buffers. This is most useful for geometry that will
210e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com     *    is long-lived. When the data in the buffer is consumed depends on the
211d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com     *    GrDrawTarget subclass. For deferred subclasses the caller has to
212e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com     *    guarantee that the data is still available in the buffers at playback.
213e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com     *    (TODO: Make this more automatic as we have done for read/write pixels)
2141c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com     */
2151c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com
2161c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com    /**
217e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com     * Reserves space for vertices and/or indices. Zero can be specifed as
218e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com     * either the vertex or index count if the caller desires to only reserve
219d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com     * space for only indices or only vertices. If zero is specifed for
220e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com     * vertexCount then the vertex source will be unmodified and likewise for
221e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com     * indexCount.
222ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     *
223e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com     * If the function returns true then the reserve suceeded and the vertices
224e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com     * and indices pointers will point to the space created.
225ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     *
226e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com     * If the target cannot make space for the request then this function will
227e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com     * return false. If vertexCount was non-zero then upon failure the vertex
228e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com     * source is reset and likewise for indexCount.
229ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     *
230e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com     * The pointers to the space allocated for vertices and indices remain valid
231934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com     * until a drawIndexed, drawNonIndexed, drawIndexedInstances, or push/
232934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com     * popGeomtrySource is called. At that point logically a snapshot of the
233934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com     * data is made and the pointers are invalid.
2341c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com     *
235ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     * @param vertexLayout the format of vertices (ignored if vertexCount == 0).
236e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com     * @param vertexCount  the number of vertices to reserve space for. Can be
237e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com     *                     0.
23825fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com     * @param indexCount   the number of indices to reserve space for. Can be 0.
239e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com     * @param vertices     will point to reserved vertex space if vertexCount is
240d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com     *                     non-zero. Illegal to pass NULL if vertexCount > 0.
24125fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com     * @param indices      will point to reserved index space if indexCount is
24225fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com     *                     non-zero. Illegal to pass NULL if indexCount > 0.
24325fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com     */
24497805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com     bool reserveVertexAndIndexSpace(GrVertexLayout vertexLayout,
24597805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com                                     int vertexCount,
24697805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com                                     int indexCount,
24797805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com                                     void** vertices,
24897805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com                                     void** indices);
24925fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com
250ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com    /**
251ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     * Provides hints to caller about the number of vertices and indices
252ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     * that can be allocated cheaply. This can be useful if caller is reserving
253ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     * space but doesn't know exactly how much geometry is needed.
254ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     *
255ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     * Also may hint whether the draw target should be flushed first. This is
256ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     * useful for deferred targets.
257ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     *
258a63389843dd18003382d61c2e4610af09ed07d38jvanverth@google.com     * @param vertexSize   size of vertices caller would like to reserve
259ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     * @param vertexCount  in: hint about how many vertices the caller would
260ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     *                     like to allocate.
261ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     *                     out: a hint about the number of vertices that can be
262ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     *                     allocated cheaply. Negative means no hint.
263ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     *                     Ignored if NULL.
264ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     * @param indexCount   in: hint about how many indices the caller would
265ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     *                     like to allocate.
266ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     *                     out: a hint about the number of indices that can be
267ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     *                     allocated cheaply. Negative means no hint.
268ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     *                     Ignored if NULL.
269ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     *
270ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     * @return  true if target should be flushed based on the input values.
271ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     */
272a63389843dd18003382d61c2e4610af09ed07d38jvanverth@google.com    virtual bool geometryHints(size_t vertexSize,
2731c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com                               int* vertexCount,
2741c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com                               int* indexCount) const;
275ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com
276ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com    /**
2771c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com     * Sets source of vertex data for the next draw. Array must contain
2781c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com     * the vertex data when this is called.
279ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     *
280ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     * @param array         cpu array containing vertex data.
2811c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com     * @param size          size of the vertex data.
2821c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com     * @param vertexCount   the number of vertices in the array.
283ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     */
2841c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com    void setVertexSourceToArray(GrVertexLayout vertexLayout,
2851c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com                                const void* vertexArray,
2861c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com                                int vertexCount);
287ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com
288ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com    /**
2891c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com     * Sets source of index data for the next indexed draw. Array must contain
2901c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com     * the indices when this is called.
291ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     *
2921c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com     * @param array         cpu array containing index data.
2931c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com     * @param indexCount    the number of indices in the array.
294ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     */
2951c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com    void setIndexSourceToArray(const void* indexArray, int indexCount);
296ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com
297ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com    /**
298ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     * Sets source of vertex data for the next draw. Data does not have to be
299934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com     * in the buffer until drawIndexed, drawNonIndexed, or drawIndexedInstances.
300ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     *
301ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     * @param buffer        vertex buffer containing vertex data. Must be
302ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     *                      unlocked before draw call.
303ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     * @param vertexLayout  layout of the vertex data in the buffer.
304ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     */
3051c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com    void setVertexSourceToBuffer(GrVertexLayout vertexLayout,
3061c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com                                 const GrVertexBuffer* buffer);
307ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com
308ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com    /**
309ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     * Sets source of index data for the next indexed draw. Data does not have
310934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com     * to be in the buffer until drawIndexed.
311ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     *
312ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     * @param buffer index buffer containing indices. Must be unlocked
313ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     *               before indexed draw call.
314ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     */
315ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com    void setIndexSourceToBuffer(const GrIndexBuffer* buffer);
316d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com
31725fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com    /**
31825fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com     * Resets vertex source. Drawing from reset vertices is illegal. Set vertex
31925fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com     * source to reserved, array, or buffer before next draw. May be able to free
32025fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com     * up temporary storage allocated by setVertexSourceToArray or
32125fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com     * reserveVertexSpace.
32225fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com     */
32325fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com    void resetVertexSource();
324d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com
32525fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com    /**
32625fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com     * Resets index source. Indexed Drawing from reset indices is illegal. Set
32725fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com     * index source to reserved, array, or buffer before next indexed draw. May
32825fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com     * be able to free up temporary storage allocated by setIndexSourceToArray
32925fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com     * or reserveIndexSpace.
33025fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com     */
33197805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com    void resetIndexSource();
332d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com
33397805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com    /**
33497805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com     * Query to find out if the vertex or index source is reserved.
33597805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com     */
33697805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com    bool hasReservedVerticesOrIndices() const {
33773d98aace4f74acc39d8de33484c8aec8e917739bsalomon@google.com        return kReserved_GeometrySrcType == this->getGeomSrc().fVertexSrc ||
33897805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com        kReserved_GeometrySrcType == this->getGeomSrc().fIndexSrc;
33997805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com    }
340ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com
341ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com    /**
34225fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com     * Pushes and resets the vertex/index sources. Any reserved vertex / index
34325fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com     * data is finalized (i.e. cannot be updated after the matching pop but can
34425fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com     * be drawn from). Must be balanced by a pop.
34525fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com     */
34625fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com    void pushGeometrySource();
34725fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com
34825fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com    /**
34925fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com     * Pops the vertex / index sources from the matching push.
35025fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com     */
35125fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com    void popGeometrySource();
35264aef2bacd1f5c25ffd9347aabd6265c9b60c0f4bsalomon@google.com
35325fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com    /**
354ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     * Draws indexed geometry using the current state and current vertex / index
355ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     * sources.
356ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     *
357ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     * @param type         The type of primitives to draw.
358ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     * @param startVertex  the vertex in the vertex array/buffer corresponding
359ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     *                     to index 0
360ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     * @param startIndex   first index to read from index src.
361ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     * @param vertexCount  one greater than the max index.
362ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     * @param indexCount   the number of index elements to read. The index count
363ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     *                     is effectively trimmed to the last completely
364ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     *                     specified primitive.
365d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com     * @param devBounds    optional bounds hint. This is a promise from the caller,
366d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com     *                     not a request for clipping.
367ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     */
36825fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com    void drawIndexed(GrPrimitiveType type,
36925fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com                     int startVertex,
37025fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com                     int startIndex,
37125fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com                     int vertexCount,
372d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com                     int indexCount,
373d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com                     const SkRect* devBounds = NULL);
374ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com
375ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com    /**
376ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     * Draws non-indexed geometry using the current state and current vertex
377ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     * sources.
378ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     *
379ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     * @param type         The type of primitives to draw.
380ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     * @param startVertex  the vertex in the vertex array/buffer corresponding
381ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     *                     to index 0
382ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     * @param vertexCount  one greater than the max index.
383d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com     * @param devBounds    optional bounds hint. This is a promise from the caller,
384d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com     *                     not a request for clipping.
385ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     */
38625fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com    void drawNonIndexed(GrPrimitiveType type,
38725fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com                        int startVertex,
388d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com                        int vertexCount,
389d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com                        const SkRect* devBounds = NULL);
390ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com
39186afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com    /**
39264aef2bacd1f5c25ffd9347aabd6265c9b60c0f4bsalomon@google.com     * Draws path into the stencil buffer. The fill must be either even/odd or
39364aef2bacd1f5c25ffd9347aabd6265c9b60c0f4bsalomon@google.com     * winding (not inverse or hairline). It will respect the HW antialias flag
39464aef2bacd1f5c25ffd9347aabd6265c9b60c0f4bsalomon@google.com     * on the draw state (if possible in the 3D API).
39564aef2bacd1f5c25ffd9347aabd6265c9b60c0f4bsalomon@google.com     */
3965f74cf8c49701f514b69dc6f1a8b5c0ffd78af0asugoi@google.com    void stencilPath(const GrPath*, const SkStrokeRec& stroke, SkPath::FillType fill);
39764aef2bacd1f5c25ffd9347aabd6265c9b60c0f4bsalomon@google.com
39864aef2bacd1f5c25ffd9347aabd6265c9b60c0f4bsalomon@google.com    /**
39986afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com     * Helper function for drawing rects. This does not use the current index
40086afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com     * and vertex sources. After returning, the vertex and index sources may
40186afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com     * have changed. They should be reestablished before the next drawIndexed
40286afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com     * or drawNonIndexed. This cannot be called between reserving and releasing
403d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com     * geometry.
404d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com     *
405d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com     * A subclass may override this to perform more optimal rect rendering. Its
406d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com     * draws should be funneled through one of the public GrDrawTarget draw methods
407d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com     * (e.g. drawNonIndexed, drawIndexedInstances, ...). The base class draws a two
408d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com     * triangle fan using drawNonIndexed from reserved vertex space.
409d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com     *
41086afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com     * @param rect      the rect to draw
41186afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com     * @param matrix    optional matrix applied to rect (before viewMatrix)
41286afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com     * @param srcRects  specifies rects for stages enabled by stageEnableMask.
41386afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com     *                  if stageEnableMask bit i is 1, srcRects is not NULL,
41486afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com     *                  and srcRects[i] is not NULL, then srcRects[i] will be
41586afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com     *                  used as coordinates for stage i. Otherwise, if stage i
41686afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com     *                  is enabled then rect is used as the coordinates.
41786afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com     * @param srcMatrices   optional matrices applied to srcRects. If
41886afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com     *                      srcRect[i] is non-NULL and srcMatrices[i] is
41986afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com     *                      non-NULL then srcRect[i] will be transformed by
42086afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com     *                      srcMatrix[i]. srcMatrices can be NULL when no
42186afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com     *                      srcMatrices are desired.
42286afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com     */
423d302f1401b3c9aea094804bad4e76de98782cfe8bsalomon@google.com    virtual void drawRect(const GrRect& rect,
424b9086a026844e4cfd08b219e49ce3f12294cba98bsalomon@google.com                          const SkMatrix* matrix,
42586afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com                          const GrRect* srcRects[],
426b9086a026844e4cfd08b219e49ce3f12294cba98bsalomon@google.com                          const SkMatrix* srcMatrices[]);
427cf939ae54842fc7408ee68a41427086962b4c3dcbsalomon@google.com    /**
428cf939ae54842fc7408ee68a41427086962b4c3dcbsalomon@google.com     * Helper for drawRect when the caller doesn't need separate src rects or
429cf939ae54842fc7408ee68a41427086962b4c3dcbsalomon@google.com     * matrices.
430cf939ae54842fc7408ee68a41427086962b4c3dcbsalomon@google.com     */
431cf939ae54842fc7408ee68a41427086962b4c3dcbsalomon@google.com    void drawSimpleRect(const GrRect& rect, const SkMatrix* matrix = NULL) {
432cf939ae54842fc7408ee68a41427086962b4c3dcbsalomon@google.com        drawRect(rect, matrix, NULL, NULL);
433cf939ae54842fc7408ee68a41427086962b4c3dcbsalomon@google.com    }
434cf939ae54842fc7408ee68a41427086962b4c3dcbsalomon@google.com    void drawSimpleRect(const GrIRect& irect, const SkMatrix* matrix = NULL) {
435cf939ae54842fc7408ee68a41427086962b4c3dcbsalomon@google.com        SkRect rect = SkRect::MakeFromIRect(irect);
436cf939ae54842fc7408ee68a41427086962b4c3dcbsalomon@google.com        this->drawRect(rect, matrix, NULL, NULL);
437cf939ae54842fc7408ee68a41427086962b4c3dcbsalomon@google.com    }
43886afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com
43986afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com    /**
440934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com     * This call is used to draw multiple instances of some geometry with a
441934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com     * given number of vertices (V) and indices (I) per-instance. The indices in
442934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com     * the index source must have the form i[k+I] == i[k] + V. Also, all indices
443934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com     * i[kI] ... i[(k+1)I-1] must be elements of the range kV ... (k+1)V-1. As a
444934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com     * concrete example, the following index buffer for drawing a series of
445934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com     * quads each as two triangles each satisfies these conditions with V=4 and
446934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com     * I=6:
447934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com     *      (0,1,2,0,2,3, 4,5,6,4,6,7, 8,9,10,8,10,11, ...)
448934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com     *
449934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com     * The call assumes that the pattern of indices fills the entire index
450934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com     * source. The size of the index buffer limits the number of instances that
451934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com     * can be drawn by the GPU in a single draw. However, the caller may specify
452934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com     * any (positive) number for instanceCount and if necessary multiple GPU
453d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com     * draws will be issued. Moreover, when drawIndexedInstances is called
454934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com     * multiple times it may be possible for GrDrawTarget to group them into a
455934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com     * single GPU draw.
456934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com     *
457934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com     * @param type          the type of primitives to draw
458934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com     * @param instanceCount the number of instances to draw. Each instance
459934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com     *                      consists of verticesPerInstance vertices indexed by
460934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com     *                      indicesPerInstance indices drawn as the primitive
461934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com     *                      type specified by type.
462934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com     * @param verticesPerInstance   The number of vertices in each instance (V
463934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com     *                              in the above description).
464934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com     * @param indicesPerInstance    The number of indices in each instance (I
465934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com     *                              in the above description).
466d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com     * @param devBounds    optional bounds hint. This is a promise from the caller,
467d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com     *                     not a request for clipping.
468934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com     */
469d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com    void drawIndexedInstances(GrPrimitiveType type,
470d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com                              int instanceCount,
471d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com                              int verticesPerInstance,
472d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com                              int indicesPerInstance,
473d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com                              const SkRect* devBounds = NULL);
474934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com
475934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com    /**
476d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com     * Clear the current render target if one isn't passed in. Ignores the
477d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com     * clip and all other draw state (blend mode, stages, etc). Clears the
478c82a8b7aa4ec19fba508c394920a9e88d3e5bd12robertphillips@google.com     * whole thing if rect is NULL, otherwise just the rect.
4790b335c1ac100aeacf79a4c98a052286fd46661e7bsalomon@google.com     */
480d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com    virtual void clear(const GrIRect* rect,
481c82a8b7aa4ec19fba508c394920a9e88d3e5bd12robertphillips@google.com                       GrColor color,
482c82a8b7aa4ec19fba508c394920a9e88d3e5bd12robertphillips@google.com                       GrRenderTarget* renderTarget = NULL) = 0;
4830b335c1ac100aeacf79a4c98a052286fd46661e7bsalomon@google.com
484ff17584e1c15f68ccc296be517e8a6776a9ddabdrobertphillips@google.com    /**
485ff17584e1c15f68ccc296be517e8a6776a9ddabdrobertphillips@google.com     * Release any resources that are cached but not currently in use. This
486ff17584e1c15f68ccc296be517e8a6776a9ddabdrobertphillips@google.com     * is intended to give an application some recourse when resources are low.
487ff17584e1c15f68ccc296be517e8a6776a9ddabdrobertphillips@google.com     */
488ff17584e1c15f68ccc296be517e8a6776a9ddabdrobertphillips@google.com    virtual void purgeResources() {};
489ff17584e1c15f68ccc296be517e8a6776a9ddabdrobertphillips@google.com
490d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com    /**
491d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com     * For subclass internal use to invoke a call to onDraw(). See DrawInfo below.
492d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com     */
493d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com    void executeDraw(const DrawInfo& info) { this->onDraw(info); }
494d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com
49525fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com    ////////////////////////////////////////////////////////////////////////////
496ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com
497873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com    /**
498873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com     * See AutoStateRestore below.
499873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com     */
500873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com    enum ASRInit {
501873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com        kPreserve_ASRInit,
502873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com        kReset_ASRInit
503873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com    };
504873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com
505873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com    /**
506873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com     * Saves off the current state and restores it in the destructor. It will
507873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com     * install a new GrDrawState object on the target (setDrawState) and restore
508873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com     * the previous one in the destructor. The caller should call drawState() to
509873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com     * get the new draw state after the ASR is installed.
510873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com     *
511873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com     * GrDrawState* state = target->drawState();
512873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com     * AutoStateRestore asr(target, GrDrawTarget::kReset_ASRInit).
513873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com     * state->setRenderTarget(rt); // state refers to the GrDrawState set on
514873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com     *                             // target before asr was initialized.
515873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com     *                             // Therefore, rt is set on the GrDrawState
516873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com     *                             // that will be restored after asr's
517873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com     *                             // destructor rather than target's current
518d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com     *                             // GrDrawState.
519873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com     */
520ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com    class AutoStateRestore : ::GrNoncopyable {
521ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com    public:
522873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com        /**
523873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com         * Default ASR will have no effect unless set() is subsequently called.
524873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com         */
52506afe7b5a1ef03bfc6494c51ab2a1f7a386de5c2bsalomon@google.com        AutoStateRestore();
526873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com
527873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com        /**
528873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com         * Saves the state on target. The state will be restored when the ASR
529873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com         * is destroyed. If this constructor is used do not call set().
530873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com         *
531873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com         * @param init  Should the newly installed GrDrawState be a copy of the
532873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com         *              previous state or a default-initialized GrDrawState.
533873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com         */
534873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com        AutoStateRestore(GrDrawTarget* target, ASRInit init);
535873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com
536ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com        ~AutoStateRestore();
537ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com
53806afe7b5a1ef03bfc6494c51ab2a1f7a386de5c2bsalomon@google.com        /**
539873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com         * Saves the state on target. The state will be restored when the ASR
540873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com         * is destroyed. This should only be called once per ASR object and only
541873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com         * when the default constructor was used. For nested saves use multiple
542873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com         * ASR objects.
543873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com         *
544873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com         * @param init  Should the newly installed GrDrawState be a copy of the
545873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com         *              previous state or a default-initialized GrDrawState.
54606afe7b5a1ef03bfc6494c51ab2a1f7a386de5c2bsalomon@google.com         */
547873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com        void set(GrDrawTarget* target, ASRInit init);
54806afe7b5a1ef03bfc6494c51ab2a1f7a386de5c2bsalomon@google.com
549ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com    private:
550873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com        GrDrawTarget*        fDrawTarget;
551873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com        SkTLazy<GrDrawState> fTempState;
552873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com        GrDrawState*         fSavedState;
553ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com    };
554ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com
55525fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com    ////////////////////////////////////////////////////////////////////////////
5561c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com
557ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com    class AutoReleaseGeometry : ::GrNoncopyable {
558ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com    public:
559ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com        AutoReleaseGeometry(GrDrawTarget*  target,
560ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com                            GrVertexLayout vertexLayout,
56125fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com                            int            vertexCount,
56225fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com                            int            indexCount);
56325fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com        AutoReleaseGeometry();
56425fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com        ~AutoReleaseGeometry();
5655782d712ffc31557d0cb12d5a220cebb783f6895bsalomon@google.com        bool set(GrDrawTarget*  target,
5665782d712ffc31557d0cb12d5a220cebb783f6895bsalomon@google.com                 GrVertexLayout vertexLayout,
56725fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com                 int            vertexCount,
56825fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com                 int            indexCount);
569a47a48dca5045d71cbc5de343404045209a13e15bsalomon@google.com        bool succeeded() const { return NULL != fTarget; }
5706513cd06ae34f5d777b3aaea0b4533014d0a10f2bsalomon@google.com        void* vertices() const { GrAssert(this->succeeded()); return fVertices; }
5716513cd06ae34f5d777b3aaea0b4533014d0a10f2bsalomon@google.com        void* indices() const { GrAssert(this->succeeded()); return fIndices; }
572ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com        GrPoint* positions() const {
5736513cd06ae34f5d777b3aaea0b4533014d0a10f2bsalomon@google.com            return static_cast<GrPoint*>(this->vertices());
574ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com        }
575ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com
576ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com    private:
57725fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com        void reset();
578d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com
579ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com        GrDrawTarget* fTarget;
580ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com        void*         fVertices;
581ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com        void*         fIndices;
582ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com    };
583ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com
58425fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com    ////////////////////////////////////////////////////////////////////////////
585ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com
586ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com    class AutoClipRestore : ::GrNoncopyable {
587ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com    public:
588ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com        AutoClipRestore(GrDrawTarget* target) {
589ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com            fTarget = target;
590ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com            fClip = fTarget->getClip();
591ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com        }
592ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com
5938d67c0711b52226db59158a0cfce09f35badd96absalomon@google.com        AutoClipRestore(GrDrawTarget* target, const SkIRect& newClip);
5948d67c0711b52226db59158a0cfce09f35badd96absalomon@google.com
595ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com        ~AutoClipRestore() {
596ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com            fTarget->setClip(fClip);
597ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com        }
598ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com    private:
5998d67c0711b52226db59158a0cfce09f35badd96absalomon@google.com        GrDrawTarget*           fTarget;
6008d67c0711b52226db59158a0cfce09f35badd96absalomon@google.com        const GrClipData*       fClip;
6018d67c0711b52226db59158a0cfce09f35badd96absalomon@google.com        SkTLazy<SkClipStack>    fStack;
6028d67c0711b52226db59158a0cfce09f35badd96absalomon@google.com        GrClipData              fReplacementClip;
603ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com    };
604d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com
60525fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com    ////////////////////////////////////////////////////////////////////////////
606d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com
60725fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com    class AutoGeometryPush : ::GrNoncopyable {
60825fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com    public:
60925fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com        AutoGeometryPush(GrDrawTarget* target) {
61025fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com            GrAssert(NULL != target);
61125fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com            fTarget = target;
61225fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com            target->pushGeometrySource();
61325fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com        }
61425fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com        ~AutoGeometryPush() {
61525fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com            fTarget->popGeometrySource();
61625fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com        }
61725fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com    private:
61825fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com        GrDrawTarget* fTarget;
61925fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com    };
620ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com
621ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.comprotected:
622471d471dcd7422e5dd9c822c1092b2ba4721dcfebsalomon@google.com
62386c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com    /**
62486c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com     * Optimizations for blending / coverage to be applied based on the current
62586c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com     * state.
62686c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com     * Subclasses that actually draw (as opposed to those that just buffer for
62786c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com     * playback) must implement the flags that replace the output color.
62886c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com     */
62986c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com    enum BlendOptFlags {
63086c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com        /**
63186c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com         * No optimization
63286c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com         */
63386c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com        kNone_BlendOpt = 0,
63486c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com        /**
63586c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com         * Don't draw at all
63686c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com         */
63786c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com        kSkipDraw_BlendOptFlag = 0x2,
63886c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com        /**
63986c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com         * Emit the src color, disable HW blending (replace dst with src)
64086c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com         */
64186c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com        kDisableBlend_BlendOptFlag = 0x4,
64286c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com        /**
64386c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com         * The coverage value does not have to be computed separately from
64486c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com         * alpha, the the output color can be the modulation of the two.
64586c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com         */
64686c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com        kCoverageAsAlpha_BlendOptFlag = 0x1,
64786c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com        /**
64886c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com         * Instead of emitting a src color, emit coverage in the alpha channel
64986c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com         * and r,g,b are "don't cares".
65086c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com         */
65186c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com        kEmitCoverage_BlendOptFlag = 0x10,
65286c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com        /**
65386c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com         * Emit transparent black instead of the src color, no need to compute
65486c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com         * coverage.
65586c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com         */
65686c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com        kEmitTransBlack_BlendOptFlag = 0x8,
65786c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com    };
65886c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com    GR_DECL_BITFIELD_OPS_FRIENDS(BlendOptFlags);
65986c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com
66061b05dcc7ebe48663c3ba84b7bd7449d6c887ac1skia.committer@gmail.com    /**
661cf939ae54842fc7408ee68a41427086962b4c3dcbsalomon@google.com     * Determines what optimizations can be applied based on the blend. The coefficients may have
662cf939ae54842fc7408ee68a41427086962b4c3dcbsalomon@google.com     * to be tweaked in order for the optimization to work. srcCoeff and dstCoeff are optional
663cf939ae54842fc7408ee68a41427086962b4c3dcbsalomon@google.com     * params that receive the tweaked coefficients. Normally the function looks at the current
664cf939ae54842fc7408ee68a41427086962b4c3dcbsalomon@google.com     * state to see if coverage is enabled. By setting forceCoverage the caller can speculatively
665cf939ae54842fc7408ee68a41427086962b4c3dcbsalomon@google.com     * determine the blend optimizations that would be used if there was partial pixel coverage.
666cf939ae54842fc7408ee68a41427086962b4c3dcbsalomon@google.com     */
66786c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com    BlendOptFlags getBlendOpts(bool forceCoverage = false,
66886c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com                               GrBlendCoeff* srcCoeff = NULL,
66986c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com                               GrBlendCoeff* dstCoeff = NULL) const;
67086c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com
67125fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com    enum GeometrySrcType {
67225fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com        kNone_GeometrySrcType,     //<! src has not been specified
67325fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com        kReserved_GeometrySrcType, //<! src was set using reserve*Space
67425fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com        kArray_GeometrySrcType,    //<! src was set using set*SourceToArray
67525fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com        kBuffer_GeometrySrcType    //<! src was set using set*SourceToBuffer
67625fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com    };
677d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com
67825fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com    struct GeometrySrcState {
67925fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com        GeometrySrcType         fVertexSrc;
68025fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com        union {
68125fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com            // valid if src type is buffer
68225fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com            const GrVertexBuffer*   fVertexBuffer;
68325fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com            // valid if src type is reserved or array
68425fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com            int                     fVertexCount;
68525fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com        };
686d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com
68725fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com        GeometrySrcType         fIndexSrc;
68825fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com        union {
68925fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com            // valid if src type is buffer
69025fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com            const GrIndexBuffer*    fIndexBuffer;
69125fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com            // valid if src type is reserved or array
69225fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com            int                     fIndexCount;
69325fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com        };
694d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com
69525fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com        GrVertexLayout          fVertexLayout;
69625fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com    };
697934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com
698934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com    int indexCountInCurrentSource() const {
699934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com        const GeometrySrcState& src = this->getGeomSrc();
700934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com        switch (src.fIndexSrc) {
701934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com            case kNone_GeometrySrcType:
702934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com                return 0;
703934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com            case kReserved_GeometrySrcType:
704934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com            case kArray_GeometrySrcType:
705934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com                return src.fIndexCount;
706934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com            case kBuffer_GeometrySrcType:
707934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com                return src.fIndexBuffer->sizeInBytes() / sizeof(uint16_t);
708934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com            default:
709934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com                GrCrash("Unexpected Index Source.");
710934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com                return 0;
711934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com        }
712934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com    }
713a47a48dca5045d71cbc5de343404045209a13e15bsalomon@google.com
71402ddc8b85ace91b15feb329a6a1d5d62b2b846c6bsalomon@google.com    // allows derived class to set the caps
71502ddc8b85ace91b15feb329a6a1d5d62b2b846c6bsalomon@google.com    CapsInternals* capsInternals() { return &fCaps.fInternals; }
71602ddc8b85ace91b15feb329a6a1d5d62b2b846c6bsalomon@google.com
71702ddc8b85ace91b15feb329a6a1d5d62b2b846c6bsalomon@google.com    // A subclass may override this function if it wishes to be notified when the clip is changed.
71802ddc8b85ace91b15feb329a6a1d5d62b2b846c6bsalomon@google.com    // The override should call INHERITED::clipWillBeSet().
71902ddc8b85ace91b15feb329a6a1d5d62b2b846c6bsalomon@google.com    virtual void clipWillBeSet(const GrClipData* clipData);
72002ddc8b85ace91b15feb329a6a1d5d62b2b846c6bsalomon@google.com
72102ddc8b85ace91b15feb329a6a1d5d62b2b846c6bsalomon@google.com    // subclasses must call this in their destructors to ensure all vertex
72202ddc8b85ace91b15feb329a6a1d5d62b2b846c6bsalomon@google.com    // and index sources have been released (including those held by
72302ddc8b85ace91b15feb329a6a1d5d62b2b846c6bsalomon@google.com    // pushGeometrySource())
72402ddc8b85ace91b15feb329a6a1d5d62b2b846c6bsalomon@google.com    void releaseGeometry();
72502ddc8b85ace91b15feb329a6a1d5d62b2b846c6bsalomon@google.com
72602ddc8b85ace91b15feb329a6a1d5d62b2b846c6bsalomon@google.com    // accessors for derived classes
72702ddc8b85ace91b15feb329a6a1d5d62b2b846c6bsalomon@google.com    const GeometrySrcState& getGeomSrc() const { return fGeoSrcStateStack.back(); }
72802ddc8b85ace91b15feb329a6a1d5d62b2b846c6bsalomon@google.com    // it is preferable to call this rather than getGeomSrc()->fVertexLayout because of the assert.
72902ddc8b85ace91b15feb329a6a1d5d62b2b846c6bsalomon@google.com    GrVertexLayout getVertexLayout() const {
73002ddc8b85ace91b15feb329a6a1d5d62b2b846c6bsalomon@google.com        // the vertex layout is only valid if a vertex source has been specified.
73102ddc8b85ace91b15feb329a6a1d5d62b2b846c6bsalomon@google.com        GrAssert(this->getGeomSrc().fVertexSrc != kNone_GeometrySrcType);
73202ddc8b85ace91b15feb329a6a1d5d62b2b846c6bsalomon@google.com        return this->getGeomSrc().fVertexLayout;
733a47a48dca5045d71cbc5de343404045209a13e15bsalomon@google.com    }
7345782d712ffc31557d0cb12d5a220cebb783f6895bsalomon@google.com
73502ddc8b85ace91b15feb329a6a1d5d62b2b846c6bsalomon@google.com    Caps fCaps;
73602ddc8b85ace91b15feb329a6a1d5d62b2b846c6bsalomon@google.com
737d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com    /**
738d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com     * Used to communicate draws to subclass's onDraw function.
739d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com     */
74074749cd45c29b4f5300e2518f2c2c765ce8ae208bsalomon@google.com    class DrawInfo {
74174749cd45c29b4f5300e2518f2c2c765ce8ae208bsalomon@google.com    public:
74274749cd45c29b4f5300e2518f2c2c765ce8ae208bsalomon@google.com        DrawInfo(const DrawInfo& di) { (*this) = di; }
743d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com        DrawInfo& operator =(const DrawInfo& di);
74474749cd45c29b4f5300e2518f2c2c765ce8ae208bsalomon@google.com
74574749cd45c29b4f5300e2518f2c2c765ce8ae208bsalomon@google.com        GrPrimitiveType primitiveType() const { return fPrimitiveType; }
74674749cd45c29b4f5300e2518f2c2c765ce8ae208bsalomon@google.com        int startVertex() const { return fStartVertex; }
74774749cd45c29b4f5300e2518f2c2c765ce8ae208bsalomon@google.com        int startIndex() const { return fStartIndex; }
74874749cd45c29b4f5300e2518f2c2c765ce8ae208bsalomon@google.com        int vertexCount() const { return fVertexCount; }
74974749cd45c29b4f5300e2518f2c2c765ce8ae208bsalomon@google.com        int indexCount() const { return fIndexCount; }
750d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com        int verticesPerInstance() const { return fVerticesPerInstance; }
751d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com        int indicesPerInstance() const { return fIndicesPerInstance; }
752d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com        int instanceCount() const { return fInstanceCount; }
75374749cd45c29b4f5300e2518f2c2c765ce8ae208bsalomon@google.com
75474749cd45c29b4f5300e2518f2c2c765ce8ae208bsalomon@google.com        bool isIndexed() const { return fIndexCount > 0; }
755d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com#if GR_DEBUG
756d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com        bool isInstanced() const; // this version is longer because of asserts
757d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com#else
758d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com        bool isInstanced() const { return fInstanceCount > 0; }
759d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com#endif
760d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com
761d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com        // adds or remove instances
762d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com        void adjustInstanceCount(int instanceOffset);
763d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com        // shifts the start vertex
764d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com        void adjustStartVertex(int vertexOffset);
765d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com        // shifts the start index
766d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com        void adjustStartIndex(int indexOffset);
767d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com
768d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com        void setDevBounds(const SkRect& bounds) {
769d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com            fDevBoundsStorage = bounds;
770d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com            fDevBounds = &fDevBoundsStorage;
771d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com        }
772d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com        const SkRect* getDevBounds() const { return fDevBounds; }
77374749cd45c29b4f5300e2518f2c2c765ce8ae208bsalomon@google.com
77474749cd45c29b4f5300e2518f2c2c765ce8ae208bsalomon@google.com    private:
775d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com        DrawInfo() { fDevBounds = NULL; }
776d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com
77774749cd45c29b4f5300e2518f2c2c765ce8ae208bsalomon@google.com        friend class GrDrawTarget;
778d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com
77974749cd45c29b4f5300e2518f2c2c765ce8ae208bsalomon@google.com        GrPrimitiveType fPrimitiveType;
78074749cd45c29b4f5300e2518f2c2c765ce8ae208bsalomon@google.com
78174749cd45c29b4f5300e2518f2c2c765ce8ae208bsalomon@google.com        int             fStartVertex;
78274749cd45c29b4f5300e2518f2c2c765ce8ae208bsalomon@google.com        int             fStartIndex;
78374749cd45c29b4f5300e2518f2c2c765ce8ae208bsalomon@google.com        int             fVertexCount;
78474749cd45c29b4f5300e2518f2c2c765ce8ae208bsalomon@google.com        int             fIndexCount;
785d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com
786d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com        int             fInstanceCount;
787d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com        int             fVerticesPerInstance;
788d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com        int             fIndicesPerInstance;
789d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com
790d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com        SkRect          fDevBoundsStorage;
791d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com        SkRect*         fDevBounds;
79274749cd45c29b4f5300e2518f2c2c765ce8ae208bsalomon@google.com    };
79374749cd45c29b4f5300e2518f2c2c765ce8ae208bsalomon@google.com
79402ddc8b85ace91b15feb329a6a1d5d62b2b846c6bsalomon@google.comprivate:
79502ddc8b85ace91b15feb329a6a1d5d62b2b846c6bsalomon@google.com    // A subclass can optionally overload this function to be notified before
79602ddc8b85ace91b15feb329a6a1d5d62b2b846c6bsalomon@google.com    // vertex and index space is reserved.
797a63389843dd18003382d61c2e4610af09ed07d38jvanverth@google.com    virtual void willReserveVertexAndIndexSpace(size_t vertexSize, int vertexCount, int indexCount) {}
79897805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com
79925fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com    // implemented by subclass to allocate space for reserved geom
800a63389843dd18003382d61c2e4610af09ed07d38jvanverth@google.com    virtual bool onReserveVertexSpace(size_t vertexSize, int vertexCount, void** vertices) = 0;
80125fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com    virtual bool onReserveIndexSpace(int indexCount, void** indices) = 0;
80225fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com    // implemented by subclass to handle release of reserved geom space
80325fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com    virtual void releaseReservedVertexSpace() = 0;
80425fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com    virtual void releaseReservedIndexSpace() = 0;
80525fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com    // subclass must consume array contents when set
80602ddc8b85ace91b15feb329a6a1d5d62b2b846c6bsalomon@google.com    virtual void onSetVertexSourceToArray(const void* vertexArray, int vertexCount) = 0;
80702ddc8b85ace91b15feb329a6a1d5d62b2b846c6bsalomon@google.com    virtual void onSetIndexSourceToArray(const void* indexArray, int indexCount) = 0;
80825fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com    // subclass is notified that geom source will be set away from an array
80925fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com    virtual void releaseVertexArray() = 0;
81025fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com    virtual void releaseIndexArray() = 0;
81102ddc8b85ace91b15feb329a6a1d5d62b2b846c6bsalomon@google.com    // subclass overrides to be notified just before geo src state is pushed/popped.
81225fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com    virtual void geometrySourceWillPush() = 0;
81325fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com    virtual void geometrySourceWillPop(const GeometrySrcState& restoredState) = 0;
81425fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com    // subclass called to perform drawing
81574749cd45c29b4f5300e2518f2c2c765ce8ae208bsalomon@google.com    virtual void onDraw(const DrawInfo&) = 0;
8165f74cf8c49701f514b69dc6f1a8b5c0ffd78af0asugoi@google.com    virtual void onStencilPath(const GrPath*, const SkStrokeRec& stroke, SkPath::FillType fill) = 0;
81764aef2bacd1f5c25ffd9347aabd6265c9b60c0f4bsalomon@google.com
818e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com    // helpers for reserving vertex and index space.
819e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com    bool reserveVertexSpace(GrVertexLayout vertexLayout,
820e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com                            int vertexCount,
821e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com                            void** vertices);
822e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com    bool reserveIndexSpace(int indexCount, void** indices);
823d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com
824e826262939dac3e67cb5ce66d4b9faeb8e2538e6bsalomon@google.com    // called by drawIndexed and drawNonIndexed. Use a negative indexCount to
825e826262939dac3e67cb5ce66d4b9faeb8e2538e6bsalomon@google.com    // indicate non-indexed drawing.
826e826262939dac3e67cb5ce66d4b9faeb8e2538e6bsalomon@google.com    bool checkDraw(GrPrimitiveType type, int startVertex,
827e826262939dac3e67cb5ce66d4b9faeb8e2538e6bsalomon@google.com                   int startIndex, int vertexCount,
828e826262939dac3e67cb5ce66d4b9faeb8e2538e6bsalomon@google.com                   int indexCount) const;
82925fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com    // called when setting a new vert/idx source to unref prev vb/ib
83025fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com    void releasePreviousVertexSource();
83125fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com    void releasePreviousIndexSource();
832d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com
83325fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com    enum {
83425fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com        kPreallocGeoSrcStateStackCnt = 4,
835ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com    };
83602ddc8b85ace91b15feb329a6a1d5d62b2b846c6bsalomon@google.com    SkSTArray<kPreallocGeoSrcStateStackCnt, GeometrySrcState, true> fGeoSrcStateStack;
83702ddc8b85ace91b15feb329a6a1d5d62b2b846c6bsalomon@google.com    const GrClipData*                                               fClip;
83802ddc8b85ace91b15feb329a6a1d5d62b2b846c6bsalomon@google.com    GrDrawState*                                                    fDrawState;
83902ddc8b85ace91b15feb329a6a1d5d62b2b846c6bsalomon@google.com    GrDrawState                                                     fDefaultDrawState;
840fa35e3ddcc9d130ce87c927218bdf27879c38711reed@google.com
841fa35e3ddcc9d130ce87c927218bdf27879c38711reed@google.com    typedef GrRefCnt INHERITED;
842ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com};
843ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com
84486c1f71625970610e768d3bf26c933db2cd685babsalomon@google.comGR_MAKE_BITFIELD_OPS(GrDrawTarget::BlendOptFlags);
84586c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com
846ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com#endif
847