GrDrawTarget.h revision 89c62980c1eb50b2090f33312086c7e8c66739b4
1ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com/* 2ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Copyright 2010 Google Inc. 3ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * 4ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Use of this source code is governed by a BSD-style license that can be 5ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * found in the LICENSE file. 6ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com */ 7ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 8ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com#ifndef GrDrawTarget_DEFINED 9ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com#define GrDrawTarget_DEFINED 10ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 118d67c0711b52226db59158a0cfce09f35badd96absalomon@google.com#include "GrClipData.h" 126db519c42471aaaa8a8e1a3ece314014481ab832joshualitt#include "GrClipMaskManager.h" 132a05de0c049a8648942a55016126a1f92e1c14d6commit-bot@chromium.org#include "GrContext.h" 149381363050ec9d3e724076a8e9152bfa9a8de1d1tomhudson@google.com#include "GrDrawState.h" 15934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com#include "GrIndexBuffer.h" 16ccdaa0422501e5cbcba53d6bd19f2736f1beaef3kkinnunen#include "GrPathRendering.h" 172a05de0c049a8648942a55016126a1f92e1c14d6commit-bot@chromium.org#include "GrTraceMarker.h" 18ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 198d67c0711b52226db59158a0cfce09f35badd96absalomon@google.com#include "SkClipStack.h" 20a4de8c257ea0be8ff7081f645249b6afe5c48e7ecommit-bot@chromium.org#include "SkMatrix.h" 2112b4e27ae1a29460e91a59f38122483e1faec697sugoi@google.com#include "SkPath.h" 229b62aa156bcf1db6f11af9302bf8bb8ef2567142commit-bot@chromium.org#include "SkStrokeRec.h" 23a2d71482db8b6d752a51c96da74768d7dfc27932robertphillips@google.com#include "SkTArray.h" 24a4de8c257ea0be8ff7081f645249b6afe5c48e7ecommit-bot@chromium.org#include "SkTLazy.h" 25a0b40280a49a8a43af7929ead3b3489951c58501commit-bot@chromium.org#include "SkTypes.h" 268d67c0711b52226db59158a0cfce09f35badd96absalomon@google.com#include "SkXfermode.h" 2797c88c255cff3dbb8343c5d090526fdbedad6dd6Scroggo 28a2d71482db8b6d752a51c96da74768d7dfc27932robertphillips@google.comclass GrClipData; 29c26d94fd7dc0b00cd6d0e42d28285f4a38aff021bsalomon@google.comclass GrDrawTargetCaps; 3064aef2bacd1f5c25ffd9347aabd6265c9b60c0f4bsalomon@google.comclass GrPath; 31b85a0aab6905af8b329539b7573a7555b727d5e5cdaltonclass GrPathRange; 32ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.comclass GrVertexBuffer; 3312b4e27ae1a29460e91a59f38122483e1faec697sugoi@google.com 34a4de8c257ea0be8ff7081f645249b6afe5c48e7ecommit-bot@chromium.orgclass GrDrawTarget : public SkRefCnt { 35f66018798099750e639a8fa131fece492a050997bsalomon@google.comprotected: 36bcce8926524827775539874346dd424a9510dbc9bsalomon@google.com class DrawInfo; 37bcce8926524827775539874346dd424a9510dbc9bsalomon@google.com 38bcce8926524827775539874346dd424a9510dbc9bsalomon@google.compublic: 39bcce8926524827775539874346dd424a9510dbc9bsalomon@google.com SK_DECLARE_INST_COUNT(GrDrawTarget) 40bcce8926524827775539874346dd424a9510dbc9bsalomon@google.com 41ccdaa0422501e5cbcba53d6bd19f2736f1beaef3kkinnunen typedef GrPathRendering::PathTransformType PathTransformType ; 42ccdaa0422501e5cbcba53d6bd19f2736f1beaef3kkinnunen 43ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com /////////////////////////////////////////////////////////////////////////// 44ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 456e4e65066a7c0dbc9bfbfe4b8f5d49c3d8a79b59bsalomon@google.com // The context may not be fully constructed and should not be used during GrDrawTarget 466e4e65066a7c0dbc9bfbfe4b8f5d49c3d8a79b59bsalomon@google.com // construction. 476e4e65066a7c0dbc9bfbfe4b8f5d49c3d8a79b59bsalomon@google.com GrDrawTarget(GrContext* context); 4825fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com virtual ~GrDrawTarget(); 49ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 50ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com /** 5118c9c198f571997463d9a7134dbd88298e592ec2bsalomon@google.com * Gets the capabilities of the draw target. 5218c9c198f571997463d9a7134dbd88298e592ec2bsalomon@google.com */ 53c26d94fd7dc0b00cd6d0e42d28285f4a38aff021bsalomon@google.com const GrDrawTargetCaps* caps() const { return fCaps.get(); } 5418c9c198f571997463d9a7134dbd88298e592ec2bsalomon@google.com 5518c9c198f571997463d9a7134dbd88298e592ec2bsalomon@google.com /** 56ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * Sets the current clip to the region specified by clip. All draws will be 57ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * clipped against this clip if kClip_StateBit is enabled. 58ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * 595aaa69e4339e229adfb05e96084a8ec0a590238bbsalomon@google.com * Setting the clip may (or may not) zero out the client's stencil bits. 605aaa69e4339e229adfb05e96084a8ec0a590238bbsalomon@google.com * 61ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * @param description of the clipping region 62ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com */ 63beb1af78d016d2700c350487a383c6bcfa7e2e20robertphillips@google.com void setClip(const GrClipData* clip); 64ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 65ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com /** 66ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * Gets the current clip. 67ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * 68ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * @return the clip. 69ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com */ 70beb1af78d016d2700c350487a383c6bcfa7e2e20robertphillips@google.com const GrClipData* getClip() const; 71ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 72a5d056ae0b04021dfb44c2c7a3d6a34e060261b8bsalomon@google.com /** 73a5d056ae0b04021dfb44c2c7a3d6a34e060261b8bsalomon@google.com * Sets the draw state object for the draw target. Note that this does not 74a5d056ae0b04021dfb44c2c7a3d6a34e060261b8bsalomon@google.com * make a copy. The GrDrawTarget will take a reference to passed object. 75a5d056ae0b04021dfb44c2c7a3d6a34e060261b8bsalomon@google.com * Passing NULL will cause the GrDrawTarget to use its own internal draw 76a5d056ae0b04021dfb44c2c7a3d6a34e060261b8bsalomon@google.com * state object rather than an externally provided one. 77a5d056ae0b04021dfb44c2c7a3d6a34e060261b8bsalomon@google.com */ 78a5d056ae0b04021dfb44c2c7a3d6a34e060261b8bsalomon@google.com void setDrawState(GrDrawState* drawState); 79a5d056ae0b04021dfb44c2c7a3d6a34e060261b8bsalomon@google.com 80a5d056ae0b04021dfb44c2c7a3d6a34e060261b8bsalomon@google.com /** 81a5d056ae0b04021dfb44c2c7a3d6a34e060261b8bsalomon@google.com * Read-only access to the GrDrawTarget's current draw state. 82a5d056ae0b04021dfb44c2c7a3d6a34e060261b8bsalomon@google.com */ 83a5d056ae0b04021dfb44c2c7a3d6a34e060261b8bsalomon@google.com const GrDrawState& getDrawState() const { return *fDrawState; } 84a5d056ae0b04021dfb44c2c7a3d6a34e060261b8bsalomon@google.com 85a5d056ae0b04021dfb44c2c7a3d6a34e060261b8bsalomon@google.com /** 86a5d056ae0b04021dfb44c2c7a3d6a34e060261b8bsalomon@google.com * Read-write access to the GrDrawTarget's current draw state. Note that 87a5d056ae0b04021dfb44c2c7a3d6a34e060261b8bsalomon@google.com * this doesn't ref. 88a5d056ae0b04021dfb44c2c7a3d6a34e060261b8bsalomon@google.com */ 89a5d056ae0b04021dfb44c2c7a3d6a34e060261b8bsalomon@google.com GrDrawState* drawState() { return fDrawState; } 903d0835b6ac0003c18147b6e9ca76a497b92d1d40bsalomon@google.com 91e0a868c84ebc34c5a16b5faa1546016abb9ca0accommit-bot@chromium.org /** When we're using coverage AA but the blend is incompatible (given gpu 92e0a868c84ebc34c5a16b5faa1546016abb9ca0accommit-bot@chromium.org * limitations) we should disable AA. */ 9362c447d3a556e3042cdf5d23b3e2a618eaa3c100bsalomon bool shouldDisableCoverageAAForBlend() const { 94e0a868c84ebc34c5a16b5faa1546016abb9ca0accommit-bot@chromium.org // Enable below if we should draw with AA even when it produces 95e0a868c84ebc34c5a16b5faa1546016abb9ca0accommit-bot@chromium.org // incorrect blending. 96e0a868c84ebc34c5a16b5faa1546016abb9ca0accommit-bot@chromium.org // return false; 9762c447d3a556e3042cdf5d23b3e2a618eaa3c100bsalomon return !this->getDrawState().couldApplyCoverage(*this->caps()); 98e0a868c84ebc34c5a16b5faa1546016abb9ca0accommit-bot@chromium.org } 99e0a868c84ebc34c5a16b5faa1546016abb9ca0accommit-bot@chromium.org 100a31082685544d0ae4c0b203d7f5ff960640ed8dfbsalomon@google.com /** 101e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com * There are three types of "sources" of geometry (vertices and indices) for 102e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com * draw calls made on the target. When performing an indexed draw, the 103e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com * indices and vertices can use different source types. Once a source is 104934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com * specified it can be used for multiple draws. However, the time at which 105934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com * the geometry data is no longer editable depends on the source type. 10625fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * 10725fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * Sometimes it is necessary to perform a draw while upstack code has 108e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com * already specified geometry that it isn't finished with. So there are push 109e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com * and pop methods. This allows the client to push the sources, draw 110e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com * something using alternate sources, and then pop to restore the original 111e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com * sources. 112e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com * 113e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com * Aside from pushes and pops, a source remains valid until another source 114e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com * is set or resetVertexSource / resetIndexSource is called. Drawing from 115e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com * a reset source is an error. 116e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com * 117e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com * The three types of sources are: 1181c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com * 119e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com * 1. A cpu array (set*SourceToArray). This is useful when the caller 120e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com * already provided vertex data in a format compatible with a 121e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com * GrVertexLayout. The data in the array is consumed at the time that 122e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com * set*SourceToArray is called and subsequent edits to the array will not 123e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com * be reflected in draws. 1241c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com * 12525fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * 2. Reserve. This is most useful when the caller has data it must 12625fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * transform before drawing and is not long-lived. The caller requests 12725fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * that the draw target make room for some amount of vertex and/or index 12825fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * data. The target provides ptrs to hold the vertex and/or index data. 12925fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * 130d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com * The data is writable up until the next drawIndexed, drawNonIndexed, 131e4617bf6d45cdde07f89e341ebf5c485916bf0b2bsalomon@google.com * drawIndexedInstances, drawRect, copySurface, or pushGeometrySource. At 132e4617bf6d45cdde07f89e341ebf5c485916bf0b2bsalomon@google.com * this point the data is frozen and the ptrs are no longer valid. 1331c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com * 134e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com * Where the space is allocated and how it is uploaded to the GPU is 135e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com * subclass-dependent. 136e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com * 1371c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com * 3. Vertex and Index Buffers. This is most useful for geometry that will 138e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com * is long-lived. When the data in the buffer is consumed depends on the 139d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com * GrDrawTarget subclass. For deferred subclasses the caller has to 140e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com * guarantee that the data is still available in the buffers at playback. 141e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com * (TODO: Make this more automatic as we have done for read/write pixels) 142b75b0a0b8492e14c7728e0a0881f87dc64ce60f9jvanverth@google.com * 143b75b0a0b8492e14c7728e0a0881f87dc64ce60f9jvanverth@google.com * The size of each vertex is determined by querying the current GrDrawState. 1441c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com */ 1451c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com 1461c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com /** 147e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com * Reserves space for vertices and/or indices. Zero can be specifed as 148e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com * either the vertex or index count if the caller desires to only reserve 149d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com * space for only indices or only vertices. If zero is specifed for 150e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com * vertexCount then the vertex source will be unmodified and likewise for 151e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com * indexCount. 152ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * 153e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com * If the function returns true then the reserve suceeded and the vertices 154e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com * and indices pointers will point to the space created. 155ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * 156e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com * If the target cannot make space for the request then this function will 157e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com * return false. If vertexCount was non-zero then upon failure the vertex 158e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com * source is reset and likewise for indexCount. 159ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * 160e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com * The pointers to the space allocated for vertices and indices remain valid 161e4617bf6d45cdde07f89e341ebf5c485916bf0b2bsalomon@google.com * until a drawIndexed, drawNonIndexed, drawIndexedInstances, drawRect, 162e4617bf6d45cdde07f89e341ebf5c485916bf0b2bsalomon@google.com * copySurface, or push/popGeomtrySource is called. At that point logically a 163e4617bf6d45cdde07f89e341ebf5c485916bf0b2bsalomon@google.com * snapshot of the data is made and the pointers are invalid. 1641c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com * 165e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com * @param vertexCount the number of vertices to reserve space for. Can be 166b75b0a0b8492e14c7728e0a0881f87dc64ce60f9jvanverth@google.com * 0. Vertex size is queried from the current GrDrawState. 16725fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * @param indexCount the number of indices to reserve space for. Can be 0. 168e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com * @param vertices will point to reserved vertex space if vertexCount is 169d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com * non-zero. Illegal to pass NULL if vertexCount > 0. 17025fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * @param indices will point to reserved index space if indexCount is 17125fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * non-zero. Illegal to pass NULL if indexCount > 0. 17225fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com */ 173b75b0a0b8492e14c7728e0a0881f87dc64ce60f9jvanverth@google.com bool reserveVertexAndIndexSpace(int vertexCount, 17497805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com int indexCount, 17597805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com void** vertices, 17697805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com void** indices); 17725fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com 178ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com /** 179ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * Provides hints to caller about the number of vertices and indices 180ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * that can be allocated cheaply. This can be useful if caller is reserving 181ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * space but doesn't know exactly how much geometry is needed. 182ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * 183ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * Also may hint whether the draw target should be flushed first. This is 184ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * useful for deferred targets. 185ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * 186ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * @param vertexCount in: hint about how many vertices the caller would 187b75b0a0b8492e14c7728e0a0881f87dc64ce60f9jvanverth@google.com * like to allocate. Vertex size is queried from the 188b75b0a0b8492e14c7728e0a0881f87dc64ce60f9jvanverth@google.com * current GrDrawState. 189ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * out: a hint about the number of vertices that can be 190ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * allocated cheaply. Negative means no hint. 191ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * Ignored if NULL. 192ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * @param indexCount in: hint about how many indices the caller would 193ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * like to allocate. 194ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * out: a hint about the number of indices that can be 195ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * allocated cheaply. Negative means no hint. 196ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * Ignored if NULL. 197ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * 198ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * @return true if target should be flushed based on the input values. 199ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com */ 200b75b0a0b8492e14c7728e0a0881f87dc64ce60f9jvanverth@google.com virtual bool geometryHints(int* vertexCount, 2011c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com int* indexCount) const; 202ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 203ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com /** 2041c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com * Sets source of vertex data for the next draw. Array must contain 2051c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com * the vertex data when this is called. 206ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * 207b75b0a0b8492e14c7728e0a0881f87dc64ce60f9jvanverth@google.com * @param vertexArray cpu array containing vertex data. 208ae683921ffda9108147a29da7319c7eee4dc9245skia.committer@gmail.com * @param vertexCount the number of vertices in the array. Vertex size is 209b75b0a0b8492e14c7728e0a0881f87dc64ce60f9jvanverth@google.com * queried from the current GrDrawState. 210ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com */ 211b75b0a0b8492e14c7728e0a0881f87dc64ce60f9jvanverth@google.com void setVertexSourceToArray(const void* vertexArray, int vertexCount); 212ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 213ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com /** 2141c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com * Sets source of index data for the next indexed draw. Array must contain 2151c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com * the indices when this is called. 216ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * 217b75b0a0b8492e14c7728e0a0881f87dc64ce60f9jvanverth@google.com * @param indexArray cpu array containing index data. 2181c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com * @param indexCount the number of indices in the array. 219ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com */ 2201c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com void setIndexSourceToArray(const void* indexArray, int indexCount); 221ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 222ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com /** 223ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * Sets source of vertex data for the next draw. Data does not have to be 224934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com * in the buffer until drawIndexed, drawNonIndexed, or drawIndexedInstances. 225ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * 226ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * @param buffer vertex buffer containing vertex data. Must be 227ae683921ffda9108147a29da7319c7eee4dc9245skia.committer@gmail.com * unlocked before draw call. Vertex size is queried 228b75b0a0b8492e14c7728e0a0881f87dc64ce60f9jvanverth@google.com * from current GrDrawState. 229ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com */ 230b75b0a0b8492e14c7728e0a0881f87dc64ce60f9jvanverth@google.com void setVertexSourceToBuffer(const GrVertexBuffer* buffer); 231ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 232ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com /** 233ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * Sets source of index data for the next indexed draw. Data does not have 234934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com * to be in the buffer until drawIndexed. 235ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * 236ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * @param buffer index buffer containing indices. Must be unlocked 237ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * before indexed draw call. 238ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com */ 239ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com void setIndexSourceToBuffer(const GrIndexBuffer* buffer); 240d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com 24125fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com /** 24225fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * Resets vertex source. Drawing from reset vertices is illegal. Set vertex 24325fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * source to reserved, array, or buffer before next draw. May be able to free 24425fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * up temporary storage allocated by setVertexSourceToArray or 24525fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * reserveVertexSpace. 24625fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com */ 24725fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com void resetVertexSource(); 248d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com 24925fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com /** 25025fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * Resets index source. Indexed Drawing from reset indices is illegal. Set 25125fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * index source to reserved, array, or buffer before next indexed draw. May 25225fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * be able to free up temporary storage allocated by setIndexSourceToArray 25325fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * or reserveIndexSpace. 25425fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com */ 25597805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com void resetIndexSource(); 256d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com 25797805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com /** 25897805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com * Query to find out if the vertex or index source is reserved. 25997805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com */ 26097805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com bool hasReservedVerticesOrIndices() const { 26173d98aace4f74acc39d8de33484c8aec8e917739bsalomon@google.com return kReserved_GeometrySrcType == this->getGeomSrc().fVertexSrc || 26297805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com kReserved_GeometrySrcType == this->getGeomSrc().fIndexSrc; 26397805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com } 264ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 265ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com /** 26625fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * Pushes and resets the vertex/index sources. Any reserved vertex / index 26725fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * data is finalized (i.e. cannot be updated after the matching pop but can 26825fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * be drawn from). Must be balanced by a pop. 26925fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com */ 27025fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com void pushGeometrySource(); 27125fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com 27225fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com /** 27325fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com * Pops the vertex / index sources from the matching push. 27425fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com */ 27525fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com void popGeometrySource(); 27664aef2bacd1f5c25ffd9347aabd6265c9b60c0f4bsalomon@google.com 27725fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com /** 278ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * Draws indexed geometry using the current state and current vertex / index 279ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * sources. 280ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * 281ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * @param type The type of primitives to draw. 282ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * @param startVertex the vertex in the vertex array/buffer corresponding 283ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * to index 0 284ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * @param startIndex first index to read from index src. 285ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * @param vertexCount one greater than the max index. 286ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * @param indexCount the number of index elements to read. The index count 287ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * is effectively trimmed to the last completely 288ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * specified primitive. 289d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com * @param devBounds optional bounds hint. This is a promise from the caller, 290d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com * not a request for clipping. 291ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com */ 29225fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com void drawIndexed(GrPrimitiveType type, 29325fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com int startVertex, 29425fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com int startIndex, 29525fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com int vertexCount, 296d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com int indexCount, 297d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com const SkRect* devBounds = NULL); 298ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 299ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com /** 300ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * Draws non-indexed geometry using the current state and current vertex 301ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * sources. 302ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * 303ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * @param type The type of primitives to draw. 304ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * @param startVertex the vertex in the vertex array/buffer corresponding 305ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * to index 0 306ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * @param vertexCount one greater than the max index. 307d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com * @param devBounds optional bounds hint. This is a promise from the caller, 308d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com * not a request for clipping. 309ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com */ 31025fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com void drawNonIndexed(GrPrimitiveType type, 31125fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com int startVertex, 312d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com int vertexCount, 313d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com const SkRect* devBounds = NULL); 314ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 31586afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com /** 31664aef2bacd1f5c25ffd9347aabd6265c9b60c0f4bsalomon@google.com * Draws path into the stencil buffer. The fill must be either even/odd or 31764aef2bacd1f5c25ffd9347aabd6265c9b60c0f4bsalomon@google.com * winding (not inverse or hairline). It will respect the HW antialias flag 31892e496f96abbd664888f0c8a7d546ab02e703bf7joshualitt * on the draw state (if possible in the 3D API). Note, we will never have an inverse fill 31992e496f96abbd664888f0c8a7d546ab02e703bf7joshualitt * with stencil path 32064aef2bacd1f5c25ffd9347aabd6265c9b60c0f4bsalomon@google.com */ 32192e496f96abbd664888f0c8a7d546ab02e703bf7joshualitt void stencilPath(const GrPath*, GrPathRendering::FillType fill); 32264aef2bacd1f5c25ffd9347aabd6265c9b60c0f4bsalomon@google.com 32364aef2bacd1f5c25ffd9347aabd6265c9b60c0f4bsalomon@google.com /** 32432184d81629e39809bb9e915286d8fe971a8ed68commit-bot@chromium.org * Draws a path. Fill must not be a hairline. It will respect the HW 325c4dc0ad8e252a7e30d19b47d3d0d9f2c69faf854commit-bot@chromium.org * antialias flag on the draw state (if possible in the 3D API). 326c4dc0ad8e252a7e30d19b47d3d0d9f2c69faf854commit-bot@chromium.org */ 32792e496f96abbd664888f0c8a7d546ab02e703bf7joshualitt void drawPath(const GrPath*, GrPathRendering::FillType fill); 328c4dc0ad8e252a7e30d19b47d3d0d9f2c69faf854commit-bot@chromium.org 329c4dc0ad8e252a7e30d19b47d3d0d9f2c69faf854commit-bot@chromium.org /** 3309b62aa156bcf1db6f11af9302bf8bb8ef2567142commit-bot@chromium.org * Draws many paths. It will respect the HW 3319b62aa156bcf1db6f11af9302bf8bb8ef2567142commit-bot@chromium.org * antialias flag on the draw state (if possible in the 3D API). 3329b62aa156bcf1db6f11af9302bf8bb8ef2567142commit-bot@chromium.org * 333b85a0aab6905af8b329539b7573a7555b727d5e5cdalton * @param pathRange Source of paths to draw from 334b85a0aab6905af8b329539b7573a7555b727d5e5cdalton * @param indices Array of indices into the the pathRange 335b85a0aab6905af8b329539b7573a7555b727d5e5cdalton * @param count Number of paths to draw (length of indices array) 336b85a0aab6905af8b329539b7573a7555b727d5e5cdalton * @param transforms Array of individual transforms, one for each path 337b85a0aab6905af8b329539b7573a7555b727d5e5cdalton * @param transformsType Type of transformations in the array. Array contains 338db1f156231b82ffc189e5ebce34175af9a1d9a53bsalomon PathTransformSize(transformsType) * count elements 339b85a0aab6905af8b329539b7573a7555b727d5e5cdalton * @param fill Fill type for drawing all the paths 340b85a0aab6905af8b329539b7573a7555b727d5e5cdalton */ 341b85a0aab6905af8b329539b7573a7555b727d5e5cdalton void drawPaths(const GrPathRange* pathRange, 342b85a0aab6905af8b329539b7573a7555b727d5e5cdalton const uint32_t indices[], int count, 343b85a0aab6905af8b329539b7573a7555b727d5e5cdalton const float transforms[], PathTransformType transformsType, 34492e496f96abbd664888f0c8a7d546ab02e703bf7joshualitt GrPathRendering::FillType fill); 345b85a0aab6905af8b329539b7573a7555b727d5e5cdalton 3469b62aa156bcf1db6f11af9302bf8bb8ef2567142commit-bot@chromium.org /** 3470406b9e1faee06c6ecb2732a1bcf3b0e53104e07bsalomon@google.com * Helper function for drawing rects. It performs a geometry src push and pop 3480406b9e1faee06c6ecb2732a1bcf3b0e53104e07bsalomon@google.com * and thus will finalize any reserved geometry. 349044679ef8c08e1f01afadf5bc08251fe8597df81skia.committer@gmail.com * 350c78188896e28a4ae49e406a7422b345ae177dafebsalomon@google.com * @param rect the rect to draw 351c78188896e28a4ae49e406a7422b345ae177dafebsalomon@google.com * @param localRect optional rect that specifies local coords to map onto 352c78188896e28a4ae49e406a7422b345ae177dafebsalomon@google.com * rect. If NULL then rect serves as the local coords. 353c78188896e28a4ae49e406a7422b345ae177dafebsalomon@google.com * @param localMatrix optional matrix applied to localRect. If 354044679ef8c08e1f01afadf5bc08251fe8597df81skia.committer@gmail.com * srcRect is non-NULL and srcMatrix is non-NULL 355044679ef8c08e1f01afadf5bc08251fe8597df81skia.committer@gmail.com * then srcRect will be transformed by srcMatrix. 3563976825a21532e254311b90b4a9046e25717e335jvanverth@google.com * srcMatrix can be NULL when no srcMatrix is desired. 35786afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com */ 358fd03d4a829efe2d77a712fd991927c55f59a2ffecommit-bot@chromium.org void drawRect(const SkRect& rect, 359fd03d4a829efe2d77a712fd991927c55f59a2ffecommit-bot@chromium.org const SkRect* localRect, 3600406b9e1faee06c6ecb2732a1bcf3b0e53104e07bsalomon@google.com const SkMatrix* localMatrix) { 3610406b9e1faee06c6ecb2732a1bcf3b0e53104e07bsalomon@google.com AutoGeometryPush agp(this); 36201c8da1eef36570374f7e8764a38b25bf16ab7a6bsalomon this->onDrawRect(rect, localRect, localMatrix); 3630406b9e1faee06c6ecb2732a1bcf3b0e53104e07bsalomon@google.com } 3643976825a21532e254311b90b4a9046e25717e335jvanverth@google.com 365cf939ae54842fc7408ee68a41427086962b4c3dcbsalomon@google.com /** 366c78188896e28a4ae49e406a7422b345ae177dafebsalomon@google.com * Helper for drawRect when the caller doesn't need separate local rects or matrices. 367cf939ae54842fc7408ee68a41427086962b4c3dcbsalomon@google.com */ 36801c8da1eef36570374f7e8764a38b25bf16ab7a6bsalomon void drawSimpleRect(const SkRect& rect) { 36901c8da1eef36570374f7e8764a38b25bf16ab7a6bsalomon this->drawRect(rect, NULL, NULL); 370cf939ae54842fc7408ee68a41427086962b4c3dcbsalomon@google.com } 37101c8da1eef36570374f7e8764a38b25bf16ab7a6bsalomon void drawSimpleRect(const SkIRect& irect) { 3724469938e92d779dff05e745559e67907bbf21e78reed@google.com SkRect rect = SkRect::Make(irect); 37301c8da1eef36570374f7e8764a38b25bf16ab7a6bsalomon this->drawRect(rect, NULL, NULL); 374cf939ae54842fc7408ee68a41427086962b4c3dcbsalomon@google.com } 37586afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com 37686afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com /** 377934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com * This call is used to draw multiple instances of some geometry with a 378934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com * given number of vertices (V) and indices (I) per-instance. The indices in 379934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com * the index source must have the form i[k+I] == i[k] + V. Also, all indices 380934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com * i[kI] ... i[(k+1)I-1] must be elements of the range kV ... (k+1)V-1. As a 381934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com * concrete example, the following index buffer for drawing a series of 382934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com * quads each as two triangles each satisfies these conditions with V=4 and 383934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com * I=6: 384934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com * (0,1,2,0,2,3, 4,5,6,4,6,7, 8,9,10,8,10,11, ...) 385934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com * 386934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com * The call assumes that the pattern of indices fills the entire index 387934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com * source. The size of the index buffer limits the number of instances that 388934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com * can be drawn by the GPU in a single draw. However, the caller may specify 389934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com * any (positive) number for instanceCount and if necessary multiple GPU 390d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com * draws will be issued. Moreover, when drawIndexedInstances is called 391934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com * multiple times it may be possible for GrDrawTarget to group them into a 392934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com * single GPU draw. 393934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com * 394934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com * @param type the type of primitives to draw 395934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com * @param instanceCount the number of instances to draw. Each instance 396934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com * consists of verticesPerInstance vertices indexed by 397934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com * indicesPerInstance indices drawn as the primitive 398934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com * type specified by type. 399934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com * @param verticesPerInstance The number of vertices in each instance (V 400934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com * in the above description). 401934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com * @param indicesPerInstance The number of indices in each instance (I 402934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com * in the above description). 403d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com * @param devBounds optional bounds hint. This is a promise from the caller, 404d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com * not a request for clipping. 405934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com */ 406d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com void drawIndexedInstances(GrPrimitiveType type, 407d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com int instanceCount, 408d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com int verticesPerInstance, 409d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com int indicesPerInstance, 410d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com const SkRect* devBounds = NULL); 411934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com 412934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com /** 41389c62980c1eb50b2090f33312086c7e8c66739b4bsalomon * Clear the passed in render target. Ignores the draw state and clip. Clears the whole thing if 41489c62980c1eb50b2090f33312086c7e8c66739b4bsalomon * rect is NULL, otherwise just the rect. If canIgnoreRect is set then the entire render target 41589c62980c1eb50b2090f33312086c7e8c66739b4bsalomon * can be optionally cleared. 4160b335c1ac100aeacf79a4c98a052286fd46661e7bsalomon@google.com */ 41789c62980c1eb50b2090f33312086c7e8c66739b4bsalomon virtual void clear(const SkIRect* rect, GrColor color, bool canIgnoreRect, 41889c62980c1eb50b2090f33312086c7e8c66739b4bsalomon GrRenderTarget* renderTarget) = 0; 419a9493a3c78f6eb82635ece960b4f16918b885428skia.committer@gmail.com 420e4617bf6d45cdde07f89e341ebf5c485916bf0b2bsalomon@google.com /** 42189c62980c1eb50b2090f33312086c7e8c66739b4bsalomon * Discards the contents render target. 42228361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org **/ 42389c62980c1eb50b2090f33312086c7e8c66739b4bsalomon virtual void discard(GrRenderTarget*) = 0; 42428361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org 42528361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org /** 4262a05de0c049a8648942a55016126a1f92e1c14d6commit-bot@chromium.org * Called at start and end of gpu trace marking 4272a05de0c049a8648942a55016126a1f92e1c14d6commit-bot@chromium.org * GR_CREATE_GPU_TRACE_MARKER(marker_str, target) will automatically call these at the start 4282a05de0c049a8648942a55016126a1f92e1c14d6commit-bot@chromium.org * and end of a code block respectively 429a3baf3be0e2a3128fb73bd41d40d130f75a4dc86commit-bot@chromium.org */ 4303eee3834fba1d2e29dfb61adcb97e4624b6a3ac8egdaniel void addGpuTraceMarker(const GrGpuTraceMarker* marker); 4313eee3834fba1d2e29dfb61adcb97e4624b6a3ac8egdaniel void removeGpuTraceMarker(const GrGpuTraceMarker* marker); 4323eee3834fba1d2e29dfb61adcb97e4624b6a3ac8egdaniel 4333eee3834fba1d2e29dfb61adcb97e4624b6a3ac8egdaniel /** 4343eee3834fba1d2e29dfb61adcb97e4624b6a3ac8egdaniel * Takes the current active set of markers and stores them for later use. Any current marker 4353eee3834fba1d2e29dfb61adcb97e4624b6a3ac8egdaniel * in the active set is removed from the active set and the targets remove function is called. 4363eee3834fba1d2e29dfb61adcb97e4624b6a3ac8egdaniel * These functions do not work as a stack so you cannot call save a second time before calling 4373eee3834fba1d2e29dfb61adcb97e4624b6a3ac8egdaniel * restore. Also, it is assumed that when restore is called the current active set of markers 4383eee3834fba1d2e29dfb61adcb97e4624b6a3ac8egdaniel * is empty. When the stored markers are added back into the active set, the targets add marker 4393eee3834fba1d2e29dfb61adcb97e4624b6a3ac8egdaniel * is called. 4403eee3834fba1d2e29dfb61adcb97e4624b6a3ac8egdaniel */ 4413eee3834fba1d2e29dfb61adcb97e4624b6a3ac8egdaniel void saveActiveTraceMarkers(); 4423eee3834fba1d2e29dfb61adcb97e4624b6a3ac8egdaniel void restoreActiveTraceMarkers(); 443a3baf3be0e2a3128fb73bd41d40d130f75a4dc86commit-bot@chromium.org 444a3baf3be0e2a3128fb73bd41d40d130f75a4dc86commit-bot@chromium.org /** 445e4617bf6d45cdde07f89e341ebf5c485916bf0b2bsalomon@google.com * Copies a pixel rectangle from one surface to another. This call may finalize 446e4617bf6d45cdde07f89e341ebf5c485916bf0b2bsalomon@google.com * reserved vertex/index data (as though a draw call was made). The src pixels 447e4617bf6d45cdde07f89e341ebf5c485916bf0b2bsalomon@google.com * copied are specified by srcRect. They are copied to a rect of the same 448e4617bf6d45cdde07f89e341ebf5c485916bf0b2bsalomon@google.com * size in dst with top left at dstPoint. If the src rect is clipped by the 449e4617bf6d45cdde07f89e341ebf5c485916bf0b2bsalomon@google.com * src bounds then pixel values in the dst rect corresponding to area clipped 450e4617bf6d45cdde07f89e341ebf5c485916bf0b2bsalomon@google.com * by the src rect are not overwritten. This method can fail and return false 451e4617bf6d45cdde07f89e341ebf5c485916bf0b2bsalomon@google.com * depending on the type of surface, configs, etc, and the backend-specific 452e4617bf6d45cdde07f89e341ebf5c485916bf0b2bsalomon@google.com * limitations. If rect is clipped out entirely by the src or dst bounds then 453e4617bf6d45cdde07f89e341ebf5c485916bf0b2bsalomon@google.com * true is returned since there is no actual copy necessary to succeed. 454e4617bf6d45cdde07f89e341ebf5c485916bf0b2bsalomon@google.com */ 455e4617bf6d45cdde07f89e341ebf5c485916bf0b2bsalomon@google.com bool copySurface(GrSurface* dst, 456e4617bf6d45cdde07f89e341ebf5c485916bf0b2bsalomon@google.com GrSurface* src, 457e4617bf6d45cdde07f89e341ebf5c485916bf0b2bsalomon@google.com const SkIRect& srcRect, 458e4617bf6d45cdde07f89e341ebf5c485916bf0b2bsalomon@google.com const SkIPoint& dstPoint); 459116ad84d3126b0db22b2312ca59ed70e5c56f6fcbsalomon@google.com /** 460116ad84d3126b0db22b2312ca59ed70e5c56f6fcbsalomon@google.com * Function that determines whether a copySurface call would succeed without 461116ad84d3126b0db22b2312ca59ed70e5c56f6fcbsalomon@google.com * performing the copy. 462116ad84d3126b0db22b2312ca59ed70e5c56f6fcbsalomon@google.com */ 463116ad84d3126b0db22b2312ca59ed70e5c56f6fcbsalomon@google.com bool canCopySurface(GrSurface* dst, 464116ad84d3126b0db22b2312ca59ed70e5c56f6fcbsalomon@google.com GrSurface* src, 465116ad84d3126b0db22b2312ca59ed70e5c56f6fcbsalomon@google.com const SkIRect& srcRect, 466116ad84d3126b0db22b2312ca59ed70e5c56f6fcbsalomon@google.com const SkIPoint& dstPoint); 4670b335c1ac100aeacf79a4c98a052286fd46661e7bsalomon@google.com 468ff17584e1c15f68ccc296be517e8a6776a9ddabdrobertphillips@google.com /** 469eb85117c05471e1a55ce387cbc38279f857a4584bsalomon@google.com * This is can be called before allocating a texture to be a dst for copySurface. It will 470eb85117c05471e1a55ce387cbc38279f857a4584bsalomon@google.com * populate the origin, config, and flags fields of the desc such that copySurface is more 471eb85117c05471e1a55ce387cbc38279f857a4584bsalomon@google.com * likely to succeed and be efficient. 472eb85117c05471e1a55ce387cbc38279f857a4584bsalomon@google.com */ 473f2703d83da3ab2ae18b45231fd4f11e16cce3184bsalomon virtual void initCopySurfaceDstDesc(const GrSurface* src, GrSurfaceDesc* desc); 474eb85117c05471e1a55ce387cbc38279f857a4584bsalomon@google.com 475eb85117c05471e1a55ce387cbc38279f857a4584bsalomon@google.com 476eb85117c05471e1a55ce387cbc38279f857a4584bsalomon@google.com /** 477ff17584e1c15f68ccc296be517e8a6776a9ddabdrobertphillips@google.com * Release any resources that are cached but not currently in use. This 478ff17584e1c15f68ccc296be517e8a6776a9ddabdrobertphillips@google.com * is intended to give an application some recourse when resources are low. 479ff17584e1c15f68ccc296be517e8a6776a9ddabdrobertphillips@google.com */ 480ff17584e1c15f68ccc296be517e8a6776a9ddabdrobertphillips@google.com virtual void purgeResources() {}; 481ff17584e1c15f68ccc296be517e8a6776a9ddabdrobertphillips@google.com 482d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com /** 483d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com * For subclass internal use to invoke a call to onDraw(). See DrawInfo below. 484d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com */ 485d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com void executeDraw(const DrawInfo& info) { this->onDraw(info); } 486d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com 487c4dc0ad8e252a7e30d19b47d3d0d9f2c69faf854commit-bot@chromium.org /** 48832184d81629e39809bb9e915286d8fe971a8ed68commit-bot@chromium.org * For subclass internal use to invoke a call to onDrawPath(). 489c4dc0ad8e252a7e30d19b47d3d0d9f2c69faf854commit-bot@chromium.org */ 49092e496f96abbd664888f0c8a7d546ab02e703bf7joshualitt void executeDrawPath(const GrPath* path, GrPathRendering::FillType fill, 49132184d81629e39809bb9e915286d8fe971a8ed68commit-bot@chromium.org const GrDeviceCoordTexture* dstCopy) { 49232184d81629e39809bb9e915286d8fe971a8ed68commit-bot@chromium.org this->onDrawPath(path, fill, dstCopy); 493c4dc0ad8e252a7e30d19b47d3d0d9f2c69faf854commit-bot@chromium.org } 494c4dc0ad8e252a7e30d19b47d3d0d9f2c69faf854commit-bot@chromium.org 4959b62aa156bcf1db6f11af9302bf8bb8ef2567142commit-bot@chromium.org /** 4969b62aa156bcf1db6f11af9302bf8bb8ef2567142commit-bot@chromium.org * For subclass internal use to invoke a call to onDrawPaths(). 4979b62aa156bcf1db6f11af9302bf8bb8ef2567142commit-bot@chromium.org */ 498b85a0aab6905af8b329539b7573a7555b727d5e5cdalton void executeDrawPaths(const GrPathRange* pathRange, 499b85a0aab6905af8b329539b7573a7555b727d5e5cdalton const uint32_t indices[], int count, 500b85a0aab6905af8b329539b7573a7555b727d5e5cdalton const float transforms[], PathTransformType transformsType, 50192e496f96abbd664888f0c8a7d546ab02e703bf7joshualitt GrPathRendering::FillType fill, 5029b62aa156bcf1db6f11af9302bf8bb8ef2567142commit-bot@chromium.org const GrDeviceCoordTexture* dstCopy) { 503b85a0aab6905af8b329539b7573a7555b727d5e5cdalton this->onDrawPaths(pathRange, indices, count, transforms, transformsType, fill, dstCopy); 5049b62aa156bcf1db6f11af9302bf8bb8ef2567142commit-bot@chromium.org } 505329bf4862e9d5e05363c2b071d8ca475a0ef1952joshualitt 50625fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com //////////////////////////////////////////////////////////////////////////// 507ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 508873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com /** 509873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com * See AutoStateRestore below. 510873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com */ 511873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com enum ASRInit { 512873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com kPreserve_ASRInit, 513873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com kReset_ASRInit 514873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com }; 515873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com 516873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com /** 517873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com * Saves off the current state and restores it in the destructor. It will 518873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com * install a new GrDrawState object on the target (setDrawState) and restore 519873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com * the previous one in the destructor. The caller should call drawState() to 520873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com * get the new draw state after the ASR is installed. 521873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com * 522873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com * GrDrawState* state = target->drawState(); 523873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com * AutoStateRestore asr(target, GrDrawTarget::kReset_ASRInit). 524873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com * state->setRenderTarget(rt); // state refers to the GrDrawState set on 525873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com * // target before asr was initialized. 526873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com * // Therefore, rt is set on the GrDrawState 527873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com * // that will be restored after asr's 528873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com * // destructor rather than target's current 529d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com * // GrDrawState. 530873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com */ 531a0b40280a49a8a43af7929ead3b3489951c58501commit-bot@chromium.org class AutoStateRestore : public ::SkNoncopyable { 532ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com public: 533873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com /** 534873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com * Default ASR will have no effect unless set() is subsequently called. 535873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com */ 53606afe7b5a1ef03bfc6494c51ab2a1f7a386de5c2bsalomon@google.com AutoStateRestore(); 537873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com 538873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com /** 539873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com * Saves the state on target. The state will be restored when the ASR 540873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com * is destroyed. If this constructor is used do not call set(). 541873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com * 542873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com * @param init Should the newly installed GrDrawState be a copy of the 543873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com * previous state or a default-initialized GrDrawState. 544137f1347abaf0bb6a945e91c2f6cb49f0ee69bc3bsalomon@google.com * @param viewMatrix Optional view matrix. If init = kPreserve then the draw state's 545137f1347abaf0bb6a945e91c2f6cb49f0ee69bc3bsalomon@google.com * matrix will be preconcat'ed with the param. All stages will be 546137f1347abaf0bb6a945e91c2f6cb49f0ee69bc3bsalomon@google.com updated to compensate for the matrix change. If init == kReset 547137f1347abaf0bb6a945e91c2f6cb49f0ee69bc3bsalomon@google.com then the draw state's matrix will be this matrix. 548873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com */ 549137f1347abaf0bb6a945e91c2f6cb49f0ee69bc3bsalomon@google.com AutoStateRestore(GrDrawTarget* target, ASRInit init, const SkMatrix* viewMatrix = NULL); 550873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com 551ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com ~AutoStateRestore(); 552ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 55306afe7b5a1ef03bfc6494c51ab2a1f7a386de5c2bsalomon@google.com /** 554873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com * Saves the state on target. The state will be restored when the ASR 555873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com * is destroyed. This should only be called once per ASR object and only 556873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com * when the default constructor was used. For nested saves use multiple 557873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com * ASR objects. 558873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com * 559873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com * @param init Should the newly installed GrDrawState be a copy of the 560873ea0c93f202600ec2591bc1e2e5d7a1e05f59dbsalomon@google.com * previous state or a default-initialized GrDrawState. 561137f1347abaf0bb6a945e91c2f6cb49f0ee69bc3bsalomon@google.com * @param viewMatrix Optional view matrix. If init = kPreserve then the draw state's 562137f1347abaf0bb6a945e91c2f6cb49f0ee69bc3bsalomon@google.com * matrix will be preconcat'ed with the param. All stages will be 563137f1347abaf0bb6a945e91c2f6cb49f0ee69bc3bsalomon@google.com updated to compensate for the matrix change. If init == kReset 564137f1347abaf0bb6a945e91c2f6cb49f0ee69bc3bsalomon@google.com then the draw state's matrix will be this matrix. 56506afe7b5a1ef03bfc6494c51ab2a1f7a386de5c2bsalomon@google.com */ 566137f1347abaf0bb6a945e91c2f6cb49f0ee69bc3bsalomon@google.com void set(GrDrawTarget* target, ASRInit init, const SkMatrix* viewMatrix = NULL); 567137f1347abaf0bb6a945e91c2f6cb49f0ee69bc3bsalomon@google.com 568137f1347abaf0bb6a945e91c2f6cb49f0ee69bc3bsalomon@google.com /** 569137f1347abaf0bb6a945e91c2f6cb49f0ee69bc3bsalomon@google.com * Like set() but makes the view matrix identity. When init is kReset it is as though 570137f1347abaf0bb6a945e91c2f6cb49f0ee69bc3bsalomon@google.com * NULL was passed to set's viewMatrix param. When init is kPreserve it is as though 571137f1347abaf0bb6a945e91c2f6cb49f0ee69bc3bsalomon@google.com * the inverse view matrix was passed. If kPreserve is passed and the draw state's matrix 572137f1347abaf0bb6a945e91c2f6cb49f0ee69bc3bsalomon@google.com * is not invertible then this may fail. 573137f1347abaf0bb6a945e91c2f6cb49f0ee69bc3bsalomon@google.com */ 574137f1347abaf0bb6a945e91c2f6cb49f0ee69bc3bsalomon@google.com bool setIdentity(GrDrawTarget* target, ASRInit init); 57506afe7b5a1ef03bfc6494c51ab2a1f7a386de5c2bsalomon@google.com 576ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com private: 577137f1347abaf0bb6a945e91c2f6cb49f0ee69bc3bsalomon@google.com GrDrawTarget* fDrawTarget; 578137f1347abaf0bb6a945e91c2f6cb49f0ee69bc3bsalomon@google.com SkTLazy<GrDrawState> fTempState; 579137f1347abaf0bb6a945e91c2f6cb49f0ee69bc3bsalomon@google.com GrDrawState* fSavedState; 580ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com }; 581ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 58225fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com //////////////////////////////////////////////////////////////////////////// 5831c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com 584a0b40280a49a8a43af7929ead3b3489951c58501commit-bot@chromium.org class AutoReleaseGeometry : public ::SkNoncopyable { 585ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com public: 586ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com AutoReleaseGeometry(GrDrawTarget* target, 58725fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com int vertexCount, 58825fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com int indexCount); 58925fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com AutoReleaseGeometry(); 59025fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com ~AutoReleaseGeometry(); 5915782d712ffc31557d0cb12d5a220cebb783f6895bsalomon@google.com bool set(GrDrawTarget* target, 59225fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com int vertexCount, 59325fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com int indexCount); 59449f085dddff10473b6ebf832a974288300224e60bsalomon bool succeeded() const { return SkToBool(fTarget); } 595f6de475e5cbd143f348ff7738919e397b7fe7f57tfarina@chromium.org void* vertices() const { SkASSERT(this->succeeded()); return fVertices; } 596f6de475e5cbd143f348ff7738919e397b7fe7f57tfarina@chromium.org void* indices() const { SkASSERT(this->succeeded()); return fIndices; } 597972f9cd7a063d0544f8c919fd12b9a3adbd12b24commit-bot@chromium.org SkPoint* positions() const { 598972f9cd7a063d0544f8c919fd12b9a3adbd12b24commit-bot@chromium.org return static_cast<SkPoint*>(this->vertices()); 599ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com } 600ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 601ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com private: 60225fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com void reset(); 603d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com 604ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com GrDrawTarget* fTarget; 605ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com void* fVertices; 606ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com void* fIndices; 607ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com }; 608ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 60925fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com //////////////////////////////////////////////////////////////////////////// 610ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 611a0b40280a49a8a43af7929ead3b3489951c58501commit-bot@chromium.org class AutoClipRestore : public ::SkNoncopyable { 612ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com public: 613ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com AutoClipRestore(GrDrawTarget* target) { 614ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com fTarget = target; 615ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com fClip = fTarget->getClip(); 616ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com } 617ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 6188d67c0711b52226db59158a0cfce09f35badd96absalomon@google.com AutoClipRestore(GrDrawTarget* target, const SkIRect& newClip); 6198d67c0711b52226db59158a0cfce09f35badd96absalomon@google.com 620ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com ~AutoClipRestore() { 621ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com fTarget->setClip(fClip); 622ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com } 623ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com private: 6248d67c0711b52226db59158a0cfce09f35badd96absalomon@google.com GrDrawTarget* fTarget; 6258d67c0711b52226db59158a0cfce09f35badd96absalomon@google.com const GrClipData* fClip; 6268d67c0711b52226db59158a0cfce09f35badd96absalomon@google.com SkTLazy<SkClipStack> fStack; 6278d67c0711b52226db59158a0cfce09f35badd96absalomon@google.com GrClipData fReplacementClip; 628ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com }; 629d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com 63025fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com //////////////////////////////////////////////////////////////////////////// 631d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com 6320406b9e1faee06c6ecb2732a1bcf3b0e53104e07bsalomon@google.com /** 6330406b9e1faee06c6ecb2732a1bcf3b0e53104e07bsalomon@google.com * Saves the geometry src state at construction and restores in the destructor. It also saves 6340406b9e1faee06c6ecb2732a1bcf3b0e53104e07bsalomon@google.com * and then restores the vertex attrib state. 6350406b9e1faee06c6ecb2732a1bcf3b0e53104e07bsalomon@google.com */ 636a0b40280a49a8a43af7929ead3b3489951c58501commit-bot@chromium.org class AutoGeometryPush : public ::SkNoncopyable { 6370406b9e1faee06c6ecb2732a1bcf3b0e53104e07bsalomon@google.com public: 6380406b9e1faee06c6ecb2732a1bcf3b0e53104e07bsalomon@google.com AutoGeometryPush(GrDrawTarget* target) 6390406b9e1faee06c6ecb2732a1bcf3b0e53104e07bsalomon@google.com : fAttribRestore(target->drawState()) { 64049f085dddff10473b6ebf832a974288300224e60bsalomon SkASSERT(target); 6410406b9e1faee06c6ecb2732a1bcf3b0e53104e07bsalomon@google.com fTarget = target; 6420406b9e1faee06c6ecb2732a1bcf3b0e53104e07bsalomon@google.com target->pushGeometrySource(); 6430406b9e1faee06c6ecb2732a1bcf3b0e53104e07bsalomon@google.com } 6440406b9e1faee06c6ecb2732a1bcf3b0e53104e07bsalomon@google.com 6450406b9e1faee06c6ecb2732a1bcf3b0e53104e07bsalomon@google.com ~AutoGeometryPush() { fTarget->popGeometrySource(); } 6460406b9e1faee06c6ecb2732a1bcf3b0e53104e07bsalomon@google.com 6470406b9e1faee06c6ecb2732a1bcf3b0e53104e07bsalomon@google.com private: 6480406b9e1faee06c6ecb2732a1bcf3b0e53104e07bsalomon@google.com GrDrawTarget* fTarget; 6490406b9e1faee06c6ecb2732a1bcf3b0e53104e07bsalomon@google.com GrDrawState::AutoVertexAttribRestore fAttribRestore; 6500406b9e1faee06c6ecb2732a1bcf3b0e53104e07bsalomon@google.com }; 6510406b9e1faee06c6ecb2732a1bcf3b0e53104e07bsalomon@google.com 6520406b9e1faee06c6ecb2732a1bcf3b0e53104e07bsalomon@google.com /** 6530406b9e1faee06c6ecb2732a1bcf3b0e53104e07bsalomon@google.com * Combination of AutoGeometryPush and AutoStateRestore. The vertex attribs will be in default 6540406b9e1faee06c6ecb2732a1bcf3b0e53104e07bsalomon@google.com * state regardless of ASRInit value. 6550406b9e1faee06c6ecb2732a1bcf3b0e53104e07bsalomon@google.com */ 656a0b40280a49a8a43af7929ead3b3489951c58501commit-bot@chromium.org class AutoGeometryAndStatePush : public ::SkNoncopyable { 65725fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com public: 658137f1347abaf0bb6a945e91c2f6cb49f0ee69bc3bsalomon@google.com AutoGeometryAndStatePush(GrDrawTarget* target, 659137f1347abaf0bb6a945e91c2f6cb49f0ee69bc3bsalomon@google.com ASRInit init, 660137f1347abaf0bb6a945e91c2f6cb49f0ee69bc3bsalomon@google.com const SkMatrix* viewMatrix = NULL) 661137f1347abaf0bb6a945e91c2f6cb49f0ee69bc3bsalomon@google.com : fState(target, init, viewMatrix) { 66249f085dddff10473b6ebf832a974288300224e60bsalomon SkASSERT(target); 66325fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com fTarget = target; 66425fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com target->pushGeometrySource(); 6650406b9e1faee06c6ecb2732a1bcf3b0e53104e07bsalomon@google.com if (kPreserve_ASRInit == init) { 6660406b9e1faee06c6ecb2732a1bcf3b0e53104e07bsalomon@google.com target->drawState()->setDefaultVertexAttribs(); 6670406b9e1faee06c6ecb2732a1bcf3b0e53104e07bsalomon@google.com } 66825fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com } 6690406b9e1faee06c6ecb2732a1bcf3b0e53104e07bsalomon@google.com 6700406b9e1faee06c6ecb2732a1bcf3b0e53104e07bsalomon@google.com ~AutoGeometryAndStatePush() { fTarget->popGeometrySource(); } 6710406b9e1faee06c6ecb2732a1bcf3b0e53104e07bsalomon@google.com 67225fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com private: 673b75b0a0b8492e14c7728e0a0881f87dc64ce60f9jvanverth@google.com AutoStateRestore fState; 6740406b9e1faee06c6ecb2732a1bcf3b0e53104e07bsalomon@google.com GrDrawTarget* fTarget; 67525fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com }; 676ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 677a8916ffd90c04dc6cc1fb9ba94af2ff950284fadcommit-bot@chromium.org /////////////////////////////////////////////////////////////////////////// 678a8916ffd90c04dc6cc1fb9ba94af2ff950284fadcommit-bot@chromium.org // Draw execution tracking (for font atlases and other resources) 679a8916ffd90c04dc6cc1fb9ba94af2ff950284fadcommit-bot@chromium.org class DrawToken { 680a8916ffd90c04dc6cc1fb9ba94af2ff950284fadcommit-bot@chromium.org public: 681a8916ffd90c04dc6cc1fb9ba94af2ff950284fadcommit-bot@chromium.org DrawToken(GrDrawTarget* drawTarget, uint32_t drawID) : 682a8916ffd90c04dc6cc1fb9ba94af2ff950284fadcommit-bot@chromium.org fDrawTarget(drawTarget), fDrawID(drawID) {} 6837475811143e190e172bf83d13c4bdba85704b604skia.committer@gmail.com 68449f085dddff10473b6ebf832a974288300224e60bsalomon bool isIssued() { return fDrawTarget && fDrawTarget->isIssued(fDrawID); } 6857475811143e190e172bf83d13c4bdba85704b604skia.committer@gmail.com 686a8916ffd90c04dc6cc1fb9ba94af2ff950284fadcommit-bot@chromium.org private: 687a8916ffd90c04dc6cc1fb9ba94af2ff950284fadcommit-bot@chromium.org GrDrawTarget* fDrawTarget; 688a8916ffd90c04dc6cc1fb9ba94af2ff950284fadcommit-bot@chromium.org uint32_t fDrawID; // this may wrap, but we're doing direct comparison 689a8916ffd90c04dc6cc1fb9ba94af2ff950284fadcommit-bot@chromium.org // so that should be okay 690a8916ffd90c04dc6cc1fb9ba94af2ff950284fadcommit-bot@chromium.org }; 6917475811143e190e172bf83d13c4bdba85704b604skia.committer@gmail.com 692a8916ffd90c04dc6cc1fb9ba94af2ff950284fadcommit-bot@chromium.org virtual DrawToken getCurrentDrawToken() { return DrawToken(this, 0); } 6937475811143e190e172bf83d13c4bdba85704b604skia.committer@gmail.com 694ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.comprotected: 69589af44a0f1323dc136b238c00ccf143e15abb243egdaniel // Extend access to GrDrawState::convertToPEndeingExec to subclasses. 69689af44a0f1323dc136b238c00ccf143e15abb243egdaniel void convertDrawStateToPendingExec(GrDrawState* ds) { 6972a9ca782ba5db5a7ebdc315655d9a30dcd6d9845bsalomon ds->convertToPendingExec(); 6982a9ca782ba5db5a7ebdc315655d9a30dcd6d9845bsalomon } 699471d471dcd7422e5dd9c822c1092b2ba4721dcfebsalomon@google.com 70025fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com enum GeometrySrcType { 70125fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com kNone_GeometrySrcType, //<! src has not been specified 70225fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com kReserved_GeometrySrcType, //<! src was set using reserve*Space 70325fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com kArray_GeometrySrcType, //<! src was set using set*SourceToArray 70425fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com kBuffer_GeometrySrcType //<! src was set using set*SourceToBuffer 70525fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com }; 706d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com 70725fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com struct GeometrySrcState { 70825fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com GeometrySrcType fVertexSrc; 70925fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com union { 71025fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com // valid if src type is buffer 71125fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com const GrVertexBuffer* fVertexBuffer; 71225fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com // valid if src type is reserved or array 71325fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com int fVertexCount; 71425fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com }; 715d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com 71625fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com GeometrySrcType fIndexSrc; 71725fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com union { 71825fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com // valid if src type is buffer 71925fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com const GrIndexBuffer* fIndexBuffer; 72025fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com // valid if src type is reserved or array 72125fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com int fIndexCount; 72225fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com }; 723d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com 724b75b0a0b8492e14c7728e0a0881f87dc64ce60f9jvanverth@google.com size_t fVertexSize; 72525fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com }; 726934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com 727934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com int indexCountInCurrentSource() const { 728934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com const GeometrySrcState& src = this->getGeomSrc(); 729934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com switch (src.fIndexSrc) { 730934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com case kNone_GeometrySrcType: 731934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com return 0; 732934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com case kReserved_GeometrySrcType: 733934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com case kArray_GeometrySrcType: 734934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com return src.fIndexCount; 735934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com case kBuffer_GeometrySrcType: 736089a780c3355129eefc942246534bc1f126b8ccbcommit-bot@chromium.org return static_cast<int>(src.fIndexBuffer->gpuMemorySize() / sizeof(uint16_t)); 737934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com default: 73888cb22b6b4816c7a9ca6c5b795965b4606f9eb7bcommit-bot@chromium.org SkFAIL("Unexpected Index Source."); 739934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com return 0; 740934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com } 741934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com } 742a47a48dca5045d71cbc5de343404045209a13e15bsalomon@google.com 743e4617bf6d45cdde07f89e341ebf5c485916bf0b2bsalomon@google.com // This method is called by copySurface The srcRect is guaranteed to be entirely within the 744e4617bf6d45cdde07f89e341ebf5c485916bf0b2bsalomon@google.com // src bounds. Likewise, the dst rect implied by dstPoint and srcRect's width and height falls 745e4617bf6d45cdde07f89e341ebf5c485916bf0b2bsalomon@google.com // entirely within the dst. The default implementation will draw a rect from the src to the 746e4617bf6d45cdde07f89e341ebf5c485916bf0b2bsalomon@google.com // dst if the src is a texture and the dst is a render target and fail otherwise. 747e4617bf6d45cdde07f89e341ebf5c485916bf0b2bsalomon@google.com virtual bool onCopySurface(GrSurface* dst, 748e4617bf6d45cdde07f89e341ebf5c485916bf0b2bsalomon@google.com GrSurface* src, 749e4617bf6d45cdde07f89e341ebf5c485916bf0b2bsalomon@google.com const SkIRect& srcRect, 750e4617bf6d45cdde07f89e341ebf5c485916bf0b2bsalomon@google.com const SkIPoint& dstPoint); 751e4617bf6d45cdde07f89e341ebf5c485916bf0b2bsalomon@google.com 752e4617bf6d45cdde07f89e341ebf5c485916bf0b2bsalomon@google.com // Called to determine whether an onCopySurface call would succeed or not. This is useful for 753e4617bf6d45cdde07f89e341ebf5c485916bf0b2bsalomon@google.com // proxy subclasses to test whether the copy would succeed without executing it yet. Derived 754e4617bf6d45cdde07f89e341ebf5c485916bf0b2bsalomon@google.com // classes must keep this consistent with their implementation of onCopySurface(). The inputs 755e4617bf6d45cdde07f89e341ebf5c485916bf0b2bsalomon@google.com // are the same as onCopySurface(), i.e. srcRect and dstPoint are clipped to be inside the src 756e4617bf6d45cdde07f89e341ebf5c485916bf0b2bsalomon@google.com // and dst bounds. 757116ad84d3126b0db22b2312ca59ed70e5c56f6fcbsalomon@google.com virtual bool onCanCopySurface(GrSurface* dst, 758116ad84d3126b0db22b2312ca59ed70e5c56f6fcbsalomon@google.com GrSurface* src, 759116ad84d3126b0db22b2312ca59ed70e5c56f6fcbsalomon@google.com const SkIRect& srcRect, 760116ad84d3126b0db22b2312ca59ed70e5c56f6fcbsalomon@google.com const SkIPoint& dstPoint); 761e4617bf6d45cdde07f89e341ebf5c485916bf0b2bsalomon@google.com 7626e4e65066a7c0dbc9bfbfe4b8f5d49c3d8a79b59bsalomon@google.com GrContext* getContext() { return fContext; } 7636e4e65066a7c0dbc9bfbfe4b8f5d49c3d8a79b59bsalomon@google.com const GrContext* getContext() const { return fContext; } 7646e4e65066a7c0dbc9bfbfe4b8f5d49c3d8a79b59bsalomon@google.com 76502ddc8b85ace91b15feb329a6a1d5d62b2b846c6bsalomon@google.com // A subclass may override this function if it wishes to be notified when the clip is changed. 76602ddc8b85ace91b15feb329a6a1d5d62b2b846c6bsalomon@google.com // The override should call INHERITED::clipWillBeSet(). 76702ddc8b85ace91b15feb329a6a1d5d62b2b846c6bsalomon@google.com virtual void clipWillBeSet(const GrClipData* clipData); 76802ddc8b85ace91b15feb329a6a1d5d62b2b846c6bsalomon@google.com 76902ddc8b85ace91b15feb329a6a1d5d62b2b846c6bsalomon@google.com // subclasses must call this in their destructors to ensure all vertex 77002ddc8b85ace91b15feb329a6a1d5d62b2b846c6bsalomon@google.com // and index sources have been released (including those held by 77102ddc8b85ace91b15feb329a6a1d5d62b2b846c6bsalomon@google.com // pushGeometrySource()) 77202ddc8b85ace91b15feb329a6a1d5d62b2b846c6bsalomon@google.com void releaseGeometry(); 77302ddc8b85ace91b15feb329a6a1d5d62b2b846c6bsalomon@google.com 77402ddc8b85ace91b15feb329a6a1d5d62b2b846c6bsalomon@google.com // accessors for derived classes 77502ddc8b85ace91b15feb329a6a1d5d62b2b846c6bsalomon@google.com const GeometrySrcState& getGeomSrc() const { return fGeoSrcStateStack.back(); } 776b75b0a0b8492e14c7728e0a0881f87dc64ce60f9jvanverth@google.com // it is preferable to call this rather than getGeomSrc()->fVertexSize because of the assert. 777b75b0a0b8492e14c7728e0a0881f87dc64ce60f9jvanverth@google.com size_t getVertexSize() const { 77802ddc8b85ace91b15feb329a6a1d5d62b2b846c6bsalomon@google.com // the vertex layout is only valid if a vertex source has been specified. 779f6de475e5cbd143f348ff7738919e397b7fe7f57tfarina@chromium.org SkASSERT(this->getGeomSrc().fVertexSrc != kNone_GeometrySrcType); 780b75b0a0b8492e14c7728e0a0881f87dc64ce60f9jvanverth@google.com return this->getGeomSrc().fVertexSize; 781a47a48dca5045d71cbc5de343404045209a13e15bsalomon@google.com } 7825782d712ffc31557d0cb12d5a220cebb783f6895bsalomon@google.com 783bcce8926524827775539874346dd424a9510dbc9bsalomon@google.com // Subclass must initialize this in its constructor. 784c26d94fd7dc0b00cd6d0e42d28285f4a38aff021bsalomon@google.com SkAutoTUnref<const GrDrawTargetCaps> fCaps; 78502ddc8b85ace91b15feb329a6a1d5d62b2b846c6bsalomon@google.com 7862a05de0c049a8648942a55016126a1f92e1c14d6commit-bot@chromium.org const GrTraceMarkerSet& getActiveTraceMarkers() { return fActiveTraceMarkers; } 7872a05de0c049a8648942a55016126a1f92e1c14d6commit-bot@chromium.org 788d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com /** 789d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com * Used to communicate draws to subclass's onDraw function. 790d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com */ 79174749cd45c29b4f5300e2518f2c2c765ce8ae208bsalomon@google.com class DrawInfo { 79274749cd45c29b4f5300e2518f2c2c765ce8ae208bsalomon@google.com public: 79374749cd45c29b4f5300e2518f2c2c765ce8ae208bsalomon@google.com DrawInfo(const DrawInfo& di) { (*this) = di; } 794d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com DrawInfo& operator =(const DrawInfo& di); 79574749cd45c29b4f5300e2518f2c2c765ce8ae208bsalomon@google.com 79674749cd45c29b4f5300e2518f2c2c765ce8ae208bsalomon@google.com GrPrimitiveType primitiveType() const { return fPrimitiveType; } 79774749cd45c29b4f5300e2518f2c2c765ce8ae208bsalomon@google.com int startVertex() const { return fStartVertex; } 79874749cd45c29b4f5300e2518f2c2c765ce8ae208bsalomon@google.com int startIndex() const { return fStartIndex; } 79974749cd45c29b4f5300e2518f2c2c765ce8ae208bsalomon@google.com int vertexCount() const { return fVertexCount; } 80074749cd45c29b4f5300e2518f2c2c765ce8ae208bsalomon@google.com int indexCount() const { return fIndexCount; } 801d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com int verticesPerInstance() const { return fVerticesPerInstance; } 802d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com int indicesPerInstance() const { return fIndicesPerInstance; } 803d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com int instanceCount() const { return fInstanceCount; } 80474749cd45c29b4f5300e2518f2c2c765ce8ae208bsalomon@google.com 80574749cd45c29b4f5300e2518f2c2c765ce8ae208bsalomon@google.com bool isIndexed() const { return fIndexCount > 0; } 806515dcd36032997ce335daa0163c6d67e851bcad1commit-bot@chromium.org#ifdef SK_DEBUG 807d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com bool isInstanced() const; // this version is longer because of asserts 808d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com#else 809d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com bool isInstanced() const { return fInstanceCount > 0; } 810d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com#endif 811d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com 812d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com // adds or remove instances 813d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com void adjustInstanceCount(int instanceOffset); 814d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com // shifts the start vertex 815d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com void adjustStartVertex(int vertexOffset); 816d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com // shifts the start index 817d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com void adjustStartIndex(int indexOffset); 818d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com 819d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com void setDevBounds(const SkRect& bounds) { 820d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com fDevBoundsStorage = bounds; 821d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com fDevBounds = &fDevBoundsStorage; 822d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com } 823d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com const SkRect* getDevBounds() const { return fDevBounds; } 82405a2ee052c9ef4c781b7b590b00b3d2da3b3449askia.committer@gmail.com 82526e18b593ab65e4d92dfbce92579d8bc180d4c2cbsalomon@google.com // NULL if no copy of the dst is needed for the draw. 82626e18b593ab65e4d92dfbce92579d8bc180d4c2cbsalomon@google.com const GrDeviceCoordTexture* getDstCopy() const { 82749f085dddff10473b6ebf832a974288300224e60bsalomon if (fDstCopy.texture()) { 82826e18b593ab65e4d92dfbce92579d8bc180d4c2cbsalomon@google.com return &fDstCopy; 82926e18b593ab65e4d92dfbce92579d8bc180d4c2cbsalomon@google.com } else { 83026e18b593ab65e4d92dfbce92579d8bc180d4c2cbsalomon@google.com return NULL; 83126e18b593ab65e4d92dfbce92579d8bc180d4c2cbsalomon@google.com } 83226e18b593ab65e4d92dfbce92579d8bc180d4c2cbsalomon@google.com } 83326e18b593ab65e4d92dfbce92579d8bc180d4c2cbsalomon@google.com 83474749cd45c29b4f5300e2518f2c2c765ce8ae208bsalomon@google.com private: 835d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com DrawInfo() { fDevBounds = NULL; } 836d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com 83774749cd45c29b4f5300e2518f2c2c765ce8ae208bsalomon@google.com friend class GrDrawTarget; 838d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com 83926e18b593ab65e4d92dfbce92579d8bc180d4c2cbsalomon@google.com GrPrimitiveType fPrimitiveType; 84074749cd45c29b4f5300e2518f2c2c765ce8ae208bsalomon@google.com 84126e18b593ab65e4d92dfbce92579d8bc180d4c2cbsalomon@google.com int fStartVertex; 84226e18b593ab65e4d92dfbce92579d8bc180d4c2cbsalomon@google.com int fStartIndex; 84326e18b593ab65e4d92dfbce92579d8bc180d4c2cbsalomon@google.com int fVertexCount; 84426e18b593ab65e4d92dfbce92579d8bc180d4c2cbsalomon@google.com int fIndexCount; 845d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com 84626e18b593ab65e4d92dfbce92579d8bc180d4c2cbsalomon@google.com int fInstanceCount; 84726e18b593ab65e4d92dfbce92579d8bc180d4c2cbsalomon@google.com int fVerticesPerInstance; 84826e18b593ab65e4d92dfbce92579d8bc180d4c2cbsalomon@google.com int fIndicesPerInstance; 849d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com 85026e18b593ab65e4d92dfbce92579d8bc180d4c2cbsalomon@google.com SkRect fDevBoundsStorage; 85126e18b593ab65e4d92dfbce92579d8bc180d4c2cbsalomon@google.com SkRect* fDevBounds; 85226e18b593ab65e4d92dfbce92579d8bc180d4c2cbsalomon@google.com 85326e18b593ab65e4d92dfbce92579d8bc180d4c2cbsalomon@google.com GrDeviceCoordTexture fDstCopy; 85474749cd45c29b4f5300e2518f2c2c765ce8ae208bsalomon@google.com }; 85574749cd45c29b4f5300e2518f2c2c765ce8ae208bsalomon@google.com 856651713408c5a5d9565665967ad09981250c7a8c9joshualitt // Makes a copy of the dst if it is necessary for the draw. Returns false if a copy is required 857651713408c5a5d9565665967ad09981250c7a8c9joshualitt // but couldn't be made. Otherwise, returns true. This method needs to be protected because it 858651713408c5a5d9565665967ad09981250c7a8c9joshualitt // needs to be accessed by GLPrograms to setup a correct drawstate 859651713408c5a5d9565665967ad09981250c7a8c9joshualitt bool setupDstReadIfNecessary(DrawInfo* info) { 860651713408c5a5d9565665967ad09981250c7a8c9joshualitt return this->setupDstReadIfNecessary(&info->fDstCopy, info->getDevBounds()); 861651713408c5a5d9565665967ad09981250c7a8c9joshualitt } 862651713408c5a5d9565665967ad09981250c7a8c9joshualitt bool setupDstReadIfNecessary(GrDeviceCoordTexture* dstCopy, const SkRect* drawBounds); 863651713408c5a5d9565665967ad09981250c7a8c9joshualitt 86402ddc8b85ace91b15feb329a6a1d5d62b2b846c6bsalomon@google.comprivate: 86502ddc8b85ace91b15feb329a6a1d5d62b2b846c6bsalomon@google.com // A subclass can optionally overload this function to be notified before 86602ddc8b85ace91b15feb329a6a1d5d62b2b846c6bsalomon@google.com // vertex and index space is reserved. 867b75b0a0b8492e14c7728e0a0881f87dc64ce60f9jvanverth@google.com virtual void willReserveVertexAndIndexSpace(int vertexCount, int indexCount) {} 86897805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com 86925fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com // implemented by subclass to allocate space for reserved geom 870a63389843dd18003382d61c2e4610af09ed07d38jvanverth@google.com virtual bool onReserveVertexSpace(size_t vertexSize, int vertexCount, void** vertices) = 0; 87125fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com virtual bool onReserveIndexSpace(int indexCount, void** indices) = 0; 87225fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com // implemented by subclass to handle release of reserved geom space 87325fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com virtual void releaseReservedVertexSpace() = 0; 87425fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com virtual void releaseReservedIndexSpace() = 0; 87525fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com // subclass must consume array contents when set 87602ddc8b85ace91b15feb329a6a1d5d62b2b846c6bsalomon@google.com virtual void onSetVertexSourceToArray(const void* vertexArray, int vertexCount) = 0; 87702ddc8b85ace91b15feb329a6a1d5d62b2b846c6bsalomon@google.com virtual void onSetIndexSourceToArray(const void* indexArray, int indexCount) = 0; 87825fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com // subclass is notified that geom source will be set away from an array 87925fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com virtual void releaseVertexArray() = 0; 88025fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com virtual void releaseIndexArray() = 0; 88102ddc8b85ace91b15feb329a6a1d5d62b2b846c6bsalomon@google.com // subclass overrides to be notified just before geo src state is pushed/popped. 88225fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com virtual void geometrySourceWillPush() = 0; 88325fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com virtual void geometrySourceWillPop(const GeometrySrcState& restoredState) = 0; 88425fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com // subclass called to perform drawing 88574749cd45c29b4f5300e2518f2c2c765ce8ae208bsalomon@google.com virtual void onDraw(const DrawInfo&) = 0; 8860406b9e1faee06c6ecb2732a1bcf3b0e53104e07bsalomon@google.com // Implementation of drawRect. The geometry src and vertex attribs will already 8870406b9e1faee06c6ecb2732a1bcf3b0e53104e07bsalomon@google.com // be saved before this is called and restored afterwards. A subclass may override 8880406b9e1faee06c6ecb2732a1bcf3b0e53104e07bsalomon@google.com // this to perform more optimal rect rendering. Its draws should be funneled through 8890406b9e1faee06c6ecb2732a1bcf3b0e53104e07bsalomon@google.com // one of the public GrDrawTarget draw methods (e.g. drawNonIndexed, 8900406b9e1faee06c6ecb2732a1bcf3b0e53104e07bsalomon@google.com // drawIndexedInstances, ...). The base class draws a two triangle fan using 8910406b9e1faee06c6ecb2732a1bcf3b0e53104e07bsalomon@google.com // drawNonIndexed from reserved vertex space. 892fd03d4a829efe2d77a712fd991927c55f59a2ffecommit-bot@chromium.org virtual void onDrawRect(const SkRect& rect, 893fd03d4a829efe2d77a712fd991927c55f59a2ffecommit-bot@chromium.org const SkRect* localRect, 8940406b9e1faee06c6ecb2732a1bcf3b0e53104e07bsalomon@google.com const SkMatrix* localMatrix); 89532184d81629e39809bb9e915286d8fe971a8ed68commit-bot@chromium.org 89692e496f96abbd664888f0c8a7d546ab02e703bf7joshualitt virtual void onStencilPath(const GrPath*, GrPathRendering::FillType) = 0; 89792e496f96abbd664888f0c8a7d546ab02e703bf7joshualitt virtual void onDrawPath(const GrPath*, GrPathRendering::FillType, 898c4dc0ad8e252a7e30d19b47d3d0d9f2c69faf854commit-bot@chromium.org const GrDeviceCoordTexture* dstCopy) = 0; 899b85a0aab6905af8b329539b7573a7555b727d5e5cdalton virtual void onDrawPaths(const GrPathRange*, 900b85a0aab6905af8b329539b7573a7555b727d5e5cdalton const uint32_t indices[], int count, 901b85a0aab6905af8b329539b7573a7555b727d5e5cdalton const float transforms[], PathTransformType, 90292e496f96abbd664888f0c8a7d546ab02e703bf7joshualitt GrPathRendering::FillType, const GrDeviceCoordTexture*) = 0; 90364aef2bacd1f5c25ffd9347aabd6265c9b60c0f4bsalomon@google.com 9042a05de0c049a8648942a55016126a1f92e1c14d6commit-bot@chromium.org virtual void didAddGpuTraceMarker() = 0; 9052a05de0c049a8648942a55016126a1f92e1c14d6commit-bot@chromium.org virtual void didRemoveGpuTraceMarker() = 0; 906a3baf3be0e2a3128fb73bd41d40d130f75a4dc86commit-bot@chromium.org 907e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com // helpers for reserving vertex and index space. 908b75b0a0b8492e14c7728e0a0881f87dc64ce60f9jvanverth@google.com bool reserveVertexSpace(size_t vertexSize, 909e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com int vertexCount, 910e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com void** vertices); 911e3d7095c2374a423815e662020459832f389a40fbsalomon@google.com bool reserveIndexSpace(int indexCount, void** indices); 912d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com 913e826262939dac3e67cb5ce66d4b9faeb8e2538e6bsalomon@google.com // called by drawIndexed and drawNonIndexed. Use a negative indexCount to 914e826262939dac3e67cb5ce66d4b9faeb8e2538e6bsalomon@google.com // indicate non-indexed drawing. 915e826262939dac3e67cb5ce66d4b9faeb8e2538e6bsalomon@google.com bool checkDraw(GrPrimitiveType type, int startVertex, 916e826262939dac3e67cb5ce66d4b9faeb8e2538e6bsalomon@google.com int startIndex, int vertexCount, 917e826262939dac3e67cb5ce66d4b9faeb8e2538e6bsalomon@google.com int indexCount) const; 91825fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com // called when setting a new vert/idx source to unref prev vb/ib 91925fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com void releasePreviousVertexSource(); 92025fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com void releasePreviousIndexSource(); 921d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com 922a8916ffd90c04dc6cc1fb9ba94af2ff950284fadcommit-bot@chromium.org // Check to see if this set of draw commands has been sent out 923a8916ffd90c04dc6cc1fb9ba94af2ff950284fadcommit-bot@chromium.org virtual bool isIssued(uint32_t drawID) { return true; } 924a393127de5153987f9e1f3e40f8ef8e63a3927f5joshualitt virtual GrClipMaskManager* getClipMaskManager() = 0; 9257475811143e190e172bf83d13c4bdba85704b604skia.committer@gmail.com 92625fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com enum { 92725fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com kPreallocGeoSrcStateStackCnt = 4, 928ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com }; 92902ddc8b85ace91b15feb329a6a1d5d62b2b846c6bsalomon@google.com SkSTArray<kPreallocGeoSrcStateStackCnt, GeometrySrcState, true> fGeoSrcStateStack; 93002ddc8b85ace91b15feb329a6a1d5d62b2b846c6bsalomon@google.com const GrClipData* fClip; 93102ddc8b85ace91b15feb329a6a1d5d62b2b846c6bsalomon@google.com GrDrawState* fDrawState; 93202ddc8b85ace91b15feb329a6a1d5d62b2b846c6bsalomon@google.com GrDrawState fDefaultDrawState; 9336e4e65066a7c0dbc9bfbfe4b8f5d49c3d8a79b59bsalomon@google.com // The context owns us, not vice-versa, so this ptr is not ref'ed by DrawTarget. 9346e4e65066a7c0dbc9bfbfe4b8f5d49c3d8a79b59bsalomon@google.com GrContext* fContext; 9352a05de0c049a8648942a55016126a1f92e1c14d6commit-bot@chromium.org // To keep track that we always have at least as many debug marker adds as removes 9362a05de0c049a8648942a55016126a1f92e1c14d6commit-bot@chromium.org int fGpuTraceMarkerCount; 9372a05de0c049a8648942a55016126a1f92e1c14d6commit-bot@chromium.org GrTraceMarkerSet fActiveTraceMarkers; 9383eee3834fba1d2e29dfb61adcb97e4624b6a3ac8egdaniel GrTraceMarkerSet fStoredTraceMarkers; 939fa35e3ddcc9d130ce87c927218bdf27879c38711reed@google.com 940a4de8c257ea0be8ff7081f645249b6afe5c48e7ecommit-bot@chromium.org typedef SkRefCnt INHERITED; 941ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com}; 942ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 943329bf4862e9d5e05363c2b071d8ca475a0ef1952joshualitt/* 944329bf4862e9d5e05363c2b071d8ca475a0ef1952joshualitt * This class is JUST for clip mask manager. Everyone else should just use draw target above. 945329bf4862e9d5e05363c2b071d8ca475a0ef1952joshualitt */ 9466db519c42471aaaa8a8e1a3ece314014481ab832joshualittclass GrClipTarget : public GrDrawTarget { 9476db519c42471aaaa8a8e1a3ece314014481ab832joshualittpublic: 948329bf4862e9d5e05363c2b071d8ca475a0ef1952joshualitt GrClipTarget(GrContext* context) : INHERITED(context) { 949329bf4862e9d5e05363c2b071d8ca475a0ef1952joshualitt fClipMaskManager.setClipTarget(this); 950329bf4862e9d5e05363c2b071d8ca475a0ef1952joshualitt } 951329bf4862e9d5e05363c2b071d8ca475a0ef1952joshualitt 952329bf4862e9d5e05363c2b071d8ca475a0ef1952joshualitt /* Clip mask manager needs access to the context. 953329bf4862e9d5e05363c2b071d8ca475a0ef1952joshualitt * TODO we only need a very small subset of context in the CMM. 954329bf4862e9d5e05363c2b071d8ca475a0ef1952joshualitt */ 955329bf4862e9d5e05363c2b071d8ca475a0ef1952joshualitt GrContext* getContext() { return INHERITED::getContext(); } 956329bf4862e9d5e05363c2b071d8ca475a0ef1952joshualitt const GrContext* getContext() const { return INHERITED::getContext(); } 957329bf4862e9d5e05363c2b071d8ca475a0ef1952joshualitt 9586db519c42471aaaa8a8e1a3ece314014481ab832joshualitt /** 9596db519c42471aaaa8a8e1a3ece314014481ab832joshualitt * Clip Mask Manager(and no one else) needs to clear private stencil bits. 9606db519c42471aaaa8a8e1a3ece314014481ab832joshualitt * ClipTarget subclass sets clip bit in the stencil buffer. The subclass 9616db519c42471aaaa8a8e1a3ece314014481ab832joshualitt * is free to clear the remaining bits to zero if masked clears are more 9626db519c42471aaaa8a8e1a3ece314014481ab832joshualitt * expensive than clearing all bits. 9636db519c42471aaaa8a8e1a3ece314014481ab832joshualitt */ 9646db519c42471aaaa8a8e1a3ece314014481ab832joshualitt virtual void clearStencilClip(const SkIRect& rect, bool insideClip, GrRenderTarget* = NULL) = 0; 9656db519c42471aaaa8a8e1a3ece314014481ab832joshualitt 9663bdd7dce5e8393aeed0a64b583e1077f5159d516joshualitt /** 9673bdd7dce5e8393aeed0a64b583e1077f5159d516joshualitt * Release any resources that are cached but not currently in use. This 9683bdd7dce5e8393aeed0a64b583e1077f5159d516joshualitt * is intended to give an application some recourse when resources are low. 9693bdd7dce5e8393aeed0a64b583e1077f5159d516joshualitt */ 9703bdd7dce5e8393aeed0a64b583e1077f5159d516joshualitt virtual void purgeResources() SK_OVERRIDE { 9713bdd7dce5e8393aeed0a64b583e1077f5159d516joshualitt // The clip mask manager can rebuild all its clip masks so just 9723bdd7dce5e8393aeed0a64b583e1077f5159d516joshualitt // get rid of them all. 9733bdd7dce5e8393aeed0a64b583e1077f5159d516joshualitt fClipMaskManager.purgeResources(); 9743bdd7dce5e8393aeed0a64b583e1077f5159d516joshualitt }; 9753bdd7dce5e8393aeed0a64b583e1077f5159d516joshualitt 976329bf4862e9d5e05363c2b071d8ca475a0ef1952joshualittprotected: 977329bf4862e9d5e05363c2b071d8ca475a0ef1952joshualitt GrClipMaskManager fClipMaskManager; 978329bf4862e9d5e05363c2b071d8ca475a0ef1952joshualitt 9796db519c42471aaaa8a8e1a3ece314014481ab832joshualittprivate: 980a393127de5153987f9e1f3e40f8ef8e63a3927f5joshualitt GrClipMaskManager* getClipMaskManager() { return &fClipMaskManager; } 981329bf4862e9d5e05363c2b071d8ca475a0ef1952joshualitt 9826db519c42471aaaa8a8e1a3ece314014481ab832joshualitt typedef GrDrawTarget INHERITED; 9836db519c42471aaaa8a8e1a3ece314014481ab832joshualitt}; 9846db519c42471aaaa8a8e1a3ece314014481ab832joshualitt 985ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com#endif 986