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

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

Issue 2154753003: Introduce GrColorSpaceXform, for gamut conversion on textures (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 5 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 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 (subset->width() != copyParams.fWidth || subset->height() != copyParams. fHeight)) { 87 (subset->width() != copyParams.fWidth || subset->height() != copyParams. fHeight)) {
88 SkRect domain; 88 SkRect domain;
89 domain.fLeft = (subset->fLeft + 0.5f) * sx; 89 domain.fLeft = (subset->fLeft + 0.5f) * sx;
90 domain.fTop = (subset->fTop + 0.5f)* sy; 90 domain.fTop = (subset->fTop + 0.5f)* sy;
91 domain.fRight = (subset->fRight - 0.5f) * sx; 91 domain.fRight = (subset->fRight - 0.5f) * sx;
92 domain.fBottom = (subset->fBottom - 0.5f) * sy; 92 domain.fBottom = (subset->fBottom - 0.5f) * sy;
93 // This would cause us to read values from outside the subset. Surely, t he caller knows 93 // This would cause us to read values from outside the subset. Surely, t he caller knows
94 // better! 94 // better!
95 SkASSERT(copyParams.fFilter != GrTextureParams::kMipMap_FilterMode); 95 SkASSERT(copyParams.fFilter != GrTextureParams::kMipMap_FilterMode);
96 paint.addColorFragmentProcessor( 96 paint.addColorFragmentProcessor(
97 GrTextureDomainEffect::Make(inputTexture, SkMatrix::I(), domain, 97 GrTextureDomainEffect::Make(inputTexture, nullptr, SkMatrix::I(), do main,
98 GrTextureDomain::kClamp_Mode, 98 GrTextureDomain::kClamp_Mode,
99 copyParams.fFilter)); 99 copyParams.fFilter));
100 } else { 100 } else {
101 GrTextureParams params(SkShader::kClamp_TileMode, copyParams.fFilter); 101 GrTextureParams params(SkShader::kClamp_TileMode, copyParams.fFilter);
102 paint.addColorTextureProcessor(inputTexture, SkMatrix::I(), params); 102 paint.addColorTextureProcessor(inputTexture, nullptr, SkMatrix::I(), par ams);
103 } 103 }
104 paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode); 104 paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode);
105 105
106 SkRect localRect; 106 SkRect localRect;
107 if (subset) { 107 if (subset) {
108 localRect = SkRect::Make(*subset); 108 localRect = SkRect::Make(*subset);
109 localRect.fLeft *= sx; 109 localRect.fLeft *= sx;
110 localRect.fTop *= sy; 110 localRect.fTop *= sy;
111 localRect.fRight *= sx; 111 localRect.fRight *= sx;
112 localRect.fBottom *= sy; 112 localRect.fBottom *= sy;
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 } 343 }
344 domainRect->fLeft /= texW; 344 domainRect->fLeft /= texW;
345 domainRect->fTop /= texH; 345 domainRect->fTop /= texH;
346 domainRect->fRight /= texW; 346 domainRect->fRight /= texW;
347 domainRect->fBottom /= texH; 347 domainRect->fBottom /= texH;
348 return kDomain_DomainMode; 348 return kDomain_DomainMode;
349 } 349 }
350 350
351 static sk_sp<GrFragmentProcessor> create_fp_for_domain_and_filter( 351 static sk_sp<GrFragmentProcessor> create_fp_for_domain_and_filter(
352 GrTexture* texture, 352 GrTexture* texture,
353 sk_sp<GrColorSpaceXform> colorSpaceXform ,
353 const SkMatrix& textureMatrix, 354 const SkMatrix& textureMatrix,
354 DomainMode domainMode, 355 DomainMode domainMode,
355 const SkRect& domain, 356 const SkRect& domain,
356 const GrTextureParams::FilterMode* filte rOrNullForBicubic) { 357 const GrTextureParams::FilterMode* filte rOrNullForBicubic) {
357 SkASSERT(kTightCopy_DomainMode != domainMode); 358 SkASSERT(kTightCopy_DomainMode != domainMode);
358 if (filterOrNullForBicubic) { 359 if (filterOrNullForBicubic) {
359 if (kDomain_DomainMode == domainMode) { 360 if (kDomain_DomainMode == domainMode) {
360 return GrTextureDomainEffect::Make(texture, textureMatrix, domain, 361 return GrTextureDomainEffect::Make(texture, std::move(colorSpaceXfor m), textureMatrix,
361 GrTextureDomain::kClamp_Mode, 362 domain, GrTextureDomain::kClamp_M ode,
362 *filterOrNullForBicubic); 363 *filterOrNullForBicubic);
363 } else { 364 } else {
364 GrTextureParams params(SkShader::kClamp_TileMode, *filterOrNullForBi cubic); 365 GrTextureParams params(SkShader::kClamp_TileMode, *filterOrNullForBi cubic);
365 return GrSimpleTextureEffect::Make(texture, textureMatrix, params); 366 return GrSimpleTextureEffect::Make(texture, std::move(colorSpaceXfor m), textureMatrix,
367 params);
366 } 368 }
367 } else { 369 } else {
368 if (kDomain_DomainMode == domainMode) { 370 if (kDomain_DomainMode == domainMode) {
369 return GrBicubicEffect::Make(texture, textureMatrix, domain); 371 return GrBicubicEffect::Make(texture, std::move(colorSpaceXform), te xtureMatrix,
372 domain);
370 } else { 373 } else {
371 static const SkShader::TileMode kClampClamp[] = 374 static const SkShader::TileMode kClampClamp[] =
372 { SkShader::kClamp_TileMode, SkShader::kClamp_TileMode }; 375 { SkShader::kClamp_TileMode, SkShader::kClamp_TileMode };
373 return GrBicubicEffect::Make(texture, textureMatrix, kClampClamp); 376 return GrBicubicEffect::Make(texture, std::move(colorSpaceXform), te xtureMatrix,
377 kClampClamp);
374 } 378 }
375 } 379 }
376 } 380 }
377 381
378 sk_sp<GrFragmentProcessor> GrTextureAdjuster::createFragmentProcessor( 382 sk_sp<GrFragmentProcessor> GrTextureAdjuster::createFragmentProcessor(
379 const SkMatrix& origTextureMatrix, 383 const SkMatrix& origTextureMatrix,
380 const SkRect& origConstraintRect, 384 const SkRect& origConstraintRect,
381 FilterConstraint filterConstraint, 385 FilterConstraint filterConstraint,
382 bool coordsLimitedToConstraintRect, 386 bool coordsLimitedToConstraintRect,
383 const GrTextureParams::FilterMode* filte rOrNullForBicubic, 387 const GrTextureParams::FilterMode* filte rOrNullForBicubic,
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
426 static const GrTextureParams::FilterMode kBilerp = GrTextureParams::kBil erp_FilterMode; 430 static const GrTextureParams::FilterMode kBilerp = GrTextureParams::kBil erp_FilterMode;
427 domainMode = 431 domainMode =
428 determine_domain_mode(*constraintRect, filterConstraint, coordsLimit edToConstraintRect, 432 determine_domain_mode(*constraintRect, filterConstraint, coordsLimit edToConstraintRect,
429 texture->width(), texture->height(), 433 texture->width(), texture->height(),
430 contentArea, &kBilerp, &domain); 434 contentArea, &kBilerp, &domain);
431 SkASSERT(kTightCopy_DomainMode != domainMode); 435 SkASSERT(kTightCopy_DomainMode != domainMode);
432 } 436 }
433 SkASSERT(kNoDomain_DomainMode == domainMode || 437 SkASSERT(kNoDomain_DomainMode == domainMode ||
434 (domain.fLeft <= domain.fRight && domain.fTop <= domain.fBottom)); 438 (domain.fLeft <= domain.fRight && domain.fTop <= domain.fBottom));
435 textureMatrix.postIDiv(texture->width(), texture->height()); 439 textureMatrix.postIDiv(texture->width(), texture->height());
436 return create_fp_for_domain_and_filter(texture, textureMatrix, domainMode, d omain, 440 SkColorSpace* dstColorSpace = nullptr; // XFORMTODO
437 filterOrNullForBicubic); 441 sk_sp<GrColorSpaceXform> colorSpaceXform = GrColorSpaceXform::Make(this->get ColorSpace(),
442 dstColorS pace);
443 return create_fp_for_domain_and_filter(texture, std::move(colorSpaceXform), textureMatrix,
444 domainMode, domain, filterOrNullForBi cubic);
438 } 445 }
439 446
440 ////////////////////////////////////////////////////////////////////////////// 447 //////////////////////////////////////////////////////////////////////////////
441 448
442 GrTexture* GrTextureMaker::refTextureForParams(const GrTextureParams& params, 449 GrTexture* GrTextureMaker::refTextureForParams(const GrTextureParams& params,
443 SkSourceGammaTreatment gammaTreat ment) { 450 SkSourceGammaTreatment gammaTreat ment) {
444 CopyParams copyParams; 451 CopyParams copyParams;
445 bool willBeMipped = params.filterMode() == GrTextureParams::kMipMap_FilterMo de; 452 bool willBeMipped = params.filterMode() == GrTextureParams::kMipMap_FilterMo de;
446 453
447 if (!fContext->caps()->mipMapSupport()) { 454 if (!fContext->caps()->mipMapSupport()) {
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
505 return nullptr; 512 return nullptr;
506 } 513 }
507 SkRect domain; 514 SkRect domain;
508 DomainMode domainMode = 515 DomainMode domainMode =
509 determine_domain_mode(constraintRect, filterConstraint, coordsLimitedToC onstraintRect, 516 determine_domain_mode(constraintRect, filterConstraint, coordsLimitedToC onstraintRect,
510 texture->width(), texture->height(), nullptr, fmFo rDetermineDomain, 517 texture->width(), texture->height(), nullptr, fmFo rDetermineDomain,
511 &domain); 518 &domain);
512 SkASSERT(kTightCopy_DomainMode != domainMode); 519 SkASSERT(kTightCopy_DomainMode != domainMode);
513 SkMatrix normalizedTextureMatrix = textureMatrix; 520 SkMatrix normalizedTextureMatrix = textureMatrix;
514 normalizedTextureMatrix.postIDiv(texture->width(), texture->height()); 521 normalizedTextureMatrix.postIDiv(texture->width(), texture->height());
515 return create_fp_for_domain_and_filter(texture, normalizedTextureMatrix, dom ainMode, domain, 522 SkColorSpace* dstColorSpace = nullptr; // XFORMTODO
523 sk_sp<GrColorSpaceXform> colorSpaceXform = GrColorSpaceXform::Make(this->get ColorSpace(),
524 dstColorS pace);
525 return create_fp_for_domain_and_filter(texture, std::move(colorSpaceXform),
526 normalizedTextureMatrix, domainMode, domain,
516 filterOrNullForBicubic); 527 filterOrNullForBicubic);
517 } 528 }
518 529
519 GrTexture* GrTextureMaker::generateTextureForParams(const CopyParams& copyParams , bool willBeMipped, 530 GrTexture* GrTextureMaker::generateTextureForParams(const CopyParams& copyParams , bool willBeMipped,
520 SkSourceGammaTreatment gamma Treatment) { 531 SkSourceGammaTreatment gamma Treatment) {
521 SkAutoTUnref<GrTexture> original(this->refOriginalTexture(willBeMipped, gamm aTreatment)); 532 SkAutoTUnref<GrTexture> original(this->refOriginalTexture(willBeMipped, gamm aTreatment));
522 if (!original) { 533 if (!original) {
523 return nullptr; 534 return nullptr;
524 } 535 }
525 return copy_on_gpu(original, nullptr, copyParams); 536 return copy_on_gpu(original, nullptr, copyParams);
526 } 537 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698