aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools/skiaserve
diff options
context:
space:
mode:
authorGravatar joshualitt <joshualitt@chromium.org>2016-02-29 05:35:04 -0800
committerGravatar Commit bot <commit-bot@chromium.org>2016-02-29 05:35:04 -0800
commit6bc967984a59e2f6602b5661caa8353dc985a4cb (patch)
tree4ab46778f75008e1eb1db4cea430d44984e595cb /tools/skiaserve
parent9b48a6e3f862076018cc7d63b180b6340f4873cd (diff)
A bit more privacy for SkiaServe's Request
Diffstat (limited to 'tools/skiaserve')
-rw-r--r--tools/skiaserve/Request.cpp14
-rw-r--r--tools/skiaserve/Request.h8
-rw-r--r--tools/skiaserve/urlhandlers/BreakHandler.cpp2
-rw-r--r--tools/skiaserve/urlhandlers/ClipAlphaHandler.cpp2
-rw-r--r--tools/skiaserve/urlhandlers/DataHandler.cpp2
-rw-r--r--tools/skiaserve/urlhandlers/DownloadHandler.cpp2
-rw-r--r--tools/skiaserve/urlhandlers/ImgHandler.cpp2
-rw-r--r--tools/skiaserve/urlhandlers/PostHandler.cpp12
8 files changed, 26 insertions, 18 deletions
diff --git a/tools/skiaserve/Request.cpp b/tools/skiaserve/Request.cpp
index bcaebde01f..98b3b030c6 100644
--- a/tools/skiaserve/Request.cpp
+++ b/tools/skiaserve/Request.cpp
@@ -136,6 +136,20 @@ bool Request::enableGPU(bool enable) {
fSurface.reset(this->createCPUSurface());
fGPUEnabled = false;
return true;
+}
+
+bool Request::initPictureFromStream(SkStream* stream) {
+ // parse picture from stream
+ fPicture.reset(SkPicture::CreateFromStream(stream));
+ if (!fPicture.get()) {
+ fprintf(stderr, "Could not create picture from stream.\n");
+ return false;
+ }
+
+ // pour picture into debug canvas
+ fDebugCanvas.reset(new SkDebugCanvas(kImageWidth, Request::kImageHeight));
+ fDebugCanvas->drawPicture(fPicture);
+ return true;
}
GrAuditTrail* Request::getAuditTrail(SkCanvas* canvas) {
diff --git a/tools/skiaserve/Request.h b/tools/skiaserve/Request.h
index bef8c4a810..60a59a7b1c 100644
--- a/tools/skiaserve/Request.h
+++ b/tools/skiaserve/Request.h
@@ -30,14 +30,14 @@ struct Request {
Request(SkString rootUrl);
SkData* drawToPng(int n);
- void drawToCanvas(int n);
SkCanvas* getCanvas();
- SkData* writeCanvasToPng(SkCanvas* canvas);
SkBitmap* getBitmapFromCanvas(SkCanvas* canvas);
bool enableGPU(bool enable);
bool hasPicture() const { return SkToBool(fPicture.get()); }
int getLastOp() const { return fDebugCanvas->getSize() - 1; }
+ bool initPictureFromStream(SkStream*);
+
// Returns the json list of ops as an SkData
SkData* getJsonOps(int n);
@@ -52,16 +52,18 @@ struct Request {
static const int kImageHeight;
UploadContext* fUploadContext;
- SkAutoTUnref<SkPicture> fPicture;
SkAutoTUnref<SkDebugCanvas> fDebugCanvas;
UrlDataManager fUrlDataManager;
private:
+ SkData* writeCanvasToPng(SkCanvas* canvas);
+ void drawToCanvas(int n);
SkSurface* createCPUSurface();
SkSurface* createGPUSurface();
GrAuditTrail* getAuditTrail(SkCanvas*);
void cleanupAuditTrail(SkCanvas*);
+ SkAutoTUnref<SkPicture> fPicture;
SkAutoTDelete<GrContextFactory> fContextFactory;
SkAutoTUnref<SkSurface> fSurface;
bool fGPUEnabled;
diff --git a/tools/skiaserve/urlhandlers/BreakHandler.cpp b/tools/skiaserve/urlhandlers/BreakHandler.cpp
index 9e01c0f509..0b044634fe 100644
--- a/tools/skiaserve/urlhandlers/BreakHandler.cpp
+++ b/tools/skiaserve/urlhandlers/BreakHandler.cpp
@@ -38,7 +38,7 @@ int BreakHandler::handle(Request* request, MHD_Connection* connection,
SkTArray<SkString> commands;
SkStrSplit(url, "/", &commands);
- if (!request->fPicture.get() || commands.count() != 4) {
+ if (!request->hasPicture() || commands.count() != 4) {
return MHD_NO;
}
diff --git a/tools/skiaserve/urlhandlers/ClipAlphaHandler.cpp b/tools/skiaserve/urlhandlers/ClipAlphaHandler.cpp
index 4d66fc9958..4ab5096a1b 100644
--- a/tools/skiaserve/urlhandlers/ClipAlphaHandler.cpp
+++ b/tools/skiaserve/urlhandlers/ClipAlphaHandler.cpp
@@ -25,7 +25,7 @@ int ClipAlphaHandler::handle(Request* request, MHD_Connection* connection,
SkTArray<SkString> commands;
SkStrSplit(url, "/", &commands);
- if (!request->fPicture.get() || commands.count() != 2) {
+ if (!request->hasPicture() || commands.count() != 2) {
return MHD_NO;
}
diff --git a/tools/skiaserve/urlhandlers/DataHandler.cpp b/tools/skiaserve/urlhandlers/DataHandler.cpp
index adad99971f..0c94530c5d 100644
--- a/tools/skiaserve/urlhandlers/DataHandler.cpp
+++ b/tools/skiaserve/urlhandlers/DataHandler.cpp
@@ -25,7 +25,7 @@ int DataHandler::handle(Request* request, MHD_Connection* connection,
SkTArray<SkString> commands;
SkStrSplit(url, "/", &commands);
- if (!request->fPicture.get() || commands.count() != 2) {
+ if (!request->hasPicture() || commands.count() != 2) {
return MHD_NO;
}
diff --git a/tools/skiaserve/urlhandlers/DownloadHandler.cpp b/tools/skiaserve/urlhandlers/DownloadHandler.cpp
index 719a382494..cc55c3b4b9 100644
--- a/tools/skiaserve/urlhandlers/DownloadHandler.cpp
+++ b/tools/skiaserve/urlhandlers/DownloadHandler.cpp
@@ -23,7 +23,7 @@ bool DownloadHandler::canHandle(const char* method, const char* url) {
int DownloadHandler::handle(Request* request, MHD_Connection* connection,
const char* url, const char* method,
const char* upload_data, size_t* upload_data_size) {
- if (!request->fPicture.get()) {
+ if (!request->hasPicture()) {
return MHD_NO;
}
diff --git a/tools/skiaserve/urlhandlers/ImgHandler.cpp b/tools/skiaserve/urlhandlers/ImgHandler.cpp
index 68828267fb..3e390fe832 100644
--- a/tools/skiaserve/urlhandlers/ImgHandler.cpp
+++ b/tools/skiaserve/urlhandlers/ImgHandler.cpp
@@ -25,7 +25,7 @@ int ImgHandler::handle(Request* request, MHD_Connection* connection,
SkTArray<SkString> commands;
SkStrSplit(url, "/", &commands);
- if (!request->fPicture.get() || commands.count() > 2) {
+ if (!request->hasPicture() || commands.count() > 2) {
return MHD_NO;
}
diff --git a/tools/skiaserve/urlhandlers/PostHandler.cpp b/tools/skiaserve/urlhandlers/PostHandler.cpp
index 7cdbf295c6..ce599200b2 100644
--- a/tools/skiaserve/urlhandlers/PostHandler.cpp
+++ b/tools/skiaserve/urlhandlers/PostHandler.cpp
@@ -62,19 +62,11 @@ int PostHandler::handle(Request* request, MHD_Connection* connection,
MHD_destroy_post_processor(uc->fPostProcessor);
uc->fPostProcessor = nullptr;
- // parse picture from stream
- request->fPicture.reset(
- SkPicture::CreateFromStream(request->fUploadContext->fStream.detachAsStream()));
- if (!request->fPicture.get()) {
+ if (!request->initPictureFromStream(request->fUploadContext->fStream.detachAsStream())) {
fprintf(stderr, "Could not create picture from stream.\n");
return MHD_NO;
}
-
- // pour picture into debug canvas
- request->fDebugCanvas.reset(new SkDebugCanvas(Request::kImageWidth,
- Request::kImageHeight));
- request->fDebugCanvas->drawPicture(request->fPicture);
-
+
// clear upload context
delete request->fUploadContext;
request->fUploadContext = nullptr;