blob: 974aff4c2f3fcd083a2953ca90f5ef9c787456bb [file] [log] [blame]
tomhudson@google.com93813632011-10-27 20:21:16 +00001/*
2 * Copyright 2011 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#ifndef GrDrawState_DEFINED
9#define GrDrawState_DEFINED
10
egdaniel89af44a2014-09-26 06:15:04 -070011
commit-bot@chromium.org24ab3b02013-08-14 21:56:37 +000012#include "GrBlend.h"
egdanielc0648242014-09-22 13:17:02 -070013#include "GrDrawTargetCaps.h"
bsalomon6251d172014-10-15 10:50:36 -070014#include "GrGeometryProcessor.h"
bsalomonf96ba022014-09-17 08:05:40 -070015#include "GrGpuResourceRef.h"
egdaniel89af44a2014-09-26 06:15:04 -070016#include "GrProcessorStage.h"
egdanielb6cbc382014-11-13 11:00:34 -080017#include "GrProcOptInfo.h"
egdaniel89af44a2014-09-26 06:15:04 -070018#include "GrRenderTarget.h"
19#include "GrStencil.h"
20#include "SkMatrix.h"
bsalomon@google.com68b58c92013-01-17 16:50:08 +000021#include "effects/GrSimpleTextureEffect.h"
tomhudson@google.com93813632011-10-27 20:21:16 +000022
egdaniel89af44a2014-09-26 06:15:04 -070023class GrDrawTargetCaps;
egdaniel170f90b2014-09-16 12:54:40 -070024class GrOptDrawState;
egdaniel89af44a2014-09-26 06:15:04 -070025class GrPaint;
26class GrTexture;
egdaniel170f90b2014-09-16 12:54:40 -070027
egdaniel89af44a2014-09-26 06:15:04 -070028class GrDrawState : public SkRefCnt {
bsalomon@google.com2e3d1442012-03-26 20:33:54 +000029public:
reed@google.comfa35e3d2012-06-26 20:16:17 +000030 SK_DECLARE_INST_COUNT(GrDrawState)
rmistry@google.comd6176b02012-08-23 18:14:13 +000031
egdaniel69bb90c2014-11-11 07:32:45 -080032 GrDrawState() {
commit-bot@chromium.org1acc3d72013-09-06 23:13:05 +000033 SkDEBUGCODE(fBlockEffectRemovalCnt = 0;)
bsalomon@google.comeb6879f2013-06-13 19:34:18 +000034 this->reset();
35 }
tomhudson@google.com93813632011-10-27 20:21:16 +000036
egdaniel69bb90c2014-11-11 07:32:45 -080037 GrDrawState(const SkMatrix& initialViewMatrix) {
commit-bot@chromium.org1acc3d72013-09-06 23:13:05 +000038 SkDEBUGCODE(fBlockEffectRemovalCnt = 0;)
bsalomon@google.comeb6879f2013-06-13 19:34:18 +000039 this->reset(initialViewMatrix);
40 }
bsalomon@google.com137f1342013-05-29 21:27:53 +000041
42 /**
43 * Copies another draw state.
44 **/
egdaniel69bb90c2014-11-11 07:32:45 -080045 GrDrawState(const GrDrawState& state) : INHERITED() {
commit-bot@chromium.org1acc3d72013-09-06 23:13:05 +000046 SkDEBUGCODE(fBlockEffectRemovalCnt = 0;)
bsalomon@google.com46f7afb2012-01-18 19:51:55 +000047 *this = state;
48 }
49
bsalomon@google.com137f1342013-05-29 21:27:53 +000050 /**
51 * Copies another draw state with a preconcat to the view matrix.
52 **/
bsalomon8f727332014-08-05 07:50:06 -070053 GrDrawState(const GrDrawState& state, const SkMatrix& preConcatMatrix);
robertphillips@google.com9ec07532012-06-22 12:01:30 +000054
egdaniel170f90b2014-09-16 12:54:40 -070055 virtual ~GrDrawState();
bsalomon@google.com137f1342013-05-29 21:27:53 +000056
bsalomon@google.com52a5dcb2012-01-17 16:01:37 +000057 /**
joshualittb0a8a372014-09-23 09:50:21 -070058 * Resets to the default state. GrProcessors will be removed from all stages.
rmistry@google.comd6176b02012-08-23 18:14:13 +000059 */
bsalomon@google.com137f1342013-05-29 21:27:53 +000060 void reset() { this->onReset(NULL); }
robertphillips@google.com9ec07532012-06-22 12:01:30 +000061
bsalomon@google.com137f1342013-05-29 21:27:53 +000062 void reset(const SkMatrix& initialViewMatrix) { this->onReset(&initialViewMatrix); }
bsalomon@google.comaf84e742012-10-05 13:23:24 +000063
64 /**
commit-bot@chromium.orgbb6a3172013-05-28 17:25:49 +000065 * Initializes the GrDrawState based on a GrPaint, view matrix and render target. Note that
66 * GrDrawState encompasses more than GrPaint. Aspects of GrDrawState that have no GrPaint
bsalomon9c0822a2014-08-11 11:07:48 -070067 * equivalents are set to default values with the exception of vertex attribute state which
68 * is unmodified by this function and clipping which will be enabled.
bsalomon@google.comaf84e742012-10-05 13:23:24 +000069 */
commit-bot@chromium.orgbb6a3172013-05-28 17:25:49 +000070 void setFromPaint(const GrPaint& , const SkMatrix& viewMatrix, GrRenderTarget*);
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +000071
72 ///////////////////////////////////////////////////////////////////////////
jvanverth@google.com9b855c72013-03-01 18:21:22 +000073 /// @name Vertex Attributes
jvanverth@google.comcc782382013-01-28 20:39:48 +000074 ////
75
egdaniel89af44a2014-09-26 06:15:04 -070076 enum {
77 kMaxVertexAttribCnt = kLast_GrVertexAttribBinding + 4,
78 };
79
80 const GrVertexAttrib* getVertexAttribs() const { return fVAPtr; }
81 int getVertexAttribCount() const { return fVACount; }
82
83 size_t getVertexStride() const { return fVAStride; }
84
85 bool hasLocalCoordAttribute() const {
86 return -1 != fFixedFunctionVertexAttribIndices[kLocalCoord_GrVertexAttribBinding];
87 }
88 bool hasColorVertexAttribute() const {
89 return -1 != fFixedFunctionVertexAttribIndices[kColor_GrVertexAttribBinding];
90 }
91 bool hasCoverageVertexAttribute() const {
92 return -1 != fFixedFunctionVertexAttribIndices[kCoverage_GrVertexAttribBinding];
93 }
94
95 const int* getFixedFunctionVertexAttribIndices() const {
96 return fFixedFunctionVertexAttribIndices;
97 }
98
99 bool validateVertexAttribs() const;
100
jvanverth@google.com9b855c72013-03-01 18:21:22 +0000101 /**
jvanverth@google.com054ae992013-04-01 20:06:51 +0000102 * The format of vertices is represented as an array of GrVertexAttribs, with each representing
103 * the type of the attribute, its offset, and semantic binding (see GrVertexAttrib in
104 * GrTypesPriv.h).
jvanverth@google.comb8b705b2013-02-28 16:28:34 +0000105 *
joshualittb0a8a372014-09-23 09:50:21 -0700106 * The mapping of attributes with kEffect bindings to GrProcessor inputs is specified when
jvanverth@google.com054ae992013-04-01 20:06:51 +0000107 * setEffect is called.
jvanverth@google.comb8b705b2013-02-28 16:28:34 +0000108 */
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000109
jvanverth@google.com9b855c72013-03-01 18:21:22 +0000110 /**
robertphillips@google.com42903302013-04-20 12:26:07 +0000111 * Sets vertex attributes for next draw. The object driving the templatization
112 * should be a global GrVertexAttrib array that is never changed.
egdaniel7b3d5ee2014-08-28 05:41:14 -0700113 *
114 * @param count the number of attributes being set, limited to kMaxVertexAttribCnt.
115 * @param stride the number of bytes between successive vertex data.
jvanverth@google.com9b855c72013-03-01 18:21:22 +0000116 */
egdaniel7b3d5ee2014-08-28 05:41:14 -0700117 template <const GrVertexAttrib A[]> void setVertexAttribs(int count, size_t stride) {
118 this->internalSetVertexAttribs(A, count, stride);
robertphillips@google.com42903302013-04-20 12:26:07 +0000119 }
jvanverth@google.comb8b705b2013-02-28 16:28:34 +0000120
jvanverth@google.com9b855c72013-03-01 18:21:22 +0000121 /**
jvanverth@google.com054ae992013-04-01 20:06:51 +0000122 * Sets default vertex attributes for next draw. The default is a single attribute:
123 * {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribType}
jvanverth@google.com9b855c72013-03-01 18:21:22 +0000124 */
125 void setDefaultVertexAttribs();
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000126
jvanverth@google.com054ae992013-04-01 20:06:51 +0000127 /**
bsalomon@google.com0406b9e2013-04-02 21:00:15 +0000128 * Helper to save/restore vertex attribs
129 */
130 class AutoVertexAttribRestore {
131 public:
bsalomon8f727332014-08-05 07:50:06 -0700132 AutoVertexAttribRestore(GrDrawState* drawState);
bsalomon@google.com0406b9e2013-04-02 21:00:15 +0000133
egdaniel3658f382014-09-15 07:01:59 -0700134 ~AutoVertexAttribRestore() { fDrawState->internalSetVertexAttribs(fVAPtr, fVACount,
135 fVAStride); }
bsalomon@google.com0406b9e2013-04-02 21:00:15 +0000136
137 private:
robertphillips@google.com42903302013-04-20 12:26:07 +0000138 GrDrawState* fDrawState;
139 const GrVertexAttrib* fVAPtr;
140 int fVACount;
egdaniel7b3d5ee2014-08-28 05:41:14 -0700141 size_t fVAStride;
bsalomon@google.com0406b9e2013-04-02 21:00:15 +0000142 };
143
jvanverth@google.com9b855c72013-03-01 18:21:22 +0000144 /// @}
145
jvanverth@google.com9b855c72013-03-01 18:21:22 +0000146 /**
bsalomon62c447d2014-08-08 08:08:50 -0700147 * Depending on features available in the underlying 3D API and the color blend mode requested
148 * it may or may not be possible to correctly blend with fractional pixel coverage generated by
149 * the fragment shader.
150 *
151 * This function considers the current draw state and the draw target's capabilities to
152 * determine whether coverage can be handled correctly. This function assumes that the caller
153 * intends to specify fractional pixel coverage (via setCoverage(), through a coverage vertex
154 * attribute, or a coverage effect) but may not have specified it yet.
155 */
156 bool couldApplyCoverage(const GrDrawTargetCaps& caps) const;
157
egdaniel89af44a2014-09-26 06:15:04 -0700158 /**
159 * Determines whether the output coverage is guaranteed to be one for all pixels hit by a draw.
160 */
161 bool hasSolidCoverage() const;
162
egdanielcd8b6302014-11-11 14:46:05 -0800163 /**
164 * This function returns true if the render target destination pixel values will be read for
165 * blending during draw.
166 */
167 bool willBlendWithDst() const;
168
jvanverth@google.comcc782382013-01-28 20:39:48 +0000169 /// @}
170
171 ///////////////////////////////////////////////////////////////////////////
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000172 /// @name Color
173 ////
174
egdaniel89af44a2014-09-26 06:15:04 -0700175 GrColor getColor() const { return fColor; }
176
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000177 /**
178 * Sets color for next draw to a premultiplied-alpha color.
179 *
180 * @param color the color to set.
181 */
egdaniel9514d242014-07-18 06:15:43 -0700182 void setColor(GrColor color) {
egdaniel3658f382014-09-15 07:01:59 -0700183 if (color != fColor) {
184 fColor = color;
egdanielb6cbc382014-11-13 11:00:34 -0800185 fColorProcInfoValid = false;
egdaniel3658f382014-09-15 07:01:59 -0700186 }
egdaniel9514d242014-07-18 06:15:43 -0700187 }
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000188
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000189 /**
190 * Sets the color to be used for the next draw to be
191 * (r,g,b,a) = (alpha, alpha, alpha, alpha).
192 *
193 * @param alpha The alpha value to set as the color.
194 */
bsalomon62c447d2014-08-08 08:08:50 -0700195 void setAlpha(uint8_t a) { this->setColor((a << 24) | (a << 16) | (a << 8) | a); }
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000196
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000197 /// @}
198
199 ///////////////////////////////////////////////////////////////////////////
bsalomon@google.com2401ae82012-01-17 21:03:05 +0000200 /// @name Coverage
201 ////
202
egdaniel89af44a2014-09-26 06:15:04 -0700203 uint8_t getCoverage() const { return fCoverage; }
204
205 GrColor getCoverageColor() const {
206 return GrColorPackRGBA(fCoverage, fCoverage, fCoverage, fCoverage);
207 }
208
bsalomon@google.com2401ae82012-01-17 21:03:05 +0000209 /**
rmistry@google.comd6176b02012-08-23 18:14:13 +0000210 * Sets a constant fractional coverage to be applied to the draw. The
bsalomon@google.com2401ae82012-01-17 21:03:05 +0000211 * initial value (after construction or reset()) is 0xff. The constant
212 * coverage is ignored when per-vertex coverage is provided.
213 */
214 void setCoverage(uint8_t coverage) {
egdaniel3658f382014-09-15 07:01:59 -0700215 if (coverage != fCoverage) {
216 fCoverage = coverage;
egdanielb6cbc382014-11-13 11:00:34 -0800217 fCoverageProcInfoValid = false;
egdaniel3658f382014-09-15 07:01:59 -0700218 }
bsalomon@google.com2401ae82012-01-17 21:03:05 +0000219 }
220
bsalomon@google.com2401ae82012-01-17 21:03:05 +0000221 /// @}
222
joshualittbd769d02014-09-04 08:56:46 -0700223 /**
224 * The geometry processor is the sole element of the skia pipeline which can use the vertex,
225 * geometry, and tesselation shaders. The GP may also compute a coverage in its fragment shader
226 * but is never put in the color processing pipeline.
227 */
228
joshualittb0a8a372014-09-23 09:50:21 -0700229 const GrGeometryProcessor* setGeometryProcessor(const GrGeometryProcessor* geometryProcessor) {
230 SkASSERT(geometryProcessor);
joshualittbd769d02014-09-04 08:56:46 -0700231 SkASSERT(!this->hasGeometryProcessor());
joshualitta5305a12014-10-10 17:47:00 -0700232 fGeometryProcessor.reset(SkRef(geometryProcessor));
egdanielb6cbc382014-11-13 11:00:34 -0800233 fCoverageProcInfoValid = false;
joshualittb0a8a372014-09-23 09:50:21 -0700234 return geometryProcessor;
joshualittbd769d02014-09-04 08:56:46 -0700235 }
236
bsalomon@google.com2401ae82012-01-17 21:03:05 +0000237 ///////////////////////////////////////////////////////////////////////////
bsalomon@google.comadc65362013-01-28 14:26:09 +0000238 /// @name Effect Stages
joshualittb0a8a372014-09-23 09:50:21 -0700239 /// Each stage hosts a GrProcessor. The effect produces an output color or coverage in the
240 /// fragment shader. Its inputs are the output from the previous stage as well as some variables
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000241 /// available to it in the fragment and vertex shader (e.g. the vertex position, the dst color,
242 /// the fragment position, local coordinates).
243 ///
244 /// The stages are divided into two sets, color-computing and coverage-computing. The final
245 /// color stage produces the final pixel color. The coverage-computing stages function exactly
246 /// as the color-computing but the output of the final coverage stage is treated as a fractional
247 /// pixel coverage rather than as input to the src/dst color blend step.
248 ///
249 /// The input color to the first color-stage is either the constant color or interpolated
250 /// per-vertex colors. The input to the first coverage stage is either a constant coverage
251 /// (usually full-coverage) or interpolated per-vertex coverage.
252 ///
253 /// See the documentation of kCoverageDrawing_StateBit for information about disabling the
254 /// the color / coverage distinction.
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000255 ////
256
egdaniel89af44a2014-09-26 06:15:04 -0700257 int numColorStages() const { return fColorStages.count(); }
258 int numCoverageStages() const { return fCoverageStages.count(); }
joshualitt4dd99882014-11-11 08:51:30 -0800259 int numFragmentStages() const { return this->numColorStages() + this->numCoverageStages(); }
egdaniel89af44a2014-09-26 06:15:04 -0700260 int numTotalStages() const {
joshualitt4dd99882014-11-11 08:51:30 -0800261 return this->numFragmentStages() + (this->hasGeometryProcessor() ? 1 : 0);
egdaniel89af44a2014-09-26 06:15:04 -0700262 }
263
264 bool hasGeometryProcessor() const { return SkToBool(fGeometryProcessor.get()); }
joshualitta5305a12014-10-10 17:47:00 -0700265 const GrGeometryProcessor* getGeometryProcessor() const { return fGeometryProcessor.get(); }
egdaniel89af44a2014-09-26 06:15:04 -0700266 const GrFragmentStage& getColorStage(int idx) const { return fColorStages[idx]; }
267 const GrFragmentStage& getCoverageStage(int idx) const { return fCoverageStages[idx]; }
268
269 /**
270 * Checks whether any of the effects will read the dst pixel color.
271 */
272 bool willEffectReadDstColor() const;
273
joshualittb0a8a372014-09-23 09:50:21 -0700274 const GrFragmentProcessor* addColorProcessor(const GrFragmentProcessor* effect) {
bsalomon49f085d2014-09-05 13:34:00 -0700275 SkASSERT(effect);
joshualittb0a8a372014-09-23 09:50:21 -0700276 SkNEW_APPEND_TO_TARRAY(&fColorStages, GrFragmentStage, (effect));
egdanielb6cbc382014-11-13 11:00:34 -0800277 fColorProcInfoValid = false;
jvanverth@google.com65eb4d52013-03-19 18:51:02 +0000278 return effect;
279 }
skia.committer@gmail.com01c34ee2013-03-20 07:01:02 +0000280
joshualittb0a8a372014-09-23 09:50:21 -0700281 const GrFragmentProcessor* addCoverageProcessor(const GrFragmentProcessor* effect) {
bsalomon49f085d2014-09-05 13:34:00 -0700282 SkASSERT(effect);
joshualittb0a8a372014-09-23 09:50:21 -0700283 SkNEW_APPEND_TO_TARRAY(&fCoverageStages, GrFragmentStage, (effect));
egdanielb6cbc382014-11-13 11:00:34 -0800284 fCoverageProcInfoValid = false;
bsalomon@google.comadc65362013-01-28 14:26:09 +0000285 return effect;
286 }
287
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000288 /**
bsalomon@google.comc7818882013-03-20 19:19:53 +0000289 * Creates a GrSimpleTextureEffect that uses local coords as texture coordinates.
tomhudson@google.com1e8f0162012-07-20 16:25:18 +0000290 */
joshualittb0a8a372014-09-23 09:50:21 -0700291 void addColorTextureProcessor(GrTexture* texture, const SkMatrix& matrix) {
292 this->addColorProcessor(GrSimpleTextureEffect::Create(texture, matrix))->unref();
bsalomon@google.comdfdb7e52012-10-16 15:19:45 +0000293 }
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000294
joshualittb0a8a372014-09-23 09:50:21 -0700295 void addCoverageTextureProcessor(GrTexture* texture, const SkMatrix& matrix) {
296 this->addCoverageProcessor(GrSimpleTextureEffect::Create(texture, matrix))->unref();
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000297 }
298
joshualittb0a8a372014-09-23 09:50:21 -0700299 void addColorTextureProcessor(GrTexture* texture,
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000300 const SkMatrix& matrix,
301 const GrTextureParams& params) {
joshualittb0a8a372014-09-23 09:50:21 -0700302 this->addColorProcessor(GrSimpleTextureEffect::Create(texture, matrix, params))->unref();
303 }
304
305 void addCoverageTextureProcessor(GrTexture* texture,
306 const SkMatrix& matrix,
307 const GrTextureParams& params) {
308 this->addCoverageProcessor(GrSimpleTextureEffect::Create(texture, matrix, params))->unref();
commit-bot@chromium.orgff6ea262013-03-12 12:26:08 +0000309 }
tomhudson@google.com676e6602012-07-10 17:21:48 +0000310
robertphillips@google.com972265d2012-06-13 18:49:30 +0000311 /**
bsalomon9b536522014-09-05 09:18:51 -0700312 * When this object is destroyed it will remove any color/coverage effects from the draw state
313 * that were added after its constructor.
314 *
315 * This class has strange behavior around geometry processor. If there is a GP on the draw state
316 * it will assert that the GP is not modified until after the destructor of the ARE. If the
317 * draw state has a NULL GP when the ARE is constructed then it will reset it to null in the
318 * destructor.
319 *
320 * TODO: We'd prefer for the ARE to just save and restore the GP. However, this would add
321 * significant complexity to the multi-ref architecture for deferred drawing. Once GrDrawState
322 * and GrOptDrawState are fully separated then GrDrawState will never be in the deferred
323 * execution state and GrOptDrawState always will be (and will be immutable and therefore
324 * unable to have an ARE). At this point we can restore sanity and have the ARE save and restore
325 * the GP.
robertphillips@google.com972265d2012-06-13 18:49:30 +0000326 */
commit-bot@chromium.orga0b40282013-09-18 13:00:55 +0000327 class AutoRestoreEffects : public ::SkNoncopyable {
robertphillips@google.com972265d2012-06-13 18:49:30 +0000328 public:
bsalomon9b536522014-09-05 09:18:51 -0700329 AutoRestoreEffects()
330 : fDrawState(NULL)
bsalomon52e9d632014-09-05 12:23:12 -0700331 , fOriginalGPID(SK_InvalidUniqueID)
bsalomon9b536522014-09-05 09:18:51 -0700332 , fColorEffectCnt(0)
333 , fCoverageEffectCnt(0) {}
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000334
bsalomon9b536522014-09-05 09:18:51 -0700335 AutoRestoreEffects(GrDrawState* ds)
336 : fDrawState(NULL)
bsalomon52e9d632014-09-05 12:23:12 -0700337 , fOriginalGPID(SK_InvalidUniqueID)
bsalomon9b536522014-09-05 09:18:51 -0700338 , fColorEffectCnt(0)
339 , fCoverageEffectCnt(0) {
skia.committer@gmail.com5c493d52013-06-14 07:00:49 +0000340 this->set(ds);
robertphillips@google.comf09b87d2013-06-13 20:06:44 +0000341 }
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000342
343 ~AutoRestoreEffects() { this->set(NULL); }
344
bsalomon8f727332014-08-05 07:50:06 -0700345 void set(GrDrawState* ds);
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000346
bsalomon49f085d2014-09-05 13:34:00 -0700347 bool isSet() const { return SkToBool(fDrawState); }
bsalomon8af05232014-06-03 06:34:58 -0700348
robertphillips@google.com972265d2012-06-13 18:49:30 +0000349 private:
bsalomon9b536522014-09-05 09:18:51 -0700350 GrDrawState* fDrawState;
bsalomon52e9d632014-09-05 12:23:12 -0700351 uint32_t fOriginalGPID;
bsalomon9b536522014-09-05 09:18:51 -0700352 int fColorEffectCnt;
353 int fCoverageEffectCnt;
robertphillips@google.com972265d2012-06-13 18:49:30 +0000354 };
355
joshualitta58fe352014-10-27 08:39:00 -0700356 /**
357 * AutoRestoreStencil
358 *
359 * This simple struct saves and restores the stencil settings
360 */
361 class AutoRestoreStencil : public ::SkNoncopyable {
362 public:
363 AutoRestoreStencil() : fDrawState(NULL) {}
364
365 AutoRestoreStencil(GrDrawState* ds) : fDrawState(NULL) { this->set(ds); }
366
367 ~AutoRestoreStencil() { this->set(NULL); }
368
369 void set(GrDrawState* ds) {
370 if (fDrawState) {
371 fDrawState->setStencil(fStencilSettings);
372 }
373 fDrawState = ds;
374 if (ds) {
375 fStencilSettings = ds->getStencil();
376 }
377 }
378
379 bool isSet() const { return SkToBool(fDrawState); }
380
381 private:
382 GrDrawState* fDrawState;
383 GrStencilSettings fStencilSettings;
384 };
385
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000386 /// @}
387
388 ///////////////////////////////////////////////////////////////////////////
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000389 /// @name Blending
390 ////
391
egdaniel89af44a2014-09-26 06:15:04 -0700392 GrBlendCoeff getSrcBlendCoeff() const { return fSrcBlend; }
393 GrBlendCoeff getDstBlendCoeff() const { return fDstBlend; }
394
395 /**
396 * Retrieves the last value set by setBlendConstant()
397 * @return the blending constant value
398 */
399 GrColor getBlendConstant() const { return fBlendConstant; }
400
401 /**
402 * Determines whether multiplying the computed per-pixel color by the pixel's fractional
403 * coverage before the blend will give the correct final destination color. In general it
404 * will not as coverage is applied after blending.
405 */
406 bool canTweakAlphaForCoverage() const;
407
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000408 /**
bsalomon@google.com1e269b52012-10-15 14:25:31 +0000409 * Sets the blending function coefficients.
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000410 *
411 * The blend function will be:
412 * D' = sat(S*srcCoef + D*dstCoef)
413 *
414 * where D is the existing destination color, S is the incoming source
415 * color, and D' is the new destination color that will be written. sat()
416 * is the saturation function.
417 *
bsalomon@google.com1e269b52012-10-15 14:25:31 +0000418 * @param srcCoef coefficient applied to the src color.
419 * @param dstCoef coefficient applied to the dst color.
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000420 */
421 void setBlendFunc(GrBlendCoeff srcCoeff, GrBlendCoeff dstCoeff) {
egdaniel3658f382014-09-15 07:01:59 -0700422 if (srcCoeff != fSrcBlend || dstCoeff != fDstBlend) {
423 fSrcBlend = srcCoeff;
424 fDstBlend = dstCoeff;
egdaniel3658f382014-09-15 07:01:59 -0700425 }
commit-bot@chromium.org515dcd32013-08-28 14:17:03 +0000426 #ifdef SK_DEBUG
commit-bot@chromium.org24ab3b02013-08-14 21:56:37 +0000427 if (GrBlendCoeffRefsDst(dstCoeff)) {
tfarina38406c82014-10-31 07:11:12 -0700428 SkDebugf("Unexpected dst blend coeff. Won't work correctly with coverage stages.\n");
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000429 }
commit-bot@chromium.org24ab3b02013-08-14 21:56:37 +0000430 if (GrBlendCoeffRefsSrc(srcCoeff)) {
tfarina38406c82014-10-31 07:11:12 -0700431 SkDebugf("Unexpected src blend coeff. Won't work correctly with coverage stages.\n");
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000432 }
433 #endif
434 }
435
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000436 /**
437 * Sets the blending function constant referenced by the following blending
bsalomon@google.com1e269b52012-10-15 14:25:31 +0000438 * coefficients:
bsalomon@google.com47059542012-06-06 20:51:20 +0000439 * kConstC_GrBlendCoeff
440 * kIConstC_GrBlendCoeff
441 * kConstA_GrBlendCoeff
442 * kIConstA_GrBlendCoeff
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000443 *
444 * @param constant the constant to set
445 */
egdaniel9514d242014-07-18 06:15:43 -0700446 void setBlendConstant(GrColor constant) {
egdaniel3658f382014-09-15 07:01:59 -0700447 if (constant != fBlendConstant) {
448 fBlendConstant = constant;
egdaniel3658f382014-09-15 07:01:59 -0700449 }
egdaniel9514d242014-07-18 06:15:43 -0700450 }
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000451
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000452 /// @}
453
454 ///////////////////////////////////////////////////////////////////////////
455 /// @name View Matrix
456 ////
457
458 /**
egdaniel89af44a2014-09-26 06:15:04 -0700459 * Retrieves the current view matrix
460 * @return the current view matrix.
461 */
462 const SkMatrix& getViewMatrix() const { return fViewMatrix; }
463
464 /**
465 * Retrieves the inverse of the current view matrix.
466 *
467 * If the current view matrix is invertible, return true, and if matrix
468 * is non-null, copy the inverse into it. If the current view matrix is
469 * non-invertible, return false and ignore the matrix parameter.
470 *
471 * @param matrix if not null, will receive a copy of the current inverse.
472 */
473 bool getViewInverse(SkMatrix* matrix) const {
474 SkMatrix inverse;
475 if (fViewMatrix.invert(&inverse)) {
476 if (matrix) {
477 *matrix = inverse;
478 }
479 return true;
480 }
481 return false;
482 }
483
484 /**
bsalomon@google.com137f1342013-05-29 21:27:53 +0000485 * Sets the view matrix to identity and updates any installed effects to compensate for the
486 * coord system change.
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000487 */
bsalomon@google.com137f1342013-05-29 21:27:53 +0000488 bool setIdentityViewMatrix();
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000489
bsalomon@google.com5b3e8902012-10-05 20:13:28 +0000490 ////////////////////////////////////////////////////////////////////////////
491
492 /**
bsalomon@google.com2fdcdeb2012-10-08 17:15:55 +0000493 * Preconcats the current view matrix and restores the previous view matrix in the destructor.
bsalomon@google.com137f1342013-05-29 21:27:53 +0000494 * Effect matrices are automatically adjusted to compensate and adjusted back in the destructor.
bsalomon@google.com5b3e8902012-10-05 20:13:28 +0000495 */
commit-bot@chromium.orga0b40282013-09-18 13:00:55 +0000496 class AutoViewMatrixRestore : public ::SkNoncopyable {
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000497 public:
498 AutoViewMatrixRestore() : fDrawState(NULL) {}
bsalomon@google.com2fdcdeb2012-10-08 17:15:55 +0000499
bsalomon@google.comc7818882013-03-20 19:19:53 +0000500 AutoViewMatrixRestore(GrDrawState* ds, const SkMatrix& preconcatMatrix) {
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000501 fDrawState = NULL;
bsalomon@google.comc7818882013-03-20 19:19:53 +0000502 this->set(ds, preconcatMatrix);
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000503 }
bsalomon@google.com2fdcdeb2012-10-08 17:15:55 +0000504
505 ~AutoViewMatrixRestore() { this->restore(); }
506
bsalomon@google.coma8347462012-10-08 18:59:39 +0000507 /**
508 * Can be called prior to destructor to restore the original matrix.
509 */
bsalomon@google.com2fdcdeb2012-10-08 17:15:55 +0000510 void restore();
skia.committer@gmail.comf467ce72012-10-09 02:01:37 +0000511
bsalomon@google.comc7818882013-03-20 19:19:53 +0000512 void set(GrDrawState* drawState, const SkMatrix& preconcatMatrix);
bsalomon@google.com2fdcdeb2012-10-08 17:15:55 +0000513
bsalomon@google.com137f1342013-05-29 21:27:53 +0000514 /** Sets the draw state's matrix to identity. This can fail because the current view matrix
515 is not invertible. */
516 bool setIdentity(GrDrawState* drawState);
bsalomon@google.com2fdcdeb2012-10-08 17:15:55 +0000517
bsalomon@google.com5b3e8902012-10-05 20:13:28 +0000518 private:
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000519 void doEffectCoordChanges(const SkMatrix& coordChangeMatrix);
520
joshualittb0a8a372014-09-23 09:50:21 -0700521 GrDrawState* fDrawState;
522 SkMatrix fViewMatrix;
523 int fNumColorStages;
joshualitta5305a12014-10-10 17:47:00 -0700524 SkAutoSTArray<8, GrFragmentStage::SavedCoordChange> fSavedCoordChanges;
bsalomon@google.com5b3e8902012-10-05 20:13:28 +0000525 };
526
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000527 /// @}
528
529 ///////////////////////////////////////////////////////////////////////////
530 /// @name Render Target
531 ////
532
533 /**
egdaniel89af44a2014-09-26 06:15:04 -0700534 * Retrieves the currently set render-target.
535 *
536 * @return The currently set render target.
537 */
bsalomon37dd3312014-11-03 08:47:23 -0800538 GrRenderTarget* getRenderTarget() const { return fRenderTarget.get(); }
egdaniel89af44a2014-09-26 06:15:04 -0700539
540 /**
bsalomon@google.comca432082013-01-23 19:53:46 +0000541 * Sets the render-target used at the next drawing call
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000542 *
543 * @param target The render target to set.
544 */
bsalomon2a9ca782014-09-05 14:27:43 -0700545 void setRenderTarget(GrRenderTarget* target) {
bsalomonbcf0a522014-10-08 08:40:09 -0700546 fRenderTarget.set(SkSafeRef(target), kWrite_GrIOType);
bsalomon2a9ca782014-09-05 14:27:43 -0700547 }
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000548
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000549 /// @}
550
551 ///////////////////////////////////////////////////////////////////////////
552 /// @name Stencil
553 ////
554
egdaniel89af44a2014-09-26 06:15:04 -0700555 const GrStencilSettings& getStencil() const { return fStencilSettings; }
556
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000557 /**
558 * Sets the stencil settings to use for the next draw.
559 * Changing the clip has the side-effect of possibly zeroing
560 * out the client settable stencil bits. So multipass algorithms
561 * using stencil should not change the clip between passes.
562 * @param settings the stencil settings to use.
563 */
564 void setStencil(const GrStencilSettings& settings) {
egdaniel3658f382014-09-15 07:01:59 -0700565 if (settings != fStencilSettings) {
566 fStencilSettings = settings;
egdaniel3658f382014-09-15 07:01:59 -0700567 }
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000568 }
569
570 /**
571 * Shortcut to disable stencil testing and ops.
572 */
573 void disableStencil() {
egdaniel3658f382014-09-15 07:01:59 -0700574 if (!fStencilSettings.isDisabled()) {
575 fStencilSettings.setDisabled();
egdaniel3658f382014-09-15 07:01:59 -0700576 }
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000577 }
578
bsalomon2ed5ef82014-07-07 08:44:05 -0700579 GrStencilSettings* stencil() { return &fStencilSettings; }
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000580
581 /// @}
582
583 ///////////////////////////////////////////////////////////////////////////
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000584 /// @name State Flags
585 ////
tomhudson@google.com62b09682011-11-09 16:39:17 +0000586
egdaniel89af44a2014-09-26 06:15:04 -0700587 /**
588 * Flags that affect rendering. Controlled using enable/disableState(). All
589 * default to disabled.
590 */
591 enum StateBits {
592 /**
593 * Perform dithering. TODO: Re-evaluate whether we need this bit
594 */
595 kDither_StateBit = 0x01,
596 /**
597 * Perform HW anti-aliasing. This means either HW FSAA, if supported by the render target,
598 * or smooth-line rendering if a line primitive is drawn and line smoothing is supported by
599 * the 3D API.
600 */
601 kHWAntialias_StateBit = 0x02,
602 /**
603 * Draws will respect the clip, otherwise the clip is ignored.
604 */
605 kClip_StateBit = 0x04,
606 /**
607 * Disables writing to the color buffer. Useful when performing stencil
608 * operations.
609 */
610 kNoColorWrites_StateBit = 0x08,
611
612 /**
613 * Usually coverage is applied after color blending. The color is blended using the coeffs
614 * specified by setBlendFunc(). The blended color is then combined with dst using coeffs
615 * of src_coverage, 1-src_coverage. Sometimes we are explicitly drawing a coverage mask. In
616 * this case there is no distinction between coverage and color and the caller needs direct
617 * control over the blend coeffs. When set, there will be a single blend step controlled by
618 * setBlendFunc() which will use coverage*color as the src color.
619 */
620 kCoverageDrawing_StateBit = 0x10,
joshualitt7a6184f2014-10-29 18:29:27 -0700621 kLast_StateBit = kCoverageDrawing_StateBit,
egdaniel89af44a2014-09-26 06:15:04 -0700622 };
623
624 uint32_t getFlagBits() const { return fFlagBits; }
625
626 bool isStateFlagEnabled(uint32_t stateBit) const { return 0 != (stateBit & fFlagBits); }
627
628 bool isClipState() const { return 0 != (fFlagBits & kClip_StateBit); }
629 bool isColorWriteDisabled() const { return 0 != (fFlagBits & kNoColorWrites_StateBit); }
630 bool isCoverageDrawing() const { return 0 != (fFlagBits & kCoverageDrawing_StateBit); }
631
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000632 void resetStateFlags() {
egdaniel3658f382014-09-15 07:01:59 -0700633 if (0 != fFlagBits) {
634 fFlagBits = 0;
egdaniel3658f382014-09-15 07:01:59 -0700635 }
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000636 }
637
638 /**
639 * Enable render state settings.
640 *
bsalomon@google.com1e269b52012-10-15 14:25:31 +0000641 * @param stateBits bitfield of StateBits specifying the states to enable
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000642 */
643 void enableState(uint32_t stateBits) {
egdaniel3658f382014-09-15 07:01:59 -0700644 if (stateBits & ~fFlagBits) {
645 fFlagBits |= stateBits;
egdaniel3658f382014-09-15 07:01:59 -0700646 }
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000647 }
648
649 /**
650 * Disable render state settings.
651 *
bsalomon@google.com1e269b52012-10-15 14:25:31 +0000652 * @param stateBits bitfield of StateBits specifying the states to disable
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000653 */
654 void disableState(uint32_t stateBits) {
egdaniel3658f382014-09-15 07:01:59 -0700655 if (stateBits & fFlagBits) {
656 fFlagBits &= ~(stateBits);
egdaniel3658f382014-09-15 07:01:59 -0700657 }
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000658 }
659
bsalomon@google.comd5d69ff2012-10-04 19:42:00 +0000660 /**
661 * Enable or disable stateBits based on a boolean.
662 *
bsalomon@google.com1e269b52012-10-15 14:25:31 +0000663 * @param stateBits bitfield of StateBits to enable or disable
bsalomon@google.comd5d69ff2012-10-04 19:42:00 +0000664 * @param enable if true enable stateBits, otherwise disable
665 */
666 void setState(uint32_t stateBits, bool enable) {
667 if (enable) {
668 this->enableState(stateBits);
669 } else {
670 this->disableState(stateBits);
671 }
672 }
673
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000674 /// @}
675
676 ///////////////////////////////////////////////////////////////////////////
677 /// @name Face Culling
678 ////
679
egdaniel89af44a2014-09-26 06:15:04 -0700680 enum DrawFace {
681 kInvalid_DrawFace = -1,
682
683 kBoth_DrawFace,
684 kCCW_DrawFace,
685 kCW_DrawFace,
686 };
687
688 /**
689 * Gets whether the target is drawing clockwise, counterclockwise,
690 * or both faces.
691 * @return the current draw face(s).
692 */
693 DrawFace getDrawFace() const { return fDrawFace; }
694
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000695 /**
696 * Controls whether clockwise, counterclockwise, or both faces are drawn.
697 * @param face the face(s) to draw.
698 */
699 void setDrawFace(DrawFace face) {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000700 SkASSERT(kInvalid_DrawFace != face);
bsalomon2ed5ef82014-07-07 08:44:05 -0700701 fDrawFace = face;
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000702 }
703
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000704 /// @}
705
706 ///////////////////////////////////////////////////////////////////////////
bsalomon62c447d2014-08-08 08:08:50 -0700707 /// @name Hints
708 /// Hints that when provided can enable optimizations.
709 ////
710
joshualitt65171342014-10-09 07:25:36 -0700711 enum Hints {
712 kVertexColorsAreOpaque_Hint = 0x1,
713 kLast_Hint = kVertexColorsAreOpaque_Hint
714 };
egdaniel89af44a2014-09-26 06:15:04 -0700715
bsalomon62c447d2014-08-08 08:08:50 -0700716 void setHint(Hints hint, bool value) { fHints = value ? (fHints | hint) : (fHints & ~hint); }
717
egdaniel89af44a2014-09-26 06:15:04 -0700718 bool vertexColorsAreOpaque() const { return kVertexColorsAreOpaque_Hint & fHints; }
719
bsalomon62c447d2014-08-08 08:08:50 -0700720 /// @}
721
722 ///////////////////////////////////////////////////////////////////////////
tomhudson@google.com62b09682011-11-09 16:39:17 +0000723
bsalomon838f62d2014-08-05 07:15:57 -0700724 /** Return type for CombineIfPossible. */
725 enum CombinedState {
726 /** The GrDrawStates cannot be combined. */
727 kIncompatible_CombinedState,
728 /** Either draw state can be used in place of the other. */
729 kAOrB_CombinedState,
730 /** Use the first draw state. */
731 kA_CombinedState,
732 /** Use the second draw state. */
733 kB_CombinedState,
734 };
735
736 /** This function determines whether the GrDrawStates used for two draws can be combined into
737 a single GrDrawState. This is used to avoid storing redundant GrDrawStates and to determine
738 if draws can be batched. The return value indicates whether combining is possible and, if
739 so, which of the two inputs should be used. */
bsalomon62c447d2014-08-08 08:08:50 -0700740 static CombinedState CombineIfPossible(const GrDrawState& a, const GrDrawState& b,
741 const GrDrawTargetCaps& caps);
bsalomon72336ed2014-08-05 07:35:56 -0700742
bsalomon8f727332014-08-05 07:50:06 -0700743 GrDrawState& operator= (const GrDrawState& that);
bsalomon@google.com3d0835b2011-12-08 16:12:03 +0000744
745private:
egdaniel89af44a2014-09-26 06:15:04 -0700746 /**
747 * Converts refs on GrGpuResources owned directly or indirectly by this GrDrawState into
748 * pending reads and writes. This should be called when a GrDrawState is recorded into
749 * a GrDrawTarget for later execution. Subclasses of GrDrawState may add setters. However,
750 * once this call has been made the GrDrawState is immutable. It is also no longer copyable.
751 * In the future this conversion will automatically happen when converting a GrDrawState into
752 * an optimized draw state.
753 */
754 void convertToPendingExec();
755
756 friend class GrDrawTarget;
757
758 bool isEqual(const GrDrawState& that) const;
759
760 /**
761 * Optimizations for blending / coverage to that can be applied based on the current state.
762 */
763 enum BlendOptFlags {
764 /**
765 * No optimization
766 */
767 kNone_BlendOpt = 0,
768 /**
769 * Don't draw at all
770 */
771 kSkipDraw_BlendOptFlag = 0x1,
772 /**
773 * The coverage value does not have to be computed separately from alpha, the the output
774 * color can be the modulation of the two.
775 */
776 kCoverageAsAlpha_BlendOptFlag = 0x2,
777 /**
778 * Instead of emitting a src color, emit coverage in the alpha channel and r,g,b are
779 * "don't cares".
780 */
781 kEmitCoverage_BlendOptFlag = 0x4,
782 /**
783 * Emit transparent black instead of the src color, no need to compute coverage.
784 */
785 kEmitTransBlack_BlendOptFlag = 0x8,
786 };
787 GR_DECL_BITFIELD_OPS_FRIENDS(BlendOptFlags);
788
789 /**
790 * Determines what optimizations can be applied based on the blend. The coefficients may have
791 * to be tweaked in order for the optimization to work. srcCoeff and dstCoeff are optional
792 * params that receive the tweaked coefficients. Normally the function looks at the current
793 * state to see if coverage is enabled. By setting forceCoverage the caller can speculatively
794 * determine the blend optimizations that would be used if there was partial pixel coverage.
795 *
796 * Subclasses of GrDrawTarget that actually draw (as opposed to those that just buffer for
797 * playback) must call this function and respect the flags that replace the output color.
798 *
799 * If the cached BlendOptFlags does not have the invalidate bit set, then getBlendOpts will
800 * simply returned the cached flags and coefficients. Otherwise it will calculate the values.
801 */
802 BlendOptFlags getBlendOpts(bool forceCoverage = false,
803 GrBlendCoeff* srcCoeff = NULL,
804 GrBlendCoeff* dstCoeff = NULL) const;
805
egdaniel912b3d22014-11-17 07:45:53 -0800806 const GrProcOptInfo& colorProcInfo() const {
807 this->calcColorInvariantOutput();
808 return fColorProcInfo;
809 }
810
811 const GrProcOptInfo& coverageProcInfo() const {
812 this->calcCoverageInvariantOutput();
813 return fCoverageProcInfo;
814 }
815
egdaniel89af44a2014-09-26 06:15:04 -0700816 /**
817 * Determines whether src alpha is guaranteed to be one for all src pixels
818 */
819 bool srcAlphaWillBeOne() const;
820
egdanielb6cbc382014-11-13 11:00:34 -0800821 /**
822 * If fColorProcInfoValid is false, function calculates the invariant output for the color
823 * stages and results are stored in fColorProcInfo.
824 */
825 void calcColorInvariantOutput() const;
826
827 /**
828 * If fCoverageProcInfoValid is false, function calculates the invariant output for the coverage
829 * stages and results are stored in fCoverageProcInfo.
830 */
831 void calcCoverageInvariantOutput() const;
832
bsalomon8f727332014-08-05 07:50:06 -0700833 void onReset(const SkMatrix* initialViewMatrix);
bsalomon@google.com137f1342013-05-29 21:27:53 +0000834
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000835 // Some of the auto restore objects assume that no effects are removed during their lifetime.
836 // This is used to assert that this condition holds.
commit-bot@chromium.org1acc3d72013-09-06 23:13:05 +0000837 SkDEBUGCODE(int fBlockEffectRemovalCnt;)
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000838
egdaniel7b3d5ee2014-08-28 05:41:14 -0700839 void internalSetVertexAttribs(const GrVertexAttrib attribs[], int count, size_t stride);
robertphillips@google.com42903302013-04-20 12:26:07 +0000840
egdaniel89af44a2014-09-26 06:15:04 -0700841 typedef GrTGpuResourceRef<GrRenderTarget> ProgramRenderTarget;
842 // These fields are roughly sorted by decreasing likelihood of being different in op==
843 ProgramRenderTarget fRenderTarget;
844 GrColor fColor;
845 SkMatrix fViewMatrix;
846 GrColor fBlendConstant;
847 uint32_t fFlagBits;
848 const GrVertexAttrib* fVAPtr;
849 int fVACount;
850 size_t fVAStride;
851 GrStencilSettings fStencilSettings;
852 uint8_t fCoverage;
853 DrawFace fDrawFace;
854 GrBlendCoeff fSrcBlend;
855 GrBlendCoeff fDstBlend;
856
joshualitta5305a12014-10-10 17:47:00 -0700857 typedef SkSTArray<4, GrFragmentStage> FragmentStageArray;
858 typedef GrProgramElementRef<const GrGeometryProcessor> ProgramGeometryProcessor;
859 ProgramGeometryProcessor fGeometryProcessor;
860 FragmentStageArray fColorStages;
861 FragmentStageArray fCoverageStages;
egdaniel89af44a2014-09-26 06:15:04 -0700862
863 uint32_t fHints;
864
865 // This is simply a different representation of info in fVertexAttribs and thus does
866 // not need to be compared in op==.
867 int fFixedFunctionVertexAttribIndices[kGrFixedFunctionVertexAttribBindingCnt];
868
egdanielb6cbc382014-11-13 11:00:34 -0800869 mutable GrProcOptInfo fColorProcInfo;
870 mutable GrProcOptInfo fCoverageProcInfo;
871 mutable bool fColorProcInfoValid;
872 mutable bool fCoverageProcInfoValid;
873
egdanielb109ac22014-10-07 06:45:44 -0700874 friend class GrOptDrawState;
875
egdaniel89af44a2014-09-26 06:15:04 -0700876 typedef SkRefCnt INHERITED;
tomhudson@google.com93813632011-10-27 20:21:16 +0000877};
878
egdanielb109ac22014-10-07 06:45:44 -0700879GR_MAKE_BITFIELD_OPS(GrDrawState::BlendOptFlags);
egdaniel89af44a2014-09-26 06:15:04 -0700880
tomhudson@google.com93813632011-10-27 20:21:16 +0000881#endif