OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #ifndef DMSrcSink_DEFINED | 8 #ifndef DMSrcSink_DEFINED |
9 #define DMSrcSink_DEFINED | 9 #define DMSrcSink_DEFINED |
10 | 10 |
11 #include "DMGpuSupport.h" | 11 #include "DMGpuSupport.h" |
12 #include "SkBBHFactory.h" | 12 #include "SkBBHFactory.h" |
13 #include "SkBBoxHierarchy.h" | 13 #include "SkBBoxHierarchy.h" |
14 #include "SkBitmap.h" | 14 #include "SkBitmap.h" |
15 #include "SkBitmapRegionDecoder.h" | 15 #include "SkBitmapRegionDecoder.h" |
16 #include "SkCanvas.h" | 16 #include "SkCanvas.h" |
17 #include "SkData.h" | 17 #include "SkData.h" |
18 #include "SkPicture.h" | 18 #include "SkPicture.h" |
19 #include "gm.h" | 19 #include "gm.h" |
20 | 20 |
21 namespace DM { | 21 namespace DM { |
22 | 22 |
| 23 // Return the extension of the provided SkString. Returns a pointer into the SkS
tring's |
| 24 // data, so its lifetime is the same as the SkString. |
| 25 const char* SkStringExtension(const SkString&); |
| 26 |
23 // This is just convenience. It lets you use either return "foo" or return SkSt
ringPrintf(...). | 27 // This is just convenience. It lets you use either return "foo" or return SkSt
ringPrintf(...). |
24 struct ImplicitString : public SkString { | 28 struct ImplicitString : public SkString { |
25 template <typename T> | 29 template <typename T> |
26 ImplicitString(const T& s) : SkString(s) {} | 30 ImplicitString(const T& s) : SkString(s) {} |
27 ImplicitString() : SkString("") {} | 31 ImplicitString() : SkString("") {} |
28 }; | 32 }; |
29 typedef ImplicitString Name; | 33 typedef ImplicitString Name; |
30 typedef ImplicitString Path; | 34 typedef ImplicitString Path; |
31 | 35 |
32 class Error { | 36 class Error { |
(...skipping 18 matching lines...) Expand all Loading... |
51 private: | 55 private: |
52 SkString fMsg; | 56 SkString fMsg; |
53 bool fFatal; | 57 bool fFatal; |
54 }; | 58 }; |
55 | 59 |
56 struct SinkFlags { | 60 struct SinkFlags { |
57 enum { kNull, kGPU, kVector, kRaster } type; | 61 enum { kNull, kGPU, kVector, kRaster } type; |
58 enum { kDirect, kIndirect } approach; | 62 enum { kDirect, kIndirect } approach; |
59 }; | 63 }; |
60 | 64 |
| 65 enum { kAnyThread_Enclave, |
| 66 kGPU_Enclave, |
| 67 #ifdef SK_CODEC_DECODES_RAW |
| 68 kRAW_Enclave, |
| 69 #endif |
| 70 kNumEnclaves, |
| 71 }; |
| 72 |
61 struct Src { | 73 struct Src { |
62 // All Srcs must be thread safe. | 74 // All Srcs must be thread safe. |
63 virtual ~Src() {} | 75 virtual ~Src() {} |
64 virtual Error SK_WARN_UNUSED_RESULT draw(SkCanvas*) const = 0; | 76 virtual Error SK_WARN_UNUSED_RESULT draw(SkCanvas*) const = 0; |
65 virtual SkISize size() const = 0; | 77 virtual SkISize size() const = 0; |
66 virtual Name name() const = 0; | 78 virtual Name name() const = 0; |
67 virtual void modifyGrContextOptions(GrContextOptions* options) const {} | 79 virtual void modifyGrContextOptions(GrContextOptions* options) const {} |
68 virtual bool veto(SinkFlags) const { return false; } | 80 virtual bool veto(SinkFlags) const { return false; } |
| 81 // If not kAnyThread_Enclave, overrides the Sink's enclave |
| 82 virtual int enclave() const { return kAnyThread_Enclave; } |
69 }; | 83 }; |
70 | 84 |
71 struct Sink { | 85 struct Sink { |
72 virtual ~Sink() {} | 86 virtual ~Sink() {} |
73 // You may write to either the bitmap or stream. If you write to log, we'll
print that out. | 87 // You may write to either the bitmap or stream. If you write to log, we'll
print that out. |
74 virtual Error SK_WARN_UNUSED_RESULT draw(const Src&, SkBitmap*, SkWStream*,
SkString* log) | 88 virtual Error SK_WARN_UNUSED_RESULT draw(const Src&, SkBitmap*, SkWStream*,
SkString* log) |
75 const = 0; | 89 const = 0; |
76 // Sinks in the same enclave (except kAnyThread_Enclave) will run serially o
n the same thread. | 90 // Sinks in the same enclave (except kAnyThread_Enclave) will run serially o
n the same thread. |
77 virtual int enclave() const = 0; | 91 virtual int enclave() const = 0; |
78 | 92 |
79 // File extension for the content draw() outputs, e.g. "png", "pdf". | 93 // File extension for the content draw() outputs, e.g. "png", "pdf". |
80 virtual const char* fileExtension() const = 0; | 94 virtual const char* fileExtension() const = 0; |
81 | 95 |
82 virtual SinkFlags flags() const = 0; | 96 virtual SinkFlags flags() const = 0; |
83 }; | 97 }; |
84 | 98 |
85 enum { kAnyThread_Enclave, kGPU_Enclave }; | |
86 static const int kNumEnclaves = kGPU_Enclave + 1; | |
87 | |
88 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~*/ | 99 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~*/ |
89 | 100 |
90 class GMSrc : public Src { | 101 class GMSrc : public Src { |
91 public: | 102 public: |
92 explicit GMSrc(skiagm::GMRegistry::Factory); | 103 explicit GMSrc(skiagm::GMRegistry::Factory); |
93 | 104 |
94 Error draw(SkCanvas*) const override; | 105 Error draw(SkCanvas*) const override; |
95 SkISize size() const override; | 106 SkISize size() const override; |
96 Name name() const override; | 107 Name name() const override; |
97 void modifyGrContextOptions(GrContextOptions* options) const override; | 108 void modifyGrContextOptions(GrContextOptions* options) const override; |
(...skipping 19 matching lines...) Expand all Loading... |
117 kGetFromCanvas_DstColorType, | 128 kGetFromCanvas_DstColorType, |
118 kIndex8_Always_DstColorType, | 129 kIndex8_Always_DstColorType, |
119 kGrayscale_Always_DstColorType, | 130 kGrayscale_Always_DstColorType, |
120 }; | 131 }; |
121 CodecSrc(Path, Mode, DstColorType, SkAlphaType, float); | 132 CodecSrc(Path, Mode, DstColorType, SkAlphaType, float); |
122 | 133 |
123 Error draw(SkCanvas*) const override; | 134 Error draw(SkCanvas*) const override; |
124 SkISize size() const override; | 135 SkISize size() const override; |
125 Name name() const override; | 136 Name name() const override; |
126 bool veto(SinkFlags) const override; | 137 bool veto(SinkFlags) const override; |
| 138 int enclave() const override { return fEnclave; } |
127 private: | 139 private: |
128 Path fPath; | 140 Path fPath; |
129 Mode fMode; | 141 Mode fMode; |
130 DstColorType fDstColorType; | 142 DstColorType fDstColorType; |
131 SkAlphaType fDstAlphaType; | 143 SkAlphaType fDstAlphaType; |
132 float fScale; | 144 float fScale; |
| 145 int fEnclave; |
133 }; | 146 }; |
134 | 147 |
135 class AndroidCodecSrc : public Src { | 148 class AndroidCodecSrc : public Src { |
136 public: | 149 public: |
137 enum Mode { | 150 enum Mode { |
138 kFullImage_Mode, | 151 kFullImage_Mode, |
139 // Splits the image into multiple subsets using a divisor and decodes th
e subsets | 152 // Splits the image into multiple subsets using a divisor and decodes th
e subsets |
140 // separately. | 153 // separately. |
141 kDivisor_Mode, | 154 kDivisor_Mode, |
142 }; | 155 }; |
143 | 156 |
144 AndroidCodecSrc(Path, Mode, CodecSrc::DstColorType, SkAlphaType, int sampleS
ize); | 157 AndroidCodecSrc(Path, Mode, CodecSrc::DstColorType, SkAlphaType, int sampleS
ize); |
145 | 158 |
146 Error draw(SkCanvas*) const override; | 159 Error draw(SkCanvas*) const override; |
147 SkISize size() const override; | 160 SkISize size() const override; |
148 Name name() const override; | 161 Name name() const override; |
149 bool veto(SinkFlags) const override; | 162 bool veto(SinkFlags) const override; |
| 163 int enclave() const override { return fEnclave; } |
150 private: | 164 private: |
151 Path fPath; | 165 Path fPath; |
152 Mode fMode; | 166 Mode fMode; |
153 CodecSrc::DstColorType fDstColorType; | 167 CodecSrc::DstColorType fDstColorType; |
154 SkAlphaType fDstAlphaType; | 168 SkAlphaType fDstAlphaType; |
155 int fSampleSize; | 169 int fSampleSize; |
| 170 int fEnclave; |
156 }; | 171 }; |
157 | 172 |
158 // Allows for testing of various implementations of Android's BitmapRegionDecode
r | 173 // Allows for testing of various implementations of Android's BitmapRegionDecode
r |
159 class BRDSrc : public Src { | 174 class BRDSrc : public Src { |
160 public: | 175 public: |
161 enum Mode { | 176 enum Mode { |
162 // Decode the entire image as one region. | 177 // Decode the entire image as one region. |
163 kFullImage_Mode, | 178 kFullImage_Mode, |
164 // Splits the image into multiple regions using a divisor and decodes th
e regions | 179 // Splits the image into multiple regions using a divisor and decodes th
e regions |
165 // separately. Also, this test adds a border of a few pixels to each of
the regions | 180 // separately. Also, this test adds a border of a few pixels to each of
the regions |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
359 | 374 |
360 class ViaMojo : public Via { | 375 class ViaMojo : public Via { |
361 public: | 376 public: |
362 explicit ViaMojo(Sink* sink) : Via(sink) {} | 377 explicit ViaMojo(Sink* sink) : Via(sink) {} |
363 Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; | 378 Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; |
364 }; | 379 }; |
365 | 380 |
366 } // namespace DM | 381 } // namespace DM |
367 | 382 |
368 #endif//DMSrcSink_DEFINED | 383 #endif//DMSrcSink_DEFINED |
OLD | NEW |