Update git submodules
[LibreOffice.git] / vcl / quartz / salvd.cxx
blob4e0c295a17f47afcb93d6590888043c707cdd80a
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
2 /*
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>
26 #ifdef MACOSX
27 #include <osx/salinst.h>
28 #include <osx/saldata.hxx>
29 #include <osx/salframe.h>
30 #else
31 #include <ios/iosinst.hxx>
32 #include "headless/svpframe.hxx"
33 #include "headless/svpinst.hxx"
34 #include "headless/svpvd.hxx"
35 #endif
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,
42 DeviceFormat eFormat,
43 const SystemGraphicsData *pData )
45 // #i92075# can be called first in a thread
46 SalData::ensureThreadAutoreleasePool();
48 #ifdef IOS
49 if( pData )
51 return std::unique_ptr<SalVirtualDevice>(new AquaSalVirtualDevice( static_cast< AquaSalGraphics* >(&rGraphics),
52 nDX, nDY, eFormat, pData ));
54 else
56 std::unique_ptr<SalVirtualDevice> pNew(new AquaSalVirtualDevice( NULL, nDX, nDY, eFormat, NULL ));
57 pNew->SetSize( nDX, nDY );
58 return pNew;
60 #else
61 return std::unique_ptr<SalVirtualDevice>(new AquaSalVirtualDevice( static_cast< AquaSalGraphics* >(&rGraphics),
62 nDX, nDY, eFormat, pData ));
63 #endif
66 AquaSalVirtualDevice::AquaSalVirtualDevice(
67 AquaSalGraphics* pGraphic, tools::Long &nDX, tools::Long &nDY,
68 DeviceFormat eFormat, const SystemGraphicsData *pData )
69 : mbGraphicsUsed( false )
70 , mnBitmapDepth( 0 )
71 , mnWidth(0)
72 , mnHeight(0)
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*/ );
85 if (nDX == 0)
87 nDX = 1;
89 if (nDY == 0)
91 nDY = 1;
93 maLayer.set(CGLayerCreateWithContext(pData->rCGContext, CGSizeMake(nDX, nDY), nullptr));
94 // Interrogate the context as to its real size
95 if (maLayer.isSet())
97 const CGSize aSize = CGLayerGetSize(maLayer.get());
98 nDX = static_cast<tools::Long>(aSize.width);
99 nDY = static_cast<tools::Long>(aSize.height);
101 else
103 nDX = 0;
104 nDY = 0;
107 mpGraphics->SetVirDevGraphics(this, maLayer, pData->rCGContext);
109 SAL_INFO("vcl.virdev", "AquaSalVirtualDevice::AquaSalVirtualDevice() this=" << this <<
110 " (" << nDX << "x" << nDY << ") mbForeignContext=" << (mbForeignContext ? "YES" : "NO"));
113 else
115 // create empty new virtual device
116 mbForeignContext = false; // the mxContext is created within VCL
117 mpGraphics = new AquaSalGraphics(); // never fails
118 switch (eFormat)
120 #ifdef IOS
121 case DeviceFormat::GRAYSCALE:
122 mnBitmapDepth = 8;
123 break;
124 #endif
125 default:
126 mnBitmapDepth = 0;
127 break;
129 #ifdef MACOSX
130 // inherit resolution from reference device
131 if( pGraphic )
133 AquaSalFrame* pFrame = pGraphic->getGraphicsFrame();
134 if( pFrame && AquaSalFrame::isAlive( pFrame ) )
136 mpGraphics->setGraphicsFrame( pFrame );
137 mpGraphics->copyResolution( *pGraphic );
140 #endif
141 if( nDX && nDY )
143 SetSize( nDX, nDY );
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 );
153 if( mpGraphics )
155 mpGraphics->SetVirDevGraphics( this, nullptr, nullptr );
156 delete mpGraphics;
157 mpGraphics = nullptr;
159 Destroy();
162 SalGraphics* AquaSalVirtualDevice::AcquireGraphics()
164 if( mbGraphicsUsed || !mpGraphics )
166 return nullptr;
168 mbGraphicsUsed = true;
169 return mpGraphics;
172 void AquaSalVirtualDevice::ReleaseGraphics( SalGraphics* )
174 mbGraphicsUsed = false;
177 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */