[cairo-commit] roadster/src map.c, 1.20, 1.21 map_draw_cairo.c, 1.8, 1.9 scenemanager.c, 1.8, 1.9

Ian McIntosh commit at pdx.freedesktop.org
Thu Mar 10 03:01:07 PST 2005


Committed by: ian

Update of /cvs/cairo/roadster/src
In directory gabe:/tmp/cvs-serv1551/src

Modified Files:
	map.c map_draw_cairo.c scenemanager.c 
Log Message:
	* src/map.c: MySQL optimization regarding GeomFromText() which saves about 10% total application CPU time. (Not as big of a deal as it sounds since we're currently disk-bound.)
	* src/map_draw_cairo.c: Re-add check for font size == 0 and don't draw labels for that layer if it is (this is how styles say "no labels").
	* src/scenemanager.c: Minor cleanup.


Index: map.c
===================================================================
RCS file: /cvs/cairo/roadster/src/map.c,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -d -r1.20 -r1.21
--- map.c	10 Mar 2005 06:12:03 -0000	1.20
+++ map.c	10 Mar 2005 11:01:05 -0000	1.21
@@ -476,21 +476,30 @@
 //                 return TRUE;
 //         }
 
+	// MySQL doesn't optimize away GeomFromText(...) and instead executes this ONCE PER ROW.
+	// That's a whole lot of parsing and was causing my_strtod to eat up 9% of Roadster's CPU time.
+	// Assinging it to a temp variable alleviates that problem.
+
+	gchar* pszSQL;
+	pszSQL = g_strdup_printf("SET @wkb=GeomFromText('Polygon((%f %f,%f %f,%f %f,%f %f,%f %f))')",
+		pRect->m_A.m_fLatitude, pRect->m_A.m_fLongitude, 	// upper left
+		pRect->m_A.m_fLatitude, pRect->m_B.m_fLongitude, 	// upper right
+		pRect->m_B.m_fLatitude, pRect->m_B.m_fLongitude, 	// bottom right
+		pRect->m_B.m_fLatitude, pRect->m_A.m_fLongitude, 	// bottom left
+		pRect->m_A.m_fLatitude, pRect->m_A.m_fLongitude		// upper left again
+		);
+	db_query(pszSQL, NULL);
+	g_free(pszSQL);
+
 	// generate SQL
-	gchar* pszSQL = g_strdup_printf(
+	pszSQL = g_strdup_printf(
 		"SELECT Road.ID, Road.TypeID, AsBinary(Road.Coordinates), RoadName.Name, RoadName.SuffixID"
 		" FROM Road "
-	//      " LEFT JOIN Road_RoadName ON (Road.ID=Road_RoadName.RoadID)"
 		" LEFT JOIN RoadName ON (Road.RoadNameID=RoadName.ID)"
 		" WHERE"
 //		" TypeID IN (%s) AND"
-		" MBRIntersects(GeomFromText('Polygon((%f %f,%f %f,%f %f,%f %f,%f %f))'), Coordinates)",
+		" MBRIntersects(@wkb, Coordinates)"
 //		azLayerNumberList,
-		pRect->m_A.m_fLatitude, pRect->m_A.m_fLongitude, 	// upper left
-		pRect->m_A.m_fLatitude, pRect->m_B.m_fLongitude, 	// upper right
-		pRect->m_B.m_fLatitude, pRect->m_B.m_fLongitude, 	// bottom right
-		pRect->m_B.m_fLatitude, pRect->m_A.m_fLongitude, 	// bottom left
-		pRect->m_A.m_fLatitude, pRect->m_A.m_fLongitude		// upper left again
 		);
 	//g_print("sql: %s\n", pszSQL);
 

Index: map_draw_cairo.c
===================================================================
RCS file: /cvs/cairo/roadster/src/map_draw_cairo.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- map_draw_cairo.c	10 Mar 2005 06:12:03 -0000	1.8
+++ map_draw_cairo.c	10 Mar 2005 11:01:05 -0000	1.9
@@ -277,7 +277,7 @@
 		}
 		cairo_show_text(pCairo, pszLabel);
 		cairo_restore(pCairo);
-		
+
 		// claim the space this took up and the label (so it won't be drawn twice)
 		scenemanager_claim_label(pMap->m_pSceneManager, pszLabel);
 		scenemanager_claim_polygon(pMap->m_pSceneManager, aBoundingPolygon, 4);
@@ -950,6 +950,9 @@
 	gdouble fLineWidth = pSubLayerStyle->m_afLineWidths[pRenderMetrics->m_nZoomLevel-1];
 	if(fLineWidth == 0) return;
 
+	gdouble fFontSize = pLabelStyle->m_afFontSizeAtZoomLevel[pRenderMetrics->m_nZoomLevel-1];
+	if(fFontSize == 0) return;
+
 	gchar* pszFontFamily = ROAD_FONT;
 
 	// set font for whole layer
@@ -957,7 +960,7 @@
 	cairo_select_font(pCairo, pszFontFamily, CAIRO_FONT_SLANT_NORMAL,
 		  pLabelStyle->m_abBoldAtZoomLevel[pRenderMetrics->m_nZoomLevel-1] ?
 		  CAIRO_FONT_WEIGHT_BOLD : CAIRO_FONT_WEIGHT_NORMAL);
-	cairo_scale_font(pCairo, pLabelStyle->m_afFontSizeAtZoomLevel[pRenderMetrics->m_nZoomLevel-1]);
+	cairo_scale_font(pCairo, fFontSize);
 
 	for(i=0 ; i<pPointStringsArray->len ; i++) {
 		RENDERING_THREAD_YIELD;

Index: scenemanager.c
===================================================================
RCS file: /cvs/cairo/roadster/src/scenemanager.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- scenemanager.c	10 Mar 2005 06:12:03 -0000	1.8
+++ scenemanager.c	10 Mar 2005 11:01:05 -0000	1.9
@@ -26,15 +26,10 @@
 
 /*
 Goals:
- - Keep labels from overlapping
- - Prevent the same text from showing up too often, and choose among the options wisely
+ - Keep text labels and other screen objects from overlapping
+ - Prevent the same text from showing up too often (currently not more than once)
 */
 
-// typedef struct roadlabel {
-//     geometryset_t* m_pGeometry;
-//     gchar* m_pszLabel;
-// } roadlabel_t;
-
 void scenemanager_init(void)
 {
 }
@@ -48,7 +43,7 @@
 	*ppReturn = pNew;
 }
 
-gboolean scenemanager_can_draw_label_at(scenemanager_t* pSceneManager, const gchar* pszLabel, GdkPoint* pScreenLocation)
+gboolean scenemanager_can_draw_label_at(scenemanager_t* pSceneManager, const gchar* pszLabel, GdkPoint* __unused_pScreenLocation)
 {
 	g_assert(pSceneManager != NULL);
 	g_assert(pszLabel != NULL);




More information about the cairo-commit mailing list