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

Unified Diff: tools/skiaserve/skiaserve.cpp

Issue 1693893002: skiaserve now retains the graphics context rather than creating a new one each request (Closed) Base URL: https://skia.googlesource.com/skia.git@master
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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/skiaserve/skiaserve.cpp
diff --git a/tools/skiaserve/skiaserve.cpp b/tools/skiaserve/skiaserve.cpp
index 7d62b1728ce8f263c280ca3fba8a8b7009bacdf8..1db8261bd4e1017933082063692224d1af5d9cae 100644
--- a/tools/skiaserve/skiaserve.cpp
+++ b/tools/skiaserve/skiaserve.cpp
@@ -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);
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698