if (SkCommandLineFlags::ShouldSkip(FLAGS_match, path.c_str())) {
continue;
}
- SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(path.c_str()));
- SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded));
+ sk_sp<SkData> encoded(SkData::MakeFromFileName(path.c_str()));
+ SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded.get()));
if (!codec) {
// Nothing to time.
SkDebugf("Cannot find codec for %s\n", path.c_str());
case SkCodec::kSuccess:
case SkCodec::kIncompleteInput:
return new CodecBench(SkOSPath::Basename(path.c_str()),
- encoded, colorType, alphaType);
+ encoded.get(), colorType, alphaType);
case SkCodec::kInvalidConversion:
// This is okay. Not all conversions are valid.
break;
if (SkCommandLineFlags::ShouldSkip(FLAGS_match, path.c_str())) {
continue;
}
- SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(path.c_str()));
- SkAutoTDelete<SkAndroidCodec> codec(SkAndroidCodec::NewFromData(encoded));
+ sk_sp<SkData> encoded(SkData::MakeFromFileName(path.c_str()));
+ SkAutoTDelete<SkAndroidCodec> codec(SkAndroidCodec::NewFromData(encoded.get()));
if (!codec) {
// Nothing to time.
SkDebugf("Cannot find codec for %s\n", path.c_str());
break;
}
- return new AndroidCodecBench(SkOSPath::Basename(path.c_str()), encoded, sampleSize);
+ return new AndroidCodecBench(SkOSPath::Basename(path.c_str()),
+ encoded.get(), sampleSize);
}
fCurrentSampleSize = 0;
}
while (fCurrentSampleSize < (int) SK_ARRAY_COUNT(brdSampleSizes)) {
while (fCurrentSubsetType <= kLastSingle_SubsetType) {
- SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(path.c_str()));
+ sk_sp<SkData> encoded(SkData::MakeFromFileName(path.c_str()));
const SkColorType colorType = fColorTypes[fCurrentColorType];
uint32_t sampleSize = brdSampleSizes[fCurrentSampleSize];
int currentSubsetType = fCurrentSubsetType++;
static void gather_uninteresting_hashes() {
if (!FLAGS_uninterestingHashesFile.isEmpty()) {
- SkAutoTUnref<SkData> data(SkData::NewFromFileName(FLAGS_uninterestingHashesFile[0]));
+ sk_sp<SkData> data(SkData::MakeFromFileName(FLAGS_uninterestingHashesFile[0]));
if (!data) {
info("WARNING: unable to read uninteresting hashes from %s\n",
FLAGS_uninterestingHashesFile[0]);
}
static void push_codec_srcs(Path path) {
- SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(path.c_str()));
+ sk_sp<SkData> encoded(SkData::MakeFromFileName(path.c_str()));
if (!encoded) {
info("Couldn't read %s.", path.c_str());
return;
}
- SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded));
+ SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded.get()));
if (nullptr == codec.get()) {
info("Couldn't create codec for %s.", path.c_str());
return;
}
bool JsonWriter::ReadJson(const char* path, void(*callback)(BitmapResult)) {
- SkAutoTUnref<SkData> json(SkData::NewFromFileName(path));
+ sk_sp<SkData> json(SkData::MakeFromFileName(path));
if (!json) {
return false;
}
}
static SkBitmapRegionDecoder* create_brd(Path path) {
- SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(path.c_str()));
+ sk_sp<SkData> encoded(SkData::MakeFromFileName(path.c_str()));
if (!encoded) {
return NULL;
}
- return SkBitmapRegionDecoder::Create(encoded, SkBitmapRegionDecoder::kAndroidCodec_Strategy);
+ return SkBitmapRegionDecoder::Create(encoded.get(),
+ SkBitmapRegionDecoder::kAndroidCodec_Strategy);
}
Error BRDSrc::draw(SkCanvas* canvas) const {
}
Error CodecSrc::draw(SkCanvas* canvas) const {
- SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str()));
+ sk_sp<SkData> encoded(SkData::MakeFromFileName(fPath.c_str()));
if (!encoded) {
return SkStringPrintf("Couldn't read %s.", fPath.c_str());
}
- SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded));
+ SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded.get()));
if (nullptr == codec.get()) {
return SkStringPrintf("Couldn't create codec for %s.", fPath.c_str());
}
}
SkISize CodecSrc::size() const {
- SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str()));
- SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded));
+ sk_sp<SkData> encoded(SkData::MakeFromFileName(fPath.c_str()));
+ SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded.get()));
if (nullptr == codec) {
return SkISize::Make(0, 0);
}
}
Error AndroidCodecSrc::draw(SkCanvas* canvas) const {
- SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str()));
+ sk_sp<SkData> encoded(SkData::MakeFromFileName(fPath.c_str()));
if (!encoded) {
return SkStringPrintf("Couldn't read %s.", fPath.c_str());
}
- SkAutoTDelete<SkAndroidCodec> codec(SkAndroidCodec::NewFromData(encoded));
+ SkAutoTDelete<SkAndroidCodec> codec(SkAndroidCodec::NewFromData(encoded.get()));
if (nullptr == codec.get()) {
return SkStringPrintf("Couldn't create android codec for %s.", fPath.c_str());
}
}
SkISize AndroidCodecSrc::size() const {
- SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str()));
- SkAutoTDelete<SkAndroidCodec> codec(SkAndroidCodec::NewFromData(encoded));
+ sk_sp<SkData> encoded(SkData::MakeFromFileName(fPath.c_str()));
+ SkAutoTDelete<SkAndroidCodec> codec(SkAndroidCodec::NewFromData(encoded.get()));
if (nullptr == codec) {
return SkISize::Make(0, 0);
}
return Error::Nonfatal("Uninteresting to test image generator to 565.");
}
- SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str()));
+ sk_sp<SkData> encoded(SkData::MakeFromFileName(fPath.c_str()));
if (!encoded) {
return SkStringPrintf("Couldn't read %s.", fPath.c_str());
}
SkAutoTDelete<SkImageGenerator> gen(nullptr);
switch (fMode) {
case kCodec_Mode:
- gen.reset(SkCodecImageGenerator::NewFromEncodedCodec(encoded));
+ gen.reset(SkCodecImageGenerator::NewFromEncodedCodec(encoded.get()));
if (!gen) {
return "Could not create codec image generator.";
}
break;
case kPlatform_Mode: {
#if defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS)
- gen.reset(SkImageGeneratorCG::NewFromEncodedCG(encoded));
+ gen.reset(SkImageGeneratorCG::NewFromEncodedCG(encoded.get()));
#elif defined(SK_BUILD_FOR_WIN)
- gen.reset(SkImageGeneratorWIC::NewFromEncodedWIC(encoded));
+ gen.reset(SkImageGeneratorWIC::NewFromEncodedWIC(encoded.get()));
#endif
if (!gen) {
}
SkISize ImageGenSrc::size() const {
- SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str()));
- SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded));
+ sk_sp<SkData> encoded(SkData::MakeFromFileName(fPath.c_str()));
+ SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded.get()));
if (nullptr == codec) {
return SkISize::Make(0, 0);
}
return Error::Nonfatal("F16 does not draw in legacy mode.");
}
- SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str()));
+ sk_sp<SkData> encoded(SkData::MakeFromFileName(fPath.c_str()));
if (!encoded) {
return SkStringPrintf("Couldn't read %s.", fPath.c_str());
}
- SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded));
+ SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded.get()));
if (nullptr == codec.get()) {
return SkStringPrintf("Couldn't create codec for %s.", fPath.c_str());
}
}
SkISize ColorCodecSrc::size() const {
- SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str()));
- SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded));
+ sk_sp<SkData> encoded(SkData::MakeFromFileName(fPath.c_str()));
+ SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded.get()));
if (nullptr == codec) {
return SkISize::Make(0, 0);
}
float times[32];
int currentTime;
- SkAutoTUnref<SkData> imageData(SkData::NewFromFileName("ship.png"));
- atlas.reset(SkImage::NewFromEncoded(imageData));
+ sk_sp<SkData> imageData(SkData::MakeFromFileName("ship.png"));
+ atlas.reset(SkImage::NewFromEncoded(imageData.get()));
if (!atlas) {
SkDebugf("\nCould not decode file ship.png\n");
" canvas.inval(); \n"
"} \n";
- SkAutoTUnref<SkData> data;
+ sk_sp<SkData> data;
if (FLAGS_infile.count()) {
- data.reset(SkData::NewFromFileName(FLAGS_infile[0]));
+ data = SkData::MakeFromFileName(FLAGS_infile[0]);
script = static_cast<const char*>(data->data());
}
if (NULL == script) {
static void client(const char* skpPath, const char* dataEndpoint) {
// Read the .skp.
- SkAutoTUnref<const SkData> skp(SkData::NewFromFileName(skpPath));
+ sk_sp<SkData> skp(SkData::MakeFromFileName(skpPath));
if (!skp) {
SkDebugf("Couldn't read %s\n", skpPath);
exit(1);
SkCommandLineFlags::Parse(argc, argv);
const char* path = FLAGS_bytes.isEmpty() ? argv[0] : FLAGS_bytes[0];
- SkAutoTUnref<SkData> bytes(SkData::NewFromFileName(path));
+ sk_sp<SkData> bytes(SkData::MakeFromFileName(path));
if (!bytes) {
SkDebugf("Could not read %s\n", path);
return 2;
}
- uint8_t option = calculate_option(bytes);
+ uint8_t option = calculate_option(bytes.get());
if (!FLAGS_type.isEmpty()) {
switch (FLAGS_type[0][0]) {
- case 'a': return fuzz_api(bytes);
+ case 'a': return fuzz_api(bytes.get());
- case 'c': return fuzz_color_deserialize(bytes);
+ case 'c': return fuzz_color_deserialize(bytes.get());
case 'i':
if (FLAGS_type[0][1] == 'c') { //icc
- return fuzz_icc(bytes);
+ return fuzz_icc(bytes.get());
}
// We only allow one degree of freedom to avoid a search space explosion for afl-fuzz.
if (FLAGS_type[0][6] == 's') { // image_scale
- return fuzz_img(bytes, option, 0);
+ return fuzz_img(bytes.get(), option, 0);
}
// image_mode
- return fuzz_img(bytes, 0, option);
- case 's': return fuzz_skp(bytes);
+ return fuzz_img(bytes.get(), 0, option);
+ case 's': return fuzz_skp(bytes.get());
}
}
return printUsage(argv[0]);
SkRect bounds;
(void)paint.measureText(text, byteLength, &bounds);
bounds.offset(x, y);
- SkAutoTUnref<SkData> urlData(SkData::NewWithCString(url));
- SkAnnotateRectWithURL(canvas, bounds, urlData);
+ sk_sp<SkData> urlData(SkData::MakeWithCString(url));
+ SkAnnotateRectWithURL(canvas, bounds, urlData.get());
SkPaint shade;
shade.setColor(0x80346180);
canvas->drawRect(bounds, shade);
void onOnceBeforeDraw() override {
// Copyright-free file from http://openclipart.org/detail/29213/paper-plane-by-ddoo
SkString pngFilename = GetResourcePath("plane.png");
- SkAutoDataUnref data(SkData::NewFromFileName(pngFilename.c_str()));
- if (data.get()) {
+ sk_sp<SkData> data(SkData::MakeFromFileName(pngFilename.c_str()));
+ if (data) {
// Create a cache which will boot the pixels out anytime the
// bitmap is unlocked.
SkAutoTUnref<SkDiscardableMemoryPool> pool(
SkDiscardableMemoryPool::Create(1));
SkAssertResult(SkDEPRECATED_InstallDiscardablePixelRef(
- SkImageGenerator::NewFromEncoded(data),
- nullptr, &fBitmap, pool));
+ SkImageGenerator::NewFromEncoded(data.get()),
+ nullptr, &fBitmap, pool));
}
}
}
virtual void onDraw(SkCanvas* canvas) {
- SkAutoTUnref<SkData> name(SkData::NewWithCString("target-a"));
+ sk_sp<SkData> name(SkData::MakeWithCString("target-a"));
canvas->save();
canvas->translate(SkIntToScalar(100), SkIntToScalar(100));
'SK_SUPPORT_LEGACY_XFERMODE_PTR',
'SK_SUPPORT_LEGACY_TYPEFACE_PTR',
'SK_IGNORE_GPU_DITHER',
+ 'SK_SUPPORT_LEGACY_DATA_FACTORIES',
],
},
}
class SkStream;
-#ifndef SK_SUPPORT_LEGACY_DATA_FACTORIES
-#define SK_SUPPORT_LEGACY_DATA_FACTORIES
-#endif
-
/**
* SkData holds an immutable data buffer. Not only is the data immutable,
* but the actual ptr that is returned (by data() or bytes()) is guaranteed
* effectively returning 0 == memcmp(...)
*/
bool equals(const SkData* other) const;
+#ifdef SK_SUPPORT_LEGACY_DATA_FACTORIES
bool equals(sk_sp<const SkData>& other) const { return this->equals(other.get()); }
+#endif
/**
* Function that, if provided, will be called when the SkData goes out
GrUniqueKey& operator=(const GrUniqueKey& that) {
this->INHERITED::operator=(that);
- this->setCustomData(that.getCustomData());
+ this->setCustomData(sk_ref_sp(that.getCustomData()));
return *this;
}
}
bool operator!=(const GrUniqueKey& that) const { return !(*this == that); }
- void setCustomData(const SkData* data) {
- SkSafeRef(data);
- fData.reset(data);
+ void setCustomData(sk_sp<SkData> data) {
+ fData = std::move(data);
}
- const SkData* getCustomData() const {
+ SkData* getCustomData() const {
return fData.get();
}
};
private:
- SkAutoTUnref<const SkData> fData;
+ sk_sp<SkData> fData;
};
/**
"SK_SUPPORT_LEGACY_PICTURE_PTR",
"SK_SUPPORT_LEGACY_TYPEFACE_PTR",
"SK_SUPPORT_LEGACY_XFERMODE_PTR",
+ "SK_SUPPORT_LEGACY_DATA_FACTORIES",
]
################################################################################
inline bool decode_file(const char* filename, SkBitmap* bitmap,
SkColorType colorType = kN32_SkColorType, bool requireUnpremul = false) {
SkASSERT(kIndex_8_SkColorType != colorType);
- SkAutoTUnref<SkData> data(SkData::NewFromFileName(filename));
- SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(data));
+ sk_sp<SkData> data(SkData::MakeFromFileName(filename));
+ SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(data.get()));
if (!codec) {
return false;
}
fLua = new SkLua;
SkString str = GetResourcePath(LUA_FILENAME);
- SkData* data = SkData::NewFromFileName(str.c_str());
+ sk_sp<SkData> data(SkData::MakeFromFileName(str.c_str()));
if (data) {
fLua->runCode(data->data(), data->size());
- data->unref();
this->setImageFilename(fLua->get());
} else {
fLua->runCode(gMissingCode);
bytesRead = offset;
// Create a new stream for the embedded codec
- SkAutoTUnref<SkData> data(
- SkData::NewFromStream(inputStream.get(), size));
+ sk_sp<SkData> data(SkData::MakeFromStream(inputStream.get(), size));
if (nullptr == data.get()) {
SkCodecPrintf("Warning: could not create embedded stream.\n");
break;
}
- SkAutoTDelete<SkMemoryStream> embeddedStream(new SkMemoryStream(data.get()));
+ SkAutoTDelete<SkMemoryStream> embeddedStream(new SkMemoryStream(data));
bytesRead += size;
// Check if the embedded codec is bmp or png and create the codec
}
SkMemoryStream* transferBuffer(size_t offset, size_t size) override {
- SkAutoTUnref<SkData> data(SkData::NewUninitialized(size));
+ sk_sp<SkData> data(SkData::MakeUninitialized(size));
if (offset > fStreamBuffer.bytesWritten()) {
// If the offset is not buffered, read from fStream directly and skip the buffering.
const size_t skipLength = offset - fStreamBuffer.bytesWritten();
}
const size_t bytesRead = fStream->read(data->writable_data(), size);
if (bytesRead < size) {
- data.reset(SkData::NewSubset(data.get(), 0, bytesRead));
+ data = SkData::MakeSubset(data.get(), 0, bytesRead);
}
} else {
const size_t alreadyBuffered = SkTMin(fStreamBuffer.bytesWritten() - offset, size);
if (!safe_add_to_size_t(alreadyBuffered, bytesRead, &newSize)) {
return nullptr;
}
- data.reset(SkData::NewSubset(data.get(), 0, newSize));
+ data = SkData::MakeSubset(data.get(), 0, newSize);
}
}
}
}
if (fStream->getMemoryBase()) { // directly copy if getMemoryBase() is available.
- SkAutoTUnref<SkData> data(SkData::NewWithCopy(
+ sk_sp<SkData> data(SkData::MakeWithCopy(
static_cast<const uint8_t*>(fStream->getMemoryBase()) + offset, bytesToRead));
fStream.reset();
return new SkMemoryStream(data);
} else {
- SkAutoTUnref<SkData> data(SkData::NewUninitialized(bytesToRead));
+ sk_sp<SkData> data(SkData::MakeUninitialized(bytesToRead));
if (!fStream->seek(offset)) {
return nullptr;
}
const size_t bytesRead = fStream->read(data->writable_data(), bytesToRead);
if (bytesRead < bytesToRead) {
- data.reset(SkData::NewSubset(data.get(), 0, bytesRead));
+ data = SkData::MakeSubset(data.get(), 0, bytesRead);
}
return new SkMemoryStream(data);
}
}
bool SkWbmpCodec::IsWbmp(const void* buffer, size_t bytesRead) {
- SkAutoTUnref<SkData> data(SkData::NewWithoutCopy(buffer, bytesRead));
- SkMemoryStream stream(data);
+ SkMemoryStream stream(buffer, bytesRead, false);
return read_header(&stream, nullptr);
}
SkPixelRef* pixelRef = bitmap.pixelRef();
if (pixelRef) {
// see if the pixelref already has an encoded version
- SkAutoDataUnref existingData(pixelRef->refEncodedData());
- if (existingData.get() != nullptr) {
+ 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, bitmap.pixelRefOrigin());
+ write_encoded_bitmap(this, existingData.get(), bitmap.pixelRefOrigin());
return;
}
}
// see if the caller wants to manually encode
SkAutoPixmapUnlock result;
if (fPixelSerializer && bitmap.requestLock(&result)) {
- SkAutoDataUnref data(fPixelSerializer->encode(result.pixmap()));
- if (data.get() != nullptr) {
+ 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, SkIPoint::Make(0, 0));
+ write_encoded_bitmap(this, data.get(), SkIPoint::Make(0, 0));
return;
}
}
TessInfo info;
info.fTolerance = isLinear ? 0 : tol;
info.fCount = count;
- SkAutoTUnref<SkData> data(SkData::NewWithCopy(&info, sizeof(info)));
- key.setCustomData(data.get());
+ key.setCustomData(SkData::MakeWithCopy(&info, sizeof(info)));
rp->assignUniqueKeyToResource(key, allocator.vertexBuffer());
}
}
// Here we actually make a copy of the caller's pixel data
- sk_sp<SkData> data(SkData::NewWithCopy(pmap.addr(), size));
+ sk_sp<SkData> data(SkData::MakeWithCopy(pmap.addr(), size));
return sk_make_sp<SkImage_Raster>(pmap.info(), std::move(data), pmap.rowBytes(), pmap.ctable());
}
return nullptr;
}
- sk_sp<SkData> data(SkData::NewWithProc(pmap.addr(), size, proc, ctx));
+ sk_sp<SkData> data(SkData::MakeWithProc(pmap.addr(), size, proc, ctx));
return sk_make_sp<SkImage_Raster>(pmap.info(), std::move(data), pmap.rowBytes(), pmap.ctable());
}
if (!bitmap.pixelRef()) {
return false;
}
- SkAutoDataUnref data(bitmap.pixelRef()->refEncodedData());
+ 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);
+ return this->encodePKM(stream, data.get());
}
// Is it a KTX file??
return -1;
}
-static SkData* handle_type1_stream(SkStream* srcStream, size_t* headerLen,
- size_t* dataLen, size_t* trailerLen) {
+static sk_sp<SkData> handle_type1_stream(SkStream* srcStream, size_t* headerLen,
+ size_t* dataLen, size_t* trailerLen) {
// srcStream may be backed by a file or a unseekable fd, so we may not be
// able to use skip(), rewind(), or getMemoryBase(). read()ing through
// the input only once is doable, but very ugly. Furthermore, it'd be nice
// Make as few copies as possible given these constraints.
SkDynamicMemoryWStream dynamicStream;
std::unique_ptr<SkMemoryStream> staticStream;
- SkData* data = nullptr;
+ sk_sp<SkData> data;
const uint8_t* src;
size_t srcLen;
if ((srcLen = srcStream->getLength()) > 0) {
}
amount = 0;
dynamicStream.write(&amount, 1); // nullptr terminator.
- data = dynamicStream.copyToData();
+ data.reset(dynamicStream.copyToData());
src = data->bytes();
srcLen = data->size() - 1;
}
- // this handles releasing the data we may have gotten from dynamicStream.
- // if data is null, it is a no-op
- SkAutoDataUnref aud(data);
-
if (parsePFB(src, srcLen, headerLen, dataLen, trailerLen)) {
static const int kPFBSectionHeaderLength = 6;
const size_t length = *headerLen + *dataLen + *trailerLen;
SkASSERT(length > 0);
SkASSERT(length + (2 * kPFBSectionHeaderLength) <= srcLen);
- SkData* data = SkData::NewUninitialized(length);
+ sk_sp<SkData> data(SkData::MakeUninitialized(length));
const uint8_t* const srcHeader = src + kPFBSectionHeaderLength;
// There is a six-byte section header before header and data
uint8_t* const resultTrailer = &(buffer[SkToInt(*headerLen + outputOffset)]);
memcpy(resultTrailer, src + *headerLen + hexDataLen, *trailerLen);
- return SkData::NewFromMalloc(buffer.release(), length);
+ return SkData::MakeFromMalloc(buffer.release(), length);
}
return nullptr;
}
if (!rawFontData || 0 == rawFontData->getLength()) {
return false;
}
- sk_sp<SkData> fontData(handle_type1_stream(rawFontData.get(), &header,
- &data, &trailer));
+ sk_sp<SkData> fontData(handle_type1_stream(rawFontData.get(), &header, &data, &trailer));
if (fontData.get() == nullptr) {
return false;
}
SkStreamAsset* createStream() const {
if (fFile) {
- SkData* data = SkData::NewFromFILE(fFile);
- return data ? new SkMemoryStream(data) : nullptr;
+ sk_sp<SkData> data(SkData::MakeFromFILE(fFile));
+ return data ? new SkMemoryStream(std::move(data)) : nullptr;
}
return SkStream::NewFromFile(fPathName.c_str());
}
return false;
}
-SkData* CompressBitmapToFormat(const SkPixmap& pixmap, Format format) {
+sk_sp<SkData> CompressBitmapToFormat(const SkPixmap& pixmap, Format format) {
int compressedDataSize = GetCompressedDataSize(format, pixmap.width(), pixmap.height());
if (compressedDataSize < 0) {
return nullptr;
}
const uint8_t* src = reinterpret_cast<const uint8_t*>(pixmap.addr());
- SkData* dst = SkData::NewUninitialized(compressedDataSize);
+ sk_sp<SkData> dst(SkData::MakeUninitialized(compressedDataSize));
if (!CompressBufferToFormat((uint8_t*)dst->writable_data(), src, pixmap.colorType(),
pixmap.width(), pixmap.height(), pixmap.rowBytes(), format)) {
- dst->unref();
- dst = nullptr;
+ return nullptr;
}
return dst;
}
// Returns an SkData holding a blob of compressed data that corresponds
// to the pixmap. If the pixmap colorType cannot be compressed using the
- // associated format, then we return nullptr. The caller is responsible for
- // calling unref() on the returned data.
- SkData* CompressBitmapToFormat(const SkPixmap&, Format format);
+ // associated format, then we return nullptr.
+ sk_sp<SkData> CompressBitmapToFormat(const SkPixmap&, Format format);
// Compresses the given src data into dst. The src data is assumed to be
// large enough to hold width*height pixels. The dst data is expected to
SkCanvas canvas(bm);
SkRect r = SkRect::MakeWH(SkIntToScalar(10), SkIntToScalar(10));
- SkAutoDataUnref data(SkData::NewWithCString("http://www.gooogle.com"));
+ sk_sp<SkData> data(SkData::MakeWithCString("http://www.gooogle.com"));
REPORTER_ASSERT(reporter, 0 == *bm.getAddr32(0, 0));
SkAnnotateRectWithURL(&canvas, r, data.get());
SkRect r = SkRect::MakeXYWH(SkIntToScalar(72), SkIntToScalar(72),
SkIntToScalar(288), SkIntToScalar(72));
- SkAutoDataUnref data(SkData::NewWithCString("http://www.gooogle.com"));
+ sk_sp<SkData> data(SkData::MakeWithCString("http://www.gooogle.com"));
SkAnnotateRectWithURL(canvas, r, data.get());
REPORTER_ASSERT(reporter, doc->close());
- SkAutoDataUnref out(outStream.copyToData());
+ sk_sp<SkData> out(outStream.copyToData());
const char* rawOutput = (const char*)out->data();
REPORTER_ASSERT(reporter, ContainsString(rawOutput, out->size(), "/Annots "));
REPORTER_ASSERT(reporter, canvas);
SkPoint p = SkPoint::Make(SkIntToScalar(72), SkIntToScalar(72));
- SkAutoDataUnref data(SkData::NewWithCString("example"));
+ sk_sp<SkData> data(SkData::MakeWithCString("example"));
SkAnnotateNamedDestination(canvas, p, data.get());
REPORTER_ASSERT(reporter, doc->close());
- SkAutoDataUnref out(outStream.copyToData());
+ sk_sp<SkData> out(outStream.copyToData());
const char* rawOutput = (const char*)out->data();
REPORTER_ASSERT(reporter,
};
for (size_t i = 0; i < SK_ARRAY_COUNT(types); i++) {
SkImageEncoder::Type type = types[i];
- SkAutoDataUnref encoded(create_data_from_bitmap(original, type));
+ sk_sp<SkData> encoded(create_data_from_bitmap(original, type));
REPORTER_ASSERT(reporter, encoded.get() != nullptr);
if (nullptr == encoded.get()) {
continue;
#include "SkData.h"
inline bool decode_memory(const void* mem, size_t size, SkBitmap* bm) {
- SkAutoTUnref<SkData> data(SkData::NewWithoutCopy(mem, size));
+ sk_sp<SkData> data(SkData::MakeWithoutCopy(mem, size));
SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(data.get()));
if (!codec) {
bool isIncomplete = supportsIncomplete;
if (isIncomplete) {
size_t size = stream->getLength();
- SkAutoTUnref<SkData> data((SkData::NewFromStream(stream, 2 * size / 3)));
- codec.reset(SkCodec::NewFromData(data));
+ sk_sp<SkData> data((SkData::MakeFromStream(stream, 2 * size / 3)));
+ codec.reset(SkCodec::NewFromData(data.get()));
} else {
codec.reset(SkCodec::NewFromStream(stream.release()));
}
SkAutoTDelete<SkAndroidCodec> androidCodec(nullptr);
if (isIncomplete) {
size_t size = stream->getLength();
- SkAutoTUnref<SkData> data((SkData::NewFromStream(stream, 2 * size / 3)));
- androidCodec.reset(SkAndroidCodec::NewFromData(data));
+ sk_sp<SkData> data((SkData::MakeFromStream(stream, 2 * size / 3)));
+ androidCodec.reset(SkAndroidCodec::NewFromData(data.get()));
} else {
androidCodec.reset(SkAndroidCodec::NewFromStream(stream.release()));
}
if (!isIncomplete) {
// Test SkCodecImageGenerator
SkAutoTDelete<SkStream> stream(resource(path));
- SkAutoTUnref<SkData> fullData(SkData::NewFromStream(stream, stream->getLength()));
- SkAutoTDelete<SkImageGenerator> gen(SkCodecImageGenerator::NewFromEncodedCodec(fullData));
+ sk_sp<SkData> fullData(SkData::MakeFromStream(stream, stream->getLength()));
+ SkAutoTDelete<SkImageGenerator> gen(
+ SkCodecImageGenerator::NewFromEncodedCodec(fullData.get()));
SkBitmap bm;
bm.allocPixels(info);
SkAutoLockPixels autoLockPixels(bm);
compare_to_good_digest(r, codecDigest, bm);
// Test using SkFrontBufferedStream, as Android does
- SkStream* bufferedStream = SkFrontBufferedStream::Create(new SkMemoryStream(fullData),
- SkCodec::MinBufferedBytesNeeded());
+ SkStream* bufferedStream = SkFrontBufferedStream::Create(
+ new SkMemoryStream(std::move(fullData)), SkCodec::MinBufferedBytesNeeded());
REPORTER_ASSERT(r, bufferedStream);
codec.reset(SkCodec::NewFromStream(bufferedStream));
REPORTER_ASSERT(r, codec);
// Stream that is not an asset stream (!hasPosition() or !hasLength())
class NotAssetMemStream : public SkStream {
public:
- NotAssetMemStream(SkData* data) : fStream(data) {}
+ NotAssetMemStream(sk_sp<SkData> data) : fStream(std::move(data)) {}
bool hasPosition() const override {
return false;
DEF_TEST(Codec_raw_notseekable, r) {
const char* path = "dng_with_preview.dng";
SkString fullPath(GetResourcePath(path));
- SkAutoTUnref<SkData> data(SkData::NewFromFileName(fullPath.c_str()));
+ sk_sp<SkData> data(SkData::MakeFromFileName(fullPath.c_str()));
if (!data) {
SkDebugf("Missing resource '%s'\n", path);
return;
}
- SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(new NotAssetMemStream(data)));
+ SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(new NotAssetMemStream(std::move(data))));
REPORTER_ASSERT(r, codec);
test_info(r, codec.get(), codec->getInfo(), SkCodec::kSuccess, nullptr);
delete[] data;
}
-static void assert_len(skiatest::Reporter* reporter, SkData* ref, size_t len) {
+static void assert_len(skiatest::Reporter* reporter, const sk_sp<SkData>& ref, size_t len) {
REPORTER_ASSERT(reporter, ref->size() == len);
}
-static void assert_data(skiatest::Reporter* reporter, SkData* ref,
+static void assert_data(skiatest::Reporter* reporter, const sk_sp<SkData>& ref,
const void* data, size_t len) {
REPORTER_ASSERT(reporter, ref->size() == len);
REPORTER_ASSERT(reporter, !memcmp(ref->data(), data, len));
const char str[] = "Hello world";
size_t len = strlen(str);
- SkAutoTUnref<SkData> r0(SkData::NewWithCopy(str, len + 1));
- SkAutoTUnref<SkData> r1(SkData::NewWithCString(str));
+ sk_sp<SkData> r0(SkData::MakeWithCopy(str, len + 1));
+ sk_sp<SkData> r1(SkData::MakeWithCString(str));
- REPORTER_ASSERT(reporter, r0->equals(r1));
+ REPORTER_ASSERT(reporter, r0->equals(r1.get()));
- SkAutoTUnref<SkData> r2(SkData::NewWithCString(nullptr));
+ sk_sp<SkData> r2(SkData::MakeWithCString(nullptr));
REPORTER_ASSERT(reporter, 1 == r2->size());
REPORTER_ASSERT(reporter, 0 == *r2->bytes());
}
}
FILE* file = sk_fopen(path.c_str(), kRead_SkFILE_Flag);
- SkAutoTUnref<SkData> r1(SkData::NewFromFILE(file));
+ sk_sp<SkData> r1(SkData::MakeFromFILE(file));
REPORTER_ASSERT(reporter, r1.get() != nullptr);
REPORTER_ASSERT(reporter, r1->size() == 26);
REPORTER_ASSERT(reporter, strncmp(static_cast<const char*>(r1->data()), s, 26) == 0);
int fd = sk_fileno(file);
- SkAutoTUnref<SkData> r2(SkData::NewFromFD(fd));
+ sk_sp<SkData> r2(SkData::MakeFromFD(fd));
REPORTER_ASSERT(reporter, r2.get() != nullptr);
REPORTER_ASSERT(reporter, r2->size() == 26);
REPORTER_ASSERT(reporter, strncmp(static_cast<const char*>(r2->data()), s, 26) == 0);
const char* str = "We the people, in order to form a more perfect union.";
const int N = 10;
- SkAutoTUnref<SkData> r0(SkData::NewEmpty());
- SkAutoTUnref<SkData> r1(SkData::NewWithCopy(str, strlen(str)));
- SkAutoTUnref<SkData> r2(SkData::NewWithProc(new int[N], N*sizeof(int),
- delete_int_proc, gGlobal));
- SkAutoTUnref<SkData> r3(SkData::NewSubset(r1, 7, 6));
+ sk_sp<SkData> r0(SkData::MakeEmpty());
+ sk_sp<SkData> r1(SkData::MakeWithCopy(str, strlen(str)));
+ sk_sp<SkData> r2(SkData::MakeWithProc(new int[N], N*sizeof(int), delete_int_proc, gGlobal));
+ sk_sp<SkData> r3(SkData::MakeSubset(r1.get(), 7, 6));
assert_len(reporter, r0, 0);
assert_len(reporter, r1, strlen(str));
assert_data(reporter, r1, str, strlen(str));
assert_data(reporter, r3, "people", 6);
- SkData* tmp = SkData::NewSubset(r1, strlen(str), 10);
+ sk_sp<SkData> tmp(SkData::MakeSubset(r1.get(), strlen(str), 10));
assert_len(reporter, tmp, 0);
- tmp->unref();
- tmp = SkData::NewSubset(r1, 0, 0);
+ tmp = SkData::MakeSubset(r1.get(), 0, 0);
assert_len(reporter, tmp, 0);
- tmp->unref();
test_cstring(reporter);
test_files(reporter);
static void test_imagegenerator_factory(skiatest::Reporter* reporter) {
// just need a non-empty data to test things
- SkAutoTUnref<SkData> data(SkData::NewWithCString("test_imagegenerator_factory"));
+ sk_sp<SkData> data(SkData::MakeWithCString("test_imagegenerator_factory"));
gMyFactoryWasCalled = false;
SkImageGenerator* gen;
REPORTER_ASSERT(reporter, !gMyFactoryWasCalled);
- gen = SkImageGenerator::NewFromEncoded(data);
+ gen = SkImageGenerator::NewFromEncoded(data.get());
REPORTER_ASSERT(reporter, nullptr == gen);
REPORTER_ASSERT(reporter, !gMyFactoryWasCalled);
// Test is racy, in that it hopes no other thread is changing this global...
SkGraphics::ImageGeneratorFromEncodedFactory prev =
SkGraphics::SetImageGeneratorFromEncodedFactory(my_factory);
- gen = SkImageGenerator::NewFromEncoded(data);
+ gen = SkImageGenerator::NewFromEncoded(data.get());
REPORTER_ASSERT(reporter, nullptr == gen);
REPORTER_ASSERT(reporter, gMyFactoryWasCalled);
SkGraphics::SetImageGeneratorFromEncodedFactory(prev);
draw_image_test_pattern(surface->getCanvas());
return surface->makeImageSnapshot();
}
-static SkData* create_image_data(SkImageInfo* info) {
+static sk_sp<SkData> create_image_data(SkImageInfo* info) {
*info = SkImageInfo::MakeN32(20, 20, kOpaque_SkAlphaType);
const size_t rowBytes = info->minRowBytes();
- SkAutoTUnref<SkData> data(SkData::NewUninitialized(rowBytes * info->height()));
+ sk_sp<SkData> data(SkData::MakeUninitialized(rowBytes * info->height()));
{
SkBitmap bm;
bm.installPixels(*info, data->writable_data(), rowBytes);
SkCanvas canvas(bm);
draw_image_test_pattern(&canvas);
}
- return data.release();
+ return data;
}
static sk_sp<SkImage> create_data_image() {
SkImageInfo info;
sk_sp<SkData> data(create_image_data(&info));
- return SkImage::MakeRasterData(info, data, info.minRowBytes());
+ return SkImage::MakeRasterData(info, std::move(data), info.minRowBytes());
}
#if SK_SUPPORT_GPU // not gpu-specific but currently only used in GPU tests
static sk_sp<SkImage> create_image_565() {
// Want to ensure that our Release is called when the owning image is destroyed
struct RasterDataHolder {
RasterDataHolder() : fReleaseCount(0) {}
- SkAutoTUnref<SkData> fData;
+ sk_sp<SkData> fData;
int fReleaseCount;
static void Release(const void* pixels, void* context) {
RasterDataHolder* self = static_cast<RasterDataHolder*>(context);
static sk_sp<SkImage> create_rasterproc_image(RasterDataHolder* dataHolder) {
SkASSERT(dataHolder);
SkImageInfo info;
- SkAutoTUnref<SkData> data(create_image_data(&info));
- dataHolder->fData.reset(SkRef(data.get()));
- return SkImage::MakeFromRaster(SkPixmap(info, data->data(), info.minRowBytes()),
+ dataHolder->fData = create_image_data(&info);
+ return SkImage::MakeFromRaster(SkPixmap(info, dataHolder->fData->data(), info.minRowBytes()),
RasterDataHolder::Release, dataHolder);
}
static sk_sp<SkImage> create_codec_image() {
SkImageInfo info;
- SkAutoTUnref<SkData> data(create_image_data(&info));
+ sk_sp<SkData> data(create_image_data(&info));
SkBitmap bitmap;
bitmap.installPixels(info, data->writable_data(), info.minRowBytes());
- sk_sp<SkData> src(
- SkImageEncoder::EncodeData(bitmap, SkImageEncoder::kPNG_Type, 100));
- return SkImage::MakeFromEncoded(src);
+ sk_sp<SkData> src(SkImageEncoder::EncodeData(bitmap, SkImageEncoder::kPNG_Type, 100));
+ return SkImage::MakeFromEncoded(std::move(src));
}
#if SK_SUPPORT_GPU
static sk_sp<SkImage> create_gpu_image(GrContext* context) {
class MockSerializer : public SkPixelSerializer {
public:
- MockSerializer(SkData* (*func)()) : fFunc(func), fDidEncode(false) { }
+ MockSerializer(sk_sp<SkData> (*func)()) : fFunc(func), fDidEncode(false) { }
bool didEncode() const { return fDidEncode; }
SkData* onEncode(const SkPixmap&) override {
fDidEncode = true;
- return fFunc();
+ return fFunc().release();
}
private:
- SkData* (*fFunc)();
+ sk_sp<SkData> (*fFunc)();
bool fDidEncode;
typedef SkPixelSerializer INHERITED;
// Test that SkImage encoding observes custom pixel serializers.
DEF_TEST(Image_Encode_Serializer, reporter) {
- MockSerializer serializer([]() -> SkData* { return SkData::NewWithCString(kSerializedData); });
+ MockSerializer serializer([]() -> sk_sp<SkData> {
+ return SkData::MakeWithCString(kSerializedData);
+ });
sk_sp<SkImage> image(create_image());
- SkAutoTUnref<SkData> encoded(image->encode(&serializer));
- SkAutoTUnref<SkData> reference(SkData::NewWithCString(kSerializedData));
+ sk_sp<SkData> encoded(image->encode(&serializer));
+ sk_sp<SkData> reference(SkData::MakeWithCString(kSerializedData));
REPORTER_ASSERT(reporter, serializer.didEncode());
REPORTER_ASSERT(reporter, encoded);
REPORTER_ASSERT(reporter, encoded->size() > 0);
- REPORTER_ASSERT(reporter, encoded->equals(reference));
+ REPORTER_ASSERT(reporter, encoded->equals(reference.get()));
}
// Test that image encoding failures do not break picture serialization/deserialization.
REPORTER_ASSERT(reporter, picture);
REPORTER_ASSERT(reporter, picture->approximateOpCount() > 0);
- MockSerializer emptySerializer([]() -> SkData* { return SkData::NewEmpty(); });
- MockSerializer nullSerializer([]() -> SkData* { return nullptr; });
+ MockSerializer emptySerializer([]() -> sk_sp<SkData> { return SkData::MakeEmpty(); });
+ MockSerializer nullSerializer([]() -> sk_sp<SkData> { return nullptr; });
MockSerializer* serializers[] = { &emptySerializer, &nullSerializer };
for (size_t i = 0; i < SK_ARRAY_COUNT(serializers); ++i) {
{
size_t rowBytes = info.minRowBytes() - 1;
size_t size = info.getSafeSize(rowBytes);
- SkAutoDataUnref data(SkData::NewUninitialized(size));
+ sk_sp<SkData> data(SkData::MakeUninitialized(size));
SkAutoTUnref<SkMallocPixelRef> pr(
- SkMallocPixelRef::NewWithData(info, rowBytes, nullptr, data));
+ SkMallocPixelRef::NewWithData(info, rowBytes, nullptr, data.get()));
// rowbytes too small.
REPORTER_ASSERT(reporter, nullptr == pr.get());
}
{
size_t rowBytes = info.minRowBytes() + 2;
size_t size = info.getSafeSize(rowBytes) - 1;
- SkAutoDataUnref data(SkData::NewUninitialized(size));
+ sk_sp<SkData> data(SkData::MakeUninitialized(size));
SkAutoTUnref<SkMallocPixelRef> pr(
- SkMallocPixelRef::NewWithData(info, rowBytes, nullptr, data));
+ SkMallocPixelRef::NewWithData(info, rowBytes, nullptr, data.get()));
// data too small.
REPORTER_ASSERT(reporter, nullptr == pr.get());
}
REPORTER_ASSERT(reporter, addr == pr->pixels());
}
{
- SkAutoDataUnref data(SkData::NewUninitialized(size));
+ sk_sp<SkData> data(SkData::MakeUninitialized(size));
SkData* dataPtr = data.get();
REPORTER_ASSERT(reporter, dataPtr->unique());
SkAutoTUnref<SkMallocPixelRef> pr(
static bool stream_equals(const SkDynamicMemoryWStream& stream, size_t offset,
const char* buffer, size_t len) {
- SkAutoDataUnref data(stream.copyToData());
+ sk_sp<SkData> data(stream.copyToData());
if (offset + len > data->size()) {
return false;
}
}
-static SkData* load_resource(
+static sk_sp<SkData> load_resource(
skiatest::Reporter* r, const char* test, const char* filename) {
SkString path(GetResourcePath(filename));
- SkData* data = SkData::NewFromFileName(path.c_str());
+ sk_sp<SkData> data(SkData::MakeFromFileName(path.c_str()));
if (!data) {
INFOF(r, "\n%s: Resource '%s' can not be found.\n",
test, filename);
{"mandrill_512_q075.jpg", true, SkJFIFInfo::kYCbCr},
{"randPixels.jpg", true, SkJFIFInfo::kYCbCr}};
for (size_t i = 0; i < SK_ARRAY_COUNT(kTests); ++i) {
- SkAutoTUnref<SkData> data(
- load_resource(r, "JpegIdentification", kTests[i].path));
+ sk_sp<SkData> data(load_resource(r, "JpegIdentification", kTests[i].path));
if (!data) {
continue;
}
SkJFIFInfo info;
- bool isJfif = SkIsJFIF(data, &info);
+ bool isJfif = SkIsJFIF(data.get(), &info);
if (isJfif != kTests[i].isJfif) {
ERRORF(r, "%s failed isJfif test", kTests[i].path);
continue;
compressedByteStream.writeToStream(&expected);
compressedByteStream.reset();
expected.writeText("\nendstream");
- SkAutoDataUnref expectedResultData2(expected.copyToData());
+ sk_sp<SkData> expectedResultData2(expected.copyToData());
SkString result = emit_to_string(*stream);
assert_eql(reporter,
result,
bool dumpAsHex, const char* str) {
SkDynamicMemoryWStream wStream;
path.dump(&wStream, force, dumpAsHex);
- SkAutoDataUnref data(wStream.copyToData());
+ sk_sp<SkData> data(wStream.copyToData());
REPORTER_ASSERT(reporter, data->size() == strlen(str));
if (strlen(str) > 0) {
REPORTER_ASSERT(reporter, !memcmp(data->data(), str, strlen(str)));
}
#endif
-static SkData* serialized_picture_from_bitmap(const SkBitmap& bitmap) {
+static sk_sp<SkData> serialized_picture_from_bitmap(const SkBitmap& bitmap) {
SkPictureRecorder recorder;
SkCanvas* canvas = recorder.beginRecording(SkIntToScalar(bitmap.width()),
SkIntToScalar(bitmap.height()));
SkAutoTUnref<SkPixelSerializer> serializer(
SkImageEncoder::CreatePixelSerializer());
picture->serialize(&wStream, serializer);
- return wStream.copyToData();
+ return sk_sp<SkData>(wStream.copyToData());
}
struct ErrorContext {
if (!SkImageEncoder::EncodeStream(&wStream, original, SkImageEncoder::kPNG_Type, 100)) {
return;
}
- SkAutoDataUnref data(wStream.copyToData());
+ sk_sp<SkData> data(wStream.copyToData());
SkBitmap bm;
- bool installSuccess = SkDEPRECATED_InstallDiscardablePixelRef(data, &bm);
+ bool installSuccess = SkDEPRECATED_InstallDiscardablePixelRef(data.get(), &bm);
REPORTER_ASSERT(reporter, installSuccess);
// Write both bitmaps to pictures, and ensure that the resulting data streams are the same.
// Flattening original will follow the old path of performing an encode, while flattening bm
// will use the already encoded data.
- SkAutoDataUnref picture1(serialized_picture_from_bitmap(original));
- SkAutoDataUnref picture2(serialized_picture_from_bitmap(bm));
- REPORTER_ASSERT(reporter, picture1->equals(picture2));
+ sk_sp<SkData> picture1(serialized_picture_from_bitmap(original));
+ sk_sp<SkData> picture2(serialized_picture_from_bitmap(bm));
+ REPORTER_ASSERT(reporter, picture1->equals(picture2.get()));
// Now test that a parse error was generated when trying to create a new SkPicture without
// providing a function to decode the bitmap.
context.fErrors = 0;
context.fReporter = reporter;
SkSetErrorCallback(assert_one_parse_error_cb, &context);
- SkMemoryStream pictureStream(picture1);
+ SkMemoryStream pictureStream(std::move(picture1));
SkClearLastError();
sk_sp<SkPicture> pictureFromStream(SkPicture::MakeFromStream(&pictureStream, nullptr));
REPORTER_ASSERT(reporter, pictureFromStream.get() != nullptr);
make_unique_key<0>(&key2, 0);
SkAutoTUnref<TestResource> d(new TestResource(context->getGpu()));
int foo = 4132;
- SkAutoTUnref<SkData> data(SkData::NewWithCopy(&foo, sizeof(foo)));
- key2.setCustomData(data.get());
+ key2.setCustomData(SkData::MakeWithCopy(&foo, sizeof(foo)));
d->resourcePriv().setUniqueKey(key2);
}
make_unique_key<0>(&key1, 1);
make_unique_key<0>(&key2, 2);
int foo = 4132;
- SkAutoTUnref<SkData> data(SkData::NewWithCopy(&foo, sizeof(foo)));
- key1.setCustomData(data.get());
+ key1.setCustomData(SkData::MakeWithCopy(&foo, sizeof(foo)));
REPORTER_ASSERT(reporter, *(int*) key1.getCustomData()->data() == 4132);
REPORTER_ASSERT(reporter, key2.getCustomData() == nullptr);
// Call all the public methods on resource in the abandoned state. They shouldn't crash.
int foo = 4132;
- SkAutoTUnref<SkData> data(SkData::NewWithCopy(&foo, sizeof(foo)));
+ sk_sp<SkData> data(SkData::MakeWithCopy(&foo, sizeof(foo)));
resource->setCustomData(data.get());
resource->getCustomData();
resource->getUniqueID();
struct AnnotationRec {
const SkRect fRect;
const char* fKey;
- SkData* fValue;
+ sk_sp<SkData> fValue;
};
class TestAnnotationCanvas : public SkCanvas {
REPORTER_ASSERT(fReporter, fCurrIndex < fCount);
REPORTER_ASSERT(fReporter, rect == fRec[fCurrIndex].fRect);
REPORTER_ASSERT(fReporter, !strcmp(key, fRec[fCurrIndex].fKey));
- REPORTER_ASSERT(fReporter, value->equals(fRec[fCurrIndex].fValue));
+ REPORTER_ASSERT(fReporter, value->equals(fRec[fCurrIndex].fValue.get()));
fCurrIndex += 1;
}
};
const char* str0 = "rect-with-url";
const SkRect r0 = SkRect::MakeWH(10, 10);
- SkAutoTUnref<SkData> d0(SkData::NewWithCString(str0));
- SkAnnotateRectWithURL(recordingCanvas, r0, d0);
+ sk_sp<SkData> d0(SkData::MakeWithCString(str0));
+ SkAnnotateRectWithURL(recordingCanvas, r0, d0.get());
const char* str1 = "named-destination";
const SkRect r1 = SkRect::MakeXYWH(5, 5, 0, 0); // collapsed to a point
- SkAutoTUnref<SkData> d1(SkData::NewWithCString(str1));
- SkAnnotateNamedDestination(recordingCanvas, {r1.x(), r1.y()}, d1);
+ sk_sp<SkData> d1(SkData::MakeWithCString(str1));
+ SkAnnotateNamedDestination(recordingCanvas, {r1.x(), r1.y()}, d1.get());
const char* str2 = "link-to-destination";
const SkRect r2 = SkRect::MakeXYWH(20, 20, 5, 6);
- SkAutoTUnref<SkData> d2(SkData::NewWithCString(str2));
- SkAnnotateLinkToDestination(recordingCanvas, r2, d2);
+ sk_sp<SkData> d2(SkData::MakeWithCString(str2));
+ SkAnnotateLinkToDestination(recordingCanvas, r2, d2.get());
const AnnotationRec recs[] = {
- { r0, SkAnnotationKeys::URL_Key(), d0 },
- { r1, SkAnnotationKeys::Define_Named_Dest_Key(), d1 },
- { r2, SkAnnotationKeys::Link_Named_Dest_Key(), d2 },
+ { r0, SkAnnotationKeys::URL_Key(), std::move(d0) },
+ { r1, SkAnnotationKeys::Define_Named_Dest_Key(), std::move(d1) },
+ { r2, SkAnnotationKeys::Link_Named_Dest_Key(), std::move(d2) },
};
sk_sp<SkPicture> pict0(recorder.finishRecordingAsPicture());
static void TestDereferencingData(SkMemoryStream* memStream) {
memStream->read(nullptr, 0);
memStream->getMemoryBase();
- SkAutoDataUnref data(memStream->copyToData());
+ sk_sp<SkData> data(memStream->copyToData());
}
static void TestNullData() {
dynamicMemoryWStream.write(buffer, size);
}
SkAutoTDelete<SkStreamAsset> asset(dynamicMemoryWStream.detachAsStream());
- SkAutoTUnref<SkData> expected(SkData::NewUninitialized(asset->getLength()));
+ sk_sp<SkData> expected(SkData::MakeUninitialized(asset->getLength()));
uint8_t* expectedPtr = static_cast<uint8_t*>(expected->writable_data());
valueSource.setSeed(kSeed); // reseed.
// We want the exact same same "random" string of numbers to put
for (size_t i = 0; i < asset->getLength(); ++i) {
expectedPtr[i] = valueSource.nextU() & 0xFF;
}
- stream_peek_test(rep, asset, expected);
+ stream_peek_test(rep, asset, expected.get());
}
namespace {
if (!compresses_a8(fmt)) {
continue;
}
- SkAutoDataUnref data(SkTextureCompressor::CompressBitmapToFormat(pixmap, fmt));
+ sk_sp<SkData> data(SkTextureCompressor::CompressBitmapToFormat(pixmap, fmt));
REPORTER_ASSERT(reporter, nullptr == data);
}
}
if (!compresses_a8(fmt)) {
continue;
}
- SkAutoDataUnref data(SkTextureCompressor::CompressBitmapToFormat(pixmap, fmt));
+ sk_sp<SkData> data(SkTextureCompressor::CompressBitmapToFormat(pixmap, fmt));
REPORTER_ASSERT(reporter, nullptr == data);
}
}
continue;
}
- SkAutoDataUnref data(SkTextureCompressor::CompressBitmapToFormat(pixmap, fmt));
+ sk_sp<SkData> data(SkTextureCompressor::CompressBitmapToFormat(pixmap, fmt));
REPORTER_ASSERT(reporter, data);
if (nullptr == data) {
continue;
pixels[i] = lum;
}
- SkAutoDataUnref latcData(
+ sk_sp<SkData> latcData(
SkTextureCompressor::CompressBitmapToFormat(pixmap, kLATCFormat));
REPORTER_ASSERT(reporter, latcData);
if (nullptr == latcData) {
DEF_TEST(Writer32_data, reporter) {
const char* str = "0123456789";
- SkAutoTUnref<SkData> data0(SkData::NewWithCString(str));
- SkAutoTUnref<SkData> data1(SkData::NewEmpty());
+ sk_sp<SkData> data0(SkData::MakeWithCString(str));
+ sk_sp<SkData> data1(SkData::MakeEmpty());
const size_t sizes[] = {
SkWriter32::WriteDataSize(nullptr),
- SkWriter32::WriteDataSize(data0),
- SkWriter32::WriteDataSize(data1),
+ SkWriter32::WriteDataSize(data0.get()),
+ SkWriter32::WriteDataSize(data1.get()),
};
SkSWriter32<1000> writer;
sizeWritten += sizes[0];
REPORTER_ASSERT(reporter, sizeWritten == writer.bytesWritten());
- writer.writeData(data0);
+ writer.writeData(data0.get());
sizeWritten += sizes[1];
REPORTER_ASSERT(reporter, sizeWritten == writer.bytesWritten());
- writer.writeData(data1);
+ writer.writeData(data1.get());
sizeWritten += sizes[2];
REPORTER_ASSERT(reporter, sizeWritten == writer.bytesWritten());
bool GetResourceAsBitmap(const char* resource, SkBitmap* dst) {
SkString resourcePath = GetResourcePath(resource);
- SkAutoTUnref<SkData> resourceData(SkData::NewFromFileName(resourcePath.c_str()));
- SkAutoTDelete<SkImageGenerator> gen(SkImageGenerator::NewFromEncoded(resourceData));
+ sk_sp<SkData> resourceData(SkData::MakeFromFileName(resourcePath.c_str()));
+ SkAutoTDelete<SkImageGenerator> gen(SkImageGenerator::NewFromEncoded(resourceData.get()));
return gen && gen->tryGenerateBitmap(dst);
}
sk_sp<SkImage> GetResourceAsImage(const char* resource) {
SkString path = GetResourcePath(resource);
- sk_sp<SkData> resourceData(SkData::NewFromFileName(path.c_str()));
+ sk_sp<SkData> resourceData(SkData::MakeFromFileName(path.c_str()));
return SkImage::MakeFromEncoded(resourceData);
}
static void encode_data(const void* bytes, size_t count, const char* contentType,
UrlDataManager& urlDataManager, Json::Value* target) {
- SkAutoTUnref<SkData> data(SkData::NewWithCopy(bytes, count));
- SkString url = urlDataManager.addData(data, contentType);
+ sk_sp<SkData> data(SkData::MakeWithCopy(bytes, count));
+ SkString url = urlDataManager.addData(data.get(), contentType);
*target = Json::Value(url.c_str());
}
}
const void* data;
int size = decode_data(jsonBitmap[SKDEBUGCANVAS_ATTRIBUTE_DATA], urlDataManager, &data);
- sk_sp<SkData> encoded(SkData::NewWithoutCopy(data, size));
+ sk_sp<SkData> encoded(SkData::MakeWithoutCopy(data, size));
sk_sp<SkImage> image(SkImage::MakeFromEncoded(std::move(encoded), nullptr));
SkAutoTDelete<SkBitmap> bitmap(new SkBitmap());
int main() {
const DrawOptions options = GetDrawOptions();
if (options.source) {
- sk_sp<SkData> data(SkData::NewFromFileName(options.source));
+ sk_sp<SkData> data(SkData::MakeFromFileName(options.source));
if (!data) {
perror(options.source);
return 1;
}
gSeen.add(digest);
- SkAutoTUnref<SkData> data(SkData::NewWithoutCopy(ptr, len));
- SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(data));
+ sk_sp<SkData> data(SkData::MakeWithoutCopy(ptr, len));
+ SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(data.get()));
if (!codec) {
// FIXME: This code is currently unreachable because we create an empty generator when
// we fail to create a codec.
#include "lauxlib.h"
}
-static SkData* read_into_data(const char file[]) {
- SkData* data = SkData::NewFromFileName(file);
+static sk_sp<SkData> read_into_data(const char file[]) {
+ sk_sp<SkData> data(SkData::MakeFromFileName(file));
if (!data) {
- data = SkData::NewEmpty();
+ data = SkData::MakeEmpty();
}
return data;
}
SkLua L;
for (int i = 1; i < argc; ++i) {
- SkData* data = nullptr;
+ sk_sp<SkData> data;
const void* ptr;
size_t len;
SkDebugf("failed to load %s\n", argv[i]);
exit(-1);
}
- SkSafeUnref(data);
}
return 0;
}
SkLua L(summary);
for (int i = 0; i < FLAGS_luaFile.count(); ++i) {
- SkAutoDataUnref data(SkData::NewFromFileName(FLAGS_luaFile[i]));
- if (nullptr == data.get()) {
- data.reset(SkData::NewEmpty());
+ sk_sp<SkData> data(SkData::MakeFromFileName(FLAGS_luaFile[i]));
+ if (!data) {
+ data = SkData::MakeEmpty();
}
if (!FLAGS_quiet) {
SkDebugf("loading %s...\n", FLAGS_luaFile[i]);
static void get_bounds(DiffResource& resource, const char* name) {
if (resource.fBitmap.empty() && !DiffResource::isStatusFailed(resource.fStatus)) {
- SkAutoDataUnref fileBits(read_file(resource.fFullPath.c_str()));
- if (nullptr == fileBits) {
+ sk_sp<SkData> fileBits(read_file(resource.fFullPath.c_str()));
+ if (fileBits) {
+ get_bitmap(fileBits.get(), resource, true);
+ } else {
SkDebugf("WARNING: couldn't read %s file <%s>\n", name, resource.fFullPath.c_str());
resource.fStatus = DiffResource::kCouldNotRead_Status;
- } else {
- get_bitmap(fileBits, resource, true);
}
}
}
drp->fComparison.fFullPath = comparisonPath;
drp->fComparison.fStatus = DiffResource::kExists_Status;
- SkAutoDataUnref baseFileBits(read_file(drp->fBase.fFullPath.c_str()));
+ sk_sp<SkData> baseFileBits(read_file(drp->fBase.fFullPath.c_str()));
if (baseFileBits) {
drp->fBase.fStatus = DiffResource::kRead_Status;
}
- SkAutoDataUnref comparisonFileBits(read_file(drp->fComparison.fFullPath.c_str()));
+ sk_sp<SkData> comparisonFileBits(read_file(drp->fComparison.fFullPath.c_str()));
if (comparisonFileBits) {
drp->fComparison.fStatus = DiffResource::kRead_Status;
}
}
drp->fResult = DiffRecord::kCouldNotCompare_Result;
- } else if (are_buffers_equal(baseFileBits, comparisonFileBits)) {
+ } else if (are_buffers_equal(baseFileBits.get(), comparisonFileBits.get())) {
drp->fResult = DiffRecord::kEqualBits_Result;
VERBOSE_STATUS("MATCH", ANSI_COLOR_GREEN, baseFiles[i]);
} else {
AutoReleasePixels arp(drp);
- get_bitmap(baseFileBits, drp->fBase, false);
- get_bitmap(comparisonFileBits, drp->fComparison, false);
+ get_bitmap(baseFileBits.get(), drp->fBase, false);
+ get_bitmap(comparisonFileBits.get(), drp->fComparison, false);
VERBOSE_STATUS("DIFFERENT", ANSI_COLOR_RED, baseFiles[i]);
if (DiffResource::kDecoded_Status == drp->fBase.fStatus &&
DiffResource::kDecoded_Status == drp->fComparison.fStatus) {
return (0 == memcmp(skdata1->data(), skdata2->data(), skdata1->size()));
}
-SkData* read_file(const char* file_path) {
- SkData* data = SkData::NewFromFileName(file_path);
+sk_sp<SkData> read_file(const char* file_path) {
+ sk_sp<SkData> data(SkData::MakeFromFileName(file_path));
if (!data) {
SkDebugf("WARNING: could not open file <%s> for reading\n", file_path);
}
/** Reads the file at the given path and returns its complete contents as an
* SkData object (or returns nullptr on error).
*/
-SkData* read_file(const char* file_path);
+sk_sp<SkData> read_file(const char* file_path);
/** Decodes the fileBits into the resource.fBitmap. Returns false on failure. */
bool get_bitmap(SkData* fileBits, DiffResource& resource, bool sizeOnly);
doDraw(surface->getCanvas(), paint, text);
sk_sp<SkImage> image(surface->makeImageSnapshot());
- SkAutoDataUnref data(image->encode());
- if (nullptr == data.get()) {
+ sk_sp<SkData> data(image->encode());
+ if (!data) {
return false;
}
SkFILEWStream stream(path);
return bmp;
}
-SkData* Request::writeCanvasToPng(SkCanvas* canvas) {
+sk_sp<SkData> Request::writeCanvasToPng(SkCanvas* canvas) {
// capture pixels
SkAutoTDelete<SkBitmap> bmp(this->getBitmapFromCanvas(canvas));
SkASSERT(bmp);
SkDynamicMemoryWStream buffer;
SkDrawCommand::WritePNG((const png_bytep) encodedBitmap->bytes(), bmp->width(), bmp->height(),
buffer, true);
- return buffer.copyToData();
+ return sk_sp<SkData>(buffer.copyToData());
}
SkCanvas* Request::getCanvas() {
fDebugCanvas->drawTo(target, n, m);
}
-SkData* Request::drawToPng(int n, int m) {
+sk_sp<SkData> Request::drawToPng(int n, int m) {
this->drawToCanvas(n, m);
return writeCanvasToPng(this->getCanvas());
}
-SkData* Request::writeOutSkp() {
+sk_sp<SkData> Request::writeOutSkp() {
// Playback into picture recorder
SkIRect bounds = this->getBounds();
SkPictureRecorder recorder;
SkAutoTUnref<SkPixelSerializer> serializer(SkImageEncoder::CreatePixelSerializer());
picture->serialize(&outStream, serializer);
- return outStream.copyToData();
+ return sk_sp<SkData>(outStream.copyToData());
}
GrContext* Request::getContext() {
return true;
}
-SkData* Request::getJsonOps(int n) {
+sk_sp<SkData> Request::getJsonOps(int n) {
SkCanvas* canvas = this->getCanvas();
Json::Value root = fDebugCanvas->toJSON(fUrlDataManager, n, canvas);
root["mode"] = Json::Value(fGPUEnabled ? "gpu" : "cpu");
SkDynamicMemoryWStream stream;
stream.writeText(Json::FastWriter().write(root).c_str());
- return stream.copyToData();
+ return sk_sp<SkData>(stream.copyToData());
}
-SkData* Request::getJsonBatchList(int n) {
+sk_sp<SkData> Request::getJsonBatchList(int n) {
SkCanvas* canvas = this->getCanvas();
SkASSERT(fGPUEnabled);
SkDynamicMemoryWStream stream;
stream.writeText(Json::FastWriter().write(result).c_str());
- return stream.copyToData();
+ return sk_sp<SkData>(stream.copyToData());
}
-SkData* Request::getJsonInfo(int n) {
+sk_sp<SkData> Request::getJsonInfo(int n) {
// drawTo
SkAutoTUnref<SkSurface> surface(this->createCPUSurface());
SkCanvas* canvas = surface->getCanvas();
std::string json = Json::FastWriter().write(info);
// We don't want the null terminator so strlen is correct
- return SkData::NewWithCopy(json.c_str(), strlen(json.c_str()));
+ return SkData::MakeWithCopy(json.c_str(), strlen(json.c_str()));
}
SkColor Request::getPixel(int x, int y) {
~Request();
// draws to skia draw op N, highlighting the Mth batch(-1 means no highlight)
- SkData* drawToPng(int n, int m = -1);
- SkData* writeOutSkp();
+ sk_sp<SkData> drawToPng(int n, int m = -1);
+ sk_sp<SkData> writeOutSkp();
SkCanvas* getCanvas();
SkBitmap* getBitmapFromCanvas(SkCanvas* canvas);
bool enableGPU(bool enable);
bool initPictureFromStream(SkStream*);
// Returns the json list of ops as an SkData
- SkData* getJsonOps(int n);
+ sk_sp<SkData> getJsonOps(int n);
// Returns a json list of batches as an SkData
- SkData* getJsonBatchList(int n);
+ sk_sp<SkData> getJsonBatchList(int n);
// Returns json with the viewMatrix and clipRect
- SkData* getJsonInfo(int n);
+ sk_sp<SkData> getJsonInfo(int n);
// returns the color of the pixel at (x,y) in the canvas
SkColor getPixel(int x, int y);
UrlDataManager fUrlDataManager;
private:
- SkData* writeCanvasToPng(SkCanvas* canvas);
+ sk_sp<SkData> writeCanvasToPng(SkCanvas* canvas);
void drawToCanvas(int n, int m = -1);
SkSurface* createCPUSurface();
SkSurface* createGPUSurface();
if (0 == strcmp(method, MHD_HTTP_METHOD_GET)) {
int n = request->getLastOp();
- SkAutoTUnref<SkData> data(request->getJsonBatchList(n));
- return SendData(connection, data, "application/json");
+ sk_sp<SkData> data(request->getJsonBatchList(n));
+ return SendData(connection, data.get(), "application/json");
}
return MHD_NO;
sscanf(commands[1].c_str(), "%d", &n);
}
- SkAutoTUnref<SkData> data(request->getJsonOps(n));
- return SendData(connection, data, "application/json");
+ sk_sp<SkData> data(request->getJsonOps(n));
+ return SendData(connection, data.get(), "application/json");
}
// /cmd/N, for now only delete supported
return MHD_NO;
}
- SkAutoTUnref<SkData> data(request->writeOutSkp());
+ sk_sp<SkData> data(request->writeOutSkp());
// TODO fancier name handling
- return SendData(connection, data, "application/octet-stream", true,
+ return SendData(connection, data.get(), "application/octet-stream", true,
"attachment; filename=something.skp;");
}
sscanf(commands[2].c_str(), "%d", &m);
}
- SkAutoTUnref<SkData> data(request->drawToPng(n, m));
- return SendData(connection, data, "image/png");
+ sk_sp<SkData> data(request->drawToPng(n, m));
+ return SendData(connection, data.get(), "image/png");
}
sscanf(commands[1].c_str(), "%d", &n);
}
- SkAutoTUnref<SkData> data(request->getJsonInfo(n));
- return SendData(connection, data, "application/json");
+ sk_sp<SkData> data(request->getJsonInfo(n));
+ return SendData(connection, data.get(), "application/json");
}
return -1;
}
- SkAutoTUnref<SkData> data(SkData::NewFromFileName(input));
+ sk_sp<SkData> data(SkData::MakeFromFileName(input));
if (!data) {
SkDebugf("Cannot find input image.\n");
return -1;
}
- SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(data));
+ SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(data.get()));
if (!codec) {
SkDebugf("Invalid input image.\n");
return -1;