Chromium Code Reviews| 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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 86 //////////////////////////////////////////////////////////////////////////////// | 86 //////////////////////////////////////////////////////////////////////////////// |
| 87 | 87 |
| 88 #define DEBUG_INVAL_BUFFER 0xdeadcafe | 88 #define DEBUG_INVAL_BUFFER 0xdeadcafe |
| 89 #define DEBUG_INVAL_START_IDX -1 | 89 #define DEBUG_INVAL_START_IDX -1 |
| 90 | 90 |
| 91 GrDrawTarget::GrDrawTarget(GrContext* context) | 91 GrDrawTarget::GrDrawTarget(GrContext* context) |
| 92 : fClip(NULL) | 92 : fClip(NULL) |
| 93 , fContext(context) | 93 , fContext(context) |
| 94 , fGpuTraceMarkerCount(0) { | 94 , fGpuTraceMarkerCount(0) { |
| 95 SkASSERT(context); | 95 SkASSERT(context); |
| 96 fDrawState = &fDefaultDrawState; | |
| 97 // We assume that fDrawState always owns a ref to the object it points at. | |
| 98 fDefaultDrawState.ref(); | |
| 99 GeometrySrcState& geoSrc = fGeoSrcStateStack.push_back(); | 96 GeometrySrcState& geoSrc = fGeoSrcStateStack.push_back(); |
| 100 #ifdef SK_DEBUG | 97 #ifdef SK_DEBUG |
| 101 geoSrc.fVertexCount = DEBUG_INVAL_START_IDX; | 98 geoSrc.fVertexCount = DEBUG_INVAL_START_IDX; |
| 102 geoSrc.fVertexBuffer = (GrVertexBuffer*)DEBUG_INVAL_BUFFER; | 99 geoSrc.fVertexBuffer = (GrVertexBuffer*)DEBUG_INVAL_BUFFER; |
| 103 geoSrc.fIndexCount = DEBUG_INVAL_START_IDX; | 100 geoSrc.fIndexCount = DEBUG_INVAL_START_IDX; |
| 104 geoSrc.fIndexBuffer = (GrIndexBuffer*)DEBUG_INVAL_BUFFER; | 101 geoSrc.fIndexBuffer = (GrIndexBuffer*)DEBUG_INVAL_BUFFER; |
| 105 #endif | 102 #endif |
| 106 geoSrc.fVertexSrc = kNone_GeometrySrcType; | 103 geoSrc.fVertexSrc = kNone_GeometrySrcType; |
| 107 geoSrc.fIndexSrc = kNone_GeometrySrcType; | 104 geoSrc.fIndexSrc = kNone_GeometrySrcType; |
| 108 } | 105 } |
| 109 | 106 |
| 110 GrDrawTarget::~GrDrawTarget() { | 107 GrDrawTarget::~GrDrawTarget() { |
| 111 SkASSERT(1 == fGeoSrcStateStack.count()); | 108 SkASSERT(1 == fGeoSrcStateStack.count()); |
| 112 SkDEBUGCODE(GeometrySrcState& geoSrc = fGeoSrcStateStack.back()); | 109 SkDEBUGCODE(GeometrySrcState& geoSrc = fGeoSrcStateStack.back()); |
| 113 SkASSERT(kNone_GeometrySrcType == geoSrc.fIndexSrc); | 110 SkASSERT(kNone_GeometrySrcType == geoSrc.fIndexSrc); |
| 114 SkASSERT(kNone_GeometrySrcType == geoSrc.fVertexSrc); | 111 SkASSERT(kNone_GeometrySrcType == geoSrc.fVertexSrc); |
| 115 fDrawState->unref(); | |
| 116 } | 112 } |
| 117 | 113 |
| 118 void GrDrawTarget::releaseGeometry() { | 114 void GrDrawTarget::releaseGeometry() { |
| 119 int popCnt = fGeoSrcStateStack.count() - 1; | 115 int popCnt = fGeoSrcStateStack.count() - 1; |
| 120 while (popCnt) { | 116 while (popCnt) { |
| 121 this->popGeometrySource(); | 117 this->popGeometrySource(); |
| 122 --popCnt; | 118 --popCnt; |
| 123 } | 119 } |
| 124 this->resetVertexSource(); | 120 this->resetVertexSource(); |
| 125 this->resetIndexSource(); | 121 this->resetIndexSource(); |
| 126 } | 122 } |
| 127 | 123 |
| 128 void GrDrawTarget::setClip(const GrClipData* clip) { | 124 void GrDrawTarget::setClip(const GrClipData* clip) { |
| 129 fClip = clip; | 125 fClip = clip; |
| 130 } | 126 } |
| 131 | 127 |
| 132 const GrClipData* GrDrawTarget::getClip() const { | 128 const GrClipData* GrDrawTarget::getClip() const { |
| 133 return fClip; | 129 return fClip; |
| 134 } | 130 } |
| 135 | 131 |
| 136 void GrDrawTarget::setDrawState(GrDrawState* drawState) { | |
| 137 SkASSERT(fDrawState); | |
| 138 if (NULL == drawState) { | |
| 139 drawState = &fDefaultDrawState; | |
| 140 } | |
| 141 if (fDrawState != drawState) { | |
| 142 fDrawState->unref(); | |
| 143 drawState->ref(); | |
| 144 fDrawState = drawState; | |
| 145 } | |
| 146 } | |
| 147 | |
| 148 bool GrDrawTarget::reserveVertexSpace(size_t vertexSize, | 132 bool GrDrawTarget::reserveVertexSpace(size_t vertexSize, |
| 149 int vertexCount, | 133 int vertexCount, |
| 150 void** vertices) { | 134 void** vertices) { |
| 151 GeometrySrcState& geoSrc = fGeoSrcStateStack.back(); | 135 GeometrySrcState& geoSrc = fGeoSrcStateStack.back(); |
| 152 bool acquired = false; | 136 bool acquired = false; |
| 153 if (vertexCount > 0) { | 137 if (vertexCount > 0) { |
| 154 SkASSERT(vertices); | 138 SkASSERT(vertices); |
| 155 this->releasePreviousVertexSource(); | 139 this->releasePreviousVertexSource(); |
| 156 geoSrc.fVertexSrc = kNone_GeometrySrcType; | 140 geoSrc.fVertexSrc = kNone_GeometrySrcType; |
| 157 | 141 |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 184 geoSrc.fIndexSrc = kReserved_GeometrySrcType; | 168 geoSrc.fIndexSrc = kReserved_GeometrySrcType; |
| 185 geoSrc.fIndexCount = indexCount; | 169 geoSrc.fIndexCount = indexCount; |
| 186 } else if (indices) { | 170 } else if (indices) { |
| 187 *indices = NULL; | 171 *indices = NULL; |
| 188 } | 172 } |
| 189 return acquired; | 173 return acquired; |
| 190 | 174 |
| 191 } | 175 } |
| 192 | 176 |
| 193 bool GrDrawTarget::reserveVertexAndIndexSpace(int vertexCount, | 177 bool GrDrawTarget::reserveVertexAndIndexSpace(int vertexCount, |
| 178 size_t vertexStride, | |
| 194 int indexCount, | 179 int indexCount, |
| 195 void** vertices, | 180 void** vertices, |
| 196 void** indices) { | 181 void** indices) { |
| 197 size_t vertexStride = this->drawState()->getVertexStride(); | 182 this->willReserveVertexAndIndexSpace(vertexCount, vertexStride, indexCount); |
| 198 this->willReserveVertexAndIndexSpace(vertexCount, indexCount); | |
| 199 if (vertexCount) { | 183 if (vertexCount) { |
| 200 if (!this->reserveVertexSpace(vertexStride, vertexCount, vertices)) { | 184 if (!this->reserveVertexSpace(vertexStride, vertexCount, vertices)) { |
| 201 if (indexCount) { | 185 if (indexCount) { |
| 202 this->resetIndexSource(); | 186 this->resetIndexSource(); |
| 203 } | 187 } |
| 204 return false; | 188 return false; |
| 205 } | 189 } |
| 206 } | 190 } |
| 207 if (indexCount) { | 191 if (indexCount) { |
| 208 if (!this->reserveIndexSpace(indexCount, indices)) { | 192 if (!this->reserveIndexSpace(indexCount, indices)) { |
| 209 if (vertexCount) { | 193 if (vertexCount) { |
| 210 this->resetVertexSource(); | 194 this->resetVertexSource(); |
| 211 } | 195 } |
| 212 return false; | 196 return false; |
| 213 } | 197 } |
| 214 } | 198 } |
| 215 return true; | 199 return true; |
| 216 } | 200 } |
| 217 | 201 |
| 218 bool GrDrawTarget::geometryHints(int32_t* vertexCount, | 202 bool GrDrawTarget::geometryHints(size_t vertexStride, |
| 203 int32_t* vertexCount, | |
| 219 int32_t* indexCount) const { | 204 int32_t* indexCount) const { |
| 220 if (vertexCount) { | 205 if (vertexCount) { |
| 221 *vertexCount = -1; | 206 *vertexCount = -1; |
| 222 } | 207 } |
| 223 if (indexCount) { | 208 if (indexCount) { |
| 224 *indexCount = -1; | 209 *indexCount = -1; |
| 225 } | 210 } |
| 226 return false; | 211 return false; |
| 227 } | 212 } |
| 228 | 213 |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 259 #ifdef SK_DEBUG | 244 #ifdef SK_DEBUG |
| 260 geoSrc.fIndexBuffer = (GrIndexBuffer*)DEBUG_INVAL_BUFFER; | 245 geoSrc.fIndexBuffer = (GrIndexBuffer*)DEBUG_INVAL_BUFFER; |
| 261 #endif | 246 #endif |
| 262 break; | 247 break; |
| 263 default: | 248 default: |
| 264 SkFAIL("Unknown Index Source Type."); | 249 SkFAIL("Unknown Index Source Type."); |
| 265 break; | 250 break; |
| 266 } | 251 } |
| 267 } | 252 } |
| 268 | 253 |
| 269 void GrDrawTarget::setVertexSourceToBuffer(const GrVertexBuffer* buffer) { | 254 void GrDrawTarget::setVertexSourceToBuffer(const GrVertexBuffer* buffer, size_t vertexStride) { |
| 270 this->releasePreviousVertexSource(); | 255 this->releasePreviousVertexSource(); |
| 271 GeometrySrcState& geoSrc = fGeoSrcStateStack.back(); | 256 GeometrySrcState& geoSrc = fGeoSrcStateStack.back(); |
| 272 geoSrc.fVertexSrc = kBuffer_GeometrySrcType; | 257 geoSrc.fVertexSrc = kBuffer_GeometrySrcType; |
| 273 geoSrc.fVertexBuffer = buffer; | 258 geoSrc.fVertexBuffer = buffer; |
| 274 buffer->ref(); | 259 buffer->ref(); |
| 275 geoSrc.fVertexSize = this->drawState()->getVertexStride(); | 260 geoSrc.fVertexSize = vertexStride; |
| 276 } | 261 } |
| 277 | 262 |
| 278 void GrDrawTarget::setIndexSourceToBuffer(const GrIndexBuffer* buffer) { | 263 void GrDrawTarget::setIndexSourceToBuffer(const GrIndexBuffer* buffer) { |
| 279 this->releasePreviousIndexSource(); | 264 this->releasePreviousIndexSource(); |
| 280 GeometrySrcState& geoSrc = fGeoSrcStateStack.back(); | 265 GeometrySrcState& geoSrc = fGeoSrcStateStack.back(); |
| 281 geoSrc.fIndexSrc = kBuffer_GeometrySrcType; | 266 geoSrc.fIndexSrc = kBuffer_GeometrySrcType; |
| 282 geoSrc.fIndexBuffer = buffer; | 267 geoSrc.fIndexBuffer = buffer; |
| 283 buffer->ref(); | 268 buffer->ref(); |
| 284 } | 269 } |
| 285 | 270 |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 313 SkASSERT(fGeoSrcStateStack.count() > 1); | 298 SkASSERT(fGeoSrcStateStack.count() > 1); |
| 314 | 299 |
| 315 this->geometrySourceWillPop(fGeoSrcStateStack.fromBack(1)); | 300 this->geometrySourceWillPop(fGeoSrcStateStack.fromBack(1)); |
| 316 this->releasePreviousVertexSource(); | 301 this->releasePreviousVertexSource(); |
| 317 this->releasePreviousIndexSource(); | 302 this->releasePreviousIndexSource(); |
| 318 fGeoSrcStateStack.pop_back(); | 303 fGeoSrcStateStack.pop_back(); |
| 319 } | 304 } |
| 320 | 305 |
| 321 //////////////////////////////////////////////////////////////////////////////// | 306 //////////////////////////////////////////////////////////////////////////////// |
| 322 | 307 |
| 323 bool GrDrawTarget::checkDraw(GrPrimitiveType type, int startVertex, | 308 bool GrDrawTarget::checkDraw(const GrDrawState& drawState, |
| 324 int startIndex, int vertexCount, | 309 GrPrimitiveType type, |
| 310 int startVertex, | |
| 311 int startIndex, | |
| 312 int vertexCount, | |
| 325 int indexCount) const { | 313 int indexCount) const { |
| 326 const GrDrawState& drawState = this->getDrawState(); | |
| 327 #ifdef SK_DEBUG | 314 #ifdef SK_DEBUG |
| 328 const GeometrySrcState& geoSrc = fGeoSrcStateStack.back(); | 315 const GeometrySrcState& geoSrc = fGeoSrcStateStack.back(); |
| 329 int maxVertex = startVertex + vertexCount; | 316 int maxVertex = startVertex + vertexCount; |
| 330 int maxValidVertex; | 317 int maxValidVertex; |
| 331 switch (geoSrc.fVertexSrc) { | 318 switch (geoSrc.fVertexSrc) { |
| 332 case kNone_GeometrySrcType: | 319 case kNone_GeometrySrcType: |
| 333 SkFAIL("Attempting to draw without vertex src."); | 320 SkFAIL("Attempting to draw without vertex src."); |
| 334 case kReserved_GeometrySrcType: // fallthrough | 321 case kReserved_GeometrySrcType: // fallthrough |
| 335 maxValidVertex = geoSrc.fVertexCount; | 322 maxValidVertex = geoSrc.fVertexCount; |
| 336 break; | 323 break; |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 388 } | 375 } |
| 389 | 376 |
| 390 SkASSERT(drawState.validateVertexAttribs()); | 377 SkASSERT(drawState.validateVertexAttribs()); |
| 391 #endif | 378 #endif |
| 392 if (NULL == drawState.getRenderTarget()) { | 379 if (NULL == drawState.getRenderTarget()) { |
| 393 return false; | 380 return false; |
| 394 } | 381 } |
| 395 return true; | 382 return true; |
| 396 } | 383 } |
| 397 | 384 |
| 398 bool GrDrawTarget::setupDstReadIfNecessary(GrDeviceCoordTexture* dstCopy, const SkRect* drawBounds) { | 385 bool GrDrawTarget::setupDstReadIfNecessary(GrDrawState* ds, |
| 399 if (this->caps()->dstReadInShaderSupport() || !this->getDrawState().willEffe ctReadDstColor()) { | 386 GrDeviceCoordTexture* dstCopy, |
| 387 const SkRect* drawBounds) { | |
| 388 if (this->caps()->dstReadInShaderSupport() || !ds->willEffectReadDstColor()) { | |
| 400 return true; | 389 return true; |
| 401 } | 390 } |
| 402 GrRenderTarget* rt = this->drawState()->getRenderTarget(); | |
| 403 SkIRect copyRect; | 391 SkIRect copyRect; |
| 404 const GrClipData* clip = this->getClip(); | 392 const GrClipData* clip = this->getClip(); |
| 393 GrRenderTarget* rt = ds->getRenderTarget(); | |
| 405 clip->getConservativeBounds(rt, ©Rect); | 394 clip->getConservativeBounds(rt, ©Rect); |
| 406 | 395 |
| 407 if (drawBounds) { | 396 if (drawBounds) { |
| 408 SkIRect drawIBounds; | 397 SkIRect drawIBounds; |
| 409 drawBounds->roundOut(&drawIBounds); | 398 drawBounds->roundOut(&drawIBounds); |
| 410 if (!copyRect.intersect(drawIBounds)) { | 399 if (!copyRect.intersect(drawIBounds)) { |
| 411 #ifdef SK_DEBUG | 400 #ifdef SK_DEBUG |
| 412 SkDebugf("Missed an early reject. Bailing on draw from setupDstReadI fNecessary.\n"); | 401 SkDebugf("Missed an early reject. Bailing on draw from setupDstReadI fNecessary.\n"); |
| 413 #endif | 402 #endif |
| 414 return false; | 403 return false; |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 436 SkIPoint dstPoint = {0, 0}; | 425 SkIPoint dstPoint = {0, 0}; |
| 437 if (this->copySurface(copy, rt, copyRect, dstPoint)) { | 426 if (this->copySurface(copy, rt, copyRect, dstPoint)) { |
| 438 dstCopy->setTexture(copy); | 427 dstCopy->setTexture(copy); |
| 439 dstCopy->setOffset(copyRect.fLeft, copyRect.fTop); | 428 dstCopy->setOffset(copyRect.fLeft, copyRect.fTop); |
| 440 return true; | 429 return true; |
| 441 } else { | 430 } else { |
| 442 return false; | 431 return false; |
| 443 } | 432 } |
| 444 } | 433 } |
| 445 | 434 |
| 446 void GrDrawTarget::drawIndexed(GrPrimitiveType type, | 435 void GrDrawTarget::drawIndexed(GrDrawState* ds, |
| 436 GrPrimitiveType type, | |
| 447 int startVertex, | 437 int startVertex, |
| 448 int startIndex, | 438 int startIndex, |
| 449 int vertexCount, | 439 int vertexCount, |
| 450 int indexCount, | 440 int indexCount, |
| 451 const SkRect* devBounds) { | 441 const SkRect* devBounds) { |
| 452 if (indexCount > 0 && this->checkDraw(type, startVertex, startIndex, vertexC ount, indexCount)) { | 442 SkASSERT(ds); |
| 443 if (indexCount > 0 && | |
| 444 this->checkDraw(*ds, type, startVertex, startIndex, vertexCount, indexCo unt)) { | |
| 445 | |
| 453 // Setup clip | 446 // Setup clip |
| 454 GrClipMaskManager::ScissorState scissorState; | 447 GrClipMaskManager::ScissorState scissorState; |
| 455 GrDrawState::AutoRestoreEffects are; | 448 GrDrawState::AutoRestoreEffects are; |
| 456 GrDrawState::AutoRestoreStencil ars; | 449 GrDrawState::AutoRestoreStencil ars; |
| 457 if (!this->setupClip(devBounds, &are, &ars, &scissorState)) { | 450 if (!this->setupClip(devBounds, &are, &ars, ds, &scissorState)) { |
| 458 return; | 451 return; |
| 459 } | 452 } |
| 460 | 453 |
| 461 DrawInfo info; | 454 DrawInfo info; |
| 462 info.fPrimitiveType = type; | 455 info.fPrimitiveType = type; |
| 463 info.fStartVertex = startVertex; | 456 info.fStartVertex = startVertex; |
| 464 info.fStartIndex = startIndex; | 457 info.fStartIndex = startIndex; |
| 465 info.fVertexCount = vertexCount; | 458 info.fVertexCount = vertexCount; |
| 466 info.fIndexCount = indexCount; | 459 info.fIndexCount = indexCount; |
| 467 | 460 |
| 468 info.fInstanceCount = 0; | 461 info.fInstanceCount = 0; |
| 469 info.fVerticesPerInstance = 0; | 462 info.fVerticesPerInstance = 0; |
| 470 info.fIndicesPerInstance = 0; | 463 info.fIndicesPerInstance = 0; |
| 471 | 464 |
| 472 if (devBounds) { | 465 if (devBounds) { |
| 473 info.setDevBounds(*devBounds); | 466 info.setDevBounds(*devBounds); |
| 474 } | 467 } |
| 475 // TODO: We should continue with incorrect blending. | 468 // TODO: We should continue with incorrect blending. |
| 476 if (!this->setupDstReadIfNecessary(&info)) { | 469 if (!this->setupDstReadIfNecessary(ds, &info)) { |
| 477 return; | 470 return; |
| 478 } | 471 } |
| 479 this->onDraw(info, scissorState); | 472 this->onDraw(*ds, info, scissorState); |
| 480 } | 473 } |
| 481 } | 474 } |
| 482 | 475 |
| 483 void GrDrawTarget::drawNonIndexed(GrPrimitiveType type, | 476 void GrDrawTarget::drawNonIndexed(GrDrawState* ds, |
| 477 GrPrimitiveType type, | |
| 484 int startVertex, | 478 int startVertex, |
| 485 int vertexCount, | 479 int vertexCount, |
| 486 const SkRect* devBounds) { | 480 const SkRect* devBounds) { |
| 487 if (vertexCount > 0 && this->checkDraw(type, startVertex, -1, vertexCount, - 1)) { | 481 SkASSERT(ds); |
| 482 if (vertexCount > 0 && this->checkDraw(*ds, type, startVertex, -1, vertexCou nt, -1)) { | |
| 483 | |
| 488 // Setup clip | 484 // Setup clip |
| 489 GrClipMaskManager::ScissorState scissorState; | 485 GrClipMaskManager::ScissorState scissorState; |
| 490 GrDrawState::AutoRestoreEffects are; | 486 GrDrawState::AutoRestoreEffects are; |
| 491 GrDrawState::AutoRestoreStencil ars; | 487 GrDrawState::AutoRestoreStencil ars; |
| 492 if (!this->setupClip(devBounds, &are, &ars, &scissorState)) { | 488 if (!this->setupClip(devBounds, &are, &ars, ds, &scissorState)) { |
| 493 return; | 489 return; |
| 494 } | 490 } |
| 495 | 491 |
| 496 DrawInfo info; | 492 DrawInfo info; |
| 497 info.fPrimitiveType = type; | 493 info.fPrimitiveType = type; |
| 498 info.fStartVertex = startVertex; | 494 info.fStartVertex = startVertex; |
| 499 info.fStartIndex = 0; | 495 info.fStartIndex = 0; |
| 500 info.fVertexCount = vertexCount; | 496 info.fVertexCount = vertexCount; |
| 501 info.fIndexCount = 0; | 497 info.fIndexCount = 0; |
| 502 | 498 |
| 503 info.fInstanceCount = 0; | 499 info.fInstanceCount = 0; |
| 504 info.fVerticesPerInstance = 0; | 500 info.fVerticesPerInstance = 0; |
| 505 info.fIndicesPerInstance = 0; | 501 info.fIndicesPerInstance = 0; |
| 506 | 502 |
| 507 if (devBounds) { | 503 if (devBounds) { |
| 508 info.setDevBounds(*devBounds); | 504 info.setDevBounds(*devBounds); |
| 509 } | 505 } |
| 510 | 506 |
| 511 // TODO: We should continue with incorrect blending. | 507 // TODO: We should continue with incorrect blending. |
| 512 if (!this->setupDstReadIfNecessary(&info)) { | 508 if (!this->setupDstReadIfNecessary(ds, &info)) { |
| 513 return; | 509 return; |
| 514 } | 510 } |
| 515 this->onDraw(info, scissorState); | 511 this->onDraw(*ds, info, scissorState); |
| 516 } | 512 } |
| 517 } | 513 } |
| 518 | 514 |
| 519 static const GrStencilSettings& winding_path_stencil_settings() { | 515 static const GrStencilSettings& winding_path_stencil_settings() { |
| 520 GR_STATIC_CONST_SAME_STENCIL_STRUCT(gSettings, | 516 GR_STATIC_CONST_SAME_STENCIL_STRUCT(gSettings, |
| 521 kIncClamp_StencilOp, | 517 kIncClamp_StencilOp, |
| 522 kIncClamp_StencilOp, | 518 kIncClamp_StencilOp, |
| 523 kAlwaysIfInClip_StencilFunc, | 519 kAlwaysIfInClip_StencilFunc, |
| 524 0xFFFF, 0xFFFF, 0xFFFF); | 520 0xFFFF, 0xFFFF, 0xFFFF); |
| 525 return *GR_CONST_STENCIL_SETTINGS_PTR_FROM_STRUCT_PTR(&gSettings); | 521 return *GR_CONST_STENCIL_SETTINGS_PTR_FROM_STRUCT_PTR(&gSettings); |
| 526 } | 522 } |
| 527 | 523 |
| 528 static const GrStencilSettings& even_odd_path_stencil_settings() { | 524 static const GrStencilSettings& even_odd_path_stencil_settings() { |
| 529 GR_STATIC_CONST_SAME_STENCIL_STRUCT(gSettings, | 525 GR_STATIC_CONST_SAME_STENCIL_STRUCT(gSettings, |
| 530 kInvert_StencilOp, | 526 kInvert_StencilOp, |
| 531 kInvert_StencilOp, | 527 kInvert_StencilOp, |
| 532 kAlwaysIfInClip_StencilFunc, | 528 kAlwaysIfInClip_StencilFunc, |
| 533 0xFFFF, 0xFFFF, 0xFFFF); | 529 0xFFFF, 0xFFFF, 0xFFFF); |
| 534 return *GR_CONST_STENCIL_SETTINGS_PTR_FROM_STRUCT_PTR(&gSettings); | 530 return *GR_CONST_STENCIL_SETTINGS_PTR_FROM_STRUCT_PTR(&gSettings); |
| 535 } | 531 } |
| 536 | 532 |
| 537 void GrDrawTarget::getPathStencilSettingsForFilltype(GrPathRendering::FillType f ill, | 533 void GrDrawTarget::getPathStencilSettingsForFilltype(GrPathRendering::FillType f ill, |
| 534 const GrStencilBuffer* sb, | |
| 538 GrStencilSettings* outStenc ilSettings) { | 535 GrStencilSettings* outStenc ilSettings) { |
| 539 | 536 |
| 540 switch (fill) { | 537 switch (fill) { |
| 541 default: | 538 default: |
| 542 SkFAIL("Unexpected path fill."); | 539 SkFAIL("Unexpected path fill."); |
| 543 case GrPathRendering::kWinding_FillType: | 540 case GrPathRendering::kWinding_FillType: |
| 544 *outStencilSettings = winding_path_stencil_settings(); | 541 *outStencilSettings = winding_path_stencil_settings(); |
| 545 break; | 542 break; |
| 546 case GrPathRendering::kEvenOdd_FillType: | 543 case GrPathRendering::kEvenOdd_FillType: |
| 547 *outStencilSettings = even_odd_path_stencil_settings(); | 544 *outStencilSettings = even_odd_path_stencil_settings(); |
| 548 break; | 545 break; |
| 549 } | 546 } |
| 550 this->clipMaskManager()->adjustPathStencilParams(outStencilSettings); | 547 this->clipMaskManager()->adjustPathStencilParams(sb, outStencilSettings); |
| 551 } | 548 } |
| 552 | 549 |
| 553 void GrDrawTarget::stencilPath(const GrPath* path, GrPathRendering::FillType fil l) { | 550 void GrDrawTarget::stencilPath(GrDrawState* ds, |
| 551 const GrPath* path, | |
| 552 GrPathRendering::FillType fill) { | |
| 554 // TODO: extract portions of checkDraw that are relevant to path stenciling. | 553 // TODO: extract portions of checkDraw that are relevant to path stenciling. |
| 555 SkASSERT(path); | 554 SkASSERT(path); |
| 556 SkASSERT(this->caps()->pathRenderingSupport()); | 555 SkASSERT(this->caps()->pathRenderingSupport()); |
| 556 SkASSERT(ds); | |
| 557 | 557 |
| 558 // Setup clip | 558 // Setup clip |
| 559 GrClipMaskManager::ScissorState scissorState; | 559 GrClipMaskManager::ScissorState scissorState; |
| 560 GrDrawState::AutoRestoreEffects are; | 560 GrDrawState::AutoRestoreEffects are; |
| 561 GrDrawState::AutoRestoreStencil ars; | 561 GrDrawState::AutoRestoreStencil ars; |
| 562 if (!this->setupClip(NULL, &are, &ars, &scissorState)) { | 562 if (!this->setupClip(NULL, &are, &ars, ds, &scissorState)) { |
| 563 return; | 563 return; |
| 564 } | 564 } |
| 565 | 565 |
| 566 // set stencil settings for path | 566 // set stencil settings for path |
| 567 GrStencilSettings stencilSettings; | 567 GrStencilSettings stencilSettings; |
| 568 this->getPathStencilSettingsForFilltype(fill, &stencilSettings); | 568 this->getPathStencilSettingsForFilltype(fill, |
| 569 ds->getRenderTarget()->getStencilBuf fer(), | |
| 570 &stencilSettings); | |
| 569 | 571 |
| 570 this->onStencilPath(path, scissorState, stencilSettings); | 572 this->onStencilPath(*ds, path, scissorState, stencilSettings); |
| 571 } | 573 } |
| 572 | 574 |
| 573 void GrDrawTarget::drawPath(const GrPath* path, GrPathRendering::FillType fill) { | 575 void GrDrawTarget::drawPath(GrDrawState* ds, |
| 576 const GrPath* path, | |
| 577 GrPathRendering::FillType fill) { | |
| 574 // TODO: extract portions of checkDraw that are relevant to path rendering. | 578 // TODO: extract portions of checkDraw that are relevant to path rendering. |
| 575 SkASSERT(path); | 579 SkASSERT(path); |
| 576 SkASSERT(this->caps()->pathRenderingSupport()); | 580 SkASSERT(this->caps()->pathRenderingSupport()); |
| 581 SkASSERT(ds); | |
| 577 | 582 |
| 578 SkRect devBounds = path->getBounds(); | 583 SkRect devBounds = path->getBounds(); |
| 579 SkMatrix viewM = this->drawState()->getViewMatrix(); | 584 SkMatrix viewM = ds->getViewMatrix(); |
| 580 viewM.mapRect(&devBounds); | 585 viewM.mapRect(&devBounds); |
| 581 | 586 |
| 582 // Setup clip | 587 // Setup clip |
| 583 GrClipMaskManager::ScissorState scissorState; | 588 GrClipMaskManager::ScissorState scissorState; |
| 584 GrDrawState::AutoRestoreEffects are; | 589 GrDrawState::AutoRestoreEffects are; |
| 585 GrDrawState::AutoRestoreStencil ars; | 590 GrDrawState::AutoRestoreStencil ars; |
| 586 if (!this->setupClip(&devBounds, &are, &ars, &scissorState)) { | 591 if (!this->setupClip(&devBounds, &are, &ars, ds, &scissorState)) { |
| 587 return; | 592 return; |
| 588 } | 593 } |
| 589 | 594 |
| 590 // set stencil settings for path | 595 // set stencil settings for path |
| 591 GrStencilSettings stencilSettings; | 596 GrStencilSettings stencilSettings; |
| 592 this->getPathStencilSettingsForFilltype(fill, &stencilSettings); | 597 this->getPathStencilSettingsForFilltype(fill, |
| 598 ds->getRenderTarget()->getStencilBuf fer(), | |
| 599 &stencilSettings); | |
| 593 | 600 |
| 594 GrDeviceCoordTexture dstCopy; | 601 GrDeviceCoordTexture dstCopy; |
| 595 if (!this->setupDstReadIfNecessary(&dstCopy, &devBounds)) { | 602 if (!this->setupDstReadIfNecessary(ds, &dstCopy, &devBounds)) { |
| 596 return; | 603 return; |
| 597 } | 604 } |
| 598 | 605 |
| 599 this->onDrawPath(path, scissorState, stencilSettings, dstCopy.texture() ? &d stCopy : NULL); | 606 this->onDrawPath(*ds, path, scissorState, stencilSettings, dstCopy.texture() ? &dstCopy : NULL); |
| 600 } | 607 } |
| 601 | 608 |
| 602 void GrDrawTarget::drawPaths(const GrPathRange* pathRange, | 609 void GrDrawTarget::drawPaths(GrDrawState* ds, |
| 603 const uint32_t indices[], int count, | 610 const GrPathRange* pathRange, |
| 604 const float transforms[], PathTransformType transfo rmsType, | 611 const uint32_t indices[], |
| 612 int count, | |
| 613 const float transforms[], | |
| 614 PathTransformType transformsType, | |
| 605 GrPathRendering::FillType fill) { | 615 GrPathRendering::FillType fill) { |
| 606 SkASSERT(this->caps()->pathRenderingSupport()); | 616 SkASSERT(this->caps()->pathRenderingSupport()); |
| 607 SkASSERT(pathRange); | 617 SkASSERT(pathRange); |
| 608 SkASSERT(indices); | 618 SkASSERT(indices); |
| 609 SkASSERT(transforms); | 619 SkASSERT(transforms); |
| 620 SkASSERT(ds); | |
| 610 | 621 |
| 611 // Setup clip | 622 // Setup clip |
| 612 GrClipMaskManager::ScissorState scissorState; | 623 GrClipMaskManager::ScissorState scissorState; |
| 613 GrDrawState::AutoRestoreEffects are; | 624 GrDrawState::AutoRestoreEffects are; |
| 614 GrDrawState::AutoRestoreStencil ars; | 625 GrDrawState::AutoRestoreStencil ars; |
| 615 | 626 |
| 616 if (!this->setupClip(NULL, &are, &ars, &scissorState)) { | 627 if (!this->setupClip(NULL, &are, &ars, ds, &scissorState)) { |
| 617 return; | 628 return; |
| 618 } | 629 } |
| 619 | 630 |
| 620 // set stencil settings for path | 631 // set stencil settings for path |
| 621 GrStencilSettings stencilSettings; | 632 GrStencilSettings stencilSettings; |
| 622 this->getPathStencilSettingsForFilltype(fill, &stencilSettings); | 633 this->getPathStencilSettingsForFilltype(fill, |
| 634 ds->getRenderTarget()->getStencilBuf fer(), | |
| 635 &stencilSettings); | |
| 623 | 636 |
| 624 // Don't compute a bounding box for setupDstReadIfNecessary(), we'll opt | 637 // Don't compute a bounding box for setupDstReadIfNecessary(), we'll opt |
| 625 // instead for it to just copy the entire dst. Realistically this is a moot | 638 // instead for it to just copy the entire dst. Realistically this is a moot |
| 626 // point, because any context that supports NV_path_rendering will also | 639 // point, because any context that supports NV_path_rendering will also |
| 627 // support NV_blend_equation_advanced. | 640 // support NV_blend_equation_advanced. |
| 628 GrDeviceCoordTexture dstCopy; | 641 GrDeviceCoordTexture dstCopy; |
| 629 if (!this->setupDstReadIfNecessary(&dstCopy, NULL)) { | 642 if (!this->setupDstReadIfNecessary(ds, &dstCopy, NULL)) { |
| 630 return; | 643 return; |
| 631 } | 644 } |
| 632 | 645 |
| 633 this->onDrawPaths(pathRange, indices, count, transforms, transformsType, sci ssorState, | 646 this->onDrawPaths(*ds, pathRange, indices, count, transforms, transformsType , scissorState, |
| 634 stencilSettings, dstCopy.texture() ? &dstCopy : NULL); | 647 stencilSettings, dstCopy.texture() ? &dstCopy : NULL); |
| 635 } | 648 } |
| 636 | 649 |
| 637 void GrDrawTarget::clear(const SkIRect* rect, GrColor color, bool canIgnoreRect, | 650 void GrDrawTarget::clear(const SkIRect* rect, |
| 651 GrColor color, | |
| 652 bool canIgnoreRect, | |
| 638 GrRenderTarget* renderTarget) { | 653 GrRenderTarget* renderTarget) { |
| 639 if (fCaps->useDrawInsteadOfClear()) { | 654 if (fCaps->useDrawInsteadOfClear()) { |
| 640 // This works around a driver bug with clear by drawing a rect instead. | 655 // This works around a driver bug with clear by drawing a rect instead. |
| 641 // The driver will ignore a clear if it is the only thing rendered to a | 656 // The driver will ignore a clear if it is the only thing rendered to a |
| 642 // target before the target is read. | 657 // target before the target is read. |
| 643 SkIRect rtRect = SkIRect::MakeWH(renderTarget->width(), renderTarget->he ight()); | 658 SkIRect rtRect = SkIRect::MakeWH(renderTarget->width(), renderTarget->he ight()); |
| 644 if (NULL == rect || canIgnoreRect || rect->contains(rtRect)) { | 659 if (NULL == rect || canIgnoreRect || rect->contains(rtRect)) { |
| 645 rect = &rtRect; | 660 rect = &rtRect; |
| 646 // We first issue a discard() since that may help tilers. | 661 // We first issue a discard() since that may help tilers. |
| 647 this->discard(renderTarget); | 662 this->discard(renderTarget); |
| 648 } | 663 } |
| 649 AutoStateRestore asr(this, kReset_ASRInit, &SkMatrix::I()); | |
| 650 | 664 |
| 651 this->drawState()->setColor(color); | 665 GrDrawState drawState; |
| 652 this->drawState()->disableState(GrDrawState::kClip_StateBit); | |
| 653 this->drawState()->disableState(GrDrawState::kHWAntialias_StateBit); | |
| 654 this->drawState()->setRenderTarget(renderTarget); | |
| 655 | 666 |
| 656 this->drawSimpleRect(*rect); | 667 drawState.setColor(color); |
| 668 drawState.setRenderTarget(renderTarget); | |
| 669 | |
| 670 this->drawSimpleRect(&drawState, *rect); | |
| 657 } else { | 671 } else { |
| 658 this->onClear(rect, color, canIgnoreRect, renderTarget); | 672 this->onClear(rect, color, canIgnoreRect, renderTarget); |
| 659 } | 673 } |
| 660 } | 674 } |
| 661 | 675 |
| 662 typedef GrTraceMarkerSet::Iter TMIter; | 676 typedef GrTraceMarkerSet::Iter TMIter; |
| 663 void GrDrawTarget::saveActiveTraceMarkers() { | 677 void GrDrawTarget::saveActiveTraceMarkers() { |
| 664 if (this->caps()->gpuTracingSupport()) { | 678 if (this->caps()->gpuTracingSupport()) { |
| 665 SkASSERT(0 == fStoredTraceMarkers.count()); | 679 SkASSERT(0 == fStoredTraceMarkers.count()); |
| 666 fStoredTraceMarkers.addSet(fActiveTraceMarkers); | 680 fStoredTraceMarkers.addSet(fActiveTraceMarkers); |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 693 void GrDrawTarget::removeGpuTraceMarker(const GrGpuTraceMarker* marker) { | 707 void GrDrawTarget::removeGpuTraceMarker(const GrGpuTraceMarker* marker) { |
| 694 if (this->caps()->gpuTracingSupport()) { | 708 if (this->caps()->gpuTracingSupport()) { |
| 695 SkASSERT(fGpuTraceMarkerCount >= 1); | 709 SkASSERT(fGpuTraceMarkerCount >= 1); |
| 696 this->fActiveTraceMarkers.remove(*marker); | 710 this->fActiveTraceMarkers.remove(*marker); |
| 697 --fGpuTraceMarkerCount; | 711 --fGpuTraceMarkerCount; |
| 698 } | 712 } |
| 699 } | 713 } |
| 700 | 714 |
| 701 //////////////////////////////////////////////////////////////////////////////// | 715 //////////////////////////////////////////////////////////////////////////////// |
| 702 | 716 |
| 703 void GrDrawTarget::drawIndexedInstances(GrPrimitiveType type, | 717 void GrDrawTarget::drawIndexedInstances(GrDrawState* ds, |
| 718 GrPrimitiveType type, | |
| 704 int instanceCount, | 719 int instanceCount, |
| 705 int verticesPerInstance, | 720 int verticesPerInstance, |
| 706 int indicesPerInstance, | 721 int indicesPerInstance, |
| 707 const SkRect* devBounds) { | 722 const SkRect* devBounds) { |
| 708 if (!verticesPerInstance || !indicesPerInstance) { | 723 if (!verticesPerInstance || !indicesPerInstance) { |
| 709 return; | 724 return; |
| 710 } | 725 } |
| 711 | 726 |
| 712 int maxInstancesPerDraw = this->indexCountInCurrentSource() / indicesPerInst ance; | 727 int maxInstancesPerDraw = this->indexCountInCurrentSource() / indicesPerInst ance; |
| 713 if (!maxInstancesPerDraw) { | 728 if (!maxInstancesPerDraw) { |
| 714 return; | 729 return; |
| 715 } | 730 } |
| 716 | 731 |
| 732 SkASSERT(ds); | |
|
bsalomon
2014/11/14 21:51:02
move to top?
| |
| 733 | |
| 717 // Setup clip | 734 // Setup clip |
| 718 GrClipMaskManager::ScissorState scissorState; | 735 GrClipMaskManager::ScissorState scissorState; |
| 719 GrDrawState::AutoRestoreEffects are; | 736 GrDrawState::AutoRestoreEffects are; |
| 720 GrDrawState::AutoRestoreStencil ars; | 737 GrDrawState::AutoRestoreStencil ars; |
| 721 if (!this->setupClip(devBounds, &are, &ars, &scissorState)) { | 738 if (!this->setupClip(devBounds, &are, &ars, ds, &scissorState)) { |
| 722 return; | 739 return; |
| 723 } | 740 } |
| 724 | 741 |
| 725 DrawInfo info; | 742 DrawInfo info; |
| 726 info.fPrimitiveType = type; | 743 info.fPrimitiveType = type; |
| 727 info.fStartIndex = 0; | 744 info.fStartIndex = 0; |
| 728 info.fStartVertex = 0; | 745 info.fStartVertex = 0; |
| 729 info.fIndicesPerInstance = indicesPerInstance; | 746 info.fIndicesPerInstance = indicesPerInstance; |
| 730 info.fVerticesPerInstance = verticesPerInstance; | 747 info.fVerticesPerInstance = verticesPerInstance; |
| 731 | 748 |
| 732 // Set the same bounds for all the draws. | 749 // Set the same bounds for all the draws. |
| 733 if (devBounds) { | 750 if (devBounds) { |
| 734 info.setDevBounds(*devBounds); | 751 info.setDevBounds(*devBounds); |
| 735 } | 752 } |
| 736 // TODO: We should continue with incorrect blending. | 753 // TODO: We should continue with incorrect blending. |
| 737 if (!this->setupDstReadIfNecessary(&info)) { | 754 if (!this->setupDstReadIfNecessary(ds, &info)) { |
| 738 return; | 755 return; |
| 739 } | 756 } |
| 740 | |
| 741 while (instanceCount) { | 757 while (instanceCount) { |
| 742 info.fInstanceCount = SkTMin(instanceCount, maxInstancesPerDraw); | 758 info.fInstanceCount = SkTMin(instanceCount, maxInstancesPerDraw); |
| 743 info.fVertexCount = info.fInstanceCount * verticesPerInstance; | 759 info.fVertexCount = info.fInstanceCount * verticesPerInstance; |
| 744 info.fIndexCount = info.fInstanceCount * indicesPerInstance; | 760 info.fIndexCount = info.fInstanceCount * indicesPerInstance; |
| 745 | 761 |
| 746 if (this->checkDraw(type, | 762 if (this->checkDraw(*ds, |
| 763 type, | |
| 747 info.fStartVertex, | 764 info.fStartVertex, |
| 748 info.fStartIndex, | 765 info.fStartIndex, |
| 749 info.fVertexCount, | 766 info.fVertexCount, |
| 750 info.fIndexCount)) { | 767 info.fIndexCount)) { |
| 751 this->onDraw(info, scissorState); | 768 this->onDraw(*ds, info, scissorState); |
| 752 } | 769 } |
| 753 info.fStartVertex += info.fVertexCount; | 770 info.fStartVertex += info.fVertexCount; |
| 754 instanceCount -= info.fInstanceCount; | 771 instanceCount -= info.fInstanceCount; |
| 755 } | 772 } |
| 756 } | 773 } |
| 757 | 774 |
| 758 //////////////////////////////////////////////////////////////////////////////// | 775 //////////////////////////////////////////////////////////////////////////////// |
| 759 | 776 |
| 760 GrDrawTarget::AutoStateRestore::AutoStateRestore() { | |
| 761 fDrawTarget = NULL; | |
| 762 } | |
| 763 | |
| 764 GrDrawTarget::AutoStateRestore::AutoStateRestore(GrDrawTarget* target, | |
| 765 ASRInit init, | |
| 766 const SkMatrix* vm) { | |
| 767 fDrawTarget = NULL; | |
| 768 this->set(target, init, vm); | |
| 769 } | |
| 770 | |
| 771 GrDrawTarget::AutoStateRestore::~AutoStateRestore() { | |
| 772 if (fDrawTarget) { | |
| 773 fDrawTarget->setDrawState(fSavedState); | |
| 774 fSavedState->unref(); | |
| 775 } | |
| 776 } | |
| 777 | |
| 778 void GrDrawTarget::AutoStateRestore::set(GrDrawTarget* target, ASRInit init, con st SkMatrix* vm) { | |
| 779 SkASSERT(NULL == fDrawTarget); | |
| 780 fDrawTarget = target; | |
| 781 fSavedState = target->drawState(); | |
| 782 SkASSERT(fSavedState); | |
| 783 fSavedState->ref(); | |
| 784 if (kReset_ASRInit == init) { | |
| 785 if (NULL == vm) { | |
| 786 // calls the default cons | |
| 787 fTempState.init(); | |
| 788 } else { | |
| 789 SkNEW_IN_TLAZY(&fTempState, GrDrawState, (*vm)); | |
| 790 } | |
| 791 } else { | |
| 792 SkASSERT(kPreserve_ASRInit == init); | |
| 793 if (NULL == vm) { | |
| 794 fTempState.set(*fSavedState); | |
| 795 } else { | |
| 796 SkNEW_IN_TLAZY(&fTempState, GrDrawState, (*fSavedState, *vm)); | |
| 797 } | |
| 798 } | |
| 799 target->setDrawState(fTempState.get()); | |
| 800 } | |
| 801 | |
| 802 bool GrDrawTarget::AutoStateRestore::setIdentity(GrDrawTarget* target, ASRInit i nit) { | |
| 803 SkASSERT(NULL == fDrawTarget); | |
| 804 fDrawTarget = target; | |
| 805 fSavedState = target->drawState(); | |
| 806 SkASSERT(fSavedState); | |
| 807 fSavedState->ref(); | |
| 808 if (kReset_ASRInit == init) { | |
| 809 // calls the default cons | |
| 810 fTempState.init(); | |
| 811 } else { | |
| 812 SkASSERT(kPreserve_ASRInit == init); | |
| 813 // calls the copy cons | |
| 814 fTempState.set(*fSavedState); | |
| 815 if (!fTempState.get()->setIdentityViewMatrix()) { | |
| 816 // let go of any resources held by the temp | |
| 817 fTempState.get()->reset(); | |
| 818 fDrawTarget = NULL; | |
| 819 fSavedState->unref(); | |
| 820 fSavedState = NULL; | |
| 821 return false; | |
| 822 } | |
| 823 } | |
| 824 target->setDrawState(fTempState.get()); | |
| 825 return true; | |
| 826 } | |
| 827 | |
| 828 //////////////////////////////////////////////////////////////////////////////// | |
| 829 | |
| 830 GrDrawTarget::AutoReleaseGeometry::AutoReleaseGeometry( | 777 GrDrawTarget::AutoReleaseGeometry::AutoReleaseGeometry( |
| 831 GrDrawTarget* target, | 778 GrDrawTarget* target, |
| 832 int vertexCount, | 779 int vertexCount, |
| 780 size_t vertexStride, | |
| 833 int indexCount) { | 781 int indexCount) { |
| 834 fTarget = NULL; | 782 fTarget = NULL; |
| 835 this->set(target, vertexCount, indexCount); | 783 this->set(target, vertexCount, vertexStride, indexCount); |
| 836 } | 784 } |
| 837 | 785 |
| 838 GrDrawTarget::AutoReleaseGeometry::AutoReleaseGeometry() { | 786 GrDrawTarget::AutoReleaseGeometry::AutoReleaseGeometry() { |
| 839 fTarget = NULL; | 787 fTarget = NULL; |
| 840 } | 788 } |
| 841 | 789 |
| 842 GrDrawTarget::AutoReleaseGeometry::~AutoReleaseGeometry() { | 790 GrDrawTarget::AutoReleaseGeometry::~AutoReleaseGeometry() { |
| 843 this->reset(); | 791 this->reset(); |
| 844 } | 792 } |
| 845 | 793 |
| 846 bool GrDrawTarget::AutoReleaseGeometry::set(GrDrawTarget* target, | 794 bool GrDrawTarget::AutoReleaseGeometry::set(GrDrawTarget* target, |
| 847 int vertexCount, | 795 int vertexCount, |
| 796 size_t vertexStride, | |
| 848 int indexCount) { | 797 int indexCount) { |
| 849 this->reset(); | 798 this->reset(); |
| 850 fTarget = target; | 799 fTarget = target; |
| 851 bool success = true; | 800 bool success = true; |
| 852 if (fTarget) { | 801 if (fTarget) { |
| 853 success = target->reserveVertexAndIndexSpace(vertexCount, | 802 success = target->reserveVertexAndIndexSpace(vertexCount, |
| 803 vertexStride, | |
| 854 indexCount, | 804 indexCount, |
| 855 &fVertices, | 805 &fVertices, |
| 856 &fIndices); | 806 &fIndices); |
| 857 if (!success) { | 807 if (!success) { |
| 858 fTarget = NULL; | 808 fTarget = NULL; |
| 859 this->reset(); | 809 this->reset(); |
| 860 } | 810 } |
| 861 } | 811 } |
| 862 SkASSERT(success == SkToBool(fTarget)); | 812 SkASSERT(success == SkToBool(fTarget)); |
| 863 return success; | 813 return success; |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 959 return true; | 909 return true; |
| 960 } | 910 } |
| 961 | 911 |
| 962 if (!GrDrawTarget::canCopySurface(dst, src, clippedSrcRect, clippedDstPoint) ) { | 912 if (!GrDrawTarget::canCopySurface(dst, src, clippedSrcRect, clippedDstPoint) ) { |
| 963 return false; | 913 return false; |
| 964 } | 914 } |
| 965 | 915 |
| 966 GrRenderTarget* rt = dst->asRenderTarget(); | 916 GrRenderTarget* rt = dst->asRenderTarget(); |
| 967 GrTexture* tex = src->asTexture(); | 917 GrTexture* tex = src->asTexture(); |
| 968 | 918 |
| 969 GrDrawTarget::AutoStateRestore asr(this, kReset_ASRInit); | 919 GrDrawState drawState; |
| 970 this->drawState()->setRenderTarget(rt); | 920 drawState.setRenderTarget(rt); |
| 971 SkMatrix matrix; | 921 SkMatrix matrix; |
| 972 matrix.setTranslate(SkIntToScalar(clippedSrcRect.fLeft - clippedDstPoint.fX) , | 922 matrix.setTranslate(SkIntToScalar(clippedSrcRect.fLeft - clippedDstPoint.fX) , |
| 973 SkIntToScalar(clippedSrcRect.fTop - clippedDstPoint.fY)) ; | 923 SkIntToScalar(clippedSrcRect.fTop - clippedDstPoint.fY)) ; |
| 974 matrix.postIDiv(tex->width(), tex->height()); | 924 matrix.postIDiv(tex->width(), tex->height()); |
| 975 this->drawState()->addColorTextureProcessor(tex, matrix); | 925 drawState.addColorTextureProcessor(tex, matrix); |
| 976 SkIRect dstRect = SkIRect::MakeXYWH(clippedDstPoint.fX, | 926 SkIRect dstRect = SkIRect::MakeXYWH(clippedDstPoint.fX, |
| 977 clippedDstPoint.fY, | 927 clippedDstPoint.fY, |
| 978 clippedSrcRect.width(), | 928 clippedSrcRect.width(), |
| 979 clippedSrcRect.height()); | 929 clippedSrcRect.height()); |
| 980 this->drawSimpleRect(dstRect); | 930 this->drawSimpleRect(&drawState, dstRect); |
| 981 return true; | 931 return true; |
| 982 } | 932 } |
| 983 | 933 |
| 984 bool GrDrawTarget::canCopySurface(GrSurface* dst, | 934 bool GrDrawTarget::canCopySurface(const GrSurface* dst, |
| 985 GrSurface* src, | 935 const GrSurface* src, |
| 986 const SkIRect& srcRect, | 936 const SkIRect& srcRect, |
| 987 const SkIPoint& dstPoint) { | 937 const SkIPoint& dstPoint) { |
| 988 SkASSERT(dst); | 938 SkASSERT(dst); |
| 989 SkASSERT(src); | 939 SkASSERT(src); |
| 990 | 940 |
| 991 SkIRect clippedSrcRect; | 941 SkIRect clippedSrcRect; |
| 992 SkIPoint clippedDstPoint; | 942 SkIPoint clippedDstPoint; |
| 993 // If the rect is outside the src or dst then we're guaranteed success | 943 // If the rect is outside the src or dst then we're guaranteed success |
| 994 if (!clip_srcrect_and_dstpoint(dst, | 944 if (!clip_srcrect_and_dstpoint(dst, |
| 995 src, | 945 src, |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1180 id = static_cast<uint32_t>(sk_atomic_inc(&gUniqueID) + 1); | 1130 id = static_cast<uint32_t>(sk_atomic_inc(&gUniqueID) + 1); |
| 1181 } while (id == SK_InvalidUniqueID); | 1131 } while (id == SK_InvalidUniqueID); |
| 1182 return id; | 1132 return id; |
| 1183 } | 1133 } |
| 1184 | 1134 |
| 1185 //////////////////////////////////////////////////////////////////////////////// /////////////////// | 1135 //////////////////////////////////////////////////////////////////////////////// /////////////////// |
| 1186 | 1136 |
| 1187 bool GrClipTarget::setupClip(const SkRect* devBounds, | 1137 bool GrClipTarget::setupClip(const SkRect* devBounds, |
| 1188 GrDrawState::AutoRestoreEffects* are, | 1138 GrDrawState::AutoRestoreEffects* are, |
| 1189 GrDrawState::AutoRestoreStencil* ars, | 1139 GrDrawState::AutoRestoreStencil* ars, |
| 1140 GrDrawState* ds, | |
| 1190 GrClipMaskManager::ScissorState* scissorState) { | 1141 GrClipMaskManager::ScissorState* scissorState) { |
| 1191 return fClipMaskManager.setupClipping(this->getClip(), | 1142 return fClipMaskManager.setupClipping(ds, |
| 1192 devBounds, | |
| 1193 are, | 1143 are, |
| 1194 ars, | 1144 ars, |
| 1195 scissorState); | 1145 scissorState, |
| 1146 this->getClip(), | |
| 1147 devBounds); | |
| 1196 } | 1148 } |
| OLD | NEW |