remove SkPixelRef::refEncodedData()

BUG=skia:

GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=5001

Change-Id: I15dba4f44c762ab69a23eb8a77adff5f63763e30
Reviewed-on: https://skia-review.googlesource.com/5001
Commit-Queue: Hal Canary <halcanary@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
Reviewed-by: Mike Reed <reed@google.com>
This commit is contained in:
Hal Canary 2016-11-22 11:57:18 -07:00 committed by Skia Commit-Bot
parent fec1dea809
commit e8eed323ef
6 changed files with 14 additions and 139 deletions

View File

@ -21,7 +21,6 @@
#include "SkYUVSizeInfo.h"
class SkColorTable;
class SkData;
struct SkIRect;
class GrTexture;
@ -168,18 +167,6 @@ public:
*/
void setURI(const SkString& uri) { fURI = uri; }
/**
* If the pixelRef has an encoded (i.e. compressed) representation,
* return a ref to its data. If the pixelRef
* is uncompressed or otherwise does not have this form, return NULL.
*
* If non-null is returned, the caller is responsible for calling unref()
* on the data when it is finished.
*/
SkData* refEncodedData() {
return this->onRefEncodedData();
}
struct LockRequest {
SkISize fSize;
SkFilterQuality fQuality;
@ -294,9 +281,6 @@ protected:
*/
virtual bool onReadPixels(SkBitmap* dst, SkColorType colorType, const SkIRect* subsetOrNull);
// default impl returns NULL.
virtual SkData* onRefEncodedData();
// default impl does nothing.
virtual void onNotifyPixelsChanged();

View File

@ -319,10 +319,6 @@ bool SkPixelRef::onReadPixels(SkBitmap* dst, SkColorType, const SkIRect* subset)
void SkPixelRef::onNotifyPixelsChanged() { }
SkData* SkPixelRef::onRefEncodedData() {
return nullptr;
}
size_t SkPixelRef::getAllocatedSizeInBytes() const {
return 0;
}

View File

@ -153,20 +153,6 @@ void SkBinaryWriteBuffer::writeBitmap(const SkBitmap& bitmap) {
// Write a bool to indicate that we did not use an SkBitmapHeap. That feature is deprecated.
this->writeBool(false);
SkPixelRef* pixelRef = bitmap.pixelRef();
if (pixelRef) {
// see if the pixelref already has an encoded version
sk_sp<SkData> existingData(pixelRef->refEncodedData());
if (existingData) {
// Assumes that if the client did not set a serializer, they are
// happy to get the encoded data.
if (!fPixelSerializer || fPixelSerializer->useEncodedData(existingData->data(),
existingData->size())) {
write_encoded_bitmap(this, existingData.get(), bitmap.pixelRefOrigin());
return;
}
}
// see if the caller wants to manually encode
SkAutoPixmapUnlock result;
if (fPixelSerializer && bitmap.requestLock(&result)) {
@ -178,7 +164,6 @@ void SkBinaryWriteBuffer::writeBitmap(const SkBitmap& bitmap) {
return;
}
}
}
this->writeUInt(0); // signal raw pixels
SkBitmap::WriteRawPixels(this, bitmap);

View File

@ -198,27 +198,8 @@ static sk_sp<GrTexture> create_texture_from_yuv(GrContext* ctx, const SkBitmap&
return provider.refAsTexture(ctx, desc, !bm.isVolatile());
}
static GrTexture* load_etc1_texture(GrContext* ctx, const SkBitmap &bm, GrSurfaceDesc desc) {
sk_sp<SkData> data(bm.pixelRef()->refEncodedData());
if (!data) {
return nullptr;
}
const void* startOfTexData;
desc.fConfig = GrIsCompressedTextureDataSupported(ctx, data.get(), bm.width(), bm.height(),
&startOfTexData);
if (kUnknown_GrPixelConfig == desc.fConfig) {
return nullptr;
}
return ctx->textureProvider()->createTexture(desc, SkBudgeted::kYes, startOfTexData, 0);
}
GrTexture* GrUploadBitmapToTexture(GrContext* ctx, const SkBitmap& bitmap) {
GrSurfaceDesc desc = GrImageInfoToSurfaceDesc(bitmap.info(), *ctx->caps());
if (GrTexture *texture = load_etc1_texture(ctx, bitmap, desc)) {
return texture;
}
sk_sp<GrTexture> texture(create_texture_from_yuv(ctx, bitmap, desc));
if (texture) {
@ -342,13 +323,6 @@ GrTexture* GrGenerateMipMapsAndUploadToTexture(GrContext* ctx, const SkBitmap& b
SkDestinationSurfaceColorMode colorMode)
{
GrSurfaceDesc desc = GrImageInfoToSurfaceDesc(bitmap.info(), *ctx->caps());
if (kIndex_8_SkColorType != bitmap.colorType() && !bitmap.readyToDraw()) {
GrTexture* texture = load_etc1_texture(ctx, bitmap, desc);
if (texture) {
return texture;
}
}
sk_sp<GrTexture> texture(create_texture_from_yuv(ctx, bitmap, desc));
if (texture) {
return texture.release();

View File

@ -87,7 +87,6 @@ public:
bool onPeekPixels(SkPixmap*) const override;
const SkBitmap* onPeekBitmap() const override { return &fBitmap; }
SkData* onRefEncoded(GrContext*) const override;
bool getROPixels(SkBitmap*, SkDestinationSurfaceColorMode, CachingHint) const override;
GrTexture* asTextureRef(GrContext*, const GrSamplerParams&,
SkDestinationSurfaceColorMode, sk_sp<SkColorSpace>*) const override;
@ -180,18 +179,6 @@ bool SkImage_Raster::onPeekPixels(SkPixmap* pm) const {
return fBitmap.peekPixels(pm);
}
SkData* SkImage_Raster::onRefEncoded(GrContext*) const {
SkPixelRef* pr = fBitmap.pixelRef();
const SkImageInfo prInfo = pr->info();
const SkImageInfo bmInfo = fBitmap.info();
// we only try if we (the image) cover the entire area of the pixelRef
if (prInfo.width() == bmInfo.width() && prInfo.height() == bmInfo.height()) {
return pr->refEncodedData();
}
return nullptr;
}
bool SkImage_Raster::getROPixels(SkBitmap* dst, SkDestinationSurfaceColorMode, CachingHint) const {
*dst = fBitmap;
return true;

View File

@ -24,71 +24,20 @@
// overview, a KTX file contains all of the appropriate values needed to fully specify a
// texture in an OpenGL application, including the use of compressed data.
//
// This encoder takes a best guess at how to encode the bitmap passed to it. If
// there is an installed discardable pixel ref with existing PKM data, then we
// will repurpose the existing ETC1 data into a KTX file. If the data contains
// KTX data, then we simply return a copy of the same data. For all other files,
// the underlying KTX library tries to do its best to encode the appropriate
// This encoder takes a best guess at how to encode the bitmap passed to it.
// The KTX library tries to do its best to encode the appropriate
// data specified by the bitmap based on the config. (i.e. kAlpha8_Config will
// be represented as a full resolution 8-bit image dump with the appropriate
// OpenGL defines in the header).
class SkKTXImageEncoder : public SkImageEncoder {
protected:
bool onEncode(SkWStream* stream, const SkBitmap& bm, int quality) override;
private:
virtual bool encodePKM(SkWStream* stream, const SkData *data);
typedef SkImageEncoder INHERITED;
};
bool SkKTXImageEncoder::onEncode(SkWStream* stream, const SkBitmap& bitmap, int) {
if (!bitmap.pixelRef()) {
return false;
}
sk_sp<SkData> data(bitmap.pixelRef()->refEncodedData());
// Is this even encoded data?
if (data) {
const uint8_t *bytes = data->bytes();
if (etc1_pkm_is_valid(bytes)) {
return this->encodePKM(stream, data.get());
}
// Is it a KTX file??
if (SkKTXFile::is_ktx(bytes, data->size())) {
return stream->write(bytes, data->size());
}
// If it's neither a KTX nor a PKM, then we need to
// get at the actual pixels, so fall through and decompress...
}
bool onEncode(SkWStream* stream, const SkBitmap& bitmap, int) override {
return SkKTXFile::WriteBitmapToKTX(stream, bitmap);
}
};
bool SkKTXImageEncoder::encodePKM(SkWStream* stream, const SkData *data) {
const uint8_t* bytes = data->bytes();
SkASSERT(etc1_pkm_is_valid(bytes));
etc1_uint32 width = etc1_pkm_get_width(bytes);
etc1_uint32 height = etc1_pkm_get_height(bytes);
// ETC1 Data is stored as compressed 4x4 pixel blocks, so we must make sure
// that our dimensions are valid.
if (width == 0 || (width & 3) != 0 || height == 0 || (height & 3) != 0) {
return false;
}
// Advance pointer to etc1 data.
bytes += ETC_PKM_HEADER_SIZE;
return SkKTXFile::WriteETC1ToKTX(stream, bytes, width, height);
}
/////////////////////////////////////////////////////////////////////////////////////////
DEFINE_ENCODER_CREATOR(KTXImageEncoder);
/////////////////////////////////////////////////////////////////////////////////////////
SkImageEncoder* sk_libktx_efactory(SkImageEncoder::Type t) {
return (SkEncodedImageFormat::kKTX == (SkEncodedImageFormat)t) ? new SkKTXImageEncoder : nullptr;