Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(234)

Side by Side Diff: dm/DMSrcSink.cpp

Issue 1316233002: Style Change: NULL->nullptr (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 2015-08-27 (Thursday) 10:25:06 EDT Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « dm/DMGpuSupport.h ('k') | gm/aaclip.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2015 Google Inc. 2 * Copyright 2015 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "DMSrcSink.h" 8 #include "DMSrcSink.h"
9 #include "SamplePipeControllers.h" 9 #include "SamplePipeControllers.h"
10 #include "SkCodec.h" 10 #include "SkCodec.h"
(...skipping 23 matching lines...) Expand all
34 static bool lazy_decode_bitmap(const void* src, size_t size, SkBitmap* dst) { 34 static bool lazy_decode_bitmap(const void* src, size_t size, SkBitmap* dst) {
35 SkAutoTUnref<SkData> encoded(SkData::NewWithCopy(src, size)); 35 SkAutoTUnref<SkData> encoded(SkData::NewWithCopy(src, size));
36 return encoded && SkInstallDiscardablePixelRef(encoded, dst); 36 return encoded && SkInstallDiscardablePixelRef(encoded, dst);
37 } 37 }
38 38
39 namespace DM { 39 namespace DM {
40 40
41 GMSrc::GMSrc(skiagm::GMRegistry::Factory factory) : fFactory(factory) {} 41 GMSrc::GMSrc(skiagm::GMRegistry::Factory factory) : fFactory(factory) {}
42 42
43 Error GMSrc::draw(SkCanvas* canvas) const { 43 Error GMSrc::draw(SkCanvas* canvas) const {
44 SkAutoTDelete<skiagm::GM> gm(fFactory(NULL)); 44 SkAutoTDelete<skiagm::GM> gm(fFactory(nullptr));
45 canvas->concat(gm->getInitialTransform()); 45 canvas->concat(gm->getInitialTransform());
46 gm->draw(canvas); 46 gm->draw(canvas);
47 return ""; 47 return "";
48 } 48 }
49 49
50 SkISize GMSrc::size() const { 50 SkISize GMSrc::size() const {
51 SkAutoTDelete<skiagm::GM> gm(fFactory(NULL)); 51 SkAutoTDelete<skiagm::GM> gm(fFactory(nullptr));
52 return gm->getISize(); 52 return gm->getISize();
53 } 53 }
54 54
55 Name GMSrc::name() const { 55 Name GMSrc::name() const {
56 SkAutoTDelete<skiagm::GM> gm(fFactory(NULL)); 56 SkAutoTDelete<skiagm::GM> gm(fFactory(nullptr));
57 return gm->getName(); 57 return gm->getName();
58 } 58 }
59 59
60 void GMSrc::modifyGrContextOptions(GrContextOptions* options) const { 60 void GMSrc::modifyGrContextOptions(GrContextOptions* options) const {
61 SkAutoTDelete<skiagm::GM> gm(fFactory(NULL)); 61 SkAutoTDelete<skiagm::GM> gm(fFactory(nullptr));
62 gm->modifyGrContextOptions(options); 62 gm->modifyGrContextOptions(options);
63 } 63 }
64 64
65 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~*/ 65 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~*/
66 66
67 CodecSrc::CodecSrc(Path path, Mode mode, DstColorType dstColorType, float scale) 67 CodecSrc::CodecSrc(Path path, Mode mode, DstColorType dstColorType, float scale)
68 : fPath(path) 68 : fPath(path)
69 , fMode(mode) 69 , fMode(mode)
70 , fDstColorType(dstColorType) 70 , fDstColorType(dstColorType)
71 , fScale(scale) 71 , fScale(scale)
72 {} 72 {}
73 73
74 bool CodecSrc::veto(SinkFlags flags) const { 74 bool CodecSrc::veto(SinkFlags flags) const {
75 // No need to test decoding to non-raster or indirect backend. 75 // No need to test decoding to non-raster or indirect backend.
76 // TODO: Once we implement GPU paths (e.g. JPEG YUV), we should use a deferr ed decode to 76 // TODO: Once we implement GPU paths (e.g. JPEG YUV), we should use a deferr ed decode to
77 // let the GPU handle it. 77 // let the GPU handle it.
78 return flags.type != SinkFlags::kRaster 78 return flags.type != SinkFlags::kRaster
79 || flags.approach != SinkFlags::kDirect; 79 || flags.approach != SinkFlags::kDirect;
80 } 80 }
81 81
82 Error CodecSrc::draw(SkCanvas* canvas) const { 82 Error CodecSrc::draw(SkCanvas* canvas) const {
83 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str())); 83 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str()));
84 if (!encoded) { 84 if (!encoded) {
85 return SkStringPrintf("Couldn't read %s.", fPath.c_str()); 85 return SkStringPrintf("Couldn't read %s.", fPath.c_str());
86 } 86 }
87 SkAutoTDelete<SkCodec> codec(SkScaledCodec::NewFromData(encoded)); 87 SkAutoTDelete<SkCodec> codec(SkScaledCodec::NewFromData(encoded));
88 if (NULL == codec.get()) { 88 if (nullptr == codec.get()) {
89 // scaledCodec not supported, try normal codec 89 // scaledCodec not supported, try normal codec
90 codec.reset(SkCodec::NewFromData(encoded)); 90 codec.reset(SkCodec::NewFromData(encoded));
91 if (NULL == codec.get()) { 91 if (nullptr == codec.get()) {
92 return SkStringPrintf("Couldn't create codec for %s.", fPath.c_str() ); 92 return SkStringPrintf("Couldn't create codec for %s.", fPath.c_str() );
93 } 93 }
94 } 94 }
95 95
96 // Choose the color type to decode to 96 // Choose the color type to decode to
97 SkImageInfo decodeInfo = codec->getInfo(); 97 SkImageInfo decodeInfo = codec->getInfo();
98 SkColorType canvasColorType = canvas->imageInfo().colorType(); 98 SkColorType canvasColorType = canvas->imageInfo().colorType();
99 switch (fDstColorType) { 99 switch (fDstColorType) {
100 case kIndex8_Always_DstColorType: 100 case kIndex8_Always_DstColorType:
101 decodeInfo = codec->getInfo().makeColorType(kIndex_8_SkColorType); 101 decodeInfo = codec->getInfo().makeColorType(kIndex_8_SkColorType);
(...skipping 19 matching lines...) Expand all
121 } 121 }
122 122
123 // Visually inspecting very small output images is not necessary. We will 123 // Visually inspecting very small output images is not necessary. We will
124 // cover these cases in unit testing. 124 // cover these cases in unit testing.
125 if ((size.width() <= 10 || size.height() <= 10) && 1.0f != fScale) { 125 if ((size.width() <= 10 || size.height() <= 10) && 1.0f != fScale) {
126 return Error::Nonfatal("Scaling very small images is uninteresting."); 126 return Error::Nonfatal("Scaling very small images is uninteresting.");
127 } 127 }
128 decodeInfo = decodeInfo.makeWH(size.width(), size.height()); 128 decodeInfo = decodeInfo.makeWH(size.width(), size.height());
129 129
130 // Construct a color table for the decode if necessary 130 // Construct a color table for the decode if necessary
131 SkAutoTUnref<SkColorTable> colorTable(NULL); 131 SkAutoTUnref<SkColorTable> colorTable(nullptr);
132 SkPMColor* colorPtr = NULL; 132 SkPMColor* colorPtr = nullptr;
133 int* colorCountPtr = NULL; 133 int* colorCountPtr = nullptr;
134 int maxColors = 256; 134 int maxColors = 256;
135 if (kIndex_8_SkColorType == decodeInfo.colorType()) { 135 if (kIndex_8_SkColorType == decodeInfo.colorType()) {
136 SkPMColor colors[256]; 136 SkPMColor colors[256];
137 colorTable.reset(new SkColorTable(colors, maxColors)); 137 colorTable.reset(new SkColorTable(colors, maxColors));
138 colorPtr = const_cast<SkPMColor*>(colorTable->readColors()); 138 colorPtr = const_cast<SkPMColor*>(colorTable->readColors());
139 colorCountPtr = &maxColors; 139 colorCountPtr = &maxColors;
140 } 140 }
141 141
142 // FIXME: Currently we cannot draw unpremultiplied sources. 142 // FIXME: Currently we cannot draw unpremultiplied sources.
143 if (decodeInfo.alphaType() == kUnpremul_SkAlphaType) { 143 if (decodeInfo.alphaType() == kUnpremul_SkAlphaType) {
144 decodeInfo = decodeInfo.makeAlphaType(kPremul_SkAlphaType); 144 decodeInfo = decodeInfo.makeAlphaType(kPremul_SkAlphaType);
145 } 145 }
146 146
147 SkBitmap bitmap; 147 SkBitmap bitmap;
148 if (!bitmap.tryAllocPixels(decodeInfo, NULL, colorTable.get())) { 148 if (!bitmap.tryAllocPixels(decodeInfo, nullptr, colorTable.get())) {
149 return SkStringPrintf("Image(%s) is too large (%d x %d)\n", fPath.c_str( ), 149 return SkStringPrintf("Image(%s) is too large (%d x %d)\n", fPath.c_str( ),
150 decodeInfo.width(), decodeInfo.height()); 150 decodeInfo.width(), decodeInfo.height());
151 } 151 }
152 152
153 switch (fMode) { 153 switch (fMode) {
154 case kNormal_Mode: { 154 case kNormal_Mode: {
155 switch (codec->getPixels(decodeInfo, bitmap.getPixels(), bitmap.rowB ytes(), NULL, 155 switch (codec->getPixels(decodeInfo, bitmap.getPixels(), bitmap.rowB ytes(), nullptr,
156 colorPtr, colorCountPtr)) { 156 colorPtr, colorCountPtr)) {
157 case SkCodec::kSuccess: 157 case SkCodec::kSuccess:
158 // We consider incomplete to be valid, since we should still decode what is 158 // We consider incomplete to be valid, since we should still decode what is
159 // available. 159 // available.
160 case SkCodec::kIncompleteInput: 160 case SkCodec::kIncompleteInput:
161 break; 161 break;
162 case SkCodec::kInvalidConversion: 162 case SkCodec::kInvalidConversion:
163 return Error::Nonfatal("Incompatible colortype conversion"); 163 return Error::Nonfatal("Incompatible colortype conversion");
164 default: 164 default:
165 // Everything else is considered a failure. 165 // Everything else is considered a failure.
166 return SkStringPrintf("Couldn't getPixels %s.", fPath.c_str( )); 166 return SkStringPrintf("Couldn't getPixels %s.", fPath.c_str( ));
167 } 167 }
168 canvas->drawBitmap(bitmap, 0, 0); 168 canvas->drawBitmap(bitmap, 0, 0);
169 break; 169 break;
170 } 170 }
171 case kScanline_Mode: { 171 case kScanline_Mode: {
172 SkAutoTDelete<SkScanlineDecoder> scanlineDecoder( 172 SkAutoTDelete<SkScanlineDecoder> scanlineDecoder(
173 SkScanlineDecoder::NewFromData(encoded)); 173 SkScanlineDecoder::NewFromData(encoded));
174 if (NULL == scanlineDecoder || SkCodec::kSuccess != 174 if (nullptr == scanlineDecoder || SkCodec::kSuccess !=
175 scanlineDecoder->start(decodeInfo, NULL, colorPtr, colorCoun tPtr)) { 175 scanlineDecoder->start(decodeInfo, nullptr, colorPtr, colorC ountPtr)) {
176 return Error::Nonfatal("Cannot use scanline decoder for all imag es"); 176 return Error::Nonfatal("Cannot use scanline decoder for all imag es");
177 } 177 }
178 178
179 const SkCodec::Result result = scanlineDecoder->getScanlines( 179 const SkCodec::Result result = scanlineDecoder->getScanlines(
180 bitmap.getAddr(0, 0), decodeInfo.height(), bitmap.rowBytes() ); 180 bitmap.getAddr(0, 0), decodeInfo.height(), bitmap.rowBytes() );
181 switch (result) { 181 switch (result) {
182 case SkCodec::kSuccess: 182 case SkCodec::kSuccess:
183 case SkCodec::kIncompleteInput: 183 case SkCodec::kIncompleteInput:
184 break; 184 break;
185 default: 185 default:
(...skipping 22 matching lines...) Expand all
208 * subsets to cover entire image. 208 * subsets to cover entire image.
209 * Add extraX and extraY to largestSubsetBm's width and height to adj ust width 209 * Add extraX and extraY to largestSubsetBm's width and height to adj ust width
210 * and height of end subsets. 210 * and height of end subsets.
211 * subsetBm is extracted from largestSubsetBm. 211 * subsetBm is extracted from largestSubsetBm.
212 * subsetBm's size is determined based on the current subset and may be larger for end 212 * subsetBm's size is determined based on the current subset and may be larger for end
213 * subsets. 213 * subsets.
214 */ 214 */
215 SkImageInfo largestSubsetDecodeInfo = 215 SkImageInfo largestSubsetDecodeInfo =
216 decodeInfo.makeWH(subsetWidth + extraX, subsetHeight + extra Y); 216 decodeInfo.makeWH(subsetWidth + extraX, subsetHeight + extra Y);
217 SkBitmap largestSubsetBm; 217 SkBitmap largestSubsetBm;
218 if (!largestSubsetBm.tryAllocPixels(largestSubsetDecodeInfo, NULL, c olorTable.get())) { 218 if (!largestSubsetBm.tryAllocPixels(largestSubsetDecodeInfo, nullptr , colorTable.get())) {
219 return SkStringPrintf("Image(%s) is too large (%d x %d)\n", fPat h.c_str(), 219 return SkStringPrintf("Image(%s) is too large (%d x %d)\n", fPat h.c_str(),
220 largestSubsetDecodeInfo.width(), largestSubsetDecodeInfo .height()); 220 largestSubsetDecodeInfo.width(), largestSubsetDecodeInfo .height());
221 } 221 }
222 const size_t rowBytes = decodeInfo.minRowBytes(); 222 const size_t rowBytes = decodeInfo.minRowBytes();
223 char* buffer = new char[largestSubsetDecodeInfo.height() * rowBytes] ; 223 char* buffer = new char[largestSubsetDecodeInfo.height() * rowBytes] ;
224 SkAutoTDeleteArray<char> lineDeleter(buffer); 224 SkAutoTDeleteArray<char> lineDeleter(buffer);
225 for (int col = 0; col < divisor; col++) { 225 for (int col = 0; col < divisor; col++) {
226 //currentSubsetWidth may be larger than subsetWidth for rightmos t subsets 226 //currentSubsetWidth may be larger than subsetWidth for rightmos t subsets
227 const int currentSubsetWidth = (col + 1 == divisor) ? 227 const int currentSubsetWidth = (col + 1 == divisor) ?
228 subsetWidth + extraX : subsetWidth; 228 subsetWidth + extraX : subsetWidth;
229 const int x = col * subsetWidth; 229 const int x = col * subsetWidth;
230 for (int row = 0; row < divisor; row++) { 230 for (int row = 0; row < divisor; row++) {
231 //currentSubsetHeight may be larger than subsetHeight for bo ttom subsets 231 //currentSubsetHeight may be larger than subsetHeight for bo ttom subsets
232 const int currentSubsetHeight = (row + 1 == divisor) ? 232 const int currentSubsetHeight = (row + 1 == divisor) ?
233 subsetHeight + extraY : subsetHeight; 233 subsetHeight + extraY : subsetHeight;
234 const int y = row * subsetHeight; 234 const int y = row * subsetHeight;
235 //create scanline decoder for each subset 235 //create scanline decoder for each subset
236 SkAutoTDelete<SkScanlineDecoder> subsetScanlineDecoder( 236 SkAutoTDelete<SkScanlineDecoder> subsetScanlineDecoder(
237 SkScanlineDecoder::NewFromData(encoded)); 237 SkScanlineDecoder::NewFromData(encoded));
238 if (NULL == subsetScanlineDecoder || SkCodec::kSuccess != 238 if (nullptr == subsetScanlineDecoder || SkCodec::kSuccess !=
239 subsetScanlineDecoder->start( 239 subsetScanlineDecoder->start(
240 decodeInfo, NULL, colorPtr, colorCountPtr)) 240 decodeInfo, nullptr, colorPtr, colorCountPtr))
241 { 241 {
242 if (x == 0 && y == 0) { 242 if (x == 0 && y == 0) {
243 //first try, image may not be compatible 243 //first try, image may not be compatible
244 return Error::Nonfatal("Cannot use scanline decoder for all images"); 244 return Error::Nonfatal("Cannot use scanline decoder for all images");
245 } else { 245 } else {
246 return "Error scanline decoder is NULL"; 246 return "Error scanline decoder is nullptr";
247 } 247 }
248 } 248 }
249 //skip to first line of subset 249 //skip to first line of subset
250 const SkCodec::Result skipResult = 250 const SkCodec::Result skipResult =
251 subsetScanlineDecoder->skipScanlines(y); 251 subsetScanlineDecoder->skipScanlines(y);
252 switch (skipResult) { 252 switch (skipResult) {
253 case SkCodec::kSuccess: 253 case SkCodec::kSuccess:
254 case SkCodec::kIncompleteInput: 254 case SkCodec::kIncompleteInput:
255 break; 255 break;
256 default: 256 default:
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 } 298 }
299 case kStripe_Mode: { 299 case kStripe_Mode: {
300 const int height = decodeInfo.height(); 300 const int height = decodeInfo.height();
301 // This value is chosen arbitrarily. We exercise more cases by choo sing a value that 301 // This value is chosen arbitrarily. We exercise more cases by choo sing a value that
302 // does not align with image blocks. 302 // does not align with image blocks.
303 const int stripeHeight = 37; 303 const int stripeHeight = 37;
304 const int numStripes = (height + stripeHeight - 1) / stripeHeight; 304 const int numStripes = (height + stripeHeight - 1) / stripeHeight;
305 305
306 // Decode odd stripes 306 // Decode odd stripes
307 SkAutoTDelete<SkScanlineDecoder> decoder(SkScanlineDecoder::NewFromD ata(encoded)); 307 SkAutoTDelete<SkScanlineDecoder> decoder(SkScanlineDecoder::NewFromD ata(encoded));
308 if (NULL == decoder || SkCodec::kSuccess != 308 if (nullptr == decoder || SkCodec::kSuccess !=
309 decoder->start(decodeInfo, NULL, colorPtr, colorCountPtr)) { 309 decoder->start(decodeInfo, nullptr, colorPtr, colorCountPtr) ) {
310 return Error::Nonfatal("Cannot use scanline decoder for all imag es"); 310 return Error::Nonfatal("Cannot use scanline decoder for all imag es");
311 } 311 }
312 for (int i = 0; i < numStripes; i += 2) { 312 for (int i = 0; i < numStripes; i += 2) {
313 // Skip a stripe 313 // Skip a stripe
314 const int linesToSkip = SkTMin(stripeHeight, height - i * stripe Height); 314 const int linesToSkip = SkTMin(stripeHeight, height - i * stripe Height);
315 SkCodec::Result result = decoder->skipScanlines(linesToSkip); 315 SkCodec::Result result = decoder->skipScanlines(linesToSkip);
316 switch (result) { 316 switch (result) {
317 case SkCodec::kSuccess: 317 case SkCodec::kSuccess:
318 case SkCodec::kIncompleteInput: 318 case SkCodec::kIncompleteInput:
319 break; 319 break;
(...skipping 11 matching lines...) Expand all
331 case SkCodec::kSuccess: 331 case SkCodec::kSuccess:
332 case SkCodec::kIncompleteInput: 332 case SkCodec::kIncompleteInput:
333 break; 333 break;
334 default: 334 default:
335 return SkStringPrintf("Cannot get scanlines for %s." , fPath.c_str()); 335 return SkStringPrintf("Cannot get scanlines for %s." , fPath.c_str());
336 } 336 }
337 } 337 }
338 } 338 }
339 339
340 // Decode even stripes 340 // Decode even stripes
341 const SkCodec::Result startResult = decoder->start(decodeInfo, NULL, colorPtr, 341 const SkCodec::Result startResult = decoder->start(decodeInfo, nullp tr, colorPtr,
342 colorCountPtr); 342 colorCountPtr);
343 if (SkCodec::kSuccess != startResult) { 343 if (SkCodec::kSuccess != startResult) {
344 return "Failed to restart scanline decoder with same parameters. "; 344 return "Failed to restart scanline decoder with same parameters. ";
345 } 345 }
346 for (int i = 0; i < numStripes; i += 2) { 346 for (int i = 0; i < numStripes; i += 2) {
347 // Read a stripe 347 // Read a stripe
348 const int startY = i * stripeHeight; 348 const int startY = i * stripeHeight;
349 const int linesToRead = SkTMin(stripeHeight, height - startY); 349 const int linesToRead = SkTMin(stripeHeight, height - startY);
350 SkCodec::Result result = decoder->getScanlines(bitmap.getAddr(0, startY), 350 SkCodec::Result result = decoder->getScanlines(bitmap.getAddr(0, startY),
351 linesToRead, bitmap.rowBytes()); 351 linesToRead, bitmap.rowBytes());
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
405 const int preScaleW = SkTMin(w, W - x); 405 const int preScaleW = SkTMin(w, W - x);
406 const int preScaleH = SkTMin(h, H - y); 406 const int preScaleH = SkTMin(h, H - y);
407 subset.setXYWH(x, y, preScaleW, preScaleH); 407 subset.setXYWH(x, y, preScaleW, preScaleH);
408 // And scale 408 // And scale
409 // FIXME: Should we have a version of getScaledDimensions th at takes a subset 409 // FIXME: Should we have a version of getScaledDimensions th at takes a subset
410 // into account? 410 // into account?
411 decodeInfo = decodeInfo.makeWH(SkScalarRoundToInt(preScaleW * fScale), 411 decodeInfo = decodeInfo.makeWH(SkScalarRoundToInt(preScaleW * fScale),
412 SkScalarRoundToInt(preScaleH * fScale)); 412 SkScalarRoundToInt(preScaleH * fScale));
413 size_t rowBytes = decodeInfo.minRowBytes(); 413 size_t rowBytes = decodeInfo.minRowBytes();
414 if (!subsetBm.installPixels(decodeInfo, pixels, rowBytes, co lorTable.get(), 414 if (!subsetBm.installPixels(decodeInfo, pixels, rowBytes, co lorTable.get(),
415 NULL, NULL)) { 415 nullptr, nullptr)) {
416 return SkStringPrintf("could not install pixels for %s." , fPath.c_str()); 416 return SkStringPrintf("could not install pixels for %s." , fPath.c_str());
417 } 417 }
418 const SkCodec::Result result = codec->getPixels(decodeInfo, pixels, rowBytes, 418 const SkCodec::Result result = codec->getPixels(decodeInfo, pixels, rowBytes,
419 &opts, colorPtr, colorCountPtr); 419 &opts, colorPtr, colorCountPtr);
420 switch (result) { 420 switch (result) {
421 case SkCodec::kSuccess: 421 case SkCodec::kSuccess:
422 case SkCodec::kIncompleteInput: 422 case SkCodec::kIncompleteInput:
423 break; 423 break;
424 case SkCodec::kInvalidConversion: 424 case SkCodec::kInvalidConversion:
425 if (0 == (x|y)) { 425 if (0 == (x|y)) {
(...skipping 24 matching lines...) Expand all
450 } 450 }
451 return ""; 451 return "";
452 } 452 }
453 } 453 }
454 return ""; 454 return "";
455 } 455 }
456 456
457 SkISize CodecSrc::size() const { 457 SkISize CodecSrc::size() const {
458 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str())); 458 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str()));
459 SkAutoTDelete<SkCodec> codec(SkScaledCodec::NewFromData(encoded)); 459 SkAutoTDelete<SkCodec> codec(SkScaledCodec::NewFromData(encoded));
460 if (NULL == codec) { 460 if (nullptr == codec) {
461 // scaledCodec not supported, try regular codec 461 // scaledCodec not supported, try regular codec
462 codec.reset(SkCodec::NewFromData(encoded)); 462 codec.reset(SkCodec::NewFromData(encoded));
463 if (NULL == codec) { 463 if (nullptr == codec) {
464 return SkISize::Make(0, 0); 464 return SkISize::Make(0, 0);
465 } 465 }
466 } 466 }
467 SkISize size = codec->getScaledDimensions(fScale); 467 SkISize size = codec->getScaledDimensions(fScale);
468 return size; 468 return size;
469 } 469 }
470 470
471 Name CodecSrc::name() const { 471 Name CodecSrc::name() const {
472 if (1.0f == fScale) { 472 if (1.0f == fScale) {
473 return SkOSPath::Basename(fPath.c_str()); 473 return SkOSPath::Basename(fPath.c_str());
(...skipping 23 matching lines...) Expand all
497 // Decode the full image. 497 // Decode the full image.
498 SkBitmap bitmap; 498 SkBitmap bitmap;
499 if (!SkImageDecoder::DecodeMemory(encoded->data(), encoded->size(), &bit map, 499 if (!SkImageDecoder::DecodeMemory(encoded->data(), encoded->size(), &bit map,
500 dstColorType, SkImageDecoder::kDecodeP ixels_Mode)) { 500 dstColorType, SkImageDecoder::kDecodeP ixels_Mode)) {
501 return SkStringPrintf("Couldn't decode %s.", fPath.c_str()); 501 return SkStringPrintf("Couldn't decode %s.", fPath.c_str());
502 } 502 }
503 if (kRGB_565_SkColorType == dstColorType && !bitmap.isOpaque()) { 503 if (kRGB_565_SkColorType == dstColorType && !bitmap.isOpaque()) {
504 // Do not draw a bitmap with alpha to a destination without alpha. 504 // Do not draw a bitmap with alpha to a destination without alpha.
505 return Error::Nonfatal("Uninteresting to decode image with alpha int o 565."); 505 return Error::Nonfatal("Uninteresting to decode image with alpha int o 565.");
506 } 506 }
507 encoded.reset((SkData*)NULL); // Might as well drop this when we're don e with it. 507 encoded.reset((SkData*)nullptr); // Might as well drop this when we're done with it.
508 canvas->drawBitmap(bitmap, 0,0); 508 canvas->drawBitmap(bitmap, 0,0);
509 return ""; 509 return "";
510 } 510 }
511 // Decode subsets. This is a little involved. 511 // Decode subsets. This is a little involved.
512 SkAutoTDelete<SkMemoryStream> stream(new SkMemoryStream(encoded)); 512 SkAutoTDelete<SkMemoryStream> stream(new SkMemoryStream(encoded));
513 SkAutoTDelete<SkImageDecoder> decoder(SkImageDecoder::Factory(stream.get())) ; 513 SkAutoTDelete<SkImageDecoder> decoder(SkImageDecoder::Factory(stream.get())) ;
514 if (!decoder) { 514 if (!decoder) {
515 return SkStringPrintf("Can't find a good decoder for %s.", fPath.c_str() ); 515 return SkStringPrintf("Can't find a good decoder for %s.", fPath.c_str() );
516 } 516 }
517 stream->rewind(); 517 stream->rewind();
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
575 575
576 Error SKPSrc::draw(SkCanvas* canvas) const { 576 Error SKPSrc::draw(SkCanvas* canvas) const {
577 SkAutoTDelete<SkStream> stream(SkStream::NewFromFile(fPath.c_str())); 577 SkAutoTDelete<SkStream> stream(SkStream::NewFromFile(fPath.c_str()));
578 if (!stream) { 578 if (!stream) {
579 return SkStringPrintf("Couldn't read %s.", fPath.c_str()); 579 return SkStringPrintf("Couldn't read %s.", fPath.c_str());
580 } 580 }
581 SkAutoTUnref<SkPicture> pic(SkPicture::CreateFromStream(stream, &lazy_decode _bitmap)); 581 SkAutoTUnref<SkPicture> pic(SkPicture::CreateFromStream(stream, &lazy_decode _bitmap));
582 if (!pic) { 582 if (!pic) {
583 return SkStringPrintf("Couldn't decode %s as a picture.", fPath.c_str()) ; 583 return SkStringPrintf("Couldn't decode %s as a picture.", fPath.c_str()) ;
584 } 584 }
585 stream.reset((SkStream*)NULL); // Might as well drop this when we're done w ith it. 585 stream.reset((SkStream*)nullptr); // Might as well drop this when we're don e with it.
586 586
587 canvas->clipRect(kSKPViewport); 587 canvas->clipRect(kSKPViewport);
588 canvas->drawPicture(pic); 588 canvas->drawPicture(pic);
589 return ""; 589 return "";
590 } 590 }
591 591
592 SkISize SKPSrc::size() const { 592 SkISize SKPSrc::size() const {
593 SkAutoTDelete<SkStream> stream(SkStream::NewFromFile(fPath.c_str())); 593 SkAutoTDelete<SkStream> stream(SkStream::NewFromFile(fPath.c_str()));
594 if (!stream) { 594 if (!stream) {
595 return SkISize::Make(0,0); 595 return SkISize::Make(0,0);
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
642 GrContextFactory factory(options); 642 GrContextFactory factory(options);
643 const SkISize size = src.size(); 643 const SkISize size = src.size();
644 const SkImageInfo info = 644 const SkImageInfo info =
645 SkImageInfo::Make(size.width(), size.height(), kN32_SkColorType, kPremul _SkAlphaType); 645 SkImageInfo::Make(size.width(), size.height(), kN32_SkColorType, kPremul _SkAlphaType);
646 SkAutoTUnref<SkSurface> surface( 646 SkAutoTUnref<SkSurface> surface(
647 NewGpuSurface(&factory, fContextType, fGpuAPI, info, fSampleCount, f UseDFText)); 647 NewGpuSurface(&factory, fContextType, fGpuAPI, info, fSampleCount, f UseDFText));
648 if (!surface) { 648 if (!surface) {
649 return "Could not create a surface."; 649 return "Could not create a surface.";
650 } 650 }
651 if (FLAGS_preAbandonGpuContext) { 651 if (FLAGS_preAbandonGpuContext) {
652 SkSetErrorCallback(&PreAbandonGpuContextErrorHandler, NULL); 652 SkSetErrorCallback(&PreAbandonGpuContextErrorHandler, nullptr);
653 factory.abandonContexts(); 653 factory.abandonContexts();
654 } 654 }
655 SkCanvas* canvas = surface->getCanvas(); 655 SkCanvas* canvas = surface->getCanvas();
656 Error err = src.draw(canvas); 656 Error err = src.draw(canvas);
657 if (!err.isEmpty()) { 657 if (!err.isEmpty()) {
658 return err; 658 return err;
659 } 659 }
660 canvas->flush(); 660 canvas->flush();
661 if (FLAGS_gpuStats) { 661 if (FLAGS_gpuStats) {
662 canvas->getGrContext()->dumpCacheStats(log); 662 canvas->getGrContext()->dumpCacheStats(log);
(...skipping 24 matching lines...) Expand all
687 int xPages = ((width - 1) / kLetterWidth) + 1; 687 int xPages = ((width - 1) / kLetterWidth) + 1;
688 int yPages = ((height - 1) / kLetterHeight) + 1; 688 int yPages = ((height - 1) / kLetterHeight) + 1;
689 689
690 for (int y = 0; y < yPages; ++y) { 690 for (int y = 0; y < yPages; ++y) {
691 for (int x = 0; x < xPages; ++x) { 691 for (int x = 0; x < xPages; ++x) {
692 int w = SkTMin(kLetterWidth, width - (x * kLetterWidth)); 692 int w = SkTMin(kLetterWidth, width - (x * kLetterWidth));
693 int h = SkTMin(kLetterHeight, height - (y * kLetterHeight)); 693 int h = SkTMin(kLetterHeight, height - (y * kLetterHeight));
694 SkCanvas* canvas = 694 SkCanvas* canvas =
695 doc->beginPage(SkIntToScalar(w), SkIntToScalar(h)); 695 doc->beginPage(SkIntToScalar(w), SkIntToScalar(h));
696 if (!canvas) { 696 if (!canvas) {
697 return "SkDocument::beginPage(w,h) returned NULL"; 697 return "SkDocument::beginPage(w,h) returned nullptr";
698 } 698 }
699 canvas->clipRect(letter); 699 canvas->clipRect(letter);
700 canvas->translate(-letter.width() * x, -letter.height() * y); 700 canvas->translate(-letter.width() * x, -letter.height() * y);
701 Error err = src.draw(canvas); 701 Error err = src.draw(canvas);
702 if (!err.isEmpty()) { 702 if (!err.isEmpty()) {
703 return err; 703 return err;
704 } 704 }
705 doc->endPage(); 705 doc->endPage();
706 } 706 }
707 } 707 }
708 } else { 708 } else {
709 SkCanvas* canvas = 709 SkCanvas* canvas =
710 doc->beginPage(SkIntToScalar(width), SkIntToScalar(height)); 710 doc->beginPage(SkIntToScalar(width), SkIntToScalar(height));
711 if (!canvas) { 711 if (!canvas) {
712 return "SkDocument::beginPage(w,h) returned NULL"; 712 return "SkDocument::beginPage(w,h) returned nullptr";
713 } 713 }
714 Error err = src.draw(canvas); 714 Error err = src.draw(canvas);
715 if (!err.isEmpty()) { 715 if (!err.isEmpty()) {
716 return err; 716 return err;
717 } 717 }
718 doc->endPage(); 718 doc->endPage();
719 } 719 }
720 if (!doc->close()) { 720 if (!doc->close()) {
721 return "SkDocument::close() returned false"; 721 return "SkDocument::close() returned false";
722 } 722 }
723 dst->flush(); 723 dst->flush();
724 return ""; 724 return "";
725 } 725 }
726 726
727 PDFSink::PDFSink() {} 727 PDFSink::PDFSink() {}
728 728
729 Error PDFSink::draw(const Src& src, SkBitmap*, SkWStream* dst, SkString*) const { 729 Error PDFSink::draw(const Src& src, SkBitmap*, SkWStream* dst, SkString*) const {
730 SkAutoTUnref<SkDocument> doc(SkDocument::CreatePDF(dst)); 730 SkAutoTUnref<SkDocument> doc(SkDocument::CreatePDF(dst));
731 if (!doc) { 731 if (!doc) {
732 return "SkDocument::CreatePDF() returned NULL"; 732 return "SkDocument::CreatePDF() returned nullptr";
733 } 733 }
734 return draw_skdocument(src, doc.get(), dst); 734 return draw_skdocument(src, doc.get(), dst);
735 } 735 }
736 736
737 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~*/ 737 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~*/
738 738
739 XPSSink::XPSSink() {} 739 XPSSink::XPSSink() {}
740 740
741 Error XPSSink::draw(const Src& src, SkBitmap*, SkWStream* dst, SkString*) const { 741 Error XPSSink::draw(const Src& src, SkBitmap*, SkWStream* dst, SkString*) const {
742 SkAutoTUnref<SkDocument> doc(SkDocument::CreateXPS(dst)); 742 SkAutoTUnref<SkDocument> doc(SkDocument::CreateXPS(dst));
743 if (!doc) { 743 if (!doc) {
744 return "SkDocument::CreateXPS() returned NULL"; 744 return "SkDocument::CreateXPS() returned nullptr";
745 } 745 }
746 return draw_skdocument(src, doc.get(), dst); 746 return draw_skdocument(src, doc.get(), dst);
747 } 747 }
748 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~*/ 748 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~*/
749 749
750 SKPSink::SKPSink() {} 750 SKPSink::SKPSink() {}
751 751
752 Error SKPSink::draw(const Src& src, SkBitmap*, SkWStream* dst, SkString*) const { 752 Error SKPSink::draw(const Src& src, SkBitmap*, SkWStream* dst, SkString*) const {
753 SkSize size; 753 SkSize size;
754 size = src.size(); 754 size = src.size();
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after
1064 skr.visit<void>(i, drawsAsSingletonPictures); 1064 skr.visit<void>(i, drawsAsSingletonPictures);
1065 } 1065 }
1066 SkAutoTUnref<SkPicture> macroPic(macroRec.endRecordingAsPicture()); 1066 SkAutoTUnref<SkPicture> macroPic(macroRec.endRecordingAsPicture());
1067 1067
1068 canvas->drawPicture(macroPic); 1068 canvas->drawPicture(macroPic);
1069 return ""; 1069 return "";
1070 }); 1070 });
1071 } 1071 }
1072 1072
1073 } // namespace DM 1073 } // namespace DM
OLDNEW
« no previous file with comments | « dm/DMGpuSupport.h ('k') | gm/aaclip.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698