aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools/skiaserve/Request.cpp
diff options
context:
space:
mode:
authorGravatar joshualitt <joshualitt@chromium.org>2016-02-26 08:36:25 -0800
committerGravatar Commit bot <commit-bot@chromium.org>2016-02-26 08:36:25 -0800
commitee5348b069d53e5d843b2cebbac728ca7868d9fa (patch)
tree047fcf0109be8c0ddd6882660abaa77e378c887d /tools/skiaserve/Request.cpp
parent67acb83ce96149edf2c5dd56b0d08ffa8011dae9 (diff)
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
Diffstat (limited to 'tools/skiaserve/Request.cpp')
-rw-r--r--tools/skiaserve/Request.cpp48
1 files changed, 48 insertions, 0 deletions
diff --git a/tools/skiaserve/Request.cpp b/tools/skiaserve/Request.cpp
index 3d9e9d37b3..4d256d56d8 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()));
+}