GrPipelineBuilder.h revision 04ddf89627077ea8f2b447e7cd5e902956341a32
19381363050ec9d3e724076a8e9152bfa9a8de1d1tomhudson@google.com/* 29381363050ec9d3e724076a8e9152bfa9a8de1d1tomhudson@google.com * Copyright 2011 Google Inc. 39381363050ec9d3e724076a8e9152bfa9a8de1d1tomhudson@google.com * 49381363050ec9d3e724076a8e9152bfa9a8de1d1tomhudson@google.com * Use of this source code is governed by a BSD-style license that can be 59381363050ec9d3e724076a8e9152bfa9a8de1d1tomhudson@google.com * found in the LICENSE file. 69381363050ec9d3e724076a8e9152bfa9a8de1d1tomhudson@google.com */ 79381363050ec9d3e724076a8e9152bfa9a8de1d1tomhudson@google.com 89381363050ec9d3e724076a8e9152bfa9a8de1d1tomhudson@google.com#ifndef GrDrawState_DEFINED 99381363050ec9d3e724076a8e9152bfa9a8de1d1tomhudson@google.com#define GrDrawState_DEFINED 109381363050ec9d3e724076a8e9152bfa9a8de1d1tomhudson@google.com 1189af44a0f1323dc136b238c00ccf143e15abb243egdaniel 1224ab3b0ce50b3428f063849b6160e468f047487ccommit-bot@chromium.org#include "GrBlend.h" 13c06482494d2be6481a3666a66254b6c66890f994egdaniel#include "GrDrawTargetCaps.h" 146251d17dfadbbeba8a7e72affde5cbdbd0c0c95fbsalomon#include "GrGeometryProcessor.h" 15f96ba02513eadd9fa24d75396ec9f2d6682e464cbsalomon#include "GrGpuResourceRef.h" 16ae59b77612c42ff6b793dc33e3d115e6a5db34ccbsalomon#include "GrFragmentStage.h" 17b6cbc38702dc4a1540a17181cbdab71060c92ce7egdaniel#include "GrProcOptInfo.h" 1889af44a0f1323dc136b238c00ccf143e15abb243egdaniel#include "GrRenderTarget.h" 1989af44a0f1323dc136b238c00ccf143e15abb243egdaniel#include "GrStencil.h" 2089af44a0f1323dc136b238c00ccf143e15abb243egdaniel#include "SkMatrix.h" 2168b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.com#include "effects/GrSimpleTextureEffect.h" 229381363050ec9d3e724076a8e9152bfa9a8de1d1tomhudson@google.com 2389af44a0f1323dc136b238c00ccf143e15abb243egdanielclass GrDrawTargetCaps; 2489af44a0f1323dc136b238c00ccf143e15abb243egdanielclass GrPaint; 2589af44a0f1323dc136b238c00ccf143e15abb243egdanielclass GrTexture; 26170f90b4576f291879371ecd6ae4bc2b1d85c64aegdaniel 279853ccef19c200be93a6211f32589fa82a53067cjoshualittclass GrDrawState { 282e3d144dfdbc4596d33baef7396316f88f412cc8bsalomon@google.compublic: 2969bb90c214ca554f0c41a9a9c88172dbdb1da563egdaniel GrDrawState() { 301acc3d7cc28c5631b5300578ab13439bdefd4e33commit-bot@chromium.org SkDEBUGCODE(fBlockEffectRemovalCnt = 0;) 31eb6879f50a5564eeb981ec5616b55bf685eb76fcbsalomon@google.com this->reset(); 32eb6879f50a5564eeb981ec5616b55bf685eb76fcbsalomon@google.com } 33137f1347abaf0bb6a945e91c2f6cb49f0ee69bc3bsalomon@google.com 3469bb90c214ca554f0c41a9a9c88172dbdb1da563egdaniel GrDrawState(const SkMatrix& initialViewMatrix) { 351acc3d7cc28c5631b5300578ab13439bdefd4e33commit-bot@chromium.org SkDEBUGCODE(fBlockEffectRemovalCnt = 0;) 36eb6879f50a5564eeb981ec5616b55bf685eb76fcbsalomon@google.com this->reset(initialViewMatrix); 37eb6879f50a5564eeb981ec5616b55bf685eb76fcbsalomon@google.com } 3846f7afb9867200b568c21736da8a8bbb56b20e30bsalomon@google.com 39137f1347abaf0bb6a945e91c2f6cb49f0ee69bc3bsalomon@google.com /** 40137f1347abaf0bb6a945e91c2f6cb49f0ee69bc3bsalomon@google.com * Copies another draw state. 41137f1347abaf0bb6a945e91c2f6cb49f0ee69bc3bsalomon@google.com **/ 429853ccef19c200be93a6211f32589fa82a53067cjoshualitt GrDrawState(const GrDrawState& state) { 431acc3d7cc28c5631b5300578ab13439bdefd4e33commit-bot@chromium.org SkDEBUGCODE(fBlockEffectRemovalCnt = 0;) 4446f7afb9867200b568c21736da8a8bbb56b20e30bsalomon@google.com *this = state; 4546f7afb9867200b568c21736da8a8bbb56b20e30bsalomon@google.com } 4646f7afb9867200b568c21736da8a8bbb56b20e30bsalomon@google.com 47137f1347abaf0bb6a945e91c2f6cb49f0ee69bc3bsalomon@google.com /** 48137f1347abaf0bb6a945e91c2f6cb49f0ee69bc3bsalomon@google.com * Copies another draw state with a preconcat to the view matrix. 49137f1347abaf0bb6a945e91c2f6cb49f0ee69bc3bsalomon@google.com **/ 508f7273399466c95c0c86b099de438d6ef1a15c88bsalomon GrDrawState(const GrDrawState& state, const SkMatrix& preConcatMatrix); 519ec075366ed94802a142fc5e948d19a774f85b43robertphillips@google.com 52170f90b4576f291879371ecd6ae4bc2b1d85c64aegdaniel virtual ~GrDrawState(); 53137f1347abaf0bb6a945e91c2f6cb49f0ee69bc3bsalomon@google.com 5452a5dcb43b5acbde377f664807b0f75af8bb1666bsalomon@google.com /** 55b0a8a377f832c59cee939ad721e1f87d378b7142joshualitt * Resets to the default state. GrProcessors will be removed from all stages. 56d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com */ 57137f1347abaf0bb6a945e91c2f6cb49f0ee69bc3bsalomon@google.com void reset() { this->onReset(NULL); } 58ca43208e4aaac817fbc8265542f995f24a3fb7bfbsalomon@google.com 59137f1347abaf0bb6a945e91c2f6cb49f0ee69bc3bsalomon@google.com void reset(const SkMatrix& initialViewMatrix) { this->onReset(&initialViewMatrix); } 60af84e748cedbf43e2d0e8d2eac9b7800c8d8ca19bsalomon@google.com 61af84e748cedbf43e2d0e8d2eac9b7800c8d8ca19bsalomon@google.com /** 62bb6a3178c3e79c8549b332e4ce84c64b59964f1ecommit-bot@chromium.org * Initializes the GrDrawState based on a GrPaint, view matrix and render target. Note that 63bb6a3178c3e79c8549b332e4ce84c64b59964f1ecommit-bot@chromium.org * GrDrawState encompasses more than GrPaint. Aspects of GrDrawState that have no GrPaint 649c0822a4150e23cec9f9b72bd1abc2c5f9ea5a3bbsalomon * equivalents are set to default values with the exception of vertex attribute state which 659c0822a4150e23cec9f9b72bd1abc2c5f9ea5a3bbsalomon * is unmodified by this function and clipping which will be enabled. 66af84e748cedbf43e2d0e8d2eac9b7800c8d8ca19bsalomon@google.com */ 67bb6a3178c3e79c8549b332e4ce84c64b59964f1ecommit-bot@chromium.org void setFromPaint(const GrPaint& , const SkMatrix& viewMatrix, GrRenderTarget*); 688f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com 698f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com /////////////////////////////////////////////////////////////////////////// 709b855c7c95ce9fff7a447e4a6bdf8a469c1f3097jvanverth@google.com /// @name Vertex Attributes 71cc78238f0b6aa1a7b3fc767758d9eeef4c1bffa9jvanverth@google.com //// 72cc78238f0b6aa1a7b3fc767758d9eeef4c1bffa9jvanverth@google.com 7389af44a0f1323dc136b238c00ccf143e15abb243egdaniel enum { 7489af44a0f1323dc136b238c00ccf143e15abb243egdaniel kMaxVertexAttribCnt = kLast_GrVertexAttribBinding + 4, 7589af44a0f1323dc136b238c00ccf143e15abb243egdaniel }; 7689af44a0f1323dc136b238c00ccf143e15abb243egdaniel 7789af44a0f1323dc136b238c00ccf143e15abb243egdaniel const GrVertexAttrib* getVertexAttribs() const { return fVAPtr; } 7889af44a0f1323dc136b238c00ccf143e15abb243egdaniel int getVertexAttribCount() const { return fVACount; } 7989af44a0f1323dc136b238c00ccf143e15abb243egdaniel 8089af44a0f1323dc136b238c00ccf143e15abb243egdaniel size_t getVertexStride() const { return fVAStride; } 8189af44a0f1323dc136b238c00ccf143e15abb243egdaniel 8289af44a0f1323dc136b238c00ccf143e15abb243egdaniel bool hasLocalCoordAttribute() const { 8389af44a0f1323dc136b238c00ccf143e15abb243egdaniel return -1 != fFixedFunctionVertexAttribIndices[kLocalCoord_GrVertexAttribBinding]; 8489af44a0f1323dc136b238c00ccf143e15abb243egdaniel } 8589af44a0f1323dc136b238c00ccf143e15abb243egdaniel bool hasColorVertexAttribute() const { 8689af44a0f1323dc136b238c00ccf143e15abb243egdaniel return -1 != fFixedFunctionVertexAttribIndices[kColor_GrVertexAttribBinding]; 8789af44a0f1323dc136b238c00ccf143e15abb243egdaniel } 8889af44a0f1323dc136b238c00ccf143e15abb243egdaniel bool hasCoverageVertexAttribute() const { 8989af44a0f1323dc136b238c00ccf143e15abb243egdaniel return -1 != fFixedFunctionVertexAttribIndices[kCoverage_GrVertexAttribBinding]; 9089af44a0f1323dc136b238c00ccf143e15abb243egdaniel } 9189af44a0f1323dc136b238c00ccf143e15abb243egdaniel 9289af44a0f1323dc136b238c00ccf143e15abb243egdaniel const int* getFixedFunctionVertexAttribIndices() const { 9389af44a0f1323dc136b238c00ccf143e15abb243egdaniel return fFixedFunctionVertexAttribIndices; 9489af44a0f1323dc136b238c00ccf143e15abb243egdaniel } 9589af44a0f1323dc136b238c00ccf143e15abb243egdaniel 9689af44a0f1323dc136b238c00ccf143e15abb243egdaniel bool validateVertexAttribs() const; 9789af44a0f1323dc136b238c00ccf143e15abb243egdaniel 989b855c7c95ce9fff7a447e4a6bdf8a469c1f3097jvanverth@google.com /** 99054ae99d93711c26e40682a0e3a03a47ea605c53jvanverth@google.com * The format of vertices is represented as an array of GrVertexAttribs, with each representing 100054ae99d93711c26e40682a0e3a03a47ea605c53jvanverth@google.com * the type of the attribute, its offset, and semantic binding (see GrVertexAttrib in 101054ae99d93711c26e40682a0e3a03a47ea605c53jvanverth@google.com * GrTypesPriv.h). 102cc78238f0b6aa1a7b3fc767758d9eeef4c1bffa9jvanverth@google.com * 103b0a8a377f832c59cee939ad721e1f87d378b7142joshualitt * The mapping of attributes with kEffect bindings to GrProcessor inputs is specified when 104054ae99d93711c26e40682a0e3a03a47ea605c53jvanverth@google.com * setEffect is called. 105cc78238f0b6aa1a7b3fc767758d9eeef4c1bffa9jvanverth@google.com */ 106af3a3b9fb1f3be46082013a2d1977d12faf1f61crobertphillips@google.com 107af3a3b9fb1f3be46082013a2d1977d12faf1f61crobertphillips@google.com /** 108429033038271147ed66b4bc2675ac98a5ccfa75crobertphillips@google.com * Sets vertex attributes for next draw. The object driving the templatization 109429033038271147ed66b4bc2675ac98a5ccfa75crobertphillips@google.com * should be a global GrVertexAttrib array that is never changed. 1107b3d5ee72c2238aa239bce4d5b3aea98a437ca7aegdaniel * 1117b3d5ee72c2238aa239bce4d5b3aea98a437ca7aegdaniel * @param count the number of attributes being set, limited to kMaxVertexAttribCnt. 1127b3d5ee72c2238aa239bce4d5b3aea98a437ca7aegdaniel * @param stride the number of bytes between successive vertex data. 113af3a3b9fb1f3be46082013a2d1977d12faf1f61crobertphillips@google.com */ 1147b3d5ee72c2238aa239bce4d5b3aea98a437ca7aegdaniel template <const GrVertexAttrib A[]> void setVertexAttribs(int count, size_t stride) { 1157b3d5ee72c2238aa239bce4d5b3aea98a437ca7aegdaniel this->internalSetVertexAttribs(A, count, stride); 116429033038271147ed66b4bc2675ac98a5ccfa75crobertphillips@google.com } 117af3a3b9fb1f3be46082013a2d1977d12faf1f61crobertphillips@google.com 118af3a3b9fb1f3be46082013a2d1977d12faf1f61crobertphillips@google.com /** 119054ae99d93711c26e40682a0e3a03a47ea605c53jvanverth@google.com * Sets default vertex attributes for next draw. The default is a single attribute: 120054ae99d93711c26e40682a0e3a03a47ea605c53jvanverth@google.com * {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribType} 121af3a3b9fb1f3be46082013a2d1977d12faf1f61crobertphillips@google.com */ 1229b855c7c95ce9fff7a447e4a6bdf8a469c1f3097jvanverth@google.com void setDefaultVertexAttribs(); 123af3a3b9fb1f3be46082013a2d1977d12faf1f61crobertphillips@google.com 124054ae99d93711c26e40682a0e3a03a47ea605c53jvanverth@google.com /** 1250406b9e1faee06c6ecb2732a1bcf3b0e53104e07bsalomon@google.com * Helper to save/restore vertex attribs 1260406b9e1faee06c6ecb2732a1bcf3b0e53104e07bsalomon@google.com */ 1270406b9e1faee06c6ecb2732a1bcf3b0e53104e07bsalomon@google.com class AutoVertexAttribRestore { 1280406b9e1faee06c6ecb2732a1bcf3b0e53104e07bsalomon@google.com public: 1298f7273399466c95c0c86b099de438d6ef1a15c88bsalomon AutoVertexAttribRestore(GrDrawState* drawState); 1308f7273399466c95c0c86b099de438d6ef1a15c88bsalomon 1313658f382cc129e463d7f40a7e68214d04d50fe14egdaniel ~AutoVertexAttribRestore() { fDrawState->internalSetVertexAttribs(fVAPtr, fVACount, 1323658f382cc129e463d7f40a7e68214d04d50fe14egdaniel fVAStride); } 1330406b9e1faee06c6ecb2732a1bcf3b0e53104e07bsalomon@google.com 1340406b9e1faee06c6ecb2732a1bcf3b0e53104e07bsalomon@google.com private: 135429033038271147ed66b4bc2675ac98a5ccfa75crobertphillips@google.com GrDrawState* fDrawState; 136429033038271147ed66b4bc2675ac98a5ccfa75crobertphillips@google.com const GrVertexAttrib* fVAPtr; 137429033038271147ed66b4bc2675ac98a5ccfa75crobertphillips@google.com int fVACount; 1387b3d5ee72c2238aa239bce4d5b3aea98a437ca7aegdaniel size_t fVAStride; 1390406b9e1faee06c6ecb2732a1bcf3b0e53104e07bsalomon@google.com }; 1400406b9e1faee06c6ecb2732a1bcf3b0e53104e07bsalomon@google.com 1419b855c7c95ce9fff7a447e4a6bdf8a469c1f3097jvanverth@google.com /// @} 1429b855c7c95ce9fff7a447e4a6bdf8a469c1f3097jvanverth@google.com 1439b855c7c95ce9fff7a447e4a6bdf8a469c1f3097jvanverth@google.com /** 14462c447d3a556e3042cdf5d23b3e2a618eaa3c100bsalomon * Depending on features available in the underlying 3D API and the color blend mode requested 14562c447d3a556e3042cdf5d23b3e2a618eaa3c100bsalomon * it may or may not be possible to correctly blend with fractional pixel coverage generated by 14662c447d3a556e3042cdf5d23b3e2a618eaa3c100bsalomon * the fragment shader. 14762c447d3a556e3042cdf5d23b3e2a618eaa3c100bsalomon * 14862c447d3a556e3042cdf5d23b3e2a618eaa3c100bsalomon * This function considers the current draw state and the draw target's capabilities to 14962c447d3a556e3042cdf5d23b3e2a618eaa3c100bsalomon * determine whether coverage can be handled correctly. This function assumes that the caller 15062c447d3a556e3042cdf5d23b3e2a618eaa3c100bsalomon * intends to specify fractional pixel coverage (via setCoverage(), through a coverage vertex 15162c447d3a556e3042cdf5d23b3e2a618eaa3c100bsalomon * attribute, or a coverage effect) but may not have specified it yet. 15262c447d3a556e3042cdf5d23b3e2a618eaa3c100bsalomon */ 15362c447d3a556e3042cdf5d23b3e2a618eaa3c100bsalomon bool couldApplyCoverage(const GrDrawTargetCaps& caps) const; 15462c447d3a556e3042cdf5d23b3e2a618eaa3c100bsalomon 15589af44a0f1323dc136b238c00ccf143e15abb243egdaniel /** 15689af44a0f1323dc136b238c00ccf143e15abb243egdaniel * Determines whether the output coverage is guaranteed to be one for all pixels hit by a draw. 15789af44a0f1323dc136b238c00ccf143e15abb243egdaniel */ 15889af44a0f1323dc136b238c00ccf143e15abb243egdaniel bool hasSolidCoverage() const; 15989af44a0f1323dc136b238c00ccf143e15abb243egdaniel 160cd8b6307fe636eeff822c0e48db2a0cb80a33830egdaniel /** 161cd8b6307fe636eeff822c0e48db2a0cb80a33830egdaniel * This function returns true if the render target destination pixel values will be read for 162cd8b6307fe636eeff822c0e48db2a0cb80a33830egdaniel * blending during draw. 163cd8b6307fe636eeff822c0e48db2a0cb80a33830egdaniel */ 164cd8b6307fe636eeff822c0e48db2a0cb80a33830egdaniel bool willBlendWithDst() const; 165cd8b6307fe636eeff822c0e48db2a0cb80a33830egdaniel 166cc78238f0b6aa1a7b3fc767758d9eeef4c1bffa9jvanverth@google.com /// @} 167cc78238f0b6aa1a7b3fc767758d9eeef4c1bffa9jvanverth@google.com 168cc78238f0b6aa1a7b3fc767758d9eeef4c1bffa9jvanverth@google.com /////////////////////////////////////////////////////////////////////////// 1698f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com /// @name Color 1708f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com //// 1718f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com 17289af44a0f1323dc136b238c00ccf143e15abb243egdaniel GrColor getColor() const { return fColor; } 17389af44a0f1323dc136b238c00ccf143e15abb243egdaniel 1748f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com /** 1758f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com * Sets color for next draw to a premultiplied-alpha color. 1768f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com * 1778f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com * @param color the color to set. 1788f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com */ 1799514d24fa512c9cd73548715ac36ad02f34151e8egdaniel void setColor(GrColor color) { 1803658f382cc129e463d7f40a7e68214d04d50fe14egdaniel if (color != fColor) { 1813658f382cc129e463d7f40a7e68214d04d50fe14egdaniel fColor = color; 182b6cbc38702dc4a1540a17181cbdab71060c92ce7egdaniel fColorProcInfoValid = false; 1833658f382cc129e463d7f40a7e68214d04d50fe14egdaniel } 1849514d24fa512c9cd73548715ac36ad02f34151e8egdaniel } 1858f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com 1868f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com /** 1878f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com * Sets the color to be used for the next draw to be 1888f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com * (r,g,b,a) = (alpha, alpha, alpha, alpha). 1898f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com * 1908f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com * @param alpha The alpha value to set as the color. 1918f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com */ 19262c447d3a556e3042cdf5d23b3e2a618eaa3c100bsalomon void setAlpha(uint8_t a) { this->setColor((a << 24) | (a << 16) | (a << 8) | a); } 1938f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com 1948f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com /// @} 1958f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com 1968f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com /////////////////////////////////////////////////////////////////////////// 1972401ae8fd3c1f6282f571b5a7e0a499e9f4c09abbsalomon@google.com /// @name Coverage 1982401ae8fd3c1f6282f571b5a7e0a499e9f4c09abbsalomon@google.com //// 1992401ae8fd3c1f6282f571b5a7e0a499e9f4c09abbsalomon@google.com 20089af44a0f1323dc136b238c00ccf143e15abb243egdaniel uint8_t getCoverage() const { return fCoverage; } 20189af44a0f1323dc136b238c00ccf143e15abb243egdaniel 20289af44a0f1323dc136b238c00ccf143e15abb243egdaniel GrColor getCoverageColor() const { 20389af44a0f1323dc136b238c00ccf143e15abb243egdaniel return GrColorPackRGBA(fCoverage, fCoverage, fCoverage, fCoverage); 20489af44a0f1323dc136b238c00ccf143e15abb243egdaniel } 20589af44a0f1323dc136b238c00ccf143e15abb243egdaniel 2062401ae8fd3c1f6282f571b5a7e0a499e9f4c09abbsalomon@google.com /** 207d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com * Sets a constant fractional coverage to be applied to the draw. The 2082401ae8fd3c1f6282f571b5a7e0a499e9f4c09abbsalomon@google.com * initial value (after construction or reset()) is 0xff. The constant 2092401ae8fd3c1f6282f571b5a7e0a499e9f4c09abbsalomon@google.com * coverage is ignored when per-vertex coverage is provided. 2102401ae8fd3c1f6282f571b5a7e0a499e9f4c09abbsalomon@google.com */ 2112401ae8fd3c1f6282f571b5a7e0a499e9f4c09abbsalomon@google.com void setCoverage(uint8_t coverage) { 2123658f382cc129e463d7f40a7e68214d04d50fe14egdaniel if (coverage != fCoverage) { 2133658f382cc129e463d7f40a7e68214d04d50fe14egdaniel fCoverage = coverage; 214b6cbc38702dc4a1540a17181cbdab71060c92ce7egdaniel fCoverageProcInfoValid = false; 2153658f382cc129e463d7f40a7e68214d04d50fe14egdaniel } 2162401ae8fd3c1f6282f571b5a7e0a499e9f4c09abbsalomon@google.com } 2172401ae8fd3c1f6282f571b5a7e0a499e9f4c09abbsalomon@google.com 2182401ae8fd3c1f6282f571b5a7e0a499e9f4c09abbsalomon@google.com /// @} 2192401ae8fd3c1f6282f571b5a7e0a499e9f4c09abbsalomon@google.com 220bd769d0f1c8cf6ccbb2738dfad1624a4c828e4ebjoshualitt /** 221bd769d0f1c8cf6ccbb2738dfad1624a4c828e4ebjoshualitt * The geometry processor is the sole element of the skia pipeline which can use the vertex, 222bd769d0f1c8cf6ccbb2738dfad1624a4c828e4ebjoshualitt * geometry, and tesselation shaders. The GP may also compute a coverage in its fragment shader 223bd769d0f1c8cf6ccbb2738dfad1624a4c828e4ebjoshualitt * but is never put in the color processing pipeline. 224bd769d0f1c8cf6ccbb2738dfad1624a4c828e4ebjoshualitt */ 225bd769d0f1c8cf6ccbb2738dfad1624a4c828e4ebjoshualitt 226b0a8a377f832c59cee939ad721e1f87d378b7142joshualitt const GrGeometryProcessor* setGeometryProcessor(const GrGeometryProcessor* geometryProcessor) { 227b0a8a377f832c59cee939ad721e1f87d378b7142joshualitt SkASSERT(geometryProcessor); 228bd769d0f1c8cf6ccbb2738dfad1624a4c828e4ebjoshualitt SkASSERT(!this->hasGeometryProcessor()); 229a5305a110ab5201d5dadd40cbe711582d5ac4996joshualitt fGeometryProcessor.reset(SkRef(geometryProcessor)); 230b6cbc38702dc4a1540a17181cbdab71060c92ce7egdaniel fCoverageProcInfoValid = false; 231b0a8a377f832c59cee939ad721e1f87d378b7142joshualitt return geometryProcessor; 232bd769d0f1c8cf6ccbb2738dfad1624a4c828e4ebjoshualitt } 233bd769d0f1c8cf6ccbb2738dfad1624a4c828e4ebjoshualitt 2342401ae8fd3c1f6282f571b5a7e0a499e9f4c09abbsalomon@google.com /////////////////////////////////////////////////////////////////////////// 235adc6536fe5baff2216fb76ecda6cc81c61109d5cbsalomon@google.com /// @name Effect Stages 236b0a8a377f832c59cee939ad721e1f87d378b7142joshualitt /// Each stage hosts a GrProcessor. The effect produces an output color or coverage in the 237b0a8a377f832c59cee939ad721e1f87d378b7142joshualitt /// fragment shader. Its inputs are the output from the previous stage as well as some variables 238eb6879f50a5564eeb981ec5616b55bf685eb76fcbsalomon@google.com /// available to it in the fragment and vertex shader (e.g. the vertex position, the dst color, 239eb6879f50a5564eeb981ec5616b55bf685eb76fcbsalomon@google.com /// the fragment position, local coordinates). 240eb6879f50a5564eeb981ec5616b55bf685eb76fcbsalomon@google.com /// 241eb6879f50a5564eeb981ec5616b55bf685eb76fcbsalomon@google.com /// The stages are divided into two sets, color-computing and coverage-computing. The final 242eb6879f50a5564eeb981ec5616b55bf685eb76fcbsalomon@google.com /// color stage produces the final pixel color. The coverage-computing stages function exactly 243eb6879f50a5564eeb981ec5616b55bf685eb76fcbsalomon@google.com /// as the color-computing but the output of the final coverage stage is treated as a fractional 244eb6879f50a5564eeb981ec5616b55bf685eb76fcbsalomon@google.com /// pixel coverage rather than as input to the src/dst color blend step. 245eb6879f50a5564eeb981ec5616b55bf685eb76fcbsalomon@google.com /// 246eb6879f50a5564eeb981ec5616b55bf685eb76fcbsalomon@google.com /// The input color to the first color-stage is either the constant color or interpolated 247eb6879f50a5564eeb981ec5616b55bf685eb76fcbsalomon@google.com /// per-vertex colors. The input to the first coverage stage is either a constant coverage 248eb6879f50a5564eeb981ec5616b55bf685eb76fcbsalomon@google.com /// (usually full-coverage) or interpolated per-vertex coverage. 249eb6879f50a5564eeb981ec5616b55bf685eb76fcbsalomon@google.com /// 250eb6879f50a5564eeb981ec5616b55bf685eb76fcbsalomon@google.com /// See the documentation of kCoverageDrawing_StateBit for information about disabling the 251eb6879f50a5564eeb981ec5616b55bf685eb76fcbsalomon@google.com /// the color / coverage distinction. 2528f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com //// 2538f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com 25489af44a0f1323dc136b238c00ccf143e15abb243egdaniel int numColorStages() const { return fColorStages.count(); } 25589af44a0f1323dc136b238c00ccf143e15abb243egdaniel int numCoverageStages() const { return fCoverageStages.count(); } 2564dd99886420329fcacd72d87f2c46ff2555d0945joshualitt int numFragmentStages() const { return this->numColorStages() + this->numCoverageStages(); } 25789af44a0f1323dc136b238c00ccf143e15abb243egdaniel int numTotalStages() const { 2584dd99886420329fcacd72d87f2c46ff2555d0945joshualitt return this->numFragmentStages() + (this->hasGeometryProcessor() ? 1 : 0); 25989af44a0f1323dc136b238c00ccf143e15abb243egdaniel } 26089af44a0f1323dc136b238c00ccf143e15abb243egdaniel 26189af44a0f1323dc136b238c00ccf143e15abb243egdaniel bool hasGeometryProcessor() const { return SkToBool(fGeometryProcessor.get()); } 262a5305a110ab5201d5dadd40cbe711582d5ac4996joshualitt const GrGeometryProcessor* getGeometryProcessor() const { return fGeometryProcessor.get(); } 26389af44a0f1323dc136b238c00ccf143e15abb243egdaniel const GrFragmentStage& getColorStage(int idx) const { return fColorStages[idx]; } 26489af44a0f1323dc136b238c00ccf143e15abb243egdaniel const GrFragmentStage& getCoverageStage(int idx) const { return fCoverageStages[idx]; } 26589af44a0f1323dc136b238c00ccf143e15abb243egdaniel 26689af44a0f1323dc136b238c00ccf143e15abb243egdaniel /** 26789af44a0f1323dc136b238c00ccf143e15abb243egdaniel * Checks whether any of the effects will read the dst pixel color. 26889af44a0f1323dc136b238c00ccf143e15abb243egdaniel */ 26989af44a0f1323dc136b238c00ccf143e15abb243egdaniel bool willEffectReadDstColor() const; 27089af44a0f1323dc136b238c00ccf143e15abb243egdaniel 271b0a8a377f832c59cee939ad721e1f87d378b7142joshualitt const GrFragmentProcessor* addColorProcessor(const GrFragmentProcessor* effect) { 27249f085dddff10473b6ebf832a974288300224e60bsalomon SkASSERT(effect); 273b0a8a377f832c59cee939ad721e1f87d378b7142joshualitt SkNEW_APPEND_TO_TARRAY(&fColorStages, GrFragmentStage, (effect)); 274b6cbc38702dc4a1540a17181cbdab71060c92ce7egdaniel fColorProcInfoValid = false; 27565eb4d5a210884cc92c43a8582cbd1ccbddcab57jvanverth@google.com return effect; 27665eb4d5a210884cc92c43a8582cbd1ccbddcab57jvanverth@google.com } 27701c34ee59906f729f6ca7d35f0c0e5e2f5e693feskia.committer@gmail.com 278b0a8a377f832c59cee939ad721e1f87d378b7142joshualitt const GrFragmentProcessor* addCoverageProcessor(const GrFragmentProcessor* effect) { 27949f085dddff10473b6ebf832a974288300224e60bsalomon SkASSERT(effect); 280b0a8a377f832c59cee939ad721e1f87d378b7142joshualitt SkNEW_APPEND_TO_TARRAY(&fCoverageStages, GrFragmentStage, (effect)); 281b6cbc38702dc4a1540a17181cbdab71060c92ce7egdaniel fCoverageProcInfoValid = false; 282adc6536fe5baff2216fb76ecda6cc81c61109d5cbsalomon@google.com return effect; 283adc6536fe5baff2216fb76ecda6cc81c61109d5cbsalomon@google.com } 284adc6536fe5baff2216fb76ecda6cc81c61109d5cbsalomon@google.com 2858f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com /** 286c78188896e28a4ae49e406a7422b345ae177dafebsalomon@google.com * Creates a GrSimpleTextureEffect that uses local coords as texture coordinates. 2871e8f016305805d4d8cad74aba3a21b78486f9d6ftomhudson@google.com */ 288b0a8a377f832c59cee939ad721e1f87d378b7142joshualitt void addColorTextureProcessor(GrTexture* texture, const SkMatrix& matrix) { 289b0a8a377f832c59cee939ad721e1f87d378b7142joshualitt this->addColorProcessor(GrSimpleTextureEffect::Create(texture, matrix))->unref(); 2901ce49fc91714ce8974d11246d29ebe7b97b5fe98bsalomon@google.com } 2911ce49fc91714ce8974d11246d29ebe7b97b5fe98bsalomon@google.com 292b0a8a377f832c59cee939ad721e1f87d378b7142joshualitt void addCoverageTextureProcessor(GrTexture* texture, const SkMatrix& matrix) { 293b0a8a377f832c59cee939ad721e1f87d378b7142joshualitt this->addCoverageProcessor(GrSimpleTextureEffect::Create(texture, matrix))->unref(); 2947d6afdd795eb4c7ce8f5a327117cfdba5f957ddbtomhudson@google.com } 295676e66096c60615bac52f365111596de5c4ca8a6tomhudson@google.com 296b0a8a377f832c59cee939ad721e1f87d378b7142joshualitt void addColorTextureProcessor(GrTexture* texture, 297eb6879f50a5564eeb981ec5616b55bf685eb76fcbsalomon@google.com const SkMatrix& matrix, 298eb6879f50a5564eeb981ec5616b55bf685eb76fcbsalomon@google.com const GrTextureParams& params) { 299b0a8a377f832c59cee939ad721e1f87d378b7142joshualitt this->addColorProcessor(GrSimpleTextureEffect::Create(texture, matrix, params))->unref(); 300b0a8a377f832c59cee939ad721e1f87d378b7142joshualitt } 301b0a8a377f832c59cee939ad721e1f87d378b7142joshualitt 302b0a8a377f832c59cee939ad721e1f87d378b7142joshualitt void addCoverageTextureProcessor(GrTexture* texture, 303b0a8a377f832c59cee939ad721e1f87d378b7142joshualitt const SkMatrix& matrix, 304b0a8a377f832c59cee939ad721e1f87d378b7142joshualitt const GrTextureParams& params) { 305b0a8a377f832c59cee939ad721e1f87d378b7142joshualitt this->addCoverageProcessor(GrSimpleTextureEffect::Create(texture, matrix, params))->unref(); 306ff6ea2663f76aa85ec55ddd0f00ca7906f1bc4e3commit-bot@chromium.org } 307676e66096c60615bac52f365111596de5c4ca8a6tomhudson@google.com 308972265db219ce25b5159879c75e6c62efaf0fa79robertphillips@google.com /** 3099b536523cae9787f6b24ed9234c50cdf2710d67ebsalomon * When this object is destroyed it will remove any color/coverage effects from the draw state 3109b536523cae9787f6b24ed9234c50cdf2710d67ebsalomon * that were added after its constructor. 3119b536523cae9787f6b24ed9234c50cdf2710d67ebsalomon * 3129b536523cae9787f6b24ed9234c50cdf2710d67ebsalomon * This class has strange behavior around geometry processor. If there is a GP on the draw state 3139b536523cae9787f6b24ed9234c50cdf2710d67ebsalomon * it will assert that the GP is not modified until after the destructor of the ARE. If the 3149b536523cae9787f6b24ed9234c50cdf2710d67ebsalomon * draw state has a NULL GP when the ARE is constructed then it will reset it to null in the 3159b536523cae9787f6b24ed9234c50cdf2710d67ebsalomon * destructor. 3169b536523cae9787f6b24ed9234c50cdf2710d67ebsalomon * 3179b536523cae9787f6b24ed9234c50cdf2710d67ebsalomon * TODO: We'd prefer for the ARE to just save and restore the GP. However, this would add 3189b536523cae9787f6b24ed9234c50cdf2710d67ebsalomon * significant complexity to the multi-ref architecture for deferred drawing. Once GrDrawState 3199b536523cae9787f6b24ed9234c50cdf2710d67ebsalomon * and GrOptDrawState are fully separated then GrDrawState will never be in the deferred 3209b536523cae9787f6b24ed9234c50cdf2710d67ebsalomon * execution state and GrOptDrawState always will be (and will be immutable and therefore 3219b536523cae9787f6b24ed9234c50cdf2710d67ebsalomon * unable to have an ARE). At this point we can restore sanity and have the ARE save and restore 3229b536523cae9787f6b24ed9234c50cdf2710d67ebsalomon * the GP. 323972265db219ce25b5159879c75e6c62efaf0fa79robertphillips@google.com */ 324a0b40280a49a8a43af7929ead3b3489951c58501commit-bot@chromium.org class AutoRestoreEffects : public ::SkNoncopyable { 325972265db219ce25b5159879c75e6c62efaf0fa79robertphillips@google.com public: 3269b536523cae9787f6b24ed9234c50cdf2710d67ebsalomon AutoRestoreEffects() 3279b536523cae9787f6b24ed9234c50cdf2710d67ebsalomon : fDrawState(NULL) 32852e9d63f7110ac691609660342cdab32082a4235bsalomon , fOriginalGPID(SK_InvalidUniqueID) 3299b536523cae9787f6b24ed9234c50cdf2710d67ebsalomon , fColorEffectCnt(0) 3309b536523cae9787f6b24ed9234c50cdf2710d67ebsalomon , fCoverageEffectCnt(0) {} 3319b536523cae9787f6b24ed9234c50cdf2710d67ebsalomon 3329b536523cae9787f6b24ed9234c50cdf2710d67ebsalomon AutoRestoreEffects(GrDrawState* ds) 3339b536523cae9787f6b24ed9234c50cdf2710d67ebsalomon : fDrawState(NULL) 33452e9d63f7110ac691609660342cdab32082a4235bsalomon , fOriginalGPID(SK_InvalidUniqueID) 3359b536523cae9787f6b24ed9234c50cdf2710d67ebsalomon , fColorEffectCnt(0) 3369b536523cae9787f6b24ed9234c50cdf2710d67ebsalomon , fCoverageEffectCnt(0) { 3375c493d5b3dc753fccba47c8250fb38713bac3cb8skia.committer@gmail.com this->set(ds); 338f09b87dda39df1315f26afb663aeaf8048330725robertphillips@google.com } 339eb6879f50a5564eeb981ec5616b55bf685eb76fcbsalomon@google.com 340eb6879f50a5564eeb981ec5616b55bf685eb76fcbsalomon@google.com ~AutoRestoreEffects() { this->set(NULL); } 341eb6879f50a5564eeb981ec5616b55bf685eb76fcbsalomon@google.com 3428f7273399466c95c0c86b099de438d6ef1a15c88bsalomon void set(GrDrawState* ds); 343eb6879f50a5564eeb981ec5616b55bf685eb76fcbsalomon@google.com 34449f085dddff10473b6ebf832a974288300224e60bsalomon bool isSet() const { return SkToBool(fDrawState); } 3458af0523b38f25993c8b1ba3a3562b9f9ac87162dbsalomon 346972265db219ce25b5159879c75e6c62efaf0fa79robertphillips@google.com private: 3479b536523cae9787f6b24ed9234c50cdf2710d67ebsalomon GrDrawState* fDrawState; 34852e9d63f7110ac691609660342cdab32082a4235bsalomon uint32_t fOriginalGPID; 3499b536523cae9787f6b24ed9234c50cdf2710d67ebsalomon int fColorEffectCnt; 3509b536523cae9787f6b24ed9234c50cdf2710d67ebsalomon int fCoverageEffectCnt; 351972265db219ce25b5159879c75e6c62efaf0fa79robertphillips@google.com }; 352972265db219ce25b5159879c75e6c62efaf0fa79robertphillips@google.com 353a58fe35fdae3481cf43062f7032820c320c3d163joshualitt /** 354a58fe35fdae3481cf43062f7032820c320c3d163joshualitt * AutoRestoreStencil 355a58fe35fdae3481cf43062f7032820c320c3d163joshualitt * 356a58fe35fdae3481cf43062f7032820c320c3d163joshualitt * This simple struct saves and restores the stencil settings 357a58fe35fdae3481cf43062f7032820c320c3d163joshualitt */ 358a58fe35fdae3481cf43062f7032820c320c3d163joshualitt class AutoRestoreStencil : public ::SkNoncopyable { 359a58fe35fdae3481cf43062f7032820c320c3d163joshualitt public: 360a58fe35fdae3481cf43062f7032820c320c3d163joshualitt AutoRestoreStencil() : fDrawState(NULL) {} 361a58fe35fdae3481cf43062f7032820c320c3d163joshualitt 362a58fe35fdae3481cf43062f7032820c320c3d163joshualitt AutoRestoreStencil(GrDrawState* ds) : fDrawState(NULL) { this->set(ds); } 363a58fe35fdae3481cf43062f7032820c320c3d163joshualitt 364a58fe35fdae3481cf43062f7032820c320c3d163joshualitt ~AutoRestoreStencil() { this->set(NULL); } 365a58fe35fdae3481cf43062f7032820c320c3d163joshualitt 366a58fe35fdae3481cf43062f7032820c320c3d163joshualitt void set(GrDrawState* ds) { 367a58fe35fdae3481cf43062f7032820c320c3d163joshualitt if (fDrawState) { 368a58fe35fdae3481cf43062f7032820c320c3d163joshualitt fDrawState->setStencil(fStencilSettings); 369a58fe35fdae3481cf43062f7032820c320c3d163joshualitt } 370a58fe35fdae3481cf43062f7032820c320c3d163joshualitt fDrawState = ds; 371a58fe35fdae3481cf43062f7032820c320c3d163joshualitt if (ds) { 372a58fe35fdae3481cf43062f7032820c320c3d163joshualitt fStencilSettings = ds->getStencil(); 373a58fe35fdae3481cf43062f7032820c320c3d163joshualitt } 374a58fe35fdae3481cf43062f7032820c320c3d163joshualitt } 375a58fe35fdae3481cf43062f7032820c320c3d163joshualitt 376a58fe35fdae3481cf43062f7032820c320c3d163joshualitt bool isSet() const { return SkToBool(fDrawState); } 377a58fe35fdae3481cf43062f7032820c320c3d163joshualitt 378a58fe35fdae3481cf43062f7032820c320c3d163joshualitt private: 379a58fe35fdae3481cf43062f7032820c320c3d163joshualitt GrDrawState* fDrawState; 380a58fe35fdae3481cf43062f7032820c320c3d163joshualitt GrStencilSettings fStencilSettings; 381a58fe35fdae3481cf43062f7032820c320c3d163joshualitt }; 382a58fe35fdae3481cf43062f7032820c320c3d163joshualitt 3838f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com /// @} 3848f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com 3858f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com /////////////////////////////////////////////////////////////////////////// 3868f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com /// @name Blending 3878f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com //// 3888f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com 38989af44a0f1323dc136b238c00ccf143e15abb243egdaniel GrBlendCoeff getSrcBlendCoeff() const { return fSrcBlend; } 39089af44a0f1323dc136b238c00ccf143e15abb243egdaniel GrBlendCoeff getDstBlendCoeff() const { return fDstBlend; } 39189af44a0f1323dc136b238c00ccf143e15abb243egdaniel 39289af44a0f1323dc136b238c00ccf143e15abb243egdaniel /** 39389af44a0f1323dc136b238c00ccf143e15abb243egdaniel * Retrieves the last value set by setBlendConstant() 39489af44a0f1323dc136b238c00ccf143e15abb243egdaniel * @return the blending constant value 39589af44a0f1323dc136b238c00ccf143e15abb243egdaniel */ 39689af44a0f1323dc136b238c00ccf143e15abb243egdaniel GrColor getBlendConstant() const { return fBlendConstant; } 39789af44a0f1323dc136b238c00ccf143e15abb243egdaniel 39889af44a0f1323dc136b238c00ccf143e15abb243egdaniel /** 39989af44a0f1323dc136b238c00ccf143e15abb243egdaniel * Determines whether multiplying the computed per-pixel color by the pixel's fractional 40089af44a0f1323dc136b238c00ccf143e15abb243egdaniel * coverage before the blend will give the correct final destination color. In general it 40189af44a0f1323dc136b238c00ccf143e15abb243egdaniel * will not as coverage is applied after blending. 40289af44a0f1323dc136b238c00ccf143e15abb243egdaniel */ 40389af44a0f1323dc136b238c00ccf143e15abb243egdaniel bool canTweakAlphaForCoverage() const; 40489af44a0f1323dc136b238c00ccf143e15abb243egdaniel 4058f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com /** 4061e269b5a08610da13c3aee23809bb45b17e7b663bsalomon@google.com * Sets the blending function coefficients. 4078f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com * 4088f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com * The blend function will be: 4098f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com * D' = sat(S*srcCoef + D*dstCoef) 4108f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com * 4118f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com * where D is the existing destination color, S is the incoming source 4128f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com * color, and D' is the new destination color that will be written. sat() 4138f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com * is the saturation function. 4148f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com * 4151e269b5a08610da13c3aee23809bb45b17e7b663bsalomon@google.com * @param srcCoef coefficient applied to the src color. 4161e269b5a08610da13c3aee23809bb45b17e7b663bsalomon@google.com * @param dstCoef coefficient applied to the dst color. 4178f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com */ 4188f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com void setBlendFunc(GrBlendCoeff srcCoeff, GrBlendCoeff dstCoeff) { 41904ddf89627077ea8f2b447e7cd5e902956341a32bsalomon fSrcBlend = srcCoeff; 42004ddf89627077ea8f2b447e7cd5e902956341a32bsalomon fDstBlend = dstCoeff; 421515dcd36032997ce335daa0163c6d67e851bcad1commit-bot@chromium.org #ifdef SK_DEBUG 42224ab3b0ce50b3428f063849b6160e468f047487ccommit-bot@chromium.org if (GrBlendCoeffRefsDst(dstCoeff)) { 42338406c82b913350e55fa04af8c1941cd9b4aff52tfarina SkDebugf("Unexpected dst blend coeff. Won't work correctly with coverage stages.\n"); 4248f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com } 42524ab3b0ce50b3428f063849b6160e468f047487ccommit-bot@chromium.org if (GrBlendCoeffRefsSrc(srcCoeff)) { 42638406c82b913350e55fa04af8c1941cd9b4aff52tfarina SkDebugf("Unexpected src blend coeff. Won't work correctly with coverage stages.\n"); 4278f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com } 4288f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com #endif 4298f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com } 4308f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com 4318f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com /** 4328f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com * Sets the blending function constant referenced by the following blending 4331e269b5a08610da13c3aee23809bb45b17e7b663bsalomon@google.com * coefficients: 43447059542e7aa153926377456a6c611e55c8e428cbsalomon@google.com * kConstC_GrBlendCoeff 43547059542e7aa153926377456a6c611e55c8e428cbsalomon@google.com * kIConstC_GrBlendCoeff 43647059542e7aa153926377456a6c611e55c8e428cbsalomon@google.com * kConstA_GrBlendCoeff 43747059542e7aa153926377456a6c611e55c8e428cbsalomon@google.com * kIConstA_GrBlendCoeff 4388f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com * 4398f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com * @param constant the constant to set 4408f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com */ 44104ddf89627077ea8f2b447e7cd5e902956341a32bsalomon void setBlendConstant(GrColor constant) { fBlendConstant = constant; } 4428f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com 4438f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com /// @} 4448f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com 4458f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com /////////////////////////////////////////////////////////////////////////// 4468f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com /// @name View Matrix 4478f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com //// 4488f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com 4498f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com /** 45089af44a0f1323dc136b238c00ccf143e15abb243egdaniel * Retrieves the current view matrix 45189af44a0f1323dc136b238c00ccf143e15abb243egdaniel * @return the current view matrix. 45289af44a0f1323dc136b238c00ccf143e15abb243egdaniel */ 45389af44a0f1323dc136b238c00ccf143e15abb243egdaniel const SkMatrix& getViewMatrix() const { return fViewMatrix; } 45489af44a0f1323dc136b238c00ccf143e15abb243egdaniel 45589af44a0f1323dc136b238c00ccf143e15abb243egdaniel /** 45689af44a0f1323dc136b238c00ccf143e15abb243egdaniel * Retrieves the inverse of the current view matrix. 45789af44a0f1323dc136b238c00ccf143e15abb243egdaniel * 45889af44a0f1323dc136b238c00ccf143e15abb243egdaniel * If the current view matrix is invertible, return true, and if matrix 45989af44a0f1323dc136b238c00ccf143e15abb243egdaniel * is non-null, copy the inverse into it. If the current view matrix is 46089af44a0f1323dc136b238c00ccf143e15abb243egdaniel * non-invertible, return false and ignore the matrix parameter. 46189af44a0f1323dc136b238c00ccf143e15abb243egdaniel * 46289af44a0f1323dc136b238c00ccf143e15abb243egdaniel * @param matrix if not null, will receive a copy of the current inverse. 46389af44a0f1323dc136b238c00ccf143e15abb243egdaniel */ 46489af44a0f1323dc136b238c00ccf143e15abb243egdaniel bool getViewInverse(SkMatrix* matrix) const { 46589af44a0f1323dc136b238c00ccf143e15abb243egdaniel SkMatrix inverse; 46689af44a0f1323dc136b238c00ccf143e15abb243egdaniel if (fViewMatrix.invert(&inverse)) { 46789af44a0f1323dc136b238c00ccf143e15abb243egdaniel if (matrix) { 46889af44a0f1323dc136b238c00ccf143e15abb243egdaniel *matrix = inverse; 46989af44a0f1323dc136b238c00ccf143e15abb243egdaniel } 47089af44a0f1323dc136b238c00ccf143e15abb243egdaniel return true; 47189af44a0f1323dc136b238c00ccf143e15abb243egdaniel } 47289af44a0f1323dc136b238c00ccf143e15abb243egdaniel return false; 47389af44a0f1323dc136b238c00ccf143e15abb243egdaniel } 47489af44a0f1323dc136b238c00ccf143e15abb243egdaniel 47589af44a0f1323dc136b238c00ccf143e15abb243egdaniel /** 476137f1347abaf0bb6a945e91c2f6cb49f0ee69bc3bsalomon@google.com * Sets the view matrix to identity and updates any installed effects to compensate for the 477137f1347abaf0bb6a945e91c2f6cb49f0ee69bc3bsalomon@google.com * coord system change. 4788f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com */ 479137f1347abaf0bb6a945e91c2f6cb49f0ee69bc3bsalomon@google.com bool setIdentityViewMatrix(); 4808f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com 4815b3e890c376f2211218c43edd11939cfc78fd60absalomon@google.com //////////////////////////////////////////////////////////////////////////// 4825b3e890c376f2211218c43edd11939cfc78fd60absalomon@google.com 4835b3e890c376f2211218c43edd11939cfc78fd60absalomon@google.com /** 4842fdcdeb86788206c23410109b3e2b7976747fd11bsalomon@google.com * Preconcats the current view matrix and restores the previous view matrix in the destructor. 485137f1347abaf0bb6a945e91c2f6cb49f0ee69bc3bsalomon@google.com * Effect matrices are automatically adjusted to compensate and adjusted back in the destructor. 4865b3e890c376f2211218c43edd11939cfc78fd60absalomon@google.com */ 487a0b40280a49a8a43af7929ead3b3489951c58501commit-bot@chromium.org class AutoViewMatrixRestore : public ::SkNoncopyable { 4888f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com public: 4898f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com AutoViewMatrixRestore() : fDrawState(NULL) {} 4902fdcdeb86788206c23410109b3e2b7976747fd11bsalomon@google.com 491c78188896e28a4ae49e406a7422b345ae177dafebsalomon@google.com AutoViewMatrixRestore(GrDrawState* ds, const SkMatrix& preconcatMatrix) { 4928f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com fDrawState = NULL; 493c78188896e28a4ae49e406a7422b345ae177dafebsalomon@google.com this->set(ds, preconcatMatrix); 4948f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com } 4952fdcdeb86788206c23410109b3e2b7976747fd11bsalomon@google.com 4962fdcdeb86788206c23410109b3e2b7976747fd11bsalomon@google.com ~AutoViewMatrixRestore() { this->restore(); } 4972fdcdeb86788206c23410109b3e2b7976747fd11bsalomon@google.com 498a834746cc1bd92301fd0840a221ca1623c0bbb29bsalomon@google.com /** 499a834746cc1bd92301fd0840a221ca1623c0bbb29bsalomon@google.com * Can be called prior to destructor to restore the original matrix. 500a834746cc1bd92301fd0840a221ca1623c0bbb29bsalomon@google.com */ 5012fdcdeb86788206c23410109b3e2b7976747fd11bsalomon@google.com void restore(); 502f467ce7bc33af5f496e0619387551aedec6d2517skia.committer@gmail.com 503c78188896e28a4ae49e406a7422b345ae177dafebsalomon@google.com void set(GrDrawState* drawState, const SkMatrix& preconcatMatrix); 5042fdcdeb86788206c23410109b3e2b7976747fd11bsalomon@google.com 505137f1347abaf0bb6a945e91c2f6cb49f0ee69bc3bsalomon@google.com /** Sets the draw state's matrix to identity. This can fail because the current view matrix 506137f1347abaf0bb6a945e91c2f6cb49f0ee69bc3bsalomon@google.com is not invertible. */ 507137f1347abaf0bb6a945e91c2f6cb49f0ee69bc3bsalomon@google.com bool setIdentity(GrDrawState* drawState); 5082fdcdeb86788206c23410109b3e2b7976747fd11bsalomon@google.com 5095b3e890c376f2211218c43edd11939cfc78fd60absalomon@google.com private: 510eb6879f50a5564eeb981ec5616b55bf685eb76fcbsalomon@google.com void doEffectCoordChanges(const SkMatrix& coordChangeMatrix); 511eb6879f50a5564eeb981ec5616b55bf685eb76fcbsalomon@google.com 512b0a8a377f832c59cee939ad721e1f87d378b7142joshualitt GrDrawState* fDrawState; 513b0a8a377f832c59cee939ad721e1f87d378b7142joshualitt SkMatrix fViewMatrix; 514b0a8a377f832c59cee939ad721e1f87d378b7142joshualitt int fNumColorStages; 515a5305a110ab5201d5dadd40cbe711582d5ac4996joshualitt SkAutoSTArray<8, GrFragmentStage::SavedCoordChange> fSavedCoordChanges; 5165b3e890c376f2211218c43edd11939cfc78fd60absalomon@google.com }; 5175b3e890c376f2211218c43edd11939cfc78fd60absalomon@google.com 5188f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com /// @} 5198f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com 5208f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com /////////////////////////////////////////////////////////////////////////// 5218f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com /// @name Render Target 5228f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com //// 5238f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com 5248f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com /** 52589af44a0f1323dc136b238c00ccf143e15abb243egdaniel * Retrieves the currently set render-target. 52689af44a0f1323dc136b238c00ccf143e15abb243egdaniel * 52789af44a0f1323dc136b238c00ccf143e15abb243egdaniel * @return The currently set render target. 52889af44a0f1323dc136b238c00ccf143e15abb243egdaniel */ 52937dd331b20a92ce79cc26556e065dec98a66cb0bbsalomon GrRenderTarget* getRenderTarget() const { return fRenderTarget.get(); } 53089af44a0f1323dc136b238c00ccf143e15abb243egdaniel 53189af44a0f1323dc136b238c00ccf143e15abb243egdaniel /** 532ca43208e4aaac817fbc8265542f995f24a3fb7bfbsalomon@google.com * Sets the render-target used at the next drawing call 5338f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com * 5348f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com * @param target The render target to set. 5358f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com */ 536ae59b77612c42ff6b793dc33e3d115e6a5db34ccbsalomon void setRenderTarget(GrRenderTarget* target) { fRenderTarget.reset(SkSafeRef(target)); } 5378f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com 5388f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com /// @} 5398f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com 5408f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com /////////////////////////////////////////////////////////////////////////// 5418f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com /// @name Stencil 5428f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com //// 5438f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com 54489af44a0f1323dc136b238c00ccf143e15abb243egdaniel const GrStencilSettings& getStencil() const { return fStencilSettings; } 54589af44a0f1323dc136b238c00ccf143e15abb243egdaniel 5468f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com /** 5478f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com * Sets the stencil settings to use for the next draw. 5488f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com * Changing the clip has the side-effect of possibly zeroing 5498f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com * out the client settable stencil bits. So multipass algorithms 5508f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com * using stencil should not change the clip between passes. 5518f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com * @param settings the stencil settings to use. 5528f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com */ 55304ddf89627077ea8f2b447e7cd5e902956341a32bsalomon void setStencil(const GrStencilSettings& settings) { fStencilSettings = settings; } 5548f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com 5558f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com /** 5568f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com * Shortcut to disable stencil testing and ops. 5578f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com */ 55804ddf89627077ea8f2b447e7cd5e902956341a32bsalomon void disableStencil() { fStencilSettings.setDisabled(); } 5598f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com 5602ed5ef84a5609089ad9d8a8f3a52bf77e76476dbbsalomon GrStencilSettings* stencil() { return &fStencilSettings; } 5618f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com 5628f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com /// @} 5638f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com 5648f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com /////////////////////////////////////////////////////////////////////////// 5658f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com /// @name State Flags 5668f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com //// 5678f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com 56889af44a0f1323dc136b238c00ccf143e15abb243egdaniel /** 56989af44a0f1323dc136b238c00ccf143e15abb243egdaniel * Flags that affect rendering. Controlled using enable/disableState(). All 57089af44a0f1323dc136b238c00ccf143e15abb243egdaniel * default to disabled. 57189af44a0f1323dc136b238c00ccf143e15abb243egdaniel */ 57289af44a0f1323dc136b238c00ccf143e15abb243egdaniel enum StateBits { 57389af44a0f1323dc136b238c00ccf143e15abb243egdaniel /** 57489af44a0f1323dc136b238c00ccf143e15abb243egdaniel * Perform dithering. TODO: Re-evaluate whether we need this bit 57589af44a0f1323dc136b238c00ccf143e15abb243egdaniel */ 57689af44a0f1323dc136b238c00ccf143e15abb243egdaniel kDither_StateBit = 0x01, 57789af44a0f1323dc136b238c00ccf143e15abb243egdaniel /** 57889af44a0f1323dc136b238c00ccf143e15abb243egdaniel * Perform HW anti-aliasing. This means either HW FSAA, if supported by the render target, 57989af44a0f1323dc136b238c00ccf143e15abb243egdaniel * or smooth-line rendering if a line primitive is drawn and line smoothing is supported by 58089af44a0f1323dc136b238c00ccf143e15abb243egdaniel * the 3D API. 58189af44a0f1323dc136b238c00ccf143e15abb243egdaniel */ 58289af44a0f1323dc136b238c00ccf143e15abb243egdaniel kHWAntialias_StateBit = 0x02, 58389af44a0f1323dc136b238c00ccf143e15abb243egdaniel /** 58489af44a0f1323dc136b238c00ccf143e15abb243egdaniel * Draws will respect the clip, otherwise the clip is ignored. 58589af44a0f1323dc136b238c00ccf143e15abb243egdaniel */ 58689af44a0f1323dc136b238c00ccf143e15abb243egdaniel kClip_StateBit = 0x04, 58789af44a0f1323dc136b238c00ccf143e15abb243egdaniel /** 58889af44a0f1323dc136b238c00ccf143e15abb243egdaniel * Disables writing to the color buffer. Useful when performing stencil 58989af44a0f1323dc136b238c00ccf143e15abb243egdaniel * operations. 59089af44a0f1323dc136b238c00ccf143e15abb243egdaniel */ 59189af44a0f1323dc136b238c00ccf143e15abb243egdaniel kNoColorWrites_StateBit = 0x08, 59289af44a0f1323dc136b238c00ccf143e15abb243egdaniel 59389af44a0f1323dc136b238c00ccf143e15abb243egdaniel /** 59489af44a0f1323dc136b238c00ccf143e15abb243egdaniel * Usually coverage is applied after color blending. The color is blended using the coeffs 59589af44a0f1323dc136b238c00ccf143e15abb243egdaniel * specified by setBlendFunc(). The blended color is then combined with dst using coeffs 59689af44a0f1323dc136b238c00ccf143e15abb243egdaniel * of src_coverage, 1-src_coverage. Sometimes we are explicitly drawing a coverage mask. In 59789af44a0f1323dc136b238c00ccf143e15abb243egdaniel * this case there is no distinction between coverage and color and the caller needs direct 59889af44a0f1323dc136b238c00ccf143e15abb243egdaniel * control over the blend coeffs. When set, there will be a single blend step controlled by 59989af44a0f1323dc136b238c00ccf143e15abb243egdaniel * setBlendFunc() which will use coverage*color as the src color. 60089af44a0f1323dc136b238c00ccf143e15abb243egdaniel */ 60189af44a0f1323dc136b238c00ccf143e15abb243egdaniel kCoverageDrawing_StateBit = 0x10, 6027a6184fdf717a1da0c6e1e37b942b17fdaa236d3joshualitt kLast_StateBit = kCoverageDrawing_StateBit, 60389af44a0f1323dc136b238c00ccf143e15abb243egdaniel }; 60489af44a0f1323dc136b238c00ccf143e15abb243egdaniel 60589af44a0f1323dc136b238c00ccf143e15abb243egdaniel bool isClipState() const { return 0 != (fFlagBits & kClip_StateBit); } 60689af44a0f1323dc136b238c00ccf143e15abb243egdaniel bool isColorWriteDisabled() const { return 0 != (fFlagBits & kNoColorWrites_StateBit); } 60789af44a0f1323dc136b238c00ccf143e15abb243egdaniel bool isCoverageDrawing() const { return 0 != (fFlagBits & kCoverageDrawing_StateBit); } 60804ddf89627077ea8f2b447e7cd5e902956341a32bsalomon bool isDither() const { return 0 != (fFlagBits & kDither_StateBit); } 60904ddf89627077ea8f2b447e7cd5e902956341a32bsalomon bool isHWAntialias() const { return 0 != (fFlagBits & kHWAntialias_StateBit); } 6100fec61d19ca9088d54f58bd0a67150171b83d66cbsalomon@google.com 6118f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com /** 6128f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com * Enable render state settings. 6138f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com * 6141e269b5a08610da13c3aee23809bb45b17e7b663bsalomon@google.com * @param stateBits bitfield of StateBits specifying the states to enable 6158f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com */ 61604ddf89627077ea8f2b447e7cd5e902956341a32bsalomon void enableState(uint32_t stateBits) { fFlagBits |= stateBits; } 6170fec61d19ca9088d54f58bd0a67150171b83d66cbsalomon@google.com 6188f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com /** 6198f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com * Disable render state settings. 6208f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com * 6211e269b5a08610da13c3aee23809bb45b17e7b663bsalomon@google.com * @param stateBits bitfield of StateBits specifying the states to disable 6228f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com */ 62304ddf89627077ea8f2b447e7cd5e902956341a32bsalomon void disableState(uint32_t stateBits) { fFlagBits &= ~(stateBits); } 6240fec61d19ca9088d54f58bd0a67150171b83d66cbsalomon@google.com 625d5d69ffaea117428972db48796f7e75f0d1dab34bsalomon@google.com /** 626d5d69ffaea117428972db48796f7e75f0d1dab34bsalomon@google.com * Enable or disable stateBits based on a boolean. 627d5d69ffaea117428972db48796f7e75f0d1dab34bsalomon@google.com * 6281e269b5a08610da13c3aee23809bb45b17e7b663bsalomon@google.com * @param stateBits bitfield of StateBits to enable or disable 629d5d69ffaea117428972db48796f7e75f0d1dab34bsalomon@google.com * @param enable if true enable stateBits, otherwise disable 630d5d69ffaea117428972db48796f7e75f0d1dab34bsalomon@google.com */ 631d5d69ffaea117428972db48796f7e75f0d1dab34bsalomon@google.com void setState(uint32_t stateBits, bool enable) { 632d5d69ffaea117428972db48796f7e75f0d1dab34bsalomon@google.com if (enable) { 633d5d69ffaea117428972db48796f7e75f0d1dab34bsalomon@google.com this->enableState(stateBits); 634d5d69ffaea117428972db48796f7e75f0d1dab34bsalomon@google.com } else { 635d5d69ffaea117428972db48796f7e75f0d1dab34bsalomon@google.com this->disableState(stateBits); 636d5d69ffaea117428972db48796f7e75f0d1dab34bsalomon@google.com } 637d5d69ffaea117428972db48796f7e75f0d1dab34bsalomon@google.com } 638d5d69ffaea117428972db48796f7e75f0d1dab34bsalomon@google.com 6398f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com /// @} 6408f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com 6418f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com /////////////////////////////////////////////////////////////////////////// 6428f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com /// @name Face Culling 6438f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com //// 6448f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com 64589af44a0f1323dc136b238c00ccf143e15abb243egdaniel enum DrawFace { 64689af44a0f1323dc136b238c00ccf143e15abb243egdaniel kInvalid_DrawFace = -1, 64789af44a0f1323dc136b238c00ccf143e15abb243egdaniel 64889af44a0f1323dc136b238c00ccf143e15abb243egdaniel kBoth_DrawFace, 64989af44a0f1323dc136b238c00ccf143e15abb243egdaniel kCCW_DrawFace, 65089af44a0f1323dc136b238c00ccf143e15abb243egdaniel kCW_DrawFace, 65189af44a0f1323dc136b238c00ccf143e15abb243egdaniel }; 65289af44a0f1323dc136b238c00ccf143e15abb243egdaniel 65389af44a0f1323dc136b238c00ccf143e15abb243egdaniel /** 65489af44a0f1323dc136b238c00ccf143e15abb243egdaniel * Gets whether the target is drawing clockwise, counterclockwise, 65589af44a0f1323dc136b238c00ccf143e15abb243egdaniel * or both faces. 65689af44a0f1323dc136b238c00ccf143e15abb243egdaniel * @return the current draw face(s). 65789af44a0f1323dc136b238c00ccf143e15abb243egdaniel */ 65889af44a0f1323dc136b238c00ccf143e15abb243egdaniel DrawFace getDrawFace() const { return fDrawFace; } 65989af44a0f1323dc136b238c00ccf143e15abb243egdaniel 6608f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com /** 6618f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com * Controls whether clockwise, counterclockwise, or both faces are drawn. 6628f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com * @param face the face(s) to draw. 6638f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com */ 6648f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com void setDrawFace(DrawFace face) { 665f6de475e5cbd143f348ff7738919e397b7fe7f57tfarina@chromium.org SkASSERT(kInvalid_DrawFace != face); 6662ed5ef84a5609089ad9d8a8f3a52bf77e76476dbbsalomon fDrawFace = face; 6678f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com } 6688f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com 6698f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com /// @} 6708f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com 6718f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com /////////////////////////////////////////////////////////////////////////// 67262c447d3a556e3042cdf5d23b3e2a618eaa3c100bsalomon /// @name Hints 67362c447d3a556e3042cdf5d23b3e2a618eaa3c100bsalomon /// Hints that when provided can enable optimizations. 67462c447d3a556e3042cdf5d23b3e2a618eaa3c100bsalomon //// 67562c447d3a556e3042cdf5d23b3e2a618eaa3c100bsalomon 676651713408c5a5d9565665967ad09981250c7a8c9joshualitt enum Hints { 677651713408c5a5d9565665967ad09981250c7a8c9joshualitt kVertexColorsAreOpaque_Hint = 0x1, 678651713408c5a5d9565665967ad09981250c7a8c9joshualitt kLast_Hint = kVertexColorsAreOpaque_Hint 679651713408c5a5d9565665967ad09981250c7a8c9joshualitt }; 68089af44a0f1323dc136b238c00ccf143e15abb243egdaniel 68162c447d3a556e3042cdf5d23b3e2a618eaa3c100bsalomon void setHint(Hints hint, bool value) { fHints = value ? (fHints | hint) : (fHints & ~hint); } 68262c447d3a556e3042cdf5d23b3e2a618eaa3c100bsalomon 68389af44a0f1323dc136b238c00ccf143e15abb243egdaniel bool vertexColorsAreOpaque() const { return kVertexColorsAreOpaque_Hint & fHints; } 68489af44a0f1323dc136b238c00ccf143e15abb243egdaniel 68562c447d3a556e3042cdf5d23b3e2a618eaa3c100bsalomon /// @} 68662c447d3a556e3042cdf5d23b3e2a618eaa3c100bsalomon 68762c447d3a556e3042cdf5d23b3e2a618eaa3c100bsalomon /////////////////////////////////////////////////////////////////////////// 68862b09687857c923b1044be0aef4dd900f8379b22tomhudson@google.com 6898f7273399466c95c0c86b099de438d6ef1a15c88bsalomon GrDrawState& operator= (const GrDrawState& that); 69062b09687857c923b1044be0aef4dd900f8379b22tomhudson@google.com 6913658f382cc129e463d7f40a7e68214d04d50fe14egdanielprivate: 69289af44a0f1323dc136b238c00ccf143e15abb243egdaniel bool isEqual(const GrDrawState& that) const; 69389af44a0f1323dc136b238c00ccf143e15abb243egdaniel 69489af44a0f1323dc136b238c00ccf143e15abb243egdaniel /** 69589af44a0f1323dc136b238c00ccf143e15abb243egdaniel * Optimizations for blending / coverage to that can be applied based on the current state. 69689af44a0f1323dc136b238c00ccf143e15abb243egdaniel */ 69704ddf89627077ea8f2b447e7cd5e902956341a32bsalomon enum BlendOpt { 69889af44a0f1323dc136b238c00ccf143e15abb243egdaniel /** 69989af44a0f1323dc136b238c00ccf143e15abb243egdaniel * No optimization 70089af44a0f1323dc136b238c00ccf143e15abb243egdaniel */ 70104ddf89627077ea8f2b447e7cd5e902956341a32bsalomon kNone_BlendOpt, 70289af44a0f1323dc136b238c00ccf143e15abb243egdaniel /** 70389af44a0f1323dc136b238c00ccf143e15abb243egdaniel * Don't draw at all 70489af44a0f1323dc136b238c00ccf143e15abb243egdaniel */ 70504ddf89627077ea8f2b447e7cd5e902956341a32bsalomon kSkipDraw_BlendOpt, 70689af44a0f1323dc136b238c00ccf143e15abb243egdaniel /** 70789af44a0f1323dc136b238c00ccf143e15abb243egdaniel * The coverage value does not have to be computed separately from alpha, the the output 70889af44a0f1323dc136b238c00ccf143e15abb243egdaniel * color can be the modulation of the two. 70989af44a0f1323dc136b238c00ccf143e15abb243egdaniel */ 71004ddf89627077ea8f2b447e7cd5e902956341a32bsalomon kCoverageAsAlpha_BlendOpt, 71189af44a0f1323dc136b238c00ccf143e15abb243egdaniel /** 71289af44a0f1323dc136b238c00ccf143e15abb243egdaniel * Instead of emitting a src color, emit coverage in the alpha channel and r,g,b are 71389af44a0f1323dc136b238c00ccf143e15abb243egdaniel * "don't cares". 71489af44a0f1323dc136b238c00ccf143e15abb243egdaniel */ 71504ddf89627077ea8f2b447e7cd5e902956341a32bsalomon kEmitCoverage_BlendOpt, 71689af44a0f1323dc136b238c00ccf143e15abb243egdaniel /** 71789af44a0f1323dc136b238c00ccf143e15abb243egdaniel * Emit transparent black instead of the src color, no need to compute coverage. 71889af44a0f1323dc136b238c00ccf143e15abb243egdaniel */ 71904ddf89627077ea8f2b447e7cd5e902956341a32bsalomon kEmitTransBlack_BlendOpt 72089af44a0f1323dc136b238c00ccf143e15abb243egdaniel }; 72189af44a0f1323dc136b238c00ccf143e15abb243egdaniel 72289af44a0f1323dc136b238c00ccf143e15abb243egdaniel /** 72389af44a0f1323dc136b238c00ccf143e15abb243egdaniel * Determines what optimizations can be applied based on the blend. The coefficients may have 72489af44a0f1323dc136b238c00ccf143e15abb243egdaniel * to be tweaked in order for the optimization to work. srcCoeff and dstCoeff are optional 72589af44a0f1323dc136b238c00ccf143e15abb243egdaniel * params that receive the tweaked coefficients. Normally the function looks at the current 72689af44a0f1323dc136b238c00ccf143e15abb243egdaniel * state to see if coverage is enabled. By setting forceCoverage the caller can speculatively 72789af44a0f1323dc136b238c00ccf143e15abb243egdaniel * determine the blend optimizations that would be used if there was partial pixel coverage. 72889af44a0f1323dc136b238c00ccf143e15abb243egdaniel * 72904ddf89627077ea8f2b447e7cd5e902956341a32bsalomon * This is used internally and when constructing a GrOptDrawState. 73089af44a0f1323dc136b238c00ccf143e15abb243egdaniel */ 73104ddf89627077ea8f2b447e7cd5e902956341a32bsalomon BlendOpt getBlendOpt(bool forceCoverage = false, 73204ddf89627077ea8f2b447e7cd5e902956341a32bsalomon GrBlendCoeff* srcCoeff = NULL, 73304ddf89627077ea8f2b447e7cd5e902956341a32bsalomon GrBlendCoeff* dstCoeff = NULL) const; 73489af44a0f1323dc136b238c00ccf143e15abb243egdaniel 735912b3d24a0e214e46a211da40cc01fe30238386cegdaniel const GrProcOptInfo& colorProcInfo() const { 736912b3d24a0e214e46a211da40cc01fe30238386cegdaniel this->calcColorInvariantOutput(); 737912b3d24a0e214e46a211da40cc01fe30238386cegdaniel return fColorProcInfo; 738912b3d24a0e214e46a211da40cc01fe30238386cegdaniel } 739912b3d24a0e214e46a211da40cc01fe30238386cegdaniel 740912b3d24a0e214e46a211da40cc01fe30238386cegdaniel const GrProcOptInfo& coverageProcInfo() const { 741912b3d24a0e214e46a211da40cc01fe30238386cegdaniel this->calcCoverageInvariantOutput(); 742912b3d24a0e214e46a211da40cc01fe30238386cegdaniel return fCoverageProcInfo; 743912b3d24a0e214e46a211da40cc01fe30238386cegdaniel } 744912b3d24a0e214e46a211da40cc01fe30238386cegdaniel 74589af44a0f1323dc136b238c00ccf143e15abb243egdaniel /** 74689af44a0f1323dc136b238c00ccf143e15abb243egdaniel * Determines whether src alpha is guaranteed to be one for all src pixels 74789af44a0f1323dc136b238c00ccf143e15abb243egdaniel */ 74889af44a0f1323dc136b238c00ccf143e15abb243egdaniel bool srcAlphaWillBeOne() const; 74989af44a0f1323dc136b238c00ccf143e15abb243egdaniel 750b6cbc38702dc4a1540a17181cbdab71060c92ce7egdaniel /** 751b6cbc38702dc4a1540a17181cbdab71060c92ce7egdaniel * If fColorProcInfoValid is false, function calculates the invariant output for the color 752b6cbc38702dc4a1540a17181cbdab71060c92ce7egdaniel * stages and results are stored in fColorProcInfo. 753b6cbc38702dc4a1540a17181cbdab71060c92ce7egdaniel */ 754b6cbc38702dc4a1540a17181cbdab71060c92ce7egdaniel void calcColorInvariantOutput() const; 755b6cbc38702dc4a1540a17181cbdab71060c92ce7egdaniel 756b6cbc38702dc4a1540a17181cbdab71060c92ce7egdaniel /** 757b6cbc38702dc4a1540a17181cbdab71060c92ce7egdaniel * If fCoverageProcInfoValid is false, function calculates the invariant output for the coverage 758b6cbc38702dc4a1540a17181cbdab71060c92ce7egdaniel * stages and results are stored in fCoverageProcInfo. 759b6cbc38702dc4a1540a17181cbdab71060c92ce7egdaniel */ 760b6cbc38702dc4a1540a17181cbdab71060c92ce7egdaniel void calcCoverageInvariantOutput() const; 761b6cbc38702dc4a1540a17181cbdab71060c92ce7egdaniel 7623658f382cc129e463d7f40a7e68214d04d50fe14egdaniel void onReset(const SkMatrix* initialViewMatrix); 7632ed5ef84a5609089ad9d8a8f3a52bf77e76476dbbsalomon 764eb6879f50a5564eeb981ec5616b55bf685eb76fcbsalomon@google.com // Some of the auto restore objects assume that no effects are removed during their lifetime. 765eb6879f50a5564eeb981ec5616b55bf685eb76fcbsalomon@google.com // This is used to assert that this condition holds. 7661acc3d7cc28c5631b5300578ab13439bdefd4e33commit-bot@chromium.org SkDEBUGCODE(int fBlockEffectRemovalCnt;) 7678f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com 7687b3d5ee72c2238aa239bce4d5b3aea98a437ca7aegdaniel void internalSetVertexAttribs(const GrVertexAttrib attribs[], int count, size_t stride); 769429033038271147ed66b4bc2675ac98a5ccfa75crobertphillips@google.com 770a5305a110ab5201d5dadd40cbe711582d5ac4996joshualitt typedef SkSTArray<4, GrFragmentStage> FragmentStageArray; 77189af44a0f1323dc136b238c00ccf143e15abb243egdaniel 772ae59b77612c42ff6b793dc33e3d115e6a5db34ccbsalomon SkAutoTUnref<GrRenderTarget> fRenderTarget; 773ae59b77612c42ff6b793dc33e3d115e6a5db34ccbsalomon GrColor fColor; 774ae59b77612c42ff6b793dc33e3d115e6a5db34ccbsalomon SkMatrix fViewMatrix; 775ae59b77612c42ff6b793dc33e3d115e6a5db34ccbsalomon GrColor fBlendConstant; 776ae59b77612c42ff6b793dc33e3d115e6a5db34ccbsalomon uint32_t fFlagBits; 777ae59b77612c42ff6b793dc33e3d115e6a5db34ccbsalomon const GrVertexAttrib* fVAPtr; 778ae59b77612c42ff6b793dc33e3d115e6a5db34ccbsalomon int fVACount; 779ae59b77612c42ff6b793dc33e3d115e6a5db34ccbsalomon size_t fVAStride; 780ae59b77612c42ff6b793dc33e3d115e6a5db34ccbsalomon GrStencilSettings fStencilSettings; 781ae59b77612c42ff6b793dc33e3d115e6a5db34ccbsalomon uint8_t fCoverage; 782ae59b77612c42ff6b793dc33e3d115e6a5db34ccbsalomon DrawFace fDrawFace; 783ae59b77612c42ff6b793dc33e3d115e6a5db34ccbsalomon GrBlendCoeff fSrcBlend; 784ae59b77612c42ff6b793dc33e3d115e6a5db34ccbsalomon GrBlendCoeff fDstBlend; 785ae59b77612c42ff6b793dc33e3d115e6a5db34ccbsalomon SkAutoTUnref<const GrGeometryProcessor> fGeometryProcessor; 786ae59b77612c42ff6b793dc33e3d115e6a5db34ccbsalomon FragmentStageArray fColorStages; 787ae59b77612c42ff6b793dc33e3d115e6a5db34ccbsalomon FragmentStageArray fCoverageStages; 788ae59b77612c42ff6b793dc33e3d115e6a5db34ccbsalomon uint32_t fHints; 78989af44a0f1323dc136b238c00ccf143e15abb243egdaniel 79089af44a0f1323dc136b238c00ccf143e15abb243egdaniel // This is simply a different representation of info in fVertexAttribs and thus does 79189af44a0f1323dc136b238c00ccf143e15abb243egdaniel // not need to be compared in op==. 79289af44a0f1323dc136b238c00ccf143e15abb243egdaniel int fFixedFunctionVertexAttribIndices[kGrFixedFunctionVertexAttribBindingCnt]; 79389af44a0f1323dc136b238c00ccf143e15abb243egdaniel 794b6cbc38702dc4a1540a17181cbdab71060c92ce7egdaniel mutable GrProcOptInfo fColorProcInfo; 795b6cbc38702dc4a1540a17181cbdab71060c92ce7egdaniel mutable GrProcOptInfo fCoverageProcInfo; 796b6cbc38702dc4a1540a17181cbdab71060c92ce7egdaniel mutable bool fColorProcInfoValid; 797b6cbc38702dc4a1540a17181cbdab71060c92ce7egdaniel mutable bool fCoverageProcInfoValid; 798b6cbc38702dc4a1540a17181cbdab71060c92ce7egdaniel 799b109ac22b4ec3ab3478f5304c96564a0e9df6170egdaniel friend class GrOptDrawState; 8009381363050ec9d3e724076a8e9152bfa9a8de1d1tomhudson@google.com}; 8019381363050ec9d3e724076a8e9152bfa9a8de1d1tomhudson@google.com 8029381363050ec9d3e724076a8e9152bfa9a8de1d1tomhudson@google.com#endif 803