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