diff --git a/include/core/SkPixelRef.h b/include/core/SkPixelRef.h index 2677e5f22d..12a72f4e86 100644 --- a/include/core/SkPixelRef.h +++ b/include/core/SkPixelRef.h @@ -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(); diff --git a/src/core/SkPixelRef.cpp b/src/core/SkPixelRef.cpp index cdc318b2a8..18cb4d2cb6 100644 --- a/src/core/SkPixelRef.cpp +++ b/src/core/SkPixelRef.cpp @@ -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; } diff --git a/src/core/SkWriteBuffer.cpp b/src/core/SkWriteBuffer.cpp index 3d12889fa1..79422abcea 100644 --- a/src/core/SkWriteBuffer.cpp +++ b/src/core/SkWriteBuffer.cpp @@ -153,30 +153,15 @@ 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 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)) { - sk_sp data(fPixelSerializer->encode(result.pixmap())); - if (data) { - // if we have to "encode" the bitmap, then we assume there is no - // offset to share, since we are effectively creating a new pixelref - write_encoded_bitmap(this, data.get(), SkIPoint::Make(0, 0)); - return; - } + // see if the caller wants to manually encode + SkAutoPixmapUnlock result; + if (fPixelSerializer && bitmap.requestLock(&result)) { + sk_sp data(fPixelSerializer->encode(result.pixmap())); + if (data) { + // if we have to "encode" the bitmap, then we assume there is no + // offset to share, since we are effectively creating a new pixelref + write_encoded_bitmap(this, data.get(), SkIPoint::Make(0, 0)); + return; } } diff --git a/src/gpu/SkGr.cpp b/src/gpu/SkGr.cpp index 471a39305f..1319102150 100644 --- a/src/gpu/SkGr.cpp +++ b/src/gpu/SkGr.cpp @@ -198,27 +198,8 @@ static sk_sp 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 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 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 texture(create_texture_from_yuv(ctx, bitmap, desc)); if (texture) { return texture.release(); diff --git a/src/image/SkImage_Raster.cpp b/src/image/SkImage_Raster.cpp index 0875d615b0..dcc60c3e65 100644 --- a/src/image/SkImage_Raster.cpp +++ b/src/image/SkImage_Raster.cpp @@ -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*) 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; diff --git a/src/images/SkKTXImageEncoder.cpp b/src/images/SkKTXImageEncoder.cpp index 7a0ccb3a85..6717bea5f7 100644 --- a/src/images/SkKTXImageEncoder.cpp +++ b/src/images/SkKTXImageEncoder.cpp @@ -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 onEncode(SkWStream* stream, const SkBitmap& bitmap, int) override { + return SkKTXFile::WriteBitmapToKTX(stream, bitmap); + } }; -bool SkKTXImageEncoder::onEncode(SkWStream* stream, const SkBitmap& bitmap, int) { - if (!bitmap.pixelRef()) { - return false; - } - sk_sp 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... - } - - 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;