diff --git a/ChangeLog b/ChangeLog new file mode 100644 index 0000000..192392e --- /dev/null +++ b/ChangeLog @@ -0,0 +1,34 @@ +2007-08-17 Federico Mena Quintero + + * modules/libpr0n/public/ImageLogging.h: Remove gImgAccountingLog + from here. + + * modules/libpr0n/src/imgRequest.cpp: Likewise. + + * modules/libpr0n/decoders/jpeg/nsJPEGDecoder.cpp + (gJPEGDecodeAccountingLog): Create a "JPEGDecoderAccounting" log domain. + (nsJPEGDecoder::WriteFrom): Use that log domain. + + * gfx/thebes/src/gfxXlibSurface.cpp (gXlibSurfaceAccountingLog): + Define a "XlibSurfaceAccounting" log domain. + (gfxXlibSurface::LogSurfaceCreation): New method to log when an + Xlib surface is created from a pixmap. Keeps a counter of how + many pixels are allocated globally. + (gfxXlibSurface::HookSurfaceDestructionForLogging): Utility method + to set user data on the cairo surface, so that we can know when it + is destroyed. + (gfxXlibSurface::gfxXlibSurface): Log the creation of the surface, + and hook it so that we can know when it is destroyed. + +2007-08-17 Federico Mena Quintero + + * modules/libpr0n/src/imgRequest.cpp (gImgAccountingLog): New + logging domain "imgAccounting". We'll use this to log when images + get allocated, freed, requested, etc. + + * modules/libpr0n/public/ImageLogging.h (gImgAccountingLog): + Declare this. + + * modules/libpr0n/decoders/jpeg/nsJPEGDecoder.cpp + (nsJPEGDecoder::WriteFrom): Log the creation of an image frame. + diff --git a/gfx/thebes/public/gfxXlibSurface.h b/gfx/thebes/public/gfxXlibSurface.h index 078dc73..f44e9f7 100644 --- a/gfx/thebes/public/gfxXlibSurface.h +++ b/gfx/thebes/public/gfxXlibSurface.h @@ -85,6 +85,9 @@ public: // when the gfxXlibSurface is destroyed. void TakePixmap(); + void LogSurfaceCreation (); + void HookSurfaceDestructionForLogging (); + protected: // if TakePixmap() was already called on this PRBool mPixmapTaken; diff --git a/gfx/thebes/src/gfxXlibSurface.cpp b/gfx/thebes/src/gfxXlibSurface.cpp index dc2a19f..57ff375 100644 --- a/gfx/thebes/src/gfxXlibSurface.cpp +++ b/gfx/thebes/src/gfxXlibSurface.cpp @@ -21,6 +21,7 @@ * Contributor(s): * Stuart Parmenter * Vladimir Vukicevic + * Federico Mena-Quintero * * Alternatively, the contents of this file may be used under the terms of * either the GNU General Public License Version 2 or later (the "GPL"), or @@ -37,6 +38,7 @@ * ***** END LICENSE BLOCK ***** */ #include "gfxXlibSurface.h" +#include "prlog.h" #include "cairo.h" #include "cairo-xlib.h" @@ -51,6 +53,17 @@ typedef struct { static void pixmap_free_func (void *); + +#if defined(PR_LOGGING) +static PRLogModuleInfo *gXlibSurfaceAccountingLog = PR_NewLogModule ("XlibSurfaceAccounting"); +#else +#define gXlibSurfaceAccountingLog +#endif + +static cairo_user_data_key_t surface_free_key; +static PRInt64 pixels_allocated; + + #define XLIB_IMAGE_SIDE_SIZE_LIMIT 0xffff gfxXlibSurface::gfxXlibSurface(Display *dpy, Drawable drawable, Visual *visual) @@ -59,6 +72,9 @@ gfxXlibSurface::gfxXlibSurface(Display *dpy, Drawable drawable, Visual *visual) DoSizeQuery(); cairo_surface_t *surf = cairo_xlib_surface_create(dpy, drawable, visual, mSize.width, mSize.height); Init(surf); + + LogSurfaceCreation (); + HookSurfaceDestructionForLogging(); } gfxXlibSurface::gfxXlibSurface(Display *dpy, Drawable drawable, Visual *visual, const gfxIntSize& size) @@ -69,6 +85,9 @@ gfxXlibSurface::gfxXlibSurface(Display *dpy, Drawable drawable, Visual *visual, cairo_surface_t *surf = cairo_xlib_surface_create(dpy, drawable, visual, mSize.width, mSize.height); Init(surf); + + LogSurfaceCreation (); + HookSurfaceDestructionForLogging(); } gfxXlibSurface::gfxXlibSurface(Display *dpy, Visual *visual, const gfxIntSize& size) @@ -87,6 +106,9 @@ gfxXlibSurface::gfxXlibSurface(Display *dpy, Visual *visual, const gfxIntSize& s Init(surf); TakePixmap(); + + LogSurfaceCreation (); + HookSurfaceDestructionForLogging(); } gfxXlibSurface::gfxXlibSurface(Display *dpy, Drawable drawable, XRenderPictFormat *format, @@ -100,6 +122,9 @@ gfxXlibSurface::gfxXlibSurface(Display *dpy, Drawable drawable, XRenderPictForma ScreenOfDisplay(dpy,DefaultScreen(dpy)), format, mSize.width, mSize.height); Init(surf); + + LogSurfaceCreation (); + HookSurfaceDestructionForLogging(); } gfxXlibSurface::gfxXlibSurface(Display *dpy, XRenderPictFormat *format, const gfxIntSize& size) @@ -115,6 +140,9 @@ gfxXlibSurface::gfxXlibSurface(Display *dpy, XRenderPictFormat *format, const gf format, mSize.width, mSize.height); Init(surf); TakePixmap(); + + LogSurfaceCreation (); + HookSurfaceDestructionForLogging(); } gfxXlibSurface::gfxXlibSurface(cairo_surface_t *csurf) @@ -124,6 +152,9 @@ gfxXlibSurface::gfxXlibSurface(cairo_surface_t *csurf) mDisplay = cairo_xlib_surface_get_display(csurf); Init(csurf, PR_TRUE); + + LogSurfaceCreation (); + HookSurfaceDestructionForLogging(); } gfxXlibSurface::~gfxXlibSurface() @@ -198,3 +229,59 @@ pixmap_free_func (void *data) delete pfs; } + +void +gfxXlibSurface::LogSurfaceCreation () +{ + gfxIntSize size; + + size = GetSize (); + + pixels_allocated += (PRInt64) size.width * size.height; + + PR_LOG (gXlibSurfaceAccountingLog, PR_LOG_DEBUG, + ("XlibSurfaceAccounting: Xlib surface %p created, %ux%u pixels - %lld global pixels allocated", + CairoSurface (), + size.width, + size.height, + pixels_allocated)); +} + +struct SurfaceFreeData { + gfxIntSize size; + cairo_surface_t *surface; +}; + +static void +surface_destroy_func (void *closure) +{ + SurfaceFreeData *data; + + data = (SurfaceFreeData *) closure; + + pixels_allocated -= (PRInt64) data->size.width * data->size.height; + + PR_LOG (gXlibSurfaceAccountingLog, PR_LOG_DEBUG, + ("XlibSurfaceAccounting: Destroying Xlib surface %p, %dx%d pixels - %lld global pixels allocated", + data->surface, + data->size.width, + data->size.height, + pixels_allocated)); + + delete data; +} + +void +gfxXlibSurface::HookSurfaceDestructionForLogging () +{ + SurfaceFreeData *data; + + data = new SurfaceFreeData; + data->size = GetSize (); + data->surface = CairoSurface (); + + cairo_surface_set_user_data (data->surface, + &surface_free_key, + data, + surface_destroy_func); +} diff --git a/modules/libpr0n/decoders/jpeg/nsJPEGDecoder.cpp b/modules/libpr0n/decoders/jpeg/nsJPEGDecoder.cpp index 16b9fd8..daaff26 100644 --- a/modules/libpr0n/decoders/jpeg/nsJPEGDecoder.cpp +++ b/modules/libpr0n/decoders/jpeg/nsJPEGDecoder.cpp @@ -22,6 +22,7 @@ * * Contributor(s): * Stuart Parmenter + * Federico Mena-Quintero * * Alternatively, the contents of this file may be used under the terms of * either the GNU General Public License Version 2 or later (the "GPL"), or @@ -63,8 +64,10 @@ NS_IMPL_ISUPPORTS1(nsJPEGDecoder, imgIDecoder) #if defined(PR_LOGGING) PRLogModuleInfo *gJPEGlog = PR_NewLogModule("JPEGDecoder"); +static PRLogModuleInfo *gJPEGDecoderAccountingLog = PR_NewLogModule ("JPEGDecoderAccounting"); #else #define gJPEGlog +#define gJPEGDecoderAccountingLog #endif @@ -410,6 +413,10 @@ NS_IMETHODIMP nsJPEGDecoder::WriteFrom(nsIInputStream *inStr, PRUint32 count, PR format = gfxIFormats::BGR; #endif + PR_LOG (gJPEGDecoderAccountingLog, PR_LOG_DEBUG, + ("JPEGDecoderAccounting: nsJPEGDecoder::WriteFrom -- creating image frame with %ux%u pixels", + mInfo.image_width, mInfo.image_height, (long) mInfo.image_width * mInfo.image_height * 3)); + if (NS_FAILED(mFrame->Init(0, 0, mInfo.image_width, mInfo.image_height, format, 24))) { mState = JPEG_ERROR; return NS_ERROR_OUT_OF_MEMORY; diff --git a/modules/libpr0n/src/imgRequest.cpp b/modules/libpr0n/src/imgRequest.cpp index 74ea235..f36db4a 100644 --- a/modules/libpr0n/src/imgRequest.cpp +++ b/modules/libpr0n/src/imgRequest.cpp @@ -22,6 +22,7 @@ * * Contributor(s): * Stuart Parmenter + * Federico Mena-Quintero * * Alternatively, the contents of this file may be used under the terms of * either the GNU General Public License Version 2 or later (the "GPL"), or @@ -70,6 +71,7 @@ PRLogModuleInfo *gImgLog = PR_NewLogModule("imgRequest"); #endif + NS_IMPL_ISUPPORTS6(imgRequest, imgILoad, imgIDecoderObserver, imgIContainerObserver, nsIStreamListener, nsIRequestObserver,