aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar junov@google.com <junov@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2011-05-16 18:32:07 +0000
committerGravatar junov@google.com <junov@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2011-05-16 18:32:07 +0000
commit6acc9b3d2b26d11d3da5eb81775d67a0410d1ae7 (patch)
tree12188719d0586d023cdb1ee8be778a3835070adf /src
parent4b4fb3a52c32cd4937d51d1315624545973b1322 (diff)
Fixed color bleeding issue when drawing a sub region of a bitmap with filtering enabled.
Problem was resolved by adding the notion of a custom texture domain in generated shaders, when necessary. git-svn-id: http://skia.googlecode.com/svn/trunk@1337 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src')
-rw-r--r--src/gpu/SkGpuDevice.cpp31
1 files changed, 28 insertions, 3 deletions
diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp
index a0153478d3..360fa3429c 100644
--- a/src/gpu/SkGpuDevice.cpp
+++ b/src/gpu/SkGpuDevice.cpp
@@ -984,11 +984,36 @@ void SkGpuDevice::internalDrawBitmap(const SkDraw& draw,
GrRect dstRect = SkRect::MakeWH(GrIntToScalar(srcRect.width()),
GrIntToScalar(srcRect.height()));
GrRect paintRect;
- paintRect.setLTRB(GrFixedToScalar((srcRect.fLeft << 16) / bitmap.width()),
- GrFixedToScalar((srcRect.fTop << 16) / bitmap.height()),
- GrFixedToScalar((srcRect.fRight << 16) / bitmap.width()),
+ paintRect.setLTRB(GrFixedToScalar((srcRect.fLeft << 16) / bitmap.width()),
+ GrFixedToScalar((srcRect.fTop << 16) / bitmap.height()),
+ GrFixedToScalar((srcRect.fRight << 16) / bitmap.width()),
GrFixedToScalar((srcRect.fBottom << 16) / bitmap.height()));
+ if (GrSamplerState::kNearest_Filter != grPaint->fSampler.getFilter() &&
+ (srcRect.width() < bitmap.width() ||
+ srcRect.height() < bitmap.height())) {
+ // If drawing a subrect of the bitmap and filtering is enabled,
+ // use a constrained texture domain to avoid color bleeding
+ GrScalar left, top, right, bottom;
+ if (srcRect.width() > 1) {
+ GrScalar border = GR_ScalarHalf / bitmap.width();
+ left = paintRect.left() + border;
+ right = paintRect.right() - border;
+ } else {
+ left = right = GrScalarHalf(paintRect.left() + paintRect.right());
+ }
+ if (srcRect.height() > 1) {
+ GrScalar border = GR_ScalarHalf / bitmap.height();
+ top = paintRect.top() + border;
+ bottom = paintRect.bottom() - border;
+ } else {
+ top = bottom = GrScalarHalf(paintRect.top() + paintRect.bottom());
+ }
+ GrRect textureDomain;
+ textureDomain.setLTRB(left, top, right, bottom);
+ grPaint->fSampler.setTextureDomain(textureDomain);
+ }
+
fContext->drawRectToRect(*grPaint, dstRect, paintRect, &m);
}