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

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

Issue 2037413002: Add SkSourceGammaTreatment enum so we know how to create mips (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Remove leftover comments Created 4 years, 6 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
OLDNEW
1 /* 1 /*
2 * Copyright 2015 Google Inc. 2 * Copyright 2015 Google Inc.
3 * 3 *
4 * 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
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "GrTextureParamsAdjuster.h" 8 #include "GrTextureParamsAdjuster.h"
9 9
10 #include "GrCaps.h" 10 #include "GrCaps.h"
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 if (copy) { 151 if (copy) {
152 if (key.isValid()) { 152 if (key.isValid()) {
153 copy->resourcePriv().setUniqueKey(key); 153 copy->resourcePriv().setUniqueKey(key);
154 this->didCacheCopy(key); 154 this->didCacheCopy(key);
155 } 155 }
156 } 156 }
157 return copy; 157 return copy;
158 } 158 }
159 159
160 GrTexture* GrTextureAdjuster::refTextureSafeForParams(const GrTextureParams& par ams, 160 GrTexture* GrTextureAdjuster::refTextureSafeForParams(const GrTextureParams& par ams,
161 SkIPoint* outOffset) { 161 bool gammaCorrect, SkIPoin t* outOffset) {
162 GrTexture* texture = this->originalTexture(); 162 GrTexture* texture = this->originalTexture();
163 GrContext* context = texture->getContext(); 163 GrContext* context = texture->getContext();
164 CopyParams copyParams; 164 CopyParams copyParams;
165 const SkIRect* contentArea = this->contentAreaOrNull(); 165 const SkIRect* contentArea = this->contentAreaOrNull();
166 166
167 if (contentArea && GrTextureParams::kMipMap_FilterMode == params.filterMode( )) { 167 if (contentArea && GrTextureParams::kMipMap_FilterMode == params.filterMode( )) {
168 // If we generate a MIP chain for texture it will read pixel values from outside the content 168 // If we generate a MIP chain for texture it will read pixel values from outside the content
169 // area. 169 // area.
170 copyParams.fWidth = contentArea->width(); 170 copyParams.fWidth = contentArea->width();
171 copyParams.fHeight = contentArea->height(); 171 copyParams.fHeight = contentArea->height();
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 return GrBicubicEffect::Create(texture, textureMatrix, kClampClamp); 366 return GrBicubicEffect::Create(texture, textureMatrix, kClampClamp);
367 } 367 }
368 } 368 }
369 } 369 }
370 370
371 const GrFragmentProcessor* GrTextureAdjuster::createFragmentProcessor( 371 const GrFragmentProcessor* GrTextureAdjuster::createFragmentProcessor(
372 const SkMatrix& origTextureMatrix, 372 const SkMatrix& origTextureMatrix,
373 const SkRect& origConstraintRect, 373 const SkRect& origConstraintRect,
374 FilterConstraint filterConstraint, 374 FilterConstraint filterConstraint,
375 bool coordsLimitedToConstraintRect, 375 bool coordsLimitedToConstraintRect,
376 const GrTextureParams::FilterMode* filte rOrNullForBicubic) { 376 const GrTextureParams::FilterMode* filte rOrNullForBicubic,
377 bool gammaCorrect) {
377 378
378 SkMatrix textureMatrix = origTextureMatrix; 379 SkMatrix textureMatrix = origTextureMatrix;
379 const SkIRect* contentArea = this->contentAreaOrNull(); 380 const SkIRect* contentArea = this->contentAreaOrNull();
380 // Convert the constraintRect to be relative to the texture rather than the content area so 381 // Convert the constraintRect to be relative to the texture rather than the content area so
381 // that both rects are in the same coordinate system. 382 // that both rects are in the same coordinate system.
382 SkTCopyOnFirstWrite<SkRect> constraintRect(origConstraintRect); 383 SkTCopyOnFirstWrite<SkRect> constraintRect(origConstraintRect);
383 if (contentArea) { 384 if (contentArea) {
384 SkScalar l = SkIntToScalar(contentArea->fLeft); 385 SkScalar l = SkIntToScalar(contentArea->fLeft);
385 SkScalar t = SkIntToScalar(contentArea->fTop); 386 SkScalar t = SkIntToScalar(contentArea->fTop);
386 constraintRect.writable()->offset(l, t); 387 constraintRect.writable()->offset(l, t);
387 textureMatrix.postTranslate(l, t); 388 textureMatrix.postTranslate(l, t);
388 } 389 }
389 390
390 SkRect domain; 391 SkRect domain;
391 GrTextureParams params; 392 GrTextureParams params;
392 if (filterOrNullForBicubic) { 393 if (filterOrNullForBicubic) {
393 params.setFilterMode(*filterOrNullForBicubic); 394 params.setFilterMode(*filterOrNullForBicubic);
394 } 395 }
395 SkAutoTUnref<GrTexture> texture(this->refTextureSafeForParams(params, nullpt r)); 396 SkAutoTUnref<GrTexture> texture(this->refTextureSafeForParams(params, gammaC orrect, nullptr));
396 if (!texture) { 397 if (!texture) {
397 return nullptr; 398 return nullptr;
398 } 399 }
399 // If we made a copy then we only copied the contentArea, in which case the new texture is all 400 // If we made a copy then we only copied the contentArea, in which case the new texture is all
400 // content. 401 // content.
401 if (texture != this->originalTexture()) { 402 if (texture != this->originalTexture()) {
402 contentArea = nullptr; 403 contentArea = nullptr;
403 } 404 }
404 405
405 DomainMode domainMode = 406 DomainMode domainMode =
(...skipping 18 matching lines...) Expand all
424 } 425 }
425 SkASSERT(kNoDomain_DomainMode == domainMode || 426 SkASSERT(kNoDomain_DomainMode == domainMode ||
426 (domain.fLeft <= domain.fRight && domain.fTop <= domain.fBottom)); 427 (domain.fLeft <= domain.fRight && domain.fTop <= domain.fBottom));
427 textureMatrix.postIDiv(texture->width(), texture->height()); 428 textureMatrix.postIDiv(texture->width(), texture->height());
428 return create_fp_for_domain_and_filter(texture, textureMatrix, domainMode, d omain, 429 return create_fp_for_domain_and_filter(texture, textureMatrix, domainMode, d omain,
429 filterOrNullForBicubic); 430 filterOrNullForBicubic);
430 } 431 }
431 432
432 ////////////////////////////////////////////////////////////////////////////// 433 //////////////////////////////////////////////////////////////////////////////
433 434
434 GrTexture* GrTextureMaker::refTextureForParams(const GrTextureParams& params) { 435 GrTexture* GrTextureMaker::refTextureForParams(const GrTextureParams& params, bo ol gammaCorrect) {
435 CopyParams copyParams; 436 CopyParams copyParams;
436 bool willBeMipped = params.filterMode() == GrTextureParams::kMipMap_FilterMo de; 437 bool willBeMipped = params.filterMode() == GrTextureParams::kMipMap_FilterMo de;
437 438
438 if (!fContext->caps()->mipMapSupport()) { 439 if (!fContext->caps()->mipMapSupport()) {
439 willBeMipped = false; 440 willBeMipped = false;
440 } 441 }
441 442
442 if (!fContext->getGpu()->makeCopyForTextureParams(this->width(), this->heigh t(), params, 443 if (!fContext->getGpu()->makeCopyForTextureParams(this->width(), this->heigh t(), params,
443 &copyParams)) { 444 &copyParams)) {
444 return this->refOriginalTexture(willBeMipped); 445 return this->refOriginalTexture(willBeMipped, gammaCorrect);
445 } 446 }
446 GrUniqueKey copyKey; 447 GrUniqueKey copyKey;
447 this->makeCopyKey(copyParams, &copyKey); 448 this->makeCopyKey(copyParams, &copyKey);
448 if (copyKey.isValid()) { 449 if (copyKey.isValid()) {
449 GrTexture* result = fContext->textureProvider()->findAndRefTextureByUniq ueKey(copyKey); 450 GrTexture* result = fContext->textureProvider()->findAndRefTextureByUniq ueKey(copyKey);
450 if (result) { 451 if (result) {
451 return result; 452 return result;
452 } 453 }
453 } 454 }
454 455
455 GrTexture* result = this->generateTextureForParams(copyParams, willBeMipped) ; 456 GrTexture* result = this->generateTextureForParams(copyParams, willBeMipped, gammaCorrect);
456 if (!result) { 457 if (!result) {
457 return nullptr; 458 return nullptr;
458 } 459 }
459 460
460 if (copyKey.isValid()) { 461 if (copyKey.isValid()) {
461 fContext->textureProvider()->assignUniqueKeyToTexture(copyKey, result); 462 fContext->textureProvider()->assignUniqueKeyToTexture(copyKey, result);
462 this->didCacheCopy(copyKey); 463 this->didCacheCopy(copyKey);
463 } 464 }
464 return result; 465 return result;
465 } 466 }
466 467
467 const GrFragmentProcessor* GrTextureMaker::createFragmentProcessor( 468 const GrFragmentProcessor* GrTextureMaker::createFragmentProcessor(
468 const SkMatrix& textureMatrix, 469 const SkMatrix& textureMatrix,
469 const SkRect& constraintRect, 470 const SkRect& constraintRect,
470 FilterConstraint filterConstraint, 471 FilterConstraint filterConstraint,
471 bool coordsLimitedToConstraintRect, 472 bool coordsLimitedToConstraintRect,
472 const GrTextureParams::FilterMode* filte rOrNullForBicubic) { 473 const GrTextureParams::FilterMode* filte rOrNullForBicubic,
474 bool gammaCorrect) {
473 475
474 const GrTextureParams::FilterMode* fmForDetermineDomain = filterOrNullForBic ubic; 476 const GrTextureParams::FilterMode* fmForDetermineDomain = filterOrNullForBic ubic;
475 if (filterOrNullForBicubic && GrTextureParams::kMipMap_FilterMode == *filter OrNullForBicubic && 477 if (filterOrNullForBicubic && GrTextureParams::kMipMap_FilterMode == *filter OrNullForBicubic &&
476 kYes_FilterConstraint == filterConstraint) { 478 kYes_FilterConstraint == filterConstraint) {
477 // TODo: Here we should force a copy restricted to the constraintRect si nce MIP maps will 479 // TODo: Here we should force a copy restricted to the constraintRect si nce MIP maps will
478 // read outside the constraint rect. However, as in the adjuster case, w e aren't currently 480 // read outside the constraint rect. However, as in the adjuster case, w e aren't currently
479 // doing that. 481 // doing that.
480 // We instead we compute the domain as though were bilerping which is on ly correct if we 482 // We instead we compute the domain as though were bilerping which is on ly correct if we
481 // only sample level 0. 483 // only sample level 0.
482 static const GrTextureParams::FilterMode kBilerp = GrTextureParams::kBil erp_FilterMode; 484 static const GrTextureParams::FilterMode kBilerp = GrTextureParams::kBil erp_FilterMode;
483 fmForDetermineDomain = &kBilerp; 485 fmForDetermineDomain = &kBilerp;
484 } 486 }
485 487
486 GrTextureParams params; 488 GrTextureParams params;
487 if (filterOrNullForBicubic) { 489 if (filterOrNullForBicubic) {
488 params.reset(SkShader::kClamp_TileMode, *filterOrNullForBicubic); 490 params.reset(SkShader::kClamp_TileMode, *filterOrNullForBicubic);
489 } else { 491 } else {
490 // Bicubic doesn't use filtering for it's texture accesses. 492 // Bicubic doesn't use filtering for it's texture accesses.
491 params.reset(SkShader::kClamp_TileMode, GrTextureParams::kNone_FilterMod e); 493 params.reset(SkShader::kClamp_TileMode, GrTextureParams::kNone_FilterMod e);
492 } 494 }
493 SkAutoTUnref<GrTexture> texture(this->refTextureForParams(params)); 495 SkAutoTUnref<GrTexture> texture(this->refTextureForParams(params, gammaCorre ct));
494 if (!texture) { 496 if (!texture) {
495 return nullptr; 497 return nullptr;
496 } 498 }
497 SkRect domain; 499 SkRect domain;
498 DomainMode domainMode = 500 DomainMode domainMode =
499 determine_domain_mode(constraintRect, filterConstraint, coordsLimitedToC onstraintRect, 501 determine_domain_mode(constraintRect, filterConstraint, coordsLimitedToC onstraintRect,
500 texture->width(), texture->height(), nullptr, fmFo rDetermineDomain, 502 texture->width(), texture->height(), nullptr, fmFo rDetermineDomain,
501 &domain); 503 &domain);
502 SkASSERT(kTightCopy_DomainMode != domainMode); 504 SkASSERT(kTightCopy_DomainMode != domainMode);
503 SkMatrix normalizedTextureMatrix = textureMatrix; 505 SkMatrix normalizedTextureMatrix = textureMatrix;
504 normalizedTextureMatrix.postIDiv(texture->width(), texture->height()); 506 normalizedTextureMatrix.postIDiv(texture->width(), texture->height());
505 return create_fp_for_domain_and_filter(texture, normalizedTextureMatrix, dom ainMode, domain, 507 return create_fp_for_domain_and_filter(texture, normalizedTextureMatrix, dom ainMode, domain,
506 filterOrNullForBicubic); 508 filterOrNullForBicubic);
507 } 509 }
508 510
509 GrTexture* GrTextureMaker::generateTextureForParams(const CopyParams& copyParams , 511 GrTexture* GrTextureMaker::generateTextureForParams(const CopyParams& copyParams ,
510 bool willBeMipped) { 512 bool willBeMipped, bool gamm aCorrect) {
511 SkAutoTUnref<GrTexture> original(this->refOriginalTexture(willBeMipped)); 513 SkAutoTUnref<GrTexture> original(this->refOriginalTexture(willBeMipped, gamm aCorrect));
512 if (!original) { 514 if (!original) {
513 return nullptr; 515 return nullptr;
514 } 516 }
515 return copy_on_gpu(original, nullptr, copyParams); 517 return copy_on_gpu(original, nullptr, copyParams);
516 } 518 }
OLDNEW
« no previous file with comments | « src/gpu/GrTextureParamsAdjuster.h ('k') | src/gpu/SkGpuDevice.cpp » ('j') | src/gpu/SkGr.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698