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 */ 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: 42 SkData* onRefEncodedData() override; 43 44 bool onGetPixels(const SkImageInfo& info, void* pixels, size_t rowBytes, const Options&) 45 override; 46 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; 58 sk_sp<SkData> fData; 59 60 typedef SkImageGenerator INHERITED; 61}; 62 63#endif // SK_BUILD_FOR_WIN 64