| 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()));
|
| +}
|
|
|