OLD | NEW |
---|---|
(Empty) | |
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 | |
8 #include "SkCodec.h" | |
9 #include "SkData.h" | |
10 #include "SkCodec_libpng.h" | |
11 #include "SkStream.h" | |
12 | |
13 SkCodec* SkCodec::NewFromStream(SkStream* stream) { | |
14 if (!stream) { | |
15 return NULL; | |
16 } | |
17 SkAutoTDelete<SkStream> streamDeleter(stream); | |
18 const bool isPng = SkPngCodec::IsPng(stream); | |
19 if (!stream->rewind()) { | |
djsollen
2015/02/25 16:02:19
why do we have to be able to rewind the stream? A
scroggo
2015/02/25 18:00:54
I added a TODO, but have not specified the solutio
djsollen
2015/02/25 20:52:15
I'm fine with it just having a TODO, but think we
scroggo
2015/02/25 21:33:52
We already have a solution: SkFrontBufferedStream.
| |
20 return NULL; | |
21 } | |
22 if (isPng) { | |
23 streamDeleter.detach(); | |
24 return SkPngCodec::NewFromStream(stream); | |
25 } | |
26 // TODO: Check other image types. | |
27 return NULL; | |
28 } | |
29 | |
30 SkCodec* SkCodec::NewFromData(SkData* data) { | |
31 if (!data) { | |
32 return NULL; | |
33 } | |
34 return NewFromStream(SkNEW_ARGS(SkMemoryStream, (data))); | |
35 } | |
36 | |
37 SkCodec::SkCodec(const SkImageInfo& info, SkStream* stream) | |
38 : fInfo(info) | |
39 , fStream(stream) | |
40 , fNeedsRewind(false) | |
41 {} | |
42 | |
43 bool SkCodec::couldRewindIfNeeded() { | |
44 // Store the value of fNeedsRewind so we can update it. Next read will | |
45 // require a rewind. | |
46 const bool neededRewind = fNeedsRewind; | |
47 fNeedsRewind = true; | |
48 return !neededRewind || fStream->rewind(); | |
49 } | |
OLD | NEW |