UrlHandler.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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. #ifndef UrlHandler_DEFINED
  8. #define UrlHandler_DEFINED
  9. #include "include/core/SkColor.h"
  10. struct MHD_Connection;
  11. struct Request;
  12. class UrlHandler {
  13. public:
  14. virtual ~UrlHandler() {}
  15. virtual bool canHandle(const char* method, const char* url) = 0;
  16. virtual int handle(Request* request, MHD_Connection* connection,
  17. const char* url, const char* method,
  18. const char* upload_data, size_t* upload_data_size) = 0;
  19. };
  20. class CmdHandler : public UrlHandler {
  21. public:
  22. bool canHandle(const char* method, const char* url) override;
  23. int handle(Request* request, MHD_Connection* connection,
  24. const char* url, const char* method,
  25. const char* upload_data, size_t* upload_data_size) override;
  26. };
  27. class ImgHandler : public UrlHandler {
  28. public:
  29. bool canHandle(const char* method, const char* url) override;
  30. int handle(Request* request, MHD_Connection* connection,
  31. const char* url, const char* method,
  32. const char* upload_data, size_t* upload_data_size) override;
  33. };
  34. class BreakHandler : public UrlHandler {
  35. public:
  36. bool canHandle(const char* method, const char* url) override;
  37. int handle(Request* request, MHD_Connection* connection,
  38. const char* url, const char* method,
  39. const char* upload_data, size_t* upload_data_size) override;
  40. };
  41. /**
  42. Updates the clip visualization alpha. On all subsequent /img requests, the clip will be drawn in
  43. black with the specified alpha. 0 = no visible clip, 255 = fully opaque clip.
  44. */
  45. class ClipAlphaHandler : public UrlHandler {
  46. public:
  47. bool canHandle(const char* method, const char* url) override;
  48. int handle(Request* request, MHD_Connection* connection,
  49. const char* url, const char* method,
  50. const char* upload_data, size_t* upload_data_size) override;
  51. };
  52. /**
  53. Controls whether GPU rendering is enabled. Posting to /enableGPU/1 turns GPU on, /enableGPU/0
  54. disables it.
  55. */
  56. class EnableGPUHandler : public UrlHandler {
  57. public:
  58. bool canHandle(const char* method, const char* url) override;
  59. int handle(Request* request, MHD_Connection* connection,
  60. const char* url, const char* method,
  61. const char* upload_data, size_t* upload_data_size) override;
  62. };
  63. /**
  64. Controls whether overdraw rendering is enabled. Posting to /overdraw/1 turns overdraw on,
  65. /overdraw/0 disables it.
  66. */
  67. class OverdrawHandler : public UrlHandler {
  68. public:
  69. bool canHandle(const char* method, const char* url) override;
  70. int handle(Request* request, MHD_Connection* connection,
  71. const char* url, const char* method,
  72. const char* upload_data, size_t* upload_data_size) override;
  73. };
  74. class PostHandler : public UrlHandler {
  75. public:
  76. bool canHandle(const char* method, const char* url) override;
  77. int handle(Request* request, MHD_Connection* connection,
  78. const char* url, const char* method,
  79. const char* upload_data, size_t* upload_data_size) override;
  80. };
  81. class DownloadHandler : public UrlHandler {
  82. public:
  83. bool canHandle(const char* method, const char* url) override;
  84. int handle(Request* request, MHD_Connection* connection,
  85. const char* url, const char* method,
  86. const char* upload_data, size_t* upload_data_size) override;
  87. };
  88. class InfoHandler : public UrlHandler {
  89. public:
  90. bool canHandle(const char* method, const char* url) override;
  91. int handle(Request* request, MHD_Connection* connection,
  92. const char* url, const char* method,
  93. const char* upload_data, size_t* upload_data_size) override;
  94. };
  95. class DataHandler : public UrlHandler {
  96. public:
  97. bool canHandle(const char* method, const char* url) override;
  98. int handle(Request* request, MHD_Connection* connection,
  99. const char* url, const char* method,
  100. const char* upload_data, size_t* upload_data_size) override;
  101. };
  102. /*
  103. * Returns a json descripton of all the GPU ops in the image
  104. */
  105. class OpsHandler : public UrlHandler {
  106. public:
  107. bool canHandle(const char* method, const char* url) override;
  108. int handle(Request* request, MHD_Connection* connection,
  109. const char* url, const char* method,
  110. const char* upload_data, size_t* upload_data_size) override;
  111. };
  112. /*
  113. * Enables drawing of gpu op bounds
  114. */
  115. class OpBoundsHandler : public UrlHandler {
  116. public:
  117. bool canHandle(const char* method, const char* url) override;
  118. int handle(Request* request, MHD_Connection* connection,
  119. const char* url, const char* method,
  120. const char* upload_data, size_t* upload_data_size) override;
  121. };
  122. class RootHandler : public UrlHandler {
  123. public:
  124. bool canHandle(const char* method, const char* url) override;
  125. int handle(Request* request, MHD_Connection* connection,
  126. const char* url, const char* method,
  127. const char* upload_data, size_t* upload_data_size) override;
  128. };
  129. /**
  130. * Controls how rendering is performed (L32, S32, F16).
  131. * Posting to /colorMode/0 turns on L32, /colorMode/1 turns on sRGB,
  132. * /colorMode/2 turns on FP16.
  133. */
  134. class ColorModeHandler : public UrlHandler {
  135. public:
  136. bool canHandle(const char* method, const char* url) override;
  137. int handle(Request* request, MHD_Connection* connection,
  138. const char* url, const char* method,
  139. const char* upload_data, size_t* upload_data_size) override;
  140. };
  141. class QuitHandler : public UrlHandler {
  142. public:
  143. bool canHandle(const char* method, const char* url) override;
  144. int handle(Request* request, MHD_Connection* connection,
  145. const char* url, const char* method,
  146. const char* upload_data, size_t* upload_data_size) override;
  147. };
  148. #endif // UrlHandler_DEFINED