LibreOffice Module canvas (master) 1
dx_gdiplususer.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20#include <sal/config.h>
21
22#include <osl/mutex.hxx>
23
24#include "dx_gdiplususer.hxx"
25#include "dx_winstuff.hxx"
26
27
28namespace dxcanvas
29{
30 namespace
31 {
32 ::osl::Mutex* p_gdiPlusUsageCountMutex( osl::Mutex::getGlobalMutex() );
33 int n_gdiPlusUsageCount( 0 );
34
35 ULONG_PTR a_GdiPlusToken; // GDI+ handle. Owned by this object
36 }
37
39 {
40 return GDIPlusUserSharedPtr( new GDIPlusUser() );
41 }
42
44 {
45 ::osl::MutexGuard aGuard( *p_gdiPlusUsageCountMutex );
46
47 --n_gdiPlusUsageCount;
48
49 if( n_gdiPlusUsageCount == 0 )
50 Gdiplus::GdiplusShutdown( a_GdiPlusToken );
51 }
52
54 {
55 ::osl::MutexGuard aGuard( *p_gdiPlusUsageCountMutex );
56
57 if( n_gdiPlusUsageCount == 0 )
58 {
59 // Setup GDI+
60
61 // No extras here, simply taking GdiplusStartupInput's
62 // default constructor
63 Gdiplus::GdiplusStartupInput gdiPlusStartupInput;
64
65 Gdiplus::GdiplusStartup( &a_GdiPlusToken,
66 &gdiPlusStartupInput,
67 nullptr );
68 }
69
70 ++n_gdiPlusUsageCount;
71 }
72}
73
74/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static GDIPlusUserSharedPtr createInstance()
std::shared_ptr< GDIPlusUser > GDIPlusUserSharedPtr