GrDrawTarget.h revision 8d67c0711b52226db59158a0cfce09f35badd96a
1ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 2ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com/* 3ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Copyright 2010 Google Inc. 4ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * 5ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Use of this source code is governed by a BSD-style license that can be 6ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * found in the LICENSE file. 7ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com */ 8ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 9ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 10ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com 11ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com#ifndef GrDrawTarget_DEFINED 12ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com#define GrDrawTarget_DEFINED 13ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 148d67c0711b52226db59158a0cfce09f35badd96absalomon@google.com#include "GrClipData.h" 159381363050ec9d3e724076a8e9152bfa9a8de1d1tomhudson@google.com#include "GrDrawState.h" 16934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com#include "GrIndexBuffer.h" 17b9086a026844e4cfd08b219e49ce3f12294cba98bsalomon@google.com#include "SkMatrix.h" 18ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com#include "GrRefCnt.h" 19a320194e4242ef0e5e758aea896bfd52bcb3dac7bsalomon@google.com#include "GrTemplates.h" 20ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 218d67c0711b52226db59158a0cfce09f35badd96absalomon@google.com#include "SkClipStack.h" 2212b4e27ae1a29460e91a59f38122483e1faec697sugoi@google.com#include "SkPath.h" 2346f7afb9867200b568c21736da8a8bbb56b20e30bsalomon@google.com#include "SkTLazy.h" 24a2d71482db8b6d752a51c96da74768d7dfc27932robertphillips@google.com#include "SkTArray.h" 258d67c0711b52226db59158a0cfce09f35badd96absalomon@google.com#include "SkXfermode.h" 2697c88c255cff3dbb8343c5d090526fdbedad6dd6Scroggo 27a2d71482db8b6d752a51c96da74768d7dfc27932robertphillips@google.comclass GrClipData; 2864aef2bacd1f5c25ffd9347aabd6265c9b60c0f4bsalomon@google.comclass GrPath; 29ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.comclass GrVertexBuffer; 30ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 3112b4e27ae1a29460e91a59f38122483e1faec697sugoi@google.comclass SkStroke; 3212b4e27ae1a29460e91a59f38122483e1faec697sugoi@google.com 33ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.comclass GrDrawTarget : public GrRefCnt { 34f66018798099750e639a8fa131fece492a050997bsalomon@google.comprotected: 35f66018798099750e639a8fa131fece492a050997bsalomon@google.com /** This helper class allows GrDrawTarget subclasses to set the caps values without having to be 36f66018798099750e639a8fa131fece492a050997bsalomon@google.com made a friend of GrDrawTarget::Caps. */ 37f66018798099750e639a8fa131fece492a050997bsalomon@google.com class CapsInternals { 38f66018798099750e639a8fa131fece492a050997bsalomon@google.com public: 3918c9c198f571997463d9a7134dbd88298e592ec2bsalomon@google.com bool f8BitPaletteSupport : 1; 4018c9c198f571997463d9a7134dbd88298e592ec2bsalomon@google.com bool fNPOTTextureTileSupport : 1; 4118c9c198f571997463d9a7134dbd88298e592ec2bsalomon@google.com bool fTwoSidedStencilSupport : 1; 4218c9c198f571997463d9a7134dbd88298e592ec2bsalomon@google.com bool fStencilWrapOpsSupport : 1; 4318c9c198f571997463d9a7134dbd88298e592ec2bsalomon@google.com bool fHWAALineSupport : 1; 4418c9c198f571997463d9a7134dbd88298e592ec2bsalomon@google.com bool fShaderDerivativeSupport : 1; 45edfe1aac5c6f3a3f3830e86ddea8dbceeb0e6df4bsalomon@google.com bool fGeometryShaderSupport : 1; 4618c9c198f571997463d9a7134dbd88298e592ec2bsalomon@google.com bool fFSAASupport : 1; 4718c9c198f571997463d9a7134dbd88298e592ec2bsalomon@google.com bool fDualSourceBlendingSupport : 1; 4818c9c198f571997463d9a7134dbd88298e592ec2bsalomon@google.com bool fBufferLockSupport : 1; 4964aef2bacd1f5c25ffd9347aabd6265c9b60c0f4bsalomon@google.com bool fPathStencilingSupport : 1; 5018c9c198f571997463d9a7134dbd88298e592ec2bsalomon@google.com int fMaxRenderTargetSize; 5118c9c198f571997463d9a7134dbd88298e592ec2bsalomon@google.com int fMaxTextureSize; 5218c9c198f571997463d9a7134dbd88298e592ec2bsalomon@google.com }; 5318c9c198f571997463d9a7134dbd88298e592ec2bsalomon@google.com 54f66018798099750e639a8fa131fece492a050997bsalomon@google.compublic: 55f66018798099750e639a8fa131fece492a050997bsalomon@google.com SK_DECLARE_INST_COUNT(GrDrawTarget) 56f66018798099750e639a8fa131fece492a050997bsalomon@google.com 57f66018798099750e639a8fa131fece492a050997bsalomon@google.com /** 58f66018798099750e639a8fa131fece492a050997bsalomon@google.com * Represents the draw target capabilities. 59f66018798099750e639a8fa131fece492a050997bsalomon@google.com */ 60f66018798099750e639a8fa131fece492a050997bsalomon@google.com class Caps { 61f66018798099750e639a8fa131fece492a050997bsalomon@google.com public: 62f66018798099750e639a8fa131fece492a050997bsalomon@google.com Caps() { memset(this, 0, sizeof(Caps)); } 63f66018798099750e639a8fa131fece492a050997bsalomon@google.com Caps(const Caps& c) { *this = c; } 64f66018798099750e639a8fa131fece492a050997bsalomon@google.com Caps& operator= (const Caps& c) { 65f66018798099750e639a8fa131fece492a050997bsalomon@google.com memcpy(this, &c, sizeof(Caps)); 66f66018798099750e639a8fa131fece492a050997bsalomon@google.com return *this; 67f66018798099750e639a8fa131fece492a050997bsalomon@google.com } 68f66018798099750e639a8fa131fece492a050997bsalomon@google.com void print() const; 69f66018798099750e639a8fa131fece492a050997bsalomon@google.com 70f66018798099750e639a8fa131fece492a050997bsalomon@google.com bool eightBitPaletteSupport() const { return fInternals.f8BitPaletteSupport; } 71f66018798099750e639a8fa131fece492a050997bsalomon@google.com bool npotTextureTileSupport() const { return fInternals.fNPOTTextureTileSupport; } 72f66018798099750e639a8fa131fece492a050997bsalomon@google.com bool twoSidedStencilSupport() const { return fInternals.fTwoSidedStencilSupport; } 73f66018798099750e639a8fa131fece492a050997bsalomon@google.com bool stencilWrapOpsSupport() const { return fInternals.fStencilWrapOpsSupport; } 74f66018798099750e639a8fa131fece492a050997bsalomon@google.com bool hwAALineSupport() const { return fInternals.fHWAALineSupport; } 75f66018798099750e639a8fa131fece492a050997bsalomon@google.com bool shaderDerivativeSupport() const { return fInternals.fShaderDerivativeSupport; } 76f66018798099750e639a8fa131fece492a050997bsalomon@google.com bool geometryShaderSupport() const { return fInternals.fGeometryShaderSupport; } 77f66018798099750e639a8fa131fece492a050997bsalomon@google.com bool fsaaSupport() const { return fInternals.fFSAASupport; } 78f66018798099750e639a8fa131fece492a050997bsalomon@google.com bool dualSourceBlendingSupport() const { return fInternals.fDualSourceBlendingSupport; } 79f66018798099750e639a8fa131fece492a050997bsalomon@google.com bool bufferLockSupport() const { return fInternals.fBufferLockSupport; } 80f66018798099750e639a8fa131fece492a050997bsalomon@google.com bool pathStencilingSupport() const { return fInternals.fPathStencilingSupport; } 81f66018798099750e639a8fa131fece492a050997bsalomon@google.com 82f66018798099750e639a8fa131fece492a050997bsalomon@google.com int maxRenderTargetSize() const { return fInternals.fMaxRenderTargetSize; } 83f66018798099750e639a8fa131fece492a050997bsalomon@google.com int maxTextureSize() const { return fInternals.fMaxTextureSize; } 84f66018798099750e639a8fa131fece492a050997bsalomon@google.com private: 85f66018798099750e639a8fa131fece492a050997bsalomon@google.com CapsInternals fInternals; 860d82fe5a4be4aef5b9ce7ca6f4864b72c73452a9bsalomon@google.com friend class GrDrawTarget; // to set values of fInternals 87f66018798099750e639a8fa131fece492a050997bsalomon@google.com }; 88f66018798099750e639a8fa131fece492a050997bsalomon@google.com 89ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com /////////////////////////////////////////////////////////////////////////// 90ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 91ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com GrDrawTarget(); 9225fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com virtual ~GrDrawTarget(); 93ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 94ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com /** 9518c9c198f571997463d9a7134dbd88298e592ec2bsalomon@google.com * Gets the capabilities of the draw target. 9618c9c198f571997463d9a7134dbd88298e592ec2bsalomon@google.com */ 9718c9c198f571997463d9a7134dbd88298e592ec2bsalomon@google.com const Caps& getCaps() const { return fCaps; } 9818c9c198f571997463d9a7134dbd88298e592ec2bsalomon@google.com 9918c9c198f571997463d9a7134dbd88298e592ec2bsalomon@google.com /** 100ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * Sets the current clip to the region specified by clip. All draws will be 101ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * clipped against this clip if kClip_StateBit is enabled. 102ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * 1035aaa69e4339e229adfb05e96084a8ec0a590238bbsalomon@google.com * Setting the clip may (or may not) zero out the client's stencil bits. 1045aaa69e4339e229adfb05e96084a8ec0a590238bbsalomon@google.com * 105ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * @param description of the clipping region 106ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com */ 107beb1af78d016d2700c350487a383c6bcfa7e2e20robertphillips@google.com void setClip(const GrClipData* clip); 108ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 109ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com /** 110ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * Gets the current clip. 111ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * 112ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * @return the clip. 113ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com */ 114beb1af78d016d2700c350487a383c6bcfa7e2e20robertphillips@google.com const GrClipData* getClip() const; 115ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 116a5d056ae0b04021dfb44c2c7a3d6a34e060261b8bsalomon@google.com /** 117a5d056ae0b04021dfb44c2c7a3d6a34e060261b8bsalomon@google.com * Sets the draw state object for the draw target. Note that this does not 118a5d056ae0b04021dfb44c2c7a3d6a34e060261b8bsalomon@google.com * make a copy. The GrDrawTarget will take a reference to passed object. 119a5d056ae0b04021dfb44c2c7a3d6a34e060261b8bsalomon@google.com * Passing NULL will cause the GrDrawTarget to use its own internal draw 120a5d056ae0b04021dfb44c2c7a3d6a34e060261b8bsalomon@google.com * state object rather than an externally provided one. 121a5d056ae0b04021dfb44c2c7a3d6a34e060261b8bsalomon@google.com */ 122a5d056ae0b04021dfb44c2c7a3d6a34e060261b8bsalomon@google.com void setDrawState(GrDrawState* drawState); 123a5d056ae0b04021dfb44c2c7a3d6a34e060261b8bsalomon@google.com 124a5d056ae0b04021dfb44c2c7a3d6a34e060261b8bsalomon@google.com /** 125a5d056ae0b04021dfb44c2c7a3d6a34e060261b8bsalomon@google.com * Read-only access to the GrDrawTarget's current draw state. 126a5d056ae0b04021dfb44c2c7a3d6a34e060261b8bsalomon@google.com */ 127a5d056ae0b04021dfb44c2c7a3d6a34e060261b8bsalomon@google.com const GrDrawState& getDrawState() const { return *fDrawState; } 128a5d056ae0b04021dfb44c2c7a3d6a34e060261b8bsalomon@google.com 129a5d056ae0b04021dfb44c2c7a3d6a34e060261b8bsalomon@google.com /** 130a5d056ae0b04021dfb44c2c7a3d6a34e060261b8bsalomon@google.com * Read-write access to the GrDrawTarget's current draw state. Note that 131a5d056ae0b04021dfb44c2c7a3d6a34e060261b8bsalomon@google.com * this doesn't ref. 132a5d056ae0b04021dfb44c2c7a3d6a34e060261b8bsalomon@google.com */ 133a5d056ae0b04021dfb44c2c7a3d6a34e060261b8bsalomon@google.com GrDrawState* drawState() { return fDrawState; } 1343d0835b6ac0003c18147b6e9ca76a497b92d1d40bsalomon@google.com 1353d0835b6ac0003c18147b6e9ca76a497b92d1d40bsalomon@google.com /** 136a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com * Color alpha and coverage are two inputs to the drawing pipeline. For some 137a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com * blend modes it is safe to fold the coverage into constant or per-vertex 138a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com * color alpha value. For other blend modes they must be handled separately. 139a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com * Depending on features available in the underlying 3D API this may or may 140a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com * not be possible. 141a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com * 142e79c815bca39fa552983b7a8107219aa5084acdbbsalomon@google.com * This function considers the current draw state and the draw target's 143e79c815bca39fa552983b7a8107219aa5084acdbbsalomon@google.com * capabilities to determine whether coverage can be handled correctly. The 144e79c815bca39fa552983b7a8107219aa5084acdbbsalomon@google.com * following assumptions are made: 145e79c815bca39fa552983b7a8107219aa5084acdbbsalomon@google.com * 1. The caller intends to somehow specify coverage. This can be 146e79c815bca39fa552983b7a8107219aa5084acdbbsalomon@google.com * specified either by enabling a coverage stage on the GrDrawState or 147e79c815bca39fa552983b7a8107219aa5084acdbbsalomon@google.com * via the vertex layout. 148d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com * 2. Other than enabling coverage stages, the current configuration of 149e79c815bca39fa552983b7a8107219aa5084acdbbsalomon@google.com * the target's GrDrawState is as it will be at draw time. 150e79c815bca39fa552983b7a8107219aa5084acdbbsalomon@google.com * 3. If a vertex source has not yet been specified then all stages with 151e79c815bca39fa552983b7a8107219aa5084acdbbsalomon@google.com * non-NULL textures will be referenced by the vertex layout. 152a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com */ 153a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com bool canApplyCoverage() const; 154a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com 155a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com /** 156a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com * Determines whether incorporating partial pixel coverage into the constant 157a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com * color specified by setColor or per-vertex colors will give the right 158e79c815bca39fa552983b7a8107219aa5084acdbbsalomon@google.com * blending result. If a vertex source has not yet been specified then 159e79c815bca39fa552983b7a8107219aa5084acdbbsalomon@google.com * the function assumes that all stages with non-NULL textures will be 160e79c815bca39fa552983b7a8107219aa5084acdbbsalomon@google.com * referenced by the vertex layout. 161a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com */ 16286c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com bool canTweakAlphaForCoverage() const; 163a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com 164a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com /** 165d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com * Given the current draw state and hw support, will HW AA lines be used 166e79c815bca39fa552983b7a8107219aa5084acdbbsalomon@google.com * (if line primitive type is drawn)? If a vertex source has not yet been 167e79c815bca39fa552983b7a8107219aa5084acdbbsalomon@google.com * specified then the function assumes that all stages with non-NULL 168e79c815bca39fa552983b7a8107219aa5084acdbbsalomon@google.com * textures will be referenced by the vertex layout. 169a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com */ 1709381363050ec9d3e724076a8e9152bfa9a8de1d1tomhudson@google.com bool willUseHWAALines() const; 171a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com 1723d0835b6ac0003c18147b6e9ca76a497b92d1d40bsalomon@google.com /** 1738531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com * The format of vertices is represented as a bitfield of flags. 1748531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com * Flags that indicate the layout of vertex data. Vertices always contain 1759381363050ec9d3e724076a8e9152bfa9a8de1d1tomhudson@google.com * positions and may also contain up to GrDrawState::kMaxTexCoords sets 176b213ed8b767b424cb076bfbab11e936d16526635tomhudson@google.com * of 2D texture coordinates, per-vertex colors, and per-vertex coverage. 177d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com * Each stage can 178a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com * use any of the texture coordinates as its input texture coordinates or it 179a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com * may use the positions as texture coordinates. 1808531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com * 1818531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com * If no texture coordinates are specified for a stage then the stage is 1828531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com * disabled. 183ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * 1848531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com * Only one type of texture coord can be specified per stage. For 1855782d712ffc31557d0cb12d5a220cebb783f6895bsalomon@google.com * example StageTexCoordVertexLayoutBit(0, 2) and 1868531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com * StagePosAsTexCoordVertexLayoutBit(0) cannot both be specified. 187ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * 188d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com * The order in memory is always (position, texture coord 0, ..., color, 189d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com * coverage) with any unused fields omitted. Note that this means that if 190a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com * only texture coordinates 1 is referenced then there is no texture 191a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com * coordinates 0 and the order would be (position, texture coordinate 1 192a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com * [, color][, coverage]). 1938531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com */ 1945782d712ffc31557d0cb12d5a220cebb783f6895bsalomon@google.com 1958531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com /** 1968531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com * Generates a bit indicating that a texture stage uses texture coordinates 1975782d712ffc31557d0cb12d5a220cebb783f6895bsalomon@google.com * 19808283afc265f1153834256fc1012519813ba6b73bsalomon@google.com * @param stageIdx the stage that will use texture coordinates. 1998531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com * @param texCoordIdx the index of the texture coordinates to use 200ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * 2018531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com * @return the bit to add to a GrVertexLayout bitfield. 2028531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com */ 20308283afc265f1153834256fc1012519813ba6b73bsalomon@google.com static int StageTexCoordVertexLayoutBit(int stageIdx, int texCoordIdx) { 20408283afc265f1153834256fc1012519813ba6b73bsalomon@google.com GrAssert(stageIdx < GrDrawState::kNumStages); 2059381363050ec9d3e724076a8e9152bfa9a8de1d1tomhudson@google.com GrAssert(texCoordIdx < GrDrawState::kMaxTexCoords); 20608283afc265f1153834256fc1012519813ba6b73bsalomon@google.com return 1 << (stageIdx + (texCoordIdx * GrDrawState::kNumStages)); 2078531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com } 20886afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com 20908283afc265f1153834256fc1012519813ba6b73bsalomon@google.com static bool StageUsesTexCoords(GrVertexLayout layout, int stageIdx); 210b213ed8b767b424cb076bfbab11e936d16526635tomhudson@google.com 2118531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.comprivate: 21252544c7cb6e8261e3e67f897def9a9f81c0b7c45bsalomon@google.com // non-stage bits start at this index. 21352544c7cb6e8261e3e67f897def9a9f81c0b7c45bsalomon@google.com static const int STAGE_BIT_CNT = GrDrawState::kNumStages * 21452544c7cb6e8261e3e67f897def9a9f81c0b7c45bsalomon@google.com GrDrawState::kMaxTexCoords; 2158531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.compublic: 2165782d712ffc31557d0cb12d5a220cebb783f6895bsalomon@google.com 2178531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com /** 2188531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com * Additional Bits that can be specified in GrVertexLayout. 219ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com */ 220ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com enum VertexLayoutBits { 221a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com /* vertices have colors (GrColor) */ 2228531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com kColor_VertexLayoutBit = 1 << (STAGE_BIT_CNT + 0), 2232401ae8fd3c1f6282f571b5a7e0a499e9f4c09abbsalomon@google.com /* vertices have coverage (GrColor) 224e10f6fdf76fa9b627cbb8471b58b13c457af83e8bsalomon@google.com */ 225a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com kCoverage_VertexLayoutBit = 1 << (STAGE_BIT_CNT + 1), 226aeb2160b1dd34f8e640e8e56544fe407d4ff6311bsalomon@google.com /* Use text vertices. (Pos and tex coords may be a different type for 227e10f6fdf76fa9b627cbb8471b58b13c457af83e8bsalomon@google.com * text [GrGpuTextVertex vs GrPoint].) 228e10f6fdf76fa9b627cbb8471b58b13c457af83e8bsalomon@google.com */ 229a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com kTextFormat_VertexLayoutBit = 1 << (STAGE_BIT_CNT + 2), 230aeb2160b1dd34f8e640e8e56544fe407d4ff6311bsalomon@google.com 231e10f6fdf76fa9b627cbb8471b58b13c457af83e8bsalomon@google.com /* Each vertex specificies an edge. Distance to the edge is used to 232cff56083942a9784331aa2fd62ddf806cccc31cbbsalomon@google.com * compute a coverage. See GrDrawState::setVertexEdgeType(). 233e10f6fdf76fa9b627cbb8471b58b13c457af83e8bsalomon@google.com */ 234a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com kEdge_VertexLayoutBit = 1 << (STAGE_BIT_CNT + 3), 235ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com // for below assert 236d302f1401b3c9aea094804bad4e76de98782cfe8bsalomon@google.com kDummyVertexLayoutBit, 237d302f1401b3c9aea094804bad4e76de98782cfe8bsalomon@google.com kHighVertexLayoutBit = kDummyVertexLayoutBit - 1 238ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com }; 2398531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com // make sure we haven't exceeded the number of bits in GrVertexLayout. 2404be283f3a82895530d1b70372cd48ddb1c663fd8bsalomon@google.com GR_STATIC_ASSERT(kHighVertexLayoutBit < ((uint64_t)1 << 8*sizeof(GrVertexLayout))); 241ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 242ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com /** 243e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com * There are three types of "sources" of geometry (vertices and indices) for 244e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com * draw calls made on the target. When performing an indexed draw, the 245e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com * indices and vertices can use different source types. Once a source is 246934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com * specified it can be used for multiple draws. However, the time at which 247934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com * the geometry data is no longer editable depends on the source type. 24825fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * 24925fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * Sometimes it is necessary to perform a draw while upstack code has 250e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com * already specified geometry that it isn't finished with. So there are push 251e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com * and pop methods. This allows the client to push the sources, draw 252e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com * something using alternate sources, and then pop to restore the original 253e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com * sources. 254e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com * 255e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com * Aside from pushes and pops, a source remains valid until another source 256e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com * is set or resetVertexSource / resetIndexSource is called. Drawing from 257e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com * a reset source is an error. 258e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com * 259e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com * The three types of sources are: 2601c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com * 261e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com * 1. A cpu array (set*SourceToArray). This is useful when the caller 262e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com * already provided vertex data in a format compatible with a 263e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com * GrVertexLayout. The data in the array is consumed at the time that 264e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com * set*SourceToArray is called and subsequent edits to the array will not 265e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com * be reflected in draws. 2661c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com * 26725fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * 2. Reserve. This is most useful when the caller has data it must 26825fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * transform before drawing and is not long-lived. The caller requests 26925fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * that the draw target make room for some amount of vertex and/or index 27025fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * data. The target provides ptrs to hold the vertex and/or index data. 27125fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * 272d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com * The data is writable up until the next drawIndexed, drawNonIndexed, 273934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com * drawIndexedInstances, or pushGeometrySource. At this point the data is 274934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com * frozen and the ptrs are no longer valid. 2751c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com * 276e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com * Where the space is allocated and how it is uploaded to the GPU is 277e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com * subclass-dependent. 278e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com * 2791c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com * 3. Vertex and Index Buffers. This is most useful for geometry that will 280e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com * is long-lived. When the data in the buffer is consumed depends on the 281d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com * GrDrawTarget subclass. For deferred subclasses the caller has to 282e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com * guarantee that the data is still available in the buffers at playback. 283e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com * (TODO: Make this more automatic as we have done for read/write pixels) 2841c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com */ 2851c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com 2861c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com /** 287e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com * Reserves space for vertices and/or indices. Zero can be specifed as 288e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com * either the vertex or index count if the caller desires to only reserve 289d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com * space for only indices or only vertices. If zero is specifed for 290e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com * vertexCount then the vertex source will be unmodified and likewise for 291e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com * indexCount. 292ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * 293e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com * If the function returns true then the reserve suceeded and the vertices 294e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com * and indices pointers will point to the space created. 295ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * 296e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com * If the target cannot make space for the request then this function will 297e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com * return false. If vertexCount was non-zero then upon failure the vertex 298e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com * source is reset and likewise for indexCount. 299ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * 300e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com * The pointers to the space allocated for vertices and indices remain valid 301934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com * until a drawIndexed, drawNonIndexed, drawIndexedInstances, or push/ 302934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com * popGeomtrySource is called. At that point logically a snapshot of the 303934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com * data is made and the pointers are invalid. 3041c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com * 305ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * @param vertexLayout the format of vertices (ignored if vertexCount == 0). 306e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com * @param vertexCount the number of vertices to reserve space for. Can be 307e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com * 0. 30825fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * @param indexCount the number of indices to reserve space for. Can be 0. 309e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com * @param vertices will point to reserved vertex space if vertexCount is 310d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com * non-zero. Illegal to pass NULL if vertexCount > 0. 31125fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * @param indices will point to reserved index space if indexCount is 31225fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * non-zero. Illegal to pass NULL if indexCount > 0. 31325fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com */ 31497805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com bool reserveVertexAndIndexSpace(GrVertexLayout vertexLayout, 31597805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com int vertexCount, 31697805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com int indexCount, 31797805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com void** vertices, 31897805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com void** indices); 31925fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com 320ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com /** 321ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * Provides hints to caller about the number of vertices and indices 322ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * that can be allocated cheaply. This can be useful if caller is reserving 323ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * space but doesn't know exactly how much geometry is needed. 324ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * 325ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * Also may hint whether the draw target should be flushed first. This is 326ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * useful for deferred targets. 327ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * 328ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * @param vertexLayout layout of vertices caller would like to reserve 329ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * @param vertexCount in: hint about how many vertices the caller would 330ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * like to allocate. 331ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * out: a hint about the number of vertices that can be 332ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * allocated cheaply. Negative means no hint. 333ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * Ignored if NULL. 334ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * @param indexCount in: hint about how many indices the caller would 335ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * like to allocate. 336ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * out: a hint about the number of indices that can be 337ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * allocated cheaply. Negative means no hint. 338ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * Ignored if NULL. 339ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * 340ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * @return true if target should be flushed based on the input values. 341ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com */ 342ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com virtual bool geometryHints(GrVertexLayout vertexLayout, 3431c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com int* vertexCount, 3441c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com int* indexCount) const; 345ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 346ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com /** 3471c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com * Sets source of vertex data for the next draw. Array must contain 3481c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com * the vertex data when this is called. 349ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * 350ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * @param array cpu array containing vertex data. 3511c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com * @param size size of the vertex data. 3521c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com * @param vertexCount the number of vertices in the array. 353ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com */ 3541c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com void setVertexSourceToArray(GrVertexLayout vertexLayout, 3551c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com const void* vertexArray, 3561c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com int vertexCount); 357ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 358ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com /** 3591c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com * Sets source of index data for the next indexed draw. Array must contain 3601c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com * the indices when this is called. 361ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * 3621c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com * @param array cpu array containing index data. 3631c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com * @param indexCount the number of indices in the array. 364ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com */ 3651c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com void setIndexSourceToArray(const void* indexArray, int indexCount); 366ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 367ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com /** 368ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * Sets source of vertex data for the next draw. Data does not have to be 369934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com * in the buffer until drawIndexed, drawNonIndexed, or drawIndexedInstances. 370ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * 371ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * @param buffer vertex buffer containing vertex data. Must be 372ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * unlocked before draw call. 373ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * @param vertexLayout layout of the vertex data in the buffer. 374ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com */ 3751c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com void setVertexSourceToBuffer(GrVertexLayout vertexLayout, 3761c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com const GrVertexBuffer* buffer); 377ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 378ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com /** 379ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * Sets source of index data for the next indexed draw. Data does not have 380934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com * to be in the buffer until drawIndexed. 381ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * 382ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * @param buffer index buffer containing indices. Must be unlocked 383ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * before indexed draw call. 384ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com */ 385ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com void setIndexSourceToBuffer(const GrIndexBuffer* buffer); 386d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com 38725fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com /** 38825fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * Resets vertex source. Drawing from reset vertices is illegal. Set vertex 38925fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * source to reserved, array, or buffer before next draw. May be able to free 39025fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * up temporary storage allocated by setVertexSourceToArray or 39125fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * reserveVertexSpace. 39225fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com */ 39325fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com void resetVertexSource(); 394d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com 39525fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com /** 39625fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * Resets index source. Indexed Drawing from reset indices is illegal. Set 39725fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * index source to reserved, array, or buffer before next indexed draw. May 39825fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * be able to free up temporary storage allocated by setIndexSourceToArray 39925fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * or reserveIndexSpace. 40025fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com */ 40197805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com void resetIndexSource(); 402d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com 40397805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com /** 40497805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com * Query to find out if the vertex or index source is reserved. 40597805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com */ 40697805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com bool hasReservedVerticesOrIndices() const { 40773d98aace4f74acc39d8de33484c8aec8e917739bsalomon@google.com return kReserved_GeometrySrcType == this->getGeomSrc().fVertexSrc || 40897805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com kReserved_GeometrySrcType == this->getGeomSrc().fIndexSrc; 40997805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com } 410ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 411ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com /** 41225fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * Pushes and resets the vertex/index sources. Any reserved vertex / index 41325fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * data is finalized (i.e. cannot be updated after the matching pop but can 41425fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * be drawn from). Must be balanced by a pop. 41525fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com */ 41625fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com void pushGeometrySource(); 41725fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com 41825fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com /** 41925fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * Pops the vertex / index sources from the matching push. 42025fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com */ 42125fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com void popGeometrySource(); 42264aef2bacd1f5c25ffd9347aabd6265c9b60c0f4bsalomon@google.com 42325fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com /** 424ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * Draws indexed geometry using the current state and current vertex / index 425ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * sources. 426ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * 427ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * @param type The type of primitives to draw. 428ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * @param startVertex the vertex in the vertex array/buffer corresponding 429ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * to index 0 430ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * @param startIndex first index to read from index src. 431ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * @param vertexCount one greater than the max index. 432ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * @param indexCount the number of index elements to read. The index count 433ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * is effectively trimmed to the last completely 434ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * specified primitive. 435ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com */ 43625fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com void drawIndexed(GrPrimitiveType type, 43725fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com int startVertex, 43825fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com int startIndex, 43925fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com int vertexCount, 44025fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com int indexCount); 441ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 442ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com /** 443ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * Draws non-indexed geometry using the current state and current vertex 444ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * sources. 445ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * 446ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * @param type The type of primitives to draw. 447ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * @param startVertex the vertex in the vertex array/buffer corresponding 448ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * to index 0 449ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * @param vertexCount one greater than the max index. 450ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com */ 45125fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com void drawNonIndexed(GrPrimitiveType type, 45225fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com int startVertex, 45325fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com int vertexCount); 454ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 45586afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com /** 45664aef2bacd1f5c25ffd9347aabd6265c9b60c0f4bsalomon@google.com * Draws path into the stencil buffer. The fill must be either even/odd or 45764aef2bacd1f5c25ffd9347aabd6265c9b60c0f4bsalomon@google.com * winding (not inverse or hairline). It will respect the HW antialias flag 45864aef2bacd1f5c25ffd9347aabd6265c9b60c0f4bsalomon@google.com * on the draw state (if possible in the 3D API). 45964aef2bacd1f5c25ffd9347aabd6265c9b60c0f4bsalomon@google.com */ 46012b4e27ae1a29460e91a59f38122483e1faec697sugoi@google.com void stencilPath(const GrPath*, const SkStroke& stroke, SkPath::FillType fill); 46164aef2bacd1f5c25ffd9347aabd6265c9b60c0f4bsalomon@google.com 46264aef2bacd1f5c25ffd9347aabd6265c9b60c0f4bsalomon@google.com /** 46386afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com * Helper function for drawing rects. This does not use the current index 46486afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com * and vertex sources. After returning, the vertex and index sources may 46586afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com * have changed. They should be reestablished before the next drawIndexed 46686afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com * or drawNonIndexed. This cannot be called between reserving and releasing 46786afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com * geometry. The GrDrawTarget subclass may be able to perform additional 468d302f1401b3c9aea094804bad4e76de98782cfe8bsalomon@google.com * optimizations if drawRect is used rather than drawIndexed or 46986afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com * drawNonIndexed. 47086afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com * @param rect the rect to draw 47186afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com * @param matrix optional matrix applied to rect (before viewMatrix) 47286afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com * @param srcRects specifies rects for stages enabled by stageEnableMask. 47386afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com * if stageEnableMask bit i is 1, srcRects is not NULL, 47486afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com * and srcRects[i] is not NULL, then srcRects[i] will be 47586afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com * used as coordinates for stage i. Otherwise, if stage i 47686afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com * is enabled then rect is used as the coordinates. 47786afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com * @param srcMatrices optional matrices applied to srcRects. If 47886afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com * srcRect[i] is non-NULL and srcMatrices[i] is 47986afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com * non-NULL then srcRect[i] will be transformed by 48086afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com * srcMatrix[i]. srcMatrices can be NULL when no 48186afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com * srcMatrices are desired. 48286afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com */ 483d302f1401b3c9aea094804bad4e76de98782cfe8bsalomon@google.com virtual void drawRect(const GrRect& rect, 484b9086a026844e4cfd08b219e49ce3f12294cba98bsalomon@google.com const SkMatrix* matrix, 48586afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com const GrRect* srcRects[], 486b9086a026844e4cfd08b219e49ce3f12294cba98bsalomon@google.com const SkMatrix* srcMatrices[]); 487cf939ae54842fc7408ee68a41427086962b4c3dcbsalomon@google.com /** 488cf939ae54842fc7408ee68a41427086962b4c3dcbsalomon@google.com * Helper for drawRect when the caller doesn't need separate src rects or 489cf939ae54842fc7408ee68a41427086962b4c3dcbsalomon@google.com * matrices. 490cf939ae54842fc7408ee68a41427086962b4c3dcbsalomon@google.com */ 491cf939ae54842fc7408ee68a41427086962b4c3dcbsalomon@google.com void drawSimpleRect(const GrRect& rect, const SkMatrix* matrix = NULL) { 492cf939ae54842fc7408ee68a41427086962b4c3dcbsalomon@google.com drawRect(rect, matrix, NULL, NULL); 493cf939ae54842fc7408ee68a41427086962b4c3dcbsalomon@google.com } 494cf939ae54842fc7408ee68a41427086962b4c3dcbsalomon@google.com void drawSimpleRect(const GrIRect& irect, const SkMatrix* matrix = NULL) { 495cf939ae54842fc7408ee68a41427086962b4c3dcbsalomon@google.com SkRect rect = SkRect::MakeFromIRect(irect); 496cf939ae54842fc7408ee68a41427086962b4c3dcbsalomon@google.com this->drawRect(rect, matrix, NULL, NULL); 497cf939ae54842fc7408ee68a41427086962b4c3dcbsalomon@google.com } 49886afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com 499cf939ae54842fc7408ee68a41427086962b4c3dcbsalomon@google.com 50086afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com /** 501934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com * This call is used to draw multiple instances of some geometry with a 502934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com * given number of vertices (V) and indices (I) per-instance. The indices in 503934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com * the index source must have the form i[k+I] == i[k] + V. Also, all indices 504934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com * i[kI] ... i[(k+1)I-1] must be elements of the range kV ... (k+1)V-1. As a 505934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com * concrete example, the following index buffer for drawing a series of 506934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com * quads each as two triangles each satisfies these conditions with V=4 and 507934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com * I=6: 508934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com * (0,1,2,0,2,3, 4,5,6,4,6,7, 8,9,10,8,10,11, ...) 509934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com * 510934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com * The call assumes that the pattern of indices fills the entire index 511934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com * source. The size of the index buffer limits the number of instances that 512934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com * can be drawn by the GPU in a single draw. However, the caller may specify 513934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com * any (positive) number for instanceCount and if necessary multiple GPU 514934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com * draws will be issued. Morever, when drawIndexedInstances is called 515934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com * multiple times it may be possible for GrDrawTarget to group them into a 516934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com * single GPU draw. 517934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com * 518934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com * @param type the type of primitives to draw 519934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com * @param instanceCount the number of instances to draw. Each instance 520934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com * consists of verticesPerInstance vertices indexed by 521934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com * indicesPerInstance indices drawn as the primitive 522934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com * type specified by type. 523934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com * @param verticesPerInstance The number of vertices in each instance (V 524934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com * in the above description). 525934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com * @param indicesPerInstance The number of indices in each instance (I 526934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com * in the above description). 527934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com */ 528934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com virtual void drawIndexedInstances(GrPrimitiveType type, 529934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com int instanceCount, 530934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com int verticesPerInstance, 531934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com int indicesPerInstance); 532934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com 533934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com /** 534d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com * Clear the current render target if one isn't passed in. Ignores the 535d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com * clip and all other draw state (blend mode, stages, etc). Clears the 536c82a8b7aa4ec19fba508c394920a9e88d3e5bd12robertphillips@google.com * whole thing if rect is NULL, otherwise just the rect. 5370b335c1ac100aeacf79a4c98a052286fd46661e7bsalomon@google.com */ 538d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com virtual void clear(const GrIRect* rect, 539c82a8b7aa4ec19fba508c394920a9e88d3e5bd12robertphillips@google.com GrColor color, 540c82a8b7aa4ec19fba508c394920a9e88d3e5bd12robertphillips@google.com GrRenderTarget* renderTarget = NULL) = 0; 5410b335c1ac100aeacf79a4c98a052286fd46661e7bsalomon@google.com 542ff17584e1c15f68ccc296be517e8a6776a9ddabdrobertphillips@google.com /** 543ff17584e1c15f68ccc296be517e8a6776a9ddabdrobertphillips@google.com * Release any resources that are cached but not currently in use. This 544ff17584e1c15f68ccc296be517e8a6776a9ddabdrobertphillips@google.com * is intended to give an application some recourse when resources are low. 545ff17584e1c15f68ccc296be517e8a6776a9ddabdrobertphillips@google.com */ 546ff17584e1c15f68ccc296be517e8a6776a9ddabdrobertphillips@google.com virtual void purgeResources() {}; 547ff17584e1c15f68ccc296be517e8a6776a9ddabdrobertphillips@google.com 54825fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com //////////////////////////////////////////////////////////////////////////// 549ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 550873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com /** 551873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com * See AutoStateRestore below. 552873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com */ 553873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com enum ASRInit { 554873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com kPreserve_ASRInit, 555873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com kReset_ASRInit 556873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com }; 557873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com 558873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com /** 559873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com * Saves off the current state and restores it in the destructor. It will 560873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com * install a new GrDrawState object on the target (setDrawState) and restore 561873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com * the previous one in the destructor. The caller should call drawState() to 562873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com * get the new draw state after the ASR is installed. 563873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com * 564873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com * GrDrawState* state = target->drawState(); 565873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com * AutoStateRestore asr(target, GrDrawTarget::kReset_ASRInit). 566873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com * state->setRenderTarget(rt); // state refers to the GrDrawState set on 567873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com * // target before asr was initialized. 568873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com * // Therefore, rt is set on the GrDrawState 569873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com * // that will be restored after asr's 570873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com * // destructor rather than target's current 571d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com * // GrDrawState. 572873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com */ 573ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com class AutoStateRestore : ::GrNoncopyable { 574ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com public: 575873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com /** 576873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com * Default ASR will have no effect unless set() is subsequently called. 577873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com */ 57806afe7b5a1ef03bfc6494c51ab2a1f7a386de5c2bsalomon@google.com AutoStateRestore(); 579873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com 580873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com /** 581873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com * Saves the state on target. The state will be restored when the ASR 582873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com * is destroyed. If this constructor is used do not call set(). 583873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com * 584873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com * @param init Should the newly installed GrDrawState be a copy of the 585873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com * previous state or a default-initialized GrDrawState. 586873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com */ 587873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com AutoStateRestore(GrDrawTarget* target, ASRInit init); 588873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com 589ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com ~AutoStateRestore(); 590ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 59106afe7b5a1ef03bfc6494c51ab2a1f7a386de5c2bsalomon@google.com /** 592873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com * Saves the state on target. The state will be restored when the ASR 593873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com * is destroyed. This should only be called once per ASR object and only 594873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com * when the default constructor was used. For nested saves use multiple 595873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com * ASR objects. 596873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com * 597873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com * @param init Should the newly installed GrDrawState be a copy of the 598873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com * previous state or a default-initialized GrDrawState. 59906afe7b5a1ef03bfc6494c51ab2a1f7a386de5c2bsalomon@google.com */ 600873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com void set(GrDrawTarget* target, ASRInit init); 60106afe7b5a1ef03bfc6494c51ab2a1f7a386de5c2bsalomon@google.com 602ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com private: 603873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com GrDrawTarget* fDrawTarget; 604873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com SkTLazy<GrDrawState> fTempState; 605873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com GrDrawState* fSavedState; 606ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com }; 607ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 60825fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com //////////////////////////////////////////////////////////////////////////// 6091c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com 610ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com class AutoReleaseGeometry : ::GrNoncopyable { 611ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com public: 612ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com AutoReleaseGeometry(GrDrawTarget* target, 613ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com GrVertexLayout vertexLayout, 61425fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com int vertexCount, 61525fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com int indexCount); 61625fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com AutoReleaseGeometry(); 61725fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com ~AutoReleaseGeometry(); 6185782d712ffc31557d0cb12d5a220cebb783f6895bsalomon@google.com bool set(GrDrawTarget* target, 6195782d712ffc31557d0cb12d5a220cebb783f6895bsalomon@google.com GrVertexLayout vertexLayout, 62025fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com int vertexCount, 62125fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com int indexCount); 622a47a48dca5045d71cbc5de343404045209a13e15bsalomon@google.com bool succeeded() const { return NULL != fTarget; } 6236513cd06ae34f5d777b3aaea0b4533014d0a10f2bsalomon@google.com void* vertices() const { GrAssert(this->succeeded()); return fVertices; } 6246513cd06ae34f5d777b3aaea0b4533014d0a10f2bsalomon@google.com void* indices() const { GrAssert(this->succeeded()); return fIndices; } 625ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com GrPoint* positions() const { 6266513cd06ae34f5d777b3aaea0b4533014d0a10f2bsalomon@google.com return static_cast<GrPoint*>(this->vertices()); 627ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com } 628ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 629ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com private: 63025fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com void reset(); 631d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com 632ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com GrDrawTarget* fTarget; 633ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com void* fVertices; 634ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com void* fIndices; 635ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com }; 636ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 63725fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com //////////////////////////////////////////////////////////////////////////// 638ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 639ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com class AutoClipRestore : ::GrNoncopyable { 640ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com public: 641ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com AutoClipRestore(GrDrawTarget* target) { 642ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com fTarget = target; 643ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com fClip = fTarget->getClip(); 644ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com } 645ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 6468d67c0711b52226db59158a0cfce09f35badd96absalomon@google.com AutoClipRestore(GrDrawTarget* target, const SkIRect& newClip); 6478d67c0711b52226db59158a0cfce09f35badd96absalomon@google.com 648ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com ~AutoClipRestore() { 649ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com fTarget->setClip(fClip); 650ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com } 651ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com private: 6528d67c0711b52226db59158a0cfce09f35badd96absalomon@google.com GrDrawTarget* fTarget; 6538d67c0711b52226db59158a0cfce09f35badd96absalomon@google.com const GrClipData* fClip; 6548d67c0711b52226db59158a0cfce09f35badd96absalomon@google.com SkTLazy<SkClipStack> fStack; 6558d67c0711b52226db59158a0cfce09f35badd96absalomon@google.com GrClipData fReplacementClip; 656ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com }; 657d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com 65825fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com //////////////////////////////////////////////////////////////////////////// 659d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com 66025fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com class AutoGeometryPush : ::GrNoncopyable { 66125fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com public: 66225fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com AutoGeometryPush(GrDrawTarget* target) { 66325fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com GrAssert(NULL != target); 66425fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com fTarget = target; 66525fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com target->pushGeometrySource(); 66625fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com } 66725fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com ~AutoGeometryPush() { 66825fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com fTarget->popGeometrySource(); 66925fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com } 67025fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com private: 67125fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com GrDrawTarget* fTarget; 67225fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com }; 673ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 674ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com //////////////////////////////////////////////////////////////////////////// 6758531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com // Helpers for picking apart vertex layouts 6765782d712ffc31557d0cb12d5a220cebb783f6895bsalomon@google.com 677ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com /** 678ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * Helper function to compute the size of a vertex from a vertex layout 679ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * @return size of a single vertex. 680ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com */ 681ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com static size_t VertexSize(GrVertexLayout vertexLayout); 6825782d712ffc31557d0cb12d5a220cebb783f6895bsalomon@google.com 6838531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com /** 6848531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com * Helper function for determining the index of texture coordinates that 6858531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com * is input for a texture stage. Note that a stage may instead use positions 6868531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com * as texture coordinates, in which case the result of the function is 6878531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com * indistinguishable from the case when the stage is disabled. 6888531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com * 68908283afc265f1153834256fc1012519813ba6b73bsalomon@google.com * @param stageIdx the stage to query 6908531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com * @param vertexLayout layout to query 6918531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com * 6928531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com * @return the texture coordinate index or -1 if the stage doesn't use 6938531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com * separate (non-position) texture coordinates. 6948531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com */ 69508283afc265f1153834256fc1012519813ba6b73bsalomon@google.com static int VertexTexCoordsForStage(int stageIdx, GrVertexLayout vertexLayout); 696ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 697ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com /** 698ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * Helper function to compute the offset of texture coordinates in a vertex 699ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * @return offset of texture coordinates in vertex layout or -1 if the 7005782d712ffc31557d0cb12d5a220cebb783f6895bsalomon@google.com * layout has no texture coordinates. Will be 0 if positions are 7018531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com * used as texture coordinates for the stage. 702ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com */ 70308283afc265f1153834256fc1012519813ba6b73bsalomon@google.com static int VertexStageCoordOffset(int stageIdx, GrVertexLayout vertexLayout); 704ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 705ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com /** 706ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * Helper function to compute the offset of the color in a vertex 707ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * @return offset of color in vertex layout or -1 if the 708ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * layout has no color. 709ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com */ 710ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com static int VertexColorOffset(GrVertexLayout vertexLayout); 711ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 712a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com /** 713a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com * Helper function to compute the offset of the coverage in a vertex 714a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com * @return offset of coverage in vertex layout or -1 if the 715a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com * layout has no coverage. 716a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com */ 717a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com static int VertexCoverageOffset(GrVertexLayout vertexLayout); 718a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com 719aeb2160b1dd34f8e640e8e56544fe407d4ff6311bsalomon@google.com /** 720aeb2160b1dd34f8e640e8e56544fe407d4ff6311bsalomon@google.com * Helper function to compute the offset of the edge pts in a vertex 721aeb2160b1dd34f8e640e8e56544fe407d4ff6311bsalomon@google.com * @return offset of edge in vertex layout or -1 if the 722aeb2160b1dd34f8e640e8e56544fe407d4ff6311bsalomon@google.com * layout has no edge. 723aeb2160b1dd34f8e640e8e56544fe407d4ff6311bsalomon@google.com */ 724aeb2160b1dd34f8e640e8e56544fe407d4ff6311bsalomon@google.com static int VertexEdgeOffset(GrVertexLayout vertexLayout); 725aeb2160b1dd34f8e640e8e56544fe407d4ff6311bsalomon@google.com 726ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com /** 7275782d712ffc31557d0cb12d5a220cebb783f6895bsalomon@google.com * Helper function to determine if vertex layout contains explicit texture 7288531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com * coordinates of some index. 7298531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com * 7308531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com * @param coordIndex the tex coord index to query 7318531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com * @param vertexLayout layout to query 7328531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com * 7335782d712ffc31557d0cb12d5a220cebb783f6895bsalomon@google.com * @return true if vertex specifies texture coordinates for the index, 7348531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com * false otherwise. 735ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com */ 7365782d712ffc31557d0cb12d5a220cebb783f6895bsalomon@google.com static bool VertexUsesTexCoordIdx(int coordIndex, 7378531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com GrVertexLayout vertexLayout); 7385782d712ffc31557d0cb12d5a220cebb783f6895bsalomon@google.com 739ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com /** 7405782d712ffc31557d0cb12d5a220cebb783f6895bsalomon@google.com * Helper function to compute the size of each vertex and the offsets of 7415782d712ffc31557d0cb12d5a220cebb783f6895bsalomon@google.com * texture coordinates and color. Determines tex coord offsets by tex coord 7425782d712ffc31557d0cb12d5a220cebb783f6895bsalomon@google.com * index rather than by stage. (Each stage can be mapped to any t.c. index 7438531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com * by StageTexCoordVertexLayoutBit.) 7448531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com * 7458531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com * @param vertexLayout the layout to query 7468531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com * @param texCoordOffsetsByIdx after return it is the offset of each 7478531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com * tex coord index in the vertex or -1 if 748a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com * index isn't used. (optional) 749a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com * @param colorOffset after return it is the offset of the 750a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com * color field in each vertex, or -1 if 751a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com * there aren't per-vertex colors. (optional) 752a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com * @param coverageOffset after return it is the offset of the 753a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com * coverage field in each vertex, or -1 if 754a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com * there aren't per-vertex coeverages. 755a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com * (optional) 756a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com * @param edgeOffset after return it is the offset of the 757a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com * edge eq field in each vertex, or -1 if 758a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com * there aren't per-vertex edge equations. 759a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com * (optional) 7608531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com * @return size of a single vertex 7618531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com */ 7628531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com static int VertexSizeAndOffsetsByIdx(GrVertexLayout vertexLayout, 7639381363050ec9d3e724076a8e9152bfa9a8de1d1tomhudson@google.com int texCoordOffsetsByIdx[GrDrawState::kMaxTexCoords], 7649381363050ec9d3e724076a8e9152bfa9a8de1d1tomhudson@google.com int *colorOffset, 7659381363050ec9d3e724076a8e9152bfa9a8de1d1tomhudson@google.com int *coverageOffset, 7669381363050ec9d3e724076a8e9152bfa9a8de1d1tomhudson@google.com int* edgeOffset); 7675782d712ffc31557d0cb12d5a220cebb783f6895bsalomon@google.com 7688531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com /** 7695782d712ffc31557d0cb12d5a220cebb783f6895bsalomon@google.com * Helper function to compute the size of each vertex and the offsets of 7705782d712ffc31557d0cb12d5a220cebb783f6895bsalomon@google.com * texture coordinates and color. Determines tex coord offsets by stage 7715782d712ffc31557d0cb12d5a220cebb783f6895bsalomon@google.com * rather than by index. (Each stage can be mapped to any t.c. index 7725782d712ffc31557d0cb12d5a220cebb783f6895bsalomon@google.com * by StageTexCoordVertexLayoutBit.) If a stage uses positions for 7738531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com * tex coords then that stage's offset will be 0 (positions are always at 0). 7748531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com * 7758531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com * @param vertexLayout the layout to query 7768531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com * @param texCoordOffsetsByStage after return it is the offset of each 7778531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com * tex coord index in the vertex or -1 if 778a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com * index isn't used. (optional) 779a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com * @param colorOffset after return it is the offset of the 780a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com * color field in each vertex, or -1 if 781a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com * there aren't per-vertex colors. 782a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com * (optional) 783a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com * @param coverageOffset after return it is the offset of the 784a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com * coverage field in each vertex, or -1 if 785a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com * there aren't per-vertex coeverages. 786a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com * (optional) 787a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com * @param edgeOffset after return it is the offset of the 788a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com * edge eq field in each vertex, or -1 if 789a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com * there aren't per-vertex edge equations. 790a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com * (optional) 7918531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com * @return size of a single vertex 7928531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com */ 7938531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com static int VertexSizeAndOffsetsByStage(GrVertexLayout vertexLayout, 7949381363050ec9d3e724076a8e9152bfa9a8de1d1tomhudson@google.com int texCoordOffsetsByStage[GrDrawState::kNumStages], 7959381363050ec9d3e724076a8e9152bfa9a8de1d1tomhudson@google.com int* colorOffset, 7969381363050ec9d3e724076a8e9152bfa9a8de1d1tomhudson@google.com int* coverageOffset, 7979381363050ec9d3e724076a8e9152bfa9a8de1d1tomhudson@google.com int* edgeOffset); 79886afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com 79986afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com /** 80086afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com * Accessing positions, texture coords, or colors, of a vertex within an 80186afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com * array is a hassle involving casts and simple math. These helpers exist 80286afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com * to keep GrDrawTarget clients' code a bit nicer looking. 80386afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com */ 80486afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com 80586afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com /** 80686afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com * Gets a pointer to a GrPoint of a vertex's position or texture 80786afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com * coordinate. 80886afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com * @param vertices the vetex array 80986afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com * @param vertexIndex the index of the vertex in the array 81086afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com * @param vertexSize the size of each vertex in the array 81186afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com * @param offset the offset in bytes of the vertex component. 81286afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com * Defaults to zero (corresponding to vertex position) 81386afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com * @return pointer to the vertex component as a GrPoint 81486afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com */ 815d302f1401b3c9aea094804bad4e76de98782cfe8bsalomon@google.com static GrPoint* GetVertexPoint(void* vertices, 81686afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com int vertexIndex, 81786afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com int vertexSize, 81886afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com int offset = 0) { 81986afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com intptr_t start = GrTCast<intptr_t>(vertices); 820d302f1401b3c9aea094804bad4e76de98782cfe8bsalomon@google.com return GrTCast<GrPoint*>(start + offset + 82186afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com vertexIndex * vertexSize); 82286afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com } 82386afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com static const GrPoint* GetVertexPoint(const void* vertices, 82486afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com int vertexIndex, 825d302f1401b3c9aea094804bad4e76de98782cfe8bsalomon@google.com int vertexSize, 82686afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com int offset = 0) { 82786afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com intptr_t start = GrTCast<intptr_t>(vertices); 828d302f1401b3c9aea094804bad4e76de98782cfe8bsalomon@google.com return GrTCast<const GrPoint*>(start + offset + 82986afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com vertexIndex * vertexSize); 83086afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com } 83186afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com 83286afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com /** 83386afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com * Gets a pointer to a GrColor inside a vertex within a vertex array. 83486afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com * @param vertices the vetex array 83586afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com * @param vertexIndex the index of the vertex in the array 83686afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com * @param vertexSize the size of each vertex in the array 83786afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com * @param offset the offset in bytes of the vertex color 83886afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com * @return pointer to the vertex component as a GrColor 83986afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com */ 840d302f1401b3c9aea094804bad4e76de98782cfe8bsalomon@google.com static GrColor* GetVertexColor(void* vertices, 84186afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com int vertexIndex, 84286afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com int vertexSize, 84386afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com int offset) { 84486afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com intptr_t start = GrTCast<intptr_t>(vertices); 845d302f1401b3c9aea094804bad4e76de98782cfe8bsalomon@google.com return GrTCast<GrColor*>(start + offset + 84686afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com vertexIndex * vertexSize); 84786afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com } 84886afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com static const GrColor* GetVertexColor(const void* vertices, 84986afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com int vertexIndex, 850d302f1401b3c9aea094804bad4e76de98782cfe8bsalomon@google.com int vertexSize, 85186afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com int offset) { 85286afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com const intptr_t start = GrTCast<intptr_t>(vertices); 853d302f1401b3c9aea094804bad4e76de98782cfe8bsalomon@google.com return GrTCast<const GrColor*>(start + offset + 85486afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com vertexIndex * vertexSize); 85586afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com } 85686afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com 8575aaa69e4339e229adfb05e96084a8ec0a590238bbsalomon@google.com static void VertexLayoutUnitTest(); 8585aaa69e4339e229adfb05e96084a8ec0a590238bbsalomon@google.com 859ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.comprotected: 860471d471dcd7422e5dd9c822c1092b2ba4721dcfebsalomon@google.com 86186c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com /** 86286c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com * Optimizations for blending / coverage to be applied based on the current 86386c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com * state. 86486c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com * Subclasses that actually draw (as opposed to those that just buffer for 86586c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com * playback) must implement the flags that replace the output color. 86686c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com */ 86786c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com enum BlendOptFlags { 86886c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com /** 86986c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com * No optimization 87086c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com */ 87186c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com kNone_BlendOpt = 0, 87286c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com /** 87386c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com * Don't draw at all 87486c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com */ 87586c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com kSkipDraw_BlendOptFlag = 0x2, 87686c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com /** 87786c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com * Emit the src color, disable HW blending (replace dst with src) 87886c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com */ 87986c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com kDisableBlend_BlendOptFlag = 0x4, 88086c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com /** 88186c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com * The coverage value does not have to be computed separately from 88286c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com * alpha, the the output color can be the modulation of the two. 88386c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com */ 88486c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com kCoverageAsAlpha_BlendOptFlag = 0x1, 88586c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com /** 88686c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com * Instead of emitting a src color, emit coverage in the alpha channel 88786c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com * and r,g,b are "don't cares". 88886c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com */ 88986c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com kEmitCoverage_BlendOptFlag = 0x10, 89086c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com /** 89186c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com * Emit transparent black instead of the src color, no need to compute 89286c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com * coverage. 89386c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com */ 89486c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com kEmitTransBlack_BlendOptFlag = 0x8, 89586c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com }; 89686c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com GR_DECL_BITFIELD_OPS_FRIENDS(BlendOptFlags); 89786c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com 898cf939ae54842fc7408ee68a41427086962b4c3dcbsalomon@google.com /** 899cf939ae54842fc7408ee68a41427086962b4c3dcbsalomon@google.com * Determines what optimizations can be applied based on the blend. The coefficients may have 900cf939ae54842fc7408ee68a41427086962b4c3dcbsalomon@google.com * to be tweaked in order for the optimization to work. srcCoeff and dstCoeff are optional 901cf939ae54842fc7408ee68a41427086962b4c3dcbsalomon@google.com * params that receive the tweaked coefficients. Normally the function looks at the current 902cf939ae54842fc7408ee68a41427086962b4c3dcbsalomon@google.com * state to see if coverage is enabled. By setting forceCoverage the caller can speculatively 903cf939ae54842fc7408ee68a41427086962b4c3dcbsalomon@google.com * determine the blend optimizations that would be used if there was partial pixel coverage. 904cf939ae54842fc7408ee68a41427086962b4c3dcbsalomon@google.com */ 90586c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com BlendOptFlags getBlendOpts(bool forceCoverage = false, 90686c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com GrBlendCoeff* srcCoeff = NULL, 90786c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com GrBlendCoeff* dstCoeff = NULL) const; 90886c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com 90986c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com // determine if src alpha is guaranteed to be one for all src pixels 910e79c815bca39fa552983b7a8107219aa5084acdbbsalomon@google.com bool srcAlphaWillBeOne(GrVertexLayout vertexLayout) const; 911471d471dcd7422e5dd9c822c1092b2ba4721dcfebsalomon@google.com 91225fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com enum GeometrySrcType { 91325fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com kNone_GeometrySrcType, //<! src has not been specified 91425fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com kReserved_GeometrySrcType, //<! src was set using reserve*Space 91525fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com kArray_GeometrySrcType, //<! src was set using set*SourceToArray 91625fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com kBuffer_GeometrySrcType //<! src was set using set*SourceToBuffer 91725fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com }; 918d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com 91925fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com struct GeometrySrcState { 92025fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com GeometrySrcType fVertexSrc; 92125fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com union { 92225fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com // valid if src type is buffer 92325fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com const GrVertexBuffer* fVertexBuffer; 92425fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com // valid if src type is reserved or array 92525fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com int fVertexCount; 92625fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com }; 927d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com 92825fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com GeometrySrcType fIndexSrc; 92925fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com union { 93025fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com // valid if src type is buffer 93125fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com const GrIndexBuffer* fIndexBuffer; 93225fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com // valid if src type is reserved or array 93325fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com int fIndexCount; 93425fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com }; 935d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com 93625fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com GrVertexLayout fVertexLayout; 93725fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com }; 938934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com 939934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com int indexCountInCurrentSource() const { 940934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com const GeometrySrcState& src = this->getGeomSrc(); 941934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com switch (src.fIndexSrc) { 942934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com case kNone_GeometrySrcType: 943934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com return 0; 944934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com case kReserved_GeometrySrcType: 945934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com case kArray_GeometrySrcType: 946934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com return src.fIndexCount; 947934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com case kBuffer_GeometrySrcType: 948934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com return src.fIndexBuffer->sizeInBytes() / sizeof(uint16_t); 949934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com default: 950934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com GrCrash("Unexpected Index Source."); 951934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com return 0; 952934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com } 953934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com } 954a47a48dca5045d71cbc5de343404045209a13e15bsalomon@google.com 95508283afc265f1153834256fc1012519813ba6b73bsalomon@google.com bool isStageEnabled(int stageIdx) const { 95608283afc265f1153834256fc1012519813ba6b73bsalomon@google.com return this->getDrawState().isStageEnabled(stageIdx); 957a47a48dca5045d71cbc5de343404045209a13e15bsalomon@google.com } 9585782d712ffc31557d0cb12d5a220cebb783f6895bsalomon@google.com 95997805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com // A sublcass can optionally overload this function to be notified before 96097805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com // vertex and index space is reserved. 96197805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com virtual void willReserveVertexAndIndexSpace(GrVertexLayout vertexLayout, 96297805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com int vertexCount, 96397805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com int indexCount) {} 964d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com 96597805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com 96625fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com // implemented by subclass to allocate space for reserved geom 96725fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com virtual bool onReserveVertexSpace(GrVertexLayout vertexLayout, 96825fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com int vertexCount, 96925fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com void** vertices) = 0; 97025fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com virtual bool onReserveIndexSpace(int indexCount, void** indices) = 0; 97125fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com // implemented by subclass to handle release of reserved geom space 97225fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com virtual void releaseReservedVertexSpace() = 0; 97325fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com virtual void releaseReservedIndexSpace() = 0; 97425fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com // subclass must consume array contents when set 975bcdbbe61e1a3f89545b2c1461164f0f8bf5f0797bsalomon@google.com virtual void onSetVertexSourceToArray(const void* vertexArray, 976bcdbbe61e1a3f89545b2c1461164f0f8bf5f0797bsalomon@google.com int vertexCount) = 0; 977bcdbbe61e1a3f89545b2c1461164f0f8bf5f0797bsalomon@google.com virtual void onSetIndexSourceToArray(const void* indexArray, 978bcdbbe61e1a3f89545b2c1461164f0f8bf5f0797bsalomon@google.com int indexCount) = 0; 97925fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com // subclass is notified that geom source will be set away from an array 98025fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com virtual void releaseVertexArray() = 0; 98125fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com virtual void releaseIndexArray() = 0; 98225fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com // subclass overrides to be notified just before geo src state 98325fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com // is pushed/popped. 98425fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com virtual void geometrySourceWillPush() = 0; 98525fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com virtual void geometrySourceWillPop(const GeometrySrcState& restoredState) = 0; 98625fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com // subclass called to perform drawing 98725fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com virtual void onDrawIndexed(GrPrimitiveType type, 98825fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com int startVertex, 98925fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com int startIndex, 99025fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com int vertexCount, 99125fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com int indexCount) = 0; 99225fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com virtual void onDrawNonIndexed(GrPrimitiveType type, 99325fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com int startVertex, 99425fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com int vertexCount) = 0; 99512b4e27ae1a29460e91a59f38122483e1faec697sugoi@google.com virtual void onStencilPath(const GrPath*, const SkStroke& stroke, SkPath::FillType fill) = 0; 99664aef2bacd1f5c25ffd9347aabd6265c9b60c0f4bsalomon@google.com 997dea2f8d86378b791a2de94384a18e29f13f65a3ebsalomon@google.com // subclass overrides to be notified when clip is set. Must call 998dea2f8d86378b791a2de94384a18e29f13f65a3ebsalomon@google.com // INHERITED::clipwillBeSet 999beb1af78d016d2700c350487a383c6bcfa7e2e20robertphillips@google.com virtual void clipWillBeSet(const GrClipData* clipData) {} 10001c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com 100186afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com // Helpers for drawRect, protected so subclasses that override drawRect 100286afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com // can use them. 1003e3d3216fe17b6afb2e613271b5246a2766e12df6bsalomon@google.com static GrVertexLayout GetRectVertexLayout(const GrRect* srcRects[]); 100486afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com 100586afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com static void SetRectVertices(const GrRect& rect, 1006b9086a026844e4cfd08b219e49ce3f12294cba98bsalomon@google.com const SkMatrix* matrix, 1007d302f1401b3c9aea094804bad4e76de98782cfe8bsalomon@google.com const GrRect* srcRects[], 1008b9086a026844e4cfd08b219e49ce3f12294cba98bsalomon@google.com const SkMatrix* srcMatrices[], 10098b129aa3379ece6c43d9ce2ad0cdeafb089b7eb5robertphillips@google.com GrColor color, 1010d302f1401b3c9aea094804bad4e76de98782cfe8bsalomon@google.com GrVertexLayout layout, 101186afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com void* vertices); 101286afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com 1013e79c815bca39fa552983b7a8107219aa5084acdbbsalomon@google.com // accessors for derived classes 101425fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com const GeometrySrcState& getGeomSrc() const { 101525fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com return fGeoSrcStateStack.back(); 101625fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com } 1017e79c815bca39fa552983b7a8107219aa5084acdbbsalomon@google.com // it is prefereable to call this rather than getGeomSrc()->fVertexLayout 1018e79c815bca39fa552983b7a8107219aa5084acdbbsalomon@google.com // because of the assert. 1019e79c815bca39fa552983b7a8107219aa5084acdbbsalomon@google.com GrVertexLayout getVertexLayout() const { 1020e79c815bca39fa552983b7a8107219aa5084acdbbsalomon@google.com // the vertex layout is only valid if a vertex source has been 1021e79c815bca39fa552983b7a8107219aa5084acdbbsalomon@google.com // specified. 1022e79c815bca39fa552983b7a8107219aa5084acdbbsalomon@google.com GrAssert(this->getGeomSrc().fVertexSrc != kNone_GeometrySrcType); 1023e79c815bca39fa552983b7a8107219aa5084acdbbsalomon@google.com return this->getGeomSrc().fVertexLayout; 1024e79c815bca39fa552983b7a8107219aa5084acdbbsalomon@google.com } 1025ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 1026f66018798099750e639a8fa131fece492a050997bsalomon@google.com // allows derived class to set the caps 1027f66018798099750e639a8fa131fece492a050997bsalomon@google.com CapsInternals* capsInternals() { return &fCaps.fInternals; } 1028f66018798099750e639a8fa131fece492a050997bsalomon@google.com 1029beb1af78d016d2700c350487a383c6bcfa7e2e20robertphillips@google.com const GrClipData* fClip; 1030ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 1031a5d056ae0b04021dfb44c2c7a3d6a34e060261b8bsalomon@google.com GrDrawState* fDrawState; 1032a5d056ae0b04021dfb44c2c7a3d6a34e060261b8bsalomon@google.com GrDrawState fDefaultDrawState; 1033ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 103418c9c198f571997463d9a7134dbd88298e592ec2bsalomon@google.com Caps fCaps; 103518c9c198f571997463d9a7134dbd88298e592ec2bsalomon@google.com 10364a018bb20bf969a38ec11d9506843f06366dfa7cbsalomon@google.com // subclasses must call this in their destructors to ensure all vertex 1037d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com // and index sources have been released (including those held by 10384a018bb20bf969a38ec11d9506843f06366dfa7cbsalomon@google.com // pushGeometrySource()) 10394a018bb20bf969a38ec11d9506843f06366dfa7cbsalomon@google.com void releaseGeometry(); 1040e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com 104125fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.comprivate: 1042e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com // helpers for reserving vertex and index space. 1043e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com bool reserveVertexSpace(GrVertexLayout vertexLayout, 1044e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com int vertexCount, 1045e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com void** vertices); 1046e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com bool reserveIndexSpace(int indexCount, void** indices); 1047d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com 1048e826262939dac3e67cb5ce66d4b9faeb8e2538e6bsalomon@google.com // called by drawIndexed and drawNonIndexed. Use a negative indexCount to 1049e826262939dac3e67cb5ce66d4b9faeb8e2538e6bsalomon@google.com // indicate non-indexed drawing. 1050e826262939dac3e67cb5ce66d4b9faeb8e2538e6bsalomon@google.com bool checkDraw(GrPrimitiveType type, int startVertex, 1051e826262939dac3e67cb5ce66d4b9faeb8e2538e6bsalomon@google.com int startIndex, int vertexCount, 1052e826262939dac3e67cb5ce66d4b9faeb8e2538e6bsalomon@google.com int indexCount) const; 105325fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com // called when setting a new vert/idx source to unref prev vb/ib 105425fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com void releasePreviousVertexSource(); 105525fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com void releasePreviousIndexSource(); 1056d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com 105725fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com enum { 105825fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com kPreallocGeoSrcStateStackCnt = 4, 1059ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com }; 1060d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com SkSTArray<kPreallocGeoSrcStateStackCnt, 106192669014aa7ab821cdc09cc9ad610316eb16b490bsalomon@google.com GeometrySrcState, true> fGeoSrcStateStack; 1062fa35e3ddcc9d130ce87c927218bdf27879c38711reed@google.com 1063fa35e3ddcc9d130ce87c927218bdf27879c38711reed@google.com typedef GrRefCnt INHERITED; 1064ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com}; 1065ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 106686c1f71625970610e768d3bf26c933db2cd685babsalomon@google.comGR_MAKE_BITFIELD_OPS(GrDrawTarget::BlendOptFlags); 106786c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com 1068ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com#endif 1069