mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1 | #ifndef DMSrcSink_DEFINED |
| 2 | #define DMSrcSink_DEFINED |
| 3 | |
| 4 | #include "DMGpuSupport.h" |
| 5 | #include "SkBBHFactory.h" |
| 6 | #include "SkBBoxHierarchy.h" |
| 7 | #include "SkBitmap.h" |
| 8 | #include "SkCanvas.h" |
| 9 | #include "SkData.h" |
| 10 | #include "SkGPipe.h" |
| 11 | #include "SkPicture.h" |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 12 | #include "gm.h" |
| 13 | |
| 14 | namespace DM { |
| 15 | |
| 16 | // This is just convenience. It lets you use either return "foo" or return SkStringPrintf(...). |
| 17 | struct ImplicitString : public SkString { |
| 18 | template <typename T> |
| 19 | ImplicitString(const T& s) : SkString(s) {} |
| 20 | }; |
| 21 | typedef ImplicitString Error; |
| 22 | typedef ImplicitString Name; |
mtklein | 8d17a13 | 2015-01-30 11:42:31 -0800 | [diff] [blame] | 23 | typedef ImplicitString Path; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 24 | |
| 25 | struct Src { |
| 26 | // All Srcs must be thread safe. |
| 27 | virtual ~Src() {} |
| 28 | virtual Error SK_WARN_UNUSED_RESULT draw(SkCanvas*) const = 0; |
| 29 | virtual SkISize size() const = 0; |
| 30 | virtual Name name() const = 0; |
| 31 | }; |
| 32 | |
| 33 | struct Sink { |
| 34 | virtual ~Sink() {} |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 35 | // You may write to either the bitmap or stream. If you write to log, we'll print that out. |
| 36 | virtual Error SK_WARN_UNUSED_RESULT draw(const Src&, SkBitmap*, SkWStream*, SkString* log) |
| 37 | const = 0; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 38 | // Sinks in the same enclave (except kAnyThread_Enclave) will run serially on the same thread. |
| 39 | virtual int enclave() const = 0; |
| 40 | |
| 41 | // File extension for the content draw() outputs, e.g. "png", "pdf". |
| 42 | virtual const char* fileExtension() const = 0; |
| 43 | }; |
| 44 | |
mtklein | 55e88b2 | 2015-01-21 15:50:13 -0800 | [diff] [blame] | 45 | enum { kAnyThread_Enclave, kGPU_Enclave, kPDFSink_Enclave }; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 46 | static const int kNumEnclaves = kPDFSink_Enclave + 1; |
| 47 | |
| 48 | /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ |
| 49 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 50 | class GMSrc : public Src { |
| 51 | public: |
| 52 | explicit GMSrc(skiagm::GMRegistry::Factory); |
| 53 | |
| 54 | Error draw(SkCanvas*) const SK_OVERRIDE; |
| 55 | SkISize size() const SK_OVERRIDE; |
| 56 | Name name() const SK_OVERRIDE; |
| 57 | private: |
| 58 | skiagm::GMRegistry::Factory fFactory; |
| 59 | }; |
| 60 | |
| 61 | class ImageSrc : public Src { |
| 62 | public: |
mtklein | edc93bc | 2015-01-30 13:22:23 -0800 | [diff] [blame] | 63 | // divisor == 0 means decode the whole image |
| 64 | // divisor > 0 means decode in subsets, dividing into a divisor x divisor grid. |
| 65 | explicit ImageSrc(Path path, int divisor = 0); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 66 | |
| 67 | Error draw(SkCanvas*) const SK_OVERRIDE; |
| 68 | SkISize size() const SK_OVERRIDE; |
| 69 | Name name() const SK_OVERRIDE; |
| 70 | private: |
mtklein | 8d17a13 | 2015-01-30 11:42:31 -0800 | [diff] [blame] | 71 | Path fPath; |
mtklein | edc93bc | 2015-01-30 13:22:23 -0800 | [diff] [blame] | 72 | const int fDivisor; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 73 | }; |
| 74 | |
| 75 | class SKPSrc : public Src { |
| 76 | public: |
mtklein | 8d17a13 | 2015-01-30 11:42:31 -0800 | [diff] [blame] | 77 | explicit SKPSrc(Path path); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 78 | |
| 79 | Error draw(SkCanvas*) const SK_OVERRIDE; |
| 80 | SkISize size() const SK_OVERRIDE; |
| 81 | Name name() const SK_OVERRIDE; |
| 82 | private: |
mtklein | 8d17a13 | 2015-01-30 11:42:31 -0800 | [diff] [blame] | 83 | Path fPath; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 84 | }; |
| 85 | |
| 86 | /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ |
| 87 | |
mtklein | ad66f9b | 2015-02-13 15:11:10 -0800 | [diff] [blame] | 88 | class NullSink : public Sink { |
| 89 | public: |
| 90 | NullSink() {} |
| 91 | |
| 92 | Error draw(const Src& src, SkBitmap*, SkWStream*, SkString*) const SK_OVERRIDE; |
| 93 | int enclave() const SK_OVERRIDE { return kAnyThread_Enclave; } |
| 94 | const char* fileExtension() const SK_OVERRIDE { return ""; } |
| 95 | }; |
| 96 | |
| 97 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 98 | class GPUSink : public Sink { |
| 99 | public: |
mtklein | 82d2843 | 2015-01-15 12:46:02 -0800 | [diff] [blame] | 100 | GPUSink(GrContextFactory::GLContextType, GrGLStandard, int samples, bool dfText, bool threaded); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 101 | |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 102 | Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const SK_OVERRIDE; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 103 | int enclave() const SK_OVERRIDE; |
| 104 | const char* fileExtension() const SK_OVERRIDE { return "png"; } |
| 105 | private: |
| 106 | GrContextFactory::GLContextType fContextType; |
| 107 | GrGLStandard fGpuAPI; |
| 108 | int fSampleCount; |
| 109 | bool fUseDFText; |
mtklein | 82d2843 | 2015-01-15 12:46:02 -0800 | [diff] [blame] | 110 | bool fThreaded; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 111 | }; |
| 112 | |
| 113 | class PDFSink : public Sink { |
| 114 | public: |
| 115 | PDFSink(); |
| 116 | |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 117 | Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const SK_OVERRIDE; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 118 | int enclave() const SK_OVERRIDE { return kPDFSink_Enclave; } |
| 119 | const char* fileExtension() const SK_OVERRIDE { return "pdf"; } |
| 120 | }; |
| 121 | |
| 122 | class RasterSink : public Sink { |
| 123 | public: |
| 124 | explicit RasterSink(SkColorType); |
| 125 | |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 126 | Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const SK_OVERRIDE; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 127 | int enclave() const SK_OVERRIDE { return kAnyThread_Enclave; } |
| 128 | const char* fileExtension() const SK_OVERRIDE { return "png"; } |
| 129 | private: |
| 130 | SkColorType fColorType; |
| 131 | }; |
| 132 | |
mtklein | 9c3f17d | 2015-01-28 11:35:18 -0800 | [diff] [blame] | 133 | class SKPSink : public Sink { |
| 134 | public: |
| 135 | SKPSink(); |
| 136 | |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 137 | Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const SK_OVERRIDE; |
mtklein | 9c3f17d | 2015-01-28 11:35:18 -0800 | [diff] [blame] | 138 | int enclave() const SK_OVERRIDE { return kAnyThread_Enclave; } |
| 139 | const char* fileExtension() const SK_OVERRIDE { return "skp"; } |
| 140 | }; |
| 141 | |
mtklein | 8a4527e | 2015-01-31 20:00:58 -0800 | [diff] [blame] | 142 | class SVGSink : public Sink { |
| 143 | public: |
| 144 | SVGSink(); |
| 145 | |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 146 | Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const SK_OVERRIDE; |
mtklein | 8a4527e | 2015-01-31 20:00:58 -0800 | [diff] [blame] | 147 | int enclave() const SK_OVERRIDE { return kAnyThread_Enclave; } |
| 148 | const char* fileExtension() const SK_OVERRIDE { return "svg"; } |
| 149 | }; |
| 150 | |
| 151 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 152 | /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ |
| 153 | |
| 154 | class ViaMatrix : public Sink { |
| 155 | public: |
| 156 | ViaMatrix(SkMatrix, Sink*); |
| 157 | |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 158 | Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const SK_OVERRIDE; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 159 | int enclave() const SK_OVERRIDE { return fSink->enclave(); } |
| 160 | const char* fileExtension() const SK_OVERRIDE { return fSink->fileExtension(); } |
| 161 | private: |
| 162 | SkMatrix fMatrix; |
| 163 | SkAutoTDelete<Sink> fSink; |
| 164 | }; |
| 165 | |
mtklein | d603b22 | 2015-02-17 11:13:33 -0800 | [diff] [blame] | 166 | class ViaUpright : public Sink { |
| 167 | public: |
| 168 | ViaUpright(SkMatrix, Sink*); |
| 169 | |
| 170 | Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const SK_OVERRIDE; |
| 171 | int enclave() const SK_OVERRIDE { return fSink->enclave(); } |
| 172 | const char* fileExtension() const SK_OVERRIDE { return fSink->fileExtension(); } |
| 173 | private: |
| 174 | SkMatrix fMatrix; |
| 175 | SkAutoTDelete<Sink> fSink; |
| 176 | }; |
| 177 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 178 | class ViaPipe : public Sink { |
| 179 | public: |
mtklein | 7edca21 | 2015-01-21 13:18:51 -0800 | [diff] [blame] | 180 | explicit ViaPipe(Sink*); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 181 | |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 182 | Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const SK_OVERRIDE; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 183 | int enclave() const SK_OVERRIDE { return fSink->enclave(); } |
| 184 | const char* fileExtension() const SK_OVERRIDE { return fSink->fileExtension(); } |
| 185 | private: |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 186 | SkAutoTDelete<Sink> fSink; |
| 187 | }; |
| 188 | |
| 189 | class ViaSerialization : public Sink { |
| 190 | public: |
| 191 | explicit ViaSerialization(Sink*); |
| 192 | |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 193 | Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const SK_OVERRIDE; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 194 | int enclave() const SK_OVERRIDE { return fSink->enclave(); } |
| 195 | const char* fileExtension() const SK_OVERRIDE { return fSink->fileExtension(); } |
| 196 | private: |
| 197 | SkAutoTDelete<Sink> fSink; |
| 198 | }; |
| 199 | |
| 200 | class ViaTiles : public Sink { |
| 201 | public: |
| 202 | ViaTiles(int w, int h, SkBBHFactory*, Sink*); |
| 203 | |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 204 | Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const SK_OVERRIDE; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 205 | int enclave() const SK_OVERRIDE { return fSink->enclave(); } |
| 206 | const char* fileExtension() const SK_OVERRIDE { return fSink->fileExtension(); } |
| 207 | private: |
| 208 | const int fW, fH; |
| 209 | SkAutoTDelete<SkBBHFactory> fFactory; |
| 210 | SkAutoTDelete<Sink> fSink; |
| 211 | }; |
| 212 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 213 | } // namespace DM |
| 214 | |
| 215 | #endif//DMSrcSink_DEFINED |