SkImage doesn't use props, so don't need to store it

BUG=skia:
TBR=bsalomon

Review URL: https://codereview.chromium.org/1372153006
This commit is contained in:
reed 2015-10-04 11:28:36 -07:00 committed by Commit bot
parent 588b9cab10
commit af3fbfca0a
9 changed files with 26 additions and 67 deletions

View File

@ -24,7 +24,6 @@ class SkPicture;
class SkPixelSerializer; class SkPixelSerializer;
class SkString; class SkString;
class SkSurface; class SkSurface;
class SkSurfaceProps;
class GrContext; class GrContext;
class GrTexture; class GrTexture;

View File

@ -198,15 +198,10 @@ static bool raster_canvas_supports(const SkImageInfo& info) {
return false; return false;
} }
static SkSurfaceProps copy_or_safe_defaults(const SkSurfaceProps* props) { SkImage_Base::SkImage_Base(int width, int height, uint32_t uniqueID)
return props ? *props : SkSurfaceProps(0, kUnknown_SkPixelGeometry);
}
SkImage_Base::SkImage_Base(int width, int height, uint32_t uniqueID, const SkSurfaceProps* props)
: INHERITED(width, height, uniqueID) : INHERITED(width, height, uniqueID)
, fProps(copy_or_safe_defaults(props))
, fAddedToCache(false) , fAddedToCache(false)
{ } {}
SkImage_Base::~SkImage_Base() { SkImage_Base::~SkImage_Base() {
if (fAddedToCache.load()) { if (fAddedToCache.load()) {
@ -276,7 +271,7 @@ SkImage* SkImage::NewFromBitmap(const SkBitmap& bm) {
#endif #endif
// This will check for immutable (share or copy) // This will check for immutable (share or copy)
return SkNewImageFromRasterBitmap(bm, nullptr); return SkNewImageFromRasterBitmap(bm);
} }
bool SkImage::asLegacyBitmap(SkBitmap* bitmap, LegacyBitmapMode mode) const { bool SkImage::asLegacyBitmap(SkBitmap* bitmap, LegacyBitmapMode mode) const {

View File

@ -14,8 +14,7 @@
// Call this if you explicitly want to use/share this pixelRef in the image // Call this if you explicitly want to use/share this pixelRef in the image
extern SkImage* SkNewImageFromPixelRef(const SkImageInfo&, SkPixelRef*, extern SkImage* SkNewImageFromPixelRef(const SkImageInfo&, SkPixelRef*,
const SkIPoint& pixelRefOrigin, const SkIPoint& pixelRefOrigin,
size_t rowBytes, size_t rowBytes);
const SkSurfaceProps*);
/** /**
* Examines the bitmap to decide if it can share the existing pixelRef, or * Examines the bitmap to decide if it can share the existing pixelRef, or
@ -39,8 +38,7 @@ enum ForceCopyMode {
kNo_ForceCopyMode, kNo_ForceCopyMode,
kYes_ForceCopyMode, // must copy the pixels even if the bitmap is immutable kYes_ForceCopyMode, // must copy the pixels even if the bitmap is immutable
}; };
extern SkImage* SkNewImageFromRasterBitmap(const SkBitmap&, const SkSurfaceProps*, extern SkImage* SkNewImageFromRasterBitmap(const SkBitmap&, ForceCopyMode = kNo_ForceCopyMode);
ForceCopyMode = kNo_ForceCopyMode);
static inline size_t SkImageMinRowBytes(const SkImageInfo& info) { static inline size_t SkImageMinRowBytes(const SkImageInfo& info) {
size_t minRB = info.minRowBytes(); size_t minRB = info.minRowBytes();

View File

@ -20,26 +20,10 @@ enum {
class SkImage_Base : public SkImage { class SkImage_Base : public SkImage {
public: public:
SkImage_Base(int width, int height, uint32_t uniqueID, const SkSurfaceProps* props); SkImage_Base(int width, int height, uint32_t uniqueID);
virtual ~SkImage_Base(); virtual ~SkImage_Base();
/** virtual const void* onPeekPixels(SkImageInfo*, size_t* /*rowBytes*/) const { return nullptr; }
* If the props weren't know at constructor time, call this but only before the image is
* ever released into the wild (since the props field must appear to be immutable).
*/
void initWithProps(const SkSurfaceProps& props) {
SkASSERT(this->unique()); // only viewed by one thread
SkSurfaceProps* mutableProps = const_cast<SkSurfaceProps*>(&fProps);
SkASSERT(mutableProps != &props); // check for self-assignment
mutableProps->~SkSurfaceProps();
new (mutableProps) SkSurfaceProps(props);
}
const SkSurfaceProps& props() const { return fProps; }
virtual const void* onPeekPixels(SkImageInfo*, size_t* /*rowBytes*/) const {
return nullptr;
}
// Default impl calls onDraw // Default impl calls onDraw
virtual bool onReadPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes, virtual bool onReadPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes,
@ -69,8 +53,6 @@ public:
} }
private: private:
const SkSurfaceProps fProps;
// Set true by caches when they cache content that's derived from the current pixels. // Set true by caches when they cache content that's derived from the current pixels.
mutable SkAtomic<bool> fAddedToCache; mutable SkAtomic<bool> fAddedToCache;

View File

@ -17,7 +17,7 @@
class SkImage_Generator : public SkImage_Base { class SkImage_Generator : public SkImage_Base {
public: public:
SkImage_Generator(SkImageCacherator* cache) SkImage_Generator(SkImageCacherator* cache)
: INHERITED(cache->info().width(), cache->info().height(), cache->uniqueID(), NULL) : INHERITED(cache->info().width(), cache->info().height(), cache->uniqueID())
, fCache(cache) // take ownership , fCache(cache) // take ownership
{} {}

View File

@ -19,7 +19,7 @@
SkImage_Gpu::SkImage_Gpu(int w, int h, uint32_t uniqueID, SkAlphaType at, GrTexture* tex, SkImage_Gpu::SkImage_Gpu(int w, int h, uint32_t uniqueID, SkAlphaType at, GrTexture* tex,
SkSurface::Budgeted budgeted) SkSurface::Budgeted budgeted)
: INHERITED(w, h, uniqueID, nullptr) : INHERITED(w, h, uniqueID)
, fTexture(SkRef(tex)) , fTexture(SkRef(tex))
, fAlphaType(at) , fAlphaType(at)
, fBudgeted(budgeted) , fBudgeted(budgeted)

View File

@ -63,7 +63,7 @@ public:
return true; return true;
} }
SkImage_Raster(const SkImageInfo&, SkData*, size_t rb, SkColorTable*, const SkSurfaceProps*); SkImage_Raster(const SkImageInfo&, SkData*, size_t rb, SkColorTable*);
virtual ~SkImage_Raster(); virtual ~SkImage_Raster();
bool onReadPixels(const SkImageInfo&, void*, size_t, int srcX, int srcY) const override; bool onReadPixels(const SkImageInfo&, void*, size_t, int srcX, int srcY) const override;
@ -74,16 +74,15 @@ public:
SkImage* onNewSubset(const SkIRect&) const override; SkImage* onNewSubset(const SkIRect&) const override;
// exposed for SkSurface_Raster via SkNewImageFromPixelRef // exposed for SkSurface_Raster via SkNewImageFromPixelRef
SkImage_Raster(const SkImageInfo&, SkPixelRef*, const SkIPoint& pixelRefOrigin, size_t rowBytes, SkImage_Raster(const SkImageInfo&, SkPixelRef*, const SkIPoint& origin, size_t rowBytes);
const SkSurfaceProps*);
SkPixelRef* getPixelRef() const { return fBitmap.pixelRef(); } SkPixelRef* getPixelRef() const { return fBitmap.pixelRef(); }
bool isOpaque() const override; bool isOpaque() const override;
bool onAsLegacyBitmap(SkBitmap*, LegacyBitmapMode) const override; bool onAsLegacyBitmap(SkBitmap*, LegacyBitmapMode) const override;
SkImage_Raster(const SkBitmap& bm, const SkSurfaceProps* props) SkImage_Raster(const SkBitmap& bm)
: INHERITED(bm.width(), bm.height(), bm.getGenerationID(), props) : INHERITED(bm.width(), bm.height(), bm.getGenerationID())
, fBitmap(bm) , fBitmap(bm)
{ {
if (bm.pixelRef()->isPreLocked()) { if (bm.pixelRef()->isPreLocked()) {
@ -99,11 +98,7 @@ public:
} }
private: private:
SkImage_Raster() : INHERITED(0, 0, kNeedNewImageUniqueID, nullptr) { SkBitmap fBitmap;
fBitmap.setImmutable();
}
SkBitmap fBitmap;
typedef SkImage_Base INHERITED; typedef SkImage_Base INHERITED;
}; };
@ -116,8 +111,8 @@ static void release_data(void* addr, void* context) {
} }
SkImage_Raster::SkImage_Raster(const Info& info, SkData* data, size_t rowBytes, SkImage_Raster::SkImage_Raster(const Info& info, SkData* data, size_t rowBytes,
SkColorTable* ctable, const SkSurfaceProps* props) SkColorTable* ctable)
: INHERITED(info.width(), info.height(), kNeedNewImageUniqueID, props) : INHERITED(info.width(), info.height(), kNeedNewImageUniqueID)
{ {
data->ref(); data->ref();
void* addr = const_cast<void*>(data->data()); void* addr = const_cast<void*>(data->data());
@ -128,8 +123,8 @@ SkImage_Raster::SkImage_Raster(const Info& info, SkData* data, size_t rowBytes,
} }
SkImage_Raster::SkImage_Raster(const Info& info, SkPixelRef* pr, const SkIPoint& pixelRefOrigin, SkImage_Raster::SkImage_Raster(const Info& info, SkPixelRef* pr, const SkIPoint& pixelRefOrigin,
size_t rowBytes, const SkSurfaceProps* props) size_t rowBytes)
: INHERITED(info.width(), info.height(), pr->getGenerationID(), props) : INHERITED(info.width(), info.height(), pr->getGenerationID())
{ {
fBitmap.setInfo(info, rowBytes); fBitmap.setInfo(info, rowBytes);
fBitmap.setPixelRef(pr, pixelRefOrigin); fBitmap.setPixelRef(pr, pixelRefOrigin);
@ -223,7 +218,7 @@ SkImage* SkImage::NewRasterCopy(const SkImageInfo& info, const void* pixels, siz
// Here we actually make a copy of the caller's pixel data // Here we actually make a copy of the caller's pixel data
SkAutoDataUnref data(SkData::NewWithCopy(pixels, size)); SkAutoDataUnref data(SkData::NewWithCopy(pixels, size));
return new SkImage_Raster(info, data, rowBytes, ctable, nullptr); return new SkImage_Raster(info, data, rowBytes, ctable);
} }
@ -239,7 +234,7 @@ SkImage* SkImage::NewRasterData(const SkImageInfo& info, SkData* data, size_t ro
} }
SkColorTable* ctable = nullptr; SkColorTable* ctable = nullptr;
return new SkImage_Raster(info, data, rowBytes, ctable, nullptr); return new SkImage_Raster(info, data, rowBytes, ctable);
} }
SkImage* SkImage::NewFromRaster(const SkImageInfo& info, const void* pixels, size_t rowBytes, SkImage* SkImage::NewFromRaster(const SkImageInfo& info, const void* pixels, size_t rowBytes,
@ -251,20 +246,18 @@ SkImage* SkImage::NewFromRaster(const SkImageInfo& info, const void* pixels, siz
SkColorTable* ctable = nullptr; SkColorTable* ctable = nullptr;
SkAutoDataUnref data(SkData::NewWithProc(pixels, size, proc, ctx)); SkAutoDataUnref data(SkData::NewWithProc(pixels, size, proc, ctx));
return new SkImage_Raster(info, data, rowBytes, ctable, nullptr); return new SkImage_Raster(info, data, rowBytes, ctable);
} }
SkImage* SkNewImageFromPixelRef(const SkImageInfo& info, SkPixelRef* pr, SkImage* SkNewImageFromPixelRef(const SkImageInfo& info, SkPixelRef* pr,
const SkIPoint& pixelRefOrigin, size_t rowBytes, const SkIPoint& pixelRefOrigin, size_t rowBytes) {
const SkSurfaceProps* props) {
if (!SkImage_Raster::ValidArgs(info, rowBytes, false, nullptr)) { if (!SkImage_Raster::ValidArgs(info, rowBytes, false, nullptr)) {
return nullptr; return nullptr;
} }
return new SkImage_Raster(info, pr, pixelRefOrigin, rowBytes, props); return new SkImage_Raster(info, pr, pixelRefOrigin, rowBytes);
} }
SkImage* SkNewImageFromRasterBitmap(const SkBitmap& bm, const SkSurfaceProps* props, SkImage* SkNewImageFromRasterBitmap(const SkBitmap& bm, ForceCopyMode forceCopy) {
ForceCopyMode forceCopy) {
SkASSERT(nullptr == bm.getTexture()); SkASSERT(nullptr == bm.getTexture());
bool hasColorTable = false; bool hasColorTable = false;
@ -285,13 +278,8 @@ SkImage* SkNewImageFromRasterBitmap(const SkBitmap& bm, const SkSurfaceProps* pr
image = SkImage::NewRasterCopy(tmp.info(), tmp.getPixels(), tmp.rowBytes(), image = SkImage::NewRasterCopy(tmp.info(), tmp.getPixels(), tmp.rowBytes(),
tmp.getColorTable()); tmp.getColorTable());
} }
// we don't expose props to NewRasterCopy (need a private vers) so post-init it here
if (image && props) {
as_IB(image)->initWithProps(*props);
}
} else { } else {
image = new SkImage_Raster(bm, props); image = new SkImage_Raster(bm);
} }
return image; return image;
} }

View File

@ -85,9 +85,6 @@ SkImage* SkSurface_Gpu::onNewImageSnapshot(Budgeted budgeted) {
image = new SkImage_Gpu(info.width(), info.height(), kNeedNewImageUniqueID, image = new SkImage_Gpu(info.width(), info.height(), kNeedNewImageUniqueID,
info.alphaType(), tex, budgeted); info.alphaType(), tex, budgeted);
} }
if (image) {
as_IB(image)->initWithProps(this->props());
}
return image; return image;
} }

View File

@ -126,7 +126,7 @@ SkImage* SkSurface_Raster::onNewImageSnapshot(Budgeted) {
} }
// Our pixels are in memory, so read access on the snapshot SkImage could be cheap. // Our pixels are in memory, so read access on the snapshot SkImage could be cheap.
// Lock the shared pixel ref to ensure peekPixels() is usable. // Lock the shared pixel ref to ensure peekPixels() is usable.
return SkNewImageFromRasterBitmap(fBitmap, &this->props(), return SkNewImageFromRasterBitmap(fBitmap,
fWeOwnThePixels ? kNo_ForceCopyMode : kYes_ForceCopyMode); fWeOwnThePixels ? kNo_ForceCopyMode : kYes_ForceCopyMode);
} }