drawBitmap is deprecated
- update call-sites in gms - start deleting obsolete/duplicated gms Change-Id: I9ab5aa0a22d4603ccb43715c0583eb587bbe5c8e Reviewed-on: https://skia-review.googlesource.com/c/skia/+/358217 Reviewed-by: Mike Reed <reed@google.com> Commit-Queue: Mike Reed <reed@google.com>
This commit is contained in:
parent
5bbf727573
commit
568f0ae778
@ -120,13 +120,13 @@ static void test_image(SkCanvas* canvas, const SkImageInfo& info) {
|
||||
paint.setAntiAlias(true);
|
||||
paint.setColor(SK_ColorBLUE);
|
||||
make_canvas(bm)->drawCircle(50, 50, 49, paint);
|
||||
canvas->drawBitmap(bm, 10, 10);
|
||||
canvas->drawImage(bm.asImage(), 10, 10);
|
||||
|
||||
CGImageRef image = SkCreateCGImageRefWithColorspace(bm, nullptr);
|
||||
|
||||
SkBitmap bm2;
|
||||
SkCreateBitmapFromCGImage(&bm2, image);
|
||||
canvas->drawBitmap(bm2, 10, 120);
|
||||
canvas->drawImage(bm2.asImage(), 10, 120);
|
||||
canvas->drawImage(SkMakeImageFromCGImage(image), 10, 120 + bm2.height() + 10);
|
||||
|
||||
CGImageRelease(image);
|
||||
|
@ -69,7 +69,7 @@ private:
|
||||
}
|
||||
}
|
||||
|
||||
canvas->drawBitmap(bm, 0, 0);
|
||||
canvas->drawImage(bm.asImage(), 0, 0);
|
||||
}
|
||||
|
||||
public:
|
||||
|
@ -153,11 +153,14 @@ protected:
|
||||
void onDraw(SkCanvas* canvas) override {
|
||||
SkPaint paint;
|
||||
paint.setAntiAlias(true);
|
||||
paint.setFilterQuality(kLow_SkFilterQuality);
|
||||
paint.setColor(SK_ColorRED);
|
||||
|
||||
canvas->drawBitmap(fBitmap, 10, 10, &paint); // should stay blue (ignore paint's color)
|
||||
canvas->drawBitmap(fAlpha, 120, 10, &paint); // should draw red
|
||||
SkSamplingOptions sampling(SkFilterMode::kLinear);
|
||||
|
||||
// should stay blue (ignore paint's color)
|
||||
canvas->drawImage(fBitmap.asImage(), 10, 10, sampling, &paint);
|
||||
// should draw red
|
||||
canvas->drawImage(fAlpha.asImage(), 120, 10, sampling, &paint);
|
||||
}
|
||||
|
||||
private:
|
||||
|
@ -60,8 +60,8 @@ protected:
|
||||
SkCanvas legacyCanvas(legacyBMCanvas);
|
||||
legacyCanvas.drawImage(image, 0.0f, 0.0f);
|
||||
legacyCanvas.translate(SkScalar(kSize), 0.0f);
|
||||
legacyCanvas.drawBitmap(bitmap, 0.0f, 0.0f, nullptr);
|
||||
canvas->drawBitmap(legacyBMCanvas, 0.0f, 0.0f, nullptr);
|
||||
legacyCanvas.drawImage(bitmap.asImage(), 0.0f, 0.0f);
|
||||
canvas->drawImage(legacyBMCanvas.asImage(), 0.0f, 0.0f);
|
||||
canvas->translate(0.0f, SkScalar(kSize));
|
||||
|
||||
// The bottom two squares show an sRGB image, then bitmap, drawn to a srgb canvas.
|
||||
@ -71,8 +71,8 @@ protected:
|
||||
SkCanvas srgbCanvas(srgbBMCanvas);
|
||||
srgbCanvas.drawImage(image, 0.0f, 0.0f);
|
||||
srgbCanvas.translate(SkScalar(kSize), 0.0f);
|
||||
srgbCanvas.drawBitmap(bitmap, 0.0f, 0.0f, nullptr);
|
||||
canvas->drawBitmap(srgbBMCanvas, 0.0f, 0.0f, nullptr);
|
||||
srgbCanvas.drawImage(bitmap.asImage(), 0.0f, 0.0f);
|
||||
canvas->drawImage(srgbBMCanvas.asImage(), 0.0f, 0.0f);
|
||||
return DrawResult::kOk;
|
||||
}
|
||||
|
||||
|
@ -418,7 +418,7 @@ DEF_SIMPLE_GM(clip_shader_persp, canvas, 1370, 1030) {
|
||||
}
|
||||
|
||||
// Actual draw and clip boundary are the same for all configs
|
||||
canvas->clipRect(SkRect::MakeIWH(img->width(), img->height()));
|
||||
canvas->clipIRect(img->bounds());
|
||||
canvas->clear(SK_ColorBLACK);
|
||||
canvas->drawImage(img, 0, 0);
|
||||
|
||||
|
@ -36,7 +36,7 @@ protected:
|
||||
}
|
||||
|
||||
void onOnceBeforeDraw() override {
|
||||
fBitmap = ToolUtils::create_string_bitmap(80, 80, 0xFF884422, 15, 55, 96, "g");
|
||||
fImage = ToolUtils::create_string_image(80, 80, 0xFF884422, 15, 55, 96, "g");
|
||||
|
||||
SkColor c1 = ToolUtils::color_to_565(0xFF244484);
|
||||
SkColor c2 = ToolUtils::color_to_565(0xFF804020);
|
||||
@ -55,8 +55,8 @@ protected:
|
||||
void drawClippedBitmap(SkCanvas* canvas, int x, int y, const SkPaint& paint) const {
|
||||
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(fImage->bounds());
|
||||
canvas->drawImage(fImage, 0, 0, SkSamplingOptions(), &paint);
|
||||
canvas->restore();
|
||||
}
|
||||
|
||||
@ -161,7 +161,7 @@ protected:
|
||||
}
|
||||
|
||||
private:
|
||||
SkBitmap fBitmap;
|
||||
sk_sp<SkImage> fImage;
|
||||
sk_sp<SkImage> fCheckerboard, fSmall, fLarge, fLargeW, fLargeH;
|
||||
|
||||
using INHERITED = GM;
|
||||
|
@ -1,160 +0,0 @@
|
||||
/*
|
||||
* Copyright 2013 Google Inc.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license that can be
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
#include "gm/gm.h"
|
||||
#include "include/core/SkBitmap.h"
|
||||
#include "include/core/SkCanvas.h"
|
||||
#include "include/core/SkColor.h"
|
||||
#include "include/core/SkFilterQuality.h"
|
||||
#include "include/core/SkFont.h"
|
||||
#include "include/core/SkFontStyle.h"
|
||||
#include "include/core/SkImageInfo.h"
|
||||
#include "include/core/SkMatrix.h"
|
||||
#include "include/core/SkPaint.h"
|
||||
#include "include/core/SkPixmap.h"
|
||||
#include "include/core/SkScalar.h"
|
||||
#include "include/core/SkSize.h"
|
||||
#include "include/core/SkString.h"
|
||||
#include "include/core/SkTypeface.h"
|
||||
#include "include/core/SkTypes.h"
|
||||
#include "tools/Resources.h"
|
||||
#include "tools/ToolUtils.h"
|
||||
|
||||
static const char* kFilterQualityNames[] = { "none", "low", "medium", "high" };
|
||||
|
||||
struct DownsampleBitmapGM : public skiagm::GM {
|
||||
SkBitmap (*fMakeBitmap)(SkImageInfo);
|
||||
SkString fName;
|
||||
SkFilterQuality fFilterQuality;
|
||||
|
||||
DownsampleBitmapGM(SkBitmap (*fn)(SkImageInfo), const char* kind, SkFilterQuality fq)
|
||||
: fMakeBitmap(fn)
|
||||
, fName(SkStringPrintf("downsamplebitmap_%s_%s", kind, kFilterQualityNames[fq]))
|
||||
, fFilterQuality(fq)
|
||||
{
|
||||
this->setBGColor(0xFFDDDDDD);
|
||||
}
|
||||
|
||||
SkString onShortName() override { return fName; }
|
||||
|
||||
SkISize onISize() override {
|
||||
SkBitmap bm = fMakeBitmap(SkImageInfo::MakeN32Premul(1,1)/*whatever*/);
|
||||
return SkISize::Make(bm.width(), 4 * bm.height());
|
||||
}
|
||||
|
||||
void onDraw(SkCanvas* canvas) override {
|
||||
SkImageInfo info = canvas->imageInfo();
|
||||
if (!info.colorType()) { info = info.makeColorType( kN32_SkColorType); }
|
||||
if (!info.alphaType()) { info = info.makeAlphaType(kPremul_SkAlphaType); }
|
||||
|
||||
SkBitmap bm = fMakeBitmap(info);
|
||||
bm.setImmutable();
|
||||
|
||||
int curY = 0;
|
||||
int curHeight;
|
||||
float curScale = 1;
|
||||
do {
|
||||
|
||||
SkMatrix matrix;
|
||||
matrix.setScale( curScale, curScale );
|
||||
|
||||
SkPaint paint;
|
||||
paint.setFilterQuality(fFilterQuality);
|
||||
|
||||
canvas->save();
|
||||
canvas->translate(0, (SkScalar)curY);
|
||||
canvas->concat(matrix);
|
||||
canvas->drawBitmap(bm, 0, 0, &paint);
|
||||
canvas->restore();
|
||||
|
||||
curHeight = (int) (bm.height() * curScale + 2);
|
||||
curY += curHeight;
|
||||
curScale *= 0.75f;
|
||||
} while (curHeight >= 2 && curY < 4*bm.height());
|
||||
}
|
||||
};
|
||||
|
||||
static SkBitmap convert_bitmap_format(SkBitmap src, SkImageInfo info) {
|
||||
SkBitmap dst;
|
||||
dst.allocPixels(info.makeDimensions(src.dimensions()));
|
||||
|
||||
SkPixmap pm;
|
||||
SkAssertResult(dst.peekPixels(&pm));
|
||||
SkAssertResult(src.readPixels(pm));
|
||||
|
||||
return dst;
|
||||
}
|
||||
|
||||
|
||||
static SkBitmap make_text(SkImageInfo info) {
|
||||
const SkScalar textSize = 72;
|
||||
|
||||
SkBitmap bm;
|
||||
bm.allocPixels(info.makeWH(int(textSize * 8), int(textSize * 6)));
|
||||
SkCanvas canvas(bm);
|
||||
canvas.drawColor(SK_ColorWHITE);
|
||||
|
||||
SkPaint paint;
|
||||
SkFont font;
|
||||
font.setSubpixel(true);
|
||||
font.setSize(textSize);
|
||||
|
||||
font.setTypeface(ToolUtils::create_portable_typeface("serif", SkFontStyle()));
|
||||
canvas.drawString("Hamburgefons", textSize/2, 1.2f*textSize, font, paint);
|
||||
font.setTypeface(ToolUtils::create_portable_typeface("serif", SkFontStyle::Bold()));
|
||||
canvas.drawString("Hamburgefons", textSize/2, 2.4f*textSize, font, paint);
|
||||
font.setTypeface(ToolUtils::create_portable_typeface("serif", SkFontStyle::Italic()));
|
||||
canvas.drawString("Hamburgefons", textSize/2, 3.6f*textSize, font, paint);
|
||||
font.setTypeface(ToolUtils::create_portable_typeface("serif", SkFontStyle::BoldItalic()));
|
||||
canvas.drawString("Hamburgefons", textSize/2, 4.8f*textSize, font, paint);
|
||||
|
||||
return bm;
|
||||
}
|
||||
DEF_GM( return new DownsampleBitmapGM(make_text, "text", kHigh_SkFilterQuality); )
|
||||
DEF_GM( return new DownsampleBitmapGM(make_text, "text", kMedium_SkFilterQuality); )
|
||||
DEF_GM( return new DownsampleBitmapGM(make_text, "text", kLow_SkFilterQuality); )
|
||||
DEF_GM( return new DownsampleBitmapGM(make_text, "text", kNone_SkFilterQuality); )
|
||||
|
||||
|
||||
static SkBitmap make_checkerboard(SkImageInfo info) {
|
||||
const auto size = 512;
|
||||
const auto numChecks = 256;
|
||||
|
||||
SkBitmap bm;
|
||||
bm.allocN32Pixels(size,size);
|
||||
for (int y = 0; y < size; ++y) {
|
||||
for (int x = 0; x < size; ++x) {
|
||||
SkPMColor* s = bm.getAddr32(x, y);
|
||||
int cx = (x * numChecks) / size;
|
||||
int cy = (y * numChecks) / size;
|
||||
if ((cx+cy)%2) {
|
||||
*s = 0xFFFFFFFF;
|
||||
} else {
|
||||
*s = 0xFF000000;
|
||||
}
|
||||
}
|
||||
}
|
||||
return convert_bitmap_format(bm, info);
|
||||
}
|
||||
DEF_GM( return new DownsampleBitmapGM(make_checkerboard, "checkerboard", kHigh_SkFilterQuality); )
|
||||
DEF_GM( return new DownsampleBitmapGM(make_checkerboard, "checkerboard", kMedium_SkFilterQuality); )
|
||||
DEF_GM( return new DownsampleBitmapGM(make_checkerboard, "checkerboard", kLow_SkFilterQuality); )
|
||||
DEF_GM( return new DownsampleBitmapGM(make_checkerboard, "checkerboard", kNone_SkFilterQuality); )
|
||||
|
||||
|
||||
static SkBitmap make_image(SkImageInfo info) {
|
||||
SkBitmap bm;
|
||||
if (!GetResourceAsBitmap("images/mandrill_512.png", &bm)) {
|
||||
bm.allocN32Pixels(1, 1);
|
||||
bm.eraseARGB(255, 255, 0 , 0); // red == bad
|
||||
}
|
||||
return convert_bitmap_format(bm, info);
|
||||
}
|
||||
DEF_GM( return new DownsampleBitmapGM(make_image, "image", kHigh_SkFilterQuality); )
|
||||
DEF_GM( return new DownsampleBitmapGM(make_image, "image", kMedium_SkFilterQuality); )
|
||||
DEF_GM( return new DownsampleBitmapGM(make_image, "image", kLow_SkFilterQuality); )
|
||||
DEF_GM( return new DownsampleBitmapGM(make_image, "image", kNone_SkFilterQuality); )
|
@ -67,16 +67,13 @@ static void draw_bitmap(SkCanvas* canvas, const SkRect& r, sk_sp<SkImageFilter>
|
||||
SkIRect bounds;
|
||||
r.roundOut(&bounds);
|
||||
|
||||
SkBitmap bm;
|
||||
bm.allocN32Pixels(bounds.width(), bounds.height());
|
||||
bm.eraseColor(SK_ColorTRANSPARENT);
|
||||
SkCanvas c(bm);
|
||||
draw_path(&c, r, nullptr);
|
||||
auto surf = SkSurface::MakeRasterN32Premul(bounds.width(), bounds.height());
|
||||
draw_path(surf->getCanvas(), r, nullptr);
|
||||
|
||||
paint.setImageFilter(std::move(imf));
|
||||
canvas->save();
|
||||
canvas->clipRect(r);
|
||||
canvas->drawBitmap(bm, 0, 0, &paint);
|
||||
surf->draw(canvas, 0, 0, SkSamplingOptions(), &paint);
|
||||
canvas->restore();
|
||||
}
|
||||
|
||||
|
@ -1,228 +0,0 @@
|
||||
/*
|
||||
* Copyright 2011 Google Inc.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license that can be
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
#include "gm/gm.h"
|
||||
#include "include/core/SkBitmap.h"
|
||||
#include "include/core/SkCanvas.h"
|
||||
#include "include/core/SkColor.h"
|
||||
#include "include/core/SkFilterQuality.h"
|
||||
#include "include/core/SkFont.h"
|
||||
#include "include/core/SkFontStyle.h"
|
||||
#include "include/core/SkMatrix.h"
|
||||
#include "include/core/SkPaint.h"
|
||||
#include "include/core/SkRect.h"
|
||||
#include "include/core/SkScalar.h"
|
||||
#include "include/core/SkSize.h"
|
||||
#include "include/core/SkString.h"
|
||||
#include "include/core/SkTypeface.h"
|
||||
#include "include/core/SkTypes.h"
|
||||
#include "tools/Resources.h"
|
||||
#include "tools/ToolUtils.h"
|
||||
|
||||
static void setTypeface(SkFont* font, const char name[], SkFontStyle style) {
|
||||
font->setTypeface(ToolUtils::create_portable_typeface(name, style));
|
||||
}
|
||||
|
||||
static SkSize computeSize(const SkBitmap& bm, const SkMatrix& mat) {
|
||||
SkRect bounds = SkRect::MakeWH(SkIntToScalar(bm.width()),
|
||||
SkIntToScalar(bm.height()));
|
||||
mat.mapRect(&bounds);
|
||||
return SkSize::Make(bounds.width(), bounds.height());
|
||||
}
|
||||
|
||||
static void draw_cell(SkCanvas* canvas, const SkBitmap& bm, const SkMatrix& mat, SkScalar dx,
|
||||
SkFilterQuality lvl) {
|
||||
SkPaint paint;
|
||||
paint.setFilterQuality(lvl);
|
||||
|
||||
SkAutoCanvasRestore acr(canvas, true);
|
||||
canvas->translate(dx, 0);
|
||||
canvas->concat(mat);
|
||||
canvas->drawBitmap(bm, 0, 0, &paint);
|
||||
}
|
||||
|
||||
static void draw_row(SkCanvas* canvas, const SkBitmap& bm, const SkMatrix& mat, SkScalar dx) {
|
||||
draw_cell(canvas, bm, mat, 0 * dx, kNone_SkFilterQuality);
|
||||
draw_cell(canvas, bm, mat, 1 * dx, kLow_SkFilterQuality);
|
||||
draw_cell(canvas, bm, mat, 2 * dx, kMedium_SkFilterQuality);
|
||||
draw_cell(canvas, bm, mat, 3 * dx, kHigh_SkFilterQuality);
|
||||
}
|
||||
|
||||
class FilterBitmapGM : public skiagm::GM {
|
||||
void onOnceBeforeDraw() override {
|
||||
this->setBGColor(0xFFDDDDDD);
|
||||
|
||||
this->makeBitmap();
|
||||
fBM.setImmutable();
|
||||
|
||||
SkScalar cx = SkScalarHalf(fBM.width());
|
||||
SkScalar cy = SkScalarHalf(fBM.height());
|
||||
SkScalar scale = this->getScale();
|
||||
|
||||
// these two matrices use a scale factor configured by the subclass
|
||||
fMatrix[0].setScale(scale, scale);
|
||||
fMatrix[1].setRotate(30, cx, cy); fMatrix[1].postScale(scale, scale);
|
||||
|
||||
// up/down scaling mix
|
||||
fMatrix[2].setScale(0.7f, 1.05f);
|
||||
}
|
||||
|
||||
protected:
|
||||
SkBitmap fBM;
|
||||
SkMatrix fMatrix[3];
|
||||
|
||||
SkISize onISize() override { return SkISize::Make(1024, 768); }
|
||||
|
||||
virtual void makeBitmap() = 0;
|
||||
virtual SkScalar getScale() = 0;
|
||||
|
||||
void onDraw(SkCanvas* canvas) override {
|
||||
|
||||
canvas->translate(10, 10);
|
||||
for (size_t i = 0; i < SK_ARRAY_COUNT(fMatrix); ++i) {
|
||||
SkSize size = computeSize(fBM, fMatrix[i]);
|
||||
size.fWidth += 20;
|
||||
size.fHeight += 20;
|
||||
|
||||
draw_row(canvas, fBM, fMatrix[i], size.fWidth);
|
||||
canvas->translate(0, size.fHeight);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
class FilterBitmapTextGM: public FilterBitmapGM {
|
||||
public:
|
||||
FilterBitmapTextGM(float textSize) : fTextSize(textSize) {}
|
||||
|
||||
private:
|
||||
SkString onShortName() override {
|
||||
return SkStringPrintf("filterbitmap_text_%.2fpt", fTextSize);
|
||||
}
|
||||
const float fTextSize;
|
||||
|
||||
SkScalar getScale() override {
|
||||
return 32.f/fTextSize;
|
||||
}
|
||||
|
||||
void makeBitmap() override {
|
||||
fBM.allocN32Pixels(int(fTextSize * 8), int(fTextSize * 6));
|
||||
SkCanvas canvas(fBM);
|
||||
canvas.drawColor(SK_ColorWHITE);
|
||||
|
||||
SkPaint paint;
|
||||
SkFont font;
|
||||
font.setSize(fTextSize);
|
||||
font.setSubpixel(true);
|
||||
|
||||
setTypeface(&font, "serif", SkFontStyle::Normal());
|
||||
canvas.drawString("Hamburgefons", fTextSize/2, 1.2f*fTextSize, font, paint);
|
||||
setTypeface(&font, "serif", SkFontStyle::Bold());
|
||||
canvas.drawString("Hamburgefons", fTextSize/2, 2.4f*fTextSize, font, paint);
|
||||
setTypeface(&font, "serif", SkFontStyle::Italic());
|
||||
canvas.drawString("Hamburgefons", fTextSize/2, 3.6f*fTextSize, font, paint);
|
||||
setTypeface(&font, "serif", SkFontStyle::BoldItalic());
|
||||
canvas.drawString("Hamburgefons", fTextSize/2, 4.8f*fTextSize, font, paint);
|
||||
}
|
||||
};
|
||||
|
||||
class FilterBitmapCheckerboardGM: public FilterBitmapGM {
|
||||
SkString onShortName() override {
|
||||
return SkStringPrintf("filterbitmap_checkerboard_%d_%d%s",
|
||||
fSize, fNumChecks, fConvertToG8 ? "_g8" : "");
|
||||
}
|
||||
public:
|
||||
FilterBitmapCheckerboardGM(int size, int num_checks, bool convertToG8 = false)
|
||||
: fSize(size), fNumChecks(num_checks), fConvertToG8(convertToG8) {}
|
||||
|
||||
protected:
|
||||
int fSize;
|
||||
int fNumChecks;
|
||||
|
||||
SkScalar getScale() override {
|
||||
return 192.f/fSize;
|
||||
}
|
||||
|
||||
void makeBitmap() override {
|
||||
fBM.allocN32Pixels(fSize, fSize);
|
||||
for (int y = 0; y < fSize; y ++) {
|
||||
for (int x = 0; x < fSize; x ++) {
|
||||
SkPMColor* s = fBM.getAddr32(x, y);
|
||||
int cx = (x * fNumChecks) / fSize;
|
||||
int cy = (y * fNumChecks) / fSize;
|
||||
if ((cx+cy)%2) {
|
||||
*s = 0xFFFFFFFF;
|
||||
} else {
|
||||
*s = 0xFF000000;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (fConvertToG8) {
|
||||
SkBitmap tmp;
|
||||
ToolUtils::copy_to_g8(&tmp, fBM);
|
||||
fBM = tmp;
|
||||
}
|
||||
}
|
||||
private:
|
||||
const bool fConvertToG8;
|
||||
using INHERITED = FilterBitmapGM;
|
||||
};
|
||||
|
||||
class FilterBitmapImageGM: public FilterBitmapGM {
|
||||
const char* fFilename;
|
||||
int fSize;
|
||||
|
||||
SkString onShortName() override {
|
||||
return SkStringPrintf("filterbitmap_image_%s%s", fFilename, fConvertToG8 ? "_g8" : "");
|
||||
}
|
||||
|
||||
public:
|
||||
FilterBitmapImageGM(const char filename[], bool convertToG8 = false)
|
||||
: fFilename(filename), fConvertToG8(convertToG8) {}
|
||||
|
||||
protected:
|
||||
SkScalar getScale() override {
|
||||
return 192.f/fSize;
|
||||
}
|
||||
|
||||
void makeBitmap() override {
|
||||
SkString resource = SkStringPrintf("images/%s", fFilename);
|
||||
if (!GetResourceAsBitmap(resource.c_str(), &fBM)) {
|
||||
fBM.allocN32Pixels(1, 1);
|
||||
fBM.eraseARGB(255, 255, 0 , 0); // red == bad
|
||||
}
|
||||
fSize = fBM.height();
|
||||
|
||||
if (fConvertToG8) {
|
||||
SkBitmap tmp;
|
||||
ToolUtils::copy_to_g8(&tmp, fBM);
|
||||
fBM = tmp;
|
||||
}
|
||||
}
|
||||
private:
|
||||
const bool fConvertToG8;
|
||||
using INHERITED = FilterBitmapGM;
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
DEF_GM( return new FilterBitmapTextGM(3); )
|
||||
DEF_GM( return new FilterBitmapTextGM(7); )
|
||||
DEF_GM( return new FilterBitmapTextGM(10); )
|
||||
DEF_GM( return new FilterBitmapCheckerboardGM(4,4); )
|
||||
DEF_GM( return new FilterBitmapCheckerboardGM(32,32); )
|
||||
DEF_GM( return new FilterBitmapCheckerboardGM(32,32, true); )
|
||||
DEF_GM( return new FilterBitmapCheckerboardGM(32,8); )
|
||||
DEF_GM( return new FilterBitmapCheckerboardGM(32,2); )
|
||||
DEF_GM( return new FilterBitmapCheckerboardGM(192,192); )
|
||||
DEF_GM( return new FilterBitmapImageGM("mandrill_16.png"); )
|
||||
DEF_GM( return new FilterBitmapImageGM("mandrill_32.png"); )
|
||||
DEF_GM( return new FilterBitmapImageGM("mandrill_64.png"); )
|
||||
DEF_GM( return new FilterBitmapImageGM("mandrill_64.png", true); )
|
||||
DEF_GM( return new FilterBitmapImageGM("mandrill_128.png"); )
|
||||
DEF_GM( return new FilterBitmapImageGM("mandrill_256.png"); )
|
||||
DEF_GM( return new FilterBitmapImageGM("mandrill_512.png"); )
|
||||
DEF_GM( return new FilterBitmapImageGM("color_wheel.png"); )
|
@ -47,7 +47,7 @@ static void draw_image(SkCanvas* canvas, const sk_sp<SkImage> image, sk_sp<SkIma
|
||||
paint.setImageFilter(std::move(filter));
|
||||
|
||||
canvas->translate(SkIntToScalar(30), 0);
|
||||
canvas->clipRect(SkRect::MakeIWH(image->width(),image->height()));
|
||||
canvas->clipIRect(image->bounds());
|
||||
canvas->drawImage(image, 0, 0, SkSamplingOptions(), &paint);
|
||||
}
|
||||
|
||||
|
@ -67,7 +67,7 @@ static void draw_image(SkCanvas* canvas, const sk_sp<SkImage> image, sk_sp<SkIma
|
||||
paint.setImageFilter(std::move(filter));
|
||||
|
||||
canvas->translate(SkIntToScalar(30), 0);
|
||||
canvas->clipRect(SkRect::MakeIWH(image->width(),image->height()));
|
||||
canvas->clipIRect(image->bounds());
|
||||
canvas->drawImage(image, 0, 0, SkSamplingOptions(), &paint);
|
||||
}
|
||||
|
||||
|
@ -28,10 +28,9 @@
|
||||
|
||||
namespace {
|
||||
|
||||
void make_checkerboard(SkBitmap* bitmap);
|
||||
sk_sp<SkImage> make_checkerboard();
|
||||
sk_sp<SkImage> make_gradient_circle(int width, int height);
|
||||
void draw(SkCanvas* canvas, const SkBitmap& bitmap, const SkIRect& rect,
|
||||
sk_sp<SkImageFilter> filter);
|
||||
void draw(SkCanvas*, sk_sp<SkImage>, const SkIRect&, sk_sp<SkImageFilter>);
|
||||
|
||||
} // namespace
|
||||
|
||||
@ -41,8 +40,7 @@ DEF_SIMPLE_GM(imagefilterscropexpand, canvas, 730, 650) {
|
||||
SkIRect cropRect = SkIRect::MakeXYWH(10, 10, 44, 44);
|
||||
|
||||
sk_sp<SkImage> gradientCircle(make_gradient_circle(64, 64));
|
||||
SkBitmap checkerboard;
|
||||
make_checkerboard(&checkerboard);
|
||||
auto checkerboard = make_checkerboard();
|
||||
|
||||
sk_sp<SkImageFilter> gradientCircleSource(SkImageFilters::Image(std::move(gradientCircle)));
|
||||
sk_sp<SkImageFilter> noopCropped(SkImageFilters::Offset(0, 0, nullptr, &cropRect));
|
||||
@ -106,25 +104,26 @@ DEF_SIMPLE_GM(imagefilterscropexpand, canvas, 730, 650) {
|
||||
}
|
||||
|
||||
namespace {
|
||||
void make_checkerboard(SkBitmap* bitmap) {
|
||||
bitmap->allocN32Pixels(64, 64);
|
||||
SkCanvas canvas(*bitmap);
|
||||
canvas.clear(0xFFFF0000);
|
||||
sk_sp<SkImage> make_checkerboard() {
|
||||
auto surf = SkSurface::MakeRasterN32Premul(64, 64);
|
||||
auto canvas = surf->getCanvas();
|
||||
canvas->clear(0xFFFF0000);
|
||||
SkPaint darkPaint;
|
||||
darkPaint.setColor(0xFF404040);
|
||||
SkPaint lightPaint;
|
||||
lightPaint.setColor(0xFFA0A0A0);
|
||||
for (int y = 8; y < 48; y += 16) {
|
||||
for (int x = 8; x < 48; x += 16) {
|
||||
canvas.save();
|
||||
canvas.translate(SkIntToScalar(x), SkIntToScalar(y));
|
||||
canvas.drawRect(SkRect::MakeXYWH(0, 0, 8, 8), darkPaint);
|
||||
canvas.drawRect(SkRect::MakeXYWH(8, 0, 8, 8), lightPaint);
|
||||
canvas.drawRect(SkRect::MakeXYWH(0, 8, 8, 8), lightPaint);
|
||||
canvas.drawRect(SkRect::MakeXYWH(8, 8, 8, 8), darkPaint);
|
||||
canvas.restore();
|
||||
canvas->save();
|
||||
canvas->translate(SkIntToScalar(x), SkIntToScalar(y));
|
||||
canvas->drawRect(SkRect::MakeXYWH(0, 0, 8, 8), darkPaint);
|
||||
canvas->drawRect(SkRect::MakeXYWH(8, 0, 8, 8), lightPaint);
|
||||
canvas->drawRect(SkRect::MakeXYWH(0, 8, 8, 8), lightPaint);
|
||||
canvas->drawRect(SkRect::MakeXYWH(8, 8, 8, 8), darkPaint);
|
||||
canvas->restore();
|
||||
}
|
||||
}
|
||||
return surf->makeImageSnapshot();
|
||||
}
|
||||
|
||||
sk_sp<SkImage> make_gradient_circle(int width, int height) {
|
||||
@ -145,7 +144,7 @@ namespace {
|
||||
return surface->makeImageSnapshot();
|
||||
}
|
||||
|
||||
void draw(SkCanvas* canvas, const SkBitmap& bitmap, const SkIRect& layerRect,
|
||||
void draw(SkCanvas* canvas, sk_sp<SkImage> image, const SkIRect& layerRect,
|
||||
sk_sp<SkImageFilter> filter) {
|
||||
// Convert SkIRect to SkRect since that's what saveLayer and drawRect need
|
||||
SkRect rect = SkRect::Make(layerRect);
|
||||
@ -153,7 +152,7 @@ namespace {
|
||||
SkPaint paint;
|
||||
paint.setImageFilter(std::move(filter));
|
||||
canvas->saveLayer(&rect, &paint);
|
||||
canvas->drawBitmap(bitmap, 0, 0);
|
||||
canvas->drawImage(image, 0, 0);
|
||||
canvas->restore();
|
||||
|
||||
SkPaint strokePaint;
|
||||
|
@ -62,14 +62,11 @@ static void draw_bitmap(SkCanvas* canvas, const SkRect& r, sk_sp<SkImageFilter>
|
||||
SkIRect bounds;
|
||||
r.roundOut(&bounds);
|
||||
|
||||
SkBitmap bm;
|
||||
bm.allocN32Pixels(bounds.width(), bounds.height());
|
||||
bm.eraseColor(SK_ColorTRANSPARENT);
|
||||
SkCanvas c(bm);
|
||||
draw_path(&c, r, nullptr);
|
||||
auto surf = SkSurface::MakeRasterN32Premul(bounds.width(), bounds.height());
|
||||
draw_path(surf->getCanvas(), r, nullptr);
|
||||
|
||||
paint.setImageFilter(std::move(imf));
|
||||
canvas->drawBitmap(bm, 0, 0, &paint);
|
||||
surf->draw(canvas, 0, 0, SkSamplingOptions(), &paint);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
@ -86,24 +83,24 @@ protected:
|
||||
SkISize onISize() override { return SkISize::Make(400, 960); }
|
||||
|
||||
void make_checkerboard() {
|
||||
fCheckerboard.allocN32Pixels(80, 80);
|
||||
SkCanvas canvas(fCheckerboard);
|
||||
canvas.clear(SK_ColorTRANSPARENT);
|
||||
auto surf = SkSurface::MakeRasterN32Premul(80, 80);
|
||||
auto canvas = surf->getCanvas();
|
||||
SkPaint darkPaint;
|
||||
darkPaint.setColor(0xFF404040);
|
||||
SkPaint lightPaint;
|
||||
lightPaint.setColor(0xFFA0A0A0);
|
||||
for (int y = 0; y < 80; y += 16) {
|
||||
for (int x = 0; x < 80; x += 16) {
|
||||
canvas.save();
|
||||
canvas.translate(SkIntToScalar(x), SkIntToScalar(y));
|
||||
canvas.drawRect(SkRect::MakeXYWH(0, 0, 8, 8), darkPaint);
|
||||
canvas.drawRect(SkRect::MakeXYWH(8, 0, 8, 8), lightPaint);
|
||||
canvas.drawRect(SkRect::MakeXYWH(0, 8, 8, 8), lightPaint);
|
||||
canvas.drawRect(SkRect::MakeXYWH(8, 8, 8, 8), darkPaint);
|
||||
canvas.restore();
|
||||
canvas->save();
|
||||
canvas->translate(SkIntToScalar(x), SkIntToScalar(y));
|
||||
canvas->drawRect(SkRect::MakeXYWH(0, 0, 8, 8), darkPaint);
|
||||
canvas->drawRect(SkRect::MakeXYWH(8, 0, 8, 8), lightPaint);
|
||||
canvas->drawRect(SkRect::MakeXYWH(0, 8, 8, 8), lightPaint);
|
||||
canvas->drawRect(SkRect::MakeXYWH(8, 8, 8, 8), darkPaint);
|
||||
canvas->restore();
|
||||
}
|
||||
}
|
||||
fCheckerboard = surf->makeImageSnapshot();
|
||||
}
|
||||
|
||||
void draw_frame(SkCanvas* canvas, const SkRect& r) {
|
||||
@ -161,7 +158,7 @@ protected:
|
||||
canvas->save();
|
||||
for (size_t i = 0; i < SK_ARRAY_COUNT(filters); ++i) {
|
||||
SkPaint paint;
|
||||
canvas->drawBitmap(fCheckerboard, 0, 0);
|
||||
canvas->drawImage(fCheckerboard, 0, 0);
|
||||
drawProc[j](canvas, r, filters[i]);
|
||||
canvas->translate(0, DY);
|
||||
}
|
||||
@ -171,7 +168,7 @@ protected:
|
||||
}
|
||||
|
||||
private:
|
||||
SkBitmap fCheckerboard;
|
||||
sk_sp<SkImage> fCheckerboard;
|
||||
using INHERITED = GM;
|
||||
};
|
||||
|
||||
|
@ -148,7 +148,7 @@ protected:
|
||||
private:
|
||||
static void DrawClippedImage(SkCanvas* canvas, const SkImage* image, const SkPaint& paint) {
|
||||
canvas->save();
|
||||
canvas->clipRect(SkRect::MakeIWH(image->width(), image->height()));
|
||||
canvas->clipIRect(image->bounds());
|
||||
canvas->drawImage(image, 0, 0, SkSamplingOptions(), &paint);
|
||||
canvas->restore();
|
||||
}
|
||||
|
@ -261,7 +261,7 @@ private:
|
||||
|
||||
canvas->save();
|
||||
canvas->translate(tx, ty);
|
||||
canvas->clipRect(SkRect::MakeIWH(256, 256));
|
||||
canvas->clipRect(SkRect::MakeWH(256, 256));
|
||||
canvas->scale(0.5f, 0.5f);
|
||||
canvas->translate(128, 128);
|
||||
canvas->drawImage(fImage, 0, 0, SkSamplingOptions(), &p);
|
||||
|
@ -37,15 +37,15 @@ protected:
|
||||
}
|
||||
|
||||
void onOnceBeforeDraw() override {
|
||||
fBitmap.allocN32Pixels(135, 135);
|
||||
SkCanvas canvas(fBitmap);
|
||||
canvas.clear(0x0);
|
||||
auto surf = SkSurface::MakeRasterN32Premul(135, 135);
|
||||
|
||||
SkFont font(ToolUtils::create_portable_typeface(), 64.0f);
|
||||
SkPaint paint;
|
||||
paint.setColor(0xFFFFFFFF);
|
||||
canvas.drawString("ABC", 10, 55, font, paint);
|
||||
canvas.drawString("XYZ", 10, 110, font, paint);
|
||||
surf->getCanvas()->drawString("ABC", 10, 55, font, paint);
|
||||
surf->getCanvas()->drawString("XYZ", 10, 110, font, paint);
|
||||
|
||||
fImage = surf->makeImageSnapshot();
|
||||
}
|
||||
|
||||
SkISize onISize() override {
|
||||
@ -55,9 +55,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(fImage->bounds());
|
||||
canvas->drawImage(fImage, 0, 0, SkSamplingOptions(), &paint);
|
||||
canvas->restore();
|
||||
}
|
||||
|
||||
@ -91,7 +90,7 @@ protected:
|
||||
}
|
||||
|
||||
private:
|
||||
SkBitmap fBitmap;
|
||||
sk_sp<SkImage> fImage;
|
||||
|
||||
using INHERITED = GM;
|
||||
};
|
||||
|
@ -8,6 +8,7 @@
|
||||
#include "gm/gm.h"
|
||||
#include "include/core/SkBitmap.h"
|
||||
#include "include/core/SkCanvas.h"
|
||||
#include "include/core/SkImage.h"
|
||||
|
||||
// This GM should draw two yellow boxes; the bug drew one in cyan.
|
||||
|
||||
@ -24,8 +25,8 @@ DEF_SIMPLE_GM(skbug_9819, c, 256, 256) {
|
||||
|
||||
c->save();
|
||||
c->scale(128,128);
|
||||
c->drawBitmap(rgba, 0,0);
|
||||
c->drawBitmap(bgra, 0,1);
|
||||
c->drawImage(rgba.asImage(), 0,0);
|
||||
c->drawImage(bgra.asImage(), 0,1);
|
||||
c->restore();
|
||||
|
||||
auto grade = [&](int x, int y){
|
||||
|
@ -50,7 +50,8 @@ static void draw_1_bitmap(SkCanvas* canvas, const SkBitmap& bm, bool doClip,
|
||||
canvas->save();
|
||||
canvas->clipRect(clipR);
|
||||
}
|
||||
canvas->drawBitmap(bm, SkIntToScalar(dx), SkIntToScalar(dy), &paint);
|
||||
canvas->drawImage(bm.asImage(), SkIntToScalar(dx), SkIntToScalar(dy),
|
||||
SkSamplingOptions(), &paint);
|
||||
if (doClip) {
|
||||
canvas->restore();
|
||||
}
|
||||
|
@ -198,7 +198,7 @@ private:
|
||||
int x, int y) {
|
||||
canvas->save();
|
||||
canvas->translate(SkIntToScalar(x), SkIntToScalar(y));
|
||||
canvas->clipRect(SkRect::MakeIWH(bitmap.width(), bitmap.height()));
|
||||
canvas->clipIRect(bitmap.bounds());
|
||||
canvas->drawBitmap(bitmap, 0, 0, &paint);
|
||||
canvas->restore();
|
||||
}
|
||||
|
@ -145,7 +145,6 @@ gm_sources = [
|
||||
"$_gm/discard.cpp",
|
||||
"$_gm/displacement.cpp",
|
||||
"$_gm/distantclip.cpp",
|
||||
"$_gm/downsamplebitmap.cpp",
|
||||
"$_gm/draw_bitmap_rect_skbug4374.cpp",
|
||||
"$_gm/drawable.cpp",
|
||||
"$_gm/drawatlas.cpp",
|
||||
@ -173,7 +172,6 @@ gm_sources = [
|
||||
"$_gm/fatpathfill.cpp",
|
||||
"$_gm/filltypes.cpp",
|
||||
"$_gm/filltypespersp.cpp",
|
||||
"$_gm/filterbitmap.cpp",
|
||||
"$_gm/filterbug.cpp",
|
||||
"$_gm/filterfastbounds.cpp",
|
||||
"$_gm/filterindiabox.cpp",
|
||||
|
@ -916,6 +916,10 @@ public:
|
||||
this->clipRect(rect, SkClipOp::kIntersect, doAntiAlias);
|
||||
}
|
||||
|
||||
void clipIRect(const SkIRect& irect, SkClipOp op = SkClipOp::kIntersect) {
|
||||
this->clipRect(SkRect::Make(irect), op, false);
|
||||
}
|
||||
|
||||
/** Sets the maximum clip rectangle, which can be set by clipRect(), clipRRect() and
|
||||
clipPath() and intersect the current clip with the specified rect.
|
||||
The maximum clip affects only future clipping operations; it is not retroactive.
|
||||
|
Loading…
Reference in New Issue
Block a user