msarett | fc0b6d1 | 2016-03-17 13:50:17 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 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 "SkTypes.h" |
| 9 | |
| 10 | #if defined(SK_BUILD_FOR_WIN) |
| 11 | |
| 12 | #include "SkData.h" |
| 13 | #include "SkImageGenerator.h" |
| 14 | #include "SkTemplates.h" |
| 15 | #include "SkTScopedComPtr.h" |
| 16 | |
| 17 | #include <wincodec.h> |
| 18 | |
| 19 | /* |
| 20 | * Any Windows program that uses COM must initialize the COM library by calling |
| 21 | * the CoInitializeEx function. In addition, each thread that uses a COM |
| 22 | * interface must make a separate call to this function. |
| 23 | * |
| 24 | * For every successful call to CoInitializeEx, the thread must call |
| 25 | * CoUninitialize before it exits. |
| 26 | * |
| 27 | * SkImageGeneratorWIC requires the COM library and leaves it to the client to |
| 28 | * initialize COM for their application. |
| 29 | * |
| 30 | * For more information on initializing COM, please see: |
| 31 | * https://msdn.microsoft.com/en-us/library/windows/desktop/ff485844.aspx |
| 32 | */ |
| 33 | class SkImageGeneratorWIC : public SkImageGenerator { |
| 34 | public: |
| 35 | /* |
| 36 | * Refs the data if an image generator can be returned. Otherwise does |
| 37 | * not affect the data. |
| 38 | */ |
| 39 | static SkImageGenerator* NewFromEncodedWIC(SkData* data); |
| 40 | |
| 41 | protected: |
Brian Osman | 2feb796 | 2017-04-25 16:41:47 -0400 | [diff] [blame] | 42 | SkData* onRefEncodedData() override; |
msarett | fc0b6d1 | 2016-03-17 13:50:17 -0700 | [diff] [blame] | 43 | |
Matt Sarett | ebb1b5c | 2017-05-12 11:41:27 -0400 | [diff] [blame] | 44 | bool onGetPixels(const SkImageInfo& info, void* pixels, size_t rowBytes, const Options&) |
| 45 | override; |
msarett | fc0b6d1 | 2016-03-17 13:50:17 -0700 | [diff] [blame] | 46 | |
| 47 | private: |
| 48 | /* |
| 49 | * Takes ownership of the imagingFactory |
| 50 | * Takes ownership of the imageSource |
| 51 | * Refs the data |
| 52 | */ |
| 53 | SkImageGeneratorWIC(const SkImageInfo& info, IWICImagingFactory* imagingFactory, |
| 54 | IWICBitmapSource* imageSource, SkData* data); |
| 55 | |
| 56 | SkTScopedComPtr<IWICImagingFactory> fImagingFactory; |
| 57 | SkTScopedComPtr<IWICBitmapSource> fImageSource; |
bungeman | ffae30d | 2016-08-03 13:32:32 -0700 | [diff] [blame] | 58 | sk_sp<SkData> fData; |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 59 | |
msarett | fc0b6d1 | 2016-03-17 13:50:17 -0700 | [diff] [blame] | 60 | typedef SkImageGenerator INHERITED; |
| 61 | }; |
| 62 | |
| 63 | #endif // SK_BUILD_FOR_WIN |