Image group now holds a reference to a nsIDeviceContext and not a

nsIRenderingContext. Optimize() member function of nsIImage changed
to take a nsIDeviceContext
This commit is contained in:
troy%netscape.com 1998-08-03 04:53:25 +00:00
Родитель 09c36ef1f5
Коммит 65fa90f8d9
16 изменённых файлов: 269 добавлений и 123 удалений

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

@ -512,9 +512,7 @@ nsDrawingSurface nsDeviceContextUnix :: GetDrawingSurface()
}
NS_IMETHODIMP nsDeviceContextUnix :: LoadIconImage(nsIRenderingContext& aContext,
PRInt32 aId,
nsIImage*& aImage)
NS_IMETHODIMP nsDeviceContextUnix :: LoadIconImage(PRInt32 aId, nsIImage*& aImage)
{
// XXX Unix should be using DeviceContextImpl...
aImage = nsnull;
@ -557,6 +555,27 @@ NS_IMETHODIMP nsDeviceContextUnix :: CheckFontExistence(const char * aFontName)
return rv;
}
NS_IMETHODIMP nsDeviceContextUnix::CreateILColorSpace(IL_ColorSpace*& aColorSpace)
{
IL_RGBBits colorRGBBits;
// Default is to create a 24-bit color space
colorRGBBits.red_shift = 16;
colorRGBBits.red_bits = 8;
colorRGBBits.green_shift = 8;
colorRGBBits.green_bits = 8;
colorRGBBits.blue_shift = 0;
colorRGBBits.blue_bits = 8;
aColorSpace = IL_CreateTrueColorSpace(&colorRGBBits, 24);
if (nsnull == aColorSpace) {
return NS_ERROR_OUT_OF_MEMORY;
}
return NS_OK;
}

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

@ -93,12 +93,12 @@ public:
virtual PRUint32 ConvertPixel(nscolor aColor);
NS_IMETHOD LoadIconImage(nsIRenderingContext& aContext,
PRInt32 aId,
nsIImage*& aImage);
NS_IMETHOD LoadIconImage(PRInt32 aId, nsIImage*& aImage);
NS_IMETHOD CheckFontExistence(const char * aFontName);
NS_IMETHOD CreateILColorSpace(IL_ColorSpace*& aColorSpace);
protected:
~nsDeviceContextUnix();
nsresult CreateFontCache();

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

@ -189,6 +189,7 @@ nsDrawingSurfaceUnix *unixdrawing =(nsDrawingSurfaceUnix*) aSurface;
if ((PR_FALSE==mStaticImage) || (nsnull == mImage)) {
BuildImage(aSurface);
mStaticImage = PR_TRUE;
}
if (nsnull == mImage)
@ -213,6 +214,7 @@ nsDrawingSurfaceUnix *unixdrawing =(nsDrawingSurfaceUnix*) aSurface;
// Build Image each time if it's not static.
if ((PR_FALSE==mStaticImage) || (nsnull == mImage)) {
BuildImage(aSurface);
mStaticImage = PR_TRUE;
}
if (nsnull == mImage)
@ -349,10 +351,12 @@ nsresult nsImageUnix::BuildImage(nsDrawingSurface aDrawingSurface)
//------------------------------------------------------------
nsresult nsImageUnix::Optimize(nsDrawingSurface aDrawingSurface)
nsresult nsImageUnix::Optimize(nsIDeviceContext* aContext)
{
#if 0
mStaticImage = PR_TRUE;
BuildImage(aDrawingSurface);
#endif
return NS_OK;
}

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

@ -49,7 +49,7 @@ public:
virtual PRBool IsOptimized() { return (mImage!=nsnull); }
virtual nsresult BuildImage(nsDrawingSurface aDrawingSurface);
virtual nsresult Optimize(nsDrawingSurface aSurface);
virtual nsresult Optimize(nsIDeviceContext* aContext);
virtual PRUint8* GetAlphaBits() { return mAlphaBits; }
virtual PRInt32 GetAlphaWidth() { return 0;}
virtual PRInt32 GetAlphaHeight() {return 0;}

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

@ -217,7 +217,7 @@ nsNativeWidget DeviceContextImpl :: GetNativeWidget(void)
return mWidget;
}
nsresult DeviceContextImpl::CreateImageGroupContext(nsIRenderingContext& aContext)
nsresult DeviceContextImpl::CreateIconILGroupContext()
{
ilIImageRenderer* renderer;
nsresult result;
@ -229,33 +229,23 @@ nsresult DeviceContextImpl::CreateImageGroupContext(nsIRenderingContext& aContex
}
// Create an image group context. The image renderer code expects the
// display_context to be a pointer to a nsIRenderingContext
mIconImageGroup = IL_NewGroupContext((void*)(nsIRenderingContext*)&aContext,
renderer);
// display_context to be a pointer to a device context
mIconImageGroup = IL_NewGroupContext((void*)this, renderer);
if (nsnull == mIconImageGroup) {
NS_RELEASE(renderer);
return NS_ERROR_OUT_OF_MEMORY;
}
// Initialize the image group context.
// XXX Hard coded tp 24-bits.
IL_RGBBits colorRGBBits;
IL_ColorSpace* colorSpace;
colorRGBBits.red_shift = 16;
colorRGBBits.red_bits = 8;
colorRGBBits.green_shift = 8;
colorRGBBits.green_bits = 8;
colorRGBBits.blue_shift = 0;
colorRGBBits.blue_bits = 8;
colorSpace = IL_CreateTrueColorSpace(&colorRGBBits, 24);
if (nsnull == colorSpace) {
result = CreateILColorSpace(colorSpace);
if (NS_FAILED(result)) {
NS_RELEASE(renderer);
IL_DestroyGroupContext(mIconImageGroup);
return NS_ERROR_OUT_OF_MEMORY;
return result;
}
// This is all synchronous, so don't waste time with progressive display
// Icon loading is synchronous, so don't waste time with progressive display
IL_DisplayData displayData;
displayData.dither_mode = IL_Auto;
displayData.color_space = colorSpace;
@ -266,9 +256,7 @@ nsresult DeviceContextImpl::CreateImageGroupContext(nsIRenderingContext& aContex
return NS_OK;
}
NS_IMETHODIMP DeviceContextImpl::LoadIconImage(nsIRenderingContext& aContext,
PRInt32 aId,
nsIImage*& aImage)
NS_IMETHODIMP DeviceContextImpl::LoadIconImage(PRInt32 aId, nsIImage*& aImage)
{
nsresult result;
@ -288,7 +276,7 @@ NS_IMETHODIMP DeviceContextImpl::LoadIconImage(nsIRenderingContext& aContext,
// Make sure we have an image group context
if (nsnull == mIconImageGroup) {
result = CreateImageGroupContext(aContext);
result = CreateIconILGroupContext();
if (NS_FAILED(result)) {
return result;
}
@ -325,3 +313,107 @@ NS_IMETHODIMP DeviceContextImpl::LoadIconImage(nsIRenderingContext& aContext,
return result;
}
NS_IMETHODIMP DeviceContextImpl::CreateILColorSpace(IL_ColorSpace*& aColorSpace)
{
IL_RGBBits colorRGBBits;
// Default is to create a 24-bit color space
colorRGBBits.red_shift = 16;
colorRGBBits.red_bits = 8;
colorRGBBits.green_shift = 8;
colorRGBBits.green_bits = 8;
colorRGBBits.blue_shift = 0;
colorRGBBits.blue_bits = 8;
aColorSpace = IL_CreateTrueColorSpace(&colorRGBBits, 24);
if (nsnull == aColorSpace) {
return NS_ERROR_OUT_OF_MEMORY;
}
return NS_OK;
}
#if 0
nsresult result = NS_OK;
int bitsPerPixel = ::GetDeviceCaps(mDC, BITSPIXEL);
int rasterCaps = ::GetDeviceCaps(mDC, RASTERCAPS);
// See if we're dealing with an 8-bit palette device
if ((8 == bitsPerPixel) && (rasterCaps & RC_PALETTE)) {
// Create a color cube. We want to use DIB_PAL_COLORS because it's faster
// than DIB_RGB_COLORS, so make sure the indexes match that of the
// GDI physical palette
//
// Note: the image library doesn't use the reserved colors, so it doesn't
// matter what they're set to...
IL_RGB reserved[10];
IL_ColorMap* colorMap = IL_NewCubeColorMap(reserved, 10, COLOR_CUBE_SIZE + 10);
if (nsnull == colorMap) {
return NS_ERROR_OUT_OF_MEMORY;
}
// Create a physical palette if we haven't already done so. Each HDC can
// share the same physical palette
if (nsnull == gPalette) {
// Create a logical palette
BYTE tmp[sizeof(LOGPALETTE) + ((COLOR_CUBE_SIZE + 20) * sizeof(PALETTEENTRY))];
LPLOGPALETTE logPal = (LPLOGPALETTE)tmp;
logPal->palVersion = 0x300;
logPal->palNumEntries = COLOR_CUBE_SIZE + 20;
// Initialize it from the default Windows palette
HPALETTE hDefaultPalette = ::GetStockObject(DEFAULT_PALETTE);
// First ten system colors
::GetPaletteEntries(hDefaultPalette, 0, 10, logPal->palPalEntry);
// Last ten system colors
::GetPaletteEntries(hDefaultPalette, 10, 10, &logPal->palPalEntry[COLOR_CUBE_SIZE + 10]);
// Now set the color cube entries
PALETTEENTRY* entry = &logPal->palPalEntry[10];
NI_RGB* map = colorMap->map + 10;
for (PRInt32 i = 0; i < COLOR_CUBE_SIZE; i++) {
entry->peRed = map->red;
entry->peGreen = map->green;
entry->peBlue = map->blue;
entry->peFlags = 0;
entry++;
map++;
}
// Create a GDI palette
gPalette = ::CreatePalette(logPal);
}
// Create an IL pseudo color space
aColorSpace = IL_CreatePseudoColorSpace(colorMap, 8, 8);
if (nsnull == aColorSpace) {
return NS_ERROR_OUT_OF_MEMORY;
}
} else {
// Create a default color space.
// XXX We should also check for 1 16-bit device and create a 555 or 565
// color space...
IL_RGBBits colorRGBBits;
// Default is to create a 24-bit color space
colorRGBBits.red_shift = 16;
colorRGBBits.red_bits = 8;
colorRGBBits.green_shift = 8;
colorRGBBits.green_bits = 8;
colorRGBBits.blue_shift = 0;
colorRGBBits.blue_bits = 8;
aColorSpace = IL_CreateTrueColorSpace(&colorRGBBits, 24);
if (nsnull == aColorSpace) {
return NS_ERROR_OUT_OF_MEMORY;
}
}
return result;
#endif

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

@ -21,6 +21,7 @@
#include "nsIDeviceContext.h"
#include "libimg.h"
class nsIImageRequest;
class DeviceContextImpl : public nsIDeviceContext
@ -59,16 +60,16 @@ public:
virtual nsNativeWidget GetNativeWidget(void);
NS_IMETHOD LoadIconImage(nsIRenderingContext& aContext,
PRInt32 aId,
nsIImage*& aImage);
NS_IMETHOD LoadIconImage(PRInt32 aId, nsIImage*& aImage);
NS_IMETHOD CreateILColorSpace(IL_ColorSpace*& aColorSpace);
protected:
virtual ~DeviceContextImpl();
nsresult CreateFontCache();
void SetGammaTable(PRUint8 * aTable, float aCurrentGamma, float aNewGamma);
nsresult CreateImageGroupContext(nsIRenderingContext& aContext);
nsresult CreateIconILGroupContext();
float mTwipsToPixels;
float mPixelsToTwips;

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

@ -20,11 +20,11 @@
#define nsIDeviceContext_h___
#include "nsISupports.h"
#include "nsIRenderingContext.h"
#include "nsCoord.h"
#include "nsRect.h"
#include "nsIWidget.h"
class nsIRenderingContext;
class nsIView;
class nsIFontCache;
class nsIFontMetrics;
@ -46,6 +46,12 @@ typedef void * nsNativeDeviceContext;
#define NS_ICON_BROKEN_IMAGE 1
#define NS_NUMBER_OF_ICONS 2
// XXX This is gross, but don't include libimg.h, because it includes ni_pixmap.h
// which includes xp_core.h which includes windows.h
struct _NI_ColorSpace;
typedef _NI_ColorSpace NI_ColorSpace;
typedef NI_ColorSpace IL_ColorSpace;
class nsIDeviceContext : public nsISupports
{
public:
@ -104,9 +110,7 @@ public:
//load the specified icon. this is a blocking call that does not return
//until the icon is loaded.
//release the image when you're done
NS_IMETHOD LoadIconImage(nsIRenderingContext& aContext,
PRInt32 aId,
nsIImage*& aImage) = 0;
NS_IMETHOD LoadIconImage(PRInt32 aId, nsIImage*& aImage) = 0;
/**
* Check to see if a particular named font exists.
@ -114,6 +118,12 @@ public:
* @return NS_OK if font is available, else font is unavailable
*/
NS_IMETHOD CheckFontExistence(const char * aFontName) = 0;
/**
* Create an image lib color space that's appropriate for this rendering
* context
*/
NS_IMETHOD CreateILColorSpace(IL_ColorSpace*& aColorSpace) = 0;
};
#endif /* nsIDeviceContext_h___ */

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

@ -149,10 +149,10 @@ public:
/**
* Converted this pixelmap to an optimized pixelmap for the device
@param aSurface The surface to optimize for
@param aContext The device to optimize for
@return the result of the operation, if NS_OK, then the pixelmap is optimized
*/
virtual nsresult Optimize(nsDrawingSurface aSurface) = 0;
virtual nsresult Optimize(nsIDeviceContext* aContext) = 0;
/**
* Get the colormap for the pixelmap

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

@ -27,7 +27,7 @@
class nsIImageGroupObserver;
class nsIImageRequestObserver;
class nsIImageRequest;
class nsIRenderingContext;
class nsIDeviceContext;
/** For important images, like backdrops. */
#define nsImageLoadFlags_kHighPriority 0x01
@ -52,10 +52,10 @@ class nsIImageGroup : public nsISupports
{
public:
/**
* Initialize an image group with a rendering context. All images
* in this group will be decoded for the specified rendering context.
* Initialize an image group with a device context. All images
* in this group will be decoded for the specified device context.
*/
virtual nsresult Init(nsIRenderingContext *aRenderingContext) = 0;
virtual nsresult Init(nsIDeviceContext *aDeviceContext) = 0;
/**
* Add an observers to be informed of image group notifications.

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

@ -54,7 +54,7 @@ typedef enum
//----------------------------------------------------------------------
//a cross platform way of specifying a navite rendering context
//a cross platform way of specifying a native rendering context
typedef void * nsDrawingSurface;
// RenderingContext interface

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

@ -24,10 +24,10 @@
#include "ilIImageRenderer.h"
#include "nsImageNet.h"
#include "nsVoidArray.h"
#include "nsIRenderingContext.h"
#include "nsCRT.h"
#include "libimg.h"
#include "il_util.h"
#include "nsIDeviceContext.h"
static NS_DEFINE_IID(kIImageGroupIID, NS_IIMAGEGROUP_IID);
@ -42,7 +42,7 @@ public:
ImageGroupImpl(nsIImageManager *aManager);
~ImageGroupImpl();
nsresult Init(nsIRenderingContext *aRenderingContext);
nsresult Init(nsIDeviceContext *aDeviceContext);
void* operator new(size_t sz) {
void* rv = new char[sz];
@ -70,7 +70,7 @@ private:
nsIImageManager *mManager;
IL_GroupContext *mGroupContext;
nsVoidArray *mObservers;
nsIRenderingContext *mRenderingContext;
nsIDeviceContext *mDeviceContext;
IL_ColorSpace *mColorSpace;
};
@ -83,9 +83,7 @@ ImageGroupImpl::ImageGroupImpl(nsIImageManager *aManager)
ImageGroupImpl::~ImageGroupImpl()
{
if (mRenderingContext != nsnull) {
NS_RELEASE(mRenderingContext);
}
NS_IF_RELEASE(mDeviceContext);
if (mObservers != nsnull) {
PRInt32 i, count = mObservers->Count();
@ -116,7 +114,7 @@ ImageGroupImpl::~ImageGroupImpl()
NS_IMPL_ISUPPORTS(ImageGroupImpl, kIImageGroupIID)
nsresult
ImageGroupImpl::Init(nsIRenderingContext *aRenderingContext)
ImageGroupImpl::Init(nsIDeviceContext *aDeviceContext)
{
ilIImageRenderer *renderer;
nsresult result;
@ -125,30 +123,20 @@ ImageGroupImpl::Init(nsIRenderingContext *aRenderingContext)
return result;
}
// XXX Need to create an image renderer
mGroupContext = IL_NewGroupContext((void *)aRenderingContext,
mGroupContext = IL_NewGroupContext((void *)aDeviceContext,
renderer);
if (mGroupContext == nsnull) {
return NS_ERROR_OUT_OF_MEMORY;
}
mRenderingContext = aRenderingContext;
NS_ADDREF(mRenderingContext);
mDeviceContext = aDeviceContext;
NS_ADDREF(mDeviceContext);
// XXX Hard coded to be 24-bit. We need to get the right information
// from the rendering context (or device context).
IL_RGBBits colorRGBBits;
colorRGBBits.red_shift = 16;
colorRGBBits.red_bits = 8;
colorRGBBits.green_shift = 8;
colorRGBBits.green_bits = 8;
colorRGBBits.blue_shift = 0;
colorRGBBits.blue_bits = 8;
mColorSpace = IL_CreateTrueColorSpace(&colorRGBBits, 24);
IL_AddRefToColorSpace(mColorSpace);
// Ask the device context to create a color space
mDeviceContext->CreateILColorSpace(mColorSpace);
// Set the image group context display mode
IL_DisplayData displayData;
displayData.dither_mode = IL_Auto;
displayData.color_space = mColorSpace;

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

@ -83,7 +83,7 @@ ImageRendererImpl::NewPixmap(void* aDisplayContext,
PRInt32 aWidth, PRInt32 aHeight,
IL_Pixmap* aImage, IL_Pixmap* aMask)
{
nsIRenderingContext *rc = (nsIRenderingContext *)aDisplayContext;
nsIDeviceContext *dc = (nsIDeviceContext *)aDisplayContext;
nsIImage *img;
nsresult rv;
@ -161,9 +161,7 @@ ImageRendererImpl::NewPixmap(void* aDisplayContext,
*mapptr++ = cmap->map[i].blue;
}
nsIDeviceContext *dx = rc->GetDeviceContext();
img->ImageUpdated(dx, nsImageUpdateFlags_kColorMapChanged, nsnull);
NS_IF_RELEASE(dx);
img->ImageUpdated(dc, nsImageUpdateFlags_kColorMapChanged, nsnull);
if (aImage->header.transparent_pixel) {
PRUint8 red, green, blue;
@ -200,38 +198,29 @@ ImageRendererImpl::UpdatePixmap(void* aDisplayContext,
PRInt32 aXOffset, PRInt32 aYOffset,
PRInt32 aWidth, PRInt32 aHeight)
{
nsIRenderingContext *rc = (nsIRenderingContext *)aDisplayContext;
nsIImage *img = (nsIImage *)aImage->client_data;
nsIDeviceContext *dx = rc->GetDeviceContext();
nsRect drect(aXOffset, aYOffset, aWidth, aHeight);
nsIDeviceContext *dc = (nsIDeviceContext *)aDisplayContext;
nsIImage *img = (nsIImage *)aImage->client_data;
nsRect drect(aXOffset, aYOffset, aWidth, aHeight);
img->ImageUpdated(dx, nsImageUpdateFlags_kBitsChanged, &drect);
NS_IF_RELEASE(dx);
img->ImageUpdated(dc, nsImageUpdateFlags_kBitsChanged, &drect);
}
void
ImageRendererImpl::ControlPixmapBits(void* aDisplayContext,
IL_Pixmap* aImage, PRUint32 aControlMsg)
{
nsIRenderingContext *rc = (nsIRenderingContext *)aDisplayContext;
nsIDeviceContext *dc = (nsIDeviceContext *)aDisplayContext;
nsIImage *img = (nsIImage *)aImage->client_data;
if (aControlMsg == IL_RELEASE_BITS) {
nsIDeviceContext *dx = rc->GetDeviceContext();
if (nsnull != dx) {
nsDrawingSurface surf = dx->GetDrawingSurface(*rc);
if (nsnull != surf)
img->Optimize(surf);
NS_RELEASE(dx);
}
img->Optimize(dc);
}
}
void
ImageRendererImpl::DestroyPixmap(void* aDisplayContext, IL_Pixmap* aImage)
{
nsIRenderingContext *rc = (nsIRenderingContext *)aDisplayContext;
nsIDeviceContext *dc = (nsIDeviceContext *)aDisplayContext;
nsIImage *img = (nsIImage *)aImage->client_data;
aImage->client_data = nsnull;
@ -247,18 +236,15 @@ ImageRendererImpl::DisplayPixmap(void* aDisplayContext,
PRInt32 aXOffset, PRInt32 aYOffset,
PRInt32 aWidth, PRInt32 aHeight)
{
nsIRenderingContext *rc = (nsIRenderingContext *)aDisplayContext;
nsIImage *img = (nsIImage *)aImage->client_data;
// XXX Need better version of DrawImage
rc->DrawImage(img, aX, aY);
// Image library doesn't drive the display process.
// XXX Why is this part of the API?
}
void
ImageRendererImpl::DisplayIcon(void* aDisplayContext,
PRInt32 aX, PRInt32 aY, PRUint32 aIconNumber)
{
nsIRenderingContext *rc = (nsIRenderingContext *)aDisplayContext;
// XXX Why is this part of the API?
}
void
@ -266,7 +252,7 @@ ImageRendererImpl::GetIconDimensions(void* aDisplayContext,
PRInt32 *aWidthPtr, PRInt32 *aHeightPtr,
PRUint32 aIconNumber)
{
nsIRenderingContext *rc = (nsIRenderingContext *)aDisplayContext;
// XXX Why is this part of the API?
}
extern "C" NS_GFX_(nsresult)

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

@ -243,6 +243,31 @@ struct MONOBITMAPINFO {
// (value of 1) to just use the destination bits
#define MASKBLT_ROP MAKEROP4((DWORD)0x00AA0029, SRCCOPY)
void nsImageWin :: CreateDDB(nsDrawingSurface aSurface)
{
HDC the_hdc = (HDC)aSurface;
if ((the_hdc != NULL) && (mSizeImage > 0))
{
mHBitmap = ::CreateDIBitmap(the_hdc, mBHead, CBM_INIT, mImageBits, (LPBITMAPINFO)mBHead,
DIB_RGB_COLORS);
if (nsnull != mAlphaBits)
{
// Create a monochrome bitmap
// XXX Handle the case of 8-bit alpha...
NS_ASSERTION(1 == mAlphaDepth, "unexpected alpha depth");
mAlphaHBitmap = ::CreateBitmap(mAlphaWidth, mAlphaHeight, 1, 1, NULL);
MONOBITMAPINFO bmi(mAlphaWidth, mAlphaHeight);
::SetDIBits(NULL /* ignored */, mAlphaHBitmap, 0, mAlphaHeight, mAlphaBits,
(LPBITMAPINFO)&bmi, DIB_RGB_COLORS);
}
CleanUp(PR_FALSE);
}
}
// Draw the bitmap, this method has a source and destination coordinates
PRBool nsImageWin :: Draw(nsIRenderingContext &aContext, nsDrawingSurface aSurface,
PRInt32 aSX, PRInt32 aSY, PRInt32 aSWidth, PRInt32 aSHeight,
@ -253,6 +278,11 @@ PRBool nsImageWin :: Draw(nsIRenderingContext &aContext, nsDrawingSurface aSurfa
if (mBHead == nsnull)
return PR_FALSE;
// If the image can be optimized then make sure we've created the DDB
if (mIsOptimized && (nsnull == mHBitmap)) {
CreateDDB(aSurface);
}
if (!IsOptimized())
{
DWORD rop = SRCCOPY;
@ -320,6 +350,11 @@ PRBool nsImageWin :: Draw(nsIRenderingContext &aContext, nsDrawingSurface aSurfa
if (mBHead == nsnull)
return PR_FALSE;
// If the image can be optimized then make sure we've created the DDB
if (mIsOptimized && (nsnull == mHBitmap)) {
CreateDDB(aSurface);
}
if (!IsOptimized())
{
DWORD rop = SRCCOPY;
@ -925,31 +960,11 @@ PRBool nsImageWin :: SetSystemPalette(HDC* aHdc)
//------------------------------------------------------------
// creates an optimized bitmap, or HBITMAP
nsresult nsImageWin :: Optimize(nsDrawingSurface aSurface)
nsresult nsImageWin :: Optimize(nsIDeviceContext* aContext)
{
HDC the_hdc = (HDC)aSurface;
if ((the_hdc != NULL) && !IsOptimized() && (mSizeImage > 0))
{
mHBitmap = ::CreateDIBitmap(the_hdc, mBHead, CBM_INIT, mImageBits, (LPBITMAPINFO)mBHead,
DIB_RGB_COLORS);
if (nsnull != mAlphaBits)
{
// Create a monochrome bitmap
// XXX Handle the case of 8-bit alpha...
NS_ASSERTION(1 == mAlphaDepth, "unexpected alpha depth");
mAlphaHBitmap = ::CreateBitmap(mAlphaWidth, mAlphaHeight, 1, 1, NULL);
MONOBITMAPINFO bmi(mAlphaWidth, mAlphaHeight);
::SetDIBits(NULL /* ignored */, mAlphaHBitmap, 0, mAlphaHeight, mAlphaBits,
(LPBITMAPINFO)&bmi, DIB_RGB_COLORS);
}
mIsOptimized = PR_TRUE;
CleanUp(PR_FALSE);
}
// Wait until we're asked to draw, before we create the DDB, because
// we don't have an HDC now
mIsOptimized = PR_TRUE;
return NS_OK;
}

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

@ -44,7 +44,7 @@ public:
virtual void ImageUpdated(nsIDeviceContext *aContext, PRUint8 aFlags, nsRect *aUpdateRect);
virtual nsresult Init(PRInt32 aWidth, PRInt32 aHeight, PRInt32 aDepth, nsMaskRequirements aMaskRequirements);
virtual PRBool IsOptimized() { return mIsOptimized; }
virtual nsresult Optimize(nsDrawingSurface aSurface);
virtual nsresult Optimize(nsIDeviceContext* aContext);
virtual PRUint8* GetAlphaBits() { return mAlphaBits; }
virtual PRInt32 GetAlphaWidth() { return mAlphaWidth;}
virtual PRInt32 GetAlphaHeight() {return mAlphaHeight;}
@ -206,6 +206,8 @@ private:
*/
void ComputeMetrics();
void CreateDDB(nsDrawingSurface aSurface);
PRUint8 PaletteMatch(PRUint8 r, PRUint8 g, PRUint8 b);
PRInt8 mNumBytesPixel; // number of bytes per pixel

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

@ -19,6 +19,8 @@
#include "nsRenderingContextWin.h"
#include "nsRegionWin.h"
#include <math.h>
#include "libimg.h"
#include "il_util.h"
#define FLAG_CLIP_VALID 0x0001
#define FLAG_CLIP_CHANGED 0x0002
@ -26,6 +28,14 @@
#define FLAGS_ALL (FLAG_CLIP_VALID | FLAG_CLIP_CHANGED | FLAG_LOCAL_CLIP_VALID)
// Size of the color cube
#define COLOR_CUBE_SIZE 216
// Macro for creating a palette relative color if you have a COLORREF instead
// of the reg, green, and blue values. The color is color-matches to the nearest
// in the current logical palette. This has no effect on a non-palette device
#define PALETTERGB_COLORREF(c) (0x02000000 | (c))
class GraphicsState
{
public:
@ -105,6 +115,8 @@ GraphicsState :: ~GraphicsState()
static NS_DEFINE_IID(kRenderingContextIID, NS_IRENDERING_CONTEXT_IID);
HPALETTE nsRenderingContextWin::gPalette = NULL;
nsRenderingContextWin :: nsRenderingContextWin()
{
NS_INIT_REFCNT();
@ -120,6 +132,7 @@ nsRenderingContextWin :: nsRenderingContextWin()
mDefFont = NULL;
mOrigSolidPen = NULL;
mBlackPen = NULL;
mOrigPalette = NULL;
mCurrBrushColor = NULL;
mCurrFontMetrics = nsnull;
mCurrPenColor = NULL;
@ -291,12 +304,21 @@ nsresult nsRenderingContextWin :: SetupDC(HDC aOldDC, HDC aNewDC)
if (nsnull != mOrigSolidPen)
::SelectObject(aOldDC, mOrigSolidPen);
if (nsnull != mOrigPalette)
::SelectPalette(aOldDC, mOrigPalette, TRUE);
}
mOrigSolidBrush = ::SelectObject(aNewDC, mBlackBrush);
mOrigFont = ::SelectObject(aNewDC, mDefFont);
mOrigSolidPen = ::SelectObject(aNewDC, mBlackPen);
if (gPalette) {
mOrigPalette = ::SelectPalette(aNewDC, gPalette, FALSE);
// XXX Don't do the realization for an off-screen memory DC...
::RealizePalette(aNewDC);
}
return NS_OK;
}
@ -907,7 +929,8 @@ void nsRenderingContextWin :: FillArc(nscoord aX, nscoord aY, nscoord aWidth, ns
ex = (PRInt32)(distance * cos(anglerad) + cx);
ey = (PRInt32)(cy - distance * sin(anglerad));
// this just makes it consitent, on windows 95 arc will always draw CC, nt this sets direction
// this just makes it consistent, on windows 95 arc will always draw CC,
// on NT this sets direction
::SetArcDirection(mDC, AD_COUNTERCLOCKWISE);
::Pie(mDC, aX, aY, aX + aWidth, aY + aHeight, sx, sy, ex, ey);
@ -1039,7 +1062,9 @@ HBRUSH nsRenderingContextWin :: SetupSolidBrush(void)
{
if ((mCurrentColor != mCurrBrushColor) || (NULL == mCurrBrush))
{
HBRUSH tbrush = ::CreateSolidBrush(mColor);
// XXX In 16-bit mode we need to use GetNearestColor() to get a solid
// color; otherwise, we'll end up with a dithered brush...
HBRUSH tbrush = ::CreateSolidBrush(PALETTERGB_COLORREF(mColor));
::SelectObject(mDC, tbrush);
@ -1068,7 +1093,7 @@ void nsRenderingContextWin :: SetupFontAndColor(void)
}
if (mCurrentColor != mCurrTextColor) {
::SetTextColor(mDC, mColor);
::SetTextColor(mDC, PALETTERGB_COLORREF(mColor));
mStates->mTextColor = mCurrTextColor = mCurrentColor;
}
}
@ -1077,7 +1102,7 @@ HPEN nsRenderingContextWin :: SetupSolidPen(void)
{
if ((mCurrentColor != mCurrPenColor) || (NULL == mCurrPen))
{
HPEN tpen = ::CreatePen(PS_SOLID, 0, mColor);
HPEN tpen = ::CreatePen(PS_SOLID, 0, PALETTERGB_COLORREF(mColor));
::SelectObject(mDC, tpen);
@ -1117,3 +1142,4 @@ void nsRenderingContextWin :: PushClipState(void)
mStates->mFlags |= FLAG_CLIP_CHANGED;
}
}

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

@ -154,6 +154,7 @@ protected:
HFONT mDefFont;
HPEN mOrigSolidPen;
HPEN mBlackPen;
HPALETTE mOrigPalette;
//state management
GraphicsState *mStates;
nsVoidArray *mStateCache;
@ -167,6 +168,8 @@ protected:
PRUint8 *mGammaTable;
COLORREF mCurrTextColor;
static HPALETTE gPalette;
#ifdef NS_DEBUG
PRBool mInitialized;
#endif