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

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

Powered by Google App Engine
This is Rietveld 408576698