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>
This commit is contained in:
Matt Sarett 2017-04-28 15:43:35 -04:00 committed by Skia Commit-Bot
parent dc87c95382
commit a6e976aac8
5 changed files with 17 additions and 14 deletions

View File

@ -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; }

View File

@ -63,12 +63,12 @@ sk_sp<SkSpecialImage> SkSpecialSurface::makeImageSnapshot() {
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 @@ private:
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 @@ sk_sp<SkSpecialSurface> 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<SkSpecialSurface_Raster>(std::move(pr), subset, props);
return sk_make_sp<SkSpecialSurface_Raster>(info, std::move(pr), subset, props);
}
#if SK_SUPPORT_GPU

View File

@ -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();
}

View File

@ -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<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 @@ SkSurface_Raster::SkSurface_Raster(const SkImageInfo& info, void* pixels, size_t
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 @@ sk_sp<SkSurface> SkSurface::MakeRaster(const SkImageInfo& info, size_t rowBytes,
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);
}

View File

@ -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) {