Only store width and height on SkPixelRef (part 1)
Relanding https://skia-review.googlesource.com/c/14105/
in pieces to try to diagnose problems with the Chrome
roll.
Bug: skia:6535
Change-Id: Ic321c437ecd3cb7940a48fd73fc22b192804c67a
Reviewed-on: https://skia-review.googlesource.com/14650
Commit-Queue: Matt Sarett <msarett@google.com>
Reviewed-by: Mike Reed <reed@google.com>
diff --git a/include/core/SkPixelRef.h b/include/core/SkPixelRef.h
index 6a86e59..05b0fbc 100644
--- a/include/core/SkPixelRef.h
+++ b/include/core/SkPixelRef.h
@@ -39,6 +39,8 @@
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 33ef97e..dfd15b2 100644
--- a/src/core/SkSpecialSurface.cpp
+++ b/src/core/SkSpecialSurface.cpp
@@ -63,12 +63,12 @@
class SkSpecialSurface_Raster : public SkSpecialSurface_Base {
public:
- SkSpecialSurface_Raster(sk_sp<SkPixelRef> pr,
+ SkSpecialSurface_Raster(const SkImageInfo& info,
+ sk_sp<SkPixelRef> 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 @@
sk_sp<SkSpecialSurface> SkSpecialSurface::MakeFromBitmap(const SkIRect& subset, SkBitmap& bm,
const SkSurfaceProps* props) {
- return sk_make_sp<SkSpecialSurface_Raster>(sk_ref_sp(bm.pixelRef()), subset, props);
+ return sk_make_sp<SkSpecialSurface_Raster>(bm.info(), sk_ref_sp(bm.pixelRef()), subset, props);
}
sk_sp<SkSpecialSurface> SkSpecialSurface::MakeRaster(const SkImageInfo& info,
@@ -103,9 +103,9 @@
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<SkSpecialSurface_Raster>(std::move(pr), subset, props);
+ return sk_make_sp<SkSpecialSurface_Raster>(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 91de4c5..8884755 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 2de1ed7..c4796c4 100644
--- a/src/image/SkSurface_Raster.cpp
+++ b/src/image/SkSurface_Raster.cpp
@@ -20,7 +20,7 @@
SkSurface_Raster(const SkImageInfo&, void*, size_t rb,
void (*releaseProc)(void* pixels, void* context), void* context,
const SkSurfaceProps*);
- SkSurface_Raster(sk_sp<SkPixelRef>, const SkSurfaceProps*);
+ SkSurface_Raster(const SkImageInfo& info, sk_sp<SkPixelRef>, const SkSurfaceProps*);
SkCanvas* onNewCanvas() override;
sk_sp<SkSurface> onNewSurface(const SkImageInfo&) override;
@@ -108,11 +108,10 @@
fWeOwnThePixels = false; // We are "Direct"
}
-SkSurface_Raster::SkSurface_Raster(sk_sp<SkPixelRef> pr, const SkSurfaceProps* props)
- : INHERITED(pr->info().width(), pr->info().height(), props)
+SkSurface_Raster::SkSurface_Raster(const SkImageInfo& info, sk_sp<SkPixelRef> 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 @@
if (rowBytes) {
SkASSERT(pr->rowBytes() == rowBytes);
}
- return sk_make_sp<SkSurface_Raster>(std::move(pr), props);
+ return sk_make_sp<SkSurface_Raster>(info, std::move(pr), props);
}
diff --git a/src/pdf/SkPDFDevice.cpp b/src/pdf/SkPDFDevice.cpp
index 358ba16..768277a 100644
--- a/src/pdf/SkPDFDevice.cpp
+++ b/src/pdf/SkPDFDevice.cpp
@@ -106,7 +106,9 @@
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) {