drawBitmap is deprecated, use drawImage

Change-Id: Ib66517fe26036704ccb8328ef92fa0f5240c79f4
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/358222
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Mike Reed <reed@google.com>
This commit is contained in:
Mike Reed 2021-01-24 19:49:21 -05:00 committed by Skia Commit-Bot
parent 069e484cc3
commit 607a382298
27 changed files with 116 additions and 401 deletions

View File

@ -222,7 +222,7 @@ Result BRDSrc::draw(GrDirectContext*, SkCanvas* canvas) const {
}
alpha8_to_gray8(&bitmap);
canvas->drawBitmap(bitmap, 0, 0);
canvas->drawImage(bitmap.asImage(), 0, 0);
return Result::Ok();
}
case kDivisor_Mode: {
@ -278,7 +278,7 @@ Result BRDSrc::draw(GrDirectContext*, SkCanvas* canvas) const {
}
alpha8_to_gray8(&bitmap);
canvas->drawBitmapRect(bitmap,
canvas->drawImageRect(bitmap.asImage().get(),
SkRect::MakeXYWH((SkScalar) scaledBorder, (SkScalar) scaledBorder,
(SkScalar) (subsetWidth / fSampleSize),
(SkScalar) (subsetHeight / fSampleSize)),
@ -286,7 +286,8 @@ Result BRDSrc::draw(GrDirectContext*, SkCanvas* canvas) const {
(SkScalar) (top / fSampleSize),
(SkScalar) (subsetWidth / fSampleSize),
(SkScalar) (subsetHeight / fSampleSize)),
nullptr);
SkSamplingOptions(), nullptr,
SkCanvas::kStrict_SrcRectConstraint);
}
}
return Result::Ok();

View File

@ -24,26 +24,26 @@
namespace skiagm {
static void draw_bm(SkBitmap* bm) {
static sk_sp<SkImage> draw_bm() {
SkPaint bluePaint;
bluePaint.setColor(SK_ColorBLUE);
bm->allocN32Pixels(20, 20);
bm->eraseColor(SK_ColorRED);
SkCanvas canvas(*bm);
canvas.drawCircle(10, 10, 5, bluePaint);
SkBitmap bm;
bm.allocN32Pixels(20, 20);
bm.eraseColor(SK_ColorRED);
SkCanvas(bm).drawCircle(10, 10, 5, bluePaint);
return bm.asImage();
}
static void draw_mask(SkBitmap* bm) {
static sk_sp<SkImage> draw_mask() {
SkPaint circlePaint;
circlePaint.setColor(SK_ColorBLACK);
bm->allocPixels(SkImageInfo::MakeA8(20, 20));
bm->eraseColor(SK_ColorTRANSPARENT);
SkCanvas canvas(*bm);
canvas.drawCircle(10, 10, 10, circlePaint);
SkBitmap bm;
bm.allocPixels(SkImageInfo::MakeA8(20, 20));
bm.eraseColor(SK_ColorTRANSPARENT);
SkCanvas(bm).drawCircle(10, 10, 10, circlePaint);
return bm.asImage();
}
class BitmapShaderGM : public GM {
@ -51,8 +51,8 @@ class BitmapShaderGM : public GM {
protected:
void onOnceBeforeDraw() override {
this->setBGColor(SK_ColorGRAY);
draw_bm(&fBitmap);
draw_mask(&fMask);
fImage = draw_bm();
fMask = draw_mask();
}
SkString onShortName() override {
@ -75,12 +75,12 @@ protected:
}
canvas->save();
paint.setShader(fBitmap.makeShader(SkSamplingOptions(), s));
paint.setShader(fImage->makeShader(SkSamplingOptions(), s));
// draw the shader with a bitmap mask
canvas->drawBitmap(fMask, 0, 0, &paint);
canvas->drawImage(fMask, 0, 0, SkSamplingOptions(), &paint);
// no blue circle expected (the bitmap shader's coordinates are aligned to CTM still)
canvas->drawBitmap(fMask, 30, 0, &paint);
canvas->drawImage(fMask, 30, 0, SkSamplingOptions(), &paint);
canvas->translate(0, 25);
@ -92,13 +92,13 @@ protected:
// clear the shader, colorized by a solid color with a bitmap mask
paint.setShader(nullptr);
paint.setColor(SK_ColorGREEN);
canvas->drawBitmap(fMask, 0, 0, &paint);
canvas->drawBitmap(fMask, 30, 0, &paint);
canvas->drawImage(fMask, 0, 0, SkSamplingOptions(), &paint);
canvas->drawImage(fMask, 30, 0, SkSamplingOptions(), &paint);
canvas->translate(0, 25);
paint.setShader(fMask.makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat,
SkSamplingOptions(), s));
paint.setShader(fMask->makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat,
SkSamplingOptions(), s));
paint.setColor(SK_ColorRED);
// draw the mask using the shader and a color
@ -110,8 +110,7 @@ protected:
}
private:
SkBitmap fBitmap;
SkBitmap fMask;
sk_sp<SkImage> fImage, fMask;
using INHERITED = GM;
};

View File

@ -50,13 +50,17 @@ static void draw_tile_bitmap_with_fractional_offset(GrRecordingContext* context,
for (int i = 0; i < 10; ++i) {
float offset = i * 0.1f;
if (vertical) {
canvas->drawBitmapRect(bmp, SkRect::MakeXYWH(0.0f, (kTileSize - 50) + offset,
32.0f, 1124.0f),
SkRect::MakeXYWH(37.0f * i, 0.0f, 32.0f, 1124.0f), nullptr);
canvas->drawImageRect(bmp.asImage(),
SkRect::MakeXYWH(0, (kTileSize - 50) + offset, 32, 1124.0f),
SkRect::MakeXYWH(37.0f * i, 0.0f, 32.0f, 1124.0f),
SkSamplingOptions(), nullptr,
SkCanvas::kStrict_SrcRectConstraint);
} else {
canvas->drawBitmapRect(bmp, SkRect::MakeXYWH((kTileSize - 50) + offset, 0.0f,
1124.0f, 32.0f),
SkRect::MakeXYWH(0.0f, 37.0f * i, 1124.0f, 32.0f), nullptr);
canvas->drawImageRect(bmp.asImage(),
SkRect::MakeXYWH((kTileSize - 50) + offset, 0, 1124, 32),
SkRect::MakeXYWH(0.0f, 37.0f * i, 1124.0f, 32.0f),
SkSamplingOptions(), nullptr,
SkCanvas::kStrict_SrcRectConstraint);
}
}
}

View File

@ -232,7 +232,7 @@ DEF_SIMPLE_GM(blurrect_gallery, canvas, 1200, 1024) {
canvas->save();
canvas->translate((SkScalar)cur_x, (SkScalar)cur_y);
canvas->translate(-(bm.width() - r.width())/2, -(bm.height()-r.height())/2);
canvas->drawBitmap(bm, 0.f, 0.f, nullptr);
canvas->drawImage(bm.asImage(), 0.f, 0.f);
canvas->restore();
cur_x += bm.width() + fPadding;

View File

@ -29,11 +29,10 @@
#include "src/core/SkTLList.h"
#include "tools/ToolUtils.h"
static SkBitmap make_bmp(int w, int h) {
SkBitmap bmp;
bmp.allocN32Pixels(w, h, true);
static sk_sp<SkImage> make_img(int w, int h) {
auto surf = SkSurface::MakeRaster(SkImageInfo::MakeN32(w, h, kOpaque_SkAlphaType));
auto canvas = surf->getCanvas();
SkCanvas canvas(bmp);
SkScalar wScalar = SkIntToScalar(w);
SkScalar hScalar = SkIntToScalar(h);
@ -67,7 +66,7 @@ static SkBitmap make_bmp(int w, int h) {
SK_ARRAY_COUNT(colors),
SkTileMode::kRepeat,
0, &mat));
canvas.drawRect(rect, paint);
canvas->drawRect(rect, paint);
rect.inset(wScalar / 8, hScalar / 8);
mat.preTranslate(6 * wScalar, 6 * hScalar);
mat.postScale(SK_Scalar1 / 3, SK_Scalar1 / 3);
@ -79,14 +78,14 @@ static SkBitmap make_bmp(int w, int h) {
paint.setColor(SK_ColorLTGRAY);
constexpr char kTxt[] = "Skia";
SkPoint texPos = { wScalar / 17, hScalar / 2 + font.getSize() / 2.5f };
canvas.drawSimpleText(kTxt, SK_ARRAY_COUNT(kTxt)-1, SkTextEncoding::kUTF8,
texPos.fX, texPos.fY, font, paint);
canvas->drawSimpleText(kTxt, SK_ARRAY_COUNT(kTxt)-1, SkTextEncoding::kUTF8,
texPos.fX, texPos.fY, font, paint);
paint.setColor(SK_ColorBLACK);
paint.setStyle(SkPaint::kStroke_Style);
paint.setStrokeWidth(SK_Scalar1);
canvas.drawSimpleText(kTxt, SK_ARRAY_COUNT(kTxt)-1, SkTextEncoding::kUTF8,
texPos.fX, texPos.fY, font, paint);
return bmp;
canvas->drawSimpleText(kTxt, SK_ARRAY_COUNT(kTxt)-1, SkTextEncoding::kUTF8,
texPos.fX, texPos.fY, font, paint);
return surf->makeImageSnapshot();
}
namespace skiagm {
@ -147,7 +146,7 @@ protected:
rotM.setRotate(23.f, rect.centerX(), rect.centerY());
fClips.addToTail()->setPath(SkPath::Rect(rect).makeTransform(rotM));
fBmp = make_bmp(100, 100);
fImg = make_img(100, 100);
}
void onDraw(SkCanvas* canvas) override {
@ -157,7 +156,8 @@ protected:
SkPaint bgPaint;
bgPaint.setAlpha(0x15);
SkISize size = canvas->getBaseLayerSize();
canvas->drawBitmapRect(fBmp, SkRect::MakeIWH(size.fWidth, size.fHeight), &bgPaint);
canvas->drawImageRect(fImg, SkRect::MakeIWH(size.fWidth, size.fHeight),
SkSamplingOptions(), &bgPaint);
constexpr char kTxt[] = "Clip Me!";
SkFont font(ToolUtils::create_portable_typeface(), 23);
@ -185,9 +185,9 @@ protected:
}
canvas->translate(x, y);
clip->setOnCanvas(canvas, kIntersect_SkClipOp, SkToBool(aa));
canvas->drawBitmap(fBmp, 0, 0);
canvas->drawImage(fImg, 0, 0);
canvas->restore();
x += fBmp.width() + kMargin;
x += fImg->width() + kMargin;
}
for (int aa = 0; aa < 2; ++aa) {
@ -216,10 +216,10 @@ protected:
canvas->restore();
x += textW + 2 * kMargin;
}
y += fBmp.height() + kMargin;
y += fImg->height() + kMargin;
}
y = 0;
startX += 2 * fBmp.width() + SkScalarCeilToInt(2 * textW) + 6 * kMargin;
startX += 2 * fImg->width() + SkScalarCeilToInt(2 * textW) + 6 * kMargin;
}
}
@ -299,7 +299,7 @@ private:
typedef SkTLList<Clip, 1> ClipList;
ClipList fClips;
SkBitmap fBmp;
sk_sp<SkImage> fImg;;
using INHERITED = GM;
};

View File

@ -54,9 +54,9 @@ DEF_SIMPLE_GM(format4444, canvas, 64, 64) {
bitmap.allocPixels(imageInfo);
SkCanvas offscreen(bitmap);
offscreen.clear(SK_ColorRED);
canvas->drawBitmap(bitmap, 0, 0);
canvas->drawImage(bitmap.asImage(), 0, 0);
offscreen.clear(SK_ColorBLUE);
canvas->drawBitmap(bitmap, 1, 1);
canvas->drawImage(bitmap.asImage(), 1, 1);
auto pack4444 = [](unsigned a, unsigned r, unsigned g, unsigned b) -> uint16_t {
return (a << 0) | (b << 4) | (g << 8) | (r << 12);
};
@ -64,10 +64,10 @@ DEF_SIMPLE_GM(format4444, canvas, 64, 64) {
uint16_t blue4444 = pack4444(0xF, 0x0, 0x0, 0x0F);
SkPixmap redPixmap(imageInfo, &red4444, 2);
if (bitmap.writePixels(redPixmap, 0, 0)) {
canvas->drawBitmap(bitmap, 2, 2);
canvas->drawImage(bitmap.asImage(), 2, 2);
}
SkPixmap bluePixmap(imageInfo, &blue4444, 2);
if (bitmap.writePixels(bluePixmap, 0, 0)) {
canvas->drawBitmap(bitmap, 3, 3);
canvas->drawImage(bitmap.asImage(), 3, 3);
}
}

View File

@ -87,7 +87,7 @@ static void draw_bitmap(SkCanvas* canvas, const SkRect& r, const SkPaint& p) {
SkCanvas temp(bm);
temp.clear(SK_ColorMAGENTA);
canvas->drawBitmapRect(bm, r, &p);
canvas->drawImageRect(bm.asImage(), r, SkSamplingOptions(), &p);
}
constexpr drawMth gDrawMthds[] = {

View File

@ -183,7 +183,7 @@ DEF_GM( return new ImageGM; )
static void draw_pixmap(SkCanvas* canvas, const SkPixmap& pmap) {
SkBitmap bitmap;
bitmap.installPixels(pmap);
canvas->drawBitmap(bitmap, 0, 0, nullptr);
canvas->drawImage(bitmap.asImage(), 0, 0);
}
static void show_scaled_pixels(SkCanvas* canvas, SkImage* image) {

View File

@ -138,9 +138,9 @@ DEF_GM(return new ImageBlurRepeatModeGM;)
// draw and then clipping)).
DEF_SIMPLE_GM(imageblurrepeatunclipped, canvas, 256, 128) {
// To show translucency
SkBitmap checkerboard = ToolUtils::create_checkerboard_bitmap(256, 128, SK_ColorLTGRAY,
SK_ColorGRAY, 8);
canvas->drawBitmap(checkerboard, 0, 0);
auto checkerboard = ToolUtils::create_checkerboard_image(256, 128, SK_ColorLTGRAY,
SK_ColorGRAY, 8);
canvas->drawImage(checkerboard, 0, 0);
// Make an image with one red and one blue band
SkBitmap bmp;

View File

@ -46,9 +46,8 @@ protected:
void drawClippedBitmap(SkCanvas* canvas, const SkPaint& paint, int x, int y) {
canvas->save();
canvas->translate(SkIntToScalar(x), SkIntToScalar(y));
canvas->clipRect(SkRect::MakeWH(
SkIntToScalar(fBitmap.width()), SkIntToScalar(fBitmap.height())));
canvas->drawBitmap(fBitmap, 0, 0, &paint);
canvas->clipIRect(fBitmap.bounds());
canvas->drawImage(fBitmap.asImage(), 0, 0, SkSamplingOptions(), &paint);
canvas->restore();
}

View File

@ -10,16 +10,14 @@
#include "include/core/SkCanvas.h"
#include "include/core/SkColor.h"
#include "include/core/SkColorSpace.h"
#include "include/core/SkFilterQuality.h"
#include "include/core/SkFont.h"
#include "include/core/SkImage.h"
#include "include/core/SkImageInfo.h"
#include "include/core/SkMatrix.h"
#include "include/core/SkPaint.h"
#include "include/core/SkPathEffect.h"
#include "include/core/SkPixmap.h"
#include "include/core/SkPoint.h"
#include "include/core/SkRefCnt.h"
#include "include/core/SkScalar.h"
#include "include/core/SkShader.h"
#include "include/core/SkString.h"
#include "include/core/SkTileMode.h"
@ -145,7 +143,7 @@ DEF_SIMPLE_GM(p3, canvas, 450, 1300) {
paint.setColor4f({1,0,0,1}, p3.get());
SkCanvas{bm}.drawPaint(paint);
canvas->drawBitmap(bm, 10,10);
canvas->drawImage(bm.asImage(), 10,10);
compare_pixel("drawBitmap P3 red, from drawPaint",
canvas, 10,10,
{1,0,0,1}, p3.get());
@ -163,7 +161,7 @@ DEF_SIMPLE_GM(p3, canvas, 450, 1300) {
SkAssertResult(bm.peekPixels(&pm));
SkAssertResult(pm.erase({1,0,0,1}, p3.get()));
canvas->drawBitmap(bm, 10,10);
canvas->drawImage(bm.asImage(), 10,10);
compare_pixel("drawBitmap P3 red, from SkPixmap::erase",
canvas, 10,10,
{1,0,0,1}, p3.get());
@ -339,18 +337,19 @@ DEF_SIMPLE_GM(p3, canvas, 450, 1300) {
for (int i = 0; i < 256; i++) {
mask[i] = 255-i;
}
SkBitmap bm;
bm.installPixels(SkImageInfo::MakeA8(16,16), mask, 16);
SkPaint as_bitmap;
as_bitmap.setColor4f({1,0,0,1}, p3.get());
as_bitmap.setFilterQuality(kLow_SkFilterQuality);
SkSamplingOptions sampling(SkFilterMode::kLinear);
SkPaint as_shader;
as_shader.setColor4f({1,0,0,1}, p3.get());
as_shader.setShader(bm.makeShader(SkSamplingOptions(SkFilterMode::kLinear)));
as_shader.setShader(bm.makeShader(sampling));
canvas->drawBitmap(bm, 10,10, &as_bitmap);
canvas->drawImage(bm.asImage(), 10,10, sampling, &as_bitmap);
compare_pixel("A8 sprite bitmap P3 red",
canvas, 10,10,
{1,0,0,1}, p3.get());
@ -367,7 +366,7 @@ DEF_SIMPLE_GM(p3, canvas, 450, 1300) {
canvas->translate(0,80);
canvas->drawBitmapRect(bm, {10,10,70,70}, &as_bitmap);
canvas->drawImageRect(bm.asImage(), {10,10,70,70}, sampling, &as_bitmap);
compare_pixel("A8 scaled bitmap P3 red",
canvas, 10,10,
{1,0,0,1}, p3.get());

View File

@ -194,7 +194,7 @@ protected:
canvas->drawRect(SkRect::MakeXYWH(x, y,
SkIntToScalar(bm.width()),
SkIntToScalar(bm.height())), p);
canvas->drawBitmap(bm, x, y);
canvas->drawImage(bm.asImage(), x, y);
}
}

View File

@ -83,9 +83,10 @@ protected:
SkPaint bmpPaint;
bmpPaint.setAntiAlias(true);
bmpPaint.setFilterQuality(kLow_SkFilterQuality);
bmpPaint.setAlphaf(0.5f);
canvas->drawBitmap(fBmp, 5.f, 5.f, &bmpPaint);
SkSamplingOptions sampling(SkFilterMode::kLinear);
canvas->drawImage(fBmp.asImage(), 5.f, 5.f, sampling, &bmpPaint);
SkFont font(ToolUtils::create_portable_typeface(), SkIntToScalar(kPointSize));
SkPaint outlinePaint;
@ -117,8 +118,7 @@ protected:
SkPaint fillPaint;
fillPaint.setAntiAlias(true);
fillPaint.setShader(fBmp.makeShader(kTileModes[tm0], kTileModes[tm1],
SkSamplingOptions(SkFilterMode::kLinear),
localM));
sampling, localM));
constexpr char kText[] = "B";
canvas->drawString(kText, 0, 0, font, fillPaint);

View File

@ -21,301 +21,11 @@
#include "include/private/SkNx.h"
#include "src/core/SkMipmap.h"
#include "src/core/SkMipmapBuilder.h"
#include "tools/Resources.h"
#include "tools/ToolUtils.h"
#include <math.h>
#define SHOW_MIP_COLOR 0xFF000000
static SkBitmap make_bitmap(int w, int h) {
SkBitmap bm;
bm.allocN32Pixels(w, h);
SkCanvas canvas(bm);
canvas.clear(0xFFFFFFFF);
SkPaint paint;
paint.setStyle(SkPaint::kStroke_Style);
paint.setStrokeWidth(w / 16.0f);
paint.setColor(SHOW_MIP_COLOR);
canvas.drawCircle(w/2.0f, h/2.0f, w/3.0f, paint);
return bm;
}
static SkBitmap make_bitmap2(int w, int h) {
SkBitmap bm;
bm.allocN32Pixels(w, h);
SkCanvas canvas(bm);
canvas.clear(0xFFFFFFFF);
SkPaint paint;
paint.setColor(SHOW_MIP_COLOR);
paint.setStyle(SkPaint::kStroke_Style);
SkScalar inset = 2;
SkRect r = SkRect::MakeIWH(w, h).makeInset(0.5f, 0.5f);
while (r.width() > 4) {
canvas.drawRect(r, paint);
r.inset(inset, inset);
inset += 1;
}
return bm;
}
static SkBitmap make_bitmap3(int w, int h) {
SkBitmap bm;
bm.allocN32Pixels(w, h);
SkCanvas canvas(bm);
canvas.clear(0xFFFFFFFF);
SkPaint paint;
paint.setStyle(SkPaint::kStroke_Style);
paint.setStrokeWidth(2.1f);
paint.setColor(SHOW_MIP_COLOR);
SkScalar s = SkIntToScalar(w);
Sk4f p(s, -s, -s, s);
Sk4f d(5);
while (p[1] < s) {
canvas.drawLine(p[0],p[1], p[2], p[3], paint);
p = p + d;
}
return bm;
}
class ShowMipLevels : public skiagm::GM {
const int fN;
SkBitmap fBM[4];
public:
static unsigned gamma(unsigned n) {
float x = n / 255.0f;
#if 0
x = sqrtf(x);
#else
if (x > 0.0031308f) {
x = 1.055f * (powf(x, (1.0f / 2.4f))) - 0.055f;
} else {
x = 12.92f * x;
}
#endif
return (int)(x * 255);
}
static void apply_gamma(const SkBitmap& bm) {
return; // below is our experiment for sRGB correction
for (int y = 0; y < bm.height(); ++y) {
for (int x = 0; x < bm.width(); ++x) {
SkPMColor c = *bm.getAddr32(x, y);
unsigned r = gamma(SkGetPackedR32(c));
unsigned g = gamma(SkGetPackedG32(c));
unsigned b = gamma(SkGetPackedB32(c));
*bm.getAddr32(x, y) = SkPackARGB32(0xFF, r, g, b);
}
}
}
ShowMipLevels(int N) : fN(N) { }
protected:
SkString onShortName() override {
SkString str;
str.printf("showmiplevels_%d", fN);
return str;
}
SkISize onISize() override { return { 150, 862 }; }
static void DrawAndFrame(SkCanvas* canvas, const SkBitmap& orig, SkScalar x, SkScalar y) {
SkBitmap bm;
ToolUtils::copy_to(&bm, orig.colorType(), orig);
apply_gamma(bm);
canvas->drawBitmap(bm, x, y, nullptr);
SkPaint paint;
paint.setStyle(SkPaint::kStroke_Style);
paint.setColor(0xFFFFCCCC);
canvas->drawRect(SkRect::MakeIWH(bm.width(), bm.height()).makeOffset(x, y).makeOutset(0.5f, 0.5f), paint);
}
template <typename F> void drawLevels(SkCanvas* canvas, const SkBitmap& baseBM, F func) {
SkScalar x = 4;
SkScalar y = 4;
SkPixmap prevPM;
baseBM.peekPixels(&prevPM);
sk_sp<SkMipmap> mm(SkMipmap::Build(baseBM, nullptr));
int index = 0;
SkMipmap::Level level;
SkScalar scale = 0.5f;
while (mm->extractLevel(SkSize::Make(scale, scale), &level)) {
SkBitmap bm = func(prevPM, level.fPixmap);
DrawAndFrame(canvas, bm, x, y);
if (level.fPixmap.width() <= 2 || level.fPixmap.height() <= 2) {
break;
}
if (index & 1) {
x += level.fPixmap.width() + 4;
} else {
y += level.fPixmap.height() + 4;
}
scale /= 2;
prevPM = level.fPixmap;
index += 1;
}
}
void drawSet(SkCanvas* canvas, const SkBitmap& orig) {
SkAutoCanvasRestore acr(canvas, true);
drawLevels(canvas, orig, [](const SkPixmap& prev, const SkPixmap& curr) {
SkBitmap bm;
bm.installPixels(curr);
return bm;
});
}
void onOnceBeforeDraw() override {
fBM[0] = ToolUtils::create_checkerboard_bitmap(fN, fN, SK_ColorBLACK, SK_ColorWHITE, 2);
fBM[1] = make_bitmap(fN, fN);
fBM[2] = make_bitmap2(fN, fN);
fBM[3] = make_bitmap3(fN, fN);
}
void onDraw(SkCanvas* canvas) override {
canvas->translate(4, 4);
for (const auto& bm : fBM) {
this->drawSet(canvas, bm);
// round so we always produce an integral translate, so the GOLD tool won't show
// unimportant diffs if this is drawn on a GPU with different rounding rules
// since we draw the bitmaps using nearest-neighbor
canvas->translate(0, SkScalarRoundToScalar(bm.height() * 0.85f));
}
}
private:
using INHERITED = skiagm::GM;
};
DEF_GM( return new ShowMipLevels(255); )
DEF_GM( return new ShowMipLevels(256); )
///////////////////////////////////////////////////////////////////////////////////////////////////
void copy_to(SkBitmap* dst, SkColorType dstColorType, const SkBitmap& src) {
if (kGray_8_SkColorType == dstColorType) {
return ToolUtils::copy_to_g8(dst, src);
}
const SkBitmap* srcPtr = &src;
SkBitmap tmp(src);
if (kRGB_565_SkColorType == dstColorType) {
tmp.setAlphaType(kOpaque_SkAlphaType);
srcPtr = &tmp;
}
ToolUtils::copy_to(dst, dstColorType, *srcPtr);
}
/**
* Show mip levels that were built, for all supported colortypes
*/
class ShowMipLevels2 : public skiagm::GM {
const int fW, fH;
SkBitmap fBM[4];
public:
ShowMipLevels2(int w, int h) : fW(w), fH(h) { }
protected:
SkString onShortName() override {
SkString str;
str.printf("showmiplevels2_%dx%d", fW, fH);
return str;
}
SkISize onISize() override {
return { 824, 862 };
}
static void DrawAndFrame(SkCanvas* canvas, const SkBitmap& bm, SkScalar x, SkScalar y) {
canvas->drawBitmap(bm, x, y, nullptr);
SkPaint paint;
paint.setStyle(SkPaint::kStroke_Style);
paint.setColor(0xFFFFCCCC);
canvas->drawRect(SkRect::MakeIWH(bm.width(), bm.height()).makeOffset(x, y).makeOutset(0.5f, 0.5f), paint);
}
void drawLevels(SkCanvas* canvas, const SkBitmap& baseBM) {
SkScalar x = 4;
SkScalar y = 4;
sk_sp<SkMipmap> mm(SkMipmap::Build(baseBM, nullptr));
int index = 0;
SkMipmap::Level level;
SkScalar scale = 0.5f;
while (mm->extractLevel(SkSize::Make(scale, scale), &level)) {
SkBitmap bm;
bm.installPixels(level.fPixmap);
DrawAndFrame(canvas, bm, x, y);
if (level.fPixmap.width() <= 2 || level.fPixmap.height() <= 2) {
break;
}
if (index & 1) {
x += level.fPixmap.width() + 4;
} else {
y += level.fPixmap.height() + 4;
}
scale /= 2;
index += 1;
}
}
void drawSet(SkCanvas* canvas, const SkBitmap& orig) {
const SkColorType ctypes[] = {
kN32_SkColorType, kRGB_565_SkColorType, kARGB_4444_SkColorType, kGray_8_SkColorType
};
SkAutoCanvasRestore acr(canvas, true);
for (auto ctype : ctypes) {
SkBitmap bm;
copy_to(&bm, ctype, orig);
drawLevels(canvas, bm);
canvas->translate(orig.width()/2 + 8.0f, 0);
}
}
void onOnceBeforeDraw() override {
fBM[0] = ToolUtils::create_checkerboard_bitmap(fW, fH, SHOW_MIP_COLOR, SK_ColorWHITE, 2);
fBM[1] = make_bitmap(fW, fH);
fBM[2] = make_bitmap2(fW, fH);
fBM[3] = make_bitmap3(fW, fH);
}
void onDraw(SkCanvas* canvas) override {
canvas->translate(4, 4);
for (const auto& bm : fBM) {
this->drawSet(canvas, bm);
// round so we always produce an integral translate, so the GOLD tool won't show
// unimportant diffs if this is drawn on a GPU with different rounding rules
// since we draw the bitmaps using nearest-neighbor
canvas->translate(0, SkScalarRoundToScalar(bm.height() * 0.85f));
}
}
private:
using INHERITED = skiagm::GM;
};
DEF_GM( return new ShowMipLevels2(255, 255); )
DEF_GM( return new ShowMipLevels2(256, 255); )
DEF_GM( return new ShowMipLevels2(255, 256); )
DEF_GM( return new ShowMipLevels2(256, 256); )
#include "tools/Resources.h"
class ShowMipLevels3 : public skiagm::GM {
sk_sp<SkImage> fImg;

View File

@ -43,10 +43,11 @@ static void paint_rgn(SkCanvas* canvas, const SkAAClip& clip,
ToolUtils::copy_to(&bm2, bm.colorType(), bm);
canvas->drawBitmap(bm2,
SK_Scalar1 * mask.fBounds.fLeft,
SK_Scalar1 * mask.fBounds.fTop,
&paint);
canvas->drawImage(bm2.asImage(),
SK_Scalar1 * mask.fBounds.fLeft,
SK_Scalar1 * mask.fBounds.fTop,
SkSamplingOptions(),
&paint);
}
//////////////////////////////////////////////////////////////////////////////

View File

@ -167,14 +167,16 @@ protected:
// Draw the first element of the first line
x = 0;
SkPaint paint;
canvas->drawBitmap(bm, x, y, &paint);
SkSamplingOptions sampling;
canvas->drawImage(bm.asImage(), x, y);
// Draws the rest of the first line for this bitmap
// each draw being at xOffset of the previous one
for (unsigned i = 1; i < SK_ARRAY_COUNT(gColorFilterMakers); ++i) {
x += xOffset;
paint.setColorFilter(gColorFilterMakers[i]());
canvas->drawBitmap(bm, x, y, &paint);
canvas->drawImage(bm.asImage(), x, y, sampling, &paint);
}
paint.setColorFilter(nullptr);
@ -193,7 +195,7 @@ protected:
sk_sp<SkImageFilter> imageFilter2(SkImageFilters::ColorFilter(
std::move(colorFilter2), imageFilter1, nullptr));
paint.setImageFilter(std::move(imageFilter2));
canvas->drawBitmap(bm, x, y, &paint);
canvas->drawImage(bm.asImage(), x, y, sampling, &paint);
x += xOffset;
}
}

View File

@ -8,7 +8,7 @@
#include "gm/gm.h"
#include "include/core/SkBitmap.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkFilterQuality.h"
#include "include/core/SkImage.h"
#include "include/core/SkPaint.h"
#include "include/core/SkRect.h"
#include "include/core/SkScalar.h"
@ -93,9 +93,9 @@ protected:
SkIRect subRect = SkIRect::MakeLTRB(0, startItem * itemHeight,
bmp.width(), bmp.height());
SkRect dstRect = SkRect::MakeWH(SkIntToScalar(bmp.width()), 10.f * itemHeight);
SkPaint paint;
paint.setFilterQuality(kLow_SkFilterQuality);
canvas->drawBitmapRect(bmp, subRect, dstRect, &paint);
canvas->drawImageRect(bmp.asImage(), SkRect::Make(subRect), dstRect,
SkSamplingOptions(SkFilterMode::kLinear), nullptr,
SkCanvas::kStrict_SrcRectConstraint);
canvas->translate(SkIntToScalar(bmp.width() + 10), 0);
}
}

View File

@ -11,6 +11,7 @@
#include "include/core/SkCanvas.h"
#include "include/core/SkColor.h"
#include "include/core/SkColorSpace.h"
#include "include/core/SkImage.h"
#include "include/core/SkImageInfo.h"
#include "include/core/SkPaint.h"
@ -69,7 +70,7 @@ DEF_SIMPLE_GM(unpremul, canvas, 200, 200) {
bm.allocPixels(SkImageInfo::Make(100,100, kRGBA_8888_SkColorType, kUnpremul_SkAlphaType));
bm.eraseColor(color);
canvas->drawBitmap(bm, 0,0, &paint);
canvas->drawImage(bm.asImage(), 0,0, SkSamplingOptions(), &paint);
grade(50,150);
}

View File

@ -76,7 +76,7 @@ SkBitmap GMVerifier::RenderGoldBmp(skiagm::GM* gm, const SkColorInfo& colorInfo)
SkBitmap goldVerifierBmp;
goldVerifierBmp.allocPixels(SkImageInfo::Make(size, VerifierColorInfo()));
SkCanvas verifierCanvas(goldVerifierBmp);
verifierCanvas.drawBitmap(goldBmp, 0, 0);
verifierCanvas.drawImage(goldBmp.asImage(), 0, 0);
return goldVerifierBmp;
}

View File

@ -395,7 +395,7 @@ static void extract_planes(const SkBitmap& origBM,
SkMatrix matrix = SkEncodedOriginToMatrix(origin, origBM.width(), origBM.height());
SkAssertResult(matrix.invert(&matrix));
canvas.concat(matrix);
canvas.drawBitmap(origBM, 0, 0);
canvas.drawImage(origBM.asImage(), 0, 0);
if (yuvColorSpace == kIdentity_SkYUVColorSpace) {
// To test the identity color space we use JPEG YUV planes

View File

@ -199,7 +199,7 @@ private:
canvas->save();
canvas->translate(SkIntToScalar(x), SkIntToScalar(y));
canvas->clipIRect(bitmap.bounds());
canvas->drawBitmap(bitmap, 0, 0, &paint);
canvas->drawImage(bitmap.asImage(), 0, 0, SkSamplingOptions(), &paint);
canvas->restore();
}

View File

@ -133,11 +133,12 @@ class XfermodesGM : public skiagm::GM {
*/
void draw_mode(SkCanvas* canvas, SkBlendMode mode, SrcType srcType, SkScalar x, SkScalar y) {
SkPaint p;
SkSamplingOptions sampling;
SkMatrix m;
bool restoreNeeded = false;
m.setTranslate(x, y);
canvas->drawBitmap(fSrcB, x, y, &p);
canvas->drawImage(fSrcB.asImage(), x, y, sampling, &p);
p.setBlendMode(mode);
switch (srcType) {
case kSmallTransparentImage_SrcType: {
@ -145,7 +146,7 @@ class XfermodesGM : public skiagm::GM {
SkAutoCanvasRestore acr(canvas, true);
canvas->concat(m);
canvas->drawBitmap(fTransparent, 0, 0, &p);
canvas->drawImage(fTransparent.asImage(), 0, 0, sampling, &p);
break;
}
case kQuarterClearInLayer_SrcType: {
@ -195,7 +196,7 @@ class XfermodesGM : public skiagm::GM {
case kRectangleImage_SrcType: {
SkAutoCanvasRestore acr(canvas, true);
canvas->concat(m);
canvas->drawBitmap(fDstB, 0, 0, &p);
canvas->drawImage(fDstB.asImage(), 0, 0, sampling, &p);
break;
}
default:

View File

@ -1384,7 +1384,7 @@ static void test_xfermode_cropped_input(SkSurface* surf, skiatest::Reporter* rep
SkPaint paint;
paint.setImageFilter(std::move(xfermodeNoFg));
canvas->drawBitmap(bitmap, 0, 0, &paint); // drawSprite
canvas->drawImage(bitmap.asImage(), 0, 0, SkSamplingOptions(), &paint); // drawSprite
uint32_t pixel;
SkImageInfo info = SkImageInfo::Make(1, 1, kBGRA_8888_SkColorType, kUnpremul_SkAlphaType);
@ -1392,12 +1392,12 @@ static void test_xfermode_cropped_input(SkSurface* surf, skiatest::Reporter* rep
REPORTER_ASSERT(reporter, pixel == SK_ColorGREEN);
paint.setImageFilter(std::move(xfermodeNoBg));
canvas->drawBitmap(bitmap, 0, 0, &paint); // drawSprite
canvas->drawImage(bitmap.asImage(), 0, 0, SkSamplingOptions(), &paint); // drawSprite
surf->readPixels(info, &pixel, 4, 0, 0);
REPORTER_ASSERT(reporter, pixel == SK_ColorGREEN);
paint.setImageFilter(std::move(xfermodeNoFgNoBg));
canvas->drawBitmap(bitmap, 0, 0, &paint); // drawSprite
canvas->drawImage(bitmap.asImage(), 0, 0, SkSamplingOptions(), &paint); // drawSprite
surf->readPixels(info, &pixel, 4, 0, 0);
REPORTER_ASSERT(reporter, pixel == SK_ColorGREEN);
}
@ -1445,7 +1445,7 @@ DEF_TEST(ImageFilterNestedSaveLayer, reporter) {
canvas.clear(0x0);
temp.readPixels(info, &pixel, 4, 25, 25);
canvas.saveLayer(&bounds1, nullptr);
canvas.drawBitmap(bitmap, 20, 20, &filterPaint); // drawSprite
canvas.drawImage(bitmap.asImage(), 20, 20, SkSamplingOptions(), &filterPaint); // drawSprite
canvas.restore();
temp.readPixels(info, &pixel, 4, 25, 25);

View File

@ -29,12 +29,9 @@ unsigned char gPng[] = {
};
DEF_TEST(IndexedPngOverflow, reporter) {
SkBitmap image;
bool success = decode_memory(gPng, sizeof(gPng), &image);
SkBitmap bm;
bool success = decode_memory(gPng, sizeof(gPng), &bm);
REPORTER_ASSERT(reporter, success);
auto surface(SkSurface::MakeRaster(SkImageInfo::MakeN32Premul(20, 1)));
SkCanvas* canvas = surface->getCanvas();
SkRect destRect = SkRect::MakeXYWH(0, 0, 20, 1);
canvas->drawBitmapRect(image, destRect, nullptr);
SkSurface::MakeRasterN32Premul(20, 1)->getCanvas()->drawImage(bm.asImage(), 0, 0);
}

View File

@ -252,7 +252,7 @@ DEF_TEST(SkPDF_abort_jobs, rep) {
metadata.fExecutor = executor.get();
SkNullWStream dst;
auto doc = SkPDF::MakeDocument(&dst, metadata);
doc->beginPage(612, 792)->drawBitmap(b, 0, 0);
doc->beginPage(612, 792)->drawImage(b.asImage(), 0, 0);
doc->abort();
}

View File

@ -163,7 +163,7 @@ DEF_TEST(SkPDF_tagged_doc, r) {
testBitmap.allocN32Pixels(72, 72);
testBitmap.eraseColor(SK_ColorRED);
canvas->translate(72, 72);
canvas->drawBitmap(testBitmap, 0, 0);
canvas->drawImage(testBitmap.asImage(), 0, 0);
// This has a node ID but never shows up in the tag tree so it
// won't be tagged.

View File

@ -574,13 +574,14 @@ DEF_TEST(Picture, reporter) {
}
static void draw_bitmaps(const SkBitmap bitmap, SkCanvas* canvas) {
const SkPaint paint;
const SkRect rect = { 5.0f, 5.0f, 8.0f, 8.0f };
auto img = bitmap.asImage();
// Don't care what these record, as long as they're legal.
canvas->drawBitmap(bitmap, 0.0f, 0.0f, &paint);
canvas->drawBitmapRect(bitmap, rect, rect, &paint, SkCanvas::kStrict_SrcRectConstraint);
canvas->drawBitmap(bitmap, 1, 1); // drawSprite
canvas->drawImage(img, 0.0f, 0.0f);
canvas->drawImageRect(img, rect, rect, SkSamplingOptions(), nullptr,
SkCanvas::kStrict_SrcRectConstraint);
canvas->drawImage(img, 1, 1); // drawSprite
}
static void test_draw_bitmaps(SkCanvas* canvas) {