ClipAlphaHandler.cpp 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  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 "microhttpd.h"
  9. #include "tools/skiaserve/Request.h"
  10. #include "tools/skiaserve/Response.h"
  11. using namespace Response;
  12. bool ClipAlphaHandler::canHandle(const char* method, const char* url) {
  13. static const char* kBasePath = "/clipAlpha/";
  14. return 0 == strcmp(method, MHD_HTTP_METHOD_POST) &&
  15. 0 == strncmp(url, kBasePath, strlen(kBasePath));
  16. }
  17. int ClipAlphaHandler::handle(Request* request, MHD_Connection* connection,
  18. const char* url, const char* method,
  19. const char* upload_data, size_t* upload_data_size) {
  20. SkTArray<SkString> commands;
  21. SkStrSplit(url, "/", &commands);
  22. if (!request->hasPicture() || commands.count() != 2) {
  23. return MHD_NO;
  24. }
  25. int alpha;
  26. sscanf(commands[1].c_str(), "%d", &alpha);
  27. request->fDebugCanvas->setClipVizColor(SkColorSetARGB(alpha, 0, 0, 0));
  28. return SendOK(connection);
  29. }