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

Unified Diff: tools/skiaserve/Request.cpp

Issue 1741823002: Get SkiaServe Request started off with a little privacy (Closed) Base URL: https://skia.googlesource.com/skia@skiaserve-7-wireup
Patch Set: 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/skiaserve/Request.h ('k') | tools/skiaserve/skiaserve.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/skiaserve/Request.cpp
diff --git a/tools/skiaserve/Request.cpp b/tools/skiaserve/Request.cpp
index 3d9e9d37b3fbb4d344dff3224404a1ec2f7152a4..4d256d56d87260af82172ad0cdeb87a408f9f278 100644
--- a/tools/skiaserve/Request.cpp
+++ b/tools/skiaserve/Request.cpp
@@ -9,6 +9,8 @@
#include "png.h"
+#include "SkJSONCanvas.h"
+
const int Request::kImageWidth = 1920;
const int Request::kImageHeight = 1080;
@@ -48,6 +50,16 @@ static void write_png(const png_bytep rgba, png_uint_32 width, png_uint_32 heigh
sk_free(rows);
}
+Request::Request(SkString rootUrl)
+ : fUploadContext(nullptr)
+ , fUrlDataManager(rootUrl)
+ , fGPUEnabled(false) {
+ // create surface
+ GrContextOptions grContextOpts;
+ fContextFactory.reset(new GrContextFactory(grContextOpts));
+ fSurface.reset(this->createCPUSurface());
+}
+
SkBitmap* Request::getBitmapFromCanvas(SkCanvas* canvas) {
SkBitmap* bmp = new SkBitmap();
SkImageInfo info = SkImageInfo::Make(kImageWidth, kImageHeight, kRGBA_8888_SkColorType,
@@ -111,6 +123,21 @@ SkSurface* Request::createGPUSurface() {
return surface;
}
+bool Request::enableGPU(bool enable) {
+ if (enable) {
+ SkSurface* surface = this->createGPUSurface();
+ if (surface) {
+ fSurface.reset(surface);
+ fGPUEnabled = true;
+ return true;
+ }
+ return false;
+ }
+ fSurface.reset(this->createCPUSurface());
+ fGPUEnabled = false;
+ return true;
+}
+
SkData* Request::getJsonOps(int n) {
SkCanvas* canvas = this->getCanvas();
Json::Value root = fDebugCanvas->toJSON(fUrlDataManager, n, canvas);
@@ -149,3 +176,24 @@ SkData* Request::getJsonBatchList(int n) {
return stream.copyToData();
}
+
+SkData* Request::getJsonInfo(int n) {
+ // drawTo
+ SkAutoTUnref<SkSurface> surface(this->createCPUSurface());
+ SkCanvas* canvas = surface->getCanvas();
+
+ // TODO this is really slow and we should cache the matrix and clip
+ fDebugCanvas->drawTo(canvas, n);
+
+ // make some json
+ SkMatrix vm = fDebugCanvas->getCurrentMatrix();
+ SkIRect clip = fDebugCanvas->getCurrentClip();
+ Json::Value info(Json::objectValue);
+ info["ViewMatrix"] = SkJSONCanvas::MakeMatrix(vm);
+ info["ClipRect"] = SkJSONCanvas::MakeIRect(clip);
+
+ 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()));
+}
« no previous file with comments | « tools/skiaserve/Request.h ('k') | tools/skiaserve/skiaserve.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698