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" |
11 #include "GrDrawContext.h" | 11 #include "GrDrawContext.h" |
12 #include "GrLayerCache.h" | 12 #include "GrLayerCache.h" |
13 #include "GrResourceCache.h" | 13 #include "GrResourceCache.h" |
14 #include "GrResourceProvider.h" | 14 #include "GrResourceProvider.h" |
15 #include "GrSoftwarePathRenderer.h" | 15 #include "GrSoftwarePathRenderer.h" |
16 #include "GrSurfacePriv.h" | 16 #include "GrSurfacePriv.h" |
17 | 17 |
18 #include "SkConfig8888.h" | 18 #include "SkConfig8888.h" |
19 #include "SkGrPriv.h" | 19 #include "SkGrPriv.h" |
20 | 20 |
21 #include "batches/GrCopySurfaceBatch.h" | 21 #include "batches/GrCopySurfaceBatch.h" |
22 #include "effects/GrConfigConversionEffect.h" | 22 #include "effects/GrConfigConversionEffect.h" |
23 #include "effects/GrGammaEffect.h" | |
23 #include "text/GrTextBlobCache.h" | 24 #include "text/GrTextBlobCache.h" |
24 | 25 |
25 #define ASSERT_OWNED_RESOURCE(R) SkASSERT(!(R) || (R)->getContext() == this) | 26 #define ASSERT_OWNED_RESOURCE(R) SkASSERT(!(R) || (R)->getContext() == this) |
26 #define ASSERT_SINGLE_OWNER \ | 27 #define ASSERT_SINGLE_OWNER \ |
27 SkDEBUGCODE(GrSingleOwner::AutoEnforce debug_SingleOwner(&fSingleOwner);) | 28 SkDEBUGCODE(GrSingleOwner::AutoEnforce debug_SingleOwner(&fSingleOwner);) |
28 #define RETURN_IF_ABANDONED if (fDrawingManager->abandoned()) { return; } | 29 #define RETURN_IF_ABANDONED if (fDrawingManager->abandoned()) { return; } |
29 #define RETURN_FALSE_IF_ABANDONED if (fDrawingManager->abandoned()) { return fal se; } | 30 #define RETURN_FALSE_IF_ABANDONED if (fDrawingManager->abandoned()) { return fal se; } |
30 #define RETURN_NULL_IF_ABANDONED if (fDrawingManager->abandoned()) { return null ptr; } | 31 #define RETURN_NULL_IF_ABANDONED if (fDrawingManager->abandoned()) { return null ptr; } |
31 | 32 |
32 //////////////////////////////////////////////////////////////////////////////// | 33 //////////////////////////////////////////////////////////////////////////////// |
(...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
522 srcPI.fColorType = dstPI.fColorType; | 523 srcPI.fColorType = dstPI.fColorType; |
523 srcPI.fAlphaType = kPremul_SkAlphaType; | 524 srcPI.fAlphaType = kPremul_SkAlphaType; |
524 srcPI.fPixels = buffer; | 525 srcPI.fPixels = buffer; |
525 srcPI.fRowBytes = rowBytes; | 526 srcPI.fRowBytes = rowBytes; |
526 | 527 |
527 return srcPI.convertPixelsTo(&dstPI, width, height); | 528 return srcPI.convertPixelsTo(&dstPI, width, height); |
528 } | 529 } |
529 return true; | 530 return true; |
530 } | 531 } |
531 | 532 |
533 bool GrContext::applyGamma(GrRenderTarget* dst, GrTexture* src, SkScalar gamma){ | |
534 ASSERT_SINGLE_OWNER | |
535 RETURN_FALSE_IF_ABANDONED | |
536 ASSERT_OWNED_RESOURCE(dst); | |
537 ASSERT_OWNED_RESOURCE(src); | |
538 GR_AUDIT_TRAIL_AUTO_FRAME(&fAuditTrail, "GrContext::applyGamma"); | |
539 | |
540 SkSurfaceProps props(SkSurfaceProps::kGammaCorrect_Flag, | |
541 SkSurfaceProps::kLegacyFontHost_InitType); | |
542 sk_sp<GrDrawContext> drawContext(this->drawContext(sk_ref_sp(dst), &props)); | |
543 if (!drawContext) { | |
544 return false; | |
545 } | |
546 | |
547 GrPaint paint; | |
548 if (SkScalarNearlyEqual(gamma, 1.0f)) { | |
bsalomon
2016/04/29 18:27:20
Maybe just call copySurface here? Should we also d
Brian Osman
2016/05/02 21:02:45
I tried falling back to copySurface, but that code
bsalomon
2016/05/02 21:17:40
Is that what we want copySurface to do? Maybe we s
| |
549 paint.addColorTextureProcessor(src, GrCoordTransform::MakeDivByTextureWH Matrix(src)); | |
550 } else { | |
551 SkAutoTUnref<const GrFragmentProcessor> fp; | |
552 fp.reset(GrGammaEffect::Create(src, gamma)); | |
553 paint.addColorFragmentProcessor(fp); | |
554 } | |
555 paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode); | |
556 paint.setGammaCorrect(true); | |
557 | |
558 SkRect rect; | |
559 src->getBoundsRect(&rect); | |
560 drawContext->drawRect(GrClip::WideOpen(), paint, SkMatrix::I(), rect, nullpt r); | |
561 | |
562 this->flushSurfaceWrites(dst); | |
563 | |
564 return true; | |
565 } | |
566 | |
532 void GrContext::prepareSurfaceForExternalIO(GrSurface* surface) { | 567 void GrContext::prepareSurfaceForExternalIO(GrSurface* surface) { |
533 ASSERT_SINGLE_OWNER | 568 ASSERT_SINGLE_OWNER |
534 RETURN_IF_ABANDONED | 569 RETURN_IF_ABANDONED |
535 SkASSERT(surface); | 570 SkASSERT(surface); |
536 ASSERT_OWNED_RESOURCE(surface); | 571 ASSERT_OWNED_RESOURCE(surface); |
537 if (surface->surfacePriv().hasPendingIO()) { | 572 if (surface->surfacePriv().hasPendingIO()) { |
538 this->flush(); | 573 this->flush(); |
539 } | 574 } |
540 GrRenderTarget* rt = surface->asRenderTarget(); | 575 GrRenderTarget* rt = surface->asRenderTarget(); |
541 if (fGpu && rt) { | 576 if (fGpu && rt) { |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
726 ASSERT_SINGLE_OWNER | 761 ASSERT_SINGLE_OWNER |
727 fResourceCache->setLimits(maxTextures, maxTextureBytes); | 762 fResourceCache->setLimits(maxTextures, maxTextureBytes); |
728 } | 763 } |
729 | 764 |
730 ////////////////////////////////////////////////////////////////////////////// | 765 ////////////////////////////////////////////////////////////////////////////// |
731 | 766 |
732 void GrContext::dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const { | 767 void GrContext::dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const { |
733 ASSERT_SINGLE_OWNER | 768 ASSERT_SINGLE_OWNER |
734 fResourceCache->dumpMemoryStatistics(traceMemoryDump); | 769 fResourceCache->dumpMemoryStatistics(traceMemoryDump); |
735 } | 770 } |
OLD | NEW |