OLD | NEW |
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 "SkBitmapRegionCanvas.h" | 8 #include "SkBitmapRegionCanvas.h" |
9 #include "SkBitmapRegionDecoderInterface.h" | 9 #include "SkBitmapRegionDecoderInterface.h" |
10 #include "SkBitmapRegionSampler.h" | 10 #include "SkBitmapRegionSampler.h" |
11 #include "SkCodec.h" | 11 #include "SkCodec.h" |
12 #include "SkImageDecoder.h" | 12 #include "SkImageDecoder.h" |
13 | 13 |
14 SkBitmapRegionDecoderInterface* SkBitmapRegionDecoderInterface::CreateBitmapRegi
onDecoder( | 14 SkBitmapRegionDecoderInterface* SkBitmapRegionDecoderInterface::CreateBitmapRegi
onDecoder( |
15 SkStreamRewindable* stream, Strategy strategy) { | 15 SkStreamRewindable* stream, Strategy strategy) { |
| 16 SkAutoTDelete<SkStreamRewindable> streamDeleter(stream); |
16 switch (strategy) { | 17 switch (strategy) { |
17 case kOriginal_Strategy: { | 18 case kOriginal_Strategy: { |
18 SkImageDecoder* decoder = SkImageDecoder::Factory(stream); | 19 SkImageDecoder* decoder = SkImageDecoder::Factory(stream); |
19 int width, height; | 20 int width, height; |
20 if (nullptr == decoder) { | 21 if (nullptr == decoder) { |
21 SkDebugf("Error: Could not create image decoder.\n"); | 22 SkDebugf("Error: Could not create image decoder.\n"); |
22 return nullptr; | 23 return nullptr; |
23 } | 24 } |
24 if (!decoder->buildTileIndex(stream, &width, &height)) { | 25 if (!decoder->buildTileIndex(streamDeleter.detach(), &width, &height
)) { |
25 SkDebugf("Error: Could not build tile index.\n"); | 26 SkDebugf("Error: Could not build tile index.\n"); |
26 delete decoder; | 27 delete decoder; |
27 return nullptr; | 28 return nullptr; |
28 } | 29 } |
29 return new SkBitmapRegionSampler(decoder, width, height); | 30 return new SkBitmapRegionSampler(decoder, width, height); |
30 } | 31 } |
31 case kCanvas_Strategy: { | 32 case kCanvas_Strategy: { |
32 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(stream)); | 33 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(streamDeleter.de
tach())); |
33 if (nullptr == codec) { | 34 if (nullptr == codec) { |
34 SkDebugf("Error: Failed to create decoder.\n"); | 35 SkDebugf("Error: Failed to create decoder.\n"); |
35 return nullptr; | 36 return nullptr; |
36 } | 37 } |
37 switch (codec->getScanlineOrder()) { | 38 switch (codec->getScanlineOrder()) { |
38 case SkCodec::kTopDown_SkScanlineOrder: | 39 case SkCodec::kTopDown_SkScanlineOrder: |
39 case SkCodec::kNone_SkScanlineOrder: | 40 case SkCodec::kNone_SkScanlineOrder: |
40 break; | 41 break; |
41 default: | 42 default: |
42 SkDebugf("Error: Scanline ordering not supported.\n"); | 43 SkDebugf("Error: Scanline ordering not supported.\n"); |
43 return nullptr; | 44 return nullptr; |
44 } | 45 } |
45 return new SkBitmapRegionCanvas(codec.detach()); | 46 return new SkBitmapRegionCanvas(codec.detach()); |
46 } | 47 } |
47 default: | 48 default: |
48 SkASSERT(false); | 49 SkASSERT(false); |
49 return nullptr; | 50 return nullptr; |
50 } | 51 } |
51 } | 52 } |
OLD | NEW |