Begin to hide drawBitmap

... now that bitmap
- converts to image with just bitmap.asImage()
- canvas *always* converts bitmaps to images before they are drawn

Bug: skia:10037
Change-Id: I24292f62e0fd072b3b810d974d0fe5c6d9b9a68d
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/353582
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Mike Reed <reed@google.com>
This commit is contained in:
Mike Reed 2021-01-13 13:14:23 -05:00 committed by Skia Commit-Bot
parent b60255033d
commit 6dbeac51b4
12 changed files with 58 additions and 36 deletions

View File

@ -121,7 +121,7 @@ static void draw(SkCanvas* canvas,
SkColorType colorType,
const char text[]) {
SkASSERT(src.colorType() == colorType);
canvas->drawBitmap(src, 0.0f, 0.0f);
canvas->drawImage(src.asImage(), 0.0f, 0.0f);
canvas->drawSimpleText(text, strlen(text), SkTextEncoding::kUTF8, 0.0f, 12.0f, font, p);
}

View File

@ -71,9 +71,9 @@ protected:
canvas->saveLayer(nullptr, nullptr);
SkPaint p;
canvas->drawBitmap(fCompositeDst, 0, 0, &p);
canvas->drawImage(fCompositeDst.asImage(), 0, 0, &p);
p.setBlendMode(mode);
canvas->drawBitmap(fCompositeSrc, 0, 0, &p);
canvas->drawImage(fCompositeSrc.asImage(), 0, 0, &p);
}
void onDraw(SkCanvas* canvas) override {

View File

@ -10,6 +10,7 @@
#include "include/core/SkCanvas.h"
#include "include/core/SkColor.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"
@ -66,7 +67,7 @@ protected:
SkIntToScalar(xSize), SkIntToScalar(ySize));
SkPaint p;
p.setFilterQuality(fFilterQuality);
canvas->drawBitmapRect(fBM, r, &p);
canvas->drawImageRect(fBM.asImage(), r, &p);
}
void onDraw(SkCanvas* canvas) override {

View File

@ -11,6 +11,7 @@
#include "include/core/SkCanvas.h"
#include "include/core/SkColor.h"
#include "include/core/SkColorPriv.h"
#include "include/core/SkImage.h"
#include "include/core/SkImageInfo.h"
#include "include/core/SkPaint.h"
#include "include/core/SkScalar.h"
@ -34,7 +35,7 @@ static void init_bitmap(SkColorType ct, SkBitmap* bitmap) {
bitmap->eraseColor(SK_ColorWHITE);
}
static SkBitmap make_argb8888_gradient() {
static sk_sp<SkImage> make_argb8888_gradient() {
SkBitmap bitmap;
init_bitmap(kN32_SkColorType, &bitmap);
for (int y = 0; y < SLIDE_SIZE; y++) {
@ -43,20 +44,20 @@ static SkBitmap make_argb8888_gradient() {
dst[x] = SkPackARGB32(y, y, y, y);
}
}
return bitmap;
return bitmap.asImage();
}
static SkBitmap make_argb4444_gradient() {
static sk_sp<SkImage> make_argb4444_gradient() {
SkBitmap bitmap;
init_bitmap(kARGB_4444_SkColorType, &bitmap);
// Using draw rather than readPixels to suppress dither
SkPaint paint;
paint.setBlendMode(SkBlendMode::kSrc);
SkCanvas{ bitmap }.drawBitmap(make_argb8888_gradient(), 0, 0, &paint);
return bitmap;
SkCanvas{ bitmap }.drawImage(make_argb8888_gradient(), 0, 0, &paint);
return bitmap.asImage();
}
static SkBitmap make_argb8888_stripes() {
static sk_sp<SkImage> make_argb8888_stripes() {
SkBitmap bitmap;
init_bitmap(kN32_SkColorType, &bitmap);
uint8_t rowColor = 0;
@ -72,17 +73,17 @@ static SkBitmap make_argb8888_stripes() {
rowColor = 0;
}
}
return bitmap;
return bitmap.asImage();
}
static SkBitmap make_argb4444_stripes() {
static sk_sp<SkImage> make_argb4444_stripes() {
SkBitmap bitmap;
init_bitmap(kARGB_4444_SkColorType, &bitmap);
// Using draw rather than readPixels to suppress dither
SkPaint paint;
paint.setBlendMode(SkBlendMode::kSrc);
SkCanvas{ bitmap }.drawBitmap(make_argb8888_stripes(), 0, 0, &paint);
return bitmap;
SkCanvas{ bitmap }.drawImage(make_argb8888_stripes(), 0, 0, &paint);
return bitmap.asImage();
}
namespace skiagm {
@ -104,10 +105,10 @@ protected:
void onDraw(SkCanvas* canvas) override {
SkScalar slideSize = SkIntToScalar(SLIDE_SIZE);
canvas->drawBitmap(make_argb8888_gradient(), 0, 0);
canvas->drawBitmap(make_argb4444_gradient(), slideSize, 0);
canvas->drawBitmap(make_argb8888_stripes(), 0, slideSize);
canvas->drawBitmap(make_argb4444_stripes(), slideSize, slideSize);
canvas->drawImage(make_argb8888_gradient(), 0, 0);
canvas->drawImage(make_argb4444_gradient(), slideSize, 0);
canvas->drawImage(make_argb8888_stripes(), 0, slideSize);
canvas->drawImage(make_argb4444_stripes(), slideSize, slideSize);
}
private:

View File

@ -16,22 +16,24 @@
#include "include/core/SkShader.h"
#include "include/core/SkSize.h"
#include "include/core/SkString.h"
#include "include/core/SkSurface.h"
#include "include/core/SkTileMode.h"
#include "include/core/SkTypes.h"
#include "include/effects/SkGradientShader.h"
static void make_bitmap(SkBitmap* bitmap) {
bitmap->allocN32Pixels(64, 64);
static sk_sp<SkImage> make_image() {
auto surf = SkSurface::MakeRasterN32Premul(64, 64);
auto canvas = surf->getCanvas();
SkCanvas canvas(*bitmap);
canvas.drawColor(SK_ColorRED);
canvas->drawColor(SK_ColorRED);
SkPaint paint;
paint.setAntiAlias(true);
const SkPoint pts[] = { { 0, 0 }, { 64, 64 } };
const SkColor colors[] = { SK_ColorWHITE, SK_ColorBLUE };
paint.setShader(SkGradientShader::MakeLinear(pts, colors, nullptr, 2, SkTileMode::kClamp));
canvas.drawCircle(32, 32, 32, paint);
canvas->drawCircle(32, 32, 32, paint);
return surf->makeImageSnapshot();
}
class DrawBitmapRect2 : public skiagm::GM {
@ -64,8 +66,7 @@ protected:
SkPaint paint;
paint.setStyle(SkPaint::kStroke_Style);
SkBitmap bitmap;
make_bitmap(&bitmap);
auto image = make_image();
SkRect dstR = { 0, 200, 128, 380 };
@ -74,12 +75,12 @@ protected:
SkRect srcR;
srcR.set(src[i]);
canvas->drawBitmap(bitmap, 0, 0, &paint);
canvas->drawImage(image, 0, 0, &paint);
if (!fUseIRect) {
canvas->drawBitmapRect(bitmap, srcR, dstR, &paint,
SkCanvas::kStrict_SrcRectConstraint);
canvas->drawImageRect(image, srcR, dstR, &paint,
SkCanvas::kStrict_SrcRectConstraint);
} else {
canvas->drawBitmapRect(bitmap, src[i], dstR, &paint);
canvas->drawImageRect(image, src[i], dstR, &paint);
}
canvas->drawRect(dstR, paint);

View File

@ -10,6 +10,7 @@
#include "include/core/SkCanvas.h"
#include "include/core/SkColor.h"
#include "include/core/SkColorFilter.h"
#include "include/core/SkImage.h"
#include "include/core/SkImageInfo.h"
#include "include/core/SkPaint.h"
#include "include/core/SkSize.h"
@ -45,7 +46,7 @@ protected:
};
paint.setColorFilter(SkColorFilters::Matrix(opaqueGrayMatrix));
canvas->drawBitmap(bitmap, 100.0f, 100.0f, &paint);
canvas->drawImage(bitmap.asImage(), 100.0f, 100.0f, &paint);
}
private:

View File

@ -36,6 +36,7 @@
// Working on allow this to be undefined
#define SK_SUPPORT_LEGACY_GETTOTALMATRIX
//#define SK_SUPPORT_LEGACY_ONDRAWIMAGERECT
#define SK_SUPPORT_LEGACY_DRAWBITMAP
class GrBackendRenderTarget;
class GrRecordingContext;
@ -1647,6 +1648,8 @@ public:
const SkPaint* = nullptr);
void drawImageRect(const SkImage*, const SkRect& src, const SkRect& dst,
const SkSamplingOptions&, const SkPaint*, SrcRectConstraint);
void drawImageRect(const SkImage*, const SkRect& dst, const SkSamplingOptions&,
const SkPaint*, SrcRectConstraint);
/** Draws SkImage image stretched proportionally to fit into SkRect dst.
SkIRect center divides the image into nine sections: four sides, four corners, and
@ -1684,6 +1687,11 @@ public:
this->drawImageNine(image.get(), center, dst, paint);
}
#ifdef SK_SUPPORT_LEGACY_DRAWBITMAP
public:
#else
private:
#endif
/** Draws SkBitmap bitmap, with its top-left corner at (left, top),
using clip, SkMatrix, and optional SkPaint paint.
@ -1785,6 +1793,7 @@ public:
*/
void drawBitmapRect(const SkBitmap& bitmap, const SkRect& dst, const SkPaint* paint,
SrcRectConstraint constraint = kStrict_SrcRectConstraint);
public:
/** \struct SkCanvas::Lattice
SkCanvas::Lattice divides SkBitmap or SkImage into a rectangular grid.

View File

@ -2571,6 +2571,14 @@ void SkCanvas::drawImageRect(const SkImage* image, const SkRect& src, const SkRe
this->onDrawImageRect2(image, src, dst, sampling, paint, constraint);
}
void SkCanvas::drawImageRect(const SkImage* image, const SkRect& dst,
const SkSamplingOptions& sampling, const SkPaint* paint,
SrcRectConstraint constraint) {
RETURN_ON_NULL(image);
this->drawImageRect(image, SkRect::MakeIWH(image->width(), image->height()), dst, sampling,
paint, constraint);
}
void SkCanvas::onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y,
const SkPaint& paint) {
const SkRect bounds = blob->bounds().makeOffset(x, y);

View File

@ -571,7 +571,7 @@ static bool draw_orientation(const SkPixmap& dst, const SkPixmap& src, SkEncoded
SkPaint p;
p.setBlendMode(SkBlendMode::kSrc);
surf->getCanvas()->concat(m);
surf->getCanvas()->drawBitmap(bm, 0, 0, &p);
surf->getCanvas()->drawImage(SkImage::MakeFromBitmap(bm), 0, 0, &p);
return true;
}

View File

@ -195,8 +195,8 @@ public:
SkRect dst = SkRect::MakeXYWH(x, y,
this->subset().width(), this->subset().height());
canvas->drawBitmapRect(fBitmap, this->subset(),
dst, paint, SkCanvas::kStrict_SrcRectConstraint);
canvas->drawImageRect(fBitmap.asImage(), this->subset(), dst, paint,
SkCanvas::kStrict_SrcRectConstraint);
}
bool onGetROPixels(SkBitmap* bm) const override {

View File

@ -49,7 +49,7 @@ static void draw_bitmap_matrix(SkCanvas* canvas, const SkBitmap& bm,
SkAutoCanvasRestore acr(canvas, true);
canvas->concat(matrix);
SkPaint paint(paintColor);
canvas->drawBitmap(bm, 0, 0, &paint);
canvas->drawImage(SkImage::MakeFromBitmap(bm), 0, 0, &paint);
}
static void fill_color_from_bitmap(SkCanvas* canvas,

View File

@ -8,6 +8,7 @@
#include "include/core/SkBitmap.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkColor.h"
#include "include/core/SkImage.h"
#include "include/core/SkMatrix.h"
#include "include/core/SkPaint.h"
#include "include/core/SkPath.h"
@ -250,7 +251,7 @@ DEF_TEST(DrawBitmapRect, reporter) {
SkIRect srcR = { gWidth, 0, gWidth + 16, 16 };
SkRect dstR = { 0, 0, SkIntToScalar(16), SkIntToScalar(16) };
canvas.drawBitmapRect(src, srcR, dstR, nullptr);
canvas.drawImageRect(src.asImage(), srcR, dstR, nullptr);
// ensure that we draw nothing if srcR does not intersect the bitmap
REPORTER_ASSERT(reporter, check_for_all_zeros(dst));