No longer directly accessing debuggee memory.
[wine] / graphics / ttydrv / bitmap.c
1 /*
2  * TTY bitmap driver
3  *
4  * Copyright 1999 Patrik Stridvall
5  */
6
7 #include "bitmap.h"
8 #include "dc.h"
9 #include "ttydrv.h"
10 #include "winbase.h"
11 #include "debugtools.h"
12
13 DEFAULT_DEBUG_CHANNEL(ttydrv)
14
15 /**********************************************************************/
16
17 static LONG TTYDRV_DC_GetBitmapBits(BITMAPOBJ *bitmap, void *bits, LONG count);
18 static LONG TTYDRV_DC_SetBitmapBits(BITMAPOBJ *bitmap, void *bits, LONG count);
19
20 /***********************************************************************
21  *              TTYDRV_DC_AllocBitmap
22  */
23 TTYDRV_PHYSBITMAP *TTYDRV_DC_AllocBitmap(BITMAPOBJ *bitmap)
24 {
25   TTYDRV_PHYSBITMAP *physBitmap;
26   
27   if(!(bitmap->DDBitmap = HeapAlloc(GetProcessHeap(), 0, sizeof(DDBITMAP)))) {
28     ERR("Can't alloc DDBITMAP\n");
29     return NULL;
30   }
31  
32   if(!(physBitmap = HeapAlloc(GetProcessHeap(), 0, sizeof(TTYDRV_PHYSBITMAP)))) {
33     ERR("Can't alloc TTYDRV_PHYSBITMAP\n");
34     HeapFree(GetProcessHeap(), 0, bitmap->DDBitmap);
35     return NULL;
36   }
37
38   bitmap->DDBitmap->physBitmap = physBitmap;
39   bitmap->DDBitmap->funcs = DRIVER_FindDriver("DISPLAY");
40
41   return physBitmap;
42 }
43
44 /***********************************************************************
45  *           TTYDRV_DC_BitmapBits
46  */
47 LONG TTYDRV_DC_BitmapBits(HBITMAP hbitmap, void *bits, LONG count, WORD flags)
48 {
49   BITMAPOBJ *bitmap;
50   LONG result;
51
52   if(!(bitmap = (BITMAPOBJ *) GDI_GetObjPtr(hbitmap, BITMAP_MAGIC)))
53     return FALSE;
54   
55   if(flags == DDB_GET)
56     result = TTYDRV_DC_GetBitmapBits(bitmap, bits, count);
57   else if(flags == DDB_SET)
58     result = TTYDRV_DC_SetBitmapBits(bitmap, bits, count);
59   else {
60     ERR("Unknown flags value %d\n", flags);
61     result = 0;
62   }
63   
64   GDI_HEAP_UNLOCK(hbitmap);
65   return result;
66 }
67
68 /***********************************************************************
69  *              TTYDRV_DC_CreateBitmap
70  */
71 BOOL TTYDRV_DC_CreateBitmap(HBITMAP hbitmap)
72 {
73   TTYDRV_PHYSBITMAP *physBitmap;
74   BITMAPOBJ *bitmap;
75
76   TRACE("(0x%04x)\n", hbitmap);
77
78   if(!(bitmap = (BITMAPOBJ *) GDI_GetObjPtr(hbitmap, BITMAP_MAGIC)))
79     return FALSE;
80   
81   if(!(physBitmap = TTYDRV_DC_AllocBitmap(bitmap))) {
82     GDI_HEAP_UNLOCK(hbitmap);
83     return FALSE;
84   }
85  
86   /* Set bitmap bits */
87   if(bitmap->bitmap.bmBits) { 
88     TTYDRV_DC_BitmapBits(hbitmap, bitmap->bitmap.bmBits,
89                          bitmap->bitmap.bmHeight * bitmap->bitmap.bmWidthBytes,
90                          DDB_SET );
91   }
92
93   GDI_HEAP_UNLOCK(hbitmap);
94   
95   return TRUE;
96 }
97
98 /***********************************************************************
99  *              TTYDRV_DC_BITMAP_DeleteObject
100  */
101 BOOL TTYDRV_DC_BITMAP_DeleteObject(HBITMAP hbitmap, BITMAPOBJ *bitmap)
102 {
103   TRACE("(0x%04x, %p)\n", hbitmap, bitmap);
104
105   HeapFree(GetProcessHeap(), 0, bitmap->DDBitmap->physBitmap);
106   HeapFree(GetProcessHeap(), 0, bitmap->DDBitmap);
107   bitmap->DDBitmap = NULL;
108   
109   return TRUE;
110 }
111
112 /***********************************************************************
113  *              TTYDRV_DC_GetBitmapBits
114  */
115 static LONG TTYDRV_DC_GetBitmapBits(BITMAPOBJ *bitmap, void *bits, LONG count)
116 {
117   FIXME("(%p, %p, %ld): stub\n", bitmap, bits, count);
118
119   memset(bits, 0, count);
120
121   return count;
122 }
123
124 /***********************************************************************
125  *              TTYDRV_DC_BITMAP_SelectObject
126  */
127 HBITMAP TTYDRV_DC_BITMAP_SelectObject(DC *dc, HBITMAP hbitmap, BITMAPOBJ *bitmap)
128 {
129   HBITMAP hPreviousBitmap;
130
131   TRACE("(%p, 0x%04x, %p)\n", dc, hbitmap, bitmap);
132
133   if(!(dc->w.flags & DC_MEMORY)) 
134     return 0;
135
136   /* Assure that the bitmap device dependent */
137   if(!bitmap->DDBitmap && !TTYDRV_DC_CreateBitmap(hbitmap))
138     return 0;
139
140   if(bitmap->DDBitmap->funcs != dc->funcs) {
141     ERR("Trying to select a non-TTY DDB into a TTY DC\n");
142     return 0;
143   }
144
145   dc->w.totalExtent.left   = 0;
146   dc->w.totalExtent.top    = 0;
147   dc->w.totalExtent.right  = bitmap->bitmap.bmWidth;
148   dc->w.totalExtent.bottom = bitmap->bitmap.bmHeight;
149
150   /* FIXME: Should be done in the common code instead */
151   if(dc->w.hVisRgn) {
152     SetRectRgn(dc->w.hVisRgn, 0, 0,
153                bitmap->bitmap.bmWidth, bitmap->bitmap.bmHeight);
154   } else { 
155     HRGN hrgn;
156
157     if(!(hrgn = CreateRectRgn(0, 0, bitmap->bitmap.bmWidth, bitmap->bitmap.bmHeight)))
158       return 0;
159
160     dc->w.hVisRgn = hrgn;
161   }
162
163   hPreviousBitmap = dc->w.hBitmap;
164   dc->w.hBitmap = hbitmap;
165
166   return hPreviousBitmap;
167 }
168
169 /***********************************************************************
170  *              TTYDRV_DC_SetBitmapBits
171  */
172 static LONG TTYDRV_DC_SetBitmapBits(BITMAPOBJ *bitmap, void *bits, LONG count)
173 {
174   FIXME("(%p, %p, %ld): semistub\n", bitmap, bits, count);
175
176   return count;
177 }