home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / windows / x / i386unix / 120 < prev    next >
Encoding:
Text File  |  1992-12-22  |  6.9 KB  |  196 lines

  1. Newsgroups: comp.windows.x.i386unix
  2. Path: sparky!uunet!enterpoop.mit.edu!bloom-picayune.mit.edu!athena.mit.edu!dmatic
  3. From: dmatic@athena.mit.edu (Davor Matic)
  4. Subject: Customizable mfb Proposal
  5. Message-ID: <1992Dec22.174633.9453@athena.mit.edu>
  6. Sender: news@athena.mit.edu (News system)
  7. Nntp-Posting-Host: w20-575-73.mit.edu
  8. Organization: Massachusetts Institute of Technology
  9. Date: Tue, 22 Dec 1992 17:46:33 GMT
  10. Lines: 184
  11.  
  12. ----------------------
  13.  
  14.  
  15. If anyone is interested in doing this, has commenst and/or suggestions,
  16. please reply...
  17.  
  18.  
  19.  
  20. Customizable Monochrome Frame Buffer [cmfb] by Davor Matic
  21.  
  22. This is a proposal on how to make the current mfb implementation more
  23. customizable with a minimal loss of performance.  The objective is to
  24. create a monochrome frame buffer library that can be easily ported to
  25. architectures which feature frame buffers that are either not directly
  26. addressable or directly mapped.  This will not cover frame buffers
  27. which are managed by graphics coprocessors.
  28.  
  29. The basic problem with the current mfb implementation is that it
  30. assumes that the frame buffer is directly accessible and directly
  31. mapped.  This is also a great strength of the current mfb
  32. implementation, since no distinction is made between the internal
  33. representation of pixmaps and external representation of the frame
  34. buffer which account for superior speed and performance.  In the
  35. attempt to make mfb customizable, we need to preserve the performance
  36. as much as possible.  In order to successfully achieve this goal, I
  37. suggest the following approach in customizing mfb.
  38.  
  39. Step 1.
  40.  
  41. The current implementation of mfb can be macroized with fairly
  42. reasonable amount of work.  We need to introduce macros that intercept
  43. all references to the frame buffer.  There needs to be a distinction
  44. between references that read a word from the buffer, write a word into
  45. the buffer, or do both operations in a sequence.  This distinction is
  46. needed for directionally banked frame buffers.  Therefore, we will
  47. introduce the following three mapping macros:
  48.  
  49.     #define  MAPR(ptr)  ((unsigned long *)(ptr))
  50.     #define  MAPW(ptr)  ((unsigned long *)(ptr))
  51.     #define  MAPRW(ptr) ((unsigned long *)(ptr))
  52.  
  53. The next step is to replace direct references to the frame buffer with
  54. the mapping macros.  Sometimes it will be impossible to distinguish
  55. between references to internal bitmaps and references to the frame
  56. buffer at this stage.  On the other hand, if a reference can not yield
  57. an access to the frame buffer, such as reading tiles which can only be
  58. pixmaps, we shall not use the mapping macros.  An example of these
  59. modifications is below:
  60.  
  61.     *pdst = *psrc & mask;    
  62.     becomes
  63.     *MAPW(pdst) = *MAPR(psrc) & mask;
  64.  
  65.     and
  66.  
  67.     *pdst &= mask;
  68.     becomes
  69.     *MAPRW(pdst) &= mask;
  70.  
  71.     and 
  72.  
  73.     src = psrc[-n];
  74.     becomes
  75.     src = *MAPR(&(psrc[-n]));
  76.  
  77.     and
  78.     
  79.     *pdst++ = *psrc++;
  80.     becomes
  81.     *MAPW(pdst) = *MAPR(psrc); pdst++; psrc++;
  82.  
  83. This last example is the only modification to the current
  84. implementation of mfb that is visible after expanding the above
  85. defined mapping macros.  I doubt that this would harm performance of
  86. the code in any way.  After we have completed this stage, mfb should
  87. work just as well as the original one without any difference in
  88. behaviour.  This will be a good test for the new code.
  89.  
  90. Step 2
  91.  
  92. In this step, we will exercise the mapping macros.  Since at this
  93. point the code is quite unintelligent about distinguishing references
  94. to pixmaps from references to windows, it will be slow.  The speed
  95. considerations will be addressed in steps 3 and 4.
  96.  
  97. At this point, our macroized mfb is ready to be used with a mapped
  98. and/or banked frame buffer.  All we need to do is redefine the mapping
  99. macros to perform appropriate actions.  When initializing mfb, we pass
  100. it a very high pointer as a virtual frame buffer pointer, and redefine
  101. mapping macros to trap on the pointers with higher values than the
  102. virtual frame buffer pointer.  If we see a higher value than the
  103. virtual frame buffer pointer, we know that mfb is referencing the
  104. screen rather an internal pixmap.  Thus we do something like the
  105. following:
  106.  
  107.     #define VIRT_FBP   0xFF000000
  108.  
  109.     unsigned long *virt_to_real_mapping[];
  110.  
  111.     #define MAPR(ptr) \
  112.         ((unsigned long *) \
  113.          ((ptr) > VIRT_FBP ? \
  114.           virt_to_real_mapping[(ptr) - VIRT_FBP] : \
  115.           (ptr)))
  116.  
  117.     #define MAPW(ptr)  MAPR(ptr)
  118.     #define MAPRW(ptr) MAPR(ptr)
  119.  
  120. When we get this to work properly, we can go to the next step.  Or we
  121. can stop here is we get too frustrated and don't wanna bother with
  122. performance.
  123.  
  124. Step 3
  125.  
  126. Now, we are ready to concern ourselves with performance issues.  The
  127. basic idea is to generate four different sorts of functions form each
  128. previously defined function.  Each function kind will be called with
  129. the right type of source and destination drawable.  We don't need to
  130. write any new code to generate these functions.  All we need to do is
  131. macroize the function names, make symbolic links to the the original
  132. code, and compile each function with a different set macro
  133. definitions.  This is already done in mfb for drawing function that
  134. use different raster operations.
  135.  
  136. Thus, we will have usually two, or sometimes four new functions for
  137. each old function from mfb.  Here is the example:
  138.  
  139.     mfbSegmentSS()
  140.     becomes
  141.         mfbSegmentSSBmp() 
  142.     and mfbSegmentSSWin()
  143.  
  144.     and
  145.  
  146.     mfbCopyArea()
  147.     becomes 
  148.         mfbCopyAreaBmpBmp() 
  149.     and mfbCopyAreaBmpWin() 
  150.     and mfbCopyAreaWinBmp() 
  151.     and mfbCopyAreaWinWin()
  152.  
  153. This simply means that each function performs operations on the
  154. drawable types specified in the function name.  For mfbSegmentSS(),
  155. all we need to do is compile it with dummy mapping functions to get
  156. mfbSegmentSSBmp(), and compile it with appropriate mapping functions
  157. to get mfbSegmentSSWin().  In the case of mfbCopyArea(), we need to
  158. separate the mapping functions into two kinds.  One kind references
  159. the source drawablle, and the other references the source drawable.
  160. This is a trivial change, but it will have to be done manually.  Thus:
  161.  
  162.     MAPR()  becomes  MAPSRCR()  and MAPDSTR()
  163.     MAPW()  becomes  MAPSRCW()  and MAPDSTW()
  164.     MAPRW() becomes  MAPSRCRW() and MAPDSTRW()
  165.  
  166. In order to get mfbCopyAreaBmpBmp(), both, MAPSRCX and MAPDSTX
  167. mappings are the dummy macros.  For mfbCopyAreaBmpWin(), the MAPSRCX
  168. are the dummy macros, while MAPDSTX are the appropriate mapping
  169. macros, etc.  Finally, we add top level procedures called the original
  170. mfb names that perform checks on the drawable types and discriminantly
  171. call the appropriate routines.  At this point, mfb should still
  172. perform all the functions of the mfb from previous step, so we can
  173. debug it against that code.
  174.  
  175. Step 4
  176.  
  177. At this point, the mapping macros will be engaged only if indeed mfb
  178. is referencing the frame buffer, and never called when mfb is
  179. referencing an internal pixmap.  Now, we can drop the check against
  180. the virtual frame buffer pointer from the mapping macros:
  181.  
  182.     #define VIRT_FBP 0L
  183.  
  184.     #define MAPDSTR(ptr) \
  185.         ((unsigned long *) \
  186.          virt_to_real_mapping[(ptr)])
  187.  
  188. Step 5
  189.  
  190. Rename all the function prefixes to cmfb, build the appropriate
  191. Imakefile, and we have completed the customizable monochrome frame
  192. buffer library.
  193.  
  194.  
  195.  
  196.