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

Side by Side Diff: dm/DMImageTask.cpp

Issue 849103004: Make SkStream *not* ref counted. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Treat SkFontMgr::createFromStream as taking ownership of the stream (is this correct?) Created 5 years, 11 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
OLDNEW
1 #include "DMImageTask.h" 1 #include "DMImageTask.h"
2 #include "DMUtil.h" 2 #include "DMUtil.h"
3 #include "DMWriteTask.h" 3 #include "DMWriteTask.h"
4 #include "SkImageDecoder.h" 4 #include "SkImageDecoder.h"
5 #include "SkRandom.h" 5 #include "SkRandom.h"
6 6
7 #include <string.h> 7 #include <string.h>
8 8
9 namespace DM { 9 namespace DM {
10 10
(...skipping 20 matching lines...) Expand all
31 if (fSubsets == 0) { 31 if (fSubsets == 0) {
32 // Decoding the whole image is considerably simpler than decoding subset s! 32 // Decoding the whole image is considerably simpler than decoding subset s!
33 SkBitmap bitmap; 33 SkBitmap bitmap;
34 if (!SkImageDecoder::DecodeMemory(fEncoded->data(), fEncoded->size(), &b itmap)) { 34 if (!SkImageDecoder::DecodeMemory(fEncoded->data(), fEncoded->size(), &b itmap)) {
35 return this->fail("Can't DecodeMemory"); 35 return this->fail("Can't DecodeMemory");
36 } 36 }
37 this->spawnChild(SkNEW_ARGS(WriteTask, (*this, "image", bitmap))); 37 this->spawnChild(SkNEW_ARGS(WriteTask, (*this, "image", bitmap)));
38 return; 38 return;
39 } 39 }
40 40
41 SkMemoryStream stream(fEncoded->data(), fEncoded->size()); 41 SkAutoTDelete<SkMemoryStream> stream(SkNEW_ARGS(SkMemoryStream,
42 SkAutoTDelete<SkImageDecoder> decoder(SkImageDecoder::Factory(&stream)); 42 (fEncoded->data(), fEncoded- >size())));
43 SkAutoTDelete<SkImageDecoder> decoder(SkImageDecoder::Factory(stream));
43 if (!decoder) { 44 if (!decoder) {
44 return this->fail("Can't find good decoder."); 45 return this->fail("Can't find good decoder.");
45 } 46 }
46 47
47 int w,h; 48 int w,h;
48 if (!decoder->buildTileIndex(&stream, &w, &h) || w*h == 1) { 49 if (!decoder->buildTileIndex(stream.detach(), &w, &h) || w*h == 1) {
49 return; // Subset decoding is not always supported. 50 return; // Subset decoding is not always supported.
50 } 51 }
51 52
52 SkBitmap composite; 53 SkBitmap composite;
53 composite.allocN32Pixels(w,h); // We're lazy here and just always use nativ e 8888. 54 composite.allocN32Pixels(w,h); // We're lazy here and just always use nativ e 8888.
54 composite.eraseColor(SK_ColorTRANSPARENT); 55 composite.eraseColor(SK_ColorTRANSPARENT);
55 SkCanvas canvas(composite); 56 SkCanvas canvas(composite);
56 57
57 SkRandom rand; 58 SkRandom rand;
58 for (int i = 0; i < fSubsets; i++) { 59 for (int i = 0; i < fSubsets; i++) {
(...skipping 10 matching lines...) Expand all
69 if (!decoder->decodeSubset(&subset, rect, kN32_SkColorType)) { 70 if (!decoder->decodeSubset(&subset, rect, kN32_SkColorType)) {
70 return this->fail("Could not decode subset."); 71 return this->fail("Could not decode subset.");
71 } 72 }
72 canvas.drawBitmap(subset, SkIntToScalar(rect.fLeft), SkIntToScalar(rect. fTop)); 73 canvas.drawBitmap(subset, SkIntToScalar(rect.fLeft), SkIntToScalar(rect. fTop));
73 } 74 }
74 canvas.flush(); 75 canvas.flush();
75 this->spawnChild(SkNEW_ARGS(WriteTask, (*this, "image", composite))); 76 this->spawnChild(SkNEW_ARGS(WriteTask, (*this, "image", composite)));
76 } 77 }
77 78
78 } // namespace DM 79 } // namespace DM
OLDNEW
« no previous file with comments | « dm/DM.cpp ('k') | dm/DMPDFRasterizeTask.cpp » ('j') | gm/gmmain.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698