VirtualBox

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

Last change on this file was 98103, checked in by vboxsync, 16 months ago

Copyright year updates by scm.

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

© 2023 Oracle
ContactPrivacy policyTerms of Use