Fix drawBitmap() of scratch texture.
R=bsalomon@google.com Review URL: https://codereview.chromium.org/40163004 git-svn-id: http://skia.googlecode.com/svn/trunk@11947 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
parent
ad0e552fef
commit
34a849d00d
@ -109,6 +109,14 @@ protected:
|
||||
canvas.drawText(str, strlen(str), SkIntToScalar(20), SkIntToScalar(70), paint);
|
||||
}
|
||||
|
||||
void drawClippedBitmap(SkCanvas* canvas, const SkBitmap& bitmap, const SkPaint& paint) {
|
||||
canvas->save();
|
||||
canvas->clipRect(SkRect::MakeXYWH(0, 0,
|
||||
SkIntToScalar(bitmap.width()), SkIntToScalar(bitmap.height())));
|
||||
canvas->drawBitmap(bitmap, 0, 0, &paint);
|
||||
canvas->restore();
|
||||
}
|
||||
|
||||
virtual SkISize onISize() { return SkISize::Make(500, 150); }
|
||||
|
||||
virtual void onDraw(SkCanvas* canvas) {
|
||||
@ -129,6 +137,7 @@ protected:
|
||||
SkPaint paint;
|
||||
paint.setImageFilter(merge);
|
||||
canvas->drawPaint(paint);
|
||||
canvas->translate(SkIntToScalar(100), 0);
|
||||
}
|
||||
{
|
||||
SkAutoTUnref<SkImageFilter> morph(new SkDilateImageFilter(5, 5));
|
||||
@ -145,7 +154,8 @@ protected:
|
||||
|
||||
SkPaint paint;
|
||||
paint.setImageFilter(blendColor);
|
||||
canvas->drawBitmap(fBitmap, 100, 0, &paint);
|
||||
drawClippedBitmap(canvas, fBitmap, paint);
|
||||
canvas->translate(SkIntToScalar(100), 0);
|
||||
}
|
||||
{
|
||||
SkScalar matrix[20] = { SK_Scalar1, 0, 0, 0, 0,
|
||||
@ -161,7 +171,21 @@ protected:
|
||||
|
||||
SkPaint paint;
|
||||
paint.setImageFilter(&arithFilter);
|
||||
canvas->drawSprite(fBitmap, 200, 0, &paint);
|
||||
drawClippedBitmap(canvas, fBitmap, paint);
|
||||
canvas->translate(SkIntToScalar(100), 0);
|
||||
}
|
||||
{
|
||||
SkAutoTUnref<SkImageFilter> blur(new SkBlurImageFilter(
|
||||
SkIntToScalar(10), SkIntToScalar(10)));
|
||||
|
||||
SkAutoTUnref<SkXfermode> mode(SkXfermode::Create(SkXfermode::kSrcIn_Mode));
|
||||
SkImageFilter::CropRect cropRect(SkRect::MakeWH(SkIntToScalar(95), SkIntToScalar(100)));
|
||||
SkAutoTUnref<SkImageFilter> blend(new SkXfermodeImageFilter(mode, blur, NULL, &cropRect));
|
||||
|
||||
SkPaint paint;
|
||||
paint.setImageFilter(blend);
|
||||
drawClippedBitmap(canvas, fBitmap, paint);
|
||||
canvas->translate(SkIntToScalar(100), 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1353,8 +1353,8 @@ void SkGpuDevice::internalDrawBitmap(const SkBitmap& bitmap,
|
||||
|
||||
SkRect dstRect(srcRect);
|
||||
SkRect paintRect;
|
||||
SkScalar wInv = SkScalarInvert(SkIntToScalar(bitmap.width()));
|
||||
SkScalar hInv = SkScalarInvert(SkIntToScalar(bitmap.height()));
|
||||
SkScalar wInv = SkScalarInvert(SkIntToScalar(texture->width()));
|
||||
SkScalar hInv = SkScalarInvert(SkIntToScalar(texture->height()));
|
||||
paintRect.setLTRB(SkScalarMul(srcRect.fLeft, wInv),
|
||||
SkScalarMul(srcRect.fTop, hInv),
|
||||
SkScalarMul(srcRect.fRight, wInv),
|
||||
@ -1388,14 +1388,14 @@ void SkGpuDevice::internalDrawBitmap(const SkBitmap& bitmap,
|
||||
// Use a constrained texture domain to avoid color bleeding
|
||||
SkScalar left, top, right, bottom;
|
||||
if (srcRect.width() > SK_Scalar1) {
|
||||
SkScalar border = SK_ScalarHalf / bitmap.width();
|
||||
SkScalar border = SK_ScalarHalf / texture->width();
|
||||
left = paintRect.left() + border;
|
||||
right = paintRect.right() - border;
|
||||
} else {
|
||||
left = right = SkScalarHalf(paintRect.left() + paintRect.right());
|
||||
}
|
||||
if (srcRect.height() > SK_Scalar1) {
|
||||
SkScalar border = SK_ScalarHalf / bitmap.height();
|
||||
SkScalar border = SK_ScalarHalf / texture->height();
|
||||
top = paintRect.top() + border;
|
||||
bottom = paintRect.bottom() - border;
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user