| OLD | NEW |
| 1 | |
| 2 /* | 1 /* |
| 3 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
| 4 * | 3 * |
| 5 * 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 |
| 6 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 7 */ | 6 */ |
| 8 | 7 |
| 9 #include "GrContext.h" | 8 #include "GrContext.h" |
| 10 | 9 |
| 11 #include "GrBatchFontCache.h" | 10 #include "GrBatchFontCache.h" |
| 12 #include "GrBatchFlushState.h" | 11 #include "GrBatchFlushState.h" |
| 13 #include "GrBatchTest.h" | 12 #include "GrBatchTest.h" |
| 14 #include "GrCaps.h" | 13 #include "GrCaps.h" |
| 15 #include "GrContextOptions.h" | 14 #include "GrContextOptions.h" |
| 16 #include "GrDefaultGeoProcFactory.h" | 15 #include "GrDefaultGeoProcFactory.h" |
| 17 #include "GrDrawContext.h" | 16 #include "GrDrawContext.h" |
| 18 #include "GrDrawTarget.h" | 17 #include "GrDrawTarget.h" |
| 19 #include "GrGpuResource.h" | 18 #include "GrGpuResource.h" |
| 20 #include "GrGpuResourcePriv.h" | 19 #include "GrGpuResourcePriv.h" |
| 21 #include "GrGpu.h" | 20 #include "GrGpu.h" |
| 22 #include "GrIndexBuffer.h" | 21 #include "GrIndexBuffer.h" |
| 23 #include "GrLayerCache.h" | 22 #include "GrLayerCache.h" |
| 24 #include "GrOvalRenderer.h" | 23 #include "GrOvalRenderer.h" |
| 25 #include "GrPathRenderer.h" | 24 #include "GrPathRenderer.h" |
| 26 #include "GrPathUtils.h" | 25 #include "GrPathUtils.h" |
| 27 #include "GrRenderTargetPriv.h" | 26 #include "GrRenderTargetPriv.h" |
| 28 #include "GrResourceCache.h" | 27 #include "GrResourceCache.h" |
| 29 #include "GrResourceProvider.h" | 28 #include "GrResourceProvider.h" |
| 30 #include "GrSoftwarePathRenderer.h" | 29 #include "GrSoftwarePathRenderer.h" |
| 30 #include "GrStencilAndCoverTextContext.h" |
| 31 #include "GrStrokeInfo.h" | 31 #include "GrStrokeInfo.h" |
| 32 #include "GrSurfacePriv.h" | 32 #include "GrSurfacePriv.h" |
| 33 #include "GrTextBlobCache.h" | 33 #include "GrTextBlobCache.h" |
| 34 #include "GrTexturePriv.h" | 34 #include "GrTexturePriv.h" |
| 35 #include "GrTracing.h" | 35 #include "GrTracing.h" |
| 36 #include "GrVertices.h" | 36 #include "GrVertices.h" |
| 37 #include "SkDashPathPriv.h" | 37 #include "SkDashPathPriv.h" |
| 38 #include "SkConfig8888.h" | 38 #include "SkConfig8888.h" |
| 39 #include "SkGr.h" | 39 #include "SkGrPriv.h" |
| 40 #include "SkRRect.h" | 40 #include "SkRRect.h" |
| 41 #include "SkStrokeRec.h" | 41 #include "SkStrokeRec.h" |
| 42 #include "SkSurfacePriv.h" | 42 #include "SkSurfacePriv.h" |
| 43 #include "SkTLazy.h" | 43 #include "SkTLazy.h" |
| 44 #include "SkTLS.h" | 44 #include "SkTLS.h" |
| 45 #include "SkTraceEvent.h" | 45 #include "SkTraceEvent.h" |
| 46 #include "SkTypes.h" |
| 46 | 47 |
| 47 #include "batches/GrBatch.h" | 48 #include "batches/GrBatch.h" |
| 48 | 49 |
| 49 #include "effects/GrConfigConversionEffect.h" | 50 #include "effects/GrConfigConversionEffect.h" |
| 50 #include "effects/GrDashingEffect.h" | 51 #include "effects/GrDashingEffect.h" |
| 51 #include "effects/GrSingleTextureEffect.h" | 52 #include "effects/GrSingleTextureEffect.h" |
| 52 | 53 |
| 53 #define ASSERT_OWNED_RESOURCE(R) SkASSERT(!(R) || (R)->getContext() == this) | 54 #define ASSERT_OWNED_RESOURCE(R) SkASSERT(!(R) || (R)->getContext() == this) |
| 54 #define RETURN_IF_ABANDONED if (fDrawingMgr.abandoned()) { return; } | 55 #define RETURN_IF_ABANDONED if (fDrawingMgr.abandoned()) { return; } |
| 55 #define RETURN_FALSE_IF_ABANDONED if (fDrawingMgr.abandoned()) { return false; } | 56 #define RETURN_FALSE_IF_ABANDONED if (fDrawingMgr.abandoned()) { return false; } |
| 56 #define RETURN_NULL_IF_ABANDONED if (fDrawingMgr.abandoned()) { return nullptr;
} | 57 #define RETURN_NULL_IF_ABANDONED if (fDrawingMgr.abandoned()) { return nullptr;
} |
| 57 | 58 |
| 58 | 59 |
| 59 //////////////////////////////////////////////////////////////////////////////// | 60 //////////////////////////////////////////////////////////////////////////////// |
| 60 | 61 |
| 61 void GrContext::DrawingMgr::init(GrContext* context) { | 62 void GrContext::DrawingMgr::init(GrContext* context) { |
| 62 fContext = context; | 63 fContext = context; |
| 63 fDrawTarget = new GrDrawTarget(context->getGpu(), context->resourceProvider(
)); | 64 fDrawTarget = new GrDrawTarget(context->getGpu(), context->resourceProvider(
)); |
| 64 } | 65 } |
| 65 | 66 |
| 66 void GrContext::DrawingMgr::cleanup() { | 67 void GrContext::DrawingMgr::cleanup() { |
| 67 SkSafeSetNull(fDrawTarget); | 68 SkSafeSetNull(fDrawTarget); |
| 69 delete fNVPRTextContext; |
| 70 fNVPRTextContext = nullptr; |
| 68 for (int i = 0; i < kNumPixelGeometries; ++i) { | 71 for (int i = 0; i < kNumPixelGeometries; ++i) { |
| 69 SkSafeSetNull(fDrawContext[i][0]); | 72 delete fTextContexts[i][0]; |
| 70 SkSafeSetNull(fDrawContext[i][1]); | 73 fTextContexts[i][0] = nullptr; |
| 74 delete fTextContexts[i][1]; |
| 75 fTextContexts[i][1] = nullptr; |
| 71 } | 76 } |
| 72 } | 77 } |
| 73 | 78 |
| 74 GrContext::DrawingMgr::~DrawingMgr() { | 79 GrContext::DrawingMgr::~DrawingMgr() { |
| 75 this->cleanup(); | 80 this->cleanup(); |
| 76 } | 81 } |
| 77 | 82 |
| 78 void GrContext::DrawingMgr::abandon() { | 83 void GrContext::DrawingMgr::abandon() { |
| 79 SkSafeSetNull(fDrawTarget); | 84 this->cleanup(); |
| 80 for (int i = 0; i < kNumPixelGeometries; ++i) { | |
| 81 for (int j = 0; j < kNumDFTOptions; ++j) { | |
| 82 if (fDrawContext[i][j]) { | |
| 83 SkSafeSetNull(fDrawContext[i][j]->fDrawTarget); | |
| 84 SkSafeSetNull(fDrawContext[i][j]); | |
| 85 } | |
| 86 } | |
| 87 } | |
| 88 } | |
| 89 | |
| 90 void GrContext::DrawingMgr::purgeResources() { | |
| 91 if (fDrawTarget) { | |
| 92 fDrawTarget->purgeResources(); | |
| 93 } | |
| 94 } | 85 } |
| 95 | 86 |
| 96 void GrContext::DrawingMgr::reset() { | 87 void GrContext::DrawingMgr::reset() { |
| 97 if (fDrawTarget) { | 88 if (fDrawTarget) { |
| 98 fDrawTarget->reset(); | 89 fDrawTarget->reset(); |
| 99 } | 90 } |
| 100 } | 91 } |
| 101 | 92 |
| 102 void GrContext::DrawingMgr::flush() { | 93 void GrContext::DrawingMgr::flush() { |
| 103 if (fDrawTarget) { | 94 if (fDrawTarget) { |
| 104 fDrawTarget->flush(); | 95 fDrawTarget->flush(); |
| 105 } | 96 } |
| 106 } | 97 } |
| 107 | 98 |
| 108 GrDrawContext* GrContext::DrawingMgr::drawContext(const SkSurfaceProps* surfaceP
rops) { | 99 GrTextContext* GrContext::DrawingMgr::textContext(const SkSurfaceProps& props, |
| 100 GrRenderTarget* rt) { |
| 109 if (this->abandoned()) { | 101 if (this->abandoned()) { |
| 110 return nullptr; | 102 return nullptr; |
| 111 } | 103 } |
| 112 | 104 |
| 113 const SkSurfaceProps props(SkSurfacePropsCopyOrDefault(surfaceProps)); | 105 SkASSERT(props.pixelGeometry() < kNumPixelGeometries); |
| 106 bool useDIF = props.isUseDeviceIndependentFonts(); |
| 114 | 107 |
| 115 SkASSERT(props.pixelGeometry() < kNumPixelGeometries); | 108 if (useDIF && fContext->caps()->shaderCaps()->pathRenderingSupport() && |
| 116 if (!fDrawContext[props.pixelGeometry()][props.isUseDeviceIndependentFonts()
]) { | 109 rt->isStencilBufferMultisampled()) { |
| 117 fDrawContext[props.pixelGeometry()][props.isUseDeviceIndependentFonts()]
= | 110 GrStencilAttachment* sb = fContext->resourceProvider()->attachStencilAtt
achment(rt); |
| 118 new GrDrawContext(fContext, fDrawTarget, props); | 111 if (sb) { |
| 112 if (!fNVPRTextContext) { |
| 113 fNVPRTextContext = GrStencilAndCoverTextContext::Create(fContext
, props); |
| 114 } |
| 115 |
| 116 return fNVPRTextContext; |
| 117 } |
| 119 } | 118 } |
| 120 | 119 |
| 121 // For now, everyone gets a faux creation ref | 120 if (!fTextContexts[props.pixelGeometry()][useDIF]) { |
| 122 return SkRef(fDrawContext[props.pixelGeometry()][props.isUseDeviceIndependen
tFonts()]); | 121 fTextContexts[props.pixelGeometry()][useDIF] = GrAtlasTextContext::Creat
e(fContext, props); |
| 122 } |
| 123 |
| 124 return fTextContexts[props.pixelGeometry()][useDIF]; |
| 125 } |
| 126 |
| 127 GrDrawContext* GrContext::DrawingMgr::drawContext(GrRenderTarget* rt, |
| 128 const SkSurfaceProps* surfaceP
rops) { |
| 129 if (this->abandoned()) { |
| 130 return nullptr; |
| 131 } |
| 132 |
| 133 return new GrDrawContext(fContext, rt, fDrawTarget, surfaceProps); |
| 123 } | 134 } |
| 124 | 135 |
| 125 //////////////////////////////////////////////////////////////////////////////// | 136 //////////////////////////////////////////////////////////////////////////////// |
| 126 | 137 |
| 127 | 138 |
| 128 GrContext* GrContext::Create(GrBackend backend, GrBackendContext backendContext)
{ | 139 GrContext* GrContext::Create(GrBackend backend, GrBackendContext backendContext)
{ |
| 129 GrContextOptions defaultOptions; | 140 GrContextOptions defaultOptions; |
| 130 return Create(backend, backendContext, defaultOptions); | 141 return Create(backend, backendContext, defaultOptions); |
| 131 } | 142 } |
| 132 | 143 |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 236 fTextBlobCache->freeAll(); | 247 fTextBlobCache->freeAll(); |
| 237 } | 248 } |
| 238 | 249 |
| 239 void GrContext::resetContext(uint32_t state) { | 250 void GrContext::resetContext(uint32_t state) { |
| 240 fGpu->markContextDirty(state); | 251 fGpu->markContextDirty(state); |
| 241 } | 252 } |
| 242 | 253 |
| 243 void GrContext::freeGpuResources() { | 254 void GrContext::freeGpuResources() { |
| 244 this->flush(); | 255 this->flush(); |
| 245 | 256 |
| 246 fDrawingMgr.purgeResources(); | |
| 247 | |
| 248 fBatchFontCache->freeAll(); | 257 fBatchFontCache->freeAll(); |
| 249 fLayerCache->freeAll(); | 258 fLayerCache->freeAll(); |
| 250 // a path renderer may be holding onto resources | 259 // a path renderer may be holding onto resources |
| 251 SkSafeSetNull(fPathRendererChain); | 260 SkSafeSetNull(fPathRendererChain); |
| 252 SkSafeSetNull(fSoftwarePathRenderer); | 261 SkSafeSetNull(fSoftwarePathRenderer); |
| 253 | 262 |
| 254 fResourceCache->purgeAllUnlocked(); | 263 fResourceCache->purgeAllUnlocked(); |
| 255 } | 264 } |
| 256 | 265 |
| 257 void GrContext::getResourceCacheUsage(int* resourceCount, size_t* resourceBytes)
const { | 266 void GrContext::getResourceCacheUsage(int* resourceCount, size_t* resourceBytes)
const { |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 313 dstPI.fColorType = srcPI.fColorType; | 322 dstPI.fColorType = srcPI.fColorType; |
| 314 dstPI.fAlphaType = kPremul_SkAlphaType; | 323 dstPI.fAlphaType = kPremul_SkAlphaType; |
| 315 dstPI.fPixels = outPixels; | 324 dstPI.fPixels = outPixels; |
| 316 dstPI.fRowBytes = outRowBytes; | 325 dstPI.fRowBytes = outRowBytes; |
| 317 | 326 |
| 318 return srcPI.convertPixelsTo(&dstPI, width, height); | 327 return srcPI.convertPixelsTo(&dstPI, width, height); |
| 319 } | 328 } |
| 320 | 329 |
| 321 bool GrContext::writeSurfacePixels(GrSurface* surface, | 330 bool GrContext::writeSurfacePixels(GrSurface* surface, |
| 322 int left, int top, int width, int height, | 331 int left, int top, int width, int height, |
| 323 GrPixelConfig srcConfig, const void* buffer,
size_t rowBytes, | 332 GrPixelConfig srcConfig, const SkTArray<SkMip
MapLevel>& texels, |
| 324 uint32_t pixelOpsFlags) { | 333 uint32_t pixelOpsFlags) { |
| 325 RETURN_FALSE_IF_ABANDONED | 334 RETURN_FALSE_IF_ABANDONED |
| 326 ASSERT_OWNED_RESOURCE(surface); | 335 ASSERT_OWNED_RESOURCE(surface); |
| 327 SkASSERT(surface); | 336 SkASSERT(surface); |
| 328 | 337 |
| 338 SkTArray<SkMipMapLevel> texelsCopy(texels); |
| 339 |
| 329 this->testPMConversionsIfNecessary(pixelOpsFlags); | 340 this->testPMConversionsIfNecessary(pixelOpsFlags); |
| 330 | 341 |
| 331 // Trim the params here so that if we wind up making a temporary surface it
can be as small as | 342 // Trim the params here so that if we wind up making a temporary surface it
can be as small as |
| 332 // necessary and because GrGpu::getWritePixelsInfo requires it. | 343 // necessary and because GrGpu::getWritePixelsInfo requires it. |
| 333 if (!GrSurfacePriv::AdjustWritePixelParams(surface->width(), surface->height
(), | 344 for (int currentMipLevel = texelsCopy.count() - 1; currentMipLevel >= 0; cur
rentMipLevel--) { |
| 334 GrBytesPerPixel(srcConfig), &left
, &top, &width, | 345 // make sure the texelmap's size range is within int range |
| 335 &height, &buffer, &rowBytes)) { | 346 if (texelsCopy[currentMipLevel].fWidth > SK_MaxS32 |
| 336 return false; | 347 || texelsCopy[currentMipLevel].fHeight > SK_MaxS32) { |
| 348 return false; |
| 349 } |
| 350 int currentMipWidth = texelsCopy[currentMipLevel].fWidth; |
| 351 int currentMipHeight = texelsCopy[currentMipLevel].fHeight; |
| 352 |
| 353 SkMipMapLevel& currentMipMap = texelsCopy[currentMipLevel]; |
| 354 if (!GrSurfacePriv::AdjustWritePixelParams(surface->width(), surface->he
ight(), |
| 355 GrBytesPerPixel(srcConfig), &
left, &top, |
| 356 ¤tMipWidth, ¤tMip
Height, |
| 357 ¤tMipMap.fTexels, |
| 358 ¤tMipMap.fRowBytes)) { |
| 359 return false; |
| 360 } |
| 361 |
| 362 // make sure the size range is within the texelmap's size range |
| 363 if (currentMipWidth < 0 || currentMipHeight < 0) { |
| 364 return false; |
| 365 } |
| 366 texelsCopy[currentMipLevel].fWidth = currentMipWidth; |
| 367 texelsCopy[currentMipLevel].fHeight = currentMipHeight; |
| 337 } | 368 } |
| 338 | 369 |
| 339 bool applyPremulToSrc = false; | 370 bool applyPremulToSrc = false; |
| 340 if (kUnpremul_PixelOpsFlag & pixelOpsFlags) { | 371 if (kUnpremul_PixelOpsFlag & pixelOpsFlags) { |
| 341 if (!GrPixelConfigIs8888(srcConfig)) { | 372 if (!GrPixelConfigIs8888(srcConfig)) { |
| 342 return false; | 373 return false; |
| 343 } | 374 } |
| 344 applyPremulToSrc = true; | 375 applyPremulToSrc = true; |
| 345 } | 376 } |
| 346 | 377 |
| 347 GrGpu::DrawPreference drawPreference = GrGpu::kNoDraw_DrawPreference; | 378 GrGpu::DrawPreference drawPreference = GrGpu::kNoDraw_DrawPreference; |
| 348 // Don't prefer to draw for the conversion (and thereby access a texture fro
m the cache) when | 379 // Don't prefer to draw for the conversion (and thereby access a texture fro
m the cache) when |
| 349 // we've already determined that there isn't a roundtrip preserving conversi
on processor pair. | 380 // we've already determined that there isn't a roundtrip preserving conversi
on processor pair. |
| 350 if (applyPremulToSrc && !this->didFailPMUPMConversionTest()) { | 381 if (applyPremulToSrc && !this->didFailPMUPMConversionTest()) { |
| 351 drawPreference = GrGpu::kCallerPrefersDraw_DrawPreference; | 382 drawPreference = GrGpu::kCallerPrefersDraw_DrawPreference; |
| 352 } | 383 } |
| 353 | 384 |
| 354 GrGpu::WritePixelTempDrawInfo tempDrawInfo; | 385 GrGpu::WritePixelTempDrawInfo tempDrawInfo; |
| 355 if (!fGpu->getWritePixelsInfo(surface, width, height, rowBytes, srcConfig, &
drawPreference, | 386 if (!fGpu->getWritePixelsInfo(surface, width, height, srcConfig, &drawPrefer
ence, |
| 356 &tempDrawInfo)) { | 387 &tempDrawInfo)) { |
| 357 return false; | 388 return false; |
| 358 } | 389 } |
| 359 | 390 |
| 360 if (!(kDontFlush_PixelOpsFlag & pixelOpsFlags) && surface->surfacePriv().has
PendingIO()) { | 391 if (!(kDontFlush_PixelOpsFlag & pixelOpsFlags) && surface->surfacePriv().has
PendingIO()) { |
| 361 this->flush(); | 392 this->flush(); |
| 362 } | 393 } |
| 363 | 394 |
| 364 SkAutoTUnref<GrTexture> tempTexture; | 395 SkAutoTUnref<GrTexture> tempTexture; |
| 365 if (GrGpu::kNoDraw_DrawPreference != drawPreference) { | 396 if (GrGpu::kNoDraw_DrawPreference != drawPreference) { |
| 366 tempTexture.reset( | 397 tempTexture.reset( |
| 367 this->textureProvider()->createApproxTexture(tempDrawInfo.fTempSurfa
ceDesc)); | 398 this->textureProvider()->createApproxTexture(tempDrawInfo.fTempSurfa
ceDesc)); |
| 368 if (!tempTexture && GrGpu::kRequireDraw_DrawPreference == drawPreference
) { | 399 if (!tempTexture && GrGpu::kRequireDraw_DrawPreference == drawPreference
) { |
| 369 return false; | 400 return false; |
| 370 } | 401 } |
| 371 } | 402 } |
| 372 | 403 |
| 373 // temp buffer for doing sw premul conversion, if needed. | 404 // temp buffer for doing sw premul conversion, if needed. |
| 374 SkAutoSTMalloc<128 * 128, uint32_t> tmpPixels(0); | 405 SkAutoSTMalloc<128 * 128, uint32_t> tmpPixels(0); |
| 375 if (tempTexture) { | 406 if (tempTexture) { |
| 376 SkAutoTUnref<const GrFragmentProcessor> fp; | 407 SkAutoTUnref<const GrFragmentProcessor> fp; |
| 377 SkMatrix textureMatrix; | 408 SkMatrix textureMatrix; |
| 378 textureMatrix.setIDiv(tempTexture->width(), tempTexture->height()); | 409 textureMatrix.setIDiv(tempTexture->width(), tempTexture->height()); |
| 379 GrPaint paint; | 410 GrPaint paint; |
| 380 if (applyPremulToSrc) { | 411 if (applyPremulToSrc) { |
| 381 fp.reset(this->createUPMToPMEffect(paint.getProcessorDataManager(),
tempTexture, | 412 fp.reset(this->createUPMToPMEffect(tempTexture, tempDrawInfo.fSwapRA
ndB, |
| 382 tempDrawInfo.fSwapRAndB, textureM
atrix)); | 413 textureMatrix)); |
| 383 // If premultiplying was the only reason for the draw, fall back to
a straight write. | 414 // If premultiplying was the only reason for the draw, fall back to
a straight write. |
| 384 if (!fp) { | 415 if (!fp) { |
| 385 if (GrGpu::kCallerPrefersDraw_DrawPreference == drawPreference)
{ | 416 if (GrGpu::kCallerPrefersDraw_DrawPreference == drawPreference)
{ |
| 386 tempTexture.reset(nullptr); | 417 tempTexture.reset(nullptr); |
| 387 } | 418 } |
| 388 } else { | 419 } else { |
| 389 applyPremulToSrc = false; | 420 applyPremulToSrc = false; |
| 390 } | 421 } |
| 391 } | 422 } |
| 392 if (tempTexture) { | 423 if (tempTexture) { |
| 393 if (!fp) { | 424 if (!fp) { |
| 394 fp.reset(GrConfigConversionEffect::Create( | 425 fp.reset(GrConfigConversionEffect::Create(tempTexture, tempDrawI
nfo.fSwapRAndB, |
| 395 paint.getProcessorDataManager(), tempTexture, tempDrawInfo.f
SwapRAndB, | |
| 396 GrConfigConversionEffect::kNone_PMConversion, textureMatrix)
); | 426 GrConfigConversionEffect::kNone_PMConversion, textureMatrix)
); |
| 397 if (!fp) { | 427 if (!fp) { |
| 398 return false; | 428 return false; |
| 399 } | 429 } |
| 400 } | 430 } |
| 401 GrRenderTarget* renderTarget = surface->asRenderTarget(); | 431 GrRenderTarget* renderTarget = surface->asRenderTarget(); |
| 402 SkASSERT(renderTarget); | 432 SkASSERT(renderTarget); |
| 403 if (tempTexture->surfacePriv().hasPendingIO()) { | 433 if (tempTexture->surfacePriv().hasPendingIO()) { |
| 404 this->flush(); | 434 this->flush(); |
| 405 } | 435 } |
| 406 if (applyPremulToSrc) { | 436 if (applyPremulToSrc) { |
| 407 size_t tmpRowBytes = 4 * width; | 437 for (int currentMipLevel = texelsCopy.count() - 1; currentMipLev
el >= 0; |
| 408 tmpPixels.reset(width * height); | 438 currentMipLevel--) { |
| 409 if (!sw_convert_to_premul(srcConfig, width, height, rowBytes, bu
ffer, tmpRowBytes, | 439 SkMipMapLevel& currentMipMap = texelsCopy[currentMipLevel]; |
| 410 tmpPixels.get())) { | 440 int currentWidth = currentMipMap.fWidth; |
| 411 return false; | 441 int currentHeight = currentMipMap.fHeight; |
| 442 size_t tmpRowBytes = 4 * currentWidth; |
| 443 tmpPixels.reset(currentWidth * currentHeight); |
| 444 if (!sw_convert_to_premul(srcConfig, currentWidth, currentHe
ight, |
| 445 currentMipMap.fRowBytes, |
| 446 currentMipMap.fTexels, tmpRowBytes
, |
| 447 tmpPixels.get())) { |
| 448 return false; |
| 449 } |
| 450 currentMipMap.fRowBytes = tmpRowBytes; |
| 451 currentMipMap.fTexels = tmpPixels.get(); |
| 412 } | 452 } |
| 413 rowBytes = tmpRowBytes; | |
| 414 buffer = tmpPixels.get(); | |
| 415 applyPremulToSrc = false; | 453 applyPremulToSrc = false; |
| 416 } | 454 } |
| 417 if (!fGpu->writePixels(tempTexture, 0, 0, width, height, | 455 if (!fGpu->writePixels(tempTexture, 0, 0, width, height, |
| 418 tempDrawInfo.fTempSurfaceDesc.fConfig, buffer
, | 456 tempDrawInfo.fTempSurfaceDesc.fConfig, texels
Copy)) { |
| 419 rowBytes)) { | |
| 420 return false; | 457 return false; |
| 421 } | 458 } |
| 422 SkMatrix matrix; | 459 SkMatrix matrix; |
| 423 matrix.setTranslate(SkIntToScalar(left), SkIntToScalar(top)); | 460 matrix.setTranslate(SkIntToScalar(left), SkIntToScalar(top)); |
| 424 SkAutoTUnref<GrDrawContext> drawContext(this->drawContext()); | 461 SkAutoTUnref<GrDrawContext> drawContext(this->drawContext(renderTarg
et)); |
| 425 if (!drawContext) { | 462 if (!drawContext) { |
| 426 return false; | 463 return false; |
| 427 } | 464 } |
| 428 paint.addColorFragmentProcessor(fp); | 465 paint.addColorFragmentProcessor(fp); |
| 429 SkRect rect = SkRect::MakeWH(SkIntToScalar(width), SkIntToScalar(hei
ght)); | 466 SkRect rect = SkRect::MakeWH(SkIntToScalar(width), SkIntToScalar(hei
ght)); |
| 430 drawContext->drawRect(renderTarget, GrClip::WideOpen(), paint, matri
x, rect, nullptr); | 467 drawContext->drawRect(GrClip::WideOpen(), paint, matrix, rect, nullp
tr); |
| 431 | 468 |
| 432 if (kFlushWrites_PixelOp & pixelOpsFlags) { | 469 if (kFlushWrites_PixelOp & pixelOpsFlags) { |
| 433 this->flushSurfaceWrites(surface); | 470 this->flushSurfaceWrites(surface); |
| 434 } | 471 } |
| 435 } | 472 } |
| 436 } | 473 } |
| 437 if (!tempTexture) { | 474 if (!tempTexture) { |
| 438 if (applyPremulToSrc) { | 475 if (applyPremulToSrc) { |
| 439 size_t tmpRowBytes = 4 * width; | 476 for (int currentMipLevel = texelsCopy.count() - 1; currentMipLevel >
= 0; |
| 440 tmpPixels.reset(width * height); | 477 currentMipLevel--) { |
| 441 if (!sw_convert_to_premul(srcConfig, width, height, rowBytes, buffer
, tmpRowBytes, | 478 SkMipMapLevel& currentMipMap = texelsCopy[currentMipLevel]; |
| 442 tmpPixels.get())) { | 479 int currentMipWidth = currentMipMap.fWidth; |
| 443 return false; | 480 int currentMipHeight = currentMipMap.fHeight; |
| 481 size_t tmpRowBytes = 4 * currentMipWidth; |
| 482 tmpPixels.reset(currentMipWidth * currentMipHeight); |
| 483 if (!sw_convert_to_premul(srcConfig, currentMipWidth, currentMip
Height, |
| 484 currentMipMap.fRowBytes, currentMipMap
.fTexels, |
| 485 tmpRowBytes, tmpPixels.get())) { |
| 486 return false; |
| 487 } |
| 488 currentMipMap.fRowBytes = tmpRowBytes; |
| 489 currentMipMap.fTexels = tmpPixels.get(); |
| 444 } | 490 } |
| 445 rowBytes = tmpRowBytes; | |
| 446 buffer = tmpPixels.get(); | |
| 447 applyPremulToSrc = false; | 491 applyPremulToSrc = false; |
| 448 } | 492 } |
| 449 return fGpu->writePixels(surface, left, top, width, height, srcConfig, b
uffer, rowBytes); | 493 return fGpu->writePixels(surface, left, top, width, height, srcConfig, t
exelsCopy); |
| 450 } | 494 } |
| 451 return true; | 495 return true; |
| 452 } | 496 } |
| 453 | 497 |
| 498 bool GrContext::writeSurfacePixels(GrSurface* surface, |
| 499 int left, int top, int width, int height, |
| 500 GrPixelConfig srcConfig, const void* buffer,
size_t rowBytes, |
| 501 uint32_t pixelOpsFlags) { |
| 502 if (width <= 0 || height <= 0) { |
| 503 return false; |
| 504 } |
| 505 const uint32_t baseLevelWidth = width; |
| 506 const uint32_t baseLevelHeight = height; |
| 507 |
| 508 SkMipMapLevel level(buffer, rowBytes, baseLevelWidth, baseLevelHeight); |
| 509 const int mipLevelCount = 1; |
| 510 SkTArray<SkMipMapLevel> texels(mipLevelCount); |
| 511 texels.push_back(level); |
| 512 |
| 513 return this->writeSurfacePixels(surface, left, top, width, height, srcConfig
, texels, |
| 514 pixelOpsFlags); |
| 515 } |
| 516 |
| 454 bool GrContext::readSurfacePixels(GrSurface* src, | 517 bool GrContext::readSurfacePixels(GrSurface* src, |
| 455 int left, int top, int width, int height, | 518 int left, int top, int width, int height, |
| 456 GrPixelConfig dstConfig, void* buffer, size_t
rowBytes, | 519 GrPixelConfig dstConfig, void* buffer, size_t
rowBytes, |
| 457 uint32_t flags) { | 520 uint32_t flags) { |
| 458 RETURN_FALSE_IF_ABANDONED | 521 RETURN_FALSE_IF_ABANDONED |
| 459 ASSERT_OWNED_RESOURCE(src); | 522 ASSERT_OWNED_RESOURCE(src); |
| 460 SkASSERT(src); | 523 SkASSERT(src); |
| 461 | 524 |
| 462 this->testPMConversionsIfNecessary(flags); | 525 this->testPMConversionsIfNecessary(flags); |
| 463 SkAutoMutexAcquire ama(fReadPixelsMutex); | 526 SkAutoMutexAcquire ama(fReadPixelsMutex); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 509 } else { | 572 } else { |
| 510 temp.reset(this->textureProvider()->createApproxTexture(tempDrawInfo
.fTempSurfaceDesc)); | 573 temp.reset(this->textureProvider()->createApproxTexture(tempDrawInfo
.fTempSurfaceDesc)); |
| 511 } | 574 } |
| 512 if (temp) { | 575 if (temp) { |
| 513 SkMatrix textureMatrix; | 576 SkMatrix textureMatrix; |
| 514 textureMatrix.setTranslate(SkIntToScalar(left), SkIntToScalar(top)); | 577 textureMatrix.setTranslate(SkIntToScalar(left), SkIntToScalar(top)); |
| 515 textureMatrix.postIDiv(src->width(), src->height()); | 578 textureMatrix.postIDiv(src->width(), src->height()); |
| 516 GrPaint paint; | 579 GrPaint paint; |
| 517 SkAutoTUnref<const GrFragmentProcessor> fp; | 580 SkAutoTUnref<const GrFragmentProcessor> fp; |
| 518 if (unpremul) { | 581 if (unpremul) { |
| 519 fp.reset(this->createPMToUPMEffect( | 582 fp.reset(this->createPMToUPMEffect(src->asTexture(), tempDrawInf
o.fSwapRAndB, |
| 520 paint.getProcessorDataManager(), src->asTexture(), tempDrawI
nfo.fSwapRAndB, | |
| 521 textureMatrix)); | 583 textureMatrix)); |
| 522 if (fp) { | 584 if (fp) { |
| 523 unpremul = false; // we no longer need to do this on CPU aft
er the read back. | 585 unpremul = false; // we no longer need to do this on CPU aft
er the read back. |
| 524 } else if (GrGpu::kCallerPrefersDraw_DrawPreference == drawPrefe
rence) { | 586 } else if (GrGpu::kCallerPrefersDraw_DrawPreference == drawPrefe
rence) { |
| 525 // We only wanted to do the draw in order to perform the unp
remul so don't | 587 // We only wanted to do the draw in order to perform the unp
remul so don't |
| 526 // bother. | 588 // bother. |
| 527 temp.reset(nullptr); | 589 temp.reset(nullptr); |
| 528 } | 590 } |
| 529 } | 591 } |
| 530 if (!fp && temp) { | 592 if (!fp && temp) { |
| 531 fp.reset(GrConfigConversionEffect::Create( | 593 fp.reset(GrConfigConversionEffect::Create(src->asTexture(), temp
DrawInfo.fSwapRAndB, |
| 532 paint.getProcessorDataManager(), src->asTexture(), tempDrawI
nfo.fSwapRAndB, | |
| 533 GrConfigConversionEffect::kNone_PMConversion, textureMatrix)
); | 594 GrConfigConversionEffect::kNone_PMConversion, textureMatrix)
); |
| 534 } | 595 } |
| 535 if (fp) { | 596 if (fp) { |
| 536 paint.addColorFragmentProcessor(fp); | 597 paint.addColorFragmentProcessor(fp); |
| 537 SkRect rect = SkRect::MakeWH(SkIntToScalar(width), SkIntToScalar
(height)); | 598 SkRect rect = SkRect::MakeWH(SkIntToScalar(width), SkIntToScalar
(height)); |
| 538 SkAutoTUnref<GrDrawContext> drawContext(this->drawContext()); | 599 SkAutoTUnref<GrDrawContext> drawContext(this->drawContext(temp->
asRenderTarget())); |
| 539 drawContext->drawRect(temp->asRenderTarget(), GrClip::WideOpen()
, paint, | 600 drawContext->drawRect(GrClip::WideOpen(), paint, SkMatrix::I(),
rect, nullptr); |
| 540 SkMatrix::I(), rect, nullptr); | |
| 541 surfaceToRead.reset(SkRef(temp.get())); | 601 surfaceToRead.reset(SkRef(temp.get())); |
| 542 left = 0; | 602 left = 0; |
| 543 top = 0; | 603 top = 0; |
| 544 didTempDraw = true; | 604 didTempDraw = true; |
| 545 } | 605 } |
| 546 } | 606 } |
| 547 } | 607 } |
| 548 | 608 |
| 549 if (GrGpu::kRequireDraw_DrawPreference == drawPreference && !didTempDraw) { | 609 if (GrGpu::kRequireDraw_DrawPreference == drawPreference && !didTempDraw) { |
| 550 return false; | 610 return false; |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 604 } | 664 } |
| 605 ASSERT_OWNED_RESOURCE(src); | 665 ASSERT_OWNED_RESOURCE(src); |
| 606 ASSERT_OWNED_RESOURCE(dst); | 666 ASSERT_OWNED_RESOURCE(dst); |
| 607 | 667 |
| 608 // Since we're going to the draw target and not GPU, no need to check kNoFlu
sh | 668 // Since we're going to the draw target and not GPU, no need to check kNoFlu
sh |
| 609 // here. | 669 // here. |
| 610 if (!dst->asRenderTarget()) { | 670 if (!dst->asRenderTarget()) { |
| 611 return; | 671 return; |
| 612 } | 672 } |
| 613 | 673 |
| 614 SkAutoTUnref<GrDrawContext> drawContext(this->drawContext()); | 674 SkAutoTUnref<GrDrawContext> drawContext(this->drawContext(dst->asRenderTarge
t())); |
| 615 if (!drawContext) { | 675 if (!drawContext) { |
| 616 return; | 676 return; |
| 617 } | 677 } |
| 618 | 678 |
| 619 drawContext->copySurface(dst->asRenderTarget(), src, srcRect, dstPoint); | 679 drawContext->copySurface(src, srcRect, dstPoint); |
| 620 | 680 |
| 621 if (kFlushWrites_PixelOp & pixelOpsFlags) { | 681 if (kFlushWrites_PixelOp & pixelOpsFlags) { |
| 622 this->flush(); | 682 this->flush(); |
| 623 } | 683 } |
| 624 } | 684 } |
| 625 | 685 |
| 626 void GrContext::flushSurfaceWrites(GrSurface* surface) { | 686 void GrContext::flushSurfaceWrites(GrSurface* surface) { |
| 627 RETURN_IF_ABANDONED | 687 RETURN_IF_ABANDONED |
| 628 if (surface->surfacePriv().hasPendingWrite()) { | 688 if (surface->surfacePriv().hasPendingWrite()) { |
| 629 this->flush(); | 689 this->flush(); |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 698 void GrContext::testPMConversionsIfNecessary(uint32_t flags) { | 758 void GrContext::testPMConversionsIfNecessary(uint32_t flags) { |
| 699 if (SkToBool(kUnpremul_PixelOpsFlag & flags)) { | 759 if (SkToBool(kUnpremul_PixelOpsFlag & flags)) { |
| 700 SkAutoMutexAcquire ama(fTestPMConversionsMutex); | 760 SkAutoMutexAcquire ama(fTestPMConversionsMutex); |
| 701 if (!fDidTestPMConversions) { | 761 if (!fDidTestPMConversions) { |
| 702 test_pm_conversions(this, &fPMToUPMConversion, &fUPMToPMConversion); | 762 test_pm_conversions(this, &fPMToUPMConversion, &fUPMToPMConversion); |
| 703 fDidTestPMConversions = true; | 763 fDidTestPMConversions = true; |
| 704 } | 764 } |
| 705 } | 765 } |
| 706 } | 766 } |
| 707 | 767 |
| 708 const GrFragmentProcessor* GrContext::createPMToUPMEffect(GrProcessorDataManager
* procDataManager, | 768 const GrFragmentProcessor* GrContext::createPMToUPMEffect(GrTexture* texture, |
| 709 GrTexture* texture, | |
| 710 bool swapRAndB, | 769 bool swapRAndB, |
| 711 const SkMatrix& matrix
) const { | 770 const SkMatrix& matrix
) const { |
| 712 // We should have already called this->testPMConversionsIfNecessary(). | 771 // We should have already called this->testPMConversionsIfNecessary(). |
| 713 SkASSERT(fDidTestPMConversions); | 772 SkASSERT(fDidTestPMConversions); |
| 714 GrConfigConversionEffect::PMConversion pmToUPM = | 773 GrConfigConversionEffect::PMConversion pmToUPM = |
| 715 static_cast<GrConfigConversionEffect::PMConversion>(fPMToUPMConversion); | 774 static_cast<GrConfigConversionEffect::PMConversion>(fPMToUPMConversion); |
| 716 if (GrConfigConversionEffect::kNone_PMConversion != pmToUPM) { | 775 if (GrConfigConversionEffect::kNone_PMConversion != pmToUPM) { |
| 717 return GrConfigConversionEffect::Create(procDataManager, texture, swapRA
ndB, pmToUPM, | 776 return GrConfigConversionEffect::Create(texture, swapRAndB, pmToUPM, mat
rix); |
| 718 matrix); | |
| 719 } else { | 777 } else { |
| 720 return nullptr; | 778 return nullptr; |
| 721 } | 779 } |
| 722 } | 780 } |
| 723 | 781 |
| 724 const GrFragmentProcessor* GrContext::createUPMToPMEffect(GrProcessorDataManager
* procDataManager, | 782 const GrFragmentProcessor* GrContext::createUPMToPMEffect(GrTexture* texture, |
| 725 GrTexture* texture, | |
| 726 bool swapRAndB, | 783 bool swapRAndB, |
| 727 const SkMatrix& matrix
) const { | 784 const SkMatrix& matrix
) const { |
| 728 // We should have already called this->testPMConversionsIfNecessary(). | 785 // We should have already called this->testPMConversionsIfNecessary(). |
| 729 SkASSERT(fDidTestPMConversions); | 786 SkASSERT(fDidTestPMConversions); |
| 730 GrConfigConversionEffect::PMConversion upmToPM = | 787 GrConfigConversionEffect::PMConversion upmToPM = |
| 731 static_cast<GrConfigConversionEffect::PMConversion>(fUPMToPMConversion); | 788 static_cast<GrConfigConversionEffect::PMConversion>(fUPMToPMConversion); |
| 732 if (GrConfigConversionEffect::kNone_PMConversion != upmToPM) { | 789 if (GrConfigConversionEffect::kNone_PMConversion != upmToPM) { |
| 733 return GrConfigConversionEffect::Create(procDataManager, texture, swapRA
ndB, upmToPM, | 790 return GrConfigConversionEffect::Create(texture, swapRAndB, upmToPM, mat
rix); |
| 734 matrix); | |
| 735 } else { | 791 } else { |
| 736 return nullptr; | 792 return nullptr; |
| 737 } | 793 } |
| 738 } | 794 } |
| 739 | 795 |
| 740 bool GrContext::didFailPMUPMConversionTest() const { | 796 bool GrContext::didFailPMUPMConversionTest() const { |
| 741 // We should have already called this->testPMConversionsIfNecessary(). | 797 // We should have already called this->testPMConversionsIfNecessary(). |
| 742 SkASSERT(fDidTestPMConversions); | 798 SkASSERT(fDidTestPMConversions); |
| 743 // The PM<->UPM tests fail or succeed together so we only need to check one. | 799 // The PM<->UPM tests fail or succeed together so we only need to check one. |
| 744 return GrConfigConversionEffect::kNone_PMConversion == fPMToUPMConversion; | 800 return GrConfigConversionEffect::kNone_PMConversion == fPMToUPMConversion; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 757 | 813 |
| 758 void GrContext::setResourceCacheLimits(int maxTextures, size_t maxTextureBytes)
{ | 814 void GrContext::setResourceCacheLimits(int maxTextures, size_t maxTextureBytes)
{ |
| 759 fResourceCache->setLimits(maxTextures, maxTextureBytes); | 815 fResourceCache->setLimits(maxTextures, maxTextureBytes); |
| 760 } | 816 } |
| 761 | 817 |
| 762 ////////////////////////////////////////////////////////////////////////////// | 818 ////////////////////////////////////////////////////////////////////////////// |
| 763 | 819 |
| 764 void GrContext::dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const { | 820 void GrContext::dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const { |
| 765 fResourceCache->dumpMemoryStatistics(traceMemoryDump); | 821 fResourceCache->dumpMemoryStatistics(traceMemoryDump); |
| 766 } | 822 } |
| OLD | NEW |