GrDrawTarget.h revision 55b24afc178e641e17a5664beba7ab2b4982c91a
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 /** 71e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com * There are three 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 * 87e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com * The three types of sources are: 881c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com * 89e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com * 1. A cpu array (set*SourceToArray). This is useful when the caller 90e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com * already provided vertex data in a format compatible with a 91e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com * GrVertexLayout. The data in the array is consumed at the time that 92e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com * set*SourceToArray is called and subsequent edits to the array will not 93e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com * be reflected in draws. 941c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com * 9525fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * 2. Reserve. This is most useful when the caller has data it must 9625fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * transform before drawing and is not long-lived. The caller requests 9725fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * that the draw target make room for some amount of vertex and/or index 9825fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * data. The target provides ptrs to hold the vertex and/or index data. 9925fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * 100d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com * The data is writable up until the next drawIndexed, drawNonIndexed, 101e4617bf6d45cdde07f89e341ebf5c485916bf0b2bsalomon@google.com * drawIndexedInstances, drawRect, copySurface, or pushGeometrySource. At 102e4617bf6d45cdde07f89e341ebf5c485916bf0b2bsalomon@google.com * this point the data is frozen and the ptrs are no longer valid. 1031c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com * 104e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com * Where the space is allocated and how it is uploaded to the GPU is 105e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com * subclass-dependent. 106e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com * 1071c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com * 3. Vertex and Index Buffers. This is most useful for geometry that will 108e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com * is long-lived. When the data in the buffer is consumed depends on the 109d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com * GrDrawTarget subclass. For deferred subclasses the caller has to 110e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com * guarantee that the data is still available in the buffers at playback. 111e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com * (TODO: Make this more automatic as we have done for read/write pixels) 112b75b0a0b8492e14c7728e0a0881f87dc64ce60f9jvanverth@google.com * 113b75b0a0b8492e14c7728e0a0881f87dc64ce60f9jvanverth@google.com * The size of each vertex is determined by querying the current GrDrawState. 1141c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com */ 1151c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com 1161c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com /** 117e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com * Reserves space for vertices and/or indices. Zero can be specifed as 118e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com * either the vertex or index count if the caller desires to only reserve 119d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com * space for only indices or only vertices. If zero is specifed for 120e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com * vertexCount then the vertex source will be unmodified and likewise for 121e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com * indexCount. 122ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * 123e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com * If the function returns true then the reserve suceeded and the vertices 124e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com * and indices pointers will point to the space created. 125ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * 126e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com * If the target cannot make space for the request then this function will 127e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com * return false. If vertexCount was non-zero then upon failure the vertex 128e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com * source is reset and likewise for indexCount. 129ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * 130e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com * The pointers to the space allocated for vertices and indices remain valid 131e4617bf6d45cdde07f89e341ebf5c485916bf0b2bsalomon@google.com * until a drawIndexed, drawNonIndexed, drawIndexedInstances, drawRect, 132e4617bf6d45cdde07f89e341ebf5c485916bf0b2bsalomon@google.com * copySurface, or push/popGeomtrySource is called. At that point logically a 133e4617bf6d45cdde07f89e341ebf5c485916bf0b2bsalomon@google.com * snapshot of the data is made and the pointers are invalid. 1341c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com * 135e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com * @param vertexCount the number of vertices to reserve space for. Can be 136b75b0a0b8492e14c7728e0a0881f87dc64ce60f9jvanverth@google.com * 0. Vertex size is queried from the current GrDrawState. 13725fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * @param indexCount the number of indices to reserve space for. Can be 0. 138e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com * @param vertices will point to reserved vertex space if vertexCount is 139d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com * non-zero. Illegal to pass NULL if vertexCount > 0. 14025fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * @param indices will point to reserved index space if indexCount is 14125fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * non-zero. Illegal to pass NULL if indexCount > 0. 14225fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com */ 143b75b0a0b8492e14c7728e0a0881f87dc64ce60f9jvanverth@google.com bool reserveVertexAndIndexSpace(int vertexCount, 1449853ccef19c200be93a6211f32589fa82a53067cjoshualitt size_t vertexStride, 14597805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com int indexCount, 14697805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com void** vertices, 14797805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com void** indices); 14825fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com 149ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com /** 150ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * Provides hints to caller about the number of vertices and indices 151ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * that can be allocated cheaply. This can be useful if caller is reserving 152ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * space but doesn't know exactly how much geometry is needed. 153ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * 154ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * Also may hint whether the draw target should be flushed first. This is 155ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * useful for deferred targets. 156ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * 157ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * @param vertexCount in: hint about how many vertices the caller would 158b75b0a0b8492e14c7728e0a0881f87dc64ce60f9jvanverth@google.com * like to allocate. Vertex size is queried from the 159b75b0a0b8492e14c7728e0a0881f87dc64ce60f9jvanverth@google.com * current GrDrawState. 160ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * out: a hint about the number of vertices that can be 161ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * allocated cheaply. Negative means no hint. 162ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * Ignored if NULL. 163ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * @param indexCount in: hint about how many indices the caller would 164ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * like to allocate. 165ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * out: a hint about the number of indices that can be 166ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * allocated cheaply. Negative means no hint. 167ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * Ignored if NULL. 168ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * 169ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * @return true if target should be flushed based on the input values. 170ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com */ 1719853ccef19c200be93a6211f32589fa82a53067cjoshualitt virtual bool geometryHints(size_t vertexStride, int* vertexCount, int* indexCount) const; 172ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 173ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com /** 174ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * Sets source of vertex data for the next draw. Data does not have to be 175934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com * in the buffer until drawIndexed, drawNonIndexed, or drawIndexedInstances. 176ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * 177ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * @param buffer vertex buffer containing vertex data. Must be 178ae683921ffda9108147a29da7319c7eee4dc9245skia.committer@gmail.com * unlocked before draw call. Vertex size is queried 179b75b0a0b8492e14c7728e0a0881f87dc64ce60f9jvanverth@google.com * from current GrDrawState. 180ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com */ 1819853ccef19c200be93a6211f32589fa82a53067cjoshualitt void setVertexSourceToBuffer(const GrVertexBuffer* buffer, size_t vertexStride); 182ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 183ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com /** 184ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * Sets source of index data for the next indexed draw. Data does not have 185934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com * to be in the buffer until drawIndexed. 186ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * 187ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * @param buffer index buffer containing indices. Must be unlocked 188ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * before indexed draw call. 189ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com */ 190ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com void setIndexSourceToBuffer(const GrIndexBuffer* buffer); 191d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com 19225fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com /** 19325fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * Resets vertex source. Drawing from reset vertices is illegal. Set vertex 19425fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * source to reserved, array, or buffer before next draw. May be able to free 19525fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * up temporary storage allocated by setVertexSourceToArray or 19625fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * reserveVertexSpace. 19725fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com */ 19825fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com void resetVertexSource(); 199d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com 20025fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com /** 20125fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * Resets index source. Indexed Drawing from reset indices is illegal. Set 20225fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * index source to reserved, array, or buffer before next indexed draw. May 20325fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * be able to free up temporary storage allocated by setIndexSourceToArray 20425fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * or reserveIndexSpace. 20525fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com */ 20697805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com void resetIndexSource(); 207d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com 20897805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com /** 20997805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com * Query to find out if the vertex or index source is reserved. 21097805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com */ 21197805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com bool hasReservedVerticesOrIndices() const { 21273d98aace4f74acc39d8de33484c8aec8e917739bsalomon@google.com return kReserved_GeometrySrcType == this->getGeomSrc().fVertexSrc || 21397805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com kReserved_GeometrySrcType == this->getGeomSrc().fIndexSrc; 21497805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com } 215ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 216ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com /** 21725fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * Pushes and resets the vertex/index sources. Any reserved vertex / index 21825fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * data is finalized (i.e. cannot be updated after the matching pop but can 21925fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * be drawn from). Must be balanced by a pop. 22025fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com */ 22125fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com void pushGeometrySource(); 22225fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com 22325fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com /** 22425fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * Pops the vertex / index sources from the matching push. 22525fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com */ 22625fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com void popGeometrySource(); 22764aef2bacd1f5c25ffd9347aabd6265c9b60c0f4bsalomon@google.com 22825fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com /** 229ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * Draws indexed geometry using the current state and current vertex / index 230ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * sources. 231ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * 232ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * @param type The type of primitives to draw. 233ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * @param startVertex the vertex in the vertex array/buffer corresponding 234ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * to index 0 235ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * @param startIndex first index to read from index src. 236ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * @param vertexCount one greater than the max index. 237ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * @param indexCount the number of index elements to read. The index count 238ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * is effectively trimmed to the last completely 239ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * specified primitive. 240d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com * @param devBounds optional bounds hint. This is a promise from the caller, 241d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com * not a request for clipping. 242ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com */ 2439853ccef19c200be93a6211f32589fa82a53067cjoshualitt void drawIndexed(GrDrawState*, 2449853ccef19c200be93a6211f32589fa82a53067cjoshualitt GrPrimitiveType type, 24525fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com int startVertex, 24625fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com int startIndex, 24725fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com int vertexCount, 248d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com int indexCount, 249d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com const SkRect* devBounds = NULL); 250ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 251ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com /** 252ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * Draws non-indexed geometry using the current state and current vertex 253ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * sources. 254ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * 255ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * @param type The type of primitives to draw. 256ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * @param startVertex the vertex in the vertex array/buffer corresponding 257ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * to index 0 258ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * @param vertexCount one greater than the max index. 259d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com * @param devBounds optional bounds hint. This is a promise from the caller, 260d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com * not a request for clipping. 261ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com */ 2629853ccef19c200be93a6211f32589fa82a53067cjoshualitt void drawNonIndexed(GrDrawState*, 2639853ccef19c200be93a6211f32589fa82a53067cjoshualitt GrPrimitiveType type, 26425fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com int startVertex, 265d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com int vertexCount, 266d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com const SkRect* devBounds = NULL); 267ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 26886afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com /** 26964aef2bacd1f5c25ffd9347aabd6265c9b60c0f4bsalomon@google.com * Draws path into the stencil buffer. The fill must be either even/odd or 27064aef2bacd1f5c25ffd9347aabd6265c9b60c0f4bsalomon@google.com * winding (not inverse or hairline). It will respect the HW antialias flag 27192e496f96abbd664888f0c8a7d546ab02e703bf7joshualitt * on the draw state (if possible in the 3D API). Note, we will never have an inverse fill 27292e496f96abbd664888f0c8a7d546ab02e703bf7joshualitt * with stencil path 27364aef2bacd1f5c25ffd9347aabd6265c9b60c0f4bsalomon@google.com */ 2749853ccef19c200be93a6211f32589fa82a53067cjoshualitt void stencilPath(GrDrawState*, const GrPath*, GrPathRendering::FillType fill); 27564aef2bacd1f5c25ffd9347aabd6265c9b60c0f4bsalomon@google.com 27664aef2bacd1f5c25ffd9347aabd6265c9b60c0f4bsalomon@google.com /** 27732184d81629e39809bb9e915286d8fe971a8ed68commit-bot@chromium.org * Draws a path. Fill must not be a hairline. It will respect the HW 278c4dc0ad8e252a7e30d19b47d3d0d9f2c69faf854commit-bot@chromium.org * antialias flag on the draw state (if possible in the 3D API). 279c4dc0ad8e252a7e30d19b47d3d0d9f2c69faf854commit-bot@chromium.org */ 2809853ccef19c200be93a6211f32589fa82a53067cjoshualitt void drawPath(GrDrawState*, const GrPath*, GrPathRendering::FillType fill); 281c4dc0ad8e252a7e30d19b47d3d0d9f2c69faf854commit-bot@chromium.org 282c4dc0ad8e252a7e30d19b47d3d0d9f2c69faf854commit-bot@chromium.org /** 28355b24afc178e641e17a5664beba7ab2b4982c91acdalton * Draws the aggregate path from combining multiple. Note that this will not 28455b24afc178e641e17a5664beba7ab2b4982c91acdalton * always be equivalent to back-to-back calls to drawPath(). It will respect 28555b24afc178e641e17a5664beba7ab2b4982c91acdalton * the HW antialias flag on the draw state (if possible in the 3D API). 2869b62aa156bcf1db6f11af9302bf8bb8ef2567142commit-bot@chromium.org * 28755b24afc178e641e17a5664beba7ab2b4982c91acdalton * @param pathRange Source paths to draw from 28855b24afc178e641e17a5664beba7ab2b4982c91acdalton * @param indices Array of path indices to draw 28955b24afc178e641e17a5664beba7ab2b4982c91acdalton * @param indexType Data type of the array elements in indexBuffer 29055b24afc178e641e17a5664beba7ab2b4982c91acdalton * @param transformValues Array of transforms for the individual paths 29155b24afc178e641e17a5664beba7ab2b4982c91acdalton * @param transformType Type of transforms in transformBuffer 29255b24afc178e641e17a5664beba7ab2b4982c91acdalton * @param count Number of paths to draw 293b85a0aab6905af8b329539b7573a7555b727d5e5cdalton * @param fill Fill type for drawing all the paths 294b85a0aab6905af8b329539b7573a7555b727d5e5cdalton */ 2959853ccef19c200be93a6211f32589fa82a53067cjoshualitt void drawPaths(GrDrawState*, const GrPathRange* pathRange, 29655b24afc178e641e17a5664beba7ab2b4982c91acdalton const void* indices, 29755b24afc178e641e17a5664beba7ab2b4982c91acdalton PathIndexType indexType, 29855b24afc178e641e17a5664beba7ab2b4982c91acdalton const float transformValues[], 29955b24afc178e641e17a5664beba7ab2b4982c91acdalton PathTransformType transformType, 3009853ccef19c200be93a6211f32589fa82a53067cjoshualitt int count, 30192e496f96abbd664888f0c8a7d546ab02e703bf7joshualitt GrPathRendering::FillType fill); 302b85a0aab6905af8b329539b7573a7555b727d5e5cdalton 3039b62aa156bcf1db6f11af9302bf8bb8ef2567142commit-bot@chromium.org /** 3040406b9e1faee06c6ecb2732a1bcf3b0e53104e07bsalomon@google.com * Helper function for drawing rects. It performs a geometry src push and pop 3050406b9e1faee06c6ecb2732a1bcf3b0e53104e07bsalomon@google.com * and thus will finalize any reserved geometry. 306044679ef8c08e1f01afadf5bc08251fe8597df81skia.committer@gmail.com * 307c78188896e28a4ae49e406a7422b345ae177dafebsalomon@google.com * @param rect the rect to draw 308c78188896e28a4ae49e406a7422b345ae177dafebsalomon@google.com * @param localRect optional rect that specifies local coords to map onto 309c78188896e28a4ae49e406a7422b345ae177dafebsalomon@google.com * rect. If NULL then rect serves as the local coords. 310c78188896e28a4ae49e406a7422b345ae177dafebsalomon@google.com * @param localMatrix optional matrix applied to localRect. If 311044679ef8c08e1f01afadf5bc08251fe8597df81skia.committer@gmail.com * srcRect is non-NULL and srcMatrix is non-NULL 312044679ef8c08e1f01afadf5bc08251fe8597df81skia.committer@gmail.com * then srcRect will be transformed by srcMatrix. 3133976825a21532e254311b90b4a9046e25717e335jvanverth@google.com * srcMatrix can be NULL when no srcMatrix is desired. 31486afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com */ 3159853ccef19c200be93a6211f32589fa82a53067cjoshualitt void drawRect(GrDrawState* ds, 3169853ccef19c200be93a6211f32589fa82a53067cjoshualitt const SkRect& rect, 317fd03d4a829efe2d77a712fd991927c55f59a2ffecommit-bot@chromium.org const SkRect* localRect, 3180406b9e1faee06c6ecb2732a1bcf3b0e53104e07bsalomon@google.com const SkMatrix* localMatrix) { 3190406b9e1faee06c6ecb2732a1bcf3b0e53104e07bsalomon@google.com AutoGeometryPush agp(this); 3209853ccef19c200be93a6211f32589fa82a53067cjoshualitt this->onDrawRect(ds, rect, localRect, localMatrix); 3210406b9e1faee06c6ecb2732a1bcf3b0e53104e07bsalomon@google.com } 3223976825a21532e254311b90b4a9046e25717e335jvanverth@google.com 323cf939ae54842fc7408ee68a41427086962b4c3dcbsalomon@google.com /** 324c78188896e28a4ae49e406a7422b345ae177dafebsalomon@google.com * Helper for drawRect when the caller doesn't need separate local rects or matrices. 325cf939ae54842fc7408ee68a41427086962b4c3dcbsalomon@google.com */ 3269853ccef19c200be93a6211f32589fa82a53067cjoshualitt void drawSimpleRect(GrDrawState* ds, const SkRect& rect) { 3279853ccef19c200be93a6211f32589fa82a53067cjoshualitt this->drawRect(ds, rect, NULL, NULL); 328cf939ae54842fc7408ee68a41427086962b4c3dcbsalomon@google.com } 3299853ccef19c200be93a6211f32589fa82a53067cjoshualitt void drawSimpleRect(GrDrawState* ds, const SkIRect& irect) { 3304469938e92d779dff05e745559e67907bbf21e78reed@google.com SkRect rect = SkRect::Make(irect); 3319853ccef19c200be93a6211f32589fa82a53067cjoshualitt this->drawRect(ds, rect, NULL, NULL); 332cf939ae54842fc7408ee68a41427086962b4c3dcbsalomon@google.com } 33386afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com 33486afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com /** 335934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com * This call is used to draw multiple instances of some geometry with a 336934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com * given number of vertices (V) and indices (I) per-instance. The indices in 337934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com * the index source must have the form i[k+I] == i[k] + V. Also, all indices 338934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com * i[kI] ... i[(k+1)I-1] must be elements of the range kV ... (k+1)V-1. As a 339934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com * concrete example, the following index buffer for drawing a series of 340934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com * quads each as two triangles each satisfies these conditions with V=4 and 341934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com * I=6: 342934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com * (0,1,2,0,2,3, 4,5,6,4,6,7, 8,9,10,8,10,11, ...) 343934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com * 344934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com * The call assumes that the pattern of indices fills the entire index 345934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com * source. The size of the index buffer limits the number of instances that 346934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com * can be drawn by the GPU in a single draw. However, the caller may specify 347934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com * any (positive) number for instanceCount and if necessary multiple GPU 348d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com * draws will be issued. Moreover, when drawIndexedInstances is called 349934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com * multiple times it may be possible for GrDrawTarget to group them into a 350934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com * single GPU draw. 351934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com * 352934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com * @param type the type of primitives to draw 353934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com * @param instanceCount the number of instances to draw. Each instance 354934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com * consists of verticesPerInstance vertices indexed by 355934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com * indicesPerInstance indices drawn as the primitive 356934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com * type specified by type. 357934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com * @param verticesPerInstance The number of vertices in each instance (V 358934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com * in the above description). 359934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com * @param indicesPerInstance The number of indices in each instance (I 360934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com * in the above description). 361d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com * @param devBounds optional bounds hint. This is a promise from the caller, 362d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com * not a request for clipping. 363934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com */ 3649853ccef19c200be93a6211f32589fa82a53067cjoshualitt void drawIndexedInstances(GrDrawState*, 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 */ 416a702415d9e80f5631181143c293498de924e8ae4joshualitt virtual bool copySurface(GrSurface* dst, 417a702415d9e80f5631181143c293498de924e8ae4joshualitt GrSurface* src, 418a702415d9e80f5631181143c293498de924e8ae4joshualitt const SkIRect& srcRect, 419a702415d9e80f5631181143c293498de924e8ae4joshualitt const SkIPoint& dstPoint); 420116ad84d3126b0db22b2312ca59ed70e5c56f6fcbsalomon@google.com /** 421116ad84d3126b0db22b2312ca59ed70e5c56f6fcbsalomon@google.com * Function that determines whether a copySurface call would succeed without 422116ad84d3126b0db22b2312ca59ed70e5c56f6fcbsalomon@google.com * performing the copy. 423116ad84d3126b0db22b2312ca59ed70e5c56f6fcbsalomon@google.com */ 4249853ccef19c200be93a6211f32589fa82a53067cjoshualitt virtual bool canCopySurface(const GrSurface* dst, 4259853ccef19c200be93a6211f32589fa82a53067cjoshualitt const GrSurface* src, 426a702415d9e80f5631181143c293498de924e8ae4joshualitt const SkIRect& srcRect, 427a702415d9e80f5631181143c293498de924e8ae4joshualitt const SkIPoint& dstPoint); 4280b335c1ac100aeacf79a4c98a052286fd46661e7bsalomon@google.com 429ff17584e1c15f68ccc296be517e8a6776a9ddabdrobertphillips@google.com /** 430eb85117c05471e1a55ce387cbc38279f857a4584bsalomon@google.com * This is can be called before allocating a texture to be a dst for copySurface. It will 431eb85117c05471e1a55ce387cbc38279f857a4584bsalomon@google.com * populate the origin, config, and flags fields of the desc such that copySurface is more 432eb85117c05471e1a55ce387cbc38279f857a4584bsalomon@google.com * likely to succeed and be efficient. 433eb85117c05471e1a55ce387cbc38279f857a4584bsalomon@google.com */ 434f2703d83da3ab2ae18b45231fd4f11e16cce3184bsalomon virtual void initCopySurfaceDstDesc(const GrSurface* src, GrSurfaceDesc* desc); 435eb85117c05471e1a55ce387cbc38279f857a4584bsalomon@google.com 436eb85117c05471e1a55ce387cbc38279f857a4584bsalomon@google.com 437eb85117c05471e1a55ce387cbc38279f857a4584bsalomon@google.com /** 438ff17584e1c15f68ccc296be517e8a6776a9ddabdrobertphillips@google.com * Release any resources that are cached but not currently in use. This 439ff17584e1c15f68ccc296be517e8a6776a9ddabdrobertphillips@google.com * is intended to give an application some recourse when resources are low. 440ff17584e1c15f68ccc296be517e8a6776a9ddabdrobertphillips@google.com */ 441ff17584e1c15f68ccc296be517e8a6776a9ddabdrobertphillips@google.com virtual void purgeResources() {}; 442ff17584e1c15f68ccc296be517e8a6776a9ddabdrobertphillips@google.com 44325fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com //////////////////////////////////////////////////////////////////////////// 4441c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com 445a0b40280a49a8a43af7929ead3b3489951c58501commit-bot@chromium.org class AutoReleaseGeometry : public ::SkNoncopyable { 446ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com public: 447ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com AutoReleaseGeometry(GrDrawTarget* target, 44825fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com int vertexCount, 4499853ccef19c200be93a6211f32589fa82a53067cjoshualitt size_t vertexStride, 45025fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com int indexCount); 45125fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com AutoReleaseGeometry(); 45225fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com ~AutoReleaseGeometry(); 4535782d712ffc31557d0cb12d5a220cebb783f6895bsalomon@google.com bool set(GrDrawTarget* target, 45425fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com int vertexCount, 4559853ccef19c200be93a6211f32589fa82a53067cjoshualitt size_t vertexStride, 45625fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com int indexCount); 45749f085dddff10473b6ebf832a974288300224e60bsalomon bool succeeded() const { return SkToBool(fTarget); } 458f6de475e5cbd143f348ff7738919e397b7fe7f57tfarina@chromium.org void* vertices() const { SkASSERT(this->succeeded()); return fVertices; } 459f6de475e5cbd143f348ff7738919e397b7fe7f57tfarina@chromium.org void* indices() const { SkASSERT(this->succeeded()); return fIndices; } 460972f9cd7a063d0544f8c919fd12b9a3adbd12b24commit-bot@chromium.org SkPoint* positions() const { 461972f9cd7a063d0544f8c919fd12b9a3adbd12b24commit-bot@chromium.org return static_cast<SkPoint*>(this->vertices()); 462ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com } 463ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 464ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com private: 46525fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com void reset(); 466d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com 467ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com GrDrawTarget* fTarget; 468ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com void* fVertices; 469ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com void* fIndices; 470ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com }; 471ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 47225fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com //////////////////////////////////////////////////////////////////////////// 473ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 474a0b40280a49a8a43af7929ead3b3489951c58501commit-bot@chromium.org class AutoClipRestore : public ::SkNoncopyable { 475ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com public: 476ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com AutoClipRestore(GrDrawTarget* target) { 477ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com fTarget = target; 478ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com fClip = fTarget->getClip(); 479ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com } 480ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 4818d67c0711b52226db59158a0cfce09f35badd96absalomon@google.com AutoClipRestore(GrDrawTarget* target, const SkIRect& newClip); 4828d67c0711b52226db59158a0cfce09f35badd96absalomon@google.com 483ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com ~AutoClipRestore() { 484ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com fTarget->setClip(fClip); 485ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com } 486ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com private: 4878d67c0711b52226db59158a0cfce09f35badd96absalomon@google.com GrDrawTarget* fTarget; 4888d67c0711b52226db59158a0cfce09f35badd96absalomon@google.com const GrClipData* fClip; 4898d67c0711b52226db59158a0cfce09f35badd96absalomon@google.com SkTLazy<SkClipStack> fStack; 4908d67c0711b52226db59158a0cfce09f35badd96absalomon@google.com GrClipData fReplacementClip; 491ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com }; 492d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com 49325fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com //////////////////////////////////////////////////////////////////////////// 494d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com 4950406b9e1faee06c6ecb2732a1bcf3b0e53104e07bsalomon@google.com /** 4960406b9e1faee06c6ecb2732a1bcf3b0e53104e07bsalomon@google.com * Saves the geometry src state at construction and restores in the destructor. It also saves 4970406b9e1faee06c6ecb2732a1bcf3b0e53104e07bsalomon@google.com * and then restores the vertex attrib state. 4980406b9e1faee06c6ecb2732a1bcf3b0e53104e07bsalomon@google.com */ 499a0b40280a49a8a43af7929ead3b3489951c58501commit-bot@chromium.org class AutoGeometryPush : public ::SkNoncopyable { 5000406b9e1faee06c6ecb2732a1bcf3b0e53104e07bsalomon@google.com public: 5019853ccef19c200be93a6211f32589fa82a53067cjoshualitt AutoGeometryPush(GrDrawTarget* target) { 50249f085dddff10473b6ebf832a974288300224e60bsalomon SkASSERT(target); 5030406b9e1faee06c6ecb2732a1bcf3b0e53104e07bsalomon@google.com fTarget = target; 5040406b9e1faee06c6ecb2732a1bcf3b0e53104e07bsalomon@google.com target->pushGeometrySource(); 5050406b9e1faee06c6ecb2732a1bcf3b0e53104e07bsalomon@google.com } 5060406b9e1faee06c6ecb2732a1bcf3b0e53104e07bsalomon@google.com 5070406b9e1faee06c6ecb2732a1bcf3b0e53104e07bsalomon@google.com ~AutoGeometryPush() { fTarget->popGeometrySource(); } 5080406b9e1faee06c6ecb2732a1bcf3b0e53104e07bsalomon@google.com 5090406b9e1faee06c6ecb2732a1bcf3b0e53104e07bsalomon@google.com private: 5100406b9e1faee06c6ecb2732a1bcf3b0e53104e07bsalomon@google.com GrDrawTarget* fTarget; 51125fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com }; 512ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 513a8916ffd90c04dc6cc1fb9ba94af2ff950284fadcommit-bot@chromium.org /////////////////////////////////////////////////////////////////////////// 514a8916ffd90c04dc6cc1fb9ba94af2ff950284fadcommit-bot@chromium.org // Draw execution tracking (for font atlases and other resources) 515a8916ffd90c04dc6cc1fb9ba94af2ff950284fadcommit-bot@chromium.org class DrawToken { 516a8916ffd90c04dc6cc1fb9ba94af2ff950284fadcommit-bot@chromium.org public: 517a8916ffd90c04dc6cc1fb9ba94af2ff950284fadcommit-bot@chromium.org DrawToken(GrDrawTarget* drawTarget, uint32_t drawID) : 518a8916ffd90c04dc6cc1fb9ba94af2ff950284fadcommit-bot@chromium.org fDrawTarget(drawTarget), fDrawID(drawID) {} 5197475811143e190e172bf83d13c4bdba85704b604skia.committer@gmail.com 52049f085dddff10473b6ebf832a974288300224e60bsalomon bool isIssued() { return fDrawTarget && fDrawTarget->isIssued(fDrawID); } 5217475811143e190e172bf83d13c4bdba85704b604skia.committer@gmail.com 522a8916ffd90c04dc6cc1fb9ba94af2ff950284fadcommit-bot@chromium.org private: 523a8916ffd90c04dc6cc1fb9ba94af2ff950284fadcommit-bot@chromium.org GrDrawTarget* fDrawTarget; 524a8916ffd90c04dc6cc1fb9ba94af2ff950284fadcommit-bot@chromium.org uint32_t fDrawID; // this may wrap, but we're doing direct comparison 525a8916ffd90c04dc6cc1fb9ba94af2ff950284fadcommit-bot@chromium.org // so that should be okay 526a8916ffd90c04dc6cc1fb9ba94af2ff950284fadcommit-bot@chromium.org }; 5277475811143e190e172bf83d13c4bdba85704b604skia.committer@gmail.com 528a8916ffd90c04dc6cc1fb9ba94af2ff950284fadcommit-bot@chromium.org virtual DrawToken getCurrentDrawToken() { return DrawToken(this, 0); } 5297475811143e190e172bf83d13c4bdba85704b604skia.committer@gmail.com 5303322fa432a96fdc94d54f2475faf918dfa05b919joshualitt /** 5313322fa432a96fdc94d54f2475faf918dfa05b919joshualitt * Used to communicate draws to GPUs / subclasses 5323322fa432a96fdc94d54f2475faf918dfa05b919joshualitt */ 5333322fa432a96fdc94d54f2475faf918dfa05b919joshualitt class DrawInfo { 5343322fa432a96fdc94d54f2475faf918dfa05b919joshualitt public: 5353322fa432a96fdc94d54f2475faf918dfa05b919joshualitt DrawInfo(const DrawInfo& di) { (*this) = di; } 5363322fa432a96fdc94d54f2475faf918dfa05b919joshualitt DrawInfo& operator =(const DrawInfo& di); 5373322fa432a96fdc94d54f2475faf918dfa05b919joshualitt 5383322fa432a96fdc94d54f2475faf918dfa05b919joshualitt GrPrimitiveType primitiveType() const { return fPrimitiveType; } 5393322fa432a96fdc94d54f2475faf918dfa05b919joshualitt int startVertex() const { return fStartVertex; } 5403322fa432a96fdc94d54f2475faf918dfa05b919joshualitt int startIndex() const { return fStartIndex; } 5413322fa432a96fdc94d54f2475faf918dfa05b919joshualitt int vertexCount() const { return fVertexCount; } 5423322fa432a96fdc94d54f2475faf918dfa05b919joshualitt int indexCount() const { return fIndexCount; } 5433322fa432a96fdc94d54f2475faf918dfa05b919joshualitt int verticesPerInstance() const { return fVerticesPerInstance; } 5443322fa432a96fdc94d54f2475faf918dfa05b919joshualitt int indicesPerInstance() const { return fIndicesPerInstance; } 5453322fa432a96fdc94d54f2475faf918dfa05b919joshualitt int instanceCount() const { return fInstanceCount; } 5463322fa432a96fdc94d54f2475faf918dfa05b919joshualitt 5473322fa432a96fdc94d54f2475faf918dfa05b919joshualitt bool isIndexed() const { return fIndexCount > 0; } 5483322fa432a96fdc94d54f2475faf918dfa05b919joshualitt#ifdef SK_DEBUG 5493322fa432a96fdc94d54f2475faf918dfa05b919joshualitt bool isInstanced() const; // this version is longer because of asserts 5503322fa432a96fdc94d54f2475faf918dfa05b919joshualitt#else 5513322fa432a96fdc94d54f2475faf918dfa05b919joshualitt bool isInstanced() const { return fInstanceCount > 0; } 5523322fa432a96fdc94d54f2475faf918dfa05b919joshualitt#endif 5533322fa432a96fdc94d54f2475faf918dfa05b919joshualitt 5543322fa432a96fdc94d54f2475faf918dfa05b919joshualitt // adds or remove instances 5553322fa432a96fdc94d54f2475faf918dfa05b919joshualitt void adjustInstanceCount(int instanceOffset); 5563322fa432a96fdc94d54f2475faf918dfa05b919joshualitt // shifts the start vertex 5573322fa432a96fdc94d54f2475faf918dfa05b919joshualitt void adjustStartVertex(int vertexOffset); 5583322fa432a96fdc94d54f2475faf918dfa05b919joshualitt // shifts the start index 5593322fa432a96fdc94d54f2475faf918dfa05b919joshualitt void adjustStartIndex(int indexOffset); 5603322fa432a96fdc94d54f2475faf918dfa05b919joshualitt 5613322fa432a96fdc94d54f2475faf918dfa05b919joshualitt void setDevBounds(const SkRect& bounds) { 5623322fa432a96fdc94d54f2475faf918dfa05b919joshualitt fDevBoundsStorage = bounds; 5633322fa432a96fdc94d54f2475faf918dfa05b919joshualitt fDevBounds = &fDevBoundsStorage; 5643322fa432a96fdc94d54f2475faf918dfa05b919joshualitt } 5657eb8c7b00a5d776bebaf33a8687357df95c1aa43joshualitt const GrVertexBuffer* vertexBuffer() const { return fVertexBuffer.get(); } 5667eb8c7b00a5d776bebaf33a8687357df95c1aa43joshualitt const GrIndexBuffer* indexBuffer() const { return fIndexBuffer.get(); } 5677eb8c7b00a5d776bebaf33a8687357df95c1aa43joshualitt void setVertexBuffer(const GrVertexBuffer* vb) { 5687eb8c7b00a5d776bebaf33a8687357df95c1aa43joshualitt fVertexBuffer.reset(vb); 5697eb8c7b00a5d776bebaf33a8687357df95c1aa43joshualitt } 5707eb8c7b00a5d776bebaf33a8687357df95c1aa43joshualitt void setIndexBuffer(const GrIndexBuffer* ib) { 5717eb8c7b00a5d776bebaf33a8687357df95c1aa43joshualitt fIndexBuffer.reset(ib); 5727eb8c7b00a5d776bebaf33a8687357df95c1aa43joshualitt } 5733322fa432a96fdc94d54f2475faf918dfa05b919joshualitt const SkRect* getDevBounds() const { return fDevBounds; } 5743322fa432a96fdc94d54f2475faf918dfa05b919joshualitt 5753322fa432a96fdc94d54f2475faf918dfa05b919joshualitt private: 5763322fa432a96fdc94d54f2475faf918dfa05b919joshualitt DrawInfo() { fDevBounds = NULL; } 5773322fa432a96fdc94d54f2475faf918dfa05b919joshualitt 5783322fa432a96fdc94d54f2475faf918dfa05b919joshualitt friend class GrDrawTarget; 5793322fa432a96fdc94d54f2475faf918dfa05b919joshualitt 5803322fa432a96fdc94d54f2475faf918dfa05b919joshualitt GrPrimitiveType fPrimitiveType; 5813322fa432a96fdc94d54f2475faf918dfa05b919joshualitt 5823322fa432a96fdc94d54f2475faf918dfa05b919joshualitt int fStartVertex; 5833322fa432a96fdc94d54f2475faf918dfa05b919joshualitt int fStartIndex; 5843322fa432a96fdc94d54f2475faf918dfa05b919joshualitt int fVertexCount; 5853322fa432a96fdc94d54f2475faf918dfa05b919joshualitt int fIndexCount; 5863322fa432a96fdc94d54f2475faf918dfa05b919joshualitt 5873322fa432a96fdc94d54f2475faf918dfa05b919joshualitt int fInstanceCount; 5883322fa432a96fdc94d54f2475faf918dfa05b919joshualitt int fVerticesPerInstance; 5893322fa432a96fdc94d54f2475faf918dfa05b919joshualitt int fIndicesPerInstance; 5903322fa432a96fdc94d54f2475faf918dfa05b919joshualitt 5913322fa432a96fdc94d54f2475faf918dfa05b919joshualitt SkRect fDevBoundsStorage; 5923322fa432a96fdc94d54f2475faf918dfa05b919joshualitt SkRect* fDevBounds; 5933322fa432a96fdc94d54f2475faf918dfa05b919joshualitt 5947eb8c7b00a5d776bebaf33a8687357df95c1aa43joshualitt GrPendingIOResource<const GrVertexBuffer, kRead_GrIOType> fVertexBuffer; 5957eb8c7b00a5d776bebaf33a8687357df95c1aa43joshualitt GrPendingIOResource<const GrIndexBuffer, kRead_GrIOType> fIndexBuffer; 5963322fa432a96fdc94d54f2475faf918dfa05b919joshualitt }; 5972c93efeb6f2dd652eb2575c04124d82952f020c7joshualitt 5987eb8c7b00a5d776bebaf33a8687357df95c1aa43joshualitt virtual void setDrawBuffers(DrawInfo*) = 0;; 5992c93efeb6f2dd652eb2575c04124d82952f020c7joshualitt bool programUnitTest(int maxStages); 6002c93efeb6f2dd652eb2575c04124d82952f020c7joshualitt 601ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.comprotected: 60225fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com enum GeometrySrcType { 60325fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com kNone_GeometrySrcType, //<! src has not been specified 60425fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com kReserved_GeometrySrcType, //<! src was set using reserve*Space 60525fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com kBuffer_GeometrySrcType //<! src was set using set*SourceToBuffer 60625fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com }; 607d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com 60825fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com struct GeometrySrcState { 60925fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com GeometrySrcType fVertexSrc; 61025fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com union { 61125fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com // valid if src type is buffer 61225fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com const GrVertexBuffer* fVertexBuffer; 61325fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com // valid if src type is reserved or array 61425fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com int fVertexCount; 61525fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com }; 616d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com 61725fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com GeometrySrcType fIndexSrc; 61825fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com union { 61925fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com // valid if src type is buffer 62025fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com const GrIndexBuffer* fIndexBuffer; 62125fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com // valid if src type is reserved or array 62225fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com int fIndexCount; 62325fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com }; 624d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com 625b75b0a0b8492e14c7728e0a0881f87dc64ce60f9jvanverth@google.com size_t fVertexSize; 62625fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com }; 627934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com 628934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com int indexCountInCurrentSource() const { 629934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com const GeometrySrcState& src = this->getGeomSrc(); 630934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com switch (src.fIndexSrc) { 631934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com case kNone_GeometrySrcType: 632934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com return 0; 633934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com case kReserved_GeometrySrcType: 634934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com return src.fIndexCount; 635934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com case kBuffer_GeometrySrcType: 636089a780c3355129eefc942246534bc1f126b8ccbcommit-bot@chromium.org return static_cast<int>(src.fIndexBuffer->gpuMemorySize() / sizeof(uint16_t)); 637934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com default: 63888cb22b6b4816c7a9ca6c5b795965b4606f9eb7bcommit-bot@chromium.org SkFAIL("Unexpected Index Source."); 639934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com return 0; 640934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com } 641934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com } 642a47a48dca5045d71cbc5de343404045209a13e15bsalomon@google.com 6436e4e65066a7c0dbc9bfbfe4b8f5d49c3d8a79b59bsalomon@google.com GrContext* getContext() { return fContext; } 6446e4e65066a7c0dbc9bfbfe4b8f5d49c3d8a79b59bsalomon@google.com const GrContext* getContext() const { return fContext; } 6456e4e65066a7c0dbc9bfbfe4b8f5d49c3d8a79b59bsalomon@google.com 64602ddc8b85ace91b15feb329a6a1d5d62b2b846c6bsalomon@google.com // subclasses must call this in their destructors to ensure all vertex 64702ddc8b85ace91b15feb329a6a1d5d62b2b846c6bsalomon@google.com // and index sources have been released (including those held by 64802ddc8b85ace91b15feb329a6a1d5d62b2b846c6bsalomon@google.com // pushGeometrySource()) 64902ddc8b85ace91b15feb329a6a1d5d62b2b846c6bsalomon@google.com void releaseGeometry(); 65002ddc8b85ace91b15feb329a6a1d5d62b2b846c6bsalomon@google.com 65102ddc8b85ace91b15feb329a6a1d5d62b2b846c6bsalomon@google.com // accessors for derived classes 65202ddc8b85ace91b15feb329a6a1d5d62b2b846c6bsalomon@google.com const GeometrySrcState& getGeomSrc() const { return fGeoSrcStateStack.back(); } 653b75b0a0b8492e14c7728e0a0881f87dc64ce60f9jvanverth@google.com // it is preferable to call this rather than getGeomSrc()->fVertexSize because of the assert. 654b75b0a0b8492e14c7728e0a0881f87dc64ce60f9jvanverth@google.com size_t getVertexSize() const { 65502ddc8b85ace91b15feb329a6a1d5d62b2b846c6bsalomon@google.com // the vertex layout is only valid if a vertex source has been specified. 656f6de475e5cbd143f348ff7738919e397b7fe7f57tfarina@chromium.org SkASSERT(this->getGeomSrc().fVertexSrc != kNone_GeometrySrcType); 657b75b0a0b8492e14c7728e0a0881f87dc64ce60f9jvanverth@google.com return this->getGeomSrc().fVertexSize; 658a47a48dca5045d71cbc5de343404045209a13e15bsalomon@google.com } 6595782d712ffc31557d0cb12d5a220cebb783f6895bsalomon@google.com 660bcce8926524827775539874346dd424a9510dbc9bsalomon@google.com // Subclass must initialize this in its constructor. 661c26d94fd7dc0b00cd6d0e42d28285f4a38aff021bsalomon@google.com SkAutoTUnref<const GrDrawTargetCaps> fCaps; 66202ddc8b85ace91b15feb329a6a1d5d62b2b846c6bsalomon@google.com 6632a05de0c049a8648942a55016126a1f92e1c14d6commit-bot@chromium.org const GrTraceMarkerSet& getActiveTraceMarkers() { return fActiveTraceMarkers; } 6642a05de0c049a8648942a55016126a1f92e1c14d6commit-bot@chromium.org 665651713408c5a5d9565665967ad09981250c7a8c9joshualitt // Makes a copy of the dst if it is necessary for the draw. Returns false if a copy is required 666651713408c5a5d9565665967ad09981250c7a8c9joshualitt // but couldn't be made. Otherwise, returns true. This method needs to be protected because it 667651713408c5a5d9565665967ad09981250c7a8c9joshualitt // needs to be accessed by GLPrograms to setup a correct drawstate 6689853ccef19c200be93a6211f32589fa82a53067cjoshualitt bool setupDstReadIfNecessary(GrDrawState*, 6699853ccef19c200be93a6211f32589fa82a53067cjoshualitt GrDeviceCoordTexture* dstCopy, 6709853ccef19c200be93a6211f32589fa82a53067cjoshualitt const SkRect* drawBounds); 671651713408c5a5d9565665967ad09981250c7a8c9joshualitt 67202ddc8b85ace91b15feb329a6a1d5d62b2b846c6bsalomon@google.comprivate: 67302ddc8b85ace91b15feb329a6a1d5d62b2b846c6bsalomon@google.com // A subclass can optionally overload this function to be notified before 67402ddc8b85ace91b15feb329a6a1d5d62b2b846c6bsalomon@google.com // vertex and index space is reserved. 6759853ccef19c200be93a6211f32589fa82a53067cjoshualitt virtual void willReserveVertexAndIndexSpace(int vertexCount, 6769853ccef19c200be93a6211f32589fa82a53067cjoshualitt size_t vertexStride, 6779853ccef19c200be93a6211f32589fa82a53067cjoshualitt int indexCount) {} 67897805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com 67925fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com // implemented by subclass to allocate space for reserved geom 680a63389843dd18003382d61c2e4610af09ed07d38jvanverth@google.com virtual bool onReserveVertexSpace(size_t vertexSize, int vertexCount, void** vertices) = 0; 68125fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com virtual bool onReserveIndexSpace(int indexCount, void** indices) = 0; 68225fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com // implemented by subclass to handle release of reserved geom space 68325fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com virtual void releaseReservedVertexSpace() = 0; 68425fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com virtual void releaseReservedIndexSpace() = 0; 68502ddc8b85ace91b15feb329a6a1d5d62b2b846c6bsalomon@google.com // subclass overrides to be notified just before geo src state is pushed/popped. 68625fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com virtual void geometrySourceWillPush() = 0; 68725fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com virtual void geometrySourceWillPop(const GeometrySrcState& restoredState) = 0; 68825fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com // subclass called to perform drawing 6899853ccef19c200be93a6211f32589fa82a53067cjoshualitt virtual void onDraw(const GrDrawState&, 6909853ccef19c200be93a6211f32589fa82a53067cjoshualitt const DrawInfo&, 6919176e2c159089458b1e2226a94fab1af0fba32acjoshualitt const GrClipMaskManager::ScissorState&, 6929176e2c159089458b1e2226a94fab1af0fba32acjoshualitt const GrDeviceCoordTexture* dstCopy) = 0; 6935478d427c6e67c986a3390162c8fec77c466058ajoshualitt // TODO copy in order drawbuffer onDrawRect to here 6949853ccef19c200be93a6211f32589fa82a53067cjoshualitt virtual void onDrawRect(GrDrawState*, 6959853ccef19c200be93a6211f32589fa82a53067cjoshualitt const SkRect& rect, 696fd03d4a829efe2d77a712fd991927c55f59a2ffecommit-bot@chromium.org const SkRect* localRect, 6975478d427c6e67c986a3390162c8fec77c466058ajoshualitt const SkMatrix* localMatrix) = 0; 69832184d81629e39809bb9e915286d8fe971a8ed68commit-bot@chromium.org 6999853ccef19c200be93a6211f32589fa82a53067cjoshualitt virtual void onStencilPath(const GrDrawState&, 7009853ccef19c200be93a6211f32589fa82a53067cjoshualitt const GrPath*, 7012c93efeb6f2dd652eb2575c04124d82952f020c7joshualitt const GrClipMaskManager::ScissorState&, 7022c93efeb6f2dd652eb2575c04124d82952f020c7joshualitt const GrStencilSettings&) = 0; 7039853ccef19c200be93a6211f32589fa82a53067cjoshualitt virtual void onDrawPath(const GrDrawState&, 7049853ccef19c200be93a6211f32589fa82a53067cjoshualitt const GrPath*, 7052c93efeb6f2dd652eb2575c04124d82952f020c7joshualitt const GrClipMaskManager::ScissorState&, 7062c93efeb6f2dd652eb2575c04124d82952f020c7joshualitt const GrStencilSettings&, 707c4dc0ad8e252a7e30d19b47d3d0d9f2c69faf854commit-bot@chromium.org const GrDeviceCoordTexture* dstCopy) = 0; 7089853ccef19c200be93a6211f32589fa82a53067cjoshualitt virtual void onDrawPaths(const GrDrawState&, 7099853ccef19c200be93a6211f32589fa82a53067cjoshualitt const GrPathRange*, 71055b24afc178e641e17a5664beba7ab2b4982c91acdalton const void* indices, 71155b24afc178e641e17a5664beba7ab2b4982c91acdalton PathIndexType, 71255b24afc178e641e17a5664beba7ab2b4982c91acdalton const float transformValues[], 7132c93efeb6f2dd652eb2575c04124d82952f020c7joshualitt PathTransformType, 71455b24afc178e641e17a5664beba7ab2b4982c91acdalton int count, 7152c93efeb6f2dd652eb2575c04124d82952f020c7joshualitt const GrClipMaskManager::ScissorState&, 7162c93efeb6f2dd652eb2575c04124d82952f020c7joshualitt const GrStencilSettings&, 7172c93efeb6f2dd652eb2575c04124d82952f020c7joshualitt const GrDeviceCoordTexture*) = 0; 71864aef2bacd1f5c25ffd9347aabd6265c9b60c0f4bsalomon@google.com 71963b21962867af0f98e12a3ccbe5eef76b7ecc3aabsalomon virtual void onClear(const SkIRect* rect, GrColor color, bool canIgnoreRect, 72063b21962867af0f98e12a3ccbe5eef76b7ecc3aabsalomon GrRenderTarget* renderTarget) = 0; 72163b21962867af0f98e12a3ccbe5eef76b7ecc3aabsalomon 72263b21962867af0f98e12a3ccbe5eef76b7ecc3aabsalomon 723e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com // helpers for reserving vertex and index space. 724b75b0a0b8492e14c7728e0a0881f87dc64ce60f9jvanverth@google.com bool reserveVertexSpace(size_t vertexSize, 725e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com int vertexCount, 726e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com void** vertices); 727e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com bool reserveIndexSpace(int indexCount, void** indices); 728d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com 729e826262939dac3e67cb5ce66d4b9faeb8e2538e6bsalomon@google.com // called by drawIndexed and drawNonIndexed. Use a negative indexCount to 730e826262939dac3e67cb5ce66d4b9faeb8e2538e6bsalomon@google.com // indicate non-indexed drawing. 7319853ccef19c200be93a6211f32589fa82a53067cjoshualitt bool checkDraw(const GrDrawState&, 7329853ccef19c200be93a6211f32589fa82a53067cjoshualitt GrPrimitiveType type, 7339853ccef19c200be93a6211f32589fa82a53067cjoshualitt int startVertex, 7349853ccef19c200be93a6211f32589fa82a53067cjoshualitt int startIndex, 7359853ccef19c200be93a6211f32589fa82a53067cjoshualitt int vertexCount, 736e826262939dac3e67cb5ce66d4b9faeb8e2538e6bsalomon@google.com int indexCount) const; 73725fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com // called when setting a new vert/idx source to unref prev vb/ib 73825fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com void releasePreviousVertexSource(); 73925fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com void releasePreviousIndexSource(); 740d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com 741a8916ffd90c04dc6cc1fb9ba94af2ff950284fadcommit-bot@chromium.org // Check to see if this set of draw commands has been sent out 742a8916ffd90c04dc6cc1fb9ba94af2ff950284fadcommit-bot@chromium.org virtual bool isIssued(uint32_t drawID) { return true; } 7439853ccef19c200be93a6211f32589fa82a53067cjoshualitt void getPathStencilSettingsForFilltype(GrPathRendering::FillType, 7449853ccef19c200be93a6211f32589fa82a53067cjoshualitt const GrStencilBuffer*, 7459853ccef19c200be93a6211f32589fa82a53067cjoshualitt GrStencilSettings*); 746a702415d9e80f5631181143c293498de924e8ae4joshualitt virtual GrClipMaskManager* clipMaskManager() = 0; 7472c93efeb6f2dd652eb2575c04124d82952f020c7joshualitt virtual bool setupClip(const SkRect* devBounds, 7482c93efeb6f2dd652eb2575c04124d82952f020c7joshualitt GrDrawState::AutoRestoreEffects* are, 7492c93efeb6f2dd652eb2575c04124d82952f020c7joshualitt GrDrawState::AutoRestoreStencil* ars, 7509853ccef19c200be93a6211f32589fa82a53067cjoshualitt GrDrawState*, 7512c93efeb6f2dd652eb2575c04124d82952f020c7joshualitt GrClipMaskManager::ScissorState* scissorState) = 0; 7527475811143e190e172bf83d13c4bdba85704b604skia.committer@gmail.com 75325fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com enum { 75425fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com kPreallocGeoSrcStateStackCnt = 4, 755ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com }; 75602ddc8b85ace91b15feb329a6a1d5d62b2b846c6bsalomon@google.com SkSTArray<kPreallocGeoSrcStateStackCnt, GeometrySrcState, true> fGeoSrcStateStack; 75702ddc8b85ace91b15feb329a6a1d5d62b2b846c6bsalomon@google.com const GrClipData* fClip; 7586e4e65066a7c0dbc9bfbfe4b8f5d49c3d8a79b59bsalomon@google.com // The context owns us, not vice-versa, so this ptr is not ref'ed by DrawTarget. 7596e4e65066a7c0dbc9bfbfe4b8f5d49c3d8a79b59bsalomon@google.com GrContext* fContext; 7602a05de0c049a8648942a55016126a1f92e1c14d6commit-bot@chromium.org // To keep track that we always have at least as many debug marker adds as removes 7612a05de0c049a8648942a55016126a1f92e1c14d6commit-bot@chromium.org int fGpuTraceMarkerCount; 7622a05de0c049a8648942a55016126a1f92e1c14d6commit-bot@chromium.org GrTraceMarkerSet fActiveTraceMarkers; 7633eee3834fba1d2e29dfb61adcb97e4624b6a3ac8egdaniel GrTraceMarkerSet fStoredTraceMarkers; 764fa35e3ddcc9d130ce87c927218bdf27879c38711reed@google.com 765a4de8c257ea0be8ff7081f645249b6afe5c48e7ecommit-bot@chromium.org typedef SkRefCnt INHERITED; 766ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com}; 767ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 768329bf4862e9d5e05363c2b071d8ca475a0ef1952joshualitt/* 769329bf4862e9d5e05363c2b071d8ca475a0ef1952joshualitt * This class is JUST for clip mask manager. Everyone else should just use draw target above. 770329bf4862e9d5e05363c2b071d8ca475a0ef1952joshualitt */ 7716db519c42471aaaa8a8e1a3ece314014481ab832joshualittclass GrClipTarget : public GrDrawTarget { 7726db519c42471aaaa8a8e1a3ece314014481ab832joshualittpublic: 773329bf4862e9d5e05363c2b071d8ca475a0ef1952joshualitt GrClipTarget(GrContext* context) : INHERITED(context) { 774329bf4862e9d5e05363c2b071d8ca475a0ef1952joshualitt fClipMaskManager.setClipTarget(this); 775329bf4862e9d5e05363c2b071d8ca475a0ef1952joshualitt } 776329bf4862e9d5e05363c2b071d8ca475a0ef1952joshualitt 777329bf4862e9d5e05363c2b071d8ca475a0ef1952joshualitt /* Clip mask manager needs access to the context. 778329bf4862e9d5e05363c2b071d8ca475a0ef1952joshualitt * TODO we only need a very small subset of context in the CMM. 779329bf4862e9d5e05363c2b071d8ca475a0ef1952joshualitt */ 780329bf4862e9d5e05363c2b071d8ca475a0ef1952joshualitt GrContext* getContext() { return INHERITED::getContext(); } 781329bf4862e9d5e05363c2b071d8ca475a0ef1952joshualitt const GrContext* getContext() const { return INHERITED::getContext(); } 782329bf4862e9d5e05363c2b071d8ca475a0ef1952joshualitt 7836db519c42471aaaa8a8e1a3ece314014481ab832joshualitt /** 7846db519c42471aaaa8a8e1a3ece314014481ab832joshualitt * Clip Mask Manager(and no one else) needs to clear private stencil bits. 7856db519c42471aaaa8a8e1a3ece314014481ab832joshualitt * ClipTarget subclass sets clip bit in the stencil buffer. The subclass 7866db519c42471aaaa8a8e1a3ece314014481ab832joshualitt * is free to clear the remaining bits to zero if masked clears are more 7876db519c42471aaaa8a8e1a3ece314014481ab832joshualitt * expensive than clearing all bits. 7886db519c42471aaaa8a8e1a3ece314014481ab832joshualitt */ 7896db519c42471aaaa8a8e1a3ece314014481ab832joshualitt virtual void clearStencilClip(const SkIRect& rect, bool insideClip, GrRenderTarget* = NULL) = 0; 7906db519c42471aaaa8a8e1a3ece314014481ab832joshualitt 7913bdd7dce5e8393aeed0a64b583e1077f5159d516joshualitt /** 7923bdd7dce5e8393aeed0a64b583e1077f5159d516joshualitt * Release any resources that are cached but not currently in use. This 7933bdd7dce5e8393aeed0a64b583e1077f5159d516joshualitt * is intended to give an application some recourse when resources are low. 7943bdd7dce5e8393aeed0a64b583e1077f5159d516joshualitt */ 7953bdd7dce5e8393aeed0a64b583e1077f5159d516joshualitt virtual void purgeResources() SK_OVERRIDE { 7963bdd7dce5e8393aeed0a64b583e1077f5159d516joshualitt // The clip mask manager can rebuild all its clip masks so just 7973bdd7dce5e8393aeed0a64b583e1077f5159d516joshualitt // get rid of them all. 7983bdd7dce5e8393aeed0a64b583e1077f5159d516joshualitt fClipMaskManager.purgeResources(); 7993bdd7dce5e8393aeed0a64b583e1077f5159d516joshualitt }; 8003bdd7dce5e8393aeed0a64b583e1077f5159d516joshualitt 801329bf4862e9d5e05363c2b071d8ca475a0ef1952joshualittprotected: 802329bf4862e9d5e05363c2b071d8ca475a0ef1952joshualitt GrClipMaskManager fClipMaskManager; 803329bf4862e9d5e05363c2b071d8ca475a0ef1952joshualitt 8046db519c42471aaaa8a8e1a3ece314014481ab832joshualittprivate: 805a702415d9e80f5631181143c293498de924e8ae4joshualitt GrClipMaskManager* clipMaskManager() { return &fClipMaskManager; } 806329bf4862e9d5e05363c2b071d8ca475a0ef1952joshualitt 8072c93efeb6f2dd652eb2575c04124d82952f020c7joshualitt virtual bool setupClip(const SkRect* devBounds, 8082c93efeb6f2dd652eb2575c04124d82952f020c7joshualitt GrDrawState::AutoRestoreEffects* are, 8092c93efeb6f2dd652eb2575c04124d82952f020c7joshualitt GrDrawState::AutoRestoreStencil* ars, 8109853ccef19c200be93a6211f32589fa82a53067cjoshualitt GrDrawState*, 8112c93efeb6f2dd652eb2575c04124d82952f020c7joshualitt GrClipMaskManager::ScissorState* scissorState) SK_OVERRIDE; 8122c93efeb6f2dd652eb2575c04124d82952f020c7joshualitt 8136db519c42471aaaa8a8e1a3ece314014481ab832joshualitt typedef GrDrawTarget INHERITED; 8146db519c42471aaaa8a8e1a3ece314014481ab832joshualitt}; 8156db519c42471aaaa8a8e1a3ece314014481ab832joshualitt 816ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com#endif 817