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