scroggo | 478652e | 2015-03-25 07:11:02 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 8 | #include "DMSrcSink.h" |
msarett | 3d9d7a7 | 2015-10-21 10:27:10 -0700 | [diff] [blame] | 9 | #include "SkAndroidCodec.h" |
scroggo | f24f224 | 2015-03-03 08:59:20 -0800 | [diff] [blame] | 10 | #include "SkCodec.h" |
msarett | b714fb0 | 2016-01-22 14:46:42 -0800 | [diff] [blame] | 11 | #include "SkCodecImageGenerator.h" |
mtklein | a16e69e | 2015-05-05 11:38:45 -0700 | [diff] [blame] | 12 | #include "SkCommonFlags.h" |
mtklein | b3e5e4d | 2015-03-25 13:13:43 -0700 | [diff] [blame] | 13 | #include "SkData.h" |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 14 | #include "SkDocument.h" |
joshualitt | 5f5a8d7 | 2015-02-25 14:09:45 -0800 | [diff] [blame] | 15 | #include "SkError.h" |
mtklein | b3e5e4d | 2015-03-25 13:13:43 -0700 | [diff] [blame] | 16 | #include "SkImageGenerator.h" |
mtklein | c8be09a | 2016-01-04 18:56:57 -0800 | [diff] [blame] | 17 | #include "SkMallocPixelRef.h" |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 18 | #include "SkMultiPictureDraw.h" |
mtklein | ad66f9b | 2015-02-13 15:11:10 -0800 | [diff] [blame] | 19 | #include "SkNullCanvas.h" |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 20 | #include "SkOSFile.h" |
msarett | 9e9444c | 2016-02-03 12:39:10 -0800 | [diff] [blame] | 21 | #include "SkOpts.h" |
mtklein | ffa901a | 2015-03-16 10:38:07 -0700 | [diff] [blame] | 22 | #include "SkPictureData.h" |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 23 | #include "SkPictureRecorder.h" |
| 24 | #include "SkRandom.h" |
mtklein | d31c13d | 2015-05-05 12:59:56 -0700 | [diff] [blame] | 25 | #include "SkRecordDraw.h" |
| 26 | #include "SkRecorder.h" |
mtklein | 2e2ea38 | 2015-10-16 10:29:41 -0700 | [diff] [blame] | 27 | #include "SkRemote.h" |
fmalita | 2aafe6f | 2015-02-06 12:51:10 -0800 | [diff] [blame] | 28 | #include "SkSVGCanvas.h" |
scroggo | a1193e4 | 2015-01-21 12:09:53 -0800 | [diff] [blame] | 29 | #include "SkStream.h" |
mtklein | 449d9b7 | 2015-09-28 10:33:02 -0700 | [diff] [blame] | 30 | #include "SkTLogic.h" |
fmalita | 2aafe6f | 2015-02-06 12:51:10 -0800 | [diff] [blame] | 31 | #include "SkXMLWriter.h" |
msarett | e6dd004 | 2015-10-09 11:07:34 -0700 | [diff] [blame] | 32 | #include "SkSwizzler.h" |
mtklein | 6459352 | 2015-11-12 10:41:05 -0800 | [diff] [blame] | 33 | #include <functional> |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 34 | |
halcanary | 7a76f9c | 2016-02-03 11:53:18 -0800 | [diff] [blame] | 35 | #ifdef SK_MOJO |
| 36 | #include "SkMojo.mojom.h" |
| 37 | #endif |
| 38 | |
halcanary | 7e79818 | 2015-04-14 14:06:18 -0700 | [diff] [blame] | 39 | DEFINE_bool(multiPage, false, "For document-type backends, render the source" |
| 40 | " into multiple pages"); |
scroggo | 3ac66e9 | 2016-02-08 15:09:48 -0800 | [diff] [blame] | 41 | DEFINE_bool(RAW_threading, true, "Allow RAW decodes to run on multiple threads?"); |
halcanary | 7e79818 | 2015-04-14 14:06:18 -0700 | [diff] [blame] | 42 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 43 | namespace DM { |
| 44 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 45 | GMSrc::GMSrc(skiagm::GMRegistry::Factory factory) : fFactory(factory) {} |
| 46 | |
| 47 | Error GMSrc::draw(SkCanvas* canvas) const { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 48 | SkAutoTDelete<skiagm::GM> gm(fFactory(nullptr)); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 49 | canvas->concat(gm->getInitialTransform()); |
| 50 | gm->draw(canvas); |
| 51 | return ""; |
| 52 | } |
| 53 | |
| 54 | SkISize GMSrc::size() const { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 55 | SkAutoTDelete<skiagm::GM> gm(fFactory(nullptr)); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 56 | return gm->getISize(); |
| 57 | } |
| 58 | |
| 59 | Name GMSrc::name() const { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 60 | SkAutoTDelete<skiagm::GM> gm(fFactory(nullptr)); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 61 | return gm->getName(); |
| 62 | } |
| 63 | |
bsalomon | 4ee6bd8 | 2015-05-27 13:23:23 -0700 | [diff] [blame] | 64 | void GMSrc::modifyGrContextOptions(GrContextOptions* options) const { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 65 | SkAutoTDelete<skiagm::GM> gm(fFactory(nullptr)); |
bsalomon | 4ee6bd8 | 2015-05-27 13:23:23 -0700 | [diff] [blame] | 66 | gm->modifyGrContextOptions(options); |
| 67 | } |
| 68 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 69 | /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ |
| 70 | |
msarett | 5cb4885 | 2015-11-06 08:56:32 -0800 | [diff] [blame] | 71 | BRDSrc::BRDSrc(Path path, SkBitmapRegionDecoder::Strategy strategy, Mode mode, |
msarett | a5783ae | 2015-09-08 15:35:32 -0700 | [diff] [blame] | 72 | CodecSrc::DstColorType dstColorType, uint32_t sampleSize) |
| 73 | : fPath(path) |
| 74 | , fStrategy(strategy) |
| 75 | , fMode(mode) |
| 76 | , fDstColorType(dstColorType) |
| 77 | , fSampleSize(sampleSize) |
| 78 | {} |
| 79 | |
| 80 | bool BRDSrc::veto(SinkFlags flags) const { |
| 81 | // No need to test to non-raster or indirect backends. |
| 82 | return flags.type != SinkFlags::kRaster |
| 83 | || flags.approach != SinkFlags::kDirect; |
| 84 | } |
| 85 | |
msarett | 5cb4885 | 2015-11-06 08:56:32 -0800 | [diff] [blame] | 86 | static SkBitmapRegionDecoder* create_brd(Path path, |
| 87 | SkBitmapRegionDecoder::Strategy strategy) { |
msarett | a5783ae | 2015-09-08 15:35:32 -0700 | [diff] [blame] | 88 | SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(path.c_str())); |
| 89 | if (!encoded) { |
| 90 | return NULL; |
| 91 | } |
msarett | 5cb4885 | 2015-11-06 08:56:32 -0800 | [diff] [blame] | 92 | return SkBitmapRegionDecoder::Create(encoded, strategy); |
msarett | a5783ae | 2015-09-08 15:35:32 -0700 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | Error BRDSrc::draw(SkCanvas* canvas) const { |
| 96 | SkColorType colorType = canvas->imageInfo().colorType(); |
| 97 | if (kRGB_565_SkColorType == colorType && |
| 98 | CodecSrc::kGetFromCanvas_DstColorType != fDstColorType) { |
| 99 | return Error::Nonfatal("Testing non-565 to 565 is uninteresting."); |
| 100 | } |
| 101 | switch (fDstColorType) { |
| 102 | case CodecSrc::kGetFromCanvas_DstColorType: |
| 103 | break; |
| 104 | case CodecSrc::kIndex8_Always_DstColorType: |
| 105 | colorType = kIndex_8_SkColorType; |
| 106 | break; |
| 107 | case CodecSrc::kGrayscale_Always_DstColorType: |
| 108 | colorType = kGray_8_SkColorType; |
| 109 | break; |
| 110 | } |
| 111 | |
msarett | 5cb4885 | 2015-11-06 08:56:32 -0800 | [diff] [blame] | 112 | SkAutoTDelete<SkBitmapRegionDecoder> brd(create_brd(fPath, fStrategy)); |
msarett | a5783ae | 2015-09-08 15:35:32 -0700 | [diff] [blame] | 113 | if (nullptr == brd.get()) { |
| 114 | return Error::Nonfatal(SkStringPrintf("Could not create brd for %s.", fPath.c_str())); |
| 115 | } |
| 116 | |
msarett | 04965c6 | 2015-10-12 10:24:38 -0700 | [diff] [blame] | 117 | if (!brd->conversionSupported(colorType)) { |
mtklein | 9b43915 | 2015-12-09 13:02:26 -0800 | [diff] [blame] | 118 | return Error::Nonfatal("Cannot convert to color type."); |
msarett | 04965c6 | 2015-10-12 10:24:38 -0700 | [diff] [blame] | 119 | } |
| 120 | |
msarett | a5783ae | 2015-09-08 15:35:32 -0700 | [diff] [blame] | 121 | const uint32_t width = brd->width(); |
| 122 | const uint32_t height = brd->height(); |
| 123 | // Visually inspecting very small output images is not necessary. |
| 124 | if ((width / fSampleSize <= 10 || height / fSampleSize <= 10) && 1 != fSampleSize) { |
| 125 | return Error::Nonfatal("Scaling very small images is uninteresting."); |
| 126 | } |
| 127 | switch (fMode) { |
| 128 | case kFullImage_Mode: { |
msarett | 35e5d1b | 2015-10-27 12:50:25 -0700 | [diff] [blame] | 129 | SkBitmap bitmap; |
| 130 | if (!brd->decodeRegion(&bitmap, nullptr, SkIRect::MakeXYWH(0, 0, width, height), |
| 131 | fSampleSize, colorType, false)) { |
mtklein | 9b43915 | 2015-12-09 13:02:26 -0800 | [diff] [blame] | 132 | return "Cannot decode (full) region."; |
msarett | 35e5d1b | 2015-10-27 12:50:25 -0700 | [diff] [blame] | 133 | } |
| 134 | if (colorType != bitmap.colorType()) { |
mtklein | 9b43915 | 2015-12-09 13:02:26 -0800 | [diff] [blame] | 135 | return Error::Nonfatal("Cannot convert to color type."); |
msarett | a5783ae | 2015-09-08 15:35:32 -0700 | [diff] [blame] | 136 | } |
msarett | 35e5d1b | 2015-10-27 12:50:25 -0700 | [diff] [blame] | 137 | canvas->drawBitmap(bitmap, 0, 0); |
msarett | a5783ae | 2015-09-08 15:35:32 -0700 | [diff] [blame] | 138 | return ""; |
| 139 | } |
| 140 | case kDivisor_Mode: { |
| 141 | const uint32_t divisor = 2; |
| 142 | if (width < divisor || height < divisor) { |
mtklein | 9b43915 | 2015-12-09 13:02:26 -0800 | [diff] [blame] | 143 | return Error::Nonfatal("Divisor is larger than image dimension."); |
msarett | a5783ae | 2015-09-08 15:35:32 -0700 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | // Use a border to test subsets that extend outside the image. |
| 147 | // We will not allow the border to be larger than the image dimensions. Allowing |
| 148 | // these large borders causes off by one errors that indicate a problem with the |
| 149 | // test suite, not a problem with the implementation. |
| 150 | const uint32_t maxBorder = SkTMin(width, height) / (fSampleSize * divisor); |
| 151 | const uint32_t scaledBorder = SkTMin(5u, maxBorder); |
| 152 | const uint32_t unscaledBorder = scaledBorder * fSampleSize; |
| 153 | |
| 154 | // We may need to clear the canvas to avoid uninitialized memory. |
| 155 | // Assume we are scaling a 780x780 image with sampleSize = 8. |
| 156 | // The output image should be 97x97. |
| 157 | // Each subset will be 390x390. |
| 158 | // Each scaled subset be 48x48. |
| 159 | // Four scaled subsets will only fill a 96x96 image. |
| 160 | // The bottom row and last column will not be touched. |
| 161 | // This is an unfortunate result of our rounding rules when scaling. |
| 162 | // Maybe we need to consider testing scaled subsets without trying to |
| 163 | // combine them to match the full scaled image? Or maybe this is the |
| 164 | // best we can do? |
| 165 | canvas->clear(0); |
| 166 | |
| 167 | for (uint32_t x = 0; x < divisor; x++) { |
| 168 | for (uint32_t y = 0; y < divisor; y++) { |
| 169 | // Calculate the subset dimensions |
| 170 | uint32_t subsetWidth = width / divisor; |
| 171 | uint32_t subsetHeight = height / divisor; |
| 172 | const int left = x * subsetWidth; |
| 173 | const int top = y * subsetHeight; |
| 174 | |
| 175 | // Increase the size of the last subset in each row or column, when the |
| 176 | // divisor does not divide evenly into the image dimensions |
| 177 | subsetWidth += (x + 1 == divisor) ? (width % divisor) : 0; |
| 178 | subsetHeight += (y + 1 == divisor) ? (height % divisor) : 0; |
| 179 | |
| 180 | // Increase the size of the subset in order to have a border on each side |
| 181 | const int decodeLeft = left - unscaledBorder; |
| 182 | const int decodeTop = top - unscaledBorder; |
| 183 | const uint32_t decodeWidth = subsetWidth + unscaledBorder * 2; |
| 184 | const uint32_t decodeHeight = subsetHeight + unscaledBorder * 2; |
msarett | 35e5d1b | 2015-10-27 12:50:25 -0700 | [diff] [blame] | 185 | SkBitmap bitmap; |
| 186 | if (!brd->decodeRegion(&bitmap, nullptr, SkIRect::MakeXYWH(decodeLeft, |
| 187 | decodeTop, decodeWidth, decodeHeight), fSampleSize, colorType, false)) { |
mtklein | 9b43915 | 2015-12-09 13:02:26 -0800 | [diff] [blame] | 188 | return "Cannot decode region."; |
msarett | 35e5d1b | 2015-10-27 12:50:25 -0700 | [diff] [blame] | 189 | } |
| 190 | if (colorType != bitmap.colorType()) { |
mtklein | 9b43915 | 2015-12-09 13:02:26 -0800 | [diff] [blame] | 191 | return Error::Nonfatal("Cannot convert to color type."); |
msarett | a5783ae | 2015-09-08 15:35:32 -0700 | [diff] [blame] | 192 | } |
| 193 | |
msarett | 35e5d1b | 2015-10-27 12:50:25 -0700 | [diff] [blame] | 194 | canvas->drawBitmapRect(bitmap, |
msarett | a5783ae | 2015-09-08 15:35:32 -0700 | [diff] [blame] | 195 | SkRect::MakeXYWH((SkScalar) scaledBorder, (SkScalar) scaledBorder, |
| 196 | (SkScalar) (subsetWidth / fSampleSize), |
| 197 | (SkScalar) (subsetHeight / fSampleSize)), |
| 198 | SkRect::MakeXYWH((SkScalar) (left / fSampleSize), |
| 199 | (SkScalar) (top / fSampleSize), |
| 200 | (SkScalar) (subsetWidth / fSampleSize), |
| 201 | (SkScalar) (subsetHeight / fSampleSize)), |
| 202 | nullptr); |
| 203 | } |
| 204 | } |
| 205 | return ""; |
| 206 | } |
| 207 | default: |
| 208 | SkASSERT(false); |
mtklein | 9b43915 | 2015-12-09 13:02:26 -0800 | [diff] [blame] | 209 | return "Error: Should not be reached."; |
msarett | a5783ae | 2015-09-08 15:35:32 -0700 | [diff] [blame] | 210 | } |
| 211 | } |
| 212 | |
| 213 | SkISize BRDSrc::size() const { |
msarett | 5cb4885 | 2015-11-06 08:56:32 -0800 | [diff] [blame] | 214 | SkAutoTDelete<SkBitmapRegionDecoder> brd(create_brd(fPath, fStrategy)); |
msarett | a5783ae | 2015-09-08 15:35:32 -0700 | [diff] [blame] | 215 | if (brd) { |
| 216 | return SkISize::Make(SkTMax(1, brd->width() / (int) fSampleSize), |
| 217 | SkTMax(1, brd->height() / (int) fSampleSize)); |
| 218 | } |
| 219 | return SkISize::Make(0, 0); |
| 220 | } |
| 221 | |
| 222 | static SkString get_scaled_name(const Path& path, float scale) { |
| 223 | return SkStringPrintf("%s_%.3f", SkOSPath::Basename(path.c_str()).c_str(), scale); |
| 224 | } |
| 225 | |
| 226 | Name BRDSrc::name() const { |
| 227 | // We will replicate the names used by CodecSrc so that images can |
| 228 | // be compared in Gold. |
| 229 | if (1 == fSampleSize) { |
| 230 | return SkOSPath::Basename(fPath.c_str()); |
| 231 | } |
msarett | 4b0778e | 2015-11-13 09:59:11 -0800 | [diff] [blame] | 232 | return get_scaled_name(fPath, 1.0f / (float) fSampleSize); |
msarett | a5783ae | 2015-09-08 15:35:32 -0700 | [diff] [blame] | 233 | } |
| 234 | |
| 235 | /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ |
| 236 | |
scroggo | 3ac66e9 | 2016-02-08 15:09:48 -0800 | [diff] [blame] | 237 | static bool serial_from_path_name(const SkString& path) { |
| 238 | if (!FLAGS_RAW_threading) { |
| 239 | static const char* const exts[] = { |
| 240 | "arw", "cr2", "dng", "nef", "nrw", "orf", "raf", "rw2", "pef", "srw", |
| 241 | "ARW", "CR2", "DNG", "NEF", "NRW", "ORF", "RAF", "RW2", "PEF", "SRW", |
| 242 | }; |
| 243 | const char* actualExt = strrchr(path.c_str(), '.'); |
| 244 | if (actualExt) { |
| 245 | actualExt++; |
| 246 | for (auto* ext : exts) { |
| 247 | if (0 == strcmp(ext, actualExt)) { |
| 248 | return true; |
| 249 | } |
| 250 | } |
| 251 | } |
| 252 | } |
| 253 | return false; |
| 254 | } |
| 255 | |
scroggo | c5560be | 2016-02-03 09:42:42 -0800 | [diff] [blame] | 256 | CodecSrc::CodecSrc(Path path, Mode mode, DstColorType dstColorType, SkAlphaType dstAlphaType, |
| 257 | float scale) |
msarett | 438b2ad | 2015-04-09 12:43:10 -0700 | [diff] [blame] | 258 | : fPath(path) |
| 259 | , fMode(mode) |
| 260 | , fDstColorType(dstColorType) |
scroggo | c5560be | 2016-02-03 09:42:42 -0800 | [diff] [blame] | 261 | , fDstAlphaType(dstAlphaType) |
msarett | 0a24297 | 2015-06-11 14:27:27 -0700 | [diff] [blame] | 262 | , fScale(scale) |
scroggo | 3ac66e9 | 2016-02-08 15:09:48 -0800 | [diff] [blame] | 263 | , fRunSerially(serial_from_path_name(path)) |
msarett | 438b2ad | 2015-04-09 12:43:10 -0700 | [diff] [blame] | 264 | {} |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 265 | |
mtklein | 99cab4e | 2015-07-31 06:43:04 -0700 | [diff] [blame] | 266 | bool CodecSrc::veto(SinkFlags flags) const { |
msarett | b714fb0 | 2016-01-22 14:46:42 -0800 | [diff] [blame] | 267 | // Test CodecImageGenerator on 8888, 565, and gpu |
| 268 | if (kGen_Mode == fMode) { |
msarett | 36c070d | 2016-02-10 06:48:21 -0800 | [diff] [blame] | 269 | // For image generator, we want to test kDirect approaches for kRaster and kGPU, |
| 270 | // while skipping everything else. |
| 271 | return (flags.type != SinkFlags::kRaster && flags.type != SinkFlags::kGPU) || |
msarett | a23659f | 2016-02-09 12:39:17 -0800 | [diff] [blame] | 272 | flags.approach != SinkFlags::kDirect; |
msarett | b714fb0 | 2016-01-22 14:46:42 -0800 | [diff] [blame] | 273 | } |
| 274 | |
| 275 | // Test all other modes to direct raster backends (8888 and 565). |
| 276 | return flags.type != SinkFlags::kRaster || flags.approach != SinkFlags::kDirect; |
mtklein | e0effd6 | 2015-07-29 06:37:28 -0700 | [diff] [blame] | 277 | } |
scroggo | 9b77ddd | 2015-03-19 06:03:39 -0700 | [diff] [blame] | 278 | |
msarett | 9e9444c | 2016-02-03 12:39:10 -0800 | [diff] [blame] | 279 | // FIXME: Currently we cannot draw unpremultiplied sources. skbug.com/3338 and skbug.com/3339. |
| 280 | // This allows us to still test unpremultiplied decodes. |
| 281 | void premultiply_if_necessary(SkBitmap& bitmap) { |
| 282 | if (kUnpremul_SkAlphaType != bitmap.alphaType()) { |
| 283 | return; |
| 284 | } |
| 285 | |
| 286 | switch (bitmap.colorType()) { |
| 287 | case kN32_SkColorType: |
| 288 | for (int y = 0; y < bitmap.height(); y++) { |
| 289 | uint32_t* row = (uint32_t*) bitmap.getAddr(0, y); |
| 290 | SkOpts::RGBA_to_rgbA(row, row, bitmap.width()); |
| 291 | } |
| 292 | break; |
| 293 | case kIndex_8_SkColorType: { |
| 294 | SkColorTable* colorTable = bitmap.getColorTable(); |
| 295 | SkPMColor* colorPtr = const_cast<SkPMColor*>(colorTable->readColors()); |
| 296 | SkOpts::RGBA_to_rgbA(colorPtr, colorPtr, colorTable->count()); |
| 297 | break; |
| 298 | } |
| 299 | default: |
| 300 | // No need to premultiply kGray or k565 outputs. |
| 301 | break; |
| 302 | } |
msarett | e1daa48 | 2016-02-03 15:31:18 -0800 | [diff] [blame] | 303 | |
| 304 | // In the kIndex_8 case, the canvas won't even try to draw unless we mark the |
| 305 | // bitmap as kPremul. |
| 306 | bitmap.setAlphaType(kPremul_SkAlphaType); |
msarett | 9e9444c | 2016-02-03 12:39:10 -0800 | [diff] [blame] | 307 | } |
| 308 | |
scroggo | c5560be | 2016-02-03 09:42:42 -0800 | [diff] [blame] | 309 | bool get_decode_info(SkImageInfo* decodeInfo, SkColorType canvasColorType, |
| 310 | CodecSrc::DstColorType dstColorType) { |
msarett | 3d9d7a7 | 2015-10-21 10:27:10 -0700 | [diff] [blame] | 311 | switch (dstColorType) { |
| 312 | case CodecSrc::kIndex8_Always_DstColorType: |
| 313 | if (kRGB_565_SkColorType == canvasColorType) { |
| 314 | return false; |
| 315 | } |
scroggo | c5560be | 2016-02-03 09:42:42 -0800 | [diff] [blame] | 316 | *decodeInfo = decodeInfo->makeColorType(kIndex_8_SkColorType); |
msarett | 3d9d7a7 | 2015-10-21 10:27:10 -0700 | [diff] [blame] | 317 | break; |
| 318 | case CodecSrc::kGrayscale_Always_DstColorType: |
msarett | 55f7bdd | 2016-02-16 13:24:54 -0800 | [diff] [blame] | 319 | if (kRGB_565_SkColorType == canvasColorType || |
| 320 | kOpaque_SkAlphaType != decodeInfo->alphaType()) { |
msarett | 3d9d7a7 | 2015-10-21 10:27:10 -0700 | [diff] [blame] | 321 | return false; |
| 322 | } |
scroggo | c5560be | 2016-02-03 09:42:42 -0800 | [diff] [blame] | 323 | *decodeInfo = decodeInfo->makeColorType(kGray_8_SkColorType); |
msarett | 3d9d7a7 | 2015-10-21 10:27:10 -0700 | [diff] [blame] | 324 | break; |
| 325 | default: |
msarett | 55f7bdd | 2016-02-16 13:24:54 -0800 | [diff] [blame] | 326 | if (kRGB_565_SkColorType == canvasColorType && |
| 327 | kOpaque_SkAlphaType != decodeInfo->alphaType()) { |
| 328 | return false; |
| 329 | } |
scroggo | c5560be | 2016-02-03 09:42:42 -0800 | [diff] [blame] | 330 | *decodeInfo = decodeInfo->makeColorType(canvasColorType); |
msarett | 3d9d7a7 | 2015-10-21 10:27:10 -0700 | [diff] [blame] | 331 | break; |
| 332 | } |
| 333 | |
msarett | 3d9d7a7 | 2015-10-21 10:27:10 -0700 | [diff] [blame] | 334 | return true; |
| 335 | } |
| 336 | |
msarett | b714fb0 | 2016-01-22 14:46:42 -0800 | [diff] [blame] | 337 | Error test_gen(SkCanvas* canvas, SkData* data) { |
msarett | 01813e8 | 2016-01-25 10:51:29 -0800 | [diff] [blame] | 338 | SkAutoTDelete<SkImageGenerator> gen = SkCodecImageGenerator::NewFromEncodedCodec(data); |
msarett | b714fb0 | 2016-01-22 14:46:42 -0800 | [diff] [blame] | 339 | if (!gen) { |
| 340 | return "Could not create image generator."; |
| 341 | } |
| 342 | |
| 343 | // FIXME: The gpu backend does not draw kGray sources correctly. (skbug.com/4822) |
| 344 | // Currently, we will avoid creating a CodecSrc for this case (see DM.cpp). |
| 345 | SkASSERT(kGray_8_SkColorType != gen->getInfo().colorType()); |
| 346 | |
msarett | d03b7ae | 2016-01-25 08:20:55 -0800 | [diff] [blame] | 347 | if (kOpaque_SkAlphaType != gen->getInfo().alphaType() && |
| 348 | kRGB_565_SkColorType == canvas->imageInfo().colorType()) { |
| 349 | return Error::Nonfatal("Skip testing non-opaque images to 565."); |
| 350 | } |
| 351 | |
msarett | 01813e8 | 2016-01-25 10:51:29 -0800 | [diff] [blame] | 352 | SkAutoTDelete<SkImage> image(SkImage::NewFromGenerator(gen.detach(), nullptr)); |
msarett | b714fb0 | 2016-01-22 14:46:42 -0800 | [diff] [blame] | 353 | if (!image) { |
| 354 | return "Could not create image from codec image generator."; |
| 355 | } |
| 356 | |
| 357 | canvas->drawImage(image, 0, 0); |
| 358 | return ""; |
| 359 | } |
| 360 | |
mtklein | e0effd6 | 2015-07-29 06:37:28 -0700 | [diff] [blame] | 361 | Error CodecSrc::draw(SkCanvas* canvas) const { |
mtklein | 75d98fd | 2015-01-18 07:05:01 -0800 | [diff] [blame] | 362 | SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str())); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 363 | if (!encoded) { |
| 364 | return SkStringPrintf("Couldn't read %s.", fPath.c_str()); |
| 365 | } |
msarett | b714fb0 | 2016-01-22 14:46:42 -0800 | [diff] [blame] | 366 | |
| 367 | // The CodecImageGenerator test does not share much code with the other tests, |
| 368 | // so we will handle it in its own function. |
| 369 | if (kGen_Mode == fMode) { |
| 370 | return test_gen(canvas, encoded); |
| 371 | } |
| 372 | |
msarett | 3d9d7a7 | 2015-10-21 10:27:10 -0700 | [diff] [blame] | 373 | SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded)); |
msarett | 9e707a0 | 2015-09-01 14:57:57 -0700 | [diff] [blame] | 374 | if (nullptr == codec.get()) { |
| 375 | return SkStringPrintf("Couldn't create codec for %s.", fPath.c_str()); |
scroggo | 9b77ddd | 2015-03-19 06:03:39 -0700 | [diff] [blame] | 376 | } |
| 377 | |
scroggo | c5560be | 2016-02-03 09:42:42 -0800 | [diff] [blame] | 378 | SkImageInfo decodeInfo = codec->getInfo().makeAlphaType(fDstAlphaType); |
| 379 | if (!get_decode_info(&decodeInfo, canvas->imageInfo().colorType(), fDstColorType)) { |
msarett | 3d9d7a7 | 2015-10-21 10:27:10 -0700 | [diff] [blame] | 380 | return Error::Nonfatal("Testing non-565 to 565 is uninteresting."); |
msarett | 438b2ad | 2015-04-09 12:43:10 -0700 | [diff] [blame] | 381 | } |
| 382 | |
msarett | 0a24297 | 2015-06-11 14:27:27 -0700 | [diff] [blame] | 383 | // Try to scale the image if it is desired |
| 384 | SkISize size = codec->getScaledDimensions(fScale); |
| 385 | if (size == decodeInfo.dimensions() && 1.0f != fScale) { |
| 386 | return Error::Nonfatal("Test without scaling is uninteresting."); |
| 387 | } |
msarett | b32758a | 2015-08-18 13:22:46 -0700 | [diff] [blame] | 388 | |
| 389 | // Visually inspecting very small output images is not necessary. We will |
| 390 | // cover these cases in unit testing. |
| 391 | if ((size.width() <= 10 || size.height() <= 10) && 1.0f != fScale) { |
| 392 | return Error::Nonfatal("Scaling very small images is uninteresting."); |
| 393 | } |
msarett | 0a24297 | 2015-06-11 14:27:27 -0700 | [diff] [blame] | 394 | decodeInfo = decodeInfo.makeWH(size.width(), size.height()); |
| 395 | |
msarett | 438b2ad | 2015-04-09 12:43:10 -0700 | [diff] [blame] | 396 | // Construct a color table for the decode if necessary |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 397 | SkAutoTUnref<SkColorTable> colorTable(nullptr); |
| 398 | SkPMColor* colorPtr = nullptr; |
| 399 | int* colorCountPtr = nullptr; |
msarett | 438b2ad | 2015-04-09 12:43:10 -0700 | [diff] [blame] | 400 | int maxColors = 256; |
| 401 | if (kIndex_8_SkColorType == decodeInfo.colorType()) { |
| 402 | SkPMColor colors[256]; |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 403 | colorTable.reset(new SkColorTable(colors, maxColors)); |
msarett | 438b2ad | 2015-04-09 12:43:10 -0700 | [diff] [blame] | 404 | colorPtr = const_cast<SkPMColor*>(colorTable->readColors()); |
| 405 | colorCountPtr = &maxColors; |
| 406 | } |
| 407 | |
scroggo | 9b77ddd | 2015-03-19 06:03:39 -0700 | [diff] [blame] | 408 | SkBitmap bitmap; |
msarett | bb25b53 | 2016-01-13 09:31:39 -0800 | [diff] [blame] | 409 | SkPixelRefFactory* factory = nullptr; |
| 410 | SkMallocPixelRef::ZeroedPRFactory zeroFactory; |
| 411 | SkCodec::Options options; |
| 412 | if (kCodecZeroInit_Mode == fMode) { |
| 413 | factory = &zeroFactory; |
| 414 | options.fZeroInitialized = SkCodec::kYes_ZeroInitialized; |
| 415 | } |
| 416 | if (!bitmap.tryAllocPixels(decodeInfo, factory, colorTable.get())) { |
mtklein | 9b43915 | 2015-12-09 13:02:26 -0800 | [diff] [blame] | 417 | return SkStringPrintf("Image(%s) is too large (%d x %d)", fPath.c_str(), |
scroggo | 9b77ddd | 2015-03-19 06:03:39 -0700 | [diff] [blame] | 418 | decodeInfo.width(), decodeInfo.height()); |
| 419 | } |
| 420 | |
scroggo | 9c59ebc | 2015-03-25 13:48:49 -0700 | [diff] [blame] | 421 | switch (fMode) { |
msarett | bb25b53 | 2016-01-13 09:31:39 -0800 | [diff] [blame] | 422 | case kCodecZeroInit_Mode: |
msarett | 9e707a0 | 2015-09-01 14:57:57 -0700 | [diff] [blame] | 423 | case kCodec_Mode: { |
msarett | bb25b53 | 2016-01-13 09:31:39 -0800 | [diff] [blame] | 424 | switch (codec->getPixels(decodeInfo, bitmap.getPixels(), bitmap.rowBytes(), &options, |
msarett | 438b2ad | 2015-04-09 12:43:10 -0700 | [diff] [blame] | 425 | colorPtr, colorCountPtr)) { |
scroggo | eb602a5 | 2015-07-09 08:16:03 -0700 | [diff] [blame] | 426 | case SkCodec::kSuccess: |
scroggo | 9c59ebc | 2015-03-25 13:48:49 -0700 | [diff] [blame] | 427 | // We consider incomplete to be valid, since we should still decode what is |
| 428 | // available. |
scroggo | eb602a5 | 2015-07-09 08:16:03 -0700 | [diff] [blame] | 429 | case SkCodec::kIncompleteInput: |
scroggo | 9c59ebc | 2015-03-25 13:48:49 -0700 | [diff] [blame] | 430 | break; |
scroggo | 9c59ebc | 2015-03-25 13:48:49 -0700 | [diff] [blame] | 431 | default: |
| 432 | // Everything else is considered a failure. |
| 433 | return SkStringPrintf("Couldn't getPixels %s.", fPath.c_str()); |
| 434 | } |
msarett | 9e9444c | 2016-02-03 12:39:10 -0800 | [diff] [blame] | 435 | premultiply_if_necessary(bitmap); |
emmaleer | 9700206 | 2015-05-27 12:36:10 -0700 | [diff] [blame] | 436 | canvas->drawBitmap(bitmap, 0, 0); |
scroggo | 9c59ebc | 2015-03-25 13:48:49 -0700 | [diff] [blame] | 437 | break; |
emmaleer | 0a4c3cb | 2015-06-22 10:40:21 -0700 | [diff] [blame] | 438 | } |
scroggo | 9c59ebc | 2015-03-25 13:48:49 -0700 | [diff] [blame] | 439 | case kScanline_Mode: { |
scroggo | 46c5747 | 2015-09-30 08:57:13 -0700 | [diff] [blame] | 440 | if (SkCodec::kSuccess != codec->startScanlineDecode(decodeInfo, NULL, colorPtr, |
| 441 | colorCountPtr)) { |
msarett | b65e604 | 2016-02-23 05:37:25 -0800 | [diff] [blame] | 442 | return "Could not start scanline decoder"; |
scroggo | 9c59ebc | 2015-03-25 13:48:49 -0700 | [diff] [blame] | 443 | } |
scroggo | 1c005e4 | 2015-08-04 09:24:45 -0700 | [diff] [blame] | 444 | |
msarett | e6dd004 | 2015-10-09 11:07:34 -0700 | [diff] [blame] | 445 | void* dst = bitmap.getAddr(0, 0); |
| 446 | size_t rowBytes = bitmap.rowBytes(); |
| 447 | uint32_t height = decodeInfo.height(); |
scroggo | 46c5747 | 2015-09-30 08:57:13 -0700 | [diff] [blame] | 448 | switch (codec->getScanlineOrder()) { |
| 449 | case SkCodec::kTopDown_SkScanlineOrder: |
| 450 | case SkCodec::kBottomUp_SkScanlineOrder: |
| 451 | case SkCodec::kNone_SkScanlineOrder: |
msarett | e6dd004 | 2015-10-09 11:07:34 -0700 | [diff] [blame] | 452 | // We do not need to check the return value. On an incomplete |
| 453 | // image, memory will be filled with a default value. |
| 454 | codec->getScanlines(dst, height, rowBytes); |
msarett | 10522ff | 2015-09-07 08:54:01 -0700 | [diff] [blame] | 455 | break; |
scroggo | 46c5747 | 2015-09-30 08:57:13 -0700 | [diff] [blame] | 456 | case SkCodec::kOutOfOrder_SkScanlineOrder: { |
msarett | 10522ff | 2015-09-07 08:54:01 -0700 | [diff] [blame] | 457 | for (int y = 0; y < decodeInfo.height(); y++) { |
msarett | e6dd004 | 2015-10-09 11:07:34 -0700 | [diff] [blame] | 458 | int dstY = codec->outputScanline(y); |
msarett | 10522ff | 2015-09-07 08:54:01 -0700 | [diff] [blame] | 459 | void* dstPtr = bitmap.getAddr(0, dstY); |
msarett | e6dd004 | 2015-10-09 11:07:34 -0700 | [diff] [blame] | 460 | // We complete the loop, even if this call begins to fail |
| 461 | // due to an incomplete image. This ensures any uninitialized |
| 462 | // memory will be filled with the proper value. |
| 463 | codec->getScanlines(dstPtr, 1, bitmap.rowBytes()); |
msarett | 10522ff | 2015-09-07 08:54:01 -0700 | [diff] [blame] | 464 | } |
| 465 | break; |
| 466 | } |
| 467 | } |
| 468 | |
msarett | 9e9444c | 2016-02-03 12:39:10 -0800 | [diff] [blame] | 469 | premultiply_if_necessary(bitmap); |
emmaleer | 9700206 | 2015-05-27 12:36:10 -0700 | [diff] [blame] | 470 | canvas->drawBitmap(bitmap, 0, 0); |
| 471 | break; |
| 472 | } |
msarett | 0a24297 | 2015-06-11 14:27:27 -0700 | [diff] [blame] | 473 | case kStripe_Mode: { |
| 474 | const int height = decodeInfo.height(); |
| 475 | // This value is chosen arbitrarily. We exercise more cases by choosing a value that |
| 476 | // does not align with image blocks. |
| 477 | const int stripeHeight = 37; |
| 478 | const int numStripes = (height + stripeHeight - 1) / stripeHeight; |
| 479 | |
| 480 | // Decode odd stripes |
scroggo | 46c5747 | 2015-09-30 08:57:13 -0700 | [diff] [blame] | 481 | if (SkCodec::kSuccess != codec->startScanlineDecode(decodeInfo, NULL, colorPtr, |
msarett | b65e604 | 2016-02-23 05:37:25 -0800 | [diff] [blame] | 482 | colorCountPtr)) { |
| 483 | return "Could not start scanline decoder"; |
| 484 | } |
| 485 | |
| 486 | // This mode was designed to test the new skip scanlines API in libjpeg-turbo. |
| 487 | // Jpegs have kTopDown_SkScanlineOrder, and at this time, it is not interesting |
| 488 | // to run this test for image types that do not have this scanline ordering. |
| 489 | if (SkCodec::kTopDown_SkScanlineOrder != codec->getScanlineOrder()) { |
| 490 | return Error::Nonfatal("kStripe test is only interesting for kTopDown codecs."); |
msarett | 0a24297 | 2015-06-11 14:27:27 -0700 | [diff] [blame] | 491 | } |
msarett | e6dd004 | 2015-10-09 11:07:34 -0700 | [diff] [blame] | 492 | |
msarett | 0a24297 | 2015-06-11 14:27:27 -0700 | [diff] [blame] | 493 | for (int i = 0; i < numStripes; i += 2) { |
| 494 | // Skip a stripe |
| 495 | const int linesToSkip = SkTMin(stripeHeight, height - i * stripeHeight); |
msarett | e6dd004 | 2015-10-09 11:07:34 -0700 | [diff] [blame] | 496 | codec->skipScanlines(linesToSkip); |
msarett | 0a24297 | 2015-06-11 14:27:27 -0700 | [diff] [blame] | 497 | |
| 498 | // Read a stripe |
| 499 | const int startY = (i + 1) * stripeHeight; |
| 500 | const int linesToRead = SkTMin(stripeHeight, height - startY); |
| 501 | if (linesToRead > 0) { |
msarett | e6dd004 | 2015-10-09 11:07:34 -0700 | [diff] [blame] | 502 | codec->getScanlines(bitmap.getAddr(0, startY), linesToRead, bitmap.rowBytes()); |
msarett | 0a24297 | 2015-06-11 14:27:27 -0700 | [diff] [blame] | 503 | } |
| 504 | } |
| 505 | |
| 506 | // Decode even stripes |
scroggo | 46c5747 | 2015-09-30 08:57:13 -0700 | [diff] [blame] | 507 | const SkCodec::Result startResult = codec->startScanlineDecode(decodeInfo, nullptr, |
| 508 | colorPtr, colorCountPtr); |
scroggo | 1c005e4 | 2015-08-04 09:24:45 -0700 | [diff] [blame] | 509 | if (SkCodec::kSuccess != startResult) { |
| 510 | return "Failed to restart scanline decoder with same parameters."; |
msarett | 0a24297 | 2015-06-11 14:27:27 -0700 | [diff] [blame] | 511 | } |
| 512 | for (int i = 0; i < numStripes; i += 2) { |
| 513 | // Read a stripe |
| 514 | const int startY = i * stripeHeight; |
| 515 | const int linesToRead = SkTMin(stripeHeight, height - startY); |
msarett | e6dd004 | 2015-10-09 11:07:34 -0700 | [diff] [blame] | 516 | codec->getScanlines(bitmap.getAddr(0, startY), linesToRead, bitmap.rowBytes()); |
msarett | 0a24297 | 2015-06-11 14:27:27 -0700 | [diff] [blame] | 517 | |
| 518 | // Skip a stripe |
msarett | f6db27e | 2015-06-12 09:34:04 -0700 | [diff] [blame] | 519 | const int linesToSkip = SkTMin(stripeHeight, height - (i + 1) * stripeHeight); |
| 520 | if (linesToSkip > 0) { |
msarett | e6dd004 | 2015-10-09 11:07:34 -0700 | [diff] [blame] | 521 | codec->skipScanlines(linesToSkip); |
msarett | 0a24297 | 2015-06-11 14:27:27 -0700 | [diff] [blame] | 522 | } |
| 523 | } |
msarett | 9e9444c | 2016-02-03 12:39:10 -0800 | [diff] [blame] | 524 | premultiply_if_necessary(bitmap); |
msarett | 0a24297 | 2015-06-11 14:27:27 -0700 | [diff] [blame] | 525 | canvas->drawBitmap(bitmap, 0, 0); |
emmaleer | 0a4c3cb | 2015-06-22 10:40:21 -0700 | [diff] [blame] | 526 | break; |
msarett | 0a24297 | 2015-06-11 14:27:27 -0700 | [diff] [blame] | 527 | } |
msarett | 91c22b2 | 2016-02-22 12:27:46 -0800 | [diff] [blame] | 528 | case kCroppedScanline_Mode: { |
| 529 | const int width = decodeInfo.width(); |
| 530 | const int height = decodeInfo.height(); |
| 531 | // This value is chosen because, as we move across the image, it will sometimes |
| 532 | // align with the jpeg block sizes and it will sometimes not. This allows us |
| 533 | // to test interestingly different code paths in the implementation. |
| 534 | const int tileSize = 36; |
| 535 | |
| 536 | SkCodec::Options opts; |
| 537 | SkIRect subset; |
| 538 | for (int x = 0; x < width; x += tileSize) { |
| 539 | subset = SkIRect::MakeXYWH(x, 0, SkTMin(tileSize, width - x), height); |
| 540 | opts.fSubset = ⊂ |
| 541 | if (SkCodec::kSuccess != codec->startScanlineDecode(decodeInfo, &opts, |
| 542 | colorPtr, colorCountPtr)) { |
| 543 | return "Could not start scanline decoder."; |
| 544 | } |
| 545 | |
| 546 | codec->getScanlines(bitmap.getAddr(x, 0), height, bitmap.rowBytes()); |
| 547 | } |
| 548 | |
| 549 | premultiply_if_necessary(bitmap); |
| 550 | canvas->drawBitmap(bitmap, 0, 0); |
| 551 | break; |
| 552 | } |
scroggo | b636b45 | 2015-07-22 07:16:20 -0700 | [diff] [blame] | 553 | case kSubset_Mode: { |
| 554 | // Arbitrarily choose a divisor. |
| 555 | int divisor = 2; |
| 556 | // Total width/height of the image. |
| 557 | const int W = codec->getInfo().width(); |
| 558 | const int H = codec->getInfo().height(); |
| 559 | if (divisor > W || divisor > H) { |
| 560 | return Error::Nonfatal(SkStringPrintf("Cannot codec subset: divisor %d is too big " |
| 561 | "for %s with dimensions (%d x %d)", divisor, |
| 562 | fPath.c_str(), W, H)); |
| 563 | } |
| 564 | // subset dimensions |
| 565 | // SkWebpCodec, the only one that supports subsets, requires even top/left boundaries. |
| 566 | const int w = SkAlign2(W / divisor); |
| 567 | const int h = SkAlign2(H / divisor); |
| 568 | SkIRect subset; |
| 569 | SkCodec::Options opts; |
| 570 | opts.fSubset = ⊂ |
| 571 | SkBitmap subsetBm; |
| 572 | // We will reuse pixel memory from bitmap. |
| 573 | void* pixels = bitmap.getPixels(); |
| 574 | // Keep track of left and top (for drawing subsetBm into canvas). We could use |
| 575 | // fScale * x and fScale * y, but we want integers such that the next subset will start |
| 576 | // where the last one ended. So we'll add decodeInfo.width() and height(). |
| 577 | int left = 0; |
| 578 | for (int x = 0; x < W; x += w) { |
| 579 | int top = 0; |
| 580 | for (int y = 0; y < H; y+= h) { |
| 581 | // Do not make the subset go off the edge of the image. |
| 582 | const int preScaleW = SkTMin(w, W - x); |
| 583 | const int preScaleH = SkTMin(h, H - y); |
| 584 | subset.setXYWH(x, y, preScaleW, preScaleH); |
| 585 | // And scale |
| 586 | // FIXME: Should we have a version of getScaledDimensions that takes a subset |
| 587 | // into account? |
msarett | e6dd004 | 2015-10-09 11:07:34 -0700 | [diff] [blame] | 588 | decodeInfo = decodeInfo.makeWH( |
| 589 | SkTMax(1, SkScalarRoundToInt(preScaleW * fScale)), |
| 590 | SkTMax(1, SkScalarRoundToInt(preScaleH * fScale))); |
scroggo | b636b45 | 2015-07-22 07:16:20 -0700 | [diff] [blame] | 591 | size_t rowBytes = decodeInfo.minRowBytes(); |
| 592 | if (!subsetBm.installPixels(decodeInfo, pixels, rowBytes, colorTable.get(), |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 593 | nullptr, nullptr)) { |
scroggo | b636b45 | 2015-07-22 07:16:20 -0700 | [diff] [blame] | 594 | return SkStringPrintf("could not install pixels for %s.", fPath.c_str()); |
| 595 | } |
| 596 | const SkCodec::Result result = codec->getPixels(decodeInfo, pixels, rowBytes, |
| 597 | &opts, colorPtr, colorCountPtr); |
| 598 | switch (result) { |
| 599 | case SkCodec::kSuccess: |
| 600 | case SkCodec::kIncompleteInput: |
| 601 | break; |
scroggo | b636b45 | 2015-07-22 07:16:20 -0700 | [diff] [blame] | 602 | default: |
| 603 | return SkStringPrintf("subset codec failed to decode (%d, %d, %d, %d) " |
| 604 | "from %s with dimensions (%d x %d)\t error %d", |
| 605 | x, y, decodeInfo.width(), decodeInfo.height(), |
| 606 | fPath.c_str(), W, H, result); |
| 607 | } |
msarett | 9e9444c | 2016-02-03 12:39:10 -0800 | [diff] [blame] | 608 | premultiply_if_necessary(subsetBm); |
scroggo | b636b45 | 2015-07-22 07:16:20 -0700 | [diff] [blame] | 609 | canvas->drawBitmap(subsetBm, SkIntToScalar(left), SkIntToScalar(top)); |
| 610 | // translate by the scaled height. |
| 611 | top += decodeInfo.height(); |
| 612 | } |
| 613 | // translate by the scaled width. |
| 614 | left += decodeInfo.width(); |
| 615 | } |
| 616 | return ""; |
| 617 | } |
msarett | b714fb0 | 2016-01-22 14:46:42 -0800 | [diff] [blame] | 618 | default: |
| 619 | SkASSERT(false); |
| 620 | return "Invalid fMode"; |
scroggo | 9b77ddd | 2015-03-19 06:03:39 -0700 | [diff] [blame] | 621 | } |
scroggo | 9c59ebc | 2015-03-25 13:48:49 -0700 | [diff] [blame] | 622 | return ""; |
scroggo | 9b77ddd | 2015-03-19 06:03:39 -0700 | [diff] [blame] | 623 | } |
| 624 | |
| 625 | SkISize CodecSrc::size() const { |
| 626 | SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str())); |
msarett | 3d9d7a7 | 2015-10-21 10:27:10 -0700 | [diff] [blame] | 627 | SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded)); |
scroggo | 7fac5af | 2015-09-30 11:33:12 -0700 | [diff] [blame] | 628 | if (nullptr == codec) { |
| 629 | return SkISize::Make(0, 0); |
| 630 | } |
| 631 | return codec->getScaledDimensions(fScale); |
scroggo | 9b77ddd | 2015-03-19 06:03:39 -0700 | [diff] [blame] | 632 | } |
| 633 | |
| 634 | Name CodecSrc::name() const { |
msarett | 0a24297 | 2015-06-11 14:27:27 -0700 | [diff] [blame] | 635 | if (1.0f == fScale) { |
| 636 | return SkOSPath::Basename(fPath.c_str()); |
msarett | 0a24297 | 2015-06-11 14:27:27 -0700 | [diff] [blame] | 637 | } |
msarett | a5783ae | 2015-09-08 15:35:32 -0700 | [diff] [blame] | 638 | return get_scaled_name(fPath, fScale); |
scroggo | 9b77ddd | 2015-03-19 06:03:39 -0700 | [diff] [blame] | 639 | } |
| 640 | |
| 641 | /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ |
| 642 | |
msarett | 3d9d7a7 | 2015-10-21 10:27:10 -0700 | [diff] [blame] | 643 | AndroidCodecSrc::AndroidCodecSrc(Path path, Mode mode, CodecSrc::DstColorType dstColorType, |
scroggo | c5560be | 2016-02-03 09:42:42 -0800 | [diff] [blame] | 644 | SkAlphaType dstAlphaType, int sampleSize) |
msarett | 3d9d7a7 | 2015-10-21 10:27:10 -0700 | [diff] [blame] | 645 | : fPath(path) |
| 646 | , fMode(mode) |
| 647 | , fDstColorType(dstColorType) |
scroggo | c5560be | 2016-02-03 09:42:42 -0800 | [diff] [blame] | 648 | , fDstAlphaType(dstAlphaType) |
msarett | 3d9d7a7 | 2015-10-21 10:27:10 -0700 | [diff] [blame] | 649 | , fSampleSize(sampleSize) |
scroggo | 3ac66e9 | 2016-02-08 15:09:48 -0800 | [diff] [blame] | 650 | , fRunSerially(serial_from_path_name(path)) |
msarett | 3d9d7a7 | 2015-10-21 10:27:10 -0700 | [diff] [blame] | 651 | {} |
| 652 | |
| 653 | bool AndroidCodecSrc::veto(SinkFlags flags) const { |
| 654 | // No need to test decoding to non-raster or indirect backend. |
msarett | 3d9d7a7 | 2015-10-21 10:27:10 -0700 | [diff] [blame] | 655 | return flags.type != SinkFlags::kRaster |
| 656 | || flags.approach != SinkFlags::kDirect; |
| 657 | } |
| 658 | |
| 659 | Error AndroidCodecSrc::draw(SkCanvas* canvas) const { |
| 660 | SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str())); |
| 661 | if (!encoded) { |
| 662 | return SkStringPrintf("Couldn't read %s.", fPath.c_str()); |
| 663 | } |
| 664 | SkAutoTDelete<SkAndroidCodec> codec(SkAndroidCodec::NewFromData(encoded)); |
| 665 | if (nullptr == codec.get()) { |
| 666 | return SkStringPrintf("Couldn't create android codec for %s.", fPath.c_str()); |
| 667 | } |
| 668 | |
scroggo | c5560be | 2016-02-03 09:42:42 -0800 | [diff] [blame] | 669 | SkImageInfo decodeInfo = codec->getInfo().makeAlphaType(fDstAlphaType); |
| 670 | if (!get_decode_info(&decodeInfo, canvas->imageInfo().colorType(), fDstColorType)) { |
msarett | 3d9d7a7 | 2015-10-21 10:27:10 -0700 | [diff] [blame] | 671 | return Error::Nonfatal("Testing non-565 to 565 is uninteresting."); |
| 672 | } |
| 673 | |
| 674 | // Scale the image if it is desired. |
| 675 | SkISize size = codec->getSampledDimensions(fSampleSize); |
| 676 | |
| 677 | // Visually inspecting very small output images is not necessary. We will |
| 678 | // cover these cases in unit testing. |
| 679 | if ((size.width() <= 10 || size.height() <= 10) && 1 != fSampleSize) { |
| 680 | return Error::Nonfatal("Scaling very small images is uninteresting."); |
| 681 | } |
| 682 | decodeInfo = decodeInfo.makeWH(size.width(), size.height()); |
| 683 | |
| 684 | // Construct a color table for the decode if necessary |
| 685 | SkAutoTUnref<SkColorTable> colorTable(nullptr); |
| 686 | SkPMColor* colorPtr = nullptr; |
| 687 | int* colorCountPtr = nullptr; |
| 688 | int maxColors = 256; |
| 689 | if (kIndex_8_SkColorType == decodeInfo.colorType()) { |
| 690 | SkPMColor colors[256]; |
| 691 | colorTable.reset(new SkColorTable(colors, maxColors)); |
| 692 | colorPtr = const_cast<SkPMColor*>(colorTable->readColors()); |
| 693 | colorCountPtr = &maxColors; |
| 694 | } |
| 695 | |
| 696 | SkBitmap bitmap; |
| 697 | if (!bitmap.tryAllocPixels(decodeInfo, nullptr, colorTable.get())) { |
mtklein | 9b43915 | 2015-12-09 13:02:26 -0800 | [diff] [blame] | 698 | return SkStringPrintf("Image(%s) is too large (%d x %d)", fPath.c_str(), |
msarett | 3d9d7a7 | 2015-10-21 10:27:10 -0700 | [diff] [blame] | 699 | decodeInfo.width(), decodeInfo.height()); |
| 700 | } |
| 701 | |
| 702 | // Create options for the codec. |
| 703 | SkAndroidCodec::AndroidOptions options; |
| 704 | options.fColorPtr = colorPtr; |
| 705 | options.fColorCount = colorCountPtr; |
| 706 | options.fSampleSize = fSampleSize; |
| 707 | |
| 708 | switch (fMode) { |
| 709 | case kFullImage_Mode: { |
| 710 | switch (codec->getAndroidPixels(decodeInfo, bitmap.getPixels(), bitmap.rowBytes(), |
| 711 | &options)) { |
| 712 | case SkCodec::kSuccess: |
| 713 | case SkCodec::kIncompleteInput: |
| 714 | break; |
msarett | 3d9d7a7 | 2015-10-21 10:27:10 -0700 | [diff] [blame] | 715 | default: |
| 716 | return SkStringPrintf("Couldn't getPixels %s.", fPath.c_str()); |
| 717 | } |
msarett | 9e9444c | 2016-02-03 12:39:10 -0800 | [diff] [blame] | 718 | premultiply_if_necessary(bitmap); |
msarett | 3d9d7a7 | 2015-10-21 10:27:10 -0700 | [diff] [blame] | 719 | canvas->drawBitmap(bitmap, 0, 0); |
| 720 | return ""; |
| 721 | } |
| 722 | case kDivisor_Mode: { |
| 723 | const int width = codec->getInfo().width(); |
| 724 | const int height = codec->getInfo().height(); |
| 725 | const int divisor = 2; |
| 726 | if (width < divisor || height < divisor) { |
mtklein | 9b43915 | 2015-12-09 13:02:26 -0800 | [diff] [blame] | 727 | return Error::Nonfatal("Divisor is larger than image dimension."); |
msarett | 3d9d7a7 | 2015-10-21 10:27:10 -0700 | [diff] [blame] | 728 | } |
| 729 | |
msarett | fa23a9e | 2015-10-21 13:26:59 -0700 | [diff] [blame] | 730 | // Keep track of the final decoded dimensions. |
| 731 | int finalScaledWidth = 0; |
| 732 | int finalScaledHeight = 0; |
msarett | 3d9d7a7 | 2015-10-21 10:27:10 -0700 | [diff] [blame] | 733 | for (int x = 0; x < divisor; x++) { |
| 734 | for (int y = 0; y < divisor; y++) { |
| 735 | // Calculate the subset dimensions |
| 736 | int subsetWidth = width / divisor; |
| 737 | int subsetHeight = height / divisor; |
| 738 | const int left = x * subsetWidth; |
| 739 | const int top = y * subsetHeight; |
| 740 | |
| 741 | // Increase the size of the last subset in each row or column, when the |
| 742 | // divisor does not divide evenly into the image dimensions |
| 743 | subsetWidth += (x + 1 == divisor) ? (width % divisor) : 0; |
| 744 | subsetHeight += (y + 1 == divisor) ? (height % divisor) : 0; |
| 745 | SkIRect subset = SkIRect::MakeXYWH(left, top, subsetWidth, subsetHeight); |
| 746 | if (!codec->getSupportedSubset(&subset)) { |
mtklein | 9b43915 | 2015-12-09 13:02:26 -0800 | [diff] [blame] | 747 | return "Could not get supported subset to decode."; |
msarett | 3d9d7a7 | 2015-10-21 10:27:10 -0700 | [diff] [blame] | 748 | } |
| 749 | options.fSubset = ⊂ |
msarett | fa23a9e | 2015-10-21 13:26:59 -0700 | [diff] [blame] | 750 | const int scaledWidthOffset = subset.left() / fSampleSize; |
| 751 | const int scaledHeightOffset = subset.top() / fSampleSize; |
| 752 | void* pixels = bitmap.getAddr(scaledWidthOffset, scaledHeightOffset); |
msarett | 3d9d7a7 | 2015-10-21 10:27:10 -0700 | [diff] [blame] | 753 | SkISize scaledSubsetSize = codec->getSampledSubsetDimensions(fSampleSize, |
| 754 | subset); |
| 755 | SkImageInfo subsetDecodeInfo = decodeInfo.makeWH(scaledSubsetSize.width(), |
| 756 | scaledSubsetSize.height()); |
| 757 | |
msarett | fa23a9e | 2015-10-21 13:26:59 -0700 | [diff] [blame] | 758 | if (x + 1 == divisor && y + 1 == divisor) { |
| 759 | finalScaledWidth = scaledWidthOffset + scaledSubsetSize.width(); |
| 760 | finalScaledHeight = scaledHeightOffset + scaledSubsetSize.height(); |
| 761 | } |
| 762 | |
msarett | 3d9d7a7 | 2015-10-21 10:27:10 -0700 | [diff] [blame] | 763 | switch (codec->getAndroidPixels(subsetDecodeInfo, pixels, bitmap.rowBytes(), |
| 764 | &options)) { |
| 765 | case SkCodec::kSuccess: |
| 766 | case SkCodec::kIncompleteInput: |
| 767 | break; |
msarett | 3d9d7a7 | 2015-10-21 10:27:10 -0700 | [diff] [blame] | 768 | default: |
| 769 | return SkStringPrintf("Couldn't getPixels %s.", fPath.c_str()); |
| 770 | } |
| 771 | } |
| 772 | } |
msarett | fa23a9e | 2015-10-21 13:26:59 -0700 | [diff] [blame] | 773 | |
| 774 | SkRect rect = SkRect::MakeXYWH(0, 0, (SkScalar) finalScaledWidth, |
| 775 | (SkScalar) finalScaledHeight); |
msarett | 9e9444c | 2016-02-03 12:39:10 -0800 | [diff] [blame] | 776 | premultiply_if_necessary(bitmap); |
msarett | fa23a9e | 2015-10-21 13:26:59 -0700 | [diff] [blame] | 777 | canvas->drawBitmapRect(bitmap, rect, rect, nullptr); |
msarett | 3d9d7a7 | 2015-10-21 10:27:10 -0700 | [diff] [blame] | 778 | return ""; |
| 779 | } |
| 780 | default: |
| 781 | SkASSERT(false); |
mtklein | 9b43915 | 2015-12-09 13:02:26 -0800 | [diff] [blame] | 782 | return "Error: Should not be reached."; |
msarett | 3d9d7a7 | 2015-10-21 10:27:10 -0700 | [diff] [blame] | 783 | } |
| 784 | } |
| 785 | |
| 786 | SkISize AndroidCodecSrc::size() const { |
| 787 | SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str())); |
| 788 | SkAutoTDelete<SkAndroidCodec> codec(SkAndroidCodec::NewFromData(encoded)); |
| 789 | if (nullptr == codec) { |
| 790 | return SkISize::Make(0, 0); |
| 791 | } |
| 792 | return codec->getSampledDimensions(fSampleSize); |
| 793 | } |
| 794 | |
| 795 | Name AndroidCodecSrc::name() const { |
| 796 | // We will replicate the names used by CodecSrc so that images can |
| 797 | // be compared in Gold. |
| 798 | if (1 == fSampleSize) { |
| 799 | return SkOSPath::Basename(fPath.c_str()); |
| 800 | } |
msarett | 4b0778e | 2015-11-13 09:59:11 -0800 | [diff] [blame] | 801 | return get_scaled_name(fPath, 1.0f / (float) fSampleSize); |
msarett | 3d9d7a7 | 2015-10-21 10:27:10 -0700 | [diff] [blame] | 802 | } |
| 803 | |
| 804 | /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ |
| 805 | |
mtklein | f4ba321 | 2015-01-28 15:32:24 -0800 | [diff] [blame] | 806 | static const SkRect kSKPViewport = {0,0, 1000,1000}; |
| 807 | |
mtklein | 8d17a13 | 2015-01-30 11:42:31 -0800 | [diff] [blame] | 808 | SKPSrc::SKPSrc(Path path) : fPath(path) {} |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 809 | |
| 810 | Error SKPSrc::draw(SkCanvas* canvas) const { |
scroggo | a1193e4 | 2015-01-21 12:09:53 -0800 | [diff] [blame] | 811 | SkAutoTDelete<SkStream> stream(SkStream::NewFromFile(fPath.c_str())); |
mtklein | 75d98fd | 2015-01-18 07:05:01 -0800 | [diff] [blame] | 812 | if (!stream) { |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 813 | return SkStringPrintf("Couldn't read %s.", fPath.c_str()); |
| 814 | } |
msarett | 8715d47 | 2016-02-17 10:02:29 -0800 | [diff] [blame] | 815 | SkAutoTUnref<SkPicture> pic(SkPicture::CreateFromStream(stream)); |
mtklein | 75d98fd | 2015-01-18 07:05:01 -0800 | [diff] [blame] | 816 | if (!pic) { |
| 817 | return SkStringPrintf("Couldn't decode %s as a picture.", fPath.c_str()); |
| 818 | } |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 819 | stream.reset((SkStream*)nullptr); // Might as well drop this when we're done with it. |
joshualitt | 7c3a2f8 | 2015-03-31 13:32:05 -0700 | [diff] [blame] | 820 | |
mtklein | f4ba321 | 2015-01-28 15:32:24 -0800 | [diff] [blame] | 821 | canvas->clipRect(kSKPViewport); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 822 | canvas->drawPicture(pic); |
| 823 | return ""; |
| 824 | } |
| 825 | |
| 826 | SkISize SKPSrc::size() const { |
mtklein | ffa901a | 2015-03-16 10:38:07 -0700 | [diff] [blame] | 827 | SkAutoTDelete<SkStream> stream(SkStream::NewFromFile(fPath.c_str())); |
| 828 | if (!stream) { |
| 829 | return SkISize::Make(0,0); |
| 830 | } |
| 831 | SkPictInfo info; |
| 832 | if (!SkPicture::InternalOnly_StreamIsSKP(stream, &info)) { |
| 833 | return SkISize::Make(0,0); |
| 834 | } |
| 835 | SkRect viewport = kSKPViewport; |
| 836 | if (!viewport.intersect(info.fCullRect)) { |
| 837 | return SkISize::Make(0,0); |
| 838 | } |
| 839 | return viewport.roundOut().size(); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 840 | } |
| 841 | |
| 842 | Name SKPSrc::name() const { return SkOSPath::Basename(fPath.c_str()); } |
| 843 | |
| 844 | /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ |
| 845 | |
mtklein | ad66f9b | 2015-02-13 15:11:10 -0800 | [diff] [blame] | 846 | Error NullSink::draw(const Src& src, SkBitmap*, SkWStream*, SkString*) const { |
| 847 | SkAutoTDelete<SkCanvas> canvas(SkCreateNullCanvas()); |
| 848 | return src.draw(canvas); |
| 849 | } |
| 850 | |
| 851 | /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ |
| 852 | |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 853 | DEFINE_bool(gpuStats, false, "Append GPU stats to the log for each GPU task?"); |
| 854 | |
mtklein | 82d2843 | 2015-01-15 12:46:02 -0800 | [diff] [blame] | 855 | GPUSink::GPUSink(GrContextFactory::GLContextType ct, |
kkinnunen | 5219fd9 | 2015-12-10 06:28:13 -0800 | [diff] [blame] | 856 | GrContextFactory::GLContextOptions options, |
mtklein | 82d2843 | 2015-01-15 12:46:02 -0800 | [diff] [blame] | 857 | int samples, |
bsalomon | afcd7cd | 2015-08-31 12:39:41 -0700 | [diff] [blame] | 858 | bool diText, |
mtklein | 82d2843 | 2015-01-15 12:46:02 -0800 | [diff] [blame] | 859 | bool threaded) |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 860 | : fContextType(ct) |
kkinnunen | 5219fd9 | 2015-12-10 06:28:13 -0800 | [diff] [blame] | 861 | , fContextOptions(options) |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 862 | , fSampleCount(samples) |
bsalomon | afcd7cd | 2015-08-31 12:39:41 -0700 | [diff] [blame] | 863 | , fUseDIText(diText) |
mtklein | 82d2843 | 2015-01-15 12:46:02 -0800 | [diff] [blame] | 864 | , fThreaded(threaded) {} |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 865 | |
joshualitt | 5f5a8d7 | 2015-02-25 14:09:45 -0800 | [diff] [blame] | 866 | void PreAbandonGpuContextErrorHandler(SkError, void*) {} |
| 867 | |
bsalomon | 648c696 | 2015-10-23 09:06:59 -0700 | [diff] [blame] | 868 | DEFINE_bool(imm, false, "Run gpu configs in immediate mode."); |
bsalomon | 69cfe95 | 2015-11-30 13:27:47 -0800 | [diff] [blame] | 869 | DEFINE_bool(batchClip, false, "Clip each GrBatch to its device bounds for testing."); |
bsalomon | 6dea83f | 2015-12-03 12:58:06 -0800 | [diff] [blame] | 870 | DEFINE_bool(batchBounds, false, "Draw a wireframe bounds of each GrBatch."); |
bsalomon | 489147c | 2015-12-14 12:13:09 -0800 | [diff] [blame] | 871 | DEFINE_int32(batchLookback, -1, "Maximum GrBatch lookback for combining, negative means default."); |
bsalomon | 648c696 | 2015-10-23 09:06:59 -0700 | [diff] [blame] | 872 | |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 873 | Error GPUSink::draw(const Src& src, SkBitmap* dst, SkWStream*, SkString* log) const { |
kkinnunen | 5219fd9 | 2015-12-10 06:28:13 -0800 | [diff] [blame] | 874 | GrContextOptions grOptions; |
bsalomon | 489147c | 2015-12-14 12:13:09 -0800 | [diff] [blame] | 875 | grOptions.fImmediateMode = FLAGS_imm; |
| 876 | grOptions.fClipBatchToBounds = FLAGS_batchClip; |
| 877 | grOptions.fDrawBatchBounds = FLAGS_batchBounds; |
| 878 | grOptions.fMaxBatchLookback = FLAGS_batchLookback; |
kkinnunen | 64492c4 | 2015-12-08 01:24:40 -0800 | [diff] [blame] | 879 | |
kkinnunen | 5219fd9 | 2015-12-10 06:28:13 -0800 | [diff] [blame] | 880 | src.modifyGrContextOptions(&grOptions); |
| 881 | |
| 882 | GrContextFactory factory(grOptions); |
mtklein | f4ba321 | 2015-01-28 15:32:24 -0800 | [diff] [blame] | 883 | const SkISize size = src.size(); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 884 | const SkImageInfo info = |
| 885 | SkImageInfo::Make(size.width(), size.height(), kN32_SkColorType, kPremul_SkAlphaType); |
msarett | 13a036b | 2016-02-08 09:10:47 -0800 | [diff] [blame] | 886 | #if SK_SUPPORT_GPU |
| 887 | const int maxDimension = factory.getContextInfo(fContextType, fContextOptions). |
| 888 | fGrContext->caps()->maxTextureSize(); |
| 889 | if (maxDimension < SkTMax(size.width(), size.height())) { |
| 890 | return Error::Nonfatal("Src too large to create a texture.\n"); |
| 891 | } |
| 892 | #endif |
| 893 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 894 | SkAutoTUnref<SkSurface> surface( |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 895 | NewGpuSurface(&factory, fContextType, fContextOptions, info, fSampleCount, fUseDIText)); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 896 | if (!surface) { |
| 897 | return "Could not create a surface."; |
| 898 | } |
joshualitt | 5f5a8d7 | 2015-02-25 14:09:45 -0800 | [diff] [blame] | 899 | if (FLAGS_preAbandonGpuContext) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 900 | SkSetErrorCallback(&PreAbandonGpuContextErrorHandler, nullptr); |
joshualitt | 5f5a8d7 | 2015-02-25 14:09:45 -0800 | [diff] [blame] | 901 | factory.abandonContexts(); |
| 902 | } |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 903 | SkCanvas* canvas = surface->getCanvas(); |
| 904 | Error err = src.draw(canvas); |
| 905 | if (!err.isEmpty()) { |
| 906 | return err; |
| 907 | } |
| 908 | canvas->flush(); |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 909 | if (FLAGS_gpuStats) { |
| 910 | canvas->getGrContext()->dumpCacheStats(log); |
| 911 | canvas->getGrContext()->dumpGpuStats(log); |
| 912 | } |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 913 | dst->allocPixels(info); |
joshualitt | 5f5a8d7 | 2015-02-25 14:09:45 -0800 | [diff] [blame] | 914 | canvas->readPixels(dst, 0, 0); |
mtklein | 55e88b2 | 2015-01-21 15:50:13 -0800 | [diff] [blame] | 915 | if (FLAGS_abandonGpuContext) { |
| 916 | factory.abandonContexts(); |
| 917 | } |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 918 | return ""; |
| 919 | } |
| 920 | |
| 921 | /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ |
| 922 | |
halcanary | 47ef4d5 | 2015-03-03 09:13:09 -0800 | [diff] [blame] | 923 | static Error draw_skdocument(const Src& src, SkDocument* doc, SkWStream* dst) { |
| 924 | // Print the given DM:Src to a document, breaking on 8.5x11 pages. |
| 925 | SkASSERT(doc); |
halcanary | fd4a993 | 2015-01-28 11:45:58 -0800 | [diff] [blame] | 926 | int width = src.size().width(), |
| 927 | height = src.size().height(); |
| 928 | |
halcanary | 7e79818 | 2015-04-14 14:06:18 -0700 | [diff] [blame] | 929 | if (FLAGS_multiPage) { |
| 930 | const int kLetterWidth = 612, // 8.5 * 72 |
| 931 | kLetterHeight = 792; // 11 * 72 |
| 932 | const SkRect letter = SkRect::MakeWH(SkIntToScalar(kLetterWidth), |
| 933 | SkIntToScalar(kLetterHeight)); |
halcanary | fd4a993 | 2015-01-28 11:45:58 -0800 | [diff] [blame] | 934 | |
halcanary | 7e79818 | 2015-04-14 14:06:18 -0700 | [diff] [blame] | 935 | int xPages = ((width - 1) / kLetterWidth) + 1; |
| 936 | int yPages = ((height - 1) / kLetterHeight) + 1; |
halcanary | fd4a993 | 2015-01-28 11:45:58 -0800 | [diff] [blame] | 937 | |
halcanary | 7e79818 | 2015-04-14 14:06:18 -0700 | [diff] [blame] | 938 | for (int y = 0; y < yPages; ++y) { |
| 939 | for (int x = 0; x < xPages; ++x) { |
| 940 | int w = SkTMin(kLetterWidth, width - (x * kLetterWidth)); |
| 941 | int h = SkTMin(kLetterHeight, height - (y * kLetterHeight)); |
| 942 | SkCanvas* canvas = |
| 943 | doc->beginPage(SkIntToScalar(w), SkIntToScalar(h)); |
| 944 | if (!canvas) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 945 | return "SkDocument::beginPage(w,h) returned nullptr"; |
halcanary | 7e79818 | 2015-04-14 14:06:18 -0700 | [diff] [blame] | 946 | } |
| 947 | canvas->clipRect(letter); |
| 948 | canvas->translate(-letter.width() * x, -letter.height() * y); |
| 949 | Error err = src.draw(canvas); |
| 950 | if (!err.isEmpty()) { |
| 951 | return err; |
| 952 | } |
| 953 | doc->endPage(); |
djsollen | 2ab9000 | 2015-04-03 06:38:31 -0700 | [diff] [blame] | 954 | } |
halcanary | fd4a993 | 2015-01-28 11:45:58 -0800 | [diff] [blame] | 955 | } |
halcanary | 7e79818 | 2015-04-14 14:06:18 -0700 | [diff] [blame] | 956 | } else { |
| 957 | SkCanvas* canvas = |
| 958 | doc->beginPage(SkIntToScalar(width), SkIntToScalar(height)); |
| 959 | if (!canvas) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 960 | return "SkDocument::beginPage(w,h) returned nullptr"; |
halcanary | 7e79818 | 2015-04-14 14:06:18 -0700 | [diff] [blame] | 961 | } |
| 962 | Error err = src.draw(canvas); |
| 963 | if (!err.isEmpty()) { |
| 964 | return err; |
| 965 | } |
| 966 | doc->endPage(); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 967 | } |
halcanary | 7e79818 | 2015-04-14 14:06:18 -0700 | [diff] [blame] | 968 | if (!doc->close()) { |
| 969 | return "SkDocument::close() returned false"; |
| 970 | } |
halcanary | fd4a993 | 2015-01-28 11:45:58 -0800 | [diff] [blame] | 971 | dst->flush(); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 972 | return ""; |
| 973 | } |
| 974 | |
halcanary | c11c62f | 2015-09-28 11:51:54 -0700 | [diff] [blame] | 975 | PDFSink::PDFSink(const char* rasterizer) : fRasterizer(rasterizer) {} |
halcanary | 47ef4d5 | 2015-03-03 09:13:09 -0800 | [diff] [blame] | 976 | |
| 977 | Error PDFSink::draw(const Src& src, SkBitmap*, SkWStream* dst, SkString*) const { |
| 978 | SkAutoTUnref<SkDocument> doc(SkDocument::CreatePDF(dst)); |
| 979 | if (!doc) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 980 | return "SkDocument::CreatePDF() returned nullptr"; |
halcanary | 47ef4d5 | 2015-03-03 09:13:09 -0800 | [diff] [blame] | 981 | } |
halcanary | f12a167 | 2015-09-23 12:45:49 -0700 | [diff] [blame] | 982 | SkTArray<SkDocument::Attribute> info; |
| 983 | info.emplace_back(SkString("Title"), src.name()); |
| 984 | info.emplace_back(SkString("Subject"), |
| 985 | SkString("rendering correctness test")); |
| 986 | info.emplace_back(SkString("Creator"), SkString("Skia/DM")); |
halcanary | c11c62f | 2015-09-28 11:51:54 -0700 | [diff] [blame] | 987 | |
| 988 | info.emplace_back(SkString("Keywords"), |
| 989 | SkStringPrintf("Rasterizer:%s;", fRasterizer)); |
halcanary | 7001576 | 2016-02-11 07:59:59 -0800 | [diff] [blame] | 990 | doc->setMetadata(&info[0], info.count(), nullptr, nullptr); |
halcanary | 47ef4d5 | 2015-03-03 09:13:09 -0800 | [diff] [blame] | 991 | return draw_skdocument(src, doc.get(), dst); |
| 992 | } |
| 993 | |
| 994 | /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ |
| 995 | |
| 996 | XPSSink::XPSSink() {} |
| 997 | |
| 998 | Error XPSSink::draw(const Src& src, SkBitmap*, SkWStream* dst, SkString*) const { |
| 999 | SkAutoTUnref<SkDocument> doc(SkDocument::CreateXPS(dst)); |
| 1000 | if (!doc) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1001 | return "SkDocument::CreateXPS() returned nullptr"; |
halcanary | 47ef4d5 | 2015-03-03 09:13:09 -0800 | [diff] [blame] | 1002 | } |
| 1003 | return draw_skdocument(src, doc.get(), dst); |
| 1004 | } |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1005 | /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ |
| 1006 | |
mtklein | 9c3f17d | 2015-01-28 11:35:18 -0800 | [diff] [blame] | 1007 | SKPSink::SKPSink() {} |
| 1008 | |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 1009 | Error SKPSink::draw(const Src& src, SkBitmap*, SkWStream* dst, SkString*) const { |
mtklein | 9c3f17d | 2015-01-28 11:35:18 -0800 | [diff] [blame] | 1010 | SkSize size; |
| 1011 | size = src.size(); |
| 1012 | SkPictureRecorder recorder; |
| 1013 | Error err = src.draw(recorder.beginRecording(size.width(), size.height())); |
| 1014 | if (!err.isEmpty()) { |
| 1015 | return err; |
| 1016 | } |
| 1017 | SkAutoTUnref<SkPicture> pic(recorder.endRecording()); |
| 1018 | pic->serialize(dst); |
| 1019 | return ""; |
| 1020 | } |
| 1021 | |
| 1022 | /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ |
| 1023 | |
mtklein | 8a4527e | 2015-01-31 20:00:58 -0800 | [diff] [blame] | 1024 | SVGSink::SVGSink() {} |
| 1025 | |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 1026 | Error SVGSink::draw(const Src& src, SkBitmap*, SkWStream* dst, SkString*) const { |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 1027 | SkAutoTDelete<SkXMLWriter> xmlWriter(new SkXMLStreamWriter(dst)); |
fmalita | 2aafe6f | 2015-02-06 12:51:10 -0800 | [diff] [blame] | 1028 | SkAutoTUnref<SkCanvas> canvas(SkSVGCanvas::Create( |
| 1029 | SkRect::MakeWH(SkIntToScalar(src.size().width()), SkIntToScalar(src.size().height())), |
| 1030 | xmlWriter)); |
| 1031 | return src.draw(canvas); |
mtklein | 8a4527e | 2015-01-31 20:00:58 -0800 | [diff] [blame] | 1032 | } |
| 1033 | |
| 1034 | /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ |
| 1035 | |
mtklein | 27c3fdd | 2016-02-26 14:43:21 -0800 | [diff] [blame^] | 1036 | RasterSink::RasterSink(SkColorType colorType, SkColorProfileType profileType) |
| 1037 | : fColorType(colorType) |
| 1038 | , fProfileType(profileType) {} |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1039 | |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 1040 | Error RasterSink::draw(const Src& src, SkBitmap* dst, SkWStream*, SkString*) const { |
mtklein | f4ba321 | 2015-01-28 15:32:24 -0800 | [diff] [blame] | 1041 | const SkISize size = src.size(); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1042 | // If there's an appropriate alpha type for this color type, use it, otherwise use premul. |
| 1043 | SkAlphaType alphaType = kPremul_SkAlphaType; |
| 1044 | (void)SkColorTypeValidateAlphaType(fColorType, alphaType, &alphaType); |
| 1045 | |
mtklein | c8be09a | 2016-01-04 18:56:57 -0800 | [diff] [blame] | 1046 | SkMallocPixelRef::ZeroedPRFactory factory; |
mtklein | 27c3fdd | 2016-02-26 14:43:21 -0800 | [diff] [blame^] | 1047 | dst->allocPixels(SkImageInfo::Make(size.width(), size.height(), |
| 1048 | fColorType, alphaType, fProfileType), |
mtklein | c8be09a | 2016-01-04 18:56:57 -0800 | [diff] [blame] | 1049 | &factory, |
| 1050 | nullptr/*colortable*/); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1051 | SkCanvas canvas(*dst); |
| 1052 | return src.draw(&canvas); |
| 1053 | } |
| 1054 | |
| 1055 | /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ |
| 1056 | |
mtklein | a16e69e | 2015-05-05 11:38:45 -0700 | [diff] [blame] | 1057 | // Handy for front-patching a Src. Do whatever up-front work you need, then call draw_to_canvas(), |
mtklein | e44b508 | 2015-05-07 10:53:34 -0700 | [diff] [blame] | 1058 | // passing the Sink draw() arguments, a size, and a function draws into an SkCanvas. |
mtklein | a16e69e | 2015-05-05 11:38:45 -0700 | [diff] [blame] | 1059 | // Several examples below. |
| 1060 | |
mtklein | cbf8978 | 2016-02-19 14:27:14 -0800 | [diff] [blame] | 1061 | template <typename Fn> |
msarett | 62d3b10 | 2015-12-10 15:14:27 -0800 | [diff] [blame] | 1062 | static Error draw_to_canvas(Sink* sink, SkBitmap* bitmap, SkWStream* stream, SkString* log, |
mtklein | cbf8978 | 2016-02-19 14:27:14 -0800 | [diff] [blame] | 1063 | SkISize size, const Fn& draw) { |
mtklein | a16e69e | 2015-05-05 11:38:45 -0700 | [diff] [blame] | 1064 | class ProxySrc : public Src { |
| 1065 | public: |
mtklein | cbf8978 | 2016-02-19 14:27:14 -0800 | [diff] [blame] | 1066 | ProxySrc(SkISize size, const Fn& draw) : fSize(size), fDraw(draw) {} |
mtklein | a16e69e | 2015-05-05 11:38:45 -0700 | [diff] [blame] | 1067 | Error draw(SkCanvas* canvas) const override { return fDraw(canvas); } |
msarett | 62d3b10 | 2015-12-10 15:14:27 -0800 | [diff] [blame] | 1068 | Name name() const override { sk_throw(); return ""; } // Won't be called. |
mtklein | a16e69e | 2015-05-05 11:38:45 -0700 | [diff] [blame] | 1069 | SkISize size() const override { return fSize; } |
| 1070 | private: |
mtklein | cbf8978 | 2016-02-19 14:27:14 -0800 | [diff] [blame] | 1071 | SkISize fSize; |
| 1072 | const Fn& fDraw; |
mtklein | a16e69e | 2015-05-05 11:38:45 -0700 | [diff] [blame] | 1073 | }; |
msarett | 62d3b10 | 2015-12-10 15:14:27 -0800 | [diff] [blame] | 1074 | return sink->draw(ProxySrc(size, draw), bitmap, stream, log); |
mtklein | a16e69e | 2015-05-05 11:38:45 -0700 | [diff] [blame] | 1075 | } |
| 1076 | |
| 1077 | /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ |
| 1078 | |
mtklein | 4a34ecb | 2016-01-08 10:19:35 -0800 | [diff] [blame] | 1079 | DEFINE_bool(check, true, "If true, have most Via- modes fail if they affect the output."); |
| 1080 | |
| 1081 | // Is *bitmap identical to what you get drawing src into sink? |
| 1082 | static Error check_against_reference(const SkBitmap* bitmap, const Src& src, Sink* sink) { |
| 1083 | // We can only check raster outputs. |
| 1084 | // (Non-raster outputs like .pdf, .skp, .svg may differ but still draw identically.) |
| 1085 | if (FLAGS_check && bitmap) { |
| 1086 | SkBitmap reference; |
| 1087 | SkString log; |
| 1088 | Error err = sink->draw(src, &reference, nullptr, &log); |
| 1089 | // If we can draw into this Sink via some pipeline, we should be able to draw directly. |
| 1090 | SkASSERT(err.isEmpty()); |
| 1091 | if (!err.isEmpty()) { |
| 1092 | return err; |
| 1093 | } |
| 1094 | // The dimensions are a property of the Src only, and so should be identical. |
| 1095 | SkASSERT(reference.getSize() == bitmap->getSize()); |
| 1096 | if (reference.getSize() != bitmap->getSize()) { |
| 1097 | return "Dimensions don't match reference"; |
| 1098 | } |
| 1099 | // All SkBitmaps in DM are pre-locked and tight, so this comparison is easy. |
| 1100 | if (0 != memcmp(reference.getPixels(), bitmap->getPixels(), reference.getSize())) { |
| 1101 | return "Pixels don't match reference"; |
| 1102 | } |
| 1103 | } |
| 1104 | return ""; |
| 1105 | } |
| 1106 | |
| 1107 | /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ |
| 1108 | |
mtklein | d603b22 | 2015-02-17 11:13:33 -0800 | [diff] [blame] | 1109 | static SkISize auto_compute_translate(SkMatrix* matrix, int srcW, int srcH) { |
| 1110 | SkRect bounds = SkRect::MakeIWH(srcW, srcH); |
| 1111 | matrix->mapRect(&bounds); |
| 1112 | matrix->postTranslate(-bounds.x(), -bounds.y()); |
| 1113 | return SkISize::Make(SkScalarRoundToInt(bounds.width()), SkScalarRoundToInt(bounds.height())); |
| 1114 | } |
| 1115 | |
msarett | 62d3b10 | 2015-12-10 15:14:27 -0800 | [diff] [blame] | 1116 | ViaMatrix::ViaMatrix(SkMatrix matrix, Sink* sink) : Via(sink), fMatrix(matrix) {} |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1117 | |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 1118 | Error ViaMatrix::draw(const Src& src, SkBitmap* bitmap, SkWStream* stream, SkString* log) const { |
mtklein | a16e69e | 2015-05-05 11:38:45 -0700 | [diff] [blame] | 1119 | SkMatrix matrix = fMatrix; |
| 1120 | SkISize size = auto_compute_translate(&matrix, src.size().width(), src.size().height()); |
msarett | 62d3b10 | 2015-12-10 15:14:27 -0800 | [diff] [blame] | 1121 | return draw_to_canvas(fSink, bitmap, stream, log, size, [&](SkCanvas* canvas) { |
mtklein | a16e69e | 2015-05-05 11:38:45 -0700 | [diff] [blame] | 1122 | canvas->concat(matrix); |
| 1123 | return src.draw(canvas); |
| 1124 | }); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1125 | } |
| 1126 | |
mtklein | d603b22 | 2015-02-17 11:13:33 -0800 | [diff] [blame] | 1127 | // Undoes any flip or 90 degree rotate without changing the scale of the bitmap. |
| 1128 | // This should be pixel-preserving. |
msarett | 62d3b10 | 2015-12-10 15:14:27 -0800 | [diff] [blame] | 1129 | ViaUpright::ViaUpright(SkMatrix matrix, Sink* sink) : Via(sink), fMatrix(matrix) {} |
mtklein | d603b22 | 2015-02-17 11:13:33 -0800 | [diff] [blame] | 1130 | |
| 1131 | Error ViaUpright::draw(const Src& src, SkBitmap* bitmap, SkWStream* stream, SkString* log) const { |
| 1132 | Error err = fSink->draw(src, bitmap, stream, log); |
| 1133 | if (!err.isEmpty()) { |
| 1134 | return err; |
| 1135 | } |
| 1136 | |
| 1137 | SkMatrix inverse; |
| 1138 | if (!fMatrix.rectStaysRect() || !fMatrix.invert(&inverse)) { |
| 1139 | return "Cannot upright --matrix."; |
| 1140 | } |
| 1141 | SkMatrix upright = SkMatrix::I(); |
| 1142 | upright.setScaleX(SkScalarSignAsScalar(inverse.getScaleX())); |
| 1143 | upright.setScaleY(SkScalarSignAsScalar(inverse.getScaleY())); |
| 1144 | upright.setSkewX(SkScalarSignAsScalar(inverse.getSkewX())); |
| 1145 | upright.setSkewY(SkScalarSignAsScalar(inverse.getSkewY())); |
| 1146 | |
| 1147 | SkBitmap uprighted; |
| 1148 | SkISize size = auto_compute_translate(&upright, bitmap->width(), bitmap->height()); |
| 1149 | uprighted.allocPixels(bitmap->info().makeWH(size.width(), size.height())); |
| 1150 | |
| 1151 | SkCanvas canvas(uprighted); |
| 1152 | canvas.concat(upright); |
| 1153 | SkPaint paint; |
| 1154 | paint.setXfermodeMode(SkXfermode::kSrc_Mode); |
| 1155 | canvas.drawBitmap(*bitmap, 0, 0, &paint); |
| 1156 | |
| 1157 | *bitmap = uprighted; |
| 1158 | bitmap->lockPixels(); |
| 1159 | return ""; |
| 1160 | } |
| 1161 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1162 | /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ |
| 1163 | |
mtklein | 2e2ea38 | 2015-10-16 10:29:41 -0700 | [diff] [blame] | 1164 | Error ViaRemote::draw(const Src& src, SkBitmap* bitmap, SkWStream* stream, SkString* log) const { |
msarett | 62d3b10 | 2015-12-10 15:14:27 -0800 | [diff] [blame] | 1165 | return draw_to_canvas(fSink, bitmap, stream, log, src.size(), [&](SkCanvas* target) { |
mtklein | 479fe77 | 2015-10-21 12:34:01 -0700 | [diff] [blame] | 1166 | SkAutoTDelete<SkRemote::Encoder> decoder(SkRemote::NewDecoder(target)); |
| 1167 | SkAutoTDelete<SkRemote::Encoder> cache(fCache ? SkRemote::NewCachingEncoder(decoder) |
| 1168 | : nullptr); |
| 1169 | SkAutoTDelete<SkCanvas> canvas(SkRemote::NewCanvas(cache ? cache : decoder)); |
| 1170 | return src.draw(canvas); |
mtklein | 2e2ea38 | 2015-10-16 10:29:41 -0700 | [diff] [blame] | 1171 | }); |
| 1172 | } |
| 1173 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1174 | /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ |
mtklein | a16e69e | 2015-05-05 11:38:45 -0700 | [diff] [blame] | 1175 | |
mtklein | a16e69e | 2015-05-05 11:38:45 -0700 | [diff] [blame] | 1176 | Error ViaSerialization::draw( |
| 1177 | const Src& src, SkBitmap* bitmap, SkWStream* stream, SkString* log) const { |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1178 | // Record our Src into a picture. |
mtklein | a16e69e | 2015-05-05 11:38:45 -0700 | [diff] [blame] | 1179 | auto size = src.size(); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1180 | SkPictureRecorder recorder; |
mtklein | a16e69e | 2015-05-05 11:38:45 -0700 | [diff] [blame] | 1181 | Error err = src.draw(recorder.beginRecording(SkIntToScalar(size.width()), |
| 1182 | SkIntToScalar(size.height()))); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1183 | if (!err.isEmpty()) { |
| 1184 | return err; |
| 1185 | } |
| 1186 | SkAutoTUnref<SkPicture> pic(recorder.endRecording()); |
| 1187 | |
| 1188 | // Serialize it and then deserialize it. |
| 1189 | SkDynamicMemoryWStream wStream; |
| 1190 | pic->serialize(&wStream); |
scroggo | a1193e4 | 2015-01-21 12:09:53 -0800 | [diff] [blame] | 1191 | SkAutoTDelete<SkStream> rStream(wStream.detachAsStream()); |
msarett | 8715d47 | 2016-02-17 10:02:29 -0800 | [diff] [blame] | 1192 | SkAutoTUnref<SkPicture> deserialized(SkPicture::CreateFromStream(rStream)); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1193 | |
msarett | 62d3b10 | 2015-12-10 15:14:27 -0800 | [diff] [blame] | 1194 | return draw_to_canvas(fSink, bitmap, stream, log, size, [&](SkCanvas* canvas) { |
mtklein | a16e69e | 2015-05-05 11:38:45 -0700 | [diff] [blame] | 1195 | canvas->drawPicture(deserialized); |
mtklein | 4a34ecb | 2016-01-08 10:19:35 -0800 | [diff] [blame] | 1196 | return check_against_reference(bitmap, src, fSink); |
mtklein | a16e69e | 2015-05-05 11:38:45 -0700 | [diff] [blame] | 1197 | }); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1198 | } |
| 1199 | |
| 1200 | /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ |
| 1201 | |
msarett | 62d3b10 | 2015-12-10 15:14:27 -0800 | [diff] [blame] | 1202 | ViaTiles::ViaTiles(int w, int h, SkBBHFactory* factory, Sink* sink) |
| 1203 | : Via(sink) |
mtklein | 7882924 | 2015-05-06 07:54:07 -0700 | [diff] [blame] | 1204 | , fW(w) |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1205 | , fH(h) |
mtklein | 7882924 | 2015-05-06 07:54:07 -0700 | [diff] [blame] | 1206 | , fFactory(factory) {} |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1207 | |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 1208 | Error ViaTiles::draw(const Src& src, SkBitmap* bitmap, SkWStream* stream, SkString* log) const { |
mtklein | a16e69e | 2015-05-05 11:38:45 -0700 | [diff] [blame] | 1209 | auto size = src.size(); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1210 | SkPictureRecorder recorder; |
mtklein | a16e69e | 2015-05-05 11:38:45 -0700 | [diff] [blame] | 1211 | Error err = src.draw(recorder.beginRecording(SkIntToScalar(size.width()), |
| 1212 | SkIntToScalar(size.height()), |
| 1213 | fFactory.get())); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1214 | if (!err.isEmpty()) { |
| 1215 | return err; |
| 1216 | } |
mtklein | b7e8d69 | 2015-04-07 08:30:32 -0700 | [diff] [blame] | 1217 | SkAutoTUnref<SkPicture> pic(recorder.endRecordingAsPicture()); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1218 | |
msarett | 62d3b10 | 2015-12-10 15:14:27 -0800 | [diff] [blame] | 1219 | return draw_to_canvas(fSink, bitmap, stream, log, src.size(), [&](SkCanvas* canvas) { |
mtklein | a16e69e | 2015-05-05 11:38:45 -0700 | [diff] [blame] | 1220 | const int xTiles = (size.width() + fW - 1) / fW, |
| 1221 | yTiles = (size.height() + fH - 1) / fH; |
| 1222 | SkMultiPictureDraw mpd(xTiles*yTiles); |
| 1223 | SkTDArray<SkSurface*> surfaces; |
| 1224 | surfaces.setReserve(xTiles*yTiles); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1225 | |
mtklein | a16e69e | 2015-05-05 11:38:45 -0700 | [diff] [blame] | 1226 | SkImageInfo info = canvas->imageInfo().makeWH(fW, fH); |
| 1227 | for (int j = 0; j < yTiles; j++) { |
| 1228 | for (int i = 0; i < xTiles; i++) { |
| 1229 | // This lets our ultimate Sink determine the best kind of surface. |
| 1230 | // E.g., if it's a GpuSink, the surfaces and images are textures. |
| 1231 | SkSurface* s = canvas->newSurface(info); |
| 1232 | if (!s) { |
| 1233 | s = SkSurface::NewRaster(info); // Some canvases can't create surfaces. |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1234 | } |
mtklein | a16e69e | 2015-05-05 11:38:45 -0700 | [diff] [blame] | 1235 | surfaces.push(s); |
| 1236 | SkCanvas* c = s->getCanvas(); |
| 1237 | c->translate(SkIntToScalar(-i * fW), |
| 1238 | SkIntToScalar(-j * fH)); // Line up the canvas with this tile. |
| 1239 | mpd.add(c, pic); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1240 | } |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1241 | } |
mtklein | a16e69e | 2015-05-05 11:38:45 -0700 | [diff] [blame] | 1242 | mpd.draw(); |
| 1243 | for (int j = 0; j < yTiles; j++) { |
| 1244 | for (int i = 0; i < xTiles; i++) { |
| 1245 | SkAutoTUnref<SkImage> image(surfaces[i+xTiles*j]->newImageSnapshot()); |
| 1246 | canvas->drawImage(image, SkIntToScalar(i*fW), SkIntToScalar(j*fH)); |
| 1247 | } |
| 1248 | } |
| 1249 | surfaces.unrefAll(); |
| 1250 | return ""; |
| 1251 | }); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1252 | } |
| 1253 | |
mtklein | b7e8d69 | 2015-04-07 08:30:32 -0700 | [diff] [blame] | 1254 | /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ |
| 1255 | |
mtklein | 4a34ecb | 2016-01-08 10:19:35 -0800 | [diff] [blame] | 1256 | Error ViaPicture::draw(const Src& src, SkBitmap* bitmap, SkWStream* stream, SkString* log) const { |
| 1257 | auto size = src.size(); |
| 1258 | return draw_to_canvas(fSink, bitmap, stream, log, size, [&](SkCanvas* canvas) -> Error { |
| 1259 | SkPictureRecorder recorder; |
| 1260 | SkAutoTUnref<SkPicture> pic; |
| 1261 | Error err = src.draw(recorder.beginRecording(SkIntToScalar(size.width()), |
| 1262 | SkIntToScalar(size.height()))); |
| 1263 | if (!err.isEmpty()) { |
| 1264 | return err; |
| 1265 | } |
| 1266 | pic.reset(recorder.endRecordingAsPicture()); |
| 1267 | canvas->drawPicture(pic); |
| 1268 | return check_against_reference(bitmap, src, fSink); |
| 1269 | }); |
| 1270 | } |
| 1271 | |
| 1272 | /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ |
| 1273 | |
mtklein | b7e8d69 | 2015-04-07 08:30:32 -0700 | [diff] [blame] | 1274 | // Draw the Src into two pictures, then draw the second picture into the wrapped Sink. |
| 1275 | // This tests that any shortcuts we may take while recording that second picture are legal. |
| 1276 | Error ViaSecondPicture::draw( |
| 1277 | const Src& src, SkBitmap* bitmap, SkWStream* stream, SkString* log) const { |
mtklein | a16e69e | 2015-05-05 11:38:45 -0700 | [diff] [blame] | 1278 | auto size = src.size(); |
msarett | 62d3b10 | 2015-12-10 15:14:27 -0800 | [diff] [blame] | 1279 | return draw_to_canvas(fSink, bitmap, stream, log, size, [&](SkCanvas* canvas) -> Error { |
mtklein | a16e69e | 2015-05-05 11:38:45 -0700 | [diff] [blame] | 1280 | SkPictureRecorder recorder; |
| 1281 | SkAutoTUnref<SkPicture> pic; |
| 1282 | for (int i = 0; i < 2; i++) { |
| 1283 | Error err = src.draw(recorder.beginRecording(SkIntToScalar(size.width()), |
| 1284 | SkIntToScalar(size.height()))); |
| 1285 | if (!err.isEmpty()) { |
| 1286 | return err; |
mtklein | b7e8d69 | 2015-04-07 08:30:32 -0700 | [diff] [blame] | 1287 | } |
mtklein | a16e69e | 2015-05-05 11:38:45 -0700 | [diff] [blame] | 1288 | pic.reset(recorder.endRecordingAsPicture()); |
mtklein | b7e8d69 | 2015-04-07 08:30:32 -0700 | [diff] [blame] | 1289 | } |
mtklein | a16e69e | 2015-05-05 11:38:45 -0700 | [diff] [blame] | 1290 | canvas->drawPicture(pic); |
mtklein | 4a34ecb | 2016-01-08 10:19:35 -0800 | [diff] [blame] | 1291 | return check_against_reference(bitmap, src, fSink); |
mtklein | a16e69e | 2015-05-05 11:38:45 -0700 | [diff] [blame] | 1292 | }); |
mtklein | b7e8d69 | 2015-04-07 08:30:32 -0700 | [diff] [blame] | 1293 | } |
| 1294 | |
mtklein | d31c13d | 2015-05-05 12:59:56 -0700 | [diff] [blame] | 1295 | /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ |
| 1296 | |
mtklein | 6fbf4b3 | 2015-05-06 11:35:40 -0700 | [diff] [blame] | 1297 | // Draw the Src twice. This can help exercise caching. |
| 1298 | Error ViaTwice::draw(const Src& src, SkBitmap* bitmap, SkWStream* stream, SkString* log) const { |
msarett | 62d3b10 | 2015-12-10 15:14:27 -0800 | [diff] [blame] | 1299 | return draw_to_canvas(fSink, bitmap, stream, log, src.size(), [&](SkCanvas* canvas) -> Error { |
mtklein | 6fbf4b3 | 2015-05-06 11:35:40 -0700 | [diff] [blame] | 1300 | for (int i = 0; i < 2; i++) { |
| 1301 | SkAutoCanvasRestore acr(canvas, true/*save now*/); |
| 1302 | canvas->clear(SK_ColorTRANSPARENT); |
| 1303 | Error err = src.draw(canvas); |
| 1304 | if (err.isEmpty()) { |
| 1305 | return err; |
| 1306 | } |
| 1307 | } |
mtklein | 4a34ecb | 2016-01-08 10:19:35 -0800 | [diff] [blame] | 1308 | return check_against_reference(bitmap, src, fSink); |
mtklein | 6fbf4b3 | 2015-05-06 11:35:40 -0700 | [diff] [blame] | 1309 | }); |
| 1310 | } |
| 1311 | |
| 1312 | /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ |
| 1313 | |
halcanary | 7a76f9c | 2016-02-03 11:53:18 -0800 | [diff] [blame] | 1314 | #ifdef SK_MOJO |
| 1315 | Error ViaMojo::draw(const Src& src, SkBitmap* bitmap, SkWStream* stream, SkString* log) const { |
| 1316 | SkPictureRecorder recorder; |
| 1317 | SkRect size = SkRect::Make(SkIRect::MakeSize(src.size())); |
| 1318 | Error err = src.draw(recorder.beginRecording(size)); |
| 1319 | if (!err.isEmpty()) { |
| 1320 | return err; |
| 1321 | } |
| 1322 | SkAutoTUnref<SkPicture> skPicture(recorder.endRecording()); |
| 1323 | |
| 1324 | SkASSERT(skPicture); |
| 1325 | SkDynamicMemoryWStream buffer; |
| 1326 | skPicture->serialize(&buffer); |
| 1327 | skPicture.reset(); |
| 1328 | SkMojo::FlattenedPicturePtr mojoPicture = SkMojo::FlattenedPicture::New(); |
| 1329 | mojoPicture->data.resize(buffer.bytesWritten()); |
| 1330 | buffer.copyTo(mojoPicture->data.data()); |
| 1331 | buffer.reset(); |
| 1332 | SkASSERT(mojoPicture.get() && mojoPicture->data); |
| 1333 | |
| 1334 | size_t flatSize = mojoPicture->GetSerializedSize(); |
| 1335 | SkAutoMalloc storage(flatSize); |
| 1336 | if (!mojoPicture->Serialize(storage.get(), flatSize)) { |
| 1337 | return "SkMojo::FlattenedPicture::Serialize failed"; |
| 1338 | } |
| 1339 | mojoPicture = SkMojo::FlattenedPicture::New(); |
| 1340 | mojoPicture->Deserialize(storage.get()); |
| 1341 | storage.free(); |
| 1342 | if (!mojoPicture) { |
| 1343 | return "SkMojo::FlattenedPicture::Deserialize failed"; |
| 1344 | } |
| 1345 | SkMemoryStream tmpStream(mojoPicture->data.data(), |
| 1346 | mojoPicture->data.size()); |
| 1347 | skPicture.reset(SkPicture::CreateFromStream(&tmpStream)); |
| 1348 | mojoPicture.reset(); |
| 1349 | auto fn = [&](SkCanvas* canvas) -> Error { |
| 1350 | canvas->drawPicture(skPicture.get()); |
| 1351 | return check_against_reference(bitmap, src, fSink); |
| 1352 | }; |
| 1353 | return draw_to_canvas(fSink, bitmap, stream, log, src.size(), fn); |
| 1354 | } |
| 1355 | #else // not SK_MOJO |
| 1356 | Error ViaMojo::draw(const Src&, SkBitmap*, SkWStream*, SkString*) const { |
| 1357 | return "Mojo is missing!"; |
| 1358 | } |
| 1359 | #endif |
| 1360 | |
| 1361 | /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ |
| 1362 | |
mtklein | d31c13d | 2015-05-05 12:59:56 -0700 | [diff] [blame] | 1363 | // This is like SkRecords::Draw, in that it plays back SkRecords ops into a Canvas. |
| 1364 | // Unlike SkRecords::Draw, it builds a single-op sub-picture out of each Draw-type op. |
| 1365 | // This is an only-slightly-exaggerated simluation of Blink's Slimming Paint pictures. |
| 1366 | struct DrawsAsSingletonPictures { |
| 1367 | SkCanvas* fCanvas; |
mtklein | d2baa90 | 2015-07-07 09:43:28 -0700 | [diff] [blame] | 1368 | const SkDrawableList& fDrawables; |
mtklein | d31c13d | 2015-05-05 12:59:56 -0700 | [diff] [blame] | 1369 | |
mtklein | d31c13d | 2015-05-05 12:59:56 -0700 | [diff] [blame] | 1370 | template <typename T> |
| 1371 | void draw(const T& op, SkCanvas* canvas) { |
| 1372 | // We must pass SkMatrix::I() as our initial matrix. |
| 1373 | // By default SkRecords::Draw() uses the canvas' matrix as its initial matrix, |
| 1374 | // which would have the funky effect of applying transforms over and over. |
mtklein | d2baa90 | 2015-07-07 09:43:28 -0700 | [diff] [blame] | 1375 | SkRecords::Draw d(canvas, nullptr, fDrawables.begin(), fDrawables.count(), &SkMatrix::I()); |
| 1376 | d(op); |
mtklein | d31c13d | 2015-05-05 12:59:56 -0700 | [diff] [blame] | 1377 | } |
| 1378 | |
mtklein | 449d9b7 | 2015-09-28 10:33:02 -0700 | [diff] [blame] | 1379 | // Draws get their own picture. |
mtklein | d31c13d | 2015-05-05 12:59:56 -0700 | [diff] [blame] | 1380 | template <typename T> |
mtklein | 449d9b7 | 2015-09-28 10:33:02 -0700 | [diff] [blame] | 1381 | SK_WHEN(T::kTags & SkRecords::kDraw_Tag, void) operator()(const T& op) { |
mtklein | d31c13d | 2015-05-05 12:59:56 -0700 | [diff] [blame] | 1382 | SkPictureRecorder rec; |
| 1383 | this->draw(op, rec.beginRecording(SkRect::MakeLargest())); |
| 1384 | SkAutoTUnref<SkPicture> pic(rec.endRecordingAsPicture()); |
| 1385 | fCanvas->drawPicture(pic); |
| 1386 | } |
| 1387 | |
mtklein | 449d9b7 | 2015-09-28 10:33:02 -0700 | [diff] [blame] | 1388 | // We'll just issue non-draws directly. |
mtklein | d31c13d | 2015-05-05 12:59:56 -0700 | [diff] [blame] | 1389 | template <typename T> |
mtklein | 449d9b7 | 2015-09-28 10:33:02 -0700 | [diff] [blame] | 1390 | skstd::enable_if_t<!(T::kTags & SkRecords::kDraw_Tag), void> operator()(const T& op) { |
| 1391 | this->draw(op, fCanvas); |
| 1392 | } |
mtklein | d31c13d | 2015-05-05 12:59:56 -0700 | [diff] [blame] | 1393 | }; |
| 1394 | |
mtklein | d31c13d | 2015-05-05 12:59:56 -0700 | [diff] [blame] | 1395 | // Record Src into a picture, then record it into a macro picture with a sub-picture for each draw. |
| 1396 | // Then play back that macro picture into our wrapped sink. |
| 1397 | Error ViaSingletonPictures::draw( |
| 1398 | const Src& src, SkBitmap* bitmap, SkWStream* stream, SkString* log) const { |
| 1399 | auto size = src.size(); |
msarett | 62d3b10 | 2015-12-10 15:14:27 -0800 | [diff] [blame] | 1400 | return draw_to_canvas(fSink, bitmap, stream, log, size, [&](SkCanvas* canvas) -> Error { |
mtklein | d31c13d | 2015-05-05 12:59:56 -0700 | [diff] [blame] | 1401 | // Use low-level (Skia-private) recording APIs so we can read the SkRecord. |
| 1402 | SkRecord skr; |
| 1403 | SkRecorder recorder(&skr, size.width(), size.height()); |
| 1404 | Error err = src.draw(&recorder); |
| 1405 | if (!err.isEmpty()) { |
| 1406 | return err; |
| 1407 | } |
| 1408 | |
| 1409 | // Record our macro-picture, with each draw op as its own sub-picture. |
| 1410 | SkPictureRecorder macroRec; |
| 1411 | SkCanvas* macroCanvas = macroRec.beginRecording(SkIntToScalar(size.width()), |
| 1412 | SkIntToScalar(size.height())); |
mtklein | d2baa90 | 2015-07-07 09:43:28 -0700 | [diff] [blame] | 1413 | |
| 1414 | SkAutoTDelete<SkDrawableList> drawables(recorder.detachDrawableList()); |
| 1415 | const SkDrawableList empty; |
| 1416 | |
| 1417 | DrawsAsSingletonPictures drawsAsSingletonPictures = { |
| 1418 | macroCanvas, |
| 1419 | drawables ? *drawables : empty, |
| 1420 | }; |
mtklein | c6ad06a | 2015-08-19 09:51:00 -0700 | [diff] [blame] | 1421 | for (int i = 0; i < skr.count(); i++) { |
mtklein | d31c13d | 2015-05-05 12:59:56 -0700 | [diff] [blame] | 1422 | skr.visit<void>(i, drawsAsSingletonPictures); |
| 1423 | } |
| 1424 | SkAutoTUnref<SkPicture> macroPic(macroRec.endRecordingAsPicture()); |
| 1425 | |
| 1426 | canvas->drawPicture(macroPic); |
mtklein | 4a34ecb | 2016-01-08 10:19:35 -0800 | [diff] [blame] | 1427 | return check_against_reference(bitmap, src, fSink); |
mtklein | d31c13d | 2015-05-05 12:59:56 -0700 | [diff] [blame] | 1428 | }); |
| 1429 | } |
| 1430 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1431 | } // namespace DM |