nsRenderingContextGTK now uses nsDrawingSurfaceGTK

This commit is contained in:
pavlov%pavlov.net 1999-03-21 20:42:01 +00:00
Родитель 66453bb872
Коммит bf5cd32705
9 изменённых файлов: 243 добавлений и 147 удалений

Просмотреть файл

@ -35,6 +35,7 @@ CXXFLAGS += $(TK_CFLAGS)
INCLUDES += $(TK_CFLAGS)
CPPSRCS = \
nsDrawingSurfaceGTK.cpp \
nsDeviceContextGTK.cpp \
nsDeviceContextSpecFactoryG.cpp \
nsDeviceContextSpecG.cpp \

Просмотреть файл

@ -25,7 +25,6 @@
#include "nsIView.h"
#include "nsIRenderingContext.h"
#include "nsOldDrawingSurfaceGTK.h"
#include "nsRenderingContextGTK.h"
class nsDeviceContextGTK : public DeviceContextImpl

Просмотреть файл

@ -16,11 +16,12 @@
* Reserved.
*/
#include "nspr.h"
#include <gtk/gtk.h>
#include "nsDrawingSurfaceGTK.h"
static NS_DEFINE_IID(kIDrawingSurfaceIID, NS_IDRAWING_SURFACE_IID);
//static NS_DEFINE_IID(kIDrawingSurfaceGTKIID, NS_IDRAWING_SURFACE_GTK_IID);
static NS_DEFINE_IID(kIDrawingSurfaceGTKIID, NS_IDRAWING_SURFACE_GTK_IID);
nsDrawingSurfaceGTK :: nsDrawingSurfaceGTK()
{
@ -58,7 +59,9 @@ nsDrawingSurfaceGTK :: nsDrawingSurfaceGTK()
nsDrawingSurfaceGTK :: ~nsDrawingSurfaceGTK()
{
if (mPixmap)
#ifdef NS_GTK_REF
::gdk_pixmap_unref(mPixmap);
#endif
if (mImage)
::gdk_image_destroy(mImage);
}
@ -75,7 +78,7 @@ NS_IMETHODIMP nsDrawingSurfaceGTK :: QueryInterface(REFNSIID aIID, void** aInsta
NS_ADDREF_THIS();
return NS_OK;
}
/*
if (aIID.Equals(kIDrawingSurfaceGTKIID))
{
nsDrawingSurfaceGTK* tmp = this;
@ -83,7 +86,7 @@ NS_IMETHODIMP nsDrawingSurfaceGTK :: QueryInterface(REFNSIID aIID, void** aInsta
NS_ADDREF_THIS();
return NS_OK;
}
*/
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
if (aIID.Equals(kISupportsIID))
@ -98,8 +101,8 @@ NS_IMETHODIMP nsDrawingSurfaceGTK :: QueryInterface(REFNSIID aIID, void** aInsta
return NS_NOINTERFACE;
}
NS_IMPL_ADDREF(nsDrawingSurfaceGTK)
NS_IMPL_RELEASE(nsDrawingSurfaceGTK)
NS_IMPL_ADDREF(nsDrawingSurfaceGTK);
NS_IMPL_RELEASE(nsDrawingSurfaceGTK);
NS_IMETHODIMP nsDrawingSurfaceGTK :: Lock(PRInt32 aX, PRInt32 aY,
PRUint32 aWidth, PRUint32 aHeight,
@ -107,6 +110,7 @@ NS_IMETHODIMP nsDrawingSurfaceGTK :: Lock(PRInt32 aX, PRInt32 aY,
PRInt32 *aWidthBytes, PRUint32 aFlags)
{
if (mLocked)
{
NS_ASSERTION(0, "nested lock attempt");
return NS_ERROR_FAILURE;
}
@ -126,7 +130,7 @@ NS_IMETHODIMP nsDrawingSurfaceGTK :: Lock(PRInt32 aX, PRInt32 aY,
and shared pixmaps are supported, you don't need to do that.
*/
mImage = ::gdk_image_get(mPixmap, aX, aY, mLockWidth, mLockHeight);
mImage = ::gdk_image_get(mPixmap, mLockX, mLockY, mLockWidth, mLockHeight);
// aBits = &mImage->mem;
// FIXME
@ -137,18 +141,23 @@ NS_IMETHODIMP nsDrawingSurfaceGTK :: Lock(PRInt32 aX, PRInt32 aY,
NS_IMETHODIMP nsDrawingSurfaceGTK :: Unlock(void)
{
if (!mLocked)
{
NS_ASSERTION(0, "attempting to unlock an DS that isn't locked");
return NS_ERROR_FAILURE;
}
/*
//if it is writeable, we are going to want to redraw the pixmap from the image.
// my bit looking/mangling skills are asleep.. someone do this the right way
if (!(mFlags & NS_LOCK_SURFACE_READ_ONLY))
{
gdk_draw_image(mPixmap,
mGC,
mImage,
0, 0,
mLockX, mLockY,
mLockWidth, mLockHeight);
gdk_draw_image(GdkDrawable *drawable,
mGC,
mImage,
0, 0,
mLockX, mLockY,
mLockWidth, mLockHeight);
}
*/
::gdk_image_destroy(mImage);
mImage = nsnull;
@ -183,11 +192,10 @@ NS_IMETHODIMP nsDrawingSurfaceGTK :: GetPixelFormat(nsPixelFormat *aFormat)
return NS_OK;
}
NS_IMETHODIMP nsDrawingSurfaceGTK :: Init(GdkGC *aGC)
NS_IMETHODIMP nsDrawingSurfaceGTK :: Init(GdkDrawable *aDrawable, GdkGC *aGC)
{
mGC = aGC;
mPixmap = ::gdk_pixmap_new(nsnull, 1, 1, mDepth);
mPixmap = aDrawable;
return NS_OK;
}
@ -195,8 +203,8 @@ NS_IMETHODIMP nsDrawingSurfaceGTK :: Init(GdkGC *aGC)
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);
// ::g_return_val_if_fail (aGC != nsnull, NS_ERROR_FAILURE);
// ::g_return_val_if_fail ((aWidth > 0) && (aHeight > 0), NS_ERROR_FAILURE);
mGC = aGC;
mWidth = aWidth;
@ -210,7 +218,7 @@ NS_IMETHODIMP nsDrawingSurfaceGTK :: Init(GdkGC *aGC, PRUint32 aWidth,
NS_IMETHODIMP nsDrawingSurfaceGTK :: GetGC(GdkGC *aGC)
{
*aGC = ::gdk_gc_ref(mGC);
aGC = ::gdk_gc_ref(mGC);
return NS_OK;
}
@ -219,3 +227,13 @@ NS_IMETHODIMP nsDrawingSurfaceGTK :: ReleaseGC(void)
::gdk_gc_unref(mGC);
return NS_OK;
}
GdkGC *nsDrawingSurfaceGTK::GetGC(void)
{
return mGC;
}
GdkDrawable *nsDrawingSurfaceGTK::GetDrawable(void)
{
return mPixmap;
}

Просмотреть файл

@ -19,16 +19,13 @@
#ifndef nsDrawingSurfaceGTK_h___
#define nsDrawingSurfaceGTK_h___
#include "nspr.h"
#include "nscore.h"
#include "prtypes.h"
#include "nsISupports.h"
#include "nsIDrawingSurface.h"
#include "nsIDrawingSurfaceGTK.h"
#include <gtk/gtk.h>
class nsDrawingSurfaceGTK : public nsIDrawingSurface,
nsISupports
nsIDrawingSurfaceGTK
{
public:
nsDrawingSurfaceGTK();
@ -49,11 +46,15 @@ public:
//nsIDrawingSurfaceGTK interface
NS_IMETHOD Init(GdkGC *aGC);
NS_IMETHOD Init(GdkDrawable *aDrawable, GdkGC *aGC);
NS_IMETHOD Init(GdkGC *aGC, PRUint32 aWidth, PRUint32 aHeight, PRUint32 aFlags);
NS_IMETHOD GetGC(GdkGC *aGC);
NS_IMETHOD ReleaseGC(void);
// things that are useful to me.
GdkGC *GetGC(void);
GdkDrawable *GetDrawable(void);
private:
/* general */
GdkPixmap *mPixmap;
@ -66,8 +67,8 @@ private:
/* for locks */
GdkImage *mImage;
PRint32 mLockX;
PRint32 mLockY;
PRInt32 mLockX;
PRInt32 mLockY;
PRUint32 mLockWidth;
PRUint32 mLockHeight;
PRUint32 mLockFlags;

Просмотреть файл

@ -0,0 +1,77 @@
/* -*- 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.
*/
#ifndef nsIDrawingSurfaceGTK_h___
#define nsIDrawingSurfaceGTK_h___
#include "nsIDrawingSurface.h"
#include <gtk/gtk.h>
// windows specific drawing surface method set
#define NS_IDRAWING_SURFACE_GTK_IID \
{ 0x1ed958b0, 0xcab6, 0x11d2, \
{ 0xa8, 0x49, 0x00, 0x40, 0x95, 0x9a, 0x28, 0xc9 } }
class nsIDrawingSurfaceGTK : public nsISupports
{
public:
/**
* Initialize a drawing surface using a windows DC.
* aDC is "owned" by the drawing surface until the drawing
* surface is destroyed.
* @param aDC HDC to initialize drawing surface with
* @return error status
**/
NS_IMETHOD Init(GdkDrawable *aDrawable, GdkGC *aGC) = 0;
/**
* Initialize an offscreen drawing surface using a
* windows DC. aDC is not "owned" by this drawing surface, instead
* it is used to create a drawing surface compatible
* with aDC. if width or height are less than zero, aDC will
* be created with no offscreen bitmap installed.
* @param aDC HDC to initialize drawing surface with
* @param aWidth width of drawing surface
* @param aHeight height of drawing surface
* @param aFlags flags used to control type of drawing
* surface created
* @return error status
**/
NS_IMETHOD Init(GdkGC *aGC, PRUint32 aWidth, PRUint32 aHeight,
PRUint32 aFlags) = 0;
/**
* Get a windows DC that represents the drawing surface.
* GetDC() must be paired with ReleaseDC(). Getting a DC
* and Lock()ing are mutually exclusive operations.
* @param aDC out parameter for HDC
* @return error status
**/
NS_IMETHOD GetGC(GdkGC *aGC) = 0;
/**
* Release a windows DC obtained by GetDC().
* ReleaseDC() must be preceded by a call to ReleaseDC().
* @return error status
**/
NS_IMETHOD ReleaseGC(void) = 0;
};
#endif // nsIDrawingSurfaceGTK_h___

Просмотреть файл

@ -440,8 +440,8 @@ nsImageGTK::Draw(nsIRenderingContext &aContext, nsDrawingSurface aSurface,
nsDrawingSurfaceGTK *drawing = (nsDrawingSurfaceGTK*)aSurface;
moz_gdk_draw_bgr_image (drawing->drawable,
drawing->gc,
moz_gdk_draw_bgr_image (drawing->GetDrawable(),
drawing->GetGC(),
aDX, aDY, aDWidth, aDHeight,
GDK_RGB_DITHER_MAX,
mImageBits + mRowBytes * aSY + 3 * aDX,
@ -545,12 +545,12 @@ nsImageGTK::Draw(nsIRenderingContext &aContext,
if (nsnull != mAlphaPixmap)
{
// Setup gc to use the given alpha-pixmap for clipping
gdk_gc_set_clip_mask(drawing->gc, mAlphaPixmap);
gdk_gc_set_clip_origin(drawing->gc, aX, aY);
gdk_gc_set_clip_mask(drawing->GetGC(), mAlphaPixmap);
gdk_gc_set_clip_origin(drawing->GetGC(), aX, aY);
}
moz_gdk_draw_bgr_image (drawing->drawable,
drawing->gc,
moz_gdk_draw_bgr_image (drawing->GetDrawable(),
drawing->GetGC(),
aX, aY, aWidth, aHeight,
GDK_RGB_DITHER_MAX,
mImageBits, mRowBytes);
@ -558,8 +558,8 @@ nsImageGTK::Draw(nsIRenderingContext &aContext,
if (mAlphaPixmap != nsnull)
{
// Revert gc to its old clip-mask and origin
gdk_gc_set_clip_origin(drawing->gc, 0, 0);
gdk_gc_set_clip_mask(drawing->gc, nsnull);
gdk_gc_set_clip_origin(drawing->GetGC(), 0, 0);
gdk_gc_set_clip_mask(drawing->GetGC(), nsnull);
}
#ifdef CHEAP_PERFORMANCE_MEASUREMENT

Просмотреть файл

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

Просмотреть файл

@ -71,7 +71,7 @@ nsRenderingContextGTK::nsRenderingContextGTK()
mFontMetrics = nsnull;
mContext = nsnull;
mRenderingSurface = nsnull;
mSurface = nsnull;
mOffscreenSurface = nsnull;
mCurrentColor = 0;
mCurrentLineStyle = nsLineStyle_kSolid;
@ -134,13 +134,18 @@ NS_IMETHODIMP nsRenderingContextGTK::Init(nsIDeviceContext* aContext,
// ::gdk_rgb_init();
mRenderingSurface = new nsDrawingSurfaceGTK();
mSurface = new nsDrawingSurfaceGTK();
mRenderingSurface->drawable = (GdkDrawable *)aWindow->GetNativeData(NS_NATIVE_WINDOW);
mRenderingSurface->gc = (GdkGC *)aWindow->GetNativeData(NS_NATIVE_GRAPHIC);
mOffscreenSurface = mRenderingSurface;
if (mSurface)
{
GdkDrawable *win = (GdkDrawable *)aWindow->GetNativeData(NS_NATIVE_WINDOW);
GdkGC *gc = (GdkGC *)aWindow->GetNativeData(NS_NATIVE_GRAPHIC);
mSurface->Init(win,gc);
mOffscreenSurface = mSurface;
NS_ADDREF(mSurface);
}
return (CommonInit());
}
@ -150,7 +155,7 @@ NS_IMETHODIMP nsRenderingContextGTK::Init(nsIDeviceContext* aContext,
mContext = aContext;
NS_IF_ADDREF(mContext);
mRenderingSurface = (nsDrawingSurfaceGTK *) aSurface;
mSurface = (nsDrawingSurfaceGTK *) aSurface;
return (CommonInit());
}
@ -186,27 +191,35 @@ NS_IMETHODIMP nsRenderingContextGTK::LockDrawingSurface(PRInt32 aX, PRInt32 aY,
void **aBits, PRInt32 *aStride,
PRInt32 *aWidthBytes, PRUint32 aFlags)
{
return NS_OK;
PushState();
return mSurface->Lock(aX, aY, aWidth, aHeight,
aBits, aStride, aWidthBytes, aFlags);
}
NS_IMETHODIMP nsRenderingContextGTK::UnlockDrawingSurface(void)
{
PRBool clipstate;
mSurface->Unlock();
PopState(clipstate);
return NS_OK;
}
NS_IMETHODIMP nsRenderingContextGTK::SelectOffScreenDrawingSurface(nsDrawingSurface aSurface)
{
if (nsnull == aSurface)
mRenderingSurface = mOffscreenSurface;
mSurface = mOffscreenSurface;
else
mRenderingSurface = (nsDrawingSurfaceGTK *)aSurface;
mSurface = (nsDrawingSurfaceGTK *)aSurface;
return NS_OK;
}
NS_IMETHODIMP nsRenderingContextGTK::GetDrawingSurface(nsDrawingSurface *aSurface)
{
*aSurface = mRenderingSurface;
*aSurface = mSurface;
return NS_OK;
}
@ -285,7 +298,7 @@ NS_IMETHODIMP nsRenderingContextGTK::PopState(PRBool &aClipEmpty)
{
GdkRegion *rgn;
mRegion->GetNativeRegion((void*&)rgn);
::gdk_gc_set_clip_region (mRenderingSurface->gc, rgn);
::gdk_gc_set_clip_region (mSurface->GetGC(), rgn);
// can we destroy rgn now?
}
}
@ -360,7 +373,7 @@ NS_IMETHODIMP nsRenderingContextGTK::SetClipRect(const nsRect& aRect,
aClipEmpty = mRegion->IsEmpty();
mRegion->GetNativeRegion((void*&)rgn);
gdk_gc_set_clip_region(mRenderingSurface->gc,rgn);
gdk_gc_set_clip_region(mSurface->GetGC(),rgn);
return NS_OK;
}
@ -389,7 +402,7 @@ NS_IMETHODIMP nsRenderingContextGTK::SetClipRegion(const nsIRegion& aRegion,
aClipEmpty = mRegion->IsEmpty();
mRegion->GetNativeRegion((void*&)rgn);
gdk_gc_set_clip_region(mRenderingSurface->gc,rgn);
gdk_gc_set_clip_region(mSurface->GetGC(),rgn);
return NS_OK;
}
@ -432,7 +445,7 @@ NS_IMETHODIMP nsRenderingContextGTK::SetColor(nscolor aColor)
mCurrentColor = aColor;
::gdk_rgb_gc_set_foreground(mRenderingSurface->gc, NS_TO_GDK_RGB(mCurrentColor));
::gdk_rgb_gc_set_foreground(mSurface->GetGC(), NS_TO_GDK_RGB(mCurrentColor));
return NS_OK;
}
@ -462,7 +475,7 @@ NS_IMETHODIMP nsRenderingContextGTK::SetFont(nsIFontMetrics *aFontMetrics)
mFontMetrics->GetFontHandle(fontHandle);
mCurrentFont = (GdkFont *)fontHandle;
gdk_gc_set_font(mRenderingSurface->gc,
gdk_gc_set_font(mSurface->GetGC(),
mCurrentFont);
}
@ -476,21 +489,21 @@ NS_IMETHODIMP nsRenderingContextGTK::SetLineStyle(nsLineStyle aLineStyle)
switch(aLineStyle)
{
case nsLineStyle_kSolid:
::gdk_gc_set_line_attributes(mRenderingSurface->gc,
::gdk_gc_set_line_attributes(mSurface->GetGC(),
1, GDK_LINE_SOLID, (GdkCapStyle)0, (GdkJoinStyle)0);
break;
case nsLineStyle_kDashed: {
static char dashed[2] = {4,4};
::gdk_gc_set_dashes(mRenderingSurface->gc,
::gdk_gc_set_dashes(mSurface->GetGC(),
0, dashed, 2);
} break;
case nsLineStyle_kDotted: {
static char dotted[2] = {3,1};
::gdk_gc_set_dashes(mRenderingSurface->gc,
::gdk_gc_set_dashes(mSurface->GetGC(),
0, dotted, 2);
}break;
@ -545,7 +558,7 @@ NS_IMETHODIMP nsRenderingContextGTK::CreateDrawingSurface(nsRect *aBounds,
{
GdkPixmap *pixmap;
if (nsnull == mRenderingSurface) {
if (nsnull == mSurface) {
aSurface = nsnull;
return NS_ERROR_FAILURE;
}
@ -553,27 +566,28 @@ NS_IMETHODIMP nsRenderingContextGTK::CreateDrawingSurface(nsRect *aBounds,
g_return_val_if_fail (aBounds != NULL, NS_ERROR_FAILURE);
g_return_val_if_fail ((aBounds->width > 0) && (aBounds->height > 0), NS_ERROR_FAILURE);
pixmap = ::gdk_pixmap_new(mRenderingSurface->drawable, aBounds->width, aBounds->height, gdk_rgb_get_visual()->depth);
nsDrawingSurfaceGTK * surface = new nsDrawingSurfaceGTK();
nsDrawingSurfaceGTK *surf = new nsDrawingSurfaceGTK();
surface->drawable = pixmap;
surface->gc = mRenderingSurface->gc;
if (surf)
{
if (nsnull != aBounds)
surf->Init(mSurface->GetGC(), aBounds->width, aBounds->height, aSurfFlags);
else
surf->Init(mSurface->GetGC(), 0, 0, aSurfFlags);
}
aSurface = (nsDrawingSurface)surface;
aSurface = (nsDrawingSurface)surf;
return NS_OK;
}
NS_IMETHODIMP nsRenderingContextGTK::DestroyDrawingSurface(nsDrawingSurface aDS)
{
nsDrawingSurfaceGTK * surface = (nsDrawingSurfaceGTK *) aDS;
nsDrawingSurfaceGTK *surf = (nsDrawingSurfaceGTK *) aDS;
g_return_val_if_fail ((surface != NULL), NS_ERROR_FAILURE);
g_return_val_if_fail ((surface->drawable != NULL), NS_ERROR_FAILURE);
::gdk_gc_unref (surface->gc);
::gdk_pixmap_unref (surface->drawable);
g_return_val_if_fail ((surf != NULL), NS_ERROR_FAILURE);
delete surface;
NS_IF_RELEASE(surf);
return NS_OK;
}
@ -581,9 +595,9 @@ NS_IMETHODIMP nsRenderingContextGTK::DestroyDrawingSurface(nsDrawingSurface aDS)
NS_IMETHODIMP nsRenderingContextGTK::DrawLine(nscoord aX0, nscoord aY0, nscoord aX1, nscoord aY1)
{
g_return_val_if_fail(mTMatrix != NULL, NS_ERROR_FAILURE);
g_return_val_if_fail(mRenderingSurface != NULL, NS_ERROR_FAILURE);
g_return_val_if_fail(mRenderingSurface->drawable != NULL, NS_ERROR_FAILURE);
g_return_val_if_fail(mRenderingSurface->gc != NULL, NS_ERROR_FAILURE);
g_return_val_if_fail(mSurface != NULL, NS_ERROR_FAILURE);
g_return_val_if_fail(mSurface->GetDrawable() != NULL, NS_ERROR_FAILURE);
g_return_val_if_fail(mSurface->GetGC() != NULL, NS_ERROR_FAILURE);
mTMatrix->TransformCoord(&aX0,&aY0);
mTMatrix->TransformCoord(&aX1,&aY1);
@ -594,8 +608,8 @@ NS_IMETHODIMP nsRenderingContextGTK::DrawLine(nscoord aX0, nscoord aY0, nscoord
if (aX0 != aX1) {
aX1--;
}
::gdk_draw_line(mRenderingSurface->drawable,
mRenderingSurface->gc,
::gdk_draw_line(mSurface->GetDrawable(),
mSurface->GetGC(),
aX0, aY0, aX1, aY1);
return NS_OK;
@ -606,9 +620,9 @@ NS_IMETHODIMP nsRenderingContextGTK::DrawPolyline(const nsPoint aPoints[], PRInt
PRInt32 i;
g_return_val_if_fail(mTMatrix != NULL, NS_ERROR_FAILURE);
g_return_val_if_fail(mRenderingSurface != NULL, NS_ERROR_FAILURE);
g_return_val_if_fail(mRenderingSurface->drawable != NULL, NS_ERROR_FAILURE);
g_return_val_if_fail(mRenderingSurface->gc != NULL, NS_ERROR_FAILURE);
g_return_val_if_fail(mSurface != NULL, NS_ERROR_FAILURE);
g_return_val_if_fail(mSurface->GetDrawable() != NULL, NS_ERROR_FAILURE);
g_return_val_if_fail(mSurface->GetGC() != NULL, NS_ERROR_FAILURE);
GdkPoint *pts = new GdkPoint[aNumPoints];
for (i = 0; i < aNumPoints; i++)
@ -619,8 +633,8 @@ NS_IMETHODIMP nsRenderingContextGTK::DrawPolyline(const nsPoint aPoints[], PRInt
pts[i].y = p.y;
}
::gdk_draw_lines(mRenderingSurface->drawable,
mRenderingSurface->gc,
::gdk_draw_lines(mSurface->GetDrawable(),
mSurface->GetGC(),
pts, aNumPoints);
delete[] pts;
@ -635,7 +649,7 @@ NS_IMETHODIMP nsRenderingContextGTK::DrawRect(const nsRect& aRect)
NS_IMETHODIMP nsRenderingContextGTK::DrawRect(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight)
{
if (nsnull == mTMatrix || nsnull == mRenderingSurface) {
if (nsnull == mTMatrix || nsnull == mSurface) {
return NS_ERROR_FAILURE;
}
@ -646,12 +660,12 @@ NS_IMETHODIMP nsRenderingContextGTK::DrawRect(nscoord aX, nscoord aY, nscoord aW
w = aWidth;
h = aHeight;
g_return_val_if_fail ((mRenderingSurface->drawable != NULL) ||
(mRenderingSurface->gc != NULL), NS_ERROR_FAILURE);
g_return_val_if_fail ((mSurface->GetDrawable() != NULL) ||
(mSurface->GetGC() != NULL), NS_ERROR_FAILURE);
mTMatrix->TransformCoord(&x,&y,&w,&h);
::gdk_draw_rectangle(mRenderingSurface->drawable, mRenderingSurface->gc,
::gdk_draw_rectangle(mSurface->GetDrawable(), mSurface->GetGC(),
FALSE,
x, y, w - 1, h - 1);
@ -665,7 +679,7 @@ NS_IMETHODIMP nsRenderingContextGTK::FillRect(const nsRect& aRect)
NS_IMETHODIMP nsRenderingContextGTK::FillRect(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight)
{
if (nsnull == mTMatrix || nsnull == mRenderingSurface) {
if (nsnull == mTMatrix || nsnull == mSurface) {
return NS_ERROR_FAILURE;
}
@ -678,7 +692,7 @@ NS_IMETHODIMP nsRenderingContextGTK::FillRect(nscoord aX, nscoord aY, nscoord aW
mTMatrix->TransformCoord(&x,&y,&w,&h);
::gdk_draw_rectangle(mRenderingSurface->drawable, mRenderingSurface->gc,
::gdk_draw_rectangle(mSurface->GetDrawable(), mSurface->GetGC(),
TRUE,
x, y, w, h);
@ -688,9 +702,9 @@ NS_IMETHODIMP nsRenderingContextGTK::FillRect(nscoord aX, nscoord aY, nscoord aW
NS_IMETHODIMP nsRenderingContextGTK::DrawPolygon(const nsPoint aPoints[], PRInt32 aNumPoints)
{
g_return_val_if_fail(mTMatrix != NULL, NS_ERROR_FAILURE);
g_return_val_if_fail(mRenderingSurface != NULL, NS_ERROR_FAILURE);
g_return_val_if_fail(mRenderingSurface->drawable != NULL, NS_ERROR_FAILURE);
g_return_val_if_fail(mRenderingSurface->gc != NULL, NS_ERROR_FAILURE);
g_return_val_if_fail(mSurface != NULL, NS_ERROR_FAILURE);
g_return_val_if_fail(mSurface->GetDrawable() != NULL, NS_ERROR_FAILURE);
g_return_val_if_fail(mSurface->GetGC() != NULL, NS_ERROR_FAILURE);
GdkPoint *pts = new GdkPoint[aNumPoints];
for (PRInt32 i = 0; i < aNumPoints; i++)
@ -700,7 +714,7 @@ NS_IMETHODIMP nsRenderingContextGTK::DrawPolygon(const nsPoint aPoints[], PRInt3
pts[i].x = p.x;
pts[i].y = p.y;
}
::gdk_draw_polygon(mRenderingSurface->drawable, mRenderingSurface->gc, FALSE, pts, aNumPoints);
::gdk_draw_polygon(mSurface->GetDrawable(), mSurface->GetGC(), FALSE, pts, aNumPoints);
delete[] pts;
@ -710,9 +724,9 @@ NS_IMETHODIMP nsRenderingContextGTK::DrawPolygon(const nsPoint aPoints[], PRInt3
NS_IMETHODIMP nsRenderingContextGTK::FillPolygon(const nsPoint aPoints[], PRInt32 aNumPoints)
{
g_return_val_if_fail(mTMatrix != NULL, NS_ERROR_FAILURE);
g_return_val_if_fail(mRenderingSurface != NULL, NS_ERROR_FAILURE);
g_return_val_if_fail(mRenderingSurface->drawable != NULL, NS_ERROR_FAILURE);
g_return_val_if_fail(mRenderingSurface->gc != NULL, NS_ERROR_FAILURE);
g_return_val_if_fail(mSurface != NULL, NS_ERROR_FAILURE);
g_return_val_if_fail(mSurface->GetDrawable() != NULL, NS_ERROR_FAILURE);
g_return_val_if_fail(mSurface->GetGC() != NULL, NS_ERROR_FAILURE);
GdkPoint *pts = new GdkPoint[aNumPoints];
for (PRInt32 i = 0; i < aNumPoints; i++)
@ -722,7 +736,7 @@ NS_IMETHODIMP nsRenderingContextGTK::FillPolygon(const nsPoint aPoints[], PRInt3
pts[i].x = p.x;
pts[i].y = p.y;
}
::gdk_draw_polygon(mRenderingSurface->drawable, mRenderingSurface->gc, TRUE, pts, aNumPoints);
::gdk_draw_polygon(mSurface->GetDrawable(), mSurface->GetGC(), TRUE, pts, aNumPoints);
delete[] pts;
@ -737,9 +751,9 @@ NS_IMETHODIMP nsRenderingContextGTK::DrawEllipse(const nsRect& aRect)
NS_IMETHODIMP nsRenderingContextGTK::DrawEllipse(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight)
{
g_return_val_if_fail(mTMatrix != NULL, NS_ERROR_FAILURE);
g_return_val_if_fail(mRenderingSurface != NULL, NS_ERROR_FAILURE);
g_return_val_if_fail(mRenderingSurface->drawable != NULL, NS_ERROR_FAILURE);
g_return_val_if_fail(mRenderingSurface->gc != NULL, NS_ERROR_FAILURE);
g_return_val_if_fail(mSurface != NULL, NS_ERROR_FAILURE);
g_return_val_if_fail(mSurface->GetDrawable() != NULL, NS_ERROR_FAILURE);
g_return_val_if_fail(mSurface->GetGC() != NULL, NS_ERROR_FAILURE);
nscoord x,y,w,h;
@ -750,7 +764,7 @@ NS_IMETHODIMP nsRenderingContextGTK::DrawEllipse(nscoord aX, nscoord aY, nscoord
mTMatrix->TransformCoord(&x,&y,&w,&h);
::gdk_draw_arc(mRenderingSurface->drawable, mRenderingSurface->gc, FALSE,
::gdk_draw_arc(mSurface->GetDrawable(), mSurface->GetGC(), FALSE,
x, y, w, h,
0, 360 * 64);
@ -765,9 +779,9 @@ NS_IMETHODIMP nsRenderingContextGTK::FillEllipse(const nsRect& aRect)
NS_IMETHODIMP nsRenderingContextGTK::FillEllipse(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight)
{
g_return_val_if_fail(mTMatrix != NULL, NS_ERROR_FAILURE);
g_return_val_if_fail(mRenderingSurface != NULL, NS_ERROR_FAILURE);
g_return_val_if_fail(mRenderingSurface->drawable != NULL, NS_ERROR_FAILURE);
g_return_val_if_fail(mRenderingSurface->gc != NULL, NS_ERROR_FAILURE);
g_return_val_if_fail(mSurface != NULL, NS_ERROR_FAILURE);
g_return_val_if_fail(mSurface->GetDrawable() != NULL, NS_ERROR_FAILURE);
g_return_val_if_fail(mSurface->GetGC() != NULL, NS_ERROR_FAILURE);
nscoord x,y,w,h;
@ -778,7 +792,7 @@ NS_IMETHODIMP nsRenderingContextGTK::FillEllipse(nscoord aX, nscoord aY, nscoord
mTMatrix->TransformCoord(&x,&y,&w,&h);
::gdk_draw_arc(mRenderingSurface->drawable, mRenderingSurface->gc, TRUE,
::gdk_draw_arc(mSurface->GetDrawable(), mSurface->GetGC(), TRUE,
x, y, w, h,
0, 360 * 64);
@ -796,9 +810,9 @@ NS_IMETHODIMP nsRenderingContextGTK::DrawArc(nscoord aX, nscoord aY,
float aStartAngle, float aEndAngle)
{
g_return_val_if_fail(mTMatrix != NULL, NS_ERROR_FAILURE);
g_return_val_if_fail(mRenderingSurface != NULL, NS_ERROR_FAILURE);
g_return_val_if_fail(mRenderingSurface->drawable != NULL, NS_ERROR_FAILURE);
g_return_val_if_fail(mRenderingSurface->gc != NULL, NS_ERROR_FAILURE);
g_return_val_if_fail(mSurface != NULL, NS_ERROR_FAILURE);
g_return_val_if_fail(mSurface->GetDrawable() != NULL, NS_ERROR_FAILURE);
g_return_val_if_fail(mSurface->GetGC() != NULL, NS_ERROR_FAILURE);
nscoord x,y,w,h;
@ -809,7 +823,7 @@ NS_IMETHODIMP nsRenderingContextGTK::DrawArc(nscoord aX, nscoord aY,
mTMatrix->TransformCoord(&x,&y,&w,&h);
::gdk_draw_arc(mRenderingSurface->drawable, mRenderingSurface->gc, FALSE,
::gdk_draw_arc(mSurface->GetDrawable(), mSurface->GetGC(), FALSE,
x, y, w, h,
NSToIntRound(aStartAngle * 64.0f),
NSToIntRound(aEndAngle * 64.0f));
@ -829,9 +843,9 @@ NS_IMETHODIMP nsRenderingContextGTK::FillArc(nscoord aX, nscoord aY,
float aStartAngle, float aEndAngle)
{
g_return_val_if_fail(mTMatrix != NULL, NS_ERROR_FAILURE);
g_return_val_if_fail(mRenderingSurface != NULL, NS_ERROR_FAILURE);
g_return_val_if_fail(mRenderingSurface->drawable != NULL, NS_ERROR_FAILURE);
g_return_val_if_fail(mRenderingSurface->gc != NULL, NS_ERROR_FAILURE);
g_return_val_if_fail(mSurface != NULL, NS_ERROR_FAILURE);
g_return_val_if_fail(mSurface->GetDrawable() != NULL, NS_ERROR_FAILURE);
g_return_val_if_fail(mSurface->GetGC() != NULL, NS_ERROR_FAILURE);
nscoord x,y,w,h;
@ -842,7 +856,7 @@ NS_IMETHODIMP nsRenderingContextGTK::FillArc(nscoord aX, nscoord aY,
mTMatrix->TransformCoord(&x,&y,&w,&h);
::gdk_draw_arc(mRenderingSurface->drawable, mRenderingSurface->gc, TRUE,
::gdk_draw_arc(mSurface->GetDrawable(), mSurface->GetGC(), TRUE,
x, y, w, h,
NSToIntRound(aStartAngle * 64.0f),
NSToIntRound(aEndAngle * 64.0f));
@ -943,9 +957,9 @@ nsRenderingContextGTK::DrawString(const char *aString, PRUint32 aLength,
{
if (0 != aLength) {
g_return_val_if_fail(mTMatrix != NULL, NS_ERROR_FAILURE);
g_return_val_if_fail(mRenderingSurface != NULL, NS_ERROR_FAILURE);
g_return_val_if_fail(mRenderingSurface->drawable != NULL, NS_ERROR_FAILURE);
g_return_val_if_fail(mRenderingSurface->gc != NULL, NS_ERROR_FAILURE);
g_return_val_if_fail(mSurface != NULL, NS_ERROR_FAILURE);
g_return_val_if_fail(mSurface->GetDrawable() != NULL, NS_ERROR_FAILURE);
g_return_val_if_fail(mSurface->GetGC() != NULL, NS_ERROR_FAILURE);
g_return_val_if_fail(aString != NULL, NS_ERROR_FAILURE);
nscoord x = aX;
@ -965,16 +979,16 @@ nsRenderingContextGTK::DrawString(const char *aString, PRUint32 aLength,
nscoord xx = x;
nscoord yy = y;
mTMatrix->TransformCoord(&xx, &yy);
::gdk_draw_text(mRenderingSurface->drawable, mCurrentFont,
mRenderingSurface->gc,
::gdk_draw_text(mSurface->GetDrawable(), mCurrentFont,
mSurface->GetGC(),
xx, yy, &ch, 1);
x += *aSpacing++;
}
}
else {
mTMatrix->TransformCoord(&x, &y);
::gdk_draw_text (mRenderingSurface->drawable, mCurrentFont,
mRenderingSurface->gc,
::gdk_draw_text (mSurface->GetDrawable(), mCurrentFont,
mSurface->GetGC(),
x, y, aString, aLength);
}
}
@ -1024,9 +1038,9 @@ nsRenderingContextGTK::DrawString(const PRUnichar* aString, PRUint32 aLength,
{
if (0 != aLength) {
g_return_val_if_fail(mTMatrix != NULL, NS_ERROR_FAILURE);
g_return_val_if_fail(mRenderingSurface != NULL, NS_ERROR_FAILURE);
g_return_val_if_fail(mRenderingSurface->drawable != NULL, NS_ERROR_FAILURE);
g_return_val_if_fail(mRenderingSurface->gc != NULL, NS_ERROR_FAILURE);
g_return_val_if_fail(mSurface != NULL, NS_ERROR_FAILURE);
g_return_val_if_fail(mSurface->GetDrawable() != NULL, NS_ERROR_FAILURE);
g_return_val_if_fail(mSurface->GetGC() != NULL, NS_ERROR_FAILURE);
g_return_val_if_fail(aString != NULL, NS_ERROR_FAILURE);
nscoord x = aX;
@ -1046,8 +1060,8 @@ nsRenderingContextGTK::DrawString(const PRUnichar* aString, PRUint32 aLength,
nscoord xx = x;
nscoord yy = y;
mTMatrix->TransformCoord(&xx, &yy);
::gdk_draw_text_wc(mRenderingSurface->drawable, mCurrentFont,
mRenderingSurface->gc,
::gdk_draw_text_wc(mSurface->GetDrawable(), mCurrentFont,
mSurface->GetGC(),
xx, yy, &ch, 1);
x += *aSpacing++;
}
@ -1074,8 +1088,8 @@ nsRenderingContextGTK::DrawString(const PRUnichar* aString, PRUint32 aLength,
}
mTMatrix->TransformCoord(&x, &y);
::gdk_draw_text_wc (mRenderingSurface->drawable, mCurrentFont,
mRenderingSurface->gc,
::gdk_draw_text_wc (mSurface->GetDrawable(), mCurrentFont,
mSurface->GetGC(),
x, y, mDrawStringBuf, aLength);
}
}
@ -1121,7 +1135,7 @@ NS_IMETHODIMP nsRenderingContextGTK::DrawImage(nsIImage *aImage, const nsRect& a
tr = aRect;
mTMatrix->TransformCoord(&tr.x,&tr.y,&tr.width,&tr.height);
return aImage->Draw(*this,mRenderingSurface,tr.x,tr.y,tr.width,tr.height);
return aImage->Draw(*this,mSurface,tr.x,tr.y,tr.width,tr.height);
}
NS_IMETHODIMP nsRenderingContextGTK::DrawImage(nsIImage *aImage, const nsRect& aSRect, const nsRect& aDRect)
@ -1134,7 +1148,7 @@ NS_IMETHODIMP nsRenderingContextGTK::DrawImage(nsIImage *aImage, const nsRect& a
dr = aDRect;
mTMatrix->TransformCoord(&dr.x,&dr.y,&dr.width,&dr.height);
return aImage->Draw(*this,mRenderingSurface,sr.x,sr.y,sr.width,sr.height,
return aImage->Draw(*this,mSurface,sr.x,sr.y,sr.width,sr.height,
dr.x,dr.y,dr.width,dr.height);
}
@ -1151,14 +1165,14 @@ nsRenderingContextGTK::CopyOffScreenBits(nsDrawingSurface aSrcSurf,
g_return_val_if_fail(aSrcSurf != NULL, NS_ERROR_FAILURE);
g_return_val_if_fail(mTMatrix != NULL, NS_ERROR_FAILURE);
g_return_val_if_fail(mRenderingSurface != NULL, NS_ERROR_FAILURE);
g_return_val_if_fail(mRenderingSurface->drawable != NULL, NS_ERROR_FAILURE);
g_return_val_if_fail(mRenderingSurface->gc != NULL, NS_ERROR_FAILURE);
g_return_val_if_fail(mSurface != NULL, NS_ERROR_FAILURE);
g_return_val_if_fail(mSurface->GetDrawable() != NULL, NS_ERROR_FAILURE);
g_return_val_if_fail(mSurface->GetGC() != NULL, NS_ERROR_FAILURE);
if (aCopyFlags & NS_COPYBITS_TO_BACK_BUFFER)
{
NS_ASSERTION(!(nsnull == mRenderingSurface), "no back buffer");
destsurf = mRenderingSurface;
NS_ASSERTION(!(nsnull == mSurface), "no back buffer");
destsurf = mSurface;
}
else
destsurf = mOffscreenSurface;
@ -1172,9 +1186,9 @@ nsRenderingContextGTK::CopyOffScreenBits(nsDrawingSurface aSrcSurf,
//XXX flags are unused. that would seem to mean that there is
//inefficiency somewhere... MMP
::gdk_draw_pixmap(destsurf->drawable,
((nsDrawingSurfaceGTK *)aSrcSurf)->gc,
((nsDrawingSurfaceGTK *)aSrcSurf)->drawable,
::gdk_draw_pixmap(destsurf->GetDrawable(),
((nsDrawingSurfaceGTK *)aSrcSurf)->GetGC(),
((nsDrawingSurfaceGTK *)aSrcSurf)->GetDrawable(),
x, y,
drect.x, drect.y,
drect.width, drect.height);

Просмотреть файл

@ -34,7 +34,7 @@
#include "nsIDeviceContext.h"
#include "nsVoidArray.h"
#include "nsOldDrawingSurfaceGTK.h"
#include "nsDrawingSurfaceGTK.h"
#include "nsRegionGTK.h"
#include <gtk/gtk.h>
@ -153,7 +153,7 @@ public:
protected:
nsDrawingSurfaceGTK *mOffscreenSurface;
nsDrawingSurfaceGTK *mRenderingSurface;
nsDrawingSurfaceGTK *mSurface;
nsIDeviceContext *mContext;
nsIFontMetrics *mFontMetrics;
nsRegionGTK *mRegion;