VirtualBox

source: vbox/trunk/src/VBox/Main/src-server/GraphicsAdapterImpl.cpp@ 82968

Last change on this file since 82968 was 82968, checked in by vboxsync, 5 years ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 11.5 KB
Line 
1/* $Id: GraphicsAdapterImpl.cpp 82968 2020-02-04 10:35:17Z vboxsync $ */
2/** @file
3 * Implementation of IGraphicsAdapter in VBoxSVC.
4 */
5
6/*
7 * Copyright (C) 2004-2020 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18#define LOG_GROUP LOG_GROUP_MAIN_GRAPHICSADAPTER
19
20#include "LoggingNew.h"
21
22#include "GraphicsAdapterImpl.h"
23#include "MachineImpl.h"
24
25#include "AutoStateDep.h"
26#include "AutoCaller.h"
27
28#include <iprt/cpp/utils.h>
29
30
31// constructor / destructor
32/////////////////////////////////////////////////////////////////////////////
33
34GraphicsAdapter::GraphicsAdapter() :
35 mParent(NULL)
36{}
37
38GraphicsAdapter::~GraphicsAdapter()
39{}
40
41HRESULT GraphicsAdapter::FinalConstruct()
42{
43 LogFlowThisFunc(("\n"));
44 return BaseFinalConstruct();
45}
46
47void GraphicsAdapter::FinalRelease()
48{
49 LogFlowThisFunc(("\n"));
50 uninit();
51 BaseFinalRelease();
52}
53
54// public initializer/uninitializer for internal purposes only
55/////////////////////////////////////////////////////////////////////////////
56
57/**
58 * Initializes the graphics adapter object.
59 *
60 * @param aParent Handle of the parent object.
61 */
62HRESULT GraphicsAdapter::init(Machine *aParent)
63{
64 LogFlowThisFunc(("aParent=%p\n", aParent));
65
66 ComAssertRet(aParent, E_INVALIDARG);
67
68 /* Enclose the state transition NotReady->InInit->Ready */
69 AutoInitSpan autoInitSpan(this);
70 AssertReturn(autoInitSpan.isOk(), E_FAIL);
71
72 unconst(mParent) = aParent;
73 /* mPeer is left null */
74
75 mData.allocate();
76
77 /* Confirm a successful initialization */
78 autoInitSpan.setSucceeded();
79
80 return S_OK;
81}
82
83/**
84 * Initializes the graphics adapter object given another graphics adapter
85 * object (a kind of copy constructor). This object shares data with
86 * the object passed as an argument.
87 *
88 * @note This object must be destroyed before the original object
89 * it shares data with is destroyed.
90 *
91 * @note Locks @a aThat object for reading.
92 */
93HRESULT GraphicsAdapter::init(Machine *aParent, GraphicsAdapter *aThat)
94{
95 LogFlowThisFunc(("aParent=%p, aThat=%p\n", aParent, aThat));
96
97 ComAssertRet(aParent && aThat, E_INVALIDARG);
98
99 /* Enclose the state transition NotReady->InInit->Ready */
100 AutoInitSpan autoInitSpan(this);
101 AssertReturn(autoInitSpan.isOk(), E_FAIL);
102
103 unconst(mParent) = aParent;
104 unconst(mPeer) = aThat;
105
106 AutoCaller thatCaller(aThat);
107 AssertComRCReturnRC(thatCaller.rc());
108
109 AutoReadLock thatLock(aThat COMMA_LOCKVAL_SRC_POS);
110 mData.share(aThat->mData);
111
112 /* Confirm a successful initialization */
113 autoInitSpan.setSucceeded();
114
115 return S_OK;
116}
117
118/**
119 * Initializes the graphics adapter object given another graphics adapter
120 * object (a kind of copy constructor). This object makes a private copy
121 * of data of the original object passed as an argument.
122 *
123 * @note Locks @a aThat object for reading.
124 */
125HRESULT GraphicsAdapter::initCopy(Machine *aParent, GraphicsAdapter *aThat)
126{
127 LogFlowThisFunc(("aParent=%p, aThat=%p\n", aParent, aThat));
128
129 ComAssertRet(aParent && aThat, E_INVALIDARG);
130
131 /* Enclose the state transition NotReady->InInit->Ready */
132 AutoInitSpan autoInitSpan(this);
133 AssertReturn(autoInitSpan.isOk(), E_FAIL);
134
135 unconst(mParent) = aParent;
136 /* mPeer is left null */
137
138 AutoCaller thatCaller(aThat);
139 AssertComRCReturnRC(thatCaller.rc());
140
141 AutoReadLock thatLock(aThat COMMA_LOCKVAL_SRC_POS);
142 mData.attachCopy(aThat->mData);
143
144 /* Confirm a successful initialization */
145 autoInitSpan.setSucceeded();
146
147 return S_OK;
148}
149
150/**
151 * Uninitializes the instance and sets the ready flag to FALSE.
152 * Called either from FinalRelease() or by the parent when it gets destroyed.
153 */
154void GraphicsAdapter::uninit()
155{
156 LogFlowThisFunc(("\n"));
157
158 /* Enclose the state transition Ready->InUninit->NotReady */
159 AutoUninitSpan autoUninitSpan(this);
160 if (autoUninitSpan.uninitDone())
161 return;
162
163 mData.free();
164
165 unconst(mPeer) = NULL;
166 unconst(mParent) = NULL;
167}
168
169// Wrapped IGraphicsAdapter properties
170/////////////////////////////////////////////////////////////////////////////
171
172HRESULT GraphicsAdapter::getGraphicsControllerType(GraphicsControllerType_T *aGraphicsControllerType)
173{
174 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
175
176 *aGraphicsControllerType = mData->graphicsControllerType;
177
178 return S_OK;
179}
180
181HRESULT GraphicsAdapter::setGraphicsControllerType(GraphicsControllerType_T aGraphicsControllerType)
182{
183 switch (aGraphicsControllerType)
184 {
185 case GraphicsControllerType_Null:
186 case GraphicsControllerType_VBoxVGA:
187#ifdef VBOX_WITH_VMSVGA
188 case GraphicsControllerType_VMSVGA:
189 case GraphicsControllerType_VBoxSVGA:
190#endif
191 break;
192 default:
193 return setError(E_INVALIDARG, tr("The graphics controller type (%d) is invalid"), aGraphicsControllerType);
194 }
195
196 /* the machine needs to be mutable */
197 AutoMutableStateDependency adep(mParent);
198 if (FAILED(adep.rc())) return adep.rc();
199
200 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
201
202 mParent->i_setModified(Machine::IsModified_GraphicsAdapter);
203 mData.backup();
204 mData->graphicsControllerType = aGraphicsControllerType;
205
206 return S_OK;
207}
208
209HRESULT GraphicsAdapter::getVRAMSize(ULONG *aVRAMSize)
210{
211 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
212
213 *aVRAMSize = mData->ulVRAMSizeMB;
214
215 return S_OK;
216}
217
218HRESULT GraphicsAdapter::setVRAMSize(ULONG aVRAMSize)
219{
220 /* check VRAM limits */
221 if (aVRAMSize > SchemaDefs::MaxGuestVRAM)
222 return setError(E_INVALIDARG,
223 tr("Invalid VRAM size: %lu MB (must be in range [%lu, %lu] MB)"),
224 aVRAMSize, SchemaDefs::MinGuestVRAM, SchemaDefs::MaxGuestVRAM);
225
226 /* the machine needs to be mutable */
227 AutoMutableStateDependency adep(mParent);
228 if (FAILED(adep.rc())) return adep.rc();
229
230 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
231
232 mParent->i_setModified(Machine::IsModified_GraphicsAdapter);
233 mData.backup();
234 mData->ulVRAMSizeMB = aVRAMSize;
235
236 return S_OK;
237}
238
239HRESULT GraphicsAdapter::getAccelerate3DEnabled(BOOL *aAccelerate3DEnabled)
240{
241 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
242
243 *aAccelerate3DEnabled = mData->fAccelerate3D;
244
245 return S_OK;
246}
247
248HRESULT GraphicsAdapter::setAccelerate3DEnabled(BOOL aAccelerate3DEnabled)
249{
250 /* the machine needs to be mutable */
251 AutoMutableStateDependency adep(mParent);
252 if (FAILED(adep.rc())) return adep.rc();
253
254 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
255
256 /** @todo check validity! */
257
258 mParent->i_setModified(Machine::IsModified_GraphicsAdapter);
259 mData.backup();
260 mData->fAccelerate3D = !!aAccelerate3DEnabled;
261
262 return S_OK;
263}
264
265
266HRESULT GraphicsAdapter::getAccelerate2DVideoEnabled(BOOL *aAccelerate2DVideoEnabled)
267{
268 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
269
270 /** @todo quick workaround for hang with Win10 guest when 2d accel
271 * is enabled when non-VBoxVGA graphics is configured. */
272 if (mData->graphicsControllerType == GraphicsControllerType_VBoxVGA)
273 *aAccelerate2DVideoEnabled = mData->fAccelerate2DVideo;
274 else
275 *aAccelerate2DVideoEnabled = FALSE;
276
277 return S_OK;
278}
279
280HRESULT GraphicsAdapter::setAccelerate2DVideoEnabled(BOOL aAccelerate2DVideoEnabled)
281{
282 /* the machine needs to be mutable */
283 AutoMutableStateDependency adep(mParent);
284 if (FAILED(adep.rc())) return adep.rc();
285
286 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
287
288 /** @todo check validity! */
289
290 mParent->i_setModified(Machine::IsModified_GraphicsAdapter);
291 mData.backup();
292 mData->fAccelerate2DVideo = !!aAccelerate2DVideoEnabled;
293
294 return S_OK;
295}
296
297HRESULT GraphicsAdapter::getMonitorCount(ULONG *aMonitorCount)
298{
299 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
300
301 *aMonitorCount = mData->cMonitors;
302
303 return S_OK;
304}
305
306HRESULT GraphicsAdapter::setMonitorCount(ULONG aMonitorCount)
307{
308 /* make sure monitor count is a sensible number */
309 if (aMonitorCount < 1 || aMonitorCount > SchemaDefs::MaxGuestMonitors)
310 return setError(E_INVALIDARG,
311 tr("Invalid monitor count: %lu (must be in range [%lu, %lu])"),
312 aMonitorCount, 1, SchemaDefs::MaxGuestMonitors);
313
314 /* the machine needs to be mutable */
315 AutoMutableStateDependency adep(mParent);
316 if (FAILED(adep.rc())) return adep.rc();
317
318 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
319
320 mParent->i_setModified(Machine::IsModified_GraphicsAdapter);
321 mData.backup();
322 mData->cMonitors = aMonitorCount;
323
324 return S_OK;
325}
326
327// Wrapped IGraphicsAdapter methods
328/////////////////////////////////////////////////////////////////////////////
329
330// public methods only for internal purposes
331/////////////////////////////////////////////////////////////////////////////
332
333/**
334 * Loads settings from the given machine node.
335 * May be called once right after this object creation.
336 *
337 * @param data Configuration settings.
338 *
339 * @note Locks this object for writing.
340 */
341HRESULT GraphicsAdapter::i_loadSettings(const settings::GraphicsAdapter &data)
342{
343 AutoCaller autoCaller(this);
344 AssertComRCReturnRC(autoCaller.rc());
345
346 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
347
348 mData.assignCopy(&data);
349
350 return S_OK;
351}
352
353/**
354 * Saves settings to the given machine node.
355 *
356 * @param data Configuration settings.
357 *
358 * @note Locks this object for reading.
359 */
360HRESULT GraphicsAdapter::i_saveSettings(settings::GraphicsAdapter &data)
361{
362 AutoCaller autoCaller(this);
363 AssertComRCReturnRC(autoCaller.rc());
364
365 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
366
367 data = *mData.data();
368
369 return S_OK;
370}
371
372/**
373 * @note Locks this object for writing.
374 */
375void GraphicsAdapter::i_rollback()
376{
377 /* sanity */
378 AutoCaller autoCaller(this);
379 AssertComRCReturnVoid(autoCaller.rc());
380
381 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
382
383 mData.rollback();
384}
385
386/**
387 * @note Locks this object for writing, together with the peer object (also
388 * for writing) if there is one.
389 */
390void GraphicsAdapter::i_commit()
391{
392 /* sanity */
393 AutoCaller autoCaller(this);
394 AssertComRCReturnVoid(autoCaller.rc());
395
396 /* sanity too */
397 AutoCaller peerCaller(mPeer);
398 AssertComRCReturnVoid(peerCaller.rc());
399
400 /* lock both for writing since we modify both (mPeer is "master" so locked
401 * first) */
402 AutoMultiWriteLock2 alock(mPeer, this COMMA_LOCKVAL_SRC_POS);
403
404 if (mData.isBackedUp())
405 {
406 mData.commit();
407 if (mPeer)
408 {
409 /* attach new data to the peer and reshare it */
410 mPeer->mData.attach(mData);
411 }
412 }
413}
414
415/**
416 * @note Locks this object for writing, together with the peer object
417 * represented by @a aThat (locked for reading).
418 */
419void GraphicsAdapter::i_copyFrom(GraphicsAdapter *aThat)
420{
421 AssertReturnVoid(aThat != NULL);
422
423 /* sanity */
424 AutoCaller autoCaller(this);
425 AssertComRCReturnVoid(autoCaller.rc());
426
427 /* sanity too */
428 AutoCaller thatCaller(aThat);
429 AssertComRCReturnVoid(thatCaller.rc());
430
431 /* peer is not modified, lock it for reading (aThat is "master" so locked
432 * first) */
433 AutoReadLock rl(aThat COMMA_LOCKVAL_SRC_POS);
434 AutoWriteLock wl(this COMMA_LOCKVAL_SRC_POS);
435
436 /* this will back up current data */
437 mData.assignCopy(aThat->mData);
438}
439/* vi: set tabstop=4 shiftwidth=4 expandtab: */
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette