GrDrawTarget.h revision 8059eb9f6e24ed609393fbda4ad71edea03ac258
1ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com/*
2ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Copyright 2010 Google Inc.
3ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com *
4ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Use of this source code is governed by a BSD-style license that can be
5ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * found in the LICENSE file.
6ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com */
7ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com
8ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com#ifndef GrDrawTarget_DEFINED
9ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com#define GrDrawTarget_DEFINED
10ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com
118d67c0711b52226db59158a0cfce09f35badd96absalomon@google.com#include "GrClipData.h"
126db519c42471aaaa8a8e1a3ece314014481ab832joshualitt#include "GrClipMaskManager.h"
132a05de0c049a8648942a55016126a1f92e1c14d6commit-bot@chromium.org#include "GrContext.h"
149381363050ec9d3e724076a8e9152bfa9a8de1d1tomhudson@google.com#include "GrDrawState.h"
15934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com#include "GrIndexBuffer.h"
16ccdaa0422501e5cbcba53d6bd19f2736f1beaef3kkinnunen#include "GrPathRendering.h"
172a05de0c049a8648942a55016126a1f92e1c14d6commit-bot@chromium.org#include "GrTraceMarker.h"
187eb8c7b00a5d776bebaf33a8687357df95c1aa43joshualitt#include "GrVertexBuffer.h"
19ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com
208d67c0711b52226db59158a0cfce09f35badd96absalomon@google.com#include "SkClipStack.h"
21a4de8c257ea0be8ff7081f645249b6afe5c48e7ecommit-bot@chromium.org#include "SkMatrix.h"
2212b4e27ae1a29460e91a59f38122483e1faec697sugoi@google.com#include "SkPath.h"
239b62aa156bcf1db6f11af9302bf8bb8ef2567142commit-bot@chromium.org#include "SkStrokeRec.h"
24a2d71482db8b6d752a51c96da74768d7dfc27932robertphillips@google.com#include "SkTArray.h"
25a4de8c257ea0be8ff7081f645249b6afe5c48e7ecommit-bot@chromium.org#include "SkTLazy.h"
26a0b40280a49a8a43af7929ead3b3489951c58501commit-bot@chromium.org#include "SkTypes.h"
278d67c0711b52226db59158a0cfce09f35badd96absalomon@google.com#include "SkXfermode.h"
2897c88c255cff3dbb8343c5d090526fdbedad6dd6Scroggo
29a2d71482db8b6d752a51c96da74768d7dfc27932robertphillips@google.comclass GrClipData;
30c26d94fd7dc0b00cd6d0e42d28285f4a38aff021bsalomon@google.comclass GrDrawTargetCaps;
3164aef2bacd1f5c25ffd9347aabd6265c9b60c0f4bsalomon@google.comclass GrPath;
32b85a0aab6905af8b329539b7573a7555b727d5e5cdaltonclass GrPathRange;
3312b4e27ae1a29460e91a59f38122483e1faec697sugoi@google.com
34a4de8c257ea0be8ff7081f645249b6afe5c48e7ecommit-bot@chromium.orgclass GrDrawTarget : public SkRefCnt {
35bcce8926524827775539874346dd424a9510dbc9bsalomon@google.compublic:
36bcce8926524827775539874346dd424a9510dbc9bsalomon@google.com    SK_DECLARE_INST_COUNT(GrDrawTarget)
37bcce8926524827775539874346dd424a9510dbc9bsalomon@google.com
3855b24afc178e641e17a5664beba7ab2b4982c91acdalton    typedef GrPathRange::PathIndexType PathIndexType;
3955b24afc178e641e17a5664beba7ab2b4982c91acdalton    typedef GrPathRendering::PathTransformType PathTransformType;
40ccdaa0422501e5cbcba53d6bd19f2736f1beaef3kkinnunen
41ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com    ///////////////////////////////////////////////////////////////////////////
42ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com
436e4e65066a7c0dbc9bfbfe4b8f5d49c3d8a79b59bsalomon@google.com    // The context may not be fully constructed and should not be used during GrDrawTarget
446e4e65066a7c0dbc9bfbfe4b8f5d49c3d8a79b59bsalomon@google.com    // construction.
456e4e65066a7c0dbc9bfbfe4b8f5d49c3d8a79b59bsalomon@google.com    GrDrawTarget(GrContext* context);
4625fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com    virtual ~GrDrawTarget();
47ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com
48ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com    /**
4918c9c198f571997463d9a7134dbd88298e592ec2bsalomon@google.com     * Gets the capabilities of the draw target.
5018c9c198f571997463d9a7134dbd88298e592ec2bsalomon@google.com     */
51c26d94fd7dc0b00cd6d0e42d28285f4a38aff021bsalomon@google.com    const GrDrawTargetCaps* caps() const { return fCaps.get(); }
5218c9c198f571997463d9a7134dbd88298e592ec2bsalomon@google.com
5318c9c198f571997463d9a7134dbd88298e592ec2bsalomon@google.com    /**
54ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     * Sets the current clip to the region specified by clip. All draws will be
55ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     * clipped against this clip if kClip_StateBit is enabled.
56ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     *
575aaa69e4339e229adfb05e96084a8ec0a590238bbsalomon@google.com     * Setting the clip may (or may not) zero out the client's stencil bits.
585aaa69e4339e229adfb05e96084a8ec0a590238bbsalomon@google.com     *
59ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     * @param description of the clipping region
60ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     */
61beb1af78d016d2700c350487a383c6bcfa7e2e20robertphillips@google.com    void setClip(const GrClipData* clip);
62ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com
63ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com    /**
64ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     * Gets the current clip.
65ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     *
66ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     * @return the clip.
67ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     */
68beb1af78d016d2700c350487a383c6bcfa7e2e20robertphillips@google.com    const GrClipData* getClip() const;
69ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com
70a5d056ae0b04021dfb44c2c7a3d6a34e060261b8bsalomon@google.com    /**
71f90a02b42ac7a1ed59460760c6ce03f6f975f22bbsalomon     * There are two types of "sources" of geometry (vertices and indices) for
72e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com     * draw calls made on the target. When performing an indexed draw, the
73e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com     * indices and vertices can use different source types. Once a source is
74934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com     * specified it can be used for multiple draws. However, the time at which
75934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com     * the geometry data is no longer editable depends on the source type.
7625fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com     *
7725fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com     * Sometimes it is necessary to perform a draw while upstack code has
78e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com     * already specified geometry that it isn't finished with. So there are push
79e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com     * and pop methods. This allows the client to push the sources, draw
80e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com     * something using alternate sources, and then pop to restore the original
81e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com     * sources.
82e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com     *
83e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com     * Aside from pushes and pops, a source remains valid until another source
84e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com     * is set or resetVertexSource / resetIndexSource is called. Drawing from
85e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com     * a reset source is an error.
86e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com     *
87f90a02b42ac7a1ed59460760c6ce03f6f975f22bbsalomon     * The two types of sources are:
881c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com     *
89f90a02b42ac7a1ed59460760c6ce03f6f975f22bbsalomon     * 1. Reserve. This is most useful when the caller has data it must
9025fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com     *    transform before drawing and is not long-lived. The caller requests
9125fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com     *    that the draw target make room for some amount of vertex and/or index
9225fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com     *    data. The target provides ptrs to hold the vertex and/or index data.
9325fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com     *
94d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com     *    The data is writable up until the next drawIndexed, drawNonIndexed,
95e4617bf6d45cdde07f89e341ebf5c485916bf0b2bsalomon@google.com     *    drawIndexedInstances, drawRect, copySurface, or pushGeometrySource. At
96e4617bf6d45cdde07f89e341ebf5c485916bf0b2bsalomon@google.com     *    this point the data is frozen and the ptrs are no longer valid.
971c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com     *
98e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com     *    Where the space is allocated and how it is uploaded to the GPU is
99e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com     *    subclass-dependent.
100e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com     *
101f90a02b42ac7a1ed59460760c6ce03f6f975f22bbsalomon     * 2. Vertex and Index Buffers. This is most useful for geometry that will
102e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com     *    is long-lived. When the data in the buffer is consumed depends on the
103d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com     *    GrDrawTarget subclass. For deferred subclasses the caller has to
104e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com     *    guarantee that the data is still available in the buffers at playback.
105e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com     *    (TODO: Make this more automatic as we have done for read/write pixels)
1061c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com     */
1071c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com
1081c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com    /**
109e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com     * Reserves space for vertices and/or indices. Zero can be specifed as
110e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com     * either the vertex or index count if the caller desires to only reserve
111d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com     * space for only indices or only vertices. If zero is specifed for
112e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com     * vertexCount then the vertex source will be unmodified and likewise for
113e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com     * indexCount.
114ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     *
115e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com     * If the function returns true then the reserve suceeded and the vertices
116e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com     * and indices pointers will point to the space created.
117ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     *
118e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com     * If the target cannot make space for the request then this function will
119e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com     * return false. If vertexCount was non-zero then upon failure the vertex
120e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com     * source is reset and likewise for indexCount.
121ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     *
122e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com     * The pointers to the space allocated for vertices and indices remain valid
123e4617bf6d45cdde07f89e341ebf5c485916bf0b2bsalomon@google.com     * until a drawIndexed, drawNonIndexed, drawIndexedInstances, drawRect,
124e4617bf6d45cdde07f89e341ebf5c485916bf0b2bsalomon@google.com     * copySurface, or push/popGeomtrySource is called. At that point logically a
125e4617bf6d45cdde07f89e341ebf5c485916bf0b2bsalomon@google.com     * snapshot of the data is made and the pointers are invalid.
1261c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com     *
127e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com     * @param vertexCount  the number of vertices to reserve space for. Can be
128b75b0a0b8492e14c7728e0a0881f87dc64ce60f9jvanverth@google.com     *                     0. Vertex size is queried from the current GrDrawState.
12925fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com     * @param indexCount   the number of indices to reserve space for. Can be 0.
130e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com     * @param vertices     will point to reserved vertex space if vertexCount is
131d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com     *                     non-zero. Illegal to pass NULL if vertexCount > 0.
13225fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com     * @param indices      will point to reserved index space if indexCount is
13325fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com     *                     non-zero. Illegal to pass NULL if indexCount > 0.
13425fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com     */
135b75b0a0b8492e14c7728e0a0881f87dc64ce60f9jvanverth@google.com     bool reserveVertexAndIndexSpace(int vertexCount,
1369853ccef19c200be93a6211f32589fa82a53067cjoshualitt                                     size_t vertexStride,
13797805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com                                     int indexCount,
13897805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com                                     void** vertices,
13997805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com                                     void** indices);
14025fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com
141ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com    /**
142ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     * Provides hints to caller about the number of vertices and indices
143ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     * that can be allocated cheaply. This can be useful if caller is reserving
144ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     * space but doesn't know exactly how much geometry is needed.
145ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     *
146ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     * Also may hint whether the draw target should be flushed first. This is
147ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     * useful for deferred targets.
148ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     *
149ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     * @param vertexCount  in: hint about how many vertices the caller would
150b75b0a0b8492e14c7728e0a0881f87dc64ce60f9jvanverth@google.com     *                     like to allocate. Vertex size is queried from the
151b75b0a0b8492e14c7728e0a0881f87dc64ce60f9jvanverth@google.com     *                     current GrDrawState.
152ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     *                     out: a hint about the number of vertices that can be
153ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     *                     allocated cheaply. Negative means no hint.
154ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     *                     Ignored if NULL.
155ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     * @param indexCount   in: hint about how many indices the caller would
156ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     *                     like to allocate.
157ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     *                     out: a hint about the number of indices that can be
158ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     *                     allocated cheaply. Negative means no hint.
159ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     *                     Ignored if NULL.
160ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     *
161ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     * @return  true if target should be flushed based on the input values.
162ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     */
1639853ccef19c200be93a6211f32589fa82a53067cjoshualitt    virtual bool geometryHints(size_t vertexStride, int* vertexCount, int* indexCount) const;
164ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com
165ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com    /**
166ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     * Sets source of vertex data for the next draw. Data does not have to be
167934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com     * in the buffer until drawIndexed, drawNonIndexed, or drawIndexedInstances.
168ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     *
169ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     * @param buffer        vertex buffer containing vertex data. Must be
170ae683921ffda9108147a29da7319c7eee4dc9245skia.committer@gmail.com     *                      unlocked before draw call. Vertex size is queried
171b75b0a0b8492e14c7728e0a0881f87dc64ce60f9jvanverth@google.com     *                      from current GrDrawState.
172ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     */
1739853ccef19c200be93a6211f32589fa82a53067cjoshualitt    void setVertexSourceToBuffer(const GrVertexBuffer* buffer, size_t vertexStride);
174ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com
175ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com    /**
176ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     * Sets source of index data for the next indexed draw. Data does not have
177934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com     * to be in the buffer until drawIndexed.
178ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     *
179ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     * @param buffer index buffer containing indices. Must be unlocked
180ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     *               before indexed draw call.
181ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     */
182ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com    void setIndexSourceToBuffer(const GrIndexBuffer* buffer);
183d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com
18425fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com    /**
18525fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com     * Resets vertex source. Drawing from reset vertices is illegal. Set vertex
18625fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com     * source to reserved, array, or buffer before next draw. May be able to free
18725fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com     * up temporary storage allocated by setVertexSourceToArray or
18825fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com     * reserveVertexSpace.
18925fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com     */
19025fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com    void resetVertexSource();
191d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com
19225fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com    /**
19325fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com     * Resets index source. Indexed Drawing from reset indices is illegal. Set
19425fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com     * index source to reserved, array, or buffer before next indexed draw. May
19525fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com     * be able to free up temporary storage allocated by setIndexSourceToArray
19625fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com     * or reserveIndexSpace.
19725fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com     */
19897805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com    void resetIndexSource();
199d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com
20097805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com    /**
20197805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com     * Query to find out if the vertex or index source is reserved.
20297805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com     */
20397805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com    bool hasReservedVerticesOrIndices() const {
20473d98aace4f74acc39d8de33484c8aec8e917739bsalomon@google.com        return kReserved_GeometrySrcType == this->getGeomSrc().fVertexSrc ||
20597805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com        kReserved_GeometrySrcType == this->getGeomSrc().fIndexSrc;
20697805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com    }
207ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com
208ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com    /**
20925fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com     * Pushes and resets the vertex/index sources. Any reserved vertex / index
21025fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com     * data is finalized (i.e. cannot be updated after the matching pop but can
21125fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com     * be drawn from). Must be balanced by a pop.
21225fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com     */
21325fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com    void pushGeometrySource();
21425fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com
21525fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com    /**
21625fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com     * Pops the vertex / index sources from the matching push.
21725fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com     */
21825fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com    void popGeometrySource();
21964aef2bacd1f5c25ffd9347aabd6265c9b60c0f4bsalomon@google.com
22025fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com    /**
221ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     * Draws indexed geometry using the current state and current vertex / index
222ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     * sources.
223ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     *
224ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     * @param type         The type of primitives to draw.
225ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     * @param startVertex  the vertex in the vertex array/buffer corresponding
226ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     *                     to index 0
227ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     * @param startIndex   first index to read from index src.
228ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     * @param vertexCount  one greater than the max index.
229ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     * @param indexCount   the number of index elements to read. The index count
230ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     *                     is effectively trimmed to the last completely
231ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     *                     specified primitive.
232d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com     * @param devBounds    optional bounds hint. This is a promise from the caller,
233d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com     *                     not a request for clipping.
234ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     */
2359853ccef19c200be93a6211f32589fa82a53067cjoshualitt    void drawIndexed(GrDrawState*,
23656995b5cc00c9c83bd5fcf86bca9a67e939a96cbjoshualitt                     const GrGeometryProcessor*,
2379853ccef19c200be93a6211f32589fa82a53067cjoshualitt                     GrPrimitiveType type,
23825fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com                     int startVertex,
23925fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com                     int startIndex,
24025fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com                     int vertexCount,
241d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com                     int indexCount,
242d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com                     const SkRect* devBounds = NULL);
243ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com
244ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com    /**
245ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     * Draws non-indexed geometry using the current state and current vertex
246ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     * sources.
247ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     *
248ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     * @param type         The type of primitives to draw.
249ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     * @param startVertex  the vertex in the vertex array/buffer corresponding
250ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     *                     to index 0
251ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     * @param vertexCount  one greater than the max index.
252d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com     * @param devBounds    optional bounds hint. This is a promise from the caller,
253d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com     *                     not a request for clipping.
254ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com     */
2559853ccef19c200be93a6211f32589fa82a53067cjoshualitt    void drawNonIndexed(GrDrawState*,
25656995b5cc00c9c83bd5fcf86bca9a67e939a96cbjoshualitt                        const GrGeometryProcessor*,
2579853ccef19c200be93a6211f32589fa82a53067cjoshualitt                        GrPrimitiveType type,
25825fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com                        int startVertex,
259d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com                        int vertexCount,
260d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com                        const SkRect* devBounds = NULL);
261ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com
26286afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com    /**
26364aef2bacd1f5c25ffd9347aabd6265c9b60c0f4bsalomon@google.com     * Draws path into the stencil buffer. The fill must be either even/odd or
26464aef2bacd1f5c25ffd9347aabd6265c9b60c0f4bsalomon@google.com     * winding (not inverse or hairline). It will respect the HW antialias flag
26592e496f96abbd664888f0c8a7d546ab02e703bf7joshualitt     * on the draw state (if possible in the 3D API).  Note, we will never have an inverse fill
26692e496f96abbd664888f0c8a7d546ab02e703bf7joshualitt     * with stencil path
26764aef2bacd1f5c25ffd9347aabd6265c9b60c0f4bsalomon@google.com     */
26856995b5cc00c9c83bd5fcf86bca9a67e939a96cbjoshualitt    void stencilPath(GrDrawState*, const GrPathProcessor*, const GrPath*,GrPathRendering::FillType);
26964aef2bacd1f5c25ffd9347aabd6265c9b60c0f4bsalomon@google.com
27064aef2bacd1f5c25ffd9347aabd6265c9b60c0f4bsalomon@google.com    /**
27132184d81629e39809bb9e915286d8fe971a8ed68commit-bot@chromium.org     * Draws a path. Fill must not be a hairline. It will respect the HW
272c4dc0ad8e252a7e30d19b47d3d0d9f2c69faf854commit-bot@chromium.org     * antialias flag on the draw state (if possible in the 3D API).
273c4dc0ad8e252a7e30d19b47d3d0d9f2c69faf854commit-bot@chromium.org     */
27456995b5cc00c9c83bd5fcf86bca9a67e939a96cbjoshualitt    void drawPath(GrDrawState*, const GrPathProcessor*, const GrPath*, GrPathRendering::FillType);
275c4dc0ad8e252a7e30d19b47d3d0d9f2c69faf854commit-bot@chromium.org
276c4dc0ad8e252a7e30d19b47d3d0d9f2c69faf854commit-bot@chromium.org    /**
27755b24afc178e641e17a5664beba7ab2b4982c91acdalton     * Draws the aggregate path from combining multiple. Note that this will not
27855b24afc178e641e17a5664beba7ab2b4982c91acdalton     * always be equivalent to back-to-back calls to drawPath(). It will respect
27955b24afc178e641e17a5664beba7ab2b4982c91acdalton     * the HW antialias flag on the draw state (if possible in the 3D API).
2809b62aa156bcf1db6f11af9302bf8bb8ef2567142commit-bot@chromium.org     *
28155b24afc178e641e17a5664beba7ab2b4982c91acdalton     * @param pathRange       Source paths to draw from
28255b24afc178e641e17a5664beba7ab2b4982c91acdalton     * @param indices         Array of path indices to draw
28355b24afc178e641e17a5664beba7ab2b4982c91acdalton     * @param indexType       Data type of the array elements in indexBuffer
28455b24afc178e641e17a5664beba7ab2b4982c91acdalton     * @param transformValues Array of transforms for the individual paths
28555b24afc178e641e17a5664beba7ab2b4982c91acdalton     * @param transformType   Type of transforms in transformBuffer
28655b24afc178e641e17a5664beba7ab2b4982c91acdalton     * @param count           Number of paths to draw
287b85a0aab6905af8b329539b7573a7555b727d5e5cdalton     * @param fill            Fill type for drawing all the paths
288b85a0aab6905af8b329539b7573a7555b727d5e5cdalton     */
2892e3b3e369d79e78f7635d4c20e83a47ab571bdf2joshualitt    void drawPaths(GrDrawState*,
29056995b5cc00c9c83bd5fcf86bca9a67e939a96cbjoshualitt                   const GrPathProcessor*,
2912e3b3e369d79e78f7635d4c20e83a47ab571bdf2joshualitt                   const GrPathRange* pathRange,
29255b24afc178e641e17a5664beba7ab2b4982c91acdalton                   const void* indices,
29355b24afc178e641e17a5664beba7ab2b4982c91acdalton                   PathIndexType indexType,
29455b24afc178e641e17a5664beba7ab2b4982c91acdalton                   const float transformValues[],
29555b24afc178e641e17a5664beba7ab2b4982c91acdalton                   PathTransformType transformType,
2969853ccef19c200be93a6211f32589fa82a53067cjoshualitt                   int count,
29792e496f96abbd664888f0c8a7d546ab02e703bf7joshualitt                   GrPathRendering::FillType fill);
298b85a0aab6905af8b329539b7573a7555b727d5e5cdalton
2999b62aa156bcf1db6f11af9302bf8bb8ef2567142commit-bot@chromium.org    /**
3000406b9e1faee06c6ecb2732a1bcf3b0e53104e07bsalomon@google.com     * Helper function for drawing rects. It performs a geometry src push and pop
3010406b9e1faee06c6ecb2732a1bcf3b0e53104e07bsalomon@google.com     * and thus will finalize any reserved geometry.
302044679ef8c08e1f01afadf5bc08251fe8597df81skia.committer@gmail.com     *
303c78188896e28a4ae49e406a7422b345ae177dafebsalomon@google.com     * @param rect        the rect to draw
304c78188896e28a4ae49e406a7422b345ae177dafebsalomon@google.com     * @param localRect   optional rect that specifies local coords to map onto
305c78188896e28a4ae49e406a7422b345ae177dafebsalomon@google.com     *                    rect. If NULL then rect serves as the local coords.
3068fc6c2d82c1f30ff82274334c01f0799def6a609joshualitt     * @param localMatrix Optional local matrix. The local coordinates are specified by localRect,
3078fc6c2d82c1f30ff82274334c01f0799def6a609joshualitt     *                    or if it is NULL by rect. This matrix applies to the coordinate implied by
3088fc6c2d82c1f30ff82274334c01f0799def6a609joshualitt     *                    that rectangle before it is input to GrCoordTransforms that read local
3098fc6c2d82c1f30ff82274334c01f0799def6a609joshualitt     *                    coordinates
31086afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com     */
3119853ccef19c200be93a6211f32589fa82a53067cjoshualitt    void drawRect(GrDrawState* ds,
3122e3b3e369d79e78f7635d4c20e83a47ab571bdf2joshualitt                  GrColor color,
3138059eb9f6e24ed609393fbda4ad71edea03ac258joshualitt                  const SkMatrix& viewMatrix,
3149853ccef19c200be93a6211f32589fa82a53067cjoshualitt                  const SkRect& rect,
315fd03d4a829efe2d77a712fd991927c55f59a2ffecommit-bot@chromium.org                  const SkRect* localRect,
3160406b9e1faee06c6ecb2732a1bcf3b0e53104e07bsalomon@google.com                  const SkMatrix* localMatrix) {
3170406b9e1faee06c6ecb2732a1bcf3b0e53104e07bsalomon@google.com        AutoGeometryPush agp(this);
3188059eb9f6e24ed609393fbda4ad71edea03ac258joshualitt        this->onDrawRect(ds, color, viewMatrix, rect, localRect, localMatrix);
3190406b9e1faee06c6ecb2732a1bcf3b0e53104e07bsalomon@google.com    }
3203976825a21532e254311b90b4a9046e25717e335jvanverth@google.com
321cf939ae54842fc7408ee68a41427086962b4c3dcbsalomon@google.com    /**
322c78188896e28a4ae49e406a7422b345ae177dafebsalomon@google.com     * Helper for drawRect when the caller doesn't need separate local rects or matrices.
323cf939ae54842fc7408ee68a41427086962b4c3dcbsalomon@google.com     */
3248059eb9f6e24ed609393fbda4ad71edea03ac258joshualitt    void drawSimpleRect(GrDrawState* ds, GrColor color, const SkMatrix& viewM, const SkRect& rect) {
3258059eb9f6e24ed609393fbda4ad71edea03ac258joshualitt        this->drawRect(ds, color, viewM, rect, NULL, NULL);
326cf939ae54842fc7408ee68a41427086962b4c3dcbsalomon@google.com    }
3278059eb9f6e24ed609393fbda4ad71edea03ac258joshualitt    void drawSimpleRect(GrDrawState* ds, GrColor color, const SkMatrix& viewM,
3288059eb9f6e24ed609393fbda4ad71edea03ac258joshualitt                        const SkIRect& irect) {
3294469938e92d779dff05e745559e67907bbf21e78reed@google.com        SkRect rect = SkRect::Make(irect);
3308059eb9f6e24ed609393fbda4ad71edea03ac258joshualitt        this->drawRect(ds, color, viewM, rect, NULL, NULL);
331cf939ae54842fc7408ee68a41427086962b4c3dcbsalomon@google.com    }
33286afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com
33386afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com    /**
334934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com     * This call is used to draw multiple instances of some geometry with a
335934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com     * given number of vertices (V) and indices (I) per-instance. The indices in
336934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com     * the index source must have the form i[k+I] == i[k] + V. Also, all indices
337934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com     * i[kI] ... i[(k+1)I-1] must be elements of the range kV ... (k+1)V-1. As a
338934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com     * concrete example, the following index buffer for drawing a series of
339934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com     * quads each as two triangles each satisfies these conditions with V=4 and
340934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com     * I=6:
341934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com     *      (0,1,2,0,2,3, 4,5,6,4,6,7, 8,9,10,8,10,11, ...)
342934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com     *
343934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com     * The call assumes that the pattern of indices fills the entire index
344934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com     * source. The size of the index buffer limits the number of instances that
345934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com     * can be drawn by the GPU in a single draw. However, the caller may specify
346934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com     * any (positive) number for instanceCount and if necessary multiple GPU
347d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com     * draws will be issued. Moreover, when drawIndexedInstances is called
348934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com     * multiple times it may be possible for GrDrawTarget to group them into a
349934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com     * single GPU draw.
350934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com     *
351934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com     * @param type          the type of primitives to draw
352934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com     * @param instanceCount the number of instances to draw. Each instance
353934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com     *                      consists of verticesPerInstance vertices indexed by
354934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com     *                      indicesPerInstance indices drawn as the primitive
355934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com     *                      type specified by type.
356934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com     * @param verticesPerInstance   The number of vertices in each instance (V
357934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com     *                              in the above description).
358934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com     * @param indicesPerInstance    The number of indices in each instance (I
359934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com     *                              in the above description).
360d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com     * @param devBounds    optional bounds hint. This is a promise from the caller,
361d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com     *                     not a request for clipping.
362934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com     */
3639853ccef19c200be93a6211f32589fa82a53067cjoshualitt    void drawIndexedInstances(GrDrawState*,
36456995b5cc00c9c83bd5fcf86bca9a67e939a96cbjoshualitt                              const GrGeometryProcessor*,
3659853ccef19c200be93a6211f32589fa82a53067cjoshualitt                              GrPrimitiveType type,
366d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com                              int instanceCount,
367d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com                              int verticesPerInstance,
368d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com                              int indicesPerInstance,
369d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com                              const SkRect* devBounds = NULL);
370934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com
371934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com    /**
37289c62980c1eb50b2090f33312086c7e8c66739b4bsalomon     * Clear the passed in render target. Ignores the draw state and clip. Clears the whole thing if
37389c62980c1eb50b2090f33312086c7e8c66739b4bsalomon     * rect is NULL, otherwise just the rect. If canIgnoreRect is set then the entire render target
37489c62980c1eb50b2090f33312086c7e8c66739b4bsalomon     * can be optionally cleared.
3750b335c1ac100aeacf79a4c98a052286fd46661e7bsalomon@google.com     */
3769853ccef19c200be93a6211f32589fa82a53067cjoshualitt    void clear(const SkIRect* rect,
3779853ccef19c200be93a6211f32589fa82a53067cjoshualitt               GrColor color,
3789853ccef19c200be93a6211f32589fa82a53067cjoshualitt               bool canIgnoreRect,
37963b21962867af0f98e12a3ccbe5eef76b7ecc3aabsalomon               GrRenderTarget* renderTarget);
380a9493a3c78f6eb82635ece960b4f16918b885428skia.committer@gmail.com
381e4617bf6d45cdde07f89e341ebf5c485916bf0b2bsalomon@google.com    /**
38289c62980c1eb50b2090f33312086c7e8c66739b4bsalomon     * Discards the contents render target.
38328361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org     **/
38489c62980c1eb50b2090f33312086c7e8c66739b4bsalomon    virtual void discard(GrRenderTarget*) = 0;
38528361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org
38628361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org    /**
3872a05de0c049a8648942a55016126a1f92e1c14d6commit-bot@chromium.org     * Called at start and end of gpu trace marking
3882a05de0c049a8648942a55016126a1f92e1c14d6commit-bot@chromium.org     * GR_CREATE_GPU_TRACE_MARKER(marker_str, target) will automatically call these at the start
3892a05de0c049a8648942a55016126a1f92e1c14d6commit-bot@chromium.org     * and end of a code block respectively
390a3baf3be0e2a3128fb73bd41d40d130f75a4dc86commit-bot@chromium.org     */
3913eee3834fba1d2e29dfb61adcb97e4624b6a3ac8egdaniel    void addGpuTraceMarker(const GrGpuTraceMarker* marker);
3923eee3834fba1d2e29dfb61adcb97e4624b6a3ac8egdaniel    void removeGpuTraceMarker(const GrGpuTraceMarker* marker);
3933eee3834fba1d2e29dfb61adcb97e4624b6a3ac8egdaniel
3943eee3834fba1d2e29dfb61adcb97e4624b6a3ac8egdaniel    /**
3953eee3834fba1d2e29dfb61adcb97e4624b6a3ac8egdaniel     * Takes the current active set of markers and stores them for later use. Any current marker
3963eee3834fba1d2e29dfb61adcb97e4624b6a3ac8egdaniel     * in the active set is removed from the active set and the targets remove function is called.
3973eee3834fba1d2e29dfb61adcb97e4624b6a3ac8egdaniel     * These functions do not work as a stack so you cannot call save a second time before calling
3983eee3834fba1d2e29dfb61adcb97e4624b6a3ac8egdaniel     * restore. Also, it is assumed that when restore is called the current active set of markers
3993eee3834fba1d2e29dfb61adcb97e4624b6a3ac8egdaniel     * is empty. When the stored markers are added back into the active set, the targets add marker
4003eee3834fba1d2e29dfb61adcb97e4624b6a3ac8egdaniel     * is called.
4013eee3834fba1d2e29dfb61adcb97e4624b6a3ac8egdaniel     */
4023eee3834fba1d2e29dfb61adcb97e4624b6a3ac8egdaniel    void saveActiveTraceMarkers();
4033eee3834fba1d2e29dfb61adcb97e4624b6a3ac8egdaniel    void restoreActiveTraceMarkers();
404a3baf3be0e2a3128fb73bd41d40d130f75a4dc86commit-bot@chromium.org
405a3baf3be0e2a3128fb73bd41d40d130f75a4dc86commit-bot@chromium.org    /**
406e4617bf6d45cdde07f89e341ebf5c485916bf0b2bsalomon@google.com     * Copies a pixel rectangle from one surface to another. This call may finalize
407e4617bf6d45cdde07f89e341ebf5c485916bf0b2bsalomon@google.com     * reserved vertex/index data (as though a draw call was made). The src pixels
408e4617bf6d45cdde07f89e341ebf5c485916bf0b2bsalomon@google.com     * copied are specified by srcRect. They are copied to a rect of the same
409e4617bf6d45cdde07f89e341ebf5c485916bf0b2bsalomon@google.com     * size in dst with top left at dstPoint. If the src rect is clipped by the
410e4617bf6d45cdde07f89e341ebf5c485916bf0b2bsalomon@google.com     * src bounds then  pixel values in the dst rect corresponding to area clipped
411e4617bf6d45cdde07f89e341ebf5c485916bf0b2bsalomon@google.com     * by the src rect are not overwritten. This method can fail and return false
412e4617bf6d45cdde07f89e341ebf5c485916bf0b2bsalomon@google.com     * depending on the type of surface, configs, etc, and the backend-specific
413e4617bf6d45cdde07f89e341ebf5c485916bf0b2bsalomon@google.com     * limitations. If rect is clipped out entirely by the src or dst bounds then
414e4617bf6d45cdde07f89e341ebf5c485916bf0b2bsalomon@google.com     * true is returned since there is no actual copy necessary to succeed.
415e4617bf6d45cdde07f89e341ebf5c485916bf0b2bsalomon@google.com     */
416f90a02b42ac7a1ed59460760c6ce03f6f975f22bbsalomon    bool copySurface(GrSurface* dst,
417f90a02b42ac7a1ed59460760c6ce03f6f975f22bbsalomon                     GrSurface* src,
418f90a02b42ac7a1ed59460760c6ce03f6f975f22bbsalomon                     const SkIRect& srcRect,
419f90a02b42ac7a1ed59460760c6ce03f6f975f22bbsalomon                     const SkIPoint& dstPoint);
420116ad84d3126b0db22b2312ca59ed70e5c56f6fcbsalomon@google.com    /**
421f90a02b42ac7a1ed59460760c6ce03f6f975f22bbsalomon     * Function that determines whether a copySurface call would succeed without actually
422116ad84d3126b0db22b2312ca59ed70e5c56f6fcbsalomon@google.com     * performing the copy.
423116ad84d3126b0db22b2312ca59ed70e5c56f6fcbsalomon@google.com     */
424f90a02b42ac7a1ed59460760c6ce03f6f975f22bbsalomon    bool canCopySurface(const GrSurface* dst,
425f90a02b42ac7a1ed59460760c6ce03f6f975f22bbsalomon                        const GrSurface* src,
426f90a02b42ac7a1ed59460760c6ce03f6f975f22bbsalomon                        const SkIRect& srcRect,
427f90a02b42ac7a1ed59460760c6ce03f6f975f22bbsalomon                        const SkIPoint& dstPoint);
428eb85117c05471e1a55ce387cbc38279f857a4584bsalomon@google.com
429eb85117c05471e1a55ce387cbc38279f857a4584bsalomon@google.com    /**
430ff17584e1c15f68ccc296be517e8a6776a9ddabdrobertphillips@google.com     * Release any resources that are cached but not currently in use. This
431ff17584e1c15f68ccc296be517e8a6776a9ddabdrobertphillips@google.com     * is intended to give an application some recourse when resources are low.
432ff17584e1c15f68ccc296be517e8a6776a9ddabdrobertphillips@google.com     */
433ff17584e1c15f68ccc296be517e8a6776a9ddabdrobertphillips@google.com    virtual void purgeResources() {};
434ff17584e1c15f68ccc296be517e8a6776a9ddabdrobertphillips@google.com
43525fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com    ////////////////////////////////////////////////////////////////////////////
4361c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com
437a0b40280a49a8a43af7929ead3b3489951c58501commit-bot@chromium.org    class AutoReleaseGeometry : public ::SkNoncopyable {
438ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com    public:
439ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com        AutoReleaseGeometry(GrDrawTarget*  target,
44025fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com                            int            vertexCount,
4419853ccef19c200be93a6211f32589fa82a53067cjoshualitt                            size_t         vertexStride,
44225fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com                            int            indexCount);
44325fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com        AutoReleaseGeometry();
44425fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com        ~AutoReleaseGeometry();
4455782d712ffc31557d0cb12d5a220cebb783f6895bsalomon@google.com        bool set(GrDrawTarget*  target,
44625fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com                 int            vertexCount,
4479853ccef19c200be93a6211f32589fa82a53067cjoshualitt                 size_t         vertexStride,
44825fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com                 int            indexCount);
44949f085dddff10473b6ebf832a974288300224e60bsalomon        bool succeeded() const { return SkToBool(fTarget); }
450f6de475e5cbd143f348ff7738919e397b7fe7f57tfarina@chromium.org        void* vertices() const { SkASSERT(this->succeeded()); return fVertices; }
451f6de475e5cbd143f348ff7738919e397b7fe7f57tfarina@chromium.org        void* indices() const { SkASSERT(this->succeeded()); return fIndices; }
452972f9cd7a063d0544f8c919fd12b9a3adbd12b24commit-bot@chromium.org        SkPoint* positions() const {
453972f9cd7a063d0544f8c919fd12b9a3adbd12b24commit-bot@chromium.org            return static_cast<SkPoint*>(this->vertices());
454ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com        }
455ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com
456ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com    private:
45725fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com        void reset();
458d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com
459ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com        GrDrawTarget* fTarget;
460ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com        void*         fVertices;
461ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com        void*         fIndices;
462ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com    };
463ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com
46425fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com    ////////////////////////////////////////////////////////////////////////////
465ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com
466a0b40280a49a8a43af7929ead3b3489951c58501commit-bot@chromium.org    class AutoClipRestore : public ::SkNoncopyable {
467ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com    public:
468ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com        AutoClipRestore(GrDrawTarget* target) {
469ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com            fTarget = target;
470ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com            fClip = fTarget->getClip();
471ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com        }
472ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com
4738d67c0711b52226db59158a0cfce09f35badd96absalomon@google.com        AutoClipRestore(GrDrawTarget* target, const SkIRect& newClip);
4748d67c0711b52226db59158a0cfce09f35badd96absalomon@google.com
475ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com        ~AutoClipRestore() {
476ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com            fTarget->setClip(fClip);
477ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com        }
478ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com    private:
4798d67c0711b52226db59158a0cfce09f35badd96absalomon@google.com        GrDrawTarget*           fTarget;
4808d67c0711b52226db59158a0cfce09f35badd96absalomon@google.com        const GrClipData*       fClip;
4818d67c0711b52226db59158a0cfce09f35badd96absalomon@google.com        SkTLazy<SkClipStack>    fStack;
4828d67c0711b52226db59158a0cfce09f35badd96absalomon@google.com        GrClipData              fReplacementClip;
483ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com    };
484d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com
48525fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com    ////////////////////////////////////////////////////////////////////////////
486d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com
4870406b9e1faee06c6ecb2732a1bcf3b0e53104e07bsalomon@google.com    /**
4880406b9e1faee06c6ecb2732a1bcf3b0e53104e07bsalomon@google.com     * Saves the geometry src state at construction and restores in the destructor. It also saves
4890406b9e1faee06c6ecb2732a1bcf3b0e53104e07bsalomon@google.com     * and then restores the vertex attrib state.
4900406b9e1faee06c6ecb2732a1bcf3b0e53104e07bsalomon@google.com     */
491a0b40280a49a8a43af7929ead3b3489951c58501commit-bot@chromium.org    class AutoGeometryPush : public ::SkNoncopyable {
4920406b9e1faee06c6ecb2732a1bcf3b0e53104e07bsalomon@google.com    public:
4939853ccef19c200be93a6211f32589fa82a53067cjoshualitt        AutoGeometryPush(GrDrawTarget* target) {
49449f085dddff10473b6ebf832a974288300224e60bsalomon            SkASSERT(target);
4950406b9e1faee06c6ecb2732a1bcf3b0e53104e07bsalomon@google.com            fTarget = target;
4960406b9e1faee06c6ecb2732a1bcf3b0e53104e07bsalomon@google.com            target->pushGeometrySource();
4970406b9e1faee06c6ecb2732a1bcf3b0e53104e07bsalomon@google.com        }
4980406b9e1faee06c6ecb2732a1bcf3b0e53104e07bsalomon@google.com
4990406b9e1faee06c6ecb2732a1bcf3b0e53104e07bsalomon@google.com        ~AutoGeometryPush() { fTarget->popGeometrySource(); }
5000406b9e1faee06c6ecb2732a1bcf3b0e53104e07bsalomon@google.com
5010406b9e1faee06c6ecb2732a1bcf3b0e53104e07bsalomon@google.com    private:
5020406b9e1faee06c6ecb2732a1bcf3b0e53104e07bsalomon@google.com        GrDrawTarget*                           fTarget;
50325fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com    };
504ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com
505a8916ffd90c04dc6cc1fb9ba94af2ff950284fadcommit-bot@chromium.org    ///////////////////////////////////////////////////////////////////////////
506a8916ffd90c04dc6cc1fb9ba94af2ff950284fadcommit-bot@chromium.org    // Draw execution tracking (for font atlases and other resources)
507a8916ffd90c04dc6cc1fb9ba94af2ff950284fadcommit-bot@chromium.org    class DrawToken {
508a8916ffd90c04dc6cc1fb9ba94af2ff950284fadcommit-bot@chromium.org    public:
509a8916ffd90c04dc6cc1fb9ba94af2ff950284fadcommit-bot@chromium.org        DrawToken(GrDrawTarget* drawTarget, uint32_t drawID) :
510a8916ffd90c04dc6cc1fb9ba94af2ff950284fadcommit-bot@chromium.org                  fDrawTarget(drawTarget), fDrawID(drawID) {}
5117475811143e190e172bf83d13c4bdba85704b604skia.committer@gmail.com
51249f085dddff10473b6ebf832a974288300224e60bsalomon        bool isIssued() { return fDrawTarget && fDrawTarget->isIssued(fDrawID); }
5137475811143e190e172bf83d13c4bdba85704b604skia.committer@gmail.com
514a8916ffd90c04dc6cc1fb9ba94af2ff950284fadcommit-bot@chromium.org    private:
515a8916ffd90c04dc6cc1fb9ba94af2ff950284fadcommit-bot@chromium.org        GrDrawTarget*  fDrawTarget;
516a8916ffd90c04dc6cc1fb9ba94af2ff950284fadcommit-bot@chromium.org        uint32_t       fDrawID;   // this may wrap, but we're doing direct comparison
517a8916ffd90c04dc6cc1fb9ba94af2ff950284fadcommit-bot@chromium.org                                  // so that should be okay
518a8916ffd90c04dc6cc1fb9ba94af2ff950284fadcommit-bot@chromium.org    };
5197475811143e190e172bf83d13c4bdba85704b604skia.committer@gmail.com
520a8916ffd90c04dc6cc1fb9ba94af2ff950284fadcommit-bot@chromium.org    virtual DrawToken getCurrentDrawToken() { return DrawToken(this, 0); }
5217475811143e190e172bf83d13c4bdba85704b604skia.committer@gmail.com
5223322fa432a96fdc94d54f2475faf918dfa05b919joshualitt    /**
5233322fa432a96fdc94d54f2475faf918dfa05b919joshualitt     * Used to communicate draws to GPUs / subclasses
5243322fa432a96fdc94d54f2475faf918dfa05b919joshualitt     */
5253322fa432a96fdc94d54f2475faf918dfa05b919joshualitt    class DrawInfo {
5263322fa432a96fdc94d54f2475faf918dfa05b919joshualitt    public:
5273322fa432a96fdc94d54f2475faf918dfa05b919joshualitt        DrawInfo(const DrawInfo& di) { (*this) = di; }
5283322fa432a96fdc94d54f2475faf918dfa05b919joshualitt        DrawInfo& operator =(const DrawInfo& di);
5293322fa432a96fdc94d54f2475faf918dfa05b919joshualitt
5303322fa432a96fdc94d54f2475faf918dfa05b919joshualitt        GrPrimitiveType primitiveType() const { return fPrimitiveType; }
5313322fa432a96fdc94d54f2475faf918dfa05b919joshualitt        int startVertex() const { return fStartVertex; }
5323322fa432a96fdc94d54f2475faf918dfa05b919joshualitt        int startIndex() const { return fStartIndex; }
5333322fa432a96fdc94d54f2475faf918dfa05b919joshualitt        int vertexCount() const { return fVertexCount; }
5343322fa432a96fdc94d54f2475faf918dfa05b919joshualitt        int indexCount() const { return fIndexCount; }
5353322fa432a96fdc94d54f2475faf918dfa05b919joshualitt        int verticesPerInstance() const { return fVerticesPerInstance; }
5363322fa432a96fdc94d54f2475faf918dfa05b919joshualitt        int indicesPerInstance() const { return fIndicesPerInstance; }
5373322fa432a96fdc94d54f2475faf918dfa05b919joshualitt        int instanceCount() const { return fInstanceCount; }
5383322fa432a96fdc94d54f2475faf918dfa05b919joshualitt
5393322fa432a96fdc94d54f2475faf918dfa05b919joshualitt        bool isIndexed() const { return fIndexCount > 0; }
5403322fa432a96fdc94d54f2475faf918dfa05b919joshualitt#ifdef SK_DEBUG
5413322fa432a96fdc94d54f2475faf918dfa05b919joshualitt        bool isInstanced() const; // this version is longer because of asserts
5423322fa432a96fdc94d54f2475faf918dfa05b919joshualitt#else
5433322fa432a96fdc94d54f2475faf918dfa05b919joshualitt        bool isInstanced() const { return fInstanceCount > 0; }
5443322fa432a96fdc94d54f2475faf918dfa05b919joshualitt#endif
5453322fa432a96fdc94d54f2475faf918dfa05b919joshualitt
5463322fa432a96fdc94d54f2475faf918dfa05b919joshualitt        // adds or remove instances
5473322fa432a96fdc94d54f2475faf918dfa05b919joshualitt        void adjustInstanceCount(int instanceOffset);
5483322fa432a96fdc94d54f2475faf918dfa05b919joshualitt        // shifts the start vertex
5493322fa432a96fdc94d54f2475faf918dfa05b919joshualitt        void adjustStartVertex(int vertexOffset);
5503322fa432a96fdc94d54f2475faf918dfa05b919joshualitt        // shifts the start index
5513322fa432a96fdc94d54f2475faf918dfa05b919joshualitt        void adjustStartIndex(int indexOffset);
5523322fa432a96fdc94d54f2475faf918dfa05b919joshualitt
5533322fa432a96fdc94d54f2475faf918dfa05b919joshualitt        void setDevBounds(const SkRect& bounds) {
5543322fa432a96fdc94d54f2475faf918dfa05b919joshualitt            fDevBoundsStorage = bounds;
5553322fa432a96fdc94d54f2475faf918dfa05b919joshualitt            fDevBounds = &fDevBoundsStorage;
5563322fa432a96fdc94d54f2475faf918dfa05b919joshualitt        }
5577eb8c7b00a5d776bebaf33a8687357df95c1aa43joshualitt        const GrVertexBuffer* vertexBuffer() const { return fVertexBuffer.get(); }
5587eb8c7b00a5d776bebaf33a8687357df95c1aa43joshualitt        const GrIndexBuffer* indexBuffer() const { return fIndexBuffer.get(); }
5597eb8c7b00a5d776bebaf33a8687357df95c1aa43joshualitt        void setVertexBuffer(const GrVertexBuffer* vb) {
5607eb8c7b00a5d776bebaf33a8687357df95c1aa43joshualitt            fVertexBuffer.reset(vb);
5617eb8c7b00a5d776bebaf33a8687357df95c1aa43joshualitt        }
5627eb8c7b00a5d776bebaf33a8687357df95c1aa43joshualitt        void setIndexBuffer(const GrIndexBuffer* ib) {
5637eb8c7b00a5d776bebaf33a8687357df95c1aa43joshualitt            fIndexBuffer.reset(ib);
5647eb8c7b00a5d776bebaf33a8687357df95c1aa43joshualitt        }
5653322fa432a96fdc94d54f2475faf918dfa05b919joshualitt        const SkRect* getDevBounds() const { return fDevBounds; }
5663322fa432a96fdc94d54f2475faf918dfa05b919joshualitt
5673322fa432a96fdc94d54f2475faf918dfa05b919joshualitt    private:
5683322fa432a96fdc94d54f2475faf918dfa05b919joshualitt        DrawInfo() { fDevBounds = NULL; }
5693322fa432a96fdc94d54f2475faf918dfa05b919joshualitt
5703322fa432a96fdc94d54f2475faf918dfa05b919joshualitt        friend class GrDrawTarget;
5713322fa432a96fdc94d54f2475faf918dfa05b919joshualitt
5723322fa432a96fdc94d54f2475faf918dfa05b919joshualitt        GrPrimitiveType         fPrimitiveType;
5733322fa432a96fdc94d54f2475faf918dfa05b919joshualitt
5743322fa432a96fdc94d54f2475faf918dfa05b919joshualitt        int                     fStartVertex;
5753322fa432a96fdc94d54f2475faf918dfa05b919joshualitt        int                     fStartIndex;
5763322fa432a96fdc94d54f2475faf918dfa05b919joshualitt        int                     fVertexCount;
5773322fa432a96fdc94d54f2475faf918dfa05b919joshualitt        int                     fIndexCount;
5783322fa432a96fdc94d54f2475faf918dfa05b919joshualitt
5793322fa432a96fdc94d54f2475faf918dfa05b919joshualitt        int                     fInstanceCount;
5803322fa432a96fdc94d54f2475faf918dfa05b919joshualitt        int                     fVerticesPerInstance;
5813322fa432a96fdc94d54f2475faf918dfa05b919joshualitt        int                     fIndicesPerInstance;
5823322fa432a96fdc94d54f2475faf918dfa05b919joshualitt
5833322fa432a96fdc94d54f2475faf918dfa05b919joshualitt        SkRect                  fDevBoundsStorage;
5843322fa432a96fdc94d54f2475faf918dfa05b919joshualitt        SkRect*                 fDevBounds;
5853322fa432a96fdc94d54f2475faf918dfa05b919joshualitt
5867eb8c7b00a5d776bebaf33a8687357df95c1aa43joshualitt        GrPendingIOResource<const GrVertexBuffer, kRead_GrIOType> fVertexBuffer;
5877eb8c7b00a5d776bebaf33a8687357df95c1aa43joshualitt        GrPendingIOResource<const GrIndexBuffer, kRead_GrIOType>  fIndexBuffer;
5883322fa432a96fdc94d54f2475faf918dfa05b919joshualitt    };
5892c93efeb6f2dd652eb2575c04124d82952f020c7joshualitt
590371bcbcb9fa7f9acba265de9de5dd23f62a64a86bsalomon    /**
591371bcbcb9fa7f9acba265de9de5dd23f62a64a86bsalomon     * Used to populate the vertex and index buffer on the draw info before onDraw is called.
592371bcbcb9fa7f9acba265de9de5dd23f62a64a86bsalomon     */
593371bcbcb9fa7f9acba265de9de5dd23f62a64a86bsalomon    virtual void setDrawBuffers(DrawInfo*, size_t vertexStride) = 0;;
5942c93efeb6f2dd652eb2575c04124d82952f020c7joshualitt    bool programUnitTest(int maxStages);
5952c93efeb6f2dd652eb2575c04124d82952f020c7joshualitt
596ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.comprotected:
59725fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com    enum GeometrySrcType {
59825fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com        kNone_GeometrySrcType,     //<! src has not been specified
59925fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com        kReserved_GeometrySrcType, //<! src was set using reserve*Space
60025fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com        kBuffer_GeometrySrcType    //<! src was set using set*SourceToBuffer
60125fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com    };
602d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com
60325fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com    struct GeometrySrcState {
60425fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com        GeometrySrcType         fVertexSrc;
60525fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com        union {
60625fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com            // valid if src type is buffer
60725fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com            const GrVertexBuffer*   fVertexBuffer;
60825fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com            // valid if src type is reserved or array
60925fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com            int                     fVertexCount;
61025fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com        };
611d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com
61225fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com        GeometrySrcType         fIndexSrc;
61325fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com        union {
61425fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com            // valid if src type is buffer
61525fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com            const GrIndexBuffer*    fIndexBuffer;
61625fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com            // valid if src type is reserved or array
61725fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com            int                     fIndexCount;
61825fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com        };
619d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com
620b75b0a0b8492e14c7728e0a0881f87dc64ce60f9jvanverth@google.com        size_t                  fVertexSize;
62125fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com    };
622934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com
623934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com    int indexCountInCurrentSource() const {
624934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com        const GeometrySrcState& src = this->getGeomSrc();
625934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com        switch (src.fIndexSrc) {
626934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com            case kNone_GeometrySrcType:
627934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com                return 0;
628934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com            case kReserved_GeometrySrcType:
629934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com                return src.fIndexCount;
630934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com            case kBuffer_GeometrySrcType:
631089a780c3355129eefc942246534bc1f126b8ccbcommit-bot@chromium.org                return static_cast<int>(src.fIndexBuffer->gpuMemorySize() / sizeof(uint16_t));
632934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com            default:
63388cb22b6b4816c7a9ca6c5b795965b4606f9eb7bcommit-bot@chromium.org                SkFAIL("Unexpected Index Source.");
634934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com                return 0;
635934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com        }
636934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com    }
637a47a48dca5045d71cbc5de343404045209a13e15bsalomon@google.com
6386e4e65066a7c0dbc9bfbfe4b8f5d49c3d8a79b59bsalomon@google.com    GrContext* getContext() { return fContext; }
6396e4e65066a7c0dbc9bfbfe4b8f5d49c3d8a79b59bsalomon@google.com    const GrContext* getContext() const { return fContext; }
6406e4e65066a7c0dbc9bfbfe4b8f5d49c3d8a79b59bsalomon@google.com
64102ddc8b85ace91b15feb329a6a1d5d62b2b846c6bsalomon@google.com    // subclasses must call this in their destructors to ensure all vertex
64202ddc8b85ace91b15feb329a6a1d5d62b2b846c6bsalomon@google.com    // and index sources have been released (including those held by
64302ddc8b85ace91b15feb329a6a1d5d62b2b846c6bsalomon@google.com    // pushGeometrySource())
64402ddc8b85ace91b15feb329a6a1d5d62b2b846c6bsalomon@google.com    void releaseGeometry();
64502ddc8b85ace91b15feb329a6a1d5d62b2b846c6bsalomon@google.com
64602ddc8b85ace91b15feb329a6a1d5d62b2b846c6bsalomon@google.com    // accessors for derived classes
64702ddc8b85ace91b15feb329a6a1d5d62b2b846c6bsalomon@google.com    const GeometrySrcState& getGeomSrc() const { return fGeoSrcStateStack.back(); }
648b75b0a0b8492e14c7728e0a0881f87dc64ce60f9jvanverth@google.com    // it is preferable to call this rather than getGeomSrc()->fVertexSize because of the assert.
649b75b0a0b8492e14c7728e0a0881f87dc64ce60f9jvanverth@google.com    size_t getVertexSize() const {
65002ddc8b85ace91b15feb329a6a1d5d62b2b846c6bsalomon@google.com        // the vertex layout is only valid if a vertex source has been specified.
651f6de475e5cbd143f348ff7738919e397b7fe7f57tfarina@chromium.org        SkASSERT(this->getGeomSrc().fVertexSrc != kNone_GeometrySrcType);
652b75b0a0b8492e14c7728e0a0881f87dc64ce60f9jvanverth@google.com        return this->getGeomSrc().fVertexSize;
653a47a48dca5045d71cbc5de343404045209a13e15bsalomon@google.com    }
6545782d712ffc31557d0cb12d5a220cebb783f6895bsalomon@google.com
655bcce8926524827775539874346dd424a9510dbc9bsalomon@google.com    // Subclass must initialize this in its constructor.
656c26d94fd7dc0b00cd6d0e42d28285f4a38aff021bsalomon@google.com    SkAutoTUnref<const GrDrawTargetCaps> fCaps;
65702ddc8b85ace91b15feb329a6a1d5d62b2b846c6bsalomon@google.com
6582a05de0c049a8648942a55016126a1f92e1c14d6commit-bot@chromium.org    const GrTraceMarkerSet& getActiveTraceMarkers() { return fActiveTraceMarkers; }
6592a05de0c049a8648942a55016126a1f92e1c14d6commit-bot@chromium.org
660651713408c5a5d9565665967ad09981250c7a8c9joshualitt    // Makes a copy of the dst if it is necessary for the draw. Returns false if a copy is required
661651713408c5a5d9565665967ad09981250c7a8c9joshualitt    // but couldn't be made. Otherwise, returns true.  This method needs to be protected because it
662651713408c5a5d9565665967ad09981250c7a8c9joshualitt    // needs to be accessed by GLPrograms to setup a correct drawstate
6639853ccef19c200be93a6211f32589fa82a53067cjoshualitt    bool setupDstReadIfNecessary(GrDrawState*,
66456995b5cc00c9c83bd5fcf86bca9a67e939a96cbjoshualitt                                 const GrPrimitiveProcessor*,
6659853ccef19c200be93a6211f32589fa82a53067cjoshualitt                                 GrDeviceCoordTexture* dstCopy,
6669853ccef19c200be93a6211f32589fa82a53067cjoshualitt                                 const SkRect* drawBounds);
667651713408c5a5d9565665967ad09981250c7a8c9joshualitt
66802ddc8b85ace91b15feb329a6a1d5d62b2b846c6bsalomon@google.comprivate:
669f90a02b42ac7a1ed59460760c6ce03f6f975f22bbsalomon    /**
670f90a02b42ac7a1ed59460760c6ce03f6f975f22bbsalomon     * This will be called before allocating a texture as a dst for copySurface. This function
671f90a02b42ac7a1ed59460760c6ce03f6f975f22bbsalomon     * populates the dstDesc's config, flags, and origin so as to maximize efficiency and guarantee
672f90a02b42ac7a1ed59460760c6ce03f6f975f22bbsalomon     * success of the copySurface call.
673f90a02b42ac7a1ed59460760c6ce03f6f975f22bbsalomon     */
674f90a02b42ac7a1ed59460760c6ce03f6f975f22bbsalomon    void initCopySurfaceDstDesc(const GrSurface* src, GrSurfaceDesc* dstDesc) {
675f90a02b42ac7a1ed59460760c6ce03f6f975f22bbsalomon        if (!this->onInitCopySurfaceDstDesc(src, dstDesc)) {
676f90a02b42ac7a1ed59460760c6ce03f6f975f22bbsalomon            dstDesc->fOrigin = kDefault_GrSurfaceOrigin;
677f90a02b42ac7a1ed59460760c6ce03f6f975f22bbsalomon            dstDesc->fFlags = kRenderTarget_GrSurfaceFlag | kNoStencil_GrSurfaceFlag;
678f90a02b42ac7a1ed59460760c6ce03f6f975f22bbsalomon            dstDesc->fConfig = src->config();
679f90a02b42ac7a1ed59460760c6ce03f6f975f22bbsalomon        }
680f90a02b42ac7a1ed59460760c6ce03f6f975f22bbsalomon    }
681f90a02b42ac7a1ed59460760c6ce03f6f975f22bbsalomon
682f90a02b42ac7a1ed59460760c6ce03f6f975f22bbsalomon    /** Internal implementation of canCopySurface. */
683f90a02b42ac7a1ed59460760c6ce03f6f975f22bbsalomon    bool internalCanCopySurface(const GrSurface* dst,
684f90a02b42ac7a1ed59460760c6ce03f6f975f22bbsalomon                                const GrSurface* src,
685f90a02b42ac7a1ed59460760c6ce03f6f975f22bbsalomon                                const SkIRect& clippedSrcRect,
686f90a02b42ac7a1ed59460760c6ce03f6f975f22bbsalomon                                const SkIPoint& clippedDstRect);
687f90a02b42ac7a1ed59460760c6ce03f6f975f22bbsalomon
68802ddc8b85ace91b15feb329a6a1d5d62b2b846c6bsalomon@google.com    // A subclass can optionally overload this function to be notified before
68902ddc8b85ace91b15feb329a6a1d5d62b2b846c6bsalomon@google.com    // vertex and index space is reserved.
6909853ccef19c200be93a6211f32589fa82a53067cjoshualitt    virtual void willReserveVertexAndIndexSpace(int vertexCount,
6919853ccef19c200be93a6211f32589fa82a53067cjoshualitt                                                size_t vertexStride,
6929853ccef19c200be93a6211f32589fa82a53067cjoshualitt                                                int indexCount) {}
69397805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com
69425fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com    // implemented by subclass to allocate space for reserved geom
695a63389843dd18003382d61c2e4610af09ed07d38jvanverth@google.com    virtual bool onReserveVertexSpace(size_t vertexSize, int vertexCount, void** vertices) = 0;
69625fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com    virtual bool onReserveIndexSpace(int indexCount, void** indices) = 0;
69725fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com    // implemented by subclass to handle release of reserved geom space
69825fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com    virtual void releaseReservedVertexSpace() = 0;
69925fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com    virtual void releaseReservedIndexSpace() = 0;
70002ddc8b85ace91b15feb329a6a1d5d62b2b846c6bsalomon@google.com    // subclass overrides to be notified just before geo src state is pushed/popped.
70125fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com    virtual void geometrySourceWillPush() = 0;
70225fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com    virtual void geometrySourceWillPop(const GeometrySrcState& restoredState) = 0;
70325fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com    // subclass called to perform drawing
7049853ccef19c200be93a6211f32589fa82a53067cjoshualitt    virtual void onDraw(const GrDrawState&,
70556995b5cc00c9c83bd5fcf86bca9a67e939a96cbjoshualitt                        const GrGeometryProcessor*,
7069853ccef19c200be93a6211f32589fa82a53067cjoshualitt                        const DrawInfo&,
7073e79124a69d4806f0a1a776090bff718e1b90970bsalomon                        const GrScissorState&,
7089176e2c159089458b1e2226a94fab1af0fba32acjoshualitt                        const GrDeviceCoordTexture* dstCopy) = 0;
7095478d427c6e67c986a3390162c8fec77c466058ajoshualitt    // TODO copy in order drawbuffer onDrawRect to here
7109853ccef19c200be93a6211f32589fa82a53067cjoshualitt    virtual void onDrawRect(GrDrawState*,
7112e3b3e369d79e78f7635d4c20e83a47ab571bdf2joshualitt                            GrColor color,
7128059eb9f6e24ed609393fbda4ad71edea03ac258joshualitt                            const SkMatrix& viewMatrix,
7139853ccef19c200be93a6211f32589fa82a53067cjoshualitt                            const SkRect& rect,
714fd03d4a829efe2d77a712fd991927c55f59a2ffecommit-bot@chromium.org                            const SkRect* localRect,
7155478d427c6e67c986a3390162c8fec77c466058ajoshualitt                            const SkMatrix* localMatrix) = 0;
71632184d81629e39809bb9e915286d8fe971a8ed68commit-bot@chromium.org
7179853ccef19c200be93a6211f32589fa82a53067cjoshualitt    virtual void onStencilPath(const GrDrawState&,
71856995b5cc00c9c83bd5fcf86bca9a67e939a96cbjoshualitt                               const GrPathProcessor*,
7199853ccef19c200be93a6211f32589fa82a53067cjoshualitt                               const GrPath*,
7203e79124a69d4806f0a1a776090bff718e1b90970bsalomon                               const GrScissorState&,
7212c93efeb6f2dd652eb2575c04124d82952f020c7joshualitt                               const GrStencilSettings&) = 0;
7229853ccef19c200be93a6211f32589fa82a53067cjoshualitt    virtual void onDrawPath(const GrDrawState&,
72356995b5cc00c9c83bd5fcf86bca9a67e939a96cbjoshualitt                            const GrPathProcessor*,
7249853ccef19c200be93a6211f32589fa82a53067cjoshualitt                            const GrPath*,
7253e79124a69d4806f0a1a776090bff718e1b90970bsalomon                            const GrScissorState&,
7262c93efeb6f2dd652eb2575c04124d82952f020c7joshualitt                            const GrStencilSettings&,
727c4dc0ad8e252a7e30d19b47d3d0d9f2c69faf854commit-bot@chromium.org                            const GrDeviceCoordTexture* dstCopy) = 0;
7289853ccef19c200be93a6211f32589fa82a53067cjoshualitt    virtual void onDrawPaths(const GrDrawState&,
72956995b5cc00c9c83bd5fcf86bca9a67e939a96cbjoshualitt                             const GrPathProcessor*,
7309853ccef19c200be93a6211f32589fa82a53067cjoshualitt                             const GrPathRange*,
73155b24afc178e641e17a5664beba7ab2b4982c91acdalton                             const void* indices,
73255b24afc178e641e17a5664beba7ab2b4982c91acdalton                             PathIndexType,
73355b24afc178e641e17a5664beba7ab2b4982c91acdalton                             const float transformValues[],
7342c93efeb6f2dd652eb2575c04124d82952f020c7joshualitt                             PathTransformType,
73555b24afc178e641e17a5664beba7ab2b4982c91acdalton                             int count,
7363e79124a69d4806f0a1a776090bff718e1b90970bsalomon                             const GrScissorState&,
7372c93efeb6f2dd652eb2575c04124d82952f020c7joshualitt                             const GrStencilSettings&,
7382c93efeb6f2dd652eb2575c04124d82952f020c7joshualitt                             const GrDeviceCoordTexture*) = 0;
73964aef2bacd1f5c25ffd9347aabd6265c9b60c0f4bsalomon@google.com
74063b21962867af0f98e12a3ccbe5eef76b7ecc3aabsalomon    virtual void onClear(const SkIRect* rect, GrColor color, bool canIgnoreRect,
74163b21962867af0f98e12a3ccbe5eef76b7ecc3aabsalomon                         GrRenderTarget* renderTarget) = 0;
74263b21962867af0f98e12a3ccbe5eef76b7ecc3aabsalomon
743f90a02b42ac7a1ed59460760c6ce03f6f975f22bbsalomon    /** The subclass will get a chance to copy the surface for falling back to the default
744f90a02b42ac7a1ed59460760c6ce03f6f975f22bbsalomon        implementation, which simply draws a rectangle (and fails if dst isn't a render target). It
745f90a02b42ac7a1ed59460760c6ce03f6f975f22bbsalomon        should assume that any clipping has already been performed on the rect and point. It won't
746f90a02b42ac7a1ed59460760c6ce03f6f975f22bbsalomon        be called if the copy can be skipped. */
747f90a02b42ac7a1ed59460760c6ce03f6f975f22bbsalomon    virtual bool onCopySurface(GrSurface* dst,
748f90a02b42ac7a1ed59460760c6ce03f6f975f22bbsalomon                               GrSurface* src,
749f90a02b42ac7a1ed59460760c6ce03f6f975f22bbsalomon                               const SkIRect& srcRect,
750f90a02b42ac7a1ed59460760c6ce03f6f975f22bbsalomon                               const SkIPoint& dstPoint) = 0;
751f90a02b42ac7a1ed59460760c6ce03f6f975f22bbsalomon
752f90a02b42ac7a1ed59460760c6ce03f6f975f22bbsalomon    /** Indicates whether onCopySurface would succeed. It should assume that any clipping has
753f90a02b42ac7a1ed59460760c6ce03f6f975f22bbsalomon        already been performed on the rect and point. It won't be called if the copy can be
754f90a02b42ac7a1ed59460760c6ce03f6f975f22bbsalomon        skipped. */
755f90a02b42ac7a1ed59460760c6ce03f6f975f22bbsalomon    virtual bool onCanCopySurface(const GrSurface* dst,
756f90a02b42ac7a1ed59460760c6ce03f6f975f22bbsalomon                                  const GrSurface* src,
757f90a02b42ac7a1ed59460760c6ce03f6f975f22bbsalomon                                  const SkIRect& srcRect,
758f90a02b42ac7a1ed59460760c6ce03f6f975f22bbsalomon                                  const SkIPoint& dstPoint) = 0;
759f90a02b42ac7a1ed59460760c6ce03f6f975f22bbsalomon    /**
760f90a02b42ac7a1ed59460760c6ce03f6f975f22bbsalomon     * This will be called before allocating a texture to be a dst for onCopySurface. Only the
761f90a02b42ac7a1ed59460760c6ce03f6f975f22bbsalomon     * dstDesc's config, flags, and origin need be set by the function. If the subclass cannot
762f90a02b42ac7a1ed59460760c6ce03f6f975f22bbsalomon     * create a surface that would succeed its implementation of onCopySurface, it should return
763f90a02b42ac7a1ed59460760c6ce03f6f975f22bbsalomon     * false. The base class will fall back to creating a render target to draw into using the src.
764f90a02b42ac7a1ed59460760c6ce03f6f975f22bbsalomon     */
765f90a02b42ac7a1ed59460760c6ce03f6f975f22bbsalomon    virtual bool onInitCopySurfaceDstDesc(const GrSurface* src, GrSurfaceDesc* dstDesc) = 0;
76663b21962867af0f98e12a3ccbe5eef76b7ecc3aabsalomon
767e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com    // helpers for reserving vertex and index space.
768b75b0a0b8492e14c7728e0a0881f87dc64ce60f9jvanverth@google.com    bool reserveVertexSpace(size_t vertexSize,
769e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com                            int vertexCount,
770e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com                            void** vertices);
771e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com    bool reserveIndexSpace(int indexCount, void** indices);
772d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com
773e826262939dac3e67cb5ce66d4b9faeb8e2538e6bsalomon@google.com    // called by drawIndexed and drawNonIndexed. Use a negative indexCount to
774e826262939dac3e67cb5ce66d4b9faeb8e2538e6bsalomon@google.com    // indicate non-indexed drawing.
7759853ccef19c200be93a6211f32589fa82a53067cjoshualitt    bool checkDraw(const GrDrawState&,
77656995b5cc00c9c83bd5fcf86bca9a67e939a96cbjoshualitt                   const GrGeometryProcessor*,
7779853ccef19c200be93a6211f32589fa82a53067cjoshualitt                   GrPrimitiveType type,
7789853ccef19c200be93a6211f32589fa82a53067cjoshualitt                   int startVertex,
7799853ccef19c200be93a6211f32589fa82a53067cjoshualitt                   int startIndex,
7809853ccef19c200be93a6211f32589fa82a53067cjoshualitt                   int vertexCount,
781e826262939dac3e67cb5ce66d4b9faeb8e2538e6bsalomon@google.com                   int indexCount) const;
78225fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com    // called when setting a new vert/idx source to unref prev vb/ib
78325fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com    void releasePreviousVertexSource();
78425fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com    void releasePreviousIndexSource();
785d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com
786a8916ffd90c04dc6cc1fb9ba94af2ff950284fadcommit-bot@chromium.org    // Check to see if this set of draw commands has been sent out
787a8916ffd90c04dc6cc1fb9ba94af2ff950284fadcommit-bot@chromium.org    virtual bool       isIssued(uint32_t drawID) { return true; }
7889853ccef19c200be93a6211f32589fa82a53067cjoshualitt    void getPathStencilSettingsForFilltype(GrPathRendering::FillType,
7899853ccef19c200be93a6211f32589fa82a53067cjoshualitt                                           const GrStencilBuffer*,
7909853ccef19c200be93a6211f32589fa82a53067cjoshualitt                                           GrStencilSettings*);
791a702415d9e80f5631181143c293498de924e8ae4joshualitt    virtual GrClipMaskManager* clipMaskManager() = 0;
7928059eb9f6e24ed609393fbda4ad71edea03ac258joshualitt    virtual bool setupClip(GrDrawState*,
7932c93efeb6f2dd652eb2575c04124d82952f020c7joshualitt                           GrDrawState::AutoRestoreEffects* are,
7942c93efeb6f2dd652eb2575c04124d82952f020c7joshualitt                           GrDrawState::AutoRestoreStencil* ars,
7958059eb9f6e24ed609393fbda4ad71edea03ac258joshualitt                           GrScissorState* scissorState,
7968059eb9f6e24ed609393fbda4ad71edea03ac258joshualitt                           const SkRect* devBounds) = 0;
7977475811143e190e172bf83d13c4bdba85704b604skia.committer@gmail.com
79825fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com    enum {
79925fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com        kPreallocGeoSrcStateStackCnt = 4,
800ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com    };
80102ddc8b85ace91b15feb329a6a1d5d62b2b846c6bsalomon@google.com    SkSTArray<kPreallocGeoSrcStateStackCnt, GeometrySrcState, true> fGeoSrcStateStack;
80202ddc8b85ace91b15feb329a6a1d5d62b2b846c6bsalomon@google.com    const GrClipData*                                               fClip;
8036e4e65066a7c0dbc9bfbfe4b8f5d49c3d8a79b59bsalomon@google.com    // The context owns us, not vice-versa, so this ptr is not ref'ed by DrawTarget.
8046e4e65066a7c0dbc9bfbfe4b8f5d49c3d8a79b59bsalomon@google.com    GrContext*                                                      fContext;
8052a05de0c049a8648942a55016126a1f92e1c14d6commit-bot@chromium.org    // To keep track that we always have at least as many debug marker adds as removes
8062a05de0c049a8648942a55016126a1f92e1c14d6commit-bot@chromium.org    int                                                             fGpuTraceMarkerCount;
8072a05de0c049a8648942a55016126a1f92e1c14d6commit-bot@chromium.org    GrTraceMarkerSet                                                fActiveTraceMarkers;
8083eee3834fba1d2e29dfb61adcb97e4624b6a3ac8egdaniel    GrTraceMarkerSet                                                fStoredTraceMarkers;
809fa35e3ddcc9d130ce87c927218bdf27879c38711reed@google.com
810a4de8c257ea0be8ff7081f645249b6afe5c48e7ecommit-bot@chromium.org    typedef SkRefCnt INHERITED;
811ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com};
812ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com
813329bf4862e9d5e05363c2b071d8ca475a0ef1952joshualitt/*
814329bf4862e9d5e05363c2b071d8ca475a0ef1952joshualitt * This class is JUST for clip mask manager.  Everyone else should just use draw target above.
815329bf4862e9d5e05363c2b071d8ca475a0ef1952joshualitt */
8166db519c42471aaaa8a8e1a3ece314014481ab832joshualittclass GrClipTarget : public GrDrawTarget {
8176db519c42471aaaa8a8e1a3ece314014481ab832joshualittpublic:
818329bf4862e9d5e05363c2b071d8ca475a0ef1952joshualitt    GrClipTarget(GrContext* context) : INHERITED(context) {
819329bf4862e9d5e05363c2b071d8ca475a0ef1952joshualitt        fClipMaskManager.setClipTarget(this);
820329bf4862e9d5e05363c2b071d8ca475a0ef1952joshualitt    }
821329bf4862e9d5e05363c2b071d8ca475a0ef1952joshualitt
822329bf4862e9d5e05363c2b071d8ca475a0ef1952joshualitt    /* Clip mask manager needs access to the context.
823329bf4862e9d5e05363c2b071d8ca475a0ef1952joshualitt     * TODO we only need a very small subset of context in the CMM.
824329bf4862e9d5e05363c2b071d8ca475a0ef1952joshualitt     */
825329bf4862e9d5e05363c2b071d8ca475a0ef1952joshualitt    GrContext* getContext() { return INHERITED::getContext(); }
826329bf4862e9d5e05363c2b071d8ca475a0ef1952joshualitt    const GrContext* getContext() const { return INHERITED::getContext(); }
827329bf4862e9d5e05363c2b071d8ca475a0ef1952joshualitt
8286db519c42471aaaa8a8e1a3ece314014481ab832joshualitt    /**
8296db519c42471aaaa8a8e1a3ece314014481ab832joshualitt     * Clip Mask Manager(and no one else) needs to clear private stencil bits.
8306db519c42471aaaa8a8e1a3ece314014481ab832joshualitt     * ClipTarget subclass sets clip bit in the stencil buffer. The subclass
8316db519c42471aaaa8a8e1a3ece314014481ab832joshualitt     * is free to clear the remaining bits to zero if masked clears are more
8326db519c42471aaaa8a8e1a3ece314014481ab832joshualitt     * expensive than clearing all bits.
8336db519c42471aaaa8a8e1a3ece314014481ab832joshualitt     */
8346db519c42471aaaa8a8e1a3ece314014481ab832joshualitt    virtual void clearStencilClip(const SkIRect& rect, bool insideClip, GrRenderTarget* = NULL) = 0;
8356db519c42471aaaa8a8e1a3ece314014481ab832joshualitt
8363bdd7dce5e8393aeed0a64b583e1077f5159d516joshualitt    /**
8373bdd7dce5e8393aeed0a64b583e1077f5159d516joshualitt     * Release any resources that are cached but not currently in use. This
8383bdd7dce5e8393aeed0a64b583e1077f5159d516joshualitt     * is intended to give an application some recourse when resources are low.
8393bdd7dce5e8393aeed0a64b583e1077f5159d516joshualitt     */
8403bdd7dce5e8393aeed0a64b583e1077f5159d516joshualitt    virtual void purgeResources() SK_OVERRIDE {
8413bdd7dce5e8393aeed0a64b583e1077f5159d516joshualitt        // The clip mask manager can rebuild all its clip masks so just
8423bdd7dce5e8393aeed0a64b583e1077f5159d516joshualitt        // get rid of them all.
8433bdd7dce5e8393aeed0a64b583e1077f5159d516joshualitt        fClipMaskManager.purgeResources();
8443bdd7dce5e8393aeed0a64b583e1077f5159d516joshualitt    };
8453bdd7dce5e8393aeed0a64b583e1077f5159d516joshualitt
846329bf4862e9d5e05363c2b071d8ca475a0ef1952joshualittprotected:
847329bf4862e9d5e05363c2b071d8ca475a0ef1952joshualitt    GrClipMaskManager           fClipMaskManager;
848329bf4862e9d5e05363c2b071d8ca475a0ef1952joshualitt
8496db519c42471aaaa8a8e1a3ece314014481ab832joshualittprivate:
850912ed6ebb8e2813e72ed7a3dec3b6710ba7e7405tfarina    GrClipMaskManager* clipMaskManager() SK_OVERRIDE { return &fClipMaskManager; }
851329bf4862e9d5e05363c2b071d8ca475a0ef1952joshualitt
8528059eb9f6e24ed609393fbda4ad71edea03ac258joshualitt    virtual bool setupClip(GrDrawState*,
8532c93efeb6f2dd652eb2575c04124d82952f020c7joshualitt                           GrDrawState::AutoRestoreEffects* are,
8542c93efeb6f2dd652eb2575c04124d82952f020c7joshualitt                           GrDrawState::AutoRestoreStencil* ars,
8558059eb9f6e24ed609393fbda4ad71edea03ac258joshualitt                           GrScissorState* scissorState,
8568059eb9f6e24ed609393fbda4ad71edea03ac258joshualitt                           const SkRect* devBounds) SK_OVERRIDE;
8572c93efeb6f2dd652eb2575c04124d82952f020c7joshualitt
8586db519c42471aaaa8a8e1a3ece314014481ab832joshualitt    typedef GrDrawTarget INHERITED;
8596db519c42471aaaa8a8e1a3ece314014481ab832joshualitt};
8606db519c42471aaaa8a8e1a3ece314014481ab832joshualitt
861ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com#endif
862