OLD | NEW |
---|---|
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 #include "GrContext.h" | 9 #include "GrContext.h" |
10 | 10 |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
98 fDrawTarget->reset(); | 98 fDrawTarget->reset(); |
99 } | 99 } |
100 } | 100 } |
101 | 101 |
102 void GrContext::DrawingMgr::flush() { | 102 void GrContext::DrawingMgr::flush() { |
103 if (fDrawTarget) { | 103 if (fDrawTarget) { |
104 fDrawTarget->flush(); | 104 fDrawTarget->flush(); |
105 } | 105 } |
106 } | 106 } |
107 | 107 |
108 GrDrawContext* GrContext::DrawingMgr::drawContext(const SkSurfaceProps* surfaceP rops) { | 108 GrDrawContext* GrContext::DrawingMgr::drawContext(const SkSurfaceProps* surfaceP rops) { |
109 if (this->abandoned()) { | 109 if (this->abandoned()) { |
110 return nullptr; | 110 return nullptr; |
111 } | 111 } |
112 | 112 |
113 const SkSurfaceProps props(SkSurfacePropsCopyOrDefault(surfaceProps)); | 113 const SkSurfaceProps props(SkSurfacePropsCopyOrDefault(surfaceProps)); |
114 | 114 |
115 SkASSERT(props.pixelGeometry() < kNumPixelGeometries); | 115 SkASSERT(props.pixelGeometry() < kNumPixelGeometries); |
116 if (!fDrawContext[props.pixelGeometry()][props.isUseDeviceIndependentFonts() ]) { | 116 if (!fDrawContext[props.pixelGeometry()][props.isUseDeviceIndependentFonts() ]) { |
117 fDrawContext[props.pixelGeometry()][props.isUseDeviceIndependentFonts()] = | 117 fDrawContext[props.pixelGeometry()][props.isUseDeviceIndependentFonts()] = |
118 new GrDrawContext(fContext, fDrawTarget, props); | 118 new GrDrawContext(fContext, fDrawTarget, props); |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
313 dstPI.fColorType = srcPI.fColorType; | 313 dstPI.fColorType = srcPI.fColorType; |
314 dstPI.fAlphaType = kPremul_SkAlphaType; | 314 dstPI.fAlphaType = kPremul_SkAlphaType; |
315 dstPI.fPixels = outPixels; | 315 dstPI.fPixels = outPixels; |
316 dstPI.fRowBytes = outRowBytes; | 316 dstPI.fRowBytes = outRowBytes; |
317 | 317 |
318 return srcPI.convertPixelsTo(&dstPI, width, height); | 318 return srcPI.convertPixelsTo(&dstPI, width, height); |
319 } | 319 } |
320 | 320 |
321 bool GrContext::writeSurfacePixels(GrSurface* surface, | 321 bool GrContext::writeSurfacePixels(GrSurface* surface, |
322 int left, int top, int width, int height, | 322 int left, int top, int width, int height, |
323 GrPixelConfig srcConfig, const void* buffer, size_t rowBytes, | 323 GrPixelConfig srcConfig, const SkTArray<SkMip MapLevel>& texels, |
324 uint32_t pixelOpsFlags) { | 324 uint32_t pixelOpsFlags) { |
325 RETURN_FALSE_IF_ABANDONED | 325 RETURN_FALSE_IF_ABANDONED |
326 ASSERT_OWNED_RESOURCE(surface); | 326 ASSERT_OWNED_RESOURCE(surface); |
327 SkASSERT(surface); | 327 SkASSERT(surface); |
328 | 328 |
329 SkTArray<SkMipMapLevel> texelsCopy(texels); | |
bsalomon
2015/09/15 13:14:11
Why do we need to copy the mip array?
cblume
2015/09/16 18:40:46
Further down there is a call to GrSurfacePriv::Adj
| |
330 | |
329 this->testPMConversionsIfNecessary(pixelOpsFlags); | 331 this->testPMConversionsIfNecessary(pixelOpsFlags); |
330 | 332 |
331 // Trim the params here so that if we wind up making a temporary surface it can be as small as | 333 // 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. | 334 // necessary and because GrGpu::getWritePixelsInfo requires it. |
333 if (!GrSurfacePriv::AdjustWritePixelParams(surface->width(), surface->height (), | 335 auto currentMipHeight = height; |
334 GrBytesPerPixel(srcConfig), &left , &top, &width, | 336 auto currentMipWidth = width; |
335 &height, &buffer, &rowBytes)) { | 337 for (auto currentMipLevel = texelsCopy.count() - 1; currentMipLevel >= 0; cu rrentMipLevel--) { |
336 return false; | 338 auto& currentMipMap = texelsCopy[currentMipLevel]; |
339 if (!GrSurfacePriv::AdjustWritePixelParams(surface->width(), surface->he ight(), | |
340 GrBytesPerPixel(srcConfig), & left, &top, | |
341 ¤tMipWidth, ¤tMip Height, | |
342 ¤tMipMap.fTexels, | |
343 ¤tMipMap.fRowBytes)) { | |
344 return false; | |
345 } | |
346 currentMipHeight /= 2; | |
347 currentMipWidth /= 2; | |
337 } | 348 } |
338 | 349 |
339 bool applyPremulToSrc = false; | 350 bool applyPremulToSrc = false; |
340 if (kUnpremul_PixelOpsFlag & pixelOpsFlags) { | 351 if (kUnpremul_PixelOpsFlag & pixelOpsFlags) { |
341 if (!GrPixelConfigIs8888(srcConfig)) { | 352 if (!GrPixelConfigIs8888(srcConfig)) { |
342 return false; | 353 return false; |
343 } | 354 } |
344 applyPremulToSrc = true; | 355 applyPremulToSrc = true; |
345 } | 356 } |
346 | 357 |
347 GrGpu::DrawPreference drawPreference = GrGpu::kNoDraw_DrawPreference; | 358 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 | 359 // 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. | 360 // we've already determined that there isn't a roundtrip preserving conversi on processor pair. |
350 if (applyPremulToSrc && !this->didFailPMUPMConversionTest()) { | 361 if (applyPremulToSrc && !this->didFailPMUPMConversionTest()) { |
351 drawPreference = GrGpu::kCallerPrefersDraw_DrawPreference; | 362 drawPreference = GrGpu::kCallerPrefersDraw_DrawPreference; |
352 } | 363 } |
353 | 364 |
354 GrGpu::WritePixelTempDrawInfo tempDrawInfo; | 365 GrGpu::WritePixelTempDrawInfo tempDrawInfo; |
355 if (!fGpu->getWritePixelsInfo(surface, width, height, rowBytes, srcConfig, & drawPreference, | 366 if (!fGpu->getWritePixelsInfo(surface, width, height, srcConfig, &drawPrefer ence, |
356 &tempDrawInfo)) { | 367 &tempDrawInfo)) { |
357 return false; | 368 return false; |
358 } | 369 } |
359 | 370 |
360 if (!(kDontFlush_PixelOpsFlag & pixelOpsFlags) && surface->surfacePriv().has PendingIO()) { | 371 if (!(kDontFlush_PixelOpsFlag & pixelOpsFlags) && surface->surfacePriv().has PendingIO()) { |
361 this->flush(); | 372 this->flush(); |
362 } | 373 } |
363 | 374 |
364 SkAutoTUnref<GrTexture> tempTexture; | 375 SkAutoTUnref<GrTexture> tempTexture; |
365 if (GrGpu::kNoDraw_DrawPreference != drawPreference) { | 376 if (GrGpu::kNoDraw_DrawPreference != drawPreference) { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
397 if (!fp) { | 408 if (!fp) { |
398 return false; | 409 return false; |
399 } | 410 } |
400 } | 411 } |
401 GrRenderTarget* renderTarget = surface->asRenderTarget(); | 412 GrRenderTarget* renderTarget = surface->asRenderTarget(); |
402 SkASSERT(renderTarget); | 413 SkASSERT(renderTarget); |
403 if (tempTexture->surfacePriv().hasPendingIO()) { | 414 if (tempTexture->surfacePriv().hasPendingIO()) { |
404 this->flush(); | 415 this->flush(); |
405 } | 416 } |
406 if (applyPremulToSrc) { | 417 if (applyPremulToSrc) { |
407 size_t tmpRowBytes = 4 * width; | 418 auto currentWidth = width; |
408 tmpPixels.reset(width * height); | 419 auto currentHeight = height; |
409 if (!sw_convert_to_premul(srcConfig, width, height, rowBytes, bu ffer, tmpRowBytes, | 420 for (auto currentMipLevel = texelsCopy.count() - 1; currentMipLe vel >= 0; currentMipLevel--) { |
410 tmpPixels.get())) { | 421 size_t tmpRowBytes = 4 * currentWidth; |
411 return false; | 422 tmpPixels.reset(currentWidth * currentHeight); |
423 auto& currentMipMap = texelsCopy[currentMipLevel]; | |
424 if (!sw_convert_to_premul(srcConfig, currentWidth, currentHe ight, | |
425 currentMipMap.fRowBytes, | |
426 currentMipMap.fTexels, tmpRowBytes , | |
427 tmpPixels.get())) { | |
428 return false; | |
429 } | |
430 currentMipMap.fRowBytes = tmpRowBytes; | |
431 currentMipMap.fTexels = tmpPixels.get(); | |
432 currentWidth /= 2; | |
433 currentHeight /= 2; | |
412 } | 434 } |
413 rowBytes = tmpRowBytes; | |
414 buffer = tmpPixels.get(); | |
415 applyPremulToSrc = false; | 435 applyPremulToSrc = false; |
416 } | 436 } |
417 if (!fGpu->writePixels(tempTexture, 0, 0, width, height, | 437 if (!fGpu->writePixels(tempTexture, 0, 0, width, height, |
418 tempDrawInfo.fTempSurfaceDesc.fConfig, buffer , | 438 tempDrawInfo.fTempSurfaceDesc.fConfig, texels Copy)) { |
419 rowBytes)) { | |
420 return false; | 439 return false; |
421 } | 440 } |
422 SkMatrix matrix; | 441 SkMatrix matrix; |
423 matrix.setTranslate(SkIntToScalar(left), SkIntToScalar(top)); | 442 matrix.setTranslate(SkIntToScalar(left), SkIntToScalar(top)); |
424 SkAutoTUnref<GrDrawContext> drawContext(this->drawContext()); | 443 SkAutoTUnref<GrDrawContext> drawContext(this->drawContext()); |
425 if (!drawContext) { | 444 if (!drawContext) { |
426 return false; | 445 return false; |
427 } | 446 } |
428 paint.addColorFragmentProcessor(fp); | 447 paint.addColorFragmentProcessor(fp); |
429 SkRect rect = SkRect::MakeWH(SkIntToScalar(width), SkIntToScalar(hei ght)); | 448 SkRect rect = SkRect::MakeWH(SkIntToScalar(width), SkIntToScalar(hei ght)); |
430 drawContext->drawRect(renderTarget, GrClip::WideOpen(), paint, matri x, rect, nullptr); | 449 drawContext->drawRect(renderTarget, GrClip::WideOpen(), paint, matri x, rect, nullptr); |
431 | 450 |
432 if (kFlushWrites_PixelOp & pixelOpsFlags) { | 451 if (kFlushWrites_PixelOp & pixelOpsFlags) { |
433 this->flushSurfaceWrites(surface); | 452 this->flushSurfaceWrites(surface); |
434 } | 453 } |
435 } | 454 } |
436 } | 455 } |
437 if (!tempTexture) { | 456 if (!tempTexture) { |
438 if (applyPremulToSrc) { | 457 if (applyPremulToSrc) { |
439 size_t tmpRowBytes = 4 * width; | 458 auto currentWidth = width; |
440 tmpPixels.reset(width * height); | 459 auto currentHeight = height; |
441 if (!sw_convert_to_premul(srcConfig, width, height, rowBytes, buffer , tmpRowBytes, | 460 for (auto currentMipLevel = texelsCopy.count() - 1; currentMipLevel >= 0; currentMipLevel--) { |
442 tmpPixels.get())) { | 461 size_t tmpRowBytes = 4 * currentWidth; |
443 return false; | 462 tmpPixels.reset(currentWidth * currentHeight); |
463 auto& currentMipMap = texelsCopy[currentMipLevel]; | |
464 if (!sw_convert_to_premul(srcConfig, currentWidth, currentHeight , | |
465 currentMipMap.fRowBytes, currentMipMap .fTexels, | |
466 tmpRowBytes, tmpPixels.get())) { | |
467 return false; | |
468 } | |
469 currentMipMap.fRowBytes = tmpRowBytes; | |
470 currentMipMap.fTexels = tmpPixels.get(); | |
471 currentWidth /= 2; | |
472 currentHeight /= 2; | |
444 } | 473 } |
445 rowBytes = tmpRowBytes; | |
446 buffer = tmpPixels.get(); | |
447 applyPremulToSrc = false; | 474 applyPremulToSrc = false; |
448 } | 475 } |
449 return fGpu->writePixels(surface, left, top, width, height, srcConfig, b uffer, rowBytes); | 476 return fGpu->writePixels(surface, left, top, width, height, srcConfig, t exelsCopy); |
450 } | 477 } |
451 return true; | 478 return true; |
452 } | 479 } |
453 | 480 |
481 bool GrContext::writeSurfacePixels(GrSurface* surface, | |
482 int left, int top, int width, int height, | |
483 GrPixelConfig srcConfig, const void* buffer, size_t rowBytes, | |
484 uint32_t pixelOpsFlags) { | |
485 SkMipMapLevel level(buffer, rowBytes); | |
486 const int mipLevelCount = 1; | |
487 SkTArray<SkMipMapLevel> texels(mipLevelCount); | |
488 texels.push_back(level); | |
489 | |
490 return this->writeSurfacePixels(surface, left, top, width, height, srcConfig , texels, | |
491 pixelOpsFlags); | |
492 } | |
493 | |
454 bool GrContext::readSurfacePixels(GrSurface* src, | 494 bool GrContext::readSurfacePixels(GrSurface* src, |
455 int left, int top, int width, int height, | 495 int left, int top, int width, int height, |
456 GrPixelConfig dstConfig, void* buffer, size_t rowBytes, | 496 GrPixelConfig dstConfig, void* buffer, size_t rowBytes, |
457 uint32_t flags) { | 497 uint32_t flags) { |
458 RETURN_FALSE_IF_ABANDONED | 498 RETURN_FALSE_IF_ABANDONED |
459 ASSERT_OWNED_RESOURCE(src); | 499 ASSERT_OWNED_RESOURCE(src); |
460 SkASSERT(src); | 500 SkASSERT(src); |
461 | 501 |
462 this->testPMConversionsIfNecessary(flags); | 502 this->testPMConversionsIfNecessary(flags); |
463 SkAutoMutexAcquire ama(fReadPixelsMutex); | 503 SkAutoMutexAcquire ama(fReadPixelsMutex); |
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
752 } | 792 } |
753 if (maxTextureBytes) { | 793 if (maxTextureBytes) { |
754 *maxTextureBytes = fResourceCache->getMaxResourceBytes(); | 794 *maxTextureBytes = fResourceCache->getMaxResourceBytes(); |
755 } | 795 } |
756 } | 796 } |
757 | 797 |
758 void GrContext::setResourceCacheLimits(int maxTextures, size_t maxTextureBytes) { | 798 void GrContext::setResourceCacheLimits(int maxTextures, size_t maxTextureBytes) { |
759 fResourceCache->setLimits(maxTextures, maxTextureBytes); | 799 fResourceCache->setLimits(maxTextures, maxTextureBytes); |
760 } | 800 } |
761 | 801 |
OLD | NEW |