Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(184)

Side by Side Diff: src/gpu/GrContext.cpp

Issue 1258673009: Don't read from unref'ed RT in GrContext::readSurfacePixels (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 466 matching lines...) Expand 10 before | Expand all | Expand 10 after
477 } 477 }
478 478
479 GrGpu::DrawPreference drawPreference = unpremul ? GrGpu::kCallerPrefersDraw_ DrawPreference : 479 GrGpu::DrawPreference drawPreference = unpremul ? GrGpu::kCallerPrefersDraw_ DrawPreference :
480 GrGpu::kNoDraw_DrawPrefere nce; 480 GrGpu::kNoDraw_DrawPrefere nce;
481 GrGpu::ReadPixelTempDrawInfo tempDrawInfo; 481 GrGpu::ReadPixelTempDrawInfo tempDrawInfo;
482 if (!fGpu->getReadPixelsInfo(src, width, height, rowBytes, dstConfig, &drawP reference, 482 if (!fGpu->getReadPixelsInfo(src, width, height, rowBytes, dstConfig, &drawP reference,
483 &tempDrawInfo)) { 483 &tempDrawInfo)) {
484 return false; 484 return false;
485 } 485 }
486 486
487 GrRenderTarget* rtToRead = src->asRenderTarget(); 487 SkAutoTUnref<GrRenderTarget> rtToRead(SkSafeRef(src->asRenderTarget()));
488 bool didTempDraw = false; 488 bool didTempDraw = false;
489 if (GrGpu::kNoDraw_DrawPreference != drawPreference) { 489 if (GrGpu::kNoDraw_DrawPreference != drawPreference) {
490 GrTextureProvider::ScratchTexMatch match = GrTextureProvider::kApprox_Sc ratchTexMatch; 490 GrTextureProvider::ScratchTexMatch match = GrTextureProvider::kApprox_Sc ratchTexMatch;
491 if (tempDrawInfo.fUseExactScratch) { 491 if (tempDrawInfo.fUseExactScratch) {
492 // We only respect this when the entire src is being read. Otherwise we can trigger too 492 // We only respect this when the entire src is being read. Otherwise we can trigger too
493 // many odd ball texture sizes and trash the cache. 493 // many odd ball texture sizes and trash the cache.
494 if (width == src->width() && height == src->height()) { 494 if (width == src->width() && height == src->height()) {
495 match = GrTextureProvider::kExact_ScratchTexMatch; 495 match = GrTextureProvider::kExact_ScratchTexMatch;
496 } 496 }
497 } 497 }
498 SkAutoTUnref<GrTexture> temp; 498 SkAutoTUnref<GrTexture> temp;
499 temp.reset(this->textureProvider()->refScratchTexture(tempDrawInfo.fTemp SurfaceDesc, match)); 499 temp.reset(this->textureProvider()->refScratchTexture(tempDrawInfo.fTemp SurfaceDesc,
500 match));
500 if (temp) { 501 if (temp) {
501 SkMatrix textureMatrix; 502 SkMatrix textureMatrix;
502 textureMatrix.setTranslate(SkIntToScalar(left), SkIntToScalar(top)); 503 textureMatrix.setTranslate(SkIntToScalar(left), SkIntToScalar(top));
503 textureMatrix.postIDiv(src->width(), src->height()); 504 textureMatrix.postIDiv(src->width(), src->height());
504 GrPaint paint; 505 GrPaint paint;
505 SkAutoTUnref<const GrFragmentProcessor> fp; 506 SkAutoTUnref<const GrFragmentProcessor> fp;
506 if (unpremul) { 507 if (unpremul) {
507 fp.reset(this->createPMToUPMEffect( 508 fp.reset(this->createPMToUPMEffect(
508 paint.getProcessorDataManager(), src->asTexture(), tempDrawI nfo.fSwapRAndB, 509 paint.getProcessorDataManager(), src->asTexture(), tempDrawI nfo.fSwapRAndB,
509 textureMatrix)); 510 textureMatrix));
510 if (fp) { 511 if (fp) {
511 unpremul = false; // we no longer need to do this on CPU aft er the read back. 512 unpremul = false; // we no longer need to do this on CPU aft er the read back.
512 } else if (GrGpu::kCallerPrefersDraw_DrawPreference == drawPrefe rence) { 513 } else if (GrGpu::kCallerPrefersDraw_DrawPreference == drawPrefe rence) {
513 // We only wanted to do the draw in order to perform the unp remul so don't 514 // We only wanted to do the draw in order to perform the unp remul so don't
514 // bother. 515 // bother.
515 temp.reset(NULL); 516 temp.reset(NULL);
516 } 517 }
517 } 518 }
518 if (!fp && temp) { 519 if (!fp && temp) {
519 fp.reset(GrConfigConversionEffect::Create( 520 fp.reset(GrConfigConversionEffect::Create(
520 paint.getProcessorDataManager(), src->asTexture(), tempDrawI nfo.fSwapRAndB, 521 paint.getProcessorDataManager(), src->asTexture(), tempDrawI nfo.fSwapRAndB,
521 GrConfigConversionEffect::kNone_PMConversion, textureMatrix) ); 522 GrConfigConversionEffect::kNone_PMConversion, textureMatrix) );
522 } 523 }
523 if (fp) { 524 if (fp) {
524 paint.addColorProcessor(fp); 525 paint.addColorProcessor(fp);
525 SkRect rect = SkRect::MakeWH(SkIntToScalar(width), SkIntToScalar (height)); 526 SkRect rect = SkRect::MakeWH(SkIntToScalar(width), SkIntToScalar (height));
526 GrDrawContext* drawContext = this->drawContext(); 527 GrDrawContext* drawContext = this->drawContext();
527 drawContext->drawRect(temp->asRenderTarget(), GrClip::WideOpen() , paint, 528 drawContext->drawRect(temp->asRenderTarget(), GrClip::WideOpen() , paint,
528 SkMatrix::I(), rect, NULL); 529 SkMatrix::I(), rect, NULL);
529 rtToRead = temp->asRenderTarget(); 530 rtToRead.reset(SkRef(temp->asRenderTarget()));
530 left = 0; 531 left = 0;
531 top = 0; 532 top = 0;
532 didTempDraw = true; 533 didTempDraw = true;
533 } 534 }
534 } 535 }
535 } 536 }
536 537
537 if (GrGpu::kRequireDraw_DrawPreference == drawPreference && !didTempDraw) { 538 if (GrGpu::kRequireDraw_DrawPreference == drawPreference && !didTempDraw) {
538 return false; 539 return false;
539 } 540 }
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
736 ////////////////////////////////////////////////////////////////////////////// 737 //////////////////////////////////////////////////////////////////////////////
737 738
738 void GrContext::addGpuTraceMarker(const GrGpuTraceMarker* marker) { 739 void GrContext::addGpuTraceMarker(const GrGpuTraceMarker* marker) {
739 fGpu->addGpuTraceMarker(marker); 740 fGpu->addGpuTraceMarker(marker);
740 } 741 }
741 742
742 void GrContext::removeGpuTraceMarker(const GrGpuTraceMarker* marker) { 743 void GrContext::removeGpuTraceMarker(const GrGpuTraceMarker* marker) {
743 fGpu->removeGpuTraceMarker(marker); 744 fGpu->removeGpuTraceMarker(marker);
744 } 745 }
745 746
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698