GrDrawTarget.h revision 4a018bb20bf969a38ec11d9506843f06366dfa7c
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 14aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.com#include "GrClip.h" 15ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com#include "GrColor.h" 169381363050ec9d3e724076a8e9152bfa9a8de1d1tomhudson@google.com#include "GrDrawState.h" 17aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.com#include "GrMatrix.h" 18ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com#include "GrRefCnt.h" 19aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.com#include "GrRenderTarget.h" 20ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com#include "GrSamplerState.h" 21d302f1401b3c9aea094804bad4e76de98782cfe8bsalomon@google.com#include "GrStencil.h" 22aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.com#include "GrTexture.h" 23ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 2497c88c255cff3dbb8343c5d090526fdbedad6dd6Scroggo#include "SkXfermode.h" 2597c88c255cff3dbb8343c5d090526fdbedad6dd6Scroggo 26ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.comclass GrTexture; 27ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.comclass GrClipIterator; 28ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.comclass GrVertexBuffer; 29ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.comclass GrIndexBuffer; 30ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 31ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.comclass GrDrawTarget : public GrRefCnt { 32ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.compublic: 33ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com /** 3418c9c198f571997463d9a7134dbd88298e592ec2bsalomon@google.com * Represents the draw target capabilities. 3518c9c198f571997463d9a7134dbd88298e592ec2bsalomon@google.com */ 3618c9c198f571997463d9a7134dbd88298e592ec2bsalomon@google.com struct Caps { 3718c9c198f571997463d9a7134dbd88298e592ec2bsalomon@google.com Caps() { memset(this, 0, sizeof(Caps)); } 3818c9c198f571997463d9a7134dbd88298e592ec2bsalomon@google.com Caps(const Caps& c) { *this = c; } 3918c9c198f571997463d9a7134dbd88298e592ec2bsalomon@google.com Caps& operator= (const Caps& c) { 4018c9c198f571997463d9a7134dbd88298e592ec2bsalomon@google.com memcpy(this, &c, sizeof(Caps)); 4118c9c198f571997463d9a7134dbd88298e592ec2bsalomon@google.com return *this; 4218c9c198f571997463d9a7134dbd88298e592ec2bsalomon@google.com } 4318c9c198f571997463d9a7134dbd88298e592ec2bsalomon@google.com void print() const; 4418c9c198f571997463d9a7134dbd88298e592ec2bsalomon@google.com bool f8BitPaletteSupport : 1; 4518c9c198f571997463d9a7134dbd88298e592ec2bsalomon@google.com bool fNPOTTextureSupport : 1; 4618c9c198f571997463d9a7134dbd88298e592ec2bsalomon@google.com bool fNPOTTextureTileSupport : 1; 4718c9c198f571997463d9a7134dbd88298e592ec2bsalomon@google.com bool fNPOTRenderTargetSupport : 1; 4818c9c198f571997463d9a7134dbd88298e592ec2bsalomon@google.com bool fTwoSidedStencilSupport : 1; 4918c9c198f571997463d9a7134dbd88298e592ec2bsalomon@google.com bool fStencilWrapOpsSupport : 1; 5018c9c198f571997463d9a7134dbd88298e592ec2bsalomon@google.com bool fHWAALineSupport : 1; 5118c9c198f571997463d9a7134dbd88298e592ec2bsalomon@google.com bool fShaderSupport : 1; 5218c9c198f571997463d9a7134dbd88298e592ec2bsalomon@google.com bool fShaderDerivativeSupport : 1; 53edfe1aac5c6f3a3f3830e86ddea8dbceeb0e6df4bsalomon@google.com bool fGeometryShaderSupport : 1; 5418c9c198f571997463d9a7134dbd88298e592ec2bsalomon@google.com bool fFSAASupport : 1; 5518c9c198f571997463d9a7134dbd88298e592ec2bsalomon@google.com bool fDualSourceBlendingSupport : 1; 5618c9c198f571997463d9a7134dbd88298e592ec2bsalomon@google.com bool fBufferLockSupport : 1; 57a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com bool fSupportPerVertexCoverage : 1; 5818c9c198f571997463d9a7134dbd88298e592ec2bsalomon@google.com int fMinRenderTargetWidth; 5918c9c198f571997463d9a7134dbd88298e592ec2bsalomon@google.com int fMinRenderTargetHeight; 6018c9c198f571997463d9a7134dbd88298e592ec2bsalomon@google.com int fMaxRenderTargetSize; 6118c9c198f571997463d9a7134dbd88298e592ec2bsalomon@google.com int fMaxTextureSize; 6218c9c198f571997463d9a7134dbd88298e592ec2bsalomon@google.com }; 6318c9c198f571997463d9a7134dbd88298e592ec2bsalomon@google.com 6418c9c198f571997463d9a7134dbd88298e592ec2bsalomon@google.com /** 65ffca400ef6f96a280c3e2c09210f950af64a1f24bsalomon@google.com * Bitfield used to indicate which stages are in use. 66ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com */ 67ffca400ef6f96a280c3e2c09210f950af64a1f24bsalomon@google.com typedef int StageBitfield; 689381363050ec9d3e724076a8e9152bfa9a8de1d1tomhudson@google.com GR_STATIC_ASSERT(sizeof(StageBitfield)*8 >= GrDrawState::kNumStages); 69ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 70ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com /** 71ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * Flags that affect rendering. Controlled using enable/disableState(). All 72ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * default to disabled. 73ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com */ 74ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com enum StateBits { 75289533ada623f2238a83771eec977f204f75994fbsalomon@google.com /** 76289533ada623f2238a83771eec977f204f75994fbsalomon@google.com * Perform dithering. TODO: Re-evaluate whether we need this bit 77289533ada623f2238a83771eec977f204f75994fbsalomon@google.com */ 78289533ada623f2238a83771eec977f204f75994fbsalomon@google.com kDither_StateBit = 0x01, 79289533ada623f2238a83771eec977f204f75994fbsalomon@google.com /** 80289533ada623f2238a83771eec977f204f75994fbsalomon@google.com * Perform HW anti-aliasing. This means either HW FSAA, if supported 81289533ada623f2238a83771eec977f204f75994fbsalomon@google.com * by the render target, or smooth-line rendering if a line primitive 82289533ada623f2238a83771eec977f204f75994fbsalomon@google.com * is drawn and line smoothing is supported by the 3D API. 83289533ada623f2238a83771eec977f204f75994fbsalomon@google.com */ 84289533ada623f2238a83771eec977f204f75994fbsalomon@google.com kHWAntialias_StateBit = 0x02, 85289533ada623f2238a83771eec977f204f75994fbsalomon@google.com /** 86289533ada623f2238a83771eec977f204f75994fbsalomon@google.com * Draws will respect the clip, otherwise the clip is ignored. 87289533ada623f2238a83771eec977f204f75994fbsalomon@google.com */ 88289533ada623f2238a83771eec977f204f75994fbsalomon@google.com kClip_StateBit = 0x04, 89289533ada623f2238a83771eec977f204f75994fbsalomon@google.com /** 90289533ada623f2238a83771eec977f204f75994fbsalomon@google.com * Disables writing to the color buffer. Useful when performing stencil 91289533ada623f2238a83771eec977f204f75994fbsalomon@google.com * operations. 92289533ada623f2238a83771eec977f204f75994fbsalomon@google.com */ 93289533ada623f2238a83771eec977f204f75994fbsalomon@google.com kNoColorWrites_StateBit = 0x08, 94289533ada623f2238a83771eec977f204f75994fbsalomon@google.com /** 95289533ada623f2238a83771eec977f204f75994fbsalomon@google.com * Modifies the behavior of edge AA specified by setEdgeAA. If set, 96289533ada623f2238a83771eec977f204f75994fbsalomon@google.com * will test edge pairs for convexity when rasterizing. Set this if the 97289533ada623f2238a83771eec977f204f75994fbsalomon@google.com * source polygon is non-convex. 98289533ada623f2238a83771eec977f204f75994fbsalomon@google.com */ 99289533ada623f2238a83771eec977f204f75994fbsalomon@google.com kEdgeAAConcave_StateBit = 0x10, 100d302f1401b3c9aea094804bad4e76de98782cfe8bsalomon@google.com // subclass may use additional bits internally 101d302f1401b3c9aea094804bad4e76de98782cfe8bsalomon@google.com kDummyStateBit, 102d302f1401b3c9aea094804bad4e76de98782cfe8bsalomon@google.com kLastPublicStateBit = kDummyStateBit-1 103ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com }; 104ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 105d302f1401b3c9aea094804bad4e76de98782cfe8bsalomon@google.com /** 106d302f1401b3c9aea094804bad4e76de98782cfe8bsalomon@google.com * Sets the stencil settings to use for the next draw. 1075aaa69e4339e229adfb05e96084a8ec0a590238bbsalomon@google.com * Changing the clip has the side-effect of possibly zeroing 1085aaa69e4339e229adfb05e96084a8ec0a590238bbsalomon@google.com * out the client settable stencil bits. So multipass algorithms 1095aaa69e4339e229adfb05e96084a8ec0a590238bbsalomon@google.com * using stencil should not change the clip between passes. 110d302f1401b3c9aea094804bad4e76de98782cfe8bsalomon@google.com * @param settings the stencil settings to use. 111d302f1401b3c9aea094804bad4e76de98782cfe8bsalomon@google.com */ 112d302f1401b3c9aea094804bad4e76de98782cfe8bsalomon@google.com void setStencil(const GrStencilSettings& settings) { 113d302f1401b3c9aea094804bad4e76de98782cfe8bsalomon@google.com fCurrDrawState.fStencilSettings = settings; 114d302f1401b3c9aea094804bad4e76de98782cfe8bsalomon@google.com } 115d302f1401b3c9aea094804bad4e76de98782cfe8bsalomon@google.com 116d302f1401b3c9aea094804bad4e76de98782cfe8bsalomon@google.com /** 117d302f1401b3c9aea094804bad4e76de98782cfe8bsalomon@google.com * Shortcut to disable stencil testing and ops. 118d302f1401b3c9aea094804bad4e76de98782cfe8bsalomon@google.com */ 119d302f1401b3c9aea094804bad4e76de98782cfe8bsalomon@google.com void disableStencil() { 120d302f1401b3c9aea094804bad4e76de98782cfe8bsalomon@google.com fCurrDrawState.fStencilSettings.setDisabled(); 121d302f1401b3c9aea094804bad4e76de98782cfe8bsalomon@google.com } 122d302f1401b3c9aea094804bad4e76de98782cfe8bsalomon@google.com 123ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.compublic: 124ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com /////////////////////////////////////////////////////////////////////////// 125ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 126ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com GrDrawTarget(); 12725fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com virtual ~GrDrawTarget(); 128ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 129ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com /** 13018c9c198f571997463d9a7134dbd88298e592ec2bsalomon@google.com * Gets the capabilities of the draw target. 13118c9c198f571997463d9a7134dbd88298e592ec2bsalomon@google.com */ 13218c9c198f571997463d9a7134dbd88298e592ec2bsalomon@google.com const Caps& getCaps() const { return fCaps; } 13318c9c198f571997463d9a7134dbd88298e592ec2bsalomon@google.com 13418c9c198f571997463d9a7134dbd88298e592ec2bsalomon@google.com /** 135ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * Sets the current clip to the region specified by clip. All draws will be 136ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * clipped against this clip if kClip_StateBit is enabled. 137ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * 1385aaa69e4339e229adfb05e96084a8ec0a590238bbsalomon@google.com * Setting the clip may (or may not) zero out the client's stencil bits. 1395aaa69e4339e229adfb05e96084a8ec0a590238bbsalomon@google.com * 140ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * @param description of the clipping region 141ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com */ 142ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com void setClip(const GrClip& clip); 143ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 144ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com /** 145ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * Gets the current clip. 146ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * 147ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * @return the clip. 148ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com */ 149ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com const GrClip& getClip() const; 150ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 151ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com /** 152ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * Sets the texture used at the next drawing call 153ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * 1548531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com * @param stage The texture stage for which the texture will be set 1558531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com * 156ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * @param texture The texture to set. Can be NULL though there is no advantage 157ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * to settings a NULL texture if doing non-textured drawing 158ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com */ 1598531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com void setTexture(int stage, GrTexture* texture); 160ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 161ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com /** 162ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * Retrieves the currently set texture. 163ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * 164ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * @return The currently set texture. The return value will be NULL if no 165ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * texture has been set, NULL was most recently passed to 166ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * setTexture, or the last setTexture was destroyed. 167ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com */ 1685782d712ffc31557d0cb12d5a220cebb783f6895bsalomon@google.com const GrTexture* getTexture(int stage) const; 1695782d712ffc31557d0cb12d5a220cebb783f6895bsalomon@google.com GrTexture* getTexture(int stage); 170ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 171ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com /** 172ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * Sets the rendertarget used at the next drawing call 173ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * 1745782d712ffc31557d0cb12d5a220cebb783f6895bsalomon@google.com * @param target The render target to set. 175ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com */ 176ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com void setRenderTarget(GrRenderTarget* target); 177ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 178ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com /** 179ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * Retrieves the currently set rendertarget. 180ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * 181ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * @return The currently set render target. 182ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com */ 1835782d712ffc31557d0cb12d5a220cebb783f6895bsalomon@google.com const GrRenderTarget* getRenderTarget() const; 1845782d712ffc31557d0cb12d5a220cebb783f6895bsalomon@google.com GrRenderTarget* getRenderTarget(); 185ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 186ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com /** 187c6cf72381b212eb21e61d5c5e14247b483a77753bsalomon@google.com * Sets the sampler state for a stage used in subsequent draws. 188ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * 189d302f1401b3c9aea094804bad4e76de98782cfe8bsalomon@google.com * The sampler state determines how texture coordinates are 190c6cf72381b212eb21e61d5c5e14247b483a77753bsalomon@google.com * intepretted and used to sample the texture. 191ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * 192c6cf72381b212eb21e61d5c5e14247b483a77753bsalomon@google.com * @param stage the stage of the sampler to set 193ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * @param samplerState Specifies the sampler state. 194ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com */ 1958531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com void setSamplerState(int stage, const GrSamplerState& samplerState); 196ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 197ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com /** 198c6cf72381b212eb21e61d5c5e14247b483a77753bsalomon@google.com * Concats the matrix of a stage's sampler. 199ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * 200c6cf72381b212eb21e61d5c5e14247b483a77753bsalomon@google.com * @param stage the stage of the sampler to set 201c6cf72381b212eb21e61d5c5e14247b483a77753bsalomon@google.com * @param matrix the matrix to concat 202ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com */ 20327847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com void preConcatSamplerMatrix(int stage, const GrMatrix& matrix) { 2049381363050ec9d3e724076a8e9152bfa9a8de1d1tomhudson@google.com GrAssert(stage >= 0 && stage < GrDrawState::kNumStages); 20527847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com fCurrDrawState.fSamplerStates[stage].preConcatMatrix(matrix); 206c6cf72381b212eb21e61d5c5e14247b483a77753bsalomon@google.com } 207ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 208ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com /** 209aeb2160b1dd34f8e640e8e56544fe407d4ff6311bsalomon@google.com * Shortcut for preConcatSamplerMatrix on all stages in mask with same 21026c2d0a69e66f1656d2dc23953a6f153e5d5009fbsalomon@google.com * matrix 21126c2d0a69e66f1656d2dc23953a6f153e5d5009fbsalomon@google.com */ 21226c2d0a69e66f1656d2dc23953a6f153e5d5009fbsalomon@google.com void preConcatSamplerMatrices(int stageMask, const GrMatrix& matrix) { 2139381363050ec9d3e724076a8e9152bfa9a8de1d1tomhudson@google.com for (int i = 0; i < GrDrawState::kNumStages; ++i) { 21426c2d0a69e66f1656d2dc23953a6f153e5d5009fbsalomon@google.com if ((1 << i) & stageMask) { 21526c2d0a69e66f1656d2dc23953a6f153e5d5009fbsalomon@google.com this->preConcatSamplerMatrix(i, matrix); 21626c2d0a69e66f1656d2dc23953a6f153e5d5009fbsalomon@google.com } 21726c2d0a69e66f1656d2dc23953a6f153e5d5009fbsalomon@google.com } 21826c2d0a69e66f1656d2dc23953a6f153e5d5009fbsalomon@google.com } 21926c2d0a69e66f1656d2dc23953a6f153e5d5009fbsalomon@google.com 22026c2d0a69e66f1656d2dc23953a6f153e5d5009fbsalomon@google.com /** 221aeb2160b1dd34f8e640e8e56544fe407d4ff6311bsalomon@google.com * Shortcut for preConcatSamplerMatrix on all enabled stages in mask with 222aeb2160b1dd34f8e640e8e56544fe407d4ff6311bsalomon@google.com * same matrix 223aeb2160b1dd34f8e640e8e56544fe407d4ff6311bsalomon@google.com * 224aeb2160b1dd34f8e640e8e56544fe407d4ff6311bsalomon@google.com * @param stage the stage of the sampler to set 225aeb2160b1dd34f8e640e8e56544fe407d4ff6311bsalomon@google.com * @param matrix the matrix to concat 226aeb2160b1dd34f8e640e8e56544fe407d4ff6311bsalomon@google.com */ 227aeb2160b1dd34f8e640e8e56544fe407d4ff6311bsalomon@google.com void preConcatEnabledSamplerMatrices(const GrMatrix& matrix) { 228aeb2160b1dd34f8e640e8e56544fe407d4ff6311bsalomon@google.com StageBitfield stageMask = this->enabledStages(); 229aeb2160b1dd34f8e640e8e56544fe407d4ff6311bsalomon@google.com this->preConcatSamplerMatrices(stageMask, matrix); 230aeb2160b1dd34f8e640e8e56544fe407d4ff6311bsalomon@google.com } 231aeb2160b1dd34f8e640e8e56544fe407d4ff6311bsalomon@google.com 232aeb2160b1dd34f8e640e8e56544fe407d4ff6311bsalomon@google.com /** 233c6cf72381b212eb21e61d5c5e14247b483a77753bsalomon@google.com * Gets the matrix of a stage's sampler 2346f7fbc9fbb584b9b9fa6ed3a677d71ecd49aafcebsalomon@google.com * 235c6cf72381b212eb21e61d5c5e14247b483a77753bsalomon@google.com * @param stage the stage to of sampler to get 236c6cf72381b212eb21e61d5c5e14247b483a77753bsalomon@google.com * @return the sampler state's matrix 2376f7fbc9fbb584b9b9fa6ed3a677d71ecd49aafcebsalomon@google.com */ 238c6cf72381b212eb21e61d5c5e14247b483a77753bsalomon@google.com const GrMatrix& getSamplerMatrix(int stage) const { 239c6cf72381b212eb21e61d5c5e14247b483a77753bsalomon@google.com return fCurrDrawState.fSamplerStates[stage].getMatrix(); 240c6cf72381b212eb21e61d5c5e14247b483a77753bsalomon@google.com } 2416f7fbc9fbb584b9b9fa6ed3a677d71ecd49aafcebsalomon@google.com 2426f7fbc9fbb584b9b9fa6ed3a677d71ecd49aafcebsalomon@google.com /** 243c6cf72381b212eb21e61d5c5e14247b483a77753bsalomon@google.com * Sets the matrix of a stage's sampler 244c6cf72381b212eb21e61d5c5e14247b483a77753bsalomon@google.com * 245c6cf72381b212eb21e61d5c5e14247b483a77753bsalomon@google.com * @param stage the stage of sampler set 246c6cf72381b212eb21e61d5c5e14247b483a77753bsalomon@google.com * @param matrix the matrix to set 2476f7fbc9fbb584b9b9fa6ed3a677d71ecd49aafcebsalomon@google.com */ 248cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com void setSamplerMatrix(int stage, const GrMatrix& matrix) { 249c6cf72381b212eb21e61d5c5e14247b483a77753bsalomon@google.com fCurrDrawState.fSamplerStates[stage].setMatrix(matrix); 250c6cf72381b212eb21e61d5c5e14247b483a77753bsalomon@google.com } 2516f7fbc9fbb584b9b9fa6ed3a677d71ecd49aafcebsalomon@google.com 2526f7fbc9fbb584b9b9fa6ed3a677d71ecd49aafcebsalomon@google.com /** 253ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * Sets the matrix applied to veretx positions. 254ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * 255ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * In the post-view-matrix space the rectangle [0,w]x[0,h] 256ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * fully covers the render target. (w and h are the width and height of the 257ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * the rendertarget.) 258ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * 259ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * @param m the matrix used to transform the vertex positions. 260ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com */ 2618531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com void setViewMatrix(const GrMatrix& m); 262ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 263ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com /** 264ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * Multiplies the current view matrix by a matrix 265ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * 266ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * After this call V' = V*m where V is the old view matrix, 267ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * m is the parameter to this function, and V' is the new view matrix. 268ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * (We consider positions to be column vectors so position vector p is 269ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * transformed by matrix X as p' = X*p.) 270ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * 2716f7fbc9fbb584b9b9fa6ed3a677d71ecd49aafcebsalomon@google.com * @param m the matrix used to modify the view matrix. 272ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com */ 273c6cf72381b212eb21e61d5c5e14247b483a77753bsalomon@google.com void preConcatViewMatrix(const GrMatrix& m); 274ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 275ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com /** 27606afe7b5a1ef03bfc6494c51ab2a1f7a386de5c2bsalomon@google.com * Multiplies the current view matrix by a matrix 27706afe7b5a1ef03bfc6494c51ab2a1f7a386de5c2bsalomon@google.com * 27806afe7b5a1ef03bfc6494c51ab2a1f7a386de5c2bsalomon@google.com * After this call V' = m*V where V is the old view matrix, 27906afe7b5a1ef03bfc6494c51ab2a1f7a386de5c2bsalomon@google.com * m is the parameter to this function, and V' is the new view matrix. 28006afe7b5a1ef03bfc6494c51ab2a1f7a386de5c2bsalomon@google.com * (We consider positions to be column vectors so position vector p is 28106afe7b5a1ef03bfc6494c51ab2a1f7a386de5c2bsalomon@google.com * transformed by matrix X as p' = X*p.) 28206afe7b5a1ef03bfc6494c51ab2a1f7a386de5c2bsalomon@google.com * 28306afe7b5a1ef03bfc6494c51ab2a1f7a386de5c2bsalomon@google.com * @param m the matrix used to modify the view matrix. 28406afe7b5a1ef03bfc6494c51ab2a1f7a386de5c2bsalomon@google.com */ 28506afe7b5a1ef03bfc6494c51ab2a1f7a386de5c2bsalomon@google.com void postConcatViewMatrix(const GrMatrix& m); 28606afe7b5a1ef03bfc6494c51ab2a1f7a386de5c2bsalomon@google.com 28706afe7b5a1ef03bfc6494c51ab2a1f7a386de5c2bsalomon@google.com /** 2886f7fbc9fbb584b9b9fa6ed3a677d71ecd49aafcebsalomon@google.com * Retrieves the current view matrix 2896f7fbc9fbb584b9b9fa6ed3a677d71ecd49aafcebsalomon@google.com * @return the current view matrix. 2906f7fbc9fbb584b9b9fa6ed3a677d71ecd49aafcebsalomon@google.com */ 2916f7fbc9fbb584b9b9fa6ed3a677d71ecd49aafcebsalomon@google.com const GrMatrix& getViewMatrix() const; 2926f7fbc9fbb584b9b9fa6ed3a677d71ecd49aafcebsalomon@google.com 2936f7fbc9fbb584b9b9fa6ed3a677d71ecd49aafcebsalomon@google.com /** 2946f7fbc9fbb584b9b9fa6ed3a677d71ecd49aafcebsalomon@google.com * Retrieves the inverse of the current view matrix. 2956f7fbc9fbb584b9b9fa6ed3a677d71ecd49aafcebsalomon@google.com * 2966f7fbc9fbb584b9b9fa6ed3a677d71ecd49aafcebsalomon@google.com * If the current view matrix is invertible, return true, and if matrix 2976f7fbc9fbb584b9b9fa6ed3a677d71ecd49aafcebsalomon@google.com * is non-null, copy the inverse into it. If the current view matrix is 2986f7fbc9fbb584b9b9fa6ed3a677d71ecd49aafcebsalomon@google.com * non-invertible, return false and ignore the matrix parameter. 2996f7fbc9fbb584b9b9fa6ed3a677d71ecd49aafcebsalomon@google.com * 3006f7fbc9fbb584b9b9fa6ed3a677d71ecd49aafcebsalomon@google.com * @param matrix if not null, will receive a copy of the current inverse. 3016f7fbc9fbb584b9b9fa6ed3a677d71ecd49aafcebsalomon@google.com */ 3026f7fbc9fbb584b9b9fa6ed3a677d71ecd49aafcebsalomon@google.com bool getViewInverse(GrMatrix* matrix) const; 3036f7fbc9fbb584b9b9fa6ed3a677d71ecd49aafcebsalomon@google.com 3046f7fbc9fbb584b9b9fa6ed3a677d71ecd49aafcebsalomon@google.com /** 305ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * Sets color for next draw to a premultiplied-alpha color. 306ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * 307ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * @param the color to set. 308ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com */ 309ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com void setColor(GrColor); 310ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 311ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com /** 312a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com * Gets the currently set color. 313a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com * @return the current color. 314a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com */ 315a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com GrColor getColor() const { return fCurrDrawState.fColor; } 316a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com 317a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com /** 31897c88c255cff3dbb8343c5d090526fdbedad6dd6Scroggo * Add a color filter that can be represented by a color and a mode. 31997c88c255cff3dbb8343c5d090526fdbedad6dd6Scroggo */ 32097c88c255cff3dbb8343c5d090526fdbedad6dd6Scroggo void setColorFilter(GrColor, SkXfermode::Mode); 32197c88c255cff3dbb8343c5d090526fdbedad6dd6Scroggo 32297c88c255cff3dbb8343c5d090526fdbedad6dd6Scroggo /** 323ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * Sets the color to be used for the next draw to be 324ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * (r,g,b,a) = (alpha, alpha, alpha, alpha). 325ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * 326ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * @param alpha The alpha value to set as the color. 327ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com */ 328ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com void setAlpha(uint8_t alpha); 329ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 330ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com /** 331d302f1401b3c9aea094804bad4e76de98782cfe8bsalomon@google.com * Controls whether clockwise, counterclockwise, or both faces are drawn. 332d302f1401b3c9aea094804bad4e76de98782cfe8bsalomon@google.com * @param face the face(s) to draw. 333ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com */ 3349381363050ec9d3e724076a8e9152bfa9a8de1d1tomhudson@google.com void setDrawFace(GrDrawState::DrawFace face) { 3359381363050ec9d3e724076a8e9152bfa9a8de1d1tomhudson@google.com fCurrDrawState.fDrawFace = face; 3369381363050ec9d3e724076a8e9152bfa9a8de1d1tomhudson@google.com } 337ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 338ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com /** 339f2d91557b2c353429e40aa0f87c523119002f41bbsalomon@google.com * A common pattern is to compute a color with the initial stages and then 340f2d91557b2c353429e40aa0f87c523119002f41bbsalomon@google.com * modulate that color by a coverage value in later stage(s) (AA, mask- 341f2d91557b2c353429e40aa0f87c523119002f41bbsalomon@google.com * filters, glyph mask, etc). Color-filters, xfermodes, etc should be 342f2d91557b2c353429e40aa0f87c523119002f41bbsalomon@google.com * computed based on the pre-coverage-modulated color. The division of 343f2d91557b2c353429e40aa0f87c523119002f41bbsalomon@google.com * stages between color-computing and coverage-computing is specified by 3449381363050ec9d3e724076a8e9152bfa9a8de1d1tomhudson@google.com * this method. Initially this is GrDrawState::kNumStages (all stages 3459381363050ec9d3e724076a8e9152bfa9a8de1d1tomhudson@google.com * are color-computing). 346f2d91557b2c353429e40aa0f87c523119002f41bbsalomon@google.com */ 347f2d91557b2c353429e40aa0f87c523119002f41bbsalomon@google.com void setFirstCoverageStage(int firstCoverageStage) { 348f2d91557b2c353429e40aa0f87c523119002f41bbsalomon@google.com fCurrDrawState.fFirstCoverageStage = firstCoverageStage; 349f2d91557b2c353429e40aa0f87c523119002f41bbsalomon@google.com } 350f2d91557b2c353429e40aa0f87c523119002f41bbsalomon@google.com 351f2d91557b2c353429e40aa0f87c523119002f41bbsalomon@google.com /** 352f2d91557b2c353429e40aa0f87c523119002f41bbsalomon@google.com * Gets the index of the first coverage-computing stage. 353f2d91557b2c353429e40aa0f87c523119002f41bbsalomon@google.com */ 354f2d91557b2c353429e40aa0f87c523119002f41bbsalomon@google.com int getFirstCoverageStage() const { 355f2d91557b2c353429e40aa0f87c523119002f41bbsalomon@google.com return fCurrDrawState.fFirstCoverageStage; 356f2d91557b2c353429e40aa0f87c523119002f41bbsalomon@google.com } 357f2d91557b2c353429e40aa0f87c523119002f41bbsalomon@google.com 358f2d91557b2c353429e40aa0f87c523119002f41bbsalomon@google.com /** 359d302f1401b3c9aea094804bad4e76de98782cfe8bsalomon@google.com * Gets whether the target is drawing clockwise, counterclockwise, 360d302f1401b3c9aea094804bad4e76de98782cfe8bsalomon@google.com * or both faces. 361d302f1401b3c9aea094804bad4e76de98782cfe8bsalomon@google.com * @return the current draw face(s). 362ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com */ 3639381363050ec9d3e724076a8e9152bfa9a8de1d1tomhudson@google.com GrDrawState::DrawFace getDrawFace() const { 3649381363050ec9d3e724076a8e9152bfa9a8de1d1tomhudson@google.com return fCurrDrawState.fDrawFace; 3659381363050ec9d3e724076a8e9152bfa9a8de1d1tomhudson@google.com } 366ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 367ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com /** 368ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * Enable render state settings. 369ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * 370ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * @param flags bitfield of StateBits specifing the states to enable 371ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com */ 372ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com void enableState(uint32_t stateBits); 373ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 374ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com /** 375ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * Disable render state settings. 376ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * 377ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * @param flags bitfield of StateBits specifing the states to disable 378ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com */ 379ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com void disableState(uint32_t stateBits); 380ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 381ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com bool isDitherState() const { 38286afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com return 0 != (fCurrDrawState.fFlagBits & kDither_StateBit); 38386afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com } 38486afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com 385289533ada623f2238a83771eec977f204f75994fbsalomon@google.com bool isHWAntialiasState() const { 386289533ada623f2238a83771eec977f204f75994fbsalomon@google.com return 0 != (fCurrDrawState.fFlagBits & kHWAntialias_StateBit); 38792e0f222fb311a296acd081c1216d6b9652347ebsenorblanco@chromium.org } 38892e0f222fb311a296acd081c1216d6b9652347ebsenorblanco@chromium.org 38986afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com bool isClipState() const { 39086afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com return 0 != (fCurrDrawState.fFlagBits & kClip_StateBit); 391ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com } 392ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 393d302f1401b3c9aea094804bad4e76de98782cfe8bsalomon@google.com bool isColorWriteDisabled() const { 394d302f1401b3c9aea094804bad4e76de98782cfe8bsalomon@google.com return 0 != (fCurrDrawState.fFlagBits & kNoColorWrites_StateBit); 395d302f1401b3c9aea094804bad4e76de98782cfe8bsalomon@google.com } 396d302f1401b3c9aea094804bad4e76de98782cfe8bsalomon@google.com 397ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com /** 398ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * Sets the blending function coeffecients. 399ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * 400ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * The blend function will be: 401ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * D' = sat(S*srcCoef + D*dstCoef) 402ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * 403ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * where D is the existing destination color, S is the incoming source 404ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * color, and D' is the new destination color that will be written. sat() 405ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * is the saturation function. 406ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * 407ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * @param srcCoef coeffecient applied to the src color. 408ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * @param dstCoef coeffecient applied to the dst color. 409ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com */ 410271cffc77bd2fcb3458559e509634442517ca1e9bsalomon@google.com void setBlendFunc(GrBlendCoeff srcCoeff, GrBlendCoeff dstCoeff); 411ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 412ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com /** 413080773ca79cbdc230730d295441255e9254d76a6bsalomon@google.com * Sets the blending function constant referenced by the following blending 414080773ca79cbdc230730d295441255e9254d76a6bsalomon@google.com * coeffecients: 415080773ca79cbdc230730d295441255e9254d76a6bsalomon@google.com * kConstC_BlendCoeff 416080773ca79cbdc230730d295441255e9254d76a6bsalomon@google.com * kIConstC_BlendCoeff 417080773ca79cbdc230730d295441255e9254d76a6bsalomon@google.com * kConstA_BlendCoeff 418080773ca79cbdc230730d295441255e9254d76a6bsalomon@google.com * kIConstA_BlendCoeff 419080773ca79cbdc230730d295441255e9254d76a6bsalomon@google.com * 420080773ca79cbdc230730d295441255e9254d76a6bsalomon@google.com * @param constant the constant to set 421080773ca79cbdc230730d295441255e9254d76a6bsalomon@google.com */ 422080773ca79cbdc230730d295441255e9254d76a6bsalomon@google.com void setBlendConstant(GrColor constant) { fCurrDrawState.fBlendConstant = constant; } 423080773ca79cbdc230730d295441255e9254d76a6bsalomon@google.com 424080773ca79cbdc230730d295441255e9254d76a6bsalomon@google.com /** 425080773ca79cbdc230730d295441255e9254d76a6bsalomon@google.com * Retrieves the last value set by setBlendConstant() 426080773ca79cbdc230730d295441255e9254d76a6bsalomon@google.com * @return the blending constant value 427080773ca79cbdc230730d295441255e9254d76a6bsalomon@google.com */ 428080773ca79cbdc230730d295441255e9254d76a6bsalomon@google.com GrColor getBlendConstant() const { return fCurrDrawState.fBlendConstant; } 429080773ca79cbdc230730d295441255e9254d76a6bsalomon@google.com 430080773ca79cbdc230730d295441255e9254d76a6bsalomon@google.com /** 43186c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com * Determines if blending will require a read of a dst given the current 43286c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com * state set on the draw target 433a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com * 43486c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com * @return true if the dst surface will be read at each pixel hit by the 43586c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com * a draw operation. 436a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com */ 43786c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com bool drawWillReadDst() const; 438a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com 439a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com /** 440a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com * Color alpha and coverage are two inputs to the drawing pipeline. For some 441a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com * blend modes it is safe to fold the coverage into constant or per-vertex 442a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com * color alpha value. For other blend modes they must be handled separately. 443a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com * Depending on features available in the underlying 3D API this may or may 444a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com * not be possible. 445a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com * 446a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com * This function looks at the current blend on the draw target and the draw 447a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com * target's capabilities to determine whether coverage can be handled 448a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com * correctly. 449a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com */ 450a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com bool canApplyCoverage() const; 451a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com 452a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com /** 453a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com * Determines whether incorporating partial pixel coverage into the constant 454a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com * color specified by setColor or per-vertex colors will give the right 455a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com * blending result. 456a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com */ 45786c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com bool canTweakAlphaForCoverage() const; 458a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com 459a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com /** 460a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com * Determines the interpretation per-vertex edge data when the 461a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com * kEdge_VertexLayoutBit is set (see below). When per-vertex edges are not 462a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com * specified the value of this setting has no effect. 463a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com */ 4649381363050ec9d3e724076a8e9152bfa9a8de1d1tomhudson@google.com void setVertexEdgeType(GrDrawState::VertexEdgeType type) { 465a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com fCurrDrawState.fVertexEdgeType = type; 466a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com } 467a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com 468a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com /** 469a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com * Given the current draw state, vertex layout, and hw support, will HW AA 470a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com * lines be used (if line primitive type is drawn)? (Note that lines are 471a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com * always 1 pixel wide) 472a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com */ 4739381363050ec9d3e724076a8e9152bfa9a8de1d1tomhudson@google.com bool willUseHWAALines() const; 474a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com 475a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com /** 476a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com * Sets the edge data required for edge antialiasing. 477a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com * 478a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com * @param edges 3 * 6 float values, representing the edge 479a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com * equations in Ax + By + C form 480a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com */ 4819381363050ec9d3e724076a8e9152bfa9a8de1d1tomhudson@google.com void setEdgeAAData(const GrDrawState::Edge* edges, int numEdges); 482a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com 483a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com /** 484ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * Used to save and restore the GrGpu's drawing state 485ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com */ 486ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com struct SavedDrawState { 487ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com private: 4889381363050ec9d3e724076a8e9152bfa9a8de1d1tomhudson@google.com GrDrawState fState; 489ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com friend class GrDrawTarget; 490ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com }; 491ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 492ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com /** 493ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * Saves the current draw state. The state can be restored at a later time 494ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * with restoreDrawState. 495ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * 496ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * See also AutoStateRestore class. 497ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * 498ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * @param state will hold the state after the function returns. 499ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com */ 500ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com void saveCurrentDrawState(SavedDrawState* state) const; 501ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 502ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com /** 503ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * Restores previously saved draw state. The client guarantees that state 504ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * was previously passed to saveCurrentDrawState and that the rendertarget 505ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * and texture set at save are still valid. 506ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * 507ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * See also AutoStateRestore class. 508ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * 509ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * @param state the previously saved state to restore. 510ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com */ 511ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com void restoreDrawState(const SavedDrawState& state); 512ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 513ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com /** 514ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * Copies the draw state from another target to this target. 515ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * 516ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * @param srcTarget draw target used as src of the draw state. 517ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com */ 518ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com void copyDrawState(const GrDrawTarget& srcTarget); 519ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 520ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com /** 5218531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com * The format of vertices is represented as a bitfield of flags. 5228531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com * Flags that indicate the layout of vertex data. Vertices always contain 5239381363050ec9d3e724076a8e9152bfa9a8de1d1tomhudson@google.com * positions and may also contain up to GrDrawState::kMaxTexCoords sets 5249381363050ec9d3e724076a8e9152bfa9a8de1d1tomhudson@google.com * of 2D texture * coordinates, per-vertex colors, and per-vertex coverage. 5259381363050ec9d3e724076a8e9152bfa9a8de1d1tomhudson@google.com * Each stage can 526a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com * use any of the texture coordinates as its input texture coordinates or it 527a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com * may use the positions as texture coordinates. 5288531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com * 5298531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com * If no texture coordinates are specified for a stage then the stage is 5308531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com * disabled. 531ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * 5328531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com * Only one type of texture coord can be specified per stage. For 5335782d712ffc31557d0cb12d5a220cebb783f6895bsalomon@google.com * example StageTexCoordVertexLayoutBit(0, 2) and 5348531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com * StagePosAsTexCoordVertexLayoutBit(0) cannot both be specified. 535ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * 536a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com * The order in memory is always (position, texture coord 0, ..., color, 537a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com * coverage) with any unused fields omitted. Note that this means that if 538a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com * only texture coordinates 1 is referenced then there is no texture 539a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com * coordinates 0 and the order would be (position, texture coordinate 1 540a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com * [, color][, coverage]). 5418531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com */ 5425782d712ffc31557d0cb12d5a220cebb783f6895bsalomon@google.com 5438531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com /** 5448531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com * Generates a bit indicating that a texture stage uses texture coordinates 5455782d712ffc31557d0cb12d5a220cebb783f6895bsalomon@google.com * 5468531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com * @param stage the stage that will use texture coordinates. 5478531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com * @param texCoordIdx the index of the texture coordinates to use 548ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * 5498531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com * @return the bit to add to a GrVertexLayout bitfield. 5508531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com */ 5518531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com static int StageTexCoordVertexLayoutBit(int stage, int texCoordIdx) { 5529381363050ec9d3e724076a8e9152bfa9a8de1d1tomhudson@google.com GrAssert(stage < GrDrawState::kNumStages); 5539381363050ec9d3e724076a8e9152bfa9a8de1d1tomhudson@google.com GrAssert(texCoordIdx < GrDrawState::kMaxTexCoords); 5549381363050ec9d3e724076a8e9152bfa9a8de1d1tomhudson@google.com return 1 << (stage + (texCoordIdx * GrDrawState::kNumStages)); 5558531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com } 55686afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com 5578531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.comprivate: 5589381363050ec9d3e724076a8e9152bfa9a8de1d1tomhudson@google.com static const int TEX_COORD_BIT_CNT = GrDrawState::kNumStages * 5599381363050ec9d3e724076a8e9152bfa9a8de1d1tomhudson@google.com GrDrawState::kMaxTexCoords; 56086c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com 5618531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.compublic: 5628531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com /** 5638531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com * Generates a bit indicating that a texture stage uses the position 5648531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com * as its texture coordinate. 5658531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com * 5665782d712ffc31557d0cb12d5a220cebb783f6895bsalomon@google.com * @param stage the stage that will use position as texture 5678531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com * coordinates. 5688531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com * 5698531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com * @return the bit to add to a GrVertexLayout bitfield. 5708531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com */ 5718531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com static int StagePosAsTexCoordVertexLayoutBit(int stage) { 5729381363050ec9d3e724076a8e9152bfa9a8de1d1tomhudson@google.com GrAssert(stage < GrDrawState::kNumStages); 5735782d712ffc31557d0cb12d5a220cebb783f6895bsalomon@google.com return (1 << (TEX_COORD_BIT_CNT + stage)); 5748531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com } 575a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com 5768531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.comprivate: 5779381363050ec9d3e724076a8e9152bfa9a8de1d1tomhudson@google.com static const int STAGE_BIT_CNT = TEX_COORD_BIT_CNT + 5789381363050ec9d3e724076a8e9152bfa9a8de1d1tomhudson@google.com GrDrawState::kNumStages; 5795782d712ffc31557d0cb12d5a220cebb783f6895bsalomon@google.com 5808531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.compublic: 5815782d712ffc31557d0cb12d5a220cebb783f6895bsalomon@google.com 5828531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com /** 5838531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com * Additional Bits that can be specified in GrVertexLayout. 584ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com */ 585ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com enum VertexLayoutBits { 586a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com /* vertices have colors (GrColor) */ 5878531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com kColor_VertexLayoutBit = 1 << (STAGE_BIT_CNT + 0), 588e10f6fdf76fa9b627cbb8471b58b13c457af83e8bsalomon@google.com /* vertices have coverage (GrColor where all channels should have the 589e10f6fdf76fa9b627cbb8471b58b13c457af83e8bsalomon@google.com * same value) 590e10f6fdf76fa9b627cbb8471b58b13c457af83e8bsalomon@google.com */ 591a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com kCoverage_VertexLayoutBit = 1 << (STAGE_BIT_CNT + 1), 592aeb2160b1dd34f8e640e8e56544fe407d4ff6311bsalomon@google.com /* Use text vertices. (Pos and tex coords may be a different type for 593e10f6fdf76fa9b627cbb8471b58b13c457af83e8bsalomon@google.com * text [GrGpuTextVertex vs GrPoint].) 594e10f6fdf76fa9b627cbb8471b58b13c457af83e8bsalomon@google.com */ 595a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com kTextFormat_VertexLayoutBit = 1 << (STAGE_BIT_CNT + 2), 596aeb2160b1dd34f8e640e8e56544fe407d4ff6311bsalomon@google.com 597e10f6fdf76fa9b627cbb8471b58b13c457af83e8bsalomon@google.com /* Each vertex specificies an edge. Distance to the edge is used to 598e10f6fdf76fa9b627cbb8471b58b13c457af83e8bsalomon@google.com * compute a coverage. See setVertexEdgeType(). 599e10f6fdf76fa9b627cbb8471b58b13c457af83e8bsalomon@google.com */ 600a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com kEdge_VertexLayoutBit = 1 << (STAGE_BIT_CNT + 3), 601ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com // for below assert 602d302f1401b3c9aea094804bad4e76de98782cfe8bsalomon@google.com kDummyVertexLayoutBit, 603d302f1401b3c9aea094804bad4e76de98782cfe8bsalomon@google.com kHighVertexLayoutBit = kDummyVertexLayoutBit - 1 604ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com }; 6058531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com // make sure we haven't exceeded the number of bits in GrVertexLayout. 6064be283f3a82895530d1b70372cd48ddb1c663fd8bsalomon@google.com GR_STATIC_ASSERT(kHighVertexLayoutBit < ((uint64_t)1 << 8*sizeof(GrVertexLayout))); 607ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 608ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com /** 60925fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * There are three methods for specifying geometry (vertices and optionally 6101c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com * indices) to the draw target. When indexed drawing the indices and vertices 61125fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * can use a different method. Once geometry is specified it can be used for 61225fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * multiple drawIndexed and drawNonIndexed calls. 61325fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * 61425fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * Sometimes it is necessary to perform a draw while upstack code has 61525fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * already specified geometry that it isn't finished with. There are push 61625fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * pop methods 6171c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com * 6181c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com * 1. Provide a cpu array (set*SourceToArray). This is useful when the 6191c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com * caller's client has already provided vertex data in a format 6201c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com * the time compatible with a GrVertexLayout. The array must contain the 6211c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com * data at set*SourceToArray is called. The source stays in effect for 6221c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com * drawIndexed & drawNonIndexed calls until set*SourceToArray is called 6231c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com * again or one of the other two paths is chosen. 6241c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com * 62525fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * 2. Reserve. This is most useful when the caller has data it must 62625fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * transform before drawing and is not long-lived. The caller requests 62725fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * that the draw target make room for some amount of vertex and/or index 62825fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * data. The target provides ptrs to hold the vertex and/or index data. 62925fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * 63025fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * The data is writable up until the next drawIndexed, drawNonIndexed, 63125fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * or pushGeometrySource At this point the data is frozen and the ptrs 63225fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * are no longer valid. 6331c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com * 6341c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com * 3. Vertex and Index Buffers. This is most useful for geometry that will 63525fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * is long-lived. SetVertexSourceToBuffer and SetIndexSourceToBuffer are 63625fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * used to set the buffer and subsequent drawIndexed and drawNonIndexed 63725fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * calls use this source until another source is set. 6381c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com */ 6391c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com 6401c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com /** 64125fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * Reserves space for vertices. Draw target will use reserved vertices at 64225fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * at the next draw. 643ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * 644ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * If succeeds: 64525fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * if vertexCount > 0, *vertices will be the array 646ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * of vertices to be filled by caller. The next draw will read 647ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * these vertices. 648ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * 6491c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com * If a client does not already have a vertex buffer then this is the 65025fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * preferred way to allocate vertex data. It allows the subclass of 6511c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com * GrDrawTarget to decide whether to put data in buffers, to group vertex 6521c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com * data that uses the same state (e.g. for deferred rendering), etc. 653ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * 65425fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * After the next draw or pushGeometrySource the vertices ptr is no longer 65525fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * valid and the geometry data cannot be further modified. The contents 65625fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * that were put in the reserved space can be drawn by multiple draws, 65725fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * however. 6581c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com * 659ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * @param vertexLayout the format of vertices (ignored if vertexCount == 0). 66025fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * @param vertexCount the number of vertices to reserve space for. Can be 0. 661ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * @param vertices will point to reserved vertex space if vertexCount is 662ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * non-zero. Illegal to pass NULL if vertexCount > 0. 663ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * 664ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * @return true if succeeded in allocating space for the vertices and false 665ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * if not. 666ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com */ 66725fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com bool reserveVertexSpace(GrVertexLayout vertexLayout, 66825fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com int vertexCount, 66925fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com void** vertices); 67025fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com /** 67125fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * Reserves space for indices. Draw target will use the reserved indices at 67225fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * the next indexed draw. 67325fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * 67425fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * If succeeds: 67525fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * if indexCount > 0, *indices will be the array 67625fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * of indices to be filled by caller. The next draw will read 67725fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * these indices. 67825fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * 67925fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * If a client does not already have a index buffer then this is the 68025fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * preferred way to allocate index data. It allows the subclass of 68125fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * GrDrawTarget to decide whether to put data in buffers, to group index 68225fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * data that uses the same state (e.g. for deferred rendering), etc. 68325fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * 68425fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * After the next indexed draw or pushGeometrySource the indices ptr is no 68525fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * longer valid and the geometry data cannot be further modified. The 68625fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * contents that were put in the reserved space can be drawn by multiple 68725fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * draws, however. 68825fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * 68925fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * @param indexCount the number of indices to reserve space for. Can be 0. 69025fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * @param indices will point to reserved index space if indexCount is 69125fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * non-zero. Illegal to pass NULL if indexCount > 0. 69225fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com */ 69325fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com 69425fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com bool reserveIndexSpace(int indexCount, void** indices); 695ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com /** 696ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * Provides hints to caller about the number of vertices and indices 697ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * that can be allocated cheaply. This can be useful if caller is reserving 698ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * space but doesn't know exactly how much geometry is needed. 699ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * 700ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * Also may hint whether the draw target should be flushed first. This is 701ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * useful for deferred targets. 702ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * 703ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * @param vertexLayout layout of vertices caller would like to reserve 704ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * @param vertexCount in: hint about how many vertices the caller would 705ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * like to allocate. 706ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * out: a hint about the number of vertices that can be 707ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * allocated cheaply. Negative means no hint. 708ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * Ignored if NULL. 709ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * @param indexCount in: hint about how many indices the caller would 710ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * like to allocate. 711ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * out: a hint about the number of indices that can be 712ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * allocated cheaply. Negative means no hint. 713ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * Ignored if NULL. 714ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * 715ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * @return true if target should be flushed based on the input values. 716ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com */ 717ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com virtual bool geometryHints(GrVertexLayout vertexLayout, 7181c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com int* vertexCount, 7191c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com int* indexCount) const; 720ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 721ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com /** 7221c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com * Sets source of vertex data for the next draw. Array must contain 7231c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com * the vertex data when this is called. 724ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * 725ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * @param array cpu array containing vertex data. 7261c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com * @param size size of the vertex data. 7271c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com * @param vertexCount the number of vertices in the array. 728ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com */ 7291c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com void setVertexSourceToArray(GrVertexLayout vertexLayout, 7301c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com const void* vertexArray, 7311c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com int vertexCount); 732ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 733ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com /** 7341c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com * Sets source of index data for the next indexed draw. Array must contain 7351c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com * the indices when this is called. 736ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * 7371c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com * @param array cpu array containing index data. 7381c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com * @param indexCount the number of indices in the array. 739ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com */ 7401c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com void setIndexSourceToArray(const void* indexArray, int indexCount); 741ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 742ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com /** 743ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * Sets source of vertex data for the next draw. Data does not have to be 744ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * in the buffer until drawIndexed or drawNonIndexed. 745ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * 746ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * @param buffer vertex buffer containing vertex data. Must be 747ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * unlocked before draw call. 748ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * @param vertexLayout layout of the vertex data in the buffer. 749ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com */ 7501c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com void setVertexSourceToBuffer(GrVertexLayout vertexLayout, 7511c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com const GrVertexBuffer* buffer); 752ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 753ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com /** 754ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * Sets source of index data for the next indexed draw. Data does not have 755ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * to be in the buffer until drawIndexed or drawNonIndexed. 756ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * 757ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * @param buffer index buffer containing indices. Must be unlocked 758ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * before indexed draw call. 759ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com */ 760ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com void setIndexSourceToBuffer(const GrIndexBuffer* buffer); 76125fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com 76225fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com /** 76325fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * Resets vertex source. Drawing from reset vertices is illegal. Set vertex 76425fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * source to reserved, array, or buffer before next draw. May be able to free 76525fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * up temporary storage allocated by setVertexSourceToArray or 76625fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * reserveVertexSpace. 76725fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com */ 76825fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com void resetVertexSource(); 76925fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com 77025fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com /** 77125fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * Resets index source. Indexed Drawing from reset indices is illegal. Set 77225fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * index source to reserved, array, or buffer before next indexed draw. May 77325fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * be able to free up temporary storage allocated by setIndexSourceToArray 77425fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * or reserveIndexSpace. 77525fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com */ 77625fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com void resetIndexSource(); 777ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 778ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com /** 77925fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * Pushes and resets the vertex/index sources. Any reserved vertex / index 78025fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * data is finalized (i.e. cannot be updated after the matching pop but can 78125fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * be drawn from). Must be balanced by a pop. 78225fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com */ 78325fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com void pushGeometrySource(); 78425fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com 78525fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com /** 78625fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * Pops the vertex / index sources from the matching push. 78725fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com */ 78825fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com void popGeometrySource(); 78925fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com 79025fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com /** 791ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * Draws indexed geometry using the current state and current vertex / index 792ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * sources. 793ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * 794ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * @param type The type of primitives to draw. 795ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * @param startVertex the vertex in the vertex array/buffer corresponding 796ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * to index 0 797ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * @param startIndex first index to read from index src. 798ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * @param vertexCount one greater than the max index. 799ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * @param indexCount the number of index elements to read. The index count 800ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * is effectively trimmed to the last completely 801ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * specified primitive. 802ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com */ 80325fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com void drawIndexed(GrPrimitiveType type, 80425fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com int startVertex, 80525fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com int startIndex, 80625fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com int vertexCount, 80725fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com int indexCount); 808ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 809ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com /** 810ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * Draws non-indexed geometry using the current state and current vertex 811ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * sources. 812ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * 813ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * @param type The type of primitives to draw. 814ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * @param startVertex the vertex in the vertex array/buffer corresponding 815ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * to index 0 816ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * @param vertexCount one greater than the max index. 817ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com */ 81825fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com void drawNonIndexed(GrPrimitiveType type, 81925fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com int startVertex, 82025fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com int vertexCount); 821ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 82286afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com /** 82386afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com * Helper function for drawing rects. This does not use the current index 82486afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com * and vertex sources. After returning, the vertex and index sources may 82586afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com * have changed. They should be reestablished before the next drawIndexed 82686afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com * or drawNonIndexed. This cannot be called between reserving and releasing 82786afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com * geometry. The GrDrawTarget subclass may be able to perform additional 828d302f1401b3c9aea094804bad4e76de98782cfe8bsalomon@google.com * optimizations if drawRect is used rather than drawIndexed or 82986afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com * drawNonIndexed. 83086afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com * @param rect the rect to draw 83186afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com * @param matrix optional matrix applied to rect (before viewMatrix) 832ffca400ef6f96a280c3e2c09210f950af64a1f24bsalomon@google.com * @param stageEnableBitfield bitmask indicating which stages are enabled. 833ffca400ef6f96a280c3e2c09210f950af64a1f24bsalomon@google.com * Bit i indicates whether stage i is enabled. 83486afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com * @param srcRects specifies rects for stages enabled by stageEnableMask. 83586afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com * if stageEnableMask bit i is 1, srcRects is not NULL, 83686afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com * and srcRects[i] is not NULL, then srcRects[i] will be 83786afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com * used as coordinates for stage i. Otherwise, if stage i 83886afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com * is enabled then rect is used as the coordinates. 83986afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com * @param srcMatrices optional matrices applied to srcRects. If 84086afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com * srcRect[i] is non-NULL and srcMatrices[i] is 84186afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com * non-NULL then srcRect[i] will be transformed by 84286afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com * srcMatrix[i]. srcMatrices can be NULL when no 84386afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com * srcMatrices are desired. 84486afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com */ 845d302f1401b3c9aea094804bad4e76de98782cfe8bsalomon@google.com virtual void drawRect(const GrRect& rect, 84686afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com const GrMatrix* matrix, 847ffca400ef6f96a280c3e2c09210f950af64a1f24bsalomon@google.com StageBitfield stageEnableBitfield, 84886afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com const GrRect* srcRects[], 84986afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com const GrMatrix* srcMatrices[]); 85086afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com 85186afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com /** 852d302f1401b3c9aea094804bad4e76de98782cfe8bsalomon@google.com * Helper for drawRect when the caller doesn't need separate src rects or 85386afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com * matrices. 85486afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com */ 855d302f1401b3c9aea094804bad4e76de98782cfe8bsalomon@google.com void drawSimpleRect(const GrRect& rect, 856d302f1401b3c9aea094804bad4e76de98782cfe8bsalomon@google.com const GrMatrix* matrix, 857ffca400ef6f96a280c3e2c09210f950af64a1f24bsalomon@google.com StageBitfield stageEnableBitfield) { 858ffca400ef6f96a280c3e2c09210f950af64a1f24bsalomon@google.com drawRect(rect, matrix, stageEnableBitfield, NULL, NULL); 85986afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com } 86086afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com 8610b335c1ac100aeacf79a4c98a052286fd46661e7bsalomon@google.com /** 8626aa25c3f555dc2a6711365d14279db3ec909e064bsalomon@google.com * Clear the render target. Ignores the clip and all other draw state 8636aa25c3f555dc2a6711365d14279db3ec909e064bsalomon@google.com * (blend mode, stages, etc). Clears the whole thing if rect is NULL, 8646aa25c3f555dc2a6711365d14279db3ec909e064bsalomon@google.com * otherwise just the rect. 8650b335c1ac100aeacf79a4c98a052286fd46661e7bsalomon@google.com */ 8666aa25c3f555dc2a6711365d14279db3ec909e064bsalomon@google.com virtual void clear(const GrIRect* rect, GrColor color) = 0; 8670b335c1ac100aeacf79a4c98a052286fd46661e7bsalomon@google.com 868ef3913bcbff265ff86116ae4f3dd2768dc42cccasenorblanco@chromium.org /** 869ef3913bcbff265ff86116ae4f3dd2768dc42cccasenorblanco@chromium.org * Returns the maximum number of edges that may be specified in a single 870ef3913bcbff265ff86116ae4f3dd2768dc42cccasenorblanco@chromium.org * draw call when performing edge antialiasing. This is usually limited 871ef3913bcbff265ff86116ae4f3dd2768dc42cccasenorblanco@chromium.org * by the number of fragment uniforms which may be uploaded. Must be a 872ef3913bcbff265ff86116ae4f3dd2768dc42cccasenorblanco@chromium.org * minimum of six, since a triangle's vertices each belong to two boundary 873ef3913bcbff265ff86116ae4f3dd2768dc42cccasenorblanco@chromium.org * edges which may be distinct. 874ef3913bcbff265ff86116ae4f3dd2768dc42cccasenorblanco@chromium.org */ 875ef3913bcbff265ff86116ae4f3dd2768dc42cccasenorblanco@chromium.org virtual int getMaxEdges() const { return 6; } 876ef3913bcbff265ff86116ae4f3dd2768dc42cccasenorblanco@chromium.org 87725fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com //////////////////////////////////////////////////////////////////////////// 878ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 879ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com class AutoStateRestore : ::GrNoncopyable { 880ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com public: 88106afe7b5a1ef03bfc6494c51ab2a1f7a386de5c2bsalomon@google.com AutoStateRestore(); 882ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com AutoStateRestore(GrDrawTarget* target); 883ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com ~AutoStateRestore(); 884ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 88506afe7b5a1ef03bfc6494c51ab2a1f7a386de5c2bsalomon@google.com /** 88606afe7b5a1ef03bfc6494c51ab2a1f7a386de5c2bsalomon@google.com * if this object is already saving state for param target then 88706afe7b5a1ef03bfc6494c51ab2a1f7a386de5c2bsalomon@google.com * this does nothing. Otherise, it restores previously saved state on 88806afe7b5a1ef03bfc6494c51ab2a1f7a386de5c2bsalomon@google.com * previous target (if any) and saves current state on param target. 88906afe7b5a1ef03bfc6494c51ab2a1f7a386de5c2bsalomon@google.com */ 89006afe7b5a1ef03bfc6494c51ab2a1f7a386de5c2bsalomon@google.com void set(GrDrawTarget* target); 89106afe7b5a1ef03bfc6494c51ab2a1f7a386de5c2bsalomon@google.com 892ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com private: 893ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com GrDrawTarget* fDrawTarget; 894ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com SavedDrawState fDrawState; 895ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com }; 896ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 89725fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com //////////////////////////////////////////////////////////////////////////// 8981c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com 8996f7fbc9fbb584b9b9fa6ed3a677d71ecd49aafcebsalomon@google.com class AutoViewMatrixRestore : ::GrNoncopyable { 9006f7fbc9fbb584b9b9fa6ed3a677d71ecd49aafcebsalomon@google.com public: 9016f7fbc9fbb584b9b9fa6ed3a677d71ecd49aafcebsalomon@google.com AutoViewMatrixRestore() { 9026f7fbc9fbb584b9b9fa6ed3a677d71ecd49aafcebsalomon@google.com fDrawTarget = NULL; 9036f7fbc9fbb584b9b9fa6ed3a677d71ecd49aafcebsalomon@google.com } 9046f7fbc9fbb584b9b9fa6ed3a677d71ecd49aafcebsalomon@google.com 9051c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com AutoViewMatrixRestore(GrDrawTarget* target) 9066f7fbc9fbb584b9b9fa6ed3a677d71ecd49aafcebsalomon@google.com : fDrawTarget(target), fMatrix(fDrawTarget->getViewMatrix()) { 9076f7fbc9fbb584b9b9fa6ed3a677d71ecd49aafcebsalomon@google.com GrAssert(NULL != target); 9086f7fbc9fbb584b9b9fa6ed3a677d71ecd49aafcebsalomon@google.com } 9096f7fbc9fbb584b9b9fa6ed3a677d71ecd49aafcebsalomon@google.com 9106f7fbc9fbb584b9b9fa6ed3a677d71ecd49aafcebsalomon@google.com void set(GrDrawTarget* target) { 9116f7fbc9fbb584b9b9fa6ed3a677d71ecd49aafcebsalomon@google.com GrAssert(NULL != target); 9126f7fbc9fbb584b9b9fa6ed3a677d71ecd49aafcebsalomon@google.com if (NULL != fDrawTarget) { 9136f7fbc9fbb584b9b9fa6ed3a677d71ecd49aafcebsalomon@google.com fDrawTarget->setViewMatrix(fMatrix); 9146f7fbc9fbb584b9b9fa6ed3a677d71ecd49aafcebsalomon@google.com } 9156f7fbc9fbb584b9b9fa6ed3a677d71ecd49aafcebsalomon@google.com fDrawTarget = target; 9166f7fbc9fbb584b9b9fa6ed3a677d71ecd49aafcebsalomon@google.com fMatrix = target->getViewMatrix(); 9176f7fbc9fbb584b9b9fa6ed3a677d71ecd49aafcebsalomon@google.com } 9186f7fbc9fbb584b9b9fa6ed3a677d71ecd49aafcebsalomon@google.com 9196f7fbc9fbb584b9b9fa6ed3a677d71ecd49aafcebsalomon@google.com ~AutoViewMatrixRestore() { 9206f7fbc9fbb584b9b9fa6ed3a677d71ecd49aafcebsalomon@google.com if (NULL != fDrawTarget) { 9216f7fbc9fbb584b9b9fa6ed3a677d71ecd49aafcebsalomon@google.com fDrawTarget->setViewMatrix(fMatrix); 9226f7fbc9fbb584b9b9fa6ed3a677d71ecd49aafcebsalomon@google.com } 9236f7fbc9fbb584b9b9fa6ed3a677d71ecd49aafcebsalomon@google.com } 9246f7fbc9fbb584b9b9fa6ed3a677d71ecd49aafcebsalomon@google.com 9256f7fbc9fbb584b9b9fa6ed3a677d71ecd49aafcebsalomon@google.com private: 9266f7fbc9fbb584b9b9fa6ed3a677d71ecd49aafcebsalomon@google.com GrDrawTarget* fDrawTarget; 9276f7fbc9fbb584b9b9fa6ed3a677d71ecd49aafcebsalomon@google.com GrMatrix fMatrix; 9286f7fbc9fbb584b9b9fa6ed3a677d71ecd49aafcebsalomon@google.com }; 9296f7fbc9fbb584b9b9fa6ed3a677d71ecd49aafcebsalomon@google.com 93025fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com //////////////////////////////////////////////////////////////////////////// 931ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 9327ac249bdc7a86bc44610e02abeeaa0c14ba8163absalomon@google.com /** 9337ac249bdc7a86bc44610e02abeeaa0c14ba8163absalomon@google.com * Sets the view matrix to I and preconcats all stage matrices enabled in 9347ac249bdc7a86bc44610e02abeeaa0c14ba8163absalomon@google.com * mask by the view inverse. Destructor undoes these changes. 9357ac249bdc7a86bc44610e02abeeaa0c14ba8163absalomon@google.com */ 9367ac249bdc7a86bc44610e02abeeaa0c14ba8163absalomon@google.com class AutoDeviceCoordDraw : ::GrNoncopyable { 9377ac249bdc7a86bc44610e02abeeaa0c14ba8163absalomon@google.com public: 9387ac249bdc7a86bc44610e02abeeaa0c14ba8163absalomon@google.com AutoDeviceCoordDraw(GrDrawTarget* target, int stageMask); 9397ac249bdc7a86bc44610e02abeeaa0c14ba8163absalomon@google.com ~AutoDeviceCoordDraw(); 9407ac249bdc7a86bc44610e02abeeaa0c14ba8163absalomon@google.com private: 9417ac249bdc7a86bc44610e02abeeaa0c14ba8163absalomon@google.com GrDrawTarget* fDrawTarget; 9427ac249bdc7a86bc44610e02abeeaa0c14ba8163absalomon@google.com GrMatrix fViewMatrix; 9439381363050ec9d3e724076a8e9152bfa9a8de1d1tomhudson@google.com GrMatrix fSamplerMatrices[GrDrawState::kNumStages]; 9447ac249bdc7a86bc44610e02abeeaa0c14ba8163absalomon@google.com int fStageMask; 9457ac249bdc7a86bc44610e02abeeaa0c14ba8163absalomon@google.com }; 9467ac249bdc7a86bc44610e02abeeaa0c14ba8163absalomon@google.com 94725fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com //////////////////////////////////////////////////////////////////////////// 9487ac249bdc7a86bc44610e02abeeaa0c14ba8163absalomon@google.com 949ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com class AutoReleaseGeometry : ::GrNoncopyable { 950ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com public: 951ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com AutoReleaseGeometry(GrDrawTarget* target, 952ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com GrVertexLayout vertexLayout, 95325fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com int vertexCount, 95425fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com int indexCount); 95525fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com AutoReleaseGeometry(); 95625fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com ~AutoReleaseGeometry(); 9575782d712ffc31557d0cb12d5a220cebb783f6895bsalomon@google.com bool set(GrDrawTarget* target, 9585782d712ffc31557d0cb12d5a220cebb783f6895bsalomon@google.com GrVertexLayout vertexLayout, 95925fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com int vertexCount, 96025fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com int indexCount); 961a47a48dca5045d71cbc5de343404045209a13e15bsalomon@google.com bool succeeded() const { return NULL != fTarget; } 9626513cd06ae34f5d777b3aaea0b4533014d0a10f2bsalomon@google.com void* vertices() const { GrAssert(this->succeeded()); return fVertices; } 9636513cd06ae34f5d777b3aaea0b4533014d0a10f2bsalomon@google.com void* indices() const { GrAssert(this->succeeded()); return fIndices; } 964ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com GrPoint* positions() const { 9656513cd06ae34f5d777b3aaea0b4533014d0a10f2bsalomon@google.com return static_cast<GrPoint*>(this->vertices()); 966ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com } 967ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 968ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com private: 96925fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com void reset(); 97025fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com 971ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com GrDrawTarget* fTarget; 972ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com void* fVertices; 973ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com void* fIndices; 974ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com }; 975ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 97625fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com //////////////////////////////////////////////////////////////////////////// 977ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 978ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com class AutoClipRestore : ::GrNoncopyable { 979ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com public: 980ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com AutoClipRestore(GrDrawTarget* target) { 981ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com fTarget = target; 982ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com fClip = fTarget->getClip(); 983ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com } 984ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 985ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com ~AutoClipRestore() { 986ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com fTarget->setClip(fClip); 987ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com } 988ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com private: 989ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com GrDrawTarget* fTarget; 990ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com GrClip fClip; 991ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com }; 99225fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com 99325fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com //////////////////////////////////////////////////////////////////////////// 99425fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com 99525fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com class AutoGeometryPush : ::GrNoncopyable { 99625fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com public: 99725fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com AutoGeometryPush(GrDrawTarget* target) { 99825fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com GrAssert(NULL != target); 99925fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com fTarget = target; 100025fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com target->pushGeometrySource(); 100125fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com } 100225fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com ~AutoGeometryPush() { 100325fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com fTarget->popGeometrySource(); 100425fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com } 100525fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com private: 100625fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com GrDrawTarget* fTarget; 100725fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com }; 1008ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 1009ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com //////////////////////////////////////////////////////////////////////////// 10108531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com // Helpers for picking apart vertex layouts 10115782d712ffc31557d0cb12d5a220cebb783f6895bsalomon@google.com 1012ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com /** 1013ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * Helper function to compute the size of a vertex from a vertex layout 1014ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * @return size of a single vertex. 1015ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com */ 1016ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com static size_t VertexSize(GrVertexLayout vertexLayout); 10175782d712ffc31557d0cb12d5a220cebb783f6895bsalomon@google.com 10188531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com /** 10198531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com * Helper function for determining the index of texture coordinates that 10208531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com * is input for a texture stage. Note that a stage may instead use positions 10218531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com * as texture coordinates, in which case the result of the function is 10228531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com * indistinguishable from the case when the stage is disabled. 10238531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com * 10248531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com * @param stage the stage to query 10258531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com * @param vertexLayout layout to query 10268531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com * 10278531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com * @return the texture coordinate index or -1 if the stage doesn't use 10288531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com * separate (non-position) texture coordinates. 10298531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com */ 10308531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com static int VertexTexCoordsForStage(int stage, GrVertexLayout vertexLayout); 1031ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 1032ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com /** 1033ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * Helper function to compute the offset of texture coordinates in a vertex 1034ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * @return offset of texture coordinates in vertex layout or -1 if the 10355782d712ffc31557d0cb12d5a220cebb783f6895bsalomon@google.com * layout has no texture coordinates. Will be 0 if positions are 10368531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com * used as texture coordinates for the stage. 1037ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com */ 10388531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com static int VertexStageCoordOffset(int stage, GrVertexLayout vertexLayout); 1039ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 1040ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com /** 1041ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * Helper function to compute the offset of the color in a vertex 1042ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * @return offset of color in vertex layout or -1 if the 1043ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * layout has no color. 1044ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com */ 1045ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com static int VertexColorOffset(GrVertexLayout vertexLayout); 1046ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 1047a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com /** 1048a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com * Helper function to compute the offset of the coverage in a vertex 1049a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com * @return offset of coverage in vertex layout or -1 if the 1050a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com * layout has no coverage. 1051a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com */ 1052a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com static int VertexCoverageOffset(GrVertexLayout vertexLayout); 1053a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com 1054aeb2160b1dd34f8e640e8e56544fe407d4ff6311bsalomon@google.com /** 1055aeb2160b1dd34f8e640e8e56544fe407d4ff6311bsalomon@google.com * Helper function to compute the offset of the edge pts in a vertex 1056aeb2160b1dd34f8e640e8e56544fe407d4ff6311bsalomon@google.com * @return offset of edge in vertex layout or -1 if the 1057aeb2160b1dd34f8e640e8e56544fe407d4ff6311bsalomon@google.com * layout has no edge. 1058aeb2160b1dd34f8e640e8e56544fe407d4ff6311bsalomon@google.com */ 1059aeb2160b1dd34f8e640e8e56544fe407d4ff6311bsalomon@google.com static int VertexEdgeOffset(GrVertexLayout vertexLayout); 1060aeb2160b1dd34f8e640e8e56544fe407d4ff6311bsalomon@google.com 1061ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com /** 10625782d712ffc31557d0cb12d5a220cebb783f6895bsalomon@google.com * Helper function to determine if vertex layout contains explicit texture 10638531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com * coordinates of some index. 10648531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com * 10658531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com * @param coordIndex the tex coord index to query 10668531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com * @param vertexLayout layout to query 10678531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com * 10685782d712ffc31557d0cb12d5a220cebb783f6895bsalomon@google.com * @return true if vertex specifies texture coordinates for the index, 10698531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com * false otherwise. 1070ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com */ 10715782d712ffc31557d0cb12d5a220cebb783f6895bsalomon@google.com static bool VertexUsesTexCoordIdx(int coordIndex, 10728531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com GrVertexLayout vertexLayout); 10735782d712ffc31557d0cb12d5a220cebb783f6895bsalomon@google.com 1074ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com /** 1075ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * Helper function to determine if vertex layout contains either explicit or 10768531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com * implicit texture coordinates for a stage. 1077ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * 10788531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com * @param stage the stage to query 10798531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com * @param vertexLayout layout to query 10808531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com * 10815782d712ffc31557d0cb12d5a220cebb783f6895bsalomon@google.com * @return true if vertex specifies texture coordinates for the stage, 10828531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com * false otherwise. 1083ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com */ 10848531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com static bool VertexUsesStage(int stage, GrVertexLayout vertexLayout); 1085ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 10868531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com /** 10875782d712ffc31557d0cb12d5a220cebb783f6895bsalomon@google.com * Helper function to compute the size of each vertex and the offsets of 10885782d712ffc31557d0cb12d5a220cebb783f6895bsalomon@google.com * texture coordinates and color. Determines tex coord offsets by tex coord 10895782d712ffc31557d0cb12d5a220cebb783f6895bsalomon@google.com * index rather than by stage. (Each stage can be mapped to any t.c. index 10908531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com * by StageTexCoordVertexLayoutBit.) 10918531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com * 10928531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com * @param vertexLayout the layout to query 10938531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com * @param texCoordOffsetsByIdx after return it is the offset of each 10948531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com * tex coord index in the vertex or -1 if 1095a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com * index isn't used. (optional) 1096a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com * @param colorOffset after return it is the offset of the 1097a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com * color field in each vertex, or -1 if 1098a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com * there aren't per-vertex colors. (optional) 1099a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com * @param coverageOffset after return it is the offset of the 1100a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com * coverage field in each vertex, or -1 if 1101a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com * there aren't per-vertex coeverages. 1102a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com * (optional) 1103a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com * @param edgeOffset after return it is the offset of the 1104a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com * edge eq field in each vertex, or -1 if 1105a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com * there aren't per-vertex edge equations. 1106a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com * (optional) 11078531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com * @return size of a single vertex 11088531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com */ 11098531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com static int VertexSizeAndOffsetsByIdx(GrVertexLayout vertexLayout, 11109381363050ec9d3e724076a8e9152bfa9a8de1d1tomhudson@google.com int texCoordOffsetsByIdx[GrDrawState::kMaxTexCoords], 11119381363050ec9d3e724076a8e9152bfa9a8de1d1tomhudson@google.com int *colorOffset, 11129381363050ec9d3e724076a8e9152bfa9a8de1d1tomhudson@google.com int *coverageOffset, 11139381363050ec9d3e724076a8e9152bfa9a8de1d1tomhudson@google.com int* edgeOffset); 11145782d712ffc31557d0cb12d5a220cebb783f6895bsalomon@google.com 11158531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com /** 11165782d712ffc31557d0cb12d5a220cebb783f6895bsalomon@google.com * Helper function to compute the size of each vertex and the offsets of 11175782d712ffc31557d0cb12d5a220cebb783f6895bsalomon@google.com * texture coordinates and color. Determines tex coord offsets by stage 11185782d712ffc31557d0cb12d5a220cebb783f6895bsalomon@google.com * rather than by index. (Each stage can be mapped to any t.c. index 11195782d712ffc31557d0cb12d5a220cebb783f6895bsalomon@google.com * by StageTexCoordVertexLayoutBit.) If a stage uses positions for 11208531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com * tex coords then that stage's offset will be 0 (positions are always at 0). 11218531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com * 11228531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com * @param vertexLayout the layout to query 11238531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com * @param texCoordOffsetsByStage after return it is the offset of each 11248531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com * tex coord index in the vertex or -1 if 1125a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com * index isn't used. (optional) 1126a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com * @param colorOffset after return it is the offset of the 1127a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com * color field in each vertex, or -1 if 1128a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com * there aren't per-vertex colors. 1129a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com * (optional) 1130a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com * @param coverageOffset after return it is the offset of the 1131a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com * coverage field in each vertex, or -1 if 1132a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com * there aren't per-vertex coeverages. 1133a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com * (optional) 1134a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com * @param edgeOffset after return it is the offset of the 1135a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com * edge eq field in each vertex, or -1 if 1136a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com * there aren't per-vertex edge equations. 1137a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com * (optional) 11388531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com * @return size of a single vertex 11398531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com */ 11408531c1cea2a9cf7702ef314ccd0a6cd1dd33c76cbsalomon@google.com static int VertexSizeAndOffsetsByStage(GrVertexLayout vertexLayout, 11419381363050ec9d3e724076a8e9152bfa9a8de1d1tomhudson@google.com int texCoordOffsetsByStage[GrDrawState::kNumStages], 11429381363050ec9d3e724076a8e9152bfa9a8de1d1tomhudson@google.com int* colorOffset, 11439381363050ec9d3e724076a8e9152bfa9a8de1d1tomhudson@google.com int* coverageOffset, 11449381363050ec9d3e724076a8e9152bfa9a8de1d1tomhudson@google.com int* edgeOffset); 114586afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com 114686afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com /** 114786afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com * Accessing positions, texture coords, or colors, of a vertex within an 114886afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com * array is a hassle involving casts and simple math. These helpers exist 114986afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com * to keep GrDrawTarget clients' code a bit nicer looking. 115086afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com */ 115186afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com 115286afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com /** 115386afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com * Gets a pointer to a GrPoint of a vertex's position or texture 115486afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com * coordinate. 115586afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com * @param vertices the vetex array 115686afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com * @param vertexIndex the index of the vertex in the array 115786afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com * @param vertexSize the size of each vertex in the array 115886afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com * @param offset the offset in bytes of the vertex component. 115986afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com * Defaults to zero (corresponding to vertex position) 116086afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com * @return pointer to the vertex component as a GrPoint 116186afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com */ 1162d302f1401b3c9aea094804bad4e76de98782cfe8bsalomon@google.com static GrPoint* GetVertexPoint(void* vertices, 116386afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com int vertexIndex, 116486afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com int vertexSize, 116586afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com int offset = 0) { 116686afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com intptr_t start = GrTCast<intptr_t>(vertices); 1167d302f1401b3c9aea094804bad4e76de98782cfe8bsalomon@google.com return GrTCast<GrPoint*>(start + offset + 116886afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com vertexIndex * vertexSize); 116986afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com } 117086afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com static const GrPoint* GetVertexPoint(const void* vertices, 117186afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com int vertexIndex, 1172d302f1401b3c9aea094804bad4e76de98782cfe8bsalomon@google.com int vertexSize, 117386afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com int offset = 0) { 117486afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com intptr_t start = GrTCast<intptr_t>(vertices); 1175d302f1401b3c9aea094804bad4e76de98782cfe8bsalomon@google.com return GrTCast<const GrPoint*>(start + offset + 117686afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com vertexIndex * vertexSize); 117786afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com } 117886afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com 117986afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com /** 118086afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com * Gets a pointer to a GrColor inside a vertex within a vertex array. 118186afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com * @param vertices the vetex array 118286afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com * @param vertexIndex the index of the vertex in the array 118386afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com * @param vertexSize the size of each vertex in the array 118486afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com * @param offset the offset in bytes of the vertex color 118586afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com * @return pointer to the vertex component as a GrColor 118686afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com */ 1187d302f1401b3c9aea094804bad4e76de98782cfe8bsalomon@google.com static GrColor* GetVertexColor(void* vertices, 118886afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com int vertexIndex, 118986afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com int vertexSize, 119086afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com int offset) { 119186afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com intptr_t start = GrTCast<intptr_t>(vertices); 1192d302f1401b3c9aea094804bad4e76de98782cfe8bsalomon@google.com return GrTCast<GrColor*>(start + offset + 119386afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com vertexIndex * vertexSize); 119486afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com } 119586afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com static const GrColor* GetVertexColor(const void* vertices, 119686afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com int vertexIndex, 1197d302f1401b3c9aea094804bad4e76de98782cfe8bsalomon@google.com int vertexSize, 119886afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com int offset) { 119986afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com const intptr_t start = GrTCast<intptr_t>(vertices); 1200d302f1401b3c9aea094804bad4e76de98782cfe8bsalomon@google.com return GrTCast<const GrColor*>(start + offset + 120186afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com vertexIndex * vertexSize); 120286afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com } 120386afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com 12045aaa69e4339e229adfb05e96084a8ec0a590238bbsalomon@google.com static void VertexLayoutUnitTest(); 12055aaa69e4339e229adfb05e96084a8ec0a590238bbsalomon@google.com 1206ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.comprotected: 1207471d471dcd7422e5dd9c822c1092b2ba4721dcfebsalomon@google.com 120886c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com /** 120986c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com * Optimizations for blending / coverage to be applied based on the current 121086c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com * state. 121186c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com * Subclasses that actually draw (as opposed to those that just buffer for 121286c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com * playback) must implement the flags that replace the output color. 121386c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com */ 121486c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com enum BlendOptFlags { 121586c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com /** 121686c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com * No optimization 121786c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com */ 121886c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com kNone_BlendOpt = 0, 121986c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com /** 122086c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com * Don't draw at all 122186c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com */ 122286c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com kSkipDraw_BlendOptFlag = 0x2, 122386c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com /** 122486c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com * Emit the src color, disable HW blending (replace dst with src) 122586c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com */ 122686c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com kDisableBlend_BlendOptFlag = 0x4, 122786c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com /** 122886c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com * The coverage value does not have to be computed separately from 122986c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com * alpha, the the output color can be the modulation of the two. 123086c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com */ 123186c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com kCoverageAsAlpha_BlendOptFlag = 0x1, 123286c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com /** 123386c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com * Instead of emitting a src color, emit coverage in the alpha channel 123486c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com * and r,g,b are "don't cares". 123586c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com */ 123686c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com kEmitCoverage_BlendOptFlag = 0x10, 123786c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com /** 123886c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com * Emit transparent black instead of the src color, no need to compute 123986c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com * coverage. 124086c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com */ 124186c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com kEmitTransBlack_BlendOptFlag = 0x8, 124286c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com }; 124386c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com GR_DECL_BITFIELD_OPS_FRIENDS(BlendOptFlags); 124486c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com 124586c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com // Determines what optimizations can be applied based on the blend. 124686c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com // The coeffecients may have to be tweaked in order for the optimization 124786c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com // to work. srcCoeff and dstCoeff are optional params that receive the 124886c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com // tweaked coeffecients. 124986c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com // Normally the function looks at the current state to see if coverage 125086c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com // is enabled. By setting forceCoverage the caller can speculatively 125186c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com // determine the blend optimizations that would be used if there was 125286c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com // partial pixel coverage 125386c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com BlendOptFlags getBlendOpts(bool forceCoverage = false, 125486c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com GrBlendCoeff* srcCoeff = NULL, 125586c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com GrBlendCoeff* dstCoeff = NULL) const; 125686c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com 125786c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com // determine if src alpha is guaranteed to be one for all src pixels 125886c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com bool srcAlphaWillBeOne() const; 1259471d471dcd7422e5dd9c822c1092b2ba4721dcfebsalomon@google.com 126025fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com enum GeometrySrcType { 126125fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com kNone_GeometrySrcType, //<! src has not been specified 126225fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com kReserved_GeometrySrcType, //<! src was set using reserve*Space 126325fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com kArray_GeometrySrcType, //<! src was set using set*SourceToArray 126425fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com kBuffer_GeometrySrcType //<! src was set using set*SourceToBuffer 126525fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com }; 126625fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com 126725fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com struct GeometrySrcState { 126825fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com GeometrySrcType fVertexSrc; 126925fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com union { 127025fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com // valid if src type is buffer 127125fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com const GrVertexBuffer* fVertexBuffer; 127225fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com // valid if src type is reserved or array 127325fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com int fVertexCount; 127425fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com }; 127525fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com 127625fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com GeometrySrcType fIndexSrc; 127725fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com union { 127825fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com // valid if src type is buffer 127925fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com const GrIndexBuffer* fIndexBuffer; 128025fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com // valid if src type is reserved or array 128125fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com int fIndexCount; 128225fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com }; 128325fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com 128425fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com GrVertexLayout fVertexLayout; 128525fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com }; 128625fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com 1287a47a48dca5045d71cbc5de343404045209a13e15bsalomon@google.com // given a vertex layout and a draw state, will a stage be used? 1288a47a48dca5045d71cbc5de343404045209a13e15bsalomon@google.com static bool StageWillBeUsed(int stage, GrVertexLayout layout, 12899381363050ec9d3e724076a8e9152bfa9a8de1d1tomhudson@google.com const GrDrawState& state) { 1290a47a48dca5045d71cbc5de343404045209a13e15bsalomon@google.com return NULL != state.fTextures[stage] && VertexUsesStage(stage, layout); 1291a47a48dca5045d71cbc5de343404045209a13e15bsalomon@google.com } 1292a47a48dca5045d71cbc5de343404045209a13e15bsalomon@google.com 1293a47a48dca5045d71cbc5de343404045209a13e15bsalomon@google.com bool isStageEnabled(int stage) const { 129425fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com return StageWillBeUsed(stage, this->getGeomSrc().fVertexLayout, 129525fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com fCurrDrawState); 1296a47a48dca5045d71cbc5de343404045209a13e15bsalomon@google.com } 12975782d712ffc31557d0cb12d5a220cebb783f6895bsalomon@google.com 1298aeb2160b1dd34f8e640e8e56544fe407d4ff6311bsalomon@google.com StageBitfield enabledStages() const { 1299aeb2160b1dd34f8e640e8e56544fe407d4ff6311bsalomon@google.com StageBitfield mask = 0; 13009381363050ec9d3e724076a8e9152bfa9a8de1d1tomhudson@google.com for (int s = 0; s < GrDrawState::kNumStages; ++s) { 1301aeb2160b1dd34f8e640e8e56544fe407d4ff6311bsalomon@google.com mask |= this->isStageEnabled(s) ? 1 : 0; 1302aeb2160b1dd34f8e640e8e56544fe407d4ff6311bsalomon@google.com } 1303aeb2160b1dd34f8e640e8e56544fe407d4ff6311bsalomon@google.com return mask; 1304aeb2160b1dd34f8e640e8e56544fe407d4ff6311bsalomon@google.com } 1305aeb2160b1dd34f8e640e8e56544fe407d4ff6311bsalomon@google.com 1306ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com // Helpers for GrDrawTarget subclasses that won't have private access to 1307ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com // SavedDrawState but need to peek at the state values. 13089381363050ec9d3e724076a8e9152bfa9a8de1d1tomhudson@google.com static GrDrawState& accessSavedDrawState(SavedDrawState& sds) 1309ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com { return sds.fState; } 13109381363050ec9d3e724076a8e9152bfa9a8de1d1tomhudson@google.com static const GrDrawState& accessSavedDrawState(const SavedDrawState& sds) 1311ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com { return sds.fState; } 1312ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 131325fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com // implemented by subclass to allocate space for reserved geom 131425fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com virtual bool onReserveVertexSpace(GrVertexLayout vertexLayout, 131525fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com int vertexCount, 131625fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com void** vertices) = 0; 131725fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com virtual bool onReserveIndexSpace(int indexCount, void** indices) = 0; 131825fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com // implemented by subclass to handle release of reserved geom space 131925fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com virtual void releaseReservedVertexSpace() = 0; 132025fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com virtual void releaseReservedIndexSpace() = 0; 132125fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com // subclass must consume array contents when set 1322bcdbbe61e1a3f89545b2c1461164f0f8bf5f0797bsalomon@google.com virtual void onSetVertexSourceToArray(const void* vertexArray, 1323bcdbbe61e1a3f89545b2c1461164f0f8bf5f0797bsalomon@google.com int vertexCount) = 0; 1324bcdbbe61e1a3f89545b2c1461164f0f8bf5f0797bsalomon@google.com virtual void onSetIndexSourceToArray(const void* indexArray, 1325bcdbbe61e1a3f89545b2c1461164f0f8bf5f0797bsalomon@google.com int indexCount) = 0; 132625fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com // subclass is notified that geom source will be set away from an array 132725fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com virtual void releaseVertexArray() = 0; 132825fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com virtual void releaseIndexArray() = 0; 132925fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com // subclass overrides to be notified just before geo src state 133025fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com // is pushed/popped. 133125fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com virtual void geometrySourceWillPush() = 0; 133225fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com virtual void geometrySourceWillPop(const GeometrySrcState& restoredState) = 0; 133325fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com // subclass called to perform drawing 133425fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com virtual void onDrawIndexed(GrPrimitiveType type, 133525fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com int startVertex, 133625fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com int startIndex, 133725fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com int vertexCount, 133825fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com int indexCount) = 0; 133925fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com virtual void onDrawNonIndexed(GrPrimitiveType type, 134025fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com int startVertex, 134125fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com int vertexCount) = 0; 1342dea2f8d86378b791a2de94384a18e29f13f65a3ebsalomon@google.com // subclass overrides to be notified when clip is set. Must call 1343dea2f8d86378b791a2de94384a18e29f13f65a3ebsalomon@google.com // INHERITED::clipwillBeSet 1344dea2f8d86378b791a2de94384a18e29f13f65a3ebsalomon@google.com virtual void clipWillBeSet(const GrClip& clip); 13451c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com 134686afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com // Helpers for drawRect, protected so subclasses that override drawRect 134786afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com // can use them. 1348ffca400ef6f96a280c3e2c09210f950af64a1f24bsalomon@google.com static GrVertexLayout GetRectVertexLayout(StageBitfield stageEnableBitfield, 134986afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com const GrRect* srcRects[]); 135086afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com 135186afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com static void SetRectVertices(const GrRect& rect, 1352d302f1401b3c9aea094804bad4e76de98782cfe8bsalomon@google.com const GrMatrix* matrix, 1353d302f1401b3c9aea094804bad4e76de98782cfe8bsalomon@google.com const GrRect* srcRects[], 135486afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com const GrMatrix* srcMatrices[], 1355d302f1401b3c9aea094804bad4e76de98782cfe8bsalomon@google.com GrVertexLayout layout, 135686afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com void* vertices); 135786afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com 135825fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com // accessor for derived classes 135925fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com const GeometrySrcState& getGeomSrc() const { 136025fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com return fGeoSrcStateStack.back(); 136125fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com } 1362ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 1363ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com GrClip fClip; 1364ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 13659381363050ec9d3e724076a8e9152bfa9a8de1d1tomhudson@google.com GrDrawState fCurrDrawState; 1366ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 136718c9c198f571997463d9a7134dbd88298e592ec2bsalomon@google.com Caps fCaps; 136818c9c198f571997463d9a7134dbd88298e592ec2bsalomon@google.com 13694a018bb20bf969a38ec11d9506843f06366dfa7cbsalomon@google.com // subclasses must call this in their destructors to ensure all vertex 13704a018bb20bf969a38ec11d9506843f06366dfa7cbsalomon@google.com // and index sources have been released (including those held by 13714a018bb20bf969a38ec11d9506843f06366dfa7cbsalomon@google.com // pushGeometrySource()) 13724a018bb20bf969a38ec11d9506843f06366dfa7cbsalomon@google.com void releaseGeometry(); 137325fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.comprivate: 137425fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com // called when setting a new vert/idx source to unref prev vb/ib 137525fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com void releasePreviousVertexSource(); 137625fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com void releasePreviousIndexSource(); 137725fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com 137825fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com enum { 137925fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com kPreallocGeoSrcStateStackCnt = 4, 1380ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com }; 138192669014aa7ab821cdc09cc9ad610316eb16b490bsalomon@google.com SkSTArray<kPreallocGeoSrcStateStackCnt, 138292669014aa7ab821cdc09cc9ad610316eb16b490bsalomon@google.com GeometrySrcState, true> fGeoSrcStateStack; 138325fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com 1384ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com}; 1385ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 138686c1f71625970610e768d3bf26c933db2cd685babsalomon@google.comGR_MAKE_BITFIELD_OPS(GrDrawTarget::BlendOptFlags); 138786c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com 1388ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com#endif 1389