Back to index

lightning-sunbird  0.9+nobinonly
nsCairoDrawingSurface.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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
00006  * Version 1.1 (the "License"); you may not use this file except in
00007  * compliance with 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  *  Vladimir Vukicevic <vladimir@pobox.com>
00019  * Portions created by the Initial Developer are Copyright (C) 2004
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  *
00025  * Alternatively, the contents of this file may be used under the terms of
00026  * either the GNU General Public License Version 2 or later (the "GPL"), or
00027  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00028  * in which case the provisions of the GPL or the LGPL are applicable instead
00029  * of those above. If you wish to allow use of your version of this file only
00030  * under the terms of either the GPL or the LGPL, and not to allow others to
00031  * use your version of this file under the terms of the NPL, indicate your
00032  * decision by deleting the provisions above and replace them with the notice
00033  * and other provisions required by the GPL or the LGPL. If you do not delete
00034  * the provisions above, a recipient may use your version of this file under
00035  * the terms of any one of the NPL, the GPL or the LGPL.
00036  *
00037  * ***** END LICENSE BLOCK ***** */
00038 
00039 #ifndef NSCAIRODRAWINGSURFACE__H__
00040 #define NSCAIRODRAWINGSURFACE__H__
00041 
00042 #include "nsCOMPtr.h"
00043 
00044 #include "nsIDrawingSurface.h"
00045 #include "nsIRegion.h"
00046 
00047 #include <cairo.h>
00048 
00049 #if defined(MOZ_ENABLE_GTK2)
00050 #include <gdk/gdkx.h>
00051 #include <X11/extensions/XShm.h>
00052 #endif
00053 
00054 class nsIWidget;
00055 class nsCairoDeviceContext;
00056 
00057 #ifdef MOZ_ENABLE_XFT
00058 typedef struct _XftDraw XftDraw;
00059 #endif
00060 
00061 class nsCairoDrawingSurface : public nsIDrawingSurface
00062 {
00063 public:
00064     nsCairoDrawingSurface ();
00065     virtual ~nsCairoDrawingSurface ();
00066 
00067     // create a image surface if aFastAccess == TRUE, otherwise create
00068     // a fast server pixmap
00069     nsresult Init (nsCairoDeviceContext *aDC, PRUint32 aWidth, PRUint32 aHeight, PRBool aFastAccess);
00070 
00071     // create a fast drawing surface for a native widget
00072     nsresult Init (nsCairoDeviceContext *aDC, nsIWidget *aWidget);
00073 
00074     // create a fast drawing surface for a native widget
00075     nsresult Init (nsCairoDeviceContext *aDC, nsNativeWidget aWidget);
00076 
00077     // nsISupports interface
00078     NS_DECL_ISUPPORTS
00079 
00080     // nsIDrawingSurface interface
00081 
00082     NS_IMETHOD Lock(PRInt32 aX, PRInt32 aY, PRUint32 aWidth, PRUint32 aHeight,
00083                     void **aBits, PRInt32 *aStride, PRInt32 *aWidthBytes,
00084                     PRUint32 aFlags);
00085     NS_IMETHOD Unlock(void);
00086     NS_IMETHOD GetDimensions(PRUint32 *aWidth, PRUint32 *aHeight);
00087     NS_IMETHOD IsOffscreen(PRBool *aOffScreen);
00088     NS_IMETHOD IsPixelAddressable(PRBool *aAddressable);
00089     NS_IMETHOD GetPixelFormat(nsPixelFormat *aFormat);
00090 
00091     /* utility functions */
00092     cairo_surface_t *GetCairoSurface(void) { return mSurface; }
00093     PRInt32 GetDepth() { /* XXX */ return 24; }
00094     nsNativeWidget GetNativeWidget(void) { return mNativeWidget; }
00095 
00096 #ifdef MOZ_ENABLE_XFT
00097     XftDraw *GetXftDraw(void);
00098     void     GetLastXftClip(nsIRegion **aLastRegion);
00099     void     SetLastXftClip(nsIRegion  *aLastRegion);
00100 #endif /* MOZ_ENABLE_XFT */
00101 
00102 private:
00103     cairo_surface_t *mSurface, *mImageSurface;
00104     nsCairoDeviceContext *mDC;
00105     nsNativeWidget mNativeWidget;
00106 
00107 #if defined(MOZ_ENABLE_GTK2) || defined(MOZ_ENABLE_XLIB)
00108     Display *mXDisplay;
00109     Drawable mDrawable;
00110     Pixmap mPixmap;
00111     XShmSegmentInfo mShmInfo;
00112 #endif
00113 
00114 #ifdef MOZ_ENABLE_XFT
00115     XftDraw             *mXftDraw;
00116     nsCOMPtr<nsIRegion>  mLastXftClip;
00117 #endif
00118 
00119     PRUint32 mLockFlags;
00120     PRBool mFastAccess;
00121     PRUint32 mWidth, mHeight;
00122 
00123 };
00124 
00125 #endif /* NSCAIRODRAWINGSURFACE__H__ */