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
8#ifndef Request_DEFINED
9#define Request_DEFINED
10
11#include "SkTypes.h"
12
13#if SK_SUPPORT_GPU
14#include "GrContextFactory.h"
15#endif
16
17#include "SkDebugCanvas.h"
18#include "SkPicture.h"
19#include "SkStream.h"
20#include "SkSurface.h"
21
22#include "UrlDataManager.h"
23
24namespace sk_gpu_test {
25class GrContextFactory;
26}
27struct MHD_Connection;
28struct MHD_PostProcessor;
29
30struct UploadContext {
31    SkDynamicMemoryWStream fStream;
32    MHD_PostProcessor* fPostProcessor;
33    MHD_Connection* connection;
34};
35
36struct Request {
37    Request(SkString rootUrl);
38    ~Request();
39
40    // draws to canvas operation N, highlighting the Mth GrOp. m = -1 means no highlight.
41    sk_sp<SkData> drawToPng(int n, int m = -1);
42    sk_sp<SkData> writeOutSkp();
43    SkCanvas* getCanvas();
44    SkBitmap* getBitmapFromCanvas(SkCanvas* canvas);
45    bool enableGPU(bool enable);
46    bool setOverdraw(bool enable);
47    bool setColorMode(int mode);
48    bool hasPicture() const { return SkToBool(fPicture.get()); }
49    int getLastOp() const { return fDebugCanvas->getSize() - 1; }
50
51    bool initPictureFromStream(SkStream*);
52
53    // Returns the json list of ops as an SkData
54    sk_sp<SkData> getJsonOps(int n);
55
56    // Returns a json list of ops as an SkData
57    sk_sp<SkData> getJsonOpList(int n);
58
59    // Returns json with the viewMatrix and clipRect
60    sk_sp<SkData> getJsonInfo(int n);
61
62    // returns the color of the pixel at (x,y) in the canvas
63    SkColor getPixel(int x, int y);
64
65    UploadContext* fUploadContext;
66    std::unique_ptr<SkDebugCanvas> fDebugCanvas;
67    UrlDataManager fUrlDataManager;
68
69private:
70    sk_sp<SkData> writeCanvasToPng(SkCanvas* canvas);
71    void drawToCanvas(int n, int m = -1);
72    SkSurface* createCPUSurface();
73    SkSurface* createGPUSurface();
74    SkIRect getBounds();
75    GrContext* getContext();
76
77    sk_sp<SkPicture> fPicture;
78    sk_gpu_test::GrContextFactory* fContextFactory;
79    sk_sp<SkSurface> fSurface;
80    bool fGPUEnabled;
81    bool fOverdraw;
82    int fColorMode;
83};
84
85#endif
86