blob: b0df70b12488b0ecfceb8e8c6220a3dd3414a82a [file] [log] [blame]
mtklein748ca3b2015-01-15 10:56:12 -08001#include "DMSrcSink.h"
2#include "SamplePipeControllers.h"
3#include "SkCommonFlags.h"
4#include "SkDocument.h"
5#include "SkMultiPictureDraw.h"
6#include "SkOSFile.h"
7#include "SkPictureRecorder.h"
8#include "SkRandom.h"
fmalita2aafe6f2015-02-06 12:51:10 -08009#include "SkSVGCanvas.h"
scroggoa1193e42015-01-21 12:09:53 -080010#include "SkStream.h"
fmalita2aafe6f2015-02-06 12:51:10 -080011#include "SkXMLWriter.h"
mtklein748ca3b2015-01-15 10:56:12 -080012
13namespace DM {
14
mtklein748ca3b2015-01-15 10:56:12 -080015GMSrc::GMSrc(skiagm::GMRegistry::Factory factory) : fFactory(factory) {}
16
17Error GMSrc::draw(SkCanvas* canvas) const {
18 SkAutoTDelete<skiagm::GM> gm(fFactory(NULL));
19 canvas->concat(gm->getInitialTransform());
20 gm->draw(canvas);
21 return "";
22}
23
24SkISize GMSrc::size() const {
25 SkAutoTDelete<skiagm::GM> gm(fFactory(NULL));
26 return gm->getISize();
27}
28
29Name GMSrc::name() const {
30 SkAutoTDelete<skiagm::GM> gm(fFactory(NULL));
31 return gm->getName();
32}
33
34/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
35
mtkleinedc93bc2015-01-30 13:22:23 -080036ImageSrc::ImageSrc(Path path, int divisor) : fPath(path), fDivisor(divisor) {}
mtklein748ca3b2015-01-15 10:56:12 -080037
38Error ImageSrc::draw(SkCanvas* canvas) const {
mtklein75d98fd2015-01-18 07:05:01 -080039 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str()));
mtklein748ca3b2015-01-15 10:56:12 -080040 if (!encoded) {
41 return SkStringPrintf("Couldn't read %s.", fPath.c_str());
42 }
mtkleinedc93bc2015-01-30 13:22:23 -080043 const SkColorType dstColorType = canvas->imageInfo().colorType();
44 if (fDivisor == 0) {
mtklein748ca3b2015-01-15 10:56:12 -080045 // Decode the full image.
46 SkBitmap bitmap;
mtkleinedc93bc2015-01-30 13:22:23 -080047 if (!SkImageDecoder::DecodeMemory(encoded->data(), encoded->size(), &bitmap,
48 dstColorType, SkImageDecoder::kDecodePixels_Mode)) {
mtklein748ca3b2015-01-15 10:56:12 -080049 return SkStringPrintf("Couldn't decode %s.", fPath.c_str());
50 }
mtklein75d98fd2015-01-18 07:05:01 -080051 encoded.reset((SkData*)NULL); // Might as well drop this when we're done with it.
mtklein748ca3b2015-01-15 10:56:12 -080052 canvas->drawBitmap(bitmap, 0,0);
53 return "";
54 }
mtkleinedc93bc2015-01-30 13:22:23 -080055 // Decode subsets. This is a little involved.
scroggoa1193e42015-01-21 12:09:53 -080056 SkAutoTDelete<SkMemoryStream> stream(new SkMemoryStream(encoded));
57 SkAutoTDelete<SkImageDecoder> decoder(SkImageDecoder::Factory(stream.get()));
mtklein748ca3b2015-01-15 10:56:12 -080058 if (!decoder) {
59 return SkStringPrintf("Can't find a good decoder for %s.", fPath.c_str());
60 }
scroggoa1193e42015-01-21 12:09:53 -080061 stream->rewind();
mtklein748ca3b2015-01-15 10:56:12 -080062 int w,h;
scroggoa1193e42015-01-21 12:09:53 -080063 if (!decoder->buildTileIndex(stream.detach(), &w, &h) || w*h == 1) {
mtklein748ca3b2015-01-15 10:56:12 -080064 return ""; // Not an error. Subset decoding is not always supported.
65 }
mtkleinedc93bc2015-01-30 13:22:23 -080066
67 // Divide the image into subsets that cover the entire image.
68 if (fDivisor > w || fDivisor > h) {
69 return SkStringPrintf("divisor %d is too big for %s with dimensions (%d x %d)",
70 fDivisor, fPath.c_str(), w, h);
71 }
72 const int subsetWidth = w / fDivisor,
73 subsetHeight = h / fDivisor;
74 for (int y = 0; y < h; y += subsetHeight) {
75 for (int x = 0; x < w; x += subsetWidth) {
76 SkBitmap subset;
77 SkIRect rect = SkIRect::MakeXYWH(x, y, subsetWidth, subsetHeight);
78 if (!decoder->decodeSubset(&subset, rect, dstColorType)) {
79 return SkStringPrintf("Could not decode subset (%d, %d, %d, %d).",
80 x, y, x+subsetWidth, y+subsetHeight);
81 }
82 canvas->drawBitmap(subset, SkIntToScalar(x), SkIntToScalar(y));
mtklein748ca3b2015-01-15 10:56:12 -080083 }
mtklein748ca3b2015-01-15 10:56:12 -080084 }
85 return "";
86}
87
88SkISize ImageSrc::size() const {
mtklein75d98fd2015-01-18 07:05:01 -080089 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str()));
mtklein748ca3b2015-01-15 10:56:12 -080090 SkBitmap bitmap;
91 if (!encoded || !SkImageDecoder::DecodeMemory(encoded->data(),
92 encoded->size(),
93 &bitmap,
94 kUnknown_SkColorType,
95 SkImageDecoder::kDecodeBounds_Mode)) {
96 return SkISize::Make(0,0);
97 }
98 return bitmap.dimensions();
99}
100
mtklein9264a952015-01-20 10:11:53 -0800101Name ImageSrc::name() const {
mtkleinedc93bc2015-01-30 13:22:23 -0800102 return SkOSPath::Basename(fPath.c_str());
mtklein9264a952015-01-20 10:11:53 -0800103}
mtklein748ca3b2015-01-15 10:56:12 -0800104
105/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
106
mtkleinf4ba3212015-01-28 15:32:24 -0800107static const SkRect kSKPViewport = {0,0, 1000,1000};
108
mtklein8d17a132015-01-30 11:42:31 -0800109SKPSrc::SKPSrc(Path path) : fPath(path) {}
mtklein748ca3b2015-01-15 10:56:12 -0800110
111Error SKPSrc::draw(SkCanvas* canvas) const {
scroggoa1193e42015-01-21 12:09:53 -0800112 SkAutoTDelete<SkStream> stream(SkStream::NewFromFile(fPath.c_str()));
mtklein75d98fd2015-01-18 07:05:01 -0800113 if (!stream) {
mtklein748ca3b2015-01-15 10:56:12 -0800114 return SkStringPrintf("Couldn't read %s.", fPath.c_str());
115 }
mtklein75d98fd2015-01-18 07:05:01 -0800116 SkAutoTUnref<SkPicture> pic(SkPicture::CreateFromStream(stream));
117 if (!pic) {
118 return SkStringPrintf("Couldn't decode %s as a picture.", fPath.c_str());
119 }
120 stream.reset((SkStream*)NULL); // Might as well drop this when we're done with it.
mtkleinf4ba3212015-01-28 15:32:24 -0800121 canvas->clipRect(kSKPViewport);
mtklein748ca3b2015-01-15 10:56:12 -0800122 canvas->drawPicture(pic);
123 return "";
124}
125
126SkISize SKPSrc::size() const {
mtkleinf4ba3212015-01-28 15:32:24 -0800127 // This may be unnecessarily large.
128 return kSKPViewport.roundOut().size();
mtklein748ca3b2015-01-15 10:56:12 -0800129}
130
131Name SKPSrc::name() const { return SkOSPath::Basename(fPath.c_str()); }
132
133/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
134
mtkleinb9eb4ac2015-02-02 18:26:03 -0800135DEFINE_bool(gpuStats, false, "Append GPU stats to the log for each GPU task?");
136
mtklein82d28432015-01-15 12:46:02 -0800137GPUSink::GPUSink(GrContextFactory::GLContextType ct,
138 GrGLStandard api,
139 int samples,
140 bool dfText,
141 bool threaded)
mtklein748ca3b2015-01-15 10:56:12 -0800142 : fContextType(ct)
143 , fGpuAPI(api)
144 , fSampleCount(samples)
mtklein82d28432015-01-15 12:46:02 -0800145 , fUseDFText(dfText)
146 , fThreaded(threaded) {}
mtklein748ca3b2015-01-15 10:56:12 -0800147
148int GPUSink::enclave() const {
mtklein55e88b22015-01-21 15:50:13 -0800149 return fThreaded ? kAnyThread_Enclave : kGPU_Enclave;
mtklein748ca3b2015-01-15 10:56:12 -0800150}
151
mtkleinb9eb4ac2015-02-02 18:26:03 -0800152Error GPUSink::draw(const Src& src, SkBitmap* dst, SkWStream*, SkString* log) const {
mtklein55e88b22015-01-21 15:50:13 -0800153 GrContextFactory factory;
mtkleinf4ba3212015-01-28 15:32:24 -0800154 const SkISize size = src.size();
mtklein748ca3b2015-01-15 10:56:12 -0800155 const SkImageInfo info =
156 SkImageInfo::Make(size.width(), size.height(), kN32_SkColorType, kPremul_SkAlphaType);
157 SkAutoTUnref<SkSurface> surface(
mtklein55e88b22015-01-21 15:50:13 -0800158 NewGpuSurface(&factory, fContextType, fGpuAPI, info, fSampleCount, fUseDFText));
mtklein748ca3b2015-01-15 10:56:12 -0800159 if (!surface) {
160 return "Could not create a surface.";
161 }
162 SkCanvas* canvas = surface->getCanvas();
163 Error err = src.draw(canvas);
164 if (!err.isEmpty()) {
165 return err;
166 }
167 canvas->flush();
mtkleinb9eb4ac2015-02-02 18:26:03 -0800168 if (FLAGS_gpuStats) {
169 canvas->getGrContext()->dumpCacheStats(log);
170 canvas->getGrContext()->dumpGpuStats(log);
171 }
mtklein748ca3b2015-01-15 10:56:12 -0800172 dst->allocPixels(info);
173 canvas->readPixels(dst, 0,0);
mtklein55e88b22015-01-21 15:50:13 -0800174 if (FLAGS_abandonGpuContext) {
175 factory.abandonContexts();
176 }
mtklein748ca3b2015-01-15 10:56:12 -0800177 return "";
178}
179
180/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
181
182PDFSink::PDFSink() {}
183
mtkleinb9eb4ac2015-02-02 18:26:03 -0800184Error PDFSink::draw(const Src& src, SkBitmap*, SkWStream* dst, SkString*) const {
halcanaryfd4a9932015-01-28 11:45:58 -0800185 // Print the given DM:Src to a PDF, breaking on 8.5x11 pages.
mtklein748ca3b2015-01-15 10:56:12 -0800186 SkAutoTUnref<SkDocument> doc(SkDocument::CreatePDF(dst));
mtklein748ca3b2015-01-15 10:56:12 -0800187
halcanaryfd4a9932015-01-28 11:45:58 -0800188 int width = src.size().width(),
189 height = src.size().height();
190
191 const int kLetterWidth = 612, // 8.5 * 72
192 kLetterHeight = 792; // 11 * 72
193 const SkRect letter = SkRect::MakeWH(SkIntToScalar(kLetterWidth),
194 SkIntToScalar(kLetterHeight));
195
196 int xPages = ((width - 1) / kLetterWidth) + 1;
197 int yPages = ((height - 1) / kLetterHeight) + 1;
198
199 for (int y = 0; y < yPages; ++y) {
200 for (int x = 0; x < xPages; ++x) {
201 int w = SkTMin(kLetterWidth, width - (x * kLetterWidth));
202 int h = SkTMin(kLetterHeight, height - (y * kLetterHeight));
203 SkCanvas* canvas =
204 doc->beginPage(SkIntToScalar(w), SkIntToScalar(h));
205 canvas->clipRect(letter);
206 canvas->translate(-letter.width() * x, -letter.height() * y);
207 Error err = src.draw(canvas);
208 if (!err.isEmpty()) {
209 return err;
210 }
211 doc->endPage();
212 }
mtklein748ca3b2015-01-15 10:56:12 -0800213 }
mtklein748ca3b2015-01-15 10:56:12 -0800214 doc->close();
halcanaryfd4a9932015-01-28 11:45:58 -0800215 dst->flush();
mtklein748ca3b2015-01-15 10:56:12 -0800216 return "";
217}
218
219/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
220
mtklein9c3f17d2015-01-28 11:35:18 -0800221SKPSink::SKPSink() {}
222
mtkleinb9eb4ac2015-02-02 18:26:03 -0800223Error SKPSink::draw(const Src& src, SkBitmap*, SkWStream* dst, SkString*) const {
mtklein9c3f17d2015-01-28 11:35:18 -0800224 SkSize size;
225 size = src.size();
226 SkPictureRecorder recorder;
227 Error err = src.draw(recorder.beginRecording(size.width(), size.height()));
228 if (!err.isEmpty()) {
229 return err;
230 }
231 SkAutoTUnref<SkPicture> pic(recorder.endRecording());
232 pic->serialize(dst);
233 return "";
234}
235
236/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
237
mtklein8a4527e2015-01-31 20:00:58 -0800238SVGSink::SVGSink() {}
239
mtkleinb9eb4ac2015-02-02 18:26:03 -0800240Error SVGSink::draw(const Src& src, SkBitmap*, SkWStream* dst, SkString*) const {
fmalita2aafe6f2015-02-06 12:51:10 -0800241 SkAutoTDelete<SkXMLWriter> xmlWriter(SkNEW_ARGS(SkXMLStreamWriter, (dst)));
242 SkAutoTUnref<SkCanvas> canvas(SkSVGCanvas::Create(
243 SkRect::MakeWH(SkIntToScalar(src.size().width()), SkIntToScalar(src.size().height())),
244 xmlWriter));
245 return src.draw(canvas);
mtklein8a4527e2015-01-31 20:00:58 -0800246}
247
248/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
249
mtklein748ca3b2015-01-15 10:56:12 -0800250RasterSink::RasterSink(SkColorType colorType) : fColorType(colorType) {}
251
mtkleinb9eb4ac2015-02-02 18:26:03 -0800252Error RasterSink::draw(const Src& src, SkBitmap* dst, SkWStream*, SkString*) const {
mtkleinf4ba3212015-01-28 15:32:24 -0800253 const SkISize size = src.size();
mtklein748ca3b2015-01-15 10:56:12 -0800254 // If there's an appropriate alpha type for this color type, use it, otherwise use premul.
255 SkAlphaType alphaType = kPremul_SkAlphaType;
256 (void)SkColorTypeValidateAlphaType(fColorType, alphaType, &alphaType);
257
258 dst->allocPixels(SkImageInfo::Make(size.width(), size.height(), fColorType, alphaType));
259 dst->eraseColor(SK_ColorTRANSPARENT);
260 SkCanvas canvas(*dst);
261 return src.draw(&canvas);
262}
263
264/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
265
266ViaMatrix::ViaMatrix(SkMatrix matrix, Sink* sink) : fMatrix(matrix), fSink(sink) {}
267
mtkleinb9eb4ac2015-02-02 18:26:03 -0800268Error ViaMatrix::draw(const Src& src, SkBitmap* bitmap, SkWStream* stream, SkString* log) const {
mtklein748ca3b2015-01-15 10:56:12 -0800269 // We turn our arguments into a Src, then draw that Src into our Sink to fill bitmap or stream.
270 struct ProxySrc : public Src {
271 const Src& fSrc;
272 SkMatrix fMatrix;
273 ProxySrc(const Src& src, SkMatrix matrix) : fSrc(src), fMatrix(matrix) {}
274
275 Error draw(SkCanvas* canvas) const SK_OVERRIDE {
276 canvas->concat(fMatrix);
277 return fSrc.draw(canvas);
278 }
279 SkISize size() const SK_OVERRIDE { return fSrc.size(); }
280 Name name() const SK_OVERRIDE { sk_throw(); return ""; } // No one should be calling this.
281 } proxy(src, fMatrix);
mtkleinb9eb4ac2015-02-02 18:26:03 -0800282 return fSink->draw(proxy, bitmap, stream, log);
mtklein748ca3b2015-01-15 10:56:12 -0800283}
284
285/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
286
mtklein7edca212015-01-21 13:18:51 -0800287ViaPipe::ViaPipe(Sink* sink) : fSink(sink) {}
mtklein748ca3b2015-01-15 10:56:12 -0800288
mtkleinb9eb4ac2015-02-02 18:26:03 -0800289Error ViaPipe::draw(const Src& src, SkBitmap* bitmap, SkWStream* stream, SkString* log) const {
mtklein7edca212015-01-21 13:18:51 -0800290 // We turn ourselves into another Src that draws our argument into bitmap/stream via pipe.
mtklein748ca3b2015-01-15 10:56:12 -0800291 struct ProxySrc : public Src {
292 const Src& fSrc;
mtklein7edca212015-01-21 13:18:51 -0800293 ProxySrc(const Src& src) : fSrc(src) {}
mtklein748ca3b2015-01-15 10:56:12 -0800294
295 Error draw(SkCanvas* canvas) const SK_OVERRIDE {
296 SkISize size = this->size();
mtklein748ca3b2015-01-15 10:56:12 -0800297 PipeController controller(canvas, &SkImageDecoder::DecodeMemory);
298 SkGPipeWriter pipe;
mtklein7edca212015-01-21 13:18:51 -0800299 const uint32_t kFlags = 0; // We mirror SkDeferredCanvas, which doesn't use any flags.
300 return fSrc.draw(pipe.startRecording(&controller, kFlags, size.width(), size.height()));
mtklein748ca3b2015-01-15 10:56:12 -0800301 }
302 SkISize size() const SK_OVERRIDE { return fSrc.size(); }
303 Name name() const SK_OVERRIDE { sk_throw(); return ""; } // No one should be calling this.
mtklein7edca212015-01-21 13:18:51 -0800304 } proxy(src);
mtkleinb9eb4ac2015-02-02 18:26:03 -0800305 return fSink->draw(proxy, bitmap, stream, log);
mtklein748ca3b2015-01-15 10:56:12 -0800306}
307
308/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
309
310ViaSerialization::ViaSerialization(Sink* sink) : fSink(sink) {}
311
mtkleinb9eb4ac2015-02-02 18:26:03 -0800312Error ViaSerialization::draw(const Src& src, SkBitmap* bitmap, SkWStream* stream, SkString* log)
313 const {
mtklein748ca3b2015-01-15 10:56:12 -0800314 // Record our Src into a picture.
315 SkSize size;
316 size = src.size();
317 SkPictureRecorder recorder;
318 Error err = src.draw(recorder.beginRecording(size.width(), size.height()));
319 if (!err.isEmpty()) {
320 return err;
321 }
322 SkAutoTUnref<SkPicture> pic(recorder.endRecording());
323
324 // Serialize it and then deserialize it.
325 SkDynamicMemoryWStream wStream;
326 pic->serialize(&wStream);
scroggoa1193e42015-01-21 12:09:53 -0800327 SkAutoTDelete<SkStream> rStream(wStream.detachAsStream());
mtklein748ca3b2015-01-15 10:56:12 -0800328 SkAutoTUnref<SkPicture> deserialized(SkPicture::CreateFromStream(rStream));
329
330 // Turn that deserialized picture into a Src, draw it into our Sink to fill bitmap or stream.
331 struct ProxySrc : public Src {
332 const SkPicture* fPic;
333 const SkISize fSize;
334 ProxySrc(const SkPicture* pic, SkISize size) : fPic(pic), fSize(size) {}
335
336 Error draw(SkCanvas* canvas) const SK_OVERRIDE {
337 canvas->drawPicture(fPic);
338 return "";
339 }
340 SkISize size() const SK_OVERRIDE { return fSize; }
341 Name name() const SK_OVERRIDE { sk_throw(); return ""; } // No one should be calling this.
342 } proxy(deserialized, src.size());
mtkleinb9eb4ac2015-02-02 18:26:03 -0800343 return fSink->draw(proxy, bitmap, stream, log);
mtklein748ca3b2015-01-15 10:56:12 -0800344}
345
346/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
347
348ViaTiles::ViaTiles(int w, int h, SkBBHFactory* factory, Sink* sink)
349 : fW(w)
350 , fH(h)
351 , fFactory(factory)
352 , fSink(sink) {}
353
mtkleinb9eb4ac2015-02-02 18:26:03 -0800354Error ViaTiles::draw(const Src& src, SkBitmap* bitmap, SkWStream* stream, SkString* log) const {
mtklein748ca3b2015-01-15 10:56:12 -0800355 // Record our Src into a picture.
356 SkSize size;
357 size = src.size();
358 SkPictureRecorder recorder;
359 Error err = src.draw(recorder.beginRecording(size.width(), size.height(), fFactory.get()));
360 if (!err.isEmpty()) {
361 return err;
362 }
363 SkAutoTUnref<SkPicture> pic(recorder.endRecording());
364
365 // Turn that picture into a Src that draws into our Sink via tiles + MPD.
366 struct ProxySrc : public Src {
367 const int fW, fH;
368 const SkPicture* fPic;
369 const SkISize fSize;
370 ProxySrc(int w, int h, const SkPicture* pic, SkISize size)
371 : fW(w), fH(h), fPic(pic), fSize(size) {}
372
373 Error draw(SkCanvas* canvas) const SK_OVERRIDE {
374 const int xTiles = (fSize.width() + fW - 1) / fW,
375 yTiles = (fSize.height() + fH - 1) / fH;
376 SkMultiPictureDraw mpd(xTiles*yTiles);
377 SkTDArray<SkSurface*> surfaces;
378 surfaces.setReserve(xTiles*yTiles);
379
380 SkImageInfo info = canvas->imageInfo().makeWH(fW, fH);
381 for (int j = 0; j < yTiles; j++) {
382 for (int i = 0; i < xTiles; i++) {
383 // This lets our ultimate Sink determine the best kind of surface.
384 // E.g., if it's a GpuSink, the surfaces and images are textures.
385 SkSurface* s = canvas->newSurface(info);
386 if (!s) {
387 s = SkSurface::NewRaster(info); // Some canvases can't create surfaces.
388 }
389 surfaces.push(s);
390 SkCanvas* c = s->getCanvas();
391 c->translate(SkIntToScalar(-i * fW),
392 SkIntToScalar(-j * fH)); // Line up the canvas with this tile.
393 mpd.add(c, fPic);
394 }
395 }
396 mpd.draw();
397 for (int j = 0; j < yTiles; j++) {
398 for (int i = 0; i < xTiles; i++) {
399 SkAutoTUnref<SkImage> image(surfaces[i+xTiles*j]->newImageSnapshot());
400 canvas->drawImage(image, SkIntToScalar(i*fW), SkIntToScalar(j*fH));
401 }
402 }
403 surfaces.unrefAll();
404 return "";
405 }
406 SkISize size() const SK_OVERRIDE { return fSize; }
407 Name name() const SK_OVERRIDE { sk_throw(); return ""; } // No one should be calling this.
408 } proxy(fW, fH, pic, src.size());
mtkleinb9eb4ac2015-02-02 18:26:03 -0800409 return fSink->draw(proxy, bitmap, stream, log);
mtklein748ca3b2015-01-15 10:56:12 -0800410}
411
412} // namespace DM