| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 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 #include "GrContext.h" | 9 #include "GrContext.h" |
| 10 | 10 |
| (...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 409 size_t tmpRowBytes = 4 * width; | 409 size_t tmpRowBytes = 4 * width; |
| 410 tmpPixels.reset(width * height); | 410 tmpPixels.reset(width * height); |
| 411 if (!sw_convert_to_premul(srcConfig, width, height, rowBytes, bu
ffer, tmpRowBytes, | 411 if (!sw_convert_to_premul(srcConfig, width, height, rowBytes, bu
ffer, tmpRowBytes, |
| 412 tmpPixels.get())) { | 412 tmpPixels.get())) { |
| 413 return false; | 413 return false; |
| 414 } | 414 } |
| 415 rowBytes = tmpRowBytes; | 415 rowBytes = tmpRowBytes; |
| 416 buffer = tmpPixels.get(); | 416 buffer = tmpPixels.get(); |
| 417 applyPremulToSrc = false; | 417 applyPremulToSrc = false; |
| 418 } | 418 } |
| 419 if (!fGpu->writeTexturePixels(tempTexture, 0, 0, width, height, | 419 if (!fGpu->writePixels(tempTexture, 0, 0, width, height, |
| 420 tempDrawInfo.fTempSurfaceDesc.fConfig,
buffer, | 420 tempDrawInfo.fTempSurfaceDesc.fConfig, buffer
, |
| 421 rowBytes)) { | 421 rowBytes)) { |
| 422 return false; | 422 return false; |
| 423 } | 423 } |
| 424 SkMatrix matrix; | 424 SkMatrix matrix; |
| 425 matrix.setTranslate(SkIntToScalar(left), SkIntToScalar(top)); | 425 matrix.setTranslate(SkIntToScalar(left), SkIntToScalar(top)); |
| 426 GrDrawContext* drawContext = this->drawContext(); | 426 GrDrawContext* drawContext = this->drawContext(); |
| 427 if (!drawContext) { | 427 if (!drawContext) { |
| 428 return false; | 428 return false; |
| 429 } | 429 } |
| 430 paint.addColorProcessor(fp); | 430 paint.addColorProcessor(fp); |
| 431 SkRect rect = SkRect::MakeWH(SkIntToScalar(width), SkIntToScalar(hei
ght)); | 431 SkRect rect = SkRect::MakeWH(SkIntToScalar(width), SkIntToScalar(hei
ght)); |
| 432 drawContext->drawRect(renderTarget, GrClip::WideOpen(), paint, matri
x, rect, NULL); | 432 drawContext->drawRect(renderTarget, GrClip::WideOpen(), paint, matri
x, rect, NULL); |
| 433 | 433 |
| 434 if (kFlushWrites_PixelOp & pixelOpsFlags) { | 434 if (kFlushWrites_PixelOp & pixelOpsFlags) { |
| 435 this->flushSurfaceWrites(surface); | 435 this->flushSurfaceWrites(surface); |
| 436 } | 436 } |
| 437 } | 437 } |
| 438 } | 438 } |
| 439 if (!tempTexture) { | 439 if (!tempTexture) { |
| 440 SkASSERT(surface->asTexture()); | |
| 441 if (applyPremulToSrc) { | 440 if (applyPremulToSrc) { |
| 442 size_t tmpRowBytes = 4 * width; | 441 size_t tmpRowBytes = 4 * width; |
| 443 tmpPixels.reset(width * height); | 442 tmpPixels.reset(width * height); |
| 444 if (!sw_convert_to_premul(srcConfig, width, height, rowBytes, buffer
, tmpRowBytes, | 443 if (!sw_convert_to_premul(srcConfig, width, height, rowBytes, buffer
, tmpRowBytes, |
| 445 tmpPixels.get())) { | 444 tmpPixels.get())) { |
| 446 return false; | 445 return false; |
| 447 } | 446 } |
| 448 rowBytes = tmpRowBytes; | 447 rowBytes = tmpRowBytes; |
| 449 buffer = tmpPixels.get(); | 448 buffer = tmpPixels.get(); |
| 450 applyPremulToSrc = false; | 449 applyPremulToSrc = false; |
| 451 } | 450 } |
| 452 return fGpu->writeTexturePixels(surface->asTexture(), left, top, width,
height, srcConfig, | 451 return fGpu->writePixels(surface, left, top, width, height, srcConfig, b
uffer, rowBytes); |
| 453 buffer, rowBytes); | |
| 454 } | 452 } |
| 455 return true; | 453 return true; |
| 456 } | 454 } |
| 457 | 455 |
| 458 bool GrContext::readSurfacePixels(GrSurface* src, | 456 bool GrContext::readSurfacePixels(GrSurface* src, |
| 459 int left, int top, int width, int height, | 457 int left, int top, int width, int height, |
| 460 GrPixelConfig dstConfig, void* buffer, size_t
rowBytes, | 458 GrPixelConfig dstConfig, void* buffer, size_t
rowBytes, |
| 461 uint32_t flags) { | 459 uint32_t flags) { |
| 462 RETURN_FALSE_IF_ABANDONED | 460 RETURN_FALSE_IF_ABANDONED |
| 463 ASSERT_OWNED_RESOURCE(src); | 461 ASSERT_OWNED_RESOURCE(src); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 487 if (unpremul && !this->didFailPMUPMConversionTest()) { | 485 if (unpremul && !this->didFailPMUPMConversionTest()) { |
| 488 drawPreference = GrGpu::kCallerPrefersDraw_DrawPreference; | 486 drawPreference = GrGpu::kCallerPrefersDraw_DrawPreference; |
| 489 } | 487 } |
| 490 | 488 |
| 491 GrGpu::ReadPixelTempDrawInfo tempDrawInfo; | 489 GrGpu::ReadPixelTempDrawInfo tempDrawInfo; |
| 492 if (!fGpu->getReadPixelsInfo(src, width, height, rowBytes, dstConfig, &drawP
reference, | 490 if (!fGpu->getReadPixelsInfo(src, width, height, rowBytes, dstConfig, &drawP
reference, |
| 493 &tempDrawInfo)) { | 491 &tempDrawInfo)) { |
| 494 return false; | 492 return false; |
| 495 } | 493 } |
| 496 | 494 |
| 497 SkAutoTUnref<GrRenderTarget> rtToRead(SkSafeRef(src->asRenderTarget())); | 495 SkAutoTUnref<GrSurface> surfaceToRead(SkRef(src)); |
| 498 bool didTempDraw = false; | 496 bool didTempDraw = false; |
| 499 if (GrGpu::kNoDraw_DrawPreference != drawPreference) { | 497 if (GrGpu::kNoDraw_DrawPreference != drawPreference) { |
| 500 GrTextureProvider::ScratchTexMatch match = GrTextureProvider::kApprox_Sc
ratchTexMatch; | 498 GrTextureProvider::ScratchTexMatch match = GrTextureProvider::kApprox_Sc
ratchTexMatch; |
| 501 if (tempDrawInfo.fUseExactScratch) { | 499 if (tempDrawInfo.fUseExactScratch) { |
| 502 // We only respect this when the entire src is being read. Otherwise
we can trigger too | 500 // We only respect this when the entire src is being read. Otherwise
we can trigger too |
| 503 // many odd ball texture sizes and trash the cache. | 501 // many odd ball texture sizes and trash the cache. |
| 504 if (width == src->width() && height == src->height()) { | 502 if (width == src->width() && height == src->height()) { |
| 505 match = GrTextureProvider::kExact_ScratchTexMatch; | 503 match = GrTextureProvider::kExact_ScratchTexMatch; |
| 506 } | 504 } |
| 507 } | 505 } |
| (...skipping 22 matching lines...) Expand all Loading... |
| 530 fp.reset(GrConfigConversionEffect::Create( | 528 fp.reset(GrConfigConversionEffect::Create( |
| 531 paint.getProcessorDataManager(), src->asTexture(), tempDrawI
nfo.fSwapRAndB, | 529 paint.getProcessorDataManager(), src->asTexture(), tempDrawI
nfo.fSwapRAndB, |
| 532 GrConfigConversionEffect::kNone_PMConversion, textureMatrix)
); | 530 GrConfigConversionEffect::kNone_PMConversion, textureMatrix)
); |
| 533 } | 531 } |
| 534 if (fp) { | 532 if (fp) { |
| 535 paint.addColorProcessor(fp); | 533 paint.addColorProcessor(fp); |
| 536 SkRect rect = SkRect::MakeWH(SkIntToScalar(width), SkIntToScalar
(height)); | 534 SkRect rect = SkRect::MakeWH(SkIntToScalar(width), SkIntToScalar
(height)); |
| 537 GrDrawContext* drawContext = this->drawContext(); | 535 GrDrawContext* drawContext = this->drawContext(); |
| 538 drawContext->drawRect(temp->asRenderTarget(), GrClip::WideOpen()
, paint, | 536 drawContext->drawRect(temp->asRenderTarget(), GrClip::WideOpen()
, paint, |
| 539 SkMatrix::I(), rect, NULL); | 537 SkMatrix::I(), rect, NULL); |
| 540 rtToRead.reset(SkRef(temp->asRenderTarget())); | 538 surfaceToRead.reset(SkRef(temp.get())); |
| 541 left = 0; | 539 left = 0; |
| 542 top = 0; | 540 top = 0; |
| 543 didTempDraw = true; | 541 didTempDraw = true; |
| 544 } | 542 } |
| 545 } | 543 } |
| 546 } | 544 } |
| 547 | 545 |
| 548 if (GrGpu::kRequireDraw_DrawPreference == drawPreference && !didTempDraw) { | 546 if (GrGpu::kRequireDraw_DrawPreference == drawPreference && !didTempDraw) { |
| 549 return false; | 547 return false; |
| 550 } | 548 } |
| 551 GrPixelConfig configToRead = dstConfig; | 549 GrPixelConfig configToRead = dstConfig; |
| 552 if (didTempDraw) { | 550 if (didTempDraw) { |
| 553 this->flushSurfaceWrites(rtToRead); | 551 this->flushSurfaceWrites(surfaceToRead); |
| 554 // We swapped R and B while doing the temp draw. Swap back on the read. | 552 // We swapped R and B while doing the temp draw. Swap back on the read. |
| 555 if (tempDrawInfo.fSwapRAndB) { | 553 if (tempDrawInfo.fSwapRAndB) { |
| 556 configToRead = GrPixelConfigSwapRAndB(dstConfig); | 554 configToRead = GrPixelConfigSwapRAndB(dstConfig); |
| 557 } | 555 } |
| 558 } | 556 } |
| 559 if (!fGpu->readPixels(rtToRead, left, top, width, height, configToRead, buff
er, rowBytes)) { | 557 if (!fGpu->readPixels(surfaceToRead, left, top, width, height, configToRead,
buffer, |
| 558 rowBytes)) { |
| 560 return false; | 559 return false; |
| 561 } | 560 } |
| 562 | 561 |
| 563 // Perform umpremul conversion if we weren't able to perform it as a draw. | 562 // Perform umpremul conversion if we weren't able to perform it as a draw. |
| 564 if (unpremul) { | 563 if (unpremul) { |
| 565 SkDstPixelInfo dstPI; | 564 SkDstPixelInfo dstPI; |
| 566 if (!GrPixelConfig2ColorAndProfileType(dstConfig, &dstPI.fColorType, NUL
L)) { | 565 if (!GrPixelConfig2ColorAndProfileType(dstConfig, &dstPI.fColorType, NUL
L)) { |
| 567 return false; | 566 return false; |
| 568 } | 567 } |
| 569 dstPI.fAlphaType = kUnpremul_SkAlphaType; | 568 dstPI.fAlphaType = kUnpremul_SkAlphaType; |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 753 ////////////////////////////////////////////////////////////////////////////// | 752 ////////////////////////////////////////////////////////////////////////////// |
| 754 | 753 |
| 755 void GrContext::addGpuTraceMarker(const GrGpuTraceMarker* marker) { | 754 void GrContext::addGpuTraceMarker(const GrGpuTraceMarker* marker) { |
| 756 fGpu->addGpuTraceMarker(marker); | 755 fGpu->addGpuTraceMarker(marker); |
| 757 } | 756 } |
| 758 | 757 |
| 759 void GrContext::removeGpuTraceMarker(const GrGpuTraceMarker* marker) { | 758 void GrContext::removeGpuTraceMarker(const GrGpuTraceMarker* marker) { |
| 760 fGpu->removeGpuTraceMarker(marker); | 759 fGpu->removeGpuTraceMarker(marker); |
| 761 } | 760 } |
| 762 | 761 |
| OLD | NEW |