Get SkiaServe Request started off with a little privacy
This CL moves the surface stuff into the request object so it
can maintain its internal state consistently
BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1741823002
Review URL: https://codereview.chromium.org/1741823002
diff --git a/tools/skiaserve/Request.cpp b/tools/skiaserve/Request.cpp
index 3d9e9d3..4d256d5 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 @@
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 @@
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 @@
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()));
+}