[26719] | 1 | /* $Id: VBoxFBOverlay.cpp 81210 2019-10-10 11:21:37Z vboxsync $ */
|
---|
[22816] | 2 | /** @file
|
---|
[52722] | 3 | * VBox Qt GUI - VBoxFBOverlay implementation.
|
---|
[22816] | 4 | */
|
---|
| 5 |
|
---|
| 6 | /*
|
---|
[76553] | 7 | * Copyright (C) 2009-2019 Oracle Corporation
|
---|
[22816] | 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 |
|
---|
[71651] | 18 | #if defined(VBOX_GUI_USE_QGL) /* entire file */
|
---|
| 19 |
|
---|
[71666] | 20 |
|
---|
[71651] | 21 | /*********************************************************************************************************************************
|
---|
| 22 | * Header Files *
|
---|
| 23 | *********************************************************************************************************************************/
|
---|
[76606] | 24 | #define LOG_GROUP LOG_GROUP_GUI
|
---|
[41587] | 25 |
|
---|
| 26 | /* Qt includes: */
|
---|
[76606] | 27 | #ifdef RT_OS_WINDOWS
|
---|
| 28 | # include <iprt/win/windows.h> /* QGLWidget drags in Windows.h; -Wall forces us to use wrapper. */
|
---|
| 29 | # include <iprt/stdint.h> /* QGLWidget drags in stdint.h; -Wall forces us to use wrapper. */
|
---|
| 30 | #endif
|
---|
| 31 | #include <QApplication>
|
---|
| 32 | #include <QGLWidget>
|
---|
| 33 | #include <QFile>
|
---|
| 34 | #include <QTextStream>
|
---|
[41587] | 35 |
|
---|
| 36 | /* GUI includes: */
|
---|
[76606] | 37 | #include "VBoxFBOverlay.h"
|
---|
| 38 | #include "UIDesktopWidgetWatchdog.h"
|
---|
| 39 | #include "UIExtraDataManager.h"
|
---|
| 40 | #include "UIMessageCenter.h"
|
---|
| 41 | #include "UIModalWindowManager.h"
|
---|
| 42 | #include "UIPopupCenter.h"
|
---|
[79365] | 43 | #include "UICommon.h"
|
---|
[22816] | 44 |
|
---|
[41587] | 45 | /* COM includes: */
|
---|
[76606] | 46 | #include "CSession.h"
|
---|
| 47 | #include "CConsole.h"
|
---|
| 48 | #include "CMachine.h"
|
---|
| 49 | #include "CDisplay.h"
|
---|
[23732] | 50 |
|
---|
[41587] | 51 | /* Other VBox includes: */
|
---|
[76606] | 52 | #include <iprt/asm.h>
|
---|
| 53 | #include <iprt/semaphore.h>
|
---|
| 54 | #include <VBox/AssertGuest.h>
|
---|
[49420] | 55 |
|
---|
[76606] | 56 | #include <VBox/VBoxGL2D.h>
|
---|
[22816] | 57 |
|
---|
[60362] | 58 | #ifdef VBOX_WS_MAC
|
---|
[76606] | 59 | #include "VBoxUtils-darwin.h"
|
---|
| 60 | #endif
|
---|
[53823] | 61 |
|
---|
[53964] | 62 | /* Other VBox includes: */
|
---|
[52733] | 63 | #include <iprt/memcache.h>
|
---|
| 64 | #include <VBox/err.h>
|
---|
[52722] | 65 |
|
---|
[52733] | 66 | #ifdef VBOX_WITH_VIDEOHWACCEL
|
---|
[65381] | 67 | # include <VBoxVideo.h>
|
---|
[52733] | 68 | # include <VBox/vmm/ssm.h>
|
---|
[76606] | 69 | #endif
|
---|
[52733] | 70 |
|
---|
[53964] | 71 | /* Other includes: */
|
---|
| 72 | #include <math.h>
|
---|
| 73 |
|
---|
| 74 |
|
---|
[71651] | 75 | /*********************************************************************************************************************************
|
---|
| 76 | * Defined Constants And Macros *
|
---|
| 77 | *********************************************************************************************************************************/
|
---|
[22816] | 78 | #ifdef VBOXQGL_PROF_BASE
|
---|
| 79 | # ifdef VBOXQGL_DBG_SURF
|
---|
| 80 | # define VBOXQGL_PROF_WIDTH 1400
|
---|
| 81 | # define VBOXQGL_PROF_HEIGHT 1050
|
---|
| 82 | # else
|
---|
| 83 | # define VBOXQGL_PROF_WIDTH 1400
|
---|
| 84 | # define VBOXQGL_PROF_HEIGHT 1050
|
---|
| 85 | //#define VBOXQGL_PROF_WIDTH 720
|
---|
| 86 | //#define VBOXQGL_PROF_HEIGHT 480
|
---|
| 87 | # endif
|
---|
| 88 | #endif
|
---|
| 89 |
|
---|
| 90 | #define VBOXQGL_STATE_NAMEBASE "QGLVHWAData"
|
---|
[49420] | 91 | #define VBOXQGL_STATE_VERSION_PIPESAVED 3
|
---|
| 92 | #define VBOXQGL_STATE_VERSION 3
|
---|
[22816] | 93 |
|
---|
| 94 | //#define VBOXQGLOVERLAY_STATE_NAMEBASE "QGLOverlayVHWAData"
|
---|
| 95 | //#define VBOXQGLOVERLAY_STATE_VERSION 1
|
---|
| 96 |
|
---|
| 97 | #ifdef DEBUG_misha
|
---|
[27006] | 98 | //# define VBOXQGL_STATE_DEBUG
|
---|
[22816] | 99 | #endif
|
---|
| 100 |
|
---|
| 101 | #ifdef VBOXQGL_STATE_DEBUG
|
---|
| 102 | #define VBOXQGL_STATE_START_MAGIC 0x12345678
|
---|
| 103 | #define VBOXQGL_STATE_STOP_MAGIC 0x87654321
|
---|
| 104 |
|
---|
| 105 | #define VBOXQGL_STATE_SURFSTART_MAGIC 0x9abcdef1
|
---|
| 106 | #define VBOXQGL_STATE_SURFSTOP_MAGIC 0x1fedcba9
|
---|
| 107 |
|
---|
| 108 | #define VBOXQGL_STATE_OVERLAYSTART_MAGIC 0x13579bdf
|
---|
| 109 | #define VBOXQGL_STATE_OVERLAYSTOP_MAGIC 0xfdb97531
|
---|
| 110 |
|
---|
| 111 | #define VBOXQGL_SAVE_START(_pSSM) do{ int rc = SSMR3PutU32(_pSSM, VBOXQGL_STATE_START_MAGIC); AssertRC(rc);}while(0)
|
---|
| 112 | #define VBOXQGL_SAVE_STOP(_pSSM) do{ int rc = SSMR3PutU32(_pSSM, VBOXQGL_STATE_STOP_MAGIC); AssertRC(rc);}while(0)
|
---|
| 113 |
|
---|
| 114 | #define VBOXQGL_SAVE_SURFSTART(_pSSM) do{ int rc = SSMR3PutU32(_pSSM, VBOXQGL_STATE_SURFSTART_MAGIC); AssertRC(rc);}while(0)
|
---|
| 115 | #define VBOXQGL_SAVE_SURFSTOP(_pSSM) do{ int rc = SSMR3PutU32(_pSSM, VBOXQGL_STATE_SURFSTOP_MAGIC); AssertRC(rc);}while(0)
|
---|
| 116 |
|
---|
| 117 | #define VBOXQGL_SAVE_OVERLAYSTART(_pSSM) do{ int rc = SSMR3PutU32(_pSSM, VBOXQGL_STATE_OVERLAYSTART_MAGIC); AssertRC(rc);}while(0)
|
---|
| 118 | #define VBOXQGL_SAVE_OVERLAYSTOP(_pSSM) do{ int rc = SSMR3PutU32(_pSSM, VBOXQGL_STATE_OVERLAYSTOP_MAGIC); AssertRC(rc);}while(0)
|
---|
| 119 |
|
---|
| 120 | #define VBOXQGL_LOAD_CHECK(_pSSM, _v) \
|
---|
| 121 | do{ \
|
---|
| 122 | uint32_t _u32; \
|
---|
[71651] | 123 | int rcCheck = SSMR3GetU32(_pSSM, &_u32); AssertRC(rcCheck); \
|
---|
| 124 | if (_u32 != (_v)) \
|
---|
[22816] | 125 | { \
|
---|
| 126 | VBOXQGLLOG(("load error: expected magic (0x%x), but was (0x%x)\n", (_v), _u32));\
|
---|
| 127 | }\
|
---|
| 128 | Assert(_u32 == (_v)); \
|
---|
| 129 | }while(0)
|
---|
| 130 |
|
---|
| 131 | #define VBOXQGL_LOAD_START(_pSSM) VBOXQGL_LOAD_CHECK(_pSSM, VBOXQGL_STATE_START_MAGIC)
|
---|
| 132 | #define VBOXQGL_LOAD_STOP(_pSSM) VBOXQGL_LOAD_CHECK(_pSSM, VBOXQGL_STATE_STOP_MAGIC)
|
---|
| 133 |
|
---|
| 134 | #define VBOXQGL_LOAD_SURFSTART(_pSSM) VBOXQGL_LOAD_CHECK(_pSSM, VBOXQGL_STATE_SURFSTART_MAGIC)
|
---|
| 135 | #define VBOXQGL_LOAD_SURFSTOP(_pSSM) VBOXQGL_LOAD_CHECK(_pSSM, VBOXQGL_STATE_SURFSTOP_MAGIC)
|
---|
| 136 |
|
---|
| 137 | #define VBOXQGL_LOAD_OVERLAYSTART(_pSSM) VBOXQGL_LOAD_CHECK(_pSSM, VBOXQGL_STATE_OVERLAYSTART_MAGIC)
|
---|
| 138 | #define VBOXQGL_LOAD_OVERLAYSTOP(_pSSM) VBOXQGL_LOAD_CHECK(_pSSM, VBOXQGL_STATE_OVERLAYSTOP_MAGIC)
|
---|
| 139 |
|
---|
| 140 | #else
|
---|
| 141 |
|
---|
| 142 | #define VBOXQGL_SAVE_START(_pSSM) do{}while(0)
|
---|
| 143 | #define VBOXQGL_SAVE_STOP(_pSSM) do{}while(0)
|
---|
| 144 |
|
---|
| 145 | #define VBOXQGL_SAVE_SURFSTART(_pSSM) do{}while(0)
|
---|
| 146 | #define VBOXQGL_SAVE_SURFSTOP(_pSSM) do{}while(0)
|
---|
| 147 |
|
---|
| 148 | #define VBOXQGL_SAVE_OVERLAYSTART(_pSSM) do{}while(0)
|
---|
| 149 | #define VBOXQGL_SAVE_OVERLAYSTOP(_pSSM) do{}while(0)
|
---|
| 150 |
|
---|
| 151 | #define VBOXQGL_LOAD_START(_pSSM) do{}while(0)
|
---|
| 152 | #define VBOXQGL_LOAD_STOP(_pSSM) do{}while(0)
|
---|
| 153 |
|
---|
| 154 | #define VBOXQGL_LOAD_SURFSTART(_pSSM) do{}while(0)
|
---|
| 155 | #define VBOXQGL_LOAD_SURFSTOP(_pSSM) do{}while(0)
|
---|
| 156 |
|
---|
| 157 | #define VBOXQGL_LOAD_OVERLAYSTART(_pSSM) do{}while(0)
|
---|
| 158 | #define VBOXQGL_LOAD_OVERLAYSTOP(_pSSM) do{}while(0)
|
---|
| 159 |
|
---|
| 160 | #endif
|
---|
| 161 |
|
---|
[71666] | 162 |
|
---|
[71651] | 163 | /*********************************************************************************************************************************
|
---|
| 164 | * Global Variables *
|
---|
| 165 | *********************************************************************************************************************************/
|
---|
[23732] | 166 | static VBoxVHWAInfo g_VBoxVHWASupportInfo;
|
---|
[22816] | 167 |
|
---|
[71651] | 168 |
|
---|
| 169 | #ifdef DEBUG
|
---|
| 170 |
|
---|
| 171 | VBoxVHWADbgTimer::VBoxVHWADbgTimer(uint32_t cPeriods)
|
---|
| 172 | : mPeriodSum(0)
|
---|
| 173 | , mPrevTime(0)
|
---|
| 174 | , mcFrames(0)
|
---|
| 175 | , mcPeriods(cPeriods)
|
---|
| 176 | , miPeriod(0)
|
---|
| 177 | {
|
---|
| 178 | mpaPeriods = new uint64_t[cPeriods];
|
---|
| 179 | memset(mpaPeriods, 0, cPeriods * sizeof(mpaPeriods[0]));
|
---|
| 180 | }
|
---|
| 181 |
|
---|
| 182 | VBoxVHWADbgTimer::~VBoxVHWADbgTimer()
|
---|
| 183 | {
|
---|
| 184 | delete[] mpaPeriods;
|
---|
| 185 | }
|
---|
| 186 |
|
---|
| 187 | void VBoxVHWADbgTimer::frame()
|
---|
| 188 | {
|
---|
| 189 | uint64_t cur = VBOXGETTIME();
|
---|
| 190 | if (mPrevTime)
|
---|
| 191 | {
|
---|
| 192 | uint64_t curPeriod = cur - mPrevTime;
|
---|
| 193 | mPeriodSum += curPeriod - mpaPeriods[miPeriod];
|
---|
| 194 | mpaPeriods[miPeriod] = curPeriod;
|
---|
| 195 | ++miPeriod;
|
---|
| 196 | miPeriod %= mcPeriods;
|
---|
| 197 | }
|
---|
| 198 | mPrevTime = cur;
|
---|
| 199 | ++mcFrames;
|
---|
| 200 | }
|
---|
| 201 |
|
---|
| 202 | #endif /* DEBUG */
|
---|
| 203 |
|
---|
| 204 |
|
---|
[49420] | 205 | class VBoxVHWAEntriesCache
|
---|
| 206 | {
|
---|
| 207 | public:
|
---|
| 208 | VBoxVHWAEntriesCache()
|
---|
| 209 | {
|
---|
| 210 | int rc = RTMemCacheCreate(&mVBoxCmdEntryCache, sizeof (VBoxVHWACommandElement),
|
---|
| 211 | 0, /* size_t cbAlignment */
|
---|
| 212 | UINT32_MAX, /* uint32_t cMaxObjects */
|
---|
| 213 | NULL, /* PFNMEMCACHECTOR pfnCtor*/
|
---|
| 214 | NULL, /* PFNMEMCACHEDTOR pfnDtor*/
|
---|
| 215 | NULL, /* void *pvUser*/
|
---|
| 216 | 0 /* uint32_t fFlags*/
|
---|
| 217 | );
|
---|
| 218 | AssertRC(rc);
|
---|
| 219 | }
|
---|
| 220 |
|
---|
| 221 | ~VBoxVHWAEntriesCache()
|
---|
| 222 | {
|
---|
| 223 | RTMemCacheDestroy(mVBoxCmdEntryCache);
|
---|
| 224 | }
|
---|
| 225 |
|
---|
| 226 | VBoxVHWACommandElement * alloc()
|
---|
| 227 | {
|
---|
| 228 | return (VBoxVHWACommandElement*)RTMemCacheAlloc(mVBoxCmdEntryCache);
|
---|
| 229 | }
|
---|
| 230 |
|
---|
| 231 | void free(VBoxVHWACommandElement * pEl)
|
---|
| 232 | {
|
---|
| 233 | RTMemCacheFree(mVBoxCmdEntryCache, pEl);
|
---|
| 234 | }
|
---|
| 235 |
|
---|
| 236 | private:
|
---|
| 237 | RTMEMCACHE mVBoxCmdEntryCache;
|
---|
| 238 | };
|
---|
| 239 |
|
---|
[34490] | 240 | static struct VBOXVHWACMD * vhwaHHCmdCreate(VBOXVHWACMD_TYPE type, size_t size)
|
---|
[24925] | 241 | {
|
---|
[71651] | 242 | char *buf = (char *)malloc(VBOXVHWACMD_SIZE_FROMBODYSIZE(size));
|
---|
[24925] | 243 | memset(buf, 0, size);
|
---|
[71626] | 244 | VBOXVHWACMD *pCmd = (VBOXVHWACMD *)buf;
|
---|
[24925] | 245 | pCmd->enmCmd = type;
|
---|
| 246 | pCmd->Flags = VBOXVHWACMD_FLAG_HH_CMD;
|
---|
| 247 | return pCmd;
|
---|
| 248 | }
|
---|
| 249 |
|
---|
[23732] | 250 | static const VBoxVHWAInfo & vboxVHWAGetSupportInfo(const QGLContext *pContext)
|
---|
[22816] | 251 | {
|
---|
[71651] | 252 | if (!g_VBoxVHWASupportInfo.isInitialized())
|
---|
[22816] | 253 | {
|
---|
[71651] | 254 | if (pContext)
|
---|
[22816] | 255 | {
|
---|
[23732] | 256 | g_VBoxVHWASupportInfo.init(pContext);
|
---|
[22816] | 257 | }
|
---|
| 258 | else
|
---|
| 259 | {
|
---|
[23732] | 260 | VBoxGLTmpContext ctx;
|
---|
| 261 | const QGLContext *pContext = ctx.makeCurrent();
|
---|
| 262 | Assert(pContext);
|
---|
[71651] | 263 | if (pContext)
|
---|
[22816] | 264 | {
|
---|
[23732] | 265 | g_VBoxVHWASupportInfo.init(pContext);
|
---|
[22816] | 266 | }
|
---|
| 267 | }
|
---|
| 268 | }
|
---|
[23732] | 269 | return g_VBoxVHWASupportInfo;
|
---|
[22816] | 270 | }
|
---|
| 271 |
|
---|
| 272 | class VBoxVHWACommandProcessEvent : public QEvent
|
---|
| 273 | {
|
---|
| 274 | public:
|
---|
[27720] | 275 | VBoxVHWACommandProcessEvent ()
|
---|
[49420] | 276 | : QEvent ((QEvent::Type) VHWACommandProcessType),
|
---|
| 277 | fProcessed(false)
|
---|
[27777] | 278 | {
|
---|
| 279 | #ifdef DEBUG_misha
|
---|
| 280 | g_EventCounter.inc();
|
---|
| 281 | #endif
|
---|
| 282 | }
|
---|
[49420] | 283 |
|
---|
| 284 | void setProcessed()
|
---|
| 285 | {
|
---|
| 286 | fProcessed = true;
|
---|
| 287 | }
|
---|
| 288 |
|
---|
[27777] | 289 | ~VBoxVHWACommandProcessEvent()
|
---|
| 290 | {
|
---|
[49420] | 291 | if (!fProcessed)
|
---|
| 292 | {
|
---|
| 293 | AssertMsgFailed(("VHWA command beinf destroyed unproceessed!"));
|
---|
[56126] | 294 | LogRel(("GUI: VHWA command being destroyed unproceessed!"));
|
---|
[49420] | 295 | }
|
---|
| 296 | #ifdef DEBUG_misha
|
---|
[27777] | 297 | g_EventCounter.dec();
|
---|
[49420] | 298 | #endif
|
---|
[27777] | 299 | }
|
---|
[49420] | 300 | #ifdef DEBUG_misha
|
---|
| 301 | static uint32_t cPending() { return g_EventCounter.refs(); }
|
---|
| 302 | #endif
|
---|
[27777] | 303 |
|
---|
| 304 | private:
|
---|
[49420] | 305 | bool fProcessed;
|
---|
| 306 | #ifdef DEBUG_misha
|
---|
[27777] | 307 | static VBoxVHWARefCounter g_EventCounter;
|
---|
| 308 | #endif
|
---|
[22816] | 309 | };
|
---|
| 310 |
|
---|
[27777] | 311 | #ifdef DEBUG_misha
|
---|
| 312 | VBoxVHWARefCounter VBoxVHWACommandProcessEvent::g_EventCounter;
|
---|
| 313 | #endif
|
---|
[22816] | 314 |
|
---|
| 315 | VBoxVHWAHandleTable::VBoxVHWAHandleTable(uint32_t initialSize)
|
---|
| 316 | {
|
---|
| 317 | mTable = new void*[initialSize];
|
---|
| 318 | memset(mTable, 0, initialSize*sizeof(void*));
|
---|
| 319 | mcSize = initialSize;
|
---|
| 320 | mcUsage = 0;
|
---|
| 321 | mCursor = 1; /* 0 is treated as invalid */
|
---|
| 322 | }
|
---|
| 323 |
|
---|
| 324 | VBoxVHWAHandleTable::~VBoxVHWAHandleTable()
|
---|
| 325 | {
|
---|
| 326 | delete[] mTable;
|
---|
| 327 | }
|
---|
| 328 |
|
---|
[71651] | 329 | uint32_t VBoxVHWAHandleTable::put(void *data)
|
---|
[22816] | 330 | {
|
---|
| 331 | Assert(data);
|
---|
[71651] | 332 | if (!data)
|
---|
[22816] | 333 | return VBOXVHWA_SURFHANDLE_INVALID;
|
---|
| 334 |
|
---|
[71651] | 335 | if (mcUsage == mcSize)
|
---|
[22816] | 336 | {
|
---|
[63567] | 337 | /** @todo resize */
|
---|
[49940] | 338 | AssertFailed();
|
---|
[22816] | 339 | }
|
---|
| 340 |
|
---|
| 341 | Assert(mcUsage < mcSize);
|
---|
[71651] | 342 | if (mcUsage >= mcSize)
|
---|
[22816] | 343 | return VBOXVHWA_SURFHANDLE_INVALID;
|
---|
| 344 |
|
---|
[71651] | 345 | for (int k = 0; k < 2; ++k)
|
---|
[22816] | 346 | {
|
---|
| 347 | Assert(mCursor != 0);
|
---|
[71651] | 348 | for (uint32_t i = mCursor; i < mcSize; ++i)
|
---|
[22816] | 349 | {
|
---|
[71651] | 350 | if (!mTable[i])
|
---|
[22816] | 351 | {
|
---|
| 352 | doPut(i, data);
|
---|
| 353 | mCursor = i+1;
|
---|
| 354 | return i;
|
---|
| 355 | }
|
---|
| 356 | }
|
---|
| 357 | mCursor = 1; /* 0 is treated as invalid */
|
---|
| 358 | }
|
---|
| 359 |
|
---|
[49940] | 360 | AssertFailed();
|
---|
[22816] | 361 | return VBOXVHWA_SURFHANDLE_INVALID;
|
---|
| 362 | }
|
---|
| 363 |
|
---|
| 364 | bool VBoxVHWAHandleTable::mapPut(uint32_t h, void * data)
|
---|
| 365 | {
|
---|
[71651] | 366 | if (mcSize <= h)
|
---|
[22816] | 367 | return false;
|
---|
[71651] | 368 | if (h == 0)
|
---|
[22816] | 369 | return false;
|
---|
[71651] | 370 | if (mTable[h])
|
---|
[22816] | 371 | return false;
|
---|
| 372 |
|
---|
| 373 | doPut(h, data);
|
---|
| 374 | return true;
|
---|
| 375 | }
|
---|
| 376 |
|
---|
| 377 | void* VBoxVHWAHandleTable::get(uint32_t h)
|
---|
| 378 | {
|
---|
| 379 | Assert(h < mcSize);
|
---|
| 380 | Assert(h > 0);
|
---|
| 381 | return mTable[h];
|
---|
| 382 | }
|
---|
| 383 |
|
---|
| 384 | void* VBoxVHWAHandleTable::remove(uint32_t h)
|
---|
| 385 | {
|
---|
| 386 | Assert(mcUsage);
|
---|
| 387 | Assert(h < mcSize);
|
---|
| 388 | void* val = mTable[h];
|
---|
| 389 | Assert(val);
|
---|
[71651] | 390 | if (val)
|
---|
[22816] | 391 | {
|
---|
| 392 | doRemove(h);
|
---|
| 393 | }
|
---|
| 394 | return val;
|
---|
| 395 | }
|
---|
| 396 |
|
---|
| 397 | void VBoxVHWAHandleTable::doPut(uint32_t h, void * data)
|
---|
| 398 | {
|
---|
| 399 | ++mcUsage;
|
---|
| 400 | mTable[h] = data;
|
---|
| 401 | }
|
---|
| 402 |
|
---|
| 403 | void VBoxVHWAHandleTable::doRemove(uint32_t h)
|
---|
| 404 | {
|
---|
| 405 | mTable[h] = 0;
|
---|
| 406 | --mcUsage;
|
---|
| 407 | }
|
---|
| 408 |
|
---|
[71651] | 409 | static VBoxVHWATextureImage *vboxVHWAImageCreate(const QRect & aRect, const VBoxVHWAColorFormat & aFormat,
|
---|
| 410 | class VBoxVHWAGlProgramMngr * pMgr, VBOXVHWAIMG_TYPE flags)
|
---|
[22816] | 411 | {
|
---|
[34461] | 412 | bool bCanLinearNonFBO = false;
|
---|
| 413 | if (!aFormat.fourcc())
|
---|
| 414 | {
|
---|
| 415 | flags &= ~VBOXVHWAIMG_FBO;
|
---|
| 416 | bCanLinearNonFBO = true;
|
---|
| 417 | }
|
---|
| 418 |
|
---|
[25385] | 419 | const VBoxVHWAInfo & info = vboxVHWAGetSupportInfo(NULL);
|
---|
[71651] | 420 | if ((flags & VBOXVHWAIMG_PBO) && !info.getGlInfo().isPBOSupported())
|
---|
[25453] | 421 | flags &= ~VBOXVHWAIMG_PBO;
|
---|
| 422 |
|
---|
[71651] | 423 | if ((flags & VBOXVHWAIMG_PBOIMG) &&
|
---|
[25453] | 424 | (!info.getGlInfo().isPBOSupported() || !info.getGlInfo().isPBOOffsetSupported()))
|
---|
| 425 | flags &= ~VBOXVHWAIMG_PBOIMG;
|
---|
| 426 |
|
---|
[71651] | 427 | if ((flags & VBOXVHWAIMG_FBO) && !info.getGlInfo().isFBOSupported())
|
---|
[25453] | 428 | flags &= ~VBOXVHWAIMG_FBO;
|
---|
| 429 |
|
---|
| 430 | /* ensure we don't create a PBO-based texture in case we use a PBO-based image */
|
---|
[71651] | 431 | if (flags & VBOXVHWAIMG_PBOIMG)
|
---|
[25453] | 432 | flags &= ~VBOXVHWAIMG_PBO;
|
---|
| 433 |
|
---|
[71651] | 434 | if (flags & VBOXVHWAIMG_FBO)
|
---|
[25385] | 435 | {
|
---|
[71651] | 436 | if (flags & VBOXVHWAIMG_PBOIMG)
|
---|
[25453] | 437 | {
|
---|
| 438 | VBOXQGLLOG(("FBO PBO Image\n"));
|
---|
| 439 | return new VBoxVHWATextureImageFBO<VBoxVHWATextureImagePBO>(aRect, aFormat, pMgr, flags);
|
---|
| 440 | }
|
---|
[34461] | 441 | VBOXQGLLOG(("FBO Generic Image\n"));
|
---|
| 442 | return new VBoxVHWATextureImageFBO<VBoxVHWATextureImage>(aRect, aFormat, pMgr, flags);
|
---|
| 443 | }
|
---|
| 444 |
|
---|
| 445 | if (!bCanLinearNonFBO)
|
---|
| 446 | {
|
---|
| 447 | VBOXQGLLOG(("Disabling Linear stretching\n"));
|
---|
| 448 | flags &= ~VBOXVHWAIMG_LINEAR;
|
---|
| 449 | }
|
---|
| 450 |
|
---|
[71651] | 451 | if (flags & VBOXVHWAIMG_PBOIMG)
|
---|
[34461] | 452 | {
|
---|
[25385] | 453 | VBOXQGLLOG(("PBO Image\n"));
|
---|
[25453] | 454 | return new VBoxVHWATextureImagePBO(aRect, aFormat, pMgr, flags);
|
---|
[25385] | 455 | }
|
---|
[34461] | 456 |
|
---|
[25385] | 457 | VBOXQGLLOG(("Generic Image\n"));
|
---|
[25453] | 458 | return new VBoxVHWATextureImage(aRect, aFormat, pMgr, flags);
|
---|
[25385] | 459 | }
|
---|
| 460 |
|
---|
[71651] | 461 | static VBoxVHWATexture* vboxVHWATextureCreate(const QGLContext * pContext, const QRect & aRect,
|
---|
| 462 | const VBoxVHWAColorFormat & aFormat, uint32_t bytesPerLine, VBOXVHWAIMG_TYPE flags)
|
---|
[25385] | 463 | {
|
---|
[23732] | 464 | const VBoxVHWAInfo & info = vboxVHWAGetSupportInfo(pContext);
|
---|
[25470] | 465 | GLint scaleFunc = (flags & VBOXVHWAIMG_LINEAR) ? GL_LINEAR : GL_NEAREST;
|
---|
[71651] | 466 | if ((flags & VBOXVHWAIMG_PBO) && info.getGlInfo().isPBOSupported())
|
---|
[22816] | 467 | {
|
---|
| 468 | VBOXQGLLOG(("VBoxVHWATextureNP2RectPBO\n"));
|
---|
[35280] | 469 | return new VBoxVHWATextureNP2RectPBO(aRect, aFormat, bytesPerLine, scaleFunc);
|
---|
[22816] | 470 | }
|
---|
[71651] | 471 | else if (info.getGlInfo().isTextureRectangleSupported())
|
---|
[22816] | 472 | {
|
---|
| 473 | VBOXQGLLOG(("VBoxVHWATextureNP2Rect\n"));
|
---|
[35280] | 474 | return new VBoxVHWATextureNP2Rect(aRect, aFormat, bytesPerLine, scaleFunc);
|
---|
[22816] | 475 | }
|
---|
[71651] | 476 | else if (info.getGlInfo().isTextureNP2Supported())
|
---|
[22816] | 477 | {
|
---|
| 478 | VBOXQGLLOG(("VBoxVHWATextureNP2\n"));
|
---|
[35280] | 479 | return new VBoxVHWATextureNP2(aRect, aFormat, bytesPerLine, scaleFunc);
|
---|
[22816] | 480 | }
|
---|
| 481 | VBOXQGLLOG(("VBoxVHWATexture\n"));
|
---|
[35280] | 482 | return new VBoxVHWATexture(aRect, aFormat, bytesPerLine, scaleFunc);
|
---|
[22816] | 483 | }
|
---|
| 484 |
|
---|
[23162] | 485 | class VBoxVHWAGlShaderComponent
|
---|
[22816] | 486 | {
|
---|
| 487 | public:
|
---|
[71651] | 488 | VBoxVHWAGlShaderComponent(const char *aRcName, GLenum aType)
|
---|
| 489 | : mRcName(aRcName)
|
---|
| 490 | , mType(aType)
|
---|
| 491 | , mInitialized(false)
|
---|
[63492] | 492 | { NOREF(mType); }
|
---|
[22816] | 493 |
|
---|
| 494 |
|
---|
| 495 | int init();
|
---|
[23162] | 496 |
|
---|
| 497 | const char * contents() { return mSource.constData(); }
|
---|
| 498 | bool isInitialized() { return mInitialized; }
|
---|
[22816] | 499 | private:
|
---|
| 500 | const char *mRcName;
|
---|
| 501 | GLenum mType;
|
---|
[23162] | 502 | QByteArray mSource;
|
---|
| 503 | bool mInitialized;
|
---|
[22816] | 504 | };
|
---|
| 505 |
|
---|
[23162] | 506 | int VBoxVHWAGlShaderComponent::init()
|
---|
[22816] | 507 | {
|
---|
[71651] | 508 | if (isInitialized())
|
---|
[22816] | 509 | return VINF_ALREADY_INITIALIZED;
|
---|
| 510 |
|
---|
| 511 | QFile fi(mRcName);
|
---|
| 512 | if (!fi.open(QIODevice::ReadOnly))
|
---|
| 513 | {
|
---|
[49940] | 514 | AssertFailed();
|
---|
[22816] | 515 | return VERR_GENERAL_FAILURE;
|
---|
| 516 | }
|
---|
| 517 |
|
---|
| 518 | QTextStream is(&fi);
|
---|
| 519 | QString program = is.readAll();
|
---|
| 520 |
|
---|
[58866] | 521 | mSource = program.toUtf8();
|
---|
[23162] | 522 |
|
---|
| 523 | mInitialized = true;
|
---|
| 524 | return VINF_SUCCESS;
|
---|
| 525 | }
|
---|
| 526 |
|
---|
| 527 | class VBoxVHWAGlShader
|
---|
| 528 | {
|
---|
| 529 | public:
|
---|
| 530 | VBoxVHWAGlShader() :
|
---|
| 531 | mType(GL_FRAGMENT_SHADER),
|
---|
| 532 | mcComponents(0)
|
---|
| 533 | {}
|
---|
| 534 |
|
---|
| 535 | VBoxVHWAGlShader & operator= (const VBoxVHWAGlShader & other)
|
---|
| 536 | {
|
---|
| 537 | mcComponents = other.mcComponents;
|
---|
| 538 | mType = other.mType;
|
---|
[71651] | 539 | if (mcComponents)
|
---|
[23162] | 540 | {
|
---|
| 541 | maComponents = new VBoxVHWAGlShaderComponent*[mcComponents];
|
---|
| 542 | memcpy(maComponents, other.maComponents, mcComponents * sizeof(maComponents[0]));
|
---|
| 543 | }
|
---|
| 544 | return *this;
|
---|
| 545 | }
|
---|
| 546 |
|
---|
| 547 | VBoxVHWAGlShader(const VBoxVHWAGlShader & other)
|
---|
| 548 | {
|
---|
| 549 | mcComponents = other.mcComponents;
|
---|
| 550 | mType = other.mType;
|
---|
[71651] | 551 | if (mcComponents)
|
---|
[23162] | 552 | {
|
---|
| 553 | maComponents = new VBoxVHWAGlShaderComponent*[mcComponents];
|
---|
| 554 | memcpy(maComponents, other.maComponents, mcComponents * sizeof(maComponents[0]));
|
---|
| 555 | }
|
---|
| 556 | }
|
---|
| 557 |
|
---|
| 558 | VBoxVHWAGlShader(GLenum aType, VBoxVHWAGlShaderComponent ** aComponents, int cComponents)
|
---|
| 559 | : mType(aType)
|
---|
| 560 | {
|
---|
| 561 | maComponents = new VBoxVHWAGlShaderComponent*[cComponents];
|
---|
| 562 | mcComponents = cComponents;
|
---|
| 563 | memcpy(maComponents, aComponents, cComponents * sizeof(maComponents[0]));
|
---|
| 564 | }
|
---|
| 565 |
|
---|
| 566 | ~VBoxVHWAGlShader() {delete[] maComponents;}
|
---|
| 567 | int init();
|
---|
| 568 | GLenum type() { return mType; }
|
---|
| 569 | GLuint shader() { return mShader; }
|
---|
| 570 | private:
|
---|
| 571 | GLenum mType;
|
---|
| 572 | GLuint mShader;
|
---|
| 573 | VBoxVHWAGlShaderComponent ** maComponents;
|
---|
| 574 | int mcComponents;
|
---|
| 575 | };
|
---|
| 576 |
|
---|
| 577 | int VBoxVHWAGlShader::init()
|
---|
| 578 | {
|
---|
[31017] | 579 | int rc = VERR_GENERAL_FAILURE;
|
---|
[24515] | 580 | GLint *length;
|
---|
[23162] | 581 | const char **sources;
|
---|
[24515] | 582 | length = new GLint[mcComponents];
|
---|
[23162] | 583 | sources = new const char*[mcComponents];
|
---|
[71651] | 584 | for (int i = 0; i < mcComponents; i++)
|
---|
[23162] | 585 | {
|
---|
| 586 | length[i] = -1;
|
---|
| 587 | rc = maComponents[i]->init();
|
---|
[25226] | 588 | AssertRC(rc);
|
---|
[71651] | 589 | if (RT_FAILURE(rc))
|
---|
[31017] | 590 | break;
|
---|
[23162] | 591 | sources[i] = maComponents[i]->contents();
|
---|
| 592 | }
|
---|
| 593 |
|
---|
[71651] | 594 | if (RT_SUCCESS(rc))
|
---|
[31017] | 595 | {
|
---|
[23162] | 596 | #ifdef DEBUG
|
---|
[31017] | 597 | VBOXQGLLOG(("\ncompiling shaders:\n------------\n"));
|
---|
[71651] | 598 | for (int i = 0; i < mcComponents; i++)
|
---|
[31017] | 599 | VBOXQGLLOG(("**********\n%s\n***********\n", sources[i]));
|
---|
| 600 | VBOXQGLLOG(("------------\n"));
|
---|
[23162] | 601 | #endif
|
---|
[31017] | 602 | mShader = vboxglCreateShader(mType);
|
---|
[22816] | 603 |
|
---|
[31017] | 604 | VBOXQGL_CHECKERR(
|
---|
| 605 | vboxglShaderSource(mShader, mcComponents, sources, length);
|
---|
| 606 | );
|
---|
[22816] | 607 |
|
---|
[31017] | 608 | VBOXQGL_CHECKERR(
|
---|
| 609 | vboxglCompileShader(mShader);
|
---|
| 610 | );
|
---|
[22816] | 611 |
|
---|
[31017] | 612 | GLint compiled;
|
---|
| 613 | VBOXQGL_CHECKERR(
|
---|
| 614 | vboxglGetShaderiv(mShader, GL_COMPILE_STATUS, &compiled);
|
---|
| 615 | );
|
---|
[22816] | 616 |
|
---|
| 617 | #ifdef DEBUG
|
---|
[31017] | 618 | GLchar * pBuf = new GLchar[16300];
|
---|
| 619 | vboxglGetShaderInfoLog(mShader, 16300, NULL, pBuf);
|
---|
| 620 | VBOXQGLLOG(("\ncompile log:\n-----------\n%s\n---------\n", pBuf));
|
---|
| 621 | delete[] pBuf;
|
---|
[22816] | 622 | #endif
|
---|
| 623 |
|
---|
[31017] | 624 | Assert(compiled);
|
---|
[71651] | 625 | if (compiled)
|
---|
[31017] | 626 | {
|
---|
| 627 | rc = VINF_SUCCESS;
|
---|
| 628 | }
|
---|
| 629 | else
|
---|
| 630 | {
|
---|
| 631 | VBOXQGL_CHECKERR(
|
---|
| 632 | vboxglDeleteShader(mShader);
|
---|
| 633 | );
|
---|
| 634 | mShader = 0;
|
---|
| 635 | }
|
---|
[22816] | 636 | }
|
---|
| 637 |
|
---|
[23162] | 638 | delete[] length;
|
---|
| 639 | delete[] sources;
|
---|
[31017] | 640 | return rc;
|
---|
[22816] | 641 | }
|
---|
| 642 |
|
---|
| 643 | class VBoxVHWAGlProgram
|
---|
| 644 | {
|
---|
| 645 | public:
|
---|
| 646 | VBoxVHWAGlProgram(VBoxVHWAGlShader ** apShaders, int acShaders);
|
---|
| 647 |
|
---|
[63305] | 648 | virtual ~VBoxVHWAGlProgram();
|
---|
[22816] | 649 |
|
---|
| 650 | virtual int init();
|
---|
| 651 | virtual void uninit();
|
---|
| 652 | virtual int start();
|
---|
| 653 | virtual int stop();
|
---|
| 654 | bool isInitialized() { return mProgram; }
|
---|
| 655 | GLuint program() {return mProgram;}
|
---|
| 656 | private:
|
---|
| 657 | GLuint mProgram;
|
---|
[23162] | 658 | VBoxVHWAGlShader *mShaders;
|
---|
[22816] | 659 | int mcShaders;
|
---|
| 660 | };
|
---|
| 661 |
|
---|
| 662 | VBoxVHWAGlProgram::VBoxVHWAGlProgram(VBoxVHWAGlShader ** apShaders, int acShaders) :
|
---|
| 663 | mProgram(0),
|
---|
| 664 | mcShaders(0)
|
---|
| 665 | {
|
---|
| 666 | Assert(acShaders);
|
---|
[71651] | 667 | if (acShaders)
|
---|
[22816] | 668 | {
|
---|
[23162] | 669 | mShaders = new VBoxVHWAGlShader[acShaders];
|
---|
[71651] | 670 | for (int i = 0; i < acShaders; i++)
|
---|
[23162] | 671 | {
|
---|
| 672 | mShaders[i] = *apShaders[i];
|
---|
| 673 | }
|
---|
[22816] | 674 | mcShaders = acShaders;
|
---|
| 675 | }
|
---|
| 676 | }
|
---|
| 677 |
|
---|
| 678 | VBoxVHWAGlProgram::~VBoxVHWAGlProgram()
|
---|
| 679 | {
|
---|
| 680 | uninit();
|
---|
| 681 |
|
---|
[71651] | 682 | if (mShaders)
|
---|
[22816] | 683 | {
|
---|
[23162] | 684 | delete[] mShaders;
|
---|
[22816] | 685 | }
|
---|
| 686 | }
|
---|
| 687 |
|
---|
| 688 | int VBoxVHWAGlProgram::init()
|
---|
| 689 | {
|
---|
| 690 | Assert(!isInitialized());
|
---|
[71651] | 691 | if (isInitialized())
|
---|
[22816] | 692 | return VINF_ALREADY_INITIALIZED;
|
---|
| 693 |
|
---|
| 694 | Assert(mcShaders);
|
---|
[71651] | 695 | if (!mcShaders)
|
---|
[22816] | 696 | return VERR_GENERAL_FAILURE;
|
---|
| 697 |
|
---|
| 698 | int rc = VINF_SUCCESS;
|
---|
[71651] | 699 | for (int i = 0; i < mcShaders; i++)
|
---|
[22816] | 700 | {
|
---|
[23162] | 701 | int rc = mShaders[i].init();
|
---|
[25226] | 702 | AssertRC(rc);
|
---|
[71651] | 703 | if (RT_FAILURE(rc))
|
---|
[22816] | 704 | {
|
---|
| 705 | break;
|
---|
| 706 | }
|
---|
| 707 | }
|
---|
[71651] | 708 | if (RT_FAILURE(rc))
|
---|
[22816] | 709 | {
|
---|
| 710 | return rc;
|
---|
| 711 | }
|
---|
| 712 |
|
---|
| 713 | mProgram = vboxglCreateProgram();
|
---|
| 714 | Assert(mProgram);
|
---|
[71651] | 715 | if (mProgram)
|
---|
[22816] | 716 | {
|
---|
[71651] | 717 | for (int i = 0; i < mcShaders; i++)
|
---|
[22816] | 718 | {
|
---|
| 719 | VBOXQGL_CHECKERR(
|
---|
[23162] | 720 | vboxglAttachShader(mProgram, mShaders[i].shader());
|
---|
[22816] | 721 | );
|
---|
| 722 | }
|
---|
| 723 |
|
---|
| 724 | VBOXQGL_CHECKERR(
|
---|
| 725 | vboxglLinkProgram(mProgram);
|
---|
| 726 | );
|
---|
| 727 |
|
---|
| 728 |
|
---|
| 729 | GLint linked;
|
---|
| 730 | vboxglGetProgramiv(mProgram, GL_LINK_STATUS, &linked);
|
---|
| 731 |
|
---|
| 732 | #ifdef DEBUG
|
---|
| 733 | GLchar * pBuf = new GLchar[16300];
|
---|
| 734 | vboxglGetProgramInfoLog(mProgram, 16300, NULL, pBuf);
|
---|
| 735 | VBOXQGLLOG(("link log: %s\n", pBuf));
|
---|
| 736 | Assert(linked);
|
---|
[58670] | 737 | delete[] pBuf;
|
---|
[22816] | 738 | #endif
|
---|
| 739 |
|
---|
[71651] | 740 | if (linked)
|
---|
[22816] | 741 | {
|
---|
| 742 | return VINF_SUCCESS;
|
---|
| 743 | }
|
---|
| 744 |
|
---|
| 745 | VBOXQGL_CHECKERR(
|
---|
| 746 | vboxglDeleteProgram(mProgram);
|
---|
| 747 | );
|
---|
| 748 | mProgram = 0;
|
---|
| 749 | }
|
---|
| 750 | return VERR_GENERAL_FAILURE;
|
---|
| 751 | }
|
---|
| 752 |
|
---|
| 753 | void VBoxVHWAGlProgram::uninit()
|
---|
| 754 | {
|
---|
[71651] | 755 | if (!isInitialized())
|
---|
[22816] | 756 | return;
|
---|
| 757 |
|
---|
| 758 | VBOXQGL_CHECKERR(
|
---|
| 759 | vboxglDeleteProgram(mProgram);
|
---|
| 760 | );
|
---|
| 761 | mProgram = 0;
|
---|
| 762 | }
|
---|
| 763 |
|
---|
| 764 | int VBoxVHWAGlProgram::start()
|
---|
| 765 | {
|
---|
| 766 | VBOXQGL_CHECKERR(
|
---|
| 767 | vboxglUseProgram(mProgram);
|
---|
| 768 | );
|
---|
| 769 | return VINF_SUCCESS;
|
---|
| 770 | }
|
---|
| 771 |
|
---|
| 772 | int VBoxVHWAGlProgram::stop()
|
---|
| 773 | {
|
---|
| 774 | VBOXQGL_CHECKERR(
|
---|
| 775 | vboxglUseProgram(0);
|
---|
| 776 | );
|
---|
| 777 | return VINF_SUCCESS;
|
---|
| 778 | }
|
---|
| 779 |
|
---|
[24646] | 780 | #define VBOXVHWA_PROGRAM_DSTCOLORKEY 0x00000001
|
---|
| 781 | #define VBOXVHWA_PROGRAM_SRCCOLORKEY 0x00000002
|
---|
| 782 | #define VBOXVHWA_PROGRAM_COLORCONV 0x00000004
|
---|
| 783 | #define VBOXVHWA_PROGRAM_COLORKEYNODISCARD 0x00000008
|
---|
[22816] | 784 |
|
---|
[24646] | 785 | #define VBOXVHWA_SUPPORTED_PROGRAM ( \
|
---|
| 786 | VBOXVHWA_PROGRAM_DSTCOLORKEY \
|
---|
| 787 | | VBOXVHWA_PROGRAM_SRCCOLORKEY \
|
---|
| 788 | | VBOXVHWA_PROGRAM_COLORCONV \
|
---|
| 789 | | VBOXVHWA_PROGRAM_COLORKEYNODISCARD \
|
---|
| 790 | )
|
---|
| 791 |
|
---|
[22816] | 792 | class VBoxVHWAGlProgramVHWA : public VBoxVHWAGlProgram
|
---|
| 793 | {
|
---|
| 794 | public:
|
---|
[25269] | 795 | VBoxVHWAGlProgramVHWA(uint32_t type, uint32_t fourcc, VBoxVHWAGlShader ** apShaders, int acShaders);
|
---|
[22816] | 796 |
|
---|
| 797 | uint32_t type() const {return mType;}
|
---|
| 798 | uint32_t fourcc() const {return mFourcc;}
|
---|
| 799 |
|
---|
| 800 | int setDstCKeyUpperRange(GLfloat r, GLfloat g, GLfloat b);
|
---|
| 801 |
|
---|
| 802 | int setDstCKeyLowerRange(GLfloat r, GLfloat g, GLfloat b);
|
---|
| 803 |
|
---|
| 804 | int setSrcCKeyUpperRange(GLfloat r, GLfloat g, GLfloat b);
|
---|
| 805 |
|
---|
| 806 | int setSrcCKeyLowerRange(GLfloat r, GLfloat g, GLfloat b);
|
---|
| 807 |
|
---|
| 808 |
|
---|
| 809 | virtual int init();
|
---|
| 810 |
|
---|
| 811 | bool matches(uint32_t type, uint32_t fourcc)
|
---|
| 812 | {
|
---|
| 813 | return mType == type && mFourcc == fourcc;
|
---|
| 814 | }
|
---|
| 815 |
|
---|
| 816 | bool equals(const VBoxVHWAGlProgramVHWA & other)
|
---|
| 817 | {
|
---|
| 818 | return matches(other.mType, other.mFourcc);
|
---|
| 819 | }
|
---|
| 820 |
|
---|
| 821 | private:
|
---|
| 822 | uint32_t mType;
|
---|
| 823 | uint32_t mFourcc;
|
---|
| 824 |
|
---|
| 825 | GLfloat mDstUpperR, mDstUpperG, mDstUpperB;
|
---|
| 826 | GLint mUniDstUpperColor;
|
---|
| 827 |
|
---|
| 828 | GLfloat mDstLowerR, mDstLowerG, mDstLowerB;
|
---|
| 829 | GLint mUniDstLowerColor;
|
---|
| 830 |
|
---|
| 831 | GLfloat mSrcUpperR, mSrcUpperG, mSrcUpperB;
|
---|
| 832 | GLint mUniSrcUpperColor;
|
---|
| 833 |
|
---|
| 834 | GLfloat mSrcLowerR, mSrcLowerG, mSrcLowerB;
|
---|
| 835 | GLint mUniSrcLowerColor;
|
---|
| 836 |
|
---|
| 837 | GLint mDstTex;
|
---|
| 838 | GLint mUniDstTex;
|
---|
| 839 |
|
---|
| 840 | GLint mSrcTex;
|
---|
| 841 | GLint mUniSrcTex;
|
---|
| 842 |
|
---|
| 843 | GLint mVTex;
|
---|
| 844 | GLint mUniVTex;
|
---|
| 845 |
|
---|
| 846 | GLint mUTex;
|
---|
| 847 | GLint mUniUTex;
|
---|
| 848 | };
|
---|
| 849 |
|
---|
[71651] | 850 | VBoxVHWAGlProgramVHWA::VBoxVHWAGlProgramVHWA(uint32_t type, uint32_t fourcc, VBoxVHWAGlShader **apShaders, int acShaders)
|
---|
| 851 | : VBoxVHWAGlProgram(apShaders, acShaders)
|
---|
| 852 | , mType(type)
|
---|
| 853 | , mFourcc(fourcc)
|
---|
| 854 | , mDstUpperR(0.0)
|
---|
| 855 | , mDstUpperG(0.0)
|
---|
| 856 | , mDstUpperB(0.0)
|
---|
| 857 | , mUniDstUpperColor(-1)
|
---|
| 858 | , mDstLowerR(0.0)
|
---|
| 859 | , mDstLowerG(0.0)
|
---|
| 860 | , mDstLowerB(0.0)
|
---|
| 861 | , mUniDstLowerColor(-1)
|
---|
| 862 | , mSrcUpperR(0.0)
|
---|
| 863 | , mSrcUpperG(0.0)
|
---|
| 864 | , mSrcUpperB(0.0)
|
---|
| 865 | , mUniSrcUpperColor(-1)
|
---|
| 866 | , mSrcLowerR(0.0)
|
---|
| 867 | , mSrcLowerG(0.0)
|
---|
| 868 | , mSrcLowerB(0.0)
|
---|
| 869 | , mUniSrcLowerColor(-1)
|
---|
| 870 | , mDstTex(-1)
|
---|
| 871 | , mUniDstTex(-1)
|
---|
| 872 | , mSrcTex(-1)
|
---|
| 873 | , mUniSrcTex(-1)
|
---|
| 874 | , mVTex(-1)
|
---|
| 875 | , mUniVTex(-1)
|
---|
| 876 | , mUTex(-1)
|
---|
| 877 | , mUniUTex(-1)
|
---|
[22816] | 878 | {}
|
---|
| 879 |
|
---|
| 880 | int VBoxVHWAGlProgramVHWA::init()
|
---|
| 881 | {
|
---|
| 882 | int rc = VBoxVHWAGlProgram::init();
|
---|
[71651] | 883 | if (RT_FAILURE(rc))
|
---|
[22816] | 884 | return rc;
|
---|
[71651] | 885 | if (rc == VINF_ALREADY_INITIALIZED)
|
---|
[22816] | 886 | return rc;
|
---|
| 887 |
|
---|
| 888 | start();
|
---|
| 889 |
|
---|
| 890 | rc = VERR_GENERAL_FAILURE;
|
---|
| 891 |
|
---|
| 892 | do
|
---|
| 893 | {
|
---|
[22883] | 894 | GLint tex = 0;
|
---|
[22816] | 895 | mUniSrcTex = vboxglGetUniformLocation(program(), "uSrcTex");
|
---|
| 896 | Assert(mUniSrcTex != -1);
|
---|
[71651] | 897 | if (mUniSrcTex == -1)
|
---|
[22816] | 898 | break;
|
---|
| 899 |
|
---|
[22883] | 900 | VBOXQGL_CHECKERR(
|
---|
| 901 | vboxglUniform1i(mUniSrcTex, tex);
|
---|
| 902 | );
|
---|
| 903 | mSrcTex = tex;
|
---|
| 904 | ++tex;
|
---|
[22816] | 905 |
|
---|
[71651] | 906 | if (type() & VBOXVHWA_PROGRAM_SRCCOLORKEY)
|
---|
[22816] | 907 | {
|
---|
| 908 | mUniSrcLowerColor = vboxglGetUniformLocation(program(), "uSrcClr");
|
---|
| 909 | Assert(mUniSrcLowerColor != -1);
|
---|
[71651] | 910 | if (mUniSrcLowerColor == -1)
|
---|
[22816] | 911 | break;
|
---|
| 912 |
|
---|
| 913 | mSrcLowerR = 0.0; mSrcLowerG = 0.0; mSrcLowerB = 0.0;
|
---|
[24471] | 914 |
|
---|
[22816] | 915 | VBOXQGL_CHECKERR(
|
---|
| 916 | vboxglUniform4f(mUniSrcLowerColor, 0.0, 0.0, 0.0, 0.0);
|
---|
| 917 | );
|
---|
| 918 | }
|
---|
| 919 |
|
---|
[71651] | 920 | if (type() & VBOXVHWA_PROGRAM_COLORCONV)
|
---|
[22816] | 921 | {
|
---|
| 922 | switch(fourcc())
|
---|
| 923 | {
|
---|
| 924 | case FOURCC_YV12:
|
---|
| 925 | {
|
---|
| 926 | mUniVTex = vboxglGetUniformLocation(program(), "uVTex");
|
---|
| 927 | Assert(mUniVTex != -1);
|
---|
[71651] | 928 | if (mUniVTex == -1)
|
---|
[22816] | 929 | break;
|
---|
| 930 |
|
---|
| 931 | VBOXQGL_CHECKERR(
|
---|
| 932 | vboxglUniform1i(mUniVTex, tex);
|
---|
| 933 | );
|
---|
| 934 | mVTex = tex;
|
---|
[22883] | 935 | ++tex;
|
---|
[22816] | 936 |
|
---|
| 937 | mUniUTex = vboxglGetUniformLocation(program(), "uUTex");
|
---|
| 938 | Assert(mUniUTex != -1);
|
---|
[71651] | 939 | if (mUniUTex == -1)
|
---|
[22816] | 940 | break;
|
---|
| 941 | VBOXQGL_CHECKERR(
|
---|
| 942 | vboxglUniform1i(mUniUTex, tex);
|
---|
| 943 | );
|
---|
| 944 | mUTex = tex;
|
---|
[22883] | 945 | ++tex;
|
---|
[22816] | 946 |
|
---|
| 947 | break;
|
---|
| 948 | }
|
---|
| 949 | case FOURCC_UYVY:
|
---|
| 950 | case FOURCC_YUY2:
|
---|
| 951 | case FOURCC_AYUV:
|
---|
| 952 | break;
|
---|
| 953 | default:
|
---|
[49940] | 954 | AssertFailed();
|
---|
[22816] | 955 | break;
|
---|
| 956 | }
|
---|
| 957 | }
|
---|
| 958 |
|
---|
[71651] | 959 | if (type() & VBOXVHWA_PROGRAM_DSTCOLORKEY)
|
---|
[22883] | 960 | {
|
---|
| 961 |
|
---|
| 962 | mUniDstTex = vboxglGetUniformLocation(program(), "uDstTex");
|
---|
| 963 | Assert(mUniDstTex != -1);
|
---|
[71651] | 964 | if (mUniDstTex == -1)
|
---|
[22883] | 965 | break;
|
---|
| 966 | VBOXQGL_CHECKERR(
|
---|
| 967 | vboxglUniform1i(mUniDstTex, tex);
|
---|
| 968 | );
|
---|
| 969 | mDstTex = tex;
|
---|
| 970 | ++tex;
|
---|
| 971 |
|
---|
| 972 | mUniDstLowerColor = vboxglGetUniformLocation(program(), "uDstClr");
|
---|
| 973 | Assert(mUniDstLowerColor != -1);
|
---|
[71651] | 974 | if (mUniDstLowerColor == -1)
|
---|
[22883] | 975 | break;
|
---|
| 976 |
|
---|
| 977 | mDstLowerR = 0.0; mDstLowerG = 0.0; mDstLowerB = 0.0;
|
---|
| 978 |
|
---|
| 979 | VBOXQGL_CHECKERR(
|
---|
| 980 | vboxglUniform4f(mUniDstLowerColor, 0.0, 0.0, 0.0, 0.0);
|
---|
| 981 | );
|
---|
| 982 | }
|
---|
| 983 |
|
---|
[22816] | 984 | rc = VINF_SUCCESS;
|
---|
| 985 | } while(0);
|
---|
| 986 |
|
---|
| 987 |
|
---|
| 988 | stop();
|
---|
[71651] | 989 | if (rc == VINF_SUCCESS)
|
---|
[22816] | 990 | return VINF_SUCCESS;
|
---|
| 991 |
|
---|
[49940] | 992 | AssertFailed();
|
---|
[22816] | 993 | VBoxVHWAGlProgram::uninit();
|
---|
| 994 | return VERR_GENERAL_FAILURE;
|
---|
| 995 | }
|
---|
| 996 |
|
---|
| 997 | int VBoxVHWAGlProgramVHWA::setDstCKeyUpperRange(GLfloat r, GLfloat g, GLfloat b)
|
---|
| 998 | {
|
---|
| 999 | Assert(isInitialized());
|
---|
[71651] | 1000 | if (!isInitialized())
|
---|
[22816] | 1001 | return VERR_GENERAL_FAILURE;
|
---|
[71651] | 1002 | if (mDstUpperR == r && mDstUpperG == g && mDstUpperB == b)
|
---|
[22816] | 1003 | return VINF_ALREADY_INITIALIZED;
|
---|
| 1004 | vboxglUniform4f(mUniDstUpperColor, r, g, b, 0.0);
|
---|
| 1005 | mDstUpperR = r;
|
---|
| 1006 | mDstUpperG = g;
|
---|
| 1007 | mDstUpperB = b;
|
---|
| 1008 | return VINF_SUCCESS;
|
---|
| 1009 | }
|
---|
| 1010 |
|
---|
| 1011 | int VBoxVHWAGlProgramVHWA::setDstCKeyLowerRange(GLfloat r, GLfloat g, GLfloat b)
|
---|
| 1012 | {
|
---|
| 1013 | Assert(isInitialized());
|
---|
[71651] | 1014 | if (!isInitialized())
|
---|
[22816] | 1015 | return VERR_GENERAL_FAILURE;
|
---|
[71651] | 1016 | if (mDstLowerR == r && mDstLowerG == g && mDstLowerB == b)
|
---|
[22816] | 1017 | return VINF_ALREADY_INITIALIZED;
|
---|
| 1018 |
|
---|
| 1019 | VBOXQGL_CHECKERR(
|
---|
| 1020 | vboxglUniform4f(mUniDstLowerColor, r, g, b, 0.0);
|
---|
| 1021 | );
|
---|
| 1022 |
|
---|
| 1023 | mDstLowerR = r;
|
---|
| 1024 | mDstLowerG = g;
|
---|
| 1025 | mDstLowerB = b;
|
---|
| 1026 | return VINF_SUCCESS;
|
---|
| 1027 | }
|
---|
| 1028 |
|
---|
| 1029 | int VBoxVHWAGlProgramVHWA::setSrcCKeyUpperRange(GLfloat r, GLfloat g, GLfloat b)
|
---|
| 1030 | {
|
---|
| 1031 | Assert(isInitialized());
|
---|
[71651] | 1032 | if (!isInitialized())
|
---|
[22816] | 1033 | return VERR_GENERAL_FAILURE;
|
---|
[71651] | 1034 | if (mSrcUpperR == r && mSrcUpperG == g && mSrcUpperB == b)
|
---|
[22816] | 1035 | return VINF_ALREADY_INITIALIZED;
|
---|
| 1036 | vboxglUniform4f(mUniSrcUpperColor, r, g, b, 0.0);
|
---|
| 1037 | mSrcUpperR = r;
|
---|
| 1038 | mSrcUpperG = g;
|
---|
| 1039 | mSrcUpperB = b;
|
---|
| 1040 | return VINF_SUCCESS;
|
---|
| 1041 | }
|
---|
| 1042 |
|
---|
| 1043 | int VBoxVHWAGlProgramVHWA::setSrcCKeyLowerRange(GLfloat r, GLfloat g, GLfloat b)
|
---|
| 1044 | {
|
---|
| 1045 | Assert(isInitialized());
|
---|
[71651] | 1046 | if (!isInitialized())
|
---|
[22816] | 1047 | return VERR_GENERAL_FAILURE;
|
---|
[71651] | 1048 | if (mSrcLowerR == r && mSrcLowerG == g && mSrcLowerB == b)
|
---|
[22816] | 1049 | return VINF_ALREADY_INITIALIZED;
|
---|
| 1050 | VBOXQGL_CHECKERR(
|
---|
| 1051 | vboxglUniform4f(mUniSrcLowerColor, r, g, b, 0.0);
|
---|
| 1052 | );
|
---|
| 1053 | mSrcLowerR = r;
|
---|
| 1054 | mSrcLowerG = g;
|
---|
| 1055 | mSrcLowerB = b;
|
---|
| 1056 | return VINF_SUCCESS;
|
---|
| 1057 | }
|
---|
| 1058 |
|
---|
| 1059 | class VBoxVHWAGlProgramMngr
|
---|
| 1060 | {
|
---|
| 1061 | public:
|
---|
[71651] | 1062 | VBoxVHWAGlProgramMngr()
|
---|
| 1063 | : mShaderCConvApplyAYUV(":/cconvApplyAYUV.c", GL_FRAGMENT_SHADER)
|
---|
| 1064 | , mShaderCConvAYUV(":/cconvAYUV.c", GL_FRAGMENT_SHADER)
|
---|
| 1065 | , mShaderCConvBGR(":/cconvBGR.c", GL_FRAGMENT_SHADER)
|
---|
| 1066 | , mShaderCConvUYVY(":/cconvUYVY.c", GL_FRAGMENT_SHADER)
|
---|
| 1067 | , mShaderCConvYUY2(":/cconvYUY2.c", GL_FRAGMENT_SHADER)
|
---|
| 1068 | , mShaderCConvYV12(":/cconvYV12.c", GL_FRAGMENT_SHADER)
|
---|
| 1069 | , mShaderSplitBGRA(":/splitBGRA.c", GL_FRAGMENT_SHADER)
|
---|
| 1070 | , mShaderCKeyDst(":/ckeyDst.c", GL_FRAGMENT_SHADER)
|
---|
| 1071 | , mShaderCKeyDst2(":/ckeyDst2.c", GL_FRAGMENT_SHADER)
|
---|
| 1072 | , mShaderMainOverlay(":/mainOverlay.c", GL_FRAGMENT_SHADER)
|
---|
| 1073 | , mShaderMainOverlayNoCKey(":/mainOverlayNoCKey.c", GL_FRAGMENT_SHADER)
|
---|
| 1074 | , mShaderMainOverlayNoDiscard(":/mainOverlayNoDiscard.c", GL_FRAGMENT_SHADER)
|
---|
| 1075 | , mShaderMainOverlayNoDiscard2(":/mainOverlayNoDiscard2.c", GL_FRAGMENT_SHADER)
|
---|
[22816] | 1076 | {}
|
---|
| 1077 |
|
---|
[71651] | 1078 | VBoxVHWAGlProgramVHWA *getProgram(uint32_t type, const VBoxVHWAColorFormat * pFrom, const VBoxVHWAColorFormat * pTo);
|
---|
[22816] | 1079 |
|
---|
| 1080 | void stopCurrentProgram()
|
---|
| 1081 | {
|
---|
| 1082 | VBOXQGL_CHECKERR(
|
---|
| 1083 | vboxglUseProgram(0);
|
---|
| 1084 | );
|
---|
| 1085 | }
|
---|
| 1086 | private:
|
---|
[71651] | 1087 | VBoxVHWAGlProgramVHWA *searchProgram(uint32_t type, uint32_t fourcc, bool bCreate);
|
---|
| 1088 | VBoxVHWAGlProgramVHWA *createProgram(uint32_t type, uint32_t fourcc);
|
---|
[22816] | 1089 |
|
---|
| 1090 | typedef std::list <VBoxVHWAGlProgramVHWA*> ProgramList;
|
---|
| 1091 |
|
---|
| 1092 | ProgramList mPrograms;
|
---|
| 1093 |
|
---|
[23162] | 1094 | VBoxVHWAGlShaderComponent mShaderCConvApplyAYUV;
|
---|
[22816] | 1095 |
|
---|
[23162] | 1096 | VBoxVHWAGlShaderComponent mShaderCConvAYUV;
|
---|
| 1097 | VBoxVHWAGlShaderComponent mShaderCConvBGR;
|
---|
| 1098 | VBoxVHWAGlShaderComponent mShaderCConvUYVY;
|
---|
| 1099 | VBoxVHWAGlShaderComponent mShaderCConvYUY2;
|
---|
| 1100 | VBoxVHWAGlShaderComponent mShaderCConvYV12;
|
---|
| 1101 | VBoxVHWAGlShaderComponent mShaderSplitBGRA;
|
---|
[22816] | 1102 |
|
---|
[22883] | 1103 | /* expected the dst surface texture to be bound to the 1-st tex unit */
|
---|
[23162] | 1104 | VBoxVHWAGlShaderComponent mShaderCKeyDst;
|
---|
[22883] | 1105 | /* expected the dst surface texture to be bound to the 2-nd tex unit */
|
---|
[23162] | 1106 | VBoxVHWAGlShaderComponent mShaderCKeyDst2;
|
---|
| 1107 | VBoxVHWAGlShaderComponent mShaderMainOverlay;
|
---|
| 1108 | VBoxVHWAGlShaderComponent mShaderMainOverlayNoCKey;
|
---|
[24646] | 1109 | VBoxVHWAGlShaderComponent mShaderMainOverlayNoDiscard;
|
---|
| 1110 | VBoxVHWAGlShaderComponent mShaderMainOverlayNoDiscard2;
|
---|
[22816] | 1111 |
|
---|
| 1112 | friend class VBoxVHWAGlProgramVHWA;
|
---|
| 1113 | };
|
---|
| 1114 |
|
---|
[71651] | 1115 | VBoxVHWAGlProgramVHWA *VBoxVHWAGlProgramMngr::createProgram(uint32_t type, uint32_t fourcc)
|
---|
[22816] | 1116 | {
|
---|
[71651] | 1117 | VBoxVHWAGlShaderComponent *apShaders[16];
|
---|
[22816] | 1118 | uint32_t cShaders = 0;
|
---|
| 1119 |
|
---|
| 1120 | /* workaround for NVIDIA driver bug: ensure we attach the shader before those it is used in */
|
---|
| 1121 | /* reserve a slot for the mShaderCConvApplyAYUV,
|
---|
| 1122 | * in case it is not used the slot will be occupied by mShaderCConvBGR , which is ok */
|
---|
| 1123 | cShaders++;
|
---|
| 1124 |
|
---|
[71651] | 1125 | if (!!(type & VBOXVHWA_PROGRAM_DSTCOLORKEY)
|
---|
[24646] | 1126 | && !(type & VBOXVHWA_PROGRAM_COLORKEYNODISCARD))
|
---|
[22816] | 1127 | {
|
---|
[71651] | 1128 | if (fourcc == FOURCC_YV12)
|
---|
[22883] | 1129 | {
|
---|
| 1130 | apShaders[cShaders++] = &mShaderCKeyDst2;
|
---|
| 1131 | }
|
---|
| 1132 | else
|
---|
| 1133 | {
|
---|
| 1134 | apShaders[cShaders++] = &mShaderCKeyDst;
|
---|
| 1135 | }
|
---|
[22816] | 1136 | }
|
---|
| 1137 |
|
---|
[71651] | 1138 | if (type & VBOXVHWA_PROGRAM_SRCCOLORKEY)
|
---|
[22816] | 1139 | {
|
---|
[49940] | 1140 | AssertFailed();
|
---|
[22816] | 1141 | /* disabled for now, not really necessary for video overlaying */
|
---|
| 1142 | }
|
---|
| 1143 |
|
---|
| 1144 | bool bFound = false;
|
---|
| 1145 |
|
---|
[71651] | 1146 | // if (type & VBOXVHWA_PROGRAM_COLORCONV)
|
---|
[22816] | 1147 | {
|
---|
[71651] | 1148 | if (fourcc == FOURCC_UYVY)
|
---|
[22816] | 1149 | {
|
---|
| 1150 | apShaders[cShaders++] = &mShaderCConvUYVY;
|
---|
| 1151 | bFound = true;
|
---|
| 1152 | }
|
---|
[71651] | 1153 | else if (fourcc == FOURCC_YUY2)
|
---|
[22816] | 1154 | {
|
---|
| 1155 | apShaders[cShaders++] = &mShaderCConvYUY2;
|
---|
| 1156 | bFound = true;
|
---|
| 1157 | }
|
---|
[71651] | 1158 | else if (fourcc == FOURCC_YV12)
|
---|
[22816] | 1159 | {
|
---|
| 1160 | apShaders[cShaders++] = &mShaderCConvYV12;
|
---|
| 1161 | bFound = true;
|
---|
| 1162 | }
|
---|
[71651] | 1163 | else if (fourcc == FOURCC_AYUV)
|
---|
[22816] | 1164 | {
|
---|
| 1165 | apShaders[cShaders++] = &mShaderCConvAYUV;
|
---|
| 1166 | bFound = true;
|
---|
| 1167 | }
|
---|
| 1168 | }
|
---|
| 1169 |
|
---|
[71651] | 1170 | if (bFound)
|
---|
[22816] | 1171 | {
|
---|
| 1172 | type |= VBOXVHWA_PROGRAM_COLORCONV;
|
---|
| 1173 | apShaders[0] = &mShaderCConvApplyAYUV;
|
---|
| 1174 | }
|
---|
| 1175 | else
|
---|
| 1176 | {
|
---|
| 1177 | type &= (~VBOXVHWA_PROGRAM_COLORCONV);
|
---|
| 1178 | apShaders[0] = &mShaderCConvBGR;
|
---|
| 1179 | }
|
---|
| 1180 |
|
---|
[71651] | 1181 | if (type & VBOXVHWA_PROGRAM_DSTCOLORKEY)
|
---|
[22816] | 1182 | {
|
---|
[71651] | 1183 | if (type & VBOXVHWA_PROGRAM_COLORKEYNODISCARD)
|
---|
[24646] | 1184 | {
|
---|
[71651] | 1185 | if (fourcc == FOURCC_YV12)
|
---|
[24646] | 1186 | apShaders[cShaders++] = &mShaderMainOverlayNoDiscard2;
|
---|
| 1187 | else
|
---|
| 1188 | apShaders[cShaders++] = &mShaderMainOverlayNoDiscard;
|
---|
| 1189 | }
|
---|
| 1190 | else
|
---|
| 1191 | apShaders[cShaders++] = &mShaderMainOverlay;
|
---|
[22816] | 1192 | }
|
---|
| 1193 | else
|
---|
| 1194 | {
|
---|
[33540] | 1195 | // ensure we don't have empty functions /* paranoia for for ATI on linux */
|
---|
[22816] | 1196 | apShaders[cShaders++] = &mShaderMainOverlayNoCKey;
|
---|
| 1197 | }
|
---|
| 1198 |
|
---|
| 1199 | Assert(cShaders <= RT_ELEMENTS(apShaders));
|
---|
| 1200 |
|
---|
[23162] | 1201 | VBoxVHWAGlShader shader(GL_FRAGMENT_SHADER, apShaders, cShaders);
|
---|
| 1202 | VBoxVHWAGlShader *pShader = &shader;
|
---|
| 1203 |
|
---|
| 1204 | VBoxVHWAGlProgramVHWA *pProgram = new VBoxVHWAGlProgramVHWA(/*this, */type, fourcc, &pShader, 1);
|
---|
[22816] | 1205 | pProgram->init();
|
---|
| 1206 |
|
---|
| 1207 | return pProgram;
|
---|
| 1208 | }
|
---|
| 1209 |
|
---|
[24646] | 1210 | VBoxVHWAGlProgramVHWA * VBoxVHWAGlProgramMngr::getProgram(uint32_t type, const VBoxVHWAColorFormat * pFrom, const VBoxVHWAColorFormat * pTo)
|
---|
[22816] | 1211 | {
|
---|
| 1212 | Q_UNUSED(pTo);
|
---|
| 1213 | uint32_t fourcc = 0;
|
---|
[24646] | 1214 | type &= VBOXVHWA_SUPPORTED_PROGRAM;
|
---|
| 1215 |
|
---|
[71651] | 1216 | if (pFrom && pFrom->fourcc())
|
---|
[22816] | 1217 | {
|
---|
[24646] | 1218 | fourcc = pFrom->fourcc();
|
---|
| 1219 | type |= VBOXVHWA_PROGRAM_COLORCONV;
|
---|
[22816] | 1220 | }
|
---|
[24646] | 1221 | else
|
---|
[71651] | 1222 | type &= ~VBOXVHWA_PROGRAM_COLORCONV;
|
---|
[24646] | 1223 |
|
---|
[71651] | 1224 | if ( !(type & VBOXVHWA_PROGRAM_DSTCOLORKEY)
|
---|
| 1225 | && !(type & VBOXVHWA_PROGRAM_SRCCOLORKEY))
|
---|
| 1226 | type &= ~VBOXVHWA_PROGRAM_COLORKEYNODISCARD;
|
---|
[24646] | 1227 |
|
---|
[71651] | 1228 | if (type)
|
---|
[22816] | 1229 | return searchProgram(type, fourcc, true);
|
---|
| 1230 | return NULL;
|
---|
| 1231 | }
|
---|
| 1232 |
|
---|
| 1233 | VBoxVHWAGlProgramVHWA * VBoxVHWAGlProgramMngr::searchProgram(uint32_t type, uint32_t fourcc, bool bCreate)
|
---|
| 1234 | {
|
---|
[71651] | 1235 | for (ProgramList::const_iterator it = mPrograms.begin(); it != mPrograms.end(); ++ it)
|
---|
[22816] | 1236 | {
|
---|
| 1237 | if (!(*it)->matches(type, fourcc))
|
---|
| 1238 | continue;
|
---|
| 1239 | return *it;
|
---|
| 1240 | }
|
---|
[71651] | 1241 | if (bCreate)
|
---|
[22816] | 1242 | {
|
---|
| 1243 | VBoxVHWAGlProgramVHWA *pProgram = createProgram(type, fourcc);
|
---|
[71651] | 1244 | if (pProgram)
|
---|
[22816] | 1245 | {
|
---|
| 1246 | mPrograms.push_back(pProgram);
|
---|
| 1247 | return pProgram;
|
---|
| 1248 | }
|
---|
| 1249 | }
|
---|
| 1250 | return NULL;
|
---|
| 1251 | }
|
---|
| 1252 |
|
---|
| 1253 | void VBoxVHWASurfaceBase::setAddress(uchar * addr)
|
---|
| 1254 | {
|
---|
| 1255 | Assert(addr);
|
---|
[71651] | 1256 | if (!addr)
|
---|
| 1257 | return;
|
---|
| 1258 | if (addr == mAddress)
|
---|
| 1259 | return;
|
---|
[22816] | 1260 |
|
---|
[71651] | 1261 | if (mFreeAddress)
|
---|
[22816] | 1262 | free(mAddress);
|
---|
| 1263 |
|
---|
| 1264 | mAddress = addr;
|
---|
| 1265 | mFreeAddress = false;
|
---|
| 1266 |
|
---|
[25385] | 1267 | mImage->setAddress(mAddress);
|
---|
[22816] | 1268 |
|
---|
| 1269 | mUpdateMem2TexRect.set(mRect);
|
---|
| 1270 | Assert(!mUpdateMem2TexRect.isClear());
|
---|
| 1271 | Assert(mRect.contains(mUpdateMem2TexRect.rect()));
|
---|
| 1272 | }
|
---|
| 1273 |
|
---|
| 1274 | void VBoxVHWASurfaceBase::globalInit()
|
---|
| 1275 | {
|
---|
| 1276 | VBOXQGLLOG(("globalInit\n"));
|
---|
| 1277 |
|
---|
| 1278 | glEnable(GL_TEXTURE_RECTANGLE);
|
---|
[24431] | 1279 | glDisable(GL_DEPTH_TEST);
|
---|
[22816] | 1280 |
|
---|
| 1281 | VBOXQGL_CHECKERR(
|
---|
| 1282 | glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
---|
| 1283 | );
|
---|
| 1284 | VBOXQGL_CHECKERR(
|
---|
| 1285 | glPixelStorei(GL_PACK_ALIGNMENT, 1);
|
---|
| 1286 | );
|
---|
| 1287 | }
|
---|
| 1288 |
|
---|
[27682] | 1289 | VBoxVHWASurfaceBase::VBoxVHWASurfaceBase(class VBoxVHWAImage *pImage,
|
---|
[71651] | 1290 | const QSize &aSize,
|
---|
| 1291 | const QRect &aTargRect,
|
---|
| 1292 | const QRect &aSrcRect,
|
---|
| 1293 | const QRect &aVisTargRect,
|
---|
| 1294 | VBoxVHWAColorFormat &aColorFormat,
|
---|
| 1295 | VBoxVHWAColorKey *pSrcBltCKey,
|
---|
| 1296 | VBoxVHWAColorKey *pDstBltCKey,
|
---|
| 1297 | VBoxVHWAColorKey *pSrcOverlayCKey,
|
---|
| 1298 | VBoxVHWAColorKey *pDstOverlayCKey,
|
---|
| 1299 | VBOXVHWAIMG_TYPE aImgFlags)
|
---|
| 1300 | : mRect(0,0,aSize.width(),aSize.height())
|
---|
| 1301 | , mAddress(NULL)
|
---|
| 1302 | , mpSrcBltCKey(NULL)
|
---|
| 1303 | , mpDstBltCKey(NULL)
|
---|
| 1304 | , mpSrcOverlayCKey(NULL)
|
---|
| 1305 | , mpDstOverlayCKey(NULL)
|
---|
| 1306 | , mpDefaultDstOverlayCKey(NULL)
|
---|
| 1307 | , mpDefaultSrcOverlayCKey(NULL)
|
---|
| 1308 | , mLockCount(0)
|
---|
| 1309 | , mFreeAddress(false)
|
---|
| 1310 | , mbNotIntersected(false)
|
---|
| 1311 | , mComplexList(NULL)
|
---|
| 1312 | , mpPrimary(NULL)
|
---|
| 1313 | , mHGHandle(VBOXVHWA_SURFHANDLE_INVALID)
|
---|
| 1314 | , mpImage(pImage)
|
---|
[22816] | 1315 | #ifdef DEBUG
|
---|
[71651] | 1316 | , cFlipsCurr(0)
|
---|
| 1317 | , cFlipsTarg(0)
|
---|
[22816] | 1318 | #endif
|
---|
| 1319 | {
|
---|
| 1320 | setDstBltCKey(pDstBltCKey);
|
---|
| 1321 | setSrcBltCKey(pSrcBltCKey);
|
---|
| 1322 |
|
---|
| 1323 | setDefaultDstOverlayCKey(pDstOverlayCKey);
|
---|
| 1324 | resetDefaultDstOverlayCKey();
|
---|
| 1325 |
|
---|
| 1326 | setDefaultSrcOverlayCKey(pSrcOverlayCKey);
|
---|
| 1327 | resetDefaultSrcOverlayCKey();
|
---|
| 1328 |
|
---|
[25583] | 1329 | mImage = vboxVHWAImageCreate(QRect(0,0,aSize.width(),aSize.height()), aColorFormat, getGlProgramMngr(), aImgFlags);
|
---|
[22816] | 1330 |
|
---|
[23766] | 1331 | setRectValues(aTargRect, aSrcRect);
|
---|
| 1332 | setVisibleRectValues(aVisTargRect);
|
---|
[22816] | 1333 | }
|
---|
| 1334 |
|
---|
| 1335 | VBoxVHWASurfaceBase::~VBoxVHWASurfaceBase()
|
---|
| 1336 | {
|
---|
| 1337 | uninit();
|
---|
| 1338 | }
|
---|
| 1339 |
|
---|
| 1340 | GLsizei VBoxVHWASurfaceBase::makePowerOf2(GLsizei val)
|
---|
| 1341 | {
|
---|
| 1342 | int last = ASMBitLastSetS32(val);
|
---|
[71651] | 1343 | if (last>1)
|
---|
[22816] | 1344 | {
|
---|
| 1345 | last--;
|
---|
[71651] | 1346 | if ((1 << last) != val)
|
---|
[22816] | 1347 | {
|
---|
| 1348 | Assert((1 << last) < val);
|
---|
| 1349 | val = (1 << (last+1));
|
---|
| 1350 | }
|
---|
| 1351 | }
|
---|
| 1352 | return val;
|
---|
| 1353 | }
|
---|
| 1354 |
|
---|
| 1355 | ulong VBoxVHWASurfaceBase::calcBytesPerPixel(GLenum format, GLenum type)
|
---|
| 1356 | {
|
---|
| 1357 | /* we now support only common byte-aligned data */
|
---|
| 1358 | int numComponents = 0;
|
---|
| 1359 | switch(format)
|
---|
| 1360 | {
|
---|
[71651] | 1361 | case GL_COLOR_INDEX:
|
---|
| 1362 | case GL_RED:
|
---|
| 1363 | case GL_GREEN:
|
---|
| 1364 | case GL_BLUE:
|
---|
| 1365 | case GL_ALPHA:
|
---|
| 1366 | case GL_LUMINANCE:
|
---|
| 1367 | numComponents = 1;
|
---|
| 1368 | break;
|
---|
| 1369 | case GL_RGB:
|
---|
| 1370 | case GL_BGR_EXT:
|
---|
| 1371 | numComponents = 3;
|
---|
| 1372 | break;
|
---|
| 1373 | case GL_RGBA:
|
---|
| 1374 | case GL_BGRA_EXT:
|
---|
| 1375 | numComponents = 4;
|
---|
| 1376 | break;
|
---|
| 1377 | case GL_LUMINANCE_ALPHA:
|
---|
| 1378 | numComponents = 2;
|
---|
| 1379 | break;
|
---|
| 1380 | default:
|
---|
| 1381 | AssertFailed();
|
---|
| 1382 | break;
|
---|
[22816] | 1383 | }
|
---|
| 1384 |
|
---|
| 1385 | int componentSize = 0;
|
---|
| 1386 | switch(type)
|
---|
| 1387 | {
|
---|
[71651] | 1388 | case GL_UNSIGNED_BYTE:
|
---|
| 1389 | case GL_BYTE:
|
---|
| 1390 | componentSize = 1;
|
---|
| 1391 | break;
|
---|
| 1392 | //case GL_BITMAP:
|
---|
| 1393 | case GL_UNSIGNED_SHORT:
|
---|
| 1394 | case GL_SHORT:
|
---|
| 1395 | componentSize = 2;
|
---|
| 1396 | break;
|
---|
| 1397 | case GL_UNSIGNED_INT:
|
---|
| 1398 | case GL_INT:
|
---|
| 1399 | case GL_FLOAT:
|
---|
| 1400 | componentSize = 4;
|
---|
| 1401 | break;
|
---|
| 1402 | default:
|
---|
| 1403 | AssertFailed();
|
---|
| 1404 | break;
|
---|
[22816] | 1405 | }
|
---|
| 1406 | return numComponents * componentSize;
|
---|
| 1407 | }
|
---|
| 1408 |
|
---|
| 1409 | void VBoxVHWASurfaceBase::uninit()
|
---|
| 1410 | {
|
---|
[25385] | 1411 | delete mImage;
|
---|
[22816] | 1412 |
|
---|
[71651] | 1413 | if (mAddress && mFreeAddress)
|
---|
[22816] | 1414 | {
|
---|
| 1415 | free(mAddress);
|
---|
| 1416 | mAddress = NULL;
|
---|
| 1417 | }
|
---|
| 1418 | }
|
---|
| 1419 |
|
---|
| 1420 | ulong VBoxVHWASurfaceBase::memSize()
|
---|
| 1421 | {
|
---|
[25385] | 1422 | return (ulong)mImage->memSize();
|
---|
[22816] | 1423 | }
|
---|
| 1424 |
|
---|
| 1425 | void VBoxVHWASurfaceBase::init(VBoxVHWASurfaceBase * pPrimary, uchar *pvMem)
|
---|
| 1426 | {
|
---|
[71651] | 1427 | if (pPrimary)
|
---|
[22816] | 1428 | {
|
---|
| 1429 | VBOXQGL_CHECKERR(
|
---|
| 1430 | vboxglActiveTexture(GL_TEXTURE1);
|
---|
| 1431 | );
|
---|
| 1432 | }
|
---|
| 1433 |
|
---|
| 1434 | int size = memSize();
|
---|
| 1435 | uchar * address = (uchar *)malloc(size);
|
---|
| 1436 | #ifdef DEBUG_misha
|
---|
[25385] | 1437 | int tex0Size = mImage->component(0)->memSize();
|
---|
[71651] | 1438 | if (pPrimary)
|
---|
[22816] | 1439 | {
|
---|
| 1440 | memset(address, 0xff, tex0Size);
|
---|
| 1441 | Assert(size >= tex0Size);
|
---|
[71651] | 1442 | if (size > tex0Size)
|
---|
[22816] | 1443 | memset(address + tex0Size, 0x0, size - tex0Size);
|
---|
| 1444 | }
|
---|
| 1445 | else
|
---|
| 1446 | {
|
---|
| 1447 | memset(address, 0x0f, tex0Size);
|
---|
| 1448 | Assert(size >= tex0Size);
|
---|
[71651] | 1449 | if (size > tex0Size)
|
---|
[22816] | 1450 | memset(address + tex0Size, 0x3f, size - tex0Size);
|
---|
| 1451 | }
|
---|
| 1452 | #else
|
---|
| 1453 | memset(address, 0, size);
|
---|
| 1454 | #endif
|
---|
| 1455 |
|
---|
[25385] | 1456 | mImage->init(address);
|
---|
| 1457 | mpPrimary = pPrimary;
|
---|
[22816] | 1458 |
|
---|
[71651] | 1459 | if (pvMem)
|
---|
[22816] | 1460 | {
|
---|
| 1461 | mAddress = pvMem;
|
---|
| 1462 | free(address);
|
---|
| 1463 | mFreeAddress = false;
|
---|
| 1464 |
|
---|
| 1465 | }
|
---|
| 1466 | else
|
---|
| 1467 | {
|
---|
| 1468 | mAddress = address;
|
---|
| 1469 | mFreeAddress = true;
|
---|
| 1470 | }
|
---|
| 1471 |
|
---|
[25385] | 1472 | mImage->setAddress(mAddress);
|
---|
[22816] | 1473 |
|
---|
[25385] | 1474 | initDisplay();
|
---|
[22816] | 1475 |
|
---|
| 1476 | mUpdateMem2TexRect.set(mRect);
|
---|
| 1477 | Assert(!mUpdateMem2TexRect.isClear());
|
---|
| 1478 | Assert(mRect.contains(mUpdateMem2TexRect.rect()));
|
---|
| 1479 |
|
---|
[71651] | 1480 | if (pPrimary)
|
---|
[22816] | 1481 | {
|
---|
| 1482 | VBOXQGLLOG(("restoring to tex 0"));
|
---|
| 1483 | VBOXQGL_CHECKERR(
|
---|
| 1484 | vboxglActiveTexture(GL_TEXTURE0);
|
---|
| 1485 | );
|
---|
| 1486 | }
|
---|
| 1487 |
|
---|
| 1488 | }
|
---|
| 1489 |
|
---|
[71651] | 1490 | void VBoxVHWATexture::doUpdate(uchar *pAddress, const QRect *pRect)
|
---|
[22816] | 1491 | {
|
---|
| 1492 | GLenum tt = texTarget();
|
---|
[71651] | 1493 | if (pRect)
|
---|
[22816] | 1494 | Assert(mRect.contains(*pRect));
|
---|
| 1495 | else
|
---|
| 1496 | pRect = &mRect;
|
---|
| 1497 |
|
---|
| 1498 | Assert(glIsTexture(mTexture));
|
---|
| 1499 | VBOXQGL_CHECKERR(
|
---|
| 1500 | glBindTexture(tt, mTexture);
|
---|
| 1501 | );
|
---|
| 1502 |
|
---|
| 1503 | int x = pRect->x()/mColorFormat.widthCompression();
|
---|
| 1504 | int y = pRect->y()/mColorFormat.heightCompression();
|
---|
| 1505 | int width = pRect->width()/mColorFormat.widthCompression();
|
---|
| 1506 | int height = pRect->height()/mColorFormat.heightCompression();
|
---|
| 1507 |
|
---|
[71651] | 1508 | uchar *address = pAddress + pointOffsetTex(x, y);
|
---|
[22816] | 1509 |
|
---|
| 1510 | VBOXQGL_CHECKERR(
|
---|
[35280] | 1511 | glPixelStorei(GL_UNPACK_ROW_LENGTH, mBytesPerLine * 8 /mColorFormat.bitsPerPixelTex());
|
---|
[22816] | 1512 | );
|
---|
| 1513 |
|
---|
| 1514 | VBOXQGL_CHECKERR(
|
---|
| 1515 | glTexSubImage2D(tt,
|
---|
| 1516 | 0,
|
---|
| 1517 | x, y, width, height,
|
---|
| 1518 | mColorFormat.format(),
|
---|
| 1519 | mColorFormat.type(),
|
---|
| 1520 | address);
|
---|
| 1521 | );
|
---|
[35280] | 1522 |
|
---|
| 1523 | VBOXQGL_CHECKERR(
|
---|
| 1524 | glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
|
---|
| 1525 | );
|
---|
[22816] | 1526 | }
|
---|
| 1527 |
|
---|
| 1528 | void VBoxVHWATexture::texCoord(int x, int y)
|
---|
| 1529 | {
|
---|
[71651] | 1530 | glTexCoord2f(((float)x)/mTexRect.width()/mColorFormat.widthCompression(),
|
---|
| 1531 | ((float)y)/mTexRect.height()/mColorFormat.heightCompression());
|
---|
[22816] | 1532 | }
|
---|
| 1533 |
|
---|
| 1534 | void VBoxVHWATexture::multiTexCoord(GLenum texUnit, int x, int y)
|
---|
| 1535 | {
|
---|
[71651] | 1536 | vboxglMultiTexCoord2f(texUnit, ((float)x)/mTexRect.width()/mColorFormat.widthCompression(),
|
---|
| 1537 | ((float)y)/mTexRect.height()/mColorFormat.heightCompression());
|
---|
[22816] | 1538 | }
|
---|
| 1539 |
|
---|
| 1540 | void VBoxVHWATexture::uninit()
|
---|
| 1541 | {
|
---|
[71651] | 1542 | if (mTexture)
|
---|
[22816] | 1543 | glDeleteTextures(1,&mTexture);
|
---|
| 1544 | }
|
---|
| 1545 |
|
---|
[71651] | 1546 | VBoxVHWATexture::VBoxVHWATexture(const QRect & aRect, const VBoxVHWAColorFormat &aFormat,
|
---|
| 1547 | uint32_t bytesPerLine, GLint scaleFuncttion)
|
---|
| 1548 | : mAddress(NULL)
|
---|
| 1549 | , mTexture(0)
|
---|
| 1550 | , mBytesPerPixel(0)
|
---|
| 1551 | , mBytesPerPixelTex(0)
|
---|
| 1552 | , mBytesPerLine(0)
|
---|
| 1553 | , mScaleFuncttion(scaleFuncttion)
|
---|
[22816] | 1554 | {
|
---|
[71651] | 1555 | mColorFormat = aFormat;
|
---|
| 1556 | mRect = aRect;
|
---|
| 1557 | mBytesPerPixel = mColorFormat.bitsPerPixel() / 8;
|
---|
| 1558 | mBytesPerPixelTex = mColorFormat.bitsPerPixelTex() / 8;
|
---|
| 1559 | mBytesPerLine = bytesPerLine ? bytesPerLine : mBytesPerPixel * mRect.width();
|
---|
| 1560 | GLsizei wdt = VBoxVHWASurfaceBase::makePowerOf2(mRect.width() / mColorFormat.widthCompression());
|
---|
| 1561 | GLsizei hgt = VBoxVHWASurfaceBase::makePowerOf2(mRect.height() / mColorFormat.heightCompression());
|
---|
[22816] | 1562 | mTexRect = QRect(0,0,wdt,hgt);
|
---|
| 1563 | }
|
---|
| 1564 |
|
---|
[34461] | 1565 | #ifdef DEBUG_misha
|
---|
| 1566 | void VBoxVHWATexture::dbgDump()
|
---|
| 1567 | {
|
---|
| 1568 | #if 0
|
---|
| 1569 | bind();
|
---|
| 1570 | GLvoid *pvBuf = malloc(4 * mRect.width() * mRect.height());
|
---|
| 1571 | VBOXQGL_CHECKERR(
|
---|
| 1572 | glGetTexImage(texTarget(),
|
---|
| 1573 | 0, /*GLint level*/
|
---|
| 1574 | mColorFormat.format(),
|
---|
| 1575 | mColorFormat.type(),
|
---|
| 1576 | pvBuf);
|
---|
| 1577 | );
|
---|
| 1578 | VBOXQGLDBGPRINT(("<?dml?><exec cmd=\"!vbvdbg.ms 0x%p 0n%d 0n%d\">texture info</exec>\n",
|
---|
| 1579 | pvBuf, mRect.width(), mRect.height()));
|
---|
[49940] | 1580 | AssertFailed();
|
---|
[34461] | 1581 |
|
---|
| 1582 | free(pvBuf);
|
---|
| 1583 | #endif
|
---|
| 1584 | }
|
---|
| 1585 | #endif
|
---|
| 1586 |
|
---|
| 1587 |
|
---|
[22816] | 1588 | void VBoxVHWATexture::initParams()
|
---|
| 1589 | {
|
---|
| 1590 | GLenum tt = texTarget();
|
---|
| 1591 |
|
---|
[25470] | 1592 | glTexParameteri(tt, GL_TEXTURE_MIN_FILTER, mScaleFuncttion);
|
---|
[22816] | 1593 | VBOXQGL_ASSERTNOERR();
|
---|
[25470] | 1594 | glTexParameteri(tt, GL_TEXTURE_MAG_FILTER, mScaleFuncttion);
|
---|
[22816] | 1595 | VBOXQGL_ASSERTNOERR();
|
---|
| 1596 | glTexParameteri(tt, GL_TEXTURE_WRAP_S, GL_CLAMP);
|
---|
| 1597 | VBOXQGL_ASSERTNOERR();
|
---|
| 1598 |
|
---|
| 1599 | glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
---|
| 1600 | VBOXQGL_ASSERTNOERR();
|
---|
| 1601 | glPixelStorei(GL_PACK_ALIGNMENT, 1);
|
---|
| 1602 | VBOXQGL_ASSERTNOERR();
|
---|
| 1603 |
|
---|
| 1604 | glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
|
---|
| 1605 | VBOXQGL_ASSERTNOERR();
|
---|
| 1606 | }
|
---|
| 1607 |
|
---|
| 1608 | void VBoxVHWATexture::load()
|
---|
| 1609 | {
|
---|
| 1610 | VBOXQGL_CHECKERR(
|
---|
| 1611 | glPixelStorei(GL_UNPACK_ROW_LENGTH, mTexRect.width());
|
---|
| 1612 | );
|
---|
| 1613 |
|
---|
| 1614 | VBOXQGL_CHECKERR(
|
---|
| 1615 | glTexImage2D(texTarget(),
|
---|
| 1616 | 0,
|
---|
| 1617 | mColorFormat.internalFormat(),
|
---|
| 1618 | mTexRect.width(),
|
---|
| 1619 | mTexRect.height(),
|
---|
| 1620 | 0,
|
---|
| 1621 | mColorFormat.format(),
|
---|
| 1622 | mColorFormat.type(),
|
---|
| 1623 | (GLvoid *)mAddress);
|
---|
| 1624 | );
|
---|
| 1625 | }
|
---|
| 1626 |
|
---|
| 1627 | void VBoxVHWATexture::init(uchar *pvMem)
|
---|
| 1628 | {
|
---|
| 1629 | // GLsizei wdt = mTexRect.width();
|
---|
| 1630 | // GLsizei hgt = mTexRect.height();
|
---|
| 1631 |
|
---|
| 1632 | VBOXQGL_CHECKERR(
|
---|
| 1633 | glGenTextures(1, &mTexture);
|
---|
| 1634 | );
|
---|
| 1635 |
|
---|
| 1636 | VBOXQGLLOG(("tex: %d", mTexture));
|
---|
| 1637 |
|
---|
| 1638 | bind();
|
---|
| 1639 |
|
---|
| 1640 | initParams();
|
---|
| 1641 |
|
---|
| 1642 | setAddress(pvMem);
|
---|
| 1643 |
|
---|
| 1644 | load();
|
---|
| 1645 | }
|
---|
| 1646 |
|
---|
| 1647 | VBoxVHWATexture::~VBoxVHWATexture()
|
---|
| 1648 | {
|
---|
| 1649 | uninit();
|
---|
| 1650 | }
|
---|
| 1651 |
|
---|
| 1652 | void VBoxVHWATextureNP2Rect::texCoord(int x, int y)
|
---|
| 1653 | {
|
---|
[23346] | 1654 | glTexCoord2i(x/mColorFormat.widthCompression(), y/mColorFormat.heightCompression());
|
---|
[22816] | 1655 | }
|
---|
| 1656 |
|
---|
| 1657 | void VBoxVHWATextureNP2Rect::multiTexCoord(GLenum texUnit, int x, int y)
|
---|
| 1658 | {
|
---|
[23346] | 1659 | vboxglMultiTexCoord2i(texUnit, x/mColorFormat.widthCompression(), y/mColorFormat.heightCompression());
|
---|
[22816] | 1660 | }
|
---|
| 1661 |
|
---|
[71651] | 1662 | GLenum VBoxVHWATextureNP2Rect::texTarget()
|
---|
| 1663 | {
|
---|
| 1664 | return GL_TEXTURE_RECTANGLE;
|
---|
| 1665 | }
|
---|
[22816] | 1666 |
|
---|
[22846] | 1667 | bool VBoxVHWASurfaceBase::synchTexMem(const QRect * pRect)
|
---|
[22816] | 1668 | {
|
---|
[71651] | 1669 | if (pRect)
|
---|
[22816] | 1670 | Assert(mRect.contains(*pRect));
|
---|
| 1671 |
|
---|
[71651] | 1672 | if (mUpdateMem2TexRect.isClear())
|
---|
[22846] | 1673 | return false;
|
---|
[22816] | 1674 |
|
---|
[71651] | 1675 | if (pRect && !mUpdateMem2TexRect.rect().intersects(*pRect))
|
---|
[22846] | 1676 | return false;
|
---|
[22816] | 1677 |
|
---|
[24646] | 1678 | #ifdef VBOXVHWA_PROFILE_FPS
|
---|
[27682] | 1679 | mpImage->reportNewFrame();
|
---|
[24646] | 1680 | #endif
|
---|
| 1681 |
|
---|
[25385] | 1682 | mImage->update(&mUpdateMem2TexRect.rect());
|
---|
[22816] | 1683 |
|
---|
| 1684 | mUpdateMem2TexRect.clear();
|
---|
| 1685 | Assert(mUpdateMem2TexRect.isClear());
|
---|
[25264] | 1686 |
|
---|
[22846] | 1687 | return true;
|
---|
[22816] | 1688 | }
|
---|
| 1689 |
|
---|
| 1690 | void VBoxVHWATextureNP2RectPBO::init(uchar *pvMem)
|
---|
| 1691 | {
|
---|
| 1692 | VBOXQGL_CHECKERR(
|
---|
| 1693 | vboxglGenBuffers(1, &mPBO);
|
---|
| 1694 | );
|
---|
| 1695 | VBoxVHWATextureNP2Rect::init(pvMem);
|
---|
| 1696 | }
|
---|
| 1697 |
|
---|
[71651] | 1698 | void VBoxVHWATextureNP2RectPBO::doUpdate(uchar *pAddress, const QRect *pRect)
|
---|
[22816] | 1699 | {
|
---|
| 1700 | Q_UNUSED(pAddress);
|
---|
| 1701 | Q_UNUSED(pRect);
|
---|
| 1702 |
|
---|
| 1703 | vboxglBindBuffer(GL_PIXEL_UNPACK_BUFFER, mPBO);
|
---|
| 1704 |
|
---|
[22920] | 1705 | GLvoid *buf;
|
---|
[22816] | 1706 |
|
---|
[22920] | 1707 | VBOXQGL_CHECKERR(
|
---|
| 1708 | buf = vboxglMapBuffer(GL_PIXEL_UNPACK_BUFFER, GL_WRITE_ONLY);
|
---|
| 1709 | );
|
---|
| 1710 | Assert(buf);
|
---|
[71651] | 1711 | if (buf)
|
---|
[22920] | 1712 | {
|
---|
| 1713 | memcpy(buf, mAddress, memSize());
|
---|
[22816] | 1714 |
|
---|
[22920] | 1715 | bool unmapped;
|
---|
| 1716 | VBOXQGL_CHECKERR(
|
---|
| 1717 | unmapped = vboxglUnmapBuffer(GL_PIXEL_UNPACK_BUFFER);
|
---|
| 1718 | );
|
---|
[22816] | 1719 |
|
---|
[35500] | 1720 | Assert(unmapped); NOREF(unmapped);
|
---|
[22816] | 1721 |
|
---|
[22920] | 1722 | VBoxVHWATextureNP2Rect::doUpdate(0, &mRect);
|
---|
| 1723 |
|
---|
| 1724 | vboxglBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
|
---|
| 1725 | }
|
---|
| 1726 | else
|
---|
| 1727 | {
|
---|
| 1728 | VBOXQGLLOGREL(("failed to map PBO, trying fallback to non-PBO approach\n"));
|
---|
| 1729 | /* try fallback to non-PBO approach */
|
---|
| 1730 | vboxglBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
|
---|
| 1731 | VBoxVHWATextureNP2Rect::doUpdate(pAddress, pRect);
|
---|
| 1732 | }
|
---|
[22816] | 1733 | }
|
---|
| 1734 |
|
---|
| 1735 | VBoxVHWATextureNP2RectPBO::~VBoxVHWATextureNP2RectPBO()
|
---|
| 1736 | {
|
---|
| 1737 | VBOXQGL_CHECKERR(
|
---|
| 1738 | vboxglDeleteBuffers(1, &mPBO);
|
---|
| 1739 | );
|
---|
| 1740 | }
|
---|
| 1741 |
|
---|
| 1742 |
|
---|
| 1743 | void VBoxVHWATextureNP2RectPBO::load()
|
---|
| 1744 | {
|
---|
| 1745 | VBoxVHWATextureNP2Rect::load();
|
---|
| 1746 |
|
---|
[23550] | 1747 | VBOXQGL_CHECKERR(
|
---|
| 1748 | vboxglBindBuffer(GL_PIXEL_UNPACK_BUFFER, mPBO);
|
---|
| 1749 | );
|
---|
[22816] | 1750 |
|
---|
[23550] | 1751 | VBOXQGL_CHECKERR(
|
---|
| 1752 | vboxglBufferData(GL_PIXEL_UNPACK_BUFFER, memSize(), NULL, GL_STREAM_DRAW);
|
---|
| 1753 | );
|
---|
[22816] | 1754 |
|
---|
| 1755 | GLvoid *buf = vboxglMapBuffer(GL_PIXEL_UNPACK_BUFFER, GL_WRITE_ONLY);
|
---|
[23550] | 1756 | Assert(buf);
|
---|
[71651] | 1757 | if (buf)
|
---|
[23550] | 1758 | {
|
---|
| 1759 | memcpy(buf, mAddress, memSize());
|
---|
[22816] | 1760 |
|
---|
[23550] | 1761 | bool unmapped = vboxglUnmapBuffer(GL_PIXEL_UNPACK_BUFFER);
|
---|
| 1762 | Assert(unmapped); NOREF(unmapped);
|
---|
| 1763 | }
|
---|
[22816] | 1764 |
|
---|
| 1765 | vboxglBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
|
---|
| 1766 | }
|
---|
| 1767 |
|
---|
[25257] | 1768 | uchar* VBoxVHWATextureNP2RectPBOMapped::mapAlignedBuffer()
|
---|
[22816] | 1769 | {
|
---|
[25257] | 1770 | Assert(!mpMappedAllignedBuffer);
|
---|
[71651] | 1771 | if (!mpMappedAllignedBuffer)
|
---|
[22816] | 1772 | {
|
---|
[25257] | 1773 | VBOXQGL_CHECKERR(
|
---|
| 1774 | vboxglBindBuffer(GL_PIXEL_UNPACK_BUFFER, mPBO);
|
---|
| 1775 | );
|
---|
[22816] | 1776 |
|
---|
[25257] | 1777 | uchar* buf;
|
---|
| 1778 | VBOXQGL_CHECKERR(
|
---|
| 1779 | buf = (uchar*)vboxglMapBuffer(GL_PIXEL_UNPACK_BUFFER, GL_READ_WRITE);
|
---|
| 1780 | );
|
---|
[22816] | 1781 |
|
---|
[25257] | 1782 | Assert(buf);
|
---|
[22816] | 1783 |
|
---|
[25257] | 1784 | VBOXQGL_CHECKERR(
|
---|
| 1785 | vboxglBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
|
---|
[22816] | 1786 | );
|
---|
| 1787 |
|
---|
[25257] | 1788 | mpMappedAllignedBuffer = (uchar*)alignBuffer(buf);
|
---|
[22816] | 1789 |
|
---|
[25257] | 1790 | mcbOffset = calcOffset(buf, mpMappedAllignedBuffer);
|
---|
[22816] | 1791 | }
|
---|
[25257] | 1792 | return mpMappedAllignedBuffer;
|
---|
[22816] | 1793 | }
|
---|
| 1794 |
|
---|
[25385] | 1795 | void VBoxVHWATextureNP2RectPBOMapped::unmapBuffer()
|
---|
[22816] | 1796 | {
|
---|
[25257] | 1797 | Assert(mpMappedAllignedBuffer);
|
---|
[71651] | 1798 | if (mpMappedAllignedBuffer)
|
---|
[22816] | 1799 | {
|
---|
| 1800 | VBOXQGL_CHECKERR(
|
---|
[25257] | 1801 | vboxglBindBuffer(GL_PIXEL_UNPACK_BUFFER, mPBO);
|
---|
| 1802 | );
|
---|
[22816] | 1803 |
|
---|
[25257] | 1804 | bool unmapped;
|
---|
[22816] | 1805 | VBOXQGL_CHECKERR(
|
---|
[25257] | 1806 | unmapped = vboxglUnmapBuffer(GL_PIXEL_UNPACK_BUFFER);
|
---|
[22816] | 1807 | );
|
---|
| 1808 |
|
---|
[35500] | 1809 | Assert(unmapped); NOREF(unmapped);
|
---|
[22816] | 1810 |
|
---|
| 1811 | VBOXQGL_CHECKERR(
|
---|
[25257] | 1812 | vboxglBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
|
---|
| 1813 | );
|
---|
[22816] | 1814 |
|
---|
[25257] | 1815 | mpMappedAllignedBuffer = NULL;
|
---|
[22816] | 1816 | }
|
---|
| 1817 | }
|
---|
| 1818 |
|
---|
[25257] | 1819 | void VBoxVHWATextureNP2RectPBOMapped::load()
|
---|
[22816] | 1820 | {
|
---|
[25257] | 1821 | VBoxVHWATextureNP2Rect::load();
|
---|
[22816] | 1822 |
|
---|
[25257] | 1823 | VBOXQGL_CHECKERR(
|
---|
| 1824 | vboxglBindBuffer(GL_PIXEL_UNPACK_BUFFER, mPBO);
|
---|
| 1825 | );
|
---|
[22816] | 1826 |
|
---|
[25257] | 1827 | VBOXQGL_CHECKERR(
|
---|
| 1828 | vboxglBufferData(GL_PIXEL_UNPACK_BUFFER, mcbActualBufferSize, NULL, GL_STREAM_DRAW);
|
---|
| 1829 | );
|
---|
[22816] | 1830 |
|
---|
[25257] | 1831 | vboxglBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
|
---|
[22816] | 1832 | }
|
---|
| 1833 |
|
---|
[71651] | 1834 | void VBoxVHWATextureNP2RectPBOMapped::doUpdate(uchar *pAddress, const QRect *pRect)
|
---|
[22816] | 1835 | {
|
---|
[25257] | 1836 | Q_UNUSED(pAddress);
|
---|
| 1837 | Q_UNUSED(pRect);
|
---|
[22816] | 1838 |
|
---|
[25257] | 1839 | VBOXQGL_CHECKERR(
|
---|
| 1840 | vboxglBindBuffer(GL_PIXEL_UNPACK_BUFFER, mPBO);
|
---|
| 1841 | );
|
---|
| 1842 |
|
---|
[71651] | 1843 | if (mpMappedAllignedBuffer)
|
---|
[22816] | 1844 | {
|
---|
[25257] | 1845 | bool unmapped;
|
---|
| 1846 | VBOXQGL_CHECKERR(
|
---|
| 1847 | unmapped = vboxglUnmapBuffer(GL_PIXEL_UNPACK_BUFFER);
|
---|
| 1848 | );
|
---|
[22816] | 1849 |
|
---|
[35500] | 1850 | Assert(unmapped); NOREF(unmapped);
|
---|
[22816] | 1851 |
|
---|
[25257] | 1852 | mpMappedAllignedBuffer = NULL;
|
---|
| 1853 | }
|
---|
[22816] | 1854 |
|
---|
[25257] | 1855 | VBoxVHWATextureNP2Rect::doUpdate((uchar *)mcbOffset, &mRect);
|
---|
[22816] | 1856 |
|
---|
[25257] | 1857 | VBOXQGL_CHECKERR(
|
---|
| 1858 | vboxglBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
|
---|
| 1859 | );
|
---|
[22816] | 1860 | }
|
---|
[25257] | 1861 |
|
---|
[71651] | 1862 | int VBoxVHWASurfaceBase::lock(const QRect *pRect, uint32_t flags)
|
---|
[22816] | 1863 | {
|
---|
| 1864 | Q_UNUSED(flags);
|
---|
| 1865 |
|
---|
[71651] | 1866 | if (pRect)
|
---|
[22816] | 1867 | Assert(mRect.contains(*pRect));
|
---|
| 1868 |
|
---|
| 1869 | Assert(mLockCount >= 0);
|
---|
[71651] | 1870 | if (pRect && pRect->isEmpty())
|
---|
[22816] | 1871 | return VERR_GENERAL_FAILURE;
|
---|
[71651] | 1872 | if (mLockCount < 0)
|
---|
[22816] | 1873 | return VERR_GENERAL_FAILURE;
|
---|
| 1874 |
|
---|
| 1875 | VBOXQGLLOG(("lock (0x%x)", this));
|
---|
| 1876 | VBOXQGLLOG_QRECT("rect: ", pRect ? pRect : &mRect, "\n");
|
---|
| 1877 | VBOXQGLLOG_METHODTIME("time ");
|
---|
| 1878 |
|
---|
| 1879 | mUpdateMem2TexRect.add(pRect ? *pRect : mRect);
|
---|
| 1880 |
|
---|
| 1881 | Assert(!mUpdateMem2TexRect.isClear());
|
---|
| 1882 | Assert(mRect.contains(mUpdateMem2TexRect.rect()));
|
---|
| 1883 | return VINF_SUCCESS;
|
---|
| 1884 | }
|
---|
| 1885 |
|
---|
| 1886 | int VBoxVHWASurfaceBase::unlock()
|
---|
| 1887 | {
|
---|
| 1888 | VBOXQGLLOG(("unlock (0x%x)\n", this));
|
---|
| 1889 | mLockCount = 0;
|
---|
| 1890 | return VINF_SUCCESS;
|
---|
| 1891 | }
|
---|
| 1892 |
|
---|
[71651] | 1893 | void VBoxVHWASurfaceBase::setRectValues (const QRect &aTargRect, const QRect &aSrcRect)
|
---|
[22816] | 1894 | {
|
---|
| 1895 | mTargRect = aTargRect;
|
---|
| 1896 | mSrcRect = aSrcRect;
|
---|
[23766] | 1897 | }
|
---|
| 1898 |
|
---|
[71651] | 1899 | void VBoxVHWASurfaceBase::setVisibleRectValues (const QRect &aVisTargRect)
|
---|
[23766] | 1900 | {
|
---|
| 1901 | mVisibleTargRect = aVisTargRect.intersected(mTargRect);
|
---|
[71651] | 1902 | if (mVisibleTargRect.isEmpty() || mTargRect.isEmpty())
|
---|
[22816] | 1903 | mVisibleSrcRect.setSize(QSize(0, 0));
|
---|
| 1904 | else
|
---|
| 1905 | {
|
---|
| 1906 | float stretchX = float(mSrcRect.width()) / mTargRect.width();
|
---|
| 1907 | float stretchY = float(mSrcRect.height()) / mTargRect.height();
|
---|
| 1908 | int tx1, tx2, ty1, ty2, vtx1, vtx2, vty1, vty2;
|
---|
| 1909 | int sx1, sx2, sy1, sy2;
|
---|
| 1910 | mVisibleTargRect.getCoords(&vtx1, &vty1, &vtx2, &vty2);
|
---|
| 1911 | mTargRect.getCoords(&tx1, &ty1, &tx2, &ty2);
|
---|
| 1912 | mSrcRect.getCoords(&sx1, &sy1, &sx2, &sy2);
|
---|
| 1913 | int dx1 = vtx1 - tx1;
|
---|
| 1914 | int dy1 = vty1 - ty1;
|
---|
| 1915 | int dx2 = vtx2 - tx2;
|
---|
| 1916 | int dy2 = vty2 - ty2;
|
---|
| 1917 | int vsx1, vsy1, vsx2, vsy2;
|
---|
| 1918 | Assert(dx1 >= 0);
|
---|
| 1919 | Assert(dy1 >= 0);
|
---|
| 1920 | Assert(dx2 <= 0);
|
---|
| 1921 | Assert(dy2 <= 0);
|
---|
| 1922 | vsx1 = sx1 + int(dx1*stretchX);
|
---|
| 1923 | vsy1 = sy1 + int(dy1*stretchY);
|
---|
| 1924 | vsx2 = sx2 + int(dx2*stretchX);
|
---|
| 1925 | vsy2 = sy2 + int(dy2*stretchY);
|
---|
| 1926 | mVisibleSrcRect.setCoords(vsx1, vsy1, vsx2, vsy2);
|
---|
| 1927 | Assert(!mVisibleSrcRect.isEmpty());
|
---|
| 1928 | Assert(mSrcRect.contains(mVisibleSrcRect));
|
---|
| 1929 | }
|
---|
| 1930 | }
|
---|
| 1931 |
|
---|
[23766] | 1932 |
|
---|
| 1933 | void VBoxVHWASurfaceBase::setRects(const QRect & aTargRect, const QRect & aSrcRect)
|
---|
[22816] | 1934 | {
|
---|
[71651] | 1935 | if (mTargRect != aTargRect || mSrcRect != aSrcRect)
|
---|
[23766] | 1936 | setRectValues(aTargRect, aSrcRect);
|
---|
[22816] | 1937 | }
|
---|
| 1938 |
|
---|
[23766] | 1939 | void VBoxVHWASurfaceBase::setTargRectPosition(const QPoint & aPoint)
|
---|
[22816] | 1940 | {
|
---|
| 1941 | QRect tRect = targRect();
|
---|
| 1942 | tRect.moveTopLeft(aPoint);
|
---|
[23766] | 1943 | setRects(tRect, srcRect());
|
---|
[22816] | 1944 | }
|
---|
| 1945 |
|
---|
[71651] | 1946 | void VBoxVHWASurfaceBase::updateVisibility(VBoxVHWASurfaceBase *pPrimary, const QRect & aVisibleTargRect,
|
---|
| 1947 | bool bNotIntersected, bool bForce)
|
---|
[22816] | 1948 | {
|
---|
[71651] | 1949 | if (bForce || aVisibleTargRect.intersected(mTargRect) != mVisibleTargRect)
|
---|
[23766] | 1950 | setVisibleRectValues(aVisibleTargRect);
|
---|
[22816] | 1951 |
|
---|
[25385] | 1952 | mpPrimary = pPrimary;
|
---|
| 1953 | mbNotIntersected = bNotIntersected;
|
---|
[22816] | 1954 |
|
---|
[25385] | 1955 | initDisplay();
|
---|
[22816] | 1956 | }
|
---|
| 1957 |
|
---|
[25385] | 1958 | void VBoxVHWASurfaceBase::initDisplay()
|
---|
[22816] | 1959 | {
|
---|
[71651] | 1960 | if (mVisibleTargRect.isEmpty() || mVisibleSrcRect.isEmpty())
|
---|
[22816] | 1961 | {
|
---|
[25385] | 1962 | Assert(mVisibleTargRect.isEmpty() && mVisibleSrcRect.isEmpty());
|
---|
| 1963 | mImage->deleteDisplay();
|
---|
| 1964 | return;
|
---|
[22816] | 1965 | }
|
---|
| 1966 |
|
---|
[71651] | 1967 | int rc = mImage->initDisplay(mpPrimary ? mpPrimary->mImage : NULL, &mVisibleTargRect, &mVisibleSrcRect,
|
---|
| 1968 | getActiveDstOverlayCKey(mpPrimary), getActiveSrcOverlayCKey(), mbNotIntersected);
|
---|
[24646] | 1969 | AssertRC(rc);
|
---|
[22816] | 1970 | }
|
---|
| 1971 |
|
---|
| 1972 | void VBoxVHWASurfaceBase::updatedMem(const QRect *rec)
|
---|
| 1973 | {
|
---|
[71651] | 1974 | if (rec)
|
---|
[22816] | 1975 | Assert(mRect.contains(*rec));
|
---|
| 1976 | mUpdateMem2TexRect.add(*rec);
|
---|
| 1977 | }
|
---|
| 1978 |
|
---|
[22846] | 1979 | bool VBoxVHWASurfaceBase::performDisplay(VBoxVHWASurfaceBase *pPrimary, bool bForce)
|
---|
[22816] | 1980 | {
|
---|
[25385] | 1981 | Assert(mImage->displayInitialized());
|
---|
[24646] | 1982 |
|
---|
[71651] | 1983 | if (mVisibleTargRect.isEmpty())
|
---|
[22816] | 1984 | {
|
---|
| 1985 | /* nothing to display, i.e. the surface is not visible,
|
---|
| 1986 | * in the sense that it's located behind the viewport ranges */
|
---|
| 1987 | Assert(mVisibleSrcRect.isEmpty());
|
---|
[22846] | 1988 | return false;
|
---|
[22816] | 1989 | }
|
---|
[71651] | 1990 | Assert(!mVisibleSrcRect.isEmpty());
|
---|
[22816] | 1991 |
|
---|
[22846] | 1992 | bForce |= synchTexMem(&mVisibleSrcRect);
|
---|
[25385] | 1993 |
|
---|
| 1994 | const VBoxVHWAColorKey * pDstCKey = getActiveDstOverlayCKey(pPrimary);
|
---|
[71651] | 1995 | if (pPrimary && pDstCKey)
|
---|
[22846] | 1996 | bForce |= pPrimary->synchTexMem(&mVisibleTargRect);
|
---|
[22816] | 1997 |
|
---|
[71651] | 1998 | if (!bForce)
|
---|
[22846] | 1999 | return false;
|
---|
| 2000 |
|
---|
[25385] | 2001 | mImage->display();
|
---|
[22921] | 2002 |
|
---|
[22846] | 2003 | Assert(bForce);
|
---|
| 2004 | return true;
|
---|
[22816] | 2005 | }
|
---|
| 2006 |
|
---|
[25385] | 2007 | class VBoxVHWAGlProgramMngr * VBoxVHWASurfaceBase::getGlProgramMngr()
|
---|
| 2008 | {
|
---|
[27682] | 2009 | return mpImage->vboxVHWAGetGlProgramMngr();
|
---|
[25385] | 2010 | }
|
---|
| 2011 |
|
---|
[23630] | 2012 | class VBoxGLContext : public QGLContext
|
---|
| 2013 | {
|
---|
| 2014 | public:
|
---|
[71651] | 2015 | VBoxGLContext (const QGLFormat & format )
|
---|
| 2016 | : QGLContext(format)
|
---|
| 2017 | , mAllowDoneCurrent(true)
|
---|
[23630] | 2018 | {
|
---|
| 2019 | }
|
---|
[22816] | 2020 |
|
---|
[23630] | 2021 | void doneCurrent()
|
---|
| 2022 | {
|
---|
[71651] | 2023 | if (!mAllowDoneCurrent)
|
---|
[23630] | 2024 | return;
|
---|
| 2025 | QGLContext::doneCurrent();
|
---|
| 2026 | }
|
---|
| 2027 |
|
---|
| 2028 | bool isDoneCurrentAllowed() { return mAllowDoneCurrent; }
|
---|
| 2029 | void allowDoneCurrent(bool bAllow) { mAllowDoneCurrent = bAllow; }
|
---|
| 2030 | private:
|
---|
| 2031 | bool mAllowDoneCurrent;
|
---|
| 2032 | };
|
---|
| 2033 |
|
---|
[27682] | 2034 |
|
---|
[71651] | 2035 | VBoxGLWgt::VBoxGLWgt(VBoxVHWAImage *pImage, QWidget *parent, const QGLWidget *shareWidget)
|
---|
| 2036 | : QGLWidget(new VBoxGLContext(shareWidget->format()), parent, shareWidget)
|
---|
| 2037 | , mpImage(pImage)
|
---|
[27682] | 2038 | {
|
---|
| 2039 | /* work-around to disable done current needed to old ATI drivers on Linux */
|
---|
[71651] | 2040 | VBoxGLContext *pc = (VBoxGLContext *)context();
|
---|
[27682] | 2041 | pc->allowDoneCurrent (false);
|
---|
[27961] | 2042 | Assert(isSharing());
|
---|
[27682] | 2043 | }
|
---|
| 2044 |
|
---|
| 2045 |
|
---|
| 2046 | VBoxVHWAImage::VBoxVHWAImage ()
|
---|
[71651] | 2047 | : mSurfHandleTable(128) /* 128 should be enough */
|
---|
| 2048 | , mRepaintNeeded(false)
|
---|
| 2049 | // , mbVGASurfCreated(false)
|
---|
| 2050 | , mConstructingList(NULL)
|
---|
| 2051 | , mcRemaining2Contruct(0)
|
---|
| 2052 | , mSettings(NULL)
|
---|
[24646] | 2053 | #ifdef VBOXVHWA_PROFILE_FPS
|
---|
[71651] | 2054 | , mFPSCounter(64)
|
---|
| 2055 | , mbNewFrame(false)
|
---|
[24646] | 2056 | #endif
|
---|
[22816] | 2057 | {
|
---|
| 2058 | mpMngr = new VBoxVHWAGlProgramMngr();
|
---|
| 2059 | // /* No need for background drawing */
|
---|
| 2060 | // setAttribute (Qt::WA_OpaquePaintEvent);
|
---|
| 2061 | }
|
---|
| 2062 |
|
---|
[27682] | 2063 | int VBoxVHWAImage::init(VBoxVHWASettings *aSettings)
|
---|
[22816] | 2064 | {
|
---|
[27682] | 2065 | mSettings = aSettings;
|
---|
| 2066 | return VINF_SUCCESS;
|
---|
| 2067 | }
|
---|
| 2068 |
|
---|
[71651] | 2069 | const QGLFormat &VBoxVHWAImage::vboxGLFormat()
|
---|
[27682] | 2070 | {
|
---|
[22816] | 2071 | static QGLFormat vboxFormat = QGLFormat();
|
---|
| 2072 | vboxFormat.setAlpha(true);
|
---|
| 2073 | Assert(vboxFormat.alpha());
|
---|
| 2074 | vboxFormat.setSwapInterval(0);
|
---|
| 2075 | Assert(vboxFormat.swapInterval() == 0);
|
---|
| 2076 | vboxFormat.setAccum(false);
|
---|
| 2077 | Assert(!vboxFormat.accum());
|
---|
| 2078 | vboxFormat.setDepth(false);
|
---|
| 2079 | Assert(!vboxFormat.depth());
|
---|
[24471] | 2080 | // vboxFormat.setRedBufferSize(8);
|
---|
| 2081 | // vboxFormat.setGreenBufferSize(8);
|
---|
| 2082 | // vboxFormat.setBlueBufferSize(8);
|
---|
[22816] | 2083 | return vboxFormat;
|
---|
| 2084 | }
|
---|
| 2085 |
|
---|
[27682] | 2086 |
|
---|
| 2087 | VBoxVHWAImage::~VBoxVHWAImage()
|
---|
[22816] | 2088 | {
|
---|
| 2089 | delete mpMngr;
|
---|
| 2090 | }
|
---|
| 2091 |
|
---|
[24431] | 2092 | #ifdef VBOXVHWA_OLD_COORD
|
---|
[71651] | 2093 | void VBoxVHWAImage::doSetupMatrix(const QSize &aSize, bool bInverted)
|
---|
[22816] | 2094 | {
|
---|
| 2095 | VBOXQGL_CHECKERR(
|
---|
| 2096 | glLoadIdentity();
|
---|
| 2097 | );
|
---|
[71651] | 2098 | if (bInverted)
|
---|
[22816] | 2099 | {
|
---|
| 2100 | VBOXQGL_CHECKERR(
|
---|
[71651] | 2101 | glScalef(1.0f / aSize.width(), 1.0f / aSize.height(), 1.0f);
|
---|
[22816] | 2102 | );
|
---|
| 2103 | }
|
---|
| 2104 | else
|
---|
| 2105 | {
|
---|
| 2106 | /* make display coordinates be scaled to pixel coordinates */
|
---|
| 2107 | VBOXQGL_CHECKERR(
|
---|
| 2108 | glTranslatef(0.0f, 1.0f, 0.0f);
|
---|
| 2109 | );
|
---|
| 2110 | VBOXQGL_CHECKERR(
|
---|
[71651] | 2111 | glScalef(1.0f / aSize.width(), 1.0f / aSize.height(), 1.0f);
|
---|
[22816] | 2112 | );
|
---|
| 2113 | VBOXQGL_CHECKERR(
|
---|
| 2114 | glRotatef(180.0f, 1.0f, 0.0f, 0.0f);
|
---|
| 2115 | );
|
---|
| 2116 | }
|
---|
| 2117 | }
|
---|
[24431] | 2118 | #endif
|
---|
| 2119 |
|
---|
[27682] | 2120 | void VBoxVHWAImage::adjustViewport(const QSize &display, const QRect &viewport)
|
---|
[22816] | 2121 | {
|
---|
[24431] | 2122 | glViewport(-viewport.x(),
|
---|
[26509] | 2123 | viewport.height() + viewport.y() - display.height(),
|
---|
[24431] | 2124 | display.width(),
|
---|
| 2125 | display.height());
|
---|
[22816] | 2126 | }
|
---|
| 2127 |
|
---|
[27682] | 2128 | void VBoxVHWAImage::setupMatricies(const QSize &display, bool bInverted)
|
---|
[22816] | 2129 | {
|
---|
| 2130 | glMatrixMode(GL_PROJECTION);
|
---|
| 2131 | glLoadIdentity();
|
---|
[24431] | 2132 |
|
---|
[71651] | 2133 | if (bInverted)
|
---|
[25468] | 2134 | glOrtho(0., (GLdouble)display.width(), (GLdouble)display.height(), 0., -1., 1.);
|
---|
| 2135 | else
|
---|
| 2136 | glOrtho(0., (GLdouble)display.width(), 0., (GLdouble)display.height(), -1., 1.);
|
---|
| 2137 |
|
---|
[24431] | 2138 | glMatrixMode(GL_MODELVIEW);
|
---|
| 2139 | glLoadIdentity();
|
---|
[22816] | 2140 | }
|
---|
| 2141 |
|
---|
[71651] | 2142 | int VBoxVHWAImage::reset(VHWACommandList *pCmdList)
|
---|
[22816] | 2143 | {
|
---|
[71651] | 2144 | VBOXVHWACMD *pCmd;
|
---|
[24925] | 2145 | const OverlayList & overlays = mDisplay.overlays();
|
---|
[71651] | 2146 | for (OverlayList::const_iterator oIt = overlays.begin(); oIt != overlays.end(); ++ oIt)
|
---|
[24925] | 2147 | {
|
---|
| 2148 | VBoxVHWASurfList * pSurfList = *oIt;
|
---|
[71651] | 2149 | if (pSurfList->current())
|
---|
[24925] | 2150 | {
|
---|
| 2151 | /* 1. hide overlay */
|
---|
| 2152 | pCmd = vhwaHHCmdCreate(VBOXVHWACMD_TYPE_SURF_OVERLAY_UPDATE, sizeof(VBOXVHWACMD_SURF_OVERLAY_UPDATE));
|
---|
[71594] | 2153 | VBOXVHWACMD_SURF_OVERLAY_UPDATE RT_UNTRUSTED_VOLATILE_GUEST *pOUCmd = VBOXVHWACMD_BODY(pCmd, VBOXVHWACMD_SURF_OVERLAY_UPDATE);
|
---|
[24925] | 2154 | pOUCmd->u.in.hSrcSurf = pSurfList->current()->handle();
|
---|
| 2155 | pOUCmd->u.in.flags = VBOXVHWA_OVER_HIDE;
|
---|
| 2156 |
|
---|
| 2157 | pCmdList->push_back(pCmd);
|
---|
| 2158 | }
|
---|
| 2159 |
|
---|
| 2160 | /* 2. destroy overlay */
|
---|
| 2161 | const SurfList & surfaces = pSurfList->surfaces();
|
---|
[71651] | 2162 | for (SurfList::const_iterator sIt = surfaces.begin(); sIt != surfaces.end(); ++ sIt)
|
---|
[24925] | 2163 | {
|
---|
| 2164 | VBoxVHWASurfaceBase *pCurSurf = (*sIt);
|
---|
| 2165 | pCmd = vhwaHHCmdCreate(VBOXVHWACMD_TYPE_SURF_DESTROY, sizeof(VBOXVHWACMD_SURF_DESTROY));
|
---|
[71594] | 2166 | VBOXVHWACMD_SURF_DESTROY RT_UNTRUSTED_VOLATILE_GUEST *pSDCmd = VBOXVHWACMD_BODY(pCmd, VBOXVHWACMD_SURF_DESTROY);
|
---|
[24925] | 2167 | pSDCmd->u.in.hSurf = pCurSurf->handle();
|
---|
| 2168 |
|
---|
| 2169 | pCmdList->push_back(pCmd);
|
---|
| 2170 | }
|
---|
| 2171 | }
|
---|
| 2172 |
|
---|
| 2173 | /* 3. destroy primaries */
|
---|
| 2174 | const SurfList & surfaces = mDisplay.primaries().surfaces();
|
---|
[71651] | 2175 | for (SurfList::const_iterator sIt = surfaces.begin(); sIt != surfaces.end(); ++ sIt)
|
---|
[24925] | 2176 | {
|
---|
| 2177 | VBoxVHWASurfaceBase *pCurSurf = (*sIt);
|
---|
[71651] | 2178 | if (pCurSurf->handle() != VBOXVHWA_SURFHANDLE_INVALID)
|
---|
[24925] | 2179 | {
|
---|
| 2180 | pCmd = vhwaHHCmdCreate(VBOXVHWACMD_TYPE_SURF_DESTROY, sizeof(VBOXVHWACMD_SURF_DESTROY));
|
---|
[71594] | 2181 | VBOXVHWACMD_SURF_DESTROY RT_UNTRUSTED_VOLATILE_GUEST *pSDCmd = VBOXVHWACMD_BODY(pCmd, VBOXVHWACMD_SURF_DESTROY);
|
---|
[24925] | 2182 | pSDCmd->u.in.hSurf = pCurSurf->handle();
|
---|
| 2183 |
|
---|
| 2184 | pCmdList->push_back(pCmd);
|
---|
| 2185 | }
|
---|
| 2186 | }
|
---|
| 2187 |
|
---|
| 2188 | return VINF_SUCCESS;
|
---|
| 2189 | }
|
---|
| 2190 |
|
---|
[22816] | 2191 | #ifdef VBOX_WITH_VIDEOHWACCEL
|
---|
[71594] | 2192 | int VBoxVHWAImage::vhwaSurfaceCanCreate(struct VBOXVHWACMD_SURF_CANCREATE RT_UNTRUSTED_VOLATILE_GUEST *pCmd)
|
---|
[22816] | 2193 | {
|
---|
| 2194 | VBOXQGLLOG_ENTER(("\n"));
|
---|
| 2195 |
|
---|
[27682] | 2196 | const VBoxVHWAInfo & info = vboxVHWAGetSupportInfo(NULL);
|
---|
[23732] | 2197 |
|
---|
[71651] | 2198 | if (!(pCmd->SurfInfo.flags & VBOXVHWA_SD_CAPS))
|
---|
[22816] | 2199 | {
|
---|
[49940] | 2200 | AssertFailed();
|
---|
[22920] | 2201 | pCmd->u.out.ErrInfo = -1;
|
---|
[22816] | 2202 | return VINF_SUCCESS;
|
---|
| 2203 | }
|
---|
[22951] | 2204 | #ifdef VBOXVHWA_ALLOW_PRIMARY_AND_OVERLAY_ONLY
|
---|
[71651] | 2205 | if (pCmd->SurfInfo.surfCaps & VBOXVHWA_SCAPS_OFFSCREENPLAIN)
|
---|
[22816] | 2206 | {
|
---|
[22920] | 2207 | #ifdef DEBUGVHWASTRICT
|
---|
[49940] | 2208 | AssertFailed();
|
---|
[22920] | 2209 | #endif
|
---|
| 2210 | pCmd->u.out.ErrInfo = -1;
|
---|
[22816] | 2211 | return VINF_SUCCESS;
|
---|
| 2212 | }
|
---|
[22951] | 2213 | #endif
|
---|
[22816] | 2214 |
|
---|
[71651] | 2215 | if (pCmd->SurfInfo.surfCaps & VBOXVHWA_SCAPS_PRIMARYSURFACE)
|
---|
[22816] | 2216 | {
|
---|
[71651] | 2217 | if (pCmd->SurfInfo.surfCaps & VBOXVHWA_SCAPS_COMPLEX)
|
---|
[22951] | 2218 | {
|
---|
| 2219 | #ifdef DEBUG_misha
|
---|
[49940] | 2220 | AssertFailed();
|
---|
[22951] | 2221 | #endif
|
---|
| 2222 | pCmd->u.out.ErrInfo = -1;
|
---|
| 2223 | }
|
---|
| 2224 | else
|
---|
| 2225 | {
|
---|
| 2226 | pCmd->u.out.ErrInfo = 0;
|
---|
| 2227 | }
|
---|
[22816] | 2228 | return VINF_SUCCESS;
|
---|
| 2229 | }
|
---|
| 2230 |
|
---|
[22951] | 2231 | #ifdef VBOXVHWA_ALLOW_PRIMARY_AND_OVERLAY_ONLY
|
---|
[25583] | 2232 | if ((pCmd->SurfInfo.surfCaps & VBOXVHWA_SCAPS_OVERLAY) == 0)
|
---|
[22951] | 2233 | {
|
---|
| 2234 | #ifdef DEBUGVHWASTRICT
|
---|
[49940] | 2235 | AssertFailed();
|
---|
[22951] | 2236 | #endif
|
---|
| 2237 | pCmd->u.out.ErrInfo = -1;
|
---|
| 2238 | return VINF_SUCCESS;
|
---|
| 2239 | }
|
---|
| 2240 | #endif
|
---|
[22920] | 2241 |
|
---|
[25583] | 2242 | if (pCmd->u.in.bIsDifferentPixelFormat)
|
---|
[22816] | 2243 | {
|
---|
[25583] | 2244 | if (!(pCmd->SurfInfo.flags & VBOXVHWA_SD_PIXELFORMAT))
|
---|
[22816] | 2245 | {
|
---|
[49940] | 2246 | AssertFailed();
|
---|
[22920] | 2247 | pCmd->u.out.ErrInfo = -1;
|
---|
[22816] | 2248 | return VINF_SUCCESS;
|
---|
| 2249 | }
|
---|
| 2250 |
|
---|
[25583] | 2251 | if (pCmd->SurfInfo.PixelFormat.flags & VBOXVHWA_PF_RGB)
|
---|
[22816] | 2252 | {
|
---|
[25583] | 2253 | if (pCmd->SurfInfo.PixelFormat.c.rgbBitCount != 32
|
---|
[52805] | 2254 | && pCmd->SurfInfo.PixelFormat.c.rgbBitCount != 24)
|
---|
[22816] | 2255 | {
|
---|
[49940] | 2256 | AssertFailed();
|
---|
[22920] | 2257 | pCmd->u.out.ErrInfo = -1;
|
---|
[22816] | 2258 | return VINF_SUCCESS;
|
---|
| 2259 | }
|
---|
| 2260 | }
|
---|
[25583] | 2261 | else if (pCmd->SurfInfo.PixelFormat.flags & VBOXVHWA_PF_FOURCC)
|
---|
[22816] | 2262 | {
|
---|
| 2263 | /* detect whether we support this format */
|
---|
[25583] | 2264 | bool bFound = mSettings->isSupported (info, pCmd->SurfInfo.PixelFormat.fourCC);
|
---|
[24646] | 2265 |
|
---|
[25583] | 2266 | if (!bFound)
|
---|
[22816] | 2267 | {
|
---|
[26509] | 2268 | VBOXQGLLOG (("!!unsupported fourcc!!!: %c%c%c%c\n",
|
---|
| 2269 | (pCmd->SurfInfo.PixelFormat.fourCC & 0x000000ff),
|
---|
| 2270 | (pCmd->SurfInfo.PixelFormat.fourCC & 0x0000ff00) >> 8,
|
---|
| 2271 | (pCmd->SurfInfo.PixelFormat.fourCC & 0x00ff0000) >> 16,
|
---|
| 2272 | (pCmd->SurfInfo.PixelFormat.fourCC & 0xff000000) >> 24
|
---|
| 2273 | ));
|
---|
[22920] | 2274 | pCmd->u.out.ErrInfo = -1;
|
---|
[22816] | 2275 | return VINF_SUCCESS;
|
---|
| 2276 | }
|
---|
| 2277 | }
|
---|
| 2278 | else
|
---|
| 2279 | {
|
---|
[49940] | 2280 | AssertFailed();
|
---|
[22920] | 2281 | pCmd->u.out.ErrInfo = -1;
|
---|
[22816] | 2282 | return VINF_SUCCESS;
|
---|
| 2283 | }
|
---|
| 2284 | }
|
---|
| 2285 |
|
---|
| 2286 | pCmd->u.out.ErrInfo = 0;
|
---|
| 2287 | return VINF_SUCCESS;
|
---|
| 2288 | }
|
---|
| 2289 |
|
---|
[71651] | 2290 | int VBoxVHWAImage::vhwaSurfaceCreate(struct VBOXVHWACMD_SURF_CREATE RT_UNTRUSTED_VOLATILE_GUEST *pCmd)
|
---|
[22816] | 2291 | {
|
---|
[25583] | 2292 | VBOXQGLLOG_ENTER (("\n"));
|
---|
[22816] | 2293 |
|
---|
| 2294 | uint32_t handle = VBOXVHWA_SURFHANDLE_INVALID;
|
---|
[71651] | 2295 | if (pCmd->SurfInfo.hSurf != VBOXVHWA_SURFHANDLE_INVALID)
|
---|
[22816] | 2296 | {
|
---|
| 2297 | handle = pCmd->SurfInfo.hSurf;
|
---|
[71651] | 2298 | if (mSurfHandleTable.get(handle))
|
---|
[22816] | 2299 | {
|
---|
[49940] | 2300 | AssertFailed();
|
---|
[25264] | 2301 | return VERR_GENERAL_FAILURE;
|
---|
[22816] | 2302 | }
|
---|
| 2303 | }
|
---|
| 2304 |
|
---|
| 2305 | VBoxVHWASurfaceBase *surf = NULL;
|
---|
[27839] | 2306 | /* in case the Framebuffer is working in "not using VRAM" mode,
|
---|
| 2307 | * we need to report the pitch, etc. info of the form guest expects from us*/
|
---|
| 2308 | VBoxVHWAColorFormat reportedFormat;
|
---|
[33540] | 2309 | /* paranoia to ensure the VBoxVHWAColorFormat API works properly */
|
---|
[27839] | 2310 | Assert(!reportedFormat.isValid());
|
---|
[22951] | 2311 | bool bNoPBO = false;
|
---|
[22816] | 2312 | bool bPrimary = false;
|
---|
| 2313 |
|
---|
| 2314 | VBoxVHWAColorKey *pDstBltCKey = NULL, DstBltCKey;
|
---|
| 2315 | VBoxVHWAColorKey *pSrcBltCKey = NULL, SrcBltCKey;
|
---|
| 2316 | VBoxVHWAColorKey *pDstOverlayCKey = NULL, DstOverlayCKey;
|
---|
| 2317 | VBoxVHWAColorKey *pSrcOverlayCKey = NULL, SrcOverlayCKey;
|
---|
[71651] | 2318 | if (pCmd->SurfInfo.flags & VBOXVHWA_SD_CKDESTBLT)
|
---|
[22816] | 2319 | {
|
---|
| 2320 | DstBltCKey = VBoxVHWAColorKey(pCmd->SurfInfo.DstBltCK.high, pCmd->SurfInfo.DstBltCK.low);
|
---|
| 2321 | pDstBltCKey = &DstBltCKey;
|
---|
| 2322 | }
|
---|
[71651] | 2323 | if (pCmd->SurfInfo.flags & VBOXVHWA_SD_CKSRCBLT)
|
---|
[22816] | 2324 | {
|
---|
| 2325 | SrcBltCKey = VBoxVHWAColorKey(pCmd->SurfInfo.SrcBltCK.high, pCmd->SurfInfo.SrcBltCK.low);
|
---|
| 2326 | pSrcBltCKey = &SrcBltCKey;
|
---|
| 2327 | }
|
---|
[71651] | 2328 | if (pCmd->SurfInfo.flags & VBOXVHWA_SD_CKDESTOVERLAY)
|
---|
[22816] | 2329 | {
|
---|
| 2330 | DstOverlayCKey = VBoxVHWAColorKey(pCmd->SurfInfo.DstOverlayCK.high, pCmd->SurfInfo.DstOverlayCK.low);
|
---|
| 2331 | pDstOverlayCKey = &DstOverlayCKey;
|
---|
| 2332 | }
|
---|
[71651] | 2333 | if (pCmd->SurfInfo.flags & VBOXVHWA_SD_CKSRCOVERLAY)
|
---|
[22816] | 2334 | {
|
---|
| 2335 | SrcOverlayCKey = VBoxVHWAColorKey(pCmd->SurfInfo.SrcOverlayCK.high, pCmd->SurfInfo.SrcOverlayCK.low);
|
---|
| 2336 | pSrcOverlayCKey = &SrcOverlayCKey;
|
---|
| 2337 | }
|
---|
| 2338 |
|
---|
[27839] | 2339 | if (pCmd->SurfInfo.surfCaps & VBOXVHWA_SCAPS_PRIMARYSURFACE)
|
---|
[22816] | 2340 | {
|
---|
[22951] | 2341 | bNoPBO = true;
|
---|
[22816] | 2342 | bPrimary = true;
|
---|
[71651] | 2343 | VBoxVHWASurfaceBase *pVga = vgaSurface();
|
---|
[32823] | 2344 | #ifdef VBOX_WITH_WDDM
|
---|
| 2345 | uchar * addr = vboxVRAMAddressFromOffset(pCmd->SurfInfo.offSurface);
|
---|
| 2346 | Assert(addr);
|
---|
| 2347 | if (addr)
|
---|
| 2348 | {
|
---|
| 2349 | pVga->setAddress(addr);
|
---|
| 2350 | }
|
---|
| 2351 | #endif
|
---|
[22816] | 2352 |
|
---|
[22951] | 2353 | Assert((pCmd->SurfInfo.surfCaps & VBOXVHWA_SCAPS_OFFSCREENPLAIN) == 0);
|
---|
[27846] | 2354 |
|
---|
| 2355 | reportedFormat = VBoxVHWAColorFormat(pCmd->SurfInfo.PixelFormat.c.rgbBitCount,
|
---|
[71651] | 2356 | pCmd->SurfInfo.PixelFormat.m1.rgbRBitMask,
|
---|
| 2357 | pCmd->SurfInfo.PixelFormat.m2.rgbGBitMask,
|
---|
| 2358 | pCmd->SurfInfo.PixelFormat.m3.rgbBBitMask);
|
---|
[27846] | 2359 |
|
---|
[27839] | 2360 | if (pVga->handle() == VBOXVHWA_SURFHANDLE_INVALID
|
---|
[22951] | 2361 | && (pCmd->SurfInfo.surfCaps & VBOXVHWA_SCAPS_OFFSCREENPLAIN) == 0)
|
---|
[22816] | 2362 | {
|
---|
| 2363 | Assert(pCmd->SurfInfo.PixelFormat.flags & VBOXVHWA_PF_RGB);
|
---|
[71651] | 2364 | // if (pCmd->SurfInfo.PixelFormat.flags & VBOXVHWA_PF_RGB)
|
---|
[22816] | 2365 | {
|
---|
| 2366 | Assert(pCmd->SurfInfo.width == pVga->width());
|
---|
| 2367 | Assert(pCmd->SurfInfo.height == pVga->height());
|
---|
[71651] | 2368 | // if (pCmd->SurfInfo.width == pVga->width()
|
---|
[22816] | 2369 | // && pCmd->SurfInfo.height == pVga->height())
|
---|
| 2370 | {
|
---|
[27839] | 2371 | // the assert below is incorrect in case the Framebuffer is working in "not using VRAM" mode
|
---|
| 2372 | // Assert(pVga->pixelFormat().equals(format));
|
---|
[71651] | 2373 | // if (pVga->pixelFormat().equals(format))
|
---|
[22816] | 2374 | {
|
---|
| 2375 | surf = pVga;
|
---|
| 2376 |
|
---|
| 2377 | surf->setDstBltCKey(pDstBltCKey);
|
---|
| 2378 | surf->setSrcBltCKey(pSrcBltCKey);
|
---|
| 2379 |
|
---|
| 2380 | surf->setDefaultDstOverlayCKey(pDstOverlayCKey);
|
---|
| 2381 | surf->resetDefaultDstOverlayCKey();
|
---|
| 2382 |
|
---|
[27960] | 2383 | surf->setDefaultSrcOverlayCKey(pSrcOverlayCKey);
|
---|
[22816] | 2384 | surf->resetDefaultSrcOverlayCKey();
|
---|
| 2385 | // mbVGASurfCreated = true;
|
---|
| 2386 | }
|
---|
| 2387 | }
|
---|
| 2388 | }
|
---|
| 2389 | }
|
---|
| 2390 | }
|
---|
[71651] | 2391 | else if (pCmd->SurfInfo.surfCaps & VBOXVHWA_SCAPS_OFFSCREENPLAIN)
|
---|
[22951] | 2392 | {
|
---|
| 2393 | bNoPBO = true;
|
---|
| 2394 | }
|
---|
[22816] | 2395 |
|
---|
[71651] | 2396 | if (!surf)
|
---|
[22816] | 2397 | {
|
---|
[25583] | 2398 | VBOXVHWAIMG_TYPE fFlags = 0;
|
---|
[71651] | 2399 | if (!bNoPBO)
|
---|
[25583] | 2400 | {
|
---|
[34461] | 2401 | fFlags |= VBOXVHWAIMG_PBO | VBOXVHWAIMG_PBOIMG | VBOXVHWAIMG_LINEAR;
|
---|
[71651] | 2402 | if (mSettings->isStretchLinearEnabled())
|
---|
[25583] | 2403 | fFlags |= VBOXVHWAIMG_FBO;
|
---|
| 2404 | }
|
---|
| 2405 |
|
---|
[27846] | 2406 | QSize surfSize(pCmd->SurfInfo.width, pCmd->SurfInfo.height);
|
---|
| 2407 | QRect primaryRect = mDisplay.getPrimary()->rect();
|
---|
| 2408 | VBoxVHWAColorFormat format;
|
---|
| 2409 | if (bPrimary)
|
---|
| 2410 | format = mDisplay.getVGA()->pixelFormat();
|
---|
| 2411 | else if (pCmd->SurfInfo.PixelFormat.flags & VBOXVHWA_PF_RGB)
|
---|
| 2412 | format = VBoxVHWAColorFormat(pCmd->SurfInfo.PixelFormat.c.rgbBitCount,
|
---|
[71651] | 2413 | pCmd->SurfInfo.PixelFormat.m1.rgbRBitMask,
|
---|
| 2414 | pCmd->SurfInfo.PixelFormat.m2.rgbGBitMask,
|
---|
| 2415 | pCmd->SurfInfo.PixelFormat.m3.rgbBBitMask);
|
---|
[27846] | 2416 | else if (pCmd->SurfInfo.PixelFormat.flags & VBOXVHWA_PF_FOURCC)
|
---|
| 2417 | format = VBoxVHWAColorFormat(pCmd->SurfInfo.PixelFormat.fourCC);
|
---|
| 2418 | else
|
---|
[71651] | 2419 | AssertFailed();
|
---|
[27846] | 2420 |
|
---|
| 2421 | if (format.isValid())
|
---|
| 2422 | {
|
---|
[25385] | 2423 | surf = new VBoxVHWASurfaceBase(this,
|
---|
[71651] | 2424 | surfSize,
|
---|
| 2425 | primaryRect,
|
---|
| 2426 | QRect(0, 0, surfSize.width(), surfSize.height()),
|
---|
| 2427 | mViewport,
|
---|
| 2428 | format,
|
---|
| 2429 | pSrcBltCKey, pDstBltCKey, pSrcOverlayCKey, pDstOverlayCKey,
|
---|
[24646] | 2430 | #ifdef VBOXVHWA_USE_TEXGROUP
|
---|
[71651] | 2431 | 0,
|
---|
[24646] | 2432 | #endif
|
---|
[71651] | 2433 | fFlags);
|
---|
[22816] | 2434 | }
|
---|
| 2435 | else
|
---|
| 2436 | {
|
---|
[71651] | 2437 | AssertFailed();
|
---|
[27846] | 2438 | VBOXQGLLOG_EXIT(("pSurf (0x%p)\n",surf));
|
---|
[22816] | 2439 | return VERR_GENERAL_FAILURE;
|
---|
| 2440 | }
|
---|
| 2441 |
|
---|
[71651] | 2442 | uchar *addr = vboxVRAMAddressFromOffset(pCmd->SurfInfo.offSurface);
|
---|
[27839] | 2443 | surf->init(mDisplay.getPrimary(), addr);
|
---|
[22816] | 2444 |
|
---|
[71651] | 2445 | if (pCmd->SurfInfo.surfCaps & VBOXVHWA_SCAPS_OVERLAY)
|
---|
[22816] | 2446 | {
|
---|
[22951] | 2447 | #ifdef DEBUG_misha
|
---|
| 2448 | Assert(!bNoPBO);
|
---|
| 2449 | #endif
|
---|
[22816] | 2450 |
|
---|
[71651] | 2451 | if (!mConstructingList)
|
---|
[22816] | 2452 | {
|
---|
| 2453 | mConstructingList = new VBoxVHWASurfList();
|
---|
| 2454 | mcRemaining2Contruct = pCmd->SurfInfo.cBackBuffers+1;
|
---|
| 2455 | mDisplay.addOverlay(mConstructingList);
|
---|
| 2456 | }
|
---|
| 2457 |
|
---|
| 2458 | mConstructingList->add(surf);
|
---|
| 2459 | mcRemaining2Contruct--;
|
---|
[71651] | 2460 | if (!mcRemaining2Contruct)
|
---|
[22816] | 2461 | mConstructingList = NULL;
|
---|
| 2462 | }
|
---|
[22951] | 2463 | else
|
---|
[22816] | 2464 | {
|
---|
[27682] | 2465 | VBoxVHWASurfaceBase * pVga = vgaSurface();
|
---|
[22816] | 2466 | Assert(pVga->handle() != VBOXVHWA_SURFHANDLE_INVALID);
|
---|
[22953] | 2467 | Assert(pVga != surf); NOREF(pVga);
|
---|
[22816] | 2468 | mDisplay.getVGA()->getComplexList()->add(surf);
|
---|
[22920] | 2469 | #ifdef DEBUGVHWASTRICT
|
---|
[22816] | 2470 | Assert(pCmd->SurfInfo.surfCaps & VBOXVHWA_SCAPS_VISIBLE);
|
---|
[22836] | 2471 | #endif
|
---|
[71651] | 2472 | if (bPrimary)
|
---|
[22816] | 2473 | {
|
---|
| 2474 | Assert(surf->getComplexList() == mDisplay.getVGA()->getComplexList());
|
---|
| 2475 | surf->getComplexList()->setCurrentVisible(surf);
|
---|
| 2476 | mDisplay.updateVGA(surf);
|
---|
| 2477 | }
|
---|
| 2478 | }
|
---|
| 2479 | }
|
---|
[27839] | 2480 | else
|
---|
| 2481 | Assert(pCmd->SurfInfo.surfCaps & VBOXVHWA_SCAPS_PRIMARYSURFACE);
|
---|
[22816] | 2482 |
|
---|
| 2483 | Assert(mDisplay.getVGA() == mDisplay.getPrimary());
|
---|
| 2484 |
|
---|
| 2485 | /* tell the guest how we think the memory is organized */
|
---|
| 2486 | VBOXQGLLOG(("bps: %d\n", surf->bitsPerPixel()));
|
---|
| 2487 |
|
---|
[27839] | 2488 | if (!reportedFormat.isValid())
|
---|
| 2489 | {
|
---|
[35280] | 2490 | pCmd->SurfInfo.pitch = surf->bytesPerLine();
|
---|
[27839] | 2491 | pCmd->SurfInfo.sizeX = surf->memSize();
|
---|
| 2492 | pCmd->SurfInfo.sizeY = 1;
|
---|
| 2493 | }
|
---|
| 2494 | else
|
---|
| 2495 | {
|
---|
[33540] | 2496 | /* this is the case of Framebuffer not using Guest VRAM */
|
---|
[27839] | 2497 | /* can happen for primary surface creation only */
|
---|
| 2498 | Assert(pCmd->SurfInfo.surfCaps & VBOXVHWA_SCAPS_PRIMARYSURFACE);
|
---|
| 2499 | pCmd->SurfInfo.pitch = (reportedFormat.bitsPerPixel() * surf->width() + 7) / 8;
|
---|
| 2500 | /* we support only RGB case now, otherwise we would need more complicated mechanism of memsize calculation */
|
---|
| 2501 | Assert(!reportedFormat.fourcc());
|
---|
| 2502 | pCmd->SurfInfo.sizeX = (reportedFormat.bitsPerPixel() * surf->width() + 7) / 8 * surf->height();
|
---|
| 2503 | pCmd->SurfInfo.sizeY = 1;
|
---|
| 2504 | }
|
---|
[22816] | 2505 |
|
---|
[71651] | 2506 | if (handle != VBOXVHWA_SURFHANDLE_INVALID)
|
---|
[22816] | 2507 | {
|
---|
| 2508 | bool bSuccess = mSurfHandleTable.mapPut(handle, surf);
|
---|
| 2509 | Assert(bSuccess);
|
---|
[71651] | 2510 | if (!bSuccess)
|
---|
[22816] | 2511 | {
|
---|
[63567] | 2512 | /** @todo this is very bad, should not be here */
|
---|
[22816] | 2513 | return VERR_GENERAL_FAILURE;
|
---|
| 2514 | }
|
---|
| 2515 | }
|
---|
| 2516 | else
|
---|
| 2517 | {
|
---|
| 2518 | /* tell the guest our handle */
|
---|
| 2519 | handle = mSurfHandleTable.put(surf);
|
---|
| 2520 | pCmd->SurfInfo.hSurf = (VBOXVHWA_SURFHANDLE)handle;
|
---|
| 2521 | }
|
---|
| 2522 |
|
---|
| 2523 | Assert(handle != VBOXVHWA_SURFHANDLE_INVALID);
|
---|
| 2524 | Assert(surf->handle() == VBOXVHWA_SURFHANDLE_INVALID);
|
---|
| 2525 | surf->setHandle(handle);
|
---|
| 2526 | Assert(surf->handle() == handle);
|
---|
| 2527 |
|
---|
[27846] | 2528 | VBOXQGLLOG_EXIT(("pSurf (0x%p)\n",surf));
|
---|
[22816] | 2529 |
|
---|
| 2530 | return VINF_SUCCESS;
|
---|
| 2531 | }
|
---|
| 2532 |
|
---|
[32622] | 2533 | #ifdef VBOX_WITH_WDDM
|
---|
[71594] | 2534 | int VBoxVHWAImage::vhwaSurfaceGetInfo(struct VBOXVHWACMD_SURF_GETINFO RT_UNTRUSTED_VOLATILE_GUEST *pCmd)
|
---|
[29922] | 2535 | {
|
---|
| 2536 | VBoxVHWAColorFormat format;
|
---|
| 2537 | Assert(!format.isValid());
|
---|
| 2538 | if (pCmd->SurfInfo.PixelFormat.flags & VBOXVHWA_PF_RGB)
|
---|
| 2539 | format = VBoxVHWAColorFormat(pCmd->SurfInfo.PixelFormat.c.rgbBitCount,
|
---|
| 2540 | pCmd->SurfInfo.PixelFormat.m1.rgbRBitMask,
|
---|
| 2541 | pCmd->SurfInfo.PixelFormat.m2.rgbGBitMask,
|
---|
| 2542 | pCmd->SurfInfo.PixelFormat.m3.rgbBBitMask);
|
---|
| 2543 | else if (pCmd->SurfInfo.PixelFormat.flags & VBOXVHWA_PF_FOURCC)
|
---|
| 2544 | format = VBoxVHWAColorFormat(pCmd->SurfInfo.PixelFormat.fourCC);
|
---|
| 2545 | else
|
---|
[71651] | 2546 | AssertFailed();
|
---|
[29922] | 2547 |
|
---|
| 2548 | Assert(format.isValid());
|
---|
| 2549 | if (format.isValid())
|
---|
| 2550 | {
|
---|
[35280] | 2551 | pCmd->SurfInfo.pitch = VBoxVHWATextureImage::calcBytesPerLine(format, pCmd->SurfInfo.width);
|
---|
| 2552 | pCmd->SurfInfo.sizeX = VBoxVHWATextureImage::calcMemSize(format,
|
---|
| 2553 | pCmd->SurfInfo.width, pCmd->SurfInfo.height);
|
---|
[29922] | 2554 | pCmd->SurfInfo.sizeY = 1;
|
---|
| 2555 | return VINF_SUCCESS;
|
---|
| 2556 | }
|
---|
| 2557 | return VERR_INVALID_PARAMETER;
|
---|
| 2558 | }
|
---|
| 2559 | #endif
|
---|
[71651] | 2560 |
|
---|
[71594] | 2561 | int VBoxVHWAImage::vhwaSurfaceDestroy(struct VBOXVHWACMD_SURF_DESTROY RT_UNTRUSTED_VOLATILE_GUEST *pCmd)
|
---|
[22816] | 2562 | {
|
---|
| 2563 | VBoxVHWASurfaceBase *pSurf = handle2Surface(pCmd->u.in.hSurf);
|
---|
[81210] | 2564 | AssertReturn(pSurf, VERR_INVALID_PARAMETER);
|
---|
[22816] | 2565 | VBoxVHWASurfList *pList = pSurf->getComplexList();
|
---|
| 2566 | Assert(pSurf->handle() != VBOXVHWA_SURFHANDLE_INVALID);
|
---|
| 2567 |
|
---|
| 2568 | VBOXQGLLOG_ENTER(("pSurf (0x%x)\n",pSurf));
|
---|
[71651] | 2569 | if (pList != mDisplay.getVGA()->getComplexList())
|
---|
[22816] | 2570 | {
|
---|
| 2571 | Assert(pList);
|
---|
| 2572 | pList->remove(pSurf);
|
---|
[71651] | 2573 | if (pList->surfaces().empty())
|
---|
[22816] | 2574 | {
|
---|
| 2575 | mDisplay.removeOverlay(pList);
|
---|
[71651] | 2576 | if (pList == mConstructingList)
|
---|
[22816] | 2577 | {
|
---|
| 2578 | mConstructingList = NULL;
|
---|
| 2579 | mcRemaining2Contruct = 0;
|
---|
| 2580 | }
|
---|
| 2581 | delete pList;
|
---|
| 2582 | }
|
---|
| 2583 |
|
---|
| 2584 | delete(pSurf);
|
---|
| 2585 | }
|
---|
| 2586 | else
|
---|
| 2587 | {
|
---|
[49535] | 2588 | Assert(pList);
|
---|
[22816] | 2589 | Assert(pList->size() >= 1);
|
---|
[71651] | 2590 | if (pList->size() > 1)
|
---|
[22816] | 2591 | {
|
---|
[71651] | 2592 | if (pSurf == mDisplay.getVGA())
|
---|
[22816] | 2593 | {
|
---|
| 2594 | const SurfList & surfaces = pList->surfaces();
|
---|
| 2595 |
|
---|
| 2596 | for (SurfList::const_iterator it = surfaces.begin();
|
---|
| 2597 | it != surfaces.end(); ++ it)
|
---|
| 2598 | {
|
---|
| 2599 | VBoxVHWASurfaceBase *pCurSurf = (*it);
|
---|
[27785] | 2600 | Assert(pCurSurf);
|
---|
| 2601 | if (pCurSurf != pSurf)
|
---|
[22816] | 2602 | {
|
---|
| 2603 | mDisplay.updateVGA(pCurSurf);
|
---|
| 2604 | pList->setCurrentVisible(pCurSurf);
|
---|
| 2605 | break;
|
---|
| 2606 | }
|
---|
| 2607 | }
|
---|
| 2608 | }
|
---|
| 2609 |
|
---|
| 2610 | pList->remove(pSurf);
|
---|
| 2611 | delete(pSurf);
|
---|
| 2612 | }
|
---|
| 2613 | else
|
---|
| 2614 | {
|
---|
| 2615 | pSurf->setHandle(VBOXVHWA_SURFHANDLE_INVALID);
|
---|
| 2616 | }
|
---|
| 2617 | }
|
---|
| 2618 |
|
---|
[33540] | 2619 | /* just in case we destroy a visible overlay surface */
|
---|
[22852] | 2620 | mRepaintNeeded = true;
|
---|
| 2621 |
|
---|
[22816] | 2622 | void * test = mSurfHandleTable.remove(pCmd->u.in.hSurf);
|
---|
[22953] | 2623 | Assert(test); NOREF(test);
|
---|
[22816] | 2624 |
|
---|
| 2625 | return VINF_SUCCESS;
|
---|
| 2626 | }
|
---|
| 2627 |
|
---|
[71651] | 2628 | #define VBOXVHWA_CONSTRUCT_QRECT_FROM_RECTL_RB(a_pr) \
|
---|
| 2629 | QRect((a_pr)->left, \
|
---|
| 2630 | (a_pr)->top, \
|
---|
| 2631 | (a_pr)->right - (a_pr)->left + 1, \
|
---|
| 2632 | (a_pr)->bottom - (a_pr)->top + 1)
|
---|
[22816] | 2633 |
|
---|
[71651] | 2634 | #define VBOXVHWA_CONSTRUCT_QRECT_FROM_RECTL_WH(a_pr) \
|
---|
| 2635 | QRect((a_pr)->left, \
|
---|
| 2636 | (a_pr)->top, \
|
---|
| 2637 | (a_pr)->right - (a_pr)->left, \
|
---|
| 2638 | (a_pr)->bottom - (a_pr)->top)
|
---|
[22816] | 2639 |
|
---|
[71594] | 2640 | int VBoxVHWAImage::vhwaSurfaceLock(struct VBOXVHWACMD_SURF_LOCK RT_UNTRUSTED_VOLATILE_GUEST *pCmd)
|
---|
[22816] | 2641 | {
|
---|
| 2642 | VBoxVHWASurfaceBase *pSurf = handle2Surface(pCmd->u.in.hSurf);
|
---|
[81210] | 2643 | AssertReturn(pSurf, VERR_INVALID_PARAMETER);
|
---|
[22816] | 2644 | VBOXQGLLOG_ENTER(("pSurf (0x%x)\n",pSurf));
|
---|
[81210] | 2645 |
|
---|
[22816] | 2646 | vboxCheckUpdateAddress (pSurf, pCmd->u.in.offSurface);
|
---|
[27839] | 2647 | if (pCmd->u.in.rectValid)
|
---|
[22816] | 2648 | {
|
---|
| 2649 | QRect r = VBOXVHWA_CONSTRUCT_QRECT_FROM_RECTL_WH(&pCmd->u.in.rect);
|
---|
| 2650 | return pSurf->lock(&r, pCmd->u.in.flags);
|
---|
| 2651 | }
|
---|
| 2652 | return pSurf->lock(NULL, pCmd->u.in.flags);
|
---|
| 2653 | }
|
---|
| 2654 |
|
---|
[71594] | 2655 | int VBoxVHWAImage::vhwaSurfaceUnlock(struct VBOXVHWACMD_SURF_UNLOCK RT_UNTRUSTED_VOLATILE_GUEST *pCmd)
|
---|
[22816] | 2656 | {
|
---|
| 2657 | VBoxVHWASurfaceBase *pSurf = handle2Surface(pCmd->u.in.hSurf);
|
---|
[81210] | 2658 | AssertReturn(pSurf, VERR_INVALID_PARAMETER);
|
---|
[24044] | 2659 | #ifdef DEBUG_misha
|
---|
| 2660 | /* for performance reasons we should receive unlock for visible surfaces only
|
---|
| 2661 | * other surfaces receive unlock only once becoming visible, e.g. on DdFlip
|
---|
| 2662 | * Ensure this is so*/
|
---|
[71651] | 2663 | if (pSurf != mDisplay.getPrimary())
|
---|
[24044] | 2664 | {
|
---|
| 2665 | const OverlayList & overlays = mDisplay.overlays();
|
---|
| 2666 | bool bFound = false;
|
---|
| 2667 |
|
---|
[71651] | 2668 | if (!mDisplay.isPrimary(pSurf))
|
---|
[24044] | 2669 | {
|
---|
[24646] | 2670 | for (OverlayList::const_iterator it = overlays.begin();
|
---|
| 2671 | it != overlays.end(); ++ it)
|
---|
[24044] | 2672 | {
|
---|
[24646] | 2673 | VBoxVHWASurfList * pSurfList = *it;
|
---|
[71651] | 2674 | if (pSurfList->current() == pSurf)
|
---|
[24646] | 2675 | {
|
---|
| 2676 | bFound = true;
|
---|
| 2677 | break;
|
---|
| 2678 | }
|
---|
[24044] | 2679 | }
|
---|
[24646] | 2680 |
|
---|
| 2681 | Assert(bFound);
|
---|
[24044] | 2682 | }
|
---|
| 2683 |
|
---|
[24646] | 2684 | // Assert(bFound);
|
---|
[24044] | 2685 | }
|
---|
| 2686 | #endif
|
---|
[22816] | 2687 | VBOXQGLLOG_ENTER(("pSurf (0x%x)\n",pSurf));
|
---|
[71651] | 2688 | if (pCmd->u.in.xUpdatedMemValid)
|
---|
[22816] | 2689 | {
|
---|
| 2690 | QRect r = VBOXVHWA_CONSTRUCT_QRECT_FROM_RECTL_WH(&pCmd->u.in.xUpdatedMemRect);
|
---|
| 2691 | pSurf->updatedMem(&r);
|
---|
| 2692 | }
|
---|
[24646] | 2693 |
|
---|
[22816] | 2694 | return pSurf->unlock();
|
---|
| 2695 | }
|
---|
| 2696 |
|
---|
[71594] | 2697 | int VBoxVHWAImage::vhwaSurfaceBlt(struct VBOXVHWACMD_SURF_BLT RT_UNTRUSTED_VOLATILE_GUEST *pCmd)
|
---|
[22816] | 2698 | {
|
---|
| 2699 | Q_UNUSED(pCmd);
|
---|
| 2700 | return VERR_NOT_IMPLEMENTED;
|
---|
| 2701 | }
|
---|
| 2702 |
|
---|
[71594] | 2703 | int VBoxVHWAImage::vhwaSurfaceFlip(struct VBOXVHWACMD_SURF_FLIP RT_UNTRUSTED_VOLATILE_GUEST *pCmd)
|
---|
[22816] | 2704 | {
|
---|
| 2705 | VBoxVHWASurfaceBase *pTargSurf = handle2Surface(pCmd->u.in.hTargSurf);
|
---|
[81210] | 2706 | AssertReturn(pTargSurf, VERR_INVALID_PARAMETER);
|
---|
[22816] | 2707 | VBoxVHWASurfaceBase *pCurrSurf = handle2Surface(pCmd->u.in.hCurrSurf);
|
---|
[81210] | 2708 | AssertReturn(pCurrSurf, VERR_INVALID_PARAMETER);
|
---|
| 2709 | VBOXQGLLOG_ENTER(("pTargSurf (0x%x), pCurrSurf (0x%x)\n", pTargSurf, pCurrSurf));
|
---|
[22816] | 2710 | vboxCheckUpdateAddress (pCurrSurf, pCmd->u.in.offCurrSurface);
|
---|
| 2711 | vboxCheckUpdateAddress (pTargSurf, pCmd->u.in.offTargSurface);
|
---|
| 2712 |
|
---|
[71651] | 2713 | if (pCmd->u.in.xUpdatedTargMemValid)
|
---|
[22816] | 2714 | {
|
---|
| 2715 | QRect r = VBOXVHWA_CONSTRUCT_QRECT_FROM_RECTL_WH(&pCmd->u.in.xUpdatedTargMemRect);
|
---|
| 2716 | pTargSurf->updatedMem(&r);
|
---|
| 2717 | }
|
---|
| 2718 | pTargSurf->getComplexList()->setCurrentVisible(pTargSurf);
|
---|
| 2719 |
|
---|
[22852] | 2720 | mRepaintNeeded = true;
|
---|
[22816] | 2721 | #ifdef DEBUG
|
---|
| 2722 | pCurrSurf->cFlipsCurr++;
|
---|
| 2723 | pTargSurf->cFlipsTarg++;
|
---|
| 2724 | #endif
|
---|
[25232] | 2725 |
|
---|
[22816] | 2726 | return VINF_SUCCESS;
|
---|
| 2727 | }
|
---|
| 2728 |
|
---|
[71594] | 2729 | int VBoxVHWAImage::vhwaSurfaceColorFill(struct VBOXVHWACMD_SURF_COLORFILL RT_UNTRUSTED_VOLATILE_GUEST *pCmd)
|
---|
[32823] | 2730 | {
|
---|
[34276] | 2731 | NOREF(pCmd);
|
---|
[32823] | 2732 | return VERR_NOT_IMPLEMENTED;
|
---|
| 2733 | }
|
---|
| 2734 |
|
---|
[71594] | 2735 | void VBoxVHWAImage::vhwaDoSurfaceOverlayUpdate(VBoxVHWASurfaceBase *pDstSurf, VBoxVHWASurfaceBase *pSrcSurf,
|
---|
| 2736 | struct VBOXVHWACMD_SURF_OVERLAY_UPDATE RT_UNTRUSTED_VOLATILE_GUEST *pCmd)
|
---|
[22816] | 2737 | {
|
---|
[71651] | 2738 | if (pCmd->u.in.flags & VBOXVHWA_OVER_KEYDEST)
|
---|
[22816] | 2739 | {
|
---|
| 2740 | VBOXQGLLOG((", KEYDEST"));
|
---|
| 2741 | /* we use src (overlay) surface to maintain overridden dst ckey info
|
---|
| 2742 | * to allow multiple overlays have different overridden dst keys for one primary surface */
|
---|
| 2743 | /* non-null dstOverlayCKey for overlay would mean the overlay surface contains the overridden
|
---|
| 2744 | * dst ckey value in defaultDstOverlayCKey
|
---|
| 2745 | * this allows the NULL to be a valid overridden value as well
|
---|
| 2746 | * i.e.
|
---|
| 2747 | * 1. indicate the value is NUL overridden, just set NULL*/
|
---|
| 2748 | pSrcSurf->setOverriddenDstOverlayCKey(NULL);
|
---|
| 2749 | }
|
---|
[71651] | 2750 | else if (pCmd->u.in.flags & VBOXVHWA_OVER_KEYDESTOVERRIDE)
|
---|
[22816] | 2751 | {
|
---|
| 2752 | VBOXQGLLOG((", KEYDESTOVERRIDE"));
|
---|
| 2753 | /* we use src (overlay) surface to maintain overridden dst ckey info
|
---|
| 2754 | * to allow multiple overlays have different overridden dst keys for one primary surface */
|
---|
| 2755 | /* non-null dstOverlayCKey for overlay would mean the overlay surface contains the overridden
|
---|
| 2756 | * dst ckey value in defaultDstOverlayCKey
|
---|
| 2757 | * this allows the NULL to be a valid overridden value as well
|
---|
| 2758 | * i.e.
|
---|
| 2759 | * 1. indicate the value is overridden (no matter what we write here, bu it should be not NULL)*/
|
---|
| 2760 | VBoxVHWAColorKey ckey(pCmd->u.in.desc.DstCK.high, pCmd->u.in.desc.DstCK.low);
|
---|
| 2761 | VBOXQGLLOG_CKEY(" ckey: ",&ckey, "\n");
|
---|
| 2762 | pSrcSurf->setOverriddenDstOverlayCKey(&ckey);
|
---|
| 2763 | /* tell the ckey is enabled */
|
---|
| 2764 | pSrcSurf->setDefaultDstOverlayCKey(&ckey);
|
---|
| 2765 | }
|
---|
| 2766 | else
|
---|
| 2767 | {
|
---|
| 2768 | VBOXQGLLOG((", no KEYDEST"));
|
---|
| 2769 | /* we use src (overlay) surface to maintain overridden dst ckey info
|
---|
| 2770 | * to allow multiple overlays have different overridden dst keys for one primary surface */
|
---|
| 2771 | /* non-null dstOverlayCKey for overlay would mean the overlay surface contains the overridden
|
---|
| 2772 | * dst ckey value in defaultDstOverlayCKey
|
---|
| 2773 | * this allows the NULL to be a valid overridden value as well
|
---|
| 2774 | * i.e.
|
---|
| 2775 | * 1. indicate the value is overridden (no matter what we write here, bu it should be not NULL)*/
|
---|
| 2776 | VBoxVHWAColorKey dummyCKey(0, 0);
|
---|
| 2777 | pSrcSurf->setOverriddenDstOverlayCKey(&dummyCKey);
|
---|
| 2778 | /* tell the ckey is disabled */
|
---|
| 2779 | pSrcSurf->setDefaultDstOverlayCKey(NULL);
|
---|
| 2780 | }
|
---|
| 2781 |
|
---|
[71651] | 2782 | if (pCmd->u.in.flags & VBOXVHWA_OVER_KEYSRC)
|
---|
[22816] | 2783 | {
|
---|
| 2784 | VBOXQGLLOG((", KEYSRC"));
|
---|
| 2785 | pSrcSurf->resetDefaultSrcOverlayCKey();
|
---|
| 2786 | }
|
---|
[71651] | 2787 | else if (pCmd->u.in.flags & VBOXVHWA_OVER_KEYSRCOVERRIDE)
|
---|
[22816] | 2788 | {
|
---|
| 2789 | VBOXQGLLOG((", KEYSRCOVERRIDE"));
|
---|
| 2790 | VBoxVHWAColorKey ckey(pCmd->u.in.desc.SrcCK.high, pCmd->u.in.desc.SrcCK.low);
|
---|
| 2791 | pSrcSurf->setOverriddenSrcOverlayCKey(&ckey);
|
---|
| 2792 | }
|
---|
| 2793 | else
|
---|
| 2794 | {
|
---|
| 2795 | VBOXQGLLOG((", no KEYSRC"));
|
---|
| 2796 | pSrcSurf->setOverriddenSrcOverlayCKey(NULL);
|
---|
| 2797 | }
|
---|
| 2798 | VBOXQGLLOG(("\n"));
|
---|
[71651] | 2799 | if (pDstSurf)
|
---|
[22816] | 2800 | {
|
---|
| 2801 | QRect dstRect = VBOXVHWA_CONSTRUCT_QRECT_FROM_RECTL_WH(&pCmd->u.in.dstRect);
|
---|
| 2802 | QRect srcRect = VBOXVHWA_CONSTRUCT_QRECT_FROM_RECTL_WH(&pCmd->u.in.srcRect);
|
---|
| 2803 |
|
---|
| 2804 | VBOXQGLLOG(("*******overlay update*******\n"));
|
---|
| 2805 | VBOXQGLLOG(("dstSurfSize: w(%d), h(%d)\n", pDstSurf->width(), pDstSurf->height()));
|
---|
| 2806 | VBOXQGLLOG(("srcSurfSize: w(%d), h(%d)\n", pSrcSurf->width(), pSrcSurf->height()));
|
---|
| 2807 | VBOXQGLLOG_QRECT("dstRect:", &dstRect, "\n");
|
---|
| 2808 | VBOXQGLLOG_QRECT("srcRect:", &srcRect, "\n");
|
---|
| 2809 |
|
---|
[25385] | 2810 | pSrcSurf->setPrimary(pDstSurf);
|
---|
[22816] | 2811 |
|
---|
[23766] | 2812 | pSrcSurf->setRects(dstRect, srcRect);
|
---|
[22816] | 2813 | }
|
---|
| 2814 | }
|
---|
| 2815 |
|
---|
[71594] | 2816 | int VBoxVHWAImage::vhwaSurfaceOverlayUpdate(struct VBOXVHWACMD_SURF_OVERLAY_UPDATE RT_UNTRUSTED_VOLATILE_GUEST *pCmd)
|
---|
[22816] | 2817 | {
|
---|
| 2818 | VBoxVHWASurfaceBase *pSrcSurf = handle2Surface(pCmd->u.in.hSrcSurf);
|
---|
[81210] | 2819 | AssertReturn(pSrcSurf, VERR_INVALID_PARAMETER);
|
---|
[22816] | 2820 | VBoxVHWASurfList *pList = pSrcSurf->getComplexList();
|
---|
| 2821 | vboxCheckUpdateAddress (pSrcSurf, pCmd->u.in.offSrcSurface);
|
---|
| 2822 | VBOXQGLLOG(("OverlayUpdate: pSrcSurf (0x%x)\n",pSrcSurf));
|
---|
| 2823 | VBoxVHWASurfaceBase *pDstSurf = NULL;
|
---|
| 2824 |
|
---|
[71651] | 2825 | if (pCmd->u.in.hDstSurf)
|
---|
[22816] | 2826 | {
|
---|
| 2827 | pDstSurf = handle2Surface(pCmd->u.in.hDstSurf);
|
---|
[81210] | 2828 | AssertReturn(pDstSurf, VERR_INVALID_PARAMETER);
|
---|
[22816] | 2829 | vboxCheckUpdateAddress (pDstSurf, pCmd->u.in.offDstSurface);
|
---|
| 2830 | VBOXQGLLOG(("pDstSurf (0x%x)\n",pDstSurf));
|
---|
[22920] | 2831 | #ifdef DEBUGVHWASTRICT
|
---|
[22816] | 2832 | Assert(pDstSurf == mDisplay.getVGA());
|
---|
| 2833 | Assert(mDisplay.getVGA() == mDisplay.getPrimary());
|
---|
[22836] | 2834 | #endif
|
---|
[22816] | 2835 | Assert(pDstSurf->getComplexList() == mDisplay.getVGA()->getComplexList());
|
---|
| 2836 |
|
---|
[71651] | 2837 | if (pCmd->u.in.flags & VBOXVHWA_OVER_SHOW)
|
---|
[22816] | 2838 | {
|
---|
[71651] | 2839 | if (pDstSurf != mDisplay.getPrimary())
|
---|
[22816] | 2840 | {
|
---|
| 2841 | mDisplay.updateVGA(pDstSurf);
|
---|
| 2842 | pDstSurf->getComplexList()->setCurrentVisible(pDstSurf);
|
---|
| 2843 | }
|
---|
| 2844 | }
|
---|
| 2845 | }
|
---|
| 2846 |
|
---|
[32622] | 2847 | #ifdef VBOX_WITH_WDDM
|
---|
[71651] | 2848 | if (pCmd->u.in.xFlags & VBOXVHWACMD_SURF_OVERLAY_UPDATE_F_SRCMEMRECT)
|
---|
[30239] | 2849 | {
|
---|
| 2850 | QRect r = VBOXVHWA_CONSTRUCT_QRECT_FROM_RECTL_WH(&pCmd->u.in.xUpdatedSrcMemRect);
|
---|
| 2851 | pSrcSurf->updatedMem(&r);
|
---|
| 2852 | }
|
---|
[71651] | 2853 | if (pCmd->u.in.xFlags & VBOXVHWACMD_SURF_OVERLAY_UPDATE_F_DSTMEMRECT)
|
---|
[33714] | 2854 | {
|
---|
[81210] | 2855 | AssertReturn(pDstSurf, VERR_INVALID_PARAMETER);
|
---|
[33714] | 2856 | QRect r = VBOXVHWA_CONSTRUCT_QRECT_FROM_RECTL_WH(&pCmd->u.in.xUpdatedDstMemRect);
|
---|
| 2857 | pDstSurf->updatedMem(&r);
|
---|
| 2858 | }
|
---|
[30239] | 2859 | #endif
|
---|
| 2860 |
|
---|
[22816] | 2861 | const SurfList & surfaces = pList->surfaces();
|
---|
| 2862 |
|
---|
| 2863 | for (SurfList::const_iterator it = surfaces.begin();
|
---|
| 2864 | it != surfaces.end(); ++ it)
|
---|
| 2865 | {
|
---|
| 2866 | VBoxVHWASurfaceBase *pCurSrcSurf = (*it);
|
---|
| 2867 | vhwaDoSurfaceOverlayUpdate(pDstSurf, pCurSrcSurf, pCmd);
|
---|
| 2868 | }
|
---|
| 2869 |
|
---|
[71651] | 2870 | if (pCmd->u.in.flags & VBOXVHWA_OVER_HIDE)
|
---|
[22816] | 2871 | {
|
---|
[23766] | 2872 | VBOXQGLLOG(("hide\n"));
|
---|
[22816] | 2873 | pList->setCurrentVisible(NULL);
|
---|
| 2874 | }
|
---|
[71651] | 2875 | else if (pCmd->u.in.flags & VBOXVHWA_OVER_SHOW)
|
---|
[22816] | 2876 | {
|
---|
[23766] | 2877 | VBOXQGLLOG(("show\n"));
|
---|
[22816] | 2878 | pList->setCurrentVisible(pSrcSurf);
|
---|
| 2879 | }
|
---|
| 2880 |
|
---|
[22852] | 2881 | mRepaintNeeded = true;
|
---|
| 2882 |
|
---|
[22816] | 2883 | return VINF_SUCCESS;
|
---|
| 2884 | }
|
---|
| 2885 |
|
---|
[71594] | 2886 | int VBoxVHWAImage::vhwaSurfaceOverlaySetPosition(struct VBOXVHWACMD_SURF_OVERLAY_SETPOSITION RT_UNTRUSTED_VOLATILE_GUEST *pCmd)
|
---|
[22816] | 2887 | {
|
---|
| 2888 | VBoxVHWASurfaceBase *pDstSurf = handle2Surface(pCmd->u.in.hDstSurf);
|
---|
[81210] | 2889 | AssertReturn(pDstSurf, VERR_INVALID_PARAMETER);
|
---|
[22816] | 2890 | VBoxVHWASurfaceBase *pSrcSurf = handle2Surface(pCmd->u.in.hSrcSurf);
|
---|
[81210] | 2891 | AssertReturn(pSrcSurf, VERR_INVALID_PARAMETER);
|
---|
[22816] | 2892 |
|
---|
| 2893 | VBOXQGLLOG_ENTER(("pDstSurf (0x%x), pSrcSurf (0x%x)\n",pDstSurf,pSrcSurf));
|
---|
| 2894 |
|
---|
| 2895 | vboxCheckUpdateAddress (pSrcSurf, pCmd->u.in.offSrcSurface);
|
---|
| 2896 | vboxCheckUpdateAddress (pDstSurf, pCmd->u.in.offDstSurface);
|
---|
| 2897 |
|
---|
| 2898 | VBoxVHWASurfList *pList = pSrcSurf->getComplexList();
|
---|
| 2899 | const SurfList & surfaces = pList->surfaces();
|
---|
| 2900 |
|
---|
| 2901 | QPoint pos(pCmd->u.in.xPos, pCmd->u.in.yPos);
|
---|
| 2902 |
|
---|
[22920] | 2903 | #ifdef DEBUGVHWASTRICT
|
---|
[22852] | 2904 | Assert(pDstSurf == mDisplay.getVGA());
|
---|
| 2905 | Assert(mDisplay.getVGA() == mDisplay.getPrimary());
|
---|
| 2906 | #endif
|
---|
[27785] | 2907 | if (pSrcSurf->getComplexList()->current() != NULL)
|
---|
[22852] | 2908 | {
|
---|
| 2909 | Assert(pDstSurf);
|
---|
[27785] | 2910 | if (pDstSurf != mDisplay.getPrimary())
|
---|
[22852] | 2911 | {
|
---|
| 2912 | mDisplay.updateVGA(pDstSurf);
|
---|
| 2913 | pDstSurf->getComplexList()->setCurrentVisible(pDstSurf);
|
---|
| 2914 | }
|
---|
| 2915 | }
|
---|
| 2916 |
|
---|
| 2917 | mRepaintNeeded = true;
|
---|
| 2918 |
|
---|
[22816] | 2919 | for (SurfList::const_iterator it = surfaces.begin();
|
---|
| 2920 | it != surfaces.end(); ++ it)
|
---|
| 2921 | {
|
---|
| 2922 | VBoxVHWASurfaceBase *pCurSrcSurf = (*it);
|
---|
[23766] | 2923 | pCurSrcSurf->setTargRectPosition(pos);
|
---|
[22816] | 2924 | }
|
---|
| 2925 |
|
---|
| 2926 | return VINF_SUCCESS;
|
---|
| 2927 | }
|
---|
| 2928 |
|
---|
[71594] | 2929 | int VBoxVHWAImage::vhwaSurfaceColorkeySet(struct VBOXVHWACMD_SURF_COLORKEY_SET RT_UNTRUSTED_VOLATILE_GUEST *pCmd)
|
---|
[22816] | 2930 | {
|
---|
| 2931 | VBoxVHWASurfaceBase *pSurf = handle2Surface(pCmd->u.in.hSurf);
|
---|
[81210] | 2932 | AssertReturn(pSurf, VERR_INVALID_PARAMETER);
|
---|
[71651] | 2933 | VBOXQGLLOG_ENTER(("pSurf (0x%x)\n", pSurf));
|
---|
[22816] | 2934 |
|
---|
| 2935 | vboxCheckUpdateAddress (pSurf, pCmd->u.in.offSurface);
|
---|
| 2936 |
|
---|
[22852] | 2937 | mRepaintNeeded = true;
|
---|
| 2938 |
|
---|
[27785] | 2939 | if (pCmd->u.in.flags & VBOXVHWA_CKEY_DESTBLT)
|
---|
[22816] | 2940 | {
|
---|
| 2941 | VBoxVHWAColorKey ckey(pCmd->u.in.CKey.high, pCmd->u.in.CKey.low);
|
---|
| 2942 | pSurf->setDstBltCKey(&ckey);
|
---|
| 2943 | }
|
---|
[27785] | 2944 | if (pCmd->u.in.flags & VBOXVHWA_CKEY_DESTOVERLAY)
|
---|
[22816] | 2945 | {
|
---|
| 2946 | VBoxVHWAColorKey ckey(pCmd->u.in.CKey.high, pCmd->u.in.CKey.low);
|
---|
| 2947 | pSurf->setDefaultDstOverlayCKey(&ckey);
|
---|
| 2948 | }
|
---|
[27785] | 2949 | if (pCmd->u.in.flags & VBOXVHWA_CKEY_SRCBLT)
|
---|
[22816] | 2950 | {
|
---|
| 2951 | VBoxVHWAColorKey ckey(pCmd->u.in.CKey.high, pCmd->u.in.CKey.low);
|
---|
| 2952 | pSurf->setSrcBltCKey(&ckey);
|
---|
[27960] | 2953 |
|
---|
[22816] | 2954 | }
|
---|
[27785] | 2955 | if (pCmd->u.in.flags & VBOXVHWA_CKEY_SRCOVERLAY)
|
---|
[22816] | 2956 | {
|
---|
| 2957 | VBoxVHWAColorKey ckey(pCmd->u.in.CKey.high, pCmd->u.in.CKey.low);
|
---|
| 2958 | pSurf->setDefaultSrcOverlayCKey(&ckey);
|
---|
| 2959 | }
|
---|
| 2960 |
|
---|
| 2961 | return VINF_SUCCESS;
|
---|
| 2962 | }
|
---|
| 2963 |
|
---|
[71594] | 2964 | int VBoxVHWAImage::vhwaQueryInfo1(struct VBOXVHWACMD_QUERYINFO1 RT_UNTRUSTED_VOLATILE_GUEST *pCmd)
|
---|
[22816] | 2965 | {
|
---|
| 2966 | VBOXQGLLOG_ENTER(("\n"));
|
---|
| 2967 | bool bEnabled = false;
|
---|
[27682] | 2968 | const VBoxVHWAInfo & info = vboxVHWAGetSupportInfo(NULL);
|
---|
[71651] | 2969 | if (info.isVHWASupported())
|
---|
[22816] | 2970 | {
|
---|
| 2971 | Assert(pCmd->u.in.guestVersion.maj == VBOXVHWA_VERSION_MAJ);
|
---|
[71651] | 2972 | if (pCmd->u.in.guestVersion.maj == VBOXVHWA_VERSION_MAJ)
|
---|
[22816] | 2973 | {
|
---|
| 2974 | Assert(pCmd->u.in.guestVersion.min == VBOXVHWA_VERSION_MIN);
|
---|
[71651] | 2975 | if (pCmd->u.in.guestVersion.min == VBOXVHWA_VERSION_MIN)
|
---|
[22816] | 2976 | {
|
---|
| 2977 | Assert(pCmd->u.in.guestVersion.bld == VBOXVHWA_VERSION_BLD);
|
---|
[71651] | 2978 | if (pCmd->u.in.guestVersion.bld == VBOXVHWA_VERSION_BLD)
|
---|
[22816] | 2979 | {
|
---|
| 2980 | Assert(pCmd->u.in.guestVersion.reserved == VBOXVHWA_VERSION_RSV);
|
---|
[71651] | 2981 | if (pCmd->u.in.guestVersion.reserved == VBOXVHWA_VERSION_RSV)
|
---|
[22816] | 2982 | {
|
---|
| 2983 | bEnabled = true;
|
---|
| 2984 | }
|
---|
| 2985 | }
|
---|
| 2986 | }
|
---|
| 2987 | }
|
---|
| 2988 | }
|
---|
| 2989 |
|
---|
[71594] | 2990 | memset((void *)pCmd, 0, sizeof(VBOXVHWACMD_QUERYINFO1));
|
---|
| 2991 | if (bEnabled)
|
---|
[22816] | 2992 | {
|
---|
| 2993 | pCmd->u.out.cfgFlags = VBOXVHWA_CFG_ENABLED;
|
---|
| 2994 |
|
---|
| 2995 | pCmd->u.out.caps =
|
---|
[25507] | 2996 | /* we do not support blitting for now */
|
---|
[22816] | 2997 | // VBOXVHWA_CAPS_BLT | VBOXVHWA_CAPS_BLTSTRETCH | VBOXVHWA_CAPS_BLTQUEUE
|
---|
[25507] | 2998 | // | VBOXVHWA_CAPS_BLTCOLORFILL not supported, although adding it is trivial
|
---|
| 2999 | // | VBOXVHWA_CAPS_BLTFOURCC set below if shader support is available
|
---|
[71651] | 3000 | VBOXVHWA_CAPS_OVERLAY
|
---|
| 3001 | | VBOXVHWA_CAPS_OVERLAYSTRETCH
|
---|
| 3002 | | VBOXVHWA_CAPS_OVERLAYCANTCLIP
|
---|
[22816] | 3003 | // | VBOXVHWA_CAPS_OVERLAYFOURCC set below if shader support is available
|
---|
[71651] | 3004 | ;
|
---|
[22816] | 3005 |
|
---|
[63567] | 3006 | /** @todo check if we could use DDSCAPS_ALPHA instead of colorkeying */
|
---|
[25507] | 3007 |
|
---|
[22816] | 3008 | pCmd->u.out.caps2 = VBOXVHWA_CAPS2_CANRENDERWINDOWED
|
---|
| 3009 | | VBOXVHWA_CAPS2_WIDESURFACES;
|
---|
| 3010 |
|
---|
[63567] | 3011 | /// @todo setup stretchCaps
|
---|
[22816] | 3012 | pCmd->u.out.stretchCaps = 0;
|
---|
| 3013 |
|
---|
| 3014 | pCmd->u.out.numOverlays = 1;
|
---|
[63567] | 3015 | /** @todo set curOverlays properly */
|
---|
[22816] | 3016 | pCmd->u.out.curOverlays = 0;
|
---|
| 3017 |
|
---|
[71651] | 3018 | pCmd->u.out.surfaceCaps = VBOXVHWA_SCAPS_PRIMARYSURFACE
|
---|
[22951] | 3019 | #ifndef VBOXVHWA_ALLOW_PRIMARY_AND_OVERLAY_ONLY
|
---|
[71651] | 3020 | | VBOXVHWA_SCAPS_OFFSCREENPLAIN
|
---|
[22951] | 3021 | #endif
|
---|
[71651] | 3022 | | VBOXVHWA_SCAPS_FLIP
|
---|
| 3023 | | VBOXVHWA_SCAPS_LOCALVIDMEM
|
---|
| 3024 | | VBOXVHWA_SCAPS_OVERLAY
|
---|
| 3025 | // | VBOXVHWA_SCAPS_BACKBUFFER
|
---|
| 3026 | // | VBOXVHWA_SCAPS_FRONTBUFFER
|
---|
| 3027 | // | VBOXVHWA_SCAPS_VIDEOMEMORY
|
---|
| 3028 | // | VBOXVHWA_SCAPS_COMPLEX
|
---|
| 3029 | // | VBOXVHWA_SCAPS_VISIBLE
|
---|
| 3030 | ;
|
---|
[22816] | 3031 |
|
---|
[71651] | 3032 | if (info.getGlInfo().isFragmentShaderSupported() && info.getGlInfo().getMultiTexNumSupported() >= 2)
|
---|
[22816] | 3033 | {
|
---|
| 3034 | pCmd->u.out.caps |= VBOXVHWA_CAPS_COLORKEY
|
---|
[71651] | 3035 | | VBOXVHWA_CAPS_COLORKEYHWASSIST;
|
---|
[22816] | 3036 |
|
---|
[71651] | 3037 | pCmd->u.out.colorKeyCaps = 0
|
---|
| 3038 | // | VBOXVHWA_CKEYCAPS_DESTBLT | VBOXVHWA_CKEYCAPS_DESTBLTCLRSPACE
|
---|
| 3039 | // | VBOXVHWA_CKEYCAPS_SRCBLT| VBOXVHWA_CKEYCAPS_SRCBLTCLRSPACE
|
---|
| 3040 | // | VBOXVHWA_CKEYCAPS_SRCOVERLAY | VBOXVHWA_CKEYCAPS_SRCOVERLAYONEACTIVE
|
---|
| 3041 | | VBOXVHWA_CKEYCAPS_DESTOVERLAY
|
---|
| 3042 | | VBOXVHWA_CKEYCAPS_DESTOVERLAYONEACTIVE;
|
---|
[22816] | 3043 |
|
---|
[71651] | 3044 | if (info.getGlInfo().isTextureRectangleSupported())
|
---|
[22816] | 3045 | {
|
---|
| 3046 | pCmd->u.out.caps |= VBOXVHWA_CAPS_OVERLAYFOURCC
|
---|
[71651] | 3047 | // | VBOXVHWA_CAPS_BLTFOURCC
|
---|
[22816] | 3048 | ;
|
---|
| 3049 |
|
---|
[71651] | 3050 | pCmd->u.out.colorKeyCaps |= 0
|
---|
| 3051 | // | VBOXVHWA_CKEYCAPS_SRCOVERLAYYUV
|
---|
| 3052 | | VBOXVHWA_CKEYCAPS_DESTOVERLAYYUV;
|
---|
| 3053 |
|
---|
[22816] | 3054 | // pCmd->u.out.caps2 |= VBOXVHWA_CAPS2_COPYFOURCC;
|
---|
| 3055 |
|
---|
[25583] | 3056 | pCmd->u.out.numFourCC = mSettings->getIntersection(info, 0, NULL);
|
---|
[22816] | 3057 | }
|
---|
| 3058 | }
|
---|
| 3059 | }
|
---|
| 3060 |
|
---|
| 3061 | return VINF_SUCCESS;
|
---|
| 3062 | }
|
---|
| 3063 |
|
---|
[71594] | 3064 | int VBoxVHWAImage::vhwaQueryInfo2(struct VBOXVHWACMD_QUERYINFO2 RT_UNTRUSTED_VOLATILE_GUEST *pCmd)
|
---|
[22816] | 3065 | {
|
---|
| 3066 | VBOXQGLLOG_ENTER(("\n"));
|
---|
| 3067 |
|
---|
[71651] | 3068 | const VBoxVHWAInfo &info = vboxVHWAGetSupportInfo(NULL);
|
---|
[25583] | 3069 | uint32_t aFourcc[VBOXVHWA_NUMFOURCC];
|
---|
| 3070 | int num = mSettings->getIntersection(info, VBOXVHWA_NUMFOURCC, aFourcc);
|
---|
| 3071 | Assert(pCmd->numFourCC >= (uint32_t)num);
|
---|
[71651] | 3072 | if (pCmd->numFourCC < (uint32_t)num)
|
---|
[22816] | 3073 | return VERR_GENERAL_FAILURE;
|
---|
| 3074 |
|
---|
[25583] | 3075 | pCmd->numFourCC = (uint32_t)num;
|
---|
[71651] | 3076 | memcpy((void *)&pCmd->FourCC[0], aFourcc, num * sizeof(aFourcc[0]));
|
---|
[22816] | 3077 | return VINF_SUCCESS;
|
---|
| 3078 | }
|
---|
| 3079 |
|
---|
[27682] | 3080 | //static DECLCALLBACK(void) vboxQGLSaveExec(PSSMHANDLE pSSM, void *pvUser)
|
---|
| 3081 | //{
|
---|
| 3082 | // VBoxVHWAImage * pw = (VBoxVHWAImage*)pvUser;
|
---|
| 3083 | // pw->vhwaSaveExec(pSSM);
|
---|
| 3084 | //}
|
---|
| 3085 | //
|
---|
| 3086 | //static DECLCALLBACK(int) vboxQGLLoadExec(PSSMHANDLE pSSM, void *pvUser, uint32_t u32Version, uint32_t uPass)
|
---|
| 3087 | //{
|
---|
| 3088 | // Assert(uPass == SSM_PASS_FINAL); NOREF(uPass);
|
---|
| 3089 | // VBoxVHWAImage * pw = (VBoxVHWAImage*)pvUser;
|
---|
| 3090 | // return VBoxVHWAImage::vhwaLoadExec(&pw->onResizeCmdList(), pSSM, u32Version);
|
---|
| 3091 | //}
|
---|
[22816] | 3092 |
|
---|
[71651] | 3093 | int VBoxVHWAImage::vhwaSaveSurface(struct SSMHANDLE *pSSM, VBoxVHWASurfaceBase *pSurf, uint32_t surfCaps)
|
---|
[22816] | 3094 | {
|
---|
| 3095 | VBOXQGL_SAVE_SURFSTART(pSSM);
|
---|
| 3096 |
|
---|
| 3097 | uint64_t u64 = vboxVRAMOffset(pSurf);
|
---|
| 3098 | int rc;
|
---|
[71651] | 3099 | rc = SSMR3PutU32(pSSM, pSurf->handle());
|
---|
| 3100 | rc = SSMR3PutU64(pSSM, u64);
|
---|
| 3101 | rc = SSMR3PutU32(pSSM, pSurf->width());
|
---|
| 3102 | rc = SSMR3PutU32(pSSM, pSurf->height());
|
---|
| 3103 | rc = SSMR3PutU32(pSSM, surfCaps);
|
---|
| 3104 |
|
---|
[22816] | 3105 | uint32_t flags = 0;
|
---|
[71651] | 3106 | const VBoxVHWAColorKey *pDstBltCKey = pSurf->dstBltCKey();
|
---|
| 3107 | const VBoxVHWAColorKey *pSrcBltCKey = pSurf->srcBltCKey();
|
---|
| 3108 | const VBoxVHWAColorKey *pDstOverlayCKey = pSurf->dstOverlayCKey();
|
---|
| 3109 | const VBoxVHWAColorKey *pSrcOverlayCKey = pSurf->srcOverlayCKey();
|
---|
| 3110 | if (pDstBltCKey)
|
---|
[22816] | 3111 | flags |= VBOXVHWA_SD_CKDESTBLT;
|
---|
[71651] | 3112 | if (pSrcBltCKey)
|
---|
[22816] | 3113 | flags |= VBOXVHWA_SD_CKSRCBLT;
|
---|
[71651] | 3114 | if (pDstOverlayCKey)
|
---|
[22816] | 3115 | flags |= VBOXVHWA_SD_CKDESTOVERLAY;
|
---|
[71651] | 3116 | if (pSrcOverlayCKey)
|
---|
[22816] | 3117 | flags |= VBOXVHWA_SD_CKSRCOVERLAY;
|
---|
[71651] | 3118 | rc = SSMR3PutU32(pSSM, flags);
|
---|
[22816] | 3119 |
|
---|
[71651] | 3120 | if (pDstBltCKey)
|
---|
[22816] | 3121 | {
|
---|
[71651] | 3122 | rc = SSMR3PutU32(pSSM, pDstBltCKey->lower());
|
---|
| 3123 | rc = SSMR3PutU32(pSSM, pDstBltCKey->upper());
|
---|
[22816] | 3124 | }
|
---|
[71651] | 3125 | if (pSrcBltCKey)
|
---|
[22816] | 3126 | {
|
---|
[71651] | 3127 | rc = SSMR3PutU32(pSSM, pSrcBltCKey->lower());
|
---|
| 3128 | rc = SSMR3PutU32(pSSM, pSrcBltCKey->upper());
|
---|
[22816] | 3129 | }
|
---|
[71651] | 3130 | if (pDstOverlayCKey)
|
---|
[22816] | 3131 | {
|
---|
[71651] | 3132 | rc = SSMR3PutU32(pSSM, pDstOverlayCKey->lower());
|
---|
| 3133 | rc = SSMR3PutU32(pSSM, pDstOverlayCKey->upper());
|
---|
[22816] | 3134 | }
|
---|
[71651] | 3135 | if (pSrcOverlayCKey)
|
---|
[22816] | 3136 | {
|
---|
[71651] | 3137 | rc = SSMR3PutU32(pSSM, pSrcOverlayCKey->lower());
|
---|
| 3138 | rc = SSMR3PutU32(pSSM, pSrcOverlayCKey->upper());
|
---|
[22816] | 3139 | }
|
---|
[71651] | 3140 | AssertRCReturn(rc, rc);
|
---|
[22816] | 3141 |
|
---|
[27682] | 3142 | const VBoxVHWAColorFormat & format = pSurf->pixelFormat();
|
---|
[22816] | 3143 | flags = 0;
|
---|
[71651] | 3144 | if (format.fourcc())
|
---|
[22816] | 3145 | {
|
---|
| 3146 | flags |= VBOXVHWA_PF_FOURCC;
|
---|
[71651] | 3147 | rc = SSMR3PutU32(pSSM, flags);
|
---|
| 3148 | rc = SSMR3PutU32(pSSM, format.fourcc());
|
---|
[22816] | 3149 | }
|
---|
| 3150 | else
|
---|
| 3151 | {
|
---|
| 3152 | flags |= VBOXVHWA_PF_RGB;
|
---|
[71651] | 3153 | rc = SSMR3PutU32(pSSM, flags);
|
---|
| 3154 | rc = SSMR3PutU32(pSSM, format.bitsPerPixel());
|
---|
| 3155 | rc = SSMR3PutU32(pSSM, format.r().mask());
|
---|
| 3156 | rc = SSMR3PutU32(pSSM, format.g().mask());
|
---|
| 3157 | rc = SSMR3PutU32(pSSM, format.b().mask());
|
---|
| 3158 | rc = SSMR3PutU32(pSSM, format.a().mask());
|
---|
[22816] | 3159 | }
|
---|
[71651] | 3160 | AssertRCReturn(rc, rc);
|
---|
[22816] | 3161 |
|
---|
| 3162 | VBOXQGL_SAVE_SURFSTOP(pSSM);
|
---|
| 3163 | return rc;
|
---|
| 3164 | }
|
---|
| 3165 |
|
---|
[27682] | 3166 | int VBoxVHWAImage::vhwaLoadSurface(VHWACommandList * pCmdList, struct SSMHANDLE * pSSM, uint32_t cBackBuffers, uint32_t u32Version)
|
---|
[22816] | 3167 | {
|
---|
| 3168 | Q_UNUSED(u32Version);
|
---|
| 3169 |
|
---|
| 3170 | VBOXQGL_LOAD_SURFSTART(pSSM);
|
---|
| 3171 |
|
---|
| 3172 | char *buf = (char*)malloc(VBOXVHWACMD_SIZE(VBOXVHWACMD_SURF_CREATE));
|
---|
[24925] | 3173 | memset(buf, 0, sizeof(VBOXVHWACMD_SIZE(VBOXVHWACMD_SURF_CREATE)));
|
---|
[71626] | 3174 | VBOXVHWACMD *pCmd = (VBOXVHWACMD *)buf;
|
---|
[22816] | 3175 | pCmd->enmCmd = VBOXVHWACMD_TYPE_SURF_CREATE;
|
---|
| 3176 | pCmd->Flags = VBOXVHWACMD_FLAG_HH_CMD;
|
---|
| 3177 |
|
---|
[71594] | 3178 | VBOXVHWACMD_SURF_CREATE *pCreateSurf = VBOXVHWACMD_BODY_HOST_HEAP(pCmd, VBOXVHWACMD_SURF_CREATE);
|
---|
[22816] | 3179 | int rc;
|
---|
| 3180 | uint32_t u32;
|
---|
| 3181 | rc = SSMR3GetU32(pSSM, &u32); AssertRC(rc);
|
---|
| 3182 | pCreateSurf->SurfInfo.hSurf = (VBOXVHWA_SURFHANDLE)u32;
|
---|
[71651] | 3183 | if (RT_SUCCESS(rc))
|
---|
[22816] | 3184 | {
|
---|
[71651] | 3185 | rc = SSMR3GetU64(pSSM, &pCreateSurf->SurfInfo.offSurface); AssertRC(rc);
|
---|
| 3186 | rc = SSMR3GetU32(pSSM, &pCreateSurf->SurfInfo.width); AssertRC(rc);
|
---|
| 3187 | rc = SSMR3GetU32(pSSM, &pCreateSurf->SurfInfo.height); AssertRC(rc);
|
---|
| 3188 | rc = SSMR3GetU32(pSSM, &pCreateSurf->SurfInfo.surfCaps); AssertRC(rc);
|
---|
| 3189 | rc = SSMR3GetU32(pSSM, &pCreateSurf->SurfInfo.flags); AssertRC(rc);
|
---|
| 3190 | if (pCreateSurf->SurfInfo.flags & VBOXVHWA_SD_CKDESTBLT)
|
---|
[22816] | 3191 | {
|
---|
[71651] | 3192 | rc = SSMR3GetU32(pSSM, &pCreateSurf->SurfInfo.DstBltCK.low); AssertRC(rc);
|
---|
| 3193 | rc = SSMR3GetU32(pSSM, &pCreateSurf->SurfInfo.DstBltCK.high); AssertRC(rc);
|
---|
[22816] | 3194 | }
|
---|
[71651] | 3195 | if (pCreateSurf->SurfInfo.flags & VBOXVHWA_SD_CKSRCBLT)
|
---|
[22816] | 3196 | {
|
---|
[71651] | 3197 | rc = SSMR3GetU32(pSSM, &pCreateSurf->SurfInfo.SrcBltCK.low); AssertRC(rc);
|
---|
| 3198 | rc = SSMR3GetU32(pSSM, &pCreateSurf->SurfInfo.SrcBltCK.high); AssertRC(rc);
|
---|
[22816] | 3199 | }
|
---|
[71651] | 3200 | if (pCreateSurf->SurfInfo.flags & VBOXVHWA_SD_CKDESTOVERLAY)
|
---|
[22816] | 3201 | {
|
---|
[71651] | 3202 | rc = SSMR3GetU32(pSSM, &pCreateSurf->SurfInfo.DstOverlayCK.low); AssertRC(rc);
|
---|
| 3203 | rc = SSMR3GetU32(pSSM, &pCreateSurf->SurfInfo.DstOverlayCK.high); AssertRC(rc);
|
---|
[22816] | 3204 | }
|
---|
[71651] | 3205 | if (pCreateSurf->SurfInfo.flags & VBOXVHWA_SD_CKSRCOVERLAY)
|
---|
[22816] | 3206 | {
|
---|
[71651] | 3207 | rc = SSMR3GetU32(pSSM, &pCreateSurf->SurfInfo.SrcOverlayCK.low); AssertRC(rc);
|
---|
| 3208 | rc = SSMR3GetU32(pSSM, &pCreateSurf->SurfInfo.SrcOverlayCK.high); AssertRC(rc);
|
---|
[22816] | 3209 | }
|
---|
| 3210 |
|
---|
[71651] | 3211 | rc = SSMR3GetU32(pSSM, &pCreateSurf->SurfInfo.PixelFormat.flags); AssertRC(rc);
|
---|
| 3212 | if (pCreateSurf->SurfInfo.PixelFormat.flags & VBOXVHWA_PF_RGB)
|
---|
[22816] | 3213 | {
|
---|
[71651] | 3214 | rc = SSMR3GetU32(pSSM, &pCreateSurf->SurfInfo.PixelFormat.c.rgbBitCount); AssertRC(rc);
|
---|
| 3215 | rc = SSMR3GetU32(pSSM, &pCreateSurf->SurfInfo.PixelFormat.m1.rgbRBitMask); AssertRC(rc);
|
---|
| 3216 | rc = SSMR3GetU32(pSSM, &pCreateSurf->SurfInfo.PixelFormat.m2.rgbGBitMask); AssertRC(rc);
|
---|
| 3217 | rc = SSMR3GetU32(pSSM, &pCreateSurf->SurfInfo.PixelFormat.m3.rgbBBitMask); AssertRC(rc);
|
---|
| 3218 | rc = SSMR3GetU32(pSSM, &pCreateSurf->SurfInfo.PixelFormat.m4.rgbABitMask); AssertRC(rc);
|
---|
[22816] | 3219 | }
|
---|
[71651] | 3220 | else if (pCreateSurf->SurfInfo.PixelFormat.flags & VBOXVHWA_PF_FOURCC)
|
---|
[22816] | 3221 | {
|
---|
[71651] | 3222 | rc = SSMR3GetU32(pSSM, &pCreateSurf->SurfInfo.PixelFormat.fourCC);
|
---|
| 3223 | AssertRC(rc);
|
---|
[22816] | 3224 | }
|
---|
| 3225 | else
|
---|
| 3226 | {
|
---|
[49940] | 3227 | AssertFailed();
|
---|
[22816] | 3228 | }
|
---|
[71651] | 3229 | AssertRCReturnStmt(rc, free(buf), rc);
|
---|
[22816] | 3230 |
|
---|
[71651] | 3231 | if (cBackBuffers)
|
---|
[24171] | 3232 | {
|
---|
| 3233 | pCreateSurf->SurfInfo.cBackBuffers = cBackBuffers;
|
---|
| 3234 | pCreateSurf->SurfInfo.surfCaps |= VBOXVHWA_SCAPS_COMPLEX;
|
---|
| 3235 | }
|
---|
| 3236 |
|
---|
[22816] | 3237 | pCmdList->push_back(pCmd);
|
---|
[27682] | 3238 | // vboxExecOnResize(&VBoxVHWAImage::vboxDoVHWACmdAndFree, pCmd); AssertRC(rc);
|
---|
[71651] | 3239 | // if (RT_SUCCESS(rc))
|
---|
[22816] | 3240 | // {
|
---|
| 3241 | // rc = pCmd->rc;
|
---|
| 3242 | // AssertRC(rc);
|
---|
| 3243 | // }
|
---|
| 3244 | }
|
---|
[56747] | 3245 | else
|
---|
| 3246 | free(buf);
|
---|
[22816] | 3247 |
|
---|
| 3248 | VBOXQGL_LOAD_SURFSTOP(pSSM);
|
---|
| 3249 |
|
---|
| 3250 | return rc;
|
---|
| 3251 | }
|
---|
| 3252 |
|
---|
[27682] | 3253 | int VBoxVHWAImage::vhwaSaveOverlayData(struct SSMHANDLE * pSSM, VBoxVHWASurfaceBase *pSurf, bool bVisible)
|
---|
[22816] | 3254 | {
|
---|
| 3255 | VBOXQGL_SAVE_OVERLAYSTART(pSSM);
|
---|
| 3256 |
|
---|
| 3257 | uint32_t flags = 0;
|
---|
| 3258 | const VBoxVHWAColorKey * dstCKey = pSurf->dstOverlayCKey();
|
---|
| 3259 | const VBoxVHWAColorKey * defaultDstCKey = pSurf->defaultDstOverlayCKey();
|
---|
| 3260 | const VBoxVHWAColorKey * srcCKey = pSurf->srcOverlayCKey();;
|
---|
| 3261 | const VBoxVHWAColorKey * defaultSrcCKey = pSurf->defaultSrcOverlayCKey();
|
---|
| 3262 | bool bSaveDstCKey = false;
|
---|
| 3263 | bool bSaveSrcCKey = false;
|
---|
| 3264 |
|
---|
[71651] | 3265 | if (bVisible)
|
---|
[22816] | 3266 | {
|
---|
| 3267 | flags |= VBOXVHWA_OVER_SHOW;
|
---|
| 3268 | }
|
---|
| 3269 | else
|
---|
| 3270 | {
|
---|
| 3271 | flags |= VBOXVHWA_OVER_HIDE;
|
---|
| 3272 | }
|
---|
| 3273 |
|
---|
[71651] | 3274 | if (!dstCKey)
|
---|
[22816] | 3275 | {
|
---|
| 3276 | flags |= VBOXVHWA_OVER_KEYDEST;
|
---|
| 3277 | }
|
---|
[71651] | 3278 | else if (defaultDstCKey)
|
---|
[22816] | 3279 | {
|
---|
| 3280 | flags |= VBOXVHWA_OVER_KEYDESTOVERRIDE;
|
---|
| 3281 | bSaveDstCKey = true;
|
---|
| 3282 | }
|
---|
| 3283 |
|
---|
[71651] | 3284 | if (srcCKey == defaultSrcCKey)
|
---|
[22816] | 3285 | {
|
---|
| 3286 | flags |= VBOXVHWA_OVER_KEYSRC;
|
---|
| 3287 | }
|
---|
[71651] | 3288 | else if (srcCKey)
|
---|
[22816] | 3289 | {
|
---|
| 3290 | flags |= VBOXVHWA_OVER_KEYSRCOVERRIDE;
|
---|
| 3291 | bSaveSrcCKey = true;
|
---|
| 3292 | }
|
---|
| 3293 |
|
---|
[71651] | 3294 | int rc = SSMR3PutU32(pSSM, flags);
|
---|
[22816] | 3295 |
|
---|
[71651] | 3296 | rc = SSMR3PutU32(pSSM, mDisplay.getPrimary()->handle());
|
---|
| 3297 | rc = SSMR3PutU32(pSSM, pSurf->handle());
|
---|
[22816] | 3298 |
|
---|
[71651] | 3299 | if (bSaveDstCKey)
|
---|
[22816] | 3300 | {
|
---|
[71651] | 3301 | rc = SSMR3PutU32(pSSM, dstCKey->lower());
|
---|
| 3302 | rc = SSMR3PutU32(pSSM, dstCKey->upper());
|
---|
[22816] | 3303 | }
|
---|
[71651] | 3304 | if (bSaveSrcCKey)
|
---|
[22816] | 3305 | {
|
---|
[71651] | 3306 | rc = SSMR3PutU32(pSSM, srcCKey->lower());
|
---|
| 3307 | rc = SSMR3PutU32(pSSM, srcCKey->upper());
|
---|
[22816] | 3308 | }
|
---|
| 3309 |
|
---|
| 3310 | int x1, x2, y1, y2;
|
---|
| 3311 | pSurf->targRect().getCoords(&x1, &y1, &x2, &y2);
|
---|
[71651] | 3312 | rc = SSMR3PutS32(pSSM, x1);
|
---|
| 3313 | rc = SSMR3PutS32(pSSM, x2+1);
|
---|
| 3314 | rc = SSMR3PutS32(pSSM, y1);
|
---|
| 3315 | rc = SSMR3PutS32(pSSM, y2+1);
|
---|
[22816] | 3316 |
|
---|
| 3317 | pSurf->srcRect().getCoords(&x1, &y1, &x2, &y2);
|
---|
[71651] | 3318 | rc = SSMR3PutS32(pSSM, x1);
|
---|
| 3319 | rc = SSMR3PutS32(pSSM, x2+1);
|
---|
| 3320 | rc = SSMR3PutS32(pSSM, y1);
|
---|
| 3321 | rc = SSMR3PutS32(pSSM, y2+1);
|
---|
| 3322 | AssertRCReturn(rc, rc);
|
---|
[22816] | 3323 |
|
---|
| 3324 | VBOXQGL_SAVE_OVERLAYSTOP(pSSM);
|
---|
| 3325 |
|
---|
| 3326 | return rc;
|
---|
| 3327 | }
|
---|
| 3328 |
|
---|
[71626] | 3329 | int VBoxVHWAImage::vhwaLoadOverlayData(VHWACommandList *pCmdList, struct SSMHANDLE *pSSM, uint32_t u32Version)
|
---|
[22816] | 3330 | {
|
---|
| 3331 | Q_UNUSED(u32Version);
|
---|
| 3332 |
|
---|
| 3333 | VBOXQGL_LOAD_OVERLAYSTART(pSSM);
|
---|
| 3334 |
|
---|
| 3335 | char *buf = new char[VBOXVHWACMD_SIZE(VBOXVHWACMD_SURF_CREATE)];
|
---|
[24925] | 3336 | memset(buf, 0, VBOXVHWACMD_SIZE(VBOXVHWACMD_SURF_CREATE));
|
---|
[22816] | 3337 | VBOXVHWACMD * pCmd = (VBOXVHWACMD*)buf;
|
---|
| 3338 | pCmd->enmCmd = VBOXVHWACMD_TYPE_SURF_OVERLAY_UPDATE;
|
---|
| 3339 | pCmd->Flags = VBOXVHWACMD_FLAG_HH_CMD;
|
---|
| 3340 |
|
---|
[71594] | 3341 | VBOXVHWACMD_SURF_OVERLAY_UPDATE *pUpdateOverlay = VBOXVHWACMD_BODY_HOST_HEAP(pCmd, VBOXVHWACMD_SURF_OVERLAY_UPDATE);
|
---|
[22816] | 3342 | int rc;
|
---|
| 3343 |
|
---|
| 3344 | rc = SSMR3GetU32(pSSM, &pUpdateOverlay->u.in.flags); AssertRC(rc);
|
---|
| 3345 | uint32_t hSrc, hDst;
|
---|
| 3346 | rc = SSMR3GetU32(pSSM, &hDst); AssertRC(rc);
|
---|
| 3347 | rc = SSMR3GetU32(pSSM, &hSrc); AssertRC(rc);
|
---|
| 3348 | pUpdateOverlay->u.in.hSrcSurf = hSrc;
|
---|
| 3349 | pUpdateOverlay->u.in.hDstSurf = hDst;
|
---|
| 3350 | {
|
---|
| 3351 | pUpdateOverlay->u.in.offDstSurface = VBOXVHWA_OFFSET64_VOID;
|
---|
| 3352 | pUpdateOverlay->u.in.offSrcSurface = VBOXVHWA_OFFSET64_VOID;
|
---|
| 3353 |
|
---|
[71651] | 3354 | if (pUpdateOverlay->u.in.flags & VBOXVHWA_OVER_KEYDESTOVERRIDE)
|
---|
[22816] | 3355 | {
|
---|
[71651] | 3356 | rc = SSMR3GetU32(pSSM, &pUpdateOverlay->u.in.desc.DstCK.low); AssertRC(rc);
|
---|
[22816] | 3357 | rc = SSMR3GetU32(pSSM, &pUpdateOverlay->u.in.desc.DstCK.high); AssertRC(rc);
|
---|
| 3358 | }
|
---|
| 3359 |
|
---|
[71651] | 3360 | if (pUpdateOverlay->u.in.flags & VBOXVHWA_OVER_KEYSRCOVERRIDE)
|
---|
[22816] | 3361 | {
|
---|
[71651] | 3362 | rc = SSMR3GetU32(pSSM, &pUpdateOverlay->u.in.desc.SrcCK.low); AssertRC(rc);
|
---|
[22816] | 3363 | rc = SSMR3GetU32(pSSM, &pUpdateOverlay->u.in.desc.SrcCK.high); AssertRC(rc);
|
---|
| 3364 | }
|
---|
| 3365 |
|
---|
[71651] | 3366 | rc = SSMR3GetS32(pSSM, &pUpdateOverlay->u.in.dstRect.left); AssertRC(rc);
|
---|
| 3367 | rc = SSMR3GetS32(pSSM, &pUpdateOverlay->u.in.dstRect.right); AssertRC(rc);
|
---|
| 3368 | rc = SSMR3GetS32(pSSM, &pUpdateOverlay->u.in.dstRect.top); AssertRC(rc);
|
---|
[22816] | 3369 | rc = SSMR3GetS32(pSSM, &pUpdateOverlay->u.in.dstRect.bottom); AssertRC(rc);
|
---|
| 3370 |
|
---|
[71651] | 3371 | rc = SSMR3GetS32(pSSM, &pUpdateOverlay->u.in.srcRect.left); AssertRC(rc);
|
---|
| 3372 | rc = SSMR3GetS32(pSSM, &pUpdateOverlay->u.in.srcRect.right); AssertRC(rc);
|
---|
| 3373 | rc = SSMR3GetS32(pSSM, &pUpdateOverlay->u.in.srcRect.top); AssertRC(rc);
|
---|
| 3374 | rc = SSMR3GetS32(pSSM, &pUpdateOverlay->u.in.srcRect.bottom);
|
---|
| 3375 | AssertRCReturnStmt(rc, free(buf), rc);
|
---|
[22816] | 3376 |
|
---|
| 3377 | pCmdList->push_back(pCmd);
|
---|
| 3378 | }
|
---|
| 3379 |
|
---|
| 3380 | VBOXQGL_LOAD_OVERLAYSTOP(pSSM);
|
---|
| 3381 |
|
---|
| 3382 | return rc;
|
---|
| 3383 | }
|
---|
| 3384 |
|
---|
[71651] | 3385 | void VBoxVHWAImage::vhwaSaveExecVoid(struct SSMHANDLE *pSSM)
|
---|
[24861] | 3386 | {
|
---|
| 3387 | VBOXQGL_SAVE_START(pSSM);
|
---|
[71651] | 3388 | SSMR3PutU32(pSSM, 0); /* 0 primaries */
|
---|
[24861] | 3389 | VBOXQGL_SAVE_STOP(pSSM);
|
---|
| 3390 | }
|
---|
| 3391 |
|
---|
[71651] | 3392 | void VBoxVHWAImage::vhwaSaveExec(struct SSMHANDLE *pSSM)
|
---|
[22816] | 3393 | {
|
---|
| 3394 | VBOXQGL_SAVE_START(pSSM);
|
---|
| 3395 |
|
---|
| 3396 | /* the mechanism of restoring data is based on generating VHWA commands that restore the surfaces state
|
---|
| 3397 | * the following commands are generated:
|
---|
| 3398 | * I. CreateSurface
|
---|
| 3399 | * II. UpdateOverlay
|
---|
| 3400 | *
|
---|
| 3401 | * Data format is the following:
|
---|
| 3402 | * I. u32 - Num primary surfaces - (the current frontbuffer is detected in the stored surf flags which are posted to the generated CreateSurface cmd)
|
---|
| 3403 | * II. for each primary surf
|
---|
| 3404 | * II.1 generate & execute CreateSurface cmd (see below on the generation logic)
|
---|
| 3405 | * III. u32 - Num overlays
|
---|
| 3406 | * IV. for each overlay
|
---|
| 3407 | * IV.1 u32 - Num surfaces in overlay (the current frontbuffer is detected in the stored surf flags which are posted to the generated CreateSurface cmd)
|
---|
| 3408 | * IV.2 for each surface in overlay
|
---|
| 3409 | * IV.2.a generate & execute CreateSurface cmd (see below on the generation logic)
|
---|
| 3410 | * IV.2.b generate & execute UpdateOverlay cmd (see below on the generation logic)
|
---|
| 3411 | *
|
---|
| 3412 | */
|
---|
| 3413 | const SurfList & primaryList = mDisplay.primaries().surfaces();
|
---|
| 3414 | uint32_t cPrimary = (uint32_t)primaryList.size();
|
---|
[71652] | 3415 | if ( cPrimary
|
---|
| 3416 | && ( mDisplay.getVGA() == NULL
|
---|
| 3417 | || mDisplay.getVGA()->handle() == VBOXVHWA_SURFHANDLE_INVALID))
|
---|
[22816] | 3418 | {
|
---|
| 3419 | cPrimary -= 1;
|
---|
| 3420 | }
|
---|
[24867] | 3421 |
|
---|
[71651] | 3422 | int rc = SSMR3PutU32(pSSM, cPrimary);
|
---|
[71652] | 3423 | AssertRCReturnVoid(rc);
|
---|
[71651] | 3424 | if (cPrimary)
|
---|
[22816] | 3425 | {
|
---|
[71651] | 3426 | for (SurfList::const_iterator pr = primaryList.begin(); pr != primaryList.end(); ++ pr)
|
---|
[24867] | 3427 | {
|
---|
| 3428 | VBoxVHWASurfaceBase *pSurf = *pr;
|
---|
| 3429 | // bool bVga = (pSurf == mDisplay.getVGA());
|
---|
| 3430 | bool bVisible = (pSurf == mDisplay.getPrimary());
|
---|
| 3431 | uint32_t flags = VBOXVHWA_SCAPS_PRIMARYSURFACE;
|
---|
[71651] | 3432 | if (bVisible)
|
---|
[24867] | 3433 | flags |= VBOXVHWA_SCAPS_VISIBLE;
|
---|
[22816] | 3434 |
|
---|
[71651] | 3435 | if (pSurf->handle() != VBOXVHWA_SURFHANDLE_INVALID)
|
---|
[24867] | 3436 | {
|
---|
[71651] | 3437 | rc = vhwaSaveSurface(pSSM, *pr, flags);
|
---|
[22816] | 3438 | #ifdef DEBUG
|
---|
[24867] | 3439 | --cPrimary;
|
---|
| 3440 | Assert(cPrimary < UINT32_MAX / 2);
|
---|
[22816] | 3441 | #endif
|
---|
[24867] | 3442 | }
|
---|
| 3443 | else
|
---|
| 3444 | {
|
---|
| 3445 | Assert(pSurf == mDisplay.getVGA());
|
---|
| 3446 | }
|
---|
[22816] | 3447 | }
|
---|
| 3448 |
|
---|
| 3449 | #ifdef DEBUG
|
---|
[24867] | 3450 | Assert(!cPrimary);
|
---|
[22816] | 3451 | #endif
|
---|
| 3452 |
|
---|
[24867] | 3453 | const OverlayList & overlays = mDisplay.overlays();
|
---|
[71651] | 3454 | rc = SSMR3PutU32(pSSM, (uint32_t)overlays.size());
|
---|
[22816] | 3455 |
|
---|
[71651] | 3456 | for (OverlayList::const_iterator it = overlays.begin(); it != overlays.end(); ++ it)
|
---|
[22816] | 3457 | {
|
---|
[24867] | 3458 | VBoxVHWASurfList * pSurfList = *it;
|
---|
| 3459 | const SurfList & surfaces = pSurfList->surfaces();
|
---|
| 3460 | uint32_t cSurfs = (uint32_t)surfaces.size();
|
---|
| 3461 | uint32_t flags = VBOXVHWA_SCAPS_OVERLAY;
|
---|
[71651] | 3462 | if (cSurfs > 1)
|
---|
[24867] | 3463 | flags |= VBOXVHWA_SCAPS_COMPLEX;
|
---|
[71651] | 3464 | rc = SSMR3PutU32(pSSM, cSurfs);
|
---|
| 3465 | for (SurfList::const_iterator sit = surfaces.begin(); sit != surfaces.end(); ++ sit)
|
---|
| 3466 | rc = vhwaSaveSurface(pSSM, *sit, flags);
|
---|
[22816] | 3467 |
|
---|
[24867] | 3468 | bool bVisible = true;
|
---|
| 3469 | VBoxVHWASurfaceBase * pOverlayData = pSurfList->current();
|
---|
[71651] | 3470 | if (!pOverlayData)
|
---|
[24867] | 3471 | {
|
---|
| 3472 | pOverlayData = surfaces.front();
|
---|
| 3473 | bVisible = false;
|
---|
| 3474 | }
|
---|
| 3475 |
|
---|
[71651] | 3476 | rc = vhwaSaveOverlayData(pSSM, pOverlayData, bVisible);
|
---|
[22816] | 3477 | }
|
---|
| 3478 | }
|
---|
| 3479 |
|
---|
| 3480 | VBOXQGL_SAVE_STOP(pSSM);
|
---|
| 3481 | }
|
---|
| 3482 |
|
---|
[27682] | 3483 | int VBoxVHWAImage::vhwaLoadVHWAEnable(VHWACommandList * pCmdList)
|
---|
[24646] | 3484 | {
|
---|
[71651] | 3485 | char *buf = (char *)malloc(sizeof(VBOXVHWACMD));
|
---|
[24646] | 3486 | Assert(buf);
|
---|
[71651] | 3487 | if (buf)
|
---|
[24646] | 3488 | {
|
---|
[24925] | 3489 | memset(buf, 0, sizeof(VBOXVHWACMD));
|
---|
[71626] | 3490 | VBOXVHWACMD *pCmd = (VBOXVHWACMD *)buf;
|
---|
[24646] | 3491 | pCmd->enmCmd = VBOXVHWACMD_TYPE_ENABLE;
|
---|
| 3492 | pCmd->Flags = VBOXVHWACMD_FLAG_HH_CMD;
|
---|
| 3493 | pCmdList->push_back(pCmd);
|
---|
| 3494 | return VINF_SUCCESS;
|
---|
| 3495 | }
|
---|
| 3496 |
|
---|
| 3497 | return VERR_OUT_OF_RESOURCES;
|
---|
| 3498 | }
|
---|
| 3499 |
|
---|
[71594] | 3500 | int VBoxVHWAImage::vhwaLoadExec(VHWACommandList *pCmdList, struct SSMHANDLE * pSSM, uint32_t u32Version)
|
---|
[22816] | 3501 | {
|
---|
| 3502 | VBOXQGL_LOAD_START(pSSM);
|
---|
| 3503 |
|
---|
[71651] | 3504 | if (u32Version > VBOXQGL_STATE_VERSION)
|
---|
[24867] | 3505 | return VERR_VERSION_MISMATCH;
|
---|
| 3506 |
|
---|
[22816] | 3507 | int rc;
|
---|
| 3508 | uint32_t u32;
|
---|
| 3509 |
|
---|
[24867] | 3510 | rc = vhwaLoadVHWAEnable(pCmdList); AssertRC(rc);
|
---|
[71651] | 3511 | if (RT_SUCCESS(rc))
|
---|
[22816] | 3512 | {
|
---|
[24867] | 3513 | rc = SSMR3GetU32(pSSM, &u32); AssertRC(rc);
|
---|
[71651] | 3514 | if (RT_SUCCESS(rc))
|
---|
[22816] | 3515 | {
|
---|
[71651] | 3516 | if (u32Version == 1U && u32 == UINT32_MAX) /* work around the v1 bug */
|
---|
[24867] | 3517 | u32 = 0;
|
---|
[71651] | 3518 | if (u32)
|
---|
[22816] | 3519 | {
|
---|
[71651] | 3520 | for (uint32_t i = 0; i < u32; ++i)
|
---|
[22816] | 3521 | {
|
---|
[71651] | 3522 | rc = vhwaLoadSurface(pCmdList, pSSM, 0, u32Version);
|
---|
| 3523 | AssertRCBreak(rc);
|
---|
[24867] | 3524 | }
|
---|
[22816] | 3525 |
|
---|
[71651] | 3526 | if (RT_SUCCESS(rc))
|
---|
[24867] | 3527 | {
|
---|
| 3528 | rc = SSMR3GetU32(pSSM, &u32); AssertRC(rc);
|
---|
[71651] | 3529 | if (RT_SUCCESS(rc))
|
---|
[22816] | 3530 | {
|
---|
[71651] | 3531 | for (uint32_t i = 0; i < u32; ++i)
|
---|
[24867] | 3532 | {
|
---|
| 3533 | uint32_t cSurfs;
|
---|
| 3534 | rc = SSMR3GetU32(pSSM, &cSurfs); AssertRC(rc);
|
---|
[71651] | 3535 | for (uint32_t j = 0; j < cSurfs; ++j)
|
---|
[24867] | 3536 | {
|
---|
[71651] | 3537 | rc = vhwaLoadSurface(pCmdList, pSSM, cSurfs - 1, u32Version);
|
---|
| 3538 | AssertRCBreak(rc);
|
---|
[24867] | 3539 | }
|
---|
[22816] | 3540 |
|
---|
[71651] | 3541 | if (RT_SUCCESS(rc))
|
---|
[24867] | 3542 | {
|
---|
[71651] | 3543 | rc = vhwaLoadOverlayData(pCmdList, pSSM, u32Version);
|
---|
| 3544 | AssertRCBreak(rc);
|
---|
[24867] | 3545 | }
|
---|
[71651] | 3546 | else
|
---|
[24867] | 3547 | break;
|
---|
| 3548 | }
|
---|
[22816] | 3549 | }
|
---|
| 3550 | }
|
---|
| 3551 | }
|
---|
[24867] | 3552 | #ifdef VBOXQGL_STATE_DEBUG
|
---|
[71651] | 3553 | else if (u32Version == 1) /* read the 0 overlay count to ensure the following VBOXQGL_LOAD_STOP succeeds */
|
---|
[24867] | 3554 | {
|
---|
[71651] | 3555 | rc = SSMR3GetU32(pSSM, &u32);
|
---|
| 3556 | AssertRC(rc);
|
---|
| 3557 | Assert(u32 == 0 || RT_FAILURE(rc));
|
---|
[24867] | 3558 | }
|
---|
| 3559 | #endif
|
---|
[22816] | 3560 | }
|
---|
| 3561 | }
|
---|
| 3562 |
|
---|
| 3563 | VBOXQGL_LOAD_STOP(pSSM);
|
---|
| 3564 |
|
---|
| 3565 | return rc;
|
---|
| 3566 | }
|
---|
| 3567 |
|
---|
[34490] | 3568 | int VBoxVHWAImage::vhwaConstruct(struct VBOXVHWACMD_HH_CONSTRUCT *pCmd)
|
---|
[22816] | 3569 | {
|
---|
[27682] | 3570 | // PVM pVM = (PVM)pCmd->pVM;
|
---|
[63567] | 3571 | // uint32_t intsId = 0; /** @todo set the proper id */
|
---|
[27682] | 3572 | //
|
---|
| 3573 | // char nameFuf[sizeof(VBOXQGL_STATE_NAMEBASE) + 8];
|
---|
| 3574 | //
|
---|
| 3575 | // char * pszName = nameFuf;
|
---|
| 3576 | // sprintf(pszName, "%s%d", VBOXQGL_STATE_NAMEBASE, intsId);
|
---|
| 3577 | // int rc = SSMR3RegisterExternal(
|
---|
| 3578 | // pVM, /* The VM handle*/
|
---|
| 3579 | // pszName, /* Data unit name. */
|
---|
| 3580 | // intsId, /* The instance identifier of the data unit.
|
---|
| 3581 | // * This must together with the name be unique. */
|
---|
| 3582 | // VBOXQGL_STATE_VERSION, /* Data layout version number. */
|
---|
| 3583 | // 128, /* The approximate amount of data in the unit.
|
---|
| 3584 | // * Only for progress indicators. */
|
---|
| 3585 | // NULL, NULL, NULL, /* pfnLiveXxx */
|
---|
| 3586 | // NULL, /* Prepare save callback, optional. */
|
---|
| 3587 | // vboxQGLSaveExec, /* Execute save callback, optional. */
|
---|
| 3588 | // NULL, /* Done save callback, optional. */
|
---|
| 3589 | // NULL, /* Prepare load callback, optional. */
|
---|
| 3590 | // vboxQGLLoadExec, /* Execute load callback, optional. */
|
---|
| 3591 | // NULL, /* Done load callback, optional. */
|
---|
| 3592 | // this /* User argument. */
|
---|
| 3593 | // );
|
---|
| 3594 | // AssertRC(rc);
|
---|
| 3595 | mpvVRAM = pCmd->pvVRAM;
|
---|
| 3596 | mcbVRAM = pCmd->cbVRAM;
|
---|
| 3597 | return VINF_SUCCESS;
|
---|
[22816] | 3598 | }
|
---|
| 3599 |
|
---|
[71651] | 3600 | uchar *VBoxVHWAImage::vboxVRAMAddressFromOffset(uint64_t offset)
|
---|
[22816] | 3601 | {
|
---|
[63567] | 3602 | /** @todo check vramSize() */
|
---|
[71651] | 3603 | return (offset != VBOXVHWA_OFFSET64_VOID) ? ((uint8_t *)vramBase()) + offset : NULL;
|
---|
[22816] | 3604 | }
|
---|
| 3605 |
|
---|
[71651] | 3606 | uint64_t VBoxVHWAImage::vboxVRAMOffsetFromAddress(uchar *addr)
|
---|
[22816] | 3607 | {
|
---|
[71651] | 3608 | return uint64_t(addr - ((uchar *)vramBase()));
|
---|
[22816] | 3609 | }
|
---|
| 3610 |
|
---|
[71651] | 3611 | uint64_t VBoxVHWAImage::vboxVRAMOffset(VBoxVHWASurfaceBase *pSurf)
|
---|
[22816] | 3612 | {
|
---|
| 3613 | return pSurf->addressAlocated() ? VBOXVHWA_OFFSET64_VOID : vboxVRAMOffsetFromAddress(pSurf->address());
|
---|
| 3614 | }
|
---|
| 3615 |
|
---|
| 3616 | #endif
|
---|
| 3617 |
|
---|
| 3618 | #ifdef VBOXQGL_DBG_SURF
|
---|
| 3619 |
|
---|
| 3620 | int g_iCur = 0;
|
---|
[71651] | 3621 | VBoxVHWASurfaceBase *g_apSurf[] = {NULL, NULL, NULL};
|
---|
[22816] | 3622 |
|
---|
[71651] | 3623 | void VBoxVHWAImage::vboxDoTestSurfaces(void *context)
|
---|
[22816] | 3624 | {
|
---|
[71651] | 3625 | if (g_iCur >= RT_ELEMENTS(g_apSurf))
|
---|
[22816] | 3626 | g_iCur = 0;
|
---|
| 3627 | VBoxVHWASurfaceBase * pSurf1 = g_apSurf[g_iCur];
|
---|
[71651] | 3628 | if (pSurf1)
|
---|
[22816] | 3629 | pSurf1->getComplexList()->setCurrentVisible(pSurf1);
|
---|
| 3630 | }
|
---|
| 3631 | #endif
|
---|
| 3632 |
|
---|
[27682] | 3633 | void VBoxVHWAImage::vboxDoUpdateViewport(const QRect & aRect)
|
---|
[22816] | 3634 | {
|
---|
| 3635 | adjustViewport(mDisplay.getPrimary()->size(), aRect);
|
---|
| 3636 | mViewport = aRect;
|
---|
| 3637 |
|
---|
[71651] | 3638 | const SurfList &primaryList = mDisplay.primaries().surfaces();
|
---|
[22816] | 3639 |
|
---|
[71651] | 3640 | for (SurfList::const_iterator pr = primaryList.begin(); pr != primaryList.end(); ++pr)
|
---|
[22816] | 3641 | {
|
---|
| 3642 | VBoxVHWASurfaceBase *pSurf = *pr;
|
---|
[24646] | 3643 | pSurf->updateVisibility(NULL, aRect, false, false);
|
---|
[22816] | 3644 | }
|
---|
| 3645 |
|
---|
| 3646 | const OverlayList & overlays = mDisplay.overlays();
|
---|
[24648] | 3647 | QRect overInter = overlaysRectIntersection();
|
---|
[58860] | 3648 | overInter = overInter.intersected(aRect);
|
---|
[22816] | 3649 |
|
---|
[24646] | 3650 | bool bDisplayPrimary = true;
|
---|
| 3651 |
|
---|
[71651] | 3652 | for (OverlayList::const_iterator it = overlays.begin(); it != overlays.end(); ++it)
|
---|
[22816] | 3653 | {
|
---|
[71651] | 3654 | VBoxVHWASurfList *pSurfList = *it;
|
---|
| 3655 | const SurfList &surfaces = pSurfList->surfaces();
|
---|
| 3656 | if (surfaces.size())
|
---|
[22816] | 3657 | {
|
---|
[24646] | 3658 | bool bNotIntersected = !overInter.isEmpty() && surfaces.front()->targRect().contains(overInter);
|
---|
| 3659 | Assert(bNotIntersected);
|
---|
| 3660 |
|
---|
| 3661 | bDisplayPrimary &= !bNotIntersected;
|
---|
| 3662 | for (SurfList::const_iterator sit = surfaces.begin();
|
---|
| 3663 | sit != surfaces.end(); ++ sit)
|
---|
| 3664 | {
|
---|
| 3665 | VBoxVHWASurfaceBase *pSurf = *sit;
|
---|
| 3666 | pSurf->updateVisibility(mDisplay.getPrimary(), aRect, bNotIntersected, false);
|
---|
| 3667 | }
|
---|
[22816] | 3668 | }
|
---|
| 3669 | }
|
---|
[24646] | 3670 |
|
---|
| 3671 | Assert(!bDisplayPrimary);
|
---|
| 3672 | mDisplay.setDisplayPrimary(bDisplayPrimary);
|
---|
[22816] | 3673 | }
|
---|
| 3674 |
|
---|
[27682] | 3675 | bool VBoxVHWAImage::hasSurfaces() const
|
---|
[22816] | 3676 | {
|
---|
[27850] | 3677 | if (mDisplay.overlays().size() != 0)
|
---|
[22816] | 3678 | return true;
|
---|
[27850] | 3679 | if (mDisplay.primaries().size() > 1)
|
---|
[22816] | 3680 | return true;
|
---|
[27850] | 3681 | /* in case gl was never turned on, we have no surfaces at all including VGA */
|
---|
| 3682 | if (!mDisplay.getVGA())
|
---|
| 3683 | return false;
|
---|
[22816] | 3684 | return mDisplay.getVGA()->handle() != VBOXVHWA_SURFHANDLE_INVALID;
|
---|
| 3685 | }
|
---|
| 3686 |
|
---|
[27682] | 3687 | bool VBoxVHWAImage::hasVisibleOverlays()
|
---|
[22816] | 3688 | {
|
---|
[71651] | 3689 | const OverlayList &overlays = mDisplay.overlays();
|
---|
| 3690 | for (OverlayList::const_iterator it = overlays.begin(); it != overlays.end(); ++ it)
|
---|
[22816] | 3691 | {
|
---|
| 3692 | VBoxVHWASurfList * pSurfList = *it;
|
---|
[71651] | 3693 | if (pSurfList->current() != NULL)
|
---|
[22816] | 3694 | return true;
|
---|
| 3695 | }
|
---|
| 3696 | return false;
|
---|
| 3697 | }
|
---|
| 3698 |
|
---|
[27682] | 3699 | QRect VBoxVHWAImage::overlaysRectUnion()
|
---|
[22816] | 3700 | {
|
---|
[71651] | 3701 | const OverlayList &overlays = mDisplay.overlays();
|
---|
[22816] | 3702 | VBoxVHWADirtyRect un;
|
---|
[71651] | 3703 | for (OverlayList::const_iterator it = overlays.begin(); it != overlays.end(); ++ it)
|
---|
[22816] | 3704 | {
|
---|
[71651] | 3705 | VBoxVHWASurfaceBase *pOverlay = (*it)->current();
|
---|
| 3706 | if (pOverlay != NULL)
|
---|
[22816] | 3707 | un.add(pOverlay->targRect());
|
---|
| 3708 | }
|
---|
| 3709 | return un.toRect();
|
---|
| 3710 | }
|
---|
| 3711 |
|
---|
[27682] | 3712 | QRect VBoxVHWAImage::overlaysRectIntersection()
|
---|
[24646] | 3713 | {
|
---|
[71651] | 3714 | const OverlayList &overlays = mDisplay.overlays();
|
---|
[24646] | 3715 | QRect rect;
|
---|
| 3716 | VBoxVHWADirtyRect un;
|
---|
[71651] | 3717 | for (OverlayList::const_iterator it = overlays.begin(); it != overlays.end(); ++ it)
|
---|
[24646] | 3718 | {
|
---|
[71651] | 3719 | VBoxVHWASurfaceBase *pOverlay = (*it)->current();
|
---|
| 3720 | if (pOverlay != NULL)
|
---|
[24646] | 3721 | {
|
---|
[71651] | 3722 | if (rect.isNull())
|
---|
[24646] | 3723 | rect = pOverlay->targRect();
|
---|
| 3724 | else
|
---|
| 3725 | {
|
---|
| 3726 | rect = rect.intersected(pOverlay->targRect());
|
---|
[71651] | 3727 | if (rect.isNull())
|
---|
[24646] | 3728 | break;
|
---|
| 3729 | }
|
---|
| 3730 | }
|
---|
| 3731 | }
|
---|
| 3732 | return rect;
|
---|
| 3733 | }
|
---|
| 3734 |
|
---|
[71651] | 3735 | void VBoxVHWAImage::vboxDoUpdateRect(const QRect *pRect)
|
---|
[22816] | 3736 | {
|
---|
| 3737 | mDisplay.getPrimary()->updatedMem(pRect);
|
---|
| 3738 | }
|
---|
| 3739 |
|
---|
[71651] | 3740 | void VBoxVHWAImage::resize(const VBoxFBSizeInfo &size)
|
---|
[22816] | 3741 | {
|
---|
| 3742 | VBOXQGL_CHECKERR(
|
---|
| 3743 | vboxglActiveTexture(GL_TEXTURE0);
|
---|
| 3744 | );
|
---|
| 3745 |
|
---|
| 3746 | bool remind = false;
|
---|
| 3747 | bool fallback = false;
|
---|
| 3748 |
|
---|
| 3749 | VBOXQGLLOG(("resizing: fmt=%d, vram=%p, bpp=%d, bpl=%d, width=%d, height=%d\n",
|
---|
[63305] | 3750 | size.pixelFormat(), size.VRAM(),
|
---|
| 3751 | size.bitsPerPixel(), size.bytesPerLine(),
|
---|
| 3752 | size.width(), size.height()));
|
---|
[22816] | 3753 |
|
---|
| 3754 | /* clean the old values first */
|
---|
| 3755 |
|
---|
[63305] | 3756 | ulong bytesPerLine = 0; /* Shut up MSC. */
|
---|
| 3757 | uint32_t bitsPerPixel = 0; /* Shut up MSC. */
|
---|
| 3758 | uint32_t b = 0xff;
|
---|
| 3759 | uint32_t g = 0xff00;
|
---|
| 3760 | uint32_t r = 0xff0000;
|
---|
| 3761 | bool fUsesGuestVram = false; /* Shut up MSC. */
|
---|
[22816] | 3762 |
|
---|
| 3763 | /* check if we support the pixel format and can use the guest VRAM directly */
|
---|
[54598] | 3764 | if (size.pixelFormat() == KBitmapFormat_BGR)
|
---|
[22816] | 3765 | {
|
---|
| 3766 |
|
---|
[27682] | 3767 | bitsPerPixel = size.bitsPerPixel();
|
---|
| 3768 | bytesPerLine = size.bytesPerLine();
|
---|
[22816] | 3769 | ulong bitsPerLine = bytesPerLine * 8;
|
---|
| 3770 |
|
---|
| 3771 | switch (bitsPerPixel)
|
---|
| 3772 | {
|
---|
| 3773 | case 32:
|
---|
| 3774 | break;
|
---|
| 3775 | case 24:
|
---|
| 3776 | #ifdef DEBUG_misha
|
---|
[49940] | 3777 | AssertFailed();
|
---|
[22816] | 3778 | #endif
|
---|
| 3779 | break;
|
---|
| 3780 | case 8:
|
---|
| 3781 | #ifdef DEBUG_misha
|
---|
[49940] | 3782 | AssertFailed();
|
---|
[22816] | 3783 | #endif
|
---|
| 3784 | g = b = 0;
|
---|
| 3785 | remind = true;
|
---|
| 3786 | break;
|
---|
| 3787 | case 1:
|
---|
| 3788 | #ifdef DEBUG_misha
|
---|
[49940] | 3789 | AssertFailed();
|
---|
[22816] | 3790 | #endif
|
---|
| 3791 | r = 1;
|
---|
| 3792 | g = b = 0;
|
---|
| 3793 | remind = true;
|
---|
| 3794 | break;
|
---|
| 3795 | default:
|
---|
| 3796 | #ifdef DEBUG_misha
|
---|
[49940] | 3797 | AssertFailed();
|
---|
[22816] | 3798 | #endif
|
---|
| 3799 | remind = true;
|
---|
| 3800 | fallback = true;
|
---|
| 3801 | break;
|
---|
| 3802 | }
|
---|
| 3803 |
|
---|
| 3804 | if (!fallback)
|
---|
| 3805 | {
|
---|
| 3806 | /* QImage only supports 32-bit aligned scan lines... */
|
---|
[27682] | 3807 | Assert ((size.bytesPerLine() & 3) == 0);
|
---|
| 3808 | fallback = ((size.bytesPerLine() & 3) != 0);
|
---|
[27839] | 3809 | Assert(!fallback);
|
---|
[22816] | 3810 | }
|
---|
| 3811 | if (!fallback)
|
---|
| 3812 | {
|
---|
| 3813 | /* ...and the scan lines ought to be a whole number of pixels. */
|
---|
[27682] | 3814 | Assert ((bitsPerLine & (size.bitsPerPixel() - 1)) == 0);
|
---|
| 3815 | fallback = ((bitsPerLine & (size.bitsPerPixel() - 1)) != 0);
|
---|
[27839] | 3816 | Assert(!fallback);
|
---|
[22816] | 3817 | }
|
---|
| 3818 | if (!fallback)
|
---|
| 3819 | {
|
---|
[27682] | 3820 | // ulong virtWdt = bitsPerLine / size.bitsPerPixel();
|
---|
[63305] | 3821 | fUsesGuestVram = true;
|
---|
[22816] | 3822 | }
|
---|
| 3823 | }
|
---|
| 3824 | else
|
---|
| 3825 | {
|
---|
[71651] | 3826 | AssertFailed();
|
---|
[22816] | 3827 | fallback = true;
|
---|
| 3828 | }
|
---|
| 3829 |
|
---|
| 3830 | if (fallback)
|
---|
| 3831 | {
|
---|
[27839] | 3832 | /* we should never come to fallback more now */
|
---|
[71651] | 3833 | AssertFailed();
|
---|
[22816] | 3834 | /* we don't support either the pixel format or the color depth,
|
---|
| 3835 | * fallback to a self-provided 32bpp RGB buffer */
|
---|
| 3836 | bitsPerPixel = 32;
|
---|
| 3837 | b = 0xff;
|
---|
| 3838 | g = 0xff00;
|
---|
| 3839 | r = 0xff0000;
|
---|
[63305] | 3840 | bytesPerLine = size.width() * bitsPerPixel / 8;
|
---|
| 3841 | fUsesGuestVram = false;
|
---|
[22816] | 3842 | }
|
---|
| 3843 |
|
---|
[71651] | 3844 | ulong bytesPerPixel = bitsPerPixel / 8;
|
---|
[53803] | 3845 | const QSize scaledSize = size.scaledSize();
|
---|
| 3846 | const ulong displayWidth = scaledSize.isValid() ? scaledSize.width() : bytesPerLine / bytesPerPixel;
|
---|
| 3847 | const ulong displayHeight = scaledSize.isValid() ? scaledSize.height() : size.height();
|
---|
[22816] | 3848 |
|
---|
| 3849 | #ifdef VBOXQGL_DBG_SURF
|
---|
[71651] | 3850 | for (int i = 0; i < RT_ELEMENTS(g_apSurf); i++)
|
---|
[22816] | 3851 | {
|
---|
| 3852 | VBoxVHWASurfaceBase * pSurf1 = g_apSurf[i];
|
---|
[71651] | 3853 | if (pSurf1)
|
---|
[22816] | 3854 | {
|
---|
| 3855 | VBoxVHWASurfList *pConstructingList = pSurf1->getComplexList();
|
---|
| 3856 | delete pSurf1;
|
---|
[71651] | 3857 | if (pConstructingList)
|
---|
[22816] | 3858 | delete pConstructingList;
|
---|
| 3859 | }
|
---|
| 3860 | }
|
---|
| 3861 | #endif
|
---|
| 3862 |
|
---|
[71651] | 3863 | VBoxVHWASurfaceBase *pDisplay = mDisplay.setVGA(NULL);
|
---|
| 3864 | if (pDisplay)
|
---|
[22816] | 3865 | delete pDisplay;
|
---|
| 3866 |
|
---|
| 3867 | VBoxVHWAColorFormat format(bitsPerPixel, r,g,b);
|
---|
| 3868 | QSize dispSize(displayWidth, displayHeight);
|
---|
| 3869 | QRect dispRect(0, 0, displayWidth, displayHeight);
|
---|
| 3870 | pDisplay = new VBoxVHWASurfaceBase(this,
|
---|
[71651] | 3871 | dispSize,
|
---|
| 3872 | dispRect,
|
---|
| 3873 | dispRect,
|
---|
| 3874 | dispRect, /* we do not know viewport at the stage of precise, set as a
|
---|
| 3875 | disp rect, it will be updated on repaint */
|
---|
| 3876 | format,
|
---|
| 3877 | NULL, NULL, NULL, NULL,
|
---|
[24646] | 3878 | #ifdef VBOXVHWA_USE_TEXGROUP
|
---|
[71651] | 3879 | 0,
|
---|
[24646] | 3880 | #endif
|
---|
[71651] | 3881 | 0 /* VBOXVHWAIMG_TYPE fFlags */);
|
---|
[63305] | 3882 | pDisplay->init(NULL, fUsesGuestVram ? size.VRAM() : NULL);
|
---|
[22816] | 3883 | mDisplay.setVGA(pDisplay);
|
---|
| 3884 | // VBOXQGLLOG(("\n\n*******\n\n viewport size is: (%d):(%d)\n\n*******\n\n", size().width(), size().height()));
|
---|
| 3885 | mViewport = QRect(0,0,displayWidth, displayHeight);
|
---|
| 3886 | adjustViewport(dispSize, mViewport);
|
---|
[25468] | 3887 | setupMatricies(dispSize, true);
|
---|
[22816] | 3888 |
|
---|
| 3889 | #ifdef VBOXQGL_DBG_SURF
|
---|
| 3890 | {
|
---|
| 3891 | uint32_t width = 100;
|
---|
| 3892 | uint32_t height = 60;
|
---|
| 3893 |
|
---|
[71651] | 3894 | for (int i = 0; i < RT_ELEMENTS(g_apSurf); i++)
|
---|
[22816] | 3895 | {
|
---|
[23346] | 3896 | VBoxVHWAColorFormat tmpFormat(FOURCC_YV12);
|
---|
| 3897 | QSize tmpSize(width, height) ;
|
---|
| 3898 | VBoxVHWASurfaceBase *pSurf1 = new VBoxVHWASurfaceBase(this, tmpSize,
|
---|
[71651] | 3899 | mDisplay.getPrimary()->rect(),
|
---|
| 3900 | QRect(0, 0, width, height),
|
---|
| 3901 | mViewport,
|
---|
| 3902 | tmpFormat,
|
---|
| 3903 | NULL, NULL, NULL, &VBoxVHWAColorKey(0,0),
|
---|
[24646] | 3904 | #ifdef VBOXVHWA_USE_TEXGROUP
|
---|
[71651] | 3905 | 0,
|
---|
[24646] | 3906 | #endif
|
---|
[71651] | 3907 | false);
|
---|
[22816] | 3908 |
|
---|
| 3909 | Assert(mDisplay.getVGA());
|
---|
| 3910 | pSurf1->init(mDisplay.getVGA(), NULL);
|
---|
| 3911 | uchar *addr = pSurf1->address();
|
---|
| 3912 | uchar cur = 0;
|
---|
[71651] | 3913 | for (uint32_t k = 0; k < width*height; k++)
|
---|
[22816] | 3914 | {
|
---|
| 3915 | addr[k] = cur;
|
---|
| 3916 | cur+=64;
|
---|
| 3917 | }
|
---|
| 3918 | pSurf1->updatedMem(&QRect(0,0,width, height));
|
---|
| 3919 |
|
---|
| 3920 | VBoxVHWASurfList *pConstructingList = new VBoxVHWASurfList();
|
---|
| 3921 | mDisplay.addOverlay(pConstructingList);
|
---|
| 3922 | pConstructingList->add(pSurf1);
|
---|
| 3923 | g_apSurf[i] = pSurf1;
|
---|
| 3924 |
|
---|
| 3925 | }
|
---|
| 3926 |
|
---|
| 3927 | VBOXVHWACMD_SURF_OVERLAY_UPDATE updateCmd;
|
---|
| 3928 | memset(&updateCmd, 0, sizeof(updateCmd));
|
---|
| 3929 | updateCmd.u.in.hSrcSurf = (VBOXVHWA_SURFHANDLE)g_apSurf[0];
|
---|
| 3930 | updateCmd.u.in.hDstSurf = (VBOXVHWA_SURFHANDLE)pDisplay;
|
---|
[71651] | 3931 | updateCmd.u.in.flags = VBOXVHWA_OVER_SHOW
|
---|
| 3932 | | VBOXVHWA_OVER_KEYDESTOVERRIDE;
|
---|
[22816] | 3933 |
|
---|
| 3934 | updateCmd.u.in.desc.DstCK.high = 1;
|
---|
| 3935 | updateCmd.u.in.desc.DstCK.low = 1;
|
---|
| 3936 |
|
---|
| 3937 | updateCmd.u.in.dstRect.left = 0;
|
---|
| 3938 | updateCmd.u.in.dstRect.right = pDisplay->width();
|
---|
[71651] | 3939 | updateCmd.u.in.dstRect.top = (pDisplay->height() - height) / 2;
|
---|
[22816] | 3940 | updateCmd.u.in.dstRect.bottom = updateCmd.u.in.dstRect.top + height;
|
---|
| 3941 |
|
---|
| 3942 | updateCmd.u.in.srcRect.left = 0;
|
---|
| 3943 | updateCmd.u.in.srcRect.right = width;
|
---|
| 3944 | updateCmd.u.in.srcRect.top = 0;
|
---|
| 3945 | updateCmd.u.in.srcRect.bottom = height;
|
---|
| 3946 |
|
---|
[23346] | 3947 | updateCmd.u.in.offDstSurface = VBOXVHWA_OFFSET64_VOID; /* just a magic to avoid surf mem buffer change */
|
---|
| 3948 | updateCmd.u.in.offSrcSurface = VBOXVHWA_OFFSET64_VOID; /* just a magic to avoid surf mem buffer change */
|
---|
[22816] | 3949 |
|
---|
| 3950 | vhwaSurfaceOverlayUpdate(&updateCmd);
|
---|
| 3951 | }
|
---|
| 3952 | #endif
|
---|
| 3953 |
|
---|
[71651] | 3954 | // if (!mOnResizeCmdList.empty())
|
---|
[27682] | 3955 | // {
|
---|
| 3956 | // for (VHWACommandList::const_iterator it = mOnResizeCmdList.begin();
|
---|
| 3957 | // it != mOnResizeCmdList.end(); ++ it)
|
---|
| 3958 | // {
|
---|
| 3959 | // VBOXVHWACMD * pCmd = (*it);
|
---|
| 3960 | // vboxDoVHWACmdExec(pCmd);
|
---|
| 3961 | // free(pCmd);
|
---|
| 3962 | // }
|
---|
| 3963 | // mOnResizeCmdList.clear();
|
---|
| 3964 | // }
|
---|
[22816] | 3965 |
|
---|
| 3966 | if (remind)
|
---|
[71371] | 3967 | popupCenter().remindAboutWrongColorDepth(windowManager().mainWindowShown(), size.bitsPerPixel(), 32);
|
---|
[47510] | 3968 | else
|
---|
[71371] | 3969 | popupCenter().forgetAboutWrongColorDepth(windowManager().mainWindowShown());
|
---|
[22816] | 3970 | }
|
---|
| 3971 |
|
---|
[71651] | 3972 | VBoxVHWAColorFormat::VBoxVHWAColorFormat (uint32_t bitsPerPixel, uint32_t r, uint32_t g, uint32_t b)
|
---|
| 3973 | : mWidthCompression(1)
|
---|
| 3974 | , mHeightCompression(1)
|
---|
[22816] | 3975 | {
|
---|
[71651] | 3976 | init(bitsPerPixel, r, g, b);
|
---|
[22816] | 3977 | }
|
---|
| 3978 |
|
---|
[71651] | 3979 | VBoxVHWAColorFormat::VBoxVHWAColorFormat(uint32_t fourcc)
|
---|
| 3980 | : mWidthCompression(1)
|
---|
| 3981 | , mHeightCompression(1)
|
---|
[22816] | 3982 | {
|
---|
[71651] | 3983 | init(fourcc);
|
---|
[22816] | 3984 | }
|
---|
| 3985 |
|
---|
[71651] | 3986 | void VBoxVHWAColorFormat::init(uint32_t fourcc)
|
---|
[22816] | 3987 | {
|
---|
| 3988 | mDataFormat = fourcc;
|
---|
| 3989 | mInternalFormat = GL_RGBA8;//GL_RGB;
|
---|
| 3990 | mFormat = GL_BGRA_EXT;//GL_RGBA;
|
---|
| 3991 | mType = GL_UNSIGNED_BYTE;
|
---|
[71651] | 3992 | mR = VBoxVHWAColorComponent(0xff);
|
---|
| 3993 | mG = VBoxVHWAColorComponent(0xff);
|
---|
| 3994 | mB = VBoxVHWAColorComponent(0xff);
|
---|
| 3995 | mA = VBoxVHWAColorComponent(0xff);
|
---|
[22816] | 3996 | mBitsPerPixelTex = 32;
|
---|
| 3997 |
|
---|
| 3998 | switch(fourcc)
|
---|
| 3999 | {
|
---|
| 4000 | case FOURCC_AYUV:
|
---|
| 4001 | mBitsPerPixel = 32;
|
---|
| 4002 | mWidthCompression = 1;
|
---|
| 4003 | break;
|
---|
| 4004 | case FOURCC_UYVY:
|
---|
| 4005 | case FOURCC_YUY2:
|
---|
| 4006 | mBitsPerPixel = 16;
|
---|
| 4007 | mWidthCompression = 2;
|
---|
| 4008 | break;
|
---|
| 4009 | case FOURCC_YV12:
|
---|
| 4010 | mBitsPerPixel = 8;
|
---|
| 4011 | mWidthCompression = 4;
|
---|
| 4012 | break;
|
---|
| 4013 | default:
|
---|
[49940] | 4014 | AssertFailed();
|
---|
[22816] | 4015 | mBitsPerPixel = 0;
|
---|
| 4016 | mBitsPerPixelTex = 0;
|
---|
| 4017 | mWidthCompression = 0;
|
---|
| 4018 | break;
|
---|
| 4019 | }
|
---|
| 4020 | }
|
---|
| 4021 |
|
---|
[71651] | 4022 | void VBoxVHWAColorFormat::init(uint32_t bitsPerPixel, uint32_t r, uint32_t g, uint32_t b)
|
---|
[22816] | 4023 | {
|
---|
| 4024 | mBitsPerPixel = bitsPerPixel;
|
---|
| 4025 | mBitsPerPixelTex = bitsPerPixel;
|
---|
| 4026 | mDataFormat = 0;
|
---|
| 4027 | switch (bitsPerPixel)
|
---|
| 4028 | {
|
---|
| 4029 | case 32:
|
---|
| 4030 | mInternalFormat = GL_RGB;//3;//GL_RGB;
|
---|
| 4031 | mFormat = GL_BGRA_EXT;//GL_RGBA;
|
---|
| 4032 | mType = GL_UNSIGNED_BYTE;
|
---|
[71651] | 4033 | mR = VBoxVHWAColorComponent(r);
|
---|
| 4034 | mG = VBoxVHWAColorComponent(g);
|
---|
| 4035 | mB = VBoxVHWAColorComponent(b);
|
---|
[22816] | 4036 | break;
|
---|
| 4037 | case 24:
|
---|
| 4038 | #ifdef DEBUG_misha
|
---|
[49940] | 4039 | AssertFailed();
|
---|
[22816] | 4040 | #endif
|
---|
| 4041 | mInternalFormat = 3;//GL_RGB;
|
---|
| 4042 | mFormat = GL_BGR_EXT;
|
---|
| 4043 | mType = GL_UNSIGNED_BYTE;
|
---|
[71651] | 4044 | mR = VBoxVHWAColorComponent(r);
|
---|
| 4045 | mG = VBoxVHWAColorComponent(g);
|
---|
| 4046 | mB = VBoxVHWAColorComponent(b);
|
---|
[22816] | 4047 | break;
|
---|
| 4048 | case 16:
|
---|
| 4049 | #ifdef DEBUG_misha
|
---|
[49940] | 4050 | AssertFailed();
|
---|
[22816] | 4051 | #endif
|
---|
| 4052 | mInternalFormat = GL_RGB5;
|
---|
| 4053 | mFormat = GL_BGR_EXT;
|
---|
[71651] | 4054 | mType = GL_UNSIGNED_BYTE; /** @todo ??? */
|
---|
| 4055 | mR = VBoxVHWAColorComponent(r);
|
---|
| 4056 | mG = VBoxVHWAColorComponent(g);
|
---|
| 4057 | mB = VBoxVHWAColorComponent(b);
|
---|
[22816] | 4058 | break;
|
---|
| 4059 | case 8:
|
---|
| 4060 | #ifdef DEBUG_misha
|
---|
[49940] | 4061 | AssertFailed();
|
---|
[22816] | 4062 | #endif
|
---|
| 4063 | mInternalFormat = 1;//GL_RGB;
|
---|
| 4064 | mFormat = GL_RED;//GL_RGB;
|
---|
| 4065 | mType = GL_UNSIGNED_BYTE;
|
---|
[71651] | 4066 | mR = VBoxVHWAColorComponent(0xff);
|
---|
[22816] | 4067 | break;
|
---|
| 4068 | case 1:
|
---|
| 4069 | #ifdef DEBUG_misha
|
---|
[49940] | 4070 | AssertFailed();
|
---|
[22816] | 4071 | #endif
|
---|
| 4072 | mInternalFormat = 1;
|
---|
| 4073 | mFormat = GL_COLOR_INDEX;
|
---|
| 4074 | mType = GL_BITMAP;
|
---|
[71651] | 4075 | mR = VBoxVHWAColorComponent(0x1);
|
---|
[22816] | 4076 | break;
|
---|
| 4077 | default:
|
---|
| 4078 | #ifdef DEBUG_misha
|
---|
[49940] | 4079 | AssertFailed();
|
---|
[22816] | 4080 | #endif
|
---|
| 4081 | mBitsPerPixel = 0;
|
---|
| 4082 | mBitsPerPixelTex = 0;
|
---|
| 4083 | break;
|
---|
| 4084 | }
|
---|
| 4085 | }
|
---|
| 4086 |
|
---|
[71651] | 4087 | bool VBoxVHWAColorFormat::equals(const VBoxVHWAColorFormat &other) const
|
---|
[22816] | 4088 | {
|
---|
[71651] | 4089 | if (fourcc())
|
---|
[22816] | 4090 | return fourcc() == other.fourcc();
|
---|
[71651] | 4091 | if (other.fourcc())
|
---|
[22816] | 4092 | return false;
|
---|
| 4093 |
|
---|
| 4094 | return bitsPerPixel() == other.bitsPerPixel();
|
---|
| 4095 | }
|
---|
| 4096 |
|
---|
[25583] | 4097 | VBoxVHWAColorComponent::VBoxVHWAColorComponent (uint32_t aMask)
|
---|
[22816] | 4098 | {
|
---|
[71651] | 4099 | unsigned f = ASMBitFirstSetU32(aMask);
|
---|
| 4100 | if (f)
|
---|
[22816] | 4101 | {
|
---|
| 4102 | mOffset = f - 1;
|
---|
[71651] | 4103 | f = ASMBitFirstSetU32(~(aMask >> mOffset));
|
---|
| 4104 | if (f)
|
---|
[22816] | 4105 | mcBits = f - 1;
|
---|
| 4106 | else
|
---|
| 4107 | mcBits = 32 - mOffset;
|
---|
| 4108 |
|
---|
[71651] | 4109 | Assert(mcBits);
|
---|
[22816] | 4110 | mMask = (((uint32_t)0xffffffff) >> (32 - mcBits)) << mOffset;
|
---|
[71651] | 4111 | Assert(mMask == aMask);
|
---|
[22816] | 4112 |
|
---|
| 4113 | mRange = (mMask >> mOffset) + 1;
|
---|
| 4114 | }
|
---|
| 4115 | else
|
---|
| 4116 | {
|
---|
| 4117 | mMask = 0;
|
---|
| 4118 | mRange = 0;
|
---|
| 4119 | mOffset = 32;
|
---|
| 4120 | mcBits = 0;
|
---|
| 4121 | }
|
---|
| 4122 | }
|
---|
| 4123 |
|
---|
[71651] | 4124 | void VBoxVHWAColorFormat::pixel2Normalized(uint32_t pix, float *r, float *g, float *b) const
|
---|
[22816] | 4125 | {
|
---|
[71651] | 4126 | *r = mR.colorValNorm(pix);
|
---|
| 4127 | *g = mG.colorValNorm(pix);
|
---|
| 4128 | *b = mB.colorValNorm(pix);
|
---|
[22816] | 4129 | }
|
---|
| 4130 |
|
---|
[71651] | 4131 | VBoxQGLOverlay::VBoxQGLOverlay()
|
---|
| 4132 | : mpOverlayWgt(NULL)
|
---|
| 4133 | , mpViewport(NULL)
|
---|
| 4134 | , mGlOn(false)
|
---|
| 4135 | , mOverlayWidgetVisible(false)
|
---|
| 4136 | , mOverlayVisible(false)
|
---|
| 4137 | , mGlCurrent(false)
|
---|
| 4138 | , mProcessingCommands(false)
|
---|
| 4139 | , mNeedOverlayRepaint(false)
|
---|
| 4140 | , mNeedSetVisible(false)
|
---|
| 4141 | , mCmdPipe()
|
---|
| 4142 | , mSettings()
|
---|
| 4143 | , mpSession()
|
---|
| 4144 | , mpShareWgt(NULL)
|
---|
| 4145 | , m_id(0)
|
---|
[22816] | 4146 | {
|
---|
[24471] | 4147 | /* postpone the gl widget initialization to avoid conflict with 3D on Mac */
|
---|
| 4148 | }
|
---|
[23630] | 4149 |
|
---|
[71651] | 4150 | void VBoxQGLOverlay::init(QWidget *pViewport, QObject *pPostEventObject, CSession *aSession, uint32_t id)
|
---|
[52086] | 4151 | {
|
---|
| 4152 | mpViewport = pViewport;
|
---|
| 4153 | mpSession = aSession;
|
---|
| 4154 | m_id = id;
|
---|
| 4155 | mSettings.init(*aSession);
|
---|
| 4156 | mCmdPipe.init(pPostEventObject);
|
---|
| 4157 | }
|
---|
| 4158 |
|
---|
[27682] | 4159 | class VBoxGLShareWgt : public QGLWidget
|
---|
| 4160 | {
|
---|
| 4161 | public:
|
---|
[71651] | 4162 | VBoxGLShareWgt()
|
---|
| 4163 | : QGLWidget(new VBoxGLContext(VBoxVHWAImage::vboxGLFormat()))
|
---|
[27961] | 4164 | {
|
---|
| 4165 | /* work-around to disable done current needed to old ATI drivers on Linux */
|
---|
[71651] | 4166 | VBoxGLContext *pc = (VBoxGLContext *)context();
|
---|
| 4167 | pc->allowDoneCurrent(false);
|
---|
[27961] | 4168 | }
|
---|
[27682] | 4169 |
|
---|
| 4170 | protected:
|
---|
| 4171 | void initializeGL()
|
---|
| 4172 | {
|
---|
| 4173 | vboxVHWAGetSupportInfo(context());
|
---|
| 4174 | VBoxVHWASurfaceBase::globalInit();
|
---|
| 4175 | }
|
---|
| 4176 | };
|
---|
[24471] | 4177 | void VBoxQGLOverlay::initGl()
|
---|
| 4178 | {
|
---|
[71651] | 4179 | if (mpOverlayWgt)
|
---|
[27682] | 4180 | {
|
---|
| 4181 | Assert(mpShareWgt);
|
---|
[26509] | 4182 | return;
|
---|
[27682] | 4183 | }
|
---|
[25226] | 4184 |
|
---|
[27682] | 4185 | if (!mpShareWgt)
|
---|
| 4186 | {
|
---|
| 4187 | mpShareWgt = new VBoxGLShareWgt();
|
---|
| 4188 | /* force initializeGL */
|
---|
| 4189 | mpShareWgt->updateGL();
|
---|
| 4190 | }
|
---|
[25226] | 4191 |
|
---|
[27682] | 4192 | mOverlayImage.init(&mSettings);
|
---|
| 4193 | mpOverlayWgt = new VBoxGLWgt(&mOverlayImage, mpViewport, mpShareWgt);
|
---|
[25226] | 4194 |
|
---|
[22816] | 4195 | mOverlayWidgetVisible = true; /* to ensure it is set hidden with vboxShowOverlay */
|
---|
[71651] | 4196 | vboxShowOverlay(false);
|
---|
[25226] | 4197 |
|
---|
[71651] | 4198 | mpOverlayWgt->setMouseTracking(true);
|
---|
[22816] | 4199 | }
|
---|
| 4200 |
|
---|
[27697] | 4201 | void VBoxQGLOverlay::updateAttachment(QWidget *pViewport, QObject *pPostEventObject)
|
---|
| 4202 | {
|
---|
| 4203 | if (mpViewport != pViewport)
|
---|
| 4204 | {
|
---|
| 4205 | mpViewport = pViewport;
|
---|
[27757] | 4206 | mpOverlayWgt = NULL;
|
---|
| 4207 | mOverlayWidgetVisible = false;
|
---|
| 4208 | if (mOverlayImage.hasSurfaces())
|
---|
[27720] | 4209 | {
|
---|
[27839] | 4210 | // Assert(!mOverlayVisible);
|
---|
[27724] | 4211 | if (pViewport)
|
---|
| 4212 | {
|
---|
| 4213 | initGl();
|
---|
[27720] | 4214 | // vboxDoCheckUpdateViewport();
|
---|
[27724] | 4215 | }
|
---|
[27839] | 4216 | // Assert(!mOverlayVisible);
|
---|
[27720] | 4217 | }
|
---|
[27697] | 4218 | mGlCurrent = false;
|
---|
| 4219 | }
|
---|
[27757] | 4220 | mCmdPipe.setNotifyObject(pPostEventObject);
|
---|
[27697] | 4221 | }
|
---|
| 4222 |
|
---|
[24162] | 4223 | int VBoxQGLOverlay::reset()
|
---|
| 4224 | {
|
---|
[49420] | 4225 | CDisplay display = mpSession->GetConsole().GetDisplay();
|
---|
| 4226 | Assert (!display.isNull());
|
---|
[24162] | 4227 |
|
---|
[49420] | 4228 | mCmdPipe.reset(&display);
|
---|
[24162] | 4229 |
|
---|
[24925] | 4230 | resetGl();
|
---|
| 4231 |
|
---|
[24162] | 4232 | return VINF_SUCCESS;
|
---|
| 4233 | }
|
---|
| 4234 |
|
---|
[71651] | 4235 | static DECLCALLBACK(void) vbvaVHWAHHCommandFreeCmd(void *pvContext)
|
---|
[24925] | 4236 | {
|
---|
[71651] | 4237 | free(pvContext);
|
---|
[24925] | 4238 | }
|
---|
| 4239 |
|
---|
| 4240 | int VBoxQGLOverlay::resetGl()
|
---|
| 4241 | {
|
---|
[27682] | 4242 | VHWACommandList list;
|
---|
| 4243 | int rc = mOverlayImage.reset(&list);
|
---|
| 4244 | AssertRC(rc);
|
---|
| 4245 | if (RT_SUCCESS(rc))
|
---|
[24925] | 4246 | {
|
---|
[71651] | 4247 | for (VHWACommandList::const_iterator sIt = list.begin(); sIt != list.end(); ++ sIt)
|
---|
[24925] | 4248 | {
|
---|
[27682] | 4249 | VBOXVHWACMD *pCmd = (*sIt);
|
---|
| 4250 | VBOXVHWA_HH_CALLBACK_SET(pCmd, vbvaVHWAHHCommandFreeCmd, pCmd);
|
---|
[71651] | 4251 | mCmdPipe.postCmd(VBOXVHWA_PIPECMD_VHWA, pCmd, pCmd->enmCmd, false /*fGuestCmd*/);
|
---|
[24925] | 4252 | }
|
---|
| 4253 | }
|
---|
| 4254 | return VINF_SUCCESS;
|
---|
| 4255 | }
|
---|
| 4256 |
|
---|
[71651] | 4257 | int VBoxQGLOverlay::onVHWACommand(struct VBOXVHWACMD RT_UNTRUSTED_VOLATILE_GUEST *pCmd,
|
---|
| 4258 | int /*VBOXVHWACMD_TYPE*/ enmCmdInt, bool fGuestCmd)
|
---|
[22816] | 4259 | {
|
---|
[71651] | 4260 | VBOXVHWACMD_TYPE const enmCmd = (VBOXVHWACMD_TYPE)enmCmdInt;
|
---|
| 4261 | Log(("VHWA Command >>> %#p, %d\n", pCmd, enmCmd));
|
---|
| 4262 | switch (enmCmd)
|
---|
[22836] | 4263 | {
|
---|
| 4264 | case VBOXVHWACMD_TYPE_SURF_FLIP:
|
---|
| 4265 | case VBOXVHWACMD_TYPE_SURF_OVERLAY_UPDATE:
|
---|
| 4266 | case VBOXVHWACMD_TYPE_SURF_OVERLAY_SETPOSITION:
|
---|
| 4267 | break;
|
---|
[49420] | 4268 | case VBOXVHWACMD_TYPE_HH_CONSTRUCT:
|
---|
| 4269 | {
|
---|
[71651] | 4270 | pCmd->Flags &= ~VBOXVHWACMD_FLAG_HG_ASYNCH;
|
---|
| 4271 | ASSERT_GUEST_STMT_RETURN(!fGuestCmd, pCmd->rc = VERR_ACCESS_DENIED, VINF_SUCCESS);
|
---|
[71594] | 4272 | VBOXVHWACMD_HH_CONSTRUCT *pBody = VBOXVHWACMD_BODY_HOST_HEAP(pCmd, VBOXVHWACMD_HH_CONSTRUCT);
|
---|
[49420] | 4273 | pCmd->rc = vhwaConstruct(pBody);
|
---|
[71651] | 4274 | Log(("VHWA Command <<< Sync %#p, %d\n", pCmd, enmCmd));
|
---|
[49420] | 4275 | return VINF_SUCCESS;
|
---|
| 4276 | }
|
---|
[71651] | 4277 |
|
---|
[24162] | 4278 | case VBOXVHWACMD_TYPE_HH_RESET:
|
---|
| 4279 | {
|
---|
[71651] | 4280 | pCmd->Flags &= ~VBOXVHWACMD_FLAG_HG_ASYNCH;
|
---|
| 4281 | ASSERT_GUEST_STMT_RETURN(!fGuestCmd, pCmd->rc = VERR_ACCESS_DENIED, VINF_SUCCESS);
|
---|
[24162] | 4282 | /* we do not post a reset command to the gui thread since this may lead to a deadlock
|
---|
| 4283 | * when reset is initiated by the gui thread*/
|
---|
| 4284 | pCmd->rc = reset();
|
---|
[71651] | 4285 | Log(("VHWA Command <<< Sync %#p, %d\n", pCmd, enmCmd));
|
---|
[24162] | 4286 | return VINF_SUCCESS;
|
---|
| 4287 | }
|
---|
[71651] | 4288 |
|
---|
[34129] | 4289 | case VBOXVHWACMD_TYPE_HH_ENABLE:
|
---|
| 4290 | pCmd->Flags &= ~VBOXVHWACMD_FLAG_HG_ASYNCH;
|
---|
[71651] | 4291 | ASSERT_GUEST_STMT_RETURN(!fGuestCmd, pCmd->rc = VERR_ACCESS_DENIED, VINF_SUCCESS);
|
---|
[34129] | 4292 | pCmd->rc = VINF_SUCCESS;
|
---|
[71651] | 4293 | Log(("VHWA Command <<< Sync %#p, %d\n", pCmd, enmCmd));
|
---|
[34129] | 4294 | return VINF_SUCCESS;
|
---|
[71651] | 4295 |
|
---|
[34129] | 4296 | case VBOXVHWACMD_TYPE_HH_DISABLE:
|
---|
| 4297 | pCmd->Flags &= ~VBOXVHWACMD_FLAG_HG_ASYNCH;
|
---|
[71651] | 4298 | ASSERT_GUEST_STMT_RETURN(!fGuestCmd, pCmd->rc = VERR_ACCESS_DENIED, VINF_SUCCESS);
|
---|
[34129] | 4299 | pCmd->rc = VINF_SUCCESS;
|
---|
[71651] | 4300 | Log(("VHWA Command <<< Sync %#p, %d\n", pCmd, enmCmd));
|
---|
[34129] | 4301 | return VINF_SUCCESS;
|
---|
[71651] | 4302 |
|
---|
[34140] | 4303 | case VBOXVHWACMD_TYPE_HH_SAVESTATE_SAVEBEGIN:
|
---|
[71651] | 4304 | pCmd->Flags &= ~VBOXVHWACMD_FLAG_HG_ASYNCH;
|
---|
| 4305 | ASSERT_GUEST_STMT_RETURN(!fGuestCmd, pCmd->rc = VERR_ACCESS_DENIED, VINF_SUCCESS);
|
---|
[34140] | 4306 | mCmdPipe.disable();
|
---|
| 4307 | pCmd->rc = VINF_SUCCESS;
|
---|
[71651] | 4308 | Log(("VHWA Command <<< Sync %#p, %d\n", pCmd, enmCmd));
|
---|
[34140] | 4309 | return VINF_SUCCESS;
|
---|
[71651] | 4310 |
|
---|
[34140] | 4311 | case VBOXVHWACMD_TYPE_HH_SAVESTATE_SAVEEND:
|
---|
[71651] | 4312 | ASSERT_GUEST_STMT_RETURN(!fGuestCmd, pCmd->rc = VERR_ACCESS_DENIED, VINF_SUCCESS);
|
---|
| 4313 | pCmd->Flags &= ~VBOXVHWACMD_FLAG_HG_ASYNCH;
|
---|
[34140] | 4314 | mCmdPipe.enable();
|
---|
| 4315 | pCmd->rc = VINF_SUCCESS;
|
---|
[71651] | 4316 | Log(("VHWA Command <<< Sync %#p, %d\n", pCmd, enmCmd));
|
---|
[34140] | 4317 | return VINF_SUCCESS;
|
---|
[71651] | 4318 |
|
---|
[34140] | 4319 | case VBOXVHWACMD_TYPE_HH_SAVESTATE_SAVEPERFORM:
|
---|
| 4320 | {
|
---|
[71651] | 4321 | pCmd->Flags &= ~VBOXVHWACMD_FLAG_HG_ASYNCH;
|
---|
| 4322 | ASSERT_GUEST_STMT_RETURN(!fGuestCmd, pCmd->rc = VERR_ACCESS_DENIED, VINF_SUCCESS);
|
---|
[71594] | 4323 | VBOXVHWACMD_HH_SAVESTATE_SAVEPERFORM *pSave = VBOXVHWACMD_BODY_HOST_HEAP(pCmd, VBOXVHWACMD_HH_SAVESTATE_SAVEPERFORM);
|
---|
[34140] | 4324 | PSSMHANDLE pSSM = pSave->pSSM;
|
---|
| 4325 | int rc = SSMR3PutU32(pSSM, VBOXQGL_STATE_VERSION); AssertRC(rc);
|
---|
| 4326 | if (RT_SUCCESS(rc))
|
---|
| 4327 | vhwaSaveExec(pSSM);
|
---|
| 4328 | pCmd->rc = rc;
|
---|
[71651] | 4329 | Log(("VHWA Command <<< Sync %#p, %d\n", pCmd, enmCmd));
|
---|
[34140] | 4330 | return VINF_SUCCESS;
|
---|
| 4331 | }
|
---|
| 4332 | case VBOXVHWACMD_TYPE_HH_SAVESTATE_LOADPERFORM:
|
---|
| 4333 | {
|
---|
[71651] | 4334 | pCmd->Flags &= ~VBOXVHWACMD_FLAG_HG_ASYNCH;
|
---|
| 4335 | ASSERT_GUEST_STMT_RETURN(!fGuestCmd, pCmd->rc = VERR_ACCESS_DENIED, VINF_SUCCESS);
|
---|
[71594] | 4336 | VBOXVHWACMD_HH_SAVESTATE_LOADPERFORM *pLoad = VBOXVHWACMD_BODY_HOST_HEAP(pCmd, VBOXVHWACMD_HH_SAVESTATE_LOADPERFORM);
|
---|
[34140] | 4337 | PSSMHANDLE pSSM = pLoad->pSSM;
|
---|
[49420] | 4338 | uint32_t u32Version = 0;
|
---|
[34140] | 4339 | int rc = SSMR3GetU32(pSSM, &u32Version); Assert(RT_SUCCESS(rc) || rc == VERR_SSM_LOADED_TOO_MUCH);
|
---|
| 4340 | if (RT_SUCCESS(rc))
|
---|
| 4341 | {
|
---|
[71651] | 4342 | rc = vhwaLoadExec(pSSM, u32Version);
|
---|
| 4343 | AssertRC(rc);
|
---|
[34140] | 4344 | }
|
---|
[49420] | 4345 | else
|
---|
[34140] | 4346 | {
|
---|
[49420] | 4347 | /* sanity */
|
---|
| 4348 | u32Version = 0;
|
---|
| 4349 |
|
---|
| 4350 | if (rc == VERR_SSM_LOADED_TOO_MUCH)
|
---|
| 4351 | rc = VINF_SUCCESS;
|
---|
[34140] | 4352 | }
|
---|
| 4353 | pCmd->rc = rc;
|
---|
[71651] | 4354 | Log(("VHWA Command <<< Sync %#p, %d\n", pCmd, enmCmd));
|
---|
[34140] | 4355 | return VINF_SUCCESS;
|
---|
| 4356 | }
|
---|
[71651] | 4357 |
|
---|
[49420] | 4358 | case VBOXVHWACMD_TYPE_QUERY_INFO1:
|
---|
| 4359 | {
|
---|
[49485] | 4360 | #ifdef RT_STRICT
|
---|
[71594] | 4361 | VBOXVHWACMD_QUERYINFO1 RT_UNTRUSTED_VOLATILE_GUEST *pBody = VBOXVHWACMD_BODY(pCmd, VBOXVHWACMD_QUERYINFO1);
|
---|
[49485] | 4362 | #endif
|
---|
[49420] | 4363 | Assert(pBody->u.in.guestVersion.maj == VBOXVHWA_VERSION_MAJ);
|
---|
| 4364 | Assert(pBody->u.in.guestVersion.min == VBOXVHWA_VERSION_MIN);
|
---|
| 4365 | Assert(pBody->u.in.guestVersion.bld == VBOXVHWA_VERSION_BLD);
|
---|
| 4366 | Assert(pBody->u.in.guestVersion.reserved == VBOXVHWA_VERSION_RSV);
|
---|
| 4367 | /* do NOT break!! make it proceed asynchronously */
|
---|
| 4368 | }
|
---|
[71651] | 4369 |
|
---|
[22836] | 4370 | default:
|
---|
| 4371 | break;
|
---|
[25264] | 4372 | }
|
---|
[49420] | 4373 |
|
---|
[71651] | 4374 | Log(("VHWA Command --- Going Async %#p, %d\n", pCmd, enmCmd));
|
---|
[22816] | 4375 | /* indicate that we process and complete the command asynchronously */
|
---|
| 4376 | pCmd->Flags |= VBOXVHWACMD_FLAG_HG_ASYNCH;
|
---|
[22836] | 4377 |
|
---|
[71651] | 4378 | mCmdPipe.postCmd(VBOXVHWA_PIPECMD_VHWA, (void *)pCmd, enmCmd, fGuestCmd);
|
---|
[49420] | 4379 | return VINF_CALLBACK_RETURN;
|
---|
[22836] | 4380 |
|
---|
[22816] | 4381 | }
|
---|
| 4382 |
|
---|
[71651] | 4383 | void VBoxQGLOverlay::onVHWACommandEvent(QEvent *pEvent)
|
---|
[22816] | 4384 | {
|
---|
[71651] | 4385 | VBoxVHWACommandProcessEvent *pVhwaEvent = (VBoxVHWACommandProcessEvent *)pEvent;
|
---|
[49420] | 4386 | /* sanity actually */
|
---|
| 4387 | pVhwaEvent->setProcessed();
|
---|
| 4388 |
|
---|
[22816] | 4389 | Assert(!mProcessingCommands);
|
---|
| 4390 | mProcessingCommands = true;
|
---|
| 4391 | Assert(!mGlCurrent);
|
---|
| 4392 | mGlCurrent = false; /* just a fall-back */
|
---|
[49420] | 4393 | VBoxVHWACommandElement *pCmd = mCmdPipe.getCmd();
|
---|
| 4394 | if (pCmd)
|
---|
[22816] | 4395 | {
|
---|
[49420] | 4396 | processCmd(pCmd);
|
---|
| 4397 | mCmdPipe.doneCmd();
|
---|
[24925] | 4398 | }
|
---|
[22816] | 4399 |
|
---|
| 4400 | mProcessingCommands = false;
|
---|
[22834] | 4401 | repaint();
|
---|
| 4402 | mGlCurrent = false;
|
---|
[22816] | 4403 | }
|
---|
| 4404 |
|
---|
[71651] | 4405 | bool VBoxQGLOverlay::onNotifyUpdate(ULONG uX, ULONG uY, ULONG uW, ULONG uH)
|
---|
[22816] | 4406 | {
|
---|
[53803] | 4407 | /* Prepare corresponding viewport part: */
|
---|
[53964] | 4408 | QRect rect(uX, uY, uW, uH);
|
---|
[53803] | 4409 |
|
---|
[53964] | 4410 | /* Take the scaling into account: */
|
---|
[53803] | 4411 | const double dScaleFactor = mSizeInfo.scaleFactor();
|
---|
[53964] | 4412 | const QSize scaledSize = mSizeInfo.scaledSize();
|
---|
| 4413 | if (scaledSize.isValid())
|
---|
[53803] | 4414 | {
|
---|
[53964] | 4415 | /* Calculate corresponding scale-factors: */
|
---|
[71651] | 4416 | const double xScaleFactor = mSizeInfo.visualState() == UIVisualStateType_Scale
|
---|
| 4417 | ? (double)scaledSize.width() / mSizeInfo.width() : dScaleFactor;
|
---|
| 4418 | const double yScaleFactor = mSizeInfo.visualState() == UIVisualStateType_Scale
|
---|
| 4419 | ? (double)scaledSize.height() / mSizeInfo.height() : dScaleFactor;
|
---|
[53803] | 4420 | /* Adjust corresponding viewport part: */
|
---|
[56217] | 4421 | rect.moveTo((int)floor((double)rect.x() * xScaleFactor) - 1,
|
---|
| 4422 | (int)floor((double)rect.y() * yScaleFactor) - 1);
|
---|
| 4423 | rect.setSize(QSize((int)ceil((double)rect.width() * xScaleFactor) + 2,
|
---|
| 4424 | (int)ceil((double)rect.height() * yScaleFactor) + 2));
|
---|
[53803] | 4425 | }
|
---|
| 4426 |
|
---|
[69931] | 4427 | /* Take the device-pixel-ratio into account: */
|
---|
[53823] | 4428 | if (mSizeInfo.useUnscaledHiDPIOutput())
|
---|
| 4429 | {
|
---|
[69931] | 4430 | const double dDevicePixelRatio = gpDesktop->devicePixelRatio(mpViewport->window());
|
---|
| 4431 | if (dDevicePixelRatio > 1.0)
|
---|
[53823] | 4432 | {
|
---|
[69931] | 4433 | rect.moveTo((int)floor((double)rect.x() / dDevicePixelRatio) - 1,
|
---|
| 4434 | (int)floor((double)rect.y() / dDevicePixelRatio) - 1);
|
---|
| 4435 | rect.setSize(QSize((int)ceil((double)rect.width() / dDevicePixelRatio) + 2,
|
---|
| 4436 | (int)ceil((double)rect.height() / dDevicePixelRatio) + 2));
|
---|
[53823] | 4437 | }
|
---|
| 4438 | }
|
---|
| 4439 |
|
---|
[49420] | 4440 | /* we do not to miss notify updates, because we have to update bg textures for it,
|
---|
[51487] | 4441 | * so no not check for m_fUnused here,
|
---|
[49420] | 4442 | * mOverlay will store the required info for us */
|
---|
[71651] | 4443 | mCmdPipe.postCmd(VBOXVHWA_PIPECMD_PAINT, &rect, -1, false);
|
---|
[53803] | 4444 |
|
---|
[22816] | 4445 | return true;
|
---|
| 4446 | }
|
---|
| 4447 |
|
---|
[71651] | 4448 | void VBoxQGLOverlay::onResizeEventPostprocess(const VBoxFBSizeInfo &re, const QPoint &topLeft)
|
---|
[22816] | 4449 | {
|
---|
[27682] | 4450 | mSizeInfo = re;
|
---|
| 4451 | mContentsTopLeft = topLeft;
|
---|
[22816] | 4452 |
|
---|
[49420] | 4453 | if (mGlOn)
|
---|
[22816] | 4454 | {
|
---|
[49420] | 4455 | Assert(mOverlayImage.hasSurfaces());
|
---|
[22816] | 4456 | Assert(!mGlCurrent);
|
---|
[22834] | 4457 | Assert(!mNeedOverlayRepaint);
|
---|
[22816] | 4458 | mGlCurrent = false;
|
---|
| 4459 | makeCurrent();
|
---|
[33540] | 4460 | /* need to ensure we're in sync */
|
---|
[22834] | 4461 | mNeedOverlayRepaint = vboxSynchGl();
|
---|
[49420] | 4462 |
|
---|
| 4463 | if (!mOverlayImage.hasSurfaces())
|
---|
| 4464 | vboxSetGlOn(false);
|
---|
[22816] | 4465 | }
|
---|
[49420] | 4466 | else
|
---|
| 4467 | Assert(!mOverlayImage.hasSurfaces());
|
---|
[22816] | 4468 |
|
---|
[49420] | 4469 | if (!mOnResizeCmdList.empty())
|
---|
[22816] | 4470 | {
|
---|
[71651] | 4471 | for (VHWACommandList::const_iterator it = mOnResizeCmdList.begin(); it != mOnResizeCmdList.end(); ++ it)
|
---|
[22816] | 4472 | {
|
---|
[71651] | 4473 | VBOXVHWACMD *pCmd = (*it);
|
---|
| 4474 | vboxDoVHWACmdExec(pCmd, pCmd->enmCmd, false);
|
---|
[22816] | 4475 | free(pCmd);
|
---|
| 4476 | }
|
---|
| 4477 | mOnResizeCmdList.clear();
|
---|
| 4478 | }
|
---|
| 4479 |
|
---|
[22834] | 4480 | repaintOverlay();
|
---|
| 4481 | mGlCurrent = false;
|
---|
| 4482 | }
|
---|
| 4483 |
|
---|
| 4484 | void VBoxQGLOverlay::repaintMain()
|
---|
| 4485 | {
|
---|
[71651] | 4486 | if (mMainDirtyRect.isClear())
|
---|
[22834] | 4487 | return;
|
---|
| 4488 |
|
---|
| 4489 | const QRect &rect = mMainDirtyRect.rect();
|
---|
[71651] | 4490 | if (mOverlayWidgetVisible)
|
---|
| 4491 | if (mOverlayViewport.contains(rect))
|
---|
[22834] | 4492 | return;
|
---|
[22816] | 4493 |
|
---|
[71651] | 4494 | mpViewport->repaint(rect.x() - mContentsTopLeft.x(),
|
---|
| 4495 | rect.y() - mContentsTopLeft.y(),
|
---|
| 4496 | rect.width(),
|
---|
| 4497 | rect.height());
|
---|
[22834] | 4498 |
|
---|
| 4499 | mMainDirtyRect.clear();
|
---|
[22816] | 4500 | }
|
---|
| 4501 |
|
---|
[71651] | 4502 | void VBoxQGLOverlay::vboxDoVHWACmd(void RT_UNTRUSTED_VOLATILE_GUEST *pvCmd, int /*VBOXVHWACMD_TYPE*/ enmCmd, bool fGuestCmd)
|
---|
[22816] | 4503 | {
|
---|
[71651] | 4504 | vboxDoVHWACmdExec(pvCmd, enmCmd, fGuestCmd);
|
---|
[22816] | 4505 |
|
---|
[27682] | 4506 | CDisplay display = mpSession->GetConsole().GetDisplay();
|
---|
[71651] | 4507 | Assert(!display.isNull());
|
---|
[22816] | 4508 |
|
---|
[71651] | 4509 | Log(("VHWA Command <<< Async %#p, %d\n", pvCmd, enmCmd));
|
---|
[49420] | 4510 |
|
---|
[71651] | 4511 | display.CompleteVHWACommand((BYTE *)pvCmd);
|
---|
[22816] | 4512 | }
|
---|
| 4513 |
|
---|
[22834] | 4514 | bool VBoxQGLOverlay::vboxSynchGl()
|
---|
[22816] | 4515 | {
|
---|
[71651] | 4516 | VBoxVHWASurfaceBase *pVGA = mOverlayImage.vgaSurface();
|
---|
| 4517 | if ( pVGA
|
---|
| 4518 | && mSizeInfo.pixelFormat() == pVGA->pixelFormat().toVBoxPixelFormat()
|
---|
| 4519 | && mSizeInfo.VRAM() == pVGA->address()
|
---|
| 4520 | && mSizeInfo.bitsPerPixel() == pVGA->bitsPerPixel()
|
---|
| 4521 | && mSizeInfo.bytesPerLine() == pVGA->bytesPerLine()
|
---|
| 4522 | && mSizeInfo.width() == pVGA->width()
|
---|
| 4523 | && mSizeInfo.height() == pVGA->height()
|
---|
| 4524 | )
|
---|
[22816] | 4525 | {
|
---|
[22834] | 4526 | return false;
|
---|
[22816] | 4527 | }
|
---|
| 4528 | /* create and issue a resize event to the gl widget to ensure we have all gl data initialized
|
---|
| 4529 | * and synchronized with the framebuffer */
|
---|
[27682] | 4530 | mOverlayImage.resize(mSizeInfo);
|
---|
[22834] | 4531 | return true;
|
---|
[22816] | 4532 | }
|
---|
| 4533 |
|
---|
| 4534 | void VBoxQGLOverlay::vboxSetGlOn(bool on)
|
---|
| 4535 | {
|
---|
[71651] | 4536 | if (on == mGlOn)
|
---|
[22816] | 4537 | return;
|
---|
| 4538 |
|
---|
| 4539 | mGlOn = on;
|
---|
| 4540 |
|
---|
[71651] | 4541 | if (on)
|
---|
[22816] | 4542 | {
|
---|
[24170] | 4543 | /* need to ensure we have gl functions initialized */
|
---|
[27682] | 4544 | mpOverlayWgt->makeCurrent();
|
---|
| 4545 | vboxVHWAGetSupportInfo(mpOverlayWgt->context());
|
---|
[24170] | 4546 |
|
---|
[22816] | 4547 | VBOXQGLLOGREL(("Switching Gl mode on\n"));
|
---|
[27682] | 4548 | Assert(!mpOverlayWgt->isVisible());
|
---|
[22816] | 4549 | /* just to ensure */
|
---|
| 4550 | vboxShowOverlay(false);
|
---|
| 4551 | mOverlayVisible = false;
|
---|
| 4552 | vboxSynchGl();
|
---|
| 4553 | }
|
---|
| 4554 | else
|
---|
| 4555 | {
|
---|
| 4556 | VBOXQGLLOGREL(("Switching Gl mode off\n"));
|
---|
| 4557 | mOverlayVisible = false;
|
---|
| 4558 | vboxShowOverlay(false);
|
---|
| 4559 | /* for now just set the flag w/o destroying anything */
|
---|
| 4560 | }
|
---|
| 4561 | }
|
---|
| 4562 |
|
---|
| 4563 | void VBoxQGLOverlay::vboxDoCheckUpdateViewport()
|
---|
| 4564 | {
|
---|
[71651] | 4565 | if (!mOverlayVisible)
|
---|
[22816] | 4566 | {
|
---|
| 4567 | vboxShowOverlay(false);
|
---|
| 4568 | return;
|
---|
| 4569 | }
|
---|
| 4570 |
|
---|
[27682] | 4571 | int cX = mContentsTopLeft.x();
|
---|
| 4572 | int cY = mContentsTopLeft.y();
|
---|
| 4573 | QRect fbVp(cX, cY, mpViewport->width(), mpViewport->height());
|
---|
[22816] | 4574 | QRect overVp = fbVp.intersected(mOverlayViewport);
|
---|
| 4575 |
|
---|
[71651] | 4576 | if (overVp.isEmpty())
|
---|
[22816] | 4577 | vboxShowOverlay(false);
|
---|
| 4578 | else
|
---|
| 4579 | {
|
---|
[71651] | 4580 | if (overVp != mOverlayImage.vboxViewport())
|
---|
[22816] | 4581 | {
|
---|
| 4582 | makeCurrent();
|
---|
[27682] | 4583 | mOverlayImage.vboxDoUpdateViewport(overVp);
|
---|
[22834] | 4584 | mNeedOverlayRepaint = true;
|
---|
[22816] | 4585 | }
|
---|
| 4586 |
|
---|
| 4587 | QRect rect(overVp.x() - cX, overVp.y() - cY, overVp.width(), overVp.height());
|
---|
| 4588 |
|
---|
| 4589 | vboxCheckUpdateOverlay(rect);
|
---|
| 4590 |
|
---|
| 4591 | vboxShowOverlay(true);
|
---|
[23657] | 4592 |
|
---|
| 4593 | /* workaround for linux ATI issue: need to update gl viewport after widget becomes visible */
|
---|
[27682] | 4594 | mOverlayImage.vboxDoUpdateViewport(overVp);
|
---|
[22816] | 4595 | }
|
---|
| 4596 | }
|
---|
| 4597 |
|
---|
| 4598 | void VBoxQGLOverlay::vboxShowOverlay(bool show)
|
---|
| 4599 | {
|
---|
[71651] | 4600 | if (mOverlayWidgetVisible != show)
|
---|
[22816] | 4601 | {
|
---|
[27682] | 4602 | mpOverlayWgt->setVisible(show);
|
---|
[22816] | 4603 | mOverlayWidgetVisible = show;
|
---|
[23346] | 4604 | mGlCurrent = false;
|
---|
[71651] | 4605 | if (!show)
|
---|
[27682] | 4606 | mMainDirtyRect.add(mOverlayImage.vboxViewport());
|
---|
[22816] | 4607 | }
|
---|
| 4608 | }
|
---|
| 4609 |
|
---|
[71651] | 4610 | void VBoxQGLOverlay::vboxCheckUpdateOverlay(const QRect &rect)
|
---|
[22816] | 4611 | {
|
---|
[27682] | 4612 | QRect overRect(mpOverlayWgt->pos(), mpOverlayWgt->size());
|
---|
[71651] | 4613 | if (overRect.x() != rect.x() || overRect.y() != rect.y())
|
---|
[22816] | 4614 | {
|
---|
[23874] | 4615 | #if defined(RT_OS_WINDOWS)
|
---|
[27682] | 4616 | mpOverlayWgt->setVisible(false);
|
---|
[23766] | 4617 | mNeedSetVisible = true;
|
---|
[23874] | 4618 | #endif
|
---|
[23766] | 4619 | VBOXQGLLOG_QRECT("moving wgt to " , &rect, "\n");
|
---|
[27682] | 4620 | mpOverlayWgt->move(rect.x(), rect.y());
|
---|
[23346] | 4621 | mGlCurrent = false;
|
---|
[22816] | 4622 | }
|
---|
| 4623 |
|
---|
[71651] | 4624 | if (overRect.width() != rect.width() || overRect.height() != rect.height())
|
---|
[22816] | 4625 | {
|
---|
[23874] | 4626 | #if defined(RT_OS_WINDOWS)
|
---|
[27682] | 4627 | mpOverlayWgt->setVisible(false);
|
---|
[23766] | 4628 | mNeedSetVisible = true;
|
---|
[23874] | 4629 | #endif
|
---|
[23766] | 4630 | VBOXQGLLOG(("resizing wgt to w(%d) ,h(%d)\n" , rect.width(), rect.height()));
|
---|
[27682] | 4631 | mpOverlayWgt->resize(rect.width(), rect.height());
|
---|
[23346] | 4632 | mGlCurrent = false;
|
---|
[22816] | 4633 | }
|
---|
| 4634 | }
|
---|
| 4635 |
|
---|
[71651] | 4636 | void VBoxQGLOverlay::addMainDirtyRect(const QRect &aRect)
|
---|
[22834] | 4637 | {
|
---|
| 4638 | mMainDirtyRect.add(aRect);
|
---|
[71651] | 4639 | if (mGlOn)
|
---|
[22834] | 4640 | {
|
---|
[27682] | 4641 | mOverlayImage.vboxDoUpdateRect(&aRect);
|
---|
[22846] | 4642 | mNeedOverlayRepaint = true;
|
---|
[22834] | 4643 | }
|
---|
| 4644 | }
|
---|
| 4645 |
|
---|
[71594] | 4646 | int VBoxQGLOverlay::vhwaSurfaceUnlock(struct VBOXVHWACMD_SURF_UNLOCK RT_UNTRUSTED_VOLATILE_GUEST *pCmd)
|
---|
[22834] | 4647 | {
|
---|
[27682] | 4648 | int rc = mOverlayImage.vhwaSurfaceUnlock(pCmd);
|
---|
[71651] | 4649 | VBoxVHWASurfaceBase *pVGA = mOverlayImage.vgaSurface();
|
---|
| 4650 | const VBoxVHWADirtyRect &rect = pVGA->getDirtyRect();
|
---|
[22846] | 4651 | mNeedOverlayRepaint = true;
|
---|
[71651] | 4652 | if (!rect.isClear())
|
---|
[22834] | 4653 | mMainDirtyRect.add(rect);
|
---|
| 4654 | return rc;
|
---|
| 4655 | }
|
---|
| 4656 |
|
---|
[71651] | 4657 | void VBoxQGLOverlay::vboxDoVHWACmdExec(void RT_UNTRUSTED_VOLATILE_GUEST *pvCmd, int /*VBOXVHWACMD_TYPE*/ enmCmdInt, bool fGuestCmd)
|
---|
[22816] | 4658 | {
|
---|
[71651] | 4659 | struct VBOXVHWACMD RT_UNTRUSTED_VOLATILE_GUEST *pCmd = (struct VBOXVHWACMD RT_UNTRUSTED_VOLATILE_GUEST *)pvCmd;
|
---|
| 4660 | VBOXVHWACMD_TYPE enmCmd = (VBOXVHWACMD_TYPE)enmCmdInt;
|
---|
| 4661 |
|
---|
[71626] | 4662 | switch (enmCmd)
|
---|
[22816] | 4663 | {
|
---|
| 4664 | case VBOXVHWACMD_TYPE_SURF_CANCREATE:
|
---|
| 4665 | {
|
---|
[71626] | 4666 | VBOXVHWACMD_SURF_CANCREATE RT_UNTRUSTED_VOLATILE_GUEST *pBody = VBOXVHWACMD_BODY(pCmd, VBOXVHWACMD_SURF_CANCREATE);
|
---|
[49420] | 4667 | Assert(!mGlOn == !mOverlayImage.hasSurfaces());
|
---|
[30394] | 4668 | initGl();
|
---|
[24471] | 4669 | makeCurrent();
|
---|
[27682] | 4670 | pCmd->rc = mOverlayImage.vhwaSurfaceCanCreate(pBody);
|
---|
[49420] | 4671 | Assert(!mGlOn == !mOverlayImage.hasSurfaces());
|
---|
[71651] | 4672 | break;
|
---|
| 4673 | }
|
---|
| 4674 |
|
---|
[22816] | 4675 | case VBOXVHWACMD_TYPE_SURF_CREATE:
|
---|
| 4676 | {
|
---|
[71594] | 4677 | VBOXVHWACMD_SURF_CREATE RT_UNTRUSTED_VOLATILE_GUEST *pBody = VBOXVHWACMD_BODY(pCmd, VBOXVHWACMD_SURF_CREATE);
|
---|
[49420] | 4678 | Assert(!mGlOn == !mOverlayImage.hasSurfaces());
|
---|
[30394] | 4679 | initGl();
|
---|
[24471] | 4680 | makeCurrent();
|
---|
[22816] | 4681 | vboxSetGlOn(true);
|
---|
[27682] | 4682 | pCmd->rc = mOverlayImage.vhwaSurfaceCreate(pBody);
|
---|
[71651] | 4683 | if (!mOverlayImage.hasSurfaces())
|
---|
[22816] | 4684 | {
|
---|
| 4685 | vboxSetGlOn(false);
|
---|
| 4686 | }
|
---|
| 4687 | else
|
---|
| 4688 | {
|
---|
[27682] | 4689 | mOverlayVisible = mOverlayImage.hasVisibleOverlays();
|
---|
[71651] | 4690 | if (mOverlayVisible)
|
---|
[22816] | 4691 | {
|
---|
[27682] | 4692 | mOverlayViewport = mOverlayImage.overlaysRectUnion();
|
---|
[22816] | 4693 | }
|
---|
| 4694 | vboxDoCheckUpdateViewport();
|
---|
[22846] | 4695 | mNeedOverlayRepaint = true;
|
---|
[22816] | 4696 | }
|
---|
[49420] | 4697 |
|
---|
| 4698 | Assert(!mGlOn == !mOverlayImage.hasSurfaces());
|
---|
[71651] | 4699 | break;
|
---|
| 4700 | }
|
---|
| 4701 |
|
---|
[22816] | 4702 | case VBOXVHWACMD_TYPE_SURF_DESTROY:
|
---|
| 4703 | {
|
---|
[71594] | 4704 | VBOXVHWACMD_SURF_DESTROY RT_UNTRUSTED_VOLATILE_GUEST *pBody = VBOXVHWACMD_BODY(pCmd, VBOXVHWACMD_SURF_DESTROY);
|
---|
[49420] | 4705 | Assert(!mGlOn == !mOverlayImage.hasSurfaces());
|
---|
[30394] | 4706 | initGl();
|
---|
[24471] | 4707 | makeCurrent();
|
---|
[27682] | 4708 | pCmd->rc = mOverlayImage.vhwaSurfaceDestroy(pBody);
|
---|
[71651] | 4709 | if (!mOverlayImage.hasSurfaces())
|
---|
[22816] | 4710 | {
|
---|
| 4711 | vboxSetGlOn(false);
|
---|
| 4712 | }
|
---|
| 4713 | else
|
---|
| 4714 | {
|
---|
[27682] | 4715 | mOverlayVisible = mOverlayImage.hasVisibleOverlays();
|
---|
[71651] | 4716 | if (mOverlayVisible)
|
---|
[22816] | 4717 | {
|
---|
[27682] | 4718 | mOverlayViewport = mOverlayImage.overlaysRectUnion();
|
---|
[22816] | 4719 | }
|
---|
| 4720 | vboxDoCheckUpdateViewport();
|
---|
[22846] | 4721 | mNeedOverlayRepaint = true;
|
---|
[22816] | 4722 | }
|
---|
[49420] | 4723 | Assert(!mGlOn == !mOverlayImage.hasSurfaces());
|
---|
[71651] | 4724 | break;
|
---|
| 4725 | }
|
---|
| 4726 |
|
---|
[22816] | 4727 | case VBOXVHWACMD_TYPE_SURF_LOCK:
|
---|
| 4728 | {
|
---|
[71594] | 4729 | VBOXVHWACMD_SURF_LOCK RT_UNTRUSTED_VOLATILE_GUEST *pBody = VBOXVHWACMD_BODY(pCmd, VBOXVHWACMD_SURF_LOCK);
|
---|
[49420] | 4730 | Assert(!mGlOn == !mOverlayImage.hasSurfaces());
|
---|
[30394] | 4731 | initGl();
|
---|
[24471] | 4732 | makeCurrent();
|
---|
[27682] | 4733 | pCmd->rc = mOverlayImage.vhwaSurfaceLock(pBody);
|
---|
[49420] | 4734 | Assert(!mGlOn == !mOverlayImage.hasSurfaces());
|
---|
[71651] | 4735 | break;
|
---|
| 4736 | }
|
---|
| 4737 |
|
---|
[22816] | 4738 | case VBOXVHWACMD_TYPE_SURF_UNLOCK:
|
---|
| 4739 | {
|
---|
[71594] | 4740 | VBOXVHWACMD_SURF_UNLOCK RT_UNTRUSTED_VOLATILE_GUEST *pBody = VBOXVHWACMD_BODY(pCmd, VBOXVHWACMD_SURF_UNLOCK);
|
---|
[49420] | 4741 | Assert(!mGlOn == !mOverlayImage.hasSurfaces());
|
---|
[30394] | 4742 | initGl();
|
---|
[24471] | 4743 | makeCurrent();
|
---|
[22834] | 4744 | pCmd->rc = vhwaSurfaceUnlock(pBody);
|
---|
[49420] | 4745 | Assert(!mGlOn == !mOverlayImage.hasSurfaces());
|
---|
[22852] | 4746 | /* mNeedOverlayRepaint is set inside the vhwaSurfaceUnlock */
|
---|
[71651] | 4747 | break;
|
---|
| 4748 | }
|
---|
| 4749 |
|
---|
[22816] | 4750 | case VBOXVHWACMD_TYPE_SURF_BLT:
|
---|
| 4751 | {
|
---|
[71594] | 4752 | VBOXVHWACMD_SURF_BLT RT_UNTRUSTED_VOLATILE_GUEST *pBody = VBOXVHWACMD_BODY(pCmd, VBOXVHWACMD_SURF_BLT);
|
---|
[49420] | 4753 | Assert(!mGlOn == !mOverlayImage.hasSurfaces());
|
---|
[30394] | 4754 | initGl();
|
---|
[24471] | 4755 | makeCurrent();
|
---|
[27682] | 4756 | pCmd->rc = mOverlayImage.vhwaSurfaceBlt(pBody);
|
---|
[22846] | 4757 | mNeedOverlayRepaint = true;
|
---|
[49420] | 4758 | Assert(!mGlOn == !mOverlayImage.hasSurfaces());
|
---|
[71651] | 4759 | break;
|
---|
| 4760 | }
|
---|
| 4761 |
|
---|
[22816] | 4762 | case VBOXVHWACMD_TYPE_SURF_FLIP:
|
---|
| 4763 | {
|
---|
[71594] | 4764 | VBOXVHWACMD_SURF_FLIP RT_UNTRUSTED_VOLATILE_GUEST *pBody = VBOXVHWACMD_BODY(pCmd, VBOXVHWACMD_SURF_FLIP);
|
---|
[49420] | 4765 | Assert(!mGlOn == !mOverlayImage.hasSurfaces());
|
---|
[30394] | 4766 | initGl();
|
---|
[24471] | 4767 | makeCurrent();
|
---|
[27682] | 4768 | pCmd->rc = mOverlayImage.vhwaSurfaceFlip(pBody);
|
---|
[22834] | 4769 | mNeedOverlayRepaint = true;
|
---|
[49420] | 4770 | Assert(!mGlOn == !mOverlayImage.hasSurfaces());
|
---|
[71651] | 4771 | break;
|
---|
| 4772 | }
|
---|
| 4773 |
|
---|
[22816] | 4774 | case VBOXVHWACMD_TYPE_SURF_OVERLAY_UPDATE:
|
---|
| 4775 | {
|
---|
[71594] | 4776 | VBOXVHWACMD_SURF_OVERLAY_UPDATE RT_UNTRUSTED_VOLATILE_GUEST *pBody = VBOXVHWACMD_BODY(pCmd, VBOXVHWACMD_SURF_OVERLAY_UPDATE);
|
---|
[49420] | 4777 | Assert(!mGlOn == !mOverlayImage.hasSurfaces());
|
---|
[30394] | 4778 | initGl();
|
---|
[24471] | 4779 | makeCurrent();
|
---|
[27682] | 4780 | pCmd->rc = mOverlayImage.vhwaSurfaceOverlayUpdate(pBody);
|
---|
| 4781 | mOverlayVisible = mOverlayImage.hasVisibleOverlays();
|
---|
[71651] | 4782 | if (mOverlayVisible)
|
---|
[22816] | 4783 | {
|
---|
[27682] | 4784 | mOverlayViewport = mOverlayImage.overlaysRectUnion();
|
---|
[22816] | 4785 | }
|
---|
| 4786 | vboxDoCheckUpdateViewport();
|
---|
[22846] | 4787 | mNeedOverlayRepaint = true;
|
---|
[49420] | 4788 | Assert(!mGlOn == !mOverlayImage.hasSurfaces());
|
---|
[71651] | 4789 | break;
|
---|
| 4790 | }
|
---|
| 4791 |
|
---|
[22816] | 4792 | case VBOXVHWACMD_TYPE_SURF_OVERLAY_SETPOSITION:
|
---|
| 4793 | {
|
---|
[71594] | 4794 | VBOXVHWACMD_SURF_OVERLAY_SETPOSITION RT_UNTRUSTED_VOLATILE_GUEST *pBody = VBOXVHWACMD_BODY(pCmd, VBOXVHWACMD_SURF_OVERLAY_SETPOSITION);
|
---|
[49420] | 4795 | Assert(!mGlOn == !mOverlayImage.hasSurfaces());
|
---|
[30394] | 4796 | initGl();
|
---|
[24471] | 4797 | makeCurrent();
|
---|
[27682] | 4798 | pCmd->rc = mOverlayImage.vhwaSurfaceOverlaySetPosition(pBody);
|
---|
| 4799 | mOverlayVisible = mOverlayImage.hasVisibleOverlays();
|
---|
[71651] | 4800 | if (mOverlayVisible)
|
---|
[22816] | 4801 | {
|
---|
[27682] | 4802 | mOverlayViewport = mOverlayImage.overlaysRectUnion();
|
---|
[22816] | 4803 | }
|
---|
| 4804 | vboxDoCheckUpdateViewport();
|
---|
[22846] | 4805 | mNeedOverlayRepaint = true;
|
---|
[49420] | 4806 | Assert(!mGlOn == !mOverlayImage.hasSurfaces());
|
---|
[71651] | 4807 | break;
|
---|
| 4808 | }
|
---|
| 4809 |
|
---|
[32823] | 4810 | #ifdef VBOX_WITH_WDDM
|
---|
| 4811 | case VBOXVHWACMD_TYPE_SURF_COLORFILL:
|
---|
| 4812 | {
|
---|
[71594] | 4813 | VBOXVHWACMD_SURF_COLORFILL RT_UNTRUSTED_VOLATILE_GUEST *pBody = VBOXVHWACMD_BODY(pCmd, VBOXVHWACMD_SURF_COLORFILL);
|
---|
[49420] | 4814 | Assert(!mGlOn == !mOverlayImage.hasSurfaces());
|
---|
[32823] | 4815 | initGl();
|
---|
| 4816 | makeCurrent();
|
---|
| 4817 | pCmd->rc = mOverlayImage.vhwaSurfaceColorFill(pBody);
|
---|
| 4818 | mNeedOverlayRepaint = true;
|
---|
[49420] | 4819 | Assert(!mGlOn == !mOverlayImage.hasSurfaces());
|
---|
[71651] | 4820 | break;
|
---|
| 4821 | }
|
---|
[32823] | 4822 | #endif
|
---|
[22816] | 4823 | case VBOXVHWACMD_TYPE_SURF_COLORKEY_SET:
|
---|
| 4824 | {
|
---|
[71594] | 4825 | VBOXVHWACMD_SURF_COLORKEY_SET RT_UNTRUSTED_VOLATILE_GUEST *pBody = VBOXVHWACMD_BODY(pCmd, VBOXVHWACMD_SURF_COLORKEY_SET);
|
---|
[49420] | 4826 | Assert(!mGlOn == !mOverlayImage.hasSurfaces());
|
---|
[30394] | 4827 | initGl();
|
---|
[24471] | 4828 | makeCurrent();
|
---|
[27682] | 4829 | pCmd->rc = mOverlayImage.vhwaSurfaceColorkeySet(pBody);
|
---|
[25242] | 4830 | /* this is here to ensure we have color key changes picked up */
|
---|
| 4831 | vboxDoCheckUpdateViewport();
|
---|
[22852] | 4832 | mNeedOverlayRepaint = true;
|
---|
[49420] | 4833 | Assert(!mGlOn == !mOverlayImage.hasSurfaces());
|
---|
[71651] | 4834 | break;
|
---|
| 4835 | }
|
---|
| 4836 |
|
---|
[22816] | 4837 | case VBOXVHWACMD_TYPE_QUERY_INFO1:
|
---|
| 4838 | {
|
---|
[71594] | 4839 | VBOXVHWACMD_QUERYINFO1 RT_UNTRUSTED_VOLATILE_GUEST *pBody = VBOXVHWACMD_BODY(pCmd, VBOXVHWACMD_QUERYINFO1);
|
---|
[49420] | 4840 | Assert(!mGlOn == !mOverlayImage.hasSurfaces());
|
---|
[24471] | 4841 | initGl();
|
---|
| 4842 | makeCurrent();
|
---|
[27682] | 4843 | pCmd->rc = mOverlayImage.vhwaQueryInfo1(pBody);
|
---|
[49420] | 4844 | Assert(!mGlOn == !mOverlayImage.hasSurfaces());
|
---|
[71651] | 4845 | break;
|
---|
| 4846 | }
|
---|
| 4847 |
|
---|
[22816] | 4848 | case VBOXVHWACMD_TYPE_QUERY_INFO2:
|
---|
| 4849 | {
|
---|
[71594] | 4850 | VBOXVHWACMD_QUERYINFO2 RT_UNTRUSTED_VOLATILE_GUEST *pBody = VBOXVHWACMD_BODY(pCmd, VBOXVHWACMD_QUERYINFO2);
|
---|
[49420] | 4851 | Assert(!mGlOn == !mOverlayImage.hasSurfaces());
|
---|
[30394] | 4852 | initGl();
|
---|
[24471] | 4853 | makeCurrent();
|
---|
[27682] | 4854 | pCmd->rc = mOverlayImage.vhwaQueryInfo2(pBody);
|
---|
[49420] | 4855 | Assert(!mGlOn == !mOverlayImage.hasSurfaces());
|
---|
[71651] | 4856 | break;
|
---|
| 4857 | }
|
---|
| 4858 |
|
---|
[22816] | 4859 | case VBOXVHWACMD_TYPE_ENABLE:
|
---|
[49420] | 4860 | Assert(!mGlOn == !mOverlayImage.hasSurfaces());
|
---|
[26509] | 4861 | initGl();
|
---|
[49420] | 4862 | Assert(!mGlOn == !mOverlayImage.hasSurfaces());
|
---|
[65653] | 4863 | pCmd->rc = VINF_SUCCESS;
|
---|
| 4864 | break;
|
---|
[71651] | 4865 |
|
---|
[22816] | 4866 | case VBOXVHWACMD_TYPE_DISABLE:
|
---|
| 4867 | pCmd->rc = VINF_SUCCESS;
|
---|
| 4868 | break;
|
---|
[71651] | 4869 |
|
---|
[22816] | 4870 | case VBOXVHWACMD_TYPE_HH_CONSTRUCT:
|
---|
| 4871 | {
|
---|
[71651] | 4872 | ASSERT_GUEST_STMT_RETURN_VOID(!fGuestCmd, pCmd->rc = VERR_ACCESS_DENIED);
|
---|
[71594] | 4873 | VBOXVHWACMD_HH_CONSTRUCT *pBody = VBOXVHWACMD_BODY_HOST_HEAP(pCmd, VBOXVHWACMD_HH_CONSTRUCT);
|
---|
[49420] | 4874 | Assert(!mGlOn == !mOverlayImage.hasSurfaces());
|
---|
[22816] | 4875 | pCmd->rc = vhwaConstruct(pBody);
|
---|
[49420] | 4876 | Assert(!mGlOn == !mOverlayImage.hasSurfaces());
|
---|
[71651] | 4877 | break;
|
---|
| 4878 | }
|
---|
| 4879 |
|
---|
[32622] | 4880 | #ifdef VBOX_WITH_WDDM
|
---|
[29922] | 4881 | case VBOXVHWACMD_TYPE_SURF_GETINFO:
|
---|
| 4882 | {
|
---|
[71594] | 4883 | VBOXVHWACMD_SURF_GETINFO RT_UNTRUSTED_VOLATILE_GUEST *pBody = VBOXVHWACMD_BODY(pCmd, VBOXVHWACMD_SURF_GETINFO);
|
---|
[49420] | 4884 | Assert(!mGlOn == !mOverlayImage.hasSurfaces());
|
---|
[29922] | 4885 | pCmd->rc = mOverlayImage.vhwaSurfaceGetInfo(pBody);
|
---|
[49420] | 4886 | Assert(!mGlOn == !mOverlayImage.hasSurfaces());
|
---|
[71651] | 4887 | break;
|
---|
| 4888 | }
|
---|
[29922] | 4889 | #endif
|
---|
[71651] | 4890 |
|
---|
[22816] | 4891 | default:
|
---|
[49940] | 4892 | AssertFailed();
|
---|
[22816] | 4893 | pCmd->rc = VERR_NOT_IMPLEMENTED;
|
---|
| 4894 | break;
|
---|
| 4895 | }
|
---|
| 4896 | }
|
---|
| 4897 |
|
---|
[34523] | 4898 | #if 0
|
---|
[22816] | 4899 | static DECLCALLBACK(void) vboxQGLOverlaySaveExec(PSSMHANDLE pSSM, void *pvUser)
|
---|
| 4900 | {
|
---|
| 4901 | VBoxQGLOverlay * fb = (VBoxQGLOverlay*)pvUser;
|
---|
| 4902 | fb->vhwaSaveExec(pSSM);
|
---|
| 4903 | }
|
---|
[34523] | 4904 | #endif
|
---|
[22816] | 4905 |
|
---|
| 4906 | static DECLCALLBACK(int) vboxQGLOverlayLoadExec(PSSMHANDLE pSSM, void *pvUser, uint32_t u32Version, uint32_t uPass)
|
---|
| 4907 | {
|
---|
| 4908 | Assert(uPass == SSM_PASS_FINAL); NOREF(uPass);
|
---|
[71651] | 4909 | VBoxQGLOverlay *fb = (VBoxQGLOverlay *)pvUser;
|
---|
[22816] | 4910 | return fb->vhwaLoadExec(pSSM, u32Version);
|
---|
| 4911 | }
|
---|
| 4912 |
|
---|
[71651] | 4913 | int VBoxQGLOverlay::vhwaLoadExec(struct SSMHANDLE *pSSM, uint32_t u32Version)
|
---|
[22816] | 4914 | {
|
---|
[34129] | 4915 | int rc = VBoxVHWAImage::vhwaLoadExec(&mOnResizeCmdList, pSSM, u32Version);
|
---|
| 4916 | AssertRC(rc);
|
---|
| 4917 | if (RT_SUCCESS(rc))
|
---|
| 4918 | {
|
---|
[34141] | 4919 | if (u32Version >= VBOXQGL_STATE_VERSION_PIPESAVED)
|
---|
| 4920 | {
|
---|
| 4921 | rc = mCmdPipe.loadExec(pSSM, u32Version, mOverlayImage.vramBase());
|
---|
| 4922 | AssertRC(rc);
|
---|
| 4923 | }
|
---|
[34129] | 4924 | }
|
---|
| 4925 | return rc;
|
---|
[22816] | 4926 | }
|
---|
| 4927 |
|
---|
[71651] | 4928 | void VBoxQGLOverlay::vhwaSaveExec(struct SSMHANDLE *pSSM)
|
---|
[22816] | 4929 | {
|
---|
[27682] | 4930 | mOverlayImage.vhwaSaveExec(pSSM);
|
---|
[34129] | 4931 | mCmdPipe.saveExec(pSSM, mOverlayImage.vramBase());
|
---|
[22816] | 4932 | }
|
---|
| 4933 |
|
---|
[34490] | 4934 | int VBoxQGLOverlay::vhwaConstruct(struct VBOXVHWACMD_HH_CONSTRUCT *pCmd)
|
---|
[22816] | 4935 | {
|
---|
[44347] | 4936 | PUVM pUVM = VMR3GetUVM((PVM)pCmd->pVM);
|
---|
[27839] | 4937 | uint32_t intsId = m_id;
|
---|
[22816] | 4938 |
|
---|
| 4939 | char nameFuf[sizeof(VBOXQGL_STATE_NAMEBASE) + 8];
|
---|
| 4940 |
|
---|
| 4941 | char * pszName = nameFuf;
|
---|
| 4942 | sprintf(pszName, "%s%d", VBOXQGL_STATE_NAMEBASE, intsId);
|
---|
[71651] | 4943 | int rc = SSMR3RegisterExternal(pUVM, /* The VM handle*/
|
---|
| 4944 | pszName, /* Data unit name. */
|
---|
| 4945 | intsId, /* The instance identifier of the data unit.
|
---|
| 4946 | * This must together with the name be unique. */
|
---|
| 4947 | VBOXQGL_STATE_VERSION, /* Data layout version number. */
|
---|
| 4948 | 128, /* The approximate amount of data in the unit.
|
---|
| 4949 | * Only for progress indicators. */
|
---|
| 4950 | NULL, NULL, NULL, /* pfnLiveXxx */
|
---|
| 4951 | NULL, /* Prepare save callback, optional. */
|
---|
| 4952 | NULL, //vboxQGLOverlaySaveExec, /* Execute save callback, optional. */
|
---|
| 4953 | NULL, /* Done save callback, optional. */
|
---|
| 4954 | NULL, /* Prepare load callback, optional. */
|
---|
| 4955 | vboxQGLOverlayLoadExec, /* Execute load callback, optional. */
|
---|
| 4956 | NULL, /* Done load callback, optional. */
|
---|
| 4957 | this /* User argument. */
|
---|
| 4958 | );
|
---|
[25226] | 4959 | AssertRC(rc);
|
---|
[27682] | 4960 | if (RT_SUCCESS(rc))
|
---|
| 4961 | {
|
---|
| 4962 | rc = mOverlayImage.vhwaConstruct(pCmd);
|
---|
| 4963 | AssertRC(rc);
|
---|
| 4964 | }
|
---|
[22816] | 4965 | return rc;
|
---|
| 4966 | }
|
---|
| 4967 |
|
---|
[49420] | 4968 | void VBoxQGLOverlay::processCmd(VBoxVHWACommandElement * pCmd)
|
---|
[22816] | 4969 | {
|
---|
[49420] | 4970 | switch(pCmd->type())
|
---|
[22816] | 4971 | {
|
---|
| 4972 | case VBOXVHWA_PIPECMD_PAINT:
|
---|
[22834] | 4973 | addMainDirtyRect(pCmd->rect());
|
---|
[22816] | 4974 | break;
|
---|
[71651] | 4975 |
|
---|
[22816] | 4976 | #ifdef VBOX_WITH_VIDEOHWACCEL
|
---|
| 4977 | case VBOXVHWA_PIPECMD_VHWA:
|
---|
[71651] | 4978 | vboxDoVHWACmd(pCmd->vhwaCmdPtr(), pCmd->vhwaCmdType(), pCmd->vhwaIsGuestCmd());
|
---|
[22816] | 4979 | break;
|
---|
[71651] | 4980 |
|
---|
[22816] | 4981 | case VBOXVHWA_PIPECMD_FUNC:
|
---|
| 4982 | {
|
---|
| 4983 | const VBOXVHWAFUNCCALLBACKINFO & info = pCmd->func();
|
---|
| 4984 | info.pfnCallback(info.pContext1, info.pContext2);
|
---|
| 4985 | break;
|
---|
| 4986 | }
|
---|
| 4987 | #endif
|
---|
| 4988 | default:
|
---|
[49940] | 4989 | AssertFailed();
|
---|
[49420] | 4990 | }
|
---|
[22816] | 4991 | }
|
---|
| 4992 |
|
---|
[71651] | 4993 | VBoxVHWACommandElementProcessor::VBoxVHWACommandElementProcessor()
|
---|
| 4994 | : m_pNotifyObject(NULL)
|
---|
| 4995 | , mpCurCmd(NULL)
|
---|
| 4996 | , mbResetting(false)
|
---|
| 4997 | , mcDisabled(0)
|
---|
[22816] | 4998 | {
|
---|
| 4999 | int rc = RTCritSectInit(&mCritSect);
|
---|
| 5000 | AssertRC(rc);
|
---|
| 5001 |
|
---|
[49420] | 5002 | RTListInit(&mCommandList);
|
---|
[49940] | 5003 |
|
---|
| 5004 | m_pCmdEntryCache = new VBoxVHWAEntriesCache;
|
---|
[22816] | 5005 | }
|
---|
| 5006 |
|
---|
[52086] | 5007 | void VBoxVHWACommandElementProcessor::init(QObject *pNotifyObject)
|
---|
| 5008 | {
|
---|
| 5009 | m_pNotifyObject = pNotifyObject;
|
---|
| 5010 | }
|
---|
| 5011 |
|
---|
[22816] | 5012 | VBoxVHWACommandElementProcessor::~VBoxVHWACommandElementProcessor()
|
---|
| 5013 | {
|
---|
[27757] | 5014 | Assert(!m_NotifyObjectRefs.refs());
|
---|
[49420] | 5015 | RTListIsEmpty(&mCommandList);
|
---|
| 5016 |
|
---|
[22816] | 5017 | RTCritSectDelete(&mCritSect);
|
---|
[49940] | 5018 |
|
---|
| 5019 | delete m_pCmdEntryCache;
|
---|
[22816] | 5020 | }
|
---|
| 5021 |
|
---|
[71651] | 5022 | void VBoxVHWACommandElementProcessor::postCmd(VBOXVHWA_PIPECMD_TYPE aType, void *pvData,
|
---|
| 5023 | int /*VBOXVHWACMD_TYPE*/ enmCmd, bool fGuestCmd)
|
---|
[22816] | 5024 | {
|
---|
[49420] | 5025 | QObject *pNotifyObject = NULL;
|
---|
[22836] | 5026 |
|
---|
[49420] | 5027 | Log(("VHWA post %d %#p\n", aType, pvData));
|
---|
| 5028 |
|
---|
[22816] | 5029 | /* 1. lock*/
|
---|
| 5030 | RTCritSectEnter(&mCritSect);
|
---|
[49420] | 5031 |
|
---|
[71651] | 5032 | VBoxVHWACommandElement *pCmd = m_pCmdEntryCache->alloc();
|
---|
| 5033 | if (!pCmd)
|
---|
[22816] | 5034 | {
|
---|
| 5035 | VBOXQGLLOG(("!!!no more free elements!!!\n"));
|
---|
| 5036 | #ifdef VBOXQGL_PROF_BASE
|
---|
| 5037 | RTCritSectLeave(&mCritSect);
|
---|
| 5038 | return;
|
---|
| 5039 | #else
|
---|
[63567] | 5040 | /// @todo
|
---|
[22816] | 5041 | #endif
|
---|
| 5042 | }
|
---|
[71651] | 5043 | pCmd->setData(aType, pvData, enmCmd, fGuestCmd);
|
---|
[22836] | 5044 |
|
---|
[22816] | 5045 | /* 2. if can add to current*/
|
---|
[27777] | 5046 | if (m_pNotifyObject)
|
---|
| 5047 | {
|
---|
[49420] | 5048 | m_NotifyObjectRefs.inc(); /* ensure the parent does not get destroyed while we are using it */
|
---|
| 5049 | pNotifyObject = m_pNotifyObject;
|
---|
[27777] | 5050 | }
|
---|
[27720] | 5051 |
|
---|
[49420] | 5052 | RTListAppend(&mCommandList, &pCmd->ListNode);
|
---|
[27720] | 5053 |
|
---|
[22816] | 5054 | RTCritSectLeave(&mCritSect);
|
---|
[22836] | 5055 |
|
---|
[27757] | 5056 | if (pNotifyObject)
|
---|
[27720] | 5057 | {
|
---|
| 5058 | VBoxVHWACommandProcessEvent *pCurrentEvent = new VBoxVHWACommandProcessEvent();
|
---|
[71651] | 5059 | QApplication::postEvent(pNotifyObject, pCurrentEvent);
|
---|
[27757] | 5060 | m_NotifyObjectRefs.dec();
|
---|
[27720] | 5061 | }
|
---|
| 5062 | }
|
---|
| 5063 |
|
---|
[27757] | 5064 | void VBoxVHWACommandElementProcessor::setNotifyObject(QObject *pNotifyObject)
|
---|
[27720] | 5065 | {
|
---|
| 5066 | int cEventsNeeded = 0;
|
---|
| 5067 | RTCritSectEnter(&mCritSect);
|
---|
[27757] | 5068 | if (m_pNotifyObject == pNotifyObject)
|
---|
| 5069 | {
|
---|
| 5070 | RTCritSectLeave(&mCritSect);
|
---|
| 5071 | return;
|
---|
| 5072 | }
|
---|
[27720] | 5073 |
|
---|
[27757] | 5074 | if (m_pNotifyObject)
|
---|
[22816] | 5075 | {
|
---|
[27757] | 5076 | m_pNotifyObject = NULL;
|
---|
| 5077 | RTCritSectLeave(&mCritSect);
|
---|
| 5078 |
|
---|
| 5079 | m_NotifyObjectRefs.wait0();
|
---|
| 5080 |
|
---|
| 5081 | RTCritSectEnter(&mCritSect);
|
---|
[22816] | 5082 | }
|
---|
[27757] | 5083 | else
|
---|
| 5084 | {
|
---|
| 5085 | /* NULL can not be references */
|
---|
[71651] | 5086 | Assert(!m_NotifyObjectRefs.refs());
|
---|
[27757] | 5087 | }
|
---|
| 5088 |
|
---|
| 5089 | if (pNotifyObject)
|
---|
| 5090 | {
|
---|
| 5091 | m_pNotifyObject = pNotifyObject;
|
---|
| 5092 |
|
---|
[49420] | 5093 | VBoxVHWACommandElement *pCur;
|
---|
[49485] | 5094 | RTListForEachCpp(&mCommandList, pCur, VBoxVHWACommandElement, ListNode)
|
---|
[27757] | 5095 | {
|
---|
[49420] | 5096 | ++cEventsNeeded;
|
---|
[27757] | 5097 | }
|
---|
| 5098 |
|
---|
| 5099 | if (cEventsNeeded)
|
---|
| 5100 | m_NotifyObjectRefs.inc();
|
---|
| 5101 | }
|
---|
| 5102 | else
|
---|
| 5103 | {
|
---|
| 5104 | /* should be zeroed already */
|
---|
| 5105 | Assert(!m_pNotifyObject);
|
---|
| 5106 | }
|
---|
| 5107 |
|
---|
[27720] | 5108 | RTCritSectLeave(&mCritSect);
|
---|
| 5109 |
|
---|
[27757] | 5110 | if (cEventsNeeded)
|
---|
[22816] | 5111 | {
|
---|
[27757] | 5112 | /* cEventsNeeded can only be != 0 if pNotifyObject is valid */
|
---|
[71651] | 5113 | Assert(pNotifyObject);
|
---|
[27724] | 5114 | for (int i = 0; i < cEventsNeeded; ++i)
|
---|
| 5115 | {
|
---|
| 5116 | VBoxVHWACommandProcessEvent *pCurrentEvent = new VBoxVHWACommandProcessEvent();
|
---|
[27757] | 5117 | QApplication::postEvent(pNotifyObject, pCurrentEvent);
|
---|
[27724] | 5118 | }
|
---|
[27757] | 5119 | m_NotifyObjectRefs.dec();
|
---|
[22816] | 5120 | }
|
---|
| 5121 | }
|
---|
| 5122 |
|
---|
[49420] | 5123 | void VBoxVHWACommandElementProcessor::doneCmd()
|
---|
[22816] | 5124 | {
|
---|
[71651] | 5125 | VBoxVHWACommandElement *pEl;
|
---|
[22816] | 5126 | RTCritSectEnter(&mCritSect);
|
---|
[49420] | 5127 | pEl = mpCurCmd;
|
---|
| 5128 | Assert(mpCurCmd);
|
---|
| 5129 | mpCurCmd = NULL;
|
---|
| 5130 | RTCritSectLeave(&mCritSect);
|
---|
| 5131 |
|
---|
| 5132 | if (pEl)
|
---|
[49940] | 5133 | m_pCmdEntryCache->free(pEl);
|
---|
[49420] | 5134 | }
|
---|
| 5135 |
|
---|
[71651] | 5136 | VBoxVHWACommandElement *VBoxVHWACommandElementProcessor::getCmd()
|
---|
[49420] | 5137 | {
|
---|
[71651] | 5138 | VBoxVHWACommandElement *pEl = NULL;
|
---|
[49420] | 5139 | RTCritSectEnter(&mCritSect);
|
---|
| 5140 |
|
---|
| 5141 | Assert(!mpCurCmd);
|
---|
| 5142 |
|
---|
| 5143 | if (mbResetting)
|
---|
[22816] | 5144 | {
|
---|
[49425] | 5145 | RTCritSectLeave(&mCritSect);
|
---|
[49420] | 5146 | return NULL;
|
---|
[22816] | 5147 | }
|
---|
[27777] | 5148 |
|
---|
[49420] | 5149 | if (mcDisabled)
|
---|
[34140] | 5150 | {
|
---|
[71651] | 5151 | QObject *pNotifyObject = NULL;
|
---|
[27777] | 5152 |
|
---|
[49420] | 5153 | if (!RTListIsEmpty(&mCommandList))
|
---|
[34140] | 5154 | {
|
---|
| 5155 | Assert(m_pNotifyObject);
|
---|
| 5156 | if (m_pNotifyObject)
|
---|
| 5157 | {
|
---|
| 5158 | m_NotifyObjectRefs.inc(); /* ensure the parent does not get destroyed while we are using it */
|
---|
| 5159 | pNotifyObject = m_pNotifyObject;
|
---|
| 5160 | }
|
---|
| 5161 | }
|
---|
[49420] | 5162 |
|
---|
| 5163 | RTCritSectLeave(&mCritSect);
|
---|
| 5164 |
|
---|
| 5165 | if (pNotifyObject)
|
---|
| 5166 | {
|
---|
| 5167 | VBoxVHWACommandProcessEvent *pCurrentEvent = new VBoxVHWACommandProcessEvent();
|
---|
| 5168 | QApplication::postEvent(pNotifyObject, pCurrentEvent);
|
---|
| 5169 | m_NotifyObjectRefs.dec();
|
---|
| 5170 | }
|
---|
| 5171 | return NULL;
|
---|
[27720] | 5172 | }
|
---|
[24162] | 5173 |
|
---|
[49485] | 5174 | pEl = RTListGetFirstCpp(&mCommandList, VBoxVHWACommandElement, ListNode);
|
---|
[49420] | 5175 | if (pEl)
|
---|
| 5176 | {
|
---|
| 5177 | RTListNodeRemove(&pEl->ListNode);
|
---|
| 5178 | mpCurCmd = pEl;
|
---|
| 5179 | }
|
---|
| 5180 |
|
---|
[22816] | 5181 | RTCritSectLeave(&mCritSect);
|
---|
[34140] | 5182 |
|
---|
[49420] | 5183 | return pEl;
|
---|
[24162] | 5184 | }
|
---|
[22816] | 5185 |
|
---|
[24162] | 5186 | /* it is currently assumed no one sends any new commands while reset is in progress */
|
---|
[49420] | 5187 | void VBoxVHWACommandElementProcessor::reset(CDisplay *pDisplay)
|
---|
[24162] | 5188 | {
|
---|
| 5189 | RTCritSectEnter(&mCritSect);
|
---|
| 5190 |
|
---|
[49420] | 5191 | mbResetting = true;
|
---|
[27720] | 5192 |
|
---|
[71651] | 5193 | if (mpCurCmd)
|
---|
[24162] | 5194 | {
|
---|
[71651] | 5195 | for (;;)
|
---|
[24162] | 5196 | {
|
---|
| 5197 | RTCritSectLeave(&mCritSect);
|
---|
[49433] | 5198 | RTThreadSleep(2); /* 2 ms */
|
---|
[24162] | 5199 | RTCritSectEnter(&mCritSect);
|
---|
| 5200 | /* it is assumed no one sends any new commands while reset is in progress */
|
---|
[71651] | 5201 | if (!mpCurCmd)
|
---|
[24162] | 5202 | {
|
---|
| 5203 | break;
|
---|
| 5204 | }
|
---|
| 5205 | }
|
---|
| 5206 | }
|
---|
| 5207 |
|
---|
[49420] | 5208 | RTCritSectLeave(&mCritSect);
|
---|
[27777] | 5209 |
|
---|
[71651] | 5210 | VBoxVHWACommandElement *pCur, *pNext;
|
---|
[49485] | 5211 | RTListForEachSafeCpp(&mCommandList, pCur, pNext, VBoxVHWACommandElement, ListNode)
|
---|
[49420] | 5212 | {
|
---|
[71651] | 5213 | switch (pCur->type())
|
---|
[49420] | 5214 | {
|
---|
| 5215 | #ifdef VBOX_WITH_VIDEOHWACCEL
|
---|
[71651] | 5216 | case VBOXVHWA_PIPECMD_VHWA:
|
---|
| 5217 | {
|
---|
| 5218 | struct VBOXVHWACMD RT_UNTRUSTED_VOLATILE_GUEST *pCmd = pCur->vhwaCmdPtr();
|
---|
| 5219 | pCmd->rc = VERR_INVALID_STATE;
|
---|
| 5220 | Log(("VHWA Command <<< Async RESET %#p, %d\n", pCmd, pCmd->enmCmd));
|
---|
| 5221 | pDisplay->CompleteVHWACommand((BYTE *)pCmd);
|
---|
| 5222 | }
|
---|
| 5223 | break;
|
---|
| 5224 |
|
---|
| 5225 | case VBOXVHWA_PIPECMD_FUNC:
|
---|
| 5226 | /* should not happen, don't handle this for now */
|
---|
| 5227 | AssertFailed();
|
---|
| 5228 | break;
|
---|
[49420] | 5229 | #endif
|
---|
[71651] | 5230 | case VBOXVHWA_PIPECMD_PAINT:
|
---|
| 5231 | break;
|
---|
| 5232 |
|
---|
| 5233 | default:
|
---|
| 5234 | /* should not happen, don't handle this for now */
|
---|
| 5235 | AssertFailed();
|
---|
| 5236 | break;
|
---|
[49420] | 5237 | }
|
---|
[27720] | 5238 |
|
---|
[49420] | 5239 | RTListNodeRemove(&pCur->ListNode);
|
---|
[49940] | 5240 | m_pCmdEntryCache->free(pCur);
|
---|
[49420] | 5241 | }
|
---|
[49430] | 5242 |
|
---|
| 5243 | RTCritSectEnter(&mCritSect);
|
---|
| 5244 |
|
---|
| 5245 | mbResetting = false;
|
---|
| 5246 |
|
---|
| 5247 | RTCritSectLeave(&mCritSect);
|
---|
[22816] | 5248 | }
|
---|
| 5249 |
|
---|
[71651] | 5250 | #define VBOXVHWACOMMANDELEMENTLISTBEGIN_MAGIC UINT32_C(0x89abcdef)
|
---|
| 5251 | #define VBOXVHWACOMMANDELEMENTLISTEND_MAGIC UINT32_C(0xfedcba98)
|
---|
[34129] | 5252 |
|
---|
[71651] | 5253 | int VBoxVHWACommandElementProcessor::loadExec(struct SSMHANDLE *pSSM, uint32_t u32Version, void *pvVRAM)
|
---|
[34129] | 5254 | {
|
---|
| 5255 | uint32_t u32;
|
---|
[34276] | 5256 |
|
---|
| 5257 | Q_UNUSED(u32Version);
|
---|
| 5258 |
|
---|
[71651] | 5259 | int rc = SSMR3GetU32(pSSM, &u32);
|
---|
| 5260 | AssertRCReturn(rc, rc);
|
---|
| 5261 | AssertReturn(u32 == VBOXVHWACOMMANDELEMENTLISTBEGIN_MAGIC, VERR_INVALID_MAGIC);
|
---|
| 5262 |
|
---|
| 5263 | SSMR3GetU32(pSSM, &u32);
|
---|
| 5264 | bool b;
|
---|
| 5265 | rc = SSMR3GetBool(pSSM, &b);
|
---|
| 5266 | AssertRCReturn(rc, rc);
|
---|
| 5267 |
|
---|
| 5268 | // m_NotifyObjectRefs = VBoxVHWARefCounter(u32);
|
---|
| 5269 | bool fContinue = true;
|
---|
| 5270 | do
|
---|
[34129] | 5271 | {
|
---|
[71651] | 5272 | rc = SSMR3GetU32(pSSM, &u32);
|
---|
| 5273 | AssertRCReturn(rc, rc);
|
---|
| 5274 |
|
---|
| 5275 | bool fNewEvent;
|
---|
| 5276 | switch (u32)
|
---|
[34129] | 5277 | {
|
---|
[71651] | 5278 | case VBOXVHWA_PIPECMD_PAINT:
|
---|
[34129] | 5279 | {
|
---|
[71651] | 5280 | int x,y,w,h;
|
---|
| 5281 | rc = SSMR3GetS32(pSSM, &x);
|
---|
| 5282 | rc = SSMR3GetS32(pSSM, &y);
|
---|
| 5283 | rc = SSMR3GetS32(pSSM, &w);
|
---|
| 5284 | rc = SSMR3GetS32(pSSM, &h);
|
---|
| 5285 | rc = SSMR3GetBool(pSSM, &fNewEvent);
|
---|
| 5286 | AssertRCReturn(rc, rc);
|
---|
[34129] | 5287 |
|
---|
[71651] | 5288 | QRect r = QRect(x, y, w, h);
|
---|
| 5289 | postCmd(VBOXVHWA_PIPECMD_PAINT, &r, -1, false);
|
---|
| 5290 | break;
|
---|
| 5291 | }
|
---|
[34129] | 5292 |
|
---|
[71651] | 5293 | case VBOXVHWA_PIPECMD_VHWA:
|
---|
| 5294 | {
|
---|
| 5295 | uint32_t offCmd;
|
---|
| 5296 | rc = SSMR3GetU32(pSSM, &offCmd);
|
---|
| 5297 | rc = SSMR3GetBool(pSSM, &fNewEvent);
|
---|
| 5298 | AssertRCReturn(rc, rc);
|
---|
[34129] | 5299 |
|
---|
[71651] | 5300 | VBOXVHWACMD *pCmd = (VBOXVHWACMD *)(((uint8_t *)pvVRAM) + offCmd);
|
---|
| 5301 | postCmd(VBOXVHWA_PIPECMD_VHWA, pCmd, pCmd->enmCmd, true);
|
---|
| 5302 | break;
|
---|
| 5303 | }
|
---|
[34129] | 5304 |
|
---|
[71651] | 5305 | case VBOXVHWACOMMANDELEMENTLISTEND_MAGIC:
|
---|
| 5306 | fContinue = false;
|
---|
| 5307 | break;
|
---|
[34129] | 5308 |
|
---|
[71651] | 5309 | default:
|
---|
| 5310 | AssertLogRelMsgFailed(("u32=%#x\n", u32));
|
---|
| 5311 | break;
|
---|
[34129] | 5312 | }
|
---|
| 5313 |
|
---|
[71651] | 5314 | } while (fContinue && RT_SUCCESS(rc));
|
---|
| 5315 |
|
---|
[34129] | 5316 | return rc;
|
---|
| 5317 | }
|
---|
| 5318 |
|
---|
[71651] | 5319 | void VBoxVHWACommandElementProcessor::saveExec(struct SSMHANDLE *pSSM, void *pvVRAM)
|
---|
[34129] | 5320 | {
|
---|
| 5321 | int rc;
|
---|
| 5322 |
|
---|
[71651] | 5323 | rc = SSMR3PutU32(pSSM, VBOXVHWACOMMANDELEMENTLISTBEGIN_MAGIC);
|
---|
| 5324 | rc = SSMR3PutU32(pSSM, m_NotifyObjectRefs.refs());
|
---|
| 5325 | rc = SSMR3PutBool(pSSM, true);
|
---|
| 5326 | AssertRC(rc);
|
---|
[34129] | 5327 |
|
---|
[49420] | 5328 | VBoxVHWACommandElement *pCur;
|
---|
[49485] | 5329 | RTListForEachCpp(&mCommandList, pCur, VBoxVHWACommandElement, ListNode)
|
---|
[34129] | 5330 | {
|
---|
| 5331 |
|
---|
| 5332 | switch (pCur->type())
|
---|
| 5333 | {
|
---|
| 5334 | case VBOXVHWA_PIPECMD_PAINT:
|
---|
[71651] | 5335 | rc = SSMR3PutU32(pSSM, pCur->type());
|
---|
| 5336 | rc = SSMR3PutS32(pSSM, pCur->rect().x());
|
---|
| 5337 | rc = SSMR3PutS32(pSSM, pCur->rect().y());
|
---|
| 5338 | rc = SSMR3PutS32(pSSM, pCur->rect().width());
|
---|
| 5339 | rc = SSMR3PutS32(pSSM, pCur->rect().height());
|
---|
| 5340 | rc = SSMR3PutBool(pSSM, true);
|
---|
| 5341 | AssertRC(rc);
|
---|
[34129] | 5342 | break;
|
---|
[71651] | 5343 |
|
---|
[34129] | 5344 | case VBOXVHWA_PIPECMD_VHWA:
|
---|
[71651] | 5345 | if (pCur->vhwaIsGuestCmd())
|
---|
| 5346 | {
|
---|
| 5347 | rc = SSMR3PutU32(pSSM, pCur->type());
|
---|
| 5348 | rc = SSMR3PutU32(pSSM, (uint32_t)(uintptr_t)pCur->vhwaCmdPtr() - (uintptr_t)pvVRAM);
|
---|
| 5349 | rc = SSMR3PutBool(pSSM, true);
|
---|
| 5350 | AssertRC(rc);
|
---|
| 5351 | }
|
---|
[34129] | 5352 | break;
|
---|
[71651] | 5353 |
|
---|
[34129] | 5354 | default:
|
---|
[49940] | 5355 | AssertFailed();
|
---|
[34129] | 5356 | break;
|
---|
| 5357 | }
|
---|
| 5358 | }
|
---|
| 5359 |
|
---|
[71651] | 5360 | rc = SSMR3PutU32(pSSM, VBOXVHWACOMMANDELEMENTLISTEND_MAGIC);
|
---|
| 5361 | AssertRC(rc);
|
---|
[34129] | 5362 | }
|
---|
| 5363 |
|
---|
| 5364 | void VBoxVHWACommandElementProcessor::lock()
|
---|
| 5365 | {
|
---|
| 5366 | RTCritSectEnter(&mCritSect);
|
---|
| 5367 |
|
---|
[71651] | 5368 | if (mpCurCmd)
|
---|
[34129] | 5369 | {
|
---|
[71651] | 5370 | for (;;)
|
---|
[34129] | 5371 | {
|
---|
| 5372 | RTCritSectLeave(&mCritSect);
|
---|
[49433] | 5373 | RTThreadSleep(2); /* 2 ms */
|
---|
[34129] | 5374 | RTCritSectEnter(&mCritSect);
|
---|
| 5375 | /* it is assumed no one sends any new commands while reset is in progress */
|
---|
[71651] | 5376 | if (!mpCurCmd)
|
---|
[34129] | 5377 | {
|
---|
| 5378 | break;
|
---|
| 5379 | }
|
---|
| 5380 | }
|
---|
| 5381 | }
|
---|
| 5382 |
|
---|
[49420] | 5383 | Assert(!mpCurCmd);
|
---|
[34129] | 5384 | }
|
---|
| 5385 |
|
---|
| 5386 | void VBoxVHWACommandElementProcessor::unlock()
|
---|
| 5387 | {
|
---|
| 5388 | RTCritSectLeave(&mCritSect);
|
---|
| 5389 | }
|
---|
| 5390 |
|
---|
[34140] | 5391 | void VBoxVHWACommandElementProcessor::disable()
|
---|
| 5392 | {
|
---|
| 5393 | lock();
|
---|
| 5394 | ++mcDisabled;
|
---|
| 5395 | unlock();
|
---|
| 5396 | }
|
---|
| 5397 |
|
---|
| 5398 | void VBoxVHWACommandElementProcessor::enable()
|
---|
| 5399 | {
|
---|
| 5400 | lock();
|
---|
| 5401 | --mcDisabled;
|
---|
| 5402 | unlock();
|
---|
| 5403 | }
|
---|
| 5404 |
|
---|
[35280] | 5405 | /* static */
|
---|
[71651] | 5406 | uint32_t VBoxVHWATextureImage::calcBytesPerLine(const VBoxVHWAColorFormat &format, int width)
|
---|
[35280] | 5407 | {
|
---|
[71651] | 5408 | uint32_t pitch = (format.bitsPerPixel() * width + 7) / 8;
|
---|
[35280] | 5409 | switch (format.fourcc())
|
---|
| 5410 | {
|
---|
| 5411 | case FOURCC_YV12:
|
---|
| 5412 | /* make sure the color components pitch is multiple of 8
|
---|
| 5413 | * where 8 is 2 (for color component width is Y width / 2) * 4 for 4byte texture format */
|
---|
| 5414 | pitch = (pitch + 7) & ~7;
|
---|
| 5415 | break;
|
---|
[71651] | 5416 |
|
---|
[35280] | 5417 | default:
|
---|
| 5418 | pitch = (pitch + 3) & ~3;
|
---|
| 5419 | break;
|
---|
| 5420 | }
|
---|
| 5421 | return pitch;
|
---|
| 5422 | }
|
---|
| 5423 |
|
---|
| 5424 | /* static */
|
---|
[71651] | 5425 | uint32_t VBoxVHWATextureImage::calcMemSize(const VBoxVHWAColorFormat &format, int width, int height)
|
---|
[35280] | 5426 | {
|
---|
| 5427 | uint32_t pitch = calcBytesPerLine(format, width);
|
---|
| 5428 | switch (format.fourcc())
|
---|
| 5429 | {
|
---|
| 5430 | case FOURCC_YV12:
|
---|
| 5431 | /* we have 3 separate planes here
|
---|
| 5432 | * Y - pitch x height
|
---|
[71651] | 5433 | * U - pitch / 2 x height / 2
|
---|
| 5434 | * V - pitch / 2 x height / 2
|
---|
[35280] | 5435 | * */
|
---|
| 5436 | return 3 * pitch * height / 2;
|
---|
[71651] | 5437 |
|
---|
[35280] | 5438 | default:
|
---|
| 5439 | return pitch * height;
|
---|
| 5440 | }
|
---|
| 5441 | }
|
---|
| 5442 |
|
---|
[71651] | 5443 | VBoxVHWATextureImage::VBoxVHWATextureImage(const QRect &size, const VBoxVHWAColorFormat &format,
|
---|
| 5444 | class VBoxVHWAGlProgramMngr * aMgr, VBOXVHWAIMG_TYPE flags)
|
---|
| 5445 | : mVisibleDisplay(0)
|
---|
| 5446 | , mpProgram(0)
|
---|
| 5447 | , mProgramMngr(aMgr)
|
---|
| 5448 | , mpDst(NULL)
|
---|
| 5449 | , mpDstCKey(NULL)
|
---|
| 5450 | , mpSrcCKey(NULL)
|
---|
| 5451 | , mbNotIntersected(false)
|
---|
[25385] | 5452 | {
|
---|
[35280] | 5453 | uint32_t pitch = calcBytesPerLine(format, size.width());
|
---|
| 5454 |
|
---|
| 5455 | mpTex[0] = vboxVHWATextureCreate(NULL, size, format, pitch, flags);
|
---|
[25385] | 5456 | mColorFormat = format;
|
---|
[71651] | 5457 | if (mColorFormat.fourcc() == FOURCC_YV12)
|
---|
[25385] | 5458 | {
|
---|
[71651] | 5459 | QRect rect(size.x() / 2,size.y() / 2,size.width() / 2,size.height() / 2);
|
---|
| 5460 | mpTex[1] = vboxVHWATextureCreate(NULL, rect, format, pitch / 2, flags);
|
---|
| 5461 | mpTex[2] = vboxVHWATextureCreate(NULL, rect, format, pitch / 2, flags);
|
---|
[25385] | 5462 | mcTex = 3;
|
---|
| 5463 | }
|
---|
| 5464 | else
|
---|
| 5465 | mcTex = 1;
|
---|
| 5466 | }
|
---|
| 5467 |
|
---|
| 5468 | void VBoxVHWATextureImage::deleteDisplayList()
|
---|
| 5469 | {
|
---|
[71651] | 5470 | if (mVisibleDisplay)
|
---|
[25385] | 5471 | {
|
---|
| 5472 | glDeleteLists(mVisibleDisplay, 1);
|
---|
| 5473 | mVisibleDisplay = 0;
|
---|
| 5474 | }
|
---|
| 5475 | }
|
---|
| 5476 |
|
---|
| 5477 | void VBoxVHWATextureImage::deleteDisplay()
|
---|
| 5478 | {
|
---|
| 5479 | deleteDisplayList();
|
---|
| 5480 | mpProgram = NULL;
|
---|
| 5481 | }
|
---|
| 5482 |
|
---|
[71651] | 5483 | void VBoxVHWATextureImage::draw(VBoxVHWATextureImage *pDst, const QRect *pDstRect, const QRect *pSrcRect)
|
---|
[25385] | 5484 | {
|
---|
| 5485 | int tx1, ty1, tx2, ty2;
|
---|
| 5486 | pSrcRect->getCoords(&tx1, &ty1, &tx2, &ty2);
|
---|
[71651] | 5487 |
|
---|
[25385] | 5488 | int bx1, by1, bx2, by2;
|
---|
| 5489 | pDstRect->getCoords(&bx1, &by1, &bx2, &by2);
|
---|
[71651] | 5490 |
|
---|
[25385] | 5491 | tx2++; ty2++;bx2++; by2++;
|
---|
| 5492 |
|
---|
| 5493 | glBegin(GL_QUADS);
|
---|
| 5494 | uint32_t c = texCoord(GL_TEXTURE0, tx1, ty1);
|
---|
[71651] | 5495 | if (pDst)
|
---|
[25385] | 5496 | pDst->texCoord(GL_TEXTURE0 + c, bx1, by1);
|
---|
| 5497 | glVertex2i(bx1, by1);
|
---|
| 5498 |
|
---|
| 5499 | texCoord(GL_TEXTURE0, tx1, ty2);
|
---|
[71651] | 5500 | if (pDst)
|
---|
[25385] | 5501 | pDst->texCoord(GL_TEXTURE0 + c, bx1, by2);
|
---|
| 5502 | glVertex2i(bx1, by2);
|
---|
| 5503 |
|
---|
| 5504 | texCoord(GL_TEXTURE0, tx2, ty2);
|
---|
[71651] | 5505 | if (pDst)
|
---|
[25385] | 5506 | pDst->texCoord(GL_TEXTURE0 + c, bx2, by2);
|
---|
| 5507 | glVertex2i(bx2, by2);
|
---|
| 5508 |
|
---|
| 5509 | texCoord(GL_TEXTURE0, tx2, ty1);
|
---|
[71651] | 5510 | if (pDst)
|
---|
[25385] | 5511 | pDst->texCoord(GL_TEXTURE0 + c, bx2, by1);
|
---|
| 5512 | glVertex2i(bx2, by1);
|
---|
| 5513 |
|
---|
| 5514 | glEnd();
|
---|
| 5515 | }
|
---|
| 5516 |
|
---|
| 5517 | void VBoxVHWATextureImage::internalSetDstCKey(const VBoxVHWAColorKey * pDstCKey)
|
---|
| 5518 | {
|
---|
[71651] | 5519 | if (pDstCKey)
|
---|
[25385] | 5520 | {
|
---|
| 5521 | mDstCKey = *pDstCKey;
|
---|
| 5522 | mpDstCKey = &mDstCKey;
|
---|
| 5523 | }
|
---|
| 5524 | else
|
---|
| 5525 | {
|
---|
| 5526 | mpDstCKey = NULL;
|
---|
| 5527 | }
|
---|
| 5528 | }
|
---|
| 5529 |
|
---|
| 5530 | void VBoxVHWATextureImage::internalSetSrcCKey(const VBoxVHWAColorKey * pSrcCKey)
|
---|
| 5531 | {
|
---|
[71651] | 5532 | if (pSrcCKey)
|
---|
[25385] | 5533 | {
|
---|
| 5534 | mSrcCKey = *pSrcCKey;
|
---|
| 5535 | mpSrcCKey = &mSrcCKey;
|
---|
| 5536 | }
|
---|
| 5537 | else
|
---|
| 5538 | {
|
---|
| 5539 | mpSrcCKey = NULL;
|
---|
| 5540 | }
|
---|
| 5541 | }
|
---|
| 5542 |
|
---|
| 5543 | int VBoxVHWATextureImage::initDisplay(VBoxVHWATextureImage *pDst,
|
---|
[71651] | 5544 | const QRect *pDstRect, const QRect *pSrcRect,
|
---|
| 5545 | const VBoxVHWAColorKey *pDstCKey, const VBoxVHWAColorKey *pSrcCKey, bool bNotIntersected)
|
---|
[25385] | 5546 | {
|
---|
[71651] | 5547 | if ( !mVisibleDisplay
|
---|
| 5548 | || mpDst != pDst
|
---|
| 5549 | || *pDstRect != mDstRect
|
---|
| 5550 | || *pSrcRect != mSrcRect
|
---|
| 5551 | || !!(pDstCKey) != !!(mpDstCKey)
|
---|
| 5552 | || !!(pSrcCKey) != !!(mpSrcCKey)
|
---|
| 5553 | || mbNotIntersected != bNotIntersected
|
---|
| 5554 | || mpProgram != calcProgram(pDst, pDstCKey, pSrcCKey, bNotIntersected))
|
---|
| 5555 | return createSetDisplay(pDst, pDstRect, pSrcRect, pDstCKey, pSrcCKey, bNotIntersected);
|
---|
| 5556 | if ( (pDstCKey && mpDstCKey && *pDstCKey != *mpDstCKey)
|
---|
| 5557 | || (pSrcCKey && mpSrcCKey && *pSrcCKey != *mpSrcCKey))
|
---|
[25385] | 5558 | {
|
---|
| 5559 | Assert(mpProgram);
|
---|
| 5560 | updateSetCKeys(pDstCKey, pSrcCKey);
|
---|
| 5561 | return VINF_SUCCESS;
|
---|
| 5562 | }
|
---|
| 5563 | return VINF_SUCCESS;
|
---|
| 5564 | }
|
---|
| 5565 |
|
---|
| 5566 | void VBoxVHWATextureImage::bind(VBoxVHWATextureImage * pPrimary)
|
---|
| 5567 | {
|
---|
[71651] | 5568 | for (uint32_t i = 1; i < mcTex; i++)
|
---|
[25385] | 5569 | {
|
---|
| 5570 | vboxglActiveTexture(GL_TEXTURE0 + i);
|
---|
| 5571 | mpTex[i]->bind();
|
---|
| 5572 | }
|
---|
[71651] | 5573 | if (pPrimary)
|
---|
| 5574 | for (uint32_t i = 0; i < pPrimary->mcTex; i++)
|
---|
[25385] | 5575 | {
|
---|
| 5576 | vboxglActiveTexture(GL_TEXTURE0 + i + mcTex);
|
---|
| 5577 | pPrimary->mpTex[i]->bind();
|
---|
| 5578 | }
|
---|
| 5579 |
|
---|
| 5580 | vboxglActiveTexture(GL_TEXTURE0);
|
---|
| 5581 | mpTex[0]->bind();
|
---|
| 5582 | }
|
---|
| 5583 |
|
---|
[71651] | 5584 | uint32_t VBoxVHWATextureImage::calcProgramType(VBoxVHWATextureImage *pDst, const VBoxVHWAColorKey *pDstCKey,
|
---|
| 5585 | const VBoxVHWAColorKey *pSrcCKey, bool bNotIntersected)
|
---|
[25385] | 5586 | {
|
---|
| 5587 | uint32_t type = 0;
|
---|
| 5588 |
|
---|
[71651] | 5589 | if (pDstCKey != NULL)
|
---|
[25385] | 5590 | type |= VBOXVHWA_PROGRAM_DSTCOLORKEY;
|
---|
[71651] | 5591 | if (pSrcCKey)
|
---|
[25385] | 5592 | type |= VBOXVHWA_PROGRAM_SRCCOLORKEY;
|
---|
[71651] | 5593 | if ((pDstCKey || pSrcCKey) && bNotIntersected)
|
---|
[25385] | 5594 | type |= VBOXVHWA_PROGRAM_COLORKEYNODISCARD;
|
---|
| 5595 |
|
---|
[25763] | 5596 | NOREF(pDst);
|
---|
[25440] | 5597 | return type;
|
---|
| 5598 | }
|
---|
| 5599 |
|
---|
[71651] | 5600 | class VBoxVHWAGlProgramVHWA *VBoxVHWATextureImage::calcProgram(VBoxVHWATextureImage *pDst, const VBoxVHWAColorKey *pDstCKey,
|
---|
| 5601 | const VBoxVHWAColorKey *pSrcCKey, bool bNotIntersected)
|
---|
[25440] | 5602 | {
|
---|
| 5603 | uint32_t type = calcProgramType(pDst, pDstCKey, pSrcCKey, bNotIntersected);
|
---|
| 5604 |
|
---|
[27682] | 5605 | return mProgramMngr->getProgram(type, &pixelFormat(), pDst ? &pDst->pixelFormat() : NULL);
|
---|
[25385] | 5606 | }
|
---|
| 5607 |
|
---|
[71651] | 5608 | int VBoxVHWATextureImage::createSetDisplay(VBoxVHWATextureImage *pDst, const QRect *pDstRect, const QRect *pSrcRect,
|
---|
| 5609 | const VBoxVHWAColorKey *pDstCKey, const VBoxVHWAColorKey * pSrcCKey,
|
---|
| 5610 | bool bNotIntersected)
|
---|
[25385] | 5611 | {
|
---|
| 5612 | deleteDisplay();
|
---|
[71651] | 5613 | int rc = createDisplay(pDst, pDstRect, pSrcRect, pDstCKey, pSrcCKey, bNotIntersected, &mVisibleDisplay, &mpProgram);
|
---|
| 5614 | if (RT_FAILURE(rc))
|
---|
[25385] | 5615 | {
|
---|
| 5616 | mVisibleDisplay = 0;
|
---|
| 5617 | mpProgram = NULL;
|
---|
| 5618 | }
|
---|
| 5619 |
|
---|
| 5620 | mpDst = pDst;
|
---|
| 5621 |
|
---|
| 5622 | mDstRect = *pDstRect;
|
---|
| 5623 | mSrcRect = *pSrcRect;
|
---|
| 5624 |
|
---|
| 5625 | internalSetDstCKey(pDstCKey);
|
---|
| 5626 | internalSetSrcCKey(pSrcCKey);
|
---|
| 5627 |
|
---|
| 5628 | mbNotIntersected = bNotIntersected;
|
---|
| 5629 |
|
---|
| 5630 | return rc;
|
---|
| 5631 | }
|
---|
| 5632 |
|
---|
| 5633 |
|
---|
[71651] | 5634 | int VBoxVHWATextureImage::createDisplayList(VBoxVHWATextureImage *pDst, const QRect *pDstRect, const QRect *pSrcRect,
|
---|
| 5635 | const VBoxVHWAColorKey *pDstCKey, const VBoxVHWAColorKey *pSrcCKey,
|
---|
| 5636 | bool bNotIntersected, GLuint *pDisplay)
|
---|
[25385] | 5637 | {
|
---|
[25441] | 5638 | Q_UNUSED(pDstCKey);
|
---|
| 5639 | Q_UNUSED(pSrcCKey);
|
---|
| 5640 | Q_UNUSED(bNotIntersected);
|
---|
| 5641 |
|
---|
[25385] | 5642 | glGetError(); /* clear the err flag */
|
---|
| 5643 | GLuint display = glGenLists(1);
|
---|
| 5644 | GLenum err = glGetError();
|
---|
[71651] | 5645 | if (err == GL_NO_ERROR)
|
---|
[25385] | 5646 | {
|
---|
| 5647 | Assert(display);
|
---|
[71651] | 5648 | if (!display)
|
---|
[25385] | 5649 | {
|
---|
| 5650 | /* well, it seems it should not return 0 on success according to the spec,
|
---|
| 5651 | * but just in case, pick another one */
|
---|
| 5652 | display = glGenLists(1);
|
---|
| 5653 | err = glGetError();
|
---|
[71651] | 5654 | if (err == GL_NO_ERROR)
|
---|
[25385] | 5655 | {
|
---|
| 5656 | Assert(display);
|
---|
| 5657 | }
|
---|
| 5658 | else
|
---|
| 5659 | {
|
---|
| 5660 | /* we are failed */
|
---|
| 5661 | Assert(!display);
|
---|
| 5662 | display = 0;
|
---|
| 5663 | }
|
---|
| 5664 | }
|
---|
| 5665 |
|
---|
[71651] | 5666 | if (display)
|
---|
[25385] | 5667 | {
|
---|
| 5668 | glNewList(display, GL_COMPILE);
|
---|
| 5669 |
|
---|
| 5670 | runDisplay(pDst, pDstRect, pSrcRect);
|
---|
| 5671 |
|
---|
| 5672 | glEndList();
|
---|
| 5673 | VBOXQGL_ASSERTNOERR();
|
---|
| 5674 | *pDisplay = display;
|
---|
| 5675 | return VINF_SUCCESS;
|
---|
| 5676 | }
|
---|
| 5677 | }
|
---|
| 5678 | else
|
---|
| 5679 | {
|
---|
| 5680 | VBOXQGLLOG(("gl error ocured (0x%x)\n", err));
|
---|
| 5681 | Assert(err == GL_NO_ERROR);
|
---|
| 5682 | }
|
---|
| 5683 | return VERR_GENERAL_FAILURE;
|
---|
| 5684 | }
|
---|
| 5685 |
|
---|
[71651] | 5686 | void VBoxVHWATextureImage::updateCKeys(VBoxVHWATextureImage *pDst, class VBoxVHWAGlProgramVHWA *pProgram,
|
---|
| 5687 | const VBoxVHWAColorKey *pDstCKey, const VBoxVHWAColorKey *pSrcCKey)
|
---|
[25385] | 5688 | {
|
---|
[71651] | 5689 | if (pProgram)
|
---|
[25385] | 5690 | {
|
---|
| 5691 | pProgram->start();
|
---|
[71651] | 5692 | if (pSrcCKey)
|
---|
[27682] | 5693 | VBoxVHWATextureImage::setCKey(pProgram, &pixelFormat(), pSrcCKey, false);
|
---|
[71651] | 5694 | if (pDstCKey)
|
---|
[27682] | 5695 | VBoxVHWATextureImage::setCKey(pProgram, &pDst->pixelFormat(), pDstCKey, true);
|
---|
[25385] | 5696 | pProgram->stop();
|
---|
| 5697 | }
|
---|
| 5698 | }
|
---|
| 5699 |
|
---|
[71651] | 5700 | void VBoxVHWATextureImage::updateSetCKeys(const VBoxVHWAColorKey *pDstCKey, const VBoxVHWAColorKey *pSrcCKey)
|
---|
[25385] | 5701 | {
|
---|
| 5702 | updateCKeys(mpDst, mpProgram, pDstCKey, pSrcCKey);
|
---|
| 5703 | internalSetDstCKey(pDstCKey);
|
---|
| 5704 | internalSetSrcCKey(pSrcCKey);
|
---|
| 5705 | }
|
---|
| 5706 |
|
---|
[71651] | 5707 | int VBoxVHWATextureImage::createDisplay(VBoxVHWATextureImage *pDst, const QRect *pDstRect, const QRect *pSrcRect,
|
---|
| 5708 | const VBoxVHWAColorKey *pDstCKey, const VBoxVHWAColorKey *pSrcCKey, bool bNotIntersected,
|
---|
| 5709 | GLuint *pDisplay, class VBoxVHWAGlProgramVHWA **ppProgram)
|
---|
[25385] | 5710 | {
|
---|
[71651] | 5711 | VBoxVHWAGlProgramVHWA *pProgram = NULL;
|
---|
[27960] | 5712 | if (!pDst)
|
---|
[25385] | 5713 | {
|
---|
| 5714 | /* sanity */
|
---|
| 5715 | Assert(pDstCKey == NULL);
|
---|
| 5716 | pDstCKey = NULL;
|
---|
| 5717 | }
|
---|
| 5718 |
|
---|
[27960] | 5719 | Assert(!pSrcCKey);
|
---|
| 5720 | if (pSrcCKey)
|
---|
| 5721 | pSrcCKey = NULL; /* fallback */
|
---|
| 5722 |
|
---|
[25385] | 5723 | pProgram = calcProgram(pDst, pDstCKey, pSrcCKey, bNotIntersected);
|
---|
| 5724 |
|
---|
| 5725 | updateCKeys(pDst, pProgram, pDstCKey, pSrcCKey);
|
---|
| 5726 |
|
---|
| 5727 | GLuint displ;
|
---|
[71651] | 5728 | int rc = createDisplayList(pDst, pDstRect, pSrcRect, pDstCKey, pSrcCKey, bNotIntersected, &displ);
|
---|
| 5729 | if (RT_SUCCESS(rc))
|
---|
[25385] | 5730 | {
|
---|
| 5731 | *pDisplay = displ;
|
---|
| 5732 | *ppProgram = pProgram;
|
---|
| 5733 | }
|
---|
| 5734 |
|
---|
| 5735 | return rc;
|
---|
| 5736 | }
|
---|
| 5737 |
|
---|
[71651] | 5738 | void VBoxVHWATextureImage::display(VBoxVHWATextureImage *pDst, const QRect *pDstRect, const QRect *pSrcRect,
|
---|
| 5739 | const VBoxVHWAColorKey *pDstCKey, const VBoxVHWAColorKey *pSrcCKey, bool bNotIntersected)
|
---|
[25385] | 5740 | {
|
---|
[71651] | 5741 | VBoxVHWAGlProgramVHWA *pProgram = calcProgram(pDst, pDstCKey, pSrcCKey, bNotIntersected);
|
---|
| 5742 | if (pProgram)
|
---|
[25385] | 5743 | pProgram->start();
|
---|
| 5744 |
|
---|
| 5745 | runDisplay(pDst, pDstRect, pSrcRect);
|
---|
| 5746 |
|
---|
[71651] | 5747 | if (pProgram)
|
---|
[25385] | 5748 | pProgram->stop();
|
---|
| 5749 | }
|
---|
| 5750 |
|
---|
| 5751 | void VBoxVHWATextureImage::display()
|
---|
| 5752 | {
|
---|
[34461] | 5753 | #ifdef DEBUG_misha
|
---|
| 5754 | if (mpDst)
|
---|
| 5755 | dbgDump();
|
---|
| 5756 |
|
---|
| 5757 | static bool bDisplayOn = true;
|
---|
| 5758 | #endif
|
---|
[25385] | 5759 | Assert(mVisibleDisplay);
|
---|
[71651] | 5760 | if ( mVisibleDisplay
|
---|
[34461] | 5761 | #ifdef DEBUG_misha
|
---|
[71651] | 5762 | && bDisplayOn
|
---|
[34461] | 5763 | #endif
|
---|
[71651] | 5764 | )
|
---|
[25385] | 5765 | {
|
---|
[71651] | 5766 | if (mpProgram)
|
---|
[25385] | 5767 | mpProgram->start();
|
---|
| 5768 |
|
---|
| 5769 | VBOXQGL_CHECKERR(
|
---|
| 5770 | glCallList(mVisibleDisplay);
|
---|
| 5771 | );
|
---|
| 5772 |
|
---|
[71651] | 5773 | if (mpProgram)
|
---|
[25385] | 5774 | mpProgram->stop();
|
---|
| 5775 | }
|
---|
| 5776 | else
|
---|
| 5777 | {
|
---|
| 5778 | display(mpDst, &mDstRect, &mSrcRect,
|
---|
| 5779 | mpDstCKey, mpSrcCKey, mbNotIntersected);
|
---|
| 5780 | }
|
---|
| 5781 | }
|
---|
| 5782 |
|
---|
[34461] | 5783 | #ifdef DEBUG_misha
|
---|
| 5784 | void VBoxVHWATextureImage::dbgDump()
|
---|
| 5785 | {
|
---|
| 5786 | for (uint32_t i = 0; i < mcTex; ++i)
|
---|
| 5787 | mpTex[i]->dbgDump();
|
---|
| 5788 | }
|
---|
| 5789 | #endif
|
---|
| 5790 |
|
---|
[71651] | 5791 | int VBoxVHWATextureImage::setCKey(VBoxVHWAGlProgramVHWA *pProgram, const VBoxVHWAColorFormat *pFormat,
|
---|
| 5792 | const VBoxVHWAColorKey *pCKey, bool bDst)
|
---|
[25385] | 5793 | {
|
---|
| 5794 | float r,g,b;
|
---|
[71651] | 5795 | pFormat->pixel2Normalized(pCKey->lower(), &r, &g, &b);
|
---|
| 5796 | int rcL = bDst ? pProgram->setDstCKeyLowerRange(r, g, b) : pProgram->setSrcCKeyLowerRange(r, g, b);
|
---|
[25385] | 5797 | Assert(RT_SUCCESS(rcL));
|
---|
| 5798 |
|
---|
| 5799 | return RT_SUCCESS(rcL) /*&& RT_SUCCESS(rcU)*/ ? VINF_SUCCESS: VERR_GENERAL_FAILURE;
|
---|
| 5800 | }
|
---|
| 5801 |
|
---|
[52086] | 5802 | VBoxVHWASettings::VBoxVHWASettings ()
|
---|
[25583] | 5803 | {
|
---|
[52086] | 5804 | }
|
---|
| 5805 |
|
---|
| 5806 | void VBoxVHWASettings::init(CSession &session)
|
---|
| 5807 | {
|
---|
[74878] | 5808 | const QUuid uMachineID = session.GetMachine().GetId();
|
---|
[25385] | 5809 |
|
---|
[74878] | 5810 | mStretchLinearEnabled = gEDataManager->useLinearStretch(uMachineID);
|
---|
[25385] | 5811 |
|
---|
[25583] | 5812 | uint32_t aFourccs[VBOXVHWA_NUMFOURCC];
|
---|
| 5813 | int num = 0;
|
---|
[74878] | 5814 | if (gEDataManager->usePixelFormatAYUV(uMachineID))
|
---|
[25583] | 5815 | aFourccs[num++] = FOURCC_AYUV;
|
---|
[74878] | 5816 | if (gEDataManager->usePixelFormatUYVY(uMachineID))
|
---|
[25583] | 5817 | aFourccs[num++] = FOURCC_UYVY;
|
---|
[74878] | 5818 | if (gEDataManager->usePixelFormatYUY2(uMachineID))
|
---|
[25583] | 5819 | aFourccs[num++] = FOURCC_YUY2;
|
---|
[74878] | 5820 | if (gEDataManager->usePixelFormatYV12(uMachineID))
|
---|
[25583] | 5821 | aFourccs[num++] = FOURCC_YV12;
|
---|
| 5822 |
|
---|
| 5823 | mFourccEnabledCount = num;
|
---|
| 5824 | memcpy(mFourccEnabledList, aFourccs, num* sizeof (aFourccs[0]));
|
---|
| 5825 | }
|
---|
| 5826 |
|
---|
[71651] | 5827 | int VBoxVHWASettings::calcIntersection(int c1, const uint32_t *a1, int c2, const uint32_t *a2, int cOut, uint32_t *aOut)
|
---|
[25583] | 5828 | {
|
---|
| 5829 | /* fourcc arrays are not big, so linear search is enough,
|
---|
| 5830 | * also no need to check for duplicates */
|
---|
| 5831 | int cMatch = 0;
|
---|
| 5832 | for (int i = 0; i < c1; ++i)
|
---|
| 5833 | {
|
---|
| 5834 | uint32_t cur1 = a1[i];
|
---|
| 5835 | for (int j = 0; j < c2; ++j)
|
---|
| 5836 | {
|
---|
| 5837 | uint32_t cur2 = a2[j];
|
---|
[71651] | 5838 | if (cur1 == cur2)
|
---|
[25583] | 5839 | {
|
---|
[71651] | 5840 | if (cOut > cMatch && aOut)
|
---|
[25583] | 5841 | aOut[cMatch] = cur1;
|
---|
| 5842 | ++cMatch;
|
---|
| 5843 | break;
|
---|
| 5844 | }
|
---|
| 5845 | }
|
---|
| 5846 | }
|
---|
| 5847 |
|
---|
| 5848 | return cMatch;
|
---|
| 5849 | }
|
---|
| 5850 |
|
---|
[52722] | 5851 | #endif /* VBOX_GUI_USE_QGL */
|
---|
[26719] | 5852 |
|
---|