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: Supply color space? |
robertphillips
2016/07/21 19:22:41
Soup up this comment
e.g., this matches the none-
| |
361 sk_sp<GrDrawContext> drawContext(this->drawContext(sk_ref_sp(renderT arget), nullptr)); | |
361 if (!drawContext) { | 362 if (!drawContext) { |
362 return false; | 363 return false; |
363 } | 364 } |
364 GrPaint paint; | 365 GrPaint paint; |
365 paint.addColorFragmentProcessor(std::move(fp)); | 366 paint.addColorFragmentProcessor(std::move(fp)); |
366 paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode); | 367 paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode); |
367 paint.setAllowSRGBInputs(true); | 368 paint.setAllowSRGBInputs(true); |
368 SkRect rect = SkRect::MakeWH(SkIntToScalar(width), SkIntToScalar(hei ght)); | 369 SkRect rect = SkRect::MakeWH(SkIntToScalar(width), SkIntToScalar(hei ght)); |
369 drawContext->drawRect(GrNoClip(), paint, matrix, rect, nullptr); | 370 drawContext->drawRect(GrNoClip(), paint, matrix, rect, nullptr); |
370 | 371 |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
437 SkAutoTUnref<GrSurface> surfaceToRead(SkRef(src)); | 438 SkAutoTUnref<GrSurface> surfaceToRead(SkRef(src)); |
438 bool didTempDraw = false; | 439 bool didTempDraw = false; |
439 if (GrGpu::kNoDraw_DrawPreference != drawPreference) { | 440 if (GrGpu::kNoDraw_DrawPreference != drawPreference) { |
440 if (SkBackingFit::kExact == tempDrawInfo.fTempSurfaceFit) { | 441 if (SkBackingFit::kExact == tempDrawInfo.fTempSurfaceFit) { |
441 // We only respect this when the entire src is being read. Otherwise we can trigger too | 442 // 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. | 443 // many odd ball texture sizes and trash the cache. |
443 if (width != src->width() || height != src->height()) { | 444 if (width != src->width() || height != src->height()) { |
444 tempDrawInfo.fTempSurfaceFit= SkBackingFit::kApprox; | 445 tempDrawInfo.fTempSurfaceFit= SkBackingFit::kApprox; |
445 } | 446 } |
446 } | 447 } |
448 // TODO: Supply color space? | |
447 sk_sp<GrDrawContext> tempDC = this->newDrawContext(tempDrawInfo.fTempSur faceFit, | 449 sk_sp<GrDrawContext> tempDC = this->newDrawContext(tempDrawInfo.fTempSur faceFit, |
448 tempDrawInfo.fTempSur faceDesc.fWidth, | 450 tempDrawInfo.fTempSur faceDesc.fWidth, |
449 tempDrawInfo.fTempSur faceDesc.fHeight, | 451 tempDrawInfo.fTempSur faceDesc.fHeight, |
450 tempDrawInfo.fTempSur faceDesc.fConfig, | 452 tempDrawInfo.fTempSur faceDesc.fConfig, |
453 nullptr, | |
451 tempDrawInfo.fTempSur faceDesc.fSampleCnt, | 454 tempDrawInfo.fTempSur faceDesc.fSampleCnt, |
452 tempDrawInfo.fTempSur faceDesc.fOrigin); | 455 tempDrawInfo.fTempSur faceDesc.fOrigin); |
453 if (tempDC) { | 456 if (tempDC) { |
454 SkMatrix textureMatrix; | 457 SkMatrix textureMatrix; |
455 textureMatrix.setTranslate(SkIntToScalar(left), SkIntToScalar(top)); | 458 textureMatrix.setTranslate(SkIntToScalar(left), SkIntToScalar(top)); |
456 textureMatrix.postIDiv(src->width(), src->height()); | 459 textureMatrix.postIDiv(src->width(), src->height()); |
457 sk_sp<GrFragmentProcessor> fp; | 460 sk_sp<GrFragmentProcessor> fp; |
458 if (unpremul) { | 461 if (unpremul) { |
459 fp = this->createPMToUPMEffect(src->asTexture(), tempDrawInfo.fS wizzle, | 462 fp = this->createPMToUPMEffect(src->asTexture(), tempDrawInfo.fS wizzle, |
460 textureMatrix); | 463 textureMatrix); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
527 ASSERT_OWNED_RESOURCE(src); | 530 ASSERT_OWNED_RESOURCE(src); |
528 GR_AUDIT_TRAIL_AUTO_FRAME(&fAuditTrail, "GrContext::applyGamma"); | 531 GR_AUDIT_TRAIL_AUTO_FRAME(&fAuditTrail, "GrContext::applyGamma"); |
529 | 532 |
530 // Dimensions must match exactly. | 533 // Dimensions must match exactly. |
531 if (dst->width() != src->width() || dst->height() != src->height()) { | 534 if (dst->width() != src->width() || dst->height() != src->height()) { |
532 return false; | 535 return false; |
533 } | 536 } |
534 | 537 |
535 SkSurfaceProps props(SkSurfaceProps::kGammaCorrect_Flag, | 538 SkSurfaceProps props(SkSurfaceProps::kGammaCorrect_Flag, |
536 SkSurfaceProps::kLegacyFontHost_InitType); | 539 SkSurfaceProps::kLegacyFontHost_InitType); |
537 sk_sp<GrDrawContext> drawContext(this->drawContext(sk_ref_sp(dst), &props)); | 540 // TODO: Supply color space? |
541 sk_sp<GrDrawContext> drawContext(this->drawContext(sk_ref_sp(dst), nullptr, &props)); | |
538 if (!drawContext) { | 542 if (!drawContext) { |
539 return false; | 543 return false; |
540 } | 544 } |
541 | 545 |
542 GrPaint paint; | 546 GrPaint paint; |
543 paint.addColorTextureProcessor(src, nullptr, GrCoordTransform::MakeDivByText ureWHMatrix(src)); | 547 paint.addColorTextureProcessor(src, nullptr, GrCoordTransform::MakeDivByText ureWHMatrix(src)); |
544 if (!SkScalarNearlyEqual(gamma, 1.0f)) { | 548 if (!SkScalarNearlyEqual(gamma, 1.0f)) { |
545 paint.addColorFragmentProcessor(GrGammaEffect::Make(gamma)); | 549 paint.addColorFragmentProcessor(GrGammaEffect::Make(gamma)); |
546 } | 550 } |
547 paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode); | 551 paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
589 return false; | 593 return false; |
590 } | 594 } |
591 // If we don't have an RT for the dst then we won't have a GrDrawContext to insert the | 595 // 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 | 596 // 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 | 597 // (GrCopyContext?) that has the subset of GrDrawContext operations that should be |
594 // allowed on textures that aren't render targets. | 598 // 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. | 599 // For now we just flush any writes to the src and issue an immediate co py to the dst. |
596 src->flushWrites(); | 600 src->flushWrites(); |
597 return fGpu->copySurface(dst, src, clippedSrcRect, clippedDstPoint); | 601 return fGpu->copySurface(dst, src, clippedSrcRect, clippedDstPoint); |
598 } | 602 } |
599 sk_sp<GrDrawContext> drawContext(this->drawContext(sk_ref_sp(dst->asRenderTa rget()))); | 603 sk_sp<GrDrawContext> drawContext(this->drawContext(sk_ref_sp(dst->asRenderTa rget()), nullptr)); |
600 if (!drawContext) { | 604 if (!drawContext) { |
601 return false; | 605 return false; |
602 } | 606 } |
603 | 607 |
604 if (!drawContext->copySurface(src, srcRect, dstPoint)) { | 608 if (!drawContext->copySurface(src, srcRect, dstPoint)) { |
605 return false; | 609 return false; |
606 } | 610 } |
607 return true; | 611 return true; |
608 } | 612 } |
609 | 613 |
(...skipping 19 matching lines...) Expand all Loading... | |
629 chosenSampleCount = 4; | 633 chosenSampleCount = 4; |
630 } else { | 634 } else { |
631 chosenSampleCount = 16; | 635 chosenSampleCount = 16; |
632 } | 636 } |
633 } | 637 } |
634 return chosenSampleCount <= fGpu->caps()->maxSampleCount() ? chosenSampleCou nt : 0; | 638 return chosenSampleCount <= fGpu->caps()->maxSampleCount() ? chosenSampleCou nt : 0; |
635 } | 639 } |
636 | 640 |
637 | 641 |
638 sk_sp<GrDrawContext> GrContext::drawContext(sk_sp<GrRenderTarget> rt, | 642 sk_sp<GrDrawContext> GrContext::drawContext(sk_sp<GrRenderTarget> rt, |
643 sk_sp<SkColorSpace> colorSpace, | |
639 const SkSurfaceProps* surfaceProps) { | 644 const SkSurfaceProps* surfaceProps) { |
640 ASSERT_SINGLE_OWNER | 645 ASSERT_SINGLE_OWNER |
641 return fDrawingManager->drawContext(std::move(rt), surfaceProps); | 646 return fDrawingManager->drawContext(std::move(rt), std::move(colorSpace), su rfaceProps); |
642 } | 647 } |
643 | 648 |
644 sk_sp<GrDrawContext> GrContext::newDrawContext(SkBackingFit fit, | 649 sk_sp<GrDrawContext> GrContext::newDrawContext(SkBackingFit fit, |
645 int width, int height, | 650 int width, int height, |
646 GrPixelConfig config, | 651 GrPixelConfig config, |
652 sk_sp<SkColorSpace> colorSpace, | |
647 int sampleCnt, | 653 int sampleCnt, |
648 GrSurfaceOrigin origin, | 654 GrSurfaceOrigin origin, |
649 const SkSurfaceProps* surfaceProp s, | 655 const SkSurfaceProps* surfaceProp s, |
650 SkBudgeted budgeted) { | 656 SkBudgeted budgeted) { |
651 GrSurfaceDesc desc; | 657 GrSurfaceDesc desc; |
652 desc.fFlags = kRenderTarget_GrSurfaceFlag; | 658 desc.fFlags = kRenderTarget_GrSurfaceFlag; |
653 desc.fOrigin = origin; | 659 desc.fOrigin = origin; |
654 desc.fWidth = width; | 660 desc.fWidth = width; |
655 desc.fHeight = height; | 661 desc.fHeight = height; |
656 desc.fConfig = config; | 662 desc.fConfig = config; |
657 desc.fSampleCnt = sampleCnt; | 663 desc.fSampleCnt = sampleCnt; |
658 | 664 |
659 sk_sp<GrTexture> tex; | 665 sk_sp<GrTexture> tex; |
660 if (SkBackingFit::kExact == fit) { | 666 if (SkBackingFit::kExact == fit) { |
661 tex.reset(this->textureProvider()->createTexture(desc, budgeted)); | 667 tex.reset(this->textureProvider()->createTexture(desc, budgeted)); |
662 } else { | 668 } else { |
663 tex.reset(this->textureProvider()->createApproxTexture(desc)); | 669 tex.reset(this->textureProvider()->createApproxTexture(desc)); |
664 } | 670 } |
665 if (!tex) { | 671 if (!tex) { |
666 return nullptr; | 672 return nullptr; |
667 } | 673 } |
668 | 674 |
669 sk_sp<GrDrawContext> drawContext(this->drawContext(sk_ref_sp(tex->asRenderTa rget()), | 675 sk_sp<GrDrawContext> drawContext(this->drawContext(sk_ref_sp(tex->asRenderTa rget()), |
670 surfaceProps)); | 676 std::move(colorSpace), su rfaceProps)); |
671 if (!drawContext) { | 677 if (!drawContext) { |
672 return nullptr; | 678 return nullptr; |
673 } | 679 } |
674 | 680 |
675 return drawContext; | 681 return drawContext; |
676 } | 682 } |
677 | 683 |
678 bool GrContext::abandoned() const { | 684 bool GrContext::abandoned() const { |
679 ASSERT_SINGLE_OWNER | 685 ASSERT_SINGLE_OWNER |
680 return fDrawingManager->wasAbandoned(); | 686 return fDrawingManager->wasAbandoned(); |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
755 ASSERT_SINGLE_OWNER | 761 ASSERT_SINGLE_OWNER |
756 fResourceCache->setLimits(maxTextures, maxTextureBytes); | 762 fResourceCache->setLimits(maxTextures, maxTextureBytes); |
757 } | 763 } |
758 | 764 |
759 ////////////////////////////////////////////////////////////////////////////// | 765 ////////////////////////////////////////////////////////////////////////////// |
760 | 766 |
761 void GrContext::dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const { | 767 void GrContext::dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const { |
762 ASSERT_SINGLE_OWNER | 768 ASSERT_SINGLE_OWNER |
763 fResourceCache->dumpMemoryStatistics(traceMemoryDump); | 769 fResourceCache->dumpMemoryStatistics(traceMemoryDump); |
764 } | 770 } |
OLD | NEW |