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