From 8f02fd926e14dfad7f5eb77a67a6701f449511e0 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Thu, 6 Sep 2012 22:12:05 +0100 Subject: If reusing dynamic textures, do not reuse small data length textures that fall below current viewer discard level 2 thresholds. Viewer LL 3.3.4 and before sometimes fail to properly redisplay dynamic textures that have a small data length compared to pixel size when pulled from cache. This appears to happen when the data length is smaller than the estimate discard level 2 size the viewer uses when making this GetTexture request. This commit works around this by always regenerating dynamic textures that fall below this threshold rather than reusing them if ReuseDynamicTextures = true This can be controlled by the [Textures] ReuseDynamicLowDataTextures config setting which defaults to false. --- .../DynamicTexture/DynamicTextureModule.cs | 59 ++++++++++++++++++---- 1 file changed, 49 insertions(+), 10 deletions(-) (limited to 'OpenSim/Region/CoreModules/Scripting/DynamicTexture/DynamicTextureModule.cs') diff --git a/OpenSim/Region/CoreModules/Scripting/DynamicTexture/DynamicTextureModule.cs b/OpenSim/Region/CoreModules/Scripting/DynamicTexture/DynamicTextureModule.cs index e09f1a9..1f340df 100644 --- a/OpenSim/Region/CoreModules/Scripting/DynamicTexture/DynamicTextureModule.cs +++ b/OpenSim/Region/CoreModules/Scripting/DynamicTexture/DynamicTextureModule.cs @@ -42,7 +42,7 @@ namespace OpenSim.Region.CoreModules.Scripting.DynamicTexture { public class DynamicTextureModule : IRegionModule, IDynamicTextureManager { -// private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); + private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); private const int ALL_SIDES = -1; @@ -54,6 +54,17 @@ namespace OpenSim.Region.CoreModules.Scripting.DynamicTexture /// public bool ReuseTextures { get; set; } + /// + /// If false, then textures which have a low data size are not reused when ReuseTextures = true. + /// + /// + /// LL viewers 3.3.4 and before appear to not fully render textures pulled from the viewer cache if those + /// textures have a relatively high pixel surface but a small data size. Typically, this appears to happen + /// if the data size is smaller than the viewer's discard level 2 size estimate. So if this is setting is + /// false, textures smaller than the calculation in IsSizeReuseable are always regenerated rather than reused + /// to work around this problem. + public bool ReuseLowDataTextures { get; set; } + private Dictionary RegisteredScenes = new Dictionary(); private Dictionary RenderPlugins = @@ -83,18 +94,17 @@ namespace OpenSim.Region.CoreModules.Scripting.DynamicTexture /// /// Called by code which actually renders the dynamic texture to supply texture data. /// - /// - /// - /// True if the data generated can be reused for subsequent identical requests - public void ReturnData(UUID id, byte[] data, bool isReuseable) + /// + /// + public void ReturnData(UUID updaterId, IDynamicTexture texture) { DynamicTextureUpdater updater = null; lock (Updaters) { - if (Updaters.ContainsKey(id)) + if (Updaters.ContainsKey(updaterId)) { - updater = Updaters[id]; + updater = Updaters[updaterId]; } } @@ -103,11 +113,16 @@ namespace OpenSim.Region.CoreModules.Scripting.DynamicTexture if (RegisteredScenes.ContainsKey(updater.SimUUID)) { Scene scene = RegisteredScenes[updater.SimUUID]; - UUID newTextureID = updater.DataReceived(data, scene); + UUID newTextureID = updater.DataReceived(texture.Data, scene); - if (ReuseTextures && isReuseable && !updater.BlendWithOldTexture) + if (ReuseTextures + && !updater.BlendWithOldTexture + && texture.IsReuseable + && (ReuseLowDataTextures || IsDataSizeReuseable(texture))) + { m_reuseableDynamicTextures.Store( - GenerateReusableTextureKey(updater.BodyData, updater.Params), newTextureID); + GenerateReusableTextureKey(texture.InputCommands, texture.InputParams), newTextureID); + } } } @@ -123,6 +138,27 @@ namespace OpenSim.Region.CoreModules.Scripting.DynamicTexture } } + /// + /// Determines whether the texture is reuseable based on its data size. + /// + /// + /// This is a workaround for a viewer bug where very small data size textures relative to their pixel size + /// are not redisplayed properly when pulled from cache. The calculation here is based on the typical discard + /// level of 2, a 'rate' of 0.125 and 4 components (which makes for a factor of 0.5). + /// + /// + private bool IsDataSizeReuseable(IDynamicTexture texture) + { +// Console.WriteLine("{0} {1}", texture.Size.Width, texture.Size.Height); + int discardLevel2DataThreshold = (int)Math.Ceiling((texture.Size.Width >> 2) * (texture.Size.Height >> 2) * 0.5); + +// m_log.DebugFormat( +// "[DYNAMIC TEXTURE MODULE]: Discard level 2 threshold {0}, texture data length {1}", +// discardLevel2DataThreshold, texture.Data.Length); + + return discardLevel2DataThreshold < texture.Data.Length; + } + public UUID AddDynamicTextureURL(UUID simID, UUID primID, string contentType, string url, string extraParams, int updateTimer) { @@ -293,7 +329,10 @@ namespace OpenSim.Region.CoreModules.Scripting.DynamicTexture { IConfig texturesConfig = config.Configs["Textures"]; if (texturesConfig != null) + { ReuseTextures = texturesConfig.GetBoolean("ReuseDynamicTextures", false); + ReuseLowDataTextures = texturesConfig.GetBoolean("ReuseDynamicLowDataTextures", false); + } if (!RegisteredScenes.ContainsKey(scene.RegionInfo.RegionID)) { -- cgit v1.1