| 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 #include "GrGpu.h" | 10 #include "GrGpu.h" |
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 259 6, | 259 6, |
| 260 MAX_QUADS, | 260 MAX_QUADS, |
| 261 4); | 261 4); |
| 262 } | 262 } |
| 263 | 263 |
| 264 return fQuadIndexBuffer; | 264 return fQuadIndexBuffer; |
| 265 } | 265 } |
| 266 | 266 |
| 267 //////////////////////////////////////////////////////////////////////////////// | 267 //////////////////////////////////////////////////////////////////////////////// |
| 268 | 268 |
| 269 bool GrGpu::setupClipAndFlushState(DrawType type, | |
| 270 const GrDeviceCoordTexture* dstCopy, | |
| 271 const SkRect* devBounds, | |
| 272 GrDrawState::AutoRestoreEffects* are, | |
| 273 GrDrawState::AutoRestoreStencil* ars) { | |
| 274 GrClipMaskManager::ScissorState scissorState; | |
| 275 if (!fClipMaskManager.setupClipping(this->getClip(), | |
| 276 devBounds, | |
| 277 are, | |
| 278 ars, | |
| 279 &scissorState)) { | |
| 280 return false; | |
| 281 } | |
| 282 | |
| 283 if (!this->flushGraphicsState(type, scissorState, dstCopy)) { | |
| 284 return false; | |
| 285 } | |
| 286 | |
| 287 return true; | |
| 288 } | |
| 289 | |
| 290 //////////////////////////////////////////////////////////////////////////////// | |
| 291 | |
| 292 void GrGpu::geometrySourceWillPush() { | 269 void GrGpu::geometrySourceWillPush() { |
| 293 const GeometrySrcState& geoSrc = this->getGeomSrc(); | 270 const GeometrySrcState& geoSrc = this->getGeomSrc(); |
| 294 if (kReserved_GeometrySrcType == geoSrc.fVertexSrc) { | 271 if (kReserved_GeometrySrcType == geoSrc.fVertexSrc) { |
| 295 this->finalizeReservedVertices(); | 272 this->finalizeReservedVertices(); |
| 296 } | 273 } |
| 297 if (kReserved_GeometrySrcType == geoSrc.fIndexSrc) { | 274 if (kReserved_GeometrySrcType == geoSrc.fIndexSrc) { |
| 298 this->finalizeReservedIndices(); | 275 this->finalizeReservedIndices(); |
| 299 } | 276 } |
| 300 GeometryPoolState& newState = fGeomPoolStateStack.push_back(); | 277 GeometryPoolState& newState = fGeomPoolStateStack.push_back(); |
| 301 #ifdef SK_DEBUG | 278 #ifdef SK_DEBUG |
| 302 newState.fPoolVertexBuffer = (GrVertexBuffer*)DEBUG_INVAL_BUFFER; | 279 newState.fPoolVertexBuffer = (GrVertexBuffer*)DEBUG_INVAL_BUFFER; |
| 303 newState.fPoolStartVertex = DEBUG_INVAL_START_IDX; | 280 newState.fPoolStartVertex = DEBUG_INVAL_START_IDX; |
| 304 newState.fPoolIndexBuffer = (GrIndexBuffer*)DEBUG_INVAL_BUFFER; | 281 newState.fPoolIndexBuffer = (GrIndexBuffer*)DEBUG_INVAL_BUFFER; |
| 305 newState.fPoolStartIndex = DEBUG_INVAL_START_IDX; | 282 newState.fPoolStartIndex = DEBUG_INVAL_START_IDX; |
| 306 #else | 283 #else |
| 307 (void) newState; // silence compiler warning | 284 (void) newState; // silence compiler warning |
| 308 #endif | 285 #endif |
| 309 } | 286 } |
| 310 | 287 |
| 311 void GrGpu::geometrySourceWillPop(const GeometrySrcState& restoredState) { | 288 void GrGpu::geometrySourceWillPop(const GeometrySrcState& restoredState) { |
| 312 // if popping last entry then pops are unbalanced with pushes | 289 // if popping last entry then pops are unbalanced with pushes |
| 313 SkASSERT(fGeomPoolStateStack.count() > 1); | 290 SkASSERT(fGeomPoolStateStack.count() > 1); |
| 314 fGeomPoolStateStack.pop_back(); | 291 fGeomPoolStateStack.pop_back(); |
| 315 } | 292 } |
| 316 | 293 |
| 317 void GrGpu::onDraw(const DrawInfo& info) { | 294 void GrGpu::onDraw(const DrawInfo& info, const GrClipMaskManager::ScissorState&
scissorState) { |
| 318 this->handleDirtyContext(); | 295 this->handleDirtyContext(); |
| 319 GrDrawState::AutoRestoreEffects are; | 296 if (!this->flushGraphicsState(PrimTypeToDrawType(info.primitiveType()), |
| 320 GrDrawState::AutoRestoreStencil ars; | 297 scissorState, |
| 321 if (!this->setupClipAndFlushState(PrimTypeToDrawType(info.primitiveType()), | 298 info.getDstCopy())) { |
| 322 info.getDstCopy(), | |
| 323 info.getDevBounds(), | |
| 324 &are, | |
| 325 &ars)) { | |
| 326 return; | 299 return; |
| 327 } | 300 } |
| 328 this->onGpuDraw(info); | 301 this->onGpuDraw(info); |
| 329 } | 302 } |
| 330 | 303 |
| 331 | 304 void GrGpu::onStencilPath(const GrPath* path, |
| 332 // TODO hack | 305 const GrClipMaskManager::ScissorState& scissorState, |
| 333 static const GrStencilSettings& winding_path_stencil_settings() { | 306 const GrStencilSettings& stencilSettings) { |
| 334 GR_STATIC_CONST_SAME_STENCIL_STRUCT(gSettings, | |
| 335 kIncClamp_StencilOp, | |
| 336 kIncClamp_StencilOp, | |
| 337 kAlwaysIfInClip_StencilFunc, | |
| 338 0xFFFF, 0xFFFF, 0xFFFF); | |
| 339 return *GR_CONST_STENCIL_SETTINGS_PTR_FROM_STRUCT_PTR(&gSettings); | |
| 340 } | |
| 341 | |
| 342 static const GrStencilSettings& even_odd_path_stencil_settings() { | |
| 343 GR_STATIC_CONST_SAME_STENCIL_STRUCT(gSettings, | |
| 344 kInvert_StencilOp, | |
| 345 kInvert_StencilOp, | |
| 346 kAlwaysIfInClip_StencilFunc, | |
| 347 0xFFFF, 0xFFFF, 0xFFFF); | |
| 348 return *GR_CONST_STENCIL_SETTINGS_PTR_FROM_STRUCT_PTR(&gSettings); | |
| 349 } | |
| 350 | |
| 351 static void get_path_stencil_settings_for_filltype(GrPathRendering::FillType fil
l, | |
| 352 GrStencilSettings* outStencil
Settings) { | |
| 353 | |
| 354 switch (fill) { | |
| 355 default: | |
| 356 SkFAIL("Unexpected path fill."); | |
| 357 case GrPathRendering::kWinding_FillType: | |
| 358 *outStencilSettings = winding_path_stencil_settings(); | |
| 359 break; | |
| 360 case GrPathRendering::kEvenOdd_FillType: | |
| 361 *outStencilSettings = even_odd_path_stencil_settings(); | |
| 362 break; | |
| 363 } | |
| 364 } | |
| 365 | |
| 366 void GrGpu::onStencilPath(const GrPath* path, GrPathRendering::FillType fill) { | |
| 367 this->handleDirtyContext(); | 307 this->handleDirtyContext(); |
| 368 | 308 |
| 369 GrDrawState::AutoRestoreEffects are; | 309 if (!this->flushGraphicsState(kStencilPath_DrawType, scissorState, NULL)) { |
| 370 GrDrawState::AutoRestoreStencil ars; | |
| 371 if (!this->setupClipAndFlushState(kStencilPath_DrawType, NULL, NULL, &are, &
ars)) { | |
| 372 return; | 310 return; |
| 373 } | 311 } |
| 374 | 312 |
| 375 GrStencilSettings stencilSettings; | |
| 376 get_path_stencil_settings_for_filltype(fill, &stencilSettings); | |
| 377 fClipMaskManager.adjustPathStencilParams(&stencilSettings); | |
| 378 | |
| 379 this->pathRendering()->stencilPath(path, stencilSettings); | 313 this->pathRendering()->stencilPath(path, stencilSettings); |
| 380 } | 314 } |
| 381 | 315 |
| 382 | 316 |
| 383 void GrGpu::onDrawPath(const GrPath* path, GrPathRendering::FillType fill, | 317 void GrGpu::onDrawPath(const GrPath* path, |
| 318 const GrClipMaskManager::ScissorState& scissorState, |
| 319 const GrStencilSettings& stencilSettings, |
| 384 const GrDeviceCoordTexture* dstCopy) { | 320 const GrDeviceCoordTexture* dstCopy) { |
| 385 this->handleDirtyContext(); | 321 this->handleDirtyContext(); |
| 386 | 322 |
| 387 drawState()->setDefaultVertexAttribs(); | 323 drawState()->setDefaultVertexAttribs(); |
| 388 | 324 |
| 389 GrDrawState::AutoRestoreEffects are; | 325 if (!this->flushGraphicsState(kDrawPath_DrawType, scissorState, dstCopy)) { |
| 390 GrDrawState::AutoRestoreStencil ars; | |
| 391 if (!this->setupClipAndFlushState(kDrawPath_DrawType, dstCopy, NULL, &are, &
ars)) { | |
| 392 return; | 326 return; |
| 393 } | 327 } |
| 394 | 328 |
| 395 GrStencilSettings stencilSettings; | |
| 396 get_path_stencil_settings_for_filltype(fill, &stencilSettings); | |
| 397 fClipMaskManager.adjustPathStencilParams(&stencilSettings); | |
| 398 | |
| 399 this->pathRendering()->drawPath(path, stencilSettings); | 329 this->pathRendering()->drawPath(path, stencilSettings); |
| 400 } | 330 } |
| 401 | 331 |
| 402 void GrGpu::onDrawPaths(const GrPathRange* pathRange, | 332 void GrGpu::onDrawPaths(const GrPathRange* pathRange, |
| 403 const uint32_t indices[], int count, | 333 const uint32_t indices[], |
| 404 const float transforms[], PathTransformType transformsTy
pe, | 334 int count, |
| 405 GrPathRendering::FillType fill, const GrDeviceCoordTextu
re* dstCopy) { | 335 const float transforms[], |
| 336 PathTransformType transformsType, |
| 337 const GrClipMaskManager::ScissorState& scissorState, |
| 338 const GrStencilSettings& stencilSettings, |
| 339 const GrDeviceCoordTexture* dstCopy) { |
| 406 this->handleDirtyContext(); | 340 this->handleDirtyContext(); |
| 407 | 341 |
| 408 drawState()->setDefaultVertexAttribs(); | 342 drawState()->setDefaultVertexAttribs(); |
| 409 | 343 |
| 410 GrDrawState::AutoRestoreEffects are; | 344 if (!this->flushGraphicsState(kDrawPaths_DrawType, scissorState, dstCopy)) { |
| 411 GrDrawState::AutoRestoreStencil ars; | |
| 412 if (!this->setupClipAndFlushState(kDrawPaths_DrawType, dstCopy, NULL, &are,
&ars)) { | |
| 413 return; | 345 return; |
| 414 } | 346 } |
| 415 | 347 |
| 416 GrStencilSettings stencilSettings; | |
| 417 get_path_stencil_settings_for_filltype(fill, &stencilSettings); | |
| 418 fClipMaskManager.adjustPathStencilParams(&stencilSettings); | |
| 419 | |
| 420 pathRange->willDrawPaths(indices, count); | 348 pathRange->willDrawPaths(indices, count); |
| 421 this->pathRendering()->drawPaths(pathRange, indices, count, transforms, tran
sformsType, | 349 this->pathRendering()->drawPaths(pathRange, indices, count, transforms, tran
sformsType, |
| 422 stencilSettings); | 350 stencilSettings); |
| 423 } | 351 } |
| 424 | 352 |
| 425 void GrGpu::finalizeReservedVertices() { | 353 void GrGpu::finalizeReservedVertices() { |
| 426 SkASSERT(fVertexPool); | 354 SkASSERT(fVertexPool); |
| 427 fVertexPool->unmap(); | 355 fVertexPool->unmap(); |
| 428 } | 356 } |
| 429 | 357 |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 505 --fVertexPoolUseCnt; | 433 --fVertexPoolUseCnt; |
| 506 } | 434 } |
| 507 | 435 |
| 508 void GrGpu::releaseReservedIndexSpace() { | 436 void GrGpu::releaseReservedIndexSpace() { |
| 509 const GeometrySrcState& geoSrc = this->getGeomSrc(); | 437 const GeometrySrcState& geoSrc = this->getGeomSrc(); |
| 510 SkASSERT(kReserved_GeometrySrcType == geoSrc.fIndexSrc); | 438 SkASSERT(kReserved_GeometrySrcType == geoSrc.fIndexSrc); |
| 511 size_t bytes = geoSrc.fIndexCount * sizeof(uint16_t); | 439 size_t bytes = geoSrc.fIndexCount * sizeof(uint16_t); |
| 512 fIndexPool->putBack(bytes); | 440 fIndexPool->putBack(bytes); |
| 513 --fIndexPoolUseCnt; | 441 --fIndexPoolUseCnt; |
| 514 } | 442 } |
| OLD | NEW |