WebRadioApp  0.1
ewgfxcore.h
Go to the documentation of this file.
1 /*******************************************************************************
2  *
3  * E M B E D D E D W I Z A R D P R O J E C T
4  *
5  * Copyright (c) TARA Systems
6  *GmbH written by Paul Banach and Manfred Schweyer
7  *
8  ********************************************************************************
9  *
10  * This software and related documentation ("Software") are intellectual
11  * property owned by TARA Systems and are copyright of TARA Systems.
12  * Any modification, copying, reproduction or redistribution of the Software in
13  * whole or in part by any means not in accordance with the End-User License
14  * Agreement for Embedded Wizard is expressly prohibited. The removal of this
15  * preamble is expressly prohibited.
16  *
17  ********************************************************************************
18  *
19  * DESCRIPTION:
20  * This is an internal header of the Embedded Wizard Graphics Engine EWGFX. It
21  * declares the core functionality of the engine:
22  *
23  * > Surface and font glyph management. Creation and destroying of surfaces
24  * and glyphs. Cache management.
25  *
26  * > Drawing packages - so called 'issues' and the enclosed drawing 'tasks'.
27  * An issue provides storage for drawing operations. This builds the base
28  * for the optimization of the drawing process.
29  *
30  * > State machines to control the execution of pending issues.
31  *
32  *******************************************************************************/
33 
34 #ifndef EWGFXCORE_H
35 #define EWGFXCORE_H
36 
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
40 
41 /*******************************************************************************
42  * MACRO:
43  * EW_LOCK_XXX
44  *
45  * DESCRIPTION:
46  * The following enumeration defines the possible modes used when obtaining
47  * a direct access to a surface memory. These modes serve as hints only. They
48  * determine the intention of the user only and help to avoid any unnecessary
49  * operation when locking surfaces.
50  *
51  * ELEMENTS:
52  * EW_LOCK_PIXEL_READ - Allow read access to the surface pixel memory.
53  * EW_LOCK_PIXEL_WRITE - Allow write access to the pixel surface memory.
54  * EW_LOCK_PIXEL_READ_WRITE - Allow both the read and the write access.
55  * EW_LOCK_CLUT_READ - Allow read access to the Index8 surface CLUT.
56  * EW_LOCK_CLUT_WRITE - Allow write access to the Index8 surface CLUT.
57  * EW_LOCK_CLUT_READ_WRITE - Allow both the read and the write access.
58  * EW_LOCK_DONT_WAIT - Don't wait for the surface if it is involved in
59  * other pending drawing operations. This mode can cause unexpected results
60  * when CPU tries to read or write the surface pixel memory and at the same
61  * time the surface is modified by the graphics subsystem.
62  *
63  *******************************************************************************/
64 #define EW_LOCK_PIXEL_READ 0x01
65 #define EW_LOCK_PIXEL_WRITE 0x02
66 #define EW_LOCK_PIXEL_READ_WRITE 0x03
67 #define EW_LOCK_CLUT_READ 0x04
68 #define EW_LOCK_CLUT_WRITE 0x08
69 #define EW_LOCK_CLUT_READ_WRITE 0x0C
70 #define EW_LOCK_DONT_WAIT 0x80
71 
72 /*******************************************************************************
73  * MACRO:
74  * EW_TASK_XXX
75  *
76  * DESCRIPTION:
77  * The following enumeration defines flags to control the execution of a task.
78  * Beside this, the flags also should simplify the evaluation and optimization
79  * of pending tasks.
80  *
81  * ELEMENTS:
82  * EW_TASK_ALPHABLEND - If set, determines, that the drawing operation
83  * should apply the alpha blending algorithm for all drawn pixel. If not
84  *set, the drawn pixel simply overwrite the previous content of the surface.
85  * EW_TASK_SOLID - If set, determines, that the drawn pixel should
86  * be modulated by a solid color or opacity value.
87  * EW_TASK_GRADIENT - If set, determines, that the drawn pixel should
88  * be modulated by a color or opacity complex gradient.
89  * EW_TASK_LINEAR_GRADIENT - If set, determines, that the drawn pixel should
90  * be modulated by a color or opacity linear (vertical or horizontal)
91  * gradient.
92  * EW_TASK_HIGH_QUALITY - If set, the drawing operation should be performed
93  * with the best possible quality. This flag is just a hint. Its meaning
94  * depends on the capability of the underlying graphics subsystem.
95  * EW_TASK_ENTIRE_AREA - If set, determines that the task will affect the
96  * entire area of the surface specified in the task variables X1,Y1 ..
97  *X2,Y2. If not set, some of the pixel within the area may remain unchanged
98  *(e.g. when drawing a text). EW_TASK_OVERLAP - If set, determines an
99  *optional task, which can be simply ignored if no elimination took place for
100  *the underlying sibling tasks. This flag is used exclusively for bitmaps
101  *composed of a full opaque and a semi-transparent area. When drawing such a
102  *bitmap, the opaque area can be handled separately in order to optimize the
103  *operation, otherwise the entire bitmap needs to be handled as a
104  *semi-transparent bitmap. EW_TASK_EMULATION - If set, the drawing
105  *operation should be performed by the software emulation. If not set, the
106  *underlying graphics subsystem should perform the operation.
107  *
108  *******************************************************************************/
109 #define EW_TASK_ALPHABLEND 0x0001
110 #define EW_TASK_SOLID 0x0002
111 #define EW_TASK_GRADIENT 0x0004
112 #define EW_TASK_LINEAR_GRADIENT 0x0006
113 #define EW_TASK_HIGH_QUALITY 0x0008
114 #define EW_TASK_ENTIRE_AREA 0x0100
115 #define EW_TASK_OVERLAP 0x0200
116 #define EW_TASK_EMULATION 0x8000
117 #define EW_TASK_MODE_MASK 0x000F
118 
119 /*******************************************************************************
120  * MACRO:
121  * EW_TASKID_XXX
122  *
123  * DESCRIPTION:
124  * The following enumeration defines command tokens for the drawing tasks.
125  *
126  * ELEMENTS:
127  * EW_TASKID_FILL_RECTANGLE - Fill a rectangular area with a solid color
128  * or with a color gradient.
129  * EW_TASKID_COPY_SURFACE - Copy an area from a source surface into an
130  * area within a destination surface.
131  * EW_TASKID_TILE_SURFACE - Fill an area within the destination surface
132  * with repetitions of an area from a source surface.
133  * EW_TASKID_WARP_PERSP_SURFACE - Project a rectangular area from the source
134  * surface on a four point polygon within a destination surface. Perspective
135  * projection will take place.
136  * EW_TASKID_WARP_AFFINE_SURFACE - Project a rectangular area from the source
137  * surface on a four point polygon within a destination surface. Affine only
138  * projection will take place.
139  * EW_TASKID_WARP_SCALE_SURFACE - Project a rectangular area from the source
140  * surface on a four point polygon within a destination surface. Scale only
141  * projection will take place.
142  * EW_TASKID_DRAW_LINE - Draw a line with a solid color or with a
143  * color gradient.
144  * EW_TASKID_DRAW_TEXT - Draw text fragment with a solid color or
145  * with a color gradient.
146  * EW_TASKID_FILL_POLYGON - Fill a polygon with a solid color or with
147  * a color gradient.
148  *
149  *******************************************************************************/
150 #define EW_TASKID_FILL_RECTANGLE 1
151 #define EW_TASKID_COPY_SURFACE 2
152 #define EW_TASKID_TILE_SURFACE 3
153 #define EW_TASKID_WARP_PERSP_SURFACE 4
154 #define EW_TASKID_WARP_AFFINE_SURFACE 5
155 #define EW_TASKID_WARP_SCALE_SURFACE 6
156 #define EW_TASKID_DRAW_LINE 7
157 #define EW_TASKID_DRAW_TEXT 8
158 #define EW_TASKID_FILL_POLYGON 9
159 
160 /*******************************************************************************
161  * TYPE:
162  * XSurface
163  *
164  * DESCRIPTION:
165  * The type XSurface defines the structure to cover attributes of the generic,
166  * platform independent surface. It allows the Graphics Engine to handle with
167  * surfaces without taking in account the real representation of the surface
168  * in the underlying graphics subsystem.
169  *
170  * Beside this, the XSurface structure complements the sophisticated concepts
171  * of the Graphics Engine to perform operations in a very efficient way:
172  *
173  * - The surface cache. All existing surfaces are stored within a global cache
174  * and can be reused very quickly - as long as there is still video memory
175  * available. The repeated surface allocation, loading and deallocation can
176  * be omitted in this manner.
177  *
178  * - Lazy drawing tasks. The drawing operations affecting a destination
179  *surface are performed in blocks - as so-called issues. As long as the
180  *composition of a surface is still not completed, the prepared graphics tasks
181  *remain waiting within the issue. As soon as the issue becomes flushed, the
182  *tasks are evaluated and passed to the underlying graphics subsystem. During
183  *the evaluation pass, the Graphics Engine can detect and eliminate superfluous
184  * operations, the order of operations can be changed, or other optimization
185  * steps can be executed on the waiting drawing tasks.
186  *
187  * ELEMENTS:
188  * Newer,
189  * Older - References to the sibling surfaces within the surface cache.
190  * Owned - Usage counter to determine, whether the surface has an owner.
191  * As soon as the counter == 0, the surface is considered as ready for a
192  * new owner. Note, not owned surfaces may still be involved in pending
193  * drawing operations.
194  * Used - Usage counter to determine, whether the surface is involved in
195  * tasks pending for other surfaces or if it is helt by its owner. As long
196  * as the counter is > 0, the surface may not be released.
197  * Pending - Counter for completely composed but still waiting issues for this
198  * surface. As long as the counter > 0, there are incomplete drawing tasks
199  * with this surface as the destination.
200  * Owner - The owner in context of which the surface is stored. Usually this
201  * is a XBitmap.
202  * Tag1,
203  * Tag2 - Unique identification for the surface. Useful to find surfaces
204  * within the cache with the objective to reuse them.
205  * Format - Pixel format of the surface. (See EW_PIXEL_FORMAT_XXX).
206  * Width,
207  * Height - Size of the surface in pixel.
208  * MemSize - Estimated size of memory in bytes used to cover the surface.
209  * DoCache - Determines what to do when the surface is freed again. If this
210  * value is != 0, the surface will remain in the surface cache (if there
211  * is enough space in the cache). If this value is == 0, the surface is
212  * discarded automatically at the moment when it is freed.
213  * Stamp - Identifies the screen update, this surface has been used last
214  * time.
215  * Tasks - Issue currently in the drawing composition. The issue stores the
216  * drawing operations as a list of tasks.
217  * Handle - Reference to the real surface or to its video memory. This value
218  * depends on the underlying graphics subsystem.
219  *
220  *******************************************************************************/
221 typedef struct XSurface {
222  struct XSurface *Newer;
223  struct XSurface *Older;
224  int Owned;
225  int Used;
226  int Pending;
227  void *Owner;
228  unsigned long Tag1;
229  unsigned long Tag2;
230  short Format;
231  short Width;
232  short Height;
233  char Reserved[2];
234  int MemSize;
235  int DoCache;
236  int Stamp;
237  struct XIssue *Tasks;
238  unsigned long Handle;
239 } XSurface;
240 
241 /*******************************************************************************
242  * TYPE:
243  * XGlyph
244  *
245  * DESCRIPTION:
246  * The type XGlyph defines the structure to cover attributes and metrics of a
247  * glyph after it has been loaded into the global glyph cache surface. In this
248  * manner the glyphs can be handled by the Graphics Engine as areas of a
249  *simple surface - the text composition is performed by copying of these areas
250  *from the glyph cache surface into a destination surface. This is a convenient
251  *way to handle glyphs by the underlying graphics subsystem.
252  *
253  * The area allocation within the glyph cache surface is performed by a
254  *special kind of 2D memory manager. It ensures a fair surface occupation with
255  *as few as possible waste.
256  *
257  * ELEMENTS:
258  * Newer,
259  * Older - References to the sibling glyphs within the global glyph cache.
260  * Next,
261  * Prev - References to the sibling glyphs within the hashed glyph list.
262  * Used - Usage counter to determine, whether the glyph is involved in any
263  * tasks pending for other surfaces or if it is used by its owner. As long
264  * as the counter is > 0, the glyph may not be released.
265  * Font,
266  * CharCode - Unique identification for the glyph. Useful to find glyphs
267  *within the cache with the objective to reuse them. Width, Height - Size of
268  *the glyph in pixel (means the size of the ink-box). OriginX, OriginY - Upper
269  *left corner of the glyph, relative to the current printing position on the
270  *baseline. Advance - Advance in horizontal direction added to the printing
271  *position. CacheX, CacheY - The storage location of the glyph within the
272  *cache surface. Pixel - Option copy of the glyph pixel data in case of
273  *target systems where no read access to glyph cache surface is possible.
274  *
275  *******************************************************************************/
276 typedef struct XGlyph {
277  struct XGlyph *Newer;
278  struct XGlyph *Older;
279  struct XGlyph *Next;
280  struct XGlyph *Prev;
281  int Used;
282  unsigned long Font;
283  unsigned long CharCode;
284  short Width;
285  short Height;
286  short OriginX;
287  short OriginY;
288  short Advance;
289  short CacheX;
290  short CacheY;
291  char Reserved[2];
292  unsigned char *Pixel;
294 
295 /*******************************************************************************
296  * TYPE:
297  * XSurfaceLock
298  *
299  * DESCRIPTION:
300  * The XSurfaceLock structure provides information needed for the direct
301  *access to the memory of a previously locked surface. It includes the pointer
302  *to the pixel memory, the distance between two pixel rows, etc. In case of an
303  *Index8 surface, also the CLUT can be accessed directly.
304  *
305  * ELEMENTS:
306  * Memory - Descriptor containing pointers and distance information for the
307  * surface pixel and color table.
308  * X, Y,
309  * Width,
310  * Height - Surface area guaranteed by this lock. The access outside this area
311  * may cause an access violation. The area also serves as a hint to optimize
312  * and limit memory transfers to/from the video memory.
313  * Please note: The area is already expressed in coordinates valid within
314  *the surface by taking in account all particular configuration aspects like the
315  * default rotation of the surface content.
316  * Index,
317  * Count - Range of CLUT entries guaranteed by this lock. The access outside
318  * this range may cause an access violation. The range also serves as a hint
319  * to optimize and limit memory transfers to/from the video memory.
320  * Mode - Kind of operations, the user can perform on the locked memory.
321  *Mode also serves as a hint to optimize and limit memory transfers to/from the
322  * video memory. (See EW_LOCK_XXX).
323  * Handle - Reference to the real surface lock or to the temporarily allocated
324  * memory area. This value depends on the underlying graphics subsystem.
325  *
326  *******************************************************************************/
327 typedef struct {
328  XSurfaceMemory Memory;
329  short X;
330  short Y;
331  short Width;
332  short Height;
333  short Index;
334  short Count;
335  unsigned short Mode;
336  char Reserved[2];
337  unsigned long Handle;
338 } XSurfaceLock;
339 
340 /*******************************************************************************
341  * TYPE:
342  * XIssue
343  *
344  * DESCRIPTION:
345  * The XIssue structure incarnates the idea of a single drawing transaction,
346  * which in turn is composed of several different drawing tasks. The intention
347  * behind a transaction is to handle the enclosed tasks as a single entity.
348  *
349  * Beside this, the XIssue structure provides an own memory manager for the
350  * waiting drawing tasks. This management is realized as two separate heaps,
351  * which do share the same memory area. Whereas the lower heap occupies the
352  * lower address space of the memory area, the upper heap resides in the upper
353  * address space. The idea is to let grow the one heap against the other. The
354  * remaining gap between th both heaps is the empty still unused memory.
355  *
356  * ELEMENTS:
357  * List - Reference to a list, where this issue currently does belong to.
358  * The membership to a particular list determines the state of the issue.
359  * (issue is pending, running, finished, etc.)
360  * Next,
361  * Prev - References to the next/prev sibling issues within the same
362  *list. Surface - Destination surface affected by this issue. This is the
363  *surface, where the drawing operations take place. Tasks - Origin of a list
364  *of pending drawing operations prepared for this issue. The tasks will be
365  *reserved dynamically on the private upper heap of this issue. LowerHeap,
366  * UpperHeap - Pointers to the respective heap. The area between these both
367  * pointers is still free.
368  * UpperEnd - Upper end of the issue heap.
369  * Usage - Memory usage of the issue. The value is used for profiling
370  *only. Peak - Tracks the maxim. memory usage for the biggest task. The
371  *value is used for profiling only.
372  *
373  *******************************************************************************/
374 typedef struct XIssue {
375  struct XIssues *List;
376  struct XIssue *Next;
377  struct XIssue *Prev;
378  XSurface *Surface;
379  struct XTask *Tasks;
380  char *LowerHeap;
381  char *UpperHeap;
382  char *UpperEnd;
383  int Usage;
384  int Peak;
385 } XIssue;
386 
387 /*******************************************************************************
388  * TYPE:
389  * XIssues
390  *
391  * DESCRIPTION:
392  * The XIssues structure provides a mechanism to maintain of issues in a list.
393  * The order of the issues within the list reflects the order in which these
394  * issues will be evaluated, processed and finally freed.
395  *
396  * ELEMENTS:
397  * Head,
398  * Tail - References to the first and last issue within the list. The issues
399  * are stored in a chained list.
400  *
401  *******************************************************************************/
402 typedef struct XIssues {
403  XIssue *Head;
404  XIssue *Tail;
405 } XIssues;
406 
407 /*******************************************************************************
408  * TYPE:
409  * XTask
410  *
411  * DESCRIPTION:
412  * The XTask structure covers a single pending drawing task. The task
413  *describes the area affected by the drawing operation, the mode how to perform
414  *it and a set of additional operation dependent parameters for this task, like
415  *colors, source surfaces, glyphs, etc.
416  *
417  * Several tasks will be stored and managed together within so called issues.
418  * As soon as an issue becomes flushed, the enclosed tasks will be optimized
419  * and then executed.
420  *
421  * ELEMENTS:
422  * Next - Reference to the next pending task within the same issue.
423  * Token - Unique token to identify the kind of the drawing operation.
424  * (See EW_TASKID_XXX).
425  * Flags - Bitfield of options how to perform and optimize the drawing task.
426  * (See EW_TASK_XXX).
427  * X1, Y1,
428  * X2, Y2 - Area of the destination surface affected by the drawing
429  *operation. Data - Optional parameters for the drawing task.
430  *
431  *******************************************************************************/
432 typedef struct XTask {
433  struct XTask *Next;
434  short Token;
435  short Flags;
436  short X1;
437  short Y1;
438  short X2;
439  short Y2;
440  void *Data;
441 } XTask;
442 
443 /*******************************************************************************
444  * FUNCTION:
445  * EwInitGfxCore
446  *
447  * DESCRIPTION:
448  * The function EwInitGfxCore() initializes the Graphics Engine core module.
449  *
450  * ARGUMENTS:
451  * None
452  *
453  * RETURN VALUE:
454  * If successful, returns != 0.
455  *
456  *******************************************************************************/
457 int EwInitGfxCore(void);
458 
459 /*******************************************************************************
460  * FUNCTION:
461  * EwDoneGfxCore
462  *
463  * DESCRIPTION:
464  * The function EwDoneGfxCore() deinitializes the Graphics Engine core module.
465  * If necessary, the function discards all existing surfaces and frees the
466  * used resources.
467  *
468  * ARGUMENTS:
469  * None
470  *
471  * RETURN VALUE:
472  * None
473  *
474  *******************************************************************************/
475 void EwDoneGfxCore(void);
476 
477 /*******************************************************************************
478  * FUNCTION:
479  * EwCreateSurface
480  *
481  * DESCRIPTION:
482  * The function EwCreateSurface() creates a new surface with the given size
483  *and pixel format. The additional tag values serve for identification purpose
484  *and simplifies the reuse of previously freed surfaces -> see the
485  *EwFindSurface() function.
486  *
487  * In order to create a new surface, the function forwards the request to the
488  * underlying graphics subsystem. If the request could not be handled by the
489  * subsystem due to a resource deficit, the function tries to flush the caches
490  * and forces the processing of pending drawing operations until the subsystem
491  * can handle the request sucessfully. If all the adopted measures didn't help
492  * to handle the request, the function fails and returns null.
493  *
494  * The newly created surface passes into the ownership of the caller of this
495  * function. In order to release the surface, EwFreeSurface() should be used.
496  *
497  * ARGUMENTS:
498  * aFormat - Pixel format of the desired surface. (See EW_PIXEL_FORMAT_XXX).
499  * aWidth,
500  * aHeight - Size of the surface in pixel.
501  * aOwner - The owner in context of which the surface will be stored.
502  * aTag1,
503  * aTag2 - Unique identification for the surface.
504  *
505  * RETURN VALUE:
506  * If successful, EwCreateSurface() returns the new surface otherwise null is
507  * returned.
508  *
509  *******************************************************************************/
510 XSurface *EwCreateSurface(int aFormat, int aWidth, int aHeight, void *aOwner,
511  unsigned long aTag1, unsigned long aTag2);
512 
513 /*******************************************************************************
514  * FUNCTION:
515  * EwCreateConstSurface
516  *
517  * DESCRIPTION:
518  * The function EwCreateConstSurface() creates a new surface with the given
519  * size, pixel format and pixel information. Important here is the fact that
520  * the function doesn't reserve any memory to store the pixel information.
521  * Instead it, the surface associates the pixel data passed in the parameter
522  * aMemory.
523  *
524  * The additional tag values serve for identification purpose and simplifies
525  * the reuse of previously freed surfaces -> see the EwFindSurface() function.
526  *
527  * In order to create a new surface, the function forwards the request to the
528  * underlying graphics subsystem. If the request could not be handled by the
529  * subsystem due to a resource deficit, the function tries to flush the caches
530  * and forces the processing of pending drawing operations until the subsystem
531  * can handle the request sucessfully. If all the adopted measures didn't help
532  * to handle the request, the function fails and returns null.
533  *
534  * The newly created surface passes into the ownership of the caller of this
535  * function. In order to release the surface, EwFreeSurface() should be used.
536  *
537  * ARGUMENTS:
538  * aFormat - Pixel format of the desired surface. (See EW_PIXEL_FORMAT_XXX).
539  * aWidth,
540  * aHeight - Size of the surface in pixel.
541  * aOwner - The owner in context of which the surface will be stored.
542  * aTag1,
543  * aTag2 - Unique identification for the surface.
544  * aMemory - Structure to pass the ROM address information.
545  *
546  * RETURN VALUE:
547  * If successful, EwCreateSurface() returns the new surface otherwise null is
548  * returned.
549  *
550  *******************************************************************************/
551 XSurface *EwCreateConstSurface(int aFormat, int aWidth, int aHeight,
552  void *aOwner, unsigned long aTag1,
553  unsigned long aTag2, XSurfaceMemory *aMemory);
554 
555 /*******************************************************************************
556  * FUNCTION:
557  * EwFindSurface
558  *
559  * DESCRIPTION:
560  * The function EwFindSurface() searches the cache for an unused surface with
561  * the given parameters and if successfull, reactivates it. If no surface
562  * matches these parameters, the function fails and returns null.
563  *
564  * The found surface passes to the ownership of the caller of this function.
565  * In order to release the surface, EwFreeSurface() should be used.
566  *
567  * ARGUMENTS:
568  * aFormat - Pixel format of the desired surface. (See EW_PIXEL_FORMAT_XXX).
569  * aWidth,
570  * aHeight - Size of the surface in pixel.
571  * aOwner - The owner in context of which the surface will be stored after
572  * it has been found.
573  * aTag1,
574  * aTag2 - Unique identification for the surface.
575  *
576  * RETURN VALUE:
577  * If successful, EwFindSurface() returns the found surface otherwise null is
578  * returned.
579  *
580  *******************************************************************************/
581 XSurface *EwFindSurface(int aFormat, int aWidth, int aHeight, void *aOwner,
582  unsigned long aTag1, unsigned long aTag2);
583 
584 /*******************************************************************************
585  * FUNCTION:
586  * EwFreeSurface
587  *
588  * DESCRIPTION:
589  * The function EwFreeSurface() decrements the usage counter of the surface.
590  *If not involved in any other drawing operations the surface is considered as
591  *an unused surface.
592  *
593  * Freed surfaces do remain in the cache until they are reactivated or due to
594  *a resource deficit displaced from the video memory.
595  *
596  * ARGUMENTS:
597  * aSurface - Surface to free.
598  *
599  * RETURN VALUE:
600  * None
601  *
602  *******************************************************************************/
603 void EwFreeSurface(XSurface *aSurface);
604 
605 /*******************************************************************************
606  * FUNCTION:
607  * EwLockSurface
608  *
609  * DESCRIPTION:
610  * The function EwLockSurface() has the job to lock an area of the surface and
611  * to provide the caller with a pointer to the surface memory. In this manner
612  * the surface memory can be read and modified. After finishing the memory
613  * access, the surface should be unlocked again by calling EwUnlockSurface().
614  *
615  * Depending on the specified mode, the function may force the Graphics Engine
616  * to flush pending tasks and to wait for the surface if there are any pending
617  * tasks affecting the surface. To avoid this kind of synchronization, the
618  *flag EW_LOCK_DONT_WAIT should be set in the aMode parameter. Regardless of
619  *this additional flag, the underlying gryphics subsystem will always perform
620  *the necessary synchronisation steps in order to avoid any interferences with
621  * hardware executed drawing operations.
622  *
623  * The function fills the passed lock structure with the lock information.
624  *Here the caller will find a pointer to the pixel memory and the distance
625  *between two pixel rows. The memory returned by the function is not guaranteed
626  *to be the real video memory of the surface. If necessary, the function will
627  *handle the access by using a shadow memory area. Therefore to limit the effort
628  *of memory copy operations, the desired surface area and the access mode should
629  * be specified.
630  *
631  * If there was not possible to lock the surface, the function fails and
632  * returns zero.
633  *
634  * ARGUMENTS:
635  * aSurface - Surface to obtain the direct memory access.
636  * aX, aY,
637  * aWidth,
638  * aHeight - Limitation for the memory access to an area.
639  * aIndex,
640  * aCount - Range of CLUT entries to lock. This is for Index8 surfaces only.
641  * aMode - Desired access mode to the surface memory (see EW_LOCK_XXX).
642  * aLock - Pointer to a structure where the lock information will be
643  *stored.
644  *
645  * RETURN VALUE:
646  * If successful, the function returns != 0, otherwise 0 ist returned.
647  *
648  *******************************************************************************/
649 int EwLockSurface(XSurface *aSurface, int aX, int aY, int aWidth, int aHeight,
650  int aIndex, int aCount, unsigned short aMode,
651  XSurfaceLock *aLock);
652 
653 /*******************************************************************************
654  * FUNCTION:
655  * EwUnlockSurface
656  *
657  * DESCRIPTION:
658  * The function EwUnlockSurface() provides a counterpart of EwLockSurface().
659  * When called, the function releases the given lock and updates the affected
660  * surface. If necessary, the made modifications are transfered to the video
661  * memory of the surface.
662  *
663  * ARGUMENTS:
664  * aSurface - Surface to terminate the direct memory access.
665  * aLock - Lock descriptor initialized by the previous EwLockSurface()
666  *call.
667  *
668  * RETURN VALUE:
669  * None
670  *
671  *******************************************************************************/
672 void EwUnlockSurface(XSurface *aSurface, XSurfaceLock *aLock);
673 
674 /*******************************************************************************
675  * FUNCTION:
676  * EwCreateGlyph
677  *
678  * DESCRIPTION:
679  * The function EwCreateGlyph() creates a new glyph with the given size. The
680  * both additional font and charcode values serve for identification purpose
681  * and simplify the reuse of already existing glyphs.
682  *
683  * In order to create a new glyph, EwCreateGlyph() reserves an area within the
684  * global glyph cache surface. If there is no space available in this surface,
685  * the function forces the processing of still pending drawing operations and
686  * flushes the glyph cache. If all the adopted measures didn't help to attend
687  * the allocation, the function fails and returns null.
688  *
689  * The newly created glyph passes into the ownership of the caller. In order
690  * to release the glyph, EwFreeGlyph() should be used.
691  *
692  * ARGUMENTS:
693  * aWidth,
694  * aHeight - Size of the glyph in pixel.
695  * aFont,
696  * aCharCode - Unique identification for the glyph.
697  *
698  * RETURN VALUE:
699  * If successful, EwCreateGlyph() returns the new glyph otherwise null is
700  * returned.
701  *
702  *******************************************************************************/
703 XGlyph *EwCreateGlyph(int aWidth, int aHeight, unsigned long aFont,
704  unsigned long aCharCode);
705 
706 /*******************************************************************************
707  * FUNCTION:
708  * EwFindGlyph
709  *
710  * DESCRIPTION:
711  * The function EwFindGlyph() searches the glyph cache for a glyph matching
712  * the given font and charcode values. If no glyph could be found, the
713  *function fails and returns null.
714  *
715  * The found glyph passes to the ownership of the caller of this function. In
716  * order to release the glyph, EwFreeGlyph() should be used.
717  *
718  * ARGUMENTS:
719  * aFont,
720  * aCharCode - Unique identification for the glyph.
721  *
722  * RETURN VALUE:
723  * If successful, EwFindGlyph() returns the found glyph otherwise null is
724  * returned.
725  *
726  *******************************************************************************/
727 XGlyph *EwFindGlyph(unsigned long aFont, unsigned long aCharCode);
728 
729 /*******************************************************************************
730  * FUNCTION:
731  * EwFreeGlyph
732  *
733  * DESCRIPTION:
734  * The function EwFreeGlyph() decrements the usage counter of the glyph. If
735  *not involved in any other drawing operations the glyph is considered as
736  *unused.
737  *
738  * Freed glyphs do remain in the cache until they are used again or due to a
739  * resource deficit displaced from the video memory.
740  *
741  * ARGUMENTS:
742  * aGlyph - Glyph to free.
743  *
744  * RETURN VALUE:
745  * None
746  *
747  *******************************************************************************/
748 void EwFreeGlyph(XGlyph *aGlyph);
749 
750 /*******************************************************************************
751  * FUNCTION:
752  * EwDiscardGlyph
753  *
754  * DESCRIPTION:
755  * The function EwDiscardGlyph() forces the affected glyph to be removed from
756  * the glyph cache if the glyph is not iun use actually. Should the glyph be
757  * used, nothing happens.
758  *
759  * ARGUMENTS:
760  * aGlyph - Glyph to eventually discard.
761  *
762  * RETURN VALUE:
763  * None
764  *
765  *******************************************************************************/
766 void EwDiscardGlyph(XGlyph *aGlyph);
767 
768 /*******************************************************************************
769  * FUNCTION:
770  * EwLockGlyphCache
771  *
772  * DESCRIPTION:
773  * The function EwLockGlyphCache() provides a direct access to the pixel
774  *memory of the given glyph. In this manner the memory can be read and modified.
775  *When finishing the memory access, the glyph should be unlocked again by using
776  *the function EwUnlockGlyphCache().
777  *
778  * Because all glyphs are stored within the glyph cache surface, the request
779  * will be passed to the EwLockSurface() function, which in turn will lock the
780  * glyph area within the surface.
781  *
782  * Depending on the specified mode, the function may force the Graphics Engine
783  * to flush pending tasks and to wait for the glyph cache surface if there are
784  * pending tasks affecting the surface. To avoid this kind of synchronization,
785  * the flag EW_LOCK_DONT_WAIT should be set in the aMode parameter. Regardless
786  * of this additional flag, the underlying gryphics subsystem always performs
787  * the necessary synchronisation steps in order to avoid any interferences
788  *with hardware executed drawing operations.
789  *
790  * The function fills the passed lock structure with the lock information.
791  *Here the caller will find a pointer to the pixel memory and the distance
792  *between two pixel rows. The memory returned by the function is not guaranteed
793  *to be the real video memory of the surface. If necessary, the function will
794  *handle the access by using a shadow memory area. Therefore to limit the effort
795  *of memory copy operations, the desired access mode should be specified.
796  *
797  * If there was not possible to lock the glyph, the function fails and returns
798  * zero.
799  *
800  * ARGUMENTS:
801  * aGlyph - Glyph to obtain the direct memory access.
802  * aMode - Desired access mode to the glyph pixel memory (see EW_LOCK_XXX).
803  * aLock - Pointer to a structure where the lock information will be stored.
804  *
805  * RETURN VALUE:
806  * If successful, the function returns != 0, otherwise 0 is returned.
807  *
808  *******************************************************************************/
809 int EwLockGlyphCache(XGlyph *aGlyph, unsigned short aMode, XSurfaceLock *aLock);
810 
811 /*******************************************************************************
812  * FUNCTION:
813  * EwUnlockGlyphCache
814  *
815  * DESCRIPTION:
816  * The function EwUnlockGlyphCache() provides a counterpart to the function
817  * EwLockGlyphCache(). When called, the function releases the given lock and
818  * updates the global glyph cache surface. If necessary, the made
819  *modifications are transfered to the video memory of the surface.
820  *
821  * ARGUMENTS:
822  * aGlyph - Glyph to terminate the direct memory access.
823  * aLock - Lock descriptor initialized by the previous call to the function
824  * EwLockGlyphCache().
825  *
826  * RETURN VALUE:
827  * None
828  *
829  *******************************************************************************/
830 void EwUnlockGlyphCache(XGlyph *aGlyph, XSurfaceLock *aLock);
831 
832 /*******************************************************************************
833  * FUNCTION:
834  * EwInitIssue
835  *
836  * DESCRIPTION:
837  * The function EwInitIssue() introduces the preparation of a new drawing task
838  * for the specified surface. The surface will remain in this state until the
839  * function EwDoneIssue() has been invoked.
840  *
841  * EwInitIssue() ensures, that there is a valid issue attached to the surface.
842  * If necessary, new empty issue will be created. If no memory is available for
843  * new issues, the function forces the processing of pending drawing operations
844  * and flushes the caches.
845  *
846  * ARGUMENTS:
847  * aSurface - Surface to introduce the preparation of drawing tasks.
848  *
849  * RETURN VALUE:
850  * If successful, EwInitIssue() returns the desired issue otherwise null is
851  * returned.
852  *
853  *******************************************************************************/
854 XIssue *EwInitIssue(XSurface *aSurface);
855 
856 /*******************************************************************************
857  * FUNCTION:
858  * EwDoneIssue
859  *
860  * DESCRIPTION:
861  * The function EwDoneIssue() completes the preparation of drawing tasks for
862  *the specified surface.
863  *
864  * EwDoneIssue() can cause the issue to be flushed if the issue memory has been
865  * exhausted by the previously prepared tasks.
866  *
867  * ARGUMENTS:
868  * aSurface - Surface to complete the issue preparation.
869  *
870  * RETURN VALUE:
871  * None
872  *
873  *******************************************************************************/
874 void EwDoneIssue(XSurface *aSurface);
875 
876 /*******************************************************************************
877  * FUNCTION:
878  * EwAllocTask
879  *
880  * DESCRIPTION:
881  * The function EwAllocTask() has the job to reserve memory for a new drawing
882  * task and to incorporate it into the list of pending tasks of the specified
883  * issue. The memory reservation will take place on the upper heap area of the
884  * issue.
885  *
886  * If the parameter aCopyOf refers to an other task, the function initializes
887  * the new task with a copy of it and enqueues the task immediately after the
888  * original task. If there is no task to make a copy of it, the new task will
889  * remain uninitialized at the end of the list with pending tasks.
890  *
891  * If there is no memory to attend the task allocation, the function fails and
892  * returns null.
893  *
894  * ARGUMENTS:
895  * aIssue - Issue to attend the memory allocation.
896  * aCopyOf - Optional task to copy into the new task.
897  *
898  * RETURN VALUE:
899  * If succesful, EwAllocTask() returns a pointer to the new task otherwise
900  * null is returned.
901  *
902  *******************************************************************************/
903 XTask *EwAllocTask(XIssue *aIssue, XTask *aCopyOf);
904 
905 /*******************************************************************************
906  * FUNCTION:
907  * EwAllocTasks
908  *
909  * DESCRIPTION:
910  * The function EwAllocTasks() has the job to reserve memory for a set of new
911  * drawing tasks and to incorporate them into the list of pending tasks of the
912  * specified issue. The memory reservation will take place on the upper heap
913  * area of the issue.
914  *
915  * If the parameter aCopyOf refers to an other task, the function initializes
916  * the new tasks with a copy of it and enqueues the tasks immediately after the
917  * original task. If there is no task to make a copy of it, the new tasks will
918  * remain uninitialized at the end of the list with pending tasks.
919  *
920  * If there is no memory to attend the task allocation, the function fails and
921  * returns null.
922  *
923  * ARGUMENTS:
924  * aIssue - Issue to attend the memory allocation.
925  * aNoOfTasks - Number to tasks to allocate.
926  * aCopyOf - Optional task to copy into the new task.
927  *
928  * RETURN VALUE:
929  * If succesful, EwAllocTask() returns a pointer to the first task otherwise
930  * null is returned.
931  *
932  *******************************************************************************/
933 XTask *EwAllocTasks(XIssue *aIssue, int aNoOfTasks, XTask *aCopyOf);
934 
935 /*******************************************************************************
936  * FUNCTION:
937  * EwAllocTaskData
938  *
939  * DESCRIPTION:
940  * The function EwAllocTaskData() has the job to reserve a memory area for the
941  * parameters of a drawing task. The memory reservation will take place on the
942  * lower heap area of the specified issue.
943  *
944  * If there is no memory available to attend the allocation, the function fails
945  * and returns null.
946  *
947  * ARGUMENTS:
948  * aIssue - Issue to attend the memory allocation.
949  * aSize - Size of the memory to reserve.
950  *
951  * RETURN VALUE:
952  * If succesful, EwAllocTaskData() returns a pointer to the reserved memory
953  * area otherwise null is returned.
954  *
955  *******************************************************************************/
956 void *EwAllocTaskData(XIssue *aIssue, int aSize);
957 
958 /*******************************************************************************
959  * FUNCTION:
960  * EwFreeTaskData
961  *
962  * DESCRIPTION:
963  * The function EwFreeTaskData() has the job to shrink the memory area reserved
964  * by the preceding invocation of the EwAllocTaskData() call.
965  *
966  * ARGUMENTS:
967  * aIssue - Issue to attend the memory allocation.
968  * aPtr - Address specifying the new end of actually occupied memory area.
969  *
970  * RETURN VALUE:
971  * None
972  *
973  *******************************************************************************/
974 void EwFreeTaskData(XIssue *aIssue, void *aPtr);
975 
976 /*******************************************************************************
977  * FUNCTION:
978  * EwFlushTasks
979  *
980  * DESCRIPTION:
981  * The function EwFlushTasks() has the job to complete and flush the currently
982  * existing issue of the specified surface. If there is no open issue, nothing
983  * is done and the function returns to the caller.
984  *
985  * If 0 is passed for aSurface, the next available issue is flushed.
986  *
987  * ARGUMENTS:
988  * aSurface - Surface to flush the pending tasks.
989  *
990  * RETURN VALUE:
991  * Returns != 0, if an issue could be flushed.
992  *
993  *******************************************************************************/
994 int EwFlushTasks(XSurface *aSurface);
995 
996 /*******************************************************************************
997  * FUNCTION:
998  * EwWaitForSurface
999  *
1000  * DESCRIPTION:
1001  * The function EwWaitForSurface() ensures, that the surface is not involved in
1002  * any pending or running drawing operations. If necessary the function flushes
1003  * issues and waits until they are terminated. The last argument describes the
1004  * impact of the wait operation.
1005  *
1006  * ARGUMENTS:
1007  * aSurface - Surface to flush and finish its pending drawing operations.
1008  * aUntilUnused - If != 0, the function also waits until other operations are
1009  * done, which involve the surface as a source. If aUntilUnused == 0, only
1010  * the drawing operations affecting the surface as a destination are flushed
1011  * and finished.
1012  *
1013  * RETURN VALUE:
1014  * Returns != 0, if issues could be flushed.
1015  *
1016  *******************************************************************************/
1017 int EwWaitForSurface(XSurface *aSurface, int aUntilUnused);
1018 
1019 #ifdef __cplusplus
1020 }
1021 #endif
1022 
1023 #endif /* EWGFXCORE_H */
1024 
1025 /* pba */
XSurfaceMemory
Definition: ewgfxdriver.h:186
XSurface::Reserved
char Reserved[2]
Definition: ewgfxcore.h:293
EwAllocTasks
XTask * EwAllocTasks(XIssue *aIssue, int aNoOfTasks, XTask *aCopyOf)
XTask::X1
short X1
Definition: ewgfxcore.h:460
XIssues::Head
XIssue * Head
Definition: ewgfxcore.h:417
XTask
struct XTask XTask
XIssue::Usage
int Usage
Definition: ewgfxcore.h:416
XGlyph
struct XGlyph XGlyph
XGlyph::CharCode
unsigned long CharCode
Definition: ewgfxcore.h:317
EwDoneIssue
void EwDoneIssue(XSurface *aSurface)
XTask::Next
struct XTask * Next
Definition: ewgfxcore.h:457
EwCreateSurface
XSurface * EwCreateSurface(int aFormat, int aWidth, int aHeight, void *aOwner, unsigned long aTag1, unsigned long aTag2)
XGlyph::Advance
short Advance
Definition: ewgfxcore.h:322
XSurface::Height
short Height
Definition: ewgfxcore.h:292
XIssue::UpperHeap
char * UpperHeap
Definition: ewgfxcore.h:414
XIssue::Peak
int Peak
Definition: ewgfxcore.h:417
XIssues
Definition: ewgfxcore.h:402
XTask
Definition: ewgfxcore.h:432
XIssue
Definition: ewgfxcore.h:374
XGlyph
Definition: ewgfxcore.h:276
EwFreeGlyph
void EwFreeGlyph(XGlyph *aGlyph)
XIssues::Tail
XIssue * Tail
Definition: ewgfxcore.h:418
XGlyph::Width
short Width
Definition: ewgfxcore.h:318
XIssues
struct XIssues XIssues
XIssue
struct XIssue XIssue
EwInitIssue
XIssue * EwInitIssue(XSurface *aSurface)
EwAllocTask
XTask * EwAllocTask(XIssue *aIssue, XTask *aCopyOf)
XIssue::UpperEnd
char * UpperEnd
Definition: ewgfxcore.h:415
XSurface::Used
int Used
Definition: ewgfxcore.h:285
XSurface::Width
short Width
Definition: ewgfxcore.h:291
EwUnlockSurface
void EwUnlockSurface(XSurface *aSurface, XSurfaceLock *aLock)
XIssue::Surface
XSurface * Surface
Definition: ewgfxcore.h:411
EwUnlockGlyphCache
void EwUnlockGlyphCache(XGlyph *aGlyph, XSurfaceLock *aLock)
XIssue::Prev
struct XIssue * Prev
Definition: ewgfxcore.h:410
EwWaitForSurface
int EwWaitForSurface(XSurface *aSurface, int aUntilUnused)
EwFreeSurface
void EwFreeSurface(XSurface *aSurface)
XGlyph::CacheX
short CacheX
Definition: ewgfxcore.h:323
EwInitGfxCore
int EwInitGfxCore(void)
EwAllocTaskData
void * EwAllocTaskData(XIssue *aIssue, int aSize)
XGlyph::Height
short Height
Definition: ewgfxcore.h:319
XGlyph::CacheY
short CacheY
Definition: ewgfxcore.h:324
XIssue::LowerHeap
char * LowerHeap
Definition: ewgfxcore.h:413
XGlyph::Next
struct XGlyph * Next
Definition: ewgfxcore.h:313
EwDoneGfxCore
void EwDoneGfxCore(void)
XSurface::Older
struct XSurface * Older
Definition: ewgfxcore.h:283
XTask::Flags
short Flags
Definition: ewgfxcore.h:459
EwFreeTaskData
void EwFreeTaskData(XIssue *aIssue, void *aPtr)
XGlyph::Used
int Used
Definition: ewgfxcore.h:315
XIssue::List
struct XIssues * List
Definition: ewgfxcore.h:408
XSurface
struct XSurface XSurface
EwDiscardGlyph
void EwDiscardGlyph(XGlyph *aGlyph)
XSurface::Format
short Format
Definition: ewgfxcore.h:290
XIssue::Next
struct XIssue * Next
Definition: ewgfxcore.h:409
XSurface::MemSize
int MemSize
Definition: ewgfxcore.h:294
XGlyph::Font
unsigned long Font
Definition: ewgfxcore.h:316
XIssue::Tasks
struct XTask * Tasks
Definition: ewgfxcore.h:412
XTask::Y1
short Y1
Definition: ewgfxcore.h:461
XSurfaceLock
Definition: ewgfxcore.h:327
EwFlushTasks
int EwFlushTasks(XSurface *aSurface)
XGlyph::Pixel
unsigned char * Pixel
Definition: ewgfxcore.h:326
XSurface::Tasks
struct XIssue * Tasks
Definition: ewgfxcore.h:297
XTask::Token
short Token
Definition: ewgfxcore.h:458
XSurface::Stamp
int Stamp
Definition: ewgfxcore.h:296
XGlyph::Reserved
char Reserved[2]
Definition: ewgfxcore.h:325
XSurface::Pending
int Pending
Definition: ewgfxcore.h:286
XSurface
Definition: ewgfxcore.h:221
EwFindSurface
XSurface * EwFindSurface(int aFormat, int aWidth, int aHeight, void *aOwner, unsigned long aTag1, unsigned long aTag2)
XGlyph::Prev
struct XGlyph * Prev
Definition: ewgfxcore.h:314
XGlyph::Older
struct XGlyph * Older
Definition: ewgfxcore.h:312
XGlyph::OriginY
short OriginY
Definition: ewgfxcore.h:321
XTask::Y2
short Y2
Definition: ewgfxcore.h:463
XSurface::Tag2
unsigned long Tag2
Definition: ewgfxcore.h:289
EwFindGlyph
XGlyph * EwFindGlyph(unsigned long aFont, unsigned long aCharCode)
XSurface::Newer
struct XSurface * Newer
Definition: ewgfxcore.h:282
EwLockGlyphCache
int EwLockGlyphCache(XGlyph *aGlyph, unsigned short aMode, XSurfaceLock *aLock)
EwCreateConstSurface
XSurface * EwCreateConstSurface(int aFormat, int aWidth, int aHeight, void *aOwner, unsigned long aTag1, unsigned long aTag2, XSurfaceMemory *aMemory)
XTask::X2
short X2
Definition: ewgfxcore.h:462
XGlyph::OriginX
short OriginX
Definition: ewgfxcore.h:320
XSurface::Owner
void * Owner
Definition: ewgfxcore.h:287
XSurface::Handle
unsigned long Handle
Definition: ewgfxcore.h:298
XTask::Data
void * Data
Definition: ewgfxcore.h:464
EwCreateGlyph
XGlyph * EwCreateGlyph(int aWidth, int aHeight, unsigned long aFont, unsigned long aCharCode)
XSurface::DoCache
int DoCache
Definition: ewgfxcore.h:295
XSurface::Owned
int Owned
Definition: ewgfxcore.h:284
XGlyph::Newer
struct XGlyph * Newer
Definition: ewgfxcore.h:311
XSurface::Tag1
unsigned long Tag1
Definition: ewgfxcore.h:288
EwLockSurface
int EwLockSurface(XSurface *aSurface, int aX, int aY, int aWidth, int aHeight, int aIndex, int aCount, unsigned short aMode, XSurfaceLock *aLock)