Back to index

lightning-sunbird  0.9+nobinonly
nsImageGTK.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either of the GNU General Public License Version 2 or later (the "GPL"),
00026  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 #ifndef nsImageGTK_h___
00039 #define nsImageGTK_h___
00040 
00041 #include "nsIImage.h"
00042 
00043 #include <X11/Xlib.h>
00044 #include <X11/Xutil.h>
00045 #include <gdk/gdk.h>
00046 #include "nsRegion.h"
00047 #ifdef MOZ_WIDGET_GTK2
00048 #include "nsIGdkPixbufImage.h"
00049 #endif
00050 
00051 class nsDrawingSurfaceGTK;
00052 
00053 class nsImageGTK :
00054 #ifdef MOZ_WIDGET_GTK2
00055                    public nsIGdkPixbufImage
00056 #else
00057                    public nsIImage
00058 #endif
00059 {
00060 public:
00061   nsImageGTK();
00062   virtual ~nsImageGTK();
00063 
00064   static void Startup();
00065   static void Shutdown();
00066 
00067   NS_DECL_ISUPPORTS
00068 
00072   virtual PRInt32     GetBytesPix()       { return mNumBytesPixel; }
00073   virtual PRInt32     GetHeight();
00074   virtual PRInt32     GetWidth();
00075   virtual PRUint8*    GetBits();
00076   virtual void*       GetBitInfo();
00077   virtual PRBool      GetIsRowOrderTopToBottom() { return PR_TRUE; }
00078   virtual PRInt32     GetLineStride();
00079 
00080   virtual nsColorMap* GetColorMap();
00081 
00082   NS_IMETHOD Draw(nsIRenderingContext &aContext,
00083                   nsIDrawingSurface* aSurface,
00084                   PRInt32 aX, PRInt32 aY,
00085                   PRInt32 aWidth, PRInt32 aHeight);
00086   NS_IMETHOD Draw(nsIRenderingContext &aContext,
00087                   nsIDrawingSurface* aSurface,
00088                   PRInt32 aSX, PRInt32 aSY, PRInt32 aSWidth, PRInt32 aSHeight,
00089                   PRInt32 aDX, PRInt32 aDY, PRInt32 aDWidth, PRInt32 aDHeight);
00090 
00091   NS_IMETHOD DrawToImage(nsIImage* aDstImage, nscoord aDX, nscoord aDY,
00092                          nscoord aDWidth, nscoord aDHeight);
00093 
00094   NS_IMETHOD DrawTile(nsIRenderingContext &aContext,
00095                       nsIDrawingSurface* aSurface,
00096                       PRInt32 aSXOffset, PRInt32 aSYOffset,
00097                       PRInt32 aPadX, PRInt32 aPadY,
00098                       const nsRect &aTileRect);
00099 
00100   void UpdateCachedImage();
00101   virtual void ImageUpdated(nsIDeviceContext *aContext,
00102                             PRUint8 aFlags, nsRect *aUpdateRect);
00103   virtual PRBool      GetIsImageComplete();
00104   virtual nsresult    Init(PRInt32 aWidth, PRInt32 aHeight,
00105                            PRInt32 aDepth,
00106                            nsMaskRequirements aMaskRequirements);
00107 
00108   virtual nsresult    Optimize(nsIDeviceContext* aContext);
00109 
00110   virtual PRBool      GetHasAlphaMask()     { return mAlphaBits != nsnull || mAlphaPixmap != nsnull; }
00111   virtual PRUint8*    GetAlphaBits();
00112   virtual PRInt32     GetAlphaLineStride();
00113 
00119   virtual PRInt8 GetAlphaDepth() { 
00120     if (mTrueAlphaBits)
00121       return mTrueAlphaDepth;
00122     else
00123       return mAlphaDepth;
00124   }
00125 
00126   NS_IMETHOD   LockImagePixels(PRBool aMaskPixels);
00127   NS_IMETHOD   UnlockImagePixels(PRBool aMaskPixels);    
00128 
00129 #ifdef MOZ_WIDGET_GTK2
00130   NS_IMETHOD_(GdkPixbuf*) GetGdkPixbuf();
00131 #endif
00132 
00133 private:
00137   void ComputeMetrics() {
00138     mRowBytes = (mWidth * mDepth) >> 5;
00139 
00140     if (((PRUint32)mWidth * mDepth) & 0x1F)
00141       mRowBytes++;
00142     mRowBytes <<= 2;
00143     
00144     mSizeImage = mRowBytes * mHeight;
00145   };
00146   void ComputePaletteSize(PRIntn nBitCount);
00147 
00148 private:
00149 
00150   static unsigned scaled6[1<<6];
00151   static unsigned scaled5[1<<5];
00152 
00153   void DrawComposited32(PRBool isLSB, PRBool flipBytes,
00154                         PRUint8 *imageOrigin, PRUint32 imageStride,
00155                         PRUint8 *alphaOrigin, PRUint32 alphaStride,
00156                         unsigned width, unsigned height,
00157                         XImage *ximage, unsigned char *readData, unsigned char *srcData);
00158   void DrawComposited24(PRBool isLSB, PRBool flipBytes,
00159                         PRUint8 *imageOrigin, PRUint32 imageStride,
00160                         PRUint8 *alphaOrigin, PRUint32 alphaStride,
00161                         unsigned width, unsigned height,
00162                         XImage *ximage, unsigned char *readData, unsigned char *srcData);
00163   void DrawComposited16(PRBool isLSB, PRBool flipBytes,
00164                         PRUint8 *imageOrigin, PRUint32 imageStride,
00165                         PRUint8 *alphaOrigin, PRUint32 alphaStride,
00166                         unsigned width, unsigned height,
00167                         XImage *ximage, unsigned char *readData, unsigned char *srcData);
00168   void DrawCompositedGeneral(PRBool isLSB, PRBool flipBytes,
00169                              PRUint8 *imageOrigin, PRUint32 imageStride,
00170                              PRUint8 *alphaOrigin, PRUint32 alphaStride,
00171                              unsigned width, unsigned height,
00172                              XImage *ximage, unsigned char *readData, unsigned char *srcData);
00173   inline void DrawComposited(nsIRenderingContext &aContext,
00174                              nsIDrawingSurface* aSurface,
00175                              PRInt32 srcWidth, PRInt32 srcHeight,
00176                              PRInt32 dstWidth, PRInt32 dstHeight,
00177                              PRInt32 dstOrigX, PRInt32 dstOrigY,
00178                              PRInt32 aDX, PRInt32 aDY,
00179                              PRInt32 aDWidth, PRInt32 aDHeight);
00180   inline void DrawCompositeTile(nsIRenderingContext &aContext,
00181                                 nsIDrawingSurface* aSurface,
00182                                 PRInt32 aSX, PRInt32 aSY,
00183                                 PRInt32 aSWidth, PRInt32 aSHeight,
00184                                 PRInt32 aDX, PRInt32 aDY,
00185                                 PRInt32 aDWidth, PRInt32 aDHeight);
00186 
00187   inline void TilePixmap(GdkPixmap *src, GdkPixmap *dest, PRInt32 aSXOffset, PRInt32 aSYOffset, 
00188                          const nsRect &destRect, const nsRect &clipRect, PRBool useClip);
00189   inline void CreateOffscreenPixmap(PRInt32 aWidth, PRInt32 aHeight);
00190   inline void SetupGCForAlpha(GdkGC *aGC, PRInt32 aX, PRInt32 aY);
00191 
00192   void SlowTile(nsDrawingSurfaceGTK *aSurface, const nsRect &aTileRect,
00193                 PRInt32 aSXOffset, PRInt32 aSYOffset, const nsRect& aRect, PRBool aIsValid);
00194 
00195   PRUint8      *mImageBits;
00196   GdkPixmap    *mImagePixmap;
00197   PRUint8      *mTrueAlphaBits;
00198   PRUint8      *mAlphaBits;
00199   GdkPixmap    *mAlphaPixmap;
00200   XImage       *mAlphaXImage;
00201 
00202   PRInt32       mWidth;
00203   PRInt32       mHeight;
00204   PRInt32       mRowBytes;
00205   PRInt32       mSizeImage;
00206 
00207   PRInt32       mDecodedX1;         // Keeps track of what part of image
00208   PRInt32       mDecodedY1;         // has been decoded.
00209   PRInt32       mDecodedX2;
00210   PRInt32       mDecodedY2;
00211 
00212   nsRegion      mUpdateRegion;
00213 
00214   // alpha layer members
00215   PRInt32       mAlphaRowBytes;     // alpha bytes per row
00216   PRInt32       mTrueAlphaRowBytes; // alpha bytes per row
00217   PRInt8        mAlphaDepth;        // alpha layer depth
00218   PRInt8        mTrueAlphaDepth;    // alpha layer depth
00219   PRPackedBool  mIsSpacer;
00220   PRPackedBool  mPendingUpdate;
00221 
00222   PRInt8        mNumBytesPixel;
00223   PRUint8       mFlags;             // flags set by ImageUpdated
00224   PRInt8        mDepth;             // bits per pixel
00225 
00226   PRPackedBool  mOptimized;
00227 };
00228 
00229 #endif