blob: 7f41748c020f978461dd4959a05f56c14595cd5c [file] [log] [blame]
joshualitt24dd6872016-02-25 08:37:54 -08001/*
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
mtkleinecbc5262016-09-22 11:51:24 -070011#include "SkTypes.h"
12
joshualitt40836102016-03-11 11:45:53 -080013#if SK_SUPPORT_GPU
joshualitt24dd6872016-02-25 08:37:54 -080014#include "GrContextFactory.h"
joshualitt40836102016-03-11 11:45:53 -080015#endif
joshualitt24dd6872016-02-25 08:37:54 -080016
17#include "SkDebugCanvas.h"
18#include "SkPicture.h"
19#include "SkStream.h"
20#include "SkSurface.h"
21
22#include "UrlDataManager.h"
23
bsalomon3724e572016-03-30 18:56:19 -070024namespace sk_gpu_test {
joshualitt40836102016-03-11 11:45:53 -080025class GrContextFactory;
bsalomon3724e572016-03-30 18:56:19 -070026}
joshualitt24dd6872016-02-25 08:37:54 -080027struct MHD_Connection;
28struct MHD_PostProcessor;
29
30struct UploadContext {
31 SkDynamicMemoryWStream fStream;
32 MHD_PostProcessor* fPostProcessor;
33 MHD_Connection* connection;
34};
35
36struct Request {
joshualitt40836102016-03-11 11:45:53 -080037 Request(SkString rootUrl);
38 ~Request();
joshualitt24dd6872016-02-25 08:37:54 -080039
Brian Salomon144a5c52016-12-20 16:48:59 -050040 // draws to canvas operation N, highlighting the Mth GrOp. m = -1 means no highlight.
bungeman38d909e2016-08-02 14:40:46 -070041 sk_sp<SkData> drawToPng(int n, int m = -1);
42 sk_sp<SkData> writeOutSkp();
joshualitt4dcbe432016-02-25 10:50:28 -080043 SkCanvas* getCanvas();
joshualitt4dcbe432016-02-25 10:50:28 -080044 SkBitmap* getBitmapFromCanvas(SkCanvas* canvas);
joshualittee5348b2016-02-26 08:36:25 -080045 bool enableGPU(bool enable);
Ben Wagnerc03e1c52016-10-17 15:20:02 -040046 bool setOverdraw(bool enable);
brianosman78312952016-04-19 10:16:53 -070047 bool setColorMode(int mode);
joshualitt1e5884b2016-02-26 08:22:49 -080048 bool hasPicture() const { return SkToBool(fPicture.get()); }
49 int getLastOp() const { return fDebugCanvas->getSize() - 1; }
50
joshualitt6bc96792016-02-29 05:35:04 -080051 bool initPictureFromStream(SkStream*);
52
joshualitt1e5884b2016-02-26 08:22:49 -080053 // Returns the json list of ops as an SkData
bungeman38d909e2016-08-02 14:40:46 -070054 sk_sp<SkData> getJsonOps(int n);
joshualitt1e5884b2016-02-26 08:22:49 -080055
Brian Salomon144a5c52016-12-20 16:48:59 -050056 // Returns a json list of ops as an SkData
57 sk_sp<SkData> getJsonOpList(int n);
joshualitt4dcbe432016-02-25 10:50:28 -080058
joshualittee5348b2016-02-26 08:36:25 -080059 // Returns json with the viewMatrix and clipRect
bungeman38d909e2016-08-02 14:40:46 -070060 sk_sp<SkData> getJsonInfo(int n);
joshualittee5348b2016-02-26 08:36:25 -080061
joshualitte0449cf2016-03-09 10:07:02 -080062 // returns the color of the pixel at (x,y) in the canvas
63 SkColor getPixel(int x, int y);
joshualitt4dcbe432016-02-25 10:50:28 -080064
joshualitt24dd6872016-02-25 08:37:54 -080065 UploadContext* fUploadContext;
Mike Reed5df49342016-11-12 08:06:55 -060066 std::unique_ptr<SkDebugCanvas> fDebugCanvas;
joshualittee5348b2016-02-26 08:36:25 -080067 UrlDataManager fUrlDataManager;
halcanary9d524f22016-03-29 09:03:52 -070068
joshualittee5348b2016-02-26 08:36:25 -080069private:
bungeman38d909e2016-08-02 14:40:46 -070070 sk_sp<SkData> writeCanvasToPng(SkCanvas* canvas);
joshualitt46b301d2016-03-02 08:32:37 -080071 void drawToCanvas(int n, int m = -1);
joshualittee5348b2016-02-26 08:36:25 -080072 SkSurface* createCPUSurface();
73 SkSurface* createGPUSurface();
joshualittae47aee2016-03-10 13:29:36 -080074 SkIRect getBounds();
75 GrContext* getContext();
halcanary9d524f22016-03-29 09:03:52 -070076
reedca2622b2016-03-18 07:25:55 -070077 sk_sp<SkPicture> fPicture;
bsalomon3724e572016-03-30 18:56:19 -070078 sk_gpu_test::GrContextFactory* fContextFactory;
Hal Canary1b612a82016-11-03 16:26:13 -040079 sk_sp<SkSurface> fSurface;
joshualitt24dd6872016-02-25 08:37:54 -080080 bool fGPUEnabled;
Ben Wagnerc03e1c52016-10-17 15:20:02 -040081 bool fOverdraw;
brianosman78312952016-04-19 10:16:53 -070082 int fColorMode;
joshualitt24dd6872016-02-25 08:37:54 -080083};
84
85#endif