Skip to content

Commit

Permalink
Fix poor comptr usage and leaks. Return to static initializer model.
Browse files Browse the repository at this point in the history
  • Loading branch information
MSFTFox committed Nov 4, 2016
1 parent 5eab616 commit 5e385a9
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 11 deletions.
4 changes: 2 additions & 2 deletions Frameworks/CoreGraphics/CGContext.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1648,9 +1648,9 @@ void CGContextFillRects(CGContextRef context, const CGRect* rects, size_t count)
void CGContextDrawPath(CGContextRef context, CGPathDrawingMode mode) {
NOISY_RETURN_IF_NULL(context);
if (context->HasPath()) {
ID2D1Geometry* pGeometry;
ComPtr<ID2D1Geometry> pGeometry;
FAIL_FAST_IF_FAILED(_CGPathGetGeometry(context->Path(), &pGeometry));
FAIL_FAST_IF_FAILED(__CGContextDrawGeometry(context, pGeometry, mode));
FAIL_FAST_IF_FAILED(__CGContextDrawGeometry(context, pGeometry.Get(), mode));
context->ClearPath();
}
}
Expand Down
2 changes: 1 addition & 1 deletion Frameworks/CoreGraphics/CGPath.mm
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ HRESULT InitializeGeometries() {
HRESULT _CGPathGetGeometry(CGPathRef path, ID2D1Geometry** pGeometry) {
if (path && pGeometry) {
RETURN_IF_FAILED(path->ClosePath());
*pGeometry = path->GetPathGeometry().Get();
path->GetPathGeometry().CopyTo(pGeometry);
}
return S_OK;
}
Expand Down
14 changes: 6 additions & 8 deletions Frameworks/CoreGraphics/D2DWrapper.mm
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,16 @@

using namespace Microsoft::WRL;

static HRESULT __createD2DFactory(ID2D1Factory** factory) {
return D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED, factory);
}

HRESULT _CGGetD2DFactory(ID2D1Factory** factory) {
static ComPtr<ID2D1Factory> sFactory;
static HRESULT sHr;
static dispatch_once_t dispatchToken;

dispatch_once(&dispatchToken, ^{
sHr = D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED, __uuidof(ID2D1Factory), &sFactory);
});
static HRESULT sHr = __createD2DFactory(&sFactory);

sFactory.Get()->AddRef();
sFactory.CopyTo(factory);
return sHr;
RETURN_HR(sHr);
}

static ComPtr<IWICImagingFactory> __createWICFactory() {
Expand Down

0 comments on commit 5e385a9

Please sign in to comment.