little more xlib work
This commit is contained in:
Родитель
5cc467b89c
Коммит
e34ab4441f
|
@ -27,15 +27,64 @@ extern int gDepth;
|
|||
extern Visual *gVisual;
|
||||
extern XVisualInfo *gVisualInfo;
|
||||
|
||||
extern PRUint32 gRedZeroMask; //red color mask in zero position
|
||||
extern PRUint32 gGreenZeroMask; //green color mask in zero position
|
||||
extern PRUint32 gBlueZeroMask; //blue color mask in zero position
|
||||
extern PRUint32 gAlphaZeroMask; //alpha data mask in zero position
|
||||
extern PRUint32 gRedMask; //red color mask
|
||||
extern PRUint32 gGreenMask; //green color mask
|
||||
extern PRUint32 gBlueMask; //blue color mask
|
||||
extern PRUint32 gAlphaMask; //alpha data mask
|
||||
extern PRUint8 gRedCount; //number of red color bits
|
||||
extern PRUint8 gGreenCount; //number of green color bits
|
||||
extern PRUint8 gBlueCount; //number of blue color bits
|
||||
extern PRUint8 gAlphaCount; //number of alpha data bits
|
||||
extern PRUint8 gRedShift; //number to shift value into red position
|
||||
extern PRUint8 gGreenShift; //number to shift value into green position
|
||||
extern PRUint8 gBlueShift; //number to shift value into blue position
|
||||
extern PRUint8 gAlphaShift; //number to shift value into alpha position
|
||||
|
||||
nsDrawingSurfaceXlib::nsDrawingSurfaceXlib()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
printf("nsDrawingSurfaceXlib::nsDrawingSurfaceXlib()\n");
|
||||
mPixmap = 0;
|
||||
mImage = nsnull;
|
||||
mGC = 0;
|
||||
// set up lock info
|
||||
mLocked = PR_FALSE;
|
||||
mLockX = 0;
|
||||
mLockY = 0;
|
||||
mLockWidth = 0;
|
||||
mLockHeight = 0;
|
||||
mLockFlags = 0;
|
||||
// dimensions...
|
||||
mWidth = 0;
|
||||
mHeight = 0;
|
||||
mIsOffscreen = PR_FALSE;
|
||||
// set up the masks for the pix formats
|
||||
mPixFormat.mRedMask = gVisualInfo->red_mask;
|
||||
mPixFormat.mGreenMask = gVisualInfo->green_mask;
|
||||
mPixFormat.mBlueMask = gVisualInfo->blue_mask;
|
||||
mPixFormat.mRedMask = gRedMask;
|
||||
mPixFormat.mGreenMask = gGreenMask;
|
||||
mPixFormat.mBlueMask = gBlueMask;
|
||||
mPixFormat.mAlphaMask = gAlphaMask;
|
||||
mPixFormat.mRedCount = gRedCount;
|
||||
mPixFormat.mGreenCount = gGreenCount;
|
||||
mPixFormat.mBlueCount = gBlueCount;
|
||||
mPixFormat.mAlphaCount = gAlphaCount;
|
||||
mPixFormat.mRedShift = gRedShift;
|
||||
mPixFormat.mGreenShift = gGreenShift;
|
||||
mPixFormat.mBlueShift = gBlueShift;
|
||||
mPixFormat.mAlphaShift = gAlphaShift;
|
||||
}
|
||||
|
||||
nsDrawingSurfaceXlib::~nsDrawingSurfaceXlib()
|
||||
{
|
||||
if (mPixmap) {
|
||||
XFreePixmap(gDisplay, mPixmap);
|
||||
}
|
||||
if (mImage) {
|
||||
XDestroyImage(mImage);
|
||||
}
|
||||
}
|
||||
|
||||
NS_IMPL_QUERY_INTERFACE(nsDrawingSurfaceXlib, kIDrawingSurfaceIID)
|
||||
|
@ -49,35 +98,80 @@ nsDrawingSurfaceXlib::Lock(PRInt32 aX, PRInt32 aY,
|
|||
void **aBits, PRInt32 *aStride,
|
||||
PRInt32 *aWidthBytes, PRUint32 aFlags)
|
||||
{
|
||||
if (mLocked)
|
||||
{
|
||||
NS_ASSERTION(0, "nested lock attempt");
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
mLocked = PR_TRUE;
|
||||
|
||||
mLockX = aX;
|
||||
mLockY = aY;
|
||||
mLockWidth = aWidth;
|
||||
mLockHeight = aHeight;
|
||||
mLockFlags = aFlags;
|
||||
|
||||
mImage = XGetImage(gDisplay, mPixmap,
|
||||
mLockX, mLockY,
|
||||
mLockWidth, mLockHeight,
|
||||
0xFFFFFFFF,
|
||||
ZPixmap);
|
||||
|
||||
*aBits = mImage->data;
|
||||
|
||||
*aWidthBytes = mImage->bytes_per_line;
|
||||
*aStride = mImage->bytes_per_line;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDrawingSurfaceXlib::Unlock(void)
|
||||
{
|
||||
if (!mLocked) {
|
||||
NS_ASSERTION(0, "attempting to unlock an DS that isn't locked");
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
// If the lock was not read only, put the bits back on the pixmap
|
||||
if (!(mLockFlags & NS_LOCK_SURFACE_READ_ONLY)) {
|
||||
XPutImage(gDisplay, mPixmap, mGC, mImage,
|
||||
0, 0, mLockX, mLockY,
|
||||
mLockWidth, mLockHeight);
|
||||
}
|
||||
if (mImage) {
|
||||
XDestroyImage(mImage);
|
||||
mImage = nsnull;
|
||||
}
|
||||
mLocked = PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDrawingSurfaceXlib::GetDimensions(PRUint32 *aWidth, PRUint32 *aHeight)
|
||||
{
|
||||
*aWidth = mWidth;
|
||||
*aHeight = mHeight;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDrawingSurfaceXlib::IsOffscreen(PRBool *aOffScreen)
|
||||
{
|
||||
*aOffScreen = mIsOffscreen;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDrawingSurfaceXlib::IsPixelAddressable(PRBool *aAddressable)
|
||||
{
|
||||
*aAddressable = PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDrawingSurfaceXlib::GetPixelFormat(nsPixelFormat *aFormat)
|
||||
{
|
||||
*aFormat = mPixFormat;
|
||||
return NS_OK;
|
||||
}
|
||||
|
|
|
@ -28,6 +28,7 @@ class nsDrawingSurfaceXlib : public nsIDrawingSurface
|
|||
{
|
||||
public:
|
||||
nsDrawingSurfaceXlib();
|
||||
~nsDrawingSurfaceXlib();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
|
@ -45,7 +46,21 @@ public:
|
|||
private:
|
||||
GC mGC;
|
||||
Pixmap mPixmap;
|
||||
XImage *mImage;
|
||||
nsPixelFormat mPixFormat;
|
||||
PRUint8 mDepth;
|
||||
// for locking
|
||||
PRInt32 mLockX;
|
||||
PRInt32 mLockY;
|
||||
PRUint32 mLockWidth;
|
||||
PRUint32 mLockHeight;
|
||||
PRUint32 mLockFlags;
|
||||
PRBool mLocked;
|
||||
// dimensions
|
||||
PRUint32 mWidth;
|
||||
PRUint32 mHeight;
|
||||
// are we offscreen
|
||||
PRBool mIsOffscreen;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -26,6 +26,8 @@
|
|||
#include "nsIServiceManager.h"
|
||||
#include "nsITimer.h"
|
||||
|
||||
static PRUint8 convertMaskToCount(unsigned long val);
|
||||
static PRUint8 getShiftForMask(unsigned long val);
|
||||
|
||||
static NS_DEFINE_IID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID);
|
||||
static NS_DEFINE_IID(kIEventQueueServiceIID, NS_IEVENTQUEUESERVICE_IID);
|
||||
|
@ -80,11 +82,28 @@ NS_METHOD nsAppShell::Create(int* argc, char ** argv)
|
|||
if (gVisualInfo == NULL) {
|
||||
printf("nsAppShell::Create(): Warning: Failed to get XVisualInfo\n");
|
||||
}
|
||||
if (num_visuals != 0) {
|
||||
if (num_visuals != 1) {
|
||||
printf("nsAppShell:Create(): Warning: %d XVisualInfo structs were returned.\n", num_visuals);
|
||||
}
|
||||
// get the depth for this display
|
||||
gDepth = DefaultDepth(gDisplay, gScreenNum);
|
||||
// set up the color info for this display
|
||||
// set up the masks
|
||||
gRedMask = gVisualInfo->red_mask;
|
||||
gGreenMask = gVisualInfo->green_mask;
|
||||
gBlueMask = gVisualInfo->blue_mask;
|
||||
gAlphaMask = 0;
|
||||
// set up the number of bits in each
|
||||
gRedCount = convertMaskToCount(gVisualInfo->red_mask);
|
||||
gGreenCount = convertMaskToCount(gVisualInfo->green_mask);
|
||||
gBlueCount = convertMaskToCount(gVisualInfo->blue_mask);
|
||||
gAlphaCount = 0;
|
||||
// set up the number of bits that you need to shift to get to
|
||||
// a specific mask
|
||||
gRedShift = getShiftForMask(gVisualInfo->red_mask);
|
||||
gGreenShift = getShiftForMask(gVisualInfo->green_mask);
|
||||
gBlueShift = getShiftForMask(gVisualInfo->blue_mask);
|
||||
gAlphaShift = 0;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -168,22 +187,22 @@ nsresult nsAppShell::Run()
|
|||
}
|
||||
if (select_retval == 0) {
|
||||
// the select timed out, process the timeout queue.
|
||||
printf("Timer ran out...\n");
|
||||
// printf("Timer ran out...\n");
|
||||
please_run_timer_queue = 1;
|
||||
}
|
||||
// check to see if there's data avilable for the queue
|
||||
if (FD_ISSET(queue_fd, &select_set)) {
|
||||
printf("queue data available.\n");
|
||||
//printf("queue data available.\n");
|
||||
PR_ProcessPendingEvents(EQueue);
|
||||
}
|
||||
// check to see if there's data avilable for
|
||||
// xlib
|
||||
if (FD_ISSET(xlib_fd, &select_set)) {
|
||||
printf("xlib data available.\n");
|
||||
//printf("xlib data available.\n");
|
||||
XNextEvent(gDisplay, &event);
|
||||
}
|
||||
if (please_run_timer_queue) {
|
||||
printf("Running timer queue...\n");
|
||||
//printf("Running timer queue...\n");
|
||||
NS_ProcessTimeouts();
|
||||
}
|
||||
}
|
||||
|
@ -222,3 +241,30 @@ void* nsAppShell::GetNativeData(PRUint32 aDataType)
|
|||
return nsnull;
|
||||
}
|
||||
|
||||
static PRUint8 convertMaskToCount(unsigned long val)
|
||||
{
|
||||
PRUint8 retval = 0;
|
||||
PRUint8 cur_bit = 0;
|
||||
// walk through the number, incrementing the value if
|
||||
// the bit in question is set.
|
||||
while (cur_bit < (sizeof(unsigned long) * 8)) {
|
||||
if ((val >> cur_bit) & 0x1) {
|
||||
retval++;
|
||||
}
|
||||
cur_bit++;
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
static PRUint8 getShiftForMask(unsigned long val)
|
||||
{
|
||||
PRUint8 cur_bit = 0;
|
||||
// walk through the number, looking for the first 1
|
||||
while (cur_bit < (sizeof(unsigned long) * 8)) {
|
||||
if ((val >> cur_bit) & 0x1) {
|
||||
return cur_bit;
|
||||
}
|
||||
cur_bit++;
|
||||
}
|
||||
return cur_bit;
|
||||
}
|
||||
|
|
|
@ -25,6 +25,23 @@ int gDepth;
|
|||
Visual *gVisual;
|
||||
XVisualInfo *gVisualInfo;
|
||||
|
||||
PRUint32 gRedZeroMask; //red color mask in zero position
|
||||
PRUint32 gGreenZeroMask; //green color mask in zero position
|
||||
PRUint32 gBlueZeroMask; //blue color mask in zero position
|
||||
PRUint32 gAlphaZeroMask; //alpha data mask in zero position
|
||||
PRUint32 gRedMask; //red color mask
|
||||
PRUint32 gGreenMask; //green color mask
|
||||
PRUint32 gBlueMask; //blue color mask
|
||||
PRUint32 gAlphaMask; //alpha data mask
|
||||
PRUint8 gRedCount; //number of red color bits
|
||||
PRUint8 gGreenCount; //number of green color bits
|
||||
PRUint8 gBlueCount; //number of blue color bits
|
||||
PRUint8 gAlphaCount; //number of alpha data bits
|
||||
PRUint8 gRedShift; //number to shift value into red position
|
||||
PRUint8 gGreenShift; //number to shift value into green position
|
||||
PRUint8 gBlueShift; //number to shift value into blue position
|
||||
PRUint8 gAlphaShift; //number to shift value into alpha position
|
||||
|
||||
nsWidget::nsWidget() : nsBaseWidget()
|
||||
{
|
||||
mPreferredWidth = 0;
|
||||
|
|
|
@ -109,5 +109,23 @@ extern int gDepth;
|
|||
extern Visual *gVisual;
|
||||
extern XVisualInfo *gVisualInfo;
|
||||
|
||||
extern PRUint32 gRedZeroMask; //red color mask in zero position
|
||||
extern PRUint32 gGreenZeroMask; //green color mask in zero position
|
||||
extern PRUint32 gBlueZeroMask; //blue color mask in zero position
|
||||
extern PRUint32 gAlphaZeroMask; //alpha data mask in zero position
|
||||
extern PRUint32 gRedMask; //red color mask
|
||||
extern PRUint32 gGreenMask; //green color mask
|
||||
extern PRUint32 gBlueMask; //blue color mask
|
||||
extern PRUint32 gAlphaMask; //alpha data mask
|
||||
extern PRUint8 gRedCount; //number of red color bits
|
||||
extern PRUint8 gGreenCount; //number of green color bits
|
||||
extern PRUint8 gBlueCount; //number of blue color bits
|
||||
extern PRUint8 gAlphaCount; //number of alpha data bits
|
||||
extern PRUint8 gRedShift; //number to shift value into red position
|
||||
extern PRUint8 gGreenShift; //number to shift value into green position
|
||||
extern PRUint8 gBlueShift; //number to shift value into blue position
|
||||
extern PRUint8 gAlphaShift; //number to shift value into alpha position
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче