OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "GrContext.h" | 8 #include "GrContext.h" |
9 #include "GrContextOptions.h" | 9 #include "GrContextOptions.h" |
10 #include "GrDrawingManager.h" | 10 #include "GrDrawingManager.h" |
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
350 buffer = tmpPixels.get(); | 350 buffer = tmpPixels.get(); |
351 applyPremulToSrc = false; | 351 applyPremulToSrc = false; |
352 } | 352 } |
353 if (!fGpu->writePixels(tempTexture, 0, 0, width, height, | 353 if (!fGpu->writePixels(tempTexture, 0, 0, width, height, |
354 tempDrawInfo.fWriteConfig, buffer, | 354 tempDrawInfo.fWriteConfig, buffer, |
355 rowBytes)) { | 355 rowBytes)) { |
356 return false; | 356 return false; |
357 } | 357 } |
358 SkMatrix matrix; | 358 SkMatrix matrix; |
359 matrix.setTranslate(SkIntToScalar(left), SkIntToScalar(top)); | 359 matrix.setTranslate(SkIntToScalar(left), SkIntToScalar(top)); |
360 sk_sp<GrDrawContext> drawContext(this->drawContext(sk_ref_sp(renderT
arget))); | 360 // TODO: Need to decide the semantics of this function for color spa
ces. Do we support |
| 361 // conversion from a passed-in color space? For now, specifying null
ptr means that this |
| 362 // path will do no conversion, so it will match the behavior of the
non-draw path. |
| 363 sk_sp<GrDrawContext> drawContext(this->drawContext(sk_ref_sp(renderT
arget), nullptr)); |
361 if (!drawContext) { | 364 if (!drawContext) { |
362 return false; | 365 return false; |
363 } | 366 } |
364 GrPaint paint; | 367 GrPaint paint; |
365 paint.addColorFragmentProcessor(std::move(fp)); | 368 paint.addColorFragmentProcessor(std::move(fp)); |
366 paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode); | 369 paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode); |
367 paint.setAllowSRGBInputs(true); | 370 paint.setAllowSRGBInputs(true); |
368 SkRect rect = SkRect::MakeWH(SkIntToScalar(width), SkIntToScalar(hei
ght)); | 371 SkRect rect = SkRect::MakeWH(SkIntToScalar(width), SkIntToScalar(hei
ght)); |
369 drawContext->drawRect(GrNoClip(), paint, matrix, rect, nullptr); | 372 drawContext->drawRect(GrNoClip(), paint, matrix, rect, nullptr); |
370 | 373 |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
437 SkAutoTUnref<GrSurface> surfaceToRead(SkRef(src)); | 440 SkAutoTUnref<GrSurface> surfaceToRead(SkRef(src)); |
438 bool didTempDraw = false; | 441 bool didTempDraw = false; |
439 if (GrGpu::kNoDraw_DrawPreference != drawPreference) { | 442 if (GrGpu::kNoDraw_DrawPreference != drawPreference) { |
440 if (SkBackingFit::kExact == tempDrawInfo.fTempSurfaceFit) { | 443 if (SkBackingFit::kExact == tempDrawInfo.fTempSurfaceFit) { |
441 // We only respect this when the entire src is being read. Otherwise
we can trigger too | 444 // We only respect this when the entire src is being read. Otherwise
we can trigger too |
442 // many odd ball texture sizes and trash the cache. | 445 // many odd ball texture sizes and trash the cache. |
443 if (width != src->width() || height != src->height()) { | 446 if (width != src->width() || height != src->height()) { |
444 tempDrawInfo.fTempSurfaceFit= SkBackingFit::kApprox; | 447 tempDrawInfo.fTempSurfaceFit= SkBackingFit::kApprox; |
445 } | 448 } |
446 } | 449 } |
| 450 // TODO: Need to decide the semantics of this function for color spaces.
Do we support |
| 451 // conversion to a passed-in color space? For now, specifying nullptr me
ans that this |
| 452 // path will do no conversion, so it will match the behavior of the non-
draw path. |
447 sk_sp<GrDrawContext> tempDC = this->newDrawContext(tempDrawInfo.fTempSur
faceFit, | 453 sk_sp<GrDrawContext> tempDC = this->newDrawContext(tempDrawInfo.fTempSur
faceFit, |
448 tempDrawInfo.fTempSur
faceDesc.fWidth, | 454 tempDrawInfo.fTempSur
faceDesc.fWidth, |
449 tempDrawInfo.fTempSur
faceDesc.fHeight, | 455 tempDrawInfo.fTempSur
faceDesc.fHeight, |
450 tempDrawInfo.fTempSur
faceDesc.fConfig, | 456 tempDrawInfo.fTempSur
faceDesc.fConfig, |
| 457 nullptr, |
451 tempDrawInfo.fTempSur
faceDesc.fSampleCnt, | 458 tempDrawInfo.fTempSur
faceDesc.fSampleCnt, |
452 tempDrawInfo.fTempSur
faceDesc.fOrigin); | 459 tempDrawInfo.fTempSur
faceDesc.fOrigin); |
453 if (tempDC) { | 460 if (tempDC) { |
454 SkMatrix textureMatrix; | 461 SkMatrix textureMatrix; |
455 textureMatrix.setTranslate(SkIntToScalar(left), SkIntToScalar(top)); | 462 textureMatrix.setTranslate(SkIntToScalar(left), SkIntToScalar(top)); |
456 textureMatrix.postIDiv(src->width(), src->height()); | 463 textureMatrix.postIDiv(src->width(), src->height()); |
457 sk_sp<GrFragmentProcessor> fp; | 464 sk_sp<GrFragmentProcessor> fp; |
458 if (unpremul) { | 465 if (unpremul) { |
459 fp = this->createPMToUPMEffect(src->asTexture(), tempDrawInfo.fS
wizzle, | 466 fp = this->createPMToUPMEffect(src->asTexture(), tempDrawInfo.fS
wizzle, |
460 textureMatrix); | 467 textureMatrix); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
527 ASSERT_OWNED_RESOURCE(src); | 534 ASSERT_OWNED_RESOURCE(src); |
528 GR_AUDIT_TRAIL_AUTO_FRAME(&fAuditTrail, "GrContext::applyGamma"); | 535 GR_AUDIT_TRAIL_AUTO_FRAME(&fAuditTrail, "GrContext::applyGamma"); |
529 | 536 |
530 // Dimensions must match exactly. | 537 // Dimensions must match exactly. |
531 if (dst->width() != src->width() || dst->height() != src->height()) { | 538 if (dst->width() != src->width() || dst->height() != src->height()) { |
532 return false; | 539 return false; |
533 } | 540 } |
534 | 541 |
535 SkSurfaceProps props(SkSurfaceProps::kGammaCorrect_Flag, | 542 SkSurfaceProps props(SkSurfaceProps::kGammaCorrect_Flag, |
536 SkSurfaceProps::kLegacyFontHost_InitType); | 543 SkSurfaceProps::kLegacyFontHost_InitType); |
537 sk_sp<GrDrawContext> drawContext(this->drawContext(sk_ref_sp(dst), &props)); | 544 // TODO: Supply color space? |
| 545 sk_sp<GrDrawContext> drawContext(this->drawContext(sk_ref_sp(dst), nullptr,
&props)); |
538 if (!drawContext) { | 546 if (!drawContext) { |
539 return false; | 547 return false; |
540 } | 548 } |
541 | 549 |
542 GrPaint paint; | 550 GrPaint paint; |
543 paint.addColorTextureProcessor(src, nullptr, GrCoordTransform::MakeDivByText
ureWHMatrix(src)); | 551 paint.addColorTextureProcessor(src, nullptr, GrCoordTransform::MakeDivByText
ureWHMatrix(src)); |
544 if (!SkScalarNearlyEqual(gamma, 1.0f)) { | 552 if (!SkScalarNearlyEqual(gamma, 1.0f)) { |
545 paint.addColorFragmentProcessor(GrGammaEffect::Make(gamma)); | 553 paint.addColorFragmentProcessor(GrGammaEffect::Make(gamma)); |
546 } | 554 } |
547 paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode); | 555 paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
589 return false; | 597 return false; |
590 } | 598 } |
591 // If we don't have an RT for the dst then we won't have a GrDrawContext
to insert the | 599 // If we don't have an RT for the dst then we won't have a GrDrawContext
to insert the |
592 // the copy surface into. In the future we plan to have a more limited C
ontext type | 600 // the copy surface into. In the future we plan to have a more limited C
ontext type |
593 // (GrCopyContext?) that has the subset of GrDrawContext operations that
should be | 601 // (GrCopyContext?) that has the subset of GrDrawContext operations that
should be |
594 // allowed on textures that aren't render targets. | 602 // allowed on textures that aren't render targets. |
595 // For now we just flush any writes to the src and issue an immediate co
py to the dst. | 603 // For now we just flush any writes to the src and issue an immediate co
py to the dst. |
596 src->flushWrites(); | 604 src->flushWrites(); |
597 return fGpu->copySurface(dst, src, clippedSrcRect, clippedDstPoint); | 605 return fGpu->copySurface(dst, src, clippedSrcRect, clippedDstPoint); |
598 } | 606 } |
599 sk_sp<GrDrawContext> drawContext(this->drawContext(sk_ref_sp(dst->asRenderTa
rget()))); | 607 sk_sp<GrDrawContext> drawContext(this->drawContext(sk_ref_sp(dst->asRenderTa
rget()), nullptr)); |
600 if (!drawContext) { | 608 if (!drawContext) { |
601 return false; | 609 return false; |
602 } | 610 } |
603 | 611 |
604 if (!drawContext->copySurface(src, srcRect, dstPoint)) { | 612 if (!drawContext->copySurface(src, srcRect, dstPoint)) { |
605 return false; | 613 return false; |
606 } | 614 } |
607 return true; | 615 return true; |
608 } | 616 } |
609 | 617 |
(...skipping 19 matching lines...) Expand all Loading... |
629 chosenSampleCount = 4; | 637 chosenSampleCount = 4; |
630 } else { | 638 } else { |
631 chosenSampleCount = 16; | 639 chosenSampleCount = 16; |
632 } | 640 } |
633 } | 641 } |
634 return chosenSampleCount <= fGpu->caps()->maxSampleCount() ? chosenSampleCou
nt : 0; | 642 return chosenSampleCount <= fGpu->caps()->maxSampleCount() ? chosenSampleCou
nt : 0; |
635 } | 643 } |
636 | 644 |
637 | 645 |
638 sk_sp<GrDrawContext> GrContext::drawContext(sk_sp<GrRenderTarget> rt, | 646 sk_sp<GrDrawContext> GrContext::drawContext(sk_sp<GrRenderTarget> rt, |
| 647 sk_sp<SkColorSpace> colorSpace, |
639 const SkSurfaceProps* surfaceProps)
{ | 648 const SkSurfaceProps* surfaceProps)
{ |
640 ASSERT_SINGLE_OWNER | 649 ASSERT_SINGLE_OWNER |
641 return fDrawingManager->drawContext(std::move(rt), surfaceProps); | 650 return fDrawingManager->drawContext(std::move(rt), std::move(colorSpace), su
rfaceProps); |
642 } | 651 } |
643 | 652 |
644 sk_sp<GrDrawContext> GrContext::newDrawContext(SkBackingFit fit, | 653 sk_sp<GrDrawContext> GrContext::newDrawContext(SkBackingFit fit, |
645 int width, int height, | 654 int width, int height, |
646 GrPixelConfig config, | 655 GrPixelConfig config, |
| 656 sk_sp<SkColorSpace> colorSpace, |
647 int sampleCnt, | 657 int sampleCnt, |
648 GrSurfaceOrigin origin, | 658 GrSurfaceOrigin origin, |
649 const SkSurfaceProps* surfaceProp
s, | 659 const SkSurfaceProps* surfaceProp
s, |
650 SkBudgeted budgeted) { | 660 SkBudgeted budgeted) { |
651 GrSurfaceDesc desc; | 661 GrSurfaceDesc desc; |
652 desc.fFlags = kRenderTarget_GrSurfaceFlag; | 662 desc.fFlags = kRenderTarget_GrSurfaceFlag; |
653 desc.fOrigin = origin; | 663 desc.fOrigin = origin; |
654 desc.fWidth = width; | 664 desc.fWidth = width; |
655 desc.fHeight = height; | 665 desc.fHeight = height; |
656 desc.fConfig = config; | 666 desc.fConfig = config; |
657 desc.fSampleCnt = sampleCnt; | 667 desc.fSampleCnt = sampleCnt; |
658 | 668 |
659 sk_sp<GrTexture> tex; | 669 sk_sp<GrTexture> tex; |
660 if (SkBackingFit::kExact == fit) { | 670 if (SkBackingFit::kExact == fit) { |
661 tex.reset(this->textureProvider()->createTexture(desc, budgeted)); | 671 tex.reset(this->textureProvider()->createTexture(desc, budgeted)); |
662 } else { | 672 } else { |
663 tex.reset(this->textureProvider()->createApproxTexture(desc)); | 673 tex.reset(this->textureProvider()->createApproxTexture(desc)); |
664 } | 674 } |
665 if (!tex) { | 675 if (!tex) { |
666 return nullptr; | 676 return nullptr; |
667 } | 677 } |
668 | 678 |
669 sk_sp<GrDrawContext> drawContext(this->drawContext(sk_ref_sp(tex->asRenderTa
rget()), | 679 sk_sp<GrDrawContext> drawContext(this->drawContext(sk_ref_sp(tex->asRenderTa
rget()), |
670 surfaceProps)); | 680 std::move(colorSpace), su
rfaceProps)); |
671 if (!drawContext) { | 681 if (!drawContext) { |
672 return nullptr; | 682 return nullptr; |
673 } | 683 } |
674 | 684 |
675 return drawContext; | 685 return drawContext; |
676 } | 686 } |
677 | 687 |
678 bool GrContext::abandoned() const { | 688 bool GrContext::abandoned() const { |
679 ASSERT_SINGLE_OWNER | 689 ASSERT_SINGLE_OWNER |
680 return fDrawingManager->wasAbandoned(); | 690 return fDrawingManager->wasAbandoned(); |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
755 ASSERT_SINGLE_OWNER | 765 ASSERT_SINGLE_OWNER |
756 fResourceCache->setLimits(maxTextures, maxTextureBytes); | 766 fResourceCache->setLimits(maxTextures, maxTextureBytes); |
757 } | 767 } |
758 | 768 |
759 ////////////////////////////////////////////////////////////////////////////// | 769 ////////////////////////////////////////////////////////////////////////////// |
760 | 770 |
761 void GrContext::dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const { | 771 void GrContext::dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const { |
762 ASSERT_SINGLE_OWNER | 772 ASSERT_SINGLE_OWNER |
763 fResourceCache->dumpMemoryStatistics(traceMemoryDump); | 773 fResourceCache->dumpMemoryStatistics(traceMemoryDump); |
764 } | 774 } |
OLD | NEW |