VirtualBox

source: vbox/trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/xpdm/VBoxDispPalette.cpp@ 96407

Last change on this file since 96407 was 96407, checked in by vboxsync, 2 years ago

scm copyright and license note update

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.1 KB
Line 
1/* $Id: VBoxDispPalette.cpp 96407 2022-08-22 17:43:14Z vboxsync $ */
2/** @file
3 * VBox XPDM Display driver, palette related functions
4 */
5
6/*
7 * Copyright (C) 2011-2022 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * SPDX-License-Identifier: GPL-3.0-only
26 */
27
28
29#include "VBoxDisp.h"
30#include "VBoxDispMini.h"
31
32#define MAX_CLUT_SIZE (sizeof(VIDEO_CLUT)+(sizeof(ULONG) * 256))
33
34/* 10 default palette colors with it's complementors which are used for window decoration colors*/
35const PALETTEENTRY defPal[10] =
36{
37 {0, 0, 0, 0},
38 {0x80, 0, 0, 0},
39 {0, 0x80, 0, 0},
40 {0x80, 0x80, 0, 0},
41 {0, 0, 0x80, 0},
42 {0x80, 0, 0x80, 0},
43 {0, 0x80, 0x80, 0},
44 {0xC0, 0xC0, 0xC0, 0},
45 {0xC0, 0xDC, 0xC0, 0},
46 {0xA6, 0xCA, 0xF0, 0},
47};
48
49const PALETTEENTRY defPalComp[10] =
50{
51 {0xFF, 0xFF, 0xFF, 0},
52 {0, 0xFF, 0xFF, 0},
53 {0xFF, 0, 0xFF, 0},
54 {0, 0, 0xFF, 0},
55 {0xFF, 0xFF, 0, 0},
56 {0, 0xFF, 0, 0},
57 {0xFF, 0, 0, 0},
58 {0x80, 0x80, 0x80, 0},
59 {0xA0, 0xA0, 0xA4, 0},
60 {0xFF, 0xFB, 0xF0, 0},
61};
62
63/* Creates default device palette */
64int VBoxDispInitPalette(PVBOXDISPDEV pDev, DEVINFO *pDevInfo)
65{
66 if (pDev->mode.ulBitsPerPel!=8)
67 {
68 pDev->hDefaultPalette = EngCreatePalette(PAL_BITFIELDS, 0, NULL,
69 pDev->mode.flMaskR, pDev->mode.flMaskG, pDev->mode.flMaskB);
70
71 if (!pDev->hDefaultPalette)
72 {
73 WARN(("EngCreatePalette failed"));
74 return VERR_GENERAL_FAILURE;
75 }
76
77 pDevInfo->hpalDefault = pDev->hDefaultPalette;
78 return VINF_SUCCESS;
79 }
80
81 /* Create driver managed palette.
82 * First entry should be black (0,0,0), last should be while (255, 255, 255).
83 * Note: Other entries should be set in similar way, so that entries with complementing indicies
84 * have quite contrast colors stored.
85 */
86
87 pDev->pPalette = (PPALETTEENTRY) EngAllocMem(0, sizeof(PALETTEENTRY) * 256, MEM_ALLOC_TAG);
88 if (!pDev->pPalette)
89 {
90 WARN(("not enough memory!"));
91 return VERR_NO_MEMORY;
92 }
93
94 BYTE r=0, g=0, b=0;
95 for (ULONG i=0; i<256; ++i)
96 {
97 pDev->pPalette[i].peRed = r;
98 pDev->pPalette[i].peGreen = g;
99 pDev->pPalette[i].peBlue = b;
100 pDev->pPalette[i].peFlags = 0;
101
102 r += 32;
103 if (!r)
104 {
105 g += 32;
106 if (!g)
107 {
108 b += 64;
109 }
110 }
111 }
112
113 /* Now overwrite window decoration colors by common ones */
114 for (ULONG i=0; i<RT_ELEMENTS(defPal); ++i)
115 {
116 pDev->pPalette[i] = defPal[i];
117 pDev->pPalette[(~i)&0xFF] = defPalComp[i];
118 }
119
120 /* Sanity check in case we'd change palette filling */
121 Assert(pDev->pPalette[0].peRed==0 && pDev->pPalette[0].peGreen==0 && pDev->pPalette[0].peBlue==0);
122 Assert(pDev->pPalette[255].peRed==255 && pDev->pPalette[255].peGreen==255 && pDev->pPalette[255].peBlue==255);
123
124 pDev->hDefaultPalette = EngCreatePalette(PAL_INDEXED, 256, (PULONG)pDev->pPalette, 0, 0, 0);
125 if (!pDev->hDefaultPalette)
126 {
127 WARN(("EngCreatePalette failed"));
128 EngFreeMem(pDev->pPalette);
129 pDev->pPalette = NULL;
130 return VERR_GENERAL_FAILURE;
131 }
132
133 pDevInfo->hpalDefault = pDev->hDefaultPalette;
134 return VINF_SUCCESS;
135}
136
137void VBoxDispDestroyPalette(PVBOXDISPDEV pDev)
138{
139 if (pDev->hDefaultPalette)
140 {
141 EngDeletePalette(pDev->hDefaultPalette);
142 pDev->hDefaultPalette = 0;
143 }
144
145 if (pDev->pPalette)
146 {
147 EngFreeMem(pDev->pPalette);
148 }
149}
150
151int VBoxDispSetPalette8BPP(PVBOXDISPDEV pDev)
152{
153 if (pDev->mode.ulBitsPerPel!=8)
154 {
155 return VERR_NOT_SUPPORTED;
156 }
157
158 BYTE aClut[MAX_CLUT_SIZE];
159 PVIDEO_CLUT pClut = (PVIDEO_CLUT) aClut;
160 PVIDEO_CLUTDATA pData = &pClut->LookupTable[0].RgbArray;
161
162 /* Prepare palette info to pass to miniport */
163 pClut->NumEntries = 256;
164 pClut->FirstEntry = 0;
165 for (ULONG idx=0; idx<256; ++idx)
166 {
167 pData[idx].Red = pDev->pPalette[idx].peRed >> pDev->mode.ulPaletteShift;
168 pData[idx].Green = pDev->pPalette[idx].peGreen >> pDev->mode.ulPaletteShift;
169 pData[idx].Blue = pDev->pPalette[idx].peBlue >> pDev->mode.ulPaletteShift;
170 pData[idx].Unused = 0;
171 }
172
173 return VBoxDispMPSetColorRegisters(pDev->hDriver, pClut, MAX_CLUT_SIZE);
174}
175
176/*
177 * Display driver callbacks.
178 */
179BOOL APIENTRY VBoxDispDrvSetPalette(DHPDEV dhpdev, PALOBJ *ppalo, FLONG fl, ULONG iStart, ULONG cColors)
180{
181 BYTE aClut[MAX_CLUT_SIZE];
182 PVIDEO_CLUT pClut = (PVIDEO_CLUT) aClut;
183 PVIDEO_CLUTDATA pData = &pClut->LookupTable[0].RgbArray;
184 PVBOXDISPDEV pDev = (PVBOXDISPDEV)dhpdev;
185 NOREF(fl);
186 int rc;
187 LOGF_ENTER();
188
189 pClut->NumEntries = (USHORT) cColors;
190 pClut->FirstEntry = (USHORT) iStart;
191
192 /* Copy PALOBJ colors to PVIDEO_CLUT */
193 if (cColors != PALOBJ_cGetColors(ppalo, iStart, cColors, (ULONG*) pData))
194 {
195 WARN(("PALOBJ_cGetColors failed"));
196 return FALSE;
197 }
198
199 /* Set reserved bytes to 0 and perform shifting if needed */
200 for (ULONG idx=0; idx<cColors; ++idx)
201 {
202 pData[idx].Unused = 0;
203 if (pDev->mode.ulPaletteShift)
204 {
205 pData[idx].Red >>= pDev->mode.ulPaletteShift;
206 pData[idx].Green >>= pDev->mode.ulPaletteShift;
207 pData[idx].Blue >>= pDev->mode.ulPaletteShift;
208 }
209 }
210
211 rc = VBoxDispMPSetColorRegisters(pDev->hDriver, pClut, MAX_CLUT_SIZE);
212 VBOX_WARNRC_RETV(rc, FALSE);
213
214 LOGF_LEAVE();
215 return TRUE;
216}
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette