Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(403)

Side by Side Diff: dm/DMSrcSink.h

Issue 788243008: Sketch DM refactor. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: better failure messages, disable a few things temporarily to try to go green Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « dm/DMSerializeTask.cpp ('k') | dm/DMSrcSink.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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
OLDNEW
« no previous file with comments | « dm/DMSerializeTask.cpp ('k') | dm/DMSrcSink.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698