Index: Core.csproj =================================================================== --- Core.csproj (revision 26740) +++ Core.csproj (working copy) @@ -332,6 +332,8 @@ + + Index: guilib/FontObject.cs =================================================================== --- guilib/FontObject.cs (revision 0) +++ guilib/FontObject.cs (revision 0) @@ -0,0 +1,74 @@ +#region Copyright (C) 2005-2010 Team MediaPortal + +// Copyright (C) 2005-2010 Team MediaPortal +// http://www.team-mediaportal.com +// +// MediaPortal is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 2 of the License, or +// (at your option) any later version. +// +// MediaPortal is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with MediaPortal. If not, see . + +#endregion + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace MediaPortal.GUI.Library +{ + /// + /// This is used for caching system fonts (non-latin char support) + /// + class FontObject : IDisposable + { + protected bool disposed = false; + + #region Properties + public int size + { + get; + set; + } + + public System.Drawing.Font font + { + get; + set; + } + #endregion //properties + + #region IDisposable Members + public void Dispose() + { + Dispose(true); + GC.SuppressFinalize(this); + } + + protected virtual void Dispose(bool disposing) + { + if (!disposed) + { + if (disposing) + { + // Dispose managed resources. + } + if (this.font != null) + { + this.font.Dispose(); + this.font = null; + } + } + disposed = true; + } + #endregion //IDisposable + } +} Index: guilib/FontTexture.cs =================================================================== --- guilib/FontTexture.cs (revision 0) +++ guilib/FontTexture.cs (revision 0) @@ -0,0 +1,79 @@ +#region Copyright (C) 2005-2010 Team MediaPortal + +// Copyright (C) 2005-2010 Team MediaPortal +// http://www.team-mediaportal.com +// +// MediaPortal is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 2 of the License, or +// (at your option) any later version. +// +// MediaPortal is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with MediaPortal. If not, see . + +#endregion + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Microsoft.DirectX.Direct3D; + +namespace MediaPortal.GUI.Library +{ + /// + /// This is used for caching font textures (non-latin char support) + /// + class FontTexture : IDisposable + { + protected bool disposed = false; + + #region Properties + public int size + { + get; + set; + } + public string text + { + get; + set; + } + public Texture texture + { + get; + set; + } + #endregion //properties + + #region IDisposable Members + public void Dispose() + { + Dispose(true); + GC.SuppressFinalize(this); + } + + protected virtual void Dispose(bool disposing) + { + if (!disposed) + { + if (disposing) + { + // Dispose managed resources. + } + if (this.texture != null) + { + this.texture.Dispose(); + this.texture = null; + } + } + disposed = true; + } + #endregion //IDisposable + } +} Index: guilib/GUIFontManager.cs =================================================================== --- guilib/GUIFontManager.cs (revision 26740) +++ guilib/GUIFontManager.cs (working copy) @@ -72,21 +72,6 @@ public int fontHeight; } ; - // This is used for caching font textures (non-latin char support) - private struct FontTexture - { - public int size; - public string text; - public Texture texture; - } ; - - // This is used for caching system fonts (non-latin char support) - private struct FontObject - { - public int size; - public System.Drawing.Font font; - } ; - #endregion private static object _renderlock = new object(); @@ -94,7 +79,7 @@ protected static Dictionary _dictFontAlias = new Dictionary(); private static Sprite _d3dxSprite; private static bool _d3dxSpriteUsed; - private static int _maxCachedTextures = 500; + private static int _maxCachedTextures = 250; private static List _listDrawText = new List(); private static List _listFontTextures = new List(); private static List _listFontObjects = new List(); @@ -363,7 +348,7 @@ if (!fontCached) { System.Drawing.Font systemFont = new System.Drawing.Font("Arial", fontSize); - FontObject newFont; + FontObject newFont= new FontObject(); newFont.size = fontSize; newFont.font = systemFont; _listFontObjects.Add(newFont); @@ -396,20 +381,27 @@ { bool textureCached = false; int cacheSlot = 0; + FontTexture drawingTexture = new FontTexture(); foreach (FontTexture cachedTexture in _listFontTextures) { if (cachedTexture.text == draw.text && cachedTexture.size == fontSize) { textureCached = true; + drawingTexture = cachedTexture; break; } cacheSlot++; } Size size = new Size(0, 0); - - if (!textureCached) + if (textureCached) { + //keep commonly used textures at the top of the pile + _listFontTextures.RemoveAt(cacheSlot); + _listFontTextures.Add(drawingTexture); + } + else // texture needs to be cached + { Texture texture = null; float textwidth = 0, textheight = 0; @@ -477,19 +469,23 @@ size.Width = (int)textwidth; size.Height = (int)textheight; - FontTexture newTexture; + FontTexture newTexture = new FontTexture(); newTexture.text = draw.text; newTexture.texture = texture; newTexture.size = fontSize; if (_listFontTextures.Count >= _maxCachedTextures) { + //need to clear this and not rely on the finalizer + FontTexture disposableFont = _listFontTextures[0]; _listFontTextures.RemoveAt(0); + disposableFont.Dispose(); } _listFontTextures.Add(newTexture); + drawingTexture = newTexture; } - _d3dxSprite.Draw(_listFontTextures[cacheSlot].texture, new Rectangle(0, 0, size.Width, size.Height), + _d3dxSprite.Draw(drawingTexture.texture, new Rectangle(0, 0, size.Width, size.Height), Vector3.Empty, new Vector3((int)draw.xpos, (int)draw.ypos, 0), draw.color); }