Skip to content

Commit

Permalink
Factory helper should only create single threaded D2D factories.
Browse files Browse the repository at this point in the history
  • Loading branch information
MSFTFox committed Oct 5, 2016
1 parent ffa1e18 commit 5dc6402
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 9 deletions.
12 changes: 3 additions & 9 deletions Frameworks/CoreGraphics/D2DWrapper.mm
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,9 @@

using namespace Microsoft::WRL;

// Private helper for creating a D2DFactory
static ComPtr<ID2D1Factory> __CreateD2DFactoryInstance() {
// Helper for creating a D2DFactory
ComPtr<ID2D1Factory> _CreateD2DFactoryInstance() {
ComPtr<ID2D1Factory> d2dFactory;
THROW_IF_FAILED(D2D1CreateFactory(D2D1_FACTORY_TYPE_MULTI_THREADED, __uuidof(ID2D1Factory), &d2dFactory));
THROW_IF_FAILED(D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED, __uuidof(ID2D1Factory), &d2dFactory));
return d2dFactory;
}

// Helper for accessing a single static multithreaded D2DFactory instance
ComPtr<ID2D1Factory> _GetD2DFactoryInstance() {
static ComPtr<ID2D1Factory> s_d2dFactory = __CreateD2DFactoryInstance();
return s_d2dFactory;
}
24 changes: 24 additions & 0 deletions include/CoreGraphics/D2DWrapper.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//******************************************************************************
//
// Copyright (c) Microsoft. All rights reserved.
//
// This code is licensed under the MIT License (MIT).
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
//******************************************************************************

#pragma once

#include <COMIncludes.h>
#import <wrl/client.h>
#import <D2d1.h>
#include <COMIncludes_End.h>

Microsoft::WRL::ComPtr<ID2D1Factory> _CreateD2DFactoryInstance();

0 comments on commit 5dc6402

Please sign in to comment.