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

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

Powered by Google App Engine
This is Rietveld 408576698