Back to index

lightning-sunbird  0.9+nobinonly
Classes | Public Member Functions | Private Attributes
SolidBrushCache Class Reference
Collaboration diagram for SolidBrushCache:
Collaboration graph
[legend]

List of all members.

Classes

struct  CacheEntry

Public Member Functions

 SolidBrushCache ()
 ~SolidBrushCache ()
HBRUSH GetSolidBrush (HDC theHDC, COLORREF aColor)

Private Attributes

CacheEntry mCache [BRUSH_CACHE_SIZE]
int mIndexOldest

Detailed Description

Definition at line 2524 of file nsRenderingContextWin.cpp.


Class Documentation

struct SolidBrushCache::CacheEntry

Definition at line 2532 of file nsRenderingContextWin.cpp.

Class Members
HBRUSH mBrush
COLORREF mBrushColor

Constructor & Destructor Documentation

Definition at line 2541 of file nsRenderingContextWin.cpp.

  : mIndexOldest(2)
{
  // First two entries are stock objects
  mCache[0].mBrush = gStockWhiteBrush;
  mCache[0].mBrushColor = RGB(255, 255, 255);
  mCache[1].mBrush = (HBRUSH)::GetStockObject(BLACK_BRUSH);
  mCache[1].mBrushColor = RGB(0, 0, 0);
}

Definition at line 2551 of file nsRenderingContextWin.cpp.

{
  // No need to delete the stock objects
  for (int i = 2; i < BRUSH_CACHE_SIZE; i++) {
    if (mCache[i].mBrush) {
      ::DeleteObject(mCache[i].mBrush);
    }
  }
}

Member Function Documentation

HBRUSH SolidBrushCache::GetSolidBrush ( HDC  theHDC,
COLORREF  aColor 
)

Definition at line 2562 of file nsRenderingContextWin.cpp.

{
  int     i;
  HBRUSH  result = NULL;
  
  // See if it's already in the cache
  for (i = 0; (i < BRUSH_CACHE_SIZE) && mCache[i].mBrush; i++) {
    if (mCache[i].mBrush && (mCache[i].mBrushColor == aColor)) {
      // Found an existing brush
      result = mCache[i].mBrush;
      ::SelectObject(theHDC, result);
      break;
    }
  }

  if (!result) {
    // We didn't find it in the set of existing brushes, so create a
    // new brush
    result = (HBRUSH)::CreateSolidBrush(PALETTERGB_COLORREF(aColor));

    // Select the brush.  NOTE: we want to select the new brush before
    // deleting the old brush to prevent any win98 GDI leaks (bug 159298)
    ::SelectObject(theHDC, result);

    // If there's an empty slot in the cache, then just add it there
    if (i >= BRUSH_CACHE_SIZE) {
      // Nope. The cache is full so we need to replace the oldest entry
      // in the cache
      ::DeleteObject(mCache[mIndexOldest].mBrush);
      i = mIndexOldest;
      if (++mIndexOldest >= BRUSH_CACHE_SIZE) {
        mIndexOldest = 2;
      }
    }

    // Add the new entry
    mCache[i].mBrush = result;
    mCache[i].mBrushColor = aColor;
  }

  return result;
}

Here is the caller graph for this function:


Member Data Documentation

Definition at line 2537 of file nsRenderingContextWin.cpp.

Definition at line 2538 of file nsRenderingContextWin.cpp.


The documentation for this class was generated from the following file: