VirtualBox

source: vbox/trunk/src/VBox/Main/src-client/DisplaySourceBitmapImpl.cpp@ 58449

Last change on this file since 58449 was 55328, checked in by vboxsync, 10 years ago

Main: clear DisplaySourceBitmap if screen is disabled.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.8 KB
Line 
1/* $Id: DisplaySourceBitmapImpl.cpp 55328 2015-04-17 13:10:08Z vboxsync $ */
2/** @file
3 *
4 * Bitmap of a guest screen implementation.
5 */
6
7/*
8 * Copyright (C) 2014 Oracle Corporation
9 *
10 * This file is part of VirtualBox Open Source Edition (OSE), as
11 * available from http://www.virtualbox.org. This file is free software;
12 * you can redistribute it and/or modify it under the terms of the GNU
13 * General Public License (GPL) as published by the Free Software
14 * Foundation, in version 2 as it comes in the "COPYING" file of the
15 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
16 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
17 */
18
19#include "DisplayImpl.h"
20#include "Logging.h"
21
22/*
23 * DisplaySourceBitmap implementation.
24 */
25DEFINE_EMPTY_CTOR_DTOR(DisplaySourceBitmap)
26
27HRESULT DisplaySourceBitmap::FinalConstruct()
28{
29 return BaseFinalConstruct();
30}
31
32void DisplaySourceBitmap::FinalRelease()
33{
34 uninit();
35
36 BaseFinalRelease();
37}
38
39HRESULT DisplaySourceBitmap::init(ComObjPtr<Display> pDisplay, unsigned uScreenId, DISPLAYFBINFO *pFBInfo)
40{
41 LogFlowThisFunc(("[%u]\n", uScreenId));
42
43 ComAssertRet(!pDisplay.isNull(), E_INVALIDARG);
44
45 /* Enclose the state transition NotReady->InInit->Ready */
46 AutoInitSpan autoInitSpan(this);
47 AssertReturn(autoInitSpan.isOk(), E_FAIL);
48
49 m.pDisplay = pDisplay;
50 m.uScreenId = uScreenId;
51 m.pFBInfo = pFBInfo;
52
53 m.pu8Allocated = NULL;
54
55 m.pu8Address = NULL;
56 m.ulWidth = 0;
57 m.ulHeight = 0;
58 m.ulBitsPerPixel = 0;
59 m.ulBytesPerLine = 0;
60 m.bitmapFormat = BitmapFormat_Opaque;
61
62 int rc = initSourceBitmap(uScreenId, pFBInfo);
63
64 if (RT_FAILURE(rc))
65 return E_FAIL;
66
67 /* Confirm a successful initialization */
68 autoInitSpan.setSucceeded();
69
70 return S_OK;
71}
72
73void DisplaySourceBitmap::uninit()
74{
75 /* Enclose the state transition Ready->InUninit->NotReady */
76 AutoUninitSpan autoUninitSpan(this);
77 if (autoUninitSpan.uninitDone())
78 return;
79
80 LogFlowThisFunc(("[%u]\n", m.uScreenId));
81
82 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
83
84 m.pDisplay.setNull();
85 RTMemFree(m.pu8Allocated);
86}
87
88HRESULT DisplaySourceBitmap::getScreenId(ULONG *aScreenId)
89{
90 HRESULT hr = S_OK;
91 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
92
93 *aScreenId = m.uScreenId;
94 return hr;
95}
96
97HRESULT DisplaySourceBitmap::queryBitmapInfo(BYTE **aAddress,
98 ULONG *aWidth,
99 ULONG *aHeight,
100 ULONG *aBitsPerPixel,
101 ULONG *aBytesPerLine,
102 BitmapFormat_T *aBitmapFormat)
103{
104 HRESULT hr = S_OK;
105 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
106
107 *aAddress = m.pu8Address;
108 *aWidth = m.ulWidth;
109 *aHeight = m.ulHeight;
110 *aBitsPerPixel = m.ulBitsPerPixel;
111 *aBytesPerLine = m.ulBytesPerLine;
112 *aBitmapFormat = m.bitmapFormat;
113
114 return hr;
115}
116
117int DisplaySourceBitmap::initSourceBitmap(unsigned aScreenId,
118 DISPLAYFBINFO *pFBInfo)
119{
120 int rc = VINF_SUCCESS;
121
122 if (pFBInfo->w == 0 || pFBInfo->h == 0)
123 {
124 return VERR_NOT_SUPPORTED;
125 }
126
127 BYTE *pAddress = NULL;
128 ULONG ulWidth = 0;
129 ULONG ulHeight = 0;
130 ULONG ulBitsPerPixel = 0;
131 ULONG ulBytesPerLine = 0;
132 BitmapFormat_T bitmapFormat = BitmapFormat_Opaque;
133
134 if (pFBInfo->pu8FramebufferVRAM && pFBInfo->u16BitsPerPixel == 32 && !pFBInfo->fDisabled)
135 {
136 /* From VRAM. */
137 LogFunc(("%d from VRAM\n", aScreenId));
138 pAddress = pFBInfo->pu8FramebufferVRAM;
139 ulWidth = pFBInfo->w;
140 ulHeight = pFBInfo->h;
141 ulBitsPerPixel = pFBInfo->u16BitsPerPixel;
142 ulBytesPerLine = pFBInfo->u32LineSize;
143 bitmapFormat = BitmapFormat_BGR;
144 m.pu8Allocated = NULL;
145 }
146 else
147 {
148 /* Allocated byffer */
149 LogFunc(("%d allocated\n", aScreenId));
150 pAddress = NULL;
151 ulWidth = pFBInfo->w;
152 ulHeight = pFBInfo->h;
153 ulBitsPerPixel = 32;
154 ulBytesPerLine = ulWidth * 4;
155 bitmapFormat = BitmapFormat_BGR;
156
157 m.pu8Allocated = (uint8_t *)RTMemAlloc(ulBytesPerLine * ulHeight);
158 if (m.pu8Allocated == NULL)
159 {
160 rc = VERR_NO_MEMORY;
161 }
162 else
163 {
164 pAddress = m.pu8Allocated;
165 }
166 }
167
168 if (RT_SUCCESS(rc))
169 {
170 m.pu8Address = pAddress;
171 m.ulWidth = ulWidth;
172 m.ulHeight = ulHeight;
173 m.ulBitsPerPixel = ulBitsPerPixel;
174 m.ulBytesPerLine = ulBytesPerLine;
175 m.bitmapFormat = bitmapFormat;
176 if (pFBInfo->fDisabled)
177 {
178 RT_BZERO(pAddress, ulBytesPerLine * ulHeight);
179 }
180 }
181
182 return rc;
183}
184
185/* 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