| 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 509 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 520 srcPI.fColorType = dstPI.fColorType; | 520 srcPI.fColorType = dstPI.fColorType; |
| 521 srcPI.fAlphaType = kPremul_SkAlphaType; | 521 srcPI.fAlphaType = kPremul_SkAlphaType; |
| 522 srcPI.fPixels = buffer; | 522 srcPI.fPixels = buffer; |
| 523 srcPI.fRowBytes = rowBytes; | 523 srcPI.fRowBytes = rowBytes; |
| 524 | 524 |
| 525 return srcPI.convertPixelsTo(&dstPI, width, height); | 525 return srcPI.convertPixelsTo(&dstPI, width, height); |
| 526 } | 526 } |
| 527 return true; | 527 return true; |
| 528 } | 528 } |
| 529 | 529 |
| 530 bool GrContext::applyGamma(GrRenderTarget* dst, GrTexture* src, SkScalar gamma){ | |
| 531 ASSERT_SINGLE_OWNER | |
| 532 RETURN_FALSE_IF_ABANDONED | |
| 533 ASSERT_OWNED_RESOURCE(dst); | |
| 534 ASSERT_OWNED_RESOURCE(src); | |
| 535 GR_AUDIT_TRAIL_AUTO_FRAME(&fAuditTrail, "GrContext::applyGamma"); | |
| 536 | |
| 537 // Dimensions must match exactly. | |
| 538 if (dst->width() != src->width() || dst->height() != src->height()) { | |
| 539 return false; | |
| 540 } | |
| 541 | |
| 542 // TODO: Supply color space? | |
| 543 sk_sp<GrDrawContext> drawContext(this->makeDrawContext(sk_ref_sp(dst), nullp
tr)); | |
| 544 if (!drawContext) { | |
| 545 return false; | |
| 546 } | |
| 547 | |
| 548 GrPaint paint; | |
| 549 paint.addColorTextureProcessor(src, nullptr, GrCoordTransform::MakeDivByText
ureWHMatrix(src)); | |
| 550 if (!SkScalarNearlyEqual(gamma, 1.0f)) { | |
| 551 paint.addColorFragmentProcessor(GrGammaEffect::Make(gamma)); | |
| 552 } | |
| 553 paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode); | |
| 554 paint.setGammaCorrect(true); | |
| 555 | |
| 556 SkRect rect; | |
| 557 src->getBoundsRect(&rect); | |
| 558 drawContext->drawRect(GrNoClip(), paint, SkMatrix::I(), rect); | |
| 559 | |
| 560 this->flushSurfaceWrites(dst); | |
| 561 return true; | |
| 562 } | |
| 563 | |
| 564 void GrContext::prepareSurfaceForExternalIO(GrSurface* surface) { | 530 void GrContext::prepareSurfaceForExternalIO(GrSurface* surface) { |
| 565 ASSERT_SINGLE_OWNER | 531 ASSERT_SINGLE_OWNER |
| 566 RETURN_IF_ABANDONED | 532 RETURN_IF_ABANDONED |
| 567 SkASSERT(surface); | 533 SkASSERT(surface); |
| 568 ASSERT_OWNED_RESOURCE(surface); | 534 ASSERT_OWNED_RESOURCE(surface); |
| 569 if (surface->surfacePriv().hasPendingIO()) { | 535 if (surface->surfacePriv().hasPendingIO()) { |
| 570 this->flush(); | 536 this->flush(); |
| 571 } | 537 } |
| 572 GrRenderTarget* rt = surface->asRenderTarget(); | 538 GrRenderTarget* rt = surface->asRenderTarget(); |
| 573 if (fGpu && rt) { | 539 if (fGpu && rt) { |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 763 ASSERT_SINGLE_OWNER | 729 ASSERT_SINGLE_OWNER |
| 764 fResourceCache->setLimits(maxTextures, maxTextureBytes); | 730 fResourceCache->setLimits(maxTextures, maxTextureBytes); |
| 765 } | 731 } |
| 766 | 732 |
| 767 ////////////////////////////////////////////////////////////////////////////// | 733 ////////////////////////////////////////////////////////////////////////////// |
| 768 | 734 |
| 769 void GrContext::dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const { | 735 void GrContext::dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const { |
| 770 ASSERT_SINGLE_OWNER | 736 ASSERT_SINGLE_OWNER |
| 771 fResourceCache->dumpMemoryStatistics(traceMemoryDump); | 737 fResourceCache->dumpMemoryStatistics(traceMemoryDump); |
| 772 } | 738 } |
| OLD | NEW |