diff --git a/include/core/SkPixelRef.h b/include/core/SkPixelRef.h index 6a86e59a86..05b0fbcf9c 100644 --- a/include/core/SkPixelRef.h +++ b/include/core/SkPixelRef.h @@ -39,6 +39,8 @@ public: return fInfo; } + int width() const { return fInfo.width(); } + int height() const { return fInfo.height(); } void* pixels() const { return fPixels; } SkColorTable* colorTable() const { return fCTable.get(); } size_t rowBytes() const { return fRowBytes; } diff --git a/src/core/SkSpecialSurface.cpp b/src/core/SkSpecialSurface.cpp index 33ef97e5bd..dfd15b2b2b 100644 --- a/src/core/SkSpecialSurface.cpp +++ b/src/core/SkSpecialSurface.cpp @@ -63,12 +63,12 @@ sk_sp SkSpecialSurface::makeImageSnapshot() { class SkSpecialSurface_Raster : public SkSpecialSurface_Base { public: - SkSpecialSurface_Raster(sk_sp pr, + SkSpecialSurface_Raster(const SkImageInfo& info, + sk_sp pr, const SkIRect& subset, const SkSurfaceProps* props) : INHERITED(subset, props) { - const SkImageInfo& info = pr->info(); - + SkASSERT(info.width() == pr->width() && info.height() == pr->height()); fBitmap.setInfo(info, info.minRowBytes()); fBitmap.setPixelRef(std::move(pr), 0, 0); @@ -93,7 +93,7 @@ private: sk_sp SkSpecialSurface::MakeFromBitmap(const SkIRect& subset, SkBitmap& bm, const SkSurfaceProps* props) { - return sk_make_sp(sk_ref_sp(bm.pixelRef()), subset, props); + return sk_make_sp(bm.info(), sk_ref_sp(bm.pixelRef()), subset, props); } sk_sp SkSpecialSurface::MakeRaster(const SkImageInfo& info, @@ -103,9 +103,9 @@ sk_sp SkSpecialSurface::MakeRaster(const SkImageInfo& info, return nullptr; } - const SkIRect subset = SkIRect::MakeWH(pr->info().width(), pr->info().height()); + const SkIRect subset = SkIRect::MakeWH(info.width(), info.height()); - return sk_make_sp(std::move(pr), subset, props); + return sk_make_sp(info, std::move(pr), subset, props); } #if SK_SUPPORT_GPU diff --git a/src/image/SkImage_Raster.cpp b/src/image/SkImage_Raster.cpp index 91de4c5b0b..88847551d1 100644 --- a/src/image/SkImage_Raster.cpp +++ b/src/image/SkImage_Raster.cpp @@ -28,7 +28,7 @@ // fixes https://bug.skia.org/5096 static bool is_not_subset(const SkBitmap& bm) { SkASSERT(bm.pixelRef()); - SkISize dim = bm.pixelRef()->info().dimensions(); + SkISize dim = SkISize::Make(bm.pixelRef()->width(), bm.pixelRef()->height()); SkASSERT(dim != bm.dimensions() || bm.pixelRefOrigin().isZero()); return dim == bm.dimensions(); } diff --git a/src/image/SkSurface_Raster.cpp b/src/image/SkSurface_Raster.cpp index 2de1ed70d3..c4796c402f 100644 --- a/src/image/SkSurface_Raster.cpp +++ b/src/image/SkSurface_Raster.cpp @@ -20,7 +20,7 @@ public: SkSurface_Raster(const SkImageInfo&, void*, size_t rb, void (*releaseProc)(void* pixels, void* context), void* context, const SkSurfaceProps*); - SkSurface_Raster(sk_sp, const SkSurfaceProps*); + SkSurface_Raster(const SkImageInfo& info, sk_sp, const SkSurfaceProps*); SkCanvas* onNewCanvas() override; sk_sp onNewSurface(const SkImageInfo&) override; @@ -108,11 +108,10 @@ SkSurface_Raster::SkSurface_Raster(const SkImageInfo& info, void* pixels, size_t fWeOwnThePixels = false; // We are "Direct" } -SkSurface_Raster::SkSurface_Raster(sk_sp pr, const SkSurfaceProps* props) - : INHERITED(pr->info().width(), pr->info().height(), props) +SkSurface_Raster::SkSurface_Raster(const SkImageInfo& info, sk_sp pr, + const SkSurfaceProps* props) + : INHERITED(pr->width(), pr->height(), props) { - const SkImageInfo& info = pr->info(); - fBitmap.setInfo(info, pr->rowBytes()); fRowBytes = pr->rowBytes(); // we track this, so that subsequent re-allocs will match fBitmap.setPixelRef(std::move(pr), 0, 0); @@ -215,5 +214,5 @@ sk_sp SkSurface::MakeRaster(const SkImageInfo& info, size_t rowBytes, if (rowBytes) { SkASSERT(pr->rowBytes() == rowBytes); } - return sk_make_sp(std::move(pr), props); + return sk_make_sp(info, std::move(pr), props); } diff --git a/src/pdf/SkPDFDevice.cpp b/src/pdf/SkPDFDevice.cpp index 358ba1638f..768277a7b9 100644 --- a/src/pdf/SkPDFDevice.cpp +++ b/src/pdf/SkPDFDevice.cpp @@ -106,7 +106,9 @@ static SkImageSubset make_image_subset(const SkBitmap& bitmap) { SkIRect subset = bitmap.getSubset(); SkASSERT(bitmap.pixelRef()); SkBitmap tmp; - tmp.setInfo(bitmap.pixelRef()->info(), bitmap.rowBytes()); + SkImageInfo pixelRefInfo = + bitmap.info().makeWH(bitmap.pixelRef()->width(), bitmap.pixelRef()->height()); + tmp.setInfo(pixelRefInfo, bitmap.rowBytes()); tmp.setPixelRef(sk_ref_sp(bitmap.pixelRef()), 0, 0); auto img = SkImage::MakeFromBitmap(tmp); if (img) {