take gr-context parameter to refEncoded, indicating a desire for only gpu-specific formats

Prime motivator:
- we always call refEncoded on the generator when trying to upload
   - we call it *before* we ask for raster or YUV
- for blink, this call can be very slow, as they have to cons-up their SkData the first time (and grab a mutex to do it)
- this parameter will indicate to them that we're only interested in gpu formats, which they will know if they have.

BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1556333004

Review URL: https://codereview.chromium.org/1556333004
This commit is contained in:
reed 2016-01-05 09:16:19 -08:00 committed by Commit bot
parent 20ccd40de9
commit 05dd251e5e
10 changed files with 37 additions and 18 deletions

View File

@ -22,6 +22,12 @@ class SkMatrix;
class SkPaint;
class SkPicture;
#ifdef SK_SUPPORT_LEGACY_REFENCODEDDATA_NOCTX
#define SK_REFENCODEDDATA_CTXPARAM
#else
#define SK_REFENCODEDDATA_CTXPARAM GrContext* ctx
#endif
/**
* Takes ownership of SkImageGenerator. If this method fails for
* whatever reason, it will return false and immediatetely delete
@ -64,12 +70,20 @@ public:
/**
* Return a ref to the encoded (i.e. compressed) representation,
* of this data.
* of this data. If the GrContext is non-null, then the caller is only interested in
* gpu-specific formats, so the impl may return null even if they have encoded data,
* assuming they know it is not suitable for the gpu.
*
* If non-NULL is returned, the caller is responsible for calling
* unref() on the data when it is finished.
*/
SkData* refEncodedData() { return this->onRefEncodedData(); }
SkData* refEncodedData(GrContext* ctx = nullptr) {
#ifdef SK_SUPPORT_LEGACY_REFENCODEDDATA_NOCTX
return this->onRefEncodedData();
#else
return this->onRefEncodedData(ctx);
#endif
}
/**
* Return the ImageInfo associated with this generator.
@ -230,7 +244,7 @@ public:
protected:
SkImageGenerator(const SkImageInfo& info);
virtual SkData* onRefEncodedData();
virtual SkData* onRefEncodedData(SK_REFENCODEDDATA_CTXPARAM);
virtual bool onGetPixels(const SkImageInfo& info, void* pixels, size_t rowBytes,
SkPMColor ctable[], int* ctableCount);

View File

@ -69,9 +69,9 @@ SkImageCacherator::SkImageCacherator(SkImageGenerator* gen, const SkImageInfo& i
, fUniqueID(uniqueID)
{}
SkData* SkImageCacherator::refEncoded() {
SkData* SkImageCacherator::refEncoded(GrContext* ctx) {
ScopedGenerator generator(this);
return generator->refEncodedData();
return generator->refEncodedData(ctx);
}
static bool check_output_bitmap(const SkBitmap& bitmap, uint32_t expectedID) {
@ -259,7 +259,7 @@ GrTexture* SkImageCacherator::lockTexture(GrContext* ctx, const GrUniqueKey& key
const GrSurfaceDesc desc = GrImageInfoToSurfaceDesc(fInfo);
// 3. Ask the generator to return a compressed form that the GPU might support
SkAutoTUnref<SkData> data(this->refEncoded());
SkAutoTUnref<SkData> data(this->refEncoded(ctx));
if (data) {
GrTexture* tex = load_compressed_into_texture(ctx, data, desc);
if (tex) {

View File

@ -54,8 +54,11 @@ public:
/**
* If the underlying src naturally is represented by an encoded blob (in SkData), this returns
* a ref to that data. If not, it returns null.
*
* If a GrContext is specified, then the caller is only interested in gpu-specific encoded
* formats, so others (e.g. PNG) can just return nullptr.
*/
SkData* refEncoded();
SkData* refEncoded(GrContext*);
// Only return true if the generate has already been cached.
bool lockAsBitmapOnlyIfAlreadyCached(SkBitmap*);

View File

@ -137,7 +137,7 @@ bool SkImageGenerator::generateScaledPixels(const SkISize& scaledSize,
/////////////////////////////////////////////////////////////////////////////////////////////
SkData* SkImageGenerator::onRefEncodedData() {
SkData* SkImageGenerator::onRefEncodedData(SK_REFENCODEDDATA_CTXPARAM) {
return nullptr;
}

View File

@ -202,7 +202,8 @@ SkData* SkImage::encode(SkPixelSerializer* serializer) const {
}
SkData* SkImage::refEncoded() const {
return as_IB(this)->onRefEncoded();
GrContext* ctx = nullptr; // should we allow the caller to pass in a ctx?
return as_IB(this)->onRefEncoded(ctx);
}
SkImage* SkImage::NewFromEncoded(SkData* encoded, const SkIRect* subset) {

View File

@ -51,7 +51,8 @@ public:
virtual SkImage* onNewSubset(const SkIRect&) const = 0;
virtual SkData* onRefEncoded() const { return nullptr; }
// If a ctx is specified, then only gpu-specific formats are requested.
virtual SkData* onRefEncoded(GrContext*) const { return nullptr; }
virtual bool onAsLegacyBitmap(SkBitmap*, LegacyBitmapMode) const;

View File

@ -24,7 +24,7 @@ public:
bool onReadPixels(const SkImageInfo&, void*, size_t, int srcX, int srcY, CachingHint) const override;
const void* onPeekPixels(SkImageInfo*, size_t* /*rowBytes*/) const override;
SkImageCacherator* peekCacherator() const override { return fCache; }
SkData* onRefEncoded() const override;
SkData* onRefEncoded(GrContext*) const override;
bool isOpaque() const override { return fCache->info().isOpaque(); }
SkImage* onNewSubset(const SkIRect&) const override;
bool getROPixels(SkBitmap*, CachingHint) const override;
@ -66,8 +66,8 @@ const void* SkImage_Generator::onPeekPixels(SkImageInfo* infoPtr, size_t* rowByt
return NULL;
}
SkData* SkImage_Generator::onRefEncoded() const {
return fCache->refEncoded();
SkData* SkImage_Generator::onRefEncoded(GrContext* ctx) const {
return fCache->refEncoded(ctx);
}
bool SkImage_Generator::getROPixels(SkBitmap* bitmap, CachingHint chint) const {

View File

@ -68,7 +68,7 @@ public:
bool onReadPixels(const SkImageInfo&, void*, size_t, int srcX, int srcY, CachingHint) const override;
const void* onPeekPixels(SkImageInfo*, size_t* /*rowBytes*/) const override;
SkData* onRefEncoded() const override;
SkData* onRefEncoded(GrContext*) const override;
bool getROPixels(SkBitmap*, CachingHint) const override;
GrTexture* asTextureRef(GrContext*, const GrTextureParams&) const override;
SkImage* onNewSubset(const SkIRect&) const override;
@ -150,7 +150,7 @@ const void* SkImage_Raster::onPeekPixels(SkImageInfo* infoPtr, size_t* rowBytesP
return fBitmap.getPixels();
}
SkData* SkImage_Raster::onRefEncoded() const {
SkData* SkImage_Raster::onRefEncoded(GrContext*) const {
SkPixelRef* pr = fBitmap.pixelRef();
const SkImageInfo prInfo = pr->info();
const SkImageInfo bmInfo = fBitmap.info();

View File

@ -37,7 +37,7 @@ public:
bool ditherImage);
protected:
SkData* onRefEncodedData() override;
SkData* onRefEncodedData(SK_REFENCODEDDATA_CTXPARAM) override;
bool onGetPixels(const SkImageInfo& info, void* pixels, size_t rowBytes,
SkPMColor ctable[], int* ctableCount) override;
bool onGetYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBytes[3],
@ -126,7 +126,7 @@ DecodingImageGenerator::~DecodingImageGenerator() {
SkSafeUnref(fData);
}
SkData* DecodingImageGenerator::onRefEncodedData() {
SkData* DecodingImageGenerator::onRefEncodedData(SK_REFENCODEDDATA_CTXPARAM) {
// This functionality is used in `gm --serialize`
// Does not encode options.
if (nullptr == fData) {

View File

@ -43,7 +43,7 @@ public:
{}
protected:
SkData* onRefEncodedData() override {
SkData* onRefEncodedData(SK_REFENCODEDDATA_CTXPARAM) override {
return SkRef(fData.get());
}
bool onGetPixels(const SkImageInfo& info, void* pixels, size_t rowBytes,