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:
parent
20ccd40de9
commit
05dd251e5e
@ -22,6 +22,12 @@ class SkMatrix;
|
|||||||
class SkPaint;
|
class SkPaint;
|
||||||
class SkPicture;
|
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
|
* Takes ownership of SkImageGenerator. If this method fails for
|
||||||
* whatever reason, it will return false and immediatetely delete
|
* whatever reason, it will return false and immediatetely delete
|
||||||
@ -64,12 +70,20 @@ public:
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a ref to the encoded (i.e. compressed) representation,
|
* 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
|
* If non-NULL is returned, the caller is responsible for calling
|
||||||
* unref() on the data when it is finished.
|
* 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.
|
* Return the ImageInfo associated with this generator.
|
||||||
@ -230,7 +244,7 @@ public:
|
|||||||
protected:
|
protected:
|
||||||
SkImageGenerator(const SkImageInfo& info);
|
SkImageGenerator(const SkImageInfo& info);
|
||||||
|
|
||||||
virtual SkData* onRefEncodedData();
|
virtual SkData* onRefEncodedData(SK_REFENCODEDDATA_CTXPARAM);
|
||||||
|
|
||||||
virtual bool onGetPixels(const SkImageInfo& info, void* pixels, size_t rowBytes,
|
virtual bool onGetPixels(const SkImageInfo& info, void* pixels, size_t rowBytes,
|
||||||
SkPMColor ctable[], int* ctableCount);
|
SkPMColor ctable[], int* ctableCount);
|
||||||
|
@ -69,9 +69,9 @@ SkImageCacherator::SkImageCacherator(SkImageGenerator* gen, const SkImageInfo& i
|
|||||||
, fUniqueID(uniqueID)
|
, fUniqueID(uniqueID)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
SkData* SkImageCacherator::refEncoded() {
|
SkData* SkImageCacherator::refEncoded(GrContext* ctx) {
|
||||||
ScopedGenerator generator(this);
|
ScopedGenerator generator(this);
|
||||||
return generator->refEncodedData();
|
return generator->refEncodedData(ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool check_output_bitmap(const SkBitmap& bitmap, uint32_t expectedID) {
|
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);
|
const GrSurfaceDesc desc = GrImageInfoToSurfaceDesc(fInfo);
|
||||||
|
|
||||||
// 3. Ask the generator to return a compressed form that the GPU might support
|
// 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) {
|
if (data) {
|
||||||
GrTexture* tex = load_compressed_into_texture(ctx, data, desc);
|
GrTexture* tex = load_compressed_into_texture(ctx, data, desc);
|
||||||
if (tex) {
|
if (tex) {
|
||||||
|
@ -54,8 +54,11 @@ public:
|
|||||||
/**
|
/**
|
||||||
* If the underlying src naturally is represented by an encoded blob (in SkData), this returns
|
* 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.
|
* 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.
|
// Only return true if the generate has already been cached.
|
||||||
bool lockAsBitmapOnlyIfAlreadyCached(SkBitmap*);
|
bool lockAsBitmapOnlyIfAlreadyCached(SkBitmap*);
|
||||||
|
@ -137,7 +137,7 @@ bool SkImageGenerator::generateScaledPixels(const SkISize& scaledSize,
|
|||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
SkData* SkImageGenerator::onRefEncodedData() {
|
SkData* SkImageGenerator::onRefEncodedData(SK_REFENCODEDDATA_CTXPARAM) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -202,7 +202,8 @@ SkData* SkImage::encode(SkPixelSerializer* serializer) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
SkData* SkImage::refEncoded() 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) {
|
SkImage* SkImage::NewFromEncoded(SkData* encoded, const SkIRect* subset) {
|
||||||
|
@ -51,7 +51,8 @@ public:
|
|||||||
|
|
||||||
virtual SkImage* onNewSubset(const SkIRect&) const = 0;
|
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;
|
virtual bool onAsLegacyBitmap(SkBitmap*, LegacyBitmapMode) const;
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ public:
|
|||||||
bool onReadPixels(const SkImageInfo&, void*, size_t, int srcX, int srcY, CachingHint) const override;
|
bool onReadPixels(const SkImageInfo&, void*, size_t, int srcX, int srcY, CachingHint) const override;
|
||||||
const void* onPeekPixels(SkImageInfo*, size_t* /*rowBytes*/) const override;
|
const void* onPeekPixels(SkImageInfo*, size_t* /*rowBytes*/) const override;
|
||||||
SkImageCacherator* peekCacherator() const override { return fCache; }
|
SkImageCacherator* peekCacherator() const override { return fCache; }
|
||||||
SkData* onRefEncoded() const override;
|
SkData* onRefEncoded(GrContext*) const override;
|
||||||
bool isOpaque() const override { return fCache->info().isOpaque(); }
|
bool isOpaque() const override { return fCache->info().isOpaque(); }
|
||||||
SkImage* onNewSubset(const SkIRect&) const override;
|
SkImage* onNewSubset(const SkIRect&) const override;
|
||||||
bool getROPixels(SkBitmap*, CachingHint) const override;
|
bool getROPixels(SkBitmap*, CachingHint) const override;
|
||||||
@ -66,8 +66,8 @@ const void* SkImage_Generator::onPeekPixels(SkImageInfo* infoPtr, size_t* rowByt
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
SkData* SkImage_Generator::onRefEncoded() const {
|
SkData* SkImage_Generator::onRefEncoded(GrContext* ctx) const {
|
||||||
return fCache->refEncoded();
|
return fCache->refEncoded(ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SkImage_Generator::getROPixels(SkBitmap* bitmap, CachingHint chint) const {
|
bool SkImage_Generator::getROPixels(SkBitmap* bitmap, CachingHint chint) const {
|
||||||
|
@ -68,7 +68,7 @@ public:
|
|||||||
|
|
||||||
bool onReadPixels(const SkImageInfo&, void*, size_t, int srcX, int srcY, CachingHint) const override;
|
bool onReadPixels(const SkImageInfo&, void*, size_t, int srcX, int srcY, CachingHint) const override;
|
||||||
const void* onPeekPixels(SkImageInfo*, size_t* /*rowBytes*/) 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;
|
bool getROPixels(SkBitmap*, CachingHint) const override;
|
||||||
GrTexture* asTextureRef(GrContext*, const GrTextureParams&) const override;
|
GrTexture* asTextureRef(GrContext*, const GrTextureParams&) const override;
|
||||||
SkImage* onNewSubset(const SkIRect&) 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();
|
return fBitmap.getPixels();
|
||||||
}
|
}
|
||||||
|
|
||||||
SkData* SkImage_Raster::onRefEncoded() const {
|
SkData* SkImage_Raster::onRefEncoded(GrContext*) const {
|
||||||
SkPixelRef* pr = fBitmap.pixelRef();
|
SkPixelRef* pr = fBitmap.pixelRef();
|
||||||
const SkImageInfo prInfo = pr->info();
|
const SkImageInfo prInfo = pr->info();
|
||||||
const SkImageInfo bmInfo = fBitmap.info();
|
const SkImageInfo bmInfo = fBitmap.info();
|
||||||
|
@ -37,7 +37,7 @@ public:
|
|||||||
bool ditherImage);
|
bool ditherImage);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
SkData* onRefEncodedData() override;
|
SkData* onRefEncodedData(SK_REFENCODEDDATA_CTXPARAM) override;
|
||||||
bool onGetPixels(const SkImageInfo& info, void* pixels, size_t rowBytes,
|
bool onGetPixels(const SkImageInfo& info, void* pixels, size_t rowBytes,
|
||||||
SkPMColor ctable[], int* ctableCount) override;
|
SkPMColor ctable[], int* ctableCount) override;
|
||||||
bool onGetYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBytes[3],
|
bool onGetYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBytes[3],
|
||||||
@ -126,7 +126,7 @@ DecodingImageGenerator::~DecodingImageGenerator() {
|
|||||||
SkSafeUnref(fData);
|
SkSafeUnref(fData);
|
||||||
}
|
}
|
||||||
|
|
||||||
SkData* DecodingImageGenerator::onRefEncodedData() {
|
SkData* DecodingImageGenerator::onRefEncodedData(SK_REFENCODEDDATA_CTXPARAM) {
|
||||||
// This functionality is used in `gm --serialize`
|
// This functionality is used in `gm --serialize`
|
||||||
// Does not encode options.
|
// Does not encode options.
|
||||||
if (nullptr == fData) {
|
if (nullptr == fData) {
|
||||||
|
@ -43,7 +43,7 @@ public:
|
|||||||
{}
|
{}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
SkData* onRefEncodedData() override {
|
SkData* onRefEncodedData(SK_REFENCODEDDATA_CTXPARAM) override {
|
||||||
return SkRef(fData.get());
|
return SkRef(fData.get());
|
||||||
}
|
}
|
||||||
bool onGetPixels(const SkImageInfo& info, void* pixels, size_t rowBytes,
|
bool onGetPixels(const SkImageInfo& info, void* pixels, size_t rowBytes,
|
||||||
|
Loading…
Reference in New Issue
Block a user