OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2010 Google Inc. | 3 * Copyright 2010 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 | 9 |
10 | 10 |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 *indices = NULL; | 188 *indices = NULL; |
189 } | 189 } |
190 return acquired; | 190 return acquired; |
191 | 191 |
192 } | 192 } |
193 | 193 |
194 bool GrDrawTarget::reserveVertexAndIndexSpace(int vertexCount, | 194 bool GrDrawTarget::reserveVertexAndIndexSpace(int vertexCount, |
195 int indexCount, | 195 int indexCount, |
196 void** vertices, | 196 void** vertices, |
197 void** indices) { | 197 void** indices) { |
198 size_t vertexStride = this->drawState()->getVertexStride(); | 198 size_t vertexSize = this->drawState()->getVertexSize(); |
199 this->willReserveVertexAndIndexSpace(vertexCount, indexCount); | 199 this->willReserveVertexAndIndexSpace(vertexCount, indexCount); |
200 if (vertexCount) { | 200 if (vertexCount) { |
201 if (!this->reserveVertexSpace(vertexStride, vertexCount, vertices)) { | 201 if (!this->reserveVertexSpace(vertexSize, vertexCount, vertices)) { |
202 if (indexCount) { | 202 if (indexCount) { |
203 this->resetIndexSource(); | 203 this->resetIndexSource(); |
204 } | 204 } |
205 return false; | 205 return false; |
206 } | 206 } |
207 } | 207 } |
208 if (indexCount) { | 208 if (indexCount) { |
209 if (!this->reserveIndexSpace(indexCount, indices)) { | 209 if (!this->reserveIndexSpace(indexCount, indices)) { |
210 if (vertexCount) { | 210 if (vertexCount) { |
211 this->resetVertexSource(); | 211 this->resetVertexSource(); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
271 SkFAIL("Unknown Index Source Type."); | 271 SkFAIL("Unknown Index Source Type."); |
272 break; | 272 break; |
273 } | 273 } |
274 } | 274 } |
275 | 275 |
276 void GrDrawTarget::setVertexSourceToArray(const void* vertexArray, | 276 void GrDrawTarget::setVertexSourceToArray(const void* vertexArray, |
277 int vertexCount) { | 277 int vertexCount) { |
278 this->releasePreviousVertexSource(); | 278 this->releasePreviousVertexSource(); |
279 GeometrySrcState& geoSrc = fGeoSrcStateStack.back(); | 279 GeometrySrcState& geoSrc = fGeoSrcStateStack.back(); |
280 geoSrc.fVertexSrc = kArray_GeometrySrcType; | 280 geoSrc.fVertexSrc = kArray_GeometrySrcType; |
281 geoSrc.fVertexSize = this->drawState()->getVertexStride(); | 281 geoSrc.fVertexSize = this->drawState()->getVertexSize(); |
282 geoSrc.fVertexCount = vertexCount; | 282 geoSrc.fVertexCount = vertexCount; |
283 this->onSetVertexSourceToArray(vertexArray, vertexCount); | 283 this->onSetVertexSourceToArray(vertexArray, vertexCount); |
284 } | 284 } |
285 | 285 |
286 void GrDrawTarget::setIndexSourceToArray(const void* indexArray, | 286 void GrDrawTarget::setIndexSourceToArray(const void* indexArray, |
287 int indexCount) { | 287 int indexCount) { |
288 this->releasePreviousIndexSource(); | 288 this->releasePreviousIndexSource(); |
289 GeometrySrcState& geoSrc = fGeoSrcStateStack.back(); | 289 GeometrySrcState& geoSrc = fGeoSrcStateStack.back(); |
290 geoSrc.fIndexSrc = kArray_GeometrySrcType; | 290 geoSrc.fIndexSrc = kArray_GeometrySrcType; |
291 geoSrc.fIndexCount = indexCount; | 291 geoSrc.fIndexCount = indexCount; |
292 this->onSetIndexSourceToArray(indexArray, indexCount); | 292 this->onSetIndexSourceToArray(indexArray, indexCount); |
293 } | 293 } |
294 | 294 |
295 void GrDrawTarget::setVertexSourceToBuffer(const GrVertexBuffer* buffer) { | 295 void GrDrawTarget::setVertexSourceToBuffer(const GrVertexBuffer* buffer) { |
296 this->releasePreviousVertexSource(); | 296 this->releasePreviousVertexSource(); |
297 GeometrySrcState& geoSrc = fGeoSrcStateStack.back(); | 297 GeometrySrcState& geoSrc = fGeoSrcStateStack.back(); |
298 geoSrc.fVertexSrc = kBuffer_GeometrySrcType; | 298 geoSrc.fVertexSrc = kBuffer_GeometrySrcType; |
299 geoSrc.fVertexBuffer = buffer; | 299 geoSrc.fVertexBuffer = buffer; |
300 buffer->ref(); | 300 buffer->ref(); |
301 geoSrc.fVertexSize = this->drawState()->getVertexStride(); | 301 geoSrc.fVertexSize = this->drawState()->getVertexSize(); |
302 } | 302 } |
303 | 303 |
304 void GrDrawTarget::setIndexSourceToBuffer(const GrIndexBuffer* buffer) { | 304 void GrDrawTarget::setIndexSourceToBuffer(const GrIndexBuffer* buffer) { |
305 this->releasePreviousIndexSource(); | 305 this->releasePreviousIndexSource(); |
306 GeometrySrcState& geoSrc = fGeoSrcStateStack.back(); | 306 GeometrySrcState& geoSrc = fGeoSrcStateStack.back(); |
307 geoSrc.fIndexSrc = kBuffer_GeometrySrcType; | 307 geoSrc.fIndexSrc = kBuffer_GeometrySrcType; |
308 geoSrc.fIndexBuffer = buffer; | 308 geoSrc.fIndexBuffer = buffer; |
309 buffer->ref(); | 309 buffer->ref(); |
310 } | 310 } |
311 | 311 |
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
666 namespace { | 666 namespace { |
667 | 667 |
668 // position + (optional) texture coord | 668 // position + (optional) texture coord |
669 extern const GrVertexAttrib gBWRectPosUVAttribs[] = { | 669 extern const GrVertexAttrib gBWRectPosUVAttribs[] = { |
670 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding
}, | 670 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding
}, |
671 {kVec2f_GrVertexAttribType, sizeof(SkPoint), kLocalCoord_GrVertexAttribBindi
ng} | 671 {kVec2f_GrVertexAttribType, sizeof(SkPoint), kLocalCoord_GrVertexAttribBindi
ng} |
672 }; | 672 }; |
673 | 673 |
674 void set_vertex_attributes(GrDrawState* drawState, bool hasUVs) { | 674 void set_vertex_attributes(GrDrawState* drawState, bool hasUVs) { |
675 if (hasUVs) { | 675 if (hasUVs) { |
676 drawState->setVertexAttribs<gBWRectPosUVAttribs>(2, 2 * sizeof(SkPoint))
; | 676 drawState->setVertexAttribs<gBWRectPosUVAttribs>(2); |
677 } else { | 677 } else { |
678 drawState->setVertexAttribs<gBWRectPosUVAttribs>(1, sizeof(SkPoint)); | 678 drawState->setVertexAttribs<gBWRectPosUVAttribs>(1); |
679 } | 679 } |
680 } | 680 } |
681 | 681 |
682 }; | 682 }; |
683 | 683 |
684 void GrDrawTarget::onDrawRect(const SkRect& rect, | 684 void GrDrawTarget::onDrawRect(const SkRect& rect, |
685 const SkRect* localRect, | 685 const SkRect* localRect, |
686 const SkMatrix* localMatrix) { | 686 const SkMatrix* localMatrix) { |
687 | 687 |
688 set_vertex_attributes(this->drawState(), NULL != localRect); | 688 set_vertex_attributes(this->drawState(), NULL != localRect); |
689 | 689 |
690 AutoReleaseGeometry geo(this, 4, 0); | 690 AutoReleaseGeometry geo(this, 4, 0); |
691 if (!geo.succeeded()) { | 691 if (!geo.succeeded()) { |
692 GrPrintf("Failed to get space for vertices!\n"); | 692 GrPrintf("Failed to get space for vertices!\n"); |
693 return; | 693 return; |
694 } | 694 } |
695 | 695 |
696 size_t vstride = this->drawState()->getVertexStride(); | 696 size_t vsize = this->drawState()->getVertexSize(); |
697 geo.positions()->setRectFan(rect.fLeft, rect.fTop, rect.fRight, rect.fBottom
, vstride); | 697 geo.positions()->setRectFan(rect.fLeft, rect.fTop, rect.fRight, rect.fBottom
, vsize); |
698 if (NULL != localRect) { | 698 if (NULL != localRect) { |
699 SkPoint* coords = GrTCast<SkPoint*>(GrTCast<intptr_t>(geo.vertices()) + | 699 SkPoint* coords = GrTCast<SkPoint*>(GrTCast<intptr_t>(geo.vertices()) + |
700 sizeof(SkPoint)); | 700 sizeof(SkPoint)); |
701 coords->setRectFan(localRect->fLeft, localRect->fTop, | 701 coords->setRectFan(localRect->fLeft, localRect->fTop, |
702 localRect->fRight, localRect->fBottom, | 702 localRect->fRight, localRect->fBottom, |
703 vstride); | 703 vsize); |
704 if (NULL != localMatrix) { | 704 if (NULL != localMatrix) { |
705 localMatrix->mapPointsWithStride(coords, vstride, 4); | 705 localMatrix->mapPointsWithStride(coords, vsize, 4); |
706 } | 706 } |
707 } | 707 } |
708 SkRect bounds; | 708 SkRect bounds; |
709 this->getDrawState().getViewMatrix().mapRect(&bounds, rect); | 709 this->getDrawState().getViewMatrix().mapRect(&bounds, rect); |
710 | 710 |
711 this->drawNonIndexed(kTriangleFan_GrPrimitiveType, 0, 4, &bounds); | 711 this->drawNonIndexed(kTriangleFan_GrPrimitiveType, 0, 4, &bounds); |
712 } | 712 } |
713 | 713 |
714 void GrDrawTarget::clipWillBeSet(const GrClipData* clipData) { | 714 void GrDrawTarget::clipWillBeSet(const GrClipData* clipData) { |
715 } | 715 } |
(...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1132 SkASSERT(!fConfigTextureSupport[kUnknown_GrPixelConfig]); | 1132 SkASSERT(!fConfigTextureSupport[kUnknown_GrPixelConfig]); |
1133 | 1133 |
1134 for (size_t i = 1; i < SK_ARRAY_COUNT(kConfigNames); ++i) { | 1134 for (size_t i = 1; i < SK_ARRAY_COUNT(kConfigNames); ++i) { |
1135 r.appendf("%s is uploadable to a texture: %s\n", | 1135 r.appendf("%s is uploadable to a texture: %s\n", |
1136 kConfigNames[i], | 1136 kConfigNames[i], |
1137 gNY[fConfigTextureSupport[i]]); | 1137 gNY[fConfigTextureSupport[i]]); |
1138 } | 1138 } |
1139 | 1139 |
1140 return r; | 1140 return r; |
1141 } | 1141 } |
OLD | NEW |