Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes
nsGCCacheXlib Class Reference

#include <nsGCCache.h>

List of all members.

Public Member Functions

 nsGCCacheXlib ()
virtual ~nsGCCacheXlib ()
void Flush (unsigned long flags)
xGCGetGC (Display *display, Window window, unsigned long flags, XGCValues *gcv, Region clipRegion)

Private Member Functions

void ReuseGC (GCCacheEntryXlib *entry, unsigned long flags, XGCValues *gcv)
void free_cache_entry (PRCList *clist)
void move_cache_entry (PRCList *clist)
void ReportStats ()

Static Private Member Functions

static void XCopyRegion (Region src, Region dr_return)

Private Attributes

PRCList GCCache
PRCList GCFreeList

Static Private Attributes

static Region copyRegion = 0

Detailed Description

Definition at line 118 of file nsGCCache.h.


Constructor & Destructor Documentation

Definition at line 53 of file nsGCCache.cpp.

{
  PR_INIT_CLIST(&GCCache);
  PR_INIT_CLIST(&GCFreeList);
  for (int i = 0; i < GC_CACHE_SIZE; i++) {
    GCCacheEntryXlib *entry = new GCCacheEntryXlib();
    entry->gc=NULL;
    PR_INSERT_LINK(&entry->clist, &GCFreeList);
  }
  DEBUG_METER(memset(&GCCacheStats, 0, sizeof(GCCacheStats));)
}

Here is the call graph for this function:

Definition at line 87 of file nsGCCache.cpp.

{
  PRCList *head;

  ReportStats();

  while (!PR_CLIST_IS_EMPTY(&GCCache)) {
    head = PR_LIST_HEAD(&GCCache);
    if (head == &GCCache)
      break;
    free_cache_entry(head);
  }

  while (!PR_CLIST_IS_EMPTY(&GCFreeList)) {
    head = PR_LIST_HEAD(&GCFreeList);
    if (head == &GCFreeList)
      break;
    PR_REMOVE_LINK(head);
    delete (GCCacheEntryXlib *)head;
  }
}

Here is the call graph for this function:


Member Function Documentation

void nsGCCacheXlib::Flush ( unsigned long  flags)

Definition at line 135 of file nsGCCache.cpp.

{
  while (!PR_CLIST_IS_EMPTY(&GCCache)) {
    PRCList *head = PR_LIST_HEAD(&GCCache);
    if (head == &GCCache)
      break;
    GCCacheEntryXlib *entry = (GCCacheEntryXlib *)head;
    if (entry->flags & flags)
      free_cache_entry(head);
  }
}

Here is the call graph for this function:

void nsGCCacheXlib::free_cache_entry ( PRCList *  clist) [private]

Definition at line 74 of file nsGCCache.cpp.

{
  GCCacheEntryXlib *entry = (GCCacheEntryXlib *)clist;
  entry->gc->Release();
  if (entry->clipRegion)
    ::XDestroyRegion(entry->clipRegion);
  
  /* thread on the freelist, at the front */
  PR_REMOVE_LINK(clist);
  memset(entry, 0, sizeof(*entry));
  PR_INSERT_LINK(clist, &GCFreeList);
}

Here is the call graph for this function:

Here is the caller graph for this function:

xGC * nsGCCacheXlib::GetGC ( Display display,
Window  window,
unsigned long  flags,
XGCValues *  gcv,
Region  clipRegion 
)

Definition at line 147 of file nsGCCache.cpp.

{
  PRCList *iter;
  GCCacheEntryXlib *entry;
  DEBUG_METER(int i = 0;)
  
  for (iter = PR_LIST_HEAD(&GCCache); iter != &GCCache;
       iter = PR_NEXT_LINK(iter)) {

    entry = (GCCacheEntryXlib *)iter;
    if (flags == entry->flags && 
        !memcmp (gcv, &entry->gcv, sizeof (*gcv))) {
      /* if there's a clipRegion, we have to match */

      if ((clipRegion && entry->clipRegion &&
           ::XEqualRegion(clipRegion, entry->clipRegion)) ||
          /* and if there isn't, we can't have one */
          (!clipRegion && !entry->clipRegion)) {

        /* move to the front of the list, if needed */
        if (iter != PR_LIST_HEAD(&GCCache)) {
          PR_REMOVE_LINK(iter);
          PR_INSERT_LINK(iter, &GCCache);
        }
        DEBUG_METER(GCCacheStats.hits[i]++;)

        entry->gc->AddRef();
        return entry->gc;
      }
    }
    DEBUG_METER(++i;)
  }
    
  /* might need to forcibly free the LRU cache entry */
  if (PR_CLIST_IS_EMPTY(&GCFreeList)) {
    DEBUG_METER(GCCacheStats.reclaim++);
    move_cache_entry(PR_LIST_TAIL(&GCCache));
  }

  DEBUG_METER(GCCacheStats.misses++;)
  
  iter = PR_LIST_HEAD(&GCFreeList);
  PR_REMOVE_LINK(iter);
  PR_INSERT_LINK(iter, &GCCache);
  entry = (GCCacheEntryXlib *)iter;

  if (!entry->gc) {
    // No old GC, greate new
    entry->gc = new xGC(display, drawable, flags, gcv);
    entry->gc->AddRef(); // addref the newly created xGC
    entry->flags = flags;
    entry->gcv = *gcv;
    entry->clipRegion = NULL;
    //printf("creating new gc=%X\n",entry->gc); 
  }
  else if (entry->gc->mRefCnt > 0) {
    // Old GC still in use, create new
    entry->gc->Release();
    entry->gc = new xGC(display, drawable, flags, gcv);
    entry->gc->AddRef(); // addref the newly created xGC
    entry->flags = flags;
    entry->gcv = *gcv;
    if (entry->clipRegion)
       XDestroyRegion(entry->clipRegion);
    entry->clipRegion = NULL;
    //printf("creating new (use)gc=%X\n",entry->gc); 
  }
  else {
    ReuseGC(entry, flags, gcv);
  }

  if (clipRegion) {
    entry->clipRegion = ::XCreateRegion();
    XCopyRegion(clipRegion, entry->clipRegion);
    if (entry->clipRegion)
      ::XSetRegion(display, entry->gc->mGC, entry->clipRegion);
    /* XXX what if it fails? */
  }
  
  entry->gc->AddRef();
  return entry->gc;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsGCCacheXlib::move_cache_entry ( PRCList *  clist) [private]

Definition at line 66 of file nsGCCache.cpp.

{
  /* thread on the freelist, at the front */
  PR_REMOVE_LINK(clist);
  PR_INSERT_LINK(clist, &GCFreeList);
}

Here is the caller graph for this function:

Definition at line 110 of file nsGCCache.cpp.

                           { 
  DEBUG_METER(
              fprintf(stderr, "GC Cache:\n\thits:");
              int hits = 0;
              for (int i = 0; i < GC_CACHE_SIZE; i++) {
                fprintf(stderr, " %4d", GCCacheStats.hits[i]);
                hits+=GCCacheStats.hits[i];
              }
              int total = hits + GCCacheStats.misses;
              float percent = float(float(hits) / float(total));
              percent *= 100;
              fprintf(stderr, "\n\thits: %d, misses: %d, hit percent: %f%%\n", 
                      hits, GCCacheStats.misses, percent);
              );
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsGCCacheXlib::ReuseGC ( GCCacheEntryXlib entry,
unsigned long  flags,
XGCValues *  gcv 
) [private]

Definition at line 230 of file nsGCCache.cpp.

{
  // We have old GC, reuse it and check what
  // we have to change

  if (entry->clipRegion) {
    // set it to none here and then set the clip region with
    // gdk_gc_set_clip_region in GetGC()
    gcv->clip_mask = None;
    flags |= GCClipMask;
    ::XDestroyRegion(entry->clipRegion);
    entry->clipRegion = NULL;
  }

  if (flags != 0) {
    ::XChangeGC(entry->gc->mDisplay, entry->gc->mGC,
                flags, gcv);
  }
  entry->flags = flags;  entry->gcv = *gcv;
}

Here is the caller graph for this function:

void nsGCCacheXlib::XCopyRegion ( Region  src,
Region  dr_return 
) [static, private]

Definition at line 128 of file nsGCCache.cpp.

{
  if (!copyRegion) copyRegion = ::XCreateRegion();
  ::XUnionRegion(srca, copyRegion, dr_return);
}

Here is the caller graph for this function:


Member Data Documentation

Region nsGCCacheXlib::copyRegion = 0 [static, private]

Definition at line 135 of file nsGCCache.h.

PRCList nsGCCacheXlib::GCCache [private]

Definition at line 130 of file nsGCCache.h.

PRCList nsGCCacheXlib::GCFreeList [private]

Definition at line 131 of file nsGCCache.h.


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