Index: src/gpu/GrContext.cpp |
diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp |
index c223a602132743d9a7baffcdb98c94e6cd39cee2..b316f924a93c6e059269e1c4fee7ec39f1eb41b2 100644 |
--- a/src/gpu/GrContext.cpp |
+++ b/src/gpu/GrContext.cpp |
@@ -19,6 +19,7 @@ |
#include "SkGrPriv.h" |
#include "batches/GrCopySurfaceBatch.h" |
+#include "effects/GrColorSpaceEffect.h" |
#include "effects/GrConfigConversionEffect.h" |
#include "text/GrTextBlobCache.h" |
@@ -528,6 +529,63 @@ bool GrContext::readSurfacePixels(GrSurface* src, |
return true; |
} |
+bool GrContext::writeSurfacePixelsWithColorSpace(GrSurface* surface, |
+ int left, int top, int width, int height, |
+ GrPixelConfig srcConfig, |
+ const SkColorSpace* srcColorSpace, |
+ const SkColorSpace* dstColorSpace, |
+ const void* buffer, size_t rowBytes, |
+ uint32_t colorSpaceOpsFlags) { |
+ ASSERT_SINGLE_OWNER |
+ RETURN_FALSE_IF_ABANDONED |
+ ASSERT_OWNED_RESOURCE(surface); |
+ SkASSERT(surface); |
+ GR_AUDIT_TRAIL_AUTO_FRAME(&fAuditTrail, "GrContext::writeSurfacePixelsWithColorSpace"); |
+ |
+ if (surface->surfacePriv().hasPendingIO()) { |
+ this->flush(); |
+ } |
+ |
+ GrSurfaceDesc srcDesc; |
+ srcDesc.fWidth = width; |
+ srcDesc.fHeight = height; |
+ srcDesc.fConfig = srcConfig; |
+ |
+ SkAutoTUnref<GrTexture> tempTexture( |
+ this->textureProvider()->createTexture(srcDesc, SkBudgeted::kYes, buffer, rowBytes)); |
+ if (!tempTexture) { |
+ return false; |
+ } |
+ |
+ SkAutoTUnref<const GrFragmentProcessor> fp; |
+ fp.reset(GrColorSpaceEffect::Create(tempTexture, |
+ srcColorSpace, dstColorSpace, colorSpaceOpsFlags)); |
+ |
+ GrRenderTarget* renderTarget = surface->asRenderTarget(); |
+ SkASSERT(renderTarget); |
+ |
+ SkMatrix matrix; |
+ matrix.setTranslate(SkIntToScalar(left), SkIntToScalar(top)); |
+ SkSurfaceProps props(SkSurfaceProps::kGammaCorrect_Flag, |
+ SkSurfaceProps::kLegacyFontHost_InitType); |
+ SkAutoTUnref<GrDrawContext> drawContext(this->drawContext(renderTarget, &props)); |
+ if (!drawContext) { |
+ return false; |
+ } |
+ |
+ GrPaint paint; |
+ paint.addColorFragmentProcessor(fp); |
+ paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode); |
+ paint.setGammaCorrect(true); |
+ |
+ SkRect rect = SkRect::MakeWH(SkIntToScalar(width), SkIntToScalar(height)); |
+ drawContext->drawRect(GrClip::WideOpen(), paint, matrix, rect, nullptr); |
+ |
+ this->flushSurfaceWrites(surface); |
+ |
+ return true; |
+} |
+ |
void GrContext::prepareSurfaceForExternalIO(GrSurface* surface) { |
ASSERT_SINGLE_OWNER |
RETURN_IF_ABANDONED |