Chromium Code Reviews| Index: src/codec/SkCodec.cpp |
| diff --git a/src/codec/SkCodec.cpp b/src/codec/SkCodec.cpp |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..69d95a41da24be0231cdd32b8719d2b1d6ea3747 |
| --- /dev/null |
| +++ b/src/codec/SkCodec.cpp |
| @@ -0,0 +1,49 @@ |
| +/* |
| + * Copyright 2015 Google Inc. |
| + * |
| + * Use of this source code is governed by a BSD-style license that can be |
| + * found in the LICENSE file. |
| + */ |
| + |
| +#include "SkCodec.h" |
| +#include "SkData.h" |
| +#include "SkCodec_libpng.h" |
| +#include "SkStream.h" |
| + |
| +SkCodec* SkCodec::NewFromStream(SkStream* stream) { |
| + if (!stream) { |
| + return NULL; |
| + } |
| + SkAutoTDelete<SkStream> streamDeleter(stream); |
| + const bool isPng = SkPngCodec::IsPng(stream); |
| + 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.
|
| + return NULL; |
| + } |
| + if (isPng) { |
| + streamDeleter.detach(); |
| + return SkPngCodec::NewFromStream(stream); |
| + } |
| + // TODO: Check other image types. |
| + return NULL; |
| +} |
| + |
| +SkCodec* SkCodec::NewFromData(SkData* data) { |
| + if (!data) { |
| + return NULL; |
| + } |
| + return NewFromStream(SkNEW_ARGS(SkMemoryStream, (data))); |
| +} |
| + |
| +SkCodec::SkCodec(const SkImageInfo& info, SkStream* stream) |
| + : fInfo(info) |
| + , fStream(stream) |
| + , fNeedsRewind(false) |
| +{} |
| + |
| +bool SkCodec::couldRewindIfNeeded() { |
| + // Store the value of fNeedsRewind so we can update it. Next read will |
| + // require a rewind. |
| + const bool neededRewind = fNeedsRewind; |
| + fNeedsRewind = true; |
| + return !neededRewind || fStream->rewind(); |
| +} |