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

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

Issue 40163004: Fix drawBitmap() of scratch texture. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Fix texture domain borders also; add GM Created 7 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 | Annotate | Revision Log
« no previous file with comments | « gm/imagefiltersgraph.cpp ('k') | no next file » | 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 2011 Google Inc. 2 * Copyright 2011 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 "SkGpuDevice.h" 8 #include "SkGpuDevice.h"
9 9
10 #include "effects/GrTextureDomainEffect.h" 10 #include "effects/GrTextureDomainEffect.h"
(...skipping 1335 matching lines...) Expand 10 before | Expand all | Expand 10 after
1346 bitmap.height() <= fContext->getMaxTextureSize()); 1346 bitmap.height() <= fContext->getMaxTextureSize());
1347 1347
1348 GrTexture* texture; 1348 GrTexture* texture;
1349 SkAutoCachedTexture act(this, bitmap, &params, &texture); 1349 SkAutoCachedTexture act(this, bitmap, &params, &texture);
1350 if (NULL == texture) { 1350 if (NULL == texture) {
1351 return; 1351 return;
1352 } 1352 }
1353 1353
1354 SkRect dstRect(srcRect); 1354 SkRect dstRect(srcRect);
1355 SkRect paintRect; 1355 SkRect paintRect;
1356 SkScalar wInv = SkScalarInvert(SkIntToScalar(bitmap.width())); 1356 SkScalar wInv = SkScalarInvert(SkIntToScalar(texture->width()));
1357 SkScalar hInv = SkScalarInvert(SkIntToScalar(bitmap.height())); 1357 SkScalar hInv = SkScalarInvert(SkIntToScalar(texture->height()));
1358 paintRect.setLTRB(SkScalarMul(srcRect.fLeft, wInv), 1358 paintRect.setLTRB(SkScalarMul(srcRect.fLeft, wInv),
1359 SkScalarMul(srcRect.fTop, hInv), 1359 SkScalarMul(srcRect.fTop, hInv),
1360 SkScalarMul(srcRect.fRight, wInv), 1360 SkScalarMul(srcRect.fRight, wInv),
1361 SkScalarMul(srcRect.fBottom, hInv)); 1361 SkScalarMul(srcRect.fBottom, hInv));
1362 1362
1363 bool needsTextureDomain = false; 1363 bool needsTextureDomain = false;
1364 if (!(flags & SkCanvas::kBleed_DrawBitmapRectFlag) && 1364 if (!(flags & SkCanvas::kBleed_DrawBitmapRectFlag) &&
1365 params.filterMode() != GrTextureParams::kNone_FilterMode) { 1365 params.filterMode() != GrTextureParams::kNone_FilterMode) {
1366 // Need texture domain if drawing a sub rect. 1366 // Need texture domain if drawing a sub rect.
1367 needsTextureDomain = srcRect.width() < bitmap.width() || 1367 needsTextureDomain = srcRect.width() < bitmap.width() ||
(...skipping 13 matching lines...) Expand all
1381 } 1381 }
1382 } 1382 }
1383 } 1383 }
1384 1384
1385 SkRect textureDomain = SkRect::MakeEmpty(); 1385 SkRect textureDomain = SkRect::MakeEmpty();
1386 SkAutoTUnref<GrEffectRef> effect; 1386 SkAutoTUnref<GrEffectRef> effect;
1387 if (needsTextureDomain) { 1387 if (needsTextureDomain) {
1388 // Use a constrained texture domain to avoid color bleeding 1388 // Use a constrained texture domain to avoid color bleeding
1389 SkScalar left, top, right, bottom; 1389 SkScalar left, top, right, bottom;
1390 if (srcRect.width() > SK_Scalar1) { 1390 if (srcRect.width() > SK_Scalar1) {
1391 SkScalar border = SK_ScalarHalf / bitmap.width(); 1391 SkScalar border = SK_ScalarHalf / texture->width();
1392 left = paintRect.left() + border; 1392 left = paintRect.left() + border;
1393 right = paintRect.right() - border; 1393 right = paintRect.right() - border;
1394 } else { 1394 } else {
1395 left = right = SkScalarHalf(paintRect.left() + paintRect.right()); 1395 left = right = SkScalarHalf(paintRect.left() + paintRect.right());
1396 } 1396 }
1397 if (srcRect.height() > SK_Scalar1) { 1397 if (srcRect.height() > SK_Scalar1) {
1398 SkScalar border = SK_ScalarHalf / bitmap.height(); 1398 SkScalar border = SK_ScalarHalf / texture->height();
1399 top = paintRect.top() + border; 1399 top = paintRect.top() + border;
1400 bottom = paintRect.bottom() - border; 1400 bottom = paintRect.bottom() - border;
1401 } else { 1401 } else {
1402 top = bottom = SkScalarHalf(paintRect.top() + paintRect.bottom()); 1402 top = bottom = SkScalarHalf(paintRect.top() + paintRect.bottom());
1403 } 1403 }
1404 textureDomain.setLTRB(left, top, right, bottom); 1404 textureDomain.setLTRB(left, top, right, bottom);
1405 effect.reset(GrTextureDomainEffect::Create(texture, 1405 effect.reset(GrTextureDomainEffect::Create(texture,
1406 SkMatrix::I(), 1406 SkMatrix::I(),
1407 textureDomain, 1407 textureDomain,
1408 GrTextureDomainEffect::kClamp _WrapMode, 1408 GrTextureDomainEffect::kClamp _WrapMode,
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after
1846 GrTexture* texture, 1846 GrTexture* texture,
1847 bool needClear) 1847 bool needClear)
1848 : SkBitmapDevice(make_bitmap(context, texture->asRenderTarget())) { 1848 : SkBitmapDevice(make_bitmap(context, texture->asRenderTarget())) {
1849 1849
1850 SkASSERT(texture && texture->asRenderTarget()); 1850 SkASSERT(texture && texture->asRenderTarget());
1851 // This constructor is called from onCreateCompatibleDevice. It has locked t he RT in the texture 1851 // This constructor is called from onCreateCompatibleDevice. It has locked t he RT in the texture
1852 // cache. We pass true for the third argument so that it will get unlocked. 1852 // cache. We pass true for the third argument so that it will get unlocked.
1853 this->initFromRenderTarget(context, texture->asRenderTarget(), true); 1853 this->initFromRenderTarget(context, texture->asRenderTarget(), true);
1854 fNeedClear = needClear; 1854 fNeedClear = needClear;
1855 } 1855 }
OLDNEW
« no previous file with comments | « gm/imagefiltersgraph.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698