OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2008 The Android Open Source Project | 2 * Copyright 2008 The Android Open Source Project |
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 "SkTypes.h" | 8 #include "SkTypes.h" |
9 #if defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS) | 9 #if defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS) |
10 | 10 |
11 #include "SkCGUtils.h" | 11 #include "SkCGUtils.h" |
12 #include "SkColorPriv.h" | 12 #include "SkColorPriv.h" |
| 13 #include "SkData.h" |
13 #include "SkImageDecoder.h" | 14 #include "SkImageDecoder.h" |
14 #include "SkImageEncoder.h" | 15 #include "SkImageEncoder.h" |
15 #include "SkMovie.h" | 16 #include "SkMovie.h" |
16 #include "SkStream.h" | 17 #include "SkStream.h" |
17 #include "SkStreamPriv.h" | 18 #include "SkStreamPriv.h" |
18 #include "SkTemplates.h" | 19 #include "SkTemplates.h" |
19 #include "SkUnPreMultiply.h" | 20 #include "SkUnPreMultiply.h" |
20 | 21 |
21 #ifdef SK_BUILD_FOR_MAC | 22 #ifdef SK_BUILD_FOR_MAC |
22 #include <ApplicationServices/ApplicationServices.h> | 23 #include <ApplicationServices/ApplicationServices.h> |
23 #endif | 24 #endif |
24 | 25 |
25 #ifdef SK_BUILD_FOR_IOS | 26 #ifdef SK_BUILD_FOR_IOS |
26 #include <CoreGraphics/CoreGraphics.h> | 27 #include <CoreGraphics/CoreGraphics.h> |
27 #include <ImageIO/ImageIO.h> | 28 #include <ImageIO/ImageIO.h> |
28 #include <MobileCoreServices/MobileCoreServices.h> | 29 #include <MobileCoreServices/MobileCoreServices.h> |
29 #endif | 30 #endif |
30 | 31 |
31 static void malloc_release_proc(void* info, const void* data, size_t size) { | 32 static void data_unref_proc(void* skdata, const void*, size_t) { |
32 sk_free(info); | 33 SkASSERT(skdata); |
| 34 static_cast<SkData*>(skdata)->unref(); |
33 } | 35 } |
34 | 36 |
35 static CGDataProviderRef SkStreamToDataProvider(SkStream* stream) { | 37 static CGDataProviderRef SkStreamToDataProvider(SkStream* stream) { |
36 // TODO: use callbacks, so we don't have to load all the data into RAM | 38 // TODO: use callbacks, so we don't have to load all the data into RAM |
37 SkAutoMalloc storage; | 39 SkData* skdata = SkCopyStreamToData(stream); |
38 const size_t len = SkCopyStreamToStorage(&storage, stream); | 40 if (!skdata) { |
39 void* data = storage.detach(); | 41 return nullptr; |
| 42 } |
40 | 43 |
41 return CGDataProviderCreateWithData(data, data, len, malloc_release_proc); | 44 return CGDataProviderCreateWithData(skdata, skdata->data(), skdata->size(),
data_unref_proc); |
42 } | 45 } |
43 | 46 |
44 static CGImageSourceRef SkStreamToCGImageSource(SkStream* stream) { | 47 static CGImageSourceRef SkStreamToCGImageSource(SkStream* stream) { |
45 CGDataProviderRef data = SkStreamToDataProvider(stream); | 48 CGDataProviderRef data = SkStreamToDataProvider(stream); |
46 if (!data) { | 49 if (!data) { |
47 return nullptr; | 50 return nullptr; |
48 } | 51 } |
49 CGImageSourceRef imageSrc = CGImageSourceCreateWithDataProvider(data, 0); | 52 CGImageSourceRef imageSrc = CGImageSourceCreateWithDataProvider(data, 0); |
50 CGDataProviderRelease(data); | 53 CGDataProviderRelease(data); |
51 return imageSrc; | 54 return imageSrc; |
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
399 const CFStringRef name = CGImageSourceGetType(imageSrc); | 402 const CFStringRef name = CGImageSourceGetType(imageSrc); |
400 if (nullptr == name) { | 403 if (nullptr == name) { |
401 return SkImageDecoder::kUnknown_Format; | 404 return SkImageDecoder::kUnknown_Format; |
402 } | 405 } |
403 return UTType_to_Format(name); | 406 return UTType_to_Format(name); |
404 } | 407 } |
405 | 408 |
406 static SkImageDecoder_FormatReg gFormatReg(get_format_cg); | 409 static SkImageDecoder_FormatReg gFormatReg(get_format_cg); |
407 | 410 |
408 #endif//defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS) | 411 #endif//defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS) |
OLD | NEW |