From e90411c2c1a2808a7f76667ca683c1e21d11ea09 Mon Sep 17 00:00:00 2001 From: Julian Smart Date: Thu, 19 Jan 2006 10:33:33 +0000 Subject: [PATCH] Applied patch [ 1331340 ] faster Drawing of Polygons and Polylines Chris Borgolte git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@36998 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/gtk/dcclient.cpp | 56 +++++++++++++++++++++++++++++++++++++++++-- src/gtk1/dcclient.cpp | 56 +++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 108 insertions(+), 4 deletions(-) diff --git a/src/gtk/dcclient.cpp b/src/gtk/dcclient.cpp index 5dabb7b244..d97e4ae8de 100644 --- a/src/gtk/dcclient.cpp +++ b/src/gtk/dcclient.cpp @@ -687,7 +687,19 @@ void wxWindowDC::DoDrawLines( int n, wxPoint points[], wxCoord xoffset, wxCoord if (m_pen.GetStyle() == wxTRANSPARENT) return; if (n <= 0) return; - GdkPoint *gpts = new GdkPoint[n]; + //Check, if scaling is necessary + bool doScale(true); + long val(10); + if (!xoffset) + if (!yoffset) + if (XLOG2DEV(val)==val) + if (YLOG2DEV(val)==val) + doScale = false; + + GdkPoint *gpts = NULL; + + if (doScale){ + gpts = new GdkPoint[n]; if (! gpts) { wxFAIL_MSG( wxT("Cannot allocate PolyLine") ); @@ -704,10 +716,20 @@ void wxWindowDC::DoDrawLines( int n, wxPoint points[], wxCoord xoffset, wxCoord gpts[i].x = x1; gpts[i].y = y1; } + } + else { + for (int i = 0; i < n; i++) { + CalcBoundingBox( points[i].x, points[i].y ); + } + + //GdkPoint and wxPoint have the same memory allignment, so we can cast one into another + gpts = reinterpret_cast(points); + } if (m_window) gdk_draw_lines( m_window, m_penGC, gpts, n); + if (doScale) delete[] gpts; } @@ -717,7 +739,21 @@ void wxWindowDC::DoDrawPolygon( int n, wxPoint points[], wxCoord xoffset, wxCoor if (n <= 0) return; - GdkPoint *gdkpoints = new GdkPoint[n+1]; + //Check, if scaling is necessary + bool doScale(true); + long val(10); + if (!xoffset) + if (!yoffset) + if (XLOG2DEV(val)==val) + if (YLOG2DEV(val)==val){ + doScale = false; + } + + GdkPoint *gdkpoints = NULL; + + if (doScale){ + gdkpoints = new GdkPoint[n+1]; //FIXME: Why the "+1" + int i; for (i = 0 ; i < n ; i++) { @@ -726,9 +762,24 @@ void wxWindowDC::DoDrawPolygon( int n, wxPoint points[], wxCoord xoffset, wxCoor CalcBoundingBox( points[i].x + xoffset, points[i].y + yoffset ); } + } + else { + int i(0); + for (; i < n ; ++i) { + CalcBoundingBox( points[i].x, points[i].y ); + } + //GdkPoint and wxPoint have the same memory allignment, so we can cast one into another + gdkpoints = reinterpret_cast (points); + } if (m_window) { + //I think wxSOLID is the most often used style (it is for me), + //so I put it in front of the if ... ifelse's + if (m_brush.GetStyle() == wxSOLID) + { + gdk_draw_polygon( m_window, m_brushGC, TRUE, gdkpoints, n ); + }else if (m_brush.GetStyle() != wxTRANSPARENT) { if ((m_brush.GetStyle() == wxSTIPPLE_MASK_OPAQUE) && (m_brush.GetStipple()->GetMask())) @@ -782,6 +833,7 @@ void wxWindowDC::DoDrawPolygon( int n, wxPoint points[], wxCoord xoffset, wxCoor } } + if (doScale) delete[] gdkpoints; } diff --git a/src/gtk1/dcclient.cpp b/src/gtk1/dcclient.cpp index 5dabb7b244..d97e4ae8de 100644 --- a/src/gtk1/dcclient.cpp +++ b/src/gtk1/dcclient.cpp @@ -687,7 +687,19 @@ void wxWindowDC::DoDrawLines( int n, wxPoint points[], wxCoord xoffset, wxCoord if (m_pen.GetStyle() == wxTRANSPARENT) return; if (n <= 0) return; - GdkPoint *gpts = new GdkPoint[n]; + //Check, if scaling is necessary + bool doScale(true); + long val(10); + if (!xoffset) + if (!yoffset) + if (XLOG2DEV(val)==val) + if (YLOG2DEV(val)==val) + doScale = false; + + GdkPoint *gpts = NULL; + + if (doScale){ + gpts = new GdkPoint[n]; if (! gpts) { wxFAIL_MSG( wxT("Cannot allocate PolyLine") ); @@ -704,10 +716,20 @@ void wxWindowDC::DoDrawLines( int n, wxPoint points[], wxCoord xoffset, wxCoord gpts[i].x = x1; gpts[i].y = y1; } + } + else { + for (int i = 0; i < n; i++) { + CalcBoundingBox( points[i].x, points[i].y ); + } + + //GdkPoint and wxPoint have the same memory allignment, so we can cast one into another + gpts = reinterpret_cast(points); + } if (m_window) gdk_draw_lines( m_window, m_penGC, gpts, n); + if (doScale) delete[] gpts; } @@ -717,7 +739,21 @@ void wxWindowDC::DoDrawPolygon( int n, wxPoint points[], wxCoord xoffset, wxCoor if (n <= 0) return; - GdkPoint *gdkpoints = new GdkPoint[n+1]; + //Check, if scaling is necessary + bool doScale(true); + long val(10); + if (!xoffset) + if (!yoffset) + if (XLOG2DEV(val)==val) + if (YLOG2DEV(val)==val){ + doScale = false; + } + + GdkPoint *gdkpoints = NULL; + + if (doScale){ + gdkpoints = new GdkPoint[n+1]; //FIXME: Why the "+1" + int i; for (i = 0 ; i < n ; i++) { @@ -726,9 +762,24 @@ void wxWindowDC::DoDrawPolygon( int n, wxPoint points[], wxCoord xoffset, wxCoor CalcBoundingBox( points[i].x + xoffset, points[i].y + yoffset ); } + } + else { + int i(0); + for (; i < n ; ++i) { + CalcBoundingBox( points[i].x, points[i].y ); + } + //GdkPoint and wxPoint have the same memory allignment, so we can cast one into another + gdkpoints = reinterpret_cast (points); + } if (m_window) { + //I think wxSOLID is the most often used style (it is for me), + //so I put it in front of the if ... ifelse's + if (m_brush.GetStyle() == wxSOLID) + { + gdk_draw_polygon( m_window, m_brushGC, TRUE, gdkpoints, n ); + }else if (m_brush.GetStyle() != wxTRANSPARENT) { if ((m_brush.GetStyle() == wxSTIPPLE_MASK_OPAQUE) && (m_brush.GetStipple()->GetMask())) @@ -782,6 +833,7 @@ void wxWindowDC::DoDrawPolygon( int n, wxPoint points[], wxCoord xoffset, wxCoor } } + if (doScale) delete[] gdkpoints; } -- 2.45.2