Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(145)

Unified Diff: tools/skiaserve/skiaserve.cpp

Issue 1670153005: Create image cache for use by json canvas (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: comments Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tools/UrlDataManager.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/skiaserve/skiaserve.cpp
diff --git a/tools/skiaserve/skiaserve.cpp b/tools/skiaserve/skiaserve.cpp
index 85e9c87c17b490eb32c1522152be9d30fcf8d368..a8ddcdf488f9d812e925ff8c2d8334908456450e 100644
--- a/tools/skiaserve/skiaserve.cpp
+++ b/tools/skiaserve/skiaserve.cpp
@@ -18,6 +18,8 @@
#include "SkStream.h"
#include "SkSurface.h"
+#include "UrlDataManager.h"
+
#include <sys/socket.h>
#include <microhttpd.h>
@@ -63,10 +65,11 @@ struct UploadContext {
};
struct Request {
- Request() : fUploadContext(nullptr) {}
+ Request(SkString rootUrl) : fUploadContext(nullptr), fUrlDataManager(rootUrl) {}
UploadContext* fUploadContext;
SkAutoTUnref<SkPicture> fPicture;
SkAutoTUnref<SkDebugCanvas> fDebugCanvas;
+ UrlDataManager fUrlDataManager;
};
// TODO factor this out into functions, also handle CPU path
@@ -99,6 +102,7 @@ SkData* writeCanvasToPng(SkCanvas* canvas) {
}
// write to png
+ // TODO encoding to png can be quite slow, we should investigate bmp
SkData* png = SkImageEncoder::EncodeData(bmp, SkImageEncoder::kPNG_Type, 100);
if (!png) {
fprintf(stderr, "Can't encode to png\n");
@@ -411,6 +415,33 @@ public:
}
};
+class DataHandler : public UrlHandler {
+public:
+ bool canHandle(const char* method, const char* url) override {
+ static const char* kBaseUrl = "/data";
+ return 0 == strcmp(method, MHD_HTTP_METHOD_GET) &&
+ 0 == strncmp(url, kBaseUrl, strlen(kBaseUrl));
+ }
+
+ int handle(Request* request, MHD_Connection* connection,
+ const char* url, const char* method,
+ const char* upload_data, size_t* upload_data_size) override {
+ SkTArray<SkString> commands;
+ SkStrSplit(url, "/", &commands);
+
+ if (!request->fPicture.get() || commands.count() != 2) {
+ return MHD_NO;
+ }
+
+ SkAutoTUnref<UrlDataManager::UrlData> urlData(
+ SkRef(request->fUrlDataManager.getDataFromUrl(SkString(url))));
+
+ if (urlData) {
+ return SendData(connection, urlData->fData.get(), urlData->fContentType.c_str());
+ }
+ return MHD_NO;
+ }
+};
class RootHandler : public UrlHandler {
public:
@@ -436,6 +467,7 @@ public:
fHandlers.push_back(new CmdHandler);
fHandlers.push_back(new InfoHandler);
fHandlers.push_back(new DownloadHandler);
+ fHandlers.push_back(new DataHandler);
}
~UrlManager() {
@@ -476,7 +508,7 @@ int answer_to_connection(void* cls, struct MHD_Connection* connection,
}
int skiaserve_main() {
- Request request; // This simple server has one request
+ Request request(SkString("/data")); // This simple server has one request
struct MHD_Daemon* daemon;
// TODO Add option to bind this strictly to an address, e.g. localhost, for security.
daemon = MHD_start_daemon(MHD_USE_SELECT_INTERNALLY, FLAGS_port, nullptr, nullptr,
« no previous file with comments | « tools/UrlDataManager.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698