began work on nsDrawingSurfaceGTK.cpp. it isn't built yet, as it doens't

compile though.  renamed the nsDrawingSurfaceGTK.h to nsOldDrawingSurfaceGTK.h
to avoid name conflicts for now.
This commit is contained in:
pavlov%pavlov.net 1999-02-26 15:26:02 +00:00
parent 919aa7b2fc
commit e1bed4ee70
7 changed files with 288 additions and 20 deletions

View File

@ -43,7 +43,7 @@ CPPSRCS = \
nsGfxFactoryGTK.cpp \
nsRenderingContextGTK.cpp \
nsImageGTK.cpp \
nsRegionGTK.cpp \
nsRegionGTK.cpp
include $(topsrcdir)/config/rules.mk

View File

@ -45,17 +45,11 @@ nsDeviceContextGTK::nsDeviceContextGTK()
mPaletteInfo.sizePalette = 0;
mPaletteInfo.numReserved = 0;
mPaletteInfo.palette = NULL;
mColormap = nsnull;
mNumCells = 0;
}
nsDeviceContextGTK::~nsDeviceContextGTK()
{
if (mColormap)
{
gdk_colormap_unref(mColormap);
mColormap = nsnull;
}
}
NS_IMPL_QUERY_INTERFACE(nsDeviceContextGTK, kDeviceContextIID)

View File

@ -25,7 +25,7 @@
#include "nsIView.h"
#include "nsIRenderingContext.h"
#include "nsDrawingSurfaceGTK.h"
#include "nsOldDrawingSurfaceGTK.h"
#include "nsRenderingContextGTK.h"
class nsDeviceContextGTK : public DeviceContextImpl
@ -69,7 +69,6 @@ private:
PRUint32 mDepth;
PRBool mWriteable;
nsPaletteInfo mPaletteInfo;
GdkColormap *mColormap;
PRUint32 mNumCells;
};

View File

@ -0,0 +1,200 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "nspr.h"
#include "nsDrawingSurfaceGTK.h"
static NS_DEFINE_IID(kIDrawingSurfaceIID, NS_IDRAWING_SURFACE_IID);
//static NS_DEFINE_IID(kIDrawingSurfaceGTKIID, NS_IDRAWING_SURFACE_GTK_IID);
nsDrawingSurfaceGTK :: nsDrawingSurfaceGTK()
{
NS_INIT_REFCNT();
GdkVisual *v;
mPixmap = nsnull;
mGC = nsnull;
mDepth = 0;
mWidth = mHeight = 0;
mFlags = 0;
mImage = nsnull;
mLockWidth = mLockHeight = 0;
mLockFlags = 0;
mLocked = PR_FALSE;
v = ::gdk_rgb_get_visual();
mPixFormat.mRedMask = v->red_mask;
mPixFormat.mGreenMask = v->green_mask;
mPixFormat.mBlueMask = v->blue_mask;
// FIXME
mPixFormat.mAlphaMask = 0;
mPixFormat.mRedShift = v->red_shift;
mPixFormat.mGreenShift = v->green_shift;
mPixFormat.mBlueShift = v->blue_shift;
// FIXME
mPixFormat.mAlphaShift = 0;
mDepth = v->depth;
}
nsDrawingSurfaceGTK :: ~nsDrawingSurfaceGTK()
{
if (mPixmap)
::gdk_pixmap_unref(mPixmap);
if (mImage)
::gdk_image_destroy(mImage);
}
NS_IMETHODIMP nsDrawingSurfaceGTK :: QueryInterface(REFNSIID aIID, void** aInstancePtr)
{
if (nsnull == aInstancePtr)
return NS_ERROR_NULL_POINTER;
if (aIID.Equals(kIDrawingSurfaceIID))
{
nsIDrawingSurface* tmp = this;
*aInstancePtr = (void*) tmp;
NS_ADDREF_THIS();
return NS_OK;
}
/*
if (aIID.Equals(kIDrawingSurfaceGTKIID))
{
nsDrawingSurfaceGTK* tmp = this;
*aInstancePtr = (void*) tmp;
NS_ADDREF_THIS();
return NS_OK;
}
*/
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
if (aIID.Equals(kISupportsIID))
{
nsIDrawingSurface* tmp = this;
nsISupports* tmp2 = tmp;
*aInstancePtr = (void*) tmp2;
NS_ADDREF_THIS();
return NS_OK;
}
return NS_NOINTERFACE;
}
NS_IMPL_ADDREF(nsDrawingSurfaceGTK)
NS_IMPL_RELEASE(nsDrawingSurfaceGTK)
NS_IMETHODIMP nsDrawingSurfaceGTK :: Lock(PRInt32 aX, PRInt32 aY,
PRUint32 aWidth, PRUint32 aHeight,
void **aBits, PRInt32 *aStride,
PRInt32 *aWidthBytes, PRUint32 aFlags)
{
if (mLocked)
NS_ASSERTION(0, "nested lock attempt");
return NS_ERROR_FAILURE;
}
mLocked = PR_TRUE;
mLockWidth = aWidth;
mLockHeight = aHeight;
mLockFlags = aFlags;
mImage = ::gdk_image_get(mPixmap, aX, aY, mLockWidth, mLockHeight);
// aBits = &mImage->mem;
// FIXME
return NS_OK;
}
NS_IMETHODIMP nsDrawingSurfaceGTK :: Unlock(void)
{
if (!mLocked)
NS_ASSERTION(0, "attempting to unlock an DS that isn't locked");
return NS_ERROR_FAILURE;
}
::gdk_image_destroy(mImage);
mImage = nsnull;
return NS_OK;
}
NS_IMETHODIMP nsDrawingSurfaceGTK :: GetDimensions(PRUint32 *aWidth, PRUint32 *aHeight)
{
*aWidth = mWidth;
*aHeight = mHeight;
return NS_OK;
}
NS_IMETHODIMP nsDrawingSurfaceGTK :: IsOffscreen(PRBool *aOffScreen)
{
return NS_OK;
}
NS_IMETHODIMP nsDrawingSurfaceGTK :: IsPixelAddressable(PRBool *aAddressable)
{
return NS_OK;
}
NS_IMETHODIMP nsDrawingSurfaceGTK :: GetPixelFormat(nsPixelFormat *aFormat)
{
*aFormat = mPixFormat;
return NS_OK;
}
NS_IMETHODIMP nsDrawingSurfaceGTK :: Init(GdkGC *aGC)
{
mGC = aGC;
mPixmap = ::gdk_pixmap_new(nsnull, 1, 1, mDepth);
return NS_OK;
}
NS_IMETHODIMP nsDrawingSurfaceGTK :: Init(GdkGC *aGC, PRUint32 aWidth,
PRUint32 aHeight, PRUint32 aFlags)
{
::g_return_val_if_fail (aGC != NULL, NS_ERROR_FAILURE);
::g_return_val_if_fail ((aWidth > 0) && (aHeight > 0), NS_ERROR_FAILURE);
mGC = aGC;
mWidth = aWidth;
mHeight = aHeight;
mFlags = aFlags;
mPixmap = ::gdk_pixmap_new(nsnull, mWidth, mHeight, mDepth);
return NS_OK;
}
NS_IMETHODIMP nsDrawingSurfaceGTK :: GetGC(GdkGC *aGC)
{
*aGC = ::gdk_gc_ref(mGC);
return NS_OK;
}
NS_IMETHODIMP nsDrawingSurfaceGTK :: ReleaseGC(void)
{
::gdk_gc_unref(mGC);
return NS_OK;
}

View File

@ -1,14 +1,75 @@
#ifndef nsDrawingSurfaceGTK_h__
#define nsDrawingSurfaceGTK_h__
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include <gdk/gdk.h>
#ifndef nsDrawingSurfaceGTK_h___
#define nsDrawingSurfaceGTK_h___
struct nsDrawingSurfaceGTK {
GdkDrawable *drawable;
GdkGC *gc;
#include "nspr.h"
#include "nscore.h"
#include "prtypes.h"
#include "nsISupports.h"
#include "nsIDrawingSurface.h"
#include <gtk/gtk.h>
class nsDrawingSurfaceGTK : public nsIDrawingSurface,
nsISupports
{
public:
nsDrawingSurfaceGTK();
virtual ~nsDrawingSurfaceGTK();
NS_DECL_ISUPPORTS
//nsIDrawingSurface interface
NS_IMETHOD Lock(PRInt32 aX, PRInt32 aY, PRUint32 aWidth, PRUint32 aHeight,
void **aBits, PRInt32 *aStride, PRInt32 *aWidthBytes,
PRUint32 aFlags);
NS_IMETHOD Unlock(void);
NS_IMETHOD GetDimensions(PRUint32 *aWidth, PRUint32 *aHeight);
NS_IMETHOD IsOffscreen(PRBool *aOffScreen);
NS_IMETHOD IsPixelAddressable(PRBool *aAddressable);
NS_IMETHOD GetPixelFormat(nsPixelFormat *aFormat);
//nsIDrawingSurfaceGTK interface
NS_IMETHOD Init(GdkGC *aGC);
NS_IMETHOD Init(GdkGC *aGC, PRUint32 aWidth, PRUint32 aHeight, PRUint32 aFlags);
NS_IMETHOD GetGC(GdkGC *aGC);
NS_IMETHOD ReleaseGC(void);
private:
/* general */
GdkPixmap *mPixmap;
GdkGC *mGC;
gint mDepth;
nsPixelFormat mPixFormat;
PRUint32 mWidth;
PRUint32 mHeight;
PRUint32 mFlags;
/* for locks */
GdkImage *mImage;
PRUint32 mLockWidth;
PRUint32 mLockHeight;
PRUint32 mLockFlags;
PRBool mLocked;
};
typedef nsDrawingSurfaceGTK nsDrawingSurfaceGTK;
#endif /* nsDrawingSurfaceGTK_h__ */
#endif

View File

@ -0,0 +1,14 @@
#ifndef nsOldDrawingSurfaceGTK_h__
#define nsOldDrawingSurfaceGTK_h__
#include <gdk/gdk.h>
struct nsDrawingSurfaceGTK {
GdkDrawable *drawable;
GdkGC *gc;
};
typedef nsDrawingSurfaceGTK nsDrawingSurfaceGTK;
#endif /* nsOldDrawingSurfaceGTK_h__ */

View File

@ -34,7 +34,7 @@
#include "nsIDeviceContext.h"
#include "nsVoidArray.h"
#include "nsDrawingSurfaceGTK.h"
#include "nsOldDrawingSurfaceGTK.h"
#include "nsRegionGTK.h"
#include <gtk/gtk.h>