1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <sal/config.h>
21 #include <sal/log.hxx>
23 #include <vcl/svapp.hxx>
24 #include <vcl/sysdata.hxx>
27 #include <osx/salinst.h>
28 #include <osx/saldata.hxx>
29 #include <osx/salframe.h>
31 #include <ios/iosinst.hxx>
32 #include "headless/svpframe.hxx"
33 #include "headless/svpinst.hxx"
34 #include "headless/svpvd.hxx"
36 #include <quartz/salgdi.h>
37 #include <quartz/salvd.h>
38 #include <quartz/utils.h>
40 std::unique_ptr
<SalVirtualDevice
> AquaSalInstance::CreateVirtualDevice( SalGraphics
& rGraphics
,
41 tools::Long
&nDX
, tools::Long
&nDY
,
43 const SystemGraphicsData
*pData
)
45 // #i92075# can be called first in a thread
46 SalData::ensureThreadAutoreleasePool();
51 return std::unique_ptr
<SalVirtualDevice
>(new AquaSalVirtualDevice( static_cast< AquaSalGraphics
* >(&rGraphics
),
52 nDX
, nDY
, eFormat
, pData
));
56 std::unique_ptr
<SalVirtualDevice
> pNew(new AquaSalVirtualDevice( NULL
, nDX
, nDY
, eFormat
, NULL
));
57 pNew
->SetSize( nDX
, nDY
);
61 return std::unique_ptr
<SalVirtualDevice
>(new AquaSalVirtualDevice( static_cast< AquaSalGraphics
* >(&rGraphics
),
62 nDX
, nDY
, eFormat
, pData
));
66 AquaSalVirtualDevice::AquaSalVirtualDevice(
67 AquaSalGraphics
* pGraphic
, tools::Long
&nDX
, tools::Long
&nDY
,
68 DeviceFormat eFormat
, const SystemGraphicsData
*pData
)
69 : mbGraphicsUsed( false )
74 SAL_INFO( "vcl.virdev", "AquaSalVirtualDevice::AquaSalVirtualDevice() this=" << this
75 << " size=(" << nDX
<< "x" << nDY
<< ") bitcount=" << static_cast<int>(eFormat
) <<
76 " pData=" << pData
<< " context=" << (pData
? pData
->rCGContext
: nullptr) );
78 if( pGraphic
&& pData
&& pData
->rCGContext
)
80 // Create virtual device based on existing SystemGraphicsData
81 // We ignore nDx and nDY, as the desired size comes from the SystemGraphicsData.
82 // the mxContext is from pData (what "mxContext"? there is no such field anywhere in vcl;)
83 mbForeignContext
= true;
84 mpGraphics
= new AquaSalGraphics( /*pGraphic*/ );
93 maLayer
.set(CGLayerCreateWithContext(pData
->rCGContext
, CGSizeMake(nDX
, nDY
), nullptr));
94 // Interrogate the context as to its real size
97 const CGSize aSize
= CGLayerGetSize(maLayer
.get());
98 nDX
= static_cast<tools::Long
>(aSize
.width
);
99 nDY
= static_cast<tools::Long
>(aSize
.height
);
107 mpGraphics
->SetVirDevGraphics(this, maLayer
, pData
->rCGContext
);
109 SAL_INFO("vcl.virdev", "AquaSalVirtualDevice::AquaSalVirtualDevice() this=" << this <<
110 " (" << nDX
<< "x" << nDY
<< ") mbForeignContext=" << (mbForeignContext
? "YES" : "NO"));
115 // create empty new virtual device
116 mbForeignContext
= false; // the mxContext is created within VCL
117 mpGraphics
= new AquaSalGraphics(); // never fails
121 case DeviceFormat::GRAYSCALE
:
130 // inherit resolution from reference device
133 AquaSalFrame
* pFrame
= pGraphic
->getGraphicsFrame();
134 if( pFrame
&& AquaSalFrame::isAlive( pFrame
) )
136 mpGraphics
->setGraphicsFrame( pFrame
);
137 mpGraphics
->copyResolution( *pGraphic
);
145 // NOTE: if SetSize does not succeed, we just ignore the nDX and nDY
149 AquaSalVirtualDevice::~AquaSalVirtualDevice()
151 SAL_INFO( "vcl.virdev", "AquaSalVirtualDevice::~AquaSalVirtualDevice() this=" << this );
155 mpGraphics
->SetVirDevGraphics( this, nullptr, nullptr );
157 mpGraphics
= nullptr;
162 SalGraphics
* AquaSalVirtualDevice::AcquireGraphics()
164 if( mbGraphicsUsed
|| !mpGraphics
)
168 mbGraphicsUsed
= true;
172 void AquaSalVirtualDevice::ReleaseGraphics( SalGraphics
* )
174 mbGraphicsUsed
= false;
177 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */