blob: 83705733b8d2b9098063f07e704619a1aa0487ba [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"
mtklein8a4527e2015-01-31 20:00:58 -08009#include "SkSVGDevice.h"
scroggoa1193e42015-01-21 12:09:53 -080010#include "SkStream.h"
mtklein748ca3b2015-01-15 10:56:12 -080011
12namespace DM {
13
mtklein748ca3b2015-01-15 10:56:12 -080014GMSrc::GMSrc(skiagm::GMRegistry::Factory factory) : fFactory(factory) {}
15
16Error GMSrc::draw(SkCanvas* canvas) const {
17 SkAutoTDelete<skiagm::GM> gm(fFactory(NULL));
18 canvas->concat(gm->getInitialTransform());
19 gm->draw(canvas);
20 return "";
21}
22
23SkISize GMSrc::size() const {
24 SkAutoTDelete<skiagm::GM> gm(fFactory(NULL));
25 return gm->getISize();
26}
27
28Name GMSrc::name() const {
29 SkAutoTDelete<skiagm::GM> gm(fFactory(NULL));
30 return gm->getName();
31}
32
33/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
34
mtkleinedc93bc2015-01-30 13:22:23 -080035ImageSrc::ImageSrc(Path path, int divisor) : fPath(path), fDivisor(divisor) {}
mtklein748ca3b2015-01-15 10:56:12 -080036
37Error ImageSrc::draw(SkCanvas* canvas) const {
mtklein75d98fd2015-01-18 07:05:01 -080038 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str()));
mtklein748ca3b2015-01-15 10:56:12 -080039 if (!encoded) {
40 return SkStringPrintf("Couldn't read %s.", fPath.c_str());
41 }
mtkleinedc93bc2015-01-30 13:22:23 -080042 const SkColorType dstColorType = canvas->imageInfo().colorType();
43 if (fDivisor == 0) {
mtklein748ca3b2015-01-15 10:56:12 -080044 // Decode the full image.
45 SkBitmap bitmap;
mtkleinedc93bc2015-01-30 13:22:23 -080046 if (!SkImageDecoder::DecodeMemory(encoded->data(), encoded->size(), &bitmap,
47 dstColorType, SkImageDecoder::kDecodePixels_Mode)) {
mtklein748ca3b2015-01-15 10:56:12 -080048 return SkStringPrintf("Couldn't decode %s.", fPath.c_str());
49 }
mtklein75d98fd2015-01-18 07:05:01 -080050 encoded.reset((SkData*)NULL); // Might as well drop this when we're done with it.
mtklein748ca3b2015-01-15 10:56:12 -080051 canvas->drawBitmap(bitmap, 0,0);
52 return "";
53 }
mtkleinedc93bc2015-01-30 13:22:23 -080054 // Decode subsets. This is a little involved.
scroggoa1193e42015-01-21 12:09:53 -080055 SkAutoTDelete<SkMemoryStream> stream(new SkMemoryStream(encoded));
56 SkAutoTDelete<SkImageDecoder> decoder(SkImageDecoder::Factory(stream.get()));
mtklein748ca3b2015-01-15 10:56:12 -080057 if (!decoder) {
58 return SkStringPrintf("Can't find a good decoder for %s.", fPath.c_str());
59 }
scroggoa1193e42015-01-21 12:09:53 -080060 stream->rewind();
mtklein748ca3b2015-01-15 10:56:12 -080061 int w,h;
scroggoa1193e42015-01-21 12:09:53 -080062 if (!decoder->buildTileIndex(stream.detach(), &w, &h) || w*h == 1) {
mtklein748ca3b2015-01-15 10:56:12 -080063 return ""; // Not an error. Subset decoding is not always supported.
64 }
mtkleinedc93bc2015-01-30 13:22:23 -080065
66 // Divide the image into subsets that cover the entire image.
67 if (fDivisor > w || fDivisor > h) {
68 return SkStringPrintf("divisor %d is too big for %s with dimensions (%d x %d)",
69 fDivisor, fPath.c_str(), w, h);
70 }
71 const int subsetWidth = w / fDivisor,
72 subsetHeight = h / fDivisor;
73 for (int y = 0; y < h; y += subsetHeight) {
74 for (int x = 0; x < w; x += subsetWidth) {
75 SkBitmap subset;
76 SkIRect rect = SkIRect::MakeXYWH(x, y, subsetWidth, subsetHeight);
77 if (!decoder->decodeSubset(&subset, rect, dstColorType)) {
78 return SkStringPrintf("Could not decode subset (%d, %d, %d, %d).",
79 x, y, x+subsetWidth, y+subsetHeight);
80 }
81 canvas->drawBitmap(subset, SkIntToScalar(x), SkIntToScalar(y));
mtklein748ca3b2015-01-15 10:56:12 -080082 }
mtklein748ca3b2015-01-15 10:56:12 -080083 }
84 return "";
85}
86
87SkISize ImageSrc::size() const {
mtklein75d98fd2015-01-18 07:05:01 -080088 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str()));
mtklein748ca3b2015-01-15 10:56:12 -080089 SkBitmap bitmap;
90 if (!encoded || !SkImageDecoder::DecodeMemory(encoded->data(),
91 encoded->size(),
92 &bitmap,
93 kUnknown_SkColorType,
94 SkImageDecoder::kDecodeBounds_Mode)) {
95 return SkISize::Make(0,0);
96 }
97 return bitmap.dimensions();
98}
99
mtklein9264a952015-01-20 10:11:53 -0800100Name ImageSrc::name() const {
mtkleinedc93bc2015-01-30 13:22:23 -0800101 return SkOSPath::Basename(fPath.c_str());
mtklein9264a952015-01-20 10:11:53 -0800102}
mtklein748ca3b2015-01-15 10:56:12 -0800103
104/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
105
mtkleinf4ba3212015-01-28 15:32:24 -0800106static const SkRect kSKPViewport = {0,0, 1000,1000};
107
mtklein8d17a132015-01-30 11:42:31 -0800108SKPSrc::SKPSrc(Path path) : fPath(path) {}
mtklein748ca3b2015-01-15 10:56:12 -0800109
110Error SKPSrc::draw(SkCanvas* canvas) const {
scroggoa1193e42015-01-21 12:09:53 -0800111 SkAutoTDelete<SkStream> stream(SkStream::NewFromFile(fPath.c_str()));
mtklein75d98fd2015-01-18 07:05:01 -0800112 if (!stream) {
mtklein748ca3b2015-01-15 10:56:12 -0800113 return SkStringPrintf("Couldn't read %s.", fPath.c_str());
114 }
mtklein75d98fd2015-01-18 07:05:01 -0800115 SkAutoTUnref<SkPicture> pic(SkPicture::CreateFromStream(stream));
116 if (!pic) {
117 return SkStringPrintf("Couldn't decode %s as a picture.", fPath.c_str());
118 }
119 stream.reset((SkStream*)NULL); // Might as well drop this when we're done with it.
mtkleinf4ba3212015-01-28 15:32:24 -0800120 canvas->clipRect(kSKPViewport);
mtklein748ca3b2015-01-15 10:56:12 -0800121 canvas->drawPicture(pic);
122 return "";
123}
124
125SkISize SKPSrc::size() const {
mtkleinf4ba3212015-01-28 15:32:24 -0800126 // This may be unnecessarily large.
127 return kSKPViewport.roundOut().size();
mtklein748ca3b2015-01-15 10:56:12 -0800128}
129
130Name SKPSrc::name() const { return SkOSPath::Basename(fPath.c_str()); }
131
132/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
133
mtkleinb9eb4ac2015-02-02 18:26:03 -0800134DEFINE_bool(gpuStats, false, "Append GPU stats to the log for each GPU task?");
135
mtklein82d28432015-01-15 12:46:02 -0800136GPUSink::GPUSink(GrContextFactory::GLContextType ct,
137 GrGLStandard api,
138 int samples,
139 bool dfText,
140 bool threaded)
mtklein748ca3b2015-01-15 10:56:12 -0800141 : fContextType(ct)
142 , fGpuAPI(api)
143 , fSampleCount(samples)
mtklein82d28432015-01-15 12:46:02 -0800144 , fUseDFText(dfText)
145 , fThreaded(threaded) {}
mtklein748ca3b2015-01-15 10:56:12 -0800146
147int GPUSink::enclave() const {
mtklein55e88b22015-01-21 15:50:13 -0800148 return fThreaded ? kAnyThread_Enclave : kGPU_Enclave;
mtklein748ca3b2015-01-15 10:56:12 -0800149}
150
mtkleinb9eb4ac2015-02-02 18:26:03 -0800151Error GPUSink::draw(const Src& src, SkBitmap* dst, SkWStream*, SkString* log) const {
mtklein55e88b22015-01-21 15:50:13 -0800152 GrContextFactory factory;
mtkleinf4ba3212015-01-28 15:32:24 -0800153 const SkISize size = src.size();
mtklein748ca3b2015-01-15 10:56:12 -0800154 const SkImageInfo info =
155 SkImageInfo::Make(size.width(), size.height(), kN32_SkColorType, kPremul_SkAlphaType);
156 SkAutoTUnref<SkSurface> surface(
mtklein55e88b22015-01-21 15:50:13 -0800157 NewGpuSurface(&factory, fContextType, fGpuAPI, info, fSampleCount, fUseDFText));
mtklein748ca3b2015-01-15 10:56:12 -0800158 if (!surface) {
159 return "Could not create a surface.";
160 }
161 SkCanvas* canvas = surface->getCanvas();
162 Error err = src.draw(canvas);
163 if (!err.isEmpty()) {
164 return err;
165 }
166 canvas->flush();
mtkleinb9eb4ac2015-02-02 18:26:03 -0800167 if (FLAGS_gpuStats) {
168 canvas->getGrContext()->dumpCacheStats(log);
169 canvas->getGrContext()->dumpGpuStats(log);
170 }
mtklein748ca3b2015-01-15 10:56:12 -0800171 dst->allocPixels(info);
172 canvas->readPixels(dst, 0,0);
mtklein55e88b22015-01-21 15:50:13 -0800173 if (FLAGS_abandonGpuContext) {
174 factory.abandonContexts();
175 }
mtklein748ca3b2015-01-15 10:56:12 -0800176 return "";
177}
178
179/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
180
181PDFSink::PDFSink() {}
182
mtkleinb9eb4ac2015-02-02 18:26:03 -0800183Error PDFSink::draw(const Src& src, SkBitmap*, SkWStream* dst, SkString*) const {
halcanaryfd4a9932015-01-28 11:45:58 -0800184 // Print the given DM:Src to a PDF, breaking on 8.5x11 pages.
mtklein748ca3b2015-01-15 10:56:12 -0800185 SkAutoTUnref<SkDocument> doc(SkDocument::CreatePDF(dst));
mtklein748ca3b2015-01-15 10:56:12 -0800186
halcanaryfd4a9932015-01-28 11:45:58 -0800187 int width = src.size().width(),
188 height = src.size().height();
189
190 const int kLetterWidth = 612, // 8.5 * 72
191 kLetterHeight = 792; // 11 * 72
192 const SkRect letter = SkRect::MakeWH(SkIntToScalar(kLetterWidth),
193 SkIntToScalar(kLetterHeight));
194
195 int xPages = ((width - 1) / kLetterWidth) + 1;
196 int yPages = ((height - 1) / kLetterHeight) + 1;
197
198 for (int y = 0; y < yPages; ++y) {
199 for (int x = 0; x < xPages; ++x) {
200 int w = SkTMin(kLetterWidth, width - (x * kLetterWidth));
201 int h = SkTMin(kLetterHeight, height - (y * kLetterHeight));
202 SkCanvas* canvas =
203 doc->beginPage(SkIntToScalar(w), SkIntToScalar(h));
204 canvas->clipRect(letter);
205 canvas->translate(-letter.width() * x, -letter.height() * y);
206 Error err = src.draw(canvas);
207 if (!err.isEmpty()) {
208 return err;
209 }
210 doc->endPage();
211 }
mtklein748ca3b2015-01-15 10:56:12 -0800212 }
mtklein748ca3b2015-01-15 10:56:12 -0800213 doc->close();
halcanaryfd4a9932015-01-28 11:45:58 -0800214 dst->flush();
mtklein748ca3b2015-01-15 10:56:12 -0800215 return "";
216}
217
218/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
219
mtklein9c3f17d2015-01-28 11:35:18 -0800220SKPSink::SKPSink() {}
221
mtkleinb9eb4ac2015-02-02 18:26:03 -0800222Error SKPSink::draw(const Src& src, SkBitmap*, SkWStream* dst, SkString*) const {
mtklein9c3f17d2015-01-28 11:35:18 -0800223 SkSize size;
224 size = src.size();
225 SkPictureRecorder recorder;
226 Error err = src.draw(recorder.beginRecording(size.width(), size.height()));
227 if (!err.isEmpty()) {
228 return err;
229 }
230 SkAutoTUnref<SkPicture> pic(recorder.endRecording());
231 pic->serialize(dst);
232 return "";
233}
234
235/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
236
mtklein8a4527e2015-01-31 20:00:58 -0800237SVGSink::SVGSink() {}
238
mtkleinb9eb4ac2015-02-02 18:26:03 -0800239Error SVGSink::draw(const Src& src, SkBitmap*, SkWStream* dst, SkString*) const {
mtklein8a4527e2015-01-31 20:00:58 -0800240 SkAutoTUnref<SkBaseDevice> device(SkSVGDevice::Create(src.size(), dst));
241 SkCanvas canvas(device);
242 return src.draw(&canvas);
243}
244
245/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
246
mtklein748ca3b2015-01-15 10:56:12 -0800247RasterSink::RasterSink(SkColorType colorType) : fColorType(colorType) {}
248
mtkleinb9eb4ac2015-02-02 18:26:03 -0800249Error RasterSink::draw(const Src& src, SkBitmap* dst, SkWStream*, SkString*) const {
mtkleinf4ba3212015-01-28 15:32:24 -0800250 const SkISize size = src.size();
mtklein748ca3b2015-01-15 10:56:12 -0800251 // If there's an appropriate alpha type for this color type, use it, otherwise use premul.
252 SkAlphaType alphaType = kPremul_SkAlphaType;
253 (void)SkColorTypeValidateAlphaType(fColorType, alphaType, &alphaType);
254
255 dst->allocPixels(SkImageInfo::Make(size.width(), size.height(), fColorType, alphaType));
256 dst->eraseColor(SK_ColorTRANSPARENT);
257 SkCanvas canvas(*dst);
258 return src.draw(&canvas);
259}
260
261/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
262
263ViaMatrix::ViaMatrix(SkMatrix matrix, Sink* sink) : fMatrix(matrix), fSink(sink) {}
264
mtkleinb9eb4ac2015-02-02 18:26:03 -0800265Error ViaMatrix::draw(const Src& src, SkBitmap* bitmap, SkWStream* stream, SkString* log) const {
mtklein748ca3b2015-01-15 10:56:12 -0800266 // We turn our arguments into a Src, then draw that Src into our Sink to fill bitmap or stream.
267 struct ProxySrc : public Src {
268 const Src& fSrc;
269 SkMatrix fMatrix;
270 ProxySrc(const Src& src, SkMatrix matrix) : fSrc(src), fMatrix(matrix) {}
271
272 Error draw(SkCanvas* canvas) const SK_OVERRIDE {
273 canvas->concat(fMatrix);
274 return fSrc.draw(canvas);
275 }
276 SkISize size() const SK_OVERRIDE { return fSrc.size(); }
277 Name name() const SK_OVERRIDE { sk_throw(); return ""; } // No one should be calling this.
278 } proxy(src, fMatrix);
mtkleinb9eb4ac2015-02-02 18:26:03 -0800279 return fSink->draw(proxy, bitmap, stream, log);
mtklein748ca3b2015-01-15 10:56:12 -0800280}
281
282/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
283
mtklein7edca212015-01-21 13:18:51 -0800284ViaPipe::ViaPipe(Sink* sink) : fSink(sink) {}
mtklein748ca3b2015-01-15 10:56:12 -0800285
mtkleinb9eb4ac2015-02-02 18:26:03 -0800286Error ViaPipe::draw(const Src& src, SkBitmap* bitmap, SkWStream* stream, SkString* log) const {
mtklein7edca212015-01-21 13:18:51 -0800287 // We turn ourselves into another Src that draws our argument into bitmap/stream via pipe.
mtklein748ca3b2015-01-15 10:56:12 -0800288 struct ProxySrc : public Src {
289 const Src& fSrc;
mtklein7edca212015-01-21 13:18:51 -0800290 ProxySrc(const Src& src) : fSrc(src) {}
mtklein748ca3b2015-01-15 10:56:12 -0800291
292 Error draw(SkCanvas* canvas) const SK_OVERRIDE {
293 SkISize size = this->size();
mtklein748ca3b2015-01-15 10:56:12 -0800294 PipeController controller(canvas, &SkImageDecoder::DecodeMemory);
295 SkGPipeWriter pipe;
mtklein7edca212015-01-21 13:18:51 -0800296 const uint32_t kFlags = 0; // We mirror SkDeferredCanvas, which doesn't use any flags.
297 return fSrc.draw(pipe.startRecording(&controller, kFlags, size.width(), size.height()));
mtklein748ca3b2015-01-15 10:56:12 -0800298 }
299 SkISize size() const SK_OVERRIDE { return fSrc.size(); }
300 Name name() const SK_OVERRIDE { sk_throw(); return ""; } // No one should be calling this.
mtklein7edca212015-01-21 13:18:51 -0800301 } proxy(src);
mtkleinb9eb4ac2015-02-02 18:26:03 -0800302 return fSink->draw(proxy, bitmap, stream, log);
mtklein748ca3b2015-01-15 10:56:12 -0800303}
304
305/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
306
307ViaSerialization::ViaSerialization(Sink* sink) : fSink(sink) {}
308
mtkleinb9eb4ac2015-02-02 18:26:03 -0800309Error ViaSerialization::draw(const Src& src, SkBitmap* bitmap, SkWStream* stream, SkString* log)
310 const {
mtklein748ca3b2015-01-15 10:56:12 -0800311 // Record our Src into a picture.
312 SkSize size;
313 size = src.size();
314 SkPictureRecorder recorder;
315 Error err = src.draw(recorder.beginRecording(size.width(), size.height()));
316 if (!err.isEmpty()) {
317 return err;
318 }
319 SkAutoTUnref<SkPicture> pic(recorder.endRecording());
320
321 // Serialize it and then deserialize it.
322 SkDynamicMemoryWStream wStream;
323 pic->serialize(&wStream);
scroggoa1193e42015-01-21 12:09:53 -0800324 SkAutoTDelete<SkStream> rStream(wStream.detachAsStream());
mtklein748ca3b2015-01-15 10:56:12 -0800325 SkAutoTUnref<SkPicture> deserialized(SkPicture::CreateFromStream(rStream));
326
327 // Turn that deserialized picture into a Src, draw it into our Sink to fill bitmap or stream.
328 struct ProxySrc : public Src {
329 const SkPicture* fPic;
330 const SkISize fSize;
331 ProxySrc(const SkPicture* pic, SkISize size) : fPic(pic), fSize(size) {}
332
333 Error draw(SkCanvas* canvas) const SK_OVERRIDE {
334 canvas->drawPicture(fPic);
335 return "";
336 }
337 SkISize size() const SK_OVERRIDE { return fSize; }
338 Name name() const SK_OVERRIDE { sk_throw(); return ""; } // No one should be calling this.
339 } proxy(deserialized, src.size());
mtkleinb9eb4ac2015-02-02 18:26:03 -0800340 return fSink->draw(proxy, bitmap, stream, log);
mtklein748ca3b2015-01-15 10:56:12 -0800341}
342
343/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
344
345ViaTiles::ViaTiles(int w, int h, SkBBHFactory* factory, Sink* sink)
346 : fW(w)
347 , fH(h)
348 , fFactory(factory)
349 , fSink(sink) {}
350
mtkleinb9eb4ac2015-02-02 18:26:03 -0800351Error ViaTiles::draw(const Src& src, SkBitmap* bitmap, SkWStream* stream, SkString* log) const {
mtklein748ca3b2015-01-15 10:56:12 -0800352 // Record our Src into a picture.
353 SkSize size;
354 size = src.size();
355 SkPictureRecorder recorder;
356 Error err = src.draw(recorder.beginRecording(size.width(), size.height(), fFactory.get()));
357 if (!err.isEmpty()) {
358 return err;
359 }
360 SkAutoTUnref<SkPicture> pic(recorder.endRecording());
361
362 // Turn that picture into a Src that draws into our Sink via tiles + MPD.
363 struct ProxySrc : public Src {
364 const int fW, fH;
365 const SkPicture* fPic;
366 const SkISize fSize;
367 ProxySrc(int w, int h, const SkPicture* pic, SkISize size)
368 : fW(w), fH(h), fPic(pic), fSize(size) {}
369
370 Error draw(SkCanvas* canvas) const SK_OVERRIDE {
371 const int xTiles = (fSize.width() + fW - 1) / fW,
372 yTiles = (fSize.height() + fH - 1) / fH;
373 SkMultiPictureDraw mpd(xTiles*yTiles);
374 SkTDArray<SkSurface*> surfaces;
375 surfaces.setReserve(xTiles*yTiles);
376
377 SkImageInfo info = canvas->imageInfo().makeWH(fW, fH);
378 for (int j = 0; j < yTiles; j++) {
379 for (int i = 0; i < xTiles; i++) {
380 // This lets our ultimate Sink determine the best kind of surface.
381 // E.g., if it's a GpuSink, the surfaces and images are textures.
382 SkSurface* s = canvas->newSurface(info);
383 if (!s) {
384 s = SkSurface::NewRaster(info); // Some canvases can't create surfaces.
385 }
386 surfaces.push(s);
387 SkCanvas* c = s->getCanvas();
388 c->translate(SkIntToScalar(-i * fW),
389 SkIntToScalar(-j * fH)); // Line up the canvas with this tile.
390 mpd.add(c, fPic);
391 }
392 }
393 mpd.draw();
394 for (int j = 0; j < yTiles; j++) {
395 for (int i = 0; i < xTiles; i++) {
396 SkAutoTUnref<SkImage> image(surfaces[i+xTiles*j]->newImageSnapshot());
397 canvas->drawImage(image, SkIntToScalar(i*fW), SkIntToScalar(j*fH));
398 }
399 }
400 surfaces.unrefAll();
401 return "";
402 }
403 SkISize size() const SK_OVERRIDE { return fSize; }
404 Name name() const SK_OVERRIDE { sk_throw(); return ""; } // No one should be calling this.
405 } proxy(fW, fH, pic, src.size());
mtkleinb9eb4ac2015-02-02 18:26:03 -0800406 return fSink->draw(proxy, bitmap, stream, log);
mtklein748ca3b2015-01-15 10:56:12 -0800407}
408
409} // namespace DM