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:
parent
fec1dea809
commit
e8eed323ef
@ -21,7 +21,6 @@
|
|||||||
#include "SkYUVSizeInfo.h"
|
#include "SkYUVSizeInfo.h"
|
||||||
|
|
||||||
class SkColorTable;
|
class SkColorTable;
|
||||||
class SkData;
|
|
||||||
struct SkIRect;
|
struct SkIRect;
|
||||||
|
|
||||||
class GrTexture;
|
class GrTexture;
|
||||||
@ -168,18 +167,6 @@ public:
|
|||||||
*/
|
*/
|
||||||
void setURI(const SkString& uri) { fURI = uri; }
|
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 {
|
struct LockRequest {
|
||||||
SkISize fSize;
|
SkISize fSize;
|
||||||
SkFilterQuality fQuality;
|
SkFilterQuality fQuality;
|
||||||
@ -294,9 +281,6 @@ protected:
|
|||||||
*/
|
*/
|
||||||
virtual bool onReadPixels(SkBitmap* dst, SkColorType colorType, const SkIRect* subsetOrNull);
|
virtual bool onReadPixels(SkBitmap* dst, SkColorType colorType, const SkIRect* subsetOrNull);
|
||||||
|
|
||||||
// default impl returns NULL.
|
|
||||||
virtual SkData* onRefEncodedData();
|
|
||||||
|
|
||||||
// default impl does nothing.
|
// default impl does nothing.
|
||||||
virtual void onNotifyPixelsChanged();
|
virtual void onNotifyPixelsChanged();
|
||||||
|
|
||||||
|
@ -319,10 +319,6 @@ bool SkPixelRef::onReadPixels(SkBitmap* dst, SkColorType, const SkIRect* subset)
|
|||||||
|
|
||||||
void SkPixelRef::onNotifyPixelsChanged() { }
|
void SkPixelRef::onNotifyPixelsChanged() { }
|
||||||
|
|
||||||
SkData* SkPixelRef::onRefEncodedData() {
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t SkPixelRef::getAllocatedSizeInBytes() const {
|
size_t SkPixelRef::getAllocatedSizeInBytes() const {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -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.
|
// Write a bool to indicate that we did not use an SkBitmapHeap. That feature is deprecated.
|
||||||
this->writeBool(false);
|
this->writeBool(false);
|
||||||
|
|
||||||
SkPixelRef* pixelRef = bitmap.pixelRef();
|
// see if the caller wants to manually encode
|
||||||
if (pixelRef) {
|
SkAutoPixmapUnlock result;
|
||||||
// see if the pixelref already has an encoded version
|
if (fPixelSerializer && bitmap.requestLock(&result)) {
|
||||||
sk_sp<SkData> existingData(pixelRef->refEncodedData());
|
sk_sp<SkData> data(fPixelSerializer->encode(result.pixmap()));
|
||||||
if (existingData) {
|
if (data) {
|
||||||
// Assumes that if the client did not set a serializer, they are
|
// if we have to "encode" the bitmap, then we assume there is no
|
||||||
// happy to get the encoded data.
|
// offset to share, since we are effectively creating a new pixelref
|
||||||
if (!fPixelSerializer || fPixelSerializer->useEncodedData(existingData->data(),
|
write_encoded_bitmap(this, data.get(), SkIPoint::Make(0, 0));
|
||||||
existingData->size())) {
|
return;
|
||||||
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<SkData> 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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -198,27 +198,8 @@ static sk_sp<GrTexture> create_texture_from_yuv(GrContext* ctx, const SkBitmap&
|
|||||||
return provider.refAsTexture(ctx, desc, !bm.isVolatile());
|
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) {
|
GrTexture* GrUploadBitmapToTexture(GrContext* ctx, const SkBitmap& bitmap) {
|
||||||
GrSurfaceDesc desc = GrImageInfoToSurfaceDesc(bitmap.info(), *ctx->caps());
|
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));
|
sk_sp<GrTexture> texture(create_texture_from_yuv(ctx, bitmap, desc));
|
||||||
if (texture) {
|
if (texture) {
|
||||||
@ -342,13 +323,6 @@ GrTexture* GrGenerateMipMapsAndUploadToTexture(GrContext* ctx, const SkBitmap& b
|
|||||||
SkDestinationSurfaceColorMode colorMode)
|
SkDestinationSurfaceColorMode colorMode)
|
||||||
{
|
{
|
||||||
GrSurfaceDesc desc = GrImageInfoToSurfaceDesc(bitmap.info(), *ctx->caps());
|
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));
|
sk_sp<GrTexture> texture(create_texture_from_yuv(ctx, bitmap, desc));
|
||||||
if (texture) {
|
if (texture) {
|
||||||
return texture.release();
|
return texture.release();
|
||||||
|
@ -87,7 +87,6 @@ public:
|
|||||||
bool onPeekPixels(SkPixmap*) const override;
|
bool onPeekPixels(SkPixmap*) const override;
|
||||||
const SkBitmap* onPeekBitmap() const override { return &fBitmap; }
|
const SkBitmap* onPeekBitmap() const override { return &fBitmap; }
|
||||||
|
|
||||||
SkData* onRefEncoded(GrContext*) const override;
|
|
||||||
bool getROPixels(SkBitmap*, SkDestinationSurfaceColorMode, CachingHint) const override;
|
bool getROPixels(SkBitmap*, SkDestinationSurfaceColorMode, CachingHint) const override;
|
||||||
GrTexture* asTextureRef(GrContext*, const GrSamplerParams&,
|
GrTexture* asTextureRef(GrContext*, const GrSamplerParams&,
|
||||||
SkDestinationSurfaceColorMode, sk_sp<SkColorSpace>*) const override;
|
SkDestinationSurfaceColorMode, sk_sp<SkColorSpace>*) const override;
|
||||||
@ -180,18 +179,6 @@ bool SkImage_Raster::onPeekPixels(SkPixmap* pm) const {
|
|||||||
return fBitmap.peekPixels(pm);
|
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 {
|
bool SkImage_Raster::getROPixels(SkBitmap* dst, SkDestinationSurfaceColorMode, CachingHint) const {
|
||||||
*dst = fBitmap;
|
*dst = fBitmap;
|
||||||
return true;
|
return true;
|
||||||
|
@ -24,71 +24,20 @@
|
|||||||
// overview, a KTX file contains all of the appropriate values needed to fully specify a
|
// 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.
|
// 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
|
// This encoder takes a best guess at how to encode the bitmap passed to it.
|
||||||
// there is an installed discardable pixel ref with existing PKM data, then we
|
// The KTX library tries to do its best to encode the appropriate
|
||||||
// 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
|
|
||||||
// data specified by the bitmap based on the config. (i.e. kAlpha8_Config will
|
// 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
|
// be represented as a full resolution 8-bit image dump with the appropriate
|
||||||
// OpenGL defines in the header).
|
// OpenGL defines in the header).
|
||||||
|
|
||||||
class SkKTXImageEncoder : public SkImageEncoder {
|
class SkKTXImageEncoder : public SkImageEncoder {
|
||||||
protected:
|
protected:
|
||||||
bool onEncode(SkWStream* stream, const SkBitmap& bm, int quality) override;
|
bool onEncode(SkWStream* stream, const SkBitmap& bitmap, int) override {
|
||||||
|
return SkKTXFile::WriteBitmapToKTX(stream, bitmap);
|
||||||
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...
|
|
||||||
}
|
|
||||||
|
|
||||||
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);
|
DEFINE_ENCODER_CREATOR(KTXImageEncoder);
|
||||||
/////////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
SkImageEncoder* sk_libktx_efactory(SkImageEncoder::Type t) {
|
SkImageEncoder* sk_libktx_efactory(SkImageEncoder::Type t) {
|
||||||
return (SkEncodedImageFormat::kKTX == (SkEncodedImageFormat)t) ? new SkKTXImageEncoder : nullptr;
|
return (SkEncodedImageFormat::kKTX == (SkEncodedImageFormat)t) ? new SkKTXImageEncoder : nullptr;
|
||||||
|
Loading…
Reference in New Issue
Block a user