| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
| 4 * | 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
| 7 */ | 7 */ |
| 8 #include "SkImageRef.h" | 8 #include "SkImageRef.h" |
| 9 #include "SkBitmap.h" | 9 #include "SkBitmap.h" |
| 10 #include "SkFlattenableBuffers.h" | 10 #include "SkFlattenableBuffers.h" |
| 11 #include "SkImageDecoder.h" | 11 #include "SkImageDecoder.h" |
| 12 #include "SkStream.h" | 12 #include "SkStream.h" |
| 13 #include "SkTemplates.h" | 13 #include "SkTemplates.h" |
| 14 #include "SkThread.h" | 14 #include "SkThread.h" |
| 15 | 15 |
| 16 //#define DUMP_IMAGEREF_LIFECYCLE | 16 //#define DUMP_IMAGEREF_LIFECYCLE |
| 17 | 17 |
| 18 | 18 |
| 19 /////////////////////////////////////////////////////////////////////////////// | 19 /////////////////////////////////////////////////////////////////////////////// |
| 20 | 20 |
| 21 SkImageRef::SkImageRef(SkStream* stream, SkBitmap::Config config, | 21 SkImageRef::SkImageRef(SkStreamRewindable* stream, SkBitmap::Config config, |
| 22 int sampleSize, SkBaseMutex* mutex) | 22 int sampleSize, SkBaseMutex* mutex) |
| 23 : SkPixelRef(mutex), fErrorInDecoding(false) { | 23 : SkPixelRef(mutex), fErrorInDecoding(false) { |
| 24 SkASSERT(stream); | 24 SkASSERT(stream); |
| 25 stream->ref(); | 25 stream->ref(); |
| 26 fStream = stream; | 26 fStream = stream; |
| 27 fConfig = config; | 27 fConfig = config; |
| 28 fSampleSize = sampleSize; | 28 fSampleSize = sampleSize; |
| 29 fDoDither = true; | 29 fDoDither = true; |
| 30 fPrev = fNext = NULL; | 30 fPrev = fNext = NULL; |
| 31 fFactory = NULL; | 31 fFactory = NULL; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 } | 72 } |
| 73 | 73 |
| 74 SkImageDecoderFactory* SkImageRef::setDecoderFactory( | 74 SkImageDecoderFactory* SkImageRef::setDecoderFactory( |
| 75 SkImageDecoderFactory* fact) { | 75 SkImageDecoderFactory* fact) { |
| 76 SkRefCnt_SafeAssign(fFactory, fact); | 76 SkRefCnt_SafeAssign(fFactory, fact); |
| 77 return fact; | 77 return fact; |
| 78 } | 78 } |
| 79 | 79 |
| 80 /////////////////////////////////////////////////////////////////////////////// | 80 /////////////////////////////////////////////////////////////////////////////// |
| 81 | 81 |
| 82 bool SkImageRef::onDecode(SkImageDecoder* codec, SkStream* stream, | 82 bool SkImageRef::onDecode(SkImageDecoder* codec, SkStreamRewindable* stream, |
| 83 SkBitmap* bitmap, SkBitmap::Config config, | 83 SkBitmap* bitmap, SkBitmap::Config config, |
| 84 SkImageDecoder::Mode mode) { | 84 SkImageDecoder::Mode mode) { |
| 85 return codec->decode(stream, bitmap, config, mode); | 85 return codec->decode(stream, bitmap, config, mode); |
| 86 } | 86 } |
| 87 | 87 |
| 88 bool SkImageRef::prepareBitmap(SkImageDecoder::Mode mode) { | 88 bool SkImageRef::prepareBitmap(SkImageDecoder::Mode mode) { |
| 89 | 89 |
| 90 if (fErrorInDecoding) { | 90 if (fErrorInDecoding) { |
| 91 return false; | 91 return false; |
| 92 } | 92 } |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 // now. | 192 // now. |
| 193 if (!fStream->rewind()) { | 193 if (!fStream->rewind()) { |
| 194 SkDEBUGF(("Failed to rewind SkImageRef stream!")); | 194 SkDEBUGF(("Failed to rewind SkImageRef stream!")); |
| 195 buffer.write32(0); | 195 buffer.write32(0); |
| 196 } else { | 196 } else { |
| 197 // FIXME: Handle getLength properly here. Perhaps this class should | 197 // FIXME: Handle getLength properly here. Perhaps this class should |
| 198 // take an SkStreamAsset. | 198 // take an SkStreamAsset. |
| 199 buffer.writeStream(fStream, fStream->getLength()); | 199 buffer.writeStream(fStream, fStream->getLength()); |
| 200 } | 200 } |
| 201 } | 201 } |
| OLD | NEW |