blob: 5cfc6f489518f4da9f52038031ba306172648413 [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.com19628322011-02-03 21:30:17 +0000246 #if GR_DEBUG
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000247 GrVertexLayout posAsTex = tcMask | StagePosAsTexCoordVertexLayoutBit(s2);
bsalomon@google.com19628322011-02-03 21:30:17 +0000248 #endif
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000249 GrAssert(0 == VertexStageCoordOffset(s2, posAsTex));
250 GrAssert(VertexUsesStage(s2, posAsTex));
251 GrAssert(2*sizeof(GrPoint) == VertexSize(posAsTex));
252 GrAssert(-1 == VertexTexCoordsForStage(s2, posAsTex));
253 }
bsalomon@google.com19628322011-02-03 21:30:17 +0000254 #if GR_DEBUG
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000255 GrVertexLayout withColor = tcMask | kColor_VertexLayoutBit;
bsalomon@google.com19628322011-02-03 21:30:17 +0000256 #endif
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000257 GrAssert(2*sizeof(GrPoint) == VertexColorOffset(withColor));
258 GrAssert(2*sizeof(GrPoint) + sizeof(GrColor) == VertexSize(withColor));
259 }
260 GrAssert(tex_coord_idx_mask(t) == tcMask);
261 GrAssert(check_layout(tcMask));
bsalomon@google.com5782d712011-01-21 21:03:59 +0000262
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000263 int stageOffsets[kNumStages];
264 int colorOffset;
265 int size;
266 size = VertexSizeAndOffsetsByStage(tcMask, stageOffsets, &colorOffset);
267 GrAssert(2*sizeof(GrPoint) == size);
268 GrAssert(-1 == colorOffset);
269 for (int s = 0; s < kNumStages; ++s) {
270 GrAssert(VertexUsesStage(s, tcMask));
271 GrAssert(sizeof(GrPoint) == stageOffsets[s]);
272 GrAssert(sizeof(GrPoint) == VertexStageCoordOffset(s, tcMask));
273 }
274 }
275 }
reed@google.comac10a2d2010-12-22 21:39:39 +0000276}
277
278////////////////////////////////////////////////////////////////////////////////
279
280GrDrawTarget::GrDrawTarget() {
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000281#if GR_DEBUG
282 VertexLayoutUnitTest();
283#endif
reed@google.comac10a2d2010-12-22 21:39:39 +0000284 fReservedGeometry.fLocked = false;
285#if GR_DEBUG
286 fReservedGeometry.fVertexCount = ~0;
287 fReservedGeometry.fIndexCount = ~0;
288#endif
289 fGeometrySrc.fVertexSrc = kReserved_GeometrySrcType;
290 fGeometrySrc.fIndexSrc = kReserved_GeometrySrcType;
291}
292
293void GrDrawTarget::setClip(const GrClip& clip) {
294 clipWillChange(clip);
295 fClip = clip;
296}
297
298const GrClip& GrDrawTarget::getClip() const {
299 return fClip;
300}
301
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000302void GrDrawTarget::setTexture(int stage, GrTexture* tex) {
303 GrAssert(stage >= 0 && stage < kNumStages);
304 fCurrDrawState.fTextures[stage] = tex;
reed@google.comac10a2d2010-12-22 21:39:39 +0000305}
306
bsalomon@google.com5782d712011-01-21 21:03:59 +0000307const GrTexture* GrDrawTarget::getTexture(int stage) const {
308 GrAssert(stage >= 0 && stage < kNumStages);
309 return fCurrDrawState.fTextures[stage];
310}
311
312GrTexture* GrDrawTarget::getTexture(int stage) {
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000313 GrAssert(stage >= 0 && stage < kNumStages);
314 return fCurrDrawState.fTextures[stage];
reed@google.comac10a2d2010-12-22 21:39:39 +0000315}
316
317void GrDrawTarget::setRenderTarget(GrRenderTarget* target) {
318 fCurrDrawState.fRenderTarget = target;
319}
320
bsalomon@google.com5782d712011-01-21 21:03:59 +0000321const GrRenderTarget* GrDrawTarget::getRenderTarget() const {
322 return fCurrDrawState.fRenderTarget;
323}
324
325GrRenderTarget* GrDrawTarget::getRenderTarget() {
reed@google.comac10a2d2010-12-22 21:39:39 +0000326 return fCurrDrawState.fRenderTarget;
327}
328
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000329void GrDrawTarget::setViewMatrix(const GrMatrix& m) {
330 fCurrDrawState.fViewMatrix = m;
reed@google.comac10a2d2010-12-22 21:39:39 +0000331}
332
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000333void GrDrawTarget::concatViewMatrix(const GrMatrix& matrix) {
334 fCurrDrawState.fViewMatrix.preConcat(matrix);
335}
336
bsalomon@google.com5782d712011-01-21 21:03:59 +0000337const GrMatrix& GrDrawTarget::getViewMatrix() const {
338 return fCurrDrawState.fViewMatrix;
reed@google.comac10a2d2010-12-22 21:39:39 +0000339}
340
341bool GrDrawTarget::getViewInverse(GrMatrix* matrix) const {
bsalomon@google.com5782d712011-01-21 21:03:59 +0000342 // Mike: Can we cache this somewhere?
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000343 // Brian: Sure, do we use it often?
reed@google.comac10a2d2010-12-22 21:39:39 +0000344
345 GrMatrix inverse;
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000346 if (fCurrDrawState.fViewMatrix.invert(&inverse)) {
reed@google.comac10a2d2010-12-22 21:39:39 +0000347 if (matrix) {
348 *matrix = inverse;
349 }
350 return true;
351 }
352 return false;
353}
354
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000355void GrDrawTarget::setSamplerState(int stage, const GrSamplerState& state) {
356 GrAssert(stage >= 0 && stage < kNumStages);
357 fCurrDrawState.fSamplerStates[stage] = state;
358}
359
360void GrDrawTarget::setTextureMatrix(int stage, const GrMatrix& m) {
361 GrAssert(stage >= 0 && stage < kNumStages);
362 fCurrDrawState.fTextureMatrices[stage] = m;
reed@google.comac10a2d2010-12-22 21:39:39 +0000363}
364
bsalomon@google.com6f7fbc92011-02-01 19:12:40 +0000365void GrDrawTarget::concatTextureMatrix(int stage, const GrMatrix& m) {
366 GrAssert(stage >= 0 && stage < kNumStages);
367 fCurrDrawState.fTextureMatrices[stage].preConcat(m);
368}
369
370const GrMatrix& GrDrawTarget::getTextureMatrix(int stage) const {
371 GrAssert(stage >= 0 && stage < kNumStages);
372 return fCurrDrawState.fTextureMatrices[stage];
373}
374
reed@google.comac10a2d2010-12-22 21:39:39 +0000375void GrDrawTarget::setStencilPass(StencilPass pass) {
376 fCurrDrawState.fStencilPass = pass;
377}
378
379void GrDrawTarget::setReverseFill(bool reverse) {
380 fCurrDrawState.fReverseFill = reverse;
381}
382
383void GrDrawTarget::enableState(uint32_t bits) {
384 fCurrDrawState.fFlagBits |= bits;
385}
386
387void GrDrawTarget::disableState(uint32_t bits) {
388 fCurrDrawState.fFlagBits &= ~(bits);
389}
390
reed@google.comac10a2d2010-12-22 21:39:39 +0000391void GrDrawTarget::setBlendFunc(BlendCoeff srcCoef,
392 BlendCoeff dstCoef) {
393 fCurrDrawState.fSrcBlend = srcCoef;
394 fCurrDrawState.fDstBlend = dstCoef;
395}
396
397void GrDrawTarget::setColor(GrColor c) {
398 fCurrDrawState.fColor = c;
399}
400
401void GrDrawTarget::setAlpha(uint8_t a) {
402 this->setColor((a << 24) | (a << 16) | (a << 8) | a);
403}
404
405void GrDrawTarget::saveCurrentDrawState(SavedDrawState* state) const {
406 state->fState = fCurrDrawState;
407}
408
409void GrDrawTarget::restoreDrawState(const SavedDrawState& state) {
410 fCurrDrawState = state.fState;
411}
412
413void GrDrawTarget::copyDrawState(const GrDrawTarget& srcTarget) {
414 fCurrDrawState = srcTarget.fCurrDrawState;
415}
416
417
418bool GrDrawTarget::reserveAndLockGeometry(GrVertexLayout vertexLayout,
419 uint32_t vertexCount,
420 uint32_t indexCount,
421 void** vertices,
422 void** indices) {
423 GrAssert(!fReservedGeometry.fLocked);
424 fReservedGeometry.fVertexCount = vertexCount;
425 fReservedGeometry.fIndexCount = indexCount;
426
427 fReservedGeometry.fLocked = acquireGeometryHelper(vertexLayout,
428 vertices,
429 indices);
430 if (fReservedGeometry.fLocked) {
431 if (vertexCount) {
432 fGeometrySrc.fVertexSrc = kReserved_GeometrySrcType;
433 fGeometrySrc.fVertexLayout = vertexLayout;
434 }
435 if (indexCount) {
436 fGeometrySrc.fIndexSrc = kReserved_GeometrySrcType;
437 }
438 }
439 return fReservedGeometry.fLocked;
440}
441
442bool GrDrawTarget::geometryHints(GrVertexLayout vertexLayout,
443 int32_t* vertexCount,
444 int32_t* indexCount) const {
445 GrAssert(!fReservedGeometry.fLocked);
446 if (NULL != vertexCount) {
447 *vertexCount = -1;
448 }
449 if (NULL != indexCount) {
450 *indexCount = -1;
451 }
452 return false;
453}
454
455void GrDrawTarget::releaseReservedGeometry() {
456 GrAssert(fReservedGeometry.fLocked);
457 releaseGeometryHelper();
458 fReservedGeometry.fLocked = false;
459}
460
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000461void GrDrawTarget::setVertexSourceToArray(GrVertexLayout vertexLayout,
462 const void* vertexArray,
463 int vertexCount) {
464 fGeometrySrc.fVertexSrc = kArray_GeometrySrcType;
reed@google.comac10a2d2010-12-22 21:39:39 +0000465 fGeometrySrc.fVertexLayout = vertexLayout;
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000466 setVertexSourceToArrayHelper(vertexArray, vertexCount);
reed@google.comac10a2d2010-12-22 21:39:39 +0000467}
468
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000469void GrDrawTarget::setIndexSourceToArray(const void* indexArray,
470 int indexCount) {
471 fGeometrySrc.fIndexSrc = kArray_GeometrySrcType;
472 setIndexSourceToArrayHelper(indexArray, indexCount);
reed@google.comac10a2d2010-12-22 21:39:39 +0000473}
474
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000475void GrDrawTarget::setVertexSourceToBuffer(GrVertexLayout vertexLayout,
476 const GrVertexBuffer* buffer) {
reed@google.comac10a2d2010-12-22 21:39:39 +0000477 fGeometrySrc.fVertexSrc = kBuffer_GeometrySrcType;
478 fGeometrySrc.fVertexBuffer = buffer;
479 fGeometrySrc.fVertexLayout = vertexLayout;
480}
481
482void GrDrawTarget::setIndexSourceToBuffer(const GrIndexBuffer* buffer) {
483 fGeometrySrc.fIndexSrc = kBuffer_GeometrySrcType;
484 fGeometrySrc.fIndexBuffer = buffer;
485}
486
487////////////////////////////////////////////////////////////////////////////////
488
489GrDrawTarget::AutoStateRestore::AutoStateRestore(GrDrawTarget* target) {
490 fDrawTarget = target;
bsalomon@google.com7d34d2e2011-01-24 17:41:47 +0000491 if (NULL != fDrawTarget) {
492 fDrawTarget->saveCurrentDrawState(&fDrawState);
493 }
reed@google.comac10a2d2010-12-22 21:39:39 +0000494}
495
496GrDrawTarget::AutoStateRestore::~AutoStateRestore() {
bsalomon@google.com7d34d2e2011-01-24 17:41:47 +0000497 if (NULL != fDrawTarget) {
498 fDrawTarget->restoreDrawState(fDrawState);
499 }
reed@google.comac10a2d2010-12-22 21:39:39 +0000500}
bsalomon@google.com7d34d2e2011-01-24 17:41:47 +0000501