VirtualBox

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

Last change on this file since 42232 was 36867, checked in by vboxsync, 14 years ago

Additions/Video: display/miniport drivers

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