Bug 557159 - [OS/2] Optimize Cairo/Thebes surfaces. Surface Part 2 - MozCairo and Thebes. r= Peter Weilbacher, a=NPOTB

This commit is contained in:
Rich Walsh 2010-08-21 12:50:32 -07:00
parent b78cd74449
commit 420a678bbd
3 changed files with 35 additions and 18 deletions

View File

@ -114,11 +114,14 @@
#define cairo_os2_fini _moz_cairo_os2_fini
#define cairo_os2_init _moz_cairo_os2_init
#define cairo_os2_surface_create _moz_cairo_os2_surface_create
#define cairo_os2_surface_create_for_window _moz_cairo_os2_surface_create_for_window
#define cairo_os2_surface_get_manual_window_refresh _moz_cairo_os2_surface_get_manual_window_refresh
#define cairo_os2_surface_refresh_window _moz_cairo_os2_surface_refresh_window
#define cairo_os2_surface_set_hwnd _moz_cairo_os2_surface_set_hwnd
#define cairo_os2_surface_set_manual_window_refresh _moz_cairo_os2_surface_set_manual_window_refresh
#define cairo_os2_surface_set_size _moz_cairo_os2_surface_set_size
#define cairo_os2_surface_get_hps _moz_cairo_os2_surface_get_hps
#define cairo_os2_surface_set_hps _moz_cairo_os2_surface_set_hps
#define cairo_paint _moz_cairo_paint
#define cairo_paint_with_alpha _moz_cairo_paint_with_alpha
#define cairo_path_destroy _moz_cairo_path_destroy

View File

@ -45,7 +45,7 @@
gfxOS2Surface::gfxOS2Surface(const gfxIntSize& aSize,
gfxASurface::gfxImageFormat aImageFormat)
: mHasWnd(PR_FALSE), mSize(aSize)
: mWnd(0), mSize(aSize)
{
#ifdef DEBUG_thebes_2
printf("gfxOS2Surface[%#x]::gfxOS2Surface(Size=%dx%d, %d)\n", (unsigned int)this,
@ -97,40 +97,35 @@ gfxOS2Surface::gfxOS2Surface(const gfxIntSize& aSize,
}
gfxOS2Surface::gfxOS2Surface(HWND aWnd)
: mHasWnd(PR_TRUE), mDC(nsnull), mBitmap(nsnull)
: mWnd(aWnd), mDC(nsnull), mPS(nsnull), mBitmap(nsnull)
{
#ifdef DEBUG_thebes_2
printf("gfxOS2Surface[%#x]::gfxOS2Surface(HWND=%#x)\n", (unsigned int)this,
(unsigned int)aWnd);
#endif
mPS = WinGetPS(aWnd);
RECTL rectl;
WinQueryWindowRect(aWnd, &rectl);
mSize.width = rectl.xRight - rectl.xLeft;
mSize.height = rectl.yTop - rectl.yBottom;
if (mSize.width == 0) mSize.width = 1; // fake a minimal surface area to let
if (mSize.height == 0) mSize.height = 1; // cairo_os2_surface_create() return something
cairo_surface_t *surf = cairo_os2_surface_create(mPS, mSize.width, mSize.height);
// This variation on cairo_os2_surface_create() avoids creating a
// persistent HPS that may never be used. It also enables manual
// refresh so nsWindow::OnPaint() controls when the screen is updated.
cairo_surface_t *surf =
cairo_os2_surface_create_for_window(mWnd, mSize.width, mSize.height);
#ifdef DEBUG_thebes_2
printf(" type(%#x)=%d (ID=%#x, h/w=%d/%d)\n", (unsigned int)surf,
cairo_surface_get_type(surf), (unsigned int)mPS, mSize.width, mSize.height);
#endif
// Normally, OS/2 cairo surfaces have to be forced to redraw completely
// by calling cairo_surface_mark_dirty(surf), but Mozilla paints them in
// full, so that is not necessary here.
// record the window handle in the cairo surface, so that refresh works
cairo_os2_surface_set_hwnd(surf, aWnd);
// manual refresh is done from nsWindow::OnPaint
cairo_os2_surface_set_manual_window_refresh(surf, 1);
Init(surf);
}
gfxOS2Surface::gfxOS2Surface(HDC aDC, const gfxIntSize& aSize)
: mHasWnd(PR_FALSE), mDC(aDC), mBitmap(nsnull), mSize(aSize)
: mWnd(0), mDC(aDC), mBitmap(nsnull), mSize(aSize)
{
#ifdef DEBUG_thebes_2
printf("gfxOS2Surface[%#x]::gfxOS2Surface(HDC=%#x, Size=%dx%d)\n", (unsigned int)this,
@ -180,7 +175,7 @@ gfxOS2Surface::~gfxOS2Surface()
// release it again with WinReleasePS. Memory or printer surfaces on the
// other hand were created on device contexts with the GPI functions, so
// use those to clean up stuff.
if (mHasWnd) {
if (mWnd) {
if (mPS) {
WinReleasePS(mPS);
}
@ -206,7 +201,7 @@ void gfxOS2Surface::Refresh(RECTL *aRect, HPS aPS)
aRect->xLeft, aRect->xRight, aRect->yBottom, aRect->yTop,
(unsigned int)aPS, (unsigned int)mPS);
#endif
cairo_os2_surface_refresh_window(CairoSurface(), aPS, aRect);
cairo_os2_surface_refresh_window(CairoSurface(), (aPS ? aPS : mPS), aRect);
}
int gfxOS2Surface::Resize(const gfxIntSize& aSize)
@ -219,3 +214,22 @@ int gfxOS2Surface::Resize(const gfxIntSize& aSize)
// hardcode mutex timeout to 50ms for now
return cairo_os2_surface_set_size(CairoSurface(), mSize.width, mSize.height, 50);
}
HPS gfxOS2Surface::GetPS()
{
// Creating an HPS on-the-fly should never be needed because GetPS()
// is only called for printing surfaces & mPS should only be null for
// window surfaces. It would be a bug if Cairo had an HPS but Thebes
// didn't, but we'll check anyway to avoid leakage. As a last resort,
// if this is a window surface we'll create one & hang on to it.
if (!mPS) {
cairo_os2_surface_get_hps(CairoSurface(), &mPS);
if (!mPS && mWnd) {
mPS = WinGetPS(mWnd);
cairo_os2_surface_set_hps(CairoSurface(), mPS);
}
}
return mPS;
}

View File

@ -66,11 +66,11 @@ public:
// Reset the cairo surface to the given size.
int Resize(const gfxIntSize& aSize);
HPS GetPS() { return mPS; }
HPS GetPS();
gfxIntSize GetSize() { return mSize; }
private:
PRBool mHasWnd; // indicates if created through the HWND constructor
HWND mWnd; // non-null if created through the HWND constructor
HDC mDC; // memory device context
HPS mPS; // presentation space connected to window or memory device
HBITMAP mBitmap; // bitmap for initialization of memory surface