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