skiaserve now retains the graphics context rather than creating a new one each request

GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1693893002

Review URL: https://codereview.chromium.org/1693893002
This commit is contained in:
ethannicholas 2016-02-12 10:09:34 -08:00 committed by Commit bot
parent 2a8fcb4647
commit de8e54ccfd

View File

@ -70,6 +70,8 @@ struct Request {
UploadContext* fUploadContext;
SkAutoTUnref<SkPicture> fPicture;
SkAutoTUnref<SkDebugCanvas> fDebugCanvas;
SkAutoTDelete<GrContextFactory> fContextFactory;
SkAutoTUnref<SkSurface> fSurface;
UrlDataManager fUrlDataManager;
};
@ -87,9 +89,6 @@ SkSurface* setupSurface(GrContextFactory* factory) {
&props);
SkASSERT(surface);
SkGLContext* gl = factory->getContextInfo(GrContextFactory::kNative_GLContextType,
GrContextFactory::kNone_GLContextOptions).fGLContext;
gl->makeCurrent();
return surface;
}
@ -112,15 +111,15 @@ SkData* writeCanvasToPng(SkCanvas* canvas) {
return png;
}
SkData* setupAndDrawToCanvasReturnPng(SkDebugCanvas* debugCanvas, int n) {
GrContextOptions grContextOpts;
SkAutoTDelete<GrContextFactory> factory(new GrContextFactory(grContextOpts));
SkAutoTUnref<SkSurface> surface(setupSurface(factory.get()));
SkASSERT(debugCanvas);
SkCanvas* canvas = surface->getCanvas();
debugCanvas->drawTo(canvas, n);
return writeCanvasToPng(canvas);
SkData* setupAndDrawToCanvasReturnPng(Request* request, int n) {
GrContextFactory* factory = request->fContextFactory;
SkGLContext* gl = factory->getContextInfo(GrContextFactory::kNative_GLContextType,
GrContextFactory::kNone_GLContextOptions).fGLContext;
gl->makeCurrent();
SkASSERT(request->fDebugCanvas);
SkCanvas* target = request->fSurface->getCanvas();
request->fDebugCanvas->drawTo(target, n);
return writeCanvasToPng(target);
}
SkSurface* setupCpuSurface() {
@ -287,7 +286,7 @@ public:
sscanf(commands[1].c_str(), "%d", &n);
}
SkAutoTUnref<SkData> data(setupAndDrawToCanvasReturnPng(request->fDebugCanvas, n));
SkAutoTUnref<SkData> data(setupAndDrawToCanvasReturnPng(request, n));
return SendData(connection, data, "image/png");
}
};
@ -337,6 +336,11 @@ public:
return MHD_NO;
}
// create surface
GrContextOptions grContextOpts;
request->fContextFactory.reset(new GrContextFactory(grContextOpts));
request->fSurface.reset(setupSurface(request->fContextFactory.get()));
// pour picture into debug canvas
request->fDebugCanvas.reset(new SkDebugCanvas(kImageWidth, kImageHeight));
request->fDebugCanvas->drawPicture(request->fPicture);