blob: 14311c4e8844f97f1289ba67aed3973a6667f722 [file] [log] [blame]
scroggo478652e2015-03-25 07:11:02 -07001/*
2 * Copyright 2015 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
mtklein748ca3b2015-01-15 10:56:12 -08008#include "DMSrcSink.h"
Robert Phillips96601082018-05-29 16:13:26 -04009#include "DDLPromiseImageHelper.h"
10#include "DDLTileHelper.h"
Brian Salomon00a5eb82018-07-11 15:32:05 -040011#include "GrBackendSurface.h"
12#include "GrContextPriv.h"
13#include "GrGpu.h"
14#include "MemoryCache.h"
msarett9876ac52016-06-01 14:47:18 -070015#include "Resources.h"
msarett3d9d7a72015-10-21 10:27:10 -070016#include "SkAndroidCodec.h"
Hal Canary95e3c052017-01-11 12:44:43 -050017#include "SkAutoMalloc.h"
Brian Osmana76b7a92018-07-18 14:36:43 -040018#include "SkAutoPixmapStorage.h"
scroggof24f2242015-03-03 08:59:20 -080019#include "SkCodec.h"
msarettb714fb02016-01-22 14:46:42 -080020#include "SkCodecImageGenerator.h"
msarett888dc162016-05-23 10:21:17 -070021#include "SkColorSpace.h"
Mike Klein841101d2017-03-10 09:55:51 -050022#include "SkColorSpaceXformCanvas.h"
mtkleina16e69e2015-05-05 11:38:45 -070023#include "SkCommonFlags.h"
Chris Dalton040238b2017-12-18 14:22:34 -070024#include "SkCommonFlagsGpu.h"
mtkleinb3e5e4d2015-03-25 13:13:43 -070025#include "SkData.h"
Hal Canary85c7fe82016-10-25 10:33:27 -040026#include "SkDebugCanvas.h"
Robert Phillipsad8a43f2017-08-30 12:06:35 -040027#include "SkDeferredDisplayListRecorder.h"
mtklein748ca3b2015-01-15 10:56:12 -080028#include "SkDocument.h"
Brian Osmanf9810662017-08-30 10:02:10 -040029#include "SkExecutor.h"
mtkleinb3e5e4d2015-03-25 13:13:43 -070030#include "SkImageGenerator.h"
msarett18976312016-03-09 14:20:58 -080031#include "SkImageGeneratorCG.h"
msarettfc0b6d12016-03-17 13:50:17 -070032#include "SkImageGeneratorWIC.h"
Mike Reed7fcfb622018-02-09 13:26:46 -050033#include "SkImageInfoPriv.h"
mtklein8bbbb692016-08-15 12:56:00 -070034#include "SkLiteDL.h"
35#include "SkLiteRecorder.h"
Herb Derbyefe39bc2018-05-01 17:06:20 -040036#include "SkMakeUnique.h"
mtkleinc8be09a2016-01-04 18:56:57 -080037#include "SkMallocPixelRef.h"
Hal Canary45cde312017-04-03 16:06:42 -040038#include "SkMultiPictureDocumentPriv.h"
mtklein748ca3b2015-01-15 10:56:12 -080039#include "SkMultiPictureDraw.h"
mtkleinad66f9b2015-02-13 15:11:10 -080040#include "SkNullCanvas.h"
mtklein748ca3b2015-01-15 10:56:12 -080041#include "SkOSFile.h"
Ben Wagnerbf111d72016-11-07 18:05:29 -050042#include "SkOSPath.h"
msarett9e9444c2016-02-03 12:39:10 -080043#include "SkOpts.h"
Mike Reede7a58322017-12-20 14:09:20 -050044#include "SkPictureCommon.h"
mtkleinffa901a2015-03-16 10:38:07 -070045#include "SkPictureData.h"
mtklein748ca3b2015-01-15 10:56:12 -080046#include "SkPictureRecorder.h"
Hal Canary23564b92018-09-07 14:33:14 -040047#include "SkPDFDocument.h"
mtklein748ca3b2015-01-15 10:56:12 -080048#include "SkRandom.h"
mtkleind31c13d2015-05-05 12:59:56 -070049#include "SkRecordDraw.h"
50#include "SkRecorder.h"
scroggoa1193e42015-01-21 12:09:53 -080051#include "SkStream.h"
Mike Klein48b64902018-07-25 13:28:44 -040052#include "SkSurface.h"
Brian Salomonf865b052018-03-09 09:01:53 -050053#include "SkSurfaceCharacterization.h"
Kevin Lubickc456b732017-01-11 17:21:57 +000054#include "SkSwizzler.h"
Brian Salomonf865b052018-03-09 09:01:53 -050055#include "SkTLogic.h"
Robert Phillipsad8a43f2017-08-30 12:06:35 -040056#include "SkTaskGroup.h"
msarettfc0b6d12016-03-17 13:50:17 -070057#if defined(SK_BUILD_FOR_WIN)
58 #include "SkAutoCoInitialize.h"
Hal Canary5e221e72017-02-06 09:51:42 -050059 #include "SkHRESULT.h"
60 #include "SkTScopedComPtr.h"
Hal Canary23564b92018-09-07 14:33:14 -040061 #include "SkXPSDocument.h"
Hal Canary5e221e72017-02-06 09:51:42 -050062 #include <XpsObjectModel.h>
msarettfc0b6d12016-03-17 13:50:17 -070063#endif
64
Florin Malita87ccf332018-05-04 12:23:24 -040065#if defined(SK_ENABLE_SKOTTIE)
Florin Malita54f65c42018-01-16 17:04:30 -050066 #include "Skottie.h"
Florin Malitaa8316552018-11-09 16:19:44 -050067 #include "SkottieUtils.h"
Florin Malita124d5af2017-12-31 17:02:26 -050068#endif
69
fmalita718df0a2016-07-15 10:33:29 -070070#if defined(SK_XML)
Ben Wagner6ce482a2018-03-27 10:57:43 -040071 #include "SkSVGCanvas.h"
fmalitaa48f0e32016-08-04 06:26:05 -070072 #include "SkSVGDOM.h"
fmalita718df0a2016-07-15 10:33:29 -070073 #include "SkXMLWriter.h"
74#endif
Michael Ludwige8e10752018-10-01 12:42:53 -040075#include "TestUtils.h"
fmalita718df0a2016-07-15 10:33:29 -070076
Hal Canary8a001442018-09-19 11:31:27 -040077#include <cmath>
78#include <functional>
79
Brian Osman8dc68c62018-05-30 12:57:45 -040080#include "../third_party/skcms/skcms.h"
Brian Osmanc494a702018-05-23 11:52:00 -040081
halcanary7e798182015-04-14 14:06:18 -070082DEFINE_bool(multiPage, false, "For document-type backends, render the source"
83 " into multiple pages");
scroggo3ac66e92016-02-08 15:09:48 -080084DEFINE_bool(RAW_threading, true, "Allow RAW decodes to run on multiple threads?");
halcanary7e798182015-04-14 14:06:18 -070085
bsalomon3724e572016-03-30 18:56:19 -070086using sk_gpu_test::GrContextFactory;
87
mtklein748ca3b2015-01-15 10:56:12 -080088namespace DM {
89
Hal Canary972eba32018-07-30 17:07:07 -040090GMSrc::GMSrc(skiagm::GMFactory factory) : fFactory(factory) {}
mtklein748ca3b2015-01-15 10:56:12 -080091
92Error GMSrc::draw(SkCanvas* canvas) const {
Ben Wagner145dbcd2016-11-03 14:40:50 -040093 std::unique_ptr<skiagm::GM> gm(fFactory(nullptr));
mtklein748ca3b2015-01-15 10:56:12 -080094 gm->draw(canvas);
95 return "";
96}
97
98SkISize GMSrc::size() const {
Ben Wagner145dbcd2016-11-03 14:40:50 -040099 std::unique_ptr<skiagm::GM> gm(fFactory(nullptr));
mtklein748ca3b2015-01-15 10:56:12 -0800100 return gm->getISize();
101}
102
103Name GMSrc::name() const {
Ben Wagner145dbcd2016-11-03 14:40:50 -0400104 std::unique_ptr<skiagm::GM> gm(fFactory(nullptr));
mtklein748ca3b2015-01-15 10:56:12 -0800105 return gm->getName();
106}
107
bsalomon4ee6bd82015-05-27 13:23:23 -0700108void GMSrc::modifyGrContextOptions(GrContextOptions* options) const {
Ben Wagner145dbcd2016-11-03 14:40:50 -0400109 std::unique_ptr<skiagm::GM> gm(fFactory(nullptr));
bsalomon4ee6bd82015-05-27 13:23:23 -0700110 gm->modifyGrContextOptions(options);
111}
112
mtklein748ca3b2015-01-15 10:56:12 -0800113/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
114
msarettd1227a72016-05-18 06:23:57 -0700115BRDSrc::BRDSrc(Path path, Mode mode, CodecSrc::DstColorType dstColorType, uint32_t sampleSize)
msaretta5783ae2015-09-08 15:35:32 -0700116 : fPath(path)
msaretta5783ae2015-09-08 15:35:32 -0700117 , fMode(mode)
118 , fDstColorType(dstColorType)
119 , fSampleSize(sampleSize)
120{}
121
122bool BRDSrc::veto(SinkFlags flags) const {
123 // No need to test to non-raster or indirect backends.
124 return flags.type != SinkFlags::kRaster
125 || flags.approach != SinkFlags::kDirect;
126}
127
msarettd1227a72016-05-18 06:23:57 -0700128static SkBitmapRegionDecoder* create_brd(Path path) {
bungeman38d909e2016-08-02 14:40:46 -0700129 sk_sp<SkData> encoded(SkData::MakeFromFileName(path.c_str()));
msaretta5783ae2015-09-08 15:35:32 -0700130 if (!encoded) {
Ben Wagnera93a14a2017-08-28 10:34:05 -0400131 return nullptr;
msaretta5783ae2015-09-08 15:35:32 -0700132 }
reed42943c82016-09-12 12:01:44 -0700133 return SkBitmapRegionDecoder::Create(encoded, SkBitmapRegionDecoder::kAndroidCodec_Strategy);
msaretta5783ae2015-09-08 15:35:32 -0700134}
135
Matt Sarett334df3a2016-12-15 18:17:33 -0500136static inline void alpha8_to_gray8(SkBitmap* bitmap) {
137 // Android requires kGray8 bitmaps to be tagged as kAlpha8. Here we convert
138 // them back to kGray8 so our test framework can draw them correctly.
139 if (kAlpha_8_SkColorType == bitmap->info().colorType()) {
140 SkImageInfo newInfo = bitmap->info().makeColorType(kGray_8_SkColorType)
141 .makeAlphaType(kOpaque_SkAlphaType);
142 *const_cast<SkImageInfo*>(&bitmap->info()) = newInfo;
143 }
144}
145
msaretta5783ae2015-09-08 15:35:32 -0700146Error BRDSrc::draw(SkCanvas* canvas) const {
147 SkColorType colorType = canvas->imageInfo().colorType();
148 if (kRGB_565_SkColorType == colorType &&
149 CodecSrc::kGetFromCanvas_DstColorType != fDstColorType) {
150 return Error::Nonfatal("Testing non-565 to 565 is uninteresting.");
151 }
152 switch (fDstColorType) {
153 case CodecSrc::kGetFromCanvas_DstColorType:
154 break;
msaretta5783ae2015-09-08 15:35:32 -0700155 case CodecSrc::kGrayscale_Always_DstColorType:
156 colorType = kGray_8_SkColorType;
157 break;
msarett34e0ec42016-04-22 16:27:24 -0700158 default:
159 SkASSERT(false);
160 break;
msaretta5783ae2015-09-08 15:35:32 -0700161 }
162
Ben Wagner145dbcd2016-11-03 14:40:50 -0400163 std::unique_ptr<SkBitmapRegionDecoder> brd(create_brd(fPath));
msaretta5783ae2015-09-08 15:35:32 -0700164 if (nullptr == brd.get()) {
165 return Error::Nonfatal(SkStringPrintf("Could not create brd for %s.", fPath.c_str()));
166 }
167
Leon Scroggins III0118e972018-03-13 11:14:33 -0400168 auto recommendedCT = brd->computeOutputColorType(colorType);
169 if (kRGB_565_SkColorType == colorType && recommendedCT != colorType) {
170 return Error::Nonfatal("Skip decoding non-opaque to 565.");
Leon Scroggins III1dc8ecb2017-08-17 13:42:48 -0400171 }
Leon Scroggins III0118e972018-03-13 11:14:33 -0400172 colorType = recommendedCT;
173
174 auto colorSpace = brd->computeOutputColorSpace(colorType, nullptr);
Leon Scroggins III1dc8ecb2017-08-17 13:42:48 -0400175
msaretta5783ae2015-09-08 15:35:32 -0700176 const uint32_t width = brd->width();
177 const uint32_t height = brd->height();
178 // Visually inspecting very small output images is not necessary.
179 if ((width / fSampleSize <= 10 || height / fSampleSize <= 10) && 1 != fSampleSize) {
180 return Error::Nonfatal("Scaling very small images is uninteresting.");
181 }
182 switch (fMode) {
183 case kFullImage_Mode: {
msarett35e5d1b2015-10-27 12:50:25 -0700184 SkBitmap bitmap;
185 if (!brd->decodeRegion(&bitmap, nullptr, SkIRect::MakeXYWH(0, 0, width, height),
Leon Scroggins III0118e972018-03-13 11:14:33 -0400186 fSampleSize, colorType, false, colorSpace)) {
mtklein9b439152015-12-09 13:02:26 -0800187 return "Cannot decode (full) region.";
msarett35e5d1b2015-10-27 12:50:25 -0700188 }
Matt Sarett334df3a2016-12-15 18:17:33 -0500189 alpha8_to_gray8(&bitmap);
Matt Sarett8db74f12017-06-14 13:02:05 +0000190
msarett35e5d1b2015-10-27 12:50:25 -0700191 canvas->drawBitmap(bitmap, 0, 0);
msaretta5783ae2015-09-08 15:35:32 -0700192 return "";
193 }
194 case kDivisor_Mode: {
195 const uint32_t divisor = 2;
196 if (width < divisor || height < divisor) {
mtklein9b439152015-12-09 13:02:26 -0800197 return Error::Nonfatal("Divisor is larger than image dimension.");
msaretta5783ae2015-09-08 15:35:32 -0700198 }
199
200 // Use a border to test subsets that extend outside the image.
201 // We will not allow the border to be larger than the image dimensions. Allowing
202 // these large borders causes off by one errors that indicate a problem with the
203 // test suite, not a problem with the implementation.
204 const uint32_t maxBorder = SkTMin(width, height) / (fSampleSize * divisor);
205 const uint32_t scaledBorder = SkTMin(5u, maxBorder);
206 const uint32_t unscaledBorder = scaledBorder * fSampleSize;
207
208 // We may need to clear the canvas to avoid uninitialized memory.
209 // Assume we are scaling a 780x780 image with sampleSize = 8.
210 // The output image should be 97x97.
211 // Each subset will be 390x390.
212 // Each scaled subset be 48x48.
213 // Four scaled subsets will only fill a 96x96 image.
214 // The bottom row and last column will not be touched.
215 // This is an unfortunate result of our rounding rules when scaling.
216 // Maybe we need to consider testing scaled subsets without trying to
217 // combine them to match the full scaled image? Or maybe this is the
218 // best we can do?
219 canvas->clear(0);
220
221 for (uint32_t x = 0; x < divisor; x++) {
222 for (uint32_t y = 0; y < divisor; y++) {
223 // Calculate the subset dimensions
224 uint32_t subsetWidth = width / divisor;
225 uint32_t subsetHeight = height / divisor;
226 const int left = x * subsetWidth;
227 const int top = y * subsetHeight;
228
229 // Increase the size of the last subset in each row or column, when the
230 // divisor does not divide evenly into the image dimensions
231 subsetWidth += (x + 1 == divisor) ? (width % divisor) : 0;
232 subsetHeight += (y + 1 == divisor) ? (height % divisor) : 0;
233
234 // Increase the size of the subset in order to have a border on each side
235 const int decodeLeft = left - unscaledBorder;
236 const int decodeTop = top - unscaledBorder;
237 const uint32_t decodeWidth = subsetWidth + unscaledBorder * 2;
238 const uint32_t decodeHeight = subsetHeight + unscaledBorder * 2;
msarett35e5d1b2015-10-27 12:50:25 -0700239 SkBitmap bitmap;
240 if (!brd->decodeRegion(&bitmap, nullptr, SkIRect::MakeXYWH(decodeLeft,
Matt Sarett68feef42017-04-11 09:51:32 -0400241 decodeTop, decodeWidth, decodeHeight), fSampleSize, colorType, false,
Leon Scroggins III0118e972018-03-13 11:14:33 -0400242 colorSpace)) {
mtklein9b439152015-12-09 13:02:26 -0800243 return "Cannot decode region.";
msarett35e5d1b2015-10-27 12:50:25 -0700244 }
msaretta5783ae2015-09-08 15:35:32 -0700245
Matt Sarett334df3a2016-12-15 18:17:33 -0500246 alpha8_to_gray8(&bitmap);
msarett35e5d1b2015-10-27 12:50:25 -0700247 canvas->drawBitmapRect(bitmap,
msaretta5783ae2015-09-08 15:35:32 -0700248 SkRect::MakeXYWH((SkScalar) scaledBorder, (SkScalar) scaledBorder,
249 (SkScalar) (subsetWidth / fSampleSize),
250 (SkScalar) (subsetHeight / fSampleSize)),
251 SkRect::MakeXYWH((SkScalar) (left / fSampleSize),
252 (SkScalar) (top / fSampleSize),
253 (SkScalar) (subsetWidth / fSampleSize),
254 (SkScalar) (subsetHeight / fSampleSize)),
255 nullptr);
256 }
257 }
258 return "";
259 }
260 default:
261 SkASSERT(false);
mtklein9b439152015-12-09 13:02:26 -0800262 return "Error: Should not be reached.";
msaretta5783ae2015-09-08 15:35:32 -0700263 }
264}
265
266SkISize BRDSrc::size() const {
Ben Wagner145dbcd2016-11-03 14:40:50 -0400267 std::unique_ptr<SkBitmapRegionDecoder> brd(create_brd(fPath));
msaretta5783ae2015-09-08 15:35:32 -0700268 if (brd) {
Hal Canaryfafe1352017-04-11 12:12:02 -0400269 return {SkTMax(1, brd->width() / (int)fSampleSize),
270 SkTMax(1, brd->height() / (int)fSampleSize)};
msaretta5783ae2015-09-08 15:35:32 -0700271 }
Hal Canaryfafe1352017-04-11 12:12:02 -0400272 return {0, 0};
msaretta5783ae2015-09-08 15:35:32 -0700273}
274
275static SkString get_scaled_name(const Path& path, float scale) {
276 return SkStringPrintf("%s_%.3f", SkOSPath::Basename(path.c_str()).c_str(), scale);
277}
278
279Name BRDSrc::name() const {
280 // We will replicate the names used by CodecSrc so that images can
281 // be compared in Gold.
282 if (1 == fSampleSize) {
283 return SkOSPath::Basename(fPath.c_str());
284 }
msarett4b0778e2015-11-13 09:59:11 -0800285 return get_scaled_name(fPath, 1.0f / (float) fSampleSize);
msaretta5783ae2015-09-08 15:35:32 -0700286}
287
288/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
289
scroggo3ac66e92016-02-08 15:09:48 -0800290static bool serial_from_path_name(const SkString& path) {
291 if (!FLAGS_RAW_threading) {
292 static const char* const exts[] = {
293 "arw", "cr2", "dng", "nef", "nrw", "orf", "raf", "rw2", "pef", "srw",
294 "ARW", "CR2", "DNG", "NEF", "NRW", "ORF", "RAF", "RW2", "PEF", "SRW",
295 };
296 const char* actualExt = strrchr(path.c_str(), '.');
297 if (actualExt) {
298 actualExt++;
299 for (auto* ext : exts) {
300 if (0 == strcmp(ext, actualExt)) {
301 return true;
302 }
303 }
304 }
305 }
306 return false;
307}
308
scroggoc5560be2016-02-03 09:42:42 -0800309CodecSrc::CodecSrc(Path path, Mode mode, DstColorType dstColorType, SkAlphaType dstAlphaType,
310 float scale)
msarett438b2ad2015-04-09 12:43:10 -0700311 : fPath(path)
312 , fMode(mode)
313 , fDstColorType(dstColorType)
scroggoc5560be2016-02-03 09:42:42 -0800314 , fDstAlphaType(dstAlphaType)
msarett0a242972015-06-11 14:27:27 -0700315 , fScale(scale)
scroggo3ac66e92016-02-08 15:09:48 -0800316 , fRunSerially(serial_from_path_name(path))
msarett438b2ad2015-04-09 12:43:10 -0700317{}
mtklein748ca3b2015-01-15 10:56:12 -0800318
mtklein99cab4e2015-07-31 06:43:04 -0700319bool CodecSrc::veto(SinkFlags flags) const {
msarett18976312016-03-09 14:20:58 -0800320 // Test to direct raster backends (8888 and 565).
msarettb714fb02016-01-22 14:46:42 -0800321 return flags.type != SinkFlags::kRaster || flags.approach != SinkFlags::kDirect;
mtkleine0effd62015-07-29 06:37:28 -0700322}
scroggo9b77ddd2015-03-19 06:03:39 -0700323
msarett34e0ec42016-04-22 16:27:24 -0700324// Allows us to test decodes to non-native 8888.
msarettb1be46b2016-05-17 08:52:11 -0700325static void swap_rb_if_necessary(SkBitmap& bitmap, CodecSrc::DstColorType dstColorType) {
msarett34e0ec42016-04-22 16:27:24 -0700326 if (CodecSrc::kNonNative8888_Always_DstColorType != dstColorType) {
327 return;
328 }
329
330 for (int y = 0; y < bitmap.height(); y++) {
331 uint32_t* row = (uint32_t*) bitmap.getAddr(0, y);
332 SkOpts::RGBA_to_BGRA(row, row, bitmap.width());
333 }
334}
335
msarettb1be46b2016-05-17 08:52:11 -0700336static bool get_decode_info(SkImageInfo* decodeInfo, SkColorType canvasColorType,
scroggoba584892016-05-20 13:56:13 -0700337 CodecSrc::DstColorType dstColorType, SkAlphaType dstAlphaType) {
msarett3d9d7a72015-10-21 10:27:10 -0700338 switch (dstColorType) {
msarett3d9d7a72015-10-21 10:27:10 -0700339 case CodecSrc::kGrayscale_Always_DstColorType:
scroggo1a361922016-05-20 14:27:16 -0700340 if (kRGB_565_SkColorType == canvasColorType) {
msarett3d9d7a72015-10-21 10:27:10 -0700341 return false;
342 }
scroggoc5560be2016-02-03 09:42:42 -0800343 *decodeInfo = decodeInfo->makeColorType(kGray_8_SkColorType);
msarett3d9d7a72015-10-21 10:27:10 -0700344 break;
msarett34e0ec42016-04-22 16:27:24 -0700345 case CodecSrc::kNonNative8888_Always_DstColorType:
Leon Scroggins III557fbbe2017-05-23 09:37:21 -0400346 if (kRGB_565_SkColorType == canvasColorType
347 || kRGBA_F16_SkColorType == canvasColorType) {
msarett34e0ec42016-04-22 16:27:24 -0700348 return false;
349 }
350#ifdef SK_PMCOLOR_IS_RGBA
351 *decodeInfo = decodeInfo->makeColorType(kBGRA_8888_SkColorType);
352#else
353 *decodeInfo = decodeInfo->makeColorType(kRGBA_8888_SkColorType);
354#endif
355 break;
msarett3d9d7a72015-10-21 10:27:10 -0700356 default:
msarett55f7bdd2016-02-16 13:24:54 -0800357 if (kRGB_565_SkColorType == canvasColorType &&
358 kOpaque_SkAlphaType != decodeInfo->alphaType()) {
359 return false;
360 }
Matt Sarett09a1c082017-02-01 15:34:22 -0800361
scroggoc5560be2016-02-03 09:42:42 -0800362 *decodeInfo = decodeInfo->makeColorType(canvasColorType);
msarett3d9d7a72015-10-21 10:27:10 -0700363 break;
364 }
365
scroggoba584892016-05-20 13:56:13 -0700366 *decodeInfo = decodeInfo->makeAlphaType(dstAlphaType);
msarett3d9d7a72015-10-21 10:27:10 -0700367 return true;
368}
369
msarettb1be46b2016-05-17 08:52:11 -0700370static void draw_to_canvas(SkCanvas* canvas, const SkImageInfo& info, void* pixels, size_t rowBytes,
Leon Scroggins571b30f2017-07-11 17:35:31 +0000371 CodecSrc::DstColorType dstColorType,
msarettb1be46b2016-05-17 08:52:11 -0700372 SkScalar left = 0, SkScalar top = 0) {
msarettb1be46b2016-05-17 08:52:11 -0700373 SkBitmap bitmap;
Leon Scroggins571b30f2017-07-11 17:35:31 +0000374 bitmap.installPixels(info, pixels, rowBytes);
msarettb1be46b2016-05-17 08:52:11 -0700375 swap_rb_if_necessary(bitmap, dstColorType);
376 canvas->drawBitmap(bitmap, left, top);
Yuqian Licb312482018-04-27 15:52:40 -0400377 canvas->flush();
msarettb1be46b2016-05-17 08:52:11 -0700378}
379
Matt Sarettf485cf92017-05-26 08:58:03 -0400380// For codec srcs, we want the "draw" step to be a memcpy. Any interesting color space or
381// color format conversions should be performed by the codec. Sometimes the output of the
382// decode will be in an interesting color space. On our srgb and f16 backends, we need to
383// "pretend" that the color space is standard sRGB to avoid triggering color conversion
384// at draw time.
385static void set_bitmap_color_space(SkImageInfo* info) {
Brian Osman6b622962018-08-27 19:16:02 +0000386 *info = info->makeColorSpace(SkColorSpace::MakeSRGB());
Matt Sarettf485cf92017-05-26 08:58:03 -0400387}
388
mtkleine0effd62015-07-29 06:37:28 -0700389Error CodecSrc::draw(SkCanvas* canvas) const {
bungeman38d909e2016-08-02 14:40:46 -0700390 sk_sp<SkData> encoded(SkData::MakeFromFileName(fPath.c_str()));
mtklein748ca3b2015-01-15 10:56:12 -0800391 if (!encoded) {
392 return SkStringPrintf("Couldn't read %s.", fPath.c_str());
393 }
msarettb714fb02016-01-22 14:46:42 -0800394
Mike Reedede7bac2017-07-23 15:30:02 -0400395 std::unique_ptr<SkCodec> codec(SkCodec::MakeFromData(encoded));
msarett9e707a02015-09-01 14:57:57 -0700396 if (nullptr == codec.get()) {
397 return SkStringPrintf("Couldn't create codec for %s.", fPath.c_str());
scroggo9b77ddd2015-03-19 06:03:39 -0700398 }
399
scroggoba584892016-05-20 13:56:13 -0700400 SkImageInfo decodeInfo = codec->getInfo();
401 if (!get_decode_info(&decodeInfo, canvas->imageInfo().colorType(), fDstColorType,
402 fDstAlphaType)) {
Matt Sarettea518f02017-02-03 11:58:59 -0800403 return Error::Nonfatal("Skipping uninteresting test.");
msarett438b2ad2015-04-09 12:43:10 -0700404 }
405
msarett0a242972015-06-11 14:27:27 -0700406 // Try to scale the image if it is desired
407 SkISize size = codec->getScaledDimensions(fScale);
408 if (size == decodeInfo.dimensions() && 1.0f != fScale) {
409 return Error::Nonfatal("Test without scaling is uninteresting.");
410 }
msarettb32758a2015-08-18 13:22:46 -0700411
412 // Visually inspecting very small output images is not necessary. We will
413 // cover these cases in unit testing.
414 if ((size.width() <= 10 || size.height() <= 10) && 1.0f != fScale) {
415 return Error::Nonfatal("Scaling very small images is uninteresting.");
416 }
msarett0a242972015-06-11 14:27:27 -0700417 decodeInfo = decodeInfo.makeWH(size.width(), size.height());
418
Mike Reed7fcfb622018-02-09 13:26:46 -0500419 const int bpp = decodeInfo.bytesPerPixel();
msarettb1be46b2016-05-17 08:52:11 -0700420 const size_t rowBytes = size.width() * bpp;
Mike Reedf0ffb892017-10-03 14:47:21 -0400421 const size_t safeSize = decodeInfo.computeByteSize(rowBytes);
scroggo19b91532016-10-24 09:03:26 -0700422 SkAutoMalloc pixels(safeSize);
msarett438b2ad2015-04-09 12:43:10 -0700423
msarettbb25b532016-01-13 09:31:39 -0800424 SkCodec::Options options;
425 if (kCodecZeroInit_Mode == fMode) {
msarettb1be46b2016-05-17 08:52:11 -0700426 memset(pixels.get(), 0, size.height() * rowBytes);
msarettbb25b532016-01-13 09:31:39 -0800427 options.fZeroInitialized = SkCodec::kYes_ZeroInitialized;
428 }
msarett34e0ec42016-04-22 16:27:24 -0700429
430 SkImageInfo bitmapInfo = decodeInfo;
Matt Sarettf485cf92017-05-26 08:58:03 -0400431 set_bitmap_color_space(&bitmapInfo);
msarett34e0ec42016-04-22 16:27:24 -0700432 if (kRGBA_8888_SkColorType == decodeInfo.colorType() ||
433 kBGRA_8888_SkColorType == decodeInfo.colorType()) {
434 bitmapInfo = bitmapInfo.makeColorType(kN32_SkColorType);
435 }
scroggo9b77ddd2015-03-19 06:03:39 -0700436
scroggo9c59ebc2015-03-25 13:48:49 -0700437 switch (fMode) {
scroggo19b91532016-10-24 09:03:26 -0700438 case kAnimated_Mode: {
439 std::vector<SkCodec::FrameInfo> frameInfos = codec->getFrameInfo();
440 if (frameInfos.size() <= 1) {
441 return SkStringPrintf("%s is not an animated image.", fPath.c_str());
442 }
443
scroggo90e971a2016-10-25 06:11:01 -0700444 // As in CodecSrc::size(), compute a roughly square grid to draw the frames
445 // into. "factor" is the number of frames to draw on one row. There will be
446 // up to "factor" rows as well.
447 const float root = sqrt((float) frameInfos.size());
448 const int factor = sk_float_ceil2int(root);
449
scroggo19b91532016-10-24 09:03:26 -0700450 // Used to cache a frame that future frames will depend on.
451 SkAutoMalloc priorFramePixels;
Nigel Tao66bc5242018-08-22 10:56:03 +1000452 int cachedFrame = SkCodec::kNoFrame;
Leon Scroggins III249b8e32017-04-17 12:46:33 -0400453 for (int i = 0; static_cast<size_t>(i) < frameInfos.size(); i++) {
scroggo19b91532016-10-24 09:03:26 -0700454 options.fFrameIndex = i;
455 // Check for a prior frame
Leon Scroggins III249b8e32017-04-17 12:46:33 -0400456 const int reqFrame = frameInfos[i].fRequiredFrame;
Nigel Tao66bc5242018-08-22 10:56:03 +1000457 if (reqFrame != SkCodec::kNoFrame && reqFrame == cachedFrame
scroggo19b91532016-10-24 09:03:26 -0700458 && priorFramePixels.get()) {
459 // Copy into pixels
460 memcpy(pixels.get(), priorFramePixels.get(), safeSize);
Leon Scroggins III33deb7e2017-06-07 12:31:51 -0400461 options.fPriorFrame = reqFrame;
scroggo19b91532016-10-24 09:03:26 -0700462 } else {
Nigel Tao66bc5242018-08-22 10:56:03 +1000463 options.fPriorFrame = SkCodec::kNoFrame;
scroggo19b91532016-10-24 09:03:26 -0700464 }
Leon Scroggins III3fc97d72016-12-09 16:39:33 -0500465 SkCodec::Result result = codec->getPixels(decodeInfo, pixels.get(),
Leon Scroggins571b30f2017-07-11 17:35:31 +0000466 rowBytes, &options);
Leon Scroggins III3fc97d72016-12-09 16:39:33 -0500467 if (SkCodec::kInvalidInput == result && i > 0) {
468 // Some of our test images have truncated later frames. Treat that
469 // the same as incomplete.
470 result = SkCodec::kIncompleteInput;
471 }
scroggo19b91532016-10-24 09:03:26 -0700472 switch (result) {
473 case SkCodec::kSuccess:
Leon Scroggins III674a1842017-07-06 12:26:09 -0400474 case SkCodec::kErrorInInput:
scroggo90e971a2016-10-25 06:11:01 -0700475 case SkCodec::kIncompleteInput: {
Leon Scroggins III557fbbe2017-05-23 09:37:21 -0400476 // If the next frame depends on this one, store it in priorFrame.
477 // It is possible that we may discard a frame that future frames depend on,
478 // but the codec will simply redecode the discarded frame.
479 // Do this before calling draw_to_canvas, which premultiplies in place. If
480 // we're decoding to unpremul, we want to pass the unmodified frame to the
481 // codec for decoding the next frame.
482 if (static_cast<size_t>(i+1) < frameInfos.size()
483 && frameInfos[i+1].fRequiredFrame == i) {
484 memcpy(priorFramePixels.reset(safeSize), pixels.get(), safeSize);
485 cachedFrame = i;
486 }
487
scroggo90e971a2016-10-25 06:11:01 -0700488 SkAutoCanvasRestore acr(canvas, true);
489 const int xTranslate = (i % factor) * decodeInfo.width();
490 const int yTranslate = (i / factor) * decodeInfo.height();
491 canvas->translate(SkIntToScalar(xTranslate), SkIntToScalar(yTranslate));
Leon Scroggins571b30f2017-07-11 17:35:31 +0000492 draw_to_canvas(canvas, bitmapInfo, pixels.get(), rowBytes, fDstColorType);
Leon Scroggins III674a1842017-07-06 12:26:09 -0400493 if (result != SkCodec::kSuccess) {
scroggo19b91532016-10-24 09:03:26 -0700494 return "";
495 }
496 break;
scroggo90e971a2016-10-25 06:11:01 -0700497 }
scroggo53f63b62016-10-27 08:29:13 -0700498 case SkCodec::kInvalidConversion:
Mike Reed304a07c2017-07-12 15:10:28 -0400499 if (i > 0 && (decodeInfo.colorType() == kRGB_565_SkColorType)) {
scroggo53f63b62016-10-27 08:29:13 -0700500 return Error::Nonfatal(SkStringPrintf(
Mike Reed304a07c2017-07-12 15:10:28 -0400501 "Cannot decode frame %i to 565 (%s).", i, fPath.c_str()));
scroggo53f63b62016-10-27 08:29:13 -0700502 }
503 // Fall through.
scroggo19b91532016-10-24 09:03:26 -0700504 default:
505 return SkStringPrintf("Couldn't getPixels for frame %i in %s.",
506 i, fPath.c_str());
507 }
scroggo19b91532016-10-24 09:03:26 -0700508 }
509 break;
510 }
msarettbb25b532016-01-13 09:31:39 -0800511 case kCodecZeroInit_Mode:
msarett9e707a02015-09-01 14:57:57 -0700512 case kCodec_Mode: {
Leon Scroggins571b30f2017-07-11 17:35:31 +0000513 switch (codec->getPixels(decodeInfo, pixels.get(), rowBytes, &options)) {
scroggoeb602a52015-07-09 08:16:03 -0700514 case SkCodec::kSuccess:
Leon Scroggins III674a1842017-07-06 12:26:09 -0400515 // We consider these to be valid, since we should still decode what is
scroggo9c59ebc2015-03-25 13:48:49 -0700516 // available.
Leon Scroggins III674a1842017-07-06 12:26:09 -0400517 case SkCodec::kErrorInInput:
scroggoeb602a52015-07-09 08:16:03 -0700518 case SkCodec::kIncompleteInput:
scroggo9c59ebc2015-03-25 13:48:49 -0700519 break;
scroggo9c59ebc2015-03-25 13:48:49 -0700520 default:
521 // Everything else is considered a failure.
522 return SkStringPrintf("Couldn't getPixels %s.", fPath.c_str());
523 }
msarettb1be46b2016-05-17 08:52:11 -0700524
Leon Scroggins571b30f2017-07-11 17:35:31 +0000525 draw_to_canvas(canvas, bitmapInfo, pixels.get(), rowBytes, fDstColorType);
scroggo9c59ebc2015-03-25 13:48:49 -0700526 break;
emmaleer0a4c3cb2015-06-22 10:40:21 -0700527 }
scroggo9c59ebc2015-03-25 13:48:49 -0700528 case kScanline_Mode: {
scroggod8d68552016-06-06 11:26:17 -0700529 void* dst = pixels.get();
530 uint32_t height = decodeInfo.height();
scroggo19b91532016-10-24 09:03:26 -0700531 const bool useIncremental = [this]() {
532 auto exts = { "png", "PNG", "gif", "GIF" };
533 for (auto ext : exts) {
534 if (fPath.endsWith(ext)) {
535 return true;
536 }
537 }
538 return false;
539 }();
540 // ico may use the old scanline method or the new one, depending on whether it
541 // internally holds a bmp or a png.
scroggo8e6c7ad2016-09-16 08:20:38 -0700542 const bool ico = fPath.endsWith("ico");
scroggo19b91532016-10-24 09:03:26 -0700543 bool useOldScanlineMethod = !useIncremental && !ico;
544 if (useIncremental || ico) {
scroggo8e6c7ad2016-09-16 08:20:38 -0700545 if (SkCodec::kSuccess == codec->startIncrementalDecode(decodeInfo, dst,
Leon Scroggins571b30f2017-07-11 17:35:31 +0000546 rowBytes, &options)) {
scroggo8e6c7ad2016-09-16 08:20:38 -0700547 int rowsDecoded;
Leon Scroggins III674a1842017-07-06 12:26:09 -0400548 auto result = codec->incrementalDecode(&rowsDecoded);
549 if (SkCodec::kIncompleteInput == result || SkCodec::kErrorInInput == result) {
scroggo8e6c7ad2016-09-16 08:20:38 -0700550 codec->fillIncompleteImage(decodeInfo, dst, rowBytes,
551 SkCodec::kNo_ZeroInitialized, height,
552 rowsDecoded);
scroggo6fb23912016-06-02 14:16:43 -0700553 }
scroggo8e6c7ad2016-09-16 08:20:38 -0700554 } else {
scroggo19b91532016-10-24 09:03:26 -0700555 if (useIncremental) {
556 // Error: These should support incremental decode.
scroggo8e6c7ad2016-09-16 08:20:38 -0700557 return "Could not start incremental decode";
558 }
559 // Otherwise, this is an ICO. Since incremental failed, it must contain a BMP,
560 // which should work via startScanlineDecode
561 useOldScanlineMethod = true;
562 }
563 }
564
565 if (useOldScanlineMethod) {
Leon Scroggins571b30f2017-07-11 17:35:31 +0000566 if (SkCodec::kSuccess != codec->startScanlineDecode(decodeInfo)) {
scroggo8e6c7ad2016-09-16 08:20:38 -0700567 return "Could not start scanline decoder";
568 }
569
Brian Osmanea176c62018-04-06 15:28:23 -0400570 // We do not need to check the return value. On an incomplete
571 // image, memory will be filled with a default value.
572 codec->getScanlines(dst, height, rowBytes);
msarett10522ff2015-09-07 08:54:01 -0700573 }
574
Leon Scroggins571b30f2017-07-11 17:35:31 +0000575 draw_to_canvas(canvas, bitmapInfo, dst, rowBytes, fDstColorType);
emmaleer97002062015-05-27 12:36:10 -0700576 break;
577 }
msarett0a242972015-06-11 14:27:27 -0700578 case kStripe_Mode: {
579 const int height = decodeInfo.height();
580 // This value is chosen arbitrarily. We exercise more cases by choosing a value that
581 // does not align with image blocks.
582 const int stripeHeight = 37;
583 const int numStripes = (height + stripeHeight - 1) / stripeHeight;
msarettb1be46b2016-05-17 08:52:11 -0700584 void* dst = pixels.get();
msarett0a242972015-06-11 14:27:27 -0700585
586 // Decode odd stripes
Leon Scroggins571b30f2017-07-11 17:35:31 +0000587 if (SkCodec::kSuccess != codec->startScanlineDecode(decodeInfo, &options)) {
msarettb65e6042016-02-23 05:37:25 -0800588 return "Could not start scanline decoder";
589 }
590
591 // This mode was designed to test the new skip scanlines API in libjpeg-turbo.
592 // Jpegs have kTopDown_SkScanlineOrder, and at this time, it is not interesting
593 // to run this test for image types that do not have this scanline ordering.
scroggo12e2f502016-05-16 09:04:18 -0700594 // We only run this on Jpeg, which is always kTopDown.
595 SkASSERT(SkCodec::kTopDown_SkScanlineOrder == codec->getScanlineOrder());
msarette6dd0042015-10-09 11:07:34 -0700596
msarett0a242972015-06-11 14:27:27 -0700597 for (int i = 0; i < numStripes; i += 2) {
598 // Skip a stripe
599 const int linesToSkip = SkTMin(stripeHeight, height - i * stripeHeight);
msarette6dd0042015-10-09 11:07:34 -0700600 codec->skipScanlines(linesToSkip);
msarett0a242972015-06-11 14:27:27 -0700601
602 // Read a stripe
603 const int startY = (i + 1) * stripeHeight;
604 const int linesToRead = SkTMin(stripeHeight, height - startY);
605 if (linesToRead > 0) {
msarettb1be46b2016-05-17 08:52:11 -0700606 codec->getScanlines(SkTAddOffset<void>(dst, rowBytes * startY), linesToRead,
607 rowBytes);
msarett0a242972015-06-11 14:27:27 -0700608 }
609 }
610
611 // Decode even stripes
Leon Scroggins571b30f2017-07-11 17:35:31 +0000612 const SkCodec::Result startResult = codec->startScanlineDecode(decodeInfo);
scroggo1c005e42015-08-04 09:24:45 -0700613 if (SkCodec::kSuccess != startResult) {
614 return "Failed to restart scanline decoder with same parameters.";
msarett0a242972015-06-11 14:27:27 -0700615 }
616 for (int i = 0; i < numStripes; i += 2) {
617 // Read a stripe
618 const int startY = i * stripeHeight;
619 const int linesToRead = SkTMin(stripeHeight, height - startY);
msarettb1be46b2016-05-17 08:52:11 -0700620 codec->getScanlines(SkTAddOffset<void>(dst, rowBytes * startY), linesToRead,
621 rowBytes);
msarett0a242972015-06-11 14:27:27 -0700622
623 // Skip a stripe
msarettf6db27e2015-06-12 09:34:04 -0700624 const int linesToSkip = SkTMin(stripeHeight, height - (i + 1) * stripeHeight);
625 if (linesToSkip > 0) {
msarette6dd0042015-10-09 11:07:34 -0700626 codec->skipScanlines(linesToSkip);
msarett0a242972015-06-11 14:27:27 -0700627 }
628 }
msarettb1be46b2016-05-17 08:52:11 -0700629
Leon Scroggins571b30f2017-07-11 17:35:31 +0000630 draw_to_canvas(canvas, bitmapInfo, dst, rowBytes, fDstColorType);
emmaleer0a4c3cb2015-06-22 10:40:21 -0700631 break;
msarett0a242972015-06-11 14:27:27 -0700632 }
msarett91c22b22016-02-22 12:27:46 -0800633 case kCroppedScanline_Mode: {
634 const int width = decodeInfo.width();
635 const int height = decodeInfo.height();
636 // This value is chosen because, as we move across the image, it will sometimes
637 // align with the jpeg block sizes and it will sometimes not. This allows us
638 // to test interestingly different code paths in the implementation.
639 const int tileSize = 36;
msarett91c22b22016-02-22 12:27:46 -0800640 SkIRect subset;
641 for (int x = 0; x < width; x += tileSize) {
642 subset = SkIRect::MakeXYWH(x, 0, SkTMin(tileSize, width - x), height);
Matt Saretta40d9c82017-05-19 15:21:05 -0400643 options.fSubset = &subset;
Leon Scroggins571b30f2017-07-11 17:35:31 +0000644 if (SkCodec::kSuccess != codec->startScanlineDecode(decodeInfo, &options)) {
msarett91c22b22016-02-22 12:27:46 -0800645 return "Could not start scanline decoder.";
646 }
647
msarettb1be46b2016-05-17 08:52:11 -0700648 codec->getScanlines(SkTAddOffset<void>(pixels.get(), x * bpp), height, rowBytes);
msarett91c22b22016-02-22 12:27:46 -0800649 }
650
Leon Scroggins571b30f2017-07-11 17:35:31 +0000651 draw_to_canvas(canvas, bitmapInfo, pixels.get(), rowBytes, fDstColorType);
msarett91c22b22016-02-22 12:27:46 -0800652 break;
653 }
scroggob636b452015-07-22 07:16:20 -0700654 case kSubset_Mode: {
655 // Arbitrarily choose a divisor.
656 int divisor = 2;
657 // Total width/height of the image.
658 const int W = codec->getInfo().width();
659 const int H = codec->getInfo().height();
660 if (divisor > W || divisor > H) {
661 return Error::Nonfatal(SkStringPrintf("Cannot codec subset: divisor %d is too big "
662 "for %s with dimensions (%d x %d)", divisor,
663 fPath.c_str(), W, H));
664 }
665 // subset dimensions
666 // SkWebpCodec, the only one that supports subsets, requires even top/left boundaries.
667 const int w = SkAlign2(W / divisor);
668 const int h = SkAlign2(H / divisor);
669 SkIRect subset;
Matt Saretta40d9c82017-05-19 15:21:05 -0400670 options.fSubset = &subset;
scroggob636b452015-07-22 07:16:20 -0700671 SkBitmap subsetBm;
672 // We will reuse pixel memory from bitmap.
msarettb1be46b2016-05-17 08:52:11 -0700673 void* dst = pixels.get();
scroggob636b452015-07-22 07:16:20 -0700674 // Keep track of left and top (for drawing subsetBm into canvas). We could use
675 // fScale * x and fScale * y, but we want integers such that the next subset will start
676 // where the last one ended. So we'll add decodeInfo.width() and height().
677 int left = 0;
678 for (int x = 0; x < W; x += w) {
679 int top = 0;
680 for (int y = 0; y < H; y+= h) {
681 // Do not make the subset go off the edge of the image.
682 const int preScaleW = SkTMin(w, W - x);
683 const int preScaleH = SkTMin(h, H - y);
684 subset.setXYWH(x, y, preScaleW, preScaleH);
685 // And scale
686 // FIXME: Should we have a version of getScaledDimensions that takes a subset
687 // into account?
msarettc7eb4902016-04-25 07:04:58 -0700688 const int scaledW = SkTMax(1, SkScalarRoundToInt(preScaleW * fScale));
689 const int scaledH = SkTMax(1, SkScalarRoundToInt(preScaleH * fScale));
690 decodeInfo = decodeInfo.makeWH(scaledW, scaledH);
691 SkImageInfo subsetBitmapInfo = bitmapInfo.makeWH(scaledW, scaledH);
msarettb1be46b2016-05-17 08:52:11 -0700692 size_t subsetRowBytes = subsetBitmapInfo.minRowBytes();
693 const SkCodec::Result result = codec->getPixels(decodeInfo, dst, subsetRowBytes,
Leon Scroggins571b30f2017-07-11 17:35:31 +0000694 &options);
scroggob636b452015-07-22 07:16:20 -0700695 switch (result) {
696 case SkCodec::kSuccess:
Leon Scroggins III674a1842017-07-06 12:26:09 -0400697 case SkCodec::kErrorInInput:
scroggob636b452015-07-22 07:16:20 -0700698 case SkCodec::kIncompleteInput:
699 break;
scroggob636b452015-07-22 07:16:20 -0700700 default:
701 return SkStringPrintf("subset codec failed to decode (%d, %d, %d, %d) "
702 "from %s with dimensions (%d x %d)\t error %d",
703 x, y, decodeInfo.width(), decodeInfo.height(),
704 fPath.c_str(), W, H, result);
705 }
Leon Scroggins571b30f2017-07-11 17:35:31 +0000706 draw_to_canvas(canvas, subsetBitmapInfo, dst, subsetRowBytes, fDstColorType,
707 SkIntToScalar(left), SkIntToScalar(top));
msarettb1be46b2016-05-17 08:52:11 -0700708
scroggob636b452015-07-22 07:16:20 -0700709 // translate by the scaled height.
710 top += decodeInfo.height();
711 }
712 // translate by the scaled width.
713 left += decodeInfo.width();
714 }
715 return "";
716 }
msarettb714fb02016-01-22 14:46:42 -0800717 default:
718 SkASSERT(false);
719 return "Invalid fMode";
scroggo9b77ddd2015-03-19 06:03:39 -0700720 }
scroggo9c59ebc2015-03-25 13:48:49 -0700721 return "";
scroggo9b77ddd2015-03-19 06:03:39 -0700722}
723
724SkISize CodecSrc::size() const {
bungeman38d909e2016-08-02 14:40:46 -0700725 sk_sp<SkData> encoded(SkData::MakeFromFileName(fPath.c_str()));
Mike Reedede7bac2017-07-23 15:30:02 -0400726 std::unique_ptr<SkCodec> codec(SkCodec::MakeFromData(encoded));
scroggo7fac5af2015-09-30 11:33:12 -0700727 if (nullptr == codec) {
Hal Canaryfafe1352017-04-11 12:12:02 -0400728 return {0, 0};
scroggo7fac5af2015-09-30 11:33:12 -0700729 }
scroggo19b91532016-10-24 09:03:26 -0700730
731 auto imageSize = codec->getScaledDimensions(fScale);
732 if (fMode == kAnimated_Mode) {
scroggo90e971a2016-10-25 06:11:01 -0700733 // We'll draw one of each frame, so make it big enough to hold them all
734 // in a grid. The grid will be roughly square, with "factor" frames per
735 // row and up to "factor" rows.
scroggo19b91532016-10-24 09:03:26 -0700736 const size_t count = codec->getFrameInfo().size();
scroggo90e971a2016-10-25 06:11:01 -0700737 const float root = sqrt((float) count);
738 const int factor = sk_float_ceil2int(root);
739 imageSize.fWidth = imageSize.fWidth * factor;
740 imageSize.fHeight = imageSize.fHeight * sk_float_ceil2int((float) count / (float) factor);
scroggo19b91532016-10-24 09:03:26 -0700741 }
742 return imageSize;
scroggo9b77ddd2015-03-19 06:03:39 -0700743}
744
745Name CodecSrc::name() const {
msarett0a242972015-06-11 14:27:27 -0700746 if (1.0f == fScale) {
scroggo6e8c68e2016-10-24 13:48:49 -0700747 Name name = SkOSPath::Basename(fPath.c_str());
748 if (fMode == kAnimated_Mode) {
749 name.append("_animated");
750 }
751 return name;
msarett0a242972015-06-11 14:27:27 -0700752 }
scroggo6e8c68e2016-10-24 13:48:49 -0700753 SkASSERT(fMode != kAnimated_Mode);
msaretta5783ae2015-09-08 15:35:32 -0700754 return get_scaled_name(fPath, fScale);
scroggo9b77ddd2015-03-19 06:03:39 -0700755}
756
757/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
758
scroggof8dc9df2016-05-16 09:04:13 -0700759AndroidCodecSrc::AndroidCodecSrc(Path path, CodecSrc::DstColorType dstColorType,
scroggoc5560be2016-02-03 09:42:42 -0800760 SkAlphaType dstAlphaType, int sampleSize)
msarett3d9d7a72015-10-21 10:27:10 -0700761 : fPath(path)
msarett3d9d7a72015-10-21 10:27:10 -0700762 , fDstColorType(dstColorType)
scroggoc5560be2016-02-03 09:42:42 -0800763 , fDstAlphaType(dstAlphaType)
msarett3d9d7a72015-10-21 10:27:10 -0700764 , fSampleSize(sampleSize)
scroggo3ac66e92016-02-08 15:09:48 -0800765 , fRunSerially(serial_from_path_name(path))
msarett3d9d7a72015-10-21 10:27:10 -0700766{}
767
768bool AndroidCodecSrc::veto(SinkFlags flags) const {
769 // No need to test decoding to non-raster or indirect backend.
msarett3d9d7a72015-10-21 10:27:10 -0700770 return flags.type != SinkFlags::kRaster
771 || flags.approach != SinkFlags::kDirect;
772}
773
774Error AndroidCodecSrc::draw(SkCanvas* canvas) const {
bungeman38d909e2016-08-02 14:40:46 -0700775 sk_sp<SkData> encoded(SkData::MakeFromFileName(fPath.c_str()));
msarett3d9d7a72015-10-21 10:27:10 -0700776 if (!encoded) {
777 return SkStringPrintf("Couldn't read %s.", fPath.c_str());
778 }
Mike Reedede7bac2017-07-23 15:30:02 -0400779 std::unique_ptr<SkAndroidCodec> codec(SkAndroidCodec::MakeFromData(encoded));
780 if (nullptr == codec) {
msarett3d9d7a72015-10-21 10:27:10 -0700781 return SkStringPrintf("Couldn't create android codec for %s.", fPath.c_str());
782 }
783
scroggoba584892016-05-20 13:56:13 -0700784 SkImageInfo decodeInfo = codec->getInfo();
785 if (!get_decode_info(&decodeInfo, canvas->imageInfo().colorType(), fDstColorType,
786 fDstAlphaType)) {
Matt Sarettea518f02017-02-03 11:58:59 -0800787 return Error::Nonfatal("Skipping uninteresting test.");
msarett3d9d7a72015-10-21 10:27:10 -0700788 }
789
790 // Scale the image if it is desired.
791 SkISize size = codec->getSampledDimensions(fSampleSize);
792
793 // Visually inspecting very small output images is not necessary. We will
794 // cover these cases in unit testing.
795 if ((size.width() <= 10 || size.height() <= 10) && 1 != fSampleSize) {
796 return Error::Nonfatal("Scaling very small images is uninteresting.");
797 }
798 decodeInfo = decodeInfo.makeWH(size.width(), size.height());
799
Mike Reed7fcfb622018-02-09 13:26:46 -0500800 int bpp = decodeInfo.bytesPerPixel();
msarettb1be46b2016-05-17 08:52:11 -0700801 size_t rowBytes = size.width() * bpp;
802 SkAutoMalloc pixels(size.height() * rowBytes);
msarett3d9d7a72015-10-21 10:27:10 -0700803
804 SkBitmap bitmap;
msarett34e0ec42016-04-22 16:27:24 -0700805 SkImageInfo bitmapInfo = decodeInfo;
Matt Sarettf485cf92017-05-26 08:58:03 -0400806 set_bitmap_color_space(&bitmapInfo);
msarett34e0ec42016-04-22 16:27:24 -0700807 if (kRGBA_8888_SkColorType == decodeInfo.colorType() ||
808 kBGRA_8888_SkColorType == decodeInfo.colorType()) {
809 bitmapInfo = bitmapInfo.makeColorType(kN32_SkColorType);
810 }
msarett3d9d7a72015-10-21 10:27:10 -0700811
812 // Create options for the codec.
813 SkAndroidCodec::AndroidOptions options;
msarett3d9d7a72015-10-21 10:27:10 -0700814 options.fSampleSize = fSampleSize;
815
msarettb1be46b2016-05-17 08:52:11 -0700816 switch (codec->getAndroidPixels(decodeInfo, pixels.get(), rowBytes, &options)) {
scroggof8dc9df2016-05-16 09:04:13 -0700817 case SkCodec::kSuccess:
Leon Scroggins III674a1842017-07-06 12:26:09 -0400818 case SkCodec::kErrorInInput:
scroggof8dc9df2016-05-16 09:04:13 -0700819 case SkCodec::kIncompleteInput:
820 break;
msarett3d9d7a72015-10-21 10:27:10 -0700821 default:
scroggof8dc9df2016-05-16 09:04:13 -0700822 return SkStringPrintf("Couldn't getPixels %s.", fPath.c_str());
msarett3d9d7a72015-10-21 10:27:10 -0700823 }
Leon Scroggins571b30f2017-07-11 17:35:31 +0000824 draw_to_canvas(canvas, bitmapInfo, pixels.get(), rowBytes, fDstColorType);
scroggof8dc9df2016-05-16 09:04:13 -0700825 return "";
msarett3d9d7a72015-10-21 10:27:10 -0700826}
827
828SkISize AndroidCodecSrc::size() const {
bungeman38d909e2016-08-02 14:40:46 -0700829 sk_sp<SkData> encoded(SkData::MakeFromFileName(fPath.c_str()));
Mike Reedede7bac2017-07-23 15:30:02 -0400830 std::unique_ptr<SkAndroidCodec> codec(SkAndroidCodec::MakeFromData(encoded));
msarett3d9d7a72015-10-21 10:27:10 -0700831 if (nullptr == codec) {
Hal Canaryfafe1352017-04-11 12:12:02 -0400832 return {0, 0};
msarett3d9d7a72015-10-21 10:27:10 -0700833 }
834 return codec->getSampledDimensions(fSampleSize);
835}
836
837Name AndroidCodecSrc::name() const {
838 // We will replicate the names used by CodecSrc so that images can
839 // be compared in Gold.
840 if (1 == fSampleSize) {
841 return SkOSPath::Basename(fPath.c_str());
842 }
msarett4b0778e2015-11-13 09:59:11 -0800843 return get_scaled_name(fPath, 1.0f / (float) fSampleSize);
msarett3d9d7a72015-10-21 10:27:10 -0700844}
845
846/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
847
msarett18976312016-03-09 14:20:58 -0800848ImageGenSrc::ImageGenSrc(Path path, Mode mode, SkAlphaType alphaType, bool isGpu)
849 : fPath(path)
850 , fMode(mode)
851 , fDstAlphaType(alphaType)
852 , fIsGpu(isGpu)
853 , fRunSerially(serial_from_path_name(path))
854{}
855
856bool ImageGenSrc::veto(SinkFlags flags) const {
857 if (fIsGpu) {
Brian Salomonbd7c5512017-03-07 09:08:36 -0500858 // MSAA runs tend to run out of memory and tests the same code paths as regular gpu configs.
859 return flags.type != SinkFlags::kGPU || flags.approach != SinkFlags::kDirect ||
860 flags.multisampled == SinkFlags::kMultisampled;
msarett18976312016-03-09 14:20:58 -0800861 }
862
863 return flags.type != SinkFlags::kRaster || flags.approach != SinkFlags::kDirect;
864}
865
866Error ImageGenSrc::draw(SkCanvas* canvas) const {
867 if (kRGB_565_SkColorType == canvas->imageInfo().colorType()) {
868 return Error::Nonfatal("Uninteresting to test image generator to 565.");
869 }
870
bungeman38d909e2016-08-02 14:40:46 -0700871 sk_sp<SkData> encoded(SkData::MakeFromFileName(fPath.c_str()));
msarett18976312016-03-09 14:20:58 -0800872 if (!encoded) {
873 return SkStringPrintf("Couldn't read %s.", fPath.c_str());
874 }
875
msarettfc0b6d12016-03-17 13:50:17 -0700876#if defined(SK_BUILD_FOR_WIN)
877 // Initialize COM in order to test with WIC.
878 SkAutoCoInitialize com;
879 if (!com.succeeded()) {
880 return "Could not initialize COM.";
881 }
882#endif
883
Ben Wagner145dbcd2016-11-03 14:40:50 -0400884 std::unique_ptr<SkImageGenerator> gen(nullptr);
msarett18976312016-03-09 14:20:58 -0800885 switch (fMode) {
886 case kCodec_Mode:
Mike Reed185130c2017-02-15 15:14:16 -0500887 gen = SkCodecImageGenerator::MakeFromEncodedCodec(encoded);
msarett18976312016-03-09 14:20:58 -0800888 if (!gen) {
889 return "Could not create codec image generator.";
890 }
891 break;
msarettfc0b6d12016-03-17 13:50:17 -0700892 case kPlatform_Mode: {
msarett18976312016-03-09 14:20:58 -0800893#if defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS)
Leon Scroggins III0cbc10f2017-10-30 09:07:53 -0400894 gen = SkImageGeneratorCG::MakeFromEncodedCG(encoded);
msarettfc0b6d12016-03-17 13:50:17 -0700895#elif defined(SK_BUILD_FOR_WIN)
Leon Scroggins IIIa57488a2018-06-25 14:01:29 -0400896 gen = SkImageGeneratorWIC::MakeFromEncodedWIC(encoded);
msarettfc0b6d12016-03-17 13:50:17 -0700897#endif
msarett18976312016-03-09 14:20:58 -0800898 if (!gen) {
msarettfc0b6d12016-03-17 13:50:17 -0700899 return "Could not create platform image generator.";
msarett18976312016-03-09 14:20:58 -0800900 }
901 break;
msarettfc0b6d12016-03-17 13:50:17 -0700902 }
msarett18976312016-03-09 14:20:58 -0800903 default:
904 SkASSERT(false);
905 return "Invalid image generator mode";
906 }
907
908 // Test deferred decoding path on GPU
909 if (fIsGpu) {
Mike Reed185130c2017-02-15 15:14:16 -0500910 sk_sp<SkImage> image(SkImage::MakeFromGenerator(std::move(gen), nullptr));
msarett18976312016-03-09 14:20:58 -0800911 if (!image) {
912 return "Could not create image from codec image generator.";
913 }
914 canvas->drawImage(image, 0, 0);
915 return "";
916 }
mtklein343a63d2016-03-22 11:46:53 -0700917
msarett18976312016-03-09 14:20:58 -0800918 // Test various color and alpha types on CPU
919 SkImageInfo decodeInfo = gen->getInfo().makeAlphaType(fDstAlphaType);
mtklein343a63d2016-03-22 11:46:53 -0700920
Mike Reed7fcfb622018-02-09 13:26:46 -0500921 int bpp = decodeInfo.bytesPerPixel();
msarettb1be46b2016-05-17 08:52:11 -0700922 size_t rowBytes = decodeInfo.width() * bpp;
923 SkAutoMalloc pixels(decodeInfo.height() * rowBytes);
Brian Osmanc87cfb62018-07-11 09:08:46 -0400924 if (!gen->getPixels(decodeInfo, pixels.get(), rowBytes)) {
Matt Sarett05cb4c32017-03-02 12:07:46 -0500925 SkString err =
926 SkStringPrintf("Image generator could not getPixels() for %s\n", fPath.c_str());
927
928#if defined(SK_BUILD_FOR_WIN)
929 if (kPlatform_Mode == fMode) {
930 // Do not issue a fatal error for WIC flakiness.
931 return Error::Nonfatal(err);
932 }
933#endif
934
935 return err;
msarett18976312016-03-09 14:20:58 -0800936 }
937
Matt Sarettf485cf92017-05-26 08:58:03 -0400938 set_bitmap_color_space(&decodeInfo);
Leon Scroggins571b30f2017-07-11 17:35:31 +0000939 draw_to_canvas(canvas, decodeInfo, pixels.get(), rowBytes,
msarettb1be46b2016-05-17 08:52:11 -0700940 CodecSrc::kGetFromCanvas_DstColorType);
msarett18976312016-03-09 14:20:58 -0800941 return "";
942}
943
944SkISize ImageGenSrc::size() const {
bungeman38d909e2016-08-02 14:40:46 -0700945 sk_sp<SkData> encoded(SkData::MakeFromFileName(fPath.c_str()));
Mike Reedede7bac2017-07-23 15:30:02 -0400946 std::unique_ptr<SkCodec> codec(SkCodec::MakeFromData(encoded));
msarett18976312016-03-09 14:20:58 -0800947 if (nullptr == codec) {
Hal Canaryfafe1352017-04-11 12:12:02 -0400948 return {0, 0};
msarett18976312016-03-09 14:20:58 -0800949 }
950 return codec->getInfo().dimensions();
951}
952
953Name ImageGenSrc::name() const {
954 return SkOSPath::Basename(fPath.c_str());
955}
956
957/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
958
msarett9ce3a542016-07-15 13:54:38 -0700959ColorCodecSrc::ColorCodecSrc(Path path, Mode mode, SkColorType colorType)
msarett69deca82016-04-29 09:38:40 -0700960 : fPath(path)
961 , fMode(mode)
msarett9ce3a542016-07-15 13:54:38 -0700962 , fColorType(colorType)
msarett69deca82016-04-29 09:38:40 -0700963{}
964
965bool ColorCodecSrc::veto(SinkFlags flags) const {
966 // Test to direct raster backends (8888 and 565).
967 return flags.type != SinkFlags::kRaster || flags.approach != SinkFlags::kDirect;
968}
969
Matt Sarett6a0feba2017-06-09 10:45:44 -0400970void clamp_if_necessary(const SkBitmap& bitmap, SkColorType dstCT) {
971 if (kRGBA_F16_SkColorType != bitmap.colorType() || kRGBA_F16_SkColorType == dstCT) {
972 // No need to clamp if the dst is F16. We will clamp when we encode to PNG.
973 return;
974 }
975
Mike Kleinb11ab572018-10-24 06:42:14 -0400976 SkRasterPipeline_MemoryCtx ptr = { bitmap.getAddr(0,0), bitmap.rowBytesAsPixels() };
Mike Klein45c16fa2017-07-18 18:15:13 -0400977
Matt Sarett6a0feba2017-06-09 10:45:44 -0400978 SkRasterPipeline_<256> p;
979 p.append(SkRasterPipeline::load_f16, &ptr);
980 p.append(SkRasterPipeline::clamp_0);
981 if (kPremul_SkAlphaType == bitmap.alphaType()) {
982 p.append(SkRasterPipeline::clamp_a);
983 } else {
984 p.append(SkRasterPipeline::clamp_1);
985 }
986 p.append(SkRasterPipeline::store_f16, &ptr);
987
Mike Klein45c16fa2017-07-18 18:15:13 -0400988 p.run(0,0, bitmap.width(), bitmap.height());
Matt Sarett6a0feba2017-06-09 10:45:44 -0400989}
990
msarett69deca82016-04-29 09:38:40 -0700991Error ColorCodecSrc::draw(SkCanvas* canvas) const {
992 if (kRGB_565_SkColorType == canvas->imageInfo().colorType()) {
993 return Error::Nonfatal("No need to test color correction to 565 backend.");
994 }
995
msarettd1ec89b2016-08-03 12:59:27 -0700996 bool runInLegacyMode = kBaseline_Mode == fMode;
msarettd1ec89b2016-08-03 12:59:27 -0700997 if (runInLegacyMode && canvas->imageInfo().colorSpace()) {
998 return Error::Nonfatal("Skipping tests that are only interesting in legacy mode.");
999 } else if (!runInLegacyMode && !canvas->imageInfo().colorSpace()) {
1000 return Error::Nonfatal("Skipping tests that are only interesting in srgb mode.");
msarett9ce3a542016-07-15 13:54:38 -07001001 }
1002
bungeman38d909e2016-08-02 14:40:46 -07001003 sk_sp<SkData> encoded(SkData::MakeFromFileName(fPath.c_str()));
msarett69deca82016-04-29 09:38:40 -07001004 if (!encoded) {
1005 return SkStringPrintf("Couldn't read %s.", fPath.c_str());
1006 }
1007
Mike Reedede7bac2017-07-23 15:30:02 -04001008 std::unique_ptr<SkCodec> codec(SkCodec::MakeFromData(encoded));
1009 if (nullptr == codec) {
msarett69deca82016-04-29 09:38:40 -07001010 return SkStringPrintf("Couldn't create codec for %s.", fPath.c_str());
1011 }
1012
msarett9876ac52016-06-01 14:47:18 -07001013 // Load the dst ICC profile. This particular dst is fairly similar to Adobe RGB.
Mike Reed0933bc92017-12-09 01:27:41 +00001014 sk_sp<SkData> dstData = GetResourceAsData("icc_profiles/HP_ZR30w.icc");
msarett9876ac52016-06-01 14:47:18 -07001015 if (!dstData) {
1016 return "Cannot read monitor profile. Is the resource path set correctly?";
1017 }
1018
msarett50ce1f22016-07-29 06:23:33 -07001019 sk_sp<SkColorSpace> dstSpace = nullptr;
1020 if (kDst_sRGB_Mode == fMode) {
Matt Sarett77a7a1b2017-02-07 13:56:11 -05001021 dstSpace = SkColorSpace::MakeSRGB();
msarett50ce1f22016-07-29 06:23:33 -07001022 } else if (kDst_HPZR30w_Mode == fMode) {
Brian Osmanc494a702018-05-23 11:52:00 -04001023 skcms_ICCProfile profile;
1024 SkAssertResult(skcms_Parse(dstData->data(), dstData->size(), &profile));
1025 dstSpace = SkColorSpace::Make(profile);
1026 SkASSERT(dstSpace);
msarett50ce1f22016-07-29 06:23:33 -07001027 }
1028
1029 SkImageInfo decodeInfo = codec->getInfo().makeColorType(fColorType).makeColorSpace(dstSpace);
msarettd1ec89b2016-08-03 12:59:27 -07001030 if (kUnpremul_SkAlphaType == decodeInfo.alphaType()) {
1031 decodeInfo = decodeInfo.makeAlphaType(kPremul_SkAlphaType);
1032 }
1033
msarett50ce1f22016-07-29 06:23:33 -07001034 SkImageInfo bitmapInfo = decodeInfo;
Matt Sarettf485cf92017-05-26 08:58:03 -04001035 set_bitmap_color_space(&bitmapInfo);
msarett50ce1f22016-07-29 06:23:33 -07001036 if (kRGBA_8888_SkColorType == decodeInfo.colorType() ||
1037 kBGRA_8888_SkColorType == decodeInfo.colorType())
1038 {
1039 bitmapInfo = bitmapInfo.makeColorType(kN32_SkColorType);
1040 }
1041
1042 SkBitmap bitmap;
1043 if (!bitmap.tryAllocPixels(bitmapInfo)) {
1044 return SkStringPrintf("Image(%s) is too large (%d x %d)", fPath.c_str(),
1045 bitmapInfo.width(), bitmapInfo.height());
1046 }
1047
1048 size_t rowBytes = bitmap.rowBytes();
1049 SkCodec::Result r = codec->getPixels(decodeInfo, bitmap.getPixels(), rowBytes);
Leon Scroggins III674a1842017-07-06 12:26:09 -04001050 switch (r) {
1051 case SkCodec::kSuccess:
1052 case SkCodec::kErrorInInput:
1053 case SkCodec::kIncompleteInput:
1054 break;
1055 default:
1056 return SkStringPrintf("Couldn't getPixels %s. Error code %d", fPath.c_str(), r);
msarett50ce1f22016-07-29 06:23:33 -07001057 }
1058
msarett69deca82016-04-29 09:38:40 -07001059 switch (fMode) {
1060 case kBaseline_Mode:
msarett39979d82016-07-28 17:11:18 -07001061 case kDst_sRGB_Mode:
msarett50ce1f22016-07-29 06:23:33 -07001062 case kDst_HPZR30w_Mode:
Matt Sarett6a0feba2017-06-09 10:45:44 -04001063 // We do not support drawing unclamped F16.
1064 clamp_if_necessary(bitmap, canvas->imageInfo().colorType());
msarett39979d82016-07-28 17:11:18 -07001065 canvas->drawBitmap(bitmap, 0, 0);
1066 break;
msarett69deca82016-04-29 09:38:40 -07001067 default:
1068 SkASSERT(false);
1069 return "Invalid fMode";
1070 }
1071 return "";
1072}
1073
1074SkISize ColorCodecSrc::size() const {
bungeman38d909e2016-08-02 14:40:46 -07001075 sk_sp<SkData> encoded(SkData::MakeFromFileName(fPath.c_str()));
Mike Reedede7bac2017-07-23 15:30:02 -04001076 std::unique_ptr<SkCodec> codec(SkCodec::MakeFromData(encoded));
msarett69deca82016-04-29 09:38:40 -07001077 if (nullptr == codec) {
Hal Canaryfafe1352017-04-11 12:12:02 -04001078 return {0, 0};
msarett69deca82016-04-29 09:38:40 -07001079 }
Hal Canaryfafe1352017-04-11 12:12:02 -04001080 return {codec->getInfo().width(), codec->getInfo().height()};
msarett69deca82016-04-29 09:38:40 -07001081}
1082
1083Name ColorCodecSrc::name() const {
1084 return SkOSPath::Basename(fPath.c_str());
1085}
1086
1087/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
1088
Robert Phillipsad8a43f2017-08-30 12:06:35 -04001089SKPSrc::SKPSrc(Path path) : fPath(path) { }
mtklein748ca3b2015-01-15 10:56:12 -08001090
Robert Phillipse4aae342018-03-14 10:26:57 -04001091static sk_sp<SkPicture> read_skp(const char* path, const SkDeserialProcs* procs = nullptr) {
Robert Phillipsad8a43f2017-08-30 12:06:35 -04001092 std::unique_ptr<SkStream> stream = SkStream::MakeFromFile(path);
mtklein75d98fd2015-01-18 07:05:01 -08001093 if (!stream) {
Robert Phillipsad8a43f2017-08-30 12:06:35 -04001094 return nullptr;
mtklein748ca3b2015-01-15 10:56:12 -08001095 }
Robert Phillipse4aae342018-03-14 10:26:57 -04001096 sk_sp<SkPicture> pic(SkPicture::MakeFromStream(stream.get(), procs));
mtklein75d98fd2015-01-18 07:05:01 -08001097 if (!pic) {
Robert Phillipsad8a43f2017-08-30 12:06:35 -04001098 return nullptr;
mtklein75d98fd2015-01-18 07:05:01 -08001099 }
bungemanf93d7112016-09-16 06:24:20 -07001100 stream = nullptr; // Might as well drop this when we're done with it.
joshualitt7c3a2f82015-03-31 13:32:05 -07001101
Robert Phillipsad8a43f2017-08-30 12:06:35 -04001102 return pic;
1103}
1104
1105Error SKPSrc::draw(SkCanvas* canvas) const {
1106 sk_sp<SkPicture> pic = read_skp(fPath.c_str());
1107 if (!pic) {
1108 return SkStringPrintf("Couldn't read %s.", fPath.c_str());
1109 }
1110
Robert Phillips33f02ed2018-03-27 08:06:57 -04001111 canvas->clipRect(SkRect::MakeWH(FLAGS_skpViewportSize, FLAGS_skpViewportSize));
mtklein748ca3b2015-01-15 10:56:12 -08001112 canvas->drawPicture(pic);
1113 return "";
1114}
1115
Robert Phillipsad8a43f2017-08-30 12:06:35 -04001116static SkRect get_cull_rect_for_skp(const char* path) {
1117 std::unique_ptr<SkStream> stream = SkStream::MakeFromFile(path);
mtkleinffa901a2015-03-16 10:38:07 -07001118 if (!stream) {
Robert Phillipsad8a43f2017-08-30 12:06:35 -04001119 return SkRect::MakeEmpty();
mtkleinffa901a2015-03-16 10:38:07 -07001120 }
1121 SkPictInfo info;
Mike Reede7a58322017-12-20 14:09:20 -05001122 if (!SkPicture_StreamIsSKP(stream.get(), &info)) {
Robert Phillipsad8a43f2017-08-30 12:06:35 -04001123 return SkRect::MakeEmpty();
mtkleinffa901a2015-03-16 10:38:07 -07001124 }
Robert Phillipsad8a43f2017-08-30 12:06:35 -04001125
1126 return info.fCullRect;
1127}
1128
1129SkISize SKPSrc::size() const {
1130 SkRect viewport = get_cull_rect_for_skp(fPath.c_str());
Robert Phillips33f02ed2018-03-27 08:06:57 -04001131 if (!viewport.intersect((SkRect::MakeWH(FLAGS_skpViewportSize, FLAGS_skpViewportSize)))) {
Hal Canaryfafe1352017-04-11 12:12:02 -04001132 return {0, 0};
mtkleinffa901a2015-03-16 10:38:07 -07001133 }
1134 return viewport.roundOut().size();
mtklein748ca3b2015-01-15 10:56:12 -08001135}
1136
1137Name SKPSrc::name() const { return SkOSPath::Basename(fPath.c_str()); }
1138
Florin Malitafc043dc2017-12-31 11:08:42 -05001139/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
1140
Chris Dalton184c37e2018-09-28 11:27:39 -06001141BisectSrc::BisectSrc(Path path, const char* trail) : INHERITED(path), fTrail(trail) {}
1142
1143Error BisectSrc::draw(SkCanvas* canvas) const {
1144 struct FoundPath {
1145 SkPath fPath;
1146 SkPaint fPaint;
1147 SkMatrix fViewMatrix;
1148 };
1149
1150 // This subclass of SkCanvas just extracts all the SkPaths (drawn via drawPath) from an SKP.
1151 class PathFindingCanvas : public SkCanvas {
1152 public:
1153 PathFindingCanvas(int width, int height) : SkCanvas(width, height, nullptr) {}
1154 const SkTArray<FoundPath>& foundPaths() const { return fFoundPaths; }
1155
1156 private:
1157 void onDrawPath(const SkPath& path, const SkPaint& paint) override {
1158 fFoundPaths.push_back() = {path, paint, this->getTotalMatrix()};
1159 }
1160
1161 SkTArray<FoundPath> fFoundPaths;
1162 };
1163
1164 PathFindingCanvas pathFinder(canvas->getBaseLayerSize().width(),
1165 canvas->getBaseLayerSize().height());
1166 Error err = this->INHERITED::draw(&pathFinder);
1167 if (!err.isEmpty()) {
1168 return err;
1169 }
1170
1171 int start = 0, end = pathFinder.foundPaths().count();
1172 for (const char* ch = fTrail.c_str(); *ch; ++ch) {
1173 int midpt = (start + end) / 2;
1174 if ('l' == *ch) {
1175 start = midpt;
1176 } else if ('r' == *ch) {
1177 end = midpt;
1178 }
1179 }
1180
1181 for (int i = start; i < end; ++i) {
1182 const FoundPath& path = pathFinder.foundPaths()[i];
1183 SkAutoCanvasRestore acr(canvas, true);
1184 canvas->concat(path.fViewMatrix);
1185 canvas->drawPath(path.fPath, path.fPaint);
1186 }
1187
1188 return "";
1189}
1190
1191/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
1192
Florin Malita87ccf332018-05-04 12:23:24 -04001193#if defined(SK_ENABLE_SKOTTIE)
Florin Malita9f7d4cd2018-07-30 15:49:20 -04001194SkottieSrc::SkottieSrc(Path path) : fPath(std::move(path)) {}
Florin Malitafc043dc2017-12-31 11:08:42 -05001195
Florin Malita54f65c42018-01-16 17:04:30 -05001196Error SkottieSrc::draw(SkCanvas* canvas) const {
Florin Malitaa8316552018-11-09 16:19:44 -05001197 auto animation = skottie::Animation::Builder()
1198 .setResourceProvider(
1199 skottie_utils::FileResourceProvider::Make(SkOSPath::Dirname(fPath.c_str())))
1200 .makeFromFile(fPath.c_str());
Florin Malita9f7d4cd2018-07-30 15:49:20 -04001201 if (!animation) {
1202 return SkStringPrintf("Unable to parse file: %s", fPath.c_str());
Florin Malitafc043dc2017-12-31 11:08:42 -05001203 }
1204
1205 canvas->drawColor(SK_ColorWHITE);
1206
Florin Malitaa33447d2018-05-29 13:46:54 -04001207 const auto t_rate = 1.0f / (kTileCount * kTileCount - 1);
Florin Malitafc043dc2017-12-31 11:08:42 -05001208
Kevin Lubickc5fe15d2018-08-29 09:52:52 -04001209 // Draw the frames in a shuffled order to exercise non-linear
1210 // frame progression. The film strip will still be in order left-to-right,
1211 // top-down, just not drawn in that order.
1212 static constexpr int frameOrder[] = { 4, 0, 3, 1, 2 };
1213 static_assert(SK_ARRAY_COUNT(frameOrder) == kTileCount, "");
Florin Malitad3c1b842018-01-27 12:43:24 -05001214
Florin Malitafc043dc2017-12-31 11:08:42 -05001215 for (int i = 0; i < kTileCount; ++i) {
Kevin Lubickc5fe15d2018-08-29 09:52:52 -04001216 const SkScalar y = frameOrder[i] * kTileSize;
Florin Malitafc043dc2017-12-31 11:08:42 -05001217
1218 for (int j = 0; j < kTileCount; ++j) {
Kevin Lubickc5fe15d2018-08-29 09:52:52 -04001219 const SkScalar x = frameOrder[j] * kTileSize;
Florin Malita9f7d4cd2018-07-30 15:49:20 -04001220 SkRect dest = SkRect::MakeXYWH(x, y, kTileSize, kTileSize);
Florin Malitafc043dc2017-12-31 11:08:42 -05001221
Kevin Lubickc5fe15d2018-08-29 09:52:52 -04001222 const auto t = t_rate * (frameOrder[i] * kTileCount + frameOrder[j]);
Florin Malitadf2713c2018-01-09 15:51:21 -05001223 {
1224 SkAutoCanvasRestore acr(canvas, true);
Florin Malitad3c1b842018-01-27 12:43:24 -05001225 canvas->clipRect(dest, true);
Florin Malita9f7d4cd2018-07-30 15:49:20 -04001226 canvas->concat(SkMatrix::MakeRectToRect(SkRect::MakeSize(animation->size()),
Florin Malitadf2713c2018-01-09 15:51:21 -05001227 dest,
Florin Malita3fae0f32018-03-15 21:52:54 -04001228 SkMatrix::kCenter_ScaleToFit));
Florin Malita9f7d4cd2018-07-30 15:49:20 -04001229 animation->seek(t);
1230 animation->render(canvas);
Florin Malitadf2713c2018-01-09 15:51:21 -05001231 }
Florin Malitafc043dc2017-12-31 11:08:42 -05001232 }
1233 }
1234
1235 return "";
1236}
1237
Florin Malita54f65c42018-01-16 17:04:30 -05001238SkISize SkottieSrc::size() const {
Florin Malita9f7d4cd2018-07-30 15:49:20 -04001239 return SkISize::Make(kTargetSize, kTargetSize);
Florin Malitafc043dc2017-12-31 11:08:42 -05001240}
1241
Florin Malita9f7d4cd2018-07-30 15:49:20 -04001242Name SkottieSrc::name() const { return SkOSPath::Basename(fPath.c_str()); }
Florin Malitafc043dc2017-12-31 11:08:42 -05001243
Florin Malita54f65c42018-01-16 17:04:30 -05001244bool SkottieSrc::veto(SinkFlags flags) const {
Florin Malitafc043dc2017-12-31 11:08:42 -05001245 // No need to test to non-(raster||gpu||vector) or indirect backends.
1246 bool type_ok = flags.type == SinkFlags::kRaster
1247 || flags.type == SinkFlags::kGPU
1248 || flags.type == SinkFlags::kVector;
1249
1250 return !type_ok || flags.approach != SinkFlags::kDirect;
1251}
Florin Malita124d5af2017-12-31 17:02:26 -05001252#endif
Florin Malitafc043dc2017-12-31 11:08:42 -05001253
1254/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
fmalitaa2b9fdf2016-08-03 19:53:36 -07001255#if defined(SK_XML)
fmalitabdf3e5c2016-09-17 07:26:26 -07001256// Used when the image doesn't have an intrinsic size.
Hal Canaryfafe1352017-04-11 12:12:02 -04001257static const SkSize kDefaultSVGSize = {1000, 1000};
fmalitaa2b9fdf2016-08-03 19:53:36 -07001258
fmalitabdf3e5c2016-09-17 07:26:26 -07001259// Used to force-scale tiny fixed-size images.
Hal Canaryfafe1352017-04-11 12:12:02 -04001260static const SkSize kMinimumSVGSize = {128, 128};
fmalitaa2b9fdf2016-08-03 19:53:36 -07001261
fmalitaacd2f5c2016-11-08 07:13:45 -08001262SVGSrc::SVGSrc(Path path)
1263 : fName(SkOSPath::Basename(path.c_str()))
1264 , fScale(1) {
fmalitabdf3e5c2016-09-17 07:26:26 -07001265
Brian Osman133823d2018-09-19 14:14:15 -04001266 sk_sp<SkData> data(SkData::MakeFromFileName(path.c_str()));
1267 if (!data) {
1268 return;
1269 }
fmalitaacd2f5c2016-11-08 07:13:45 -08001270
Brian Osman133823d2018-09-19 14:14:15 -04001271 SkMemoryStream stream(std::move(data));
1272 fDom = SkSVGDOM::MakeFromStream(stream);
1273 if (!fDom) {
1274 return;
1275 }
1276
1277 const SkSize& sz = fDom->containerSize();
1278 if (sz.isEmpty()) {
1279 // no intrinsic size
1280 fDom->setContainerSize(kDefaultSVGSize);
1281 } else {
1282 fScale = SkTMax(1.f, SkTMax(kMinimumSVGSize.width() / sz.width(),
1283 kMinimumSVGSize.height() / sz.height()));
1284 }
fmalitaacd2f5c2016-11-08 07:13:45 -08001285}
1286
1287Error SVGSrc::draw(SkCanvas* canvas) const {
fmalitabdf3e5c2016-09-17 07:26:26 -07001288 if (!fDom) {
fmalitaacd2f5c2016-11-08 07:13:45 -08001289 return SkStringPrintf("Unable to parse file: %s", fName.c_str());
fmalitaa2b9fdf2016-08-03 19:53:36 -07001290 }
1291
fmalitaacd2f5c2016-11-08 07:13:45 -08001292 SkAutoCanvasRestore acr(canvas, true);
1293 canvas->scale(fScale, fScale);
1294 fDom->render(canvas);
1295
fmalitaa2b9fdf2016-08-03 19:53:36 -07001296 return "";
1297}
1298
1299SkISize SVGSrc::size() const {
fmalitaacd2f5c2016-11-08 07:13:45 -08001300 if (!fDom) {
Hal Canaryfafe1352017-04-11 12:12:02 -04001301 return {0, 0};
fmalitabdf3e5c2016-09-17 07:26:26 -07001302 }
1303
Hal Canaryfafe1352017-04-11 12:12:02 -04001304 return SkSize{fDom->containerSize().width() * fScale, fDom->containerSize().height() * fScale}
1305 .toRound();
fmalitaa2b9fdf2016-08-03 19:53:36 -07001306}
1307
fmalitaacd2f5c2016-11-08 07:13:45 -08001308Name SVGSrc::name() const { return fName; }
fmalitaa2b9fdf2016-08-03 19:53:36 -07001309
fmalita179d8852016-08-16 14:23:29 -07001310bool SVGSrc::veto(SinkFlags flags) const {
Florin Malita93323eb2017-06-16 15:31:17 -04001311 // No need to test to non-(raster||gpu||vector) or indirect backends.
fmalita179d8852016-08-16 14:23:29 -07001312 bool type_ok = flags.type == SinkFlags::kRaster
Florin Malita93323eb2017-06-16 15:31:17 -04001313 || flags.type == SinkFlags::kGPU
1314 || flags.type == SinkFlags::kVector;
fmalita179d8852016-08-16 14:23:29 -07001315
1316 return !type_ok || flags.approach != SinkFlags::kDirect;
1317}
1318
fmalitaa2b9fdf2016-08-03 19:53:36 -07001319#endif // defined(SK_XML)
1320/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
mtklein748ca3b2015-01-15 10:56:12 -08001321
halcanary45420a92016-06-02 12:41:14 -07001322MSKPSrc::MSKPSrc(Path path) : fPath(path) {
bungemanf93d7112016-09-16 06:24:20 -07001323 std::unique_ptr<SkStreamAsset> stream = SkStream::MakeFromFile(fPath.c_str());
Hal Canary45cde312017-04-03 16:06:42 -04001324 int count = SkMultiPictureDocumentReadPageCount(stream.get());
1325 if (count > 0) {
1326 fPages.reset(count);
1327 (void)SkMultiPictureDocumentReadPageSizes(stream.get(), &fPages[0], fPages.count());
1328 }
halcanary45420a92016-06-02 12:41:14 -07001329}
1330
Hal Canary45cde312017-04-03 16:06:42 -04001331int MSKPSrc::pageCount() const { return fPages.count(); }
halcanary45420a92016-06-02 12:41:14 -07001332
1333SkISize MSKPSrc::size() const { return this->size(0); }
Hal Canary45cde312017-04-03 16:06:42 -04001334SkISize MSKPSrc::size(int i) const {
Hal Canaryfafe1352017-04-11 12:12:02 -04001335 return i >= 0 && i < fPages.count() ? fPages[i].fSize.toCeil() : SkISize{0, 0};
Hal Canary45cde312017-04-03 16:06:42 -04001336}
halcanary45420a92016-06-02 12:41:14 -07001337
1338Error MSKPSrc::draw(SkCanvas* c) const { return this->draw(0, c); }
1339Error MSKPSrc::draw(int i, SkCanvas* canvas) const {
Hal Canary45cde312017-04-03 16:06:42 -04001340 if (this->pageCount() == 0) {
halcanary45420a92016-06-02 12:41:14 -07001341 return SkStringPrintf("Unable to parse MultiPictureDocument file: %s", fPath.c_str());
1342 }
Hal Canary45cde312017-04-03 16:06:42 -04001343 if (i >= fPages.count() || i < 0) {
halcanary45420a92016-06-02 12:41:14 -07001344 return SkStringPrintf("MultiPictureDocument page number out of range: %d", i);
1345 }
Hal Canary45cde312017-04-03 16:06:42 -04001346 SkPicture* page = fPages[i].fPicture.get();
halcanary45420a92016-06-02 12:41:14 -07001347 if (!page) {
Hal Canary45cde312017-04-03 16:06:42 -04001348 std::unique_ptr<SkStreamAsset> stream = SkStream::MakeFromFile(fPath.c_str());
1349 if (!stream) {
1350 return SkStringPrintf("Unable to open file: %s", fPath.c_str());
1351 }
1352 if (!SkMultiPictureDocumentRead(stream.get(), &fPages[0], fPages.count())) {
1353 return SkStringPrintf("SkMultiPictureDocument reader failed on page %d: %s", i,
1354 fPath.c_str());
1355 }
1356 page = fPages[i].fPicture.get();
halcanary45420a92016-06-02 12:41:14 -07001357 }
1358 canvas->drawPicture(page);
1359 return "";
1360}
1361
1362Name MSKPSrc::name() const { return SkOSPath::Basename(fPath.c_str()); }
1363
1364/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
1365
mtkleinad66f9b2015-02-13 15:11:10 -08001366Error NullSink::draw(const Src& src, SkBitmap*, SkWStream*, SkString*) const {
Mike Reed5df49342016-11-12 08:06:55 -06001367 return src.draw(SkMakeNullCanvas().get());
mtkleinad66f9b2015-02-13 15:11:10 -08001368}
1369
1370/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
1371
Brian Osmane5756ec2017-09-06 17:08:30 -04001372static Error compare_bitmaps(const SkBitmap& reference, const SkBitmap& bitmap) {
1373 // The dimensions are a property of the Src only, and so should be identical.
Mike Reedf0ffb892017-10-03 14:47:21 -04001374 SkASSERT(reference.computeByteSize() == bitmap.computeByteSize());
1375 if (reference.computeByteSize() != bitmap.computeByteSize()) {
Brian Osmane5756ec2017-09-06 17:08:30 -04001376 return "Dimensions don't match reference";
1377 }
1378 // All SkBitmaps in DM are tight, so this comparison is easy.
Mike Reedf0ffb892017-10-03 14:47:21 -04001379 if (0 != memcmp(reference.getPixels(), bitmap.getPixels(), reference.computeByteSize())) {
Brian Osmane5756ec2017-09-06 17:08:30 -04001380 SkString encoded;
1381 SkString errString("Pixels don't match reference");
Michael Ludwige8e10752018-10-01 12:42:53 -04001382 if (bitmap_to_base64_data_uri(reference, &encoded)) {
1383 errString.append("\nExpected: ");
Brian Osmane5756ec2017-09-06 17:08:30 -04001384 errString.append(encoded);
1385 } else {
1386 errString.append("\nExpected image failed to encode: ");
1387 errString.append(encoded);
1388 }
Michael Ludwige8e10752018-10-01 12:42:53 -04001389 if (bitmap_to_base64_data_uri(bitmap, &encoded)) {
1390 errString.append("\nActual: ");
Brian Osmane5756ec2017-09-06 17:08:30 -04001391 errString.append(encoded);
1392 } else {
1393 errString.append("\nActual image failed to encode: ");
1394 errString.append(encoded);
1395 }
1396 return errString;
1397 }
1398 return "";
1399}
1400
1401/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
1402
mtkleinb9eb4ac2015-02-02 18:26:03 -08001403DEFINE_bool(gpuStats, false, "Append GPU stats to the log for each GPU task?");
1404
bsalomon85b4b532016-04-05 11:06:27 -07001405GPUSink::GPUSink(GrContextFactory::ContextType ct,
csmartdaltone812d492017-02-21 12:36:05 -07001406 GrContextFactory::ContextOverrides overrides,
Brian Salomonf865b052018-03-09 09:01:53 -05001407 SkCommandLineConfigGpu::SurfType surfType,
mtklein82d28432015-01-15 12:46:02 -08001408 int samples,
bsalomonafcd7cd2015-08-31 12:39:41 -07001409 bool diText,
brianosmand93c1202016-03-10 07:49:08 -08001410 SkColorType colorType,
Brian Salomonce5ee602017-07-17 11:31:31 -04001411 SkAlphaType alphaType,
brianosmanb109b8c2016-06-16 13:03:24 -07001412 sk_sp<SkColorSpace> colorSpace,
Brian Osmanf21aa042017-08-21 16:48:46 -04001413 bool threaded,
1414 const GrContextOptions& grCtxOptions)
Brian Salomonce5ee602017-07-17 11:31:31 -04001415 : fContextType(ct)
1416 , fContextOverrides(overrides)
Brian Salomonf865b052018-03-09 09:01:53 -05001417 , fSurfType(surfType)
Brian Salomonce5ee602017-07-17 11:31:31 -04001418 , fSampleCount(samples)
1419 , fUseDIText(diText)
1420 , fColorType(colorType)
1421 , fAlphaType(alphaType)
1422 , fColorSpace(std::move(colorSpace))
Brian Osmanf21aa042017-08-21 16:48:46 -04001423 , fThreaded(threaded)
1424 , fBaseContextOptions(grCtxOptions) {}
mtklein748ca3b2015-01-15 10:56:12 -08001425
Brian Salomon09d994e2016-12-21 11:14:46 -05001426DEFINE_bool(drawOpClip, false, "Clip each GrDrawOp to its device bounds for testing.");
bsalomon648c6962015-10-23 09:06:59 -07001427
Brian Osmanf9810662017-08-30 10:02:10 -04001428Error GPUSink::draw(const Src& src, SkBitmap* dst, SkWStream* dstStream, SkString* log) const {
1429 return this->onDraw(src, dst, dstStream, log, fBaseContextOptions);
1430}
1431
1432Error GPUSink::onDraw(const Src& src, SkBitmap* dst, SkWStream*, SkString* log,
1433 const GrContextOptions& baseOptions) const {
1434 GrContextOptions grOptions = baseOptions;
kkinnunen64492c42015-12-08 01:24:40 -08001435
Brian Salomon00a5eb82018-07-11 15:32:05 -04001436 // We don't expect the src to mess with the persistent cache or the executor.
1437 SkDEBUGCODE(auto cache = grOptions.fPersistentCache);
1438 SkDEBUGCODE(auto exec = grOptions.fExecutor);
kkinnunen5219fd92015-12-10 06:28:13 -08001439 src.modifyGrContextOptions(&grOptions);
Brian Salomon00a5eb82018-07-11 15:32:05 -04001440 SkASSERT(cache == grOptions.fPersistentCache);
1441 SkASSERT(exec == grOptions.fExecutor);
kkinnunen5219fd92015-12-10 06:28:13 -08001442
1443 GrContextFactory factory(grOptions);
mtkleinf4ba3212015-01-28 15:32:24 -08001444 const SkISize size = src.size();
Brian Salomonce5ee602017-07-17 11:31:31 -04001445 SkImageInfo info =
1446 SkImageInfo::Make(size.width(), size.height(), fColorType, fAlphaType, fColorSpace);
Brian Salomonf865b052018-03-09 09:01:53 -05001447 sk_sp<SkSurface> surface;
csmartdaltone812d492017-02-21 12:36:05 -07001448 GrContext* context = factory.getContextInfo(fContextType, fContextOverrides).grContext();
Brian Salomonc7fe0f72018-05-11 10:14:21 -04001449 const int maxDimension = context->contextPriv().caps()->maxTextureSize();
msarett13a036b2016-02-08 09:10:47 -08001450 if (maxDimension < SkTMax(size.width(), size.height())) {
1451 return Error::Nonfatal("Src too large to create a texture.\n");
1452 }
Brian Salomonf865b052018-03-09 09:01:53 -05001453 uint32_t flags = fUseDIText ? SkSurfaceProps::kUseDeviceIndependentFonts_Flag : 0;
1454 SkSurfaceProps props(flags, SkSurfaceProps::kLegacyFontHost_InitType);
1455 GrBackendTexture backendTexture;
1456 GrBackendRenderTarget backendRT;
1457 switch (fSurfType) {
1458 case SkCommandLineConfigGpu::SurfType::kDefault:
1459 surface = SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, info, fSampleCount,
1460 &props);
1461 break;
1462 case SkCommandLineConfigGpu::SurfType::kBackendTexture:
1463 backendTexture = context->contextPriv().getGpu()->createTestingOnlyBackendTexture(
Brian Osman2b23c4b2018-06-01 12:25:08 -04001464 nullptr, info.width(), info.height(), info.colorType(), true, GrMipMapped::kNo);
Brian Salomonf865b052018-03-09 09:01:53 -05001465 surface = SkSurface::MakeFromBackendTexture(context, backendTexture,
1466 kTopLeft_GrSurfaceOrigin, fSampleCount,
Brian Salomon53706772018-03-19 14:18:08 -04001467 fColorType, info.refColorSpace(), &props);
Brian Salomonf865b052018-03-09 09:01:53 -05001468 break;
1469 case SkCommandLineConfigGpu::SurfType::kBackendRenderTarget:
1470 if (1 == fSampleCount) {
Brian Salomonf865b052018-03-09 09:01:53 -05001471 auto colorType = SkColorTypeToGrColorType(info.colorType());
1472 backendRT = context->contextPriv().getGpu()->createTestingOnlyBackendRenderTarget(
Brian Osman2d010b62018-08-09 10:55:09 -04001473 info.width(), info.height(), colorType);
Brian Salomon49edccd2018-03-23 15:31:32 -04001474 surface = SkSurface::MakeFromBackendRenderTarget(
1475 context, backendRT, kBottomLeft_GrSurfaceOrigin, info.colorType(),
1476 info.refColorSpace(), &props);
Brian Salomonf865b052018-03-09 09:01:53 -05001477 }
1478 break;
1479 }
msarett13a036b2016-02-08 09:10:47 -08001480
mtklein748ca3b2015-01-15 10:56:12 -08001481 if (!surface) {
1482 return "Could not create a surface.";
1483 }
joshualitt5f5a8d72015-02-25 14:09:45 -08001484 if (FLAGS_preAbandonGpuContext) {
joshualitt5f5a8d72015-02-25 14:09:45 -08001485 factory.abandonContexts();
1486 }
mtklein748ca3b2015-01-15 10:56:12 -08001487 SkCanvas* canvas = surface->getCanvas();
1488 Error err = src.draw(canvas);
1489 if (!err.isEmpty()) {
1490 return err;
1491 }
1492 canvas->flush();
mtkleinb9eb4ac2015-02-02 18:26:03 -08001493 if (FLAGS_gpuStats) {
Robert Phillips0c4b7b12018-03-06 08:20:37 -05001494 canvas->getGrContext()->contextPriv().dumpCacheStats(log);
1495 canvas->getGrContext()->contextPriv().dumpGpuStats(log);
mtkleinb9eb4ac2015-02-02 18:26:03 -08001496 }
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001497 if (info.colorType() == kRGB_565_SkColorType || info.colorType() == kARGB_4444_SkColorType ||
1498 info.colorType() == kRGB_888x_SkColorType) {
Brian Salomonce5ee602017-07-17 11:31:31 -04001499 // We don't currently support readbacks into these formats on the GPU backend. Convert to
1500 // 32 bit.
1501 info = SkImageInfo::Make(size.width(), size.height(), kRGBA_8888_SkColorType,
1502 kPremul_SkAlphaType, fColorSpace);
1503 }
mtklein748ca3b2015-01-15 10:56:12 -08001504 dst->allocPixels(info);
Mike Reed12e946b2017-04-17 10:53:29 -04001505 canvas->readPixels(*dst, 0, 0);
mtklein55e88b22015-01-21 15:50:13 -08001506 if (FLAGS_abandonGpuContext) {
1507 factory.abandonContexts();
bsalomon6e2aad42016-04-01 11:54:31 -07001508 } else if (FLAGS_releaseAndAbandonGpuContext) {
1509 factory.releaseResourcesAndAbandonContexts();
mtklein55e88b22015-01-21 15:50:13 -08001510 }
Khushalc421ca12018-06-26 14:38:34 -07001511 if (!context->abandoned()) {
Brian Salomonf865b052018-03-09 09:01:53 -05001512 surface.reset();
1513 if (backendTexture.isValid()) {
Brian Salomon26102cb2018-03-09 09:33:19 -05001514 context->contextPriv().getGpu()->deleteTestingOnlyBackendTexture(backendTexture);
Brian Salomonf865b052018-03-09 09:01:53 -05001515 }
1516 if (backendRT.isValid()) {
1517 context->contextPriv().getGpu()->deleteTestingOnlyBackendRenderTarget(backendRT);
1518 }
1519 }
mtklein748ca3b2015-01-15 10:56:12 -08001520 return "";
1521}
1522
1523/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
1524
Brian Osmanf9810662017-08-30 10:02:10 -04001525GPUThreadTestingSink::GPUThreadTestingSink(GrContextFactory::ContextType ct,
1526 GrContextFactory::ContextOverrides overrides,
Brian Salomonf865b052018-03-09 09:01:53 -05001527 SkCommandLineConfigGpu::SurfType surfType,
Brian Osmanf9810662017-08-30 10:02:10 -04001528 int samples,
1529 bool diText,
1530 SkColorType colorType,
1531 SkAlphaType alphaType,
1532 sk_sp<SkColorSpace> colorSpace,
1533 bool threaded,
1534 const GrContextOptions& grCtxOptions)
Brian Salomonf865b052018-03-09 09:01:53 -05001535 : INHERITED(ct, overrides, surfType, samples, diText, colorType, alphaType,
1536 std::move(colorSpace), threaded, grCtxOptions)
Mike Klein022cfa22017-09-01 11:53:16 -04001537 , fExecutor(SkExecutor::MakeFIFOThreadPool(FLAGS_gpuThreads)) {
Brian Osmanf9810662017-08-30 10:02:10 -04001538 SkASSERT(fExecutor);
1539}
1540
1541Error GPUThreadTestingSink::draw(const Src& src, SkBitmap* dst, SkWStream* wStream,
1542 SkString* log) const {
1543 // Draw twice, once with worker threads, and once without. Verify that we get the same result.
1544 // Also, force us to only use the software path renderer, so we really stress-test the threaded
1545 // version of that code.
1546 GrContextOptions contextOptions = this->baseContextOptions();
Brian Osman195c05b2017-08-30 15:14:04 -04001547 contextOptions.fGpuPathRenderers = GpuPathRenderers::kNone;
Greg Daniel024615e2018-05-10 17:25:52 +00001548 contextOptions.fExecutor = fExecutor.get();
Adrienne Walkerab7181d2018-05-14 14:02:03 -07001549
Brian Osmanf9810662017-08-30 10:02:10 -04001550 Error err = this->onDraw(src, dst, wStream, log, contextOptions);
1551 if (!err.isEmpty() || !dst) {
1552 return err;
1553 }
1554
1555 SkBitmap reference;
1556 SkString refLog;
1557 SkDynamicMemoryWStream refStream;
1558 contextOptions.fExecutor = nullptr;
1559 Error refErr = this->onDraw(src, &reference, &refStream, &refLog, contextOptions);
1560 if (!refErr.isEmpty()) {
1561 return refErr;
1562 }
1563
Brian Osmane5756ec2017-09-06 17:08:30 -04001564 return compare_bitmaps(reference, *dst);
Brian Osmanf9810662017-08-30 10:02:10 -04001565}
1566
1567/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
1568
Brian Salomon00a5eb82018-07-11 15:32:05 -04001569GPUPersistentCacheTestingSink::GPUPersistentCacheTestingSink(
1570 GrContextFactory::ContextType ct,
1571 GrContextFactory::ContextOverrides overrides,
1572 SkCommandLineConfigGpu::SurfType surfType,
1573 int samples,
1574 bool diText,
1575 SkColorType colorType,
1576 SkAlphaType alphaType,
1577 sk_sp<SkColorSpace> colorSpace,
1578 bool threaded,
1579 const GrContextOptions& grCtxOptions)
1580 : INHERITED(ct, overrides, surfType, samples, diText, colorType, alphaType,
1581 std::move(colorSpace), threaded, grCtxOptions) {}
1582
1583Error GPUPersistentCacheTestingSink::draw(const Src& src, SkBitmap* dst, SkWStream* wStream,
1584 SkString* log) const {
1585 // Draw twice, once with a cold cache, and again with a warm cache. Verify that we get the same
1586 // result.
1587 sk_gpu_test::MemoryCache memoryCache;
1588 GrContextOptions contextOptions = this->baseContextOptions();
1589 contextOptions.fPersistentCache = &memoryCache;
1590
1591 Error err = this->onDraw(src, dst, wStream, log, contextOptions);
1592 if (!err.isEmpty() || !dst) {
1593 return err;
1594 }
1595
1596 SkBitmap reference;
1597 SkString refLog;
1598 SkDynamicMemoryWStream refStream;
1599 memoryCache.resetNumCacheMisses();
1600 Error refErr = this->onDraw(src, &reference, &refStream, &refLog, contextOptions);
1601 if (!refErr.isEmpty()) {
1602 return refErr;
1603 }
Brian Salomon7fc52992018-07-12 16:20:23 -04001604 SkASSERT(!memoryCache.numCacheMisses());
Brian Salomon00a5eb82018-07-11 15:32:05 -04001605
1606 return compare_bitmaps(reference, *dst);
1607}
1608
1609/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
halcanary47ef4d52015-03-03 09:13:09 -08001610static Error draw_skdocument(const Src& src, SkDocument* doc, SkWStream* dst) {
halcanary4ba051c2016-03-10 10:31:53 -08001611 if (src.size().isEmpty()) {
1612 return "Source has empty dimensions";
1613 }
halcanary47ef4d52015-03-03 09:13:09 -08001614 SkASSERT(doc);
halcanary45420a92016-06-02 12:41:14 -07001615 int pageCount = src.pageCount();
1616 for (int i = 0; i < pageCount; ++i) {
1617 int width = src.size(i).width(), height = src.size(i).height();
halcanary7e798182015-04-14 14:06:18 -07001618 SkCanvas* canvas =
1619 doc->beginPage(SkIntToScalar(width), SkIntToScalar(height));
1620 if (!canvas) {
halcanary96fcdcc2015-08-27 07:41:13 -07001621 return "SkDocument::beginPage(w,h) returned nullptr";
halcanary7e798182015-04-14 14:06:18 -07001622 }
halcanary45420a92016-06-02 12:41:14 -07001623 Error err = src.draw(i, canvas);
halcanary7e798182015-04-14 14:06:18 -07001624 if (!err.isEmpty()) {
1625 return err;
1626 }
1627 doc->endPage();
mtklein748ca3b2015-01-15 10:56:12 -08001628 }
reedd14df7c2016-09-22 14:12:46 -07001629 doc->close();
halcanaryfd4a9932015-01-28 11:45:58 -08001630 dst->flush();
mtklein748ca3b2015-01-15 10:56:12 -08001631 return "";
1632}
1633
halcanary47ef4d52015-03-03 09:13:09 -08001634Error PDFSink::draw(const Src& src, SkBitmap*, SkWStream* dst, SkString*) const {
Hal Canary23564b92018-09-07 14:33:14 -04001635 SkPDF::Metadata metadata;
halcanary4b656662016-04-27 07:45:18 -07001636 metadata.fTitle = src.name();
1637 metadata.fSubject = "rendering correctness test";
1638 metadata.fCreator = "Skia/DM";
Mike Reeda4daf192017-12-14 13:25:04 -05001639 metadata.fRasterDPI = fRasterDpi;
1640 metadata.fPDFA = fPDFA;
Hal Canary23564b92018-09-07 14:33:14 -04001641 sk_sp<SkDocument> doc = SkPDF::MakeDocument(dst, metadata);
halcanary47ef4d52015-03-03 09:13:09 -08001642 if (!doc) {
Hal Canary23564b92018-09-07 14:33:14 -04001643 return "SkPDF::MakeDocument() returned nullptr";
halcanary47ef4d52015-03-03 09:13:09 -08001644 }
1645 return draw_skdocument(src, doc.get(), dst);
1646}
1647
1648/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
1649
1650XPSSink::XPSSink() {}
1651
Hal Canaryabc88d22017-02-06 09:26:49 -05001652#ifdef SK_BUILD_FOR_WIN
Hal Canary5e221e72017-02-06 09:51:42 -05001653static SkTScopedComPtr<IXpsOMObjectFactory> make_xps_factory() {
1654 IXpsOMObjectFactory* factory;
1655 HRN(CoCreateInstance(CLSID_XpsOMObjectFactory,
1656 nullptr,
1657 CLSCTX_INPROC_SERVER,
1658 IID_PPV_ARGS(&factory)));
1659 return SkTScopedComPtr<IXpsOMObjectFactory>(factory);
1660}
1661
1662Error XPSSink::draw(const Src& src, SkBitmap*, SkWStream* dst, SkString*) const {
Hal Canaryabc88d22017-02-06 09:26:49 -05001663 SkAutoCoInitialize com;
1664 if (!com.succeeded()) {
1665 return "Could not initialize COM.";
1666 }
Hal Canary5e221e72017-02-06 09:51:42 -05001667 SkTScopedComPtr<IXpsOMObjectFactory> factory = make_xps_factory();
1668 if (!factory) {
1669 return "Failed to create XPS Factory.";
1670 }
Hal Canary23564b92018-09-07 14:33:14 -04001671 sk_sp<SkDocument> doc(SkXPS::MakeDocument(dst, factory.get()));
halcanary47ef4d52015-03-03 09:13:09 -08001672 if (!doc) {
Hal Canary23564b92018-09-07 14:33:14 -04001673 return "SkXPS::MAkeDocument() returned nullptr";
halcanary47ef4d52015-03-03 09:13:09 -08001674 }
1675 return draw_skdocument(src, doc.get(), dst);
1676}
Hal Canary5e221e72017-02-06 09:51:42 -05001677#else
1678Error XPSSink::draw(const Src& src, SkBitmap*, SkWStream* dst, SkString*) const {
1679 return "XPS not supported on this platform.";
1680}
1681#endif
reed54dc4872016-09-13 08:09:45 -07001682
1683/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
1684
mtklein9c3f17d2015-01-28 11:35:18 -08001685SKPSink::SKPSink() {}
1686
mtkleinb9eb4ac2015-02-02 18:26:03 -08001687Error SKPSink::draw(const Src& src, SkBitmap*, SkWStream* dst, SkString*) const {
mtklein9c3f17d2015-01-28 11:35:18 -08001688 SkSize size;
1689 size = src.size();
1690 SkPictureRecorder recorder;
1691 Error err = src.draw(recorder.beginRecording(size.width(), size.height()));
1692 if (!err.isEmpty()) {
1693 return err;
1694 }
reedca2622b2016-03-18 07:25:55 -07001695 recorder.finishRecordingAsPicture()->serialize(dst);
mtklein9c3f17d2015-01-28 11:35:18 -08001696 return "";
1697}
1698
1699/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
1700
Hal Canary85c7fe82016-10-25 10:33:27 -04001701Error DebugSink::draw(const Src& src, SkBitmap*, SkWStream* dst, SkString*) const {
1702 SkDebugCanvas debugCanvas(src.size().width(), src.size().height());
1703 Error err = src.draw(&debugCanvas);
1704 if (!err.isEmpty()) {
1705 return err;
1706 }
Mike Reed5df49342016-11-12 08:06:55 -06001707 std::unique_ptr<SkCanvas> nullCanvas = SkMakeNullCanvas();
Hal Canary85c7fe82016-10-25 10:33:27 -04001708 UrlDataManager dataManager(SkString("data"));
1709 Json::Value json = debugCanvas.toJSON(
1710 dataManager, debugCanvas.getSize(), nullCanvas.get());
1711 std::string value = Json::StyledWriter().write(json);
1712 return dst->write(value.c_str(), value.size()) ? "" : "SkWStream Error";
1713}
1714
1715/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
1716
Bryce Thomas95a7b762018-03-02 13:54:21 -08001717SVGSink::SVGSink(int pageIndex) : fPageIndex(pageIndex) {}
mtklein8a4527e2015-01-31 20:00:58 -08001718
mtkleinb9eb4ac2015-02-02 18:26:03 -08001719Error SVGSink::draw(const Src& src, SkBitmap*, SkWStream* dst, SkString*) const {
fmalita718df0a2016-07-15 10:33:29 -07001720#if defined(SK_XML)
Bryce Thomas95a7b762018-03-02 13:54:21 -08001721 if (src.pageCount() > 1) {
1722 int pageCount = src.pageCount();
1723 if (fPageIndex > pageCount - 1) {
1724 return Error(SkStringPrintf("Page index %d too high for document with only %d pages.",
1725 fPageIndex, pageCount));
1726 }
1727 }
Ben Wagner145dbcd2016-11-03 14:40:50 -04001728 std::unique_ptr<SkXMLWriter> xmlWriter(new SkXMLStreamWriter(dst));
Bryce Thomas95a7b762018-03-02 13:54:21 -08001729 return src.draw(fPageIndex,
1730 SkSVGCanvas::Make(SkRect::MakeWH(SkIntToScalar(src.size().width()),
Mike Reed5df49342016-11-12 08:06:55 -06001731 SkIntToScalar(src.size().height())),
Bryce Thomas95a7b762018-03-02 13:54:21 -08001732 xmlWriter.get())
1733 .get());
fmalita718df0a2016-07-15 10:33:29 -07001734#else
Hal Canary327ef032018-03-22 13:10:51 -04001735 (void)fPageIndex;
fmalita718df0a2016-07-15 10:33:29 -07001736 return Error("SVG sink is disabled.");
1737#endif // SK_XML
mtklein8a4527e2015-01-31 20:00:58 -08001738}
1739
1740/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
1741
brianosmanb109b8c2016-06-16 13:03:24 -07001742RasterSink::RasterSink(SkColorType colorType, sk_sp<SkColorSpace> colorSpace)
mtklein27c3fdd2016-02-26 14:43:21 -08001743 : fColorType(colorType)
brianosmanb109b8c2016-06-16 13:03:24 -07001744 , fColorSpace(std::move(colorSpace)) {}
mtklein748ca3b2015-01-15 10:56:12 -08001745
Mike Klein48b64902018-07-25 13:28:44 -04001746Error RasterSink::draw(const Src& src, SkBitmap* dst, SkWStream*, SkString*) const {
mtkleinf4ba3212015-01-28 15:32:24 -08001747 const SkISize size = src.size();
mtklein748ca3b2015-01-15 10:56:12 -08001748 // If there's an appropriate alpha type for this color type, use it, otherwise use premul.
1749 SkAlphaType alphaType = kPremul_SkAlphaType;
1750 (void)SkColorTypeValidateAlphaType(fColorType, alphaType, &alphaType);
1751
Mike Reed086a4272017-07-18 10:53:11 -04001752 dst->allocPixelsFlags(SkImageInfo::Make(size.width(), size.height(),
1753 fColorType, alphaType, fColorSpace),
1754 SkBitmap::kZeroPixels_AllocFlag);
Yuqian Lib8b62532018-02-23 14:13:36 +08001755
mtklein748ca3b2015-01-15 10:56:12 -08001756 SkCanvas canvas(*dst);
1757 return src.draw(&canvas);
1758}
1759
1760/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
1761
mtkleina16e69e2015-05-05 11:38:45 -07001762// Handy for front-patching a Src. Do whatever up-front work you need, then call draw_to_canvas(),
mtkleine44b5082015-05-07 10:53:34 -07001763// passing the Sink draw() arguments, a size, and a function draws into an SkCanvas.
mtkleina16e69e2015-05-05 11:38:45 -07001764// Several examples below.
1765
mtkleincbf89782016-02-19 14:27:14 -08001766template <typename Fn>
msarett62d3b102015-12-10 15:14:27 -08001767static Error draw_to_canvas(Sink* sink, SkBitmap* bitmap, SkWStream* stream, SkString* log,
mtkleincbf89782016-02-19 14:27:14 -08001768 SkISize size, const Fn& draw) {
mtkleina16e69e2015-05-05 11:38:45 -07001769 class ProxySrc : public Src {
1770 public:
mtkleincbf89782016-02-19 14:27:14 -08001771 ProxySrc(SkISize size, const Fn& draw) : fSize(size), fDraw(draw) {}
mtkleina16e69e2015-05-05 11:38:45 -07001772 Error draw(SkCanvas* canvas) const override { return fDraw(canvas); }
halcanaryb4a7f142016-03-30 08:31:27 -07001773 Name name() const override { return "ProxySrc"; }
1774 SkISize size() const override { return fSize; }
mtkleina16e69e2015-05-05 11:38:45 -07001775 private:
mtkleincbf89782016-02-19 14:27:14 -08001776 SkISize fSize;
1777 const Fn& fDraw;
mtkleina16e69e2015-05-05 11:38:45 -07001778 };
msarett62d3b102015-12-10 15:14:27 -08001779 return sink->draw(ProxySrc(size, draw), bitmap, stream, log);
mtkleina16e69e2015-05-05 11:38:45 -07001780}
1781
1782/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
1783
mtklein4a34ecb2016-01-08 10:19:35 -08001784DEFINE_bool(check, true, "If true, have most Via- modes fail if they affect the output.");
1785
1786// Is *bitmap identical to what you get drawing src into sink?
1787static Error check_against_reference(const SkBitmap* bitmap, const Src& src, Sink* sink) {
1788 // We can only check raster outputs.
1789 // (Non-raster outputs like .pdf, .skp, .svg may differ but still draw identically.)
1790 if (FLAGS_check && bitmap) {
1791 SkBitmap reference;
1792 SkString log;
halcanaryb4a7f142016-03-30 08:31:27 -07001793 SkDynamicMemoryWStream wStream;
1794 Error err = sink->draw(src, &reference, &wStream, &log);
mtklein4a34ecb2016-01-08 10:19:35 -08001795 // If we can draw into this Sink via some pipeline, we should be able to draw directly.
1796 SkASSERT(err.isEmpty());
1797 if (!err.isEmpty()) {
1798 return err;
1799 }
Brian Osmane5756ec2017-09-06 17:08:30 -04001800 return compare_bitmaps(reference, *bitmap);
mtklein4a34ecb2016-01-08 10:19:35 -08001801 }
1802 return "";
1803}
1804
1805/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
1806
mtkleind603b222015-02-17 11:13:33 -08001807static SkISize auto_compute_translate(SkMatrix* matrix, int srcW, int srcH) {
1808 SkRect bounds = SkRect::MakeIWH(srcW, srcH);
1809 matrix->mapRect(&bounds);
1810 matrix->postTranslate(-bounds.x(), -bounds.y());
Hal Canaryfafe1352017-04-11 12:12:02 -04001811 return {SkScalarRoundToInt(bounds.width()), SkScalarRoundToInt(bounds.height())};
mtkleind603b222015-02-17 11:13:33 -08001812}
1813
msarett62d3b102015-12-10 15:14:27 -08001814ViaMatrix::ViaMatrix(SkMatrix matrix, Sink* sink) : Via(sink), fMatrix(matrix) {}
mtklein748ca3b2015-01-15 10:56:12 -08001815
mtkleinb9eb4ac2015-02-02 18:26:03 -08001816Error ViaMatrix::draw(const Src& src, SkBitmap* bitmap, SkWStream* stream, SkString* log) const {
mtkleina16e69e2015-05-05 11:38:45 -07001817 SkMatrix matrix = fMatrix;
1818 SkISize size = auto_compute_translate(&matrix, src.size().width(), src.size().height());
Ben Wagner145dbcd2016-11-03 14:40:50 -04001819 return draw_to_canvas(fSink.get(), bitmap, stream, log, size, [&](SkCanvas* canvas) {
mtkleina16e69e2015-05-05 11:38:45 -07001820 canvas->concat(matrix);
1821 return src.draw(canvas);
1822 });
mtklein748ca3b2015-01-15 10:56:12 -08001823}
1824
mtkleind603b222015-02-17 11:13:33 -08001825// Undoes any flip or 90 degree rotate without changing the scale of the bitmap.
1826// This should be pixel-preserving.
msarett62d3b102015-12-10 15:14:27 -08001827ViaUpright::ViaUpright(SkMatrix matrix, Sink* sink) : Via(sink), fMatrix(matrix) {}
mtkleind603b222015-02-17 11:13:33 -08001828
1829Error ViaUpright::draw(const Src& src, SkBitmap* bitmap, SkWStream* stream, SkString* log) const {
1830 Error err = fSink->draw(src, bitmap, stream, log);
1831 if (!err.isEmpty()) {
1832 return err;
1833 }
1834
1835 SkMatrix inverse;
1836 if (!fMatrix.rectStaysRect() || !fMatrix.invert(&inverse)) {
1837 return "Cannot upright --matrix.";
1838 }
1839 SkMatrix upright = SkMatrix::I();
1840 upright.setScaleX(SkScalarSignAsScalar(inverse.getScaleX()));
1841 upright.setScaleY(SkScalarSignAsScalar(inverse.getScaleY()));
1842 upright.setSkewX(SkScalarSignAsScalar(inverse.getSkewX()));
1843 upright.setSkewY(SkScalarSignAsScalar(inverse.getSkewY()));
1844
1845 SkBitmap uprighted;
1846 SkISize size = auto_compute_translate(&upright, bitmap->width(), bitmap->height());
1847 uprighted.allocPixels(bitmap->info().makeWH(size.width(), size.height()));
1848
1849 SkCanvas canvas(uprighted);
1850 canvas.concat(upright);
1851 SkPaint paint;
reed374772b2016-10-05 17:33:02 -07001852 paint.setBlendMode(SkBlendMode::kSrc);
mtkleind603b222015-02-17 11:13:33 -08001853 canvas.drawBitmap(*bitmap, 0, 0, &paint);
1854
1855 *bitmap = uprighted;
mtkleind603b222015-02-17 11:13:33 -08001856 return "";
1857}
1858
mtklein748ca3b2015-01-15 10:56:12 -08001859/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
1860
mtkleina16e69e2015-05-05 11:38:45 -07001861Error ViaSerialization::draw(
1862 const Src& src, SkBitmap* bitmap, SkWStream* stream, SkString* log) const {
mtklein748ca3b2015-01-15 10:56:12 -08001863 // Record our Src into a picture.
mtkleina16e69e2015-05-05 11:38:45 -07001864 auto size = src.size();
mtklein748ca3b2015-01-15 10:56:12 -08001865 SkPictureRecorder recorder;
mtkleina16e69e2015-05-05 11:38:45 -07001866 Error err = src.draw(recorder.beginRecording(SkIntToScalar(size.width()),
1867 SkIntToScalar(size.height())));
mtklein748ca3b2015-01-15 10:56:12 -08001868 if (!err.isEmpty()) {
1869 return err;
1870 }
reedca2622b2016-03-18 07:25:55 -07001871 sk_sp<SkPicture> pic(recorder.finishRecordingAsPicture());
mtklein748ca3b2015-01-15 10:56:12 -08001872
1873 // Serialize it and then deserialize it.
reed39eaf5f2016-09-15 07:19:35 -07001874 sk_sp<SkPicture> deserialized(SkPicture::MakeFromData(pic->serialize().get()));
mtklein748ca3b2015-01-15 10:56:12 -08001875
Ben Wagner1861e882018-04-04 17:40:46 -04001876 err = draw_to_canvas(fSink.get(), bitmap, stream, log, size, [&](SkCanvas* canvas) {
mtkleina16e69e2015-05-05 11:38:45 -07001877 canvas->drawPicture(deserialized);
Ben Wagner1861e882018-04-04 17:40:46 -04001878 return "";
mtkleina16e69e2015-05-05 11:38:45 -07001879 });
Ben Wagner1861e882018-04-04 17:40:46 -04001880 if (!err.isEmpty()) {
1881 return err;
1882 }
1883
1884 return check_against_reference(bitmap, src, fSink.get());
mtklein748ca3b2015-01-15 10:56:12 -08001885}
1886
1887/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
1888
msarett62d3b102015-12-10 15:14:27 -08001889ViaTiles::ViaTiles(int w, int h, SkBBHFactory* factory, Sink* sink)
1890 : Via(sink)
mtklein78829242015-05-06 07:54:07 -07001891 , fW(w)
mtklein748ca3b2015-01-15 10:56:12 -08001892 , fH(h)
mtklein78829242015-05-06 07:54:07 -07001893 , fFactory(factory) {}
mtklein748ca3b2015-01-15 10:56:12 -08001894
mtkleinb9eb4ac2015-02-02 18:26:03 -08001895Error ViaTiles::draw(const Src& src, SkBitmap* bitmap, SkWStream* stream, SkString* log) const {
mtkleina16e69e2015-05-05 11:38:45 -07001896 auto size = src.size();
mtklein748ca3b2015-01-15 10:56:12 -08001897 SkPictureRecorder recorder;
mtkleina16e69e2015-05-05 11:38:45 -07001898 Error err = src.draw(recorder.beginRecording(SkIntToScalar(size.width()),
1899 SkIntToScalar(size.height()),
1900 fFactory.get()));
mtklein748ca3b2015-01-15 10:56:12 -08001901 if (!err.isEmpty()) {
1902 return err;
1903 }
reedca2622b2016-03-18 07:25:55 -07001904 sk_sp<SkPicture> pic(recorder.finishRecordingAsPicture());
mtklein748ca3b2015-01-15 10:56:12 -08001905
Ben Wagner145dbcd2016-11-03 14:40:50 -04001906 return draw_to_canvas(fSink.get(), bitmap, stream, log, src.size(), [&](SkCanvas* canvas) {
mtkleina16e69e2015-05-05 11:38:45 -07001907 const int xTiles = (size.width() + fW - 1) / fW,
1908 yTiles = (size.height() + fH - 1) / fH;
1909 SkMultiPictureDraw mpd(xTiles*yTiles);
reede8f30622016-03-23 18:59:25 -07001910 SkTArray<sk_sp<SkSurface>> surfaces;
1911// surfaces.setReserve(xTiles*yTiles);
mtklein748ca3b2015-01-15 10:56:12 -08001912
mtkleina16e69e2015-05-05 11:38:45 -07001913 SkImageInfo info = canvas->imageInfo().makeWH(fW, fH);
1914 for (int j = 0; j < yTiles; j++) {
1915 for (int i = 0; i < xTiles; i++) {
1916 // This lets our ultimate Sink determine the best kind of surface.
1917 // E.g., if it's a GpuSink, the surfaces and images are textures.
reede8f30622016-03-23 18:59:25 -07001918 auto s = canvas->makeSurface(info);
Cary Clarka24712e2018-09-05 18:41:40 +00001919 if (!s) {
1920 s = SkSurface::MakeRaster(info); // Some canvases can't create surfaces.
1921 }
reede8f30622016-03-23 18:59:25 -07001922 surfaces.push_back(s);
mtkleina16e69e2015-05-05 11:38:45 -07001923 SkCanvas* c = s->getCanvas();
1924 c->translate(SkIntToScalar(-i * fW),
1925 SkIntToScalar(-j * fH)); // Line up the canvas with this tile.
reedca2622b2016-03-18 07:25:55 -07001926 mpd.add(c, pic.get());
mtklein748ca3b2015-01-15 10:56:12 -08001927 }
mtklein748ca3b2015-01-15 10:56:12 -08001928 }
mtkleina16e69e2015-05-05 11:38:45 -07001929 mpd.draw();
1930 for (int j = 0; j < yTiles; j++) {
1931 for (int i = 0; i < xTiles; i++) {
reed9ce9d672016-03-17 10:51:11 -07001932 sk_sp<SkImage> image(surfaces[i+xTiles*j]->makeImageSnapshot());
mtkleina16e69e2015-05-05 11:38:45 -07001933 canvas->drawImage(image, SkIntToScalar(i*fW), SkIntToScalar(j*fH));
1934 }
1935 }
mtkleina16e69e2015-05-05 11:38:45 -07001936 return "";
1937 });
mtklein748ca3b2015-01-15 10:56:12 -08001938}
1939
mtkleinb7e8d692015-04-07 08:30:32 -07001940/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
1941
Robert Phillips33f02ed2018-03-27 08:06:57 -04001942ViaDDL::ViaDDL(int numDivisions, Sink* sink)
1943 : Via(sink)
1944 , fNumDivisions(numDivisions) {
1945}
1946
Robert Phillips33f02ed2018-03-27 08:06:57 -04001947Error ViaDDL::draw(const Src& src, SkBitmap* bitmap, SkWStream* stream, SkString* log) const {
1948 auto size = src.size();
1949 SkPictureRecorder recorder;
1950 Error err = src.draw(recorder.beginRecording(SkIntToScalar(size.width()),
1951 SkIntToScalar(size.height())));
1952 if (!err.isEmpty()) {
1953 return err;
1954 }
1955 sk_sp<SkPicture> inputPicture(recorder.finishRecordingAsPicture());
1956
1957 // this is our ultimate final drawing area/rect
1958 SkIRect viewport = SkIRect::MakeWH(size.fWidth, size.fHeight);
1959
Robert Phillips96601082018-05-29 16:13:26 -04001960 DDLPromiseImageHelper promiseImageHelper;
1961 sk_sp<SkData> compressedPictureData = promiseImageHelper.deflateSKP(inputPicture.get());
1962 if (!compressedPictureData) {
1963 return SkStringPrintf("ViaDDL: Couldn't deflate SkPicture");
Robert Phillips33f02ed2018-03-27 08:06:57 -04001964 }
1965
Robert Phillips33f02ed2018-03-27 08:06:57 -04001966 return draw_to_canvas(fSink.get(), bitmap, stream, log, size,
1967 [&](SkCanvas* canvas) -> Error {
1968 GrContext* context = canvas->getGrContext();
1969 if (!context || !context->contextPriv().getGpu()) {
1970 return SkStringPrintf("DDLs are GPU only");
1971 }
1972
Robert Phillipsa479f962018-04-10 11:45:40 -04001973 // This is here bc this is the first point where we have access to the context
Robert Phillips96601082018-05-29 16:13:26 -04001974 promiseImageHelper.uploadAllToGPU(context);
Robert Phillips33f02ed2018-03-27 08:06:57 -04001975
Robert Phillips96601082018-05-29 16:13:26 -04001976 // First, create all the tiles (including their individual dest surfaces)
1977 DDLTileHelper tiles(canvas, viewport, fNumDivisions);
Robert Phillips33f02ed2018-03-27 08:06:57 -04001978
Robert Phillips96601082018-05-29 16:13:26 -04001979 // Second, reinflate the compressed picture individually for each thread
1980 tiles.createSKPPerTile(compressedPictureData.get(), promiseImageHelper);
Robert Phillips33f02ed2018-03-27 08:06:57 -04001981
Robert Phillips96601082018-05-29 16:13:26 -04001982 // Third, create the DDLs in parallel
1983 tiles.createDDLsInParallel();
Robert Phillips33f02ed2018-03-27 08:06:57 -04001984
Robert Phillips96601082018-05-29 16:13:26 -04001985 // This drops the promiseImageHelper's refs on all the promise images
1986 promiseImageHelper.reset();
Robert Phillips33f02ed2018-03-27 08:06:57 -04001987
Robert Phillips96601082018-05-29 16:13:26 -04001988 // Fourth, synchronously render the display lists into the dest tiles
Robert Phillips33f02ed2018-03-27 08:06:57 -04001989 // TODO: it would be cool to not wait until all the tiles are drawn to begin
1990 // drawing to the GPU and composing to the final surface
Robert Phillips96601082018-05-29 16:13:26 -04001991 tiles.drawAllTilesAndFlush(context, false);
Robert Phillips33f02ed2018-03-27 08:06:57 -04001992
1993 // Finally, compose the drawn tiles into the result
1994 // Note: the separation between the tiles and the final composition better
1995 // matches Chrome but costs us a copy
Robert Phillips96601082018-05-29 16:13:26 -04001996 tiles.composeAllTiles(canvas);
Robert Phillips33f02ed2018-03-27 08:06:57 -04001997
Robert Phillipscc473352018-03-27 10:46:00 -04001998 context->flush();
Robert Phillips33f02ed2018-03-27 08:06:57 -04001999 return "";
2000 });
2001}
2002
Robert Phillips33f02ed2018-03-27 08:06:57 -04002003/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
2004
mtklein4a34ecb2016-01-08 10:19:35 -08002005Error ViaPicture::draw(const Src& src, SkBitmap* bitmap, SkWStream* stream, SkString* log) const {
2006 auto size = src.size();
Ben Wagner1861e882018-04-04 17:40:46 -04002007 Error err = draw_to_canvas(fSink.get(), bitmap, stream, log, size, [&](SkCanvas* canvas) {
mtklein4a34ecb2016-01-08 10:19:35 -08002008 SkPictureRecorder recorder;
reedca2622b2016-03-18 07:25:55 -07002009 sk_sp<SkPicture> pic;
mtklein4a34ecb2016-01-08 10:19:35 -08002010 Error err = src.draw(recorder.beginRecording(SkIntToScalar(size.width()),
2011 SkIntToScalar(size.height())));
2012 if (!err.isEmpty()) {
2013 return err;
2014 }
reedca2622b2016-03-18 07:25:55 -07002015 pic = recorder.finishRecordingAsPicture();
mtklein4a34ecb2016-01-08 10:19:35 -08002016 canvas->drawPicture(pic);
Ben Wagner1861e882018-04-04 17:40:46 -04002017 return err;
mtklein4a34ecb2016-01-08 10:19:35 -08002018 });
Ben Wagner1861e882018-04-04 17:40:46 -04002019 if (!err.isEmpty()) {
2020 return err;
2021 }
2022
2023 return check_against_reference(bitmap, src, fSink.get());
mtklein4a34ecb2016-01-08 10:19:35 -08002024}
2025
2026/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
2027
Mike Reedbae888e2017-02-18 16:50:45 -05002028#ifdef TEST_VIA_SVG
Mike Reedf67c4592017-02-17 17:06:11 -05002029#include "SkXMLWriter.h"
2030#include "SkSVGCanvas.h"
2031#include "SkSVGDOM.h"
2032
2033Error ViaSVG::draw(const Src& src, SkBitmap* bitmap, SkWStream* stream, SkString* log) const {
2034 auto size = src.size();
2035 return draw_to_canvas(fSink.get(), bitmap, stream, log, size, [&](SkCanvas* canvas) -> Error {
2036 SkDynamicMemoryWStream wstream;
2037 SkXMLStreamWriter writer(&wstream);
2038 Error err = src.draw(SkSVGCanvas::Make(SkRect::Make(size), &writer).get());
2039 if (!err.isEmpty()) {
2040 return err;
2041 }
2042 std::unique_ptr<SkStream> rstream(wstream.detachAsStream());
2043 auto dom = SkSVGDOM::MakeFromStream(*rstream);
2044 if (dom) {
2045 dom->setContainerSize(SkSize::Make(size));
2046 dom->render(canvas);
2047 }
2048 return "";
2049 });
2050}
Mike Reedbae888e2017-02-18 16:50:45 -05002051#endif
Mike Reedf67c4592017-02-17 17:06:11 -05002052
2053/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
2054
mtklein9c5052f2016-08-06 12:51:51 -07002055Error ViaLite::draw(const Src& src, SkBitmap* bitmap, SkWStream* stream, SkString* log) const {
2056 auto size = src.size();
Derek Sollenbergerd7875f52017-03-01 15:33:23 -05002057 SkIRect bounds = {0,0, size.width(), size.height()};
Ben Wagner1861e882018-04-04 17:40:46 -04002058 Error err = draw_to_canvas(fSink.get(), bitmap, stream, log, size, [&](SkCanvas* canvas) {
Derek Sollenbergerd7875f52017-03-01 15:33:23 -05002059 SkLiteDL dl;
mtklein8bbbb692016-08-15 12:56:00 -07002060 SkLiteRecorder rec;
Derek Sollenbergerd7875f52017-03-01 15:33:23 -05002061 rec.reset(&dl, bounds);
mtklein8bbbb692016-08-15 12:56:00 -07002062
2063 Error err = src.draw(&rec);
mtklein9c5052f2016-08-06 12:51:51 -07002064 if (!err.isEmpty()) {
2065 return err;
2066 }
Derek Sollenbergerd7875f52017-03-01 15:33:23 -05002067 dl.draw(canvas);
Ben Wagner1861e882018-04-04 17:40:46 -04002068 return err;
mtklein9c5052f2016-08-06 12:51:51 -07002069 });
Ben Wagner1861e882018-04-04 17:40:46 -04002070 if (!err.isEmpty()) {
2071 return err;
2072 }
2073
2074 return check_against_reference(bitmap, src, fSink.get());
mtklein9c5052f2016-08-06 12:51:51 -07002075}
2076
Mike Klein841101d2017-03-10 09:55:51 -05002077/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
2078
Mike Klein919cc452017-03-18 15:36:52 +00002079ViaCSXform::ViaCSXform(Sink* sink, sk_sp<SkColorSpace> cs, bool colorSpin)
2080 : Via(sink)
2081 , fCS(std::move(cs))
2082 , fColorSpin(colorSpin) {}
Mike Klein841101d2017-03-10 09:55:51 -05002083
2084Error ViaCSXform::draw(const Src& src, SkBitmap* bitmap, SkWStream* stream, SkString* log) const {
Brian Osmana76b7a92018-07-18 14:36:43 -04002085 Error err = draw_to_canvas(fSink.get(), bitmap, stream, log, src.size(), [&](SkCanvas* canvas) {
Brian Osman5b7e4702017-10-31 16:41:29 -04002086 {
2087 SkAutoCanvasRestore acr(canvas, true);
2088 auto proxy = SkCreateColorSpaceXformCanvas(canvas, fCS);
2089 Error err = src.draw(proxy.get());
2090 if (!err.isEmpty()) {
2091 return err;
2092 }
Mike Klein919cc452017-03-18 15:36:52 +00002093 }
2094
2095 // Undo the color spin, so we can look at the pixels in Gold.
2096 if (fColorSpin) {
2097 SkBitmap pixels;
2098 pixels.allocPixels(canvas->imageInfo());
Mike Reed12e946b2017-04-17 10:53:29 -04002099 canvas->readPixels(pixels, 0, 0);
Mike Klein919cc452017-03-18 15:36:52 +00002100
Brian Osman5b7e4702017-10-31 16:41:29 -04002101 SkPaint rotateColors;
2102 SkScalar matrix[20] = { 0, 0, 1, 0, 0, // B -> R
2103 1, 0, 0, 0, 0, // R -> G
2104 0, 1, 0, 0, 0, // G -> B
2105 0, 0, 0, 1, 0 };
2106 rotateColors.setBlendMode(SkBlendMode::kSrc);
2107 rotateColors.setColorFilter(SkColorFilter::MakeMatrixFilterRowMajor255(matrix));
2108 canvas->drawBitmap(pixels, 0, 0, &rotateColors);
Mike Klein919cc452017-03-18 15:36:52 +00002109 }
2110
Brian Osmana76b7a92018-07-18 14:36:43 -04002111 return Error("");
Mike Klein841101d2017-03-10 09:55:51 -05002112 });
Brian Osmana76b7a92018-07-18 14:36:43 -04002113
2114 if (!err.isEmpty()) {
2115 return err;
2116 }
2117
2118 if (bitmap && !fColorSpin) {
2119 // It should be possible to do this without all the copies, but that (I think) requires
2120 // adding API to SkBitmap.
2121 SkAutoPixmapStorage pmap;
2122 pmap.alloc(bitmap->info());
2123 bitmap->readPixels(pmap);
2124 pmap.setColorSpace(fCS);
2125 bitmap->allocPixels(pmap.info());
2126 bitmap->writePixels(pmap);
2127 }
2128
2129 return "";
Mike Klein841101d2017-03-10 09:55:51 -05002130}
2131
mtklein748ca3b2015-01-15 10:56:12 -08002132} // namespace DM