Back to index

lightning-sunbird  0.9+nobinonly
Static Public Member Functions | Static Protected Member Functions | Static Protected Attributes
nsX11AlphaBlend Class Reference

#include <nsX11AlphaBlend.h>

List of all members.

Static Public Member Functions

static PRBool CanAntiAlias ()
static blendPixel GetBlendPixel ()
static blendGlyph GetBlendGlyph ()
static XImage * GetXImage (PRUint32 width, PRUint32 height)
static void FreeGlobals ()
static nsresult InitGlobals (Display *dsp)
static XImage * GetBackground (Display *, int, Drawable, PRInt32, PRInt32, PRUint32, PRUint32)
static nscolor PixelToNSColor (unsigned long aPixel)

Static Protected Member Functions

static void ClearGlobals ()
static void ClearFunctions ()
static PRBool InitLibrary (Display *dsp)

Static Protected Attributes

static PRBool sAvailable
static PRUint16 sBitmapPad
static PRUint16 sBitsPerPixel
static blendGlyph sBlendMonoImage
static blendPixel sBlendPixel
static PRUint16 sBytesPerPixel
static int sDepth
static PRBool sInited
static pixelToNSColor sPixelToNSColor

Detailed Description

Definition at line 77 of file nsX11AlphaBlend.h.


Member Function Documentation

static PRBool nsX11AlphaBlend::CanAntiAlias ( ) [inline, static]

Definition at line 79 of file nsX11AlphaBlend.h.

{ return sAvailable; };

Here is the caller graph for this function:

static void nsX11AlphaBlend::ClearFunctions ( ) [static, protected]
void nsX11AlphaBlend::ClearGlobals ( ) [static, protected]

Definition at line 138 of file nsX11AlphaBlend.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 158 of file nsX11AlphaBlend.cpp.

{
  ClearGlobals();
}

Here is the call graph for this function:

Here is the caller graph for this function:

XImage * nsX11AlphaBlend::GetBackground ( Display aDisplay,
int  aScreen,
Drawable  aDrawable,
PRInt32  aX,
PRInt32  aY,
PRUint32  aWidth,
PRUint32  aHeight 
) [static]

Definition at line 380 of file nsX11AlphaBlend.cpp.

{
  PRBool any_offscreen = PR_FALSE;
  XImage *ximage;

  //
  // get the background
  //
  // bound the request to inside the window
  PRInt32 x_skip = 0;
  if (aX < 0) {
    x_skip = -aX;
    any_offscreen = PR_TRUE;
  }
  PRInt32 y_skip = 0;
  if (aY < 0) {
    y_skip = -(aY);
    any_offscreen = PR_TRUE;
  }
  PRInt32 copy_width  = aWidth  - x_skip;
  PRInt32 copy_height = aHeight - y_skip;

  Window root;
  int win_x, win_y;
  unsigned int win_width, win_height, win_border_width, win_depth;
  if (!XGetGeometry(aDisplay, aDrawable, &root, &win_x, &win_y,
                    &win_width, &win_height, &win_border_width, &win_depth)) {
    NS_ASSERTION(0, "XGetGeometry");
  }
  if ((PRUint32)(aX+x_skip+aWidth) > win_width) {
    copy_width = MIN(copy_width, (int)win_width - (aX+x_skip));
    any_offscreen = PR_TRUE;
  }
  if ((PRUint32)(aY+y_skip+aHeight) > win_height) {
    copy_height = MIN(copy_height, (int)win_height - (aY+y_skip));
    any_offscreen = PR_TRUE;
  }

  PRUint32 root_win_width, root_win_height;
  root_win_width  = DisplayWidth(aDisplay, aScreen);
  root_win_height = DisplayHeight(aDisplay, aScreen);

  if ((PRUint32)(aX+x_skip+aWidth) > root_win_width) {
    copy_width = MIN(copy_width, (int)root_win_width - (aX+x_skip));
    any_offscreen = PR_TRUE;
  }
  if ((PRUint32)(aY+y_skip+aHeight) > root_win_height) {
    copy_height = MIN(copy_height, (int)root_win_height - (aY+y_skip));
    any_offscreen = PR_TRUE;
  }
  if ((copy_width<=0) || (copy_height<=0))
    return nsnull; // nothing visible

  // get the background image
  // if any part is off screen XGetImage will fail, so we XCreateImage 
  // the image and use XGetSubImage to get the available background pixels
  if (any_offscreen) {
    char *data = (char *)nsMemory::Alloc(aWidth * aHeight * sBytesPerPixel);
    if (!data) {
      return nsnull;
    }
    XImage *super_ximage = XCreateImage(aDisplay,
                                 DefaultVisual(aDisplay, aScreen),
                                 DefaultDepth(aDisplay, aScreen), ZPixmap,
                                 0, data, aWidth, aHeight,
                                 sBitmapPad, aWidth*sBytesPerPixel);
    if (!super_ximage) {
      NS_ASSERTION(super_ximage, "failed to create the super image");
      return nsnull;
    }
    ximage = XGetSubImage(aDisplay, aDrawable,
                          aX+x_skip, aY+y_skip, 
                          copy_width, copy_height,
                          AllPlanes, ZPixmap, super_ximage, x_skip, y_skip);
    if (!ximage) {
      NS_ASSERTION(ximage, "failed to get the sub image");
      XDestroyImage(super_ximage);
      return nsnull;
    }
     ximage = super_ximage;
  }
  else {
    ximage = XGetImage(aDisplay, aDrawable, aX, aY, aWidth, aHeight,
                       AllPlanes, ZPixmap);
  }

  NS_ASSERTION(ximage, "failed to get the image");
  return ximage;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static blendGlyph nsX11AlphaBlend::GetBlendGlyph ( ) [inline, static]

Definition at line 81 of file nsX11AlphaBlend.h.

{ return sBlendMonoImage; };

Here is the caller graph for this function:

static blendPixel nsX11AlphaBlend::GetBlendPixel ( ) [inline, static]

Definition at line 80 of file nsX11AlphaBlend.h.

{ return sBlendPixel; };
static XImage* nsX11AlphaBlend::GetXImage ( PRUint32  width,
PRUint32  height 
) [static]

Definition at line 174 of file nsX11AlphaBlend.cpp.

{
  NS_ASSERTION(sInited==PR_FALSE, "InitGlobals called more than once");
  // set all the globals to default values
#if ENABLE_X11ALPHA_BLEND_PRINTF
  char* debug = PR_GetEnv("NS_ALPHA_BLEND_DEBUG");
  if (debug) {
    PR_sscanf(debug, "%lX", &gX11AlphaBlendDebug);
  }
#endif

  ClearGlobals();
  if (!InitLibrary(aDisplay))
    return NS_ERROR_NOT_AVAILABLE;

  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRBool nsX11AlphaBlend::InitLibrary ( Display dsp) [static, protected]

Definition at line 193 of file nsX11AlphaBlend.cpp.

{
  if (sInited)
    return sAvailable;

  sInited = PR_TRUE;

  Visual *visual = DefaultVisual(aDisplay,DefaultScreen(aDisplay));
  if (visual->c_class != TrueColor) {
    X11ALPHA_BLEND_PRINTF(("unsuppored visual class %d", visual->c_class));
    return PR_FALSE;
  }

  //
  // Get an XImage to get the image information
  //
  Window root_win = RootWindow(aDisplay, DefaultScreen(aDisplay));
  XImage *img = XGetImage(aDisplay, root_win, 0, 0, 1, 1, 0xffffffff, ZPixmap);
  NS_ASSERTION(img, "InitGlobals: XGetImage failed");
  if (!img)
    return PR_FALSE;
  int byte_order = img->byte_order;
  sBitmapPad     = img->bitmap_pad;
  sBitsPerPixel  = img->bits_per_pixel;
  sDepth         = img->depth;
  int blue_mask  = img->blue_mask;
  int green_mask = img->green_mask;
  int red_mask   = img->red_mask;
  XDestroyImage(img);

  PRBool same_byte_order;
#ifdef IS_LITTLE_ENDIAN
  X11ALPHA_BLEND_PRINTF(("endian           = little"));
  same_byte_order = (byte_order == LSBFirst);
#elif IS_BIG_ENDIAN
  X11ALPHA_BLEND_PRINTF(("endian           = big"));
  same_byte_order = (byte_order == MSBFirst);
#else
#  error neither IS_LITTLE_ENDIAN or IS_BIG_ENDIAN is defined
#endif

  X11ALPHA_BLEND_PRINTF(("byte_order       = %s", byte_order?"MSB":"LSB"));
  X11ALPHA_BLEND_PRINTF(("same_byte_order  = %d", same_byte_order));

  X11ALPHA_BLEND_PRINTF(("sBitmapPad       = %d", sBitmapPad));
  X11ALPHA_BLEND_PRINTF(("sDepth           = %d", sDepth));
  X11ALPHA_BLEND_PRINTF(("sBitsPerPixel    = %d", sBitsPerPixel));

  if (sBitsPerPixel <= 16)
    sBytesPerPixel = 2;
  else if (sBitsPerPixel <= 32)
    sBytesPerPixel = 4;
  else {
    X11ALPHA_BLEND_PRINTF(("sBitsPerPixel %d: not supported", sBitsPerPixel));
    return PR_FALSE;
  }
  X11ALPHA_BLEND_PRINTF(("sBytesPerPixel   = %d", sBytesPerPixel));

  if (sBitsPerPixel==16)  {
    if ((red_mask==0x7C00) && (green_mask==0x3E0) && (blue_mask==0x1F)) {
      // 555
      sAvailable           = PR_TRUE;
      if (same_byte_order) {
        sPixelToNSColor = &nsPixelToNscolor555;
        sBlendPixel     = &nsBlendPixel555;
        sBlendMonoImage = &nsBlendMonoImage555;
      }
      else {
        sPixelToNSColor = &nsPixelToNscolor555;
        sBlendPixel     = &nsBlendPixel555_br;
        sBlendMonoImage = &nsBlendMonoImage555_br;
      }
    }
    else if ((red_mask==0xF800) && (green_mask==0x7E0) && (blue_mask==0x1F)) {
      // 565
      sAvailable           = PR_TRUE;
      if (same_byte_order) {
        sPixelToNSColor = &nsPixelToNscolor565;
        sBlendPixel     = &nsBlendPixel565;
        sBlendMonoImage = &nsBlendMonoImage565;
      }
      else {
        sPixelToNSColor = &nsPixelToNscolor565;
        sBlendPixel     = &nsBlendPixel565_br;
        sBlendMonoImage = &nsBlendMonoImage565_br;
      }
    }
  }
  else if (sBitsPerPixel==24)  {
    if ((red_mask==0xFF0000) && (green_mask==0xFF00) && (blue_mask==0xFF)) {
      // 888
      sAvailable           = PR_TRUE;
      if (same_byte_order) {
        sPixelToNSColor = &nsPixelToNscolor888_lsb;
        sBlendPixel     = &nsBlendPixel888_lsb;
        sBlendMonoImage = &nsBlendMonoImage888_lsb;
      }
      else {
        sPixelToNSColor = &nsPixelToNscolor888_msb;
        sBlendPixel     = &nsBlendPixel888_msb;
        sBlendMonoImage = &nsBlendMonoImage888_msb;
      }
    }
  }
  else if (sBitsPerPixel==32)  {
      // 0888
      sAvailable           = PR_TRUE;
      if (same_byte_order) {
        sPixelToNSColor = &nsPixelToNscolor888_lsb;
        sBlendPixel     = &nsBlendPixel0888;
        sBlendMonoImage = &nsBlendMonoImage0888;
      }
      else {
        sPixelToNSColor = &nsPixelToNscolor888_lsb;
        sBlendPixel     = &nsBlendPixel0888_br;
        sBlendMonoImage = &nsBlendMonoImage0888_br;
      }
  }
  else {
    sAvailable = PR_FALSE;
    NS_ASSERTION(0, "X11AlphaBlend: unsupported framebuffer depth");
    goto nsX11AlphaBlend__InitLibrary_error;
  }
  return sAvailable;

nsX11AlphaBlend__InitLibrary_error:
  // clean everything up but note that init was called
  FreeGlobals();
  sInited = PR_TRUE;
  return(sAvailable);
}

Here is the call graph for this function:

Here is the caller graph for this function:

nscolor nsX11AlphaBlend::PixelToNSColor ( unsigned long  aPixel) [static]

Definition at line 326 of file nsX11AlphaBlend.cpp.

{
  nscolor color = (*sPixelToNSColor)(aPixel);
  return color;
}

Here is the caller graph for this function:


Member Data Documentation

PRBool nsX11AlphaBlend::sAvailable [static, protected]

Definition at line 95 of file nsX11AlphaBlend.h.

Definition at line 96 of file nsX11AlphaBlend.h.

Definition at line 97 of file nsX11AlphaBlend.h.

Definition at line 98 of file nsX11AlphaBlend.h.

Definition at line 99 of file nsX11AlphaBlend.h.

Definition at line 100 of file nsX11AlphaBlend.h.

int nsX11AlphaBlend::sDepth [static, protected]

Definition at line 101 of file nsX11AlphaBlend.h.

PRBool nsX11AlphaBlend::sInited [static, protected]

Definition at line 102 of file nsX11AlphaBlend.h.

Definition at line 103 of file nsX11AlphaBlend.h.


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