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 #include "GrContextOptions.h" | 10 #include "GrContextOptions.h" |
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
269 #if defined(GOOGLE3) | 269 #if defined(GOOGLE3) |
270 // Stack frame size is limited in GOOGLE3. | 270 // Stack frame size is limited in GOOGLE3. |
271 SkAutoSTMalloc<48 * 48, uint32_t> tmpPixels(0); | 271 SkAutoSTMalloc<48 * 48, uint32_t> tmpPixels(0); |
272 #else | 272 #else |
273 SkAutoSTMalloc<128 * 128, uint32_t> tmpPixels(0); | 273 SkAutoSTMalloc<128 * 128, uint32_t> tmpPixels(0); |
274 #endif | 274 #endif |
275 if (tempTexture) { | 275 if (tempTexture) { |
276 SkAutoTUnref<const GrFragmentProcessor> fp; | 276 SkAutoTUnref<const GrFragmentProcessor> fp; |
277 SkMatrix textureMatrix; | 277 SkMatrix textureMatrix; |
278 textureMatrix.setIDiv(tempTexture->width(), tempTexture->height()); | 278 textureMatrix.setIDiv(tempTexture->width(), tempTexture->height()); |
279 GrPaint paint; | |
280 if (applyPremulToSrc) { | 279 if (applyPremulToSrc) { |
281 fp.reset(this->createUPMToPMEffect(tempTexture, tempDrawInfo.fSwapRA
ndB, | 280 fp.reset(this->createUPMToPMEffect(tempTexture, tempDrawInfo.fSwapRA
ndB, |
282 textureMatrix)); | 281 textureMatrix)); |
283 // If premultiplying was the only reason for the draw, fall back to
a straight write. | 282 // If premultiplying was the only reason for the draw, fall back to
a straight write. |
284 if (!fp) { | 283 if (!fp) { |
285 if (GrGpu::kCallerPrefersDraw_DrawPreference == drawPreference)
{ | 284 if (GrGpu::kCallerPrefersDraw_DrawPreference == drawPreference)
{ |
286 tempTexture.reset(nullptr); | 285 tempTexture.reset(nullptr); |
287 } | 286 } |
288 } else { | 287 } else { |
289 applyPremulToSrc = false; | 288 applyPremulToSrc = false; |
(...skipping 27 matching lines...) Expand all Loading... |
317 tempDrawInfo.fTempSurfaceDesc.fConfig, buffer
, | 316 tempDrawInfo.fTempSurfaceDesc.fConfig, buffer
, |
318 rowBytes)) { | 317 rowBytes)) { |
319 return false; | 318 return false; |
320 } | 319 } |
321 SkMatrix matrix; | 320 SkMatrix matrix; |
322 matrix.setTranslate(SkIntToScalar(left), SkIntToScalar(top)); | 321 matrix.setTranslate(SkIntToScalar(left), SkIntToScalar(top)); |
323 SkAutoTUnref<GrDrawContext> drawContext(this->drawContext(renderTarg
et)); | 322 SkAutoTUnref<GrDrawContext> drawContext(this->drawContext(renderTarg
et)); |
324 if (!drawContext) { | 323 if (!drawContext) { |
325 return false; | 324 return false; |
326 } | 325 } |
| 326 GrPaint paint; |
327 paint.addColorFragmentProcessor(fp); | 327 paint.addColorFragmentProcessor(fp); |
| 328 paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode); |
328 SkRect rect = SkRect::MakeWH(SkIntToScalar(width), SkIntToScalar(hei
ght)); | 329 SkRect rect = SkRect::MakeWH(SkIntToScalar(width), SkIntToScalar(hei
ght)); |
329 drawContext->drawRect(GrClip::WideOpen(), paint, matrix, rect, nullp
tr); | 330 drawContext->drawRect(GrClip::WideOpen(), paint, matrix, rect, nullp
tr); |
330 | 331 |
331 if (kFlushWrites_PixelOp & pixelOpsFlags) { | 332 if (kFlushWrites_PixelOp & pixelOpsFlags) { |
332 this->flushSurfaceWrites(surface); | 333 this->flushSurfaceWrites(surface); |
333 } | 334 } |
334 } | 335 } |
335 } | 336 } |
336 if (!tempTexture) { | 337 if (!tempTexture) { |
337 if (applyPremulToSrc) { | 338 if (applyPremulToSrc) { |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
405 SkAutoTUnref<GrTexture> temp; | 406 SkAutoTUnref<GrTexture> temp; |
406 if (tempDrawInfo.fUseExactScratch) { | 407 if (tempDrawInfo.fUseExactScratch) { |
407 temp.reset(this->textureProvider()->createTexture(tempDrawInfo.fTemp
SurfaceDesc, true)); | 408 temp.reset(this->textureProvider()->createTexture(tempDrawInfo.fTemp
SurfaceDesc, true)); |
408 } else { | 409 } else { |
409 temp.reset(this->textureProvider()->createApproxTexture(tempDrawInfo
.fTempSurfaceDesc)); | 410 temp.reset(this->textureProvider()->createApproxTexture(tempDrawInfo
.fTempSurfaceDesc)); |
410 } | 411 } |
411 if (temp) { | 412 if (temp) { |
412 SkMatrix textureMatrix; | 413 SkMatrix textureMatrix; |
413 textureMatrix.setTranslate(SkIntToScalar(left), SkIntToScalar(top)); | 414 textureMatrix.setTranslate(SkIntToScalar(left), SkIntToScalar(top)); |
414 textureMatrix.postIDiv(src->width(), src->height()); | 415 textureMatrix.postIDiv(src->width(), src->height()); |
415 GrPaint paint; | |
416 SkAutoTUnref<const GrFragmentProcessor> fp; | 416 SkAutoTUnref<const GrFragmentProcessor> fp; |
417 if (unpremul) { | 417 if (unpremul) { |
418 fp.reset(this->createPMToUPMEffect(src->asTexture(), tempDrawInf
o.fSwapRAndB, | 418 fp.reset(this->createPMToUPMEffect(src->asTexture(), tempDrawInf
o.fSwapRAndB, |
419 textureMatrix)); | 419 textureMatrix)); |
420 if (fp) { | 420 if (fp) { |
421 unpremul = false; // we no longer need to do this on CPU aft
er the read back. | 421 unpremul = false; // we no longer need to do this on CPU aft
er the read back. |
422 } else if (GrGpu::kCallerPrefersDraw_DrawPreference == drawPrefe
rence) { | 422 } else if (GrGpu::kCallerPrefersDraw_DrawPreference == drawPrefe
rence) { |
423 // We only wanted to do the draw in order to perform the unp
remul so don't | 423 // We only wanted to do the draw in order to perform the unp
remul so don't |
424 // bother. | 424 // bother. |
425 temp.reset(nullptr); | 425 temp.reset(nullptr); |
426 } | 426 } |
427 } | 427 } |
428 if (!fp && temp) { | 428 if (!fp && temp) { |
429 fp.reset(GrConfigConversionEffect::Create(src->asTexture(), temp
DrawInfo.fSwapRAndB, | 429 fp.reset(GrConfigConversionEffect::Create(src->asTexture(), temp
DrawInfo.fSwapRAndB, |
430 GrConfigConversionEffect::kNone_PMConversion, textureMatrix)
); | 430 GrConfigConversionEffect::kNone_PMConversion, textureMatrix)
); |
431 } | 431 } |
432 if (fp) { | 432 if (fp) { |
| 433 GrPaint paint; |
433 paint.addColorFragmentProcessor(fp); | 434 paint.addColorFragmentProcessor(fp); |
| 435 paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode); |
434 SkRect rect = SkRect::MakeWH(SkIntToScalar(width), SkIntToScalar
(height)); | 436 SkRect rect = SkRect::MakeWH(SkIntToScalar(width), SkIntToScalar
(height)); |
435 SkAutoTUnref<GrDrawContext> drawContext(this->drawContext(temp->
asRenderTarget())); | 437 SkAutoTUnref<GrDrawContext> drawContext(this->drawContext(temp->
asRenderTarget())); |
436 drawContext->drawRect(GrClip::WideOpen(), paint, SkMatrix::I(),
rect, nullptr); | 438 drawContext->drawRect(GrClip::WideOpen(), paint, SkMatrix::I(),
rect, nullptr); |
437 surfaceToRead.reset(SkRef(temp.get())); | 439 surfaceToRead.reset(SkRef(temp.get())); |
438 left = 0; | 440 left = 0; |
439 top = 0; | 441 top = 0; |
440 didTempDraw = true; | 442 didTempDraw = true; |
441 } | 443 } |
442 } | 444 } |
443 } | 445 } |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
621 | 623 |
622 void GrContext::setResourceCacheLimits(int maxTextures, size_t maxTextureBytes)
{ | 624 void GrContext::setResourceCacheLimits(int maxTextures, size_t maxTextureBytes)
{ |
623 fResourceCache->setLimits(maxTextures, maxTextureBytes); | 625 fResourceCache->setLimits(maxTextures, maxTextureBytes); |
624 } | 626 } |
625 | 627 |
626 ////////////////////////////////////////////////////////////////////////////// | 628 ////////////////////////////////////////////////////////////////////////////// |
627 | 629 |
628 void GrContext::dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const { | 630 void GrContext::dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const { |
629 fResourceCache->dumpMemoryStatistics(traceMemoryDump); | 631 fResourceCache->dumpMemoryStatistics(traceMemoryDump); |
630 } | 632 } |
OLD | NEW |