Flutter Engine
The Flutter Engine
Public Member Functions | List of all members
BreakHandler Class Reference

#include <UrlHandler.h>

Inheritance diagram for BreakHandler:
UrlHandler

Public Member Functions

bool canHandle (const char *method, const char *url) override
 
int handle (Request *request, MHD_Connection *connection, const char *url, const char *method, const char *upload_data, size_t *upload_data_size) override
 
- Public Member Functions inherited from UrlHandler
virtual ~UrlHandler ()
 
virtual bool canHandle (const char *method, const char *url)=0
 
virtual int handle (Request *request, MHD_Connection *connection, const char *url, const char *method, const char *upload_data, size_t *upload_data_size)=0
 

Detailed Description

Definition at line 40 of file UrlHandler.h.

Member Function Documentation

◆ canHandle()

bool BreakHandler::canHandle ( const char *  method,
const char *  url 
)
overridevirtual

Implements UrlHandler.

Definition at line 20 of file BreakHandler.cpp.

20 {
21 static const char* kBasePath = "/break";
22 return 0 == strcmp(method, MHD_HTTP_METHOD_GET) &&
23 0 == strncmp(url, kBasePath, strlen(kBasePath));
24}

◆ handle()

int BreakHandler::handle ( Request request,
MHD_Connection *  connection,
const char *  url,
const char *  method,
const char *  upload_data,
size_t *  upload_data_size 
)
overridevirtual

Implements UrlHandler.

Definition at line 26 of file BreakHandler.cpp.

28 {
30 SkStrSplit(url, "/", &commands);
31
32 if (!request->hasPicture() || commands.size() != 4) {
33 return MHD_NO;
34 }
35
36 // /break/<n>/<x>/<y>
37 int n;
38 sscanf(commands[1].c_str(), "%d", &n);
39 int x;
40 sscanf(commands[2].c_str(), "%d", &x);
41 int y;
42 sscanf(commands[3].c_str(), "%d", &y);
43
44 int count = request->fDebugCanvas->getSize();
45 SkASSERT(n < count);
46
47 SkCanvas* canvas = request->getCanvas();
48 canvas->clear(SK_ColorWHITE);
49 int saveCount = canvas->save();
50 for (int i = 0; i <= n; ++i) {
51 request->fDebugCanvas->getDrawCommandAt(i)->execute(canvas);
52 }
53 SkColor target = request->getPixel(x, y);
54
57 writer.beginObject(); // root
58
59 writer.appendName("startColor");
61
62 bool changed = false;
63 for (int i = n + 1; i < n + count; ++i) {
64 int index = i % count;
65 if (index == 0) {
66 // reset canvas for wraparound
67 canvas->restoreToCount(saveCount);
68 canvas->clear(SK_ColorWHITE);
69 saveCount = canvas->save();
70 }
71 request->fDebugCanvas->getDrawCommandAt(index)->execute(canvas);
72 SkColor current = request->getPixel(x, y);
73 if (current != target) {
74 writer.appendName("endColor");
75 DrawCommand::MakeJsonColor(writer, current);
76 writer.appendS32("endOp", index);
77 changed = true;
78 break;
79 }
80 }
81 if (!changed) {
82 writer.appendName("endColor");
84 writer.appendS32("endOp", n);
85 }
86 canvas->restoreToCount(saveCount);
87
88 writer.endObject(); // root
89 writer.flush();
90 return SendData(connection, stream.detachAsData().get(), "application/json");
91}
int count
Definition: FontMgrTest.cpp:50
#define SkASSERT(cond)
Definition: SkAssert.h:116
uint32_t SkColor
Definition: SkColor.h:37
constexpr SkColor SK_ColorWHITE
Definition: SkColor.h:122
void SkStrSplit(const char *str, const char *delimiters, SkStrSplitMode splitMode, TArray< SkString > *out)
static void MakeJsonColor(SkJSONWriter &, const SkColor color)
void clear(SkColor color)
Definition: SkCanvas.h:1199
void restoreToCount(int saveCount)
Definition: SkCanvas.cpp:478
int save()
Definition: SkCanvas.cpp:447
uint32_t * target
double y
double x
int SendData(MHD_Connection *connection, const SkData *data, const char *type, bool setContentDisposition, const char *dispositionString)
Definition: Response.cpp:64
dictionary commands
Definition: dom.py:171

The documentation for this class was generated from the following files: