GrDrawTarget.h revision 26e18b593ab65e4d92dfbce92579d8bc180d4c2c
1ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 2ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com/* 3ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Copyright 2010 Google Inc. 4ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * 5ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Use of this source code is governed by a BSD-style license that can be 6ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * found in the LICENSE file. 7ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com */ 8ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 9ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 10ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com#ifndef GrDrawTarget_DEFINED 11ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com#define GrDrawTarget_DEFINED 12ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 138d67c0711b52226db59158a0cfce09f35badd96absalomon@google.com#include "GrClipData.h" 149381363050ec9d3e724076a8e9152bfa9a8de1d1tomhudson@google.com#include "GrDrawState.h" 15934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com#include "GrIndexBuffer.h" 16b9086a026844e4cfd08b219e49ce3f12294cba98bsalomon@google.com#include "SkMatrix.h" 17ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com#include "GrRefCnt.h" 18ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 198d67c0711b52226db59158a0cfce09f35badd96absalomon@google.com#include "SkClipStack.h" 2012b4e27ae1a29460e91a59f38122483e1faec697sugoi@google.com#include "SkPath.h" 2146f7afb9867200b568c21736da8a8bbb56b20e30bsalomon@google.com#include "SkTLazy.h" 22a2d71482db8b6d752a51c96da74768d7dfc27932robertphillips@google.com#include "SkTArray.h" 238d67c0711b52226db59158a0cfce09f35badd96absalomon@google.com#include "SkXfermode.h" 2497c88c255cff3dbb8343c5d090526fdbedad6dd6Scroggo 25a2d71482db8b6d752a51c96da74768d7dfc27932robertphillips@google.comclass GrClipData; 26c26d94fd7dc0b00cd6d0e42d28285f4a38aff021bsalomon@google.comclass GrDrawTargetCaps; 2764aef2bacd1f5c25ffd9347aabd6265c9b60c0f4bsalomon@google.comclass GrPath; 28ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.comclass GrVertexBuffer; 295f74cf8c49701f514b69dc6f1a8b5c0ffd78af0asugoi@google.comclass SkStrokeRec; 3012b4e27ae1a29460e91a59f38122483e1faec697sugoi@google.com 31ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.comclass GrDrawTarget : public GrRefCnt { 32f66018798099750e639a8fa131fece492a050997bsalomon@google.comprotected: 33bcce8926524827775539874346dd424a9510dbc9bsalomon@google.com class DrawInfo; 34bcce8926524827775539874346dd424a9510dbc9bsalomon@google.com 35bcce8926524827775539874346dd424a9510dbc9bsalomon@google.compublic: 36bcce8926524827775539874346dd424a9510dbc9bsalomon@google.com SK_DECLARE_INST_COUNT(GrDrawTarget) 37bcce8926524827775539874346dd424a9510dbc9bsalomon@google.com 38ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com /////////////////////////////////////////////////////////////////////////// 39ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 406e4e65066a7c0dbc9bfbfe4b8f5d49c3d8a79b59bsalomon@google.com // The context may not be fully constructed and should not be used during GrDrawTarget 416e4e65066a7c0dbc9bfbfe4b8f5d49c3d8a79b59bsalomon@google.com // construction. 426e4e65066a7c0dbc9bfbfe4b8f5d49c3d8a79b59bsalomon@google.com GrDrawTarget(GrContext* context); 4325fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com virtual ~GrDrawTarget(); 44ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 45ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com /** 4618c9c198f571997463d9a7134dbd88298e592ec2bsalomon@google.com * Gets the capabilities of the draw target. 4718c9c198f571997463d9a7134dbd88298e592ec2bsalomon@google.com */ 48c26d94fd7dc0b00cd6d0e42d28285f4a38aff021bsalomon@google.com const GrDrawTargetCaps* caps() const { return fCaps.get(); } 4918c9c198f571997463d9a7134dbd88298e592ec2bsalomon@google.com 5018c9c198f571997463d9a7134dbd88298e592ec2bsalomon@google.com /** 51ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * Sets the current clip to the region specified by clip. All draws will be 52ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * clipped against this clip if kClip_StateBit is enabled. 53ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * 545aaa69e4339e229adfb05e96084a8ec0a590238bbsalomon@google.com * Setting the clip may (or may not) zero out the client's stencil bits. 555aaa69e4339e229adfb05e96084a8ec0a590238bbsalomon@google.com * 56ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * @param description of the clipping region 57ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com */ 58beb1af78d016d2700c350487a383c6bcfa7e2e20robertphillips@google.com void setClip(const GrClipData* clip); 59ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 60ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com /** 61ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * Gets the current clip. 62ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * 63ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * @return the clip. 64ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com */ 65beb1af78d016d2700c350487a383c6bcfa7e2e20robertphillips@google.com const GrClipData* getClip() const; 66ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 67a5d056ae0b04021dfb44c2c7a3d6a34e060261b8bsalomon@google.com /** 68a5d056ae0b04021dfb44c2c7a3d6a34e060261b8bsalomon@google.com * Sets the draw state object for the draw target. Note that this does not 69a5d056ae0b04021dfb44c2c7a3d6a34e060261b8bsalomon@google.com * make a copy. The GrDrawTarget will take a reference to passed object. 70a5d056ae0b04021dfb44c2c7a3d6a34e060261b8bsalomon@google.com * Passing NULL will cause the GrDrawTarget to use its own internal draw 71a5d056ae0b04021dfb44c2c7a3d6a34e060261b8bsalomon@google.com * state object rather than an externally provided one. 72a5d056ae0b04021dfb44c2c7a3d6a34e060261b8bsalomon@google.com */ 73a5d056ae0b04021dfb44c2c7a3d6a34e060261b8bsalomon@google.com void setDrawState(GrDrawState* drawState); 74a5d056ae0b04021dfb44c2c7a3d6a34e060261b8bsalomon@google.com 75a5d056ae0b04021dfb44c2c7a3d6a34e060261b8bsalomon@google.com /** 76a5d056ae0b04021dfb44c2c7a3d6a34e060261b8bsalomon@google.com * Read-only access to the GrDrawTarget's current draw state. 77a5d056ae0b04021dfb44c2c7a3d6a34e060261b8bsalomon@google.com */ 78a5d056ae0b04021dfb44c2c7a3d6a34e060261b8bsalomon@google.com const GrDrawState& getDrawState() const { return *fDrawState; } 79a5d056ae0b04021dfb44c2c7a3d6a34e060261b8bsalomon@google.com 80a5d056ae0b04021dfb44c2c7a3d6a34e060261b8bsalomon@google.com /** 81a5d056ae0b04021dfb44c2c7a3d6a34e060261b8bsalomon@google.com * Read-write access to the GrDrawTarget's current draw state. Note that 82a5d056ae0b04021dfb44c2c7a3d6a34e060261b8bsalomon@google.com * this doesn't ref. 83a5d056ae0b04021dfb44c2c7a3d6a34e060261b8bsalomon@google.com */ 84a5d056ae0b04021dfb44c2c7a3d6a34e060261b8bsalomon@google.com GrDrawState* drawState() { return fDrawState; } 853d0835b6ac0003c18147b6e9ca76a497b92d1d40bsalomon@google.com 863d0835b6ac0003c18147b6e9ca76a497b92d1d40bsalomon@google.com /** 87a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com * Color alpha and coverage are two inputs to the drawing pipeline. For some 88a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com * blend modes it is safe to fold the coverage into constant or per-vertex 89a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com * color alpha value. For other blend modes they must be handled separately. 90a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com * Depending on features available in the underlying 3D API this may or may 91a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com * not be possible. 92a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com * 93e79c815bca39fa552983b7a8107219aa5084acdbbsalomon@google.com * This function considers the current draw state and the draw target's 94e79c815bca39fa552983b7a8107219aa5084acdbbsalomon@google.com * capabilities to determine whether coverage can be handled correctly. The 95e79c815bca39fa552983b7a8107219aa5084acdbbsalomon@google.com * following assumptions are made: 96e79c815bca39fa552983b7a8107219aa5084acdbbsalomon@google.com * 1. The caller intends to somehow specify coverage. This can be 97e79c815bca39fa552983b7a8107219aa5084acdbbsalomon@google.com * specified either by enabling a coverage stage on the GrDrawState or 98e79c815bca39fa552983b7a8107219aa5084acdbbsalomon@google.com * via the vertex layout. 992b446734cfa8201e5478648988de86b646cb9544bsalomon@google.com * 2. Other than enabling coverage stages or enabling coverage in the 1002b446734cfa8201e5478648988de86b646cb9544bsalomon@google.com * layout, the current configuration of the target's GrDrawState is as 1012b446734cfa8201e5478648988de86b646cb9544bsalomon@google.com * it will be at draw time. 102a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com */ 103a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com bool canApplyCoverage() const; 104a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com 105a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com /** 1062b446734cfa8201e5478648988de86b646cb9544bsalomon@google.com * Given the current draw state and hw support, will HW AA lines be used (if 1072b446734cfa8201e5478648988de86b646cb9544bsalomon@google.com * a line primitive type is drawn)? 108a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com */ 1099381363050ec9d3e724076a8e9152bfa9a8de1d1tomhudson@google.com bool willUseHWAALines() const; 110a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com 1113d0835b6ac0003c18147b6e9ca76a497b92d1d40bsalomon@google.com /** 112e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com * There are three types of "sources" of geometry (vertices and indices) for 113e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com * draw calls made on the target. When performing an indexed draw, the 114e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com * indices and vertices can use different source types. Once a source is 115934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com * specified it can be used for multiple draws. However, the time at which 116934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com * the geometry data is no longer editable depends on the source type. 11725fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * 11825fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * Sometimes it is necessary to perform a draw while upstack code has 119e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com * already specified geometry that it isn't finished with. So there are push 120e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com * and pop methods. This allows the client to push the sources, draw 121e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com * something using alternate sources, and then pop to restore the original 122e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com * sources. 123e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com * 124e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com * Aside from pushes and pops, a source remains valid until another source 125e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com * is set or resetVertexSource / resetIndexSource is called. Drawing from 126e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com * a reset source is an error. 127e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com * 128e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com * The three types of sources are: 1291c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com * 130e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com * 1. A cpu array (set*SourceToArray). This is useful when the caller 131e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com * already provided vertex data in a format compatible with a 132e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com * GrVertexLayout. The data in the array is consumed at the time that 133e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com * set*SourceToArray is called and subsequent edits to the array will not 134e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com * be reflected in draws. 1351c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com * 13625fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * 2. Reserve. This is most useful when the caller has data it must 13725fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * transform before drawing and is not long-lived. The caller requests 13825fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * that the draw target make room for some amount of vertex and/or index 13925fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * data. The target provides ptrs to hold the vertex and/or index data. 14025fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * 141d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com * The data is writable up until the next drawIndexed, drawNonIndexed, 142934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com * drawIndexedInstances, or pushGeometrySource. At this point the data is 143934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com * frozen and the ptrs are no longer valid. 1441c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com * 145e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com * Where the space is allocated and how it is uploaded to the GPU is 146e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com * subclass-dependent. 147e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com * 1481c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com * 3. Vertex and Index Buffers. This is most useful for geometry that will 149e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com * is long-lived. When the data in the buffer is consumed depends on the 150d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com * GrDrawTarget subclass. For deferred subclasses the caller has to 151e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com * guarantee that the data is still available in the buffers at playback. 152e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com * (TODO: Make this more automatic as we have done for read/write pixels) 153b75b0a0b8492e14c7728e0a0881f87dc64ce60f9jvanverth@google.com * 154b75b0a0b8492e14c7728e0a0881f87dc64ce60f9jvanverth@google.com * The size of each vertex is determined by querying the current GrDrawState. 1551c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com */ 1561c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com 1571c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com /** 158e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com * Reserves space for vertices and/or indices. Zero can be specifed as 159e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com * either the vertex or index count if the caller desires to only reserve 160d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com * space for only indices or only vertices. If zero is specifed for 161e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com * vertexCount then the vertex source will be unmodified and likewise for 162e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com * indexCount. 163ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * 164e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com * If the function returns true then the reserve suceeded and the vertices 165e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com * and indices pointers will point to the space created. 166ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * 167e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com * If the target cannot make space for the request then this function will 168e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com * return false. If vertexCount was non-zero then upon failure the vertex 169e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com * source is reset and likewise for indexCount. 170ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * 171e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com * The pointers to the space allocated for vertices and indices remain valid 172934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com * until a drawIndexed, drawNonIndexed, drawIndexedInstances, or push/ 173934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com * popGeomtrySource is called. At that point logically a snapshot of the 174934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com * data is made and the pointers are invalid. 1751c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com * 176e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com * @param vertexCount the number of vertices to reserve space for. Can be 177b75b0a0b8492e14c7728e0a0881f87dc64ce60f9jvanverth@google.com * 0. Vertex size is queried from the current GrDrawState. 17825fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * @param indexCount the number of indices to reserve space for. Can be 0. 179e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com * @param vertices will point to reserved vertex space if vertexCount is 180d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com * non-zero. Illegal to pass NULL if vertexCount > 0. 18125fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * @param indices will point to reserved index space if indexCount is 18225fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * non-zero. Illegal to pass NULL if indexCount > 0. 18325fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com */ 184b75b0a0b8492e14c7728e0a0881f87dc64ce60f9jvanverth@google.com bool reserveVertexAndIndexSpace(int vertexCount, 18597805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com int indexCount, 18697805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com void** vertices, 18797805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com void** indices); 18825fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com 189ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com /** 190ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * Provides hints to caller about the number of vertices and indices 191ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * that can be allocated cheaply. This can be useful if caller is reserving 192ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * space but doesn't know exactly how much geometry is needed. 193ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * 194ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * Also may hint whether the draw target should be flushed first. This is 195ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * useful for deferred targets. 196ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * 197ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * @param vertexCount in: hint about how many vertices the caller would 198b75b0a0b8492e14c7728e0a0881f87dc64ce60f9jvanverth@google.com * like to allocate. Vertex size is queried from the 199b75b0a0b8492e14c7728e0a0881f87dc64ce60f9jvanverth@google.com * current GrDrawState. 200ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * out: a hint about the number of vertices that can be 201ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * allocated cheaply. Negative means no hint. 202ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * Ignored if NULL. 203ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * @param indexCount in: hint about how many indices the caller would 204ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * like to allocate. 205ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * out: a hint about the number of indices that can be 206ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * allocated cheaply. Negative means no hint. 207ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * Ignored if NULL. 208ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * 209ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * @return true if target should be flushed based on the input values. 210ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com */ 211b75b0a0b8492e14c7728e0a0881f87dc64ce60f9jvanverth@google.com virtual bool geometryHints(int* vertexCount, 2121c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com int* indexCount) const; 213ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 214ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com /** 2151c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com * Sets source of vertex data for the next draw. Array must contain 2161c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com * the vertex data when this is called. 217ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * 218b75b0a0b8492e14c7728e0a0881f87dc64ce60f9jvanverth@google.com * @param vertexArray cpu array containing vertex data. 219ae683921ffda9108147a29da7319c7eee4dc9245skia.committer@gmail.com * @param vertexCount the number of vertices in the array. Vertex size is 220b75b0a0b8492e14c7728e0a0881f87dc64ce60f9jvanverth@google.com * queried from the current GrDrawState. 221ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com */ 222b75b0a0b8492e14c7728e0a0881f87dc64ce60f9jvanverth@google.com void setVertexSourceToArray(const void* vertexArray, int vertexCount); 223ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 224ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com /** 2251c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com * Sets source of index data for the next indexed draw. Array must contain 2261c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com * the indices when this is called. 227ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * 228b75b0a0b8492e14c7728e0a0881f87dc64ce60f9jvanverth@google.com * @param indexArray cpu array containing index data. 2291c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com * @param indexCount the number of indices in the array. 230ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com */ 2311c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com void setIndexSourceToArray(const void* indexArray, int indexCount); 232ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 233ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com /** 234ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * Sets source of vertex data for the next draw. Data does not have to be 235934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com * in the buffer until drawIndexed, drawNonIndexed, or drawIndexedInstances. 236ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * 237ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * @param buffer vertex buffer containing vertex data. Must be 238ae683921ffda9108147a29da7319c7eee4dc9245skia.committer@gmail.com * unlocked before draw call. Vertex size is queried 239b75b0a0b8492e14c7728e0a0881f87dc64ce60f9jvanverth@google.com * from current GrDrawState. 240ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com */ 241b75b0a0b8492e14c7728e0a0881f87dc64ce60f9jvanverth@google.com void setVertexSourceToBuffer(const GrVertexBuffer* buffer); 242ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 243ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com /** 244ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * Sets source of index data for the next indexed draw. Data does not have 245934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com * to be in the buffer until drawIndexed. 246ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * 247ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * @param buffer index buffer containing indices. Must be unlocked 248ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * before indexed draw call. 249ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com */ 250ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com void setIndexSourceToBuffer(const GrIndexBuffer* buffer); 251d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com 25225fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com /** 25325fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * Resets vertex source. Drawing from reset vertices is illegal. Set vertex 25425fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * source to reserved, array, or buffer before next draw. May be able to free 25525fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * up temporary storage allocated by setVertexSourceToArray or 25625fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * reserveVertexSpace. 25725fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com */ 25825fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com void resetVertexSource(); 259d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com 26025fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com /** 26125fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * Resets index source. Indexed Drawing from reset indices is illegal. Set 26225fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * index source to reserved, array, or buffer before next indexed draw. May 26325fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * be able to free up temporary storage allocated by setIndexSourceToArray 26425fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * or reserveIndexSpace. 26525fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com */ 26697805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com void resetIndexSource(); 267d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com 26897805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com /** 26997805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com * Query to find out if the vertex or index source is reserved. 27097805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com */ 27197805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com bool hasReservedVerticesOrIndices() const { 27273d98aace4f74acc39d8de33484c8aec8e917739bsalomon@google.com return kReserved_GeometrySrcType == this->getGeomSrc().fVertexSrc || 27397805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com kReserved_GeometrySrcType == this->getGeomSrc().fIndexSrc; 27497805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com } 275ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 276ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com /** 27725fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * Pushes and resets the vertex/index sources. Any reserved vertex / index 27825fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * data is finalized (i.e. cannot be updated after the matching pop but can 27925fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * be drawn from). Must be balanced by a pop. 28025fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com */ 28125fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com void pushGeometrySource(); 28225fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com 28325fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com /** 28425fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * Pops the vertex / index sources from the matching push. 28525fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com */ 28625fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com void popGeometrySource(); 28764aef2bacd1f5c25ffd9347aabd6265c9b60c0f4bsalomon@google.com 28825fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com /** 289ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * Draws indexed geometry using the current state and current vertex / index 290ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * sources. 291ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * 292ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * @param type The type of primitives to draw. 293ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * @param startVertex the vertex in the vertex array/buffer corresponding 294ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * to index 0 295ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * @param startIndex first index to read from index src. 296ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * @param vertexCount one greater than the max index. 297ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * @param indexCount the number of index elements to read. The index count 298ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * is effectively trimmed to the last completely 299ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * specified primitive. 300d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com * @param devBounds optional bounds hint. This is a promise from the caller, 301d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com * not a request for clipping. 302ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com */ 30325fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com void drawIndexed(GrPrimitiveType type, 30425fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com int startVertex, 30525fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com int startIndex, 30625fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com int vertexCount, 307d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com int indexCount, 308d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com const SkRect* devBounds = NULL); 309ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 310ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com /** 311ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * Draws non-indexed geometry using the current state and current vertex 312ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * sources. 313ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * 314ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * @param type The type of primitives to draw. 315ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * @param startVertex the vertex in the vertex array/buffer corresponding 316ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * to index 0 317ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * @param vertexCount one greater than the max index. 318d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com * @param devBounds optional bounds hint. This is a promise from the caller, 319d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com * not a request for clipping. 320ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com */ 32125fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com void drawNonIndexed(GrPrimitiveType type, 32225fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com int startVertex, 323d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com int vertexCount, 324d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com const SkRect* devBounds = NULL); 325ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 32686afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com /** 32764aef2bacd1f5c25ffd9347aabd6265c9b60c0f4bsalomon@google.com * Draws path into the stencil buffer. The fill must be either even/odd or 32864aef2bacd1f5c25ffd9347aabd6265c9b60c0f4bsalomon@google.com * winding (not inverse or hairline). It will respect the HW antialias flag 32964aef2bacd1f5c25ffd9347aabd6265c9b60c0f4bsalomon@google.com * on the draw state (if possible in the 3D API). 33064aef2bacd1f5c25ffd9347aabd6265c9b60c0f4bsalomon@google.com */ 3315f74cf8c49701f514b69dc6f1a8b5c0ffd78af0asugoi@google.com void stencilPath(const GrPath*, const SkStrokeRec& stroke, SkPath::FillType fill); 33264aef2bacd1f5c25ffd9347aabd6265c9b60c0f4bsalomon@google.com 33364aef2bacd1f5c25ffd9347aabd6265c9b60c0f4bsalomon@google.com /** 33486afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com * Helper function for drawing rects. This does not use the current index 33586afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com * and vertex sources. After returning, the vertex and index sources may 336c78188896e28a4ae49e406a7422b345ae177dafebsalomon@google.com * have changed. They should be reestablished before the next draw call. 337c78188896e28a4ae49e406a7422b345ae177dafebsalomon@google.com * This cannot be called between reserving and releasing 338d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com * geometry. 339044679ef8c08e1f01afadf5bc08251fe8597df81skia.committer@gmail.com * 340d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com * A subclass may override this to perform more optimal rect rendering. Its 341d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com * draws should be funneled through one of the public GrDrawTarget draw methods 342d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com * (e.g. drawNonIndexed, drawIndexedInstances, ...). The base class draws a two 343d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com * triangle fan using drawNonIndexed from reserved vertex space. 344044679ef8c08e1f01afadf5bc08251fe8597df81skia.committer@gmail.com * 345c78188896e28a4ae49e406a7422b345ae177dafebsalomon@google.com * @param rect the rect to draw 346c78188896e28a4ae49e406a7422b345ae177dafebsalomon@google.com * @param matrix optional matrix applied to rect (before viewMatrix) 347c78188896e28a4ae49e406a7422b345ae177dafebsalomon@google.com * @param localRect optional rect that specifies local coords to map onto 348c78188896e28a4ae49e406a7422b345ae177dafebsalomon@google.com * rect. If NULL then rect serves as the local coords. 349c78188896e28a4ae49e406a7422b345ae177dafebsalomon@google.com * @param localMatrix optional matrix applied to localRect. If 350044679ef8c08e1f01afadf5bc08251fe8597df81skia.committer@gmail.com * srcRect is non-NULL and srcMatrix is non-NULL 351044679ef8c08e1f01afadf5bc08251fe8597df81skia.committer@gmail.com * then srcRect will be transformed by srcMatrix. 3523976825a21532e254311b90b4a9046e25717e335jvanverth@google.com * srcMatrix can be NULL when no srcMatrix is desired. 35386afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com */ 354d302f1401b3c9aea094804bad4e76de98782cfe8bsalomon@google.com virtual void drawRect(const GrRect& rect, 355b9086a026844e4cfd08b219e49ce3f12294cba98bsalomon@google.com const SkMatrix* matrix, 356c78188896e28a4ae49e406a7422b345ae177dafebsalomon@google.com const GrRect* localRect, 357c78188896e28a4ae49e406a7422b345ae177dafebsalomon@google.com const SkMatrix* localMatrix); 3583976825a21532e254311b90b4a9046e25717e335jvanverth@google.com 359cf939ae54842fc7408ee68a41427086962b4c3dcbsalomon@google.com /** 360c78188896e28a4ae49e406a7422b345ae177dafebsalomon@google.com * Helper for drawRect when the caller doesn't need separate local rects or matrices. 361cf939ae54842fc7408ee68a41427086962b4c3dcbsalomon@google.com */ 362cf939ae54842fc7408ee68a41427086962b4c3dcbsalomon@google.com void drawSimpleRect(const GrRect& rect, const SkMatrix* matrix = NULL) { 363c78188896e28a4ae49e406a7422b345ae177dafebsalomon@google.com drawRect(rect, matrix, NULL, NULL); 364cf939ae54842fc7408ee68a41427086962b4c3dcbsalomon@google.com } 365cf939ae54842fc7408ee68a41427086962b4c3dcbsalomon@google.com void drawSimpleRect(const GrIRect& irect, const SkMatrix* matrix = NULL) { 366cf939ae54842fc7408ee68a41427086962b4c3dcbsalomon@google.com SkRect rect = SkRect::MakeFromIRect(irect); 367c78188896e28a4ae49e406a7422b345ae177dafebsalomon@google.com this->drawRect(rect, matrix, NULL, NULL); 368cf939ae54842fc7408ee68a41427086962b4c3dcbsalomon@google.com } 36986afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com 37086afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com /** 371934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com * This call is used to draw multiple instances of some geometry with a 372934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com * given number of vertices (V) and indices (I) per-instance. The indices in 373934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com * the index source must have the form i[k+I] == i[k] + V. Also, all indices 374934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com * i[kI] ... i[(k+1)I-1] must be elements of the range kV ... (k+1)V-1. As a 375934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com * concrete example, the following index buffer for drawing a series of 376934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com * quads each as two triangles each satisfies these conditions with V=4 and 377934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com * I=6: 378934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com * (0,1,2,0,2,3, 4,5,6,4,6,7, 8,9,10,8,10,11, ...) 379934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com * 380934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com * The call assumes that the pattern of indices fills the entire index 381934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com * source. The size of the index buffer limits the number of instances that 382934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com * can be drawn by the GPU in a single draw. However, the caller may specify 383934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com * any (positive) number for instanceCount and if necessary multiple GPU 384d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com * draws will be issued. Moreover, when drawIndexedInstances is called 385934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com * multiple times it may be possible for GrDrawTarget to group them into a 386934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com * single GPU draw. 387934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com * 388934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com * @param type the type of primitives to draw 389934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com * @param instanceCount the number of instances to draw. Each instance 390934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com * consists of verticesPerInstance vertices indexed by 391934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com * indicesPerInstance indices drawn as the primitive 392934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com * type specified by type. 393934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com * @param verticesPerInstance The number of vertices in each instance (V 394934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com * in the above description). 395934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com * @param indicesPerInstance The number of indices in each instance (I 396934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com * in the above description). 397d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com * @param devBounds optional bounds hint. This is a promise from the caller, 398d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com * not a request for clipping. 399934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com */ 400d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com void drawIndexedInstances(GrPrimitiveType type, 401d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com int instanceCount, 402d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com int verticesPerInstance, 403d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com int indicesPerInstance, 404d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com const SkRect* devBounds = NULL); 405934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com 406934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com /** 407d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com * Clear the current render target if one isn't passed in. Ignores the 408d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com * clip and all other draw state (blend mode, stages, etc). Clears the 409c82a8b7aa4ec19fba508c394920a9e88d3e5bd12robertphillips@google.com * whole thing if rect is NULL, otherwise just the rect. 4100b335c1ac100aeacf79a4c98a052286fd46661e7bsalomon@google.com */ 411d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com virtual void clear(const GrIRect* rect, 412c82a8b7aa4ec19fba508c394920a9e88d3e5bd12robertphillips@google.com GrColor color, 413c82a8b7aa4ec19fba508c394920a9e88d3e5bd12robertphillips@google.com GrRenderTarget* renderTarget = NULL) = 0; 4140b335c1ac100aeacf79a4c98a052286fd46661e7bsalomon@google.com 415ff17584e1c15f68ccc296be517e8a6776a9ddabdrobertphillips@google.com /** 416ff17584e1c15f68ccc296be517e8a6776a9ddabdrobertphillips@google.com * Release any resources that are cached but not currently in use. This 417ff17584e1c15f68ccc296be517e8a6776a9ddabdrobertphillips@google.com * is intended to give an application some recourse when resources are low. 418ff17584e1c15f68ccc296be517e8a6776a9ddabdrobertphillips@google.com */ 419ff17584e1c15f68ccc296be517e8a6776a9ddabdrobertphillips@google.com virtual void purgeResources() {}; 420ff17584e1c15f68ccc296be517e8a6776a9ddabdrobertphillips@google.com 421d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com /** 422d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com * For subclass internal use to invoke a call to onDraw(). See DrawInfo below. 423d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com */ 424d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com void executeDraw(const DrawInfo& info) { this->onDraw(info); } 425d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com 42625fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com //////////////////////////////////////////////////////////////////////////// 427ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 428873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com /** 429873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com * See AutoStateRestore below. 430873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com */ 431873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com enum ASRInit { 432873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com kPreserve_ASRInit, 433873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com kReset_ASRInit 434873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com }; 435873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com 436873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com /** 437873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com * Saves off the current state and restores it in the destructor. It will 438873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com * install a new GrDrawState object on the target (setDrawState) and restore 439873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com * the previous one in the destructor. The caller should call drawState() to 440873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com * get the new draw state after the ASR is installed. 441873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com * 442873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com * GrDrawState* state = target->drawState(); 443873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com * AutoStateRestore asr(target, GrDrawTarget::kReset_ASRInit). 444873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com * state->setRenderTarget(rt); // state refers to the GrDrawState set on 445873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com * // target before asr was initialized. 446873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com * // Therefore, rt is set on the GrDrawState 447873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com * // that will be restored after asr's 448873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com * // destructor rather than target's current 449d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com * // GrDrawState. 450873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com */ 451ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com class AutoStateRestore : ::GrNoncopyable { 452ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com public: 453873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com /** 454873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com * Default ASR will have no effect unless set() is subsequently called. 455873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com */ 45606afe7b5a1ef03bfc6494c51ab2a1f7a386de5c2bsalomon@google.com AutoStateRestore(); 457873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com 458873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com /** 459873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com * Saves the state on target. The state will be restored when the ASR 460873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com * is destroyed. If this constructor is used do not call set(). 461873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com * 462873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com * @param init Should the newly installed GrDrawState be a copy of the 463873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com * previous state or a default-initialized GrDrawState. 464873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com */ 465873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com AutoStateRestore(GrDrawTarget* target, ASRInit init); 466873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com 467ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com ~AutoStateRestore(); 468ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 46906afe7b5a1ef03bfc6494c51ab2a1f7a386de5c2bsalomon@google.com /** 470873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com * Saves the state on target. The state will be restored when the ASR 471873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com * is destroyed. This should only be called once per ASR object and only 472873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com * when the default constructor was used. For nested saves use multiple 473873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com * ASR objects. 474873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com * 475873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com * @param init Should the newly installed GrDrawState be a copy of the 476873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com * previous state or a default-initialized GrDrawState. 47706afe7b5a1ef03bfc6494c51ab2a1f7a386de5c2bsalomon@google.com */ 478873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com void set(GrDrawTarget* target, ASRInit init); 47906afe7b5a1ef03bfc6494c51ab2a1f7a386de5c2bsalomon@google.com 480ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com private: 481873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com GrDrawTarget* fDrawTarget; 482873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com SkTLazy<GrDrawState> fTempState; 483873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com GrDrawState* fSavedState; 484ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com }; 485ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 48625fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com //////////////////////////////////////////////////////////////////////////// 4871c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com 488ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com class AutoReleaseGeometry : ::GrNoncopyable { 489ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com public: 490ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com AutoReleaseGeometry(GrDrawTarget* target, 49125fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com int vertexCount, 49225fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com int indexCount); 49325fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com AutoReleaseGeometry(); 49425fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com ~AutoReleaseGeometry(); 4955782d712ffc31557d0cb12d5a220cebb783f6895bsalomon@google.com bool set(GrDrawTarget* target, 49625fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com int vertexCount, 49725fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com int indexCount); 498a47a48dca5045d71cbc5de343404045209a13e15bsalomon@google.com bool succeeded() const { return NULL != fTarget; } 4996513cd06ae34f5d777b3aaea0b4533014d0a10f2bsalomon@google.com void* vertices() const { GrAssert(this->succeeded()); return fVertices; } 5006513cd06ae34f5d777b3aaea0b4533014d0a10f2bsalomon@google.com void* indices() const { GrAssert(this->succeeded()); return fIndices; } 501ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com GrPoint* positions() const { 5026513cd06ae34f5d777b3aaea0b4533014d0a10f2bsalomon@google.com return static_cast<GrPoint*>(this->vertices()); 503ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com } 504ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 505ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com private: 50625fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com void reset(); 507d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com 508ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com GrDrawTarget* fTarget; 509ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com void* fVertices; 510ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com void* fIndices; 511ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com }; 512ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 51325fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com //////////////////////////////////////////////////////////////////////////// 514ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 515ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com class AutoClipRestore : ::GrNoncopyable { 516ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com public: 517ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com AutoClipRestore(GrDrawTarget* target) { 518ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com fTarget = target; 519ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com fClip = fTarget->getClip(); 520ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com } 521ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 5228d67c0711b52226db59158a0cfce09f35badd96absalomon@google.com AutoClipRestore(GrDrawTarget* target, const SkIRect& newClip); 5238d67c0711b52226db59158a0cfce09f35badd96absalomon@google.com 524ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com ~AutoClipRestore() { 525ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com fTarget->setClip(fClip); 526ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com } 527ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com private: 5288d67c0711b52226db59158a0cfce09f35badd96absalomon@google.com GrDrawTarget* fTarget; 5298d67c0711b52226db59158a0cfce09f35badd96absalomon@google.com const GrClipData* fClip; 5308d67c0711b52226db59158a0cfce09f35badd96absalomon@google.com SkTLazy<SkClipStack> fStack; 5318d67c0711b52226db59158a0cfce09f35badd96absalomon@google.com GrClipData fReplacementClip; 532ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com }; 533d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com 53425fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com //////////////////////////////////////////////////////////////////////////// 535d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com 536b75b0a0b8492e14c7728e0a0881f87dc64ce60f9jvanverth@google.com class AutoGeometryAndStatePush : ::GrNoncopyable { 53725fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com public: 538ae683921ffda9108147a29da7319c7eee4dc9245skia.committer@gmail.com AutoGeometryAndStatePush(GrDrawTarget* target, ASRInit init) 539b75b0a0b8492e14c7728e0a0881f87dc64ce60f9jvanverth@google.com : fState(target, init) { 54025fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com GrAssert(NULL != target); 54125fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com fTarget = target; 54225fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com target->pushGeometrySource(); 54325fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com } 544b75b0a0b8492e14c7728e0a0881f87dc64ce60f9jvanverth@google.com ~AutoGeometryAndStatePush() { 54525fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com fTarget->popGeometrySource(); 54625fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com } 54725fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com private: 548b75b0a0b8492e14c7728e0a0881f87dc64ce60f9jvanverth@google.com GrDrawTarget* fTarget; 549b75b0a0b8492e14c7728e0a0881f87dc64ce60f9jvanverth@google.com AutoStateRestore fState; 55025fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com }; 551ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 552ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.comprotected: 553471d471dcd7422e5dd9c822c1092b2ba4721dcfebsalomon@google.com 55425fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com enum GeometrySrcType { 55525fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com kNone_GeometrySrcType, //<! src has not been specified 55625fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com kReserved_GeometrySrcType, //<! src was set using reserve*Space 55725fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com kArray_GeometrySrcType, //<! src was set using set*SourceToArray 55825fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com kBuffer_GeometrySrcType //<! src was set using set*SourceToBuffer 55925fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com }; 560d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com 56125fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com struct GeometrySrcState { 56225fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com GeometrySrcType fVertexSrc; 56325fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com union { 56425fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com // valid if src type is buffer 56525fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com const GrVertexBuffer* fVertexBuffer; 56625fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com // valid if src type is reserved or array 56725fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com int fVertexCount; 56825fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com }; 569d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com 57025fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com GeometrySrcType fIndexSrc; 57125fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com union { 57225fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com // valid if src type is buffer 57325fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com const GrIndexBuffer* fIndexBuffer; 57425fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com // valid if src type is reserved or array 57525fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com int fIndexCount; 57625fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com }; 577d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com 578b75b0a0b8492e14c7728e0a0881f87dc64ce60f9jvanverth@google.com size_t fVertexSize; 57925fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com }; 580934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com 581934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com int indexCountInCurrentSource() const { 582934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com const GeometrySrcState& src = this->getGeomSrc(); 583934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com switch (src.fIndexSrc) { 584934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com case kNone_GeometrySrcType: 585934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com return 0; 586934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com case kReserved_GeometrySrcType: 587934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com case kArray_GeometrySrcType: 588934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com return src.fIndexCount; 589934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com case kBuffer_GeometrySrcType: 590934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com return src.fIndexBuffer->sizeInBytes() / sizeof(uint16_t); 591934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com default: 592934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com GrCrash("Unexpected Index Source."); 593934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com return 0; 594934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com } 595934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com } 596a47a48dca5045d71cbc5de343404045209a13e15bsalomon@google.com 5976e4e65066a7c0dbc9bfbfe4b8f5d49c3d8a79b59bsalomon@google.com GrContext* getContext() { return fContext; } 5986e4e65066a7c0dbc9bfbfe4b8f5d49c3d8a79b59bsalomon@google.com const GrContext* getContext() const { return fContext; } 5996e4e65066a7c0dbc9bfbfe4b8f5d49c3d8a79b59bsalomon@google.com 60002ddc8b85ace91b15feb329a6a1d5d62b2b846c6bsalomon@google.com // A subclass may override this function if it wishes to be notified when the clip is changed. 60102ddc8b85ace91b15feb329a6a1d5d62b2b846c6bsalomon@google.com // The override should call INHERITED::clipWillBeSet(). 60202ddc8b85ace91b15feb329a6a1d5d62b2b846c6bsalomon@google.com virtual void clipWillBeSet(const GrClipData* clipData); 60302ddc8b85ace91b15feb329a6a1d5d62b2b846c6bsalomon@google.com 60402ddc8b85ace91b15feb329a6a1d5d62b2b846c6bsalomon@google.com // subclasses must call this in their destructors to ensure all vertex 60502ddc8b85ace91b15feb329a6a1d5d62b2b846c6bsalomon@google.com // and index sources have been released (including those held by 60602ddc8b85ace91b15feb329a6a1d5d62b2b846c6bsalomon@google.com // pushGeometrySource()) 60702ddc8b85ace91b15feb329a6a1d5d62b2b846c6bsalomon@google.com void releaseGeometry(); 60802ddc8b85ace91b15feb329a6a1d5d62b2b846c6bsalomon@google.com 60902ddc8b85ace91b15feb329a6a1d5d62b2b846c6bsalomon@google.com // accessors for derived classes 61002ddc8b85ace91b15feb329a6a1d5d62b2b846c6bsalomon@google.com const GeometrySrcState& getGeomSrc() const { return fGeoSrcStateStack.back(); } 611b75b0a0b8492e14c7728e0a0881f87dc64ce60f9jvanverth@google.com // it is preferable to call this rather than getGeomSrc()->fVertexSize because of the assert. 612b75b0a0b8492e14c7728e0a0881f87dc64ce60f9jvanverth@google.com size_t getVertexSize() const { 61302ddc8b85ace91b15feb329a6a1d5d62b2b846c6bsalomon@google.com // the vertex layout is only valid if a vertex source has been specified. 61402ddc8b85ace91b15feb329a6a1d5d62b2b846c6bsalomon@google.com GrAssert(this->getGeomSrc().fVertexSrc != kNone_GeometrySrcType); 615b75b0a0b8492e14c7728e0a0881f87dc64ce60f9jvanverth@google.com return this->getGeomSrc().fVertexSize; 616a47a48dca5045d71cbc5de343404045209a13e15bsalomon@google.com } 6175782d712ffc31557d0cb12d5a220cebb783f6895bsalomon@google.com 618bcce8926524827775539874346dd424a9510dbc9bsalomon@google.com // Subclass must initialize this in its constructor. 619c26d94fd7dc0b00cd6d0e42d28285f4a38aff021bsalomon@google.com SkAutoTUnref<const GrDrawTargetCaps> fCaps; 62002ddc8b85ace91b15feb329a6a1d5d62b2b846c6bsalomon@google.com 621d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com /** 622d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com * Used to communicate draws to subclass's onDraw function. 623d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com */ 62474749cd45c29b4f5300e2518f2c2c765ce8ae208bsalomon@google.com class DrawInfo { 62574749cd45c29b4f5300e2518f2c2c765ce8ae208bsalomon@google.com public: 62674749cd45c29b4f5300e2518f2c2c765ce8ae208bsalomon@google.com DrawInfo(const DrawInfo& di) { (*this) = di; } 627d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com DrawInfo& operator =(const DrawInfo& di); 62874749cd45c29b4f5300e2518f2c2c765ce8ae208bsalomon@google.com 62974749cd45c29b4f5300e2518f2c2c765ce8ae208bsalomon@google.com GrPrimitiveType primitiveType() const { return fPrimitiveType; } 63074749cd45c29b4f5300e2518f2c2c765ce8ae208bsalomon@google.com int startVertex() const { return fStartVertex; } 63174749cd45c29b4f5300e2518f2c2c765ce8ae208bsalomon@google.com int startIndex() const { return fStartIndex; } 63274749cd45c29b4f5300e2518f2c2c765ce8ae208bsalomon@google.com int vertexCount() const { return fVertexCount; } 63374749cd45c29b4f5300e2518f2c2c765ce8ae208bsalomon@google.com int indexCount() const { return fIndexCount; } 634d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com int verticesPerInstance() const { return fVerticesPerInstance; } 635d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com int indicesPerInstance() const { return fIndicesPerInstance; } 636d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com int instanceCount() const { return fInstanceCount; } 63774749cd45c29b4f5300e2518f2c2c765ce8ae208bsalomon@google.com 63874749cd45c29b4f5300e2518f2c2c765ce8ae208bsalomon@google.com bool isIndexed() const { return fIndexCount > 0; } 639d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com#if GR_DEBUG 640d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com bool isInstanced() const; // this version is longer because of asserts 641d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com#else 642d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com bool isInstanced() const { return fInstanceCount > 0; } 643d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com#endif 644d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com 645d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com // adds or remove instances 646d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com void adjustInstanceCount(int instanceOffset); 647d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com // shifts the start vertex 648d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com void adjustStartVertex(int vertexOffset); 649d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com // shifts the start index 650d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com void adjustStartIndex(int indexOffset); 651d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com 652d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com void setDevBounds(const SkRect& bounds) { 653d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com fDevBoundsStorage = bounds; 654d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com fDevBounds = &fDevBoundsStorage; 655d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com } 656d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com const SkRect* getDevBounds() const { return fDevBounds; } 65774749cd45c29b4f5300e2518f2c2c765ce8ae208bsalomon@google.com 65826e18b593ab65e4d92dfbce92579d8bc180d4c2cbsalomon@google.com // NULL if no copy of the dst is needed for the draw. 65926e18b593ab65e4d92dfbce92579d8bc180d4c2cbsalomon@google.com const GrDeviceCoordTexture* getDstCopy() const { 66026e18b593ab65e4d92dfbce92579d8bc180d4c2cbsalomon@google.com if (NULL != fDstCopy.texture()) { 66126e18b593ab65e4d92dfbce92579d8bc180d4c2cbsalomon@google.com return &fDstCopy; 66226e18b593ab65e4d92dfbce92579d8bc180d4c2cbsalomon@google.com } else { 66326e18b593ab65e4d92dfbce92579d8bc180d4c2cbsalomon@google.com return NULL; 66426e18b593ab65e4d92dfbce92579d8bc180d4c2cbsalomon@google.com } 66526e18b593ab65e4d92dfbce92579d8bc180d4c2cbsalomon@google.com } 66626e18b593ab65e4d92dfbce92579d8bc180d4c2cbsalomon@google.com 66774749cd45c29b4f5300e2518f2c2c765ce8ae208bsalomon@google.com private: 668d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com DrawInfo() { fDevBounds = NULL; } 669d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com 67074749cd45c29b4f5300e2518f2c2c765ce8ae208bsalomon@google.com friend class GrDrawTarget; 671d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com 67226e18b593ab65e4d92dfbce92579d8bc180d4c2cbsalomon@google.com GrPrimitiveType fPrimitiveType; 67374749cd45c29b4f5300e2518f2c2c765ce8ae208bsalomon@google.com 67426e18b593ab65e4d92dfbce92579d8bc180d4c2cbsalomon@google.com int fStartVertex; 67526e18b593ab65e4d92dfbce92579d8bc180d4c2cbsalomon@google.com int fStartIndex; 67626e18b593ab65e4d92dfbce92579d8bc180d4c2cbsalomon@google.com int fVertexCount; 67726e18b593ab65e4d92dfbce92579d8bc180d4c2cbsalomon@google.com int fIndexCount; 678d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com 67926e18b593ab65e4d92dfbce92579d8bc180d4c2cbsalomon@google.com int fInstanceCount; 68026e18b593ab65e4d92dfbce92579d8bc180d4c2cbsalomon@google.com int fVerticesPerInstance; 68126e18b593ab65e4d92dfbce92579d8bc180d4c2cbsalomon@google.com int fIndicesPerInstance; 682d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com 68326e18b593ab65e4d92dfbce92579d8bc180d4c2cbsalomon@google.com SkRect fDevBoundsStorage; 68426e18b593ab65e4d92dfbce92579d8bc180d4c2cbsalomon@google.com SkRect* fDevBounds; 68526e18b593ab65e4d92dfbce92579d8bc180d4c2cbsalomon@google.com 68626e18b593ab65e4d92dfbce92579d8bc180d4c2cbsalomon@google.com GrDeviceCoordTexture fDstCopy; 68774749cd45c29b4f5300e2518f2c2c765ce8ae208bsalomon@google.com }; 68874749cd45c29b4f5300e2518f2c2c765ce8ae208bsalomon@google.com 68902ddc8b85ace91b15feb329a6a1d5d62b2b846c6bsalomon@google.comprivate: 69002ddc8b85ace91b15feb329a6a1d5d62b2b846c6bsalomon@google.com // A subclass can optionally overload this function to be notified before 69102ddc8b85ace91b15feb329a6a1d5d62b2b846c6bsalomon@google.com // vertex and index space is reserved. 692b75b0a0b8492e14c7728e0a0881f87dc64ce60f9jvanverth@google.com virtual void willReserveVertexAndIndexSpace(int vertexCount, 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; 70025fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com // subclass must consume array contents when set 70102ddc8b85ace91b15feb329a6a1d5d62b2b846c6bsalomon@google.com virtual void onSetVertexSourceToArray(const void* vertexArray, int vertexCount) = 0; 70202ddc8b85ace91b15feb329a6a1d5d62b2b846c6bsalomon@google.com virtual void onSetIndexSourceToArray(const void* indexArray, int indexCount) = 0; 70325fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com // subclass is notified that geom source will be set away from an array 70425fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com virtual void releaseVertexArray() = 0; 70525fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com virtual void releaseIndexArray() = 0; 70602ddc8b85ace91b15feb329a6a1d5d62b2b846c6bsalomon@google.com // subclass overrides to be notified just before geo src state is pushed/popped. 70725fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com virtual void geometrySourceWillPush() = 0; 70825fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com virtual void geometrySourceWillPop(const GeometrySrcState& restoredState) = 0; 70925fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com // subclass called to perform drawing 71074749cd45c29b4f5300e2518f2c2c765ce8ae208bsalomon@google.com virtual void onDraw(const DrawInfo&) = 0; 7115f74cf8c49701f514b69dc6f1a8b5c0ffd78af0asugoi@google.com virtual void onStencilPath(const GrPath*, const SkStrokeRec& stroke, SkPath::FillType fill) = 0; 71264aef2bacd1f5c25ffd9347aabd6265c9b60c0f4bsalomon@google.com 713e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com // helpers for reserving vertex and index space. 714b75b0a0b8492e14c7728e0a0881f87dc64ce60f9jvanverth@google.com bool reserveVertexSpace(size_t vertexSize, 715e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com int vertexCount, 716e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com void** vertices); 717e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com bool reserveIndexSpace(int indexCount, void** indices); 718d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com 719e826262939dac3e67cb5ce66d4b9faeb8e2538e6bsalomon@google.com // called by drawIndexed and drawNonIndexed. Use a negative indexCount to 720e826262939dac3e67cb5ce66d4b9faeb8e2538e6bsalomon@google.com // indicate non-indexed drawing. 721e826262939dac3e67cb5ce66d4b9faeb8e2538e6bsalomon@google.com bool checkDraw(GrPrimitiveType type, int startVertex, 722e826262939dac3e67cb5ce66d4b9faeb8e2538e6bsalomon@google.com int startIndex, int vertexCount, 723e826262939dac3e67cb5ce66d4b9faeb8e2538e6bsalomon@google.com int indexCount) const; 72425fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com // called when setting a new vert/idx source to unref prev vb/ib 72525fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com void releasePreviousVertexSource(); 72625fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com void releasePreviousIndexSource(); 727d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com 72826e18b593ab65e4d92dfbce92579d8bc180d4c2cbsalomon@google.com // Makes a copy of the dst if it is necessary for the draw. Returns false if a copy is required 72926e18b593ab65e4d92dfbce92579d8bc180d4c2cbsalomon@google.com // but couldn't be made. Otherwise, returns true. 73026e18b593ab65e4d92dfbce92579d8bc180d4c2cbsalomon@google.com bool setupDstReadIfNecessary(DrawInfo* info); 73126e18b593ab65e4d92dfbce92579d8bc180d4c2cbsalomon@google.com 73225fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com enum { 73325fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com kPreallocGeoSrcStateStackCnt = 4, 734ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com }; 73502ddc8b85ace91b15feb329a6a1d5d62b2b846c6bsalomon@google.com SkSTArray<kPreallocGeoSrcStateStackCnt, GeometrySrcState, true> fGeoSrcStateStack; 73602ddc8b85ace91b15feb329a6a1d5d62b2b846c6bsalomon@google.com const GrClipData* fClip; 73702ddc8b85ace91b15feb329a6a1d5d62b2b846c6bsalomon@google.com GrDrawState* fDrawState; 73802ddc8b85ace91b15feb329a6a1d5d62b2b846c6bsalomon@google.com GrDrawState fDefaultDrawState; 7396e4e65066a7c0dbc9bfbfe4b8f5d49c3d8a79b59bsalomon@google.com // The context owns us, not vice-versa, so this ptr is not ref'ed by DrawTarget. 7406e4e65066a7c0dbc9bfbfe4b8f5d49c3d8a79b59bsalomon@google.com GrContext* fContext; 741fa35e3ddcc9d130ce87c927218bdf27879c38711reed@google.com 742fa35e3ddcc9d130ce87c927218bdf27879c38711reed@google.com typedef GrRefCnt INHERITED; 743ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com}; 744ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 745ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com#endif 746