re-landing; b=412396, speed up mac image rendering while images are being loaded, r=stuart

This commit is contained in:
vladimir@pobox.com 2008-01-28 11:05:44 -08:00
Родитель 0aaafe014a
Коммит 61b709983c
10 изменённых файлов: 97 добавлений и 8 удалений

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

@ -28,3 +28,5 @@ nonfatal-assertions.patch: Make assertions non-fatal
endian.patch: include cairo-platform.h for endian macros
fixed-24-8.patch: Switch fixed point mode from 16.16 to 24.8
quartz-get-image-surface.patch: Add cairo_quartz_get_image_surface API analogous to the win32 one

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

@ -48,6 +48,8 @@ typedef struct cairo_quartz_surface {
void *imageData;
cairo_surface_t *imageSurfaceEquiv;
CGContextRef cgContext;
CGAffineTransform cgContextBaseCTM;

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

@ -937,6 +937,11 @@ _cairo_quartz_get_image (cairo_quartz_surface_t *surface,
return CAIRO_STATUS_SUCCESS;
}
if (surface->imageSurfaceEquiv) {
*image_out = (cairo_image_surface_t*) cairo_surface_reference(surface->imageSurfaceEquiv);
return CAIRO_STATUS_SUCCESS;
}
if (CGBitmapContextGetBitsPerPixel(surface->cgContext) != 0) {
unsigned int stride;
unsigned int bitinfo;
@ -945,6 +950,7 @@ _cairo_quartz_get_image (cairo_quartz_surface_t *surface,
unsigned int color_comps;
imageData = (unsigned char *) CGBitmapContextGetData(surface->cgContext);
#ifdef USE_10_3_WORKAROUNDS
bitinfo = CGBitmapContextGetAlphaInfo (surface->cgContext);
#else
@ -1029,6 +1035,11 @@ _cairo_quartz_surface_finish (void *abstract_surface)
surface->cgContext = NULL;
if (surface->imageSurfaceEquiv) {
cairo_surface_destroy (surface->imageSurfaceEquiv);
surface->imageSurfaceEquiv = NULL;
}
if (surface->imageData) {
free (surface->imageData);
surface->imageData = NULL;
@ -1871,6 +1882,7 @@ _cairo_quartz_surface_create_internal (CGContextRef cgContext,
surface->cgContextBaseCTM = CGContextGetCTM (cgContext);
surface->imageData = NULL;
surface->imageSurfaceEquiv = NULL;
return surface;
}
@ -2025,6 +2037,7 @@ cairo_quartz_surface_create (cairo_format_t format,
}
surf->imageData = imageData;
surf->imageSurfaceEquiv = cairo_image_surface_create_for_data (imageData, format, width, height, stride);
return (cairo_surface_t *) surf;
}
@ -2152,3 +2165,14 @@ quartz_surface_to_png (cairo_quartz_surface_t *nq, char *dest)
#endif
}
cairo_surface_t *
cairo_quartz_surface_get_image (cairo_surface_t *surface)
{
cairo_quartz_surface_t *quartz = (cairo_quartz_surface_t*)surface;
if (cairo_surface_get_type(surface) != CAIRO_SURFACE_TYPE_QUARTZ)
return NULL;
return quartz->imageSurfaceEquiv;
}

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

@ -57,6 +57,9 @@ cairo_quartz_surface_create_for_cg_context (CGContextRef cgContext,
cairo_public CGContextRef
cairo_quartz_surface_get_cg_context (cairo_surface_t *surface);
cairo_public cairo_surface_t *
cairo_quartz_surface_get_image (cairo_surface_t *surface);
CAIRO_END_DECLS
#else /* CAIRO_HAS_QUARTZ_SURFACE */

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

@ -169,6 +169,7 @@
#define cairo_quartz_surface_create _moz_cairo_quartz_surface_create
#define cairo_quartz_surface_create_for_cg_context _moz_cairo_quartz_surface_create_for_cg_context
#define cairo_quartz_surface_get_cg_context _moz_cairo_quartz_surface_get_cg_context
#define cairo_quartz_surface_get_image _moz_cairo_quartz_surface_get_image
#define cairo_rectangle _moz_cairo_rectangle
#define cairo_rectangle_list_destroy _moz_cairo_rectangle_list_destroy
#define cairo_reference _moz_cairo_reference

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

@ -111,7 +111,7 @@ nsThebesImage::Init(PRInt32 aWidth, PRInt32 aHeight, PRInt32 aDepth, nsMaskRequi
mFormat = format;
#ifdef XP_WIN
#if defined(XP_WIN)
if (!ShouldUseImageSurfaces()) {
mWinSurface = new gfxWindowsSurface(gfxIntSize(mWidth, mHeight), format);
if (mWinSurface && mWinSurface->CairoStatus() == 0) {
@ -120,14 +120,23 @@ nsThebesImage::Init(PRInt32 aWidth, PRInt32 aHeight, PRInt32 aDepth, nsMaskRequi
}
}
if (!mImageSurface) {
if (!mImageSurface)
mWinSurface = nsnull;
mImageSurface = new gfxImageSurface(gfxIntSize(mWidth, mHeight), format);
#elif defined(XP_MACOSX)
if (!ShouldUseImageSurfaces()) {
mQuartzSurface = new gfxQuartzSurface(gfxSize(mWidth, mHeight), format);
if (mQuartzSurface && mQuartzSurface->CairoStatus() == 0) {
mImageSurface = mQuartzSurface->GetImageSurface();
}
}
#else
mImageSurface = new gfxImageSurface(gfxIntSize(mWidth, mHeight), format);
if (!mImageSurface)
mQuartzSurface = nsnull;
#endif
if (!mImageSurface)
mImageSurface = new gfxImageSurface(gfxIntSize(mWidth, mHeight), format);
if (!mImageSurface || mImageSurface->CairoStatus()) {
mImageSurface = nsnull;
// guess
@ -298,6 +307,11 @@ nsThebesImage::Optimize(nsIDeviceContext* aContext)
}
#endif
#ifdef XP_MACOSX
if (mQuartzSurface && !mFormatChanged)
mOptSurface = mQuartzSurface;
#endif
if (mOptSurface == nsnull)
mOptSurface = gfxPlatform::GetPlatform()->OptimizeImage(mImageSurface, mFormat);
@ -305,6 +319,9 @@ nsThebesImage::Optimize(nsIDeviceContext* aContext)
mImageSurface = nsnull;
#ifdef XP_WIN
mWinSurface = nsnull;
#endif
#ifdef XP_MACOSX
mQuartzSurface = nsnull;
#endif
}

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

@ -44,8 +44,10 @@
#include "gfxColor.h"
#include "gfxASurface.h"
#include "gfxImageSurface.h"
#ifdef XP_WIN
#if defined(XP_WIN)
#include "gfxWindowsSurface.h"
#elif defined(XP_MACOSX)
#include "gfxQuartzSurface.h"
#endif
class nsThebesImage : public nsIImage
@ -97,7 +99,13 @@ public:
gfxASurface* ThebesSurface() {
if (mOptSurface)
return mOptSurface;
#if defined(XP_WIN)
if (mWinSurface)
return mWinSurface;
#elif defined(XP_MACOSX)
if (mQuartzSurface)
return mQuartzSurface;
#endif
return mImageSurface;
}
@ -151,8 +159,10 @@ protected:
nsRefPtr<gfxImageSurface> mImageSurface;
nsRefPtr<gfxASurface> mOptSurface;
#ifdef XP_WIN
#if defined(XP_WIN)
nsRefPtr<gfxWindowsSurface> mWinSurface;
#elif defined(XP_MACOSX)
nsRefPtr<gfxQuartzSurface> mQuartzSurface;
#endif
PRUint8 mAlphaDepth;

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

@ -40,6 +40,7 @@
#define GFX_QUARTZSURFACE_H
#include "gfxASurface.h"
#include "gfxImageSurface.h"
#include <Carbon/Carbon.h>
@ -57,6 +58,8 @@ public:
virtual PRInt32 GetDefaultContextFlags() const;
already_AddRefed<gfxImageSurface> GetImageSurface();
protected:
CGContextRef mCGContext;
gfxSize mSize;

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

@ -94,3 +94,23 @@ gfxQuartzSurface::~gfxQuartzSurface()
{
CGContextRelease(mCGContext);
}
already_AddRefed<gfxImageSurface>
gfxQuartzSurface::GetImageSurface()
{
if (!mSurfaceValid) {
NS_WARNING ("GetImageSurface on an invalid (null) surface; who's calling this without checking for surface errors?");
return nsnull;
}
NS_ASSERTION(CairoSurface() != nsnull, "CairoSurface() shouldn't be nsnull when mSurfaceValid is TRUE!");
cairo_surface_t *isurf = cairo_quartz_surface_get_image(CairoSurface());
if (!isurf)
return nsnull;
nsRefPtr<gfxASurface> asurf = gfxASurface::Wrap(isurf);
gfxImageSurface *imgsurf = (gfxImageSurface*) asurf.get();
NS_ADDREF(imgsurf);
return imgsurf;
}

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

@ -125,6 +125,13 @@ gfxWindowsSurface::~gfxWindowsSurface()
already_AddRefed<gfxImageSurface>
gfxWindowsSurface::GetImageSurface()
{
if (!mSurfaceValid) {
NS_WARNING ("GetImageSurface on an invalid (null) surface; who's calling this without checking for surface errors?");
return nsnull;
}
NS_ASSERTION(CairoSurface() != nsnull, "CairoSurface() shouldn't be nsnull when mSurfaceValid is TRUE!");
if (mForPrinting)
return nsnull;