blob: 0101ecd685bdca01c5e8eeb6b3dd1eb84d962c0a [file] [log] [blame]
reed@google.comac10a2d2010-12-22 21:39:39 +00001/*
2 Copyright 2010 Google Inc.
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15 */
16
17
18#include "GrDrawTarget.h"
19#include "GrGpuVertex.h"
20
bsalomon@google.com8531c1c2011-01-13 19:52:45 +000021// recursive helper for creating mask with all the tex coord bits set for
22// one stage
23template <int N>
24static int stage_mask_recur(int stage) {
bsalomon@google.com5782d712011-01-21 21:03:59 +000025 return GrDrawTarget::StageTexCoordVertexLayoutBit(stage, N) |
bsalomon@google.com8531c1c2011-01-13 19:52:45 +000026 stage_mask_recur<N+1>(stage);
27}
reed@google.comd728f6e2011-01-13 20:02:47 +000028template<> // linux build doesn't like static on specializations
29int stage_mask_recur<GrDrawTarget::kNumStages>(int) { return 0; }
reed@google.comac10a2d2010-12-22 21:39:39 +000030
bsalomon@google.com8531c1c2011-01-13 19:52:45 +000031// mask of all tex coord indices for one stage
32static int stage_tex_coord_mask(int stage) {
33 return stage_mask_recur<0>(stage);
reed@google.comac10a2d2010-12-22 21:39:39 +000034}
35
bsalomon@google.com8531c1c2011-01-13 19:52:45 +000036// mask of all bits relevant to one stage
37static int stage_mask(int stage) {
bsalomon@google.com5782d712011-01-21 21:03:59 +000038 return stage_tex_coord_mask(stage) |
bsalomon@google.com8531c1c2011-01-13 19:52:45 +000039 GrDrawTarget::StagePosAsTexCoordVertexLayoutBit(stage);
40}
41
42// recursive helper for creating mask of with all bits set relevant to one
43// texture coordinate index
44template <int N>
45static int tex_coord_mask_recur(int texCoordIdx) {
bsalomon@google.com5782d712011-01-21 21:03:59 +000046 return GrDrawTarget::StageTexCoordVertexLayoutBit(N, texCoordIdx) |
bsalomon@google.com8531c1c2011-01-13 19:52:45 +000047 tex_coord_mask_recur<N+1>(texCoordIdx);
48}
reed@google.comd728f6e2011-01-13 20:02:47 +000049template<> // linux build doesn't like static on specializations
50int tex_coord_mask_recur<GrDrawTarget::kMaxTexCoords>(int) { return 0; }
bsalomon@google.com8531c1c2011-01-13 19:52:45 +000051
52// mask of all bits relevant to one texture coordinate index
53static int tex_coord_idx_mask(int texCoordIdx) {
54 return tex_coord_mask_recur<0>(texCoordIdx);
55}
56
57bool check_layout(GrVertexLayout layout) {
58 // can only have 1 or 0 bits set for each stage.
59 for (int s = 0; s < GrDrawTarget::kNumStages; ++s) {
60 int stageBits = layout & stage_mask(s);
61 if (stageBits && !GrIsPow2(stageBits)) {
62 return false;
63 }
64 }
65 return true;
66}
67
68size_t GrDrawTarget::VertexSize(GrVertexLayout vertexLayout) {
69 GrAssert(check_layout(vertexLayout));
bsalomon@google.com5782d712011-01-21 21:03:59 +000070
71 size_t vecSize = (vertexLayout & kTextFormat_VertexLayoutBit) ?
bsalomon@google.com8531c1c2011-01-13 19:52:45 +000072 sizeof(GrGpuTextVertex) :
73 sizeof(GrPoint);
74
75 size_t size = vecSize; // position
76 for (int t = 0; t < kMaxTexCoords; ++t) {
77 if (tex_coord_idx_mask(t) & vertexLayout) {
78 size += vecSize;
79 }
80 }
81 if (vertexLayout & kColor_VertexLayoutBit) {
82 size += sizeof(GrColor);
83 }
84 return size;
85}
86
87int GrDrawTarget::VertexStageCoordOffset(int stage, GrVertexLayout vertexLayout) {
88 GrAssert(check_layout(vertexLayout));
89 if (StagePosAsTexCoordVertexLayoutBit(stage) & vertexLayout) {
reed@google.comac10a2d2010-12-22 21:39:39 +000090 return 0;
91 }
bsalomon@google.com8531c1c2011-01-13 19:52:45 +000092 int tcIdx = VertexTexCoordsForStage(stage, vertexLayout);
93 if (tcIdx >= 0) {
bsalomon@google.com5782d712011-01-21 21:03:59 +000094
95 int vecSize = (vertexLayout & kTextFormat_VertexLayoutBit) ?
bsalomon@google.com8531c1c2011-01-13 19:52:45 +000096 sizeof(GrGpuTextVertex) :
97 sizeof(GrPoint);
98 int offset = vecSize; // position
99 // figure out how many tex coordinates are present and precede this one.
100 for (int t = 0; t < tcIdx; ++t) {
101 if (tex_coord_idx_mask(t) & vertexLayout) {
102 offset += vecSize;
103 }
104 }
105 return offset;
106 }
107
reed@google.comac10a2d2010-12-22 21:39:39 +0000108 return -1;
109}
110
111int GrDrawTarget::VertexColorOffset(GrVertexLayout vertexLayout) {
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000112 GrAssert(check_layout(vertexLayout));
bsalomon@google.com5782d712011-01-21 21:03:59 +0000113
reed@google.comac10a2d2010-12-22 21:39:39 +0000114 if (vertexLayout & kColor_VertexLayoutBit) {
bsalomon@google.com5782d712011-01-21 21:03:59 +0000115 int vecSize = (vertexLayout & kTextFormat_VertexLayoutBit) ?
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000116 sizeof(GrGpuTextVertex) :
117 sizeof(GrPoint);
118 int offset = vecSize; // position
119 // figure out how many tex coordinates are present and precede this one.
120 for (int t = 0; t < kMaxTexCoords; ++t) {
121 if (tex_coord_idx_mask(t) & vertexLayout) {
122 offset += vecSize;
123 }
reed@google.comac10a2d2010-12-22 21:39:39 +0000124 }
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000125 return offset;
reed@google.comac10a2d2010-12-22 21:39:39 +0000126 }
127 return -1;
128}
129
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000130int GrDrawTarget::VertexSizeAndOffsetsByIdx(GrVertexLayout vertexLayout,
131 int texCoordOffsetsByIdx[kMaxTexCoords],
132 int* colorOffset) {
133 GrAssert(check_layout(vertexLayout));
bsalomon@google.com5782d712011-01-21 21:03:59 +0000134
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000135 GrAssert(NULL != texCoordOffsetsByIdx);
reed@google.comac10a2d2010-12-22 21:39:39 +0000136 GrAssert(NULL != colorOffset);
137
bsalomon@google.com5782d712011-01-21 21:03:59 +0000138 int vecSize = (vertexLayout & kTextFormat_VertexLayoutBit) ?
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000139 sizeof(GrGpuTextVertex) :
140 sizeof(GrPoint);
141 int size = vecSize; // position
bsalomon@google.com5782d712011-01-21 21:03:59 +0000142
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000143 for (int t = 0; t < kMaxTexCoords; ++t) {
144 if (tex_coord_idx_mask(t) & vertexLayout) {
145 texCoordOffsetsByIdx[t] = size;
146 size += vecSize;
reed@google.comac10a2d2010-12-22 21:39:39 +0000147 } else {
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000148 texCoordOffsetsByIdx[t] = -1;
reed@google.comac10a2d2010-12-22 21:39:39 +0000149 }
reed@google.comac10a2d2010-12-22 21:39:39 +0000150 }
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000151 if (kColor_VertexLayoutBit & vertexLayout) {
152 *colorOffset = size;
153 size += sizeof(GrColor);
154 } else {
155 *colorOffset = -1;
156 }
157 return size;
reed@google.comac10a2d2010-12-22 21:39:39 +0000158}
159
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000160int GrDrawTarget::VertexSizeAndOffsetsByStage(GrVertexLayout vertexLayout,
161 int texCoordOffsetsByStage[kNumStages],
162 int* colorOffset) {
163 GrAssert(check_layout(vertexLayout));
164
165 GrAssert(NULL != texCoordOffsetsByStage);
166 GrAssert(NULL != colorOffset);
bsalomon@google.com5782d712011-01-21 21:03:59 +0000167
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000168 int texCoordOffsetsByIdx[kMaxTexCoords];
bsalomon@google.com5782d712011-01-21 21:03:59 +0000169 int size = VertexSizeAndOffsetsByIdx(vertexLayout,
170 texCoordOffsetsByIdx,
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000171 colorOffset);
172 for (int s = 0; s < kNumStages; ++s) {
173 int tcIdx;
174 if (StagePosAsTexCoordVertexLayoutBit(s) & vertexLayout) {
175 texCoordOffsetsByStage[s] = 0;
176 } else if ((tcIdx = VertexTexCoordsForStage(s, vertexLayout)) >= 0) {
177 texCoordOffsetsByStage[s] = texCoordOffsetsByIdx[tcIdx];
178 } else {
179 texCoordOffsetsByStage[s] = -1;
180 }
181 }
bsalomon@google.com5782d712011-01-21 21:03:59 +0000182 return size;
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000183}
184
185bool GrDrawTarget::VertexUsesStage(int stage, GrVertexLayout vertexLayout) {
186 GrAssert(stage < kNumStages);
187 GrAssert(check_layout(vertexLayout));
188 return !!(stage_mask(stage) & vertexLayout);
189}
190
bsalomon@google.com5782d712011-01-21 21:03:59 +0000191bool GrDrawTarget::VertexUsesTexCoordIdx(int coordIndex,
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000192 GrVertexLayout vertexLayout) {
bsalomon@google.com5782d712011-01-21 21:03:59 +0000193 GrAssert(coordIndex < kMaxTexCoords);
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000194 GrAssert(check_layout(vertexLayout));
195 return !!(tex_coord_idx_mask(coordIndex) & vertexLayout);
196}
197
198int GrDrawTarget::VertexTexCoordsForStage(int stage, GrVertexLayout vertexLayout) {
199 GrAssert(stage < kNumStages);
200 GrAssert(check_layout(vertexLayout));
201 int bit = vertexLayout & stage_tex_coord_mask(stage);
202 if (bit) {
203 // figure out which set of texture coordates is used
204 // bits are ordered T0S0, T0S1, T0S2, ..., T1S0, T1S1, ...
205 // and start at bit 0.
206 GR_STATIC_ASSERT(sizeof(GrVertexLayout) <= sizeof(uint32_t));
207 return (32 - Gr_clz(bit) - 1) / kNumStages;
208 }
209 return -1;
210}
211
212void GrDrawTarget::VertexLayoutUnitTest() {
213 // not necessarily exhaustive
214 static bool run;
215 if (!run) {
216 run = true;
217 for (int s = 0; s < kNumStages; ++s) {
218
219 GrAssert(!VertexUsesStage(s, 0));
220 GrAssert(-1 == VertexStageCoordOffset(s, 0));
221 GrVertexLayout stageMask = 0;
222 for (int t = 0; t < kMaxTexCoords; ++t) {
223 stageMask |= StageTexCoordVertexLayoutBit(s,t);
224 }
bsalomon@google.com5782d712011-01-21 21:03:59 +0000225 GrAssert(1 == kMaxTexCoords || !check_layout(stageMask));
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000226 GrAssert(stage_tex_coord_mask(s) == stageMask);
227 stageMask |= StagePosAsTexCoordVertexLayoutBit(s);
228 GrAssert(stage_mask(s) == stageMask);
229 GrAssert(!check_layout(stageMask));
230 }
231 for (int t = 0; t < kMaxTexCoords; ++t) {
232 GrVertexLayout tcMask = 0;
233 GrAssert(!VertexUsesTexCoordIdx(t, 0));
234 for (int s = 0; s < kNumStages; ++s) {
235 tcMask |= StageTexCoordVertexLayoutBit(s,t);
236 GrAssert(VertexUsesStage(s, tcMask));
237 GrAssert(sizeof(GrPoint) == VertexStageCoordOffset(s, tcMask));
238 GrAssert(VertexUsesTexCoordIdx(t, tcMask));
239 GrAssert(2*sizeof(GrPoint) == VertexSize(tcMask));
240 GrAssert(t == VertexTexCoordsForStage(s, tcMask));
241 for (int s2 = s + 1; s2 < kNumStages; ++s2) {
242 GrAssert(-1 == VertexStageCoordOffset(s2, tcMask));
243 GrAssert(!VertexUsesStage(s2, tcMask));
244 GrAssert(-1 == VertexTexCoordsForStage(s2, tcMask));
bsalomon@google.com5782d712011-01-21 21:03:59 +0000245
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000246 GrVertexLayout posAsTex = tcMask | StagePosAsTexCoordVertexLayoutBit(s2);
247 GrAssert(0 == VertexStageCoordOffset(s2, posAsTex));
248 GrAssert(VertexUsesStage(s2, posAsTex));
249 GrAssert(2*sizeof(GrPoint) == VertexSize(posAsTex));
250 GrAssert(-1 == VertexTexCoordsForStage(s2, posAsTex));
251 }
252 GrVertexLayout withColor = tcMask | kColor_VertexLayoutBit;
253 GrAssert(2*sizeof(GrPoint) == VertexColorOffset(withColor));
254 GrAssert(2*sizeof(GrPoint) + sizeof(GrColor) == VertexSize(withColor));
255 }
256 GrAssert(tex_coord_idx_mask(t) == tcMask);
257 GrAssert(check_layout(tcMask));
bsalomon@google.com5782d712011-01-21 21:03:59 +0000258
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000259 int stageOffsets[kNumStages];
260 int colorOffset;
261 int size;
262 size = VertexSizeAndOffsetsByStage(tcMask, stageOffsets, &colorOffset);
263 GrAssert(2*sizeof(GrPoint) == size);
264 GrAssert(-1 == colorOffset);
265 for (int s = 0; s < kNumStages; ++s) {
266 GrAssert(VertexUsesStage(s, tcMask));
267 GrAssert(sizeof(GrPoint) == stageOffsets[s]);
268 GrAssert(sizeof(GrPoint) == VertexStageCoordOffset(s, tcMask));
269 }
270 }
271 }
reed@google.comac10a2d2010-12-22 21:39:39 +0000272}
273
274////////////////////////////////////////////////////////////////////////////////
275
276GrDrawTarget::GrDrawTarget() {
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000277#if GR_DEBUG
278 VertexLayoutUnitTest();
279#endif
reed@google.comac10a2d2010-12-22 21:39:39 +0000280 fReservedGeometry.fLocked = false;
281#if GR_DEBUG
282 fReservedGeometry.fVertexCount = ~0;
283 fReservedGeometry.fIndexCount = ~0;
284#endif
285 fGeometrySrc.fVertexSrc = kReserved_GeometrySrcType;
286 fGeometrySrc.fIndexSrc = kReserved_GeometrySrcType;
287}
288
289void GrDrawTarget::setClip(const GrClip& clip) {
290 clipWillChange(clip);
291 fClip = clip;
292}
293
294const GrClip& GrDrawTarget::getClip() const {
295 return fClip;
296}
297
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000298void GrDrawTarget::setTexture(int stage, GrTexture* tex) {
299 GrAssert(stage >= 0 && stage < kNumStages);
300 fCurrDrawState.fTextures[stage] = tex;
reed@google.comac10a2d2010-12-22 21:39:39 +0000301}
302
bsalomon@google.com5782d712011-01-21 21:03:59 +0000303const GrTexture* GrDrawTarget::getTexture(int stage) const {
304 GrAssert(stage >= 0 && stage < kNumStages);
305 return fCurrDrawState.fTextures[stage];
306}
307
308GrTexture* GrDrawTarget::getTexture(int stage) {
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000309 GrAssert(stage >= 0 && stage < kNumStages);
310 return fCurrDrawState.fTextures[stage];
reed@google.comac10a2d2010-12-22 21:39:39 +0000311}
312
313void GrDrawTarget::setRenderTarget(GrRenderTarget* target) {
314 fCurrDrawState.fRenderTarget = target;
315}
316
bsalomon@google.com5782d712011-01-21 21:03:59 +0000317const GrRenderTarget* GrDrawTarget::getRenderTarget() const {
318 return fCurrDrawState.fRenderTarget;
319}
320
321GrRenderTarget* GrDrawTarget::getRenderTarget() {
reed@google.comac10a2d2010-12-22 21:39:39 +0000322 return fCurrDrawState.fRenderTarget;
323}
324
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000325void GrDrawTarget::setViewMatrix(const GrMatrix& m) {
326 fCurrDrawState.fViewMatrix = m;
reed@google.comac10a2d2010-12-22 21:39:39 +0000327}
328
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000329void GrDrawTarget::concatViewMatrix(const GrMatrix& matrix) {
330 fCurrDrawState.fViewMatrix.preConcat(matrix);
331}
332
bsalomon@google.com5782d712011-01-21 21:03:59 +0000333const GrMatrix& GrDrawTarget::getViewMatrix() const {
334 return fCurrDrawState.fViewMatrix;
reed@google.comac10a2d2010-12-22 21:39:39 +0000335}
336
337bool GrDrawTarget::getViewInverse(GrMatrix* matrix) const {
bsalomon@google.com5782d712011-01-21 21:03:59 +0000338 // Mike: Can we cache this somewhere?
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000339 // Brian: Sure, do we use it often?
reed@google.comac10a2d2010-12-22 21:39:39 +0000340
341 GrMatrix inverse;
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000342 if (fCurrDrawState.fViewMatrix.invert(&inverse)) {
reed@google.comac10a2d2010-12-22 21:39:39 +0000343 if (matrix) {
344 *matrix = inverse;
345 }
346 return true;
347 }
348 return false;
349}
350
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000351void GrDrawTarget::setSamplerState(int stage, const GrSamplerState& state) {
352 GrAssert(stage >= 0 && stage < kNumStages);
353 fCurrDrawState.fSamplerStates[stage] = state;
354}
355
356void GrDrawTarget::setTextureMatrix(int stage, const GrMatrix& m) {
357 GrAssert(stage >= 0 && stage < kNumStages);
358 fCurrDrawState.fTextureMatrices[stage] = m;
reed@google.comac10a2d2010-12-22 21:39:39 +0000359}
360
361void GrDrawTarget::setStencilPass(StencilPass pass) {
362 fCurrDrawState.fStencilPass = pass;
363}
364
365void GrDrawTarget::setReverseFill(bool reverse) {
366 fCurrDrawState.fReverseFill = reverse;
367}
368
369void GrDrawTarget::enableState(uint32_t bits) {
370 fCurrDrawState.fFlagBits |= bits;
371}
372
373void GrDrawTarget::disableState(uint32_t bits) {
374 fCurrDrawState.fFlagBits &= ~(bits);
375}
376
reed@google.comac10a2d2010-12-22 21:39:39 +0000377void GrDrawTarget::setBlendFunc(BlendCoeff srcCoef,
378 BlendCoeff dstCoef) {
379 fCurrDrawState.fSrcBlend = srcCoef;
380 fCurrDrawState.fDstBlend = dstCoef;
381}
382
383void GrDrawTarget::setColor(GrColor c) {
384 fCurrDrawState.fColor = c;
385}
386
387void GrDrawTarget::setAlpha(uint8_t a) {
388 this->setColor((a << 24) | (a << 16) | (a << 8) | a);
389}
390
391void GrDrawTarget::saveCurrentDrawState(SavedDrawState* state) const {
392 state->fState = fCurrDrawState;
393}
394
395void GrDrawTarget::restoreDrawState(const SavedDrawState& state) {
396 fCurrDrawState = state.fState;
397}
398
399void GrDrawTarget::copyDrawState(const GrDrawTarget& srcTarget) {
400 fCurrDrawState = srcTarget.fCurrDrawState;
401}
402
403
404bool GrDrawTarget::reserveAndLockGeometry(GrVertexLayout vertexLayout,
405 uint32_t vertexCount,
406 uint32_t indexCount,
407 void** vertices,
408 void** indices) {
409 GrAssert(!fReservedGeometry.fLocked);
410 fReservedGeometry.fVertexCount = vertexCount;
411 fReservedGeometry.fIndexCount = indexCount;
412
413 fReservedGeometry.fLocked = acquireGeometryHelper(vertexLayout,
414 vertices,
415 indices);
416 if (fReservedGeometry.fLocked) {
417 if (vertexCount) {
418 fGeometrySrc.fVertexSrc = kReserved_GeometrySrcType;
419 fGeometrySrc.fVertexLayout = vertexLayout;
420 }
421 if (indexCount) {
422 fGeometrySrc.fIndexSrc = kReserved_GeometrySrcType;
423 }
424 }
425 return fReservedGeometry.fLocked;
426}
427
428bool GrDrawTarget::geometryHints(GrVertexLayout vertexLayout,
429 int32_t* vertexCount,
430 int32_t* indexCount) const {
431 GrAssert(!fReservedGeometry.fLocked);
432 if (NULL != vertexCount) {
433 *vertexCount = -1;
434 }
435 if (NULL != indexCount) {
436 *indexCount = -1;
437 }
438 return false;
439}
440
441void GrDrawTarget::releaseReservedGeometry() {
442 GrAssert(fReservedGeometry.fLocked);
443 releaseGeometryHelper();
444 fReservedGeometry.fLocked = false;
445}
446
447void GrDrawTarget::setVertexSourceToArray(const void* array,
448 GrVertexLayout vertexLayout) {
449 fGeometrySrc.fVertexSrc = kArray_GeometrySrcType;
450 fGeometrySrc.fVertexArray = array;
451 fGeometrySrc.fVertexLayout = vertexLayout;
452}
453
454void GrDrawTarget::setIndexSourceToArray(const void* array) {
455 fGeometrySrc.fIndexSrc = kArray_GeometrySrcType;
456 fGeometrySrc.fIndexArray = array;
457}
458
459void GrDrawTarget::setVertexSourceToBuffer(const GrVertexBuffer* buffer,
460 GrVertexLayout vertexLayout) {
461 fGeometrySrc.fVertexSrc = kBuffer_GeometrySrcType;
462 fGeometrySrc.fVertexBuffer = buffer;
463 fGeometrySrc.fVertexLayout = vertexLayout;
464}
465
466void GrDrawTarget::setIndexSourceToBuffer(const GrIndexBuffer* buffer) {
467 fGeometrySrc.fIndexSrc = kBuffer_GeometrySrcType;
468 fGeometrySrc.fIndexBuffer = buffer;
469}
470
471////////////////////////////////////////////////////////////////////////////////
472
473GrDrawTarget::AutoStateRestore::AutoStateRestore(GrDrawTarget* target) {
474 fDrawTarget = target;
bsalomon@google.com7d34d2e2011-01-24 17:41:47 +0000475 if (NULL != fDrawTarget) {
476 fDrawTarget->saveCurrentDrawState(&fDrawState);
477 }
reed@google.comac10a2d2010-12-22 21:39:39 +0000478}
479
480GrDrawTarget::AutoStateRestore::~AutoStateRestore() {
bsalomon@google.com7d34d2e2011-01-24 17:41:47 +0000481 if (NULL != fDrawTarget) {
482 fDrawTarget->restoreDrawState(fDrawState);
483 }
reed@google.comac10a2d2010-12-22 21:39:39 +0000484}
bsalomon@google.com7d34d2e2011-01-24 17:41:47 +0000485