remove kRW_LegacyBitmapMode

experiment to see if there are any unknown dependencies
on kRW_LegacyBitmapMode

R=reed@google.com,fmalita@chromium.org,bungeman@google.com
Bug: skia:5615
Change-Id: I2cc578570ac18cd31c3520e1bd801f4a7a669347
Reviewed-on: https://skia-review.googlesource.com/105283
Reviewed-by: Florin Malita <fmalita@chromium.org>
Reviewed-by: Mike Reed <reed@google.com>
Reviewed-by: Ben Wagner <bungeman@google.com>
Commit-Queue: Cary Clark <caryclark@google.com>
This commit is contained in:
Cary Clark 2018-02-07 15:51:00 -05:00 committed by Skia Commit-Bot
parent 4150eea6c4
commit 4f5a79c676
13 changed files with 61 additions and 79 deletions

View File

@ -30,7 +30,7 @@ DEF_SIMPLE_GM(cross_context_image, canvas, 512 * 3 + 60, 512 + 128 + 30) {
SkBitmap bmp;
SkPixmap pixmap;
SkAssertResult(encodedImage->asLegacyBitmap(&bmp, SkImage::kRO_LegacyBitmapMode) &&
SkAssertResult(encodedImage->asLegacyBitmap(&bmp) &&
bmp.peekPixels(&pixmap));
sk_sp<SkImage> crossContextRaster = SkImage::MakeCrossContextFromPixmap(

View File

@ -79,7 +79,7 @@ static sk_sp<SkImage> makebm(SkCanvas* origCanvas, SkBitmap* resultBM, int w, in
SkBitmap tempBM;
image->asLegacyBitmap(&tempBM, SkImage::kRO_LegacyBitmapMode);
image->asLegacyBitmap(&tempBM);
// Let backends know we won't change this, so they don't have to deep copy it defensively.
tempBM.setImmutable();

View File

@ -583,22 +583,22 @@ public:
// Helper functions to convert to SkBitmap
// TODO: enum LegacyBitmapMode to be deprecated; keeping enum until callers are revised to omit
// parameter
enum LegacyBitmapMode {
kRO_LegacyBitmapMode,
kRW_LegacyBitmapMode,
};
/**
* Attempt to create a bitmap with the same pixels as the image. The result will always be
* a raster-backed bitmap (texture-backed bitmaps are DEPRECATED, and not supported here).
*
* If the mode is kRO (read-only), the resulting bitmap will be marked as immutable.
* The resulting bitmap will be marked as immutable.
*
* On succcess, returns true. On failure, returns false and the bitmap parameter will be reset
* to empty.
*/
bool asLegacyBitmap(SkBitmap* bitmap, LegacyBitmapMode legacyBitmapMode) const;
bool asLegacyBitmap(SkBitmap* bitmap, LegacyBitmapMode legacyBitmapMode = kRO_LegacyBitmapMode) const;
/**
* Returns true if the image is backed by an image-generator or other src that creates

View File

@ -215,11 +215,11 @@ sk_sp<SkImage> SkImage::MakeFromBitmap(const SkBitmap& bm) {
return SkMakeImageFromRasterBitmap(bm, kIfMutable_SkCopyPixelsMode);
}
bool SkImage::asLegacyBitmap(SkBitmap* bitmap, LegacyBitmapMode mode) const {
return as_IB(this)->onAsLegacyBitmap(bitmap, mode);
bool SkImage::asLegacyBitmap(SkBitmap* bitmap, LegacyBitmapMode ) const {
return as_IB(this)->onAsLegacyBitmap(bitmap);
}
bool SkImage_Base::onAsLegacyBitmap(SkBitmap* bitmap, LegacyBitmapMode mode) const {
bool SkImage_Base::onAsLegacyBitmap(SkBitmap* bitmap) const {
// As the base-class, all we can do is make a copy (regardless of mode).
// Subclasses that want to be more optimal should override.
SkImageInfo info = this->onImageInfo().makeColorType(kN32_SkColorType).makeColorSpace(nullptr);
@ -231,9 +231,7 @@ bool SkImage_Base::onAsLegacyBitmap(SkBitmap* bitmap, LegacyBitmapMode mode) con
return false;
}
if (kRO_LegacyBitmapMode == mode) {
bitmap->setImmutable();
}
bitmap->setImmutable();
return true;
}

View File

@ -71,7 +71,7 @@ public:
virtual SkData* onRefEncoded() const { return nullptr; }
virtual bool onAsLegacyBitmap(SkBitmap*, LegacyBitmapMode) const;
virtual bool onAsLegacyBitmap(SkBitmap*) const;
// True for picture-backed and codec-backed
virtual bool onIsLazyGenerated() const { return false; }

View File

@ -97,7 +97,7 @@ public:
SkPixelRef* getPixelRef() const { return fBitmap.pixelRef(); }
bool onAsLegacyBitmap(SkBitmap*, LegacyBitmapMode) const override;
bool onAsLegacyBitmap(SkBitmap*) const override;
SkImage_Raster(const SkBitmap& bm, bool bitmapMayBeMutable = false)
: INHERITED(bm.width(), bm.height(),
@ -327,20 +327,18 @@ const SkPixelRef* SkBitmapImageGetPixelRef(const SkImage* image) {
return ((const SkImage_Raster*)image)->getPixelRef();
}
bool SkImage_Raster::onAsLegacyBitmap(SkBitmap* bitmap, LegacyBitmapMode mode) const {
if (kRO_LegacyBitmapMode == mode) {
// When we're a snapshot from a surface, our bitmap may not be marked immutable
// even though logically always we are, but in that case we can't physically share our
// pixelref since the caller might call setImmutable() themselves
// (thus changing our state).
if (fBitmap.isImmutable()) {
SkIPoint origin = fBitmap.pixelRefOrigin();
bitmap->setInfo(fBitmap.info(), fBitmap.rowBytes());
bitmap->setPixelRef(sk_ref_sp(fBitmap.pixelRef()), origin.x(), origin.y());
return true;
}
bool SkImage_Raster::onAsLegacyBitmap(SkBitmap* bitmap) const {
// When we're a snapshot from a surface, our bitmap may not be marked immutable
// even though logically always we are, but in that case we can't physically share our
// pixelref since the caller might call setImmutable() themselves
// (thus changing our state).
if (fBitmap.isImmutable()) {
SkIPoint origin = fBitmap.pixelRefOrigin();
bitmap->setInfo(fBitmap.info(), fBitmap.rowBytes());
bitmap->setPixelRef(sk_ref_sp(fBitmap.pixelRef()), origin.x(), origin.y());
return true;
}
return this->INHERITED::onAsLegacyBitmap(bitmap, mode);
return this->INHERITED::onAsLegacyBitmap(bitmap);
}
///////////////////////////////////////////////////////////////////////////////

View File

@ -1048,7 +1048,7 @@ HRESULT SkXPSDevice::createXpsBrush(const SkPaint& skPaint,
SkMatrix outMatrix;
SkShader::TileMode xy[2];
SkImage* image = shader->isAImage(&outMatrix, xy);
if (image && image->asLegacyBitmap(&outTexture, SkImage::kRO_LegacyBitmapMode)) {
if (image && image->asLegacyBitmap(&outTexture)) {
//TODO: outMatrix??
SkMatrix localMatrix = shader->getLocalMatrix();
if (parentTransform) {

View File

@ -165,9 +165,9 @@ DEF_TEST(Encode_JpegDownsample, r) {
REPORTER_ASSERT(r, data1->size() < data2->size());
SkBitmap bm0, bm1, bm2;
SkImage::MakeFromEncoded(data0)->asLegacyBitmap(&bm0, SkImage::kRO_LegacyBitmapMode);
SkImage::MakeFromEncoded(data1)->asLegacyBitmap(&bm1, SkImage::kRO_LegacyBitmapMode);
SkImage::MakeFromEncoded(data2)->asLegacyBitmap(&bm2, SkImage::kRO_LegacyBitmapMode);
SkImage::MakeFromEncoded(data0)->asLegacyBitmap(&bm0);
SkImage::MakeFromEncoded(data1)->asLegacyBitmap(&bm1);
SkImage::MakeFromEncoded(data2)->asLegacyBitmap(&bm2);
REPORTER_ASSERT(r, almost_equals(bm0, bm1, 60));
REPORTER_ASSERT(r, almost_equals(bm1, bm2, 60));
}
@ -279,9 +279,9 @@ DEF_TEST(Encode_PngOptions, r) {
REPORTER_ASSERT(r, data1->size() < data2->size());
SkBitmap bm0, bm1, bm2;
SkImage::MakeFromEncoded(data0)->asLegacyBitmap(&bm0, SkImage::kRO_LegacyBitmapMode);
SkImage::MakeFromEncoded(data1)->asLegacyBitmap(&bm1, SkImage::kRO_LegacyBitmapMode);
SkImage::MakeFromEncoded(data2)->asLegacyBitmap(&bm2, SkImage::kRO_LegacyBitmapMode);
SkImage::MakeFromEncoded(data0)->asLegacyBitmap(&bm0);
SkImage::MakeFromEncoded(data1)->asLegacyBitmap(&bm1);
SkImage::MakeFromEncoded(data2)->asLegacyBitmap(&bm2);
REPORTER_ASSERT(r, almost_equals(bm0, bm1, 0));
REPORTER_ASSERT(r, almost_equals(bm0, bm2, 0));
}
@ -330,10 +330,10 @@ DEF_TEST(Encode_WebpOptions, r) {
REPORTER_ASSERT(r, data2->size() > data3->size());
SkBitmap bm0, bm1, bm2, bm3;
SkImage::MakeFromEncoded(data0)->asLegacyBitmap(&bm0, SkImage::kRO_LegacyBitmapMode);
SkImage::MakeFromEncoded(data1)->asLegacyBitmap(&bm1, SkImage::kRO_LegacyBitmapMode);
SkImage::MakeFromEncoded(data2)->asLegacyBitmap(&bm2, SkImage::kRO_LegacyBitmapMode);
SkImage::MakeFromEncoded(data3)->asLegacyBitmap(&bm3, SkImage::kRO_LegacyBitmapMode);
SkImage::MakeFromEncoded(data0)->asLegacyBitmap(&bm0);
SkImage::MakeFromEncoded(data1)->asLegacyBitmap(&bm1);
SkImage::MakeFromEncoded(data2)->asLegacyBitmap(&bm2);
SkImage::MakeFromEncoded(data3)->asLegacyBitmap(&bm3);
REPORTER_ASSERT(r, almost_equals(bm0, bm1, 0));
REPORTER_ASSERT(r, almost_equals(bm0, bm2, 90));
REPORTER_ASSERT(r, almost_equals(bm2, bm3, 45));

View File

@ -689,14 +689,12 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ImageReadPixels_Gpu, reporter, ctxInfo) {
#endif
static void check_legacy_bitmap(skiatest::Reporter* reporter, const SkImage* image,
const SkBitmap& bitmap, SkImage::LegacyBitmapMode mode) {
const SkBitmap& bitmap) {
REPORTER_ASSERT(reporter, image->width() == bitmap.width());
REPORTER_ASSERT(reporter, image->height() == bitmap.height());
REPORTER_ASSERT(reporter, image->alphaType() == bitmap.alphaType());
if (SkImage::kRO_LegacyBitmapMode == mode) {
REPORTER_ASSERT(reporter, bitmap.isImmutable());
}
REPORTER_ASSERT(reporter, bitmap.isImmutable());
REPORTER_ASSERT(reporter, bitmap.getPixels());
@ -706,14 +704,14 @@ static void check_legacy_bitmap(skiatest::Reporter* reporter, const SkImage* ima
REPORTER_ASSERT(reporter, imageColor == *bitmap.getAddr32(0, 0));
}
static void test_legacy_bitmap(skiatest::Reporter* reporter, const SkImage* image, SkImage::LegacyBitmapMode mode) {
static void test_legacy_bitmap(skiatest::Reporter* reporter, const SkImage* image) {
if (!image) {
ERRORF(reporter, "Failed to create image.");
return;
}
SkBitmap bitmap;
REPORTER_ASSERT(reporter, image->asLegacyBitmap(&bitmap, mode));
check_legacy_bitmap(reporter, image, bitmap, mode);
REPORTER_ASSERT(reporter, image->asLegacyBitmap(&bitmap));
check_legacy_bitmap(reporter, image, bitmap);
// Test subsetting to exercise the rowBytes logic.
SkBitmap tmp;
@ -723,41 +721,29 @@ static void test_legacy_bitmap(skiatest::Reporter* reporter, const SkImage* imag
REPORTER_ASSERT(reporter, subsetImage.get());
SkBitmap subsetBitmap;
REPORTER_ASSERT(reporter, subsetImage->asLegacyBitmap(&subsetBitmap, mode));
check_legacy_bitmap(reporter, subsetImage.get(), subsetBitmap, mode);
REPORTER_ASSERT(reporter, subsetImage->asLegacyBitmap(&subsetBitmap));
check_legacy_bitmap(reporter, subsetImage.get(), subsetBitmap);
}
DEF_TEST(ImageLegacyBitmap, reporter) {
const SkImage::LegacyBitmapMode modes[] = {
SkImage::kRO_LegacyBitmapMode,
SkImage::kRW_LegacyBitmapMode,
};
for (auto& mode : modes) {
sk_sp<SkImage> image(create_image());
test_legacy_bitmap(reporter, image.get(), mode);
sk_sp<SkImage> image(create_image());
test_legacy_bitmap(reporter, image.get());
image = create_data_image();
test_legacy_bitmap(reporter, image.get(), mode);
image = create_data_image();
test_legacy_bitmap(reporter, image.get());
RasterDataHolder dataHolder;
image = create_rasterproc_image(&dataHolder);
test_legacy_bitmap(reporter, image.get(), mode);
image.reset();
REPORTER_ASSERT(reporter, 1 == dataHolder.fReleaseCount);
RasterDataHolder dataHolder;
image = create_rasterproc_image(&dataHolder);
test_legacy_bitmap(reporter, image.get());
image.reset();
REPORTER_ASSERT(reporter, 1 == dataHolder.fReleaseCount);
image = create_codec_image();
test_legacy_bitmap(reporter, image.get(), mode);
}
image = create_codec_image();
test_legacy_bitmap(reporter, image.get());
}
#if SK_SUPPORT_GPU
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ImageLegacyBitmap_Gpu, reporter, ctxInfo) {
const SkImage::LegacyBitmapMode modes[] = {
SkImage::kRO_LegacyBitmapMode,
SkImage::kRW_LegacyBitmapMode,
};
for (auto& mode : modes) {
sk_sp<SkImage> image(create_gpu_image(ctxInfo.grContext()));
test_legacy_bitmap(reporter, image.get(), mode);
}
sk_sp<SkImage> image(create_gpu_image(ctxInfo.grContext()));
test_legacy_bitmap(reporter, image.get());
}
#endif
@ -1352,7 +1338,7 @@ DEF_TEST(Image_makeColorSpace, r) {
sk_sp<SkImage> srgbImage = SkImage::MakeFromBitmap(srgbBitmap);
sk_sp<SkImage> p3Image = srgbImage->makeColorSpace(p3, SkTransferFunctionBehavior::kIgnore);
SkBitmap p3Bitmap;
bool success = p3Image->asLegacyBitmap(&p3Bitmap, SkImage::kRO_LegacyBitmapMode);
bool success = p3Image->asLegacyBitmap(&p3Bitmap);
REPORTER_ASSERT(r, success);
REPORTER_ASSERT(r, almost_equal(0x28, SkGetPackedR32(*p3Bitmap.getAddr32(0, 0))));
REPORTER_ASSERT(r, almost_equal(0x40, SkGetPackedG32(*p3Bitmap.getAddr32(0, 0))));
@ -1361,7 +1347,7 @@ DEF_TEST(Image_makeColorSpace, r) {
sk_sp<SkImage> adobeImage = srgbImage->makeColorSpace(adobeGamut,
SkTransferFunctionBehavior::kIgnore);
SkBitmap adobeBitmap;
success = adobeImage->asLegacyBitmap(&adobeBitmap, SkImage::kRO_LegacyBitmapMode);
success = adobeImage->asLegacyBitmap(&adobeBitmap);
REPORTER_ASSERT(r, success);
REPORTER_ASSERT(r, almost_equal(0x21, SkGetPackedR32(*adobeBitmap.getAddr32(0, 0))));
REPORTER_ASSERT(r, almost_equal(0x31, SkGetPackedG32(*adobeBitmap.getAddr32(0, 0))));
@ -1369,7 +1355,7 @@ DEF_TEST(Image_makeColorSpace, r) {
srgbImage = GetResourceAsImage("images/1x1.png");
p3Image = srgbImage->makeColorSpace(p3, SkTransferFunctionBehavior::kIgnore);
success = p3Image->asLegacyBitmap(&p3Bitmap, SkImage::kRO_LegacyBitmapMode);
success = p3Image->asLegacyBitmap(&p3Bitmap);
REPORTER_ASSERT(r, success);
REPORTER_ASSERT(r, almost_equal(0x8B, SkGetPackedR32(*p3Bitmap.getAddr32(0, 0))));
REPORTER_ASSERT(r, almost_equal(0x82, SkGetPackedG32(*p3Bitmap.getAddr32(0, 0))));

View File

@ -1042,7 +1042,7 @@ static void test_overdraw_surface(skiatest::Reporter* r, SkSurface* surface) {
sk_sp<SkImage> image = surface->makeImageSnapshot();
SkBitmap bitmap;
image->asLegacyBitmap(&bitmap, SkImage::kRO_LegacyBitmapMode);
image->asLegacyBitmap(&bitmap);
for (int y = 0; y < 10; y++) {
for (int x = 0; x < 10; x++) {
REPORTER_ASSERT(r, 1 == SkGetPackedA32(*bitmap.getAddr32(x, y)));

View File

@ -922,7 +922,7 @@ static SkBitmap* load_bitmap(const Json::Value& jsonBitmap, UrlDataManager& urlD
std::unique_ptr<SkBitmap> bitmap(new SkBitmap());
if (nullptr != image) {
if (!image->asLegacyBitmap(bitmap.get(), SkImage::kRW_LegacyBitmapMode)) {
if (!image->asLegacyBitmap(bitmap.get())) {
SkDebugf("image decode failed\n");
return nullptr;
}

View File

@ -265,7 +265,7 @@ int main(int argc, char** argv) {
perror("Unable to decode the source image.");
return 1;
}
SkAssertResult(image->asLegacyBitmap(&source, SkImage::kRO_LegacyBitmapMode));
SkAssertResult(image->asLegacyBitmap(&source));
}
}
sk_sp<SkData> rasterData, gpuData, pdfData, skpData;

View File

@ -138,7 +138,7 @@ struct Png : Dst {
}
SkBitmap bm;
if (!target->image()->asLegacyBitmap(&bm, SkImage::kRO_LegacyBitmapMode)) {
if (!target->image()->asLegacyBitmap(&bm)) {
return Status::Failed;
}