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

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

Issue 1438663004: API changes to GrTextureAdjuster. (Closed) Base URL: https://skia.googlesource.com/skia.git@dividemat
Patch Set: back away from lambdas Created 5 years, 1 month 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 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 if (!drawContext) { 113 if (!drawContext) {
114 return nullptr; 114 return nullptr;
115 } 115 }
116 116
117 SkRect dstRect = SkRect::MakeWH(SkIntToScalar(rtDesc.fWidth), SkIntToScalar( rtDesc.fHeight)); 117 SkRect dstRect = SkRect::MakeWH(SkIntToScalar(rtDesc.fWidth), SkIntToScalar( rtDesc.fHeight));
118 drawContext->fillRectToRect(GrClip::WideOpen(), paint, SkMatrix::I(), dstRec t, localRect); 118 drawContext->fillRectToRect(GrClip::WideOpen(), paint, SkMatrix::I(), dstRec t, localRect);
119 return copy.detach(); 119 return copy.detach();
120 } 120 }
121 121
122 GrTextureAdjuster::GrTextureAdjuster(GrTexture* original, const SkIRect& content Area) 122 GrTextureAdjuster::GrTextureAdjuster(GrTexture* original, const SkIRect& content Area)
123 : fOriginal(original) { 123 : INHERITED(contentArea.width(), contentArea.height())
124 , fOriginal(original) {
125 SkASSERT(SkIRect::MakeWH(original->width(), original->height()).contains(con tentArea));
124 if (contentArea.fLeft > 0 || contentArea.fTop > 0 || 126 if (contentArea.fLeft > 0 || contentArea.fTop > 0 ||
125 contentArea.fRight < original->width() || contentArea.fBottom < original ->height()) { 127 contentArea.fRight < original->width() || contentArea.fBottom < original ->height()) {
126 fContentArea.set(contentArea); 128 fContentArea.set(contentArea);
127 } 129 }
128 } 130 }
129 131
130 GrTexture* GrTextureAdjuster::refTextureSafeForParams(const GrTextureParams& par ams, 132 GrTexture* GrTextureAdjuster::refTextureSafeForParams(const GrTextureParams& par ams,
131 SkIPoint* outOffset) { 133 SkIPoint* outOffset) {
132 GrTexture* texture = this->originalTexture(); 134 GrTexture* texture = this->originalTexture();
133 GrContext* context = texture->getContext(); 135 GrContext* context = texture->getContext();
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 domainRect->fTop = domainRect->fBottom = SkScalarAve(domainRect->fTop, d omainRect->fBottom); 318 domainRect->fTop = domainRect->fBottom = SkScalarAve(domainRect->fTop, d omainRect->fBottom);
317 } 319 }
318 domainRect->fLeft /= texW; 320 domainRect->fLeft /= texW;
319 domainRect->fTop /= texH; 321 domainRect->fTop /= texH;
320 domainRect->fRight /= texW; 322 domainRect->fRight /= texW;
321 domainRect->fBottom /= texH; 323 domainRect->fBottom /= texH;
322 return kDomain_DomainMode; 324 return kDomain_DomainMode;
323 } 325 }
324 326
325 const GrFragmentProcessor* GrTextureAdjuster::createFragmentProcessor( 327 const GrFragmentProcessor* GrTextureAdjuster::createFragmentProcessor(
326 const SkMatrix& textureMatrix, 328 const SkMatrix& origTextureMatrix,
327 const SkRect& constraintRect, 329 const SkRect& origConstraintRect,
328 FilterConstraint filterConstraint, 330 FilterConstraint filterConstraint,
329 bool coordsLimitedToConstraintRect, 331 bool coordsLimitedToConstraintRect,
330 const GrTextureParams::FilterMode* filte rOrNullForBicubic) { 332 const GrTextureParams::FilterMode* filte rOrNullForBicubic) {
331 333
334 SkMatrix textureMatrix = origTextureMatrix;
332 const SkIRect* contentArea = this->contentAreaOrNull(); 335 const SkIRect* contentArea = this->contentAreaOrNull();
336 // Convert the constraintRect to be relative to the texture rather than the content area so
337 // that both rects are in the same coordinate system.
338 SkTCopyOnFirstWrite<SkRect> constraintRect(origConstraintRect);
339 if (contentArea) {
340 SkScalar l = SkIntToScalar(contentArea->fLeft);
341 SkScalar t = SkIntToScalar(contentArea->fTop);
342 constraintRect.writable()->offset(l, t);
343 textureMatrix.postTranslate(l, t);
344 }
333 345
334 SkRect domain; 346 SkRect domain;
335 GrTexture* texture = this->originalTexture(); 347 GrTexture* texture = this->originalTexture();
336 DomainMode domainMode = 348 DomainMode domainMode =
337 determine_domain_mode(constraintRect, filterConstraint, coordsLimitedToC onstraintRect, 349 determine_domain_mode(*constraintRect, filterConstraint, coordsLimitedTo ConstraintRect,
338 texture->width(), texture->height(), 350 texture->width(), texture->height(),
339 contentArea, filterOrNullForBicubic, 351 contentArea, filterOrNullForBicubic,
340 &domain); 352 &domain);
341 if (kTightCopy_DomainMode == domainMode) { 353 if (kTightCopy_DomainMode == domainMode) {
342 // TODO: Copy the texture and adjust the texture matrix (both parts need to consider 354 // TODO: Copy the texture and adjust the texture matrix (both parts need to consider
343 // non-int constraint rect) 355 // non-int constraint rect)
344 // For now: treat as bilerp and ignore what goes on above level 0. 356 // For now: treat as bilerp and ignore what goes on above level 0.
345 357
346 // We only expect MIP maps to require a tight copy. 358 // We only expect MIP maps to require a tight copy.
347 SkASSERT(filterOrNullForBicubic && 359 SkASSERT(filterOrNullForBicubic &&
348 GrTextureParams::kMipMap_FilterMode == *filterOrNullForBicubic) ; 360 GrTextureParams::kMipMap_FilterMode == *filterOrNullForBicubic) ;
349 static const GrTextureParams::FilterMode kBilerp = GrTextureParams::kBil erp_FilterMode; 361 static const GrTextureParams::FilterMode kBilerp = GrTextureParams::kBil erp_FilterMode;
350 domainMode = 362 domainMode =
351 determine_domain_mode(constraintRect, filterConstraint, coordsLimite dToConstraintRect, 363 determine_domain_mode(*constraintRect, filterConstraint, coordsLimit edToConstraintRect,
352 texture->width(), texture->height(), 364 texture->width(), texture->height(),
353 contentArea, &kBilerp, &domain); 365 contentArea, &kBilerp, &domain);
354 SkASSERT(kTightCopy_DomainMode != domainMode); 366 SkASSERT(kTightCopy_DomainMode != domainMode);
355 } 367 }
356 SkASSERT(kNoDomain_DomainMode == domainMode || 368 SkASSERT(kNoDomain_DomainMode == domainMode ||
357 (domain.fLeft <= domain.fRight && domain.fTop <= domain.fBottom)); 369 (domain.fLeft <= domain.fRight && domain.fTop <= domain.fBottom));
370 textureMatrix.postIDiv(texture->width(), texture->height());
358 if (filterOrNullForBicubic) { 371 if (filterOrNullForBicubic) {
359 if (kDomain_DomainMode == domainMode) { 372 if (kDomain_DomainMode == domainMode) {
360 return GrTextureDomainEffect::Create(texture, textureMatrix, domain, 373 return GrTextureDomainEffect::Create(texture, textureMatrix, domain,
361 GrTextureDomain::kClamp_Mode, 374 GrTextureDomain::kClamp_Mode,
362 *filterOrNullForBicubic); 375 *filterOrNullForBicubic);
363 } else { 376 } else {
364 GrTextureParams params(SkShader::kClamp_TileMode, *filterOrNullForBi cubic); 377 GrTextureParams params(SkShader::kClamp_TileMode, *filterOrNullForBi cubic);
365 return GrSimpleTextureEffect::Create(texture, textureMatrix, params) ; 378 return GrSimpleTextureEffect::Create(texture, textureMatrix, params) ;
366 } 379 }
367 } else { 380 } else {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 return result; 417 return result;
405 } 418 }
406 419
407 GrTexture* GrTextureMaker::generateTextureForParams(GrContext* ctx, const CopyPa rams& copyParams) { 420 GrTexture* GrTextureMaker::generateTextureForParams(GrContext* ctx, const CopyPa rams& copyParams) {
408 SkAutoTUnref<GrTexture> original(this->refOriginalTexture(ctx)); 421 SkAutoTUnref<GrTexture> original(this->refOriginalTexture(ctx));
409 if (!original) { 422 if (!original) {
410 return nullptr; 423 return nullptr;
411 } 424 }
412 return copy_on_gpu(original, nullptr, copyParams); 425 return copy_on_gpu(original, nullptr, copyParams);
413 } 426 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698