1 | /* $Id: DisplaySourceBitmapImpl.cpp 94921 2022-05-08 19:56:00Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * Bitmap of a guest screen implementation.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2014-2022 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_DISPLAYSOURCEBITMAP
|
---|
19 | #include "LoggingNew.h"
|
---|
20 |
|
---|
21 | #include "DisplayImpl.h"
|
---|
22 |
|
---|
23 | /*
|
---|
24 | * DisplaySourceBitmap implementation.
|
---|
25 | */
|
---|
26 | DEFINE_EMPTY_CTOR_DTOR(DisplaySourceBitmap)
|
---|
27 |
|
---|
28 | HRESULT DisplaySourceBitmap::FinalConstruct()
|
---|
29 | {
|
---|
30 | return BaseFinalConstruct();
|
---|
31 | }
|
---|
32 |
|
---|
33 | void DisplaySourceBitmap::FinalRelease()
|
---|
34 | {
|
---|
35 | uninit();
|
---|
36 |
|
---|
37 | BaseFinalRelease();
|
---|
38 | }
|
---|
39 |
|
---|
40 | HRESULT DisplaySourceBitmap::init(ComObjPtr<Display> pDisplay, unsigned uScreenId, DISPLAYFBINFO *pFBInfo)
|
---|
41 | {
|
---|
42 | LogFlowThisFunc(("[%u]\n", uScreenId));
|
---|
43 |
|
---|
44 | ComAssertRet(!pDisplay.isNull(), E_INVALIDARG);
|
---|
45 |
|
---|
46 | /* Enclose the state transition NotReady->InInit->Ready */
|
---|
47 | AutoInitSpan autoInitSpan(this);
|
---|
48 | AssertReturn(autoInitSpan.isOk(), E_FAIL);
|
---|
49 |
|
---|
50 | m.pDisplay = pDisplay;
|
---|
51 | m.uScreenId = uScreenId;
|
---|
52 | m.pFBInfo = pFBInfo;
|
---|
53 |
|
---|
54 | m.pu8Allocated = NULL;
|
---|
55 |
|
---|
56 | m.pu8Address = NULL;
|
---|
57 | m.ulWidth = 0;
|
---|
58 | m.ulHeight = 0;
|
---|
59 | m.ulBitsPerPixel = 0;
|
---|
60 | m.ulBytesPerLine = 0;
|
---|
61 | m.bitmapFormat = BitmapFormat_Opaque;
|
---|
62 |
|
---|
63 | int vrc = initSourceBitmap(uScreenId, pFBInfo);
|
---|
64 | if (RT_FAILURE(vrc))
|
---|
65 | return E_FAIL;
|
---|
66 |
|
---|
67 | /* Confirm a successful initialization */
|
---|
68 | autoInitSpan.setSucceeded();
|
---|
69 |
|
---|
70 | return S_OK;
|
---|
71 | }
|
---|
72 |
|
---|
73 | void 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 |
|
---|
88 | HRESULT DisplaySourceBitmap::getScreenId(ULONG *aScreenId)
|
---|
89 | {
|
---|
90 | HRESULT hrc = S_OK;
|
---|
91 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
92 |
|
---|
93 | *aScreenId = m.uScreenId;
|
---|
94 | return hrc;
|
---|
95 | }
|
---|
96 |
|
---|
97 | HRESULT DisplaySourceBitmap::queryBitmapInfo(BYTE **aAddress,
|
---|
98 | ULONG *aWidth,
|
---|
99 | ULONG *aHeight,
|
---|
100 | ULONG *aBitsPerPixel,
|
---|
101 | ULONG *aBytesPerLine,
|
---|
102 | BitmapFormat_T *aBitmapFormat)
|
---|
103 | {
|
---|
104 | HRESULT hrc = 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 hrc;
|
---|
115 | }
|
---|
116 |
|
---|
117 | int DisplaySourceBitmap::initSourceBitmap(unsigned aScreenId,
|
---|
118 | DISPLAYFBINFO *pFBInfo)
|
---|
119 | {
|
---|
120 | RT_NOREF(aScreenId);
|
---|
121 | int vrc = VINF_SUCCESS;
|
---|
122 |
|
---|
123 | if (pFBInfo->w == 0 || pFBInfo->h == 0)
|
---|
124 | {
|
---|
125 | return VERR_NOT_SUPPORTED;
|
---|
126 | }
|
---|
127 |
|
---|
128 | BYTE *pAddress = NULL;
|
---|
129 | ULONG ulWidth = 0;
|
---|
130 | ULONG ulHeight = 0;
|
---|
131 | ULONG ulBitsPerPixel = 0;
|
---|
132 | ULONG ulBytesPerLine = 0;
|
---|
133 | BitmapFormat_T bitmapFormat = BitmapFormat_Opaque;
|
---|
134 |
|
---|
135 | if (pFBInfo->pu8FramebufferVRAM && pFBInfo->u16BitsPerPixel == 32 && !pFBInfo->fDisabled)
|
---|
136 | {
|
---|
137 | /* From VRAM. */
|
---|
138 | LogFunc(("%d from VRAM\n", aScreenId));
|
---|
139 | pAddress = pFBInfo->pu8FramebufferVRAM;
|
---|
140 | ulWidth = pFBInfo->w;
|
---|
141 | ulHeight = pFBInfo->h;
|
---|
142 | ulBitsPerPixel = pFBInfo->u16BitsPerPixel;
|
---|
143 | ulBytesPerLine = pFBInfo->u32LineSize;
|
---|
144 | bitmapFormat = BitmapFormat_BGR;
|
---|
145 | m.pu8Allocated = NULL;
|
---|
146 | }
|
---|
147 | else
|
---|
148 | {
|
---|
149 | /* Allocated byffer */
|
---|
150 | LogFunc(("%d allocated\n", aScreenId));
|
---|
151 | pAddress = NULL;
|
---|
152 | ulWidth = pFBInfo->w;
|
---|
153 | ulHeight = pFBInfo->h;
|
---|
154 | ulBitsPerPixel = 32;
|
---|
155 | ulBytesPerLine = ulWidth * 4;
|
---|
156 | bitmapFormat = BitmapFormat_BGR;
|
---|
157 |
|
---|
158 | m.pu8Allocated = (uint8_t *)RTMemAlloc(ulBytesPerLine * ulHeight);
|
---|
159 | if (m.pu8Allocated == NULL)
|
---|
160 | {
|
---|
161 | vrc = VERR_NO_MEMORY;
|
---|
162 | }
|
---|
163 | else
|
---|
164 | {
|
---|
165 | pAddress = m.pu8Allocated;
|
---|
166 | }
|
---|
167 | }
|
---|
168 |
|
---|
169 | if (RT_SUCCESS(vrc))
|
---|
170 | {
|
---|
171 | m.pu8Address = pAddress;
|
---|
172 | m.ulWidth = ulWidth;
|
---|
173 | m.ulHeight = ulHeight;
|
---|
174 | m.ulBitsPerPixel = ulBitsPerPixel;
|
---|
175 | m.ulBytesPerLine = ulBytesPerLine;
|
---|
176 | m.bitmapFormat = bitmapFormat;
|
---|
177 | if (pFBInfo->fDisabled)
|
---|
178 | {
|
---|
179 | RT_BZERO(pAddress, ulBytesPerLine * ulHeight);
|
---|
180 | }
|
---|
181 | }
|
---|
182 |
|
---|
183 | return vrc;
|
---|
184 | }
|
---|
185 |
|
---|
186 | /* vi: set tabstop=4 shiftwidth=4 expandtab: */
|
---|