Update SkCoInitialize to better match spec.

http://codereview.appspot.com/5036044/


git-svn-id: http://skia.googlecode.com/svn/trunk@2274 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
bungeman@google.com 2011-09-16 15:37:20 +00:00
parent e5a438b8d7
commit 2e2f3f58b5
3 changed files with 21 additions and 11 deletions

View File

@ -18,13 +18,13 @@
* An instance of this class initializes COM on creation
* and closes the COM library on destruction.
*/
class AutoCoInitialize : SkNoncopyable {
class SkAutoCoInitialize : SkNoncopyable {
private:
HRESULT fHR;
public:
AutoCoInitialize();
~AutoCoInitialize();
HRESULT getHR();
SkAutoCoInitialize();
~SkAutoCoInitialize();
bool succeeded();
};
#endif

View File

@ -25,8 +25,12 @@ protected:
bool SkImageDecoder_WIC::onDecode(SkStream* stream, SkBitmap* bm, Mode mode) {
//Initialize COM.
AutoCoInitialize scopedCo;
HRESULT hr = scopedCo.getHR();
SkAutoCoInitialize scopedCo;
if (!scopedCo.succeeded()) {
return false;
}
HRESULT hr = S_OK;
//Create Windows Imaging Component ImagingFactory.
SkTScopedComPtr<IWICImagingFactory> piImagingFactory;
@ -189,8 +193,12 @@ bool SkImageEncoder_WIC::onEncode(SkWStream* stream
}
//Initialize COM.
AutoCoInitialize scopedCo;
HRESULT hr = scopedCo.getHR();
SkAutoCoInitialize scopedCo;
if (!scopedCo.succeeded()) {
return false;
}
HRESULT hr = S_OK;
//Create Windows Imaging Component ImagingFactory.
SkTScopedComPtr<IWICImagingFactory> piImagingFactory;

View File

@ -12,16 +12,18 @@
#include <ole2.h>
#include "SkAutoCoInitialize.h"
AutoCoInitialize::AutoCoInitialize() :
SkAutoCoInitialize::SkAutoCoInitialize() :
fHR(
CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE)
)
{ }
AutoCoInitialize::~AutoCoInitialize() {
SkAutoCoInitialize::~SkAutoCoInitialize() {
if (SUCCEEDED(this->fHR)) {
CoUninitialize();
}
}
HRESULT AutoCoInitialize::getHR() { return this->fHR; }
bool SkAutoCoInitialize::succeeded() {
return SUCCEEDED(this->fHR) || RPC_E_CHANGED_MODE == this->fHR;
}