Changeset 70


Ignore:
Timestamp:
May 20, 2001, 5:38:55 PM (24 years ago)
Author:
umoeller
Message:

misc updates

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/helpers/gpih.h

    r64 r70  
    235235    typedef GPIHICON2BITMAP *PGPIHICON2BITMAP;
    236236
     237    /* ******************************************************************
     238     *
     239     *   XBitmap functions
     240     *
     241     ********************************************************************/
     242
     243    /*
     244     *@@ XBITMAP:
     245     *      representation of an XBitmap, which is created
     246     *      with gpihCreateXBitmap and destroyed with
     247     *      gpihDestroyXBitmap.
     248     *
     249     *      An XBitmap is essentially a set of a memory
     250     *      device context, a memory presentation space,
     251     *      and a bitmap which is selected into that
     252     *      HPS.
     253     *
     254     *@@added V0.9.12 (2001-05-20) [umoeller]
     255     */
     256
     257    typedef struct _XBITMAP
     258    {
     259        HDC     hdcMem;     // memory DC
     260        HPS     hpsMem;     // memory PS
     261        HBITMAP hbm;        // bitmap handle
     262        SIZEL   szl;        // size of bitmap
     263    } XBITMAP, *PXBITMAP;
     264
     265    PXBITMAP XWPENTRY gpihCreateXBitmap(HAB hab, LONG cx, LONG cy);
     266    typedef PXBITMAP XWPENTRY GPIHCREATEXBITMAP(HAB hab, LONG cx, LONG cy);
     267    typedef GPIHCREATEXBITMAP *PGPIHCREATEXBITMAP;
     268
     269    VOID XWPENTRY gpihDestroyXBitmap(PXBITMAP *ppbmp);
     270    typedef VOID XWPENTRY GPIHDESTROYXBITMAP(PXBITMAP *ppbmp);
     271    typedef GPIHDESTROYXBITMAP *PGPIHDESTROYXBITMAP;
     272
    237273#endif
    238274
  • trunk/include/helpers/threads.h

    r49 r70  
    4747            ULONG   cbStruct;
    4848            void*   pThreadFunc;    // as passed to thrCreate, really a PTHREADFUNC
    49             PBOOL   pfRunning;      // as passed to thrCreate
     49            PULONG  ptidRunning;      // as passed to thrCreate V0.9.12 (2001-05-20) [umoeller]
    5050            const char *pcszThreadName; // as passed to thrCreate
    5151            ULONG   flFlags;        // as passed to thrCreate
     
    5858            HAB     hab;            // for PM threads
    5959            HMQ     hmq;            // for PM threads
    60             BOOL    fExitComplete;  // TRUE if thr_fntGeneric is exiting
     60            BOOL    fExitComplete;
    6161
    6262            // data to be maintained by application
  • trunk/src/helpers/gpih.c

    r63 r70  
    14791479        bih2.usReserved = 0;
    14801480        bih2.usRecording = BRA_BOTTOMUP;        // scan lines are bottom to top (default)
    1481         bih2.usRendering = BRH_NOTHALFTONED;    // other algorithms aren't documented anyways
    1482         bih2.cSize1 = 0;            // parameter for halftoning (undocumented anyways)
    1483         bih2.cSize2 = 0;            // parameter for halftoning (undocumented anyways)
     1481        bih2.usRendering = BRH_NOTHALFTONED;    // other algorithms aren't documented anyway
     1482        bih2.cSize1 = 0;            // parameter for halftoning (undocumented anyway)
     1483        bih2.cSize2 = 0;            // parameter for halftoning (undocumented anyway)
    14841484        bih2.ulColorEncoding = BCE_RGB;     // only possible value
    14851485        bih2.ulIdentifier = 0;              // application-specific data
     
    15451545 *      which can then be used for WinDrawBitmap and such, or
    15461546 *      NULLHANDLE upon errors.
     1547 *
     1548 *@@changed V0.9.12 (2001-05-20) [umoeller]: fixed excessive mem PS size
    15471549 */
    15481550
     
    15641566    POINTL aptl[3];
    15651567
    1566     SIZEL szlPage = {0, 0};
    1567     if (gpihCreateMemPS(hab, &szlPage, &hdcMem, &hpsMem))
     1568    SIZEL szlPage = {prcl->xRight - prcl->xLeft,
     1569                     prcl->yTop - prcl->yBottom};       // fixed V0.9.12 (2001-05-20) [umoeller]
     1570    if (gpihCreateMemPS(hab,
     1571                        &szlPage,
     1572                        &hdcMem,
     1573                        &hpsMem))
    15681574    {
    15691575        if ((hbm = gpihCreateBitmap(hpsMem,
    1570                                     prcl->xRight - prcl->xLeft,
    1571                                     prcl->yTop - prcl->yBottom)))
     1576                                    szlPage.cx,
     1577                                    szlPage.cy)))
    15721578        {
    15731579            // Associate the bit map and the memory presentation space.
     
    15951601                    hbm = NULLHANDLE; // for return code
    15961602                }
    1597             } else {
     1603            }
     1604            else
     1605            {
    15981606                // error selecting bitmap for hpsMem:
    15991607                GpiDeleteBitmap(hbm);
     
    20192027}
    20202028
     2029/*
     2030 *@@category: Helpers\PM helpers\GPI helpers\XBitmaps
     2031 *      Extended bitmaps. See gpihCreateXBitmap for an introduction.
     2032 */
     2033
     2034/* ******************************************************************
     2035 *
     2036 *   XBitmap functions
     2037 *
     2038 ********************************************************************/
     2039
     2040/*
     2041 *@@ gpihCreateXBitmap:
     2042 *      creates an XBitmap, which is returned in an
     2043 *      _XBITMAP structure.
     2044 *
     2045 *      The problem with all the GPI bitmap functions
     2046 *      is that they are quite complex and it is easy
     2047 *      to forget one of the "disassociate" and "deselect"
     2048 *      functions, which then simply leads to enormous
     2049 *      resource leaks in the application.
     2050 *
     2051 *      This function may relieve this a bit. This
     2052 *      creates a memory DC, an memory PS, and a bitmap,
     2053 *      and selects the bitmap into the memory PS.
     2054 *      You can then use any GPI function on the memory
     2055 *      PS to draw into the bitmap. Use the fields from
     2056 *      _XBITMAP for that.
     2057 *
     2058 *      The bitmap is created in RGB mode.
     2059 *
     2060 *      Use gpihDestroyXBitmap to destroy the XBitmap
     2061 *      again.
     2062 *
     2063 *      Example:
     2064 *
     2065 +          PXBITMAP pbmp = gpihCreateXBitmap(hab, 100, 100);
     2066 +          if (pbmp)
     2067 +          {
     2068 +              GpiMove(pbmp->hpsMem, ...);
     2069 +              GpiBox(pbmp->hpsMem, ...);
     2070 +
     2071 +              WinDrawBitmap(hpsScreen,
     2072 +                            pbmp->hbm,       // bitmap handle
     2073 +                            ...);
     2074 +              gpihDestroyXBitmap(&pbmp);
     2075 +          }
     2076 *
     2077 *      Without the gpih* functions, the above would expand
     2078 *      to more than 100 lines.
     2079 *
     2080 *@@added V0.9.12 (2001-05-20) [umoeller]
     2081 */
     2082
     2083PXBITMAP gpihCreateXBitmap(HAB hab,         // in: anchor block
     2084                           LONG cx,         // in: bitmap width
     2085                           LONG cy)         // in: bitmap height
     2086{
     2087    BOOL fOK = FALSE;
     2088    PXBITMAP pbmp = (PXBITMAP)malloc(sizeof(XBITMAP));
     2089    if (pbmp)
     2090    {
     2091        memset(pbmp, 0, sizeof(XBITMAP));
     2092
     2093        // create memory PS for bitmap
     2094        pbmp->szl.cx = cx;
     2095        pbmp->szl.cy = cy;
     2096        if (gpihCreateMemPS(hab,
     2097                            &pbmp->szl,
     2098                            &pbmp->hdcMem,
     2099                            &pbmp->hpsMem))
     2100        {
     2101            gpihSwitchToRGB(pbmp->hpsMem);
     2102            if (pbmp->hbm = gpihCreateBitmap(pbmp->hpsMem,
     2103                                             cx,
     2104                                             cy))
     2105            {
     2106                if (GpiSetBitmap(pbmp->hpsMem,
     2107                                 pbmp->hbm)
     2108                        != HBM_ERROR)
     2109                    fOK = TRUE;
     2110            }
     2111        }
     2112
     2113        if (!fOK)
     2114            gpihDestroyXBitmap(&pbmp);
     2115    }
     2116
     2117    return (pbmp);
     2118}
     2119
     2120/*
     2121 *@@ gpihDestroyXBitmap:
     2122 *      destroys an XBitmap created with gpihCreateXBitmap.
     2123 *
     2124 *      To be on the safe side, this sets the
     2125 *      bitmap pointer to NULL as well.
     2126 *
     2127 *@@added V0.9.12 (2001-05-20) [umoeller]
     2128 */
     2129
     2130VOID gpihDestroyXBitmap(PXBITMAP *ppbmp)
     2131{
     2132    if (ppbmp)
     2133    {
     2134        PXBITMAP pbmp;
     2135        if (pbmp = *ppbmp)
     2136        {
     2137            if (pbmp->hbm)
     2138            {
     2139                if (pbmp->hpsMem)
     2140                    GpiSetBitmap(pbmp->hpsMem, NULLHANDLE);
     2141                GpiDeleteBitmap(pbmp->hbm);
     2142            }
     2143            if (pbmp->hpsMem)
     2144            {
     2145                GpiAssociate(pbmp->hpsMem, NULLHANDLE);
     2146                GpiDestroyPS(pbmp->hpsMem);
     2147            }
     2148            if (pbmp->hdcMem)
     2149                DevCloseDC(pbmp->hdcMem);
     2150
     2151            free(pbmp);
     2152
     2153            *ppbmp = NULL;
     2154        }
     2155    }
     2156}
     2157
     2158
  • trunk/src/helpers/threads.c

    r52 r70  
    130130    if (pti)
    131131    {
    132         if (pti->pfRunning)
    133             // set "running" flag
    134             *(pti->pfRunning) = TRUE;
    135 
    136132        if (pti->flFlags & THRF_WAIT)
    137133            // "Wait" flag set: thrCreate is then
     
    174170        }
    175171
    176         // for non-transient threads: set exit flags
     172        // set exit flags
    177173        // V0.9.7 (2000-12-20) [umoeller]
    178174        pti->fExitComplete = TRUE;
    179175        pti->tid = NULLHANDLE;
    180176
    181         if (pti->pfRunning)
     177        if (pti->ptidRunning)
    182178            // clear "running" flag
    183             *(pti->pfRunning) = FALSE;
     179            *(pti->ptidRunning) = 0;
    184180
    185181        // (2000-12-18) [lafaix] clean up pti if thread is transient.
     
    213209 *      The thread's ptiMyself is then a pointer to the
    214210 *      THREADINFO structure passed to this function.
    215  *      ulData may be obtained like this:
     211 *      In your thread function, ulData may be obtained like this:
    216212 *
    217213 +          ULONG ulData = ptiMyself->ulData;
    218214 *
    219  *      The THREADINFO structure passed to this function must
    220  *      be accessible all the time while the thread is running
    221  *      because the thr* functions will use it for maintenance.
    222  *
    223  *      This function does NOT check whether a thread is
    224  *      already running in *pti. Do not use the same THREADINFO
    225  *      for several threads.
    226  *
    227  *      If you do not want to manage the structure yourself,
    228  *      you can pass the THRF_TRANSIENT flag (see below).
    229  *
    230  *      thrCreate does not call your thread func directly,
     215 *      thrCreate does not start your thread func directly,
    231216 *      but only through the thr_fntGeneric wrapper to
    232217 *      provide additional functionality. As a consequence,
     
    235220 *      (cleanup) in thr_fntGeneric. Instead, just fall out of
    236221 *      your thread function, or return().
     222 *
     223 *      The THREADINFO structure passed to this function must
     224 *      be accessible all the time while the thread is running
     225 *      because the thr* functions will use it for maintenance.
     226 *      This function does NOT check whether a thread is
     227 *      already running in *pti. Do not use the same THREADINFO
     228 *      for several threads.
     229 *
     230 *      If you do not want to manage the structure yourself,
     231 *      you can pass the THRF_TRANSIENT flag (see below).
     232 *
     233 *      ptidRunning is an optional parameter and can be NULL.
     234 *      If non-null, it must point to a ULONG which will contain
     235 *      the thread's TID while the thread is still running.
     236 *      Once the thread exits, the ULONG will automatically
     237 *      be set to zero; this is useful for a quick check whether
     238 *      the thread is currently busy.
     239 *
     240 *      Note: ptidRunning is only reliable if you set the
     241 *      THRF_WAIT or THRF_WAIT_EXPLICIT flags.
    237242 *
    238243 *      flFlags can be any combination of the following:
     
    252257 *
    253258 *      -- THRF_WAIT_EXPLICIT: like THRF_WAIT, but in this case,
    254  *         your thread function must post THREADINFO.hevRunning
     259 *         your thread function _must_ post THREADINFO.hevRunning
    255260 *         yourself (thr_fntGeneric will not automatically
    256261 *         post it). Useful for waiting until your own thread
     
    282287 *@@changed V0.9.9 (2001-03-07) [umoeller]: added pcszThreadName
    283288 *@@changed V0.9.9 (2001-03-14) [umoeller]: added THRF_WAIT_EXPLICIT
     289 *@@changed V0.9.12 (2001-05-20) [umoeller]: changed pfRunning to ptidRunning
    284290 */
    285291
    286292ULONG thrCreate(PTHREADINFO pti,     // out: THREADINFO data
    287293                PTHREADFUNC pfn,     // in: _Optlink thread function
    288                 PBOOL pfRunning,     // out: variable set to TRUE while thread is running;
     294                PULONG ptidRunning,  // out: variable set to TID while thread is running;
    289295                                     // ptr can be NULL
    290296                const char *pcszThreadName, // in: thread name (for identification)
     
    307313        pti->cbStruct = sizeof(THREADINFO);
    308314        pti->pThreadFunc = (PVOID)pfn;
    309         pti->pfRunning = pfRunning;
     315        pti->ptidRunning = ptidRunning;
    310316        pti->pcszThreadName = pcszThreadName; // V0.9.9 (2001-03-07) [umoeller]
    311317        pti->flFlags = flFlags;
     
    336342                                    pti);   // parameter passed to thread
    337343            ulrc = pti->tid;
     344
     345            if (pti->ptidRunning)
     346                // set "running" flag // V0.9.12 (2001-05-20) [umoeller]
     347                *(pti->ptidRunning) = pti->tid;
    338348
    339349            if (ulrc)
Note: See TracChangeset for help on using the changeset viewer.