blob: 4770ee2111794e17796b594492f0f202962cd73e [file] [log] [blame]
msarettfc0b6d12016-03-17 13:50:17 -07001/*
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 */
33class SkImageGeneratorWIC : public SkImageGenerator {
34public:
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
41protected:
Brian Osman2feb7962017-04-25 16:41:47 -040042 SkData* onRefEncodedData() override;
msarettfc0b6d12016-03-17 13:50:17 -070043
Matt Sarettebb1b5c2017-05-12 11:41:27 -040044 bool onGetPixels(const SkImageInfo& info, void* pixels, size_t rowBytes, const Options&)
45 override;
msarettfc0b6d12016-03-17 13:50:17 -070046
47private:
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;
bungemanffae30d2016-08-03 13:32:32 -070058 sk_sp<SkData> fData;
halcanary9d524f22016-03-29 09:03:52 -070059
msarettfc0b6d12016-03-17 13:50:17 -070060 typedef SkImageGenerator INHERITED;
61};
62
63#endif // SK_BUILD_FOR_WIN