| 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 // Dimensions must match exactly. |
| 541 if (dst->width() != src->width() || dst->height() != src->height()) { |
| 542 return false; |
| 543 } |
| 544 |
| 545 SkSurfaceProps props(SkSurfaceProps::kGammaCorrect_Flag, |
| 546 SkSurfaceProps::kLegacyFontHost_InitType); |
| 547 sk_sp<GrDrawContext> drawContext(this->drawContext(sk_ref_sp(dst), &props)); |
| 548 if (!drawContext) { |
| 549 return false; |
| 550 } |
| 551 |
| 552 GrPaint paint; |
| 553 if (SkScalarNearlyEqual(gamma, 1.0f)) { |
| 554 paint.addColorTextureProcessor(src, GrCoordTransform::MakeDivByTextureWH
Matrix(src)); |
| 555 } else { |
| 556 SkAutoTUnref<const GrFragmentProcessor> fp; |
| 557 fp.reset(GrGammaEffect::Create(src, gamma)); |
| 558 paint.addColorFragmentProcessor(fp); |
| 559 } |
| 560 paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode); |
| 561 paint.setGammaCorrect(true); |
| 562 |
| 563 SkRect rect; |
| 564 src->getBoundsRect(&rect); |
| 565 drawContext->drawRect(GrClip::WideOpen(), paint, SkMatrix::I(), rect); |
| 566 |
| 567 this->flushSurfaceWrites(dst); |
| 568 return true; |
| 569 } |
| 570 |
| 532 void GrContext::prepareSurfaceForExternalIO(GrSurface* surface) { | 571 void GrContext::prepareSurfaceForExternalIO(GrSurface* surface) { |
| 533 ASSERT_SINGLE_OWNER | 572 ASSERT_SINGLE_OWNER |
| 534 RETURN_IF_ABANDONED | 573 RETURN_IF_ABANDONED |
| 535 SkASSERT(surface); | 574 SkASSERT(surface); |
| 536 ASSERT_OWNED_RESOURCE(surface); | 575 ASSERT_OWNED_RESOURCE(surface); |
| 537 if (surface->surfacePriv().hasPendingIO()) { | 576 if (surface->surfacePriv().hasPendingIO()) { |
| 538 this->flush(); | 577 this->flush(); |
| 539 } | 578 } |
| 540 GrRenderTarget* rt = surface->asRenderTarget(); | 579 GrRenderTarget* rt = surface->asRenderTarget(); |
| 541 if (fGpu && rt) { | 580 if (fGpu && rt) { |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 726 ASSERT_SINGLE_OWNER | 765 ASSERT_SINGLE_OWNER |
| 727 fResourceCache->setLimits(maxTextures, maxTextureBytes); | 766 fResourceCache->setLimits(maxTextures, maxTextureBytes); |
| 728 } | 767 } |
| 729 | 768 |
| 730 ////////////////////////////////////////////////////////////////////////////// | 769 ////////////////////////////////////////////////////////////////////////////// |
| 731 | 770 |
| 732 void GrContext::dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const { | 771 void GrContext::dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const { |
| 733 ASSERT_SINGLE_OWNER | 772 ASSERT_SINGLE_OWNER |
| 734 fResourceCache->dumpMemoryStatistics(traceMemoryDump); | 773 fResourceCache->dumpMemoryStatistics(traceMemoryDump); |
| 735 } | 774 } |
| OLD | NEW |