Index: src/af/gr/unix/gr_UnixGraphics.cpp =================================================================== RCS file: /cvsroot/abi/src/af/gr/unix/gr_UnixGraphics.cpp,v retrieving revision 1.144 diff -u -r1.144 gr_UnixGraphics.cpp --- src/af/gr/unix/gr_UnixGraphics.cpp 3 Aug 2002 17:31:06 -0000 1.144 +++ src/af/gr/unix/gr_UnixGraphics.cpp 5 Aug 2002 05:31:35 -0000 @@ -43,6 +43,8 @@ #include #endif +UT_Mutex * GR_UnixGraphics::m_grLock = NULL; + const char* GR_Graphics::findNearestFont(const char* pszFontFamily, const char* pszFontStyle, const char* pszFontVariant, @@ -92,6 +94,10 @@ : m_bLayoutUnits(false) #endif { + // Must wait for thread system to be initialized. + m_grLock = new UT_Mutex(); + UT_MutexAcquirer grLockAcq(*m_grLock); + m_pApp = app; m_pWin = win; #ifndef WITH_PANGO @@ -238,6 +244,8 @@ GR_Graphics::CapStyle inCapStyle, GR_Graphics::LineStyle inLineStyle ) { + UT_MutexAcquirer grLockAcq(*m_grLock); + gdk_gc_set_line_attributes ( m_pGC, (gint)inWidthPixels, mapLineStyle ( inLineStyle ), mapCapStyle ( inCapStyle ), @@ -275,6 +283,8 @@ #ifndef WITH_PANGO void GR_UnixGraphics::drawGlyph(UT_uint32 Char, UT_sint32 xoff, UT_sint32 yoff) { + UT_MutexAcquirer grLockAcq(*m_grLock); + #ifdef USE_XFT XftDrawGlyphs(m_pXftDraw, &m_XftColor, m_pXftFont, xoff, yoff + m_pXftFont->ascent, &Char, 1); #else @@ -316,6 +326,8 @@ int iLength, UT_sint32 xoff, UT_sint32 yoff, int * pCharWidths) { + UT_MutexAcquirer grLockAcq(*m_grLock); + #ifdef USE_XFT XftDrawString32(m_pXftDraw, &m_XftColor, m_pXftFont, xoff, yoff + m_pXftFont->ascent, const_cast (pChars + iCharOffset), iLength); @@ -550,6 +562,8 @@ UT_uint32 GR_UnixGraphics::measureUnRemappedChar(const UT_UCSChar c) { + UT_MutexAcquirer grLockAcq(*m_grLock); + // measureString() could be defined in terms of measureUnRemappedChar() // but its not (for presumed performance reasons). Also, a difference // is that measureString() uses remapping to get past zero-width @@ -658,6 +672,8 @@ UT_uint32 GR_UnixGraphics::measureString(const UT_UCSChar* s, int iOffset, int num, unsigned short* pWidths) { + UT_MutexAcquirer grLockAcq(*m_grLock); + // on X11, we do not use the aCharWidths[] or the GR_CharWidths // cacheing mechanism -- because, XTextExtents16() provides a // local copy (in the client library) of all that information @@ -725,6 +741,8 @@ void GR_UnixGraphics::_setColor(GdkColor & c) { + UT_MutexAcquirer grLockAcq(*m_grLock); + gint ret = gdk_color_alloc(m_pColormap, &c); UT_ASSERT(ret == TRUE); @@ -959,7 +977,6 @@ UT_uint32 GR_UnixGraphics::getFontAscent() { - return getFontAscent(m_pFont); } @@ -1010,12 +1027,16 @@ void GR_UnixGraphics::drawLine(UT_sint32 x1, UT_sint32 y1, UT_sint32 x2, UT_sint32 y2) { + UT_MutexAcquirer grLockAcq(*m_grLock); + // TODO set the line width according to m_iLineWidth gdk_draw_line(m_pWin, m_pGC, x1, y1, x2, y2); } void GR_UnixGraphics::setLineWidth(UT_sint32 iLineWidth) { + UT_MutexAcquirer grLockAcq(*m_grLock); + m_iLineWidth = iLineWidth; // Get the current values of the line attributes @@ -1035,11 +1056,15 @@ void GR_UnixGraphics::xorLine(UT_sint32 x1, UT_sint32 y1, UT_sint32 x2, UT_sint32 y2) { + UT_MutexAcquirer grLockAcq(*m_grLock); + gdk_draw_line(m_pWin, m_pXORGC, x1, y1, x2, y2); } void GR_UnixGraphics::polyLine(UT_Point * pts, UT_uint32 nPoints) { + UT_MutexAcquirer grLockAcq(*m_grLock); + // see bug #303 for what this is about #if 1 GdkPoint * points = (GdkPoint *)calloc(nPoints, sizeof(GdkPoint)); @@ -1069,6 +1094,7 @@ void GR_UnixGraphics::invertRect(const UT_Rect* pRect) { UT_ASSERT(pRect); + UT_MutexAcquirer grLockAcq(*m_grLock); gdk_draw_rectangle(m_pWin, m_pXORGC, 1, pRect->left, pRect->top, pRect->width, pRect->height); @@ -1076,6 +1102,8 @@ void GR_UnixGraphics::setClipRect(const UT_Rect* pRect) { + UT_MutexAcquirer grLockAcq(*m_grLock); + // if(pRect != NULL) // UT_ASSERT(m_pRect==NULL); m_pRect = pRect; @@ -1130,6 +1158,8 @@ void GR_UnixGraphics::fillRect(const UT_RGBColor& c, UT_sint32 x, UT_sint32 y, UT_sint32 w, UT_sint32 h) { + UT_MutexAcquirer grLockAcq(*m_grLock); + // save away the current color, and restore it after we fill the rect GdkGCValues gcValues; GdkColor oColor; @@ -1158,6 +1188,8 @@ void GR_UnixGraphics::scroll(UT_sint32 dx, UT_sint32 dy) { + UT_MutexAcquirer grLockAcq(*m_grLock); + UT_sint32 winWidth, winHeight; gdk_drawable_get_size ( GDK_DRAWABLE(m_pWin), &winWidth, &winHeight ) ; UT_Rect exposeArea; @@ -1257,6 +1289,8 @@ UT_sint32 x_src, UT_sint32 y_src, UT_sint32 width, UT_sint32 height) { + UT_MutexAcquirer grLockAcq(*m_grLock); + gdk_window_copy_area(m_pWin, m_pGC, x_dest, y_dest, m_pWin, x_src, y_src, width, height); } @@ -1264,6 +1298,8 @@ void GR_UnixGraphics::clearArea(UT_sint32 x, UT_sint32 y, UT_sint32 width, UT_sint32 height) { + UT_MutexAcquirer grLockAcq(*m_grLock); + // UT_DEBUGMSG(("ClearArea: %d %d %d %d\n", x, y, width, height)); if (width > 0) { @@ -1314,7 +1350,6 @@ { GR_Image* pImg = NULL; - pImg = new GR_UnixImage(pszName,false); pImg->convertFromBuffer(pBB, iDisplayWidth, iDisplayHeight); return pImg; @@ -1328,6 +1363,8 @@ void GR_UnixGraphics::drawImage(GR_Image* pImg, UT_sint32 xDest, UT_sint32 yDest) { + UT_MutexAcquirer grLockAcq(*m_grLock); + UT_ASSERT(pImg); GR_UnixImage * pUnixImage = static_cast(pImg); @@ -1358,6 +1395,8 @@ void GR_UnixGraphics::flush(void) { + UT_MutexAcquirer grLockAcq(*m_grLock); + gdk_flush(); } @@ -1375,6 +1414,8 @@ void GR_UnixGraphics::setCursor(GR_Graphics::Cursor c) { + UT_MutexAcquirer grLockAcq(*m_grLock); + if (m_cursor == c) return; @@ -1495,6 +1536,8 @@ void GR_UnixGraphics::fillRect(GR_Color3D c, UT_sint32 x, UT_sint32 y, UT_sint32 w, UT_sint32 h) { + UT_MutexAcquirer grLockAcq(*m_grLock); + UT_ASSERT(c < COUNT_3D_COLORS); gdk_gc_set_foreground(m_pGC, &m_3dColors[c]); gdk_draw_rectangle(m_pWin, m_pGC, 1, x, y, w, h); @@ -1508,6 +1551,8 @@ void GR_UnixGraphics::polygon(UT_RGBColor& c,UT_Point *pts,UT_uint32 nPoints) { + UT_MutexAcquirer grLockAcq(*m_grLock); + // save away the current color, and restore it after we draw the polygon GdkGCValues gcValues; GdkColor oColor; Index: src/af/gr/unix/gr_UnixGraphics.h =================================================================== RCS file: /cvsroot/abi/src/af/gr/unix/gr_UnixGraphics.h,v retrieving revision 1.44 diff -u -r1.44 gr_UnixGraphics.h --- src/af/gr/unix/gr_UnixGraphics.h 3 Aug 2002 17:31:06 -0000 1.44 +++ src/af/gr/unix/gr_UnixGraphics.h 5 Aug 2002 05:31:35 -0000 @@ -26,6 +26,7 @@ #include "xap_UnixFont.h" #include "xap_Frame.h" #include "gr_Graphics.h" +#include "ut_mutex.h" #ifdef USE_XFT #include @@ -180,6 +181,8 @@ // hack bool m_bLayoutUnits; #endif + // must hold this lock before doing graphical operations. + static UT_Mutex * m_grLock; }; #endif /* GR_UNIXGRAPHICS_H */