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