Bug 446675 - "Remove BeOS port of gfx" [r=vlad]

This commit is contained in:
Joe Drew 2008-08-19 22:45:02 -05:00
parent f9365c3994
commit 7f741a1112
20 changed files with 0 additions and 5430 deletions

View File

@ -1,93 +0,0 @@
#
# ***** BEGIN LICENSE BLOCK *****
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
#
# The contents of this file are subject to the Mozilla Public License Version
# 1.1 (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
# http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
# for the specific language governing rights and limitations under the
# License.
#
# The Original Code is mozilla.org code.
#
# The Initial Developer of the Original Code is
# Netscape Communications Corporation.
# Portions created by the Initial Developer are Copyright (C) 1998
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
#
# Alternatively, the contents of this file may be used under the terms of
# either of the GNU General Public License Version 2 or later (the "GPL"),
# or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
# in which case the provisions of the GPL or the LGPL are applicable instead
# of those above. If you wish to allow use of your version of this file only
# under the terms of either the GPL or the LGPL, and not to allow others to
# use your version of this file under the terms of the MPL, indicate your
# decision by deleting the provisions above and replace them with the notice
# and other provisions required by the GPL or the LGPL. If you do not delete
# the provisions above, a recipient may use your version of this file under
# the terms of any one of the MPL, the GPL or the LGPL.
#
# ***** END LICENSE BLOCK *****
DEPTH = ../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
MODULE = gfx
LIBRARY_NAME = gfx_beos
EXPORT_LIBRARY = 1
IS_COMPONENT = 1
MODULE_NAME = nsGfxBeOSModule
GRE_MODULE = 1
LIBXUL_LIBRARY = 1
PACKAGE_FILE = gfxbeos.pkg
CPPSRCS = \
nsDeviceContextBeOS.cpp \
nsDrawingSurfaceBeOS.cpp \
nsFontMetricsBeOS.cpp \
nsGfxFactoryBeOS.cpp \
nsGraphicsStateBeOS.cpp \
nsRenderingContextBeOS.cpp \
nsImageBeOS.cpp \
nsRegionBeOS.cpp \
$(NULL)
REQUIRES = xpcom \
string \
pref \
widget \
view \
intl \
uconv \
unicharutil \
$(NULL)
EXTRA_DSO_LDOPTS = $(DIST)/lib/$(LIB_PREFIX)gfxshared_s.$(LIB_SUFFIX)
include $(topsrcdir)/config/rules.mk
CXXFLAGS += $(TK_CFLAGS)
INCLUDES += $(TK_CFLAGS)
EXTRA_DSO_LDOPTS += $(MOZ_COMPONENT_LIBS) $(MOZ_JS_LIBS) \
-lgkgfx \
$(XPCOM_LIBS) \
$(TK_LIBS) \
$(NSPR_LIBS)
INCLUDES += \
-I$(srcdir)/. \
-I$(srcdir)/.. \
-I$(srcdir)/../shared \
$(NULL)

View File

@ -1,6 +0,0 @@
[gecko]
#if SHARED_LIBRARY
dist/bin/components/@SHARED_LIBRARY@
#else
!staticcomp @LIBRARY@ @MODULE_NAME@
#endif

View File

@ -1,457 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Pierre Phaneuf <pp@ludusdesign.com>
* Sergei Dolgov <sergei_d@fi.tartu.ee>
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include <math.h>
#include <Menu.h>
#include "nspr.h"
#include "nsIPref.h"
#include "nsIServiceManager.h"
#include "nsCRT.h"
#include "nsReadableUtils.h"
#include "nsDeviceContextBeOS.h"
#include "nsFontMetricsBeOS.h"
#include "nsGfxCIID.h"
#include <ScrollBar.h>
#include <Screen.h>
#include "nsIScreenManager.h"
nscoord nsDeviceContextBeOS::mDpi = 96;
nsDeviceContextBeOS::nsDeviceContextBeOS()
: DeviceContextImpl()
{
mTwipsToPixels = 1.0;
mPixelsToTwips = 1.0;
mDepth = 0 ;
mNumCells = 0;
mWidthFloat = 0.0f;
mHeightFloat = 0.0f;
mWidth = -1;
mHeight = -1;
}
nsDeviceContextBeOS::~nsDeviceContextBeOS()
{
nsresult rv;
nsCOMPtr<nsIPref> prefs = do_GetService(NS_PREF_CONTRACTID, &rv);
if (NS_SUCCEEDED(rv))
prefs->UnregisterCallback("layout.css.dpi", prefChanged, (void *)this);
}
NS_IMETHODIMP nsDeviceContextBeOS::Init(nsNativeWidget aNativeWidget)
{
// get the screen object and its width/height
// XXXRight now this will only get the primary monitor.
nsresult ignore;
mWidget = aNativeWidget;
nsCOMPtr<nsIScreenManager> sm ( do_GetService("@mozilla.org/gfx/screenmanager;1", &ignore) );
if (sm)
{
nsCOMPtr<nsIScreen> screen;
sm->GetPrimaryScreen(getter_AddRefs(screen));
if (screen)
{
PRInt32 x, y, width, height, depth;
screen->GetAvailRect ( &x, &y, &width, &height );
screen->GetPixelDepth ( &depth );
mWidthFloat = float(width);
mHeightFloat = float(height);
mDepth = static_cast<PRUint32>(depth);
}
}
static int initialized = 0;
if (!initialized)
{
initialized = 1;
// Set prefVal the value of the preference "layout.css.dpi"
// or -1 if we can't get it.
// If it's negative, we pretend it's not set.
// If it's 0, it means force use of the operating system's logical resolution.
// If it's positive, we use it as the logical resolution
PRInt32 prefVal = -1;
nsresult res;
nsCOMPtr<nsIPref> prefs(do_GetService(NS_PREF_CONTRACTID, &res));
if (NS_SUCCEEDED(res) && prefs)
{
res = prefs->GetIntPref("layout.css.dpi", &prefVal);
if (! NS_SUCCEEDED(res))
{
prefVal = -1;
}
prefs->RegisterCallback("layout.css.dpi", prefChanged, (void *)this);
}
// Set OSVal to what the operating system thinks the logical resolution is.
// BeOS lacks monitor info, so we use fixed value for now
PRInt32 OSVal = 85;
if (prefVal > 0)
{
// If there's a valid pref value for the logical resolution,
// use it.
mDpi = prefVal;
}
else if ((prefVal == 0) || (OSVal > 96))
{
// Either if the pref is 0 (force use of OS value) or the OS
// value is bigger than 96, use the OS value.
mDpi = OSVal;
}
else
{
// if we couldn't get the pref or it's negative, and the OS
// value is under 96ppi, then use 96.
mDpi = 96;
}
}
SetDPI(mDpi);
menu_info info;
get_menu_info(&info);
mMenuFont.SetFamilyAndStyle(info.f_family,info.f_style);
mMenuFont.SetSize(info.font_size);
#ifdef DEBUG
static PRBool once = PR_TRUE;
if (once)
{
printf("GFX: dpi=%d t2p=%g p2t=%g depth=%d\n", mDpi, mTwipsToPixels, mPixelsToTwips,mDepth);
once = PR_FALSE;
}
#endif
DeviceContextImpl::CommonInit();
return NS_OK;
}
NS_IMETHODIMP nsDeviceContextBeOS::CreateRenderingContext(nsIRenderingContext *&aContext)
{
nsIRenderingContext *pContext;
nsresult rv;
nsDrawingSurfaceBeOS *surf;
BView *w;
w = (BView*)mWidget;
// to call init for this, we need to have a valid nsDrawingSurfaceBeOS created
pContext = new nsRenderingContextBeOS();
if (nsnull != pContext)
{
NS_ADDREF(pContext);
// create the nsDrawingSurfaceBeOS
surf = new nsDrawingSurfaceBeOS();
if (surf && w)
{
// init the nsDrawingSurfaceBeOS
rv = surf->Init(w);
if (NS_OK == rv)
// Init the nsRenderingContextBeOS
rv = pContext->Init(this, surf);
}
else
{
rv = NS_ERROR_OUT_OF_MEMORY;
}
}
else
{
rv = NS_ERROR_OUT_OF_MEMORY;
}
if (NS_OK != rv)
NS_IF_RELEASE(pContext);
aContext = pContext;
return rv;
}
NS_IMETHODIMP nsDeviceContextBeOS::SupportsNativeWidgets(PRBool &aSupportsWidgets)
{
//XXX it is very critical that this not lie!! MMP
// read the comments in the mac code for this
aSupportsWidgets = PR_TRUE;
return NS_OK;
}
NS_IMETHODIMP nsDeviceContextBeOS::GetSystemFont(nsSystemFontID aID, nsFont *aFont) const
{
nsresult status = NS_OK;
switch (aID)
{
case eSystemFont_PullDownMenu:
case eSystemFont_Menu:
status = GetSystemFontInfo(&mMenuFont, aID, aFont);
break;
case eSystemFont_Caption: // css2 bold
status = GetSystemFontInfo(be_bold_font, aID, aFont);
break;
case eSystemFont_List:
case eSystemFont_Field:
case eSystemFont_Icon :
case eSystemFont_MessageBox :
case eSystemFont_SmallCaption :
case eSystemFont_StatusBar :
case eSystemFont_Window: // css3
case eSystemFont_Document:
case eSystemFont_Workspace:
case eSystemFont_Desktop:
case eSystemFont_Info:
case eSystemFont_Dialog:
case eSystemFont_Button:
case eSystemFont_Tooltips: // moz
case eSystemFont_Widget:
default:
status = GetSystemFontInfo(be_plain_font, aID, aFont);
}
return status;
}
NS_IMETHODIMP nsDeviceContextBeOS::CheckFontExistence(const nsString& aFontName)
{
return nsFontMetricsBeOS::FamilyExists(aFontName);
}
/*
NS_IMETHODIMP nsDeviceContextBeOS::CheckFontExistence(const nsString& aFontName)
{
PRBool isthere = PR_FALSE;
char* cStr = ToNewCString(aFontName);
int32 numFamilies = count_font_families();
for(int32 i = 0; i < numFamilies; i++)
{
font_family family;
uint32 flags;
if(get_font_family(i, &family, &flags) == B_OK)
{
if(strcmp(family, cStr) == 0)
{
isthere = PR_TRUE;
break;
}
}
}
//printf("%s there? %s\n", cStr, isthere?"Yes":"No" );
delete[] cStr;
if (PR_TRUE == isthere)
return NS_OK;
else
return NS_ERROR_FAILURE;
}
*/
NS_IMETHODIMP nsDeviceContextBeOS::GetDeviceSurfaceDimensions(PRInt32 &aWidth, PRInt32 &aHeight)
{
if (mWidth == -1)
mWidth = NSToIntRound(mWidthFloat * mDevUnitsToAppUnits);
if (mHeight == -1)
mHeight = NSToIntRound(mHeightFloat * mDevUnitsToAppUnits);
aWidth = mWidth;
aHeight = mHeight;
return NS_OK;
}
NS_IMETHODIMP nsDeviceContextBeOS::GetRect(nsRect &aRect)
{
PRInt32 width, height;
nsresult rv;
rv = GetDeviceSurfaceDimensions(width, height);
aRect.x = 0;
aRect.y = 0;
aRect.width = width;
aRect.height = height;
return rv;
}
NS_IMETHODIMP nsDeviceContextBeOS::GetClientRect(nsRect &aRect)
{
//XXX do we know if the client rect should ever differ from the screen rect?
return GetRect(aRect);
}
NS_IMETHODIMP nsDeviceContextBeOS::GetDeviceContextFor(nsIDeviceContextSpec *aDevice,
nsIDeviceContext *&aContext)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP nsDeviceContextBeOS::BeginDocument(PRUnichar * aTitle, PRUnichar* aPrintToFileName, PRInt32 aStartPage, PRInt32 aEndPage)
{
return NS_OK;
}
NS_IMETHODIMP nsDeviceContextBeOS::EndDocument(void)
{
return NS_OK;
}
NS_IMETHODIMP nsDeviceContextBeOS::BeginPage(void)
{
return NS_OK;
}
NS_IMETHODIMP nsDeviceContextBeOS::EndPage(void)
{
return NS_OK;
}
NS_IMETHODIMP nsDeviceContextBeOS::GetDepth(PRUint32& aDepth)
{
aDepth = mDepth;
return NS_OK;
}
nsresult
nsDeviceContextBeOS::SetDPI(PRInt32 aDpi)
{
mDpi = aDpi;
int pt2t = 72;
mPixelsToTwips = float(NSToIntRound(float(NSIntPointsToTwips(pt2t)) / float(aDpi)));
mTwipsToPixels = 1.0f / mPixelsToTwips;
// XXX need to reflow all documents
return NS_OK;
}
int nsDeviceContextBeOS::prefChanged(const char *aPref, void *aClosure)
{
nsDeviceContextBeOS *context = (nsDeviceContextBeOS*)aClosure;
nsresult rv;
if (nsCRT::strcmp(aPref, "layout.css.dpi")==0)
{
PRInt32 dpi;
nsCOMPtr<nsIPref> prefs(do_GetService(NS_PREF_CONTRACTID, &rv));
rv = prefs->GetIntPref(aPref, &dpi);
if (NS_SUCCEEDED(rv))
context->SetDPI(dpi);
}
return 0;
}
nsresult
nsDeviceContextBeOS::GetSystemFontInfo(const BFont *theFont, nsSystemFontID anID, nsFont* aFont) const
{
nsresult status = NS_OK;
aFont->style = NS_FONT_STYLE_NORMAL;
aFont->weight = NS_FONT_WEIGHT_NORMAL;
aFont->decorations = NS_FONT_DECORATION_NONE;
// do we have the default_font defined by BeOS, if not then
// we error out.
if (!theFont)
{
switch (anID)
{
case eSystemFont_Menu:
status = GetSystemFontInfo(&mMenuFont, anID, aFont);
break;
case eSystemFont_List:
case eSystemFont_Field:
theFont = be_plain_font;
break;
case eSystemFont_Caption:
theFont = be_bold_font;
break;
default:
theFont = be_plain_font; // BeOS default font
}
}
if (!theFont)
{
status = NS_ERROR_FAILURE;
}
else
{
font_family family;
font_style style;
font_height height;
uint16 face;
theFont->GetFamilyAndStyle(&family, &style);
face = theFont->Face();
aFont->name.Assign(NS_ConvertUTF8toUTF16(family));
aFont->size = NSIntPixelsToTwips(uint32(theFont->Size()), mPixelsToTwips);
if(face & B_ITALIC_FACE)
aFont->style = NS_FONT_STYLE_ITALIC;
if(face & B_BOLD_FACE)
aFont->weight = NS_FONT_WEIGHT_BOLD;
if(face & B_UNDERSCORE_FACE)
aFont->decorations |= NS_FONT_DECORATION_UNDERLINE;
if(face & B_STRIKEOUT_FACE)
aFont->decorations |= NS_FONT_DECORATION_LINE_THROUGH;
aFont->systemFont = PR_TRUE;
status = NS_OK;
}
return (status);
}

View File

@ -1,100 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef nsDeviceContextBeOS_h___
#define nsDeviceContextBeOS_h___
#include "nsDeviceContext.h"
#include "nsIWidget.h"
#include "nsIView.h"
#include "nsIRenderingContext.h"
#include "nsRenderingContextBeOS.h"
class nsDeviceContextBeOS : public DeviceContextImpl
{
public:
nsDeviceContextBeOS();
virtual ~nsDeviceContextBeOS();
NS_IMETHOD Init(nsNativeWidget aNativeWidget);
NS_IMETHOD CreateRenderingContext(nsIRenderingContext *&aContext);
NS_IMETHOD CreateRenderingContext(nsIView *aView, nsIRenderingContext *&aContext) {return (DeviceContextImpl::CreateRenderingContext(aView,aContext));}
NS_IMETHOD CreateRenderingContext(nsIWidget *aWidget, nsIRenderingContext *&aContext) {return (DeviceContextImpl::CreateRenderingContext(aWidget,aContext));}
NS_IMETHOD SupportsNativeWidgets(PRBool &aSupportsWidgets);
NS_IMETHOD GetSystemFont(nsSystemFontID anID, nsFont *aFont) const;
NS_IMETHOD CheckFontExistence(const nsString& aFontName);
NS_IMETHOD GetDeviceSurfaceDimensions(PRInt32 &aWidth, PRInt32 &aHeight);
NS_IMETHOD GetClientRect(nsRect &aRect);
NS_IMETHOD GetRect(nsRect &aRect);
NS_IMETHOD GetDeviceContextFor(nsIDeviceContextSpec *aDevice,
nsIDeviceContext *&aContext);
NS_IMETHOD BeginDocument(PRUnichar * aTitle, PRUnichar* aPrintToFileName, PRInt32 aStartPage, PRInt32 aEndPage);
NS_IMETHOD EndDocument(void);
NS_IMETHOD BeginPage(void);
NS_IMETHOD EndPage(void);
NS_IMETHOD GetDepth(PRUint32& aDepth);
static int prefChanged(const char *aPref, void *aClosure);
nsresult SetDPI(PRInt32 dpi);
private:
PRUint32 mDepth;
PRBool mWriteable;
PRUint32 mNumCells;
BFont mMenuFont;
static nscoord mDpi;
float mWidthFloat;
float mHeightFloat;
PRInt32 mWidth;
PRInt32 mHeight;
nsresult GetSystemFontInfo(const BFont *font, nsSystemFontID anID, nsFont* aFont) const;
};
#endif /* nsDeviceContextBeOS_h___ */

View File

@ -1,290 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s): Sergei Dolgov
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsDrawingSurfaceBeOS.h"
#include "nsCoord.h"
#include <Region.h>
NS_IMPL_ISUPPORTS2(nsDrawingSurfaceBeOS, nsIDrawingSurface, nsIDrawingSurfaceBeOS)
#ifdef CHEAP_PERFORMANCE_MEASUREMENT
static PRTime mLockTime, mUnlockTime;
#endif
nsDrawingSurfaceBeOS :: nsDrawingSurfaceBeOS()
{
mView = nsnull;
mBitmap = nsnull;
mWidth = 0;
mHeight = 0;
mLockFlags = 0;
mLocked = PR_FALSE;
}
nsDrawingSurfaceBeOS :: ~nsDrawingSurfaceBeOS()
{
if(mBitmap)
{
// Deleting mBitmap will also remove and delete any child views
mBitmap->Unlock();
delete mBitmap;
mView = nsnull;
mBitmap = nsnull;
}
}
/**
* Lock a rect of a drawing surface and return a
* pointer to the upper left hand corner of the
* bitmap.
* @param aX x position of subrect of bitmap
* @param aY y position of subrect of bitmap
* @param aWidth width of subrect of bitmap
* @param aHeight height of subrect of bitmap
* @param aBits out parameter for upper left hand
* corner of bitmap
* @param aStride out parameter for number of bytes
* to add to aBits to go from scanline to scanline
* @param aWidthBytes out parameter for number of
* bytes per line in aBits to process aWidth pixels
* @return error status
*
**/
NS_IMETHODIMP nsDrawingSurfaceBeOS :: Lock(PRInt32 aX, PRInt32 aY,
PRUint32 aWidth, PRUint32 aHeight,
void **aBits, PRInt32 *aStride,
PRInt32 *aWidthBytes, PRUint32 aFlags)
{
mLockFlags = aFlags;
if (mBitmap && !mLocked)
{
if (mView)
mView->Sync();
if (mLockFlags & NS_LOCK_SURFACE_READ_ONLY)
mBitmap->LockBits();
*aStride = mBitmap->BytesPerRow();
*aBits = (uint8 *)mBitmap->Bits() + aX*4 + *aStride * aY;
*aWidthBytes = aWidth*4;
mLocked = PR_TRUE;
}
else
{
NS_ASSERTION(0, "nested lock attempt");
return NS_ERROR_FAILURE;
}
return NS_OK;
}
NS_IMETHODIMP nsDrawingSurfaceBeOS :: Unlock(void)
{
if (mBitmap && mLocked)
{
if (mLockFlags & NS_LOCK_SURFACE_READ_ONLY)
mBitmap->UnlockBits();
mLocked = PR_FALSE;
}
return NS_OK;
}
NS_IMETHODIMP nsDrawingSurfaceBeOS :: GetDimensions(PRUint32 *aWidth, PRUint32 *aHeight)
{
*aWidth = mWidth;
*aHeight = mHeight;
return NS_OK;
}
NS_IMETHODIMP nsDrawingSurfaceBeOS :: IsOffscreen(PRBool *aOffScreen)
{
*aOffScreen = mIsOffscreen;//mBitmap ? PR_TRUE : PR_FALSE;
return NS_OK;
}
NS_IMETHODIMP nsDrawingSurfaceBeOS :: IsPixelAddressable(PRBool *aAddressable)
{
*aAddressable = PR_FALSE;
return NS_OK;
}
NS_IMETHODIMP nsDrawingSurfaceBeOS :: GetPixelFormat(nsPixelFormat *aFormat)
{
*aFormat = mPixFormat;
return NS_OK;
}
NS_IMETHODIMP nsDrawingSurfaceBeOS :: Init(BView *aView)
{
if (aView->LockLooper())
{
//remember dimensions
BRect r = aView->Bounds();
mWidth = nscoord(r.IntegerWidth() + 1);
mHeight = nscoord(r.IntegerHeight() + 1);
mView = aView;
aView->UnlockLooper();
}
// onscreen View, attached to BWindow, acquired via GetNativeData() call in nsRendering
mIsOffscreen = PR_FALSE;
return NS_OK;
}
NS_IMETHODIMP nsDrawingSurfaceBeOS :: Init(BView *aView, PRUint32 aWidth,
PRUint32 aHeight, PRUint32 aFlags)
{
NS_ASSERTION(!(aView == nsnull), "null BView");
//remember dimensions
mWidth=aWidth;
mHeight=aHeight;
mFlags = aFlags;
//creating offscreen backbuffer surface
mIsOffscreen = PR_TRUE;
//TODO: Maybe we should reuse BView by resizing it,
//and also reuse BBitmap if new size is = < of current size
BRect r(0,0, mWidth-1, mHeight-1);
//creating auxiliary BView to draw on offscreen BBitmap
mView = new BView(r, "", 0, 0);
if (!mView)
return NS_ERROR_OUT_OF_MEMORY;
//if((aFlags & NS_CREATEDRAWINGSURFACE_FOR_PIXEL_ACCESS) &&
// (aWidth > 0) && (aHeight > 0))
if (aWidth > 0 && aHeight > 0)
{
///creating offscreen BBitmap
mBitmap = new BBitmap(r, B_RGBA32, true);
if (!mBitmap)
return NS_ERROR_OUT_OF_MEMORY;
if (mBitmap->InitCheck()!=B_OK)
{
//for some reason, the bitmap isn't valid - delete the
//bitmap object, then indicate failure
delete mBitmap;
mBitmap=NULL;
return NS_ERROR_FAILURE;
}
//NB! Locking bitmap for lifetime to avoid unneccessary locking at each
//drawing primitive call. Locking is quite time-expensive.
//To avoid it, we call surface->LockDrawable() instead LockLooper()
mBitmap->Lock();
//Setting ViewColor transparent noticeably decreases AppServer load in DrawBitmp()
//Applicable here, because Mozilla paints backgrounds explicitly, with images or filling areas.
mView->SetViewColor(B_TRANSPARENT_32_BIT);
mBitmap->AddChild(mView);
// Import prototype onscreen view state
if (aView && aView->LockLooper())
{
BRegion region;
BFont font;
mView->SetHighColor(aView->HighColor());
mView->SetLowColor(aView->LowColor());
aView->GetFont(&font);
mView->SetFont(&font);
aView->GetClippingRegion(&region);
mView->ConstrainClippingRegion(&region);
mView->SetOrigin(aView->Origin());
mView->SetFlags(aView->Flags());
aView->UnlockLooper();
}
}
return NS_OK;
}
NS_IMETHODIMP nsDrawingSurfaceBeOS :: AcquireView(BView **aView)
{
*aView = mView;
return NS_OK;
}
NS_IMETHODIMP nsDrawingSurfaceBeOS :: AcquireBitmap(BBitmap **aBitmap)
{
if (mBitmap && mView)
{
mView->Sync();
}
*aBitmap = mBitmap;
return NS_OK;
}
NS_IMETHODIMP nsDrawingSurfaceBeOS :: ReleaseView(void)
{
return NS_OK;
}
NS_IMETHODIMP nsDrawingSurfaceBeOS :: ReleaseBitmap(void)
{
return NS_OK;
}
bool nsDrawingSurfaceBeOS :: LockDrawable()
{
//TODO: try to avoid exta locking also for onscreen BView.
//Perhaps it needs synchronization with widget through nsToolkit and lock counting.
bool rv = false;
if (!mBitmap)
{
// Non-bitmap (BWindowed) view - lock it as required if exists
rv = mView && mView->LockLooper();
}
else
{
// Was locked in Init(), only test for locked state here
rv = mBitmap->IsLocked();
}
return rv;
}
void nsDrawingSurfaceBeOS :: UnlockDrawable()
{
// Do nothing, bitmap is locked for lifetime in our implementation
if (mBitmap)
return;
// Non-bitmap (BWindowed) view - unlock it as required.
// mBitmap may be gone in destroy process, so additional check for Looper()
if (mView && mView->Looper())
mView->UnlockLooper();
}

View File

@ -1,100 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s): Sergei Dolgov
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef nsDrawingSurfaceBeOS_h___
#define nsDrawingSurfaceBeOS_h___
#include "nsIDrawingSurface.h"
#include "nsIDrawingSurfaceBeOS.h"
#include <Bitmap.h>
#include <View.h>
class nsDrawingSurfaceBeOS : public nsIDrawingSurface,
public nsIDrawingSurfaceBeOS
{
public:
nsDrawingSurfaceBeOS();
virtual ~nsDrawingSurfaceBeOS();
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);
// local methods
NS_IMETHOD Init(BView *aView);
NS_IMETHOD Init(BView *aView, PRUint32 aWidth, PRUint32 aHeight,
PRUint32 aFlags);
/* below are utility functions used mostly for nsRenderingContext and nsImage
* to plug into gdk_* functions for drawing. You should not set a pointer
* that might hang around with the return from these. instead use the ones
* above. pav
*/
NS_IMETHOD AcquireView(BView **aView);
NS_IMETHOD ReleaseView(void);
NS_IMETHOD AcquireBitmap(BBitmap **aBitmap);
NS_IMETHOD ReleaseBitmap(void);
void GetSize(PRUint32 *aWidth, PRUint32 *aHeight) { *aWidth = mWidth; *aHeight = mHeight; }
bool LockDrawable();
void UnlockDrawable();
private:
BView *mView;
BBitmap *mBitmap;
nsPixelFormat mPixFormat;
PRUint32 mWidth;
PRUint32 mHeight;
PRUint32 mFlags;
PRBool mIsOffscreen;
/* for locks */
PRUint32 mLockFlags;
PRBool mLocked;
};
#endif

View File

@ -1,725 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:set cindent ts=2 sts=2 sw=2 et: */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Yannick Koehler <koehler@mythrium.com>
* Christian M Hoffman <chrmhoffmann@web.de>
* Makoto hamanaka <VYA04230@nifty.com>
* Paul Ashford <arougthopher@lizardland.net>
* Sergei Dolgov <sergei_d@fi.tartu.ee>
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsQuickSort.h"
#include "nsFontMetricsBeOS.h"
#include "nsIServiceManager.h"
#include "nsICharsetConverterManager.h"
#include "nsISaveAsCharset.h"
#include "nsIPrefService.h"
#include "nsIPrefBranch.h"
#include "nsCOMPtr.h"
#include "nspr.h"
#include "nsReadableUtils.h"
#include <UnicodeBlockObjects.h>
#undef USER_DEFINED
#define USER_DEFINED "x-user-def"
#undef NOISY_FONTS
#undef REALLY_NOISY_FONTS
nsFontMetricsBeOS::nsFontMetricsBeOS()
{
}
nsFontMetricsBeOS::~nsFontMetricsBeOS()
{
if (mDeviceContext)
{
// Notify our device context that owns us so that it can update its font cache
mDeviceContext->FontMetricsDeleted(this);
mDeviceContext = nsnull;
}
}
NS_IMPL_ISUPPORTS1(nsFontMetricsBeOS, nsIFontMetrics)
// a structure to hold a font family list
typedef struct nsFontEnumParamsBeOS {
nsFontMetricsBeOS *metrics;
nsStringArray family;
nsVoidArray isgeneric;
} NS_FONT_ENUM_PARAMS_BEOS;
// a callback func to get a font family list from a nsFont object
static PRBool FontEnumCallback(const nsString& aFamily, PRBool aGeneric, void *aData)
{
NS_FONT_ENUM_PARAMS_BEOS *param = (NS_FONT_ENUM_PARAMS_BEOS *) aData;
param->family.AppendString(aFamily);
param->isgeneric.AppendElement((void*) aGeneric);
if (aGeneric)
return PR_FALSE;
return PR_TRUE;
}
NS_IMETHODIMP nsFontMetricsBeOS::Init(const nsFont& aFont, nsIAtom* aLangGroup,
nsIDeviceContext* aContext)
{
NS_ASSERTION(!(nsnull == aContext), "attempt to init fontmetrics with null device context");
mLangGroup = aLangGroup;
mDeviceContext = aContext;
// get font family list
NS_FONT_ENUM_PARAMS_BEOS param;
param.metrics = this;
aFont.EnumerateFamilies(FontEnumCallback, &param);
PRInt16 face = 0;
mFont = aFont;
float app2twip = aContext->DevUnitsToTwips();
// process specified fonts from first item of the array.
// stop processing next when a real font found;
PRBool fontfound = PR_FALSE;
PRBool isfixed = PR_FALSE;
for (int i=0 ; i<param.family.Count() && !fontfound ; i++)
{
nsString *fam = param.family.StringAt(i);
PRBool isgeneric = ( param.isgeneric[i] ) ? PR_TRUE: PR_FALSE;
NS_ConvertUTF16toUTF8 family(*fam);
// Fallback
isfixed = family.Equals("monospace") || family.Equals("fixed");
if (!isgeneric)
{
// non-generic font
if (count_font_styles((font_family)family.get()) <= 0)
{
// the specified font does not exist on this computer.
continue;
}
mFontHandle.SetFamilyAndStyle( (font_family)family.get(), NULL );
fontfound = PR_TRUE;
break;
}
else
{
// family is generic string like
// "serif" "sans-serif" "cursive" "fantasy" "monospace" "-moz-fixed"
// so look up preferences and get real family name
const char *lang;
aLangGroup->GetUTF8String( &lang );
char prop[256];
snprintf( prop, sizeof(prop), "%s.%s", family.get(), lang );
// look up prefs
nsXPIDLCString real_family;
nsresult res;
//NS_WITH_SERVICE( nsIPref, prefs, kPrefCID, &res );
nsCOMPtr<nsIPrefService> prefs = do_GetService( NS_PREFSERVICE_CONTRACTID, &res );
if (NS_SUCCEEDED(res))
{
nsCOMPtr<nsIPrefBranch> branch;
prefs->GetBranch("font.name.", getter_AddRefs(branch));
branch->GetCharPref(prop, getter_Copies(real_family));
if (!real_family.IsEmpty() && real_family.Length() <= B_FONT_FAMILY_LENGTH && count_font_styles((font_family)real_family.get()) > 0)
{
mFontHandle.SetFamilyAndStyle( (font_family)real_family.get(), NULL );
fontfound = PR_TRUE;
break;
}
}
// not successful. use system font.
if (isfixed)
mFontHandle = BFont(be_fixed_font);
else
mFontHandle = BFont(be_plain_font);
fontfound = PR_TRUE;
break;
}
}
// if got no font, then use system font.
if (!fontfound)
{
if (isfixed)
mFontHandle = BFont(be_fixed_font);
else
mFontHandle = BFont(be_plain_font);
}
if (aFont.style == NS_FONT_STYLE_ITALIC)
face |= B_ITALIC_FACE;
if ( aFont.weight > NS_FONT_WEIGHT_NORMAL )
{
mIsBold = PR_TRUE;
face |= B_BOLD_FACE;
}
else
mIsBold = PR_FALSE;
// I don't think B_UNDERSCORE_FACE and B_STRIKEOUT_FACE really works...
// instead, nsTextFrame do them for us. ( my guess... Makoto Hamanaka )
if ( aFont.decorations & NS_FONT_DECORATION_UNDERLINE )
face |= B_UNDERSCORE_FACE;
if ( aFont.decorations & NS_FONT_DECORATION_LINE_THROUGH )
face |= B_STRIKEOUT_FACE;
mFontHandle.SetFace( face );
// emulate italic the selected family has no such style
if (aFont.style == NS_FONT_STYLE_ITALIC
&& !(mFontHandle.Face() & B_ITALIC_FACE))
mFontHandle.SetShear(105.0);
mFontHandle.SetSize(mFont.size/app2twip);
mFontHandle.SetSpacing(B_FIXED_SPACING);
#ifdef NOISY_FONTS
#ifdef DEBUG
fprintf(stderr, "looking for font %s (%d)", wildstring, aFont.size / app2twip);
#endif
#endif
//UTF8 charspace in BeOS is 0xFFFF, 256 is by "pighole rule" sqrt(0xFFFF),
// actually rare font contains more glyphs
mFontWidthCache.Init(256);
RealizeFont(aContext);
return NS_OK;
}
NS_IMETHODIMP nsFontMetricsBeOS::Destroy()
{
mDeviceContext = nsnull;
return NS_OK;
}
void nsFontMetricsBeOS::RealizeFont(nsIDeviceContext* aContext)
{
float f;
f = aContext->DevUnitsToAppUnits();
struct font_height height;
mFontHandle.GetHeight( &height );
struct font_height emHeight;
mFontHandle.GetHeight(&emHeight);
//be_plain_font->GetHeight(&emHeight);
int lineSpacing = nscoord(height.ascent + height.descent);
if (lineSpacing > (emHeight.ascent + emHeight.descent))
mLeading = nscoord((lineSpacing - (emHeight.ascent + emHeight.descent)) * f);
else
mLeading = 0;
mEmHeight = PR_MAX(1, nscoord((emHeight.ascent + emHeight.descent) * f));
mEmAscent = nscoord(height.ascent * (emHeight.ascent + emHeight.descent) * f / lineSpacing);
mEmDescent = mEmHeight - mEmAscent;
mMaxHeight = nscoord((height.ascent +
height.descent) * f) ;
mMaxAscent = nscoord(height.ascent * f) ;
mMaxDescent = nscoord(height.descent * f);
mMaxAdvance = nscoord((mFontHandle.BoundingBox().Width()+1) * f); //fyy +1
float rawWidth = mFontHandle.StringWidth("x");
mAveCharWidth = NSToCoordRound(rawWidth * f);
// 56% of ascent, best guess for non-true type
mXHeight = NSToCoordRound((float) height.ascent* f * 0.56f);
rawWidth = mFontHandle.StringWidth(" ");
mSpaceWidth = NSToCoordRound(rawWidth * f);
/* Temp */
mUnderlineOffset = -NSToIntRound(MAX (1, floor (0.1 * (height.ascent + height.descent + height.leading) + 0.5)) * f);
mUnderlineSize = NSToIntRound(MAX(1, floor (0.05 * (height.ascent + height.descent + height.leading) + 0.5)) * f);
mSuperscriptOffset = mXHeight;
mSubscriptOffset = mXHeight;
/* need better way to calculate this */
mStrikeoutOffset = NSToCoordRound(mXHeight / 2.0);
mStrikeoutSize = mUnderlineSize;
}
NS_IMETHODIMP nsFontMetricsBeOS::GetXHeight(nscoord& aResult)
{
aResult = mXHeight;
return NS_OK;
}
NS_IMETHODIMP nsFontMetricsBeOS::GetSuperscriptOffset(nscoord& aResult)
{
aResult = mSuperscriptOffset;
return NS_OK;
}
NS_IMETHODIMP nsFontMetricsBeOS::GetSubscriptOffset(nscoord& aResult)
{
aResult = mSubscriptOffset;
return NS_OK;
}
NS_IMETHODIMP nsFontMetricsBeOS::GetStrikeout(nscoord& aOffset, nscoord& aSize)
{
aOffset = mStrikeoutOffset;
aSize = mStrikeoutSize;
// aOffset = nscoord( ( mAscent / 2 ) - mDescent );
// aSize = nscoord( 20 ); // FIXME Put 1 pixel which equal 20 twips..
return NS_OK;
}
NS_IMETHODIMP nsFontMetricsBeOS::GetUnderline(nscoord& aOffset, nscoord& aSize)
{
aOffset = mUnderlineOffset;
aSize = mUnderlineSize;
//aOffset = nscoord( 0 ); // FIXME
//aSize = nscoord( 20 ); // FIXME
return NS_OK;
}
NS_IMETHODIMP nsFontMetricsBeOS::GetHeight(nscoord &aHeight)
{
aHeight = mMaxHeight;
return NS_OK;
}
NS_IMETHODIMP nsFontMetricsBeOS::GetNormalLineHeight(nscoord &aHeight)
{
aHeight = mEmHeight + mLeading;
return NS_OK;
}
NS_IMETHODIMP nsFontMetricsBeOS::GetLeading(nscoord &aLeading)
{
aLeading = mLeading;
return NS_OK;
}
NS_IMETHODIMP nsFontMetricsBeOS::GetEmHeight(nscoord &aHeight)
{
aHeight = mEmHeight;
return NS_OK;
}
NS_IMETHODIMP nsFontMetricsBeOS::GetEmAscent(nscoord &aAscent)
{
aAscent = mEmAscent;
return NS_OK;
}
NS_IMETHODIMP nsFontMetricsBeOS::GetEmDescent(nscoord &aDescent)
{
aDescent = mEmDescent;
return NS_OK;
}
NS_IMETHODIMP nsFontMetricsBeOS::GetMaxHeight(nscoord &aHeight)
{
aHeight = mMaxHeight;
return NS_OK;
}
NS_IMETHODIMP nsFontMetricsBeOS::GetMaxAscent(nscoord &aAscent)
{
aAscent = mMaxAscent;
return NS_OK;
}
NS_IMETHODIMP nsFontMetricsBeOS::GetMaxDescent(nscoord &aDescent)
{
aDescent = mMaxDescent;
return NS_OK;
}
NS_IMETHODIMP nsFontMetricsBeOS::GetMaxAdvance(nscoord &aAdvance)
{
aAdvance = mMaxAdvance;
return NS_OK;
}
NS_IMETHODIMP nsFontMetricsBeOS::GetAveCharWidth(nscoord &aAveCharWidth)
{
aAveCharWidth = mAveCharWidth;
return NS_OK;
}
NS_IMETHODIMP nsFontMetricsBeOS::GetSpaceWidth(nscoord &aSpaceWidth)
{
aSpaceWidth = mSpaceWidth;
return NS_OK;
}
NS_IMETHODIMP nsFontMetricsBeOS::GetLangGroup(nsIAtom** aLangGroup)
{
if (!aLangGroup)
return NS_ERROR_NULL_POINTER;
*aLangGroup = mLangGroup;
NS_IF_ADDREF(*aLangGroup);
return NS_OK;
}
NS_IMETHODIMP nsFontMetricsBeOS::GetFontHandle(nsFontHandle &aHandle)
{
aHandle = (nsFontHandle)&mFontHandle;
return NS_OK;
}
nsresult
nsFontMetricsBeOS::FamilyExists(const nsString& aName)
{
NS_ConvertUTF16toUTF8 family(aName);
printf("exists? %s", (font_family)family.get());
return (count_font_styles((font_family)family.get()) > 0) ? NS_OK : NS_ERROR_FAILURE;
}
// useful UTF-8 utility
inline uint32 utf8_char_len(uchar byte)
{
return (((0xE5000000 >> ((byte >> 3) & 0x1E)) & 3) + 1);
}
// nsHashKeys has trouble with char* substring conversion
// it likes 0-terminated, plus conversion to nsACString overhead.
// So KISS
inline PRUint32 utf8_to_index(char *utf8char)
{
PRUint32 ch = 0;
switch (utf8_char_len(*utf8char) - 1)
{
case 3: ch += *utf8char++; ch <<= 6;
case 2: ch += *utf8char++; ch <<= 6;
case 1: ch += *utf8char++; ch <<= 6;
case 0: ch += *utf8char++;
}
return ch;
}
// Using cached widths
float nsFontMetricsBeOS::GetStringWidth(char *utf8str, uint32 bytelen)
{
float retwidth = 0;
uint32 charlen = 1;
// Traversing utf8string - get, cache and sum widths for all utf8 chars
for (uint32 i =0; i < bytelen && *utf8str != '\0'; i += charlen)
{
float width = 0;
// Calculating utf8 char bytelength
charlen = ((0xE5000000 >> ((*utf8str >> 3) & 0x1E)) & 3) + 1;
// Converting multibyte sequence to index
PRUint32 index = utf8_to_index(utf8str);
if (!mFontWidthCache.Get(index, &width))
{
width = mFontHandle.StringWidth(utf8str, charlen);
mFontWidthCache.Put(index, width);
}
retwidth += width;
utf8str += charlen;
}
if (mIsBold && !(mFontHandle.Face() & B_BOLD_FACE))
retwidth += 1.0;
return retwidth;
}
// The Font Enumerator
nsFontEnumeratorBeOS::nsFontEnumeratorBeOS()
{
}
NS_IMPL_ISUPPORTS1(nsFontEnumeratorBeOS, nsIFontEnumerator)
static int
CompareFontNames(const void* aArg1, const void* aArg2, void* aClosure)
{
const PRUnichar* str1 = *((const PRUnichar**) aArg1);
const PRUnichar* str2 = *((const PRUnichar**) aArg2);
// XXX add nsICollation stuff
return nsCRT::strcmp(str1, str2);
}
static int
FontMatchesGenericType(font_family family, uint32 flags, const char* aGeneric,
const char* aLangGroup)
{
//Call from EnumerateAllFonts. Matches all.
//Return 1 immediately, because nsnull as argument of strstr causes crashes
if(aGeneric == nsnull || aLangGroup == nsnull)
return 1;
if (!strcmp(aLangGroup, "ja"))
return 1;
if (strstr(aLangGroup, "zh"))
return 1;
if (!strcmp(aLangGroup, "ko"))
return 1;
if (!strcmp(aLangGroup, "th"))
return 1;
if (!strcmp(aLangGroup, "he"))
return 1;
if (!strcmp(aLangGroup, "ar"))
return 1;
if (strstr(aLangGroup, "user-def"))
return 1;
if (!strcmp(aLangGroup, "unicode"))
return 1;
if (strstr(aGeneric, "fantasy")
// Let's use all possible fonts as decorative
#if 0
&& (strstr(family, "Baskerville") ||
strstr(family, "Chicago") ||
strstr(family, "Copprpl") ||
strstr(family, "Embassy") ||
strstr(family, "Europe") ||
strstr(family, "Garmnd") ||
strstr(family, "Impact") ||
strstr(family, "ProFont") ||
strstr(family, "VAGRounded"))
#endif
)
return 1;
// Hack. Sniffing is based on wide-spread names for serif and sansserif. No function in BeOS to get full font-info.
// NB! "Haru Tohaba" and "Haru" need EXACT match - !strcmp seems suspicious in that case, timeless !!!
if (!strcmp(aGeneric, "serif") &&
(strstr(family, "Dutch") || strstr(family, "Times") || strstr(family, "Roman") ||
strstr(family, "CentSchbook") || strstr(family, "Georgia") || strstr(family, "Baskerville") ||
strstr(family, "Garmnd") || strstr(family, "Cyberbit") || strcmp(family, "Haru Tohaba") == 0))
return 1;
if (!strcmp(aGeneric, "sans-serif") &&
(strstr(family, "Arial") || strstr(family, "Chianti") || strstr(family, "Helv") ||
strstr(family, "Humnst") || strstr(family, "Swiss") || strstr(family, "Tahoma") ||
strstr(family, "Sans") || strstr(family, "sans") || strstr(family, "Verdana") ||
strstr(family, "Zurich") || strcmp(family, "Haru") == 0))
return 1;
if ((strstr(aGeneric, "monospace") || strstr(aGeneric, "-moz-fixed")) &&
(flags & B_IS_FIXED || strstr(family, "Cour") || strstr(family, "Consol") ||
strstr(family, "Fixed") || strstr(family, "Kurier") || strstr(family, "Lucida") ||
strstr(family, "Mono") || strstr(family, "console") || strstr(family, "mono") ||
strstr(family, "fixed")))
return 1;
if (strstr(aGeneric, "cursive") &&
(strstr(family, "Cursiv") || strstr(family, "Kursiv") || strstr(family, "Script") ||
strstr(family, "kursiv") || strstr(family, "Embassy") || strstr(family, "script") ||
strstr(family, "Brush")))
return 1;
return 0;
}
static int MatchesLangGroup(font_family family, const char* aLangGroup)
{
BFont font;
font.SetFamilyAndStyle(family, NULL);
unicode_block lang = font.Blocks();
int match = 0;
//No restrictions
if ((strstr(aLangGroup, "user-def") || strstr(aLangGroup, "unicode")))
return 1;
// "tr" and "central-euro" need more testing, but seems OK
if ((strstr(aLangGroup, "baltic") || strstr(aLangGroup, "central-euro") || strstr(aLangGroup, "western")) &&
lang.Includes(B_LATIN1_SUPPLEMENT_BLOCK))
return 1;
if (strstr(aLangGroup, "tr") && lang.Includes(B_LATIN_EXTENDED_A_BLOCK))
return 1;
if (strstr(aLangGroup, "el") && lang.Includes(B_BASIC_GREEK_BLOCK))
return 1;
if (strstr(aLangGroup, "cyrillic") && lang.Includes(B_CYRILLIC_BLOCK))
return 1;
if (strstr(aLangGroup, "he") && lang.Includes(B_BASIC_HEBREW_BLOCK))
return 1;
if (strstr(aLangGroup, "ar") && lang.Includes(B_BASIC_ARABIC_BLOCK))
return 1;
if (strstr(aLangGroup, "th") && lang.Includes(B_THAI_BLOCK))
return 1;
// CKJ settings need more verification
if ((strstr(aLangGroup, "ja") || strstr(aLangGroup, "ko") || strstr(aLangGroup, "zh") ) &&
(lang.Includes(B_CJK_UNIFIED_IDEOGRAPHS_BLOCK) ||
lang.Includes(B_CJK_MISCELLANEOUS_BLOCK) ||
lang.Includes(B_ENCLOSED_CJK_LETTERS_AND_MONTHS_BLOCK) ||
lang.Includes(B_CJK_COMPATIBILITY_BLOCK) ||
lang.Includes(B_CJK_COMPATIBILITY_IDEOGRAPHS_BLOCK) ||
lang.Includes(B_CJK_COMPATIBILITY_FORMS_BLOCK)))
match = 1;
// additional check for partial CKJ blocks
if (strstr(aLangGroup, "ja") && (lang.Includes(B_HIRAGANA_BLOCK) || lang.Includes(B_KATAKANA_BLOCK) ))
match = 1;
if (strstr(aLangGroup, "ko") && (lang.Includes(B_HANGUL_BLOCK)))
match = 1;
if (strstr(aLangGroup, "zh") && (lang.Includes(B_HIGH_SURROGATES_BLOCK) || lang.Includes(B_LOW_SURROGATES_BLOCK) ))
match = 1;
return match;
}
static nsresult EnumFonts(const char * aLangGroup, const char* aGeneric, PRUint32* aCount, PRUnichar*** aResult)
{
int32 numFamilies = count_font_families();
PRUnichar** array = (PRUnichar**) nsMemory::Alloc(numFamilies * sizeof(PRUnichar*));
NS_ENSURE_TRUE(array, NS_ERROR_OUT_OF_MEMORY);
int j = 0;
for(int32 i = 0; i < numFamilies; i++)
{
font_family family;
uint32 flags;
if (get_font_family(i, &family, &flags) == B_OK)
{
if (family && (!aLangGroup || MatchesLangGroup(family, aLangGroup)))
{
if(FontMatchesGenericType(family, flags, aGeneric, aLangGroup))
{
if (!(array[j] = UTF8ToNewUnicode(nsDependentCString(family))))
break;
++j;
}
}
}
}
*aCount = j;
if (*aCount)
{
*aResult = array;
// Resizing array for real number of matching families after check for language and generic type
if (*aCount < numFamilies)
{
array = (PRUnichar**) nsMemory::Realloc(array, *aCount * sizeof(PRUnichar*));
NS_ENSURE_TRUE(array, NS_ERROR_OUT_OF_MEMORY);
}
NS_QuickSort(array, j, sizeof(PRUnichar*), CompareFontNames, nsnull);
}
else
{
nsMemory::Free(array);
}
return NS_OK;
}
NS_IMETHODIMP
nsFontEnumeratorBeOS::EnumerateAllFonts(PRUint32* aCount, PRUnichar*** aResult)
{
NS_ENSURE_ARG_POINTER(aResult);
*aResult = nsnull;
NS_ENSURE_ARG_POINTER(aCount);
*aCount = 0;
return EnumFonts(nsnull, nsnull, aCount, aResult);
}
NS_IMETHODIMP
nsFontEnumeratorBeOS::EnumerateFonts(const char* aLangGroup,
const char* aGeneric, PRUint32* aCount, PRUnichar*** aResult)
{
NS_ENSURE_ARG_POINTER(aResult);
*aResult = nsnull;
NS_ENSURE_ARG_POINTER(aCount);
*aCount = 0;
// aLangGroup=null or "" means any (i.e., don't care)
// aGeneric=null or "" means any (i.e, don't care)
const char* langGroup = nsnull;
if (aLangGroup && *aLangGroup)
langGroup = aLangGroup;
const char* generic = nsnull;
if (aGeneric && *aGeneric)
generic = aGeneric;
return EnumFonts(langGroup, generic, aCount, aResult);
}
NS_IMETHODIMP
nsFontEnumeratorBeOS::HaveFontFor(const char* aLangGroup, PRBool* aResult)
{
NS_ENSURE_ARG_POINTER(aLangGroup);
NS_ENSURE_ARG_POINTER(aResult);
*aResult = PR_FALSE;
int32 numFamilies = count_font_families();
for(int32 i = 0; i < numFamilies; i++)
{
font_family family;
uint32 flags;
if (get_font_family(i, &family, &flags) == B_OK)
{
if (family && (!aLangGroup || MatchesLangGroup(family, aLangGroup)))
{
*aResult = PR_TRUE;
return NS_OK;
}
}
}
return NS_OK;
}
NS_IMETHODIMP
nsFontEnumeratorBeOS::GetDefaultFont(const char *aLangGroup,
const char *aGeneric, PRUnichar **aResult)
{
// aLangGroup=null or "" means any (i.e., don't care)
// aGeneric=null or "" means any (i.e, don't care)
NS_ENSURE_ARG_POINTER(aResult);
*aResult = nsnull;
return NS_OK;
}
NS_IMETHODIMP
nsFontEnumeratorBeOS::UpdateFontList(PRBool *updateFontList)
{
*updateFontList = PR_FALSE; // always return false for now
return NS_OK;
}

View File

@ -1,139 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Paul Ashford <arougthopher@lizardland.net>
* Sergei Dolgov <sergei_d@fi.tartu.ee>
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef nsFontMetricsBeOS_h__
#define nsFontMetricsBeOS_h__
#include "nsDeviceContextBeOS.h"
#include "nsIFontMetrics.h"
#include "nsIFontEnumerator.h"
#include "nsFont.h"
#include "nsString.h"
#include "nsIDeviceContext.h"
#include "nsCRT.h"
#include "nsCOMPtr.h"
#include "nsRenderingContextBeOS.h"
#include "nsICharRepresentable.h"
#include "nsDataHashtable.h"
#include <Font.h>
class nsFontMetricsBeOS : public nsIFontMetrics
{
public:
nsFontMetricsBeOS();
virtual ~nsFontMetricsBeOS();
NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW
NS_DECL_ISUPPORTS
NS_IMETHOD Init(const nsFont& aFont, nsIAtom* aLangGroup,
nsIDeviceContext* aContext);
NS_IMETHOD Destroy();
NS_IMETHOD GetXHeight(nscoord& aResult);
NS_IMETHOD GetSuperscriptOffset(nscoord& aResult);
NS_IMETHOD GetSubscriptOffset(nscoord& aResult);
NS_IMETHOD GetStrikeout(nscoord& aOffset, nscoord& aSize);
NS_IMETHOD GetUnderline(nscoord& aOffset, nscoord& aSize);
NS_IMETHOD GetHeight(nscoord &aHeight);
NS_IMETHOD GetNormalLineHeight(nscoord &aHeight);
NS_IMETHOD GetLeading(nscoord &aLeading);
NS_IMETHOD GetEmHeight(nscoord &aHeight);
NS_IMETHOD GetEmAscent(nscoord &aAscent);
NS_IMETHOD GetEmDescent(nscoord &aDescent);
NS_IMETHOD GetMaxHeight(nscoord &aHeight);
NS_IMETHOD GetMaxAscent(nscoord &aAscent);
NS_IMETHOD GetMaxDescent(nscoord &aDescent);
NS_IMETHOD GetMaxAdvance(nscoord &aAdvance);
NS_IMETHOD GetAveCharWidth(nscoord &aAveCharWidth);
NS_IMETHOD GetLangGroup(nsIAtom** aLangGroup);
NS_IMETHOD GetFontHandle(nsFontHandle &aHandle);
NS_IMETHOD GetSpaceWidth(nscoord &aSpaceWidth);
static nsresult FamilyExists(const nsString& aFontName);
inline PRBool IsBold() { return mIsBold; }
static int FontMatchesGenericType(font_family family, uint32 flags, const char* aGeneric, const char* aLangGroup);
nsCOMPtr<nsIAtom> mLangGroup;
static int MatchesLangGroup(font_family family, const char* aLangGroup);
float GetStringWidth(char *string, uint32 len);
protected:
void RealizeFont(nsIDeviceContext* aContext);
nsIDeviceContext *mDeviceContext;
BFont mFontHandle;
nscoord mLeading;
nscoord mEmHeight;
nscoord mEmAscent;
nscoord mEmDescent;
nscoord mMaxHeight;
nscoord mMaxAscent;
nscoord mMaxDescent;
nscoord mMaxAdvance;
nscoord mAveCharWidth;
nscoord mXHeight;
nscoord mSuperscriptOffset;
nscoord mSubscriptOffset;
nscoord mStrikeoutSize;
nscoord mStrikeoutOffset;
nscoord mUnderlineSize;
nscoord mUnderlineOffset;
nscoord mSpaceWidth;
PRUint16 mPixelSize;
PRUint8 mStretchIndex;
PRUint8 mStyleIndex;
PRBool mIsBold;
nsDataHashtable<nsUint32HashKey, float> mFontWidthCache;
};
class nsFontEnumeratorBeOS : public nsIFontEnumerator
{
public:
nsFontEnumeratorBeOS();
NS_DECL_ISUPPORTS
NS_DECL_NSIFONTENUMERATOR
};
#endif

View File

@ -1,153 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsIGenericFactory.h"
#include "nsIModule.h"
#include "nsCOMPtr.h"
#include "nsGfxCIID.h"
#include "nsBlender.h"
#include "nsFontMetricsBeOS.h"
#include "nsRenderingContextBeOS.h"
#include "nsScriptableRegion.h"
#include "nsDeviceContextBeOS.h"
#include "nsImageBeOS.h"
#include "gfxImageFrame.h"
// objects that just require generic constructors
NS_GENERIC_FACTORY_CONSTRUCTOR(nsFontMetricsBeOS)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsDeviceContextBeOS)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsRenderingContextBeOS)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsImageBeOS)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsBlender)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsRegionBeOS)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsFontEnumeratorBeOS)
NS_GENERIC_FACTORY_CONSTRUCTOR(gfxImageFrame)
// our custom constructors
static NS_IMETHODIMP nsScriptableRegionConstructor(nsISupports *aOuter, REFNSIID aIID, void **aResult)
{
nsresult rv;
nsIScriptableRegion *inst;
if ( !aResult )
{
rv = NS_ERROR_NULL_POINTER;
return rv;
}
*aResult = nsnull;
if (aOuter)
{
rv = NS_ERROR_NO_AGGREGATION;
return rv;
}
// create an nsRegionBeOS and get the scriptable region from it
nsCOMPtr <nsIRegion> rgn;
NS_NEWXPCOM(rgn, nsRegionBeOS);
nsCOMPtr<nsIScriptableRegion> scriptableRgn;
if (rgn != nsnull)
{
scriptableRgn = new nsScriptableRegion(rgn);
inst = scriptableRgn;
}
if (!inst)
{
rv = NS_ERROR_OUT_OF_MEMORY;
return rv;
}
NS_ADDREF(inst);
// release our variable above now that we have created our owning
// reference - we don't want this to go out of scope early!
scriptableRgn = nsnull;
rv = inst->QueryInterface(aIID, aResult);
NS_RELEASE(inst);
return rv;
}
static const nsModuleComponentInfo components[] =
{
{ "BeOS Font Metrics",
NS_FONT_METRICS_CID,
// "@mozilla.org/gfx/font_metrics/beos;1",
"@mozilla.org/gfx/fontmetrics;1",
nsFontMetricsBeOSConstructor },
{ "BeOS Device Context",
NS_DEVICE_CONTEXT_CID,
// "@mozilla.org/gfx/device_context/beos;1",
"@mozilla.org/gfx/devicecontext;1",
nsDeviceContextBeOSConstructor },
{ "BeOS Rendering Context",
NS_RENDERING_CONTEXT_CID,
// "@mozilla.org/gfx/rendering_context/beos;1",
"@mozilla.org/gfx/renderingcontext;1",
nsRenderingContextBeOSConstructor },
{ "BeOS Image",
NS_IMAGE_CID,
// "@mozilla.org/gfx/image/beos;1",
"@mozilla.org/gfx/image;1",
nsImageBeOSConstructor },
{ "BeOS Region",
NS_REGION_CID,
"@mozilla.org/gfx/region/beos;1",
nsRegionBeOSConstructor },
{ "Scriptable Region",
NS_SCRIPTABLE_REGION_CID,
// "@mozilla.org/gfx/scriptable_region;1",
"@mozilla.org/gfx/region;1",
nsScriptableRegionConstructor },
{ "Blender",
NS_BLENDER_CID,
// "@mozilla.org/gfx/blender;1",
"@mozilla.org/gfx/blender;1",
nsBlenderConstructor },
{ "BeOS Font Enumerator",
NS_FONT_ENUMERATOR_CID,
// "@mozilla.org/gfx/font_enumerator/beos;1",
"@mozilla.org/gfx/fontenumerator;1",
nsFontEnumeratorBeOSConstructor },
{ "windows image frame",
GFX_IMAGEFRAME_CID,
"@mozilla.org/gfx/image/frame;2",
gfxImageFrameConstructor, },
};
NS_IMPL_NSGETMODULE(nsGfxBeOSModule, components)

View File

@ -1,140 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsGraphicsStateBeOS.h"
//////////////////////////////////////////////////////////////////////////
nsGraphicsState::nsGraphicsState()
{
mMatrix = nsnull;
mClipRegion = nsnull;
mColor = 0;
mLineStyle = nsLineStyle_kSolid;
mFontMetrics = nsnull;
}
//////////////////////////////////////////////////////////////////////////
nsGraphicsState::~nsGraphicsState()
{
NS_IF_RELEASE(mFontMetrics);
}
//////////////////////////////////////////////////////////////////////////
nsGraphicsStatePool::nsGraphicsStatePool()
{
mFreeList = nsnull;
}
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
//
// Public nsGraphicsStatePool
//
//////////////////////////////////////////////////////////////////////////
/* static */ nsGraphicsState *
nsGraphicsStatePool::GetNewGS()
{
nsGraphicsStatePool * thePool = PrivateGetPool();
return thePool->PrivateGetNewGS();
}
//////////////////////////////////////////////////////////////////////////
/* static */ void
nsGraphicsStatePool::ReleaseGS(nsGraphicsState* aGS)
{
nsGraphicsStatePool * thePool = PrivateGetPool();
thePool->PrivateReleaseGS(aGS);
}
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
//
// Private nsGraphicsStatePool
//
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
nsGraphicsStatePool *
nsGraphicsStatePool::gsThePool = nsnull;
//////////////////////////////////////////////////////////////////////////
nsGraphicsStatePool *
nsGraphicsStatePool::PrivateGetPool()
{
if (nsnull == gsThePool)
{
gsThePool = new nsGraphicsStatePool();
}
return gsThePool;
}
//////////////////////////////////////////////////////////////////////////
nsGraphicsStatePool::~nsGraphicsStatePool()
{
nsGraphicsState* gs = mFreeList;
while (gs != nsnull) {
nsGraphicsState* next = gs->mNext;
delete gs;
gs = next;
}
}
//////////////////////////////////////////////////////////////////////////
nsGraphicsState *
nsGraphicsStatePool::PrivateGetNewGS()
{
nsGraphicsState* gs = mFreeList;
if (gs != nsnull) {
mFreeList = gs->mNext;
return gs;
}
return new nsGraphicsState;
}
//////////////////////////////////////////////////////////////////////////
void
nsGraphicsStatePool::PrivateReleaseGS(nsGraphicsState* aGS)
{
// aGS->Clear();
aGS->mNext = mFreeList;
mFreeList = aGS;
}
//////////////////////////////////////////////////////////////////////////

View File

@ -1,90 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef nsGraphicsStateBeOS_h___
#define nsGraphicsStateBeOS_h___
#include "nsIRenderingContext.h"
#include "nsIFontMetrics.h"
#include "nsTransform2D.h"
#include "nsRegionBeOS.h"
#include "nsCOMPtr.h"
class nsGraphicsState
{
public:
nsTransform2D *mMatrix;
nsCOMPtr<nsIRegion> mClipRegion;
nscolor mColor;
nsLineStyle mLineStyle;
nsIFontMetrics *mFontMetrics;
nsGraphicsState *mNext; // link into free list of graphics states.
friend class nsGraphicsStatePool;
#ifndef USE_GS_POOL
friend class nsRenderingContextBeOS;
#endif
private:
nsGraphicsState();
~nsGraphicsState();
};
class nsGraphicsStatePool
{
public:
static nsGraphicsState * GetNewGS();
static void ReleaseGS(nsGraphicsState* aGS);
nsGraphicsStatePool();
~nsGraphicsStatePool();
private:
nsGraphicsState* mFreeList;
static nsGraphicsStatePool * PrivateGetPool();
nsGraphicsState * PrivateGetNewGS();
void PrivateReleaseGS(nsGraphicsState* aGS);
static nsGraphicsStatePool * gsThePool;
};
#endif /* nsGraphicsStateBeOS_h___ */

View File

@ -1,86 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef nsIDrawingSurfaceBeOS_h___
#define nsIDrawingSurfaceBeOS_h___
#include "nsIDrawingSurface.h"
#include <View.h>
// windows specific drawing surface method set
#define NS_IDRAWING_SURFACE_BEOS_IID \
{ 0x1ed958b0, 0xcab6, 0x11d2, \
{ 0xa8, 0x49, 0x00, 0x40, 0x95, 0x9a, 0x28, 0xc9 } }
class nsIDrawingSurfaceBeOS : public nsISupports
{
public:
NS_DECLARE_STATIC_IID_ACCESSOR(NS_IDRAWING_SURFACE_BEOS_IID)
/**
* 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(BView *aView) = 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(BView *aView, PRUint32 aWidth, PRUint32 aHeight,
PRUint32 aFlags) = 0;
};
NS_DEFINE_STATIC_IID_ACCESSOR(nsIDrawingSurfaceBeOS,
NS_IDRAWING_SURFACE_BEOS_IID)
#endif // nsIDrawingSurfaceBeOS_h___

View File

@ -1,726 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Daniel Switkin, Mathias Agopian and Sergei Dolgov
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsImageBeOS.h"
#include "nsRenderingContextBeOS.h"
#include "nspr.h"
#include <Looper.h>
#include <Bitmap.h>
#include <View.h>
NS_IMPL_ISUPPORTS1(nsImageBeOS, nsIImage)
nsImageBeOS::nsImageBeOS()
: mImage(nsnull)
, mImageBits(nsnull)
, mWidth(0)
, mHeight(0)
, mDepth(0)
, mRowBytes(0)
, mSizeImage(0)
, mDecodedX1(PR_INT32_MAX)
, mDecodedY1(PR_INT32_MAX)
, mDecodedX2(0)
, mDecodedY2(0)
, mAlphaBits(nsnull)
, mAlphaRowBytes(0)
, mAlphaDepth(0)
, mFlags(0)
, mNumBytesPixel(0)
, mImageCurrent(PR_FALSE)
, mOptimized(PR_FALSE)
, mTileBitmap(nsnull)
{
}
nsImageBeOS::~nsImageBeOS()
{
if (nsnull != mImage)
{
delete mImage;
mImage = nsnull;
}
if (mTileBitmap)
{
delete mTileBitmap;
mTileBitmap = nsnull;
}
if (nsnull != mImageBits)
{
delete [] mImageBits;
mImageBits = nsnull;
}
if (nsnull != mAlphaBits)
{
delete [] mAlphaBits;
mAlphaBits = nsnull;
}
}
nsresult nsImageBeOS::Init(PRInt32 aWidth, PRInt32 aHeight, PRInt32 aDepth,
nsMaskRequirements aMaskRequirements)
{
// Assumed: Init only gets called once by gfxIImageFrame
// Only 24 bit depths are supported for the platform independent bits
if (24 == aDepth)
{
mNumBytesPixel = 3;
}
else
{
NS_ASSERTION(PR_FALSE, "unexpected image depth");
return NS_ERROR_UNEXPECTED;
}
mWidth = aWidth;
mHeight = aHeight;
mDepth = aDepth;
mRowBytes = (mWidth * mDepth) >> 5;
if (((PRUint32)mWidth * mDepth) & 0x1F)
mRowBytes++;
mRowBytes <<= 2;
mSizeImage = mRowBytes * mHeight;
mImageBits = new PRUint8[mSizeImage];
switch (aMaskRequirements)
{
case nsMaskRequirements_kNeeds1Bit:
mAlphaRowBytes = (aWidth + 7) / 8;
mAlphaDepth = 1;
// 32-bit align each row
mAlphaRowBytes = (mAlphaRowBytes + 3) & ~0x3;
mAlphaBits = new PRUint8[mAlphaRowBytes * aHeight];
memset(mAlphaBits, 255, mAlphaRowBytes * aHeight);
break;
case nsMaskRequirements_kNeeds8Bit:
mAlphaRowBytes = aWidth;
mAlphaDepth = 8;
// 32-bit align each row
mAlphaRowBytes = (mAlphaRowBytes + 3) & ~0x3;
mAlphaBits = new PRUint8[mAlphaRowBytes * aHeight];
break;
}
return NS_OK;
}
// This is a notification that the platform independent bits have changed. Therefore,
// the contents of the BBitmap are no longer up to date. By setting the mImageCurrent
// flag to false, we can be sure that the BBitmap will be updated before it gets blit.
// TO DO: It would be better to cache the updated rectangle here, and only copy the
// area that has changed in CreateImage().
void nsImageBeOS::ImageUpdated(nsIDeviceContext *aContext, PRUint8 aFlags, nsRect *aUpdateRect)
{
// This should be 0'd out by Draw()
mFlags = aFlags;
mImageCurrent = PR_FALSE;
mDecodedX1 = PR_MIN(mDecodedX1, aUpdateRect->x);
mDecodedY1 = PR_MIN(mDecodedY1, aUpdateRect->y);
if (aUpdateRect->YMost() > mDecodedY2)
mDecodedY2 = aUpdateRect->YMost();
if (aUpdateRect->XMost() > mDecodedX2)
mDecodedX2 = aUpdateRect->XMost();
}
/** ---------------------------------------------------
* See documentation in nsIImage.h
*/
PRBool nsImageBeOS::GetIsImageComplete() {
return mDecodedX1 == 0 &&
mDecodedY1 == 0 &&
mDecodedX2 == mWidth &&
mDecodedY2 == mHeight;
}
// Draw the bitmap, this method has a source and destination coordinates
NS_IMETHODIMP nsImageBeOS::Draw(nsIRenderingContext &aContext, nsIDrawingSurface* aSurface,
PRInt32 aSX, PRInt32 aSY, PRInt32 aSWidth, PRInt32 aSHeight,
PRInt32 aDX, PRInt32 aDY, PRInt32 aDWidth, PRInt32 aDHeight)
{
// Don't bother to draw nothing
if (!aSWidth || !aSHeight || !aDWidth || !aDHeight)
return NS_OK;
if (mDecodedX2 < mDecodedX1 || mDecodedY2 < mDecodedY1)
return NS_OK;
// As we do all scaling with Be API (DrawBitmap), using float is safe and convenient
float srcX = aSX, srcY = aSY, srcMostX = aSX + aSWidth, srcMostY = aSY + aSHeight;
float dstX = aDX, dstY = aDY, dstMostX = aDX + aDWidth, dstMostY = aDY + aDHeight;
float scaleX = float(aDWidth)/float(aSWidth), scaleY = float(aDHeight)/float(aSHeight);
if (!mImageCurrent || (nsnull == mImage))
BuildImage(aSurface);
if (nsnull == mImage || mImage->BitsLength() == 0)
return NS_ERROR_FAILURE;
// Limit the image rectangle to the size of the image data which
// has been validated.
if ((mDecodedY1 > 0))
{
srcY = float(PR_MAX(mDecodedY1, aSY));
}
if ((mDecodedX1 > 0))
{
srcX = float(PR_MAX(mDecodedX1, aSX));
}
// When targeting BRects, MostX/Y is more natural than Width/Heigh
if ((mDecodedY2 < mHeight))
srcMostY = float(PR_MIN(mDecodedY2, aSY + aSHeight));
if ((mDecodedX2 < mWidth))
srcMostX = float(PR_MIN(mDecodedX2, aSX + aSWidth));
dstX = float(srcX - aSX)*scaleX + float(aDX);
dstY = float(srcY - aSY)*scaleY + float(aDY);
dstMostX = dstMostX - (float(aSWidth + aSX) - srcMostX)*scaleX;
dstMostY = dstMostY - (float(aSHeight + aSY) - srcMostY)*scaleY;
nsDrawingSurfaceBeOS *beosdrawing = (nsDrawingSurfaceBeOS *)aSurface;
BView *view;
// LockAndUpdateView() sets proper clipping region here and elsewhere in nsImageBeOS.
if (((nsRenderingContextBeOS&)aContext).LockAndUpdateView())
{
beosdrawing->AcquireView(&view);
if (view)
{
// TODO: With future locking update check if restricting clipping region
// to decoded values fastens things up - in this case clipping must be reset to 0
// at unlocking or before getting native region in LockAndUpdateView().
// Only use B_OP_ALPHA when there is an alpha channel present, as it is much slower
if (0 != mAlphaDepth)
{
view->SetDrawingMode(B_OP_ALPHA);
view->DrawBitmap(mImage, BRect(srcX, srcY, srcMostX - 1, srcMostY - 1),
BRect(dstX, dstY, dstMostX - 1, dstMostY - 1));
view->SetDrawingMode(B_OP_COPY);
}
else
{
view->DrawBitmap(mImage, BRect(srcX, srcY, srcMostX - 1, srcMostY - 1),
BRect(dstX, dstY, dstMostX - 1, dstMostY - 1));
}
// view was locked by LockAndUpdateView() before it was aquired. So unlock.
}
((nsRenderingContextBeOS&)aContext).UnlockView();
beosdrawing->ReleaseView();
}
mFlags = 0;
return NS_OK;
}
// Draw the bitmap, this draw just has destination coordinates
NS_IMETHODIMP nsImageBeOS::Draw(nsIRenderingContext &aContext, nsIDrawingSurface* aSurface,
PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight)
{
//Don't bother to draw nothing
if (!aWidth || !aHeight)
return NS_OK;
if (mDecodedX2 < mDecodedX1 || mDecodedY2 < mDecodedY1)
return NS_OK;
if (!mImageCurrent || (nsnull == mImage))
BuildImage(aSurface);
if (nsnull == mImage)
return NS_ERROR_FAILURE;
PRInt32 validX = 0, validY = 0, validMostX = mWidth, validMostY = mHeight;
// XXX kipp: this is temporary code until we eliminate the
// width/height arguments from the draw method.
aWidth = PR_MIN(aWidth, mWidth);
aHeight = PR_MIN(aHeight, mHeight);
if ((mDecodedY2 < aHeight))
validMostY = mDecodedY2;
if ((mDecodedX2 < aWidth))
validMostX = mDecodedX2;
if ((mDecodedY1 > 0))
validY = mDecodedY1;
if ((mDecodedX1 > 0))
validX = mDecodedX1;
nsDrawingSurfaceBeOS *beosdrawing = (nsDrawingSurfaceBeOS *)aSurface;
BView *view;
if (((nsRenderingContextBeOS&)aContext).LockAndUpdateView())
{
beosdrawing->AcquireView(&view);
if (view)
{
// See TODO clipping comment above - code ready for use:
// BRegion tmpreg(BRect(aX + validX, aY + validY, aX + validMostX - 1, aY + validMostY - 1));
// view->ConstrainClippingRegion(&tmpreg);
// Only use B_OP_ALPHA when there is an alpha channel present, as it is much slower
if (0 != mAlphaDepth)
{
view->SetDrawingMode(B_OP_ALPHA);
view->DrawBitmap(mImage, BRect(validX, validY, validMostX - 1, validMostY - 1),
BRect(aX + validX, aY + validY, aX + validMostX - 1, aY + validMostY - 1));
view->SetDrawingMode(B_OP_COPY);
}
else
{
view->DrawBitmap(mImage, BRect(validX, validY, validMostX - 1, validMostY - 1),
BRect(aX + validX, aY + validY, aX + validMostX - 1, aY + validMostY - 1));
}
}
((nsRenderingContextBeOS&)aContext).UnlockView();
beosdrawing->ReleaseView();
}
mFlags = 0;
return NS_OK;
}
NS_IMETHODIMP nsImageBeOS::DrawTile(nsIRenderingContext &aContext, nsIDrawingSurface* aSurface,
PRInt32 aSXOffset, PRInt32 aSYOffset, PRInt32 aPadX, PRInt32 aPadY, const nsRect &aTileRect)
{
// Don't bother to draw nothing
if (!aTileRect.width || !aTileRect.height)
return NS_OK;
if (mDecodedX2 < mDecodedX1 || mDecodedY2 < mDecodedY1)
return NS_OK;
if (!mImageCurrent || (nsnull == mImage))
BuildImage(aSurface);
if (nsnull == mImage || mImage->BitsLength() == 0)
return NS_ERROR_FAILURE;
PRInt32 validX = 0, validY = 0, validMostX = mWidth, validMostY = mHeight;
// Limit the image rectangle to the size of the image data which
// has been validated.
if ((mDecodedY2 < mHeight))
validMostY = mDecodedY2;
if ((mDecodedX2 < mWidth))
validMostX = mDecodedX2;
if ((mDecodedY1 > 0))
validY = mDecodedY1;
if ((mDecodedX1 > 0))
validX = mDecodedX1;
nsDrawingSurfaceBeOS *beosdrawing = (nsDrawingSurfaceBeOS *)aSurface;
BView *view = 0;
if (((nsRenderingContextBeOS&)aContext).LockAndUpdateView())
{
beosdrawing->AcquireView(&view);
if (view)
{
BRegion rgn(BRect(aTileRect.x, aTileRect.y,
aTileRect.x + aTileRect.width - 1, aTileRect.y + aTileRect.height - 1));
view->ConstrainClippingRegion(&rgn);
// Force transparency for bitmap blitting in case of padding even if mAlphaDepth == 0
if (0 != mAlphaDepth || aPadX || aPadY)
view->SetDrawingMode(B_OP_ALPHA);
// Creating temporary bitmap, compatible with mImage and with size of area to be filled with tiles
// Reuse existing if possible
if (!mTileBitmap || mTileBitmap->Bounds().IntegerWidth() + 1 != aTileRect.width || mTileBitmap->Bounds().IntegerHeight() + 1 != aTileRect.height)
{
if (mTileBitmap)
{
delete mTileBitmap;
mTileBitmap = nsnull;
}
mTileBitmap = new BBitmap(BRect(0, 0, aTileRect.width - 1, aTileRect.height -1), mImage->ColorSpace(), false);
}
int32 tmpbitlength = mTileBitmap->BitsLength();
if (!mTileBitmap || tmpbitlength == 0)
{
// Failed. Cleaning things a bit.
((nsRenderingContextBeOS&)aContext).UnlockView();
if (mTileBitmap)
{
delete mTileBitmap;
mTileBitmap = nsnull;
}
beosdrawing->ReleaseView();
return NS_ERROR_FAILURE;
}
uint32 *dst0 = (uint32 *)mTileBitmap->Bits();
uint32 *src0 = (uint32 *)mImage->Bits();
uint32 *dst = dst0;
uint32 dstRowLength = mTileBitmap->BytesPerRow()/4;
uint32 dstColHeight = tmpbitlength/mTileBitmap->BytesPerRow();
// Filling mTileBitmap with transparent color to preserve padding areas on destination
uint32 filllength = tmpbitlength/4;
if (0 != mAlphaDepth || aPadX || aPadY)
{
for (uint32 i=0, *dst = dst0; i < filllength; ++i)
*(dst++) = B_TRANSPARENT_MAGIC_RGBA32;
}
// Rendering mImage tile to temporary bitmap
uint32 *src = src0; dst = dst0;
for (uint32 y = 0, yy = aSYOffset; y < dstColHeight; ++y)
{
src = src0 + yy*mWidth;
dst = dst0 + y*dstRowLength;
// Avoid unnecessary job outside update rect
if (yy >= validY && yy <= validMostY)
{
for (uint32 x = 0, xx = aSXOffset; x < dstRowLength; ++x)
{
// Avoid memwrite if outside update rect
if (xx >= validX && xx <= validMostX)
dst[x] = src[xx];
if (++xx == mWidth)
{
// Width of source reached. Adding horizontal paddding.
xx = 0;
x += aPadX;
}
}
}
if (++yy == mHeight)
{
// Height of source reached. Adding vertical paddding.
yy = 0;
y += aPadY;
}
}
// Flushing tile bitmap to proper area in drawable BView
view->DrawBitmap(mTileBitmap, BPoint(aTileRect.x , aTileRect.y ));
view->SetDrawingMode(B_OP_COPY);
view->Sync();
}
((nsRenderingContextBeOS&)aContext).UnlockView();
beosdrawing->ReleaseView();
}
mFlags = 0;
return NS_OK;
}
// If not yet optimized, delete mImageBits and mAlphaBits here to save memory,
// since the image will never change again and no one else will need to get the
// platform independent bits.
nsresult nsImageBeOS::Optimize(nsIDeviceContext *aContext)
{
if (!mOptimized)
{
// Make sure the BBitmap is up to date
CreateImage(NULL);
// Release Mozilla-specific data
if (nsnull != mImageBits)
{
delete [] mImageBits;
mImageBits = nsnull;
}
if (nsnull != mAlphaBits)
{
delete [] mAlphaBits;
mAlphaBits = nsnull;
}
mOptimized = PR_TRUE;
}
return NS_OK;
}
// Not implemented at the moment. It's unclear whether this is necessary for
// the BeOS port or not. BBitmap::Lock/UnlockBits() may be used if necessary
NS_IMETHODIMP nsImageBeOS::LockImagePixels(PRBool aMaskPixels)
{
// we may need some sort of syncing here in future
return NS_OK;
}
// Same as above.
NS_IMETHODIMP nsImageBeOS::UnlockImagePixels(PRBool aMaskPixels)
{
return NS_OK;
}
nsresult nsImageBeOS::BuildImage(nsIDrawingSurface* aDrawingSurface)
{
CreateImage(aDrawingSurface);
return NS_OK;
}
// This function is responsible for copying the platform independent bits (mImageBits
// and mAlphaBits) into a BBitmap so it can be drawn using the Be APIs. Since it is
// expensive to create and destroy a BBitmap for this purpose, we will keep this bitmap
// around, which also prevents the need to copy the bits if they have not changed.
void nsImageBeOS::CreateImage(nsIDrawingSurface* aSurface)
{
PRInt32 validX = 0, validY = 0, validMostX = mWidth, validMostY = mHeight;
if (mImageBits)
{
if (24 != mDepth)
{
NS_ASSERTION(PR_FALSE, "unexpected image depth");
return;
}
// If the previous BBitmap is the right dimensions and colorspace, then reuse it.
const color_space cs = B_RGBA32;
if (nsnull != mImage)
{
BRect bounds = mImage->Bounds();
if (bounds.IntegerWidth() < validMostX - 1 || bounds.IntegerHeight() < validMostY - 1 ||
mImage->ColorSpace() != cs)
{
delete mImage;
mImage = new BBitmap(BRect(0, 0, validMostX - 1, validMostY - 1), cs, false);
}
else
{
// Don't copy the data twice if the BBitmap is up to date
if (mImageCurrent) return;
}
}
else
{
// No BBitmap exists, so create one and update it
mImage = new BBitmap(BRect(0, 0, mWidth - 1, mHeight - 1), cs, false);
}
// Only the data that has changed (the rectangle supplied to ImageUpdated())
// needs to be copied to the BBitmap.
if ((mDecodedY2 < mHeight))
validMostY = mDecodedY2;
if ((mDecodedX2 < mWidth))
validMostX = mDecodedX2;
if ((mDecodedY1 > 0))
validY = mDecodedY1;
if ((mDecodedX1 > 0))
validX = mDecodedX1;
if (mDecodedX2 < mDecodedX1 || mDecodedY2 < mDecodedY1)
return;
// Making up a 32 bit double word for the destination is much more efficient
// than writing each byte separately on some CPUs. For example, BeOS does not
// support write-combining on the Athlon/Duron family.
// Using mRowBytes as source stride due alignment of mImageBits array to 4.
// Destination stride is mWidth, as mImage always uses RGB(A)32
if (mImage && mImage->IsValid())
{
uint32 *dest, *dst0 = (uint32 *)mImage->Bits() + validX;
uint8 *src, *src0 = mImageBits + 3*validX;
if (mAlphaBits)
{
uint8 a, *alpha = mAlphaBits + validY*mAlphaRowBytes;;
for (int y = validY; y < validMostY; ++y)
{
dest = dst0 + y*mWidth;
src = src0 + y*mRowBytes;
for (int x = validX; x < validMostX; ++x)
{
if(1 == mAlphaDepth)
a = (alpha[x / 8] & (1 << (7 - (x % 8)))) ? 255 : 0;
else
a = alpha[x];
*dest++ = (a << 24) | (src[2] << 16) | (src[1] << 8) | src[0];
src += 3;
}
alpha += mAlphaRowBytes;
}
}
else
{
// Fixed 255 in the alpha channel to mean completely opaque
for (int y = validY; y < validMostY; ++y)
{
dest = dst0 + y*mWidth;
src = src0 + y*mRowBytes;
for (int x = validX; x < validMostX; ++x)
{
*dest++ = 0xff000000 | (src[2] << 16) | (src[1] << 8) | src[0];
src += 3;
}
}
}
// The contents of the BBitmap now match mImageBits (and mAlphaBits),
// so mark the flag up to date to prevent extra copies in the future.
mImageCurrent = PR_TRUE;
}
}
}
// Since this function does not touch either the source or destination BBitmap,
// there is no need to call CreateImage(). The platform independent bits will get
// copied to the BBitmap if and when it gets blit. Code is derived from GTK version,
// but some wordy constant math is moved out of loops for performance
NS_IMETHODIMP nsImageBeOS::DrawToImage(nsIImage* aDstImage,
nscoord aDX, nscoord aDY,
nscoord aDWidth, nscoord aDHeight)
{
nsImageBeOS *dest = static_cast<nsImageBeOS *>(aDstImage);
if (!dest)
return NS_ERROR_FAILURE;
if (aDX >= dest->mWidth || aDY >= dest->mHeight)
return NS_OK;
PRUint8 *rgbPtr=0, *alphaPtr=0;
PRUint32 rgbStride, alphaStride;
rgbPtr = mImageBits;
rgbStride = mRowBytes;
alphaPtr = mAlphaBits;
alphaStride = mAlphaRowBytes;
PRInt32 y;
PRInt32 ValidWidth = ( aDWidth < ( dest->mWidth - aDX ) ) ? aDWidth : ( dest->mWidth - aDX );
PRInt32 ValidHeight = ( aDHeight < ( dest->mHeight - aDY ) ) ? aDHeight : ( dest->mHeight - aDY );
// now composite the two images together
switch (mAlphaDepth)
{
case 1:
{
PRUint8 *dst = dest->mImageBits + aDY*dest->mRowBytes + 3*aDX;
PRUint8 *dstAlpha = dest->mAlphaBits + aDY*dest->mAlphaRowBytes;
PRUint8 *src = rgbPtr;
PRUint8 *alpha = alphaPtr;
PRUint8 offset = aDX & 0x7; // x starts at 0
PRUint8 offset_8U = 8U - offset;
int iterations = (ValidWidth+7)/8; // round up
PRUint32 dst_it_stride = dest->mRowBytes - 3*8*iterations;
PRUint32 src_it_stride = rgbStride - 3*8*iterations;
PRUint32 alpha_it_stride = alphaStride - iterations;
for (y=0; y < ValidHeight; ++y)
{
for (int x=0; x < ValidWidth; x += 8, dst += 24, src += 24)
{
PRUint8 alphaPixels = *alpha++;
PRInt32 VW_x = ValidWidth-x;
if (alphaPixels == 0)
continue; // all 8 transparent; jump forward
// 1 or more bits are set, handle dstAlpha now - may not be aligned.
// Are all 8 of these alpha pixels used?
if (x+7 >= ValidWidth)
{
alphaPixels &= 0xff << (8 - VW_x); // no, mask off unused
if (alphaPixels == 0)
continue; // no 1 alpha pixels left
}
if (offset == 0)
{
dstAlpha[(aDX+x)>>3] |= alphaPixels; // the cheap aligned case
}
else
{
dstAlpha[(aDX+x)>>3] |= alphaPixels >> offset;
// avoid write if no 1's to write - also avoids going past end of array
// compiler should merge the common sub-expressions
if (alphaPixels << offset_8U)
dstAlpha[((aDX+x)>>3) + 1] |= alphaPixels << offset_8U;
}
if (alphaPixels == 0xff)
{
// fix - could speed up by gathering a run of 0xff's and doing 1 memcpy
// all 8 pixels set; copy and jump forward
memcpy(dst,src,24);
continue;
}
else
{
// else mix of 1's and 0's in alphaPixels, do 1 bit at a time
// Don't go past end of line!
PRUint8 *d = dst, *s = src;
for (PRUint8 aMask = 1<<7, j = 0; aMask && j < VW_x; aMask >>= 1, ++j)
{
// if this pixel is opaque then copy into the destination image
if (alphaPixels & aMask)
{
// might be faster with *d++ = *s++ 3 times?
d[0] = s[0];
d[1] = s[1];
d[2] = s[2];
// dstAlpha bit already set
}
d += 3;
s += 3;
}
}
}
// at end of each line, bump pointers.
dst = dst + dst_it_stride;
src = src + src_it_stride;
alpha = alpha + alpha_it_stride;
dstAlpha += dest->mAlphaRowBytes;
}
}
break;
case 0:
default:
for (y=0; y < ValidHeight; ++y)
memcpy(dest->mImageBits + (y+aDY)*dest->mRowBytes + 3*aDX,
rgbPtr + y*rgbStride, 3*ValidWidth);
}
// ImageUpdated() won't be called in this case, so we need to mark the destination
// image as changed. This will cause its data to be copied in the BBitmap when it
// tries to blit. The source has not been modified, so its status has not changed.
nsRect rect(aDX, aDY, ValidWidth, ValidHeight);
dest->ImageUpdated(nsnull, 0, &rect);
mImageCurrent = PR_TRUE;
return NS_OK;
}

View File

@ -1,132 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Daniel Switkin, Mathias Agopian and Sergei Dolgov
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef nsImageBeOS_h___
#define nsImageBeOS_h___
#include "nsIImage.h"
#include "nsPoint.h"
class BBitmap;
class BView;
class nsImageBeOS : public nsIImage
{
public:
nsImageBeOS();
virtual ~nsImageBeOS();
NS_DECL_ISUPPORTS
// Vital stats
virtual PRInt32 GetBytesPix() { return mNumBytesPixel; }
virtual PRInt32 GetHeight() { return mHeight; }
virtual PRInt32 GetWidth() { return mWidth; }
virtual PRUint8 *GetBits() { return mImageBits; }
virtual void *GetBitInfo() { return nsnull; }
virtual PRBool GetIsRowOrderTopToBottom() { return PR_TRUE; }
virtual PRInt32 GetLineStride() { return mRowBytes; }
virtual nsColorMap *GetColorMap() { return nsnull; }
// The heavy lifting
NS_IMETHOD Draw(nsIRenderingContext &aContext, nsIDrawingSurface* aSurface,
PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight);
NS_IMETHOD Draw(nsIRenderingContext &aContext, nsIDrawingSurface* aSurface,
PRInt32 aSX, PRInt32 aSY, PRInt32 aSWidth, PRInt32 aSHeight,
PRInt32 aDX, PRInt32 aDY, PRInt32 aDWidth, PRInt32 aDHeight);
NS_IMETHOD DrawToImage(nsIImage *aDstImage, nscoord aDX, nscoord aDY,
nscoord aDWidth, nscoord aDHeight);
NS_IMETHOD DrawTile(nsIRenderingContext &aContext, nsIDrawingSurface* aSurface,
PRInt32 aSXOffset, PRInt32 aSYOffset, PRInt32 aPadX, PRInt32 aPadY,
const nsRect &aTileRect);
virtual void ImageUpdated(nsIDeviceContext *aContext, PRUint8 aFlags,
nsRect *aUpdateRect);
virtual PRBool GetIsImageComplete();
virtual nsresult Init(PRInt32 aWidth, PRInt32 aHeight, PRInt32 aDepth,
nsMaskRequirements aMaskRequirements);
virtual PRBool IsOptimized() { return mOptimized; }
virtual nsresult Optimize(nsIDeviceContext *aContext);
virtual PRBool GetHasAlphaMask() { return mAlphaBits != nsnull; }
virtual PRUint8 *GetAlphaBits() { return mAlphaBits; }
virtual PRInt32 GetAlphaLineStride() { return mAlphaRowBytes; }
virtual PRInt8 GetAlphaDepth() { return mAlphaDepth; }
NS_IMETHOD LockImagePixels(PRBool aMaskPixels);
NS_IMETHOD UnlockImagePixels(PRBool aMaskPixels);
private:
void ComputePaletteSize(PRIntn nBitCount);
protected:
void CreateImage(nsIDrawingSurface* aSurface);
nsresult BuildImage(nsIDrawingSurface* aDrawingSurface);
private:
BBitmap *mImage;
BBitmap *mTileBitmap;
PRUint8 *mImageBits;
PRInt32 mWidth;
PRInt32 mHeight;
PRInt32 mDepth;
PRInt32 mRowBytes;
PRInt32 mSizeImage;
// Keeps track of what part of image has been decoded
PRInt32 mDecodedX1;
PRInt32 mDecodedY1;
PRInt32 mDecodedX2;
PRInt32 mDecodedY2;
// Alpha layer members
PRUint8 *mAlphaBits;
PRInt16 mAlphaRowBytes;
PRInt8 mAlphaDepth;
// Flags set by ImageUpdated
PRUint8 mFlags;
PRInt8 mNumBytesPixel;
PRBool mImageCurrent;
PRBool mOptimized;
};
#endif

View File

@ -1,260 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include <Region.h>
#include "nsRegionBeOS.h"
#include "prmem.h"
#ifdef DEBUG_REGIONS
static int nRegions;
#endif
nsRegionBeOS :: nsRegionBeOS()
{
#ifdef DEBUG_REGIONS
++nRegions;
printf("REGIONS+ = %i\n", nRegions);
#endif
mRegion.MakeEmpty();
mRegionType = eRegionComplexity_empty;
}
nsRegionBeOS :: ~nsRegionBeOS()
{
#ifdef DEBUG_REGIONS
--nRegions;
printf("REGIONS- = %i\n", nRegions);
#endif
mRegion.MakeEmpty();
}
NS_IMPL_ISUPPORTS1(nsRegionBeOS, nsIRegion)
nsresult nsRegionBeOS :: Init(void)
{
mRegion.MakeEmpty();
mRegionType = eRegionComplexity_empty;
return NS_OK;
}
void nsRegionBeOS :: SetTo(const nsIRegion &aRegion)
{
Init();
nsRegionBeOS *pRegion = (nsRegionBeOS *)&aRegion;
mRegion = pRegion->mRegion;
SetRegionType();
}
void nsRegionBeOS :: SetTo(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight)
{
Init();
mRegion.Set(BRect(aX, aY, aX + aWidth - 1, aY + aHeight - 1));
SetRegionType();
}
void nsRegionBeOS :: Intersect(const nsIRegion &aRegion)
{
nsRegionBeOS *pRegion = (nsRegionBeOS*)&aRegion;
mRegion.IntersectWith(&pRegion->mRegion);
SetRegionType();
}
void nsRegionBeOS :: Intersect(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight)
{
BRegion tRegion;
tRegion.Set( BRect( aX, aY, aX + aWidth - 1, aY + aHeight - 1 ) );
mRegion.IntersectWith(&tRegion);
SetRegionType();
}
void nsRegionBeOS :: Union(const nsIRegion &aRegion)
{
nsRegionBeOS *pRegion = (nsRegionBeOS*)&aRegion;
mRegion.Include(&pRegion->mRegion);
SetRegionType();
}
void nsRegionBeOS :: Union(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight)
{
mRegion.Include(BRect(aX, aY, aX + aWidth - 1, aY + aHeight - 1));
SetRegionType();
}
void nsRegionBeOS :: Subtract(const nsIRegion &aRegion)
{
nsRegionBeOS *pRegion = (nsRegionBeOS*)&aRegion;
mRegion.Exclude(&pRegion->mRegion);
SetRegionType();
}
void nsRegionBeOS :: Subtract(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight)
{
mRegion.Exclude(BRect(aX, aY, aX + aWidth - 1, aY + aHeight - 1));
SetRegionType();
}
PRBool nsRegionBeOS :: IsEmpty(void)
{
if( mRegionType == eRegionComplexity_empty )
return PR_TRUE;
return PR_FALSE;
}
PRBool nsRegionBeOS :: IsEqual(const nsIRegion &aRegion)
{
#ifdef DEBUG
printf(" - nsRegionBeOS :: IsEqual not implemented!\n");
#endif
return PR_FALSE;
}
void nsRegionBeOS :: GetBoundingBox(PRInt32 *aX, PRInt32 *aY, PRInt32 *aWidth, PRInt32 *aHeight)
{
if( mRegion.CountRects() ) {
BRect rect = mRegion.Frame();
*aX = nscoord(rect.left);
*aY = nscoord(rect.top);
*aWidth = nscoord(rect.Width()+1);
*aHeight = nscoord(rect.Height()+1);
}
else
{
*aX = *aY = *aWidth = *aHeight = 0;
}
}
void nsRegionBeOS :: Offset(PRInt32 aXOffset, PRInt32 aYOffset)
{
mRegion.OffsetBy( aXOffset, aYOffset );
}
void nsRegionBeOS :: SetRegionType(void)
{
if(mRegion.CountRects() == 1)
mRegionType = eRegionComplexity_rect ;
else if(mRegion.CountRects() > 1)
mRegionType = eRegionComplexity_complex ;
else
mRegionType = eRegionComplexity_empty;
}
PRBool nsRegionBeOS :: ContainsRect(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight)
{
return mRegion.Intersects(BRect(aX, aY, aX + aWidth - 1, aY + aHeight - 1));
}
NS_IMETHODIMP nsRegionBeOS :: GetRects(nsRegionRectSet **aRects)
{
nsRegionRectSet *rects;
int nbox;
nsRegionRect *rect;
NS_ASSERTION(!(nsnull == aRects), "bad ptr");
//code lifted from old xfe. MMP
nbox = mRegion.CountRects();
rects = *aRects;
if ((nsnull == rects) || (rects->mRectsLen < (PRUint32)nbox))
{
void *buf = PR_Realloc(rects, sizeof(nsRegionRectSet) + (sizeof(nsRegionRect) * (nbox - 1)));
if(nsnull == buf)
{
if(nsnull != rects)
rects->mNumRects = 0;
return NS_OK;
}
rects = (nsRegionRectSet *)buf;
rects->mRectsLen = nbox;
}
rects->mNumRects = nbox;
rects->mArea = 0;
rect = &rects->mRects[0];
for(int32 i = 0; i < nbox; i++)
{
BRect r = mRegion.RectAt(i);
rect->x = nscoord(r.left);
rect->width = nscoord(r.right - r.left + 1);
rect->y = nscoord(r.top);
rect->height = nscoord(r.bottom - r.top + 1);
rects->mArea += rect->width * rect->height;
rect++;
}
*aRects = rects;
return NS_OK;
}
NS_IMETHODIMP nsRegionBeOS :: FreeRects(nsRegionRectSet *aRects)
{
if(nsnull != aRects)
PR_Free((void *)aRects);
return NS_OK;
}
NS_IMETHODIMP nsRegionBeOS :: GetNativeRegion(void *&aRegion) const
{
aRegion = (void *)&mRegion;
return NS_OK;
}
NS_IMETHODIMP nsRegionBeOS :: GetRegionComplexity(nsRegionComplexity &aComplexity) const
{
aComplexity = mRegionType;
return NS_OK;
}

View File

@ -1,84 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef nsRegionBeOS_h___
#define nsRegionBeOS_h___
#include "nsIRegion.h"
#include <Region.h>
class nsRegionBeOS : public nsIRegion
{
public:
nsRegionBeOS();
virtual ~nsRegionBeOS();
NS_DECL_ISUPPORTS
virtual nsresult Init();
virtual void SetTo(const nsIRegion &aRegion);
virtual void SetTo(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight);
void SetTo(const nsRegionBeOS *aRegion);
virtual void Intersect(const nsIRegion &aRegion);
virtual void Intersect(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight);
virtual void Union(const nsIRegion &aRegion);
virtual void Union(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight);
virtual void Subtract(const nsIRegion &aRegion);
virtual void Subtract(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight);
virtual PRBool IsEmpty(void);
virtual PRBool IsEqual(const nsIRegion &aRegion);
virtual void GetBoundingBox(PRInt32 *aX, PRInt32 *aY, PRInt32 *aWidth, PRInt32 *aHeight);
virtual void Offset(PRInt32 aXOffset, PRInt32 aYOffset);
virtual PRBool ContainsRect(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight);
NS_IMETHOD GetRects(nsRegionRectSet **aRects);
NS_IMETHOD FreeRects(nsRegionRectSet *aRects);
NS_IMETHOD GetNativeRegion(void *&aRegion) const;
NS_IMETHOD GetRegionComplexity(nsRegionComplexity &aComplexity) const;
NS_IMETHOD GetNumRects(PRUint32 *aRects) const { *aRects = 0; return NS_OK; }
protected:
void SetRegionType(void);
private:
BRegion mRegion;
nsRegionComplexity mRegionType;
};
#endif // nsRegionBeOS_h___

File diff suppressed because it is too large Load Diff

View File

@ -1,233 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: 4; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Daniel Switkin, Mathias Agopian, Sergei Dolgov
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef nsRenderingContextBeOS_h___
#define nsRenderingContextBeOS_h___
#include "nsRenderingContextImpl.h"
#include "nsFont.h"
#include "nsIFontMetrics.h"
#include "nsPoint.h"
#include "nsString.h"
#include "nsCRT.h"
#include "nsTransform2D.h"
#include "nsIWidget.h"
#include "nsRect.h"
#include "nsIDeviceContext.h"
#include "nsVoidArray.h"
#include "nsGfxCIID.h"
#include "nsDrawingSurfaceBeOS.h"
#include "nsRegionBeOS.h"
class nsRenderingContextBeOS : public nsRenderingContextImpl
{
public:
nsRenderingContextBeOS();
virtual ~nsRenderingContextBeOS();
NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW
NS_DECL_ISUPPORTS
NS_IMETHOD Init(nsIDeviceContext *aContext, nsIWidget *aWindow);
NS_IMETHOD Init(nsIDeviceContext *aContext, nsIDrawingSurface* aSurface);
NS_IMETHOD Reset();
NS_IMETHOD GetDeviceContext(nsIDeviceContext *&aContext);
NS_IMETHOD LockDrawingSurface(PRInt32 aX, PRInt32 aY, PRUint32 aWidth, PRUint32 aHeight,
void **aBits, PRInt32 *aStride, PRInt32 *aWidthBytes, PRUint32 aFlags);
NS_IMETHOD UnlockDrawingSurface();
NS_IMETHOD SelectOffScreenDrawingSurface(nsIDrawingSurface* aSurface);
NS_IMETHOD GetDrawingSurface(nsIDrawingSurface* *aSurface);
NS_IMETHOD GetHints(PRUint32 &aResult);
NS_IMETHOD PushState();
NS_IMETHOD PopState();
NS_IMETHOD IsVisibleRect(const nsRect &aRect, PRBool &aVisible);
NS_IMETHOD SetClipRect(const nsRect &aRect, nsClipCombine aCombine);
NS_IMETHOD GetClipRect(nsRect &aRect, PRBool &aClipValid);
NS_IMETHOD SetClipRegion(const nsIRegion &aRegion, nsClipCombine aCombine);
NS_IMETHOD CopyClipRegion(nsIRegion &aRegion);
NS_IMETHOD GetClipRegion(nsIRegion **aRegion);
NS_IMETHOD SetLineStyle(nsLineStyle aLineStyle);
NS_IMETHOD GetLineStyle(nsLineStyle &aLineStyle);
NS_IMETHOD SetColor(nscolor aColor);
NS_IMETHOD GetColor(nscolor &aColor) const;
NS_IMETHOD SetFont(const nsFont& aFont, nsIAtom* aLangGroup);
NS_IMETHOD SetFont(nsIFontMetrics *aFontMetrics);
NS_IMETHOD GetFontMetrics(nsIFontMetrics *&aFontMetrics);
NS_IMETHOD Translate(nscoord aX, nscoord aY);
NS_IMETHOD Scale(float aSx, float aSy);
NS_IMETHOD GetCurrentTransform(nsTransform2D *&aTransform);
NS_IMETHOD CreateDrawingSurface(const nsRect& aBounds, PRUint32 aSurfFlags, nsIDrawingSurface* &aSurface);
NS_IMETHOD DestroyDrawingSurface(nsIDrawingSurface* aDS);
NS_IMETHOD DrawLine(nscoord aX0, nscoord aY0, nscoord aX1, nscoord aY1);
NS_IMETHOD DrawPolyline(const nsPoint aPoints[], PRInt32 aNumPoints);
NS_IMETHOD DrawRect(const nsRect &aRect);
NS_IMETHOD DrawRect(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight);
NS_IMETHOD FillRect(const nsRect &aRect);
NS_IMETHOD FillRect(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight);
NS_IMETHOD InvertRect(const nsRect &aRect);
NS_IMETHOD InvertRect(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight);
NS_IMETHOD DrawPolygon(const nsPoint aPoints[], PRInt32 aNumPoints);
NS_IMETHOD FillPolygon(const nsPoint aPoints[], PRInt32 aNumPoints);
NS_IMETHOD DrawEllipse(const nsRect &aRect);
NS_IMETHOD DrawEllipse(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight);
NS_IMETHOD FillEllipse(const nsRect &aRect);
NS_IMETHOD FillEllipse(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight);
NS_IMETHOD DrawArc(const nsRect &aRect, float aStartAngle, float aEndAngle);
NS_IMETHOD DrawArc(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight,
float aStartAngle, float aEndAngle);
NS_IMETHOD FillArc(const nsRect &aRect, float aStartAngle, float aEndAngle);
NS_IMETHOD FillArc(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight,
float aStartAngle, float aEndAngle);
NS_IMETHOD GetWidth(char aC, nscoord &aWidth);
NS_IMETHOD GetWidth(PRUnichar aC, nscoord &aWidth, PRInt32 *aFontID);
NS_IMETHOD GetWidth(const nsString &aString, nscoord &aWidth, PRInt32 *aFontID);
NS_IMETHOD GetWidth(const char *aString, nscoord &aWidth);
NS_IMETHOD GetWidth(const char *aString, PRUint32 aLength, nscoord &aWidth);
NS_IMETHOD GetWidth(const PRUnichar *aString, PRUint32 aLength, nscoord &aWidth,
PRInt32 *aFontID);
NS_IMETHOD GetTextDimensions(const char *aString, PRUint32 aLength,
nsTextDimensions &aDimensions);
NS_IMETHOD GetTextDimensions(const PRUnichar *aString, PRUint32 aLength,
nsTextDimensions &aDimensions, PRInt32 *aFontID);
NS_IMETHOD GetTextDimensions(const char* aString,
PRInt32 aLength,
PRInt32 aAvailWidth,
PRInt32* aBreaks,
PRInt32 aNumBreaks,
nsTextDimensions& aDimensions,
PRInt32& aNumCharsFit,
nsTextDimensions& aLastWordDimensions,
PRInt32* aFontID = nsnull);
NS_IMETHOD GetTextDimensions(const PRUnichar* aString,
PRInt32 aLength,
PRInt32 aAvailWidth,
PRInt32* aBreaks,
PRInt32 aNumBreaks,
nsTextDimensions& aDimensions,
PRInt32& aNumCharsFit,
nsTextDimensions& aLastWordDimensions,
PRInt32* aFontID = nsnull);
NS_IMETHOD DrawString(const char *aString, PRUint32 aLength, nscoord aX, nscoord aY,
const nscoord *aSpacing);
NS_IMETHOD DrawString(const PRUnichar *aString, PRUint32 aLength, nscoord aX, nscoord aY,
PRInt32 aFontID, const nscoord *aSpacing);
NS_IMETHOD DrawString(const nsString &aString, nscoord aX, nscoord aY, PRInt32 aFontID,
const nscoord *aSpacing);
NS_IMETHOD CopyOffScreenBits(nsIDrawingSurface* aSrcSurf, PRInt32 aSrcX, PRInt32 aSrcY,
const nsRect &aDestBounds, PRUint32 aCopyFlags);
void CreateClipRegion();
#ifdef MOZ_MATHML
/**
* Returns metrics (in app units) of an 8-bit character string
*/
NS_IMETHOD GetBoundingMetrics(const char* aString,
PRUint32 aLength,
nsBoundingMetrics& aBoundingMetrics);
/**
* Returns metrics (in app units) of a Unicode character string
*/
NS_IMETHOD GetBoundingMetrics(const PRUnichar* aString,
PRUint32 aLength,
nsBoundingMetrics& aBoundingMetrics,
PRInt32* aFontID = nsnull);
#endif /* MOZ_MATHML */
//LockAndUpdateView() - method, similar to UpdateGC (from gtk gfx).
//Acquires "fresh" drawable mView (BView) from drawing surface, locks it (BeOS specifics),
//updates font, color and sets clipping region.
bool LockAndUpdateView();
//Each LockAndUpdateView() statement must have UnlockView() counterpart somewhere,
//if returned true.
void UnlockView();
protected:
NS_IMETHOD CommonInit();
// ConditionRect is used to fix coordinate overflow problems for
// rectangles after they are transformed to screen coordinates
void ConditionRect(nscoord &x, nscoord &y, nscoord &w, nscoord &h)
{
if (y < -32766) y = -32766;
if (y + h > 32766) h = 32766 - y;
if (x < -32766) x = -32766;
if (x + w > 32766) w = 32766 - x;
}
nsDrawingSurfaceBeOS *mOffscreenSurface;
nsDrawingSurfaceBeOS *mSurface;
nsIDeviceContext *mContext;
nsIFontMetrics *mFontMetrics;
nsCOMPtr<nsIRegion> mClipRegion;
nsVoidArray *mStateCache;
BView *mView;
nscolor mCurrentColor;
rgb_color mRGB_color;
BFont *mCurrentBFont;
nsLineStyle mCurrentLineStyle;
pattern mCurrentLinePattern;
float mP2T;
};
#endif /* nsRenderingContextBeOS_h___ */

View File

@ -96,7 +96,6 @@ MAKEFILES_gfx="
gfx/idl/Makefile
gfx/public/Makefile
gfx/src/Makefile
gfx/src/beos/Makefile
gfx/src/psshared/Makefile
gfx/src/photon/Makefile
gfx/src/thebes/Makefile

View File

@ -51,15 +51,6 @@
#include "nsWidgetsCID.h"
#include "nsCRT.h"
// if we want to do Image-dragging, also need to change Makefile.in
// to add
// -I$(topsrcdir)/gfx/src/beos \
// in INCLUDES
// and bug 294234 to be done.
// #include "nsIImage.h"
// #include "nsIImageBeOS.h"
//#include <Bitmap.h>
#include <AppDefs.h>
#include <TypeConstants.h>
#include <DataIO.h>