aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools
diff options
context:
space:
mode:
authorGravatar bungeman <bungeman@google.com>2016-08-02 14:40:46 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2016-08-02 14:40:46 -0700
commit38d909ec2875f79952de08f36adfaac5680d2c53 (patch)
treea11067146b42f3faa8531d6ef912f7246bbde1f2 /tools
parentada5a44f3bdac10a8a0c53b34f5add7aea9fdbb0 (diff)
Move off SK_SUPPORT_LEGACY_DATA_FACTORIES.
This moves Skia code off of SK_SUPPORT_LEGACY_DATA_FACTORIES. GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2206633004 Review-Url: https://codereview.chromium.org/2206633004
Diffstat (limited to 'tools')
-rw-r--r--tools/Resources.cpp6
-rw-r--r--tools/debugger/SkDrawCommand.cpp6
-rw-r--r--tools/fiddle/fiddle_main.cpp2
-rw-r--r--tools/get_images_from_skps.cpp4
-rw-r--r--tools/lua/lua_app.cpp9
-rw-r--r--tools/lua/lua_pictures.cpp6
-rw-r--r--tools/skdiff_main.cpp18
-rw-r--r--tools/skdiff_utils.cpp4
-rw-r--r--tools/skdiff_utils.h2
-rw-r--r--tools/skhello.cpp4
-rw-r--r--tools/skiaserve/Request.cpp22
-rw-r--r--tools/skiaserve/Request.h12
-rw-r--r--tools/skiaserve/urlhandlers/BatchesHandler.cpp4
-rw-r--r--tools/skiaserve/urlhandlers/CmdHandler.cpp4
-rw-r--r--tools/skiaserve/urlhandlers/DownloadHandler.cpp4
-rw-r--r--tools/skiaserve/urlhandlers/ImgHandler.cpp4
-rw-r--r--tools/skiaserve/urlhandlers/InfoHandler.cpp4
-rw-r--r--tools/visualize_color_gamut.cpp4
18 files changed, 59 insertions, 60 deletions
diff --git a/tools/Resources.cpp b/tools/Resources.cpp
index 6d3054ab33..899f5d2bc4 100644
--- a/tools/Resources.cpp
+++ b/tools/Resources.cpp
@@ -27,14 +27,14 @@ void SetResourcePath(const char* resource) {
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);
}
diff --git a/tools/debugger/SkDrawCommand.cpp b/tools/debugger/SkDrawCommand.cpp
index 51eb96706a..362325085c 100644
--- a/tools/debugger/SkDrawCommand.cpp
+++ b/tools/debugger/SkDrawCommand.cpp
@@ -609,8 +609,8 @@ static void store_bool(Json::Value* target, const char* key, bool value, bool de
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());
}
@@ -821,7 +821,7 @@ static SkBitmap* load_bitmap(const Json::Value& jsonBitmap, UrlDataManager& urlD
}
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());
diff --git a/tools/fiddle/fiddle_main.cpp b/tools/fiddle/fiddle_main.cpp
index df2e8ff66e..49ce50b459 100644
--- a/tools/fiddle/fiddle_main.cpp
+++ b/tools/fiddle/fiddle_main.cpp
@@ -93,7 +93,7 @@ static SkData* encode_snapshot(const sk_sp<SkSurface>& surface) {
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;
diff --git a/tools/get_images_from_skps.cpp b/tools/get_images_from_skps.cpp
index 11b99c214d..f9ba34b0f2 100644
--- a/tools/get_images_from_skps.cpp
+++ b/tools/get_images_from_skps.cpp
@@ -53,8 +53,8 @@ struct Sniffer : public SkPixelSerializer {
}
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.
diff --git a/tools/lua/lua_app.cpp b/tools/lua/lua_app.cpp
index 6aea8ee437..92623d0a20 100644
--- a/tools/lua/lua_app.cpp
+++ b/tools/lua/lua_app.cpp
@@ -19,10 +19,10 @@ extern "C" {
#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;
}
@@ -33,7 +33,7 @@ int tool_main(int argc, char** argv) {
SkLua L;
for (int i = 1; i < argc; ++i) {
- SkData* data = nullptr;
+ sk_sp<SkData> data;
const void* ptr;
size_t len;
@@ -50,7 +50,6 @@ int tool_main(int argc, char** argv) {
SkDebugf("failed to load %s\n", argv[i]);
exit(-1);
}
- SkSafeUnref(data);
}
return 0;
}
diff --git a/tools/lua/lua_pictures.cpp b/tools/lua/lua_pictures.cpp
index 9776002e7a..eee7088f0d 100644
--- a/tools/lua/lua_pictures.cpp
+++ b/tools/lua/lua_pictures.cpp
@@ -85,9 +85,9 @@ int tool_main(int argc, char** argv) {
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]);
diff --git a/tools/skdiff_main.cpp b/tools/skdiff_main.cpp
index bb611e96fc..0c60677c58 100644
--- a/tools/skdiff_main.cpp
+++ b/tools/skdiff_main.cpp
@@ -343,12 +343,12 @@ private:
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);
}
}
}
@@ -472,11 +472,11 @@ static void create_diff_images (DiffMetricProc dmp,
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;
}
@@ -491,13 +491,13 @@ static void create_diff_images (DiffMetricProc dmp,
}
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) {
diff --git a/tools/skdiff_utils.cpp b/tools/skdiff_utils.cpp
index 3d4bf7ea93..3a37733682 100644
--- a/tools/skdiff_utils.cpp
+++ b/tools/skdiff_utils.cpp
@@ -25,8 +25,8 @@ bool are_buffers_equal(SkData* skdata1, SkData* skdata2) {
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);
}
diff --git a/tools/skdiff_utils.h b/tools/skdiff_utils.h
index ae7d51a1d2..c535ae26b5 100644
--- a/tools/skdiff_utils.h
+++ b/tools/skdiff_utils.h
@@ -22,7 +22,7 @@ bool are_buffers_equal(SkData* skdata1, SkData* skdata2);
/** 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);
diff --git a/tools/skhello.cpp b/tools/skhello.cpp
index f7d5b9a00e..d1fb96e0eb 100644
--- a/tools/skhello.cpp
+++ b/tools/skhello.cpp
@@ -38,8 +38,8 @@ static bool do_surface(int w, int h, const char path[], const char text[],
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);
diff --git a/tools/skiaserve/Request.cpp b/tools/skiaserve/Request.cpp
index edc0a6820b..e3a0caa6e2 100644
--- a/tools/skiaserve/Request.cpp
+++ b/tools/skiaserve/Request.cpp
@@ -52,7 +52,7 @@ SkBitmap* Request::getBitmapFromCanvas(SkCanvas* canvas) {
return bmp;
}
-SkData* Request::writeCanvasToPng(SkCanvas* canvas) {
+sk_sp<SkData> Request::writeCanvasToPng(SkCanvas* canvas) {
// capture pixels
SkAutoTDelete<SkBitmap> bmp(this->getBitmapFromCanvas(canvas));
SkASSERT(bmp);
@@ -65,7 +65,7 @@ SkData* Request::writeCanvasToPng(SkCanvas* canvas) {
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() {
@@ -96,12 +96,12 @@ void Request::drawToCanvas(int n, int m) {
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;
@@ -117,7 +117,7 @@ SkData* Request::writeOutSkp() {
SkAutoTUnref<SkPixelSerializer> serializer(SkImageEncoder::CreatePixelSerializer());
picture->serialize(&outStream, serializer);
- return outStream.copyToData();
+ return sk_sp<SkData>(outStream.copyToData());
}
GrContext* Request::getContext() {
@@ -242,7 +242,7 @@ bool Request::initPictureFromStream(SkStream* stream) {
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");
@@ -251,10 +251,10 @@ SkData* Request::getJsonOps(int n) {
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);
@@ -263,10 +263,10 @@ SkData* Request::getJsonBatchList(int n) {
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();
@@ -284,7 +284,7 @@ SkData* Request::getJsonInfo(int n) {
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) {
diff --git a/tools/skiaserve/Request.h b/tools/skiaserve/Request.h
index f3af6b72ee..7a5daf55d1 100644
--- a/tools/skiaserve/Request.h
+++ b/tools/skiaserve/Request.h
@@ -36,8 +36,8 @@ struct Request {
~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);
@@ -48,13 +48,13 @@ struct Request {
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);
@@ -64,7 +64,7 @@ struct Request {
UrlDataManager fUrlDataManager;
private:
- SkData* writeCanvasToPng(SkCanvas* canvas);
+ sk_sp<SkData> writeCanvasToPng(SkCanvas* canvas);
void drawToCanvas(int n, int m = -1);
SkSurface* createCPUSurface();
SkSurface* createGPUSurface();
diff --git a/tools/skiaserve/urlhandlers/BatchesHandler.cpp b/tools/skiaserve/urlhandlers/BatchesHandler.cpp
index b245c4d8f3..81457acca4 100644
--- a/tools/skiaserve/urlhandlers/BatchesHandler.cpp
+++ b/tools/skiaserve/urlhandlers/BatchesHandler.cpp
@@ -32,8 +32,8 @@ int BatchesHandler::handle(Request* request, MHD_Connection* connection,
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;
diff --git a/tools/skiaserve/urlhandlers/CmdHandler.cpp b/tools/skiaserve/urlhandlers/CmdHandler.cpp
index 22877e7810..c8ec82d22b 100644
--- a/tools/skiaserve/urlhandlers/CmdHandler.cpp
+++ b/tools/skiaserve/urlhandlers/CmdHandler.cpp
@@ -37,8 +37,8 @@ int CmdHandler::handle(Request* request, MHD_Connection* connection,
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
diff --git a/tools/skiaserve/urlhandlers/DownloadHandler.cpp b/tools/skiaserve/urlhandlers/DownloadHandler.cpp
index 4e2391588b..17bf867485 100644
--- a/tools/skiaserve/urlhandlers/DownloadHandler.cpp
+++ b/tools/skiaserve/urlhandlers/DownloadHandler.cpp
@@ -25,9 +25,9 @@ int DownloadHandler::handle(Request* request, MHD_Connection* connection,
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;");
}
diff --git a/tools/skiaserve/urlhandlers/ImgHandler.cpp b/tools/skiaserve/urlhandlers/ImgHandler.cpp
index 91ea6d06de..659c215197 100644
--- a/tools/skiaserve/urlhandlers/ImgHandler.cpp
+++ b/tools/skiaserve/urlhandlers/ImgHandler.cpp
@@ -40,6 +40,6 @@ int ImgHandler::handle(Request* request, MHD_Connection* connection,
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");
}
diff --git a/tools/skiaserve/urlhandlers/InfoHandler.cpp b/tools/skiaserve/urlhandlers/InfoHandler.cpp
index 464bbb35e1..9335458f5f 100644
--- a/tools/skiaserve/urlhandlers/InfoHandler.cpp
+++ b/tools/skiaserve/urlhandlers/InfoHandler.cpp
@@ -37,6 +37,6 @@ int InfoHandler::handle(Request* request, MHD_Connection* connection,
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");
}
diff --git a/tools/visualize_color_gamut.cpp b/tools/visualize_color_gamut.cpp
index 4d340f8d98..424106f9c4 100644
--- a/tools/visualize_color_gamut.cpp
+++ b/tools/visualize_color_gamut.cpp
@@ -119,12 +119,12 @@ int main(int argc, char** argv) {
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;