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 <algorithm> | |
10 | |
9 #include "GrContext.h" | 11 #include "GrContext.h" |
10 | 12 |
11 #include "GrBatchFontCache.h" | 13 #include "GrBatchFontCache.h" |
12 #include "GrBatchFlushState.h" | 14 #include "GrBatchFlushState.h" |
13 #include "GrBatchTest.h" | 15 #include "GrBatchTest.h" |
14 #include "GrCaps.h" | 16 #include "GrCaps.h" |
15 #include "GrContextOptions.h" | 17 #include "GrContextOptions.h" |
16 #include "GrDefaultGeoProcFactory.h" | 18 #include "GrDefaultGeoProcFactory.h" |
17 #include "GrDrawContext.h" | 19 #include "GrDrawContext.h" |
18 #include "GrDrawTarget.h" | 20 #include "GrDrawTarget.h" |
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
313 dstPI.fColorType = srcPI.fColorType; | 315 dstPI.fColorType = srcPI.fColorType; |
314 dstPI.fAlphaType = kPremul_SkAlphaType; | 316 dstPI.fAlphaType = kPremul_SkAlphaType; |
315 dstPI.fPixels = outPixels; | 317 dstPI.fPixels = outPixels; |
316 dstPI.fRowBytes = outRowBytes; | 318 dstPI.fRowBytes = outRowBytes; |
317 | 319 |
318 return srcPI.convertPixelsTo(&dstPI, width, height); | 320 return srcPI.convertPixelsTo(&dstPI, width, height); |
319 } | 321 } |
320 | 322 |
321 bool GrContext::writeSurfacePixels(GrSurface* surface, | 323 bool GrContext::writeSurfacePixels(GrSurface* surface, |
322 int left, int top, int width, int height, | 324 int left, int top, int width, int height, |
323 GrPixelConfig srcConfig, const void* buffer, size_t rowBytes, | 325 GrPixelConfig srcConfig, const SkTArray<SkMip MapLevel>& texels, |
324 uint32_t pixelOpsFlags) { | 326 uint32_t pixelOpsFlags) { |
325 RETURN_FALSE_IF_ABANDONED | 327 RETURN_FALSE_IF_ABANDONED |
326 ASSERT_OWNED_RESOURCE(surface); | 328 ASSERT_OWNED_RESOURCE(surface); |
327 SkASSERT(surface); | 329 SkASSERT(surface); |
328 | 330 |
331 SkTArray<SkMipMapLevel> texelsCopy(texels); | |
332 | |
329 this->testPMConversionsIfNecessary(pixelOpsFlags); | 333 this->testPMConversionsIfNecessary(pixelOpsFlags); |
330 | 334 |
331 // Trim the params here so that if we wind up making a temporary surface it can be as small as | 335 // 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. | 336 // necessary and because GrGpu::getWritePixelsInfo requires it. |
333 if (!GrSurfacePriv::AdjustWritePixelParams(surface->width(), surface->height (), | 337 int currentMipWidth = width; |
334 GrBytesPerPixel(srcConfig), &left , &top, &width, | 338 int currentMipHeight = height; |
335 &height, &buffer, &rowBytes)) { | 339 for (int currentMipLevel = texelsCopy.count() - 1; currentMipLevel >= 0; cur rentMipLevel--) { |
336 return false; | 340 SkMipMapLevel& currentMipMap = texelsCopy[currentMipLevel]; |
341 if (!GrSurfacePriv::AdjustWritePixelParams(surface->width(), surface->he ight(), | |
342 GrBytesPerPixel(srcConfig), & left, &top, | |
343 ¤tMipWidth, ¤tMip Height, | |
344 ¤tMipMap.fTexels, | |
345 ¤tMipMap.fRowBytes)) { | |
346 return false; | |
347 } | |
348 currentMipWidth = std::max(1, currentMipWidth / 2); | |
bsalomon
2015/09/30 18:01:29
SkTMax
cblume
2015/10/08 09:27:56
Noted. Although, I think my better option at this
bsalomon
2015/10/08 17:01:34
Does that mean that SkMipMap and OpenGL will disag
| |
349 currentMipHeight = std::max(1, currentMipHeight / 2); | |
bsalomon
2015/09/30 18:01:29
SkTMax
| |
337 } | 350 } |
338 | 351 |
339 bool applyPremulToSrc = false; | 352 bool applyPremulToSrc = false; |
340 if (kUnpremul_PixelOpsFlag & pixelOpsFlags) { | 353 if (kUnpremul_PixelOpsFlag & pixelOpsFlags) { |
341 if (!GrPixelConfigIs8888(srcConfig)) { | 354 if (!GrPixelConfigIs8888(srcConfig)) { |
342 return false; | 355 return false; |
343 } | 356 } |
344 applyPremulToSrc = true; | 357 applyPremulToSrc = true; |
345 } | 358 } |
346 | 359 |
347 GrGpu::DrawPreference drawPreference = GrGpu::kNoDraw_DrawPreference; | 360 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 | 361 // 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. | 362 // we've already determined that there isn't a roundtrip preserving conversi on processor pair. |
350 if (applyPremulToSrc && !this->didFailPMUPMConversionTest()) { | 363 if (applyPremulToSrc && !this->didFailPMUPMConversionTest()) { |
351 drawPreference = GrGpu::kCallerPrefersDraw_DrawPreference; | 364 drawPreference = GrGpu::kCallerPrefersDraw_DrawPreference; |
352 } | 365 } |
353 | 366 |
354 GrGpu::WritePixelTempDrawInfo tempDrawInfo; | 367 GrGpu::WritePixelTempDrawInfo tempDrawInfo; |
355 if (!fGpu->getWritePixelsInfo(surface, width, height, rowBytes, srcConfig, & drawPreference, | 368 if (!fGpu->getWritePixelsInfo(surface, width, height, srcConfig, &drawPrefer ence, |
356 &tempDrawInfo)) { | 369 &tempDrawInfo)) { |
357 return false; | 370 return false; |
358 } | 371 } |
359 | 372 |
360 if (!(kDontFlush_PixelOpsFlag & pixelOpsFlags) && surface->surfacePriv().has PendingIO()) { | 373 if (!(kDontFlush_PixelOpsFlag & pixelOpsFlags) && surface->surfacePriv().has PendingIO()) { |
361 this->flush(); | 374 this->flush(); |
362 } | 375 } |
363 | 376 |
364 SkAutoTUnref<GrTexture> tempTexture; | 377 SkAutoTUnref<GrTexture> tempTexture; |
365 if (GrGpu::kNoDraw_DrawPreference != drawPreference) { | 378 if (GrGpu::kNoDraw_DrawPreference != drawPreference) { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
397 if (!fp) { | 410 if (!fp) { |
398 return false; | 411 return false; |
399 } | 412 } |
400 } | 413 } |
401 GrRenderTarget* renderTarget = surface->asRenderTarget(); | 414 GrRenderTarget* renderTarget = surface->asRenderTarget(); |
402 SkASSERT(renderTarget); | 415 SkASSERT(renderTarget); |
403 if (tempTexture->surfacePriv().hasPendingIO()) { | 416 if (tempTexture->surfacePriv().hasPendingIO()) { |
404 this->flush(); | 417 this->flush(); |
405 } | 418 } |
406 if (applyPremulToSrc) { | 419 if (applyPremulToSrc) { |
407 size_t tmpRowBytes = 4 * width; | 420 int currentWidth = width; |
408 tmpPixels.reset(width * height); | 421 int currentHeight = height; |
409 if (!sw_convert_to_premul(srcConfig, width, height, rowBytes, bu ffer, tmpRowBytes, | 422 for (int currentMipLevel = texelsCopy.count() - 1; currentMipLev el >= 0; |
410 tmpPixels.get())) { | 423 currentMipLevel--) { |
411 return false; | 424 size_t tmpRowBytes = 4 * currentWidth; |
425 tmpPixels.reset(currentWidth * currentHeight); | |
426 SkMipMapLevel& currentMipMap = texelsCopy[currentMipLevel]; | |
427 if (!sw_convert_to_premul(srcConfig, currentWidth, currentHe ight, | |
428 currentMipMap.fRowBytes, | |
429 currentMipMap.fTexels, tmpRowBytes , | |
430 tmpPixels.get())) { | |
431 return false; | |
432 } | |
433 currentMipMap.fRowBytes = tmpRowBytes; | |
434 currentMipMap.fTexels = tmpPixels.get(); | |
435 currentWidth = std::max(1, currentWidth / 2); | |
bsalomon
2015/09/30 18:01:29
SkTMax
cblume
2015/10/08 09:27:56
Done.
| |
436 currentHeight = std::max(1, currentHeight / 2); | |
bsalomon
2015/09/30 18:01:29
SkTMax
cblume
2015/10/08 09:27:56
Done.
| |
412 } | 437 } |
413 rowBytes = tmpRowBytes; | |
414 buffer = tmpPixels.get(); | |
415 applyPremulToSrc = false; | 438 applyPremulToSrc = false; |
416 } | 439 } |
417 if (!fGpu->writePixels(tempTexture, 0, 0, width, height, | 440 if (!fGpu->writePixels(tempTexture, 0, 0, width, height, |
418 tempDrawInfo.fTempSurfaceDesc.fConfig, buffer , | 441 tempDrawInfo.fTempSurfaceDesc.fConfig, texels Copy)) { |
419 rowBytes)) { | |
420 return false; | 442 return false; |
421 } | 443 } |
422 SkMatrix matrix; | 444 SkMatrix matrix; |
423 matrix.setTranslate(SkIntToScalar(left), SkIntToScalar(top)); | 445 matrix.setTranslate(SkIntToScalar(left), SkIntToScalar(top)); |
424 SkAutoTUnref<GrDrawContext> drawContext(this->drawContext()); | 446 SkAutoTUnref<GrDrawContext> drawContext(this->drawContext()); |
425 if (!drawContext) { | 447 if (!drawContext) { |
426 return false; | 448 return false; |
427 } | 449 } |
428 paint.addColorFragmentProcessor(fp); | 450 paint.addColorFragmentProcessor(fp); |
429 SkRect rect = SkRect::MakeWH(SkIntToScalar(width), SkIntToScalar(hei ght)); | 451 SkRect rect = SkRect::MakeWH(SkIntToScalar(width), SkIntToScalar(hei ght)); |
430 drawContext->drawRect(renderTarget, GrClip::WideOpen(), paint, matri x, rect, nullptr); | 452 drawContext->drawRect(renderTarget, GrClip::WideOpen(), paint, matri x, rect, nullptr); |
431 | 453 |
432 if (kFlushWrites_PixelOp & pixelOpsFlags) { | 454 if (kFlushWrites_PixelOp & pixelOpsFlags) { |
433 this->flushSurfaceWrites(surface); | 455 this->flushSurfaceWrites(surface); |
434 } | 456 } |
435 } | 457 } |
436 } | 458 } |
437 if (!tempTexture) { | 459 if (!tempTexture) { |
438 if (applyPremulToSrc) { | 460 if (applyPremulToSrc) { |
439 size_t tmpRowBytes = 4 * width; | 461 int currentMipWidth = width; |
440 tmpPixels.reset(width * height); | 462 int currentMipHeight = height; |
441 if (!sw_convert_to_premul(srcConfig, width, height, rowBytes, buffer , tmpRowBytes, | 463 for (int currentMipLevel = texelsCopy.count() - 1; currentMipLevel > = 0; |
442 tmpPixels.get())) { | 464 currentMipLevel--) { |
443 return false; | 465 size_t tmpRowBytes = 4 * currentMipWidth; |
466 tmpPixels.reset(currentMipWidth * currentMipHeight); | |
467 SkMipMapLevel& currentMipMap = texelsCopy[currentMipLevel]; | |
468 if (!sw_convert_to_premul(srcConfig, currentMipWidth, currentMip Height, | |
469 currentMipMap.fRowBytes, currentMipMap .fTexels, | |
470 tmpRowBytes, tmpPixels.get())) { | |
471 return false; | |
472 } | |
473 currentMipMap.fRowBytes = tmpRowBytes; | |
474 currentMipMap.fTexels = tmpPixels.get(); | |
475 currentMipWidth = std::max(1, currentMipWidth / 2); | |
bsalomon
2015/09/30 18:01:29
SkTMax
cblume
2015/10/08 09:27:56
Done.
| |
476 currentMipHeight = std::max(1, currentMipHeight / 2); | |
bsalomon
2015/09/30 18:01:29
SkTMax
cblume
2015/10/08 09:27:56
Done.
| |
444 } | 477 } |
445 rowBytes = tmpRowBytes; | |
446 buffer = tmpPixels.get(); | |
447 applyPremulToSrc = false; | 478 applyPremulToSrc = false; |
448 } | 479 } |
449 return fGpu->writePixels(surface, left, top, width, height, srcConfig, b uffer, rowBytes); | 480 return fGpu->writePixels(surface, left, top, width, height, srcConfig, t exelsCopy); |
450 } | 481 } |
451 return true; | 482 return true; |
452 } | 483 } |
453 | 484 |
485 bool GrContext::writeSurfacePixels(GrSurface* surface, | |
486 int left, int top, int width, int height, | |
487 GrPixelConfig srcConfig, const void* buffer, size_t rowBytes, | |
488 uint32_t pixelOpsFlags) { | |
489 if (width < 0 || height < 0) { | |
bsalomon
2015/09/30 18:01:29
Why not <=?
cblume
2015/10/08 09:27:56
Done.
| |
490 return false; | |
491 } | |
492 const uint32_t baseLevelWidth = width; | |
493 const uint32_t baseLevelHeight = height; | |
494 | |
495 SkMipMapLevel level(buffer, rowBytes, baseLevelWidth, baseLevelHeight); | |
496 const int mipLevelCount = 1; | |
497 SkTArray<SkMipMapLevel> texels(mipLevelCount); | |
498 texels.push_back(level); | |
499 | |
500 return this->writeSurfacePixels(surface, left, top, width, height, srcConfig , texels, | |
501 pixelOpsFlags); | |
502 } | |
503 | |
454 bool GrContext::readSurfacePixels(GrSurface* src, | 504 bool GrContext::readSurfacePixels(GrSurface* src, |
455 int left, int top, int width, int height, | 505 int left, int top, int width, int height, |
456 GrPixelConfig dstConfig, void* buffer, size_t rowBytes, | 506 GrPixelConfig dstConfig, void* buffer, size_t rowBytes, |
457 uint32_t flags) { | 507 uint32_t flags) { |
458 RETURN_FALSE_IF_ABANDONED | 508 RETURN_FALSE_IF_ABANDONED |
459 ASSERT_OWNED_RESOURCE(src); | 509 ASSERT_OWNED_RESOURCE(src); |
460 SkASSERT(src); | 510 SkASSERT(src); |
461 | 511 |
462 this->testPMConversionsIfNecessary(flags); | 512 this->testPMConversionsIfNecessary(flags); |
463 SkAutoMutexAcquire ama(fReadPixelsMutex); | 513 SkAutoMutexAcquire ama(fReadPixelsMutex); |
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
757 | 807 |
758 void GrContext::setResourceCacheLimits(int maxTextures, size_t maxTextureBytes) { | 808 void GrContext::setResourceCacheLimits(int maxTextures, size_t maxTextureBytes) { |
759 fResourceCache->setLimits(maxTextures, maxTextureBytes); | 809 fResourceCache->setLimits(maxTextures, maxTextureBytes); |
760 } | 810 } |
761 | 811 |
762 ////////////////////////////////////////////////////////////////////////////// | 812 ////////////////////////////////////////////////////////////////////////////// |
763 | 813 |
764 void GrContext::dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const { | 814 void GrContext::dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const { |
765 fResourceCache->dumpMemoryStatistics(traceMemoryDump); | 815 fResourceCache->dumpMemoryStatistics(traceMemoryDump); |
766 } | 816 } |
OLD | NEW |