blob: 15df975d73c4470d5c1e0b83a85ae77c96e4fe9a [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"
17#include "GrRenderTarget.h"
18#include "GrStencil.h"
19#include "SkMatrix.h"
bsalomon@google.com68b58c92013-01-17 16:50:08 +000020#include "effects/GrSimpleTextureEffect.h"
tomhudson@google.com93813632011-10-27 20:21:16 +000021
egdaniel89af44a2014-09-26 06:15:04 -070022class GrDrawTargetCaps;
egdaniel170f90b2014-09-16 12:54:40 -070023class GrOptDrawState;
egdaniel89af44a2014-09-26 06:15:04 -070024class GrPaint;
25class GrTexture;
egdaniel170f90b2014-09-16 12:54:40 -070026
egdaniel89af44a2014-09-26 06:15:04 -070027class GrDrawState : public SkRefCnt {
bsalomon@google.com2e3d1442012-03-26 20:33:54 +000028public:
reed@google.comfa35e3d2012-06-26 20:16:17 +000029 SK_DECLARE_INST_COUNT(GrDrawState)
rmistry@google.comd6176b02012-08-23 18:14:13 +000030
egdaniel69bb90c2014-11-11 07:32:45 -080031 GrDrawState() {
commit-bot@chromium.org1acc3d72013-09-06 23:13:05 +000032 SkDEBUGCODE(fBlockEffectRemovalCnt = 0;)
bsalomon@google.comeb6879f2013-06-13 19:34:18 +000033 this->reset();
34 }
tomhudson@google.com93813632011-10-27 20:21:16 +000035
egdaniel69bb90c2014-11-11 07:32:45 -080036 GrDrawState(const SkMatrix& initialViewMatrix) {
commit-bot@chromium.org1acc3d72013-09-06 23:13:05 +000037 SkDEBUGCODE(fBlockEffectRemovalCnt = 0;)
bsalomon@google.comeb6879f2013-06-13 19:34:18 +000038 this->reset(initialViewMatrix);
39 }
bsalomon@google.com137f1342013-05-29 21:27:53 +000040
41 /**
42 * Copies another draw state.
43 **/
egdaniel69bb90c2014-11-11 07:32:45 -080044 GrDrawState(const GrDrawState& state) : INHERITED() {
commit-bot@chromium.org1acc3d72013-09-06 23:13:05 +000045 SkDEBUGCODE(fBlockEffectRemovalCnt = 0;)
bsalomon@google.com46f7afb2012-01-18 19:51:55 +000046 *this = state;
47 }
48
bsalomon@google.com137f1342013-05-29 21:27:53 +000049 /**
50 * Copies another draw state with a preconcat to the view matrix.
51 **/
bsalomon8f727332014-08-05 07:50:06 -070052 GrDrawState(const GrDrawState& state, const SkMatrix& preConcatMatrix);
robertphillips@google.com9ec07532012-06-22 12:01:30 +000053
egdaniel170f90b2014-09-16 12:54:40 -070054 virtual ~GrDrawState();
bsalomon@google.com137f1342013-05-29 21:27:53 +000055
bsalomon@google.com52a5dcb2012-01-17 16:01:37 +000056 /**
joshualittb0a8a372014-09-23 09:50:21 -070057 * Resets to the default state. GrProcessors will be removed from all stages.
rmistry@google.comd6176b02012-08-23 18:14:13 +000058 */
bsalomon@google.com137f1342013-05-29 21:27:53 +000059 void reset() { this->onReset(NULL); }
robertphillips@google.com9ec07532012-06-22 12:01:30 +000060
bsalomon@google.com137f1342013-05-29 21:27:53 +000061 void reset(const SkMatrix& initialViewMatrix) { this->onReset(&initialViewMatrix); }
bsalomon@google.comaf84e742012-10-05 13:23:24 +000062
63 /**
commit-bot@chromium.orgbb6a3172013-05-28 17:25:49 +000064 * Initializes the GrDrawState based on a GrPaint, view matrix and render target. Note that
65 * GrDrawState encompasses more than GrPaint. Aspects of GrDrawState that have no GrPaint
bsalomon9c0822a2014-08-11 11:07:48 -070066 * equivalents are set to default values with the exception of vertex attribute state which
67 * is unmodified by this function and clipping which will be enabled.
bsalomon@google.comaf84e742012-10-05 13:23:24 +000068 */
commit-bot@chromium.orgbb6a3172013-05-28 17:25:49 +000069 void setFromPaint(const GrPaint& , const SkMatrix& viewMatrix, GrRenderTarget*);
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +000070
71 ///////////////////////////////////////////////////////////////////////////
jvanverth@google.com9b855c72013-03-01 18:21:22 +000072 /// @name Vertex Attributes
jvanverth@google.comcc782382013-01-28 20:39:48 +000073 ////
74
egdaniel89af44a2014-09-26 06:15:04 -070075 enum {
76 kMaxVertexAttribCnt = kLast_GrVertexAttribBinding + 4,
77 };
78
79 const GrVertexAttrib* getVertexAttribs() const { return fVAPtr; }
80 int getVertexAttribCount() const { return fVACount; }
81
82 size_t getVertexStride() const { return fVAStride; }
83
84 bool hasLocalCoordAttribute() const {
85 return -1 != fFixedFunctionVertexAttribIndices[kLocalCoord_GrVertexAttribBinding];
86 }
87 bool hasColorVertexAttribute() const {
88 return -1 != fFixedFunctionVertexAttribIndices[kColor_GrVertexAttribBinding];
89 }
90 bool hasCoverageVertexAttribute() const {
91 return -1 != fFixedFunctionVertexAttribIndices[kCoverage_GrVertexAttribBinding];
92 }
93
94 const int* getFixedFunctionVertexAttribIndices() const {
95 return fFixedFunctionVertexAttribIndices;
96 }
97
98 bool validateVertexAttribs() const;
99
jvanverth@google.com9b855c72013-03-01 18:21:22 +0000100 /**
jvanverth@google.com054ae992013-04-01 20:06:51 +0000101 * The format of vertices is represented as an array of GrVertexAttribs, with each representing
102 * the type of the attribute, its offset, and semantic binding (see GrVertexAttrib in
103 * GrTypesPriv.h).
jvanverth@google.comb8b705b2013-02-28 16:28:34 +0000104 *
joshualittb0a8a372014-09-23 09:50:21 -0700105 * The mapping of attributes with kEffect bindings to GrProcessor inputs is specified when
jvanverth@google.com054ae992013-04-01 20:06:51 +0000106 * setEffect is called.
jvanverth@google.comb8b705b2013-02-28 16:28:34 +0000107 */
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000108
jvanverth@google.com9b855c72013-03-01 18:21:22 +0000109 /**
robertphillips@google.com42903302013-04-20 12:26:07 +0000110 * Sets vertex attributes for next draw. The object driving the templatization
111 * should be a global GrVertexAttrib array that is never changed.
egdaniel7b3d5ee2014-08-28 05:41:14 -0700112 *
113 * @param count the number of attributes being set, limited to kMaxVertexAttribCnt.
114 * @param stride the number of bytes between successive vertex data.
jvanverth@google.com9b855c72013-03-01 18:21:22 +0000115 */
egdaniel7b3d5ee2014-08-28 05:41:14 -0700116 template <const GrVertexAttrib A[]> void setVertexAttribs(int count, size_t stride) {
117 this->internalSetVertexAttribs(A, count, stride);
robertphillips@google.com42903302013-04-20 12:26:07 +0000118 }
jvanverth@google.comb8b705b2013-02-28 16:28:34 +0000119
jvanverth@google.com9b855c72013-03-01 18:21:22 +0000120 /**
jvanverth@google.com054ae992013-04-01 20:06:51 +0000121 * Sets default vertex attributes for next draw. The default is a single attribute:
122 * {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribType}
jvanverth@google.com9b855c72013-03-01 18:21:22 +0000123 */
124 void setDefaultVertexAttribs();
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000125
jvanverth@google.com054ae992013-04-01 20:06:51 +0000126 /**
bsalomon@google.com0406b9e2013-04-02 21:00:15 +0000127 * Helper to save/restore vertex attribs
128 */
129 class AutoVertexAttribRestore {
130 public:
bsalomon8f727332014-08-05 07:50:06 -0700131 AutoVertexAttribRestore(GrDrawState* drawState);
bsalomon@google.com0406b9e2013-04-02 21:00:15 +0000132
egdaniel3658f382014-09-15 07:01:59 -0700133 ~AutoVertexAttribRestore() { fDrawState->internalSetVertexAttribs(fVAPtr, fVACount,
134 fVAStride); }
bsalomon@google.com0406b9e2013-04-02 21:00:15 +0000135
136 private:
robertphillips@google.com42903302013-04-20 12:26:07 +0000137 GrDrawState* fDrawState;
138 const GrVertexAttrib* fVAPtr;
139 int fVACount;
egdaniel7b3d5ee2014-08-28 05:41:14 -0700140 size_t fVAStride;
bsalomon@google.com0406b9e2013-04-02 21:00:15 +0000141 };
142
jvanverth@google.com9b855c72013-03-01 18:21:22 +0000143 /// @}
144
jvanverth@google.com9b855c72013-03-01 18:21:22 +0000145 /**
bsalomon62c447d2014-08-08 08:08:50 -0700146 * Depending on features available in the underlying 3D API and the color blend mode requested
147 * it may or may not be possible to correctly blend with fractional pixel coverage generated by
148 * the fragment shader.
149 *
150 * This function considers the current draw state and the draw target's capabilities to
151 * determine whether coverage can be handled correctly. This function assumes that the caller
152 * intends to specify fractional pixel coverage (via setCoverage(), through a coverage vertex
153 * attribute, or a coverage effect) but may not have specified it yet.
154 */
155 bool couldApplyCoverage(const GrDrawTargetCaps& caps) const;
156
egdaniel89af44a2014-09-26 06:15:04 -0700157 /**
158 * Determines whether the output coverage is guaranteed to be one for all pixels hit by a draw.
159 */
160 bool hasSolidCoverage() const;
161
jvanverth@google.comcc782382013-01-28 20:39:48 +0000162 /// @}
163
164 ///////////////////////////////////////////////////////////////////////////
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000165 /// @name Color
166 ////
167
egdaniel89af44a2014-09-26 06:15:04 -0700168 GrColor getColor() const { return fColor; }
169
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000170 /**
171 * Sets color for next draw to a premultiplied-alpha color.
172 *
173 * @param color the color to set.
174 */
egdaniel9514d242014-07-18 06:15:43 -0700175 void setColor(GrColor color) {
egdaniel3658f382014-09-15 07:01:59 -0700176 if (color != fColor) {
177 fColor = color;
egdaniel3658f382014-09-15 07:01:59 -0700178 }
egdaniel9514d242014-07-18 06:15:43 -0700179 }
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000180
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000181 /**
182 * Sets the color to be used for the next draw to be
183 * (r,g,b,a) = (alpha, alpha, alpha, alpha).
184 *
185 * @param alpha The alpha value to set as the color.
186 */
bsalomon62c447d2014-08-08 08:08:50 -0700187 void setAlpha(uint8_t a) { this->setColor((a << 24) | (a << 16) | (a << 8) | a); }
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000188
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000189 /// @}
190
191 ///////////////////////////////////////////////////////////////////////////
bsalomon@google.com2401ae82012-01-17 21:03:05 +0000192 /// @name Coverage
193 ////
194
egdaniel89af44a2014-09-26 06:15:04 -0700195 uint8_t getCoverage() const { return fCoverage; }
196
197 GrColor getCoverageColor() const {
198 return GrColorPackRGBA(fCoverage, fCoverage, fCoverage, fCoverage);
199 }
200
bsalomon@google.com2401ae82012-01-17 21:03:05 +0000201 /**
rmistry@google.comd6176b02012-08-23 18:14:13 +0000202 * Sets a constant fractional coverage to be applied to the draw. The
bsalomon@google.com2401ae82012-01-17 21:03:05 +0000203 * initial value (after construction or reset()) is 0xff. The constant
204 * coverage is ignored when per-vertex coverage is provided.
205 */
206 void setCoverage(uint8_t coverage) {
egdaniel3658f382014-09-15 07:01:59 -0700207 if (coverage != fCoverage) {
208 fCoverage = coverage;
egdaniel3658f382014-09-15 07:01:59 -0700209 }
bsalomon@google.com2401ae82012-01-17 21:03:05 +0000210 }
211
bsalomon@google.com2401ae82012-01-17 21:03:05 +0000212 /// @}
213
joshualittbd769d02014-09-04 08:56:46 -0700214 /**
215 * The geometry processor is the sole element of the skia pipeline which can use the vertex,
216 * geometry, and tesselation shaders. The GP may also compute a coverage in its fragment shader
217 * but is never put in the color processing pipeline.
218 */
219
joshualittb0a8a372014-09-23 09:50:21 -0700220 const GrGeometryProcessor* setGeometryProcessor(const GrGeometryProcessor* geometryProcessor) {
221 SkASSERT(geometryProcessor);
joshualittbd769d02014-09-04 08:56:46 -0700222 SkASSERT(!this->hasGeometryProcessor());
joshualitta5305a12014-10-10 17:47:00 -0700223 fGeometryProcessor.reset(SkRef(geometryProcessor));
joshualittb0a8a372014-09-23 09:50:21 -0700224 return geometryProcessor;
joshualittbd769d02014-09-04 08:56:46 -0700225 }
226
bsalomon@google.com2401ae82012-01-17 21:03:05 +0000227 ///////////////////////////////////////////////////////////////////////////
bsalomon@google.comadc65362013-01-28 14:26:09 +0000228 /// @name Effect Stages
joshualittb0a8a372014-09-23 09:50:21 -0700229 /// Each stage hosts a GrProcessor. The effect produces an output color or coverage in the
230 /// fragment shader. Its inputs are the output from the previous stage as well as some variables
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000231 /// available to it in the fragment and vertex shader (e.g. the vertex position, the dst color,
232 /// the fragment position, local coordinates).
233 ///
234 /// The stages are divided into two sets, color-computing and coverage-computing. The final
235 /// color stage produces the final pixel color. The coverage-computing stages function exactly
236 /// as the color-computing but the output of the final coverage stage is treated as a fractional
237 /// pixel coverage rather than as input to the src/dst color blend step.
238 ///
239 /// The input color to the first color-stage is either the constant color or interpolated
240 /// per-vertex colors. The input to the first coverage stage is either a constant coverage
241 /// (usually full-coverage) or interpolated per-vertex coverage.
242 ///
243 /// See the documentation of kCoverageDrawing_StateBit for information about disabling the
244 /// the color / coverage distinction.
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000245 ////
246
egdaniel89af44a2014-09-26 06:15:04 -0700247 int numColorStages() const { return fColorStages.count(); }
248 int numCoverageStages() const { return fCoverageStages.count(); }
249 int numTotalStages() const {
250 return this->numColorStages() + this->numCoverageStages() +
251 (this->hasGeometryProcessor() ? 1 : 0);
252 }
253
254 bool hasGeometryProcessor() const { return SkToBool(fGeometryProcessor.get()); }
joshualitta5305a12014-10-10 17:47:00 -0700255 const GrGeometryProcessor* getGeometryProcessor() const { return fGeometryProcessor.get(); }
egdaniel89af44a2014-09-26 06:15:04 -0700256 const GrFragmentStage& getColorStage(int idx) const { return fColorStages[idx]; }
257 const GrFragmentStage& getCoverageStage(int idx) const { return fCoverageStages[idx]; }
258
259 /**
260 * Checks whether any of the effects will read the dst pixel color.
261 */
262 bool willEffectReadDstColor() const;
263
joshualittb0a8a372014-09-23 09:50:21 -0700264 const GrFragmentProcessor* addColorProcessor(const GrFragmentProcessor* effect) {
bsalomon49f085d2014-09-05 13:34:00 -0700265 SkASSERT(effect);
joshualittb0a8a372014-09-23 09:50:21 -0700266 SkNEW_APPEND_TO_TARRAY(&fColorStages, GrFragmentStage, (effect));
jvanverth@google.com65eb4d52013-03-19 18:51:02 +0000267 return effect;
268 }
skia.committer@gmail.com01c34ee2013-03-20 07:01:02 +0000269
joshualittb0a8a372014-09-23 09:50:21 -0700270 const GrFragmentProcessor* addCoverageProcessor(const GrFragmentProcessor* effect) {
bsalomon49f085d2014-09-05 13:34:00 -0700271 SkASSERT(effect);
joshualittb0a8a372014-09-23 09:50:21 -0700272 SkNEW_APPEND_TO_TARRAY(&fCoverageStages, GrFragmentStage, (effect));
bsalomon@google.comadc65362013-01-28 14:26:09 +0000273 return effect;
274 }
275
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000276 /**
bsalomon@google.comc7818882013-03-20 19:19:53 +0000277 * Creates a GrSimpleTextureEffect that uses local coords as texture coordinates.
tomhudson@google.com1e8f0162012-07-20 16:25:18 +0000278 */
joshualittb0a8a372014-09-23 09:50:21 -0700279 void addColorTextureProcessor(GrTexture* texture, const SkMatrix& matrix) {
280 this->addColorProcessor(GrSimpleTextureEffect::Create(texture, matrix))->unref();
bsalomon@google.comdfdb7e52012-10-16 15:19:45 +0000281 }
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000282
joshualittb0a8a372014-09-23 09:50:21 -0700283 void addCoverageTextureProcessor(GrTexture* texture, const SkMatrix& matrix) {
284 this->addCoverageProcessor(GrSimpleTextureEffect::Create(texture, matrix))->unref();
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000285 }
286
joshualittb0a8a372014-09-23 09:50:21 -0700287 void addColorTextureProcessor(GrTexture* texture,
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000288 const SkMatrix& matrix,
289 const GrTextureParams& params) {
joshualittb0a8a372014-09-23 09:50:21 -0700290 this->addColorProcessor(GrSimpleTextureEffect::Create(texture, matrix, params))->unref();
291 }
292
293 void addCoverageTextureProcessor(GrTexture* texture,
294 const SkMatrix& matrix,
295 const GrTextureParams& params) {
296 this->addCoverageProcessor(GrSimpleTextureEffect::Create(texture, matrix, params))->unref();
commit-bot@chromium.orgff6ea262013-03-12 12:26:08 +0000297 }
tomhudson@google.com676e6602012-07-10 17:21:48 +0000298
robertphillips@google.com972265d2012-06-13 18:49:30 +0000299 /**
bsalomon9b536522014-09-05 09:18:51 -0700300 * When this object is destroyed it will remove any color/coverage effects from the draw state
301 * that were added after its constructor.
302 *
303 * This class has strange behavior around geometry processor. If there is a GP on the draw state
304 * it will assert that the GP is not modified until after the destructor of the ARE. If the
305 * draw state has a NULL GP when the ARE is constructed then it will reset it to null in the
306 * destructor.
307 *
308 * TODO: We'd prefer for the ARE to just save and restore the GP. However, this would add
309 * significant complexity to the multi-ref architecture for deferred drawing. Once GrDrawState
310 * and GrOptDrawState are fully separated then GrDrawState will never be in the deferred
311 * execution state and GrOptDrawState always will be (and will be immutable and therefore
312 * unable to have an ARE). At this point we can restore sanity and have the ARE save and restore
313 * the GP.
robertphillips@google.com972265d2012-06-13 18:49:30 +0000314 */
commit-bot@chromium.orga0b40282013-09-18 13:00:55 +0000315 class AutoRestoreEffects : public ::SkNoncopyable {
robertphillips@google.com972265d2012-06-13 18:49:30 +0000316 public:
bsalomon9b536522014-09-05 09:18:51 -0700317 AutoRestoreEffects()
318 : fDrawState(NULL)
bsalomon52e9d632014-09-05 12:23:12 -0700319 , fOriginalGPID(SK_InvalidUniqueID)
bsalomon9b536522014-09-05 09:18:51 -0700320 , fColorEffectCnt(0)
321 , fCoverageEffectCnt(0) {}
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000322
bsalomon9b536522014-09-05 09:18:51 -0700323 AutoRestoreEffects(GrDrawState* ds)
324 : fDrawState(NULL)
bsalomon52e9d632014-09-05 12:23:12 -0700325 , fOriginalGPID(SK_InvalidUniqueID)
bsalomon9b536522014-09-05 09:18:51 -0700326 , fColorEffectCnt(0)
327 , fCoverageEffectCnt(0) {
skia.committer@gmail.com5c493d52013-06-14 07:00:49 +0000328 this->set(ds);
robertphillips@google.comf09b87d2013-06-13 20:06:44 +0000329 }
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000330
331 ~AutoRestoreEffects() { this->set(NULL); }
332
bsalomon8f727332014-08-05 07:50:06 -0700333 void set(GrDrawState* ds);
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000334
bsalomon49f085d2014-09-05 13:34:00 -0700335 bool isSet() const { return SkToBool(fDrawState); }
bsalomon8af05232014-06-03 06:34:58 -0700336
robertphillips@google.com972265d2012-06-13 18:49:30 +0000337 private:
bsalomon9b536522014-09-05 09:18:51 -0700338 GrDrawState* fDrawState;
bsalomon52e9d632014-09-05 12:23:12 -0700339 uint32_t fOriginalGPID;
bsalomon9b536522014-09-05 09:18:51 -0700340 int fColorEffectCnt;
341 int fCoverageEffectCnt;
robertphillips@google.com972265d2012-06-13 18:49:30 +0000342 };
343
joshualitta58fe352014-10-27 08:39:00 -0700344 /**
345 * AutoRestoreStencil
346 *
347 * This simple struct saves and restores the stencil settings
348 */
349 class AutoRestoreStencil : public ::SkNoncopyable {
350 public:
351 AutoRestoreStencil() : fDrawState(NULL) {}
352
353 AutoRestoreStencil(GrDrawState* ds) : fDrawState(NULL) { this->set(ds); }
354
355 ~AutoRestoreStencil() { this->set(NULL); }
356
357 void set(GrDrawState* ds) {
358 if (fDrawState) {
359 fDrawState->setStencil(fStencilSettings);
360 }
361 fDrawState = ds;
362 if (ds) {
363 fStencilSettings = ds->getStencil();
364 }
365 }
366
367 bool isSet() const { return SkToBool(fDrawState); }
368
369 private:
370 GrDrawState* fDrawState;
371 GrStencilSettings fStencilSettings;
372 };
373
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000374 /// @}
375
376 ///////////////////////////////////////////////////////////////////////////
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000377 /// @name Blending
378 ////
379
egdaniel89af44a2014-09-26 06:15:04 -0700380 GrBlendCoeff getSrcBlendCoeff() const { return fSrcBlend; }
381 GrBlendCoeff getDstBlendCoeff() const { return fDstBlend; }
382
383 /**
384 * Retrieves the last value set by setBlendConstant()
385 * @return the blending constant value
386 */
387 GrColor getBlendConstant() const { return fBlendConstant; }
388
389 /**
390 * Determines whether multiplying the computed per-pixel color by the pixel's fractional
391 * coverage before the blend will give the correct final destination color. In general it
392 * will not as coverage is applied after blending.
393 */
394 bool canTweakAlphaForCoverage() const;
395
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000396 /**
bsalomon@google.com1e269b52012-10-15 14:25:31 +0000397 * Sets the blending function coefficients.
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000398 *
399 * The blend function will be:
400 * D' = sat(S*srcCoef + D*dstCoef)
401 *
402 * where D is the existing destination color, S is the incoming source
403 * color, and D' is the new destination color that will be written. sat()
404 * is the saturation function.
405 *
bsalomon@google.com1e269b52012-10-15 14:25:31 +0000406 * @param srcCoef coefficient applied to the src color.
407 * @param dstCoef coefficient applied to the dst color.
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000408 */
409 void setBlendFunc(GrBlendCoeff srcCoeff, GrBlendCoeff dstCoeff) {
egdaniel3658f382014-09-15 07:01:59 -0700410 if (srcCoeff != fSrcBlend || dstCoeff != fDstBlend) {
411 fSrcBlend = srcCoeff;
412 fDstBlend = dstCoeff;
egdaniel3658f382014-09-15 07:01:59 -0700413 }
commit-bot@chromium.org515dcd32013-08-28 14:17:03 +0000414 #ifdef SK_DEBUG
commit-bot@chromium.org24ab3b02013-08-14 21:56:37 +0000415 if (GrBlendCoeffRefsDst(dstCoeff)) {
tfarina38406c82014-10-31 07:11:12 -0700416 SkDebugf("Unexpected dst blend coeff. Won't work correctly with coverage stages.\n");
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000417 }
commit-bot@chromium.org24ab3b02013-08-14 21:56:37 +0000418 if (GrBlendCoeffRefsSrc(srcCoeff)) {
tfarina38406c82014-10-31 07:11:12 -0700419 SkDebugf("Unexpected src blend coeff. Won't work correctly with coverage stages.\n");
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000420 }
421 #endif
422 }
423
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000424 /**
425 * Sets the blending function constant referenced by the following blending
bsalomon@google.com1e269b52012-10-15 14:25:31 +0000426 * coefficients:
bsalomon@google.com47059542012-06-06 20:51:20 +0000427 * kConstC_GrBlendCoeff
428 * kIConstC_GrBlendCoeff
429 * kConstA_GrBlendCoeff
430 * kIConstA_GrBlendCoeff
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000431 *
432 * @param constant the constant to set
433 */
egdaniel9514d242014-07-18 06:15:43 -0700434 void setBlendConstant(GrColor constant) {
egdaniel3658f382014-09-15 07:01:59 -0700435 if (constant != fBlendConstant) {
436 fBlendConstant = constant;
egdaniel3658f382014-09-15 07:01:59 -0700437 }
egdaniel9514d242014-07-18 06:15:43 -0700438 }
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000439
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000440 /// @}
441
442 ///////////////////////////////////////////////////////////////////////////
443 /// @name View Matrix
444 ////
445
446 /**
egdaniel89af44a2014-09-26 06:15:04 -0700447 * Retrieves the current view matrix
448 * @return the current view matrix.
449 */
450 const SkMatrix& getViewMatrix() const { return fViewMatrix; }
451
452 /**
453 * Retrieves the inverse of the current view matrix.
454 *
455 * If the current view matrix is invertible, return true, and if matrix
456 * is non-null, copy the inverse into it. If the current view matrix is
457 * non-invertible, return false and ignore the matrix parameter.
458 *
459 * @param matrix if not null, will receive a copy of the current inverse.
460 */
461 bool getViewInverse(SkMatrix* matrix) const {
462 SkMatrix inverse;
463 if (fViewMatrix.invert(&inverse)) {
464 if (matrix) {
465 *matrix = inverse;
466 }
467 return true;
468 }
469 return false;
470 }
471
472 /**
bsalomon@google.com137f1342013-05-29 21:27:53 +0000473 * Sets the view matrix to identity and updates any installed effects to compensate for the
474 * coord system change.
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000475 */
bsalomon@google.com137f1342013-05-29 21:27:53 +0000476 bool setIdentityViewMatrix();
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000477
bsalomon@google.com5b3e8902012-10-05 20:13:28 +0000478 ////////////////////////////////////////////////////////////////////////////
479
480 /**
bsalomon@google.com2fdcdeb2012-10-08 17:15:55 +0000481 * Preconcats the current view matrix and restores the previous view matrix in the destructor.
bsalomon@google.com137f1342013-05-29 21:27:53 +0000482 * Effect matrices are automatically adjusted to compensate and adjusted back in the destructor.
bsalomon@google.com5b3e8902012-10-05 20:13:28 +0000483 */
commit-bot@chromium.orga0b40282013-09-18 13:00:55 +0000484 class AutoViewMatrixRestore : public ::SkNoncopyable {
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000485 public:
486 AutoViewMatrixRestore() : fDrawState(NULL) {}
bsalomon@google.com2fdcdeb2012-10-08 17:15:55 +0000487
bsalomon@google.comc7818882013-03-20 19:19:53 +0000488 AutoViewMatrixRestore(GrDrawState* ds, const SkMatrix& preconcatMatrix) {
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000489 fDrawState = NULL;
bsalomon@google.comc7818882013-03-20 19:19:53 +0000490 this->set(ds, preconcatMatrix);
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000491 }
bsalomon@google.com2fdcdeb2012-10-08 17:15:55 +0000492
493 ~AutoViewMatrixRestore() { this->restore(); }
494
bsalomon@google.coma8347462012-10-08 18:59:39 +0000495 /**
496 * Can be called prior to destructor to restore the original matrix.
497 */
bsalomon@google.com2fdcdeb2012-10-08 17:15:55 +0000498 void restore();
skia.committer@gmail.comf467ce72012-10-09 02:01:37 +0000499
bsalomon@google.comc7818882013-03-20 19:19:53 +0000500 void set(GrDrawState* drawState, const SkMatrix& preconcatMatrix);
bsalomon@google.com2fdcdeb2012-10-08 17:15:55 +0000501
bsalomon@google.com137f1342013-05-29 21:27:53 +0000502 /** Sets the draw state's matrix to identity. This can fail because the current view matrix
503 is not invertible. */
504 bool setIdentity(GrDrawState* drawState);
bsalomon@google.com2fdcdeb2012-10-08 17:15:55 +0000505
bsalomon@google.com5b3e8902012-10-05 20:13:28 +0000506 private:
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000507 void doEffectCoordChanges(const SkMatrix& coordChangeMatrix);
508
joshualittb0a8a372014-09-23 09:50:21 -0700509 GrDrawState* fDrawState;
510 SkMatrix fViewMatrix;
511 int fNumColorStages;
joshualitta5305a12014-10-10 17:47:00 -0700512 SkAutoSTArray<8, GrFragmentStage::SavedCoordChange> fSavedCoordChanges;
bsalomon@google.com5b3e8902012-10-05 20:13:28 +0000513 };
514
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000515 /// @}
516
517 ///////////////////////////////////////////////////////////////////////////
518 /// @name Render Target
519 ////
520
521 /**
egdaniel89af44a2014-09-26 06:15:04 -0700522 * Retrieves the currently set render-target.
523 *
524 * @return The currently set render target.
525 */
bsalomon37dd3312014-11-03 08:47:23 -0800526 GrRenderTarget* getRenderTarget() const { return fRenderTarget.get(); }
egdaniel89af44a2014-09-26 06:15:04 -0700527
528 /**
bsalomon@google.comca432082013-01-23 19:53:46 +0000529 * Sets the render-target used at the next drawing call
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000530 *
531 * @param target The render target to set.
532 */
bsalomon2a9ca782014-09-05 14:27:43 -0700533 void setRenderTarget(GrRenderTarget* target) {
bsalomonbcf0a522014-10-08 08:40:09 -0700534 fRenderTarget.set(SkSafeRef(target), kWrite_GrIOType);
bsalomon2a9ca782014-09-05 14:27:43 -0700535 }
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000536
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000537 /// @}
538
539 ///////////////////////////////////////////////////////////////////////////
540 /// @name Stencil
541 ////
542
egdaniel89af44a2014-09-26 06:15:04 -0700543 const GrStencilSettings& getStencil() const { return fStencilSettings; }
544
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000545 /**
546 * Sets the stencil settings to use for the next draw.
547 * Changing the clip has the side-effect of possibly zeroing
548 * out the client settable stencil bits. So multipass algorithms
549 * using stencil should not change the clip between passes.
550 * @param settings the stencil settings to use.
551 */
552 void setStencil(const GrStencilSettings& settings) {
egdaniel3658f382014-09-15 07:01:59 -0700553 if (settings != fStencilSettings) {
554 fStencilSettings = settings;
egdaniel3658f382014-09-15 07:01:59 -0700555 }
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000556 }
557
558 /**
559 * Shortcut to disable stencil testing and ops.
560 */
561 void disableStencil() {
egdaniel3658f382014-09-15 07:01:59 -0700562 if (!fStencilSettings.isDisabled()) {
563 fStencilSettings.setDisabled();
egdaniel3658f382014-09-15 07:01:59 -0700564 }
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000565 }
566
bsalomon2ed5ef82014-07-07 08:44:05 -0700567 GrStencilSettings* stencil() { return &fStencilSettings; }
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000568
569 /// @}
570
571 ///////////////////////////////////////////////////////////////////////////
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000572 /// @name State Flags
573 ////
tomhudson@google.com62b09682011-11-09 16:39:17 +0000574
egdaniel89af44a2014-09-26 06:15:04 -0700575 /**
576 * Flags that affect rendering. Controlled using enable/disableState(). All
577 * default to disabled.
578 */
579 enum StateBits {
580 /**
581 * Perform dithering. TODO: Re-evaluate whether we need this bit
582 */
583 kDither_StateBit = 0x01,
584 /**
585 * Perform HW anti-aliasing. This means either HW FSAA, if supported by the render target,
586 * or smooth-line rendering if a line primitive is drawn and line smoothing is supported by
587 * the 3D API.
588 */
589 kHWAntialias_StateBit = 0x02,
590 /**
591 * Draws will respect the clip, otherwise the clip is ignored.
592 */
593 kClip_StateBit = 0x04,
594 /**
595 * Disables writing to the color buffer. Useful when performing stencil
596 * operations.
597 */
598 kNoColorWrites_StateBit = 0x08,
599
600 /**
601 * Usually coverage is applied after color blending. The color is blended using the coeffs
602 * specified by setBlendFunc(). The blended color is then combined with dst using coeffs
603 * of src_coverage, 1-src_coverage. Sometimes we are explicitly drawing a coverage mask. In
604 * this case there is no distinction between coverage and color and the caller needs direct
605 * control over the blend coeffs. When set, there will be a single blend step controlled by
606 * setBlendFunc() which will use coverage*color as the src color.
607 */
608 kCoverageDrawing_StateBit = 0x10,
joshualitt7a6184f2014-10-29 18:29:27 -0700609 kLast_StateBit = kCoverageDrawing_StateBit,
egdaniel89af44a2014-09-26 06:15:04 -0700610 };
611
612 uint32_t getFlagBits() const { return fFlagBits; }
613
614 bool isStateFlagEnabled(uint32_t stateBit) const { return 0 != (stateBit & fFlagBits); }
615
616 bool isClipState() const { return 0 != (fFlagBits & kClip_StateBit); }
617 bool isColorWriteDisabled() const { return 0 != (fFlagBits & kNoColorWrites_StateBit); }
618 bool isCoverageDrawing() const { return 0 != (fFlagBits & kCoverageDrawing_StateBit); }
619
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000620 void resetStateFlags() {
egdaniel3658f382014-09-15 07:01:59 -0700621 if (0 != fFlagBits) {
622 fFlagBits = 0;
egdaniel3658f382014-09-15 07:01:59 -0700623 }
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000624 }
625
626 /**
627 * Enable render state settings.
628 *
bsalomon@google.com1e269b52012-10-15 14:25:31 +0000629 * @param stateBits bitfield of StateBits specifying the states to enable
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000630 */
631 void enableState(uint32_t stateBits) {
egdaniel3658f382014-09-15 07:01:59 -0700632 if (stateBits & ~fFlagBits) {
633 fFlagBits |= stateBits;
egdaniel3658f382014-09-15 07:01:59 -0700634 }
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000635 }
636
637 /**
638 * Disable render state settings.
639 *
bsalomon@google.com1e269b52012-10-15 14:25:31 +0000640 * @param stateBits bitfield of StateBits specifying the states to disable
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000641 */
642 void disableState(uint32_t stateBits) {
egdaniel3658f382014-09-15 07:01:59 -0700643 if (stateBits & fFlagBits) {
644 fFlagBits &= ~(stateBits);
egdaniel3658f382014-09-15 07:01:59 -0700645 }
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000646 }
647
bsalomon@google.comd5d69ff2012-10-04 19:42:00 +0000648 /**
649 * Enable or disable stateBits based on a boolean.
650 *
bsalomon@google.com1e269b52012-10-15 14:25:31 +0000651 * @param stateBits bitfield of StateBits to enable or disable
bsalomon@google.comd5d69ff2012-10-04 19:42:00 +0000652 * @param enable if true enable stateBits, otherwise disable
653 */
654 void setState(uint32_t stateBits, bool enable) {
655 if (enable) {
656 this->enableState(stateBits);
657 } else {
658 this->disableState(stateBits);
659 }
660 }
661
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000662 /// @}
663
664 ///////////////////////////////////////////////////////////////////////////
665 /// @name Face Culling
666 ////
667
egdaniel89af44a2014-09-26 06:15:04 -0700668 enum DrawFace {
669 kInvalid_DrawFace = -1,
670
671 kBoth_DrawFace,
672 kCCW_DrawFace,
673 kCW_DrawFace,
674 };
675
676 /**
677 * Gets whether the target is drawing clockwise, counterclockwise,
678 * or both faces.
679 * @return the current draw face(s).
680 */
681 DrawFace getDrawFace() const { return fDrawFace; }
682
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000683 /**
684 * Controls whether clockwise, counterclockwise, or both faces are drawn.
685 * @param face the face(s) to draw.
686 */
687 void setDrawFace(DrawFace face) {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000688 SkASSERT(kInvalid_DrawFace != face);
bsalomon2ed5ef82014-07-07 08:44:05 -0700689 fDrawFace = face;
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000690 }
691
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000692 /// @}
693
694 ///////////////////////////////////////////////////////////////////////////
bsalomon62c447d2014-08-08 08:08:50 -0700695 /// @name Hints
696 /// Hints that when provided can enable optimizations.
697 ////
698
joshualitt65171342014-10-09 07:25:36 -0700699 enum Hints {
700 kVertexColorsAreOpaque_Hint = 0x1,
701 kLast_Hint = kVertexColorsAreOpaque_Hint
702 };
egdaniel89af44a2014-09-26 06:15:04 -0700703
bsalomon62c447d2014-08-08 08:08:50 -0700704 void setHint(Hints hint, bool value) { fHints = value ? (fHints | hint) : (fHints & ~hint); }
705
egdaniel89af44a2014-09-26 06:15:04 -0700706 bool vertexColorsAreOpaque() const { return kVertexColorsAreOpaque_Hint & fHints; }
707
bsalomon62c447d2014-08-08 08:08:50 -0700708 /// @}
709
710 ///////////////////////////////////////////////////////////////////////////
tomhudson@google.com62b09682011-11-09 16:39:17 +0000711
bsalomon838f62d2014-08-05 07:15:57 -0700712 /** Return type for CombineIfPossible. */
713 enum CombinedState {
714 /** The GrDrawStates cannot be combined. */
715 kIncompatible_CombinedState,
716 /** Either draw state can be used in place of the other. */
717 kAOrB_CombinedState,
718 /** Use the first draw state. */
719 kA_CombinedState,
720 /** Use the second draw state. */
721 kB_CombinedState,
722 };
723
724 /** This function determines whether the GrDrawStates used for two draws can be combined into
725 a single GrDrawState. This is used to avoid storing redundant GrDrawStates and to determine
726 if draws can be batched. The return value indicates whether combining is possible and, if
727 so, which of the two inputs should be used. */
bsalomon62c447d2014-08-08 08:08:50 -0700728 static CombinedState CombineIfPossible(const GrDrawState& a, const GrDrawState& b,
729 const GrDrawTargetCaps& caps);
bsalomon72336ed2014-08-05 07:35:56 -0700730
bsalomon8f727332014-08-05 07:50:06 -0700731 GrDrawState& operator= (const GrDrawState& that);
bsalomon@google.com3d0835b2011-12-08 16:12:03 +0000732
733private:
egdaniel89af44a2014-09-26 06:15:04 -0700734 /**
735 * Converts refs on GrGpuResources owned directly or indirectly by this GrDrawState into
736 * pending reads and writes. This should be called when a GrDrawState is recorded into
737 * a GrDrawTarget for later execution. Subclasses of GrDrawState may add setters. However,
738 * once this call has been made the GrDrawState is immutable. It is also no longer copyable.
739 * In the future this conversion will automatically happen when converting a GrDrawState into
740 * an optimized draw state.
741 */
742 void convertToPendingExec();
743
744 friend class GrDrawTarget;
745
746 bool isEqual(const GrDrawState& that) const;
747
748 /**
749 * Optimizations for blending / coverage to that can be applied based on the current state.
750 */
751 enum BlendOptFlags {
752 /**
753 * No optimization
754 */
755 kNone_BlendOpt = 0,
756 /**
757 * Don't draw at all
758 */
759 kSkipDraw_BlendOptFlag = 0x1,
760 /**
761 * The coverage value does not have to be computed separately from alpha, the the output
762 * color can be the modulation of the two.
763 */
764 kCoverageAsAlpha_BlendOptFlag = 0x2,
765 /**
766 * Instead of emitting a src color, emit coverage in the alpha channel and r,g,b are
767 * "don't cares".
768 */
769 kEmitCoverage_BlendOptFlag = 0x4,
770 /**
771 * Emit transparent black instead of the src color, no need to compute coverage.
772 */
773 kEmitTransBlack_BlendOptFlag = 0x8,
774 };
775 GR_DECL_BITFIELD_OPS_FRIENDS(BlendOptFlags);
776
777 /**
778 * Determines what optimizations can be applied based on the blend. The coefficients may have
779 * to be tweaked in order for the optimization to work. srcCoeff and dstCoeff are optional
780 * params that receive the tweaked coefficients. Normally the function looks at the current
781 * state to see if coverage is enabled. By setting forceCoverage the caller can speculatively
782 * determine the blend optimizations that would be used if there was partial pixel coverage.
783 *
784 * Subclasses of GrDrawTarget that actually draw (as opposed to those that just buffer for
785 * playback) must call this function and respect the flags that replace the output color.
786 *
787 * If the cached BlendOptFlags does not have the invalidate bit set, then getBlendOpts will
788 * simply returned the cached flags and coefficients. Otherwise it will calculate the values.
789 */
790 BlendOptFlags getBlendOpts(bool forceCoverage = false,
791 GrBlendCoeff* srcCoeff = NULL,
792 GrBlendCoeff* dstCoeff = NULL) const;
793
794 /**
795 * Determines whether src alpha is guaranteed to be one for all src pixels
796 */
797 bool srcAlphaWillBeOne() const;
798
bsalomon8f727332014-08-05 07:50:06 -0700799 void onReset(const SkMatrix* initialViewMatrix);
bsalomon@google.com137f1342013-05-29 21:27:53 +0000800
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000801 // Some of the auto restore objects assume that no effects are removed during their lifetime.
802 // This is used to assert that this condition holds.
commit-bot@chromium.org1acc3d72013-09-06 23:13:05 +0000803 SkDEBUGCODE(int fBlockEffectRemovalCnt;)
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000804
egdaniel7b3d5ee2014-08-28 05:41:14 -0700805 void internalSetVertexAttribs(const GrVertexAttrib attribs[], int count, size_t stride);
robertphillips@google.com42903302013-04-20 12:26:07 +0000806
egdaniel89af44a2014-09-26 06:15:04 -0700807 typedef GrTGpuResourceRef<GrRenderTarget> ProgramRenderTarget;
808 // These fields are roughly sorted by decreasing likelihood of being different in op==
809 ProgramRenderTarget fRenderTarget;
810 GrColor fColor;
811 SkMatrix fViewMatrix;
812 GrColor fBlendConstant;
813 uint32_t fFlagBits;
814 const GrVertexAttrib* fVAPtr;
815 int fVACount;
816 size_t fVAStride;
817 GrStencilSettings fStencilSettings;
818 uint8_t fCoverage;
819 DrawFace fDrawFace;
820 GrBlendCoeff fSrcBlend;
821 GrBlendCoeff fDstBlend;
822
joshualitta5305a12014-10-10 17:47:00 -0700823 typedef SkSTArray<4, GrFragmentStage> FragmentStageArray;
824 typedef GrProgramElementRef<const GrGeometryProcessor> ProgramGeometryProcessor;
825 ProgramGeometryProcessor fGeometryProcessor;
826 FragmentStageArray fColorStages;
827 FragmentStageArray fCoverageStages;
egdaniel89af44a2014-09-26 06:15:04 -0700828
829 uint32_t fHints;
830
831 // This is simply a different representation of info in fVertexAttribs and thus does
832 // not need to be compared in op==.
833 int fFixedFunctionVertexAttribIndices[kGrFixedFunctionVertexAttribBindingCnt];
834
egdanielb109ac22014-10-07 06:45:44 -0700835 friend class GrOptDrawState;
836
egdaniel89af44a2014-09-26 06:15:04 -0700837 typedef SkRefCnt INHERITED;
tomhudson@google.com93813632011-10-27 20:21:16 +0000838};
839
egdanielb109ac22014-10-07 06:45:44 -0700840GR_MAKE_BITFIELD_OPS(GrDrawState::BlendOptFlags);
egdaniel89af44a2014-09-26 06:15:04 -0700841
tomhudson@google.com93813632011-10-27 20:21:16 +0000842#endif