Use bitmap.asImage()

Change-Id: Ie16194937530d7cd75f84d9af66c31b77875ef83
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/347043
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Mike Reed <reed@google.com>
This commit is contained in:
Mike Reed 2020-12-23 11:50:36 -05:00 committed by Skia Commit-Bot
parent 839eef3e9a
commit dc607e35e1
54 changed files with 77 additions and 74 deletions

View File

@ -221,7 +221,7 @@ protected:
SkBitmap bm;
bm.allocN32Pixels(256, 256);
bm.eraseColor(fColors[i].toSkColor());
auto image = SkImage::MakeFromBitmap(bm);
auto image = bm.asImage();
fImages[i] = direct ? image->makeTextureImage(direct) : std::move(image);
}

View File

@ -15,7 +15,7 @@ void draw(SkCanvas* canvas) {
canvas->scale(16, 16);
canvas->drawBitmap(redBorder, 0, 0, nullptr);
canvas->resetMatrix();
sk_sp<SkImage> image = SkImage::MakeFromBitmap(redBorder);
sk_sp<SkImage> image = redBorder.asImage();
SkPaint lowPaint;
lowPaint.setFilterQuality(kLow_SkFilterQuality);
for (auto constraint : { SkCanvas::kStrict_SrcRectConstraint,

View File

@ -21,7 +21,7 @@ void draw(SkCanvas* canvas) {
}
left = right;
}
sk_sp<SkImage> image = SkImage::MakeFromBitmap(bitmap);
sk_sp<SkImage> image = bitmap.asImage();
SkImage* imagePtr = image.get();
for (auto dest: { 20, 30, 40, 60, 90 } ) {
canvas->drawImageNine(imagePtr, center, SkRect::MakeWH(dest, dest), nullptr);

View File

@ -21,7 +21,7 @@ void draw(SkCanvas* canvas) {
}
left = right;
}
sk_sp<SkImage> image = SkImage::MakeFromBitmap(bitmap);
sk_sp<SkImage> image = bitmap.asImage();
for (auto dest: { 20, 30, 40, 60, 90 } ) {
canvas->drawImageNine(image, center, SkRect::MakeWH(dest, 110 - dest), nullptr);
canvas->translate(dest + 4, 0);

View File

@ -12,7 +12,7 @@ void draw(SkCanvas* canvas) {
SkBitmap redBorder;
redBorder.installPixels(SkImageInfo::MakeN32Premul(4, 4),
(void*) pixels, sizeof(pixels[0]));
sk_sp<SkImage> image = SkImage::MakeFromBitmap(redBorder);
sk_sp<SkImage> image = redBorder.asImage();
SkPaint lowPaint;
for (auto constraint : {
SkCanvas::kFast_SrcRectConstraint,

View File

@ -9,7 +9,7 @@ void draw(SkCanvas* canvas) {
SkBitmap bitmap;
bitmap.installPixels(SkImageInfo::MakeN32Premul(2, 2),
(void*) pixels, sizeof(pixels[0]));
sk_sp<SkImage> image = SkImage::MakeFromBitmap(bitmap);
sk_sp<SkImage> image = bitmap.asImage();
SkPaint paint;
canvas->scale(4, 4);
for (auto alpha : { 50, 100, 150, 255 } ) {

View File

@ -9,7 +9,7 @@ void draw(SkCanvas* canvas) {
SkBitmap bitmap;
bitmap.installPixels(SkImageInfo::MakeN32Premul(2, 2),
(void*) pixels, sizeof(pixels[0]));
sk_sp<SkImage> image = SkImage::MakeFromBitmap(bitmap);
sk_sp<SkImage> image = bitmap.asImage();
SkPaint paint;
canvas->scale(4, 4);
for (auto color : { SK_ColorRED, SK_ColorBLUE, SK_ColorGREEN } ) {

View File

@ -9,7 +9,7 @@ void draw(SkCanvas* canvas) {
SkBitmap bitmap;
bitmap.installPixels(SkImageInfo::MakeN32Premul(2, 2),
(void*) pixels, sizeof(pixels[0]));
sk_sp<SkImage> image = SkImage::MakeFromBitmap(bitmap);
sk_sp<SkImage> image = bitmap.asImage();
SkPaint paint;
canvas->scale(4, 4);
for (auto color : { SK_ColorRED, SK_ColorBLUE, SK_ColorGREEN } ) {

View File

@ -13,9 +13,9 @@ void draw(SkCanvas* canvas) {
SkPixmap pixmap(imageInfo, storage[0], sizeof(storage) / 5);
SkBitmap bitmap;
bitmap.installPixels(pixmap);
sk_sp<SkImage> image1 = SkImage::MakeFromBitmap(bitmap);
sk_sp<SkImage> image1 = bitmap.asImage();
bitmap.setImmutable();
sk_sp<SkImage> image2 = SkImage::MakeFromBitmap(bitmap);
sk_sp<SkImage> image2 = bitmap.asImage();
*pixmap.writable_addr8(2, 2) = 0x00;
canvas->scale(10, 10);
canvas->drawImage(image1, 0, 0);

View File

@ -22,7 +22,7 @@ void draw(SkCanvas* canvas) {
image->isLazyGenerated() ? "is lazily generated" : "not lazily generated",
20, image->height() * 3 / 4, font, paint);
};
sk_sp<SkImage> bitmapImage(SkImage::MakeFromBitmap(source));
sk_sp<SkImage> bitmapImage(source.asImage());
sk_sp<SkImage> textureImage(SkImage::MakeFromTexture(dContext, backEndTexture,
kTopLeft_GrSurfaceOrigin,
kRGBA_8888_SkColorType,

View File

@ -21,7 +21,7 @@ void draw(SkCanvas* canvas) {
canvas->drawString(image->isTextureBacked() ? "is GPU texture" : "not GPU texture",
20, image->height() * 3 / 4, font, paint);
};
sk_sp<SkImage> bitmapImage(SkImage::MakeFromBitmap(source));
sk_sp<SkImage> bitmapImage(source.asImage());
sk_sp<SkImage> textureImage(SkImage::MakeFromTexture(dContext, backEndTexture,
kTopLeft_GrSurfaceOrigin,
kRGBA_8888_SkColorType,

View File

@ -28,7 +28,7 @@ void draw(SkCanvas* canvas) {
canvas->drawString(msg, 20, image->height() * 7 / 8, font, paint);
};
sk_sp<SkImage> bitmapImage(SkImage::MakeFromBitmap(source));
sk_sp<SkImage> bitmapImage(source.asImage());
sk_sp<SkImage> textureImage(SkImage::MakeFromTexture(dContext, backEndTexture,
kTopLeft_GrSurfaceOrigin,
kRGBA_8888_SkColorType,

View File

@ -20,7 +20,7 @@ void draw(SkCanvas* canvas) {
canvas->drawImage(nonTexture, 0, 0);
canvas->drawString(label, 20, nonTexture->height() / 4, font, paint);
};
sk_sp<SkImage> bitmapImage(SkImage::MakeFromBitmap(source));
sk_sp<SkImage> bitmapImage(source.asImage());
sk_sp<SkImage> textureImage(SkImage::MakeFromTexture(dContext, backEndTexture,
kTopLeft_GrSurfaceOrigin,
kRGBA_8888_SkColorType,

View File

@ -20,7 +20,7 @@ void draw(SkCanvas* canvas) {
canvas->drawImage(raster, 0, 0);
canvas->drawString(label, 20, raster->height() / 4, font, paint);
};
sk_sp<SkImage> bitmapImage(SkImage::MakeFromBitmap(source));
sk_sp<SkImage> bitmapImage(source.asImage());
sk_sp<SkImage> textureImage(SkImage::MakeFromTexture(dContext, backEndTexture,
kTopLeft_GrSurfaceOrigin,
kRGBA_8888_SkColorType,

View File

@ -25,7 +25,7 @@ void draw(SkCanvas* canvas) {
canvas->drawImage(texture, 0, 0);
canvas->drawString(label, 20, texture->height() / 4, font, paint);
};
sk_sp<SkImage> bitmapImage(SkImage::MakeFromBitmap(source));
sk_sp<SkImage> bitmapImage(source.asImage());
sk_sp<SkImage> textureImage(SkImage::MakeFromTexture(dContext, backEndTexture,

View File

@ -14,7 +14,7 @@ void draw(SkCanvas* canvas) {
sk_sp<SkImage> image;
} tests[] = {
{ "image", image },
{ "bitmap", SkImage::MakeFromBitmap(source) },
{ "bitmap", source.asImage() },
{ "texture", SkImage::MakeFromTexture(dContext, backEndTexture, kTopLeft_GrSurfaceOrigin,
kRGBA_8888_SkColorType, kOpaque_SkAlphaType,
nullptr) }

View File

@ -15,7 +15,7 @@ void doCell(SkCanvas* canvas, float x, float y, SkAlphaType at, SkColor c, int n
SkBitmap bmp;
bmp.allocPixels(info);
fill(bmp, c, n);
sk_sp<SkImage> img = SkImage::MakeFromBitmap(bmp);
sk_sp<SkImage> img = bmp.asImage();
SkPaint paint;
const SkTileMode tile = SkTileMode::kRepeat;

View File

@ -12,7 +12,7 @@ void draw(SkCanvas* canvas) {
*(premulBitmap.getAddr32(x, y)) = 0x80808080;
}
}
sk_sp<SkImage> premulImage = SkImage::MakeFromBitmap(premulBitmap);
sk_sp<SkImage> premulImage = premulBitmap.asImage();
SkImageInfo unpremulInfo = premulInfo.makeAlphaType(kUnpremul_SkAlphaType);
SkBitmap unpremulBitmap;
@ -22,7 +22,7 @@ void draw(SkCanvas* canvas) {
*(unpremulBitmap.getAddr32(x, y)) = 0x80FFFFFF;
}
}
sk_sp<SkImage> unpremulImage = SkImage::MakeFromBitmap(unpremulBitmap);
sk_sp<SkImage> unpremulImage = unpremulBitmap.asImage();
SkPaint paint;
const SkTileMode tile = SkTileMode::kRepeat;

View File

@ -25,7 +25,7 @@ static sk_sp<SkColorFilter> make_color_filter() {
}
void draw(SkCanvas* canvas) {
auto image = SkImage::MakeFromBitmap(make_alpha_image(96, 96));
auto image = make_alpha_image(96, 96).asImage();
SkPaint paint;
paint.setColorFilter(make_color_filter());

View File

@ -23,7 +23,7 @@ sk_sp<SkImage> foo() {
SkCanvas c(bm);
c.clear(0);
c.drawRect(bounds, paint);
return SkImage::MakeFromBitmap(bm);
return bm.asImage();
}
void draw(SkCanvas* canvas) {

View File

@ -6,8 +6,8 @@ REG_FIDDLE(skbug_5648, 256, 256, true, 4) {
void draw(SkCanvas*) {
SkBitmap bitmap;
source.extractSubset(&bitmap, {0, 0, source.width() - 1, source.height() - 1});
auto img0 = SkImage::MakeFromBitmap(bitmap);
auto img1 = SkImage::MakeFromBitmap(bitmap);
auto img0 = bitmap.asImage();
auto img1 = bitmap.asImage();
SkDebugf("%u\n%u\n", img0->uniqueID(), img1->uniqueID());
}
} // END FIDDLE

View File

@ -271,7 +271,7 @@ static void fuzz_drawImage(Fuzz* fuzz) {
SkBitmap bmp;
init_bitmap(fuzz, &bmp);
sk_sp<SkImage> image(SkImage::MakeFromBitmap(bmp));
sk_sp<SkImage> image(bmp.asImage());
bool bl;
fuzz->next(&bl);

View File

@ -1224,6 +1224,8 @@ public:
private:
SkImage(const SkImageInfo& info, uint32_t uniqueID);
friend class SkBitmap;
friend class SkImage_Base;
friend class SkMipmapBuilder;

View File

@ -141,7 +141,7 @@ sk_sp<SkImage> MultiFrameImageAsset::generateFrame(float t) {
SkSamplingOptions(SkFilterMode::kLinear,
SkMipmapMode::kNearest),
SkImage::kDisallow_CachingHint)) {
image = SkImage::MakeFromBitmap(bm);
image = bm.asImage();
}
} else {
// When the image size is OK, just force-decode.

View File

@ -169,8 +169,8 @@ public:
void onOnceBeforeDraw() override {
fBlur = SkImageFilters::Blur(8.f, 8.f, nullptr);
fImage = SkImage::MakeFromBitmap(ToolUtils::create_checkerboard_bitmap(
300, 300, SK_ColorMAGENTA, SK_ColorLTGRAY, 50));
fImage = ToolUtils::create_checkerboard_image(
300, 300, SK_ColorMAGENTA, SK_ColorLTGRAY, 50);
}
void onDrawContent(SkCanvas* canvas) override {

View File

@ -1943,7 +1943,7 @@ static sk_sp<SkImage> bitmap_as_image(const SkBitmap& bitmap) {
if (bitmap.drawsNothing()) {
return nullptr;
}
return SkImage::MakeFromBitmap(bitmap);
return bitmap.asImage();
}
void SkCanvas::drawBitmap(const SkBitmap& bitmap, SkScalar dx, SkScalar dy, const SkPaint* paint) {

View File

@ -238,7 +238,7 @@ bool SkPixmap::scalePixels(const SkPixmap& actualDst, const SkSamplingOptions& s
SkRect::Make(dst.bounds()),
SkMatrix::kFill_ScaleToFit);
sk_sp<SkShader> shader = SkImageShader::Make(SkImage::MakeFromBitmap(bitmap),
sk_sp<SkShader> shader = SkImageShader::Make(bitmap.asImage(),
SkTileMode::kClamp,
SkTileMode::kClamp,
&sampling,

View File

@ -239,10 +239,10 @@ public:
return nullptr;
}
return SkImage::MakeFromBitmap(subsetBM);
return subsetBM.asImage();
}
return SkImage::MakeFromBitmap(fBitmap);
return fBitmap.asImage();
}
sk_sp<SkSurface> onMakeTightSurface(SkColorType colorType, const SkColorSpace* colorSpace,

View File

@ -244,7 +244,7 @@ sk_sp<SkImage> SkImage_Lazy::onReinterpretColorSpace(sk_sp<SkColorSpace> newCS)
pixmap.setColorSpace(this->refColorSpace());
if (ScopedGenerator(fSharedGenerator)->getPixels(pixmap)) {
bitmap.setImmutable();
return SkImage::MakeFromBitmap(bitmap);
return bitmap.asImage();
}
}
return nullptr;

View File

@ -267,7 +267,7 @@ sk_sp<SkImage> SkImage_Raster::onMakeSubset(const SkIRect& subset, GrDirectConte
subset.height());
bitmap.setImmutable();
return MakeFromBitmap(bitmap);
return bitmap.asImage();
}
///////////////////////////////////////////////////////////////////////////////
@ -399,7 +399,7 @@ sk_sp<SkImage> SkImage_Raster::onMakeColorTypeAndColorSpace(SkColorType targetCT
SkAssertResult(dst.writePixels(src));
dst.setImmutable();
return SkImage::MakeFromBitmap(dst);
return dst.asImage();
}
sk_sp<SkImage> SkImage_Raster::onReinterpretColorSpace(sk_sp<SkColorSpace> newCS) const {

View File

@ -94,7 +94,7 @@ sk_sp<SkImage> SkSurface_Raster::onNewImageSnapshot(const SkIRect* subset) {
dst.allocPixels(fBitmap.info().makeDimensions(subset->size()));
SkAssertResult(fBitmap.readPixels(dst.pixmap(), subset->left(), subset->top()));
dst.setImmutable(); // key, so MakeFromBitmap doesn't make a copy of the buffer
return SkImage::MakeFromBitmap(dst);
return dst.asImage();
}
SkCopyPixelsMode cpm = kIfMutable_SkCopyPixelsMode;

View File

@ -24,7 +24,7 @@ SkKeyedImage::SkKeyedImage(sk_sp<SkImage> i) : fImage(std::move(i)) {
fKey = SkBitmapKeyFromImage(fImage.get());
}
SkKeyedImage::SkKeyedImage(const SkBitmap& bm) : fImage(SkImage::MakeFromBitmap(bm)) {
SkKeyedImage::SkKeyedImage(const SkBitmap& bm) : fImage(bm.asImage()) {
if (fImage) {
fKey = {bm.getSubset(), bm.getGenerationID()};
}

View File

@ -136,7 +136,8 @@ sk_sp<SkImage> alpha_image_to_greyscale_image(const SkImage* mask) {
greyBitmap.getPixels(), greyBitmap.rowBytes(), 0, 0)) {
return nullptr;
}
return SkImage::MakeFromBitmap(greyBitmap);
greyBitmap.setImmutable();
return greyBitmap.asImage();
}
static int add_resource(SkTHashSet<SkPDFIndirectReference>& resources, SkPDFIndirectReference ref) {

View File

@ -462,7 +462,7 @@ static ImageAndOffset to_image(SkGlyphID gid, SkBulkGlyphMetricsAndImages* small
}
}
bm.setImmutable();
return {SkImage::MakeFromBitmap(bm), {bounds.x(), bounds.y()}};
return {bm.asImage(), {bounds.x(), bounds.y()}};
case SkMask::kA8_Format:
bm.installPixels(SkImageInfo::MakeA8(bounds.width(), bounds.height()),
mask.fImage, mask.fRowBytes);

View File

@ -247,7 +247,7 @@ sk_sp<SkImage> SkMakeImageFromCGImage(CGImageRef src) {
}
bm.setImmutable();
return SkImage::MakeFromBitmap(bm);
return bm.asImage();
}
#endif//defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS)

View File

@ -101,7 +101,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SpecialImage_GPUDevice, reporter, ctxInfo) {
SkASSERT(SkIRect::MakeWH(kWidth, kHeight) == special->subset());
// Create a gpu-backed special image from a raster-backed SkImage
sk_sp<SkImage> image(SkImage::MakeFromBitmap(bm));
sk_sp<SkImage> image(bm.asImage());
special = DeviceTestingAccess::MakeSpecial(gpuDev.get(), image.get());
SkASSERT(special->isTextureBacked());
SkASSERT(kWidth == special->width());

View File

@ -37,6 +37,6 @@ DEF_TEST(FlattenableFactoryToName, r) {
SkBitmap bm;
bm.allocN32Pixels(8, 8);
bm.eraseColor(SK_ColorCYAN);
sk_sp<SkImage> image(SkImage::MakeFromBitmap(bm));
sk_sp<SkImage> image(bm.asImage());
test_flattenable(r, image->makeShader(SkSamplingOptions()).get(), "SkImage::newShader()");
}

View File

@ -28,7 +28,7 @@ DEF_GPUTEST(GrDDLImage_MakeSubset, reporter, options) {
bm.allocPixels();
bm.eraseColor(SK_ColorBLACK);
bm.setImmutable();
auto rasterImg = SkImage::MakeFromBitmap(bm);
auto rasterImg = bm.asImage();
REPORTER_ASSERT(reporter, rasterImg->isValid(static_cast<GrRecordingContext*>(nullptr)));
// raster + context:

View File

@ -329,7 +329,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(Gr1x1TextureMipMappedTest, reporter, ctxInfo)
SkPMColor* pixel = reinterpret_cast<SkPMColor*>(bmp.getPixels());
*pixel = 0;
sk_sp<SkImage> bmpImage = SkImage::MakeFromBitmap(bmp);
sk_sp<SkImage> bmpImage = bmp.asImage();
// Make sure we scale so we don't optimize out the use of mips.
surface->getCanvas()->scale(0.5f, 0.5f);

View File

@ -22,9 +22,9 @@ DEF_TEST(ImageBitmapIdentity, r) {
(void)bm.extractSubset(&a, SkIRect::MakeXYWH(0, 0, 32, 32));
(void)bm.extractSubset(&b, SkIRect::MakeXYWH(0, 32, 32, 32));
REPORTER_ASSERT(r, a.getGenerationID() == b.getGenerationID());
auto img = SkImage::MakeFromBitmap(bm);
auto imgA = SkImage::MakeFromBitmap(a);
auto imgB = SkImage::MakeFromBitmap(b);
auto img = bm.asImage();
auto imgA = a.asImage();
auto imgB = b.asImage();
REPORTER_ASSERT(r, img->uniqueID() == bm.getGenerationID());
REPORTER_ASSERT(r, img->uniqueID() != imgA->uniqueID());
REPORTER_ASSERT(r, img->uniqueID() != imgB->uniqueID());

View File

@ -193,7 +193,7 @@ static void test_image_backed(skiatest::Reporter* reporter,
DEF_TEST(ImageFilterCache_ImageBackedRaster, reporter) {
SkBitmap srcBM = create_bm();
sk_sp<SkImage> srcImage(SkImage::MakeFromBitmap(srcBM));
sk_sp<SkImage> srcImage(srcBM.asImage());
test_image_backed(reporter, nullptr, srcImage);
}

View File

@ -124,7 +124,7 @@ public:
SkImageFilters::ColorFilter(std::move(cf), input, cropRect));
}
{
sk_sp<SkImage> gradientImage(SkImage::MakeFromBitmap(make_gradient_circle(64, 64)));
sk_sp<SkImage> gradientImage(make_gradient_circle(64, 64).asImage());
sk_sp<SkImageFilter> gradientSource(SkImageFilters::Image(std::move(gradientImage)));
this->addFilter("displacement map",
@ -515,7 +515,7 @@ static void test_negative_blur_sigma(skiatest::Reporter* reporter,
sk_sp<SkImageFilter> positiveFilter(SkImageFilters::Blur(kBlurSigma, kBlurSigma, nullptr));
sk_sp<SkImageFilter> negativeFilter(SkImageFilters::Blur(-kBlurSigma, kBlurSigma, nullptr));
sk_sp<SkImage> gradient = SkImage::MakeFromBitmap(make_gradient_circle(kWidth, kHeight));
sk_sp<SkImage> gradient = make_gradient_circle(kWidth, kHeight).asImage();
sk_sp<SkSpecialImage> imgSrc(
SkSpecialImage::MakeFromImage(dContext, SkIRect::MakeWH(kWidth, kHeight), gradient));
@ -607,7 +607,7 @@ static void test_morphology_radius_with_mirror_ctm(skiatest::Reporter* reporter,
paint.setColor(SK_ColorWHITE);
canvas.drawRect(SkRect::MakeXYWH(kWidth / 4, kHeight / 4, kWidth / 2, kHeight / 2),
paint);
sk_sp<SkImage> image = SkImage::MakeFromBitmap(bitmap);
sk_sp<SkImage> image = bitmap.asImage();
sk_sp<SkSpecialImage> imgSrc(
SkSpecialImage::MakeFromImage(dContext, SkIRect::MakeWH(kWidth, kHeight), image));
@ -1002,7 +1002,7 @@ static void test_imagefilter_merge_result_size(skiatest::Reporter* reporter,
SkBitmap greenBM;
greenBM.allocN32Pixels(20, 20);
greenBM.eraseColor(SK_ColorGREEN);
sk_sp<SkImage> greenImage(SkImage::MakeFromBitmap(greenBM));
sk_sp<SkImage> greenImage(greenBM.asImage());
sk_sp<SkImageFilter> source(SkImageFilters::Image(std::move(greenImage)));
sk_sp<SkImageFilter> merge(SkImageFilters::Merge(source, source));
@ -1637,7 +1637,7 @@ static void test_large_blur_input(skiatest::Reporter* reporter, SkCanvas* canvas
return;
}
sk_sp<SkImage> largeImage(SkImage::MakeFromBitmap(largeBmp));
sk_sp<SkImage> largeImage(largeBmp.asImage());
if (!largeImage) {
ERRORF(reporter, "Failed to create large image.");
return;
@ -1954,7 +1954,7 @@ DEF_TEST(DisplacementMapBounds, reporter) {
// Test SkImageSource::filterBounds.
DEF_TEST(ImageSourceBounds, reporter) {
sk_sp<SkImage> image(SkImage::MakeFromBitmap(make_gradient_circle(64, 64)));
sk_sp<SkImage> image(make_gradient_circle(64, 64).asImage());
// Default src and dst rects.
sk_sp<SkImageFilter> source1(SkImageFilters::Image(image));
SkIRect imageBounds = SkIRect::MakeWH(64, 64);

View File

@ -15,5 +15,5 @@ DEF_TEST(ImageFrom565Bitmap, r) {
bm.allocPixels(SkImageInfo::Make(
5, 7, kRGB_565_SkColorType, kOpaque_SkAlphaType));
bm.eraseColor(SK_ColorBLACK);
REPORTER_ASSERT(r, SkImage::MakeFromBitmap(bm) != nullptr);
REPORTER_ASSERT(r, bm.asImage() != nullptr);
}

View File

@ -314,7 +314,7 @@ DEF_TEST(image_newfrombitmap, reporter) {
SkBitmap bm;
rec[i].fMakeProc(&bm);
sk_sp<SkImage> image(SkImage::MakeFromBitmap(bm));
sk_sp<SkImage> image(bm.asImage());
SkPixmap pmap;
const bool sharedID = (image->uniqueID() == bm.getGenerationID());
@ -511,7 +511,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(UnpremulTextureImage, reporter, ctxInfo) {
}
}
auto dContext = ctxInfo.directContext();
auto texImage = SkImage::MakeFromBitmap(bmp)->makeTextureImage(dContext);
auto texImage = bmp.asImage()->makeTextureImage(dContext);
if (!texImage || texImage->alphaType() != kUnpremul_SkAlphaType) {
ERRORF(reporter, "Failed to make unpremul texture image.");
return;
@ -746,7 +746,7 @@ static void test_legacy_bitmap(skiatest::Reporter* reporter, GrDirectContext* dC
SkBitmap tmp;
REPORTER_ASSERT(reporter, bitmap.extractSubset(&tmp, SkIRect::MakeWH(image->width() / 2,
image->height() / 2)));
sk_sp<SkImage> subsetImage(SkImage::MakeFromBitmap(tmp));
sk_sp<SkImage> subsetImage(tmp.asImage());
REPORTER_ASSERT(reporter, subsetImage.get());
SkBitmap subsetBitmap;
@ -1169,7 +1169,7 @@ DEF_TEST(Image_ColorSpace, r) {
SkBitmap bitmap;
SkImageInfo info = SkImageInfo::MakeN32(10, 10, kPremul_SkAlphaType, rec2020);
bitmap.allocPixels(info);
image = SkImage::MakeFromBitmap(bitmap);
image = bitmap.asImage();
REPORTER_ASSERT(r, SkColorSpace::Equals(rec2020.get(), image->colorSpace()));
sk_sp<SkSurface> surface = SkSurface::MakeRaster(
@ -1192,7 +1192,7 @@ DEF_TEST(Image_makeColorSpace, r) {
srgbBitmap.allocPixels(SkImageInfo::MakeS32(1, 1, kOpaque_SkAlphaType));
*srgbBitmap.getAddr32(0, 0) = SkSwizzle_RGBA_to_PMColor(0xFF604020);
srgbBitmap.setImmutable();
sk_sp<SkImage> srgbImage = SkImage::MakeFromBitmap(srgbBitmap);
sk_sp<SkImage> srgbImage = srgbBitmap.asImage();
sk_sp<SkImage> p3Image = srgbImage->makeColorSpace(p3, nullptr);
SkBitmap p3Bitmap;
bool success = p3Image->asLegacyBitmap(&p3Bitmap);
@ -1253,7 +1253,7 @@ DEF_TEST(image_roundtrip_encode, reporter) {
SkBitmap bm0;
make_all_premul(&bm0);
auto img0 = SkImage::MakeFromBitmap(bm0);
auto img0 = bm0.asImage();
sk_sp<SkData> data = img0->encodeToData(SkEncodedImageFormat::kPNG, 100);
auto img1 = SkImage::MakeFromEncoded(data);

View File

@ -53,7 +53,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(RepeatedClippedBlurTest, reporter, ctxInfo) {
bm.eraseColor(SK_ColorRED);
bm.eraseArea(SkIRect::MakeXYWH(1, 2, 1277, 1274), SK_ColorGREEN);
sk_sp<SkImage> rasterImg = SkImage::MakeFromBitmap(bm);
sk_sp<SkImage> rasterImg = bm.asImage();
bigImg = rasterImg->makeTextureImage(dContext);
}

View File

@ -271,9 +271,9 @@ static void TestBitmapSerialization(const SkBitmap& validBitmap,
const SkBitmap& invalidBitmap,
bool shouldSucceed,
skiatest::Reporter* reporter) {
sk_sp<SkImage> validImage(SkImage::MakeFromBitmap(validBitmap));
sk_sp<SkImage> validImage(validBitmap.asImage());
sk_sp<SkImageFilter> validBitmapSource(SkImageFilters::Image(std::move(validImage)));
sk_sp<SkImage> invalidImage(SkImage::MakeFromBitmap(invalidBitmap));
sk_sp<SkImage> invalidImage(invalidBitmap.asImage());
sk_sp<SkImageFilter> invalidBitmapSource(SkImageFilters::Image(std::move(invalidImage)));
sk_sp<SkImageFilter> xfermodeImageFilter(
SkImageFilters::Blend(SkBlendMode::kSrcOver,

View File

@ -40,13 +40,13 @@ DEF_TEST(Shader_isAImage, reporter) {
const int H = 100;
SkBitmap bm;
bm.allocN32Pixels(W, H);
auto img = SkImage::MakeFromBitmap(bm);
auto img = bm.asImage();
const SkMatrix localM = SkMatrix::Scale(2, 3);
const SkTileMode tmx = SkTileMode::kRepeat;
const SkTileMode tmy = SkTileMode::kMirror;
auto shader0 = bm.makeShader(tmx, tmy, SkSamplingOptions(), localM);
auto shader1 = SkImage::MakeFromBitmap(bm)->makeShader(tmx, tmy, SkSamplingOptions(), localM);
auto shader1 = bm.asImage()->makeShader(tmx, tmy, SkSamplingOptions(), localM);
check_isaimage(reporter, shader0.get(), W, H, tmx, tmy, localM);
check_isaimage(reporter, shader1.get(), W, H, tmx, tmy, localM);

View File

@ -27,7 +27,7 @@ DEF_TEST(SkImageFromBitmap_extractSubset, reporter) {
canvas.drawIRect(r, p);
SkBitmap dstBitmap;
srcBitmap.extractSubset(&dstBitmap, r);
image = SkImage::MakeFromBitmap(dstBitmap);
image = dstBitmap.asImage();
}
SkBitmap tgt;

View File

@ -43,7 +43,7 @@ static void test_mipmapcache(skiatest::Reporter* reporter, SkResourceCache* cach
SkBitmap src;
src.allocN32Pixels(5, 5);
src.setImmutable();
sk_sp<SkImage> img = SkImage::MakeFromBitmap(src);
sk_sp<SkImage> img = src.asImage();
const auto desc = SkBitmapCacheDesc::Make(img.get());
const SkMipmap* mipmap = SkMipmapCache::FindAndRef(desc, cache);
@ -85,7 +85,7 @@ static void test_mipmap_notify(skiatest::Reporter* reporter, SkResourceCache* ca
for (int i = 0; i < N; ++i) {
src[i].allocN32Pixels(5, 5);
src[i].setImmutable();
img[i] = SkImage::MakeFromBitmap(src[i]);
img[i] = src[i].asImage();
SkMipmapCache::AddAndRef(as_IB(img[i].get()), cache)->unref();
desc[i] = SkBitmapCacheDesc::Make(img[i].get());
}

View File

@ -159,7 +159,7 @@ DEF_TEST(SpecialImage_Raster, reporter) {
static void test_specialimage_image(skiatest::Reporter* reporter) {
SkBitmap bm = create_bm();
sk_sp<SkImage> fullImage(SkImage::MakeFromBitmap(bm));
sk_sp<SkImage> fullImage(bm.asImage());
sk_sp<SkSpecialImage> fullSImage(SkSpecialImage::MakeFromImage(
nullptr,

View File

@ -229,7 +229,7 @@ static void invalidation_test(GrDirectContext* dContext, skiatest::Reporter* rep
SkBitmap bm;
bm.allocPixels(ii);
rasterImg = SkImage::MakeFromBitmap(bm);
rasterImg = bm.asImage();
REPORTER_ASSERT(reporter, 0 == proxyProvider->numUniqueKeyProxies_TestOnly());
REPORTER_ASSERT(reporter, 0 == cache->getResourceCount());
}

View File

@ -315,7 +315,7 @@ sk_sp<SkImage> DDLPromiseImageHelper::CreatePromiseImages(const void* rawData,
// texture wouldn't fit on the GPU. Create a separate bitmap-backed image for each thread.
if (!curImage.isYUV() && !curImage.callbackContext(0)) {
SkASSERT(curImage.baseLevel().isImmutable());
return SkImage::MakeFromBitmap(curImage.baseLevel());
return curImage.baseLevel().asImage();
}
SkASSERT(curImage.index() == *indexPtr);

View File

@ -35,7 +35,7 @@ sk_sp<SkImage> SkSharingDeserialContext::deserializeImage(
// Return something so the rest of the debugger can proceeed.
SkBitmap bm;
bm.allocPixels(SkImageInfo::MakeN32Premul(1, 1));
return SkImage::MakeFromBitmap(bm);
return bm.asImage();
}
SkSharingDeserialContext* context = reinterpret_cast<SkSharingDeserialContext*>(ctx);
uint32_t fid;

View File

@ -721,7 +721,7 @@ static const char* alpha_type_name(SkAlphaType alphaType) {
bool DrawCommand::flatten(const SkBitmap& bitmap,
SkJSONWriter& writer,
UrlDataManager& urlDataManager) {
sk_sp<SkImage> image(SkImage::MakeFromBitmap(bitmap));
sk_sp<SkImage> image(bitmap.asImage());
writer.appendString(DEBUGCANVAS_ATTRIBUTE_COLOR, color_type_name(bitmap.colorType()));
writer.appendString(DEBUGCANVAS_ATTRIBUTE_ALPHA, alpha_type_name(bitmap.alphaType()));
// Image will appear to have no uses, TODO(nifong): provide the user with a useful explanation