SkImage method for detecting lazy decoding

BUG=skia:4224
R=reed@google.com

Review URL: https://codereview.chromium.org/1305453007
This commit is contained in:
fmalita 2015-08-20 08:47:26 -07:00 committed by Commit bot
parent 7d173403f4
commit ddbbddabef
9 changed files with 36 additions and 4 deletions

View File

@ -288,6 +288,12 @@ public:
*/
bool asLegacyBitmap(SkBitmap*, LegacyBitmapMode) const;
/**
* Returns true if the image is backed by an image-generator or other src that creates
* (and caches) its pixels / texture on-demand.
*/
bool isLazyGenerated() const;
protected:
SkImage(int width, int height, uint32_t uniqueID);

View File

@ -265,6 +265,11 @@ public:
virtual SkDiscardableMemory* diagnostic_only_getDiscardable() const { return NULL; }
/**
* Returns true if the pixels are generated on-the-fly (when required).
*/
bool isLazyGenerated() const { return this->onIsLazyGenerated(); }
protected:
/**
* On success, returns true and fills out the LockRec for the pixels. On
@ -318,6 +323,8 @@ protected:
virtual bool onRequestLock(const LockRequest&, LockResult*);
virtual bool onIsLazyGenerated() const { return false; }
/** Return the mutex associated with this pixelref. This value is assigned
in the constructor, and cannot change during the lifetime of the object.
*/

View File

@ -287,6 +287,10 @@ SkImage* SkImage::NewFromPicture(const SkPicture* picture, const SkISize& dimens
return NewFromGenerator(SkImageGenerator::NewFromPicture(dimensions, picture, matrix, paint));
}
bool SkImage::isLazyGenerated() const {
return as_IB(this)->onIsLazyGenerated();
}
//////////////////////////////////////////////////////////////////////////////////////
#if !SK_SUPPORT_GPU

View File

@ -60,7 +60,7 @@ public:
virtual SkShader* onNewShader(SkShader::TileMode,
SkShader::TileMode,
const SkMatrix* localMatrix) const { return NULL; };
const SkMatrix* localMatrix) const { return NULL; }
// newWidth > 0, newHeight > 0, subset either NULL or a proper subset of this bounds
virtual SkImage* onNewImage(int newWidth, int newHeight, const SkIRect* subset,
@ -69,6 +69,8 @@ public:
virtual bool onAsLegacyBitmap(SkBitmap*, LegacyBitmapMode) const;
virtual bool onIsLazyGenerated() const { return false; }
private:
const SkSurfaceProps fProps;

View File

@ -93,6 +93,10 @@ public:
SkASSERT(fBitmap.isImmutable());
}
bool onIsLazyGenerated() const override {
return fBitmap.pixelRef() && fBitmap.pixelRef()->isLazyGenerated();
}
private:
SkImage_Raster() : INHERITED(0, 0, kNeedNewImageUniqueID, NULL) {
fBitmap.setImmutable();

View File

@ -50,6 +50,8 @@ protected:
return fImageGenerator->refEncodedData();
}
bool onIsLazyGenerated() const override { return true; }
private:
SkImageGenerator* const fImageGenerator;
bool fErrorInDecoding;

View File

@ -36,6 +36,8 @@ protected:
return fGenerator->refEncodedData();
}
bool onIsLazyGenerated() const override { return true; }
private:
SkImageGenerator* const fGenerator;
SkDiscardableMemory::Factory* const fDMFactory;

View File

@ -326,6 +326,7 @@ DEF_TEST(Image_NewFromGenerator, r) {
}
REPORTER_ASSERT(r, TestImageGenerator::Width() == image->width());
REPORTER_ASSERT(r, TestImageGenerator::Height() == image->height());
REPORTER_ASSERT(r, image->isLazyGenerated());
SkBitmap bitmap;
bitmap.allocN32Pixels(TestImageGenerator::Width(), TestImageGenerator::Height());

View File

@ -229,10 +229,11 @@ DEF_TEST(image_newfrombitmap, reporter) {
void (*fMakeProc)(SkBitmap*);
bool fExpectPeekSuccess;
bool fExpectSharedID;
bool fExpectLazy;
} rec[] = {
{ make_bitmap_lazy, false, true },
{ make_bitmap_mutable, true, false },
{ make_bitmap_immutable, true, true },
{ make_bitmap_lazy, false, true, true },
{ make_bitmap_mutable, true, false, false },
{ make_bitmap_immutable, true, true, false },
};
for (size_t i = 0; i < SK_ARRAY_COUNT(rec); ++i) {
@ -247,6 +248,9 @@ DEF_TEST(image_newfrombitmap, reporter) {
const bool peekSuccess = image->peekPixels(&pmap);
REPORTER_ASSERT(reporter, peekSuccess == rec[i].fExpectPeekSuccess);
const bool lazy = image->isLazyGenerated();
REPORTER_ASSERT(reporter, lazy == rec[i].fExpectLazy);
}
}