OLD | NEW |
1 #include "DMSrcSink.h" | 1 #include "DMSrcSink.h" |
2 #include "SamplePipeControllers.h" | 2 #include "SamplePipeControllers.h" |
3 #include "SkCommonFlags.h" | 3 #include "SkCommonFlags.h" |
4 #include "SkDocument.h" | 4 #include "SkDocument.h" |
5 #include "SkMultiPictureDraw.h" | 5 #include "SkMultiPictureDraw.h" |
6 #include "SkOSFile.h" | 6 #include "SkOSFile.h" |
| 7 #include "SkPictureData.h" |
7 #include "SkPictureRecorder.h" | 8 #include "SkPictureRecorder.h" |
8 #include "SkRandom.h" | 9 #include "SkRandom.h" |
9 #include "SkStream.h" | 10 #include "SkStream.h" |
10 | 11 |
11 namespace DM { | 12 namespace DM { |
12 | 13 |
13 GMSrc::GMSrc(skiagm::GMRegistry::Factory factory) : fFactory(factory) {} | 14 GMSrc::GMSrc(skiagm::GMRegistry::Factory factory) : fFactory(factory) {} |
14 | 15 |
15 Error GMSrc::draw(SkCanvas* canvas) const { | 16 Error GMSrc::draw(SkCanvas* canvas) const { |
16 SkAutoTDelete<skiagm::GM> gm(fFactory(NULL)); | 17 SkAutoTDelete<skiagm::GM> gm(fFactory(NULL)); |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 Name ImageSrc::name() const { | 95 Name ImageSrc::name() const { |
95 Name name = SkOSPath::Basename(fPath.c_str()); | 96 Name name = SkOSPath::Basename(fPath.c_str()); |
96 if (fSubsets > 0) { | 97 if (fSubsets > 0) { |
97 name.appendf("-%d-subsets", fSubsets); | 98 name.appendf("-%d-subsets", fSubsets); |
98 } | 99 } |
99 return name; | 100 return name; |
100 } | 101 } |
101 | 102 |
102 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~*/ | 103 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~*/ |
103 | 104 |
104 static const SkRect kSKPViewport = {0,0, 1000,1000}; | |
105 | |
106 SKPSrc::SKPSrc(SkString path) : fPath(path) {} | 105 SKPSrc::SKPSrc(SkString path) : fPath(path) {} |
107 | 106 |
108 Error SKPSrc::draw(SkCanvas* canvas) const { | 107 Error SKPSrc::draw(SkCanvas* canvas) const { |
109 SkAutoTDelete<SkStream> stream(SkStream::NewFromFile(fPath.c_str())); | 108 SkAutoTDelete<SkStream> stream(SkStream::NewFromFile(fPath.c_str())); |
110 if (!stream) { | 109 if (!stream) { |
111 return SkStringPrintf("Couldn't read %s.", fPath.c_str()); | 110 return SkStringPrintf("Couldn't read %s.", fPath.c_str()); |
112 } | 111 } |
113 SkAutoTUnref<SkPicture> pic(SkPicture::CreateFromStream(stream)); | 112 SkAutoTUnref<SkPicture> pic(SkPicture::CreateFromStream(stream)); |
114 if (!pic) { | 113 if (!pic) { |
115 return SkStringPrintf("Couldn't decode %s as a picture.", fPath.c_str())
; | 114 return SkStringPrintf("Couldn't decode %s as a picture.", fPath.c_str())
; |
116 } | 115 } |
117 stream.reset((SkStream*)NULL); // Might as well drop this when we're done w
ith it. | 116 stream.reset((SkStream*)NULL); // Might as well drop this when we're done w
ith it. |
118 canvas->clipRect(kSKPViewport); | |
119 canvas->drawPicture(pic); | 117 canvas->drawPicture(pic); |
120 return ""; | 118 return ""; |
121 } | 119 } |
122 | 120 |
123 SkISize SKPSrc::size() const { | 121 SkISize SKPSrc::size() const { |
124 // This may be unnecessarily large. | 122 SkAutoTDelete<SkStream> stream(SkStream::NewFromFile(fPath.c_str())); |
125 return kSKPViewport.roundOut().size(); | 123 SkPictInfo info; |
| 124 if (!stream || !SkPicture::InternalOnly_StreamIsSKP(stream, &info)) { |
| 125 return SkISize::Make(0,0); |
| 126 } |
| 127 return info.fCullRect.roundOut().size(); |
126 } | 128 } |
127 | 129 |
128 Name SKPSrc::name() const { return SkOSPath::Basename(fPath.c_str()); } | 130 Name SKPSrc::name() const { return SkOSPath::Basename(fPath.c_str()); } |
129 | 131 |
130 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~*/ | 132 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~*/ |
131 | 133 |
| 134 static SkISize limit_raster_dimensions(const SkISize& size) { |
| 135 // Clamp both dimensions to 2K to stay within typical GPU maximum texture li
mits. |
| 136 int width = SkTMin(2048, size.width()), |
| 137 height = SkTMin(2048, size.height()); |
| 138 // Clamp our largest dimension until we're no more than 2.25 megapixels, to
keep RAM usage sane. |
| 139 int& largest = width > height ? width : height; |
| 140 while (width * height > 2359296) { |
| 141 largest /= 2; |
| 142 } |
| 143 return SkISize::Make(width, height); |
| 144 } |
| 145 |
132 GPUSink::GPUSink(GrContextFactory::GLContextType ct, | 146 GPUSink::GPUSink(GrContextFactory::GLContextType ct, |
133 GrGLStandard api, | 147 GrGLStandard api, |
134 int samples, | 148 int samples, |
135 bool dfText, | 149 bool dfText, |
136 bool threaded) | 150 bool threaded) |
137 : fContextType(ct) | 151 : fContextType(ct) |
138 , fGpuAPI(api) | 152 , fGpuAPI(api) |
139 , fSampleCount(samples) | 153 , fSampleCount(samples) |
140 , fUseDFText(dfText) | 154 , fUseDFText(dfText) |
141 , fThreaded(threaded) {} | 155 , fThreaded(threaded) {} |
142 | 156 |
143 int GPUSink::enclave() const { | 157 int GPUSink::enclave() const { |
144 return fThreaded ? kAnyThread_Enclave : kGPU_Enclave; | 158 return fThreaded ? kAnyThread_Enclave : kGPU_Enclave; |
145 } | 159 } |
146 | 160 |
147 Error GPUSink::draw(const Src& src, SkBitmap* dst, SkWStream*) const { | 161 Error GPUSink::draw(const Src& src, SkBitmap* dst, SkWStream*) const { |
148 GrContextFactory factory; | 162 GrContextFactory factory; |
149 const SkISize size = src.size(); | 163 const SkISize size = limit_raster_dimensions(src.size()); |
150 const SkImageInfo info = | 164 const SkImageInfo info = |
151 SkImageInfo::Make(size.width(), size.height(), kN32_SkColorType, kPremul
_SkAlphaType); | 165 SkImageInfo::Make(size.width(), size.height(), kN32_SkColorType, kPremul
_SkAlphaType); |
152 SkAutoTUnref<SkSurface> surface( | 166 SkAutoTUnref<SkSurface> surface( |
153 NewGpuSurface(&factory, fContextType, fGpuAPI, info, fSampleCount, f
UseDFText)); | 167 NewGpuSurface(&factory, fContextType, fGpuAPI, info, fSampleCount, f
UseDFText)); |
154 if (!surface) { | 168 if (!surface) { |
155 return "Could not create a surface."; | 169 return "Could not create a surface."; |
156 } | 170 } |
157 SkCanvas* canvas = surface->getCanvas(); | 171 SkCanvas* canvas = surface->getCanvas(); |
158 Error err = src.draw(canvas); | 172 Error err = src.draw(canvas); |
159 if (!err.isEmpty()) { | 173 if (!err.isEmpty()) { |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 SkAutoTUnref<SkPicture> pic(recorder.endRecording()); | 236 SkAutoTUnref<SkPicture> pic(recorder.endRecording()); |
223 pic->serialize(dst); | 237 pic->serialize(dst); |
224 return ""; | 238 return ""; |
225 } | 239 } |
226 | 240 |
227 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~*/ | 241 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~*/ |
228 | 242 |
229 RasterSink::RasterSink(SkColorType colorType) : fColorType(colorType) {} | 243 RasterSink::RasterSink(SkColorType colorType) : fColorType(colorType) {} |
230 | 244 |
231 Error RasterSink::draw(const Src& src, SkBitmap* dst, SkWStream*) const { | 245 Error RasterSink::draw(const Src& src, SkBitmap* dst, SkWStream*) const { |
232 const SkISize size = src.size(); | 246 const SkISize size = limit_raster_dimensions(src.size()); |
233 // If there's an appropriate alpha type for this color type, use it, otherwi
se use premul. | 247 // If there's an appropriate alpha type for this color type, use it, otherwi
se use premul. |
234 SkAlphaType alphaType = kPremul_SkAlphaType; | 248 SkAlphaType alphaType = kPremul_SkAlphaType; |
235 (void)SkColorTypeValidateAlphaType(fColorType, alphaType, &alphaType); | 249 (void)SkColorTypeValidateAlphaType(fColorType, alphaType, &alphaType); |
236 | 250 |
237 dst->allocPixels(SkImageInfo::Make(size.width(), size.height(), fColorType,
alphaType)); | 251 dst->allocPixels(SkImageInfo::Make(size.width(), size.height(), fColorType,
alphaType)); |
238 dst->eraseColor(SK_ColorTRANSPARENT); | 252 dst->eraseColor(SK_ColorTRANSPARENT); |
239 SkCanvas canvas(*dst); | 253 SkCanvas canvas(*dst); |
240 return src.draw(&canvas); | 254 return src.draw(&canvas); |
241 } | 255 } |
242 | 256 |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
381 surfaces.unrefAll(); | 395 surfaces.unrefAll(); |
382 return ""; | 396 return ""; |
383 } | 397 } |
384 SkISize size() const SK_OVERRIDE { return fSize; } | 398 SkISize size() const SK_OVERRIDE { return fSize; } |
385 Name name() const SK_OVERRIDE { sk_throw(); return ""; } // No one shou
ld be calling this. | 399 Name name() const SK_OVERRIDE { sk_throw(); return ""; } // No one shou
ld be calling this. |
386 } proxy(fW, fH, pic, src.size()); | 400 } proxy(fW, fH, pic, src.size()); |
387 return fSink->draw(proxy, bitmap, stream); | 401 return fSink->draw(proxy, bitmap, stream); |
388 } | 402 } |
389 | 403 |
390 } // namespace DM | 404 } // namespace DM |
OLD | NEW |