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

Unified Diff: tools/skiaserve/skiaserve.cpp

Issue 1715503004: added /enableGPU command to skiaserve (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 85f3e1e693cd58c6a00eb8a85f4feff28891c712..cb7af9dc2e6dcc744a5c449a1dda2711d731c78e 100644
--- a/tools/skiaserve/skiaserve.cpp
+++ b/tools/skiaserve/skiaserve.cpp
@@ -76,23 +76,6 @@ struct Request {
UrlDataManager fUrlDataManager;
};
-// TODO factor this out into functions, also handle CPU path
-SkSurface* setupSurface(GrContextFactory* factory) {
- GrContext* context = factory->get(GrContextFactory::kNative_GLContextType,
- GrContextFactory::kNone_GLContextOptions);
- int maxRTSize = context->caps()->maxRenderTargetSize();
- SkImageInfo info = SkImageInfo::Make(SkTMin(kImageWidth, maxRTSize),
- SkTMin(kImageHeight, maxRTSize),
- kN32_SkColorType, kPremul_SkAlphaType);
- uint32_t flags = 0;
- SkSurfaceProps props(flags, SkSurfaceProps::kLegacyFontHost_InitType);
- SkSurface* surface = SkSurface::NewRenderTarget(context, SkSurface::kNo_Budgeted, info, 0,
- &props);
- SkASSERT(surface);
-
- return surface;
-}
-
static void write_png_callback(png_structp png_ptr, png_bytep data, png_size_t length) {
SkWStream* out = (SkWStream*) png_get_io_ptr(png_ptr);
out->write(data, length);
@@ -172,12 +155,28 @@ SkData* drawToPng(Request* request, int n) {
return writeCanvasToPng(getCanvasFromRequest(request));
}
-SkSurface* setupCpuSurface() {
+SkSurface* createCPUSurface() {
SkImageInfo info = SkImageInfo::Make(kImageWidth, kImageHeight, kN32_SkColorType,
kPremul_SkAlphaType);
return SkSurface::NewRaster(info);
}
+SkSurface* createGPUSurface(Request* request) {
+ GrContext* context = request->fContextFactory->get(GrContextFactory::kNative_GLContextType,
+ GrContextFactory::kNone_GLContextOptions);
+ int maxRTSize = context->caps()->maxRenderTargetSize();
+ SkImageInfo info = SkImageInfo::Make(SkTMin(kImageWidth, maxRTSize),
+ SkTMin(kImageHeight, maxRTSize),
+ kN32_SkColorType, kPremul_SkAlphaType);
+ uint32_t flags = 0;
+ SkSurfaceProps props(flags, SkSurfaceProps::kLegacyFontHost_InitType);
+ SkSurface* surface = SkSurface::NewRenderTarget(context, SkSurface::kNo_Budgeted, info, 0,
+ &props);
+ SkASSERT(surface);
jcgregorio 2016/02/19 15:23:56 Instead of asserting how about checking for a NULL
+
+ return surface;
+}
+
static const size_t kBufferSize = 1024;
static int process_upload_data(void* cls, enum MHD_ValueKind kind,
@@ -458,6 +457,41 @@ public:
}
};
+/**
+ Controls whether GPU rendering is enabled. Posting to /enableGPU/1 turns GPU on, /enableGPU/0
+ disables it.
+ */
+class EnableGPUHandler : public UrlHandler {
+public:
+ bool canHandle(const char* method, const char* url) override {
+ static const char* kBasePath = "/enableGPU/";
+ return 0 == strcmp(method, MHD_HTTP_METHOD_POST) &&
+ 0 == strncmp(url, kBasePath, strlen(kBasePath));
+ }
+
+ int handle(Request* request, MHD_Connection* connection,
+ const char* url, const char* method,
+ const char* upload_data, size_t* upload_data_size) override {
+ SkTArray<SkString> commands;
+ SkStrSplit(url, "/", &commands);
+
+ if (commands.count() != 2) {
+ return MHD_NO;
+ }
+
+ int enable;
+ sscanf(commands[1].c_str(), "%d", &enable);
+
+ if (enable) {
+ request->fSurface.reset(createGPUSurface(request));
+ }
+ else {
+ request->fSurface.reset(createCPUSurface());
+ }
+ return SendOK(connection);
+ }
+};
+
class PostHandler : public UrlHandler {
public:
bool canHandle(const char* method, const char* url) override {
@@ -506,7 +540,7 @@ public:
// create surface
GrContextOptions grContextOpts;
request->fContextFactory.reset(new GrContextFactory(grContextOpts));
- request->fSurface.reset(setupSurface(request->fContextFactory.get()));
+ request->fSurface.reset(createGPUSurface(request));
// pour picture into debug canvas
request->fDebugCanvas.reset(new SkDebugCanvas(kImageWidth, kImageHeight));
@@ -575,7 +609,7 @@ public:
}
// drawTo
- SkAutoTUnref<SkSurface> surface(setupCpuSurface());
+ SkAutoTUnref<SkSurface> surface(createCPUSurface());
SkCanvas* canvas = surface->getCanvas();
int n;
@@ -676,6 +710,7 @@ public:
fHandlers.push_back(new PostHandler);
fHandlers.push_back(new ImgHandler);
fHandlers.push_back(new ClipAlphaHandler);
+ fHandlers.push_back(new EnableGPUHandler);
fHandlers.push_back(new CmdHandler);
fHandlers.push_back(new InfoHandler);
fHandlers.push_back(new DownloadHandler);
« 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