OLD | NEW |
(Empty) | |
| 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" |
| 12 #include "SkStream.h" |
| 13 #include "gm.h" |
| 14 |
| 15 namespace DM { |
| 16 |
| 17 // This is just convenience. It lets you use either return "foo" or return SkSt
ringPrintf(...). |
| 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; |
| 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() {} |
| 35 // You may write to either the bitmap or stream. |
| 36 virtual Error SK_WARN_UNUSED_RESULT draw(const Src&, SkBitmap*, SkWStream*)
const |
| 37 = 0; |
| 38 // Sinks in the same enclave (except kAnyThread_Enclave) will run serially o
n 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 |
| 45 enum { kAnyThread_Enclave, kGPUSink_Enclave, kPDFSink_Enclave }; |
| 46 static const int kNumEnclaves = kPDFSink_Enclave + 1; |
| 47 |
| 48 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~*/ |
| 49 |
| 50 void SafeUnref(SkPicture*); // These need external linkage (and specific types)
. |
| 51 void SafeUnref(SkData*); |
| 52 |
| 53 class GMSrc : public Src { |
| 54 public: |
| 55 explicit GMSrc(skiagm::GMRegistry::Factory); |
| 56 |
| 57 Error draw(SkCanvas*) const SK_OVERRIDE; |
| 58 SkISize size() const SK_OVERRIDE; |
| 59 Name name() const SK_OVERRIDE; |
| 60 private: |
| 61 skiagm::GMRegistry::Factory fFactory; |
| 62 }; |
| 63 |
| 64 class ImageSrc : public Src { |
| 65 public: |
| 66 explicit ImageSrc(SkString path, int subsets = 0); |
| 67 |
| 68 Error draw(SkCanvas*) const SK_OVERRIDE; |
| 69 SkISize size() const SK_OVERRIDE; |
| 70 Name name() const SK_OVERRIDE; |
| 71 private: |
| 72 SkString fPath; |
| 73 int fSubsets; |
| 74 SkLazyPtr<SkData, SafeUnref> fEncoded; |
| 75 }; |
| 76 |
| 77 class SKPSrc : public Src { |
| 78 public: |
| 79 explicit SKPSrc(SkString path); |
| 80 |
| 81 Error draw(SkCanvas*) const SK_OVERRIDE; |
| 82 SkISize size() const SK_OVERRIDE; |
| 83 Name name() const SK_OVERRIDE; |
| 84 private: |
| 85 SkString fPath; |
| 86 SkLazyPtr<SkPicture, SafeUnref> fPic; |
| 87 }; |
| 88 |
| 89 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~*/ |
| 90 |
| 91 class GPUSink : public Sink { |
| 92 public: |
| 93 GPUSink(GrContextFactory::GLContextType, GrGLStandard, int samples, bool dfT
ext); |
| 94 |
| 95 Error draw(const Src&, SkBitmap*, SkWStream*) const SK_OVERRIDE; |
| 96 int enclave() const SK_OVERRIDE; |
| 97 const char* fileExtension() const SK_OVERRIDE { return "png"; } |
| 98 private: |
| 99 GrContextFactory::GLContextType fContextType; |
| 100 GrGLStandard fGpuAPI; |
| 101 int fSampleCount; |
| 102 bool fUseDFText; |
| 103 }; |
| 104 |
| 105 class PDFSink : public Sink { |
| 106 public: |
| 107 PDFSink(); |
| 108 |
| 109 Error draw(const Src&, SkBitmap*, SkWStream*) const SK_OVERRIDE; |
| 110 int enclave() const SK_OVERRIDE { return kPDFSink_Enclave; } |
| 111 const char* fileExtension() const SK_OVERRIDE { return "pdf"; } |
| 112 }; |
| 113 |
| 114 class RasterSink : public Sink { |
| 115 public: |
| 116 explicit RasterSink(SkColorType); |
| 117 |
| 118 Error draw(const Src&, SkBitmap*, SkWStream*) const SK_OVERRIDE; |
| 119 int enclave() const SK_OVERRIDE { return kAnyThread_Enclave; } |
| 120 const char* fileExtension() const SK_OVERRIDE { return "png"; } |
| 121 private: |
| 122 SkColorType fColorType; |
| 123 }; |
| 124 |
| 125 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~*/ |
| 126 |
| 127 class ViaMatrix : public Sink { |
| 128 public: |
| 129 ViaMatrix(SkMatrix, Sink*); |
| 130 |
| 131 Error draw(const Src&, SkBitmap*, SkWStream*) const SK_OVERRIDE; |
| 132 int enclave() const SK_OVERRIDE { return fSink->enclave(); } |
| 133 const char* fileExtension() const SK_OVERRIDE { return fSink->fileExtension(
); } |
| 134 private: |
| 135 SkMatrix fMatrix; |
| 136 SkAutoTDelete<Sink> fSink; |
| 137 }; |
| 138 |
| 139 class ViaPipe : public Sink { |
| 140 public: |
| 141 ViaPipe(int flags, Sink*); |
| 142 |
| 143 Error draw(const Src&, SkBitmap*, SkWStream*) const SK_OVERRIDE; |
| 144 int enclave() const SK_OVERRIDE { return fSink->enclave(); } |
| 145 const char* fileExtension() const SK_OVERRIDE { return fSink->fileExtension(
); } |
| 146 private: |
| 147 SkGPipeWriter::Flags fFlags; |
| 148 SkAutoTDelete<Sink> fSink; |
| 149 }; |
| 150 |
| 151 class ViaSerialization : public Sink { |
| 152 public: |
| 153 explicit ViaSerialization(Sink*); |
| 154 |
| 155 Error draw(const Src&, SkBitmap*, SkWStream*) const SK_OVERRIDE; |
| 156 int enclave() const SK_OVERRIDE { return fSink->enclave(); } |
| 157 const char* fileExtension() const SK_OVERRIDE { return fSink->fileExtension(
); } |
| 158 private: |
| 159 SkAutoTDelete<Sink> fSink; |
| 160 }; |
| 161 |
| 162 class ViaTiles : public Sink { |
| 163 public: |
| 164 ViaTiles(int w, int h, SkBBHFactory*, Sink*); |
| 165 |
| 166 Error draw(const Src&, SkBitmap*, SkWStream*) const SK_OVERRIDE; |
| 167 int enclave() const SK_OVERRIDE { return fSink->enclave(); } |
| 168 const char* fileExtension() const SK_OVERRIDE { return fSink->fileExtension(
); } |
| 169 private: |
| 170 const int fW, fH; |
| 171 SkAutoTDelete<SkBBHFactory> fFactory; |
| 172 SkAutoTDelete<Sink> fSink; |
| 173 }; |
| 174 |
| 175 } // namespace DM |
| 176 |
| 177 #endif//DMSrcSink_DEFINED |
OLD | NEW |