| 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 // This fits within a typical maximum texture, and puts a reasonable 16MB ca
p on raster bitmaps. | |
| 136 return SkISize::Make(SkTMin(2048, size.width()), SkTMin(2048, size.height())
); | |
| 137 } | |
| 138 | |
| 139 GPUSink::GPUSink(GrContextFactory::GLContextType ct, | 132 GPUSink::GPUSink(GrContextFactory::GLContextType ct, |
| 140 GrGLStandard api, | 133 GrGLStandard api, |
| 141 int samples, | 134 int samples, |
| 142 bool dfText, | 135 bool dfText, |
| 143 bool threaded) | 136 bool threaded) |
| 144 : fContextType(ct) | 137 : fContextType(ct) |
| 145 , fGpuAPI(api) | 138 , fGpuAPI(api) |
| 146 , fSampleCount(samples) | 139 , fSampleCount(samples) |
| 147 , fUseDFText(dfText) | 140 , fUseDFText(dfText) |
| 148 , fThreaded(threaded) {} | 141 , fThreaded(threaded) {} |
| 149 | 142 |
| 150 int GPUSink::enclave() const { | 143 int GPUSink::enclave() const { |
| 151 return fThreaded ? kAnyThread_Enclave : kGPU_Enclave; | 144 return fThreaded ? kAnyThread_Enclave : kGPU_Enclave; |
| 152 } | 145 } |
| 153 | 146 |
| 154 Error GPUSink::draw(const Src& src, SkBitmap* dst, SkWStream*) const { | 147 Error GPUSink::draw(const Src& src, SkBitmap* dst, SkWStream*) const { |
| 155 GrContextFactory factory; | 148 GrContextFactory factory; |
| 156 const SkISize size = limit_raster_dimensions(src.size()); | 149 const SkISize size = src.size(); |
| 157 const SkImageInfo info = | 150 const SkImageInfo info = |
| 158 SkImageInfo::Make(size.width(), size.height(), kN32_SkColorType, kPremul
_SkAlphaType); | 151 SkImageInfo::Make(size.width(), size.height(), kN32_SkColorType, kPremul
_SkAlphaType); |
| 159 SkAutoTUnref<SkSurface> surface( | 152 SkAutoTUnref<SkSurface> surface( |
| 160 NewGpuSurface(&factory, fContextType, fGpuAPI, info, fSampleCount, f
UseDFText)); | 153 NewGpuSurface(&factory, fContextType, fGpuAPI, info, fSampleCount, f
UseDFText)); |
| 161 if (!surface) { | 154 if (!surface) { |
| 162 return "Could not create a surface."; | 155 return "Could not create a surface."; |
| 163 } | 156 } |
| 164 SkCanvas* canvas = surface->getCanvas(); | 157 SkCanvas* canvas = surface->getCanvas(); |
| 165 Error err = src.draw(canvas); | 158 Error err = src.draw(canvas); |
| 166 if (!err.isEmpty()) { | 159 if (!err.isEmpty()) { |
| (...skipping 26 matching lines...) Expand all Loading... |
| 193 doc->endPage(); | 186 doc->endPage(); |
| 194 doc->close(); | 187 doc->close(); |
| 195 return ""; | 188 return ""; |
| 196 } | 189 } |
| 197 | 190 |
| 198 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~*/ | 191 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~*/ |
| 199 | 192 |
| 200 RasterSink::RasterSink(SkColorType colorType) : fColorType(colorType) {} | 193 RasterSink::RasterSink(SkColorType colorType) : fColorType(colorType) {} |
| 201 | 194 |
| 202 Error RasterSink::draw(const Src& src, SkBitmap* dst, SkWStream*) const { | 195 Error RasterSink::draw(const Src& src, SkBitmap* dst, SkWStream*) const { |
| 203 const SkISize size = limit_raster_dimensions(src.size()); | 196 const SkISize size = src.size(); |
| 204 // If there's an appropriate alpha type for this color type, use it, otherwi
se use premul. | 197 // If there's an appropriate alpha type for this color type, use it, otherwi
se use premul. |
| 205 SkAlphaType alphaType = kPremul_SkAlphaType; | 198 SkAlphaType alphaType = kPremul_SkAlphaType; |
| 206 (void)SkColorTypeValidateAlphaType(fColorType, alphaType, &alphaType); | 199 (void)SkColorTypeValidateAlphaType(fColorType, alphaType, &alphaType); |
| 207 | 200 |
| 208 dst->allocPixels(SkImageInfo::Make(size.width(), size.height(), fColorType,
alphaType)); | 201 dst->allocPixels(SkImageInfo::Make(size.width(), size.height(), fColorType,
alphaType)); |
| 209 dst->eraseColor(SK_ColorTRANSPARENT); | 202 dst->eraseColor(SK_ColorTRANSPARENT); |
| 210 SkCanvas canvas(*dst); | 203 SkCanvas canvas(*dst); |
| 211 return src.draw(&canvas); | 204 return src.draw(&canvas); |
| 212 } | 205 } |
| 213 | 206 |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 surfaces.unrefAll(); | 345 surfaces.unrefAll(); |
| 353 return ""; | 346 return ""; |
| 354 } | 347 } |
| 355 SkISize size() const SK_OVERRIDE { return fSize; } | 348 SkISize size() const SK_OVERRIDE { return fSize; } |
| 356 Name name() const SK_OVERRIDE { sk_throw(); return ""; } // No one shou
ld be calling this. | 349 Name name() const SK_OVERRIDE { sk_throw(); return ""; } // No one shou
ld be calling this. |
| 357 } proxy(fW, fH, pic, src.size()); | 350 } proxy(fW, fH, pic, src.size()); |
| 358 return fSink->draw(proxy, bitmap, stream); | 351 return fSink->draw(proxy, bitmap, stream); |
| 359 } | 352 } |
| 360 | 353 |
| 361 } // namespace DM | 354 } // namespace DM |
| OLD | NEW |