OpBoundsHandler.cpp 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. /*
  2. * Copyright 2016 Google Inc.
  3. *
  4. * Use of this source code is governed by a BSD-style license that can be
  5. * found in the LICENSE file.
  6. */
  7. #include "tools/skiaserve/urlhandlers/UrlHandler.h"
  8. #include "tools/skiaserve/Request.h"
  9. #include "tools/skiaserve/Response.h"
  10. #include "microhttpd.h"
  11. using namespace Response;
  12. bool OpBoundsHandler::canHandle(const char* method, const char* url) {
  13. static const char* kBasePath = "/gpuOpBounds/";
  14. return 0 == strcmp(method, MHD_HTTP_METHOD_POST) &&
  15. 0 == strncmp(url, kBasePath, strlen(kBasePath));
  16. }
  17. int OpBoundsHandler::handle(Request* request, MHD_Connection* connection, const char* url,
  18. const char* method, const char* upload_data, size_t* upload_data_size) {
  19. SkTArray<SkString> commands;
  20. SkStrSplit(url, "/", &commands);
  21. if (!request->hasPicture() || commands.count() != 2) {
  22. return MHD_NO;
  23. }
  24. int enabled;
  25. sscanf(commands[1].c_str(), "%d", &enabled);
  26. request->fDebugCanvas->setDrawGpuOpBounds(SkToBool(enabled));
  27. return SendOK(connection);
  28. }