Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenpalette.c
Go to the documentation of this file.
00001 /* DirectDraw - IDirectPalette base interface 00002 * 00003 * Copyright 1997-2000 Marcus Meissner 00004 * Copyright 2000-2001 TransGaming Technologies Inc. 00005 * Copyright 2006 Stefan Dösinger for CodeWeavers 00006 * 00007 * This library is free software; you can redistribute it and/or 00008 * modify it under the terms of the GNU Lesser General Public 00009 * License as published by the Free Software Foundation; either 00010 * version 2.1 of the License, or (at your option) any later version. 00011 * 00012 * This library is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 * Lesser General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU Lesser General Public 00018 * License along with this library; if not, write to the Free Software 00019 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA 00020 */ 00021 #include "config.h" 00022 #include "winerror.h" 00023 #include "wine/debug.h" 00024 00025 #include <string.h> 00026 00027 #include "wined3d_private.h" 00028 00029 WINE_DEFAULT_DEBUG_CHANNEL(d3d); 00030 00031 #define SIZE_BITS (WINEDDPCAPS_1BIT | WINEDDPCAPS_2BIT | WINEDDPCAPS_4BIT | WINEDDPCAPS_8BIT) 00032 00033 ULONG CDECL wined3d_palette_incref(struct wined3d_palette *palette) 00034 { 00035 ULONG refcount = InterlockedIncrement(&palette->ref); 00036 00037 TRACE("%p increasing refcount to %u.\n", palette, refcount); 00038 00039 return refcount; 00040 } 00041 00042 ULONG CDECL wined3d_palette_decref(struct wined3d_palette *palette) 00043 { 00044 ULONG refcount = InterlockedDecrement(&palette->ref); 00045 00046 TRACE("%p decreasing refcount to %u.\n", palette, refcount); 00047 00048 if (!refcount) 00049 { 00050 DeleteObject(palette->hpal); 00051 HeapFree(GetProcessHeap(), 0, palette); 00052 } 00053 00054 return refcount; 00055 } 00056 00057 static WORD wined3d_palette_size(DWORD flags) 00058 { 00059 switch (flags & SIZE_BITS) 00060 { 00061 case WINEDDPCAPS_1BIT: return 2; 00062 case WINEDDPCAPS_2BIT: return 4; 00063 case WINEDDPCAPS_4BIT: return 16; 00064 case WINEDDPCAPS_8BIT: return 256; 00065 default: 00066 FIXME("Unhandled size bits %#x.\n", flags & SIZE_BITS); 00067 return 256; 00068 } 00069 } 00070 00071 HRESULT CDECL wined3d_palette_get_entries(const struct wined3d_palette *palette, 00072 DWORD flags, DWORD start, DWORD count, PALETTEENTRY *entries) 00073 { 00074 TRACE("palette %p, flags %#x, start %u, count %u, entries %p.\n", 00075 palette, flags, start, count, entries); 00076 00077 if (flags) return WINED3DERR_INVALIDCALL; /* unchecked */ 00078 if (start + count > wined3d_palette_size(palette->flags)) 00079 return WINED3DERR_INVALIDCALL; 00080 00081 if (palette->flags & WINEDDPCAPS_8BITENTRIES) 00082 { 00083 BYTE *entry = (BYTE *)entries; 00084 unsigned int i; 00085 00086 for (i = start; i < count + start; ++i) 00087 *entry++ = palette->palents[i].peRed; 00088 } 00089 else 00090 memcpy(entries, palette->palents + start, count * sizeof(*entries)); 00091 00092 return WINED3D_OK; 00093 } 00094 00095 HRESULT CDECL wined3d_palette_set_entries(struct wined3d_palette *palette, 00096 DWORD flags, DWORD start, DWORD count, const PALETTEENTRY *entries) 00097 { 00098 struct wined3d_resource *resource; 00099 00100 TRACE("palette %p, flags %#x, start %u, count %u, entries %p.\n", 00101 palette, flags, start, count, entries); 00102 TRACE("Palette flags: %#x.\n", palette->flags); 00103 00104 if (palette->flags & WINEDDPCAPS_8BITENTRIES) 00105 { 00106 const BYTE *entry = (const BYTE *)entries; 00107 unsigned int i; 00108 00109 for (i = start; i < count + start; ++i) 00110 palette->palents[i].peRed = *entry++; 00111 } 00112 else 00113 { 00114 memcpy(palette->palents + start, entries, count * sizeof(*palette->palents)); 00115 00116 /* When WINEDDCAPS_ALLOW256 isn't set we need to override entry 0 with black and 255 with white */ 00117 if (!(palette->flags & WINEDDPCAPS_ALLOW256)) 00118 { 00119 TRACE("WINEDDPCAPS_ALLOW256 set, overriding palette entry 0 with black and 255 with white\n"); 00120 palette->palents[0].peRed = 0; 00121 palette->palents[0].peGreen = 0; 00122 palette->palents[0].peBlue = 0; 00123 00124 palette->palents[255].peRed = 255; 00125 palette->palents[255].peGreen = 255; 00126 palette->palents[255].peBlue = 255; 00127 } 00128 00129 if (palette->hpal) 00130 SetPaletteEntries(palette->hpal, start, count, palette->palents + start); 00131 } 00132 00133 /* If the palette is attached to the render target, update all render targets */ 00134 LIST_FOR_EACH_ENTRY(resource, &palette->device->resources, struct wined3d_resource, resource_list_entry) 00135 { 00136 if (resource->type == WINED3D_RTYPE_SURFACE) 00137 { 00138 struct wined3d_surface *surface = surface_from_resource(resource); 00139 if (surface->palette == palette) 00140 surface->surface_ops->surface_realize_palette(surface); 00141 } 00142 } 00143 00144 return WINED3D_OK; 00145 } 00146 00147 DWORD CDECL wined3d_palette_get_flags(const struct wined3d_palette *palette) 00148 { 00149 TRACE("palette %p.\n", palette); 00150 00151 return palette->flags; 00152 } 00153 00154 void * CDECL wined3d_palette_get_parent(const struct wined3d_palette *palette) 00155 { 00156 TRACE("palette %p.\n", palette); 00157 00158 return palette->parent; 00159 } 00160 00161 static HRESULT wined3d_palette_init(struct wined3d_palette *palette, struct wined3d_device *device, 00162 DWORD flags, const PALETTEENTRY *entries, void *parent) 00163 { 00164 HRESULT hr; 00165 00166 palette->ref = 1; 00167 palette->parent = parent; 00168 palette->device = device; 00169 palette->flags = flags; 00170 00171 palette->palNumEntries = wined3d_palette_size(flags); 00172 palette->hpal = CreatePalette((const LOGPALETTE *)&palette->palVersion); 00173 if (!palette->hpal) 00174 { 00175 WARN("Failed to create palette.\n"); 00176 return E_FAIL; 00177 } 00178 00179 hr = wined3d_palette_set_entries(palette, 0, 0, wined3d_palette_size(flags), entries); 00180 if (FAILED(hr)) 00181 { 00182 WARN("Failed to set palette entries, hr %#x.\n", hr); 00183 DeleteObject(palette->hpal); 00184 return hr; 00185 } 00186 00187 return WINED3D_OK; 00188 } 00189 00190 HRESULT CDECL wined3d_palette_create(struct wined3d_device *device, DWORD flags, 00191 const PALETTEENTRY *entries, void *parent, struct wined3d_palette **palette) 00192 { 00193 struct wined3d_palette *object; 00194 HRESULT hr; 00195 00196 TRACE("device %p, flags %#x, entries %p, palette %p, parent %p.\n", 00197 device, flags, entries, palette, parent); 00198 00199 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object)); 00200 if (!object) 00201 { 00202 ERR("Failed to allocate palette memory.\n"); 00203 return E_OUTOFMEMORY; 00204 } 00205 00206 hr = wined3d_palette_init(object, device, flags, entries, parent); 00207 if (FAILED(hr)) 00208 { 00209 WARN("Failed to initialize palette, hr %#x.\n", hr); 00210 HeapFree(GetProcessHeap(), 0, object); 00211 return hr; 00212 } 00213 00214 TRACE("Created palette %p.\n", object); 00215 *palette = object; 00216 00217 return WINED3D_OK; 00218 } Generated on Sun May 27 2012 04:17:05 for ReactOS by
1.7.6.1
|