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
12struct MHD_Connection;
13struct Request;
14
15class UrlHandler {
16public:
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
24class CmdHandler : public UrlHandler {
25public:
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
32class ImgHandler : public UrlHandler {
33public:
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
40class BreakHandler : public UrlHandler {
41public:
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 */
52class ClipAlphaHandler : public UrlHandler {
53public:
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 */
64class EnableGPUHandler : public UrlHandler {
65public:
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 */
76class OverdrawHandler : public UrlHandler {
77public:
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
84class PostHandler : public UrlHandler {
85public:
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
92class DownloadHandler : public UrlHandler {
93public:
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
100class InfoHandler : public UrlHandler {
101public:
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
108class DataHandler : public UrlHandler {
109public:
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 */
119class OpsHandler : public UrlHandler {
120public:
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 */
130class OpBoundsHandler : public UrlHandler {
131public:
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
138class RootHandler : public UrlHandler {
139public:
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 */
151class ColorModeHandler : public UrlHandler {
152public:
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
159class QuitHandler : public UrlHandler {
160public:
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