diff options
Diffstat (limited to 'OpenSim/Region/CoreModules/Scripting/DynamicTexture')
-rw-r--r-- | OpenSim/Region/CoreModules/Scripting/DynamicTexture/DynamicTexture.cs | 61 | ||||
-rw-r--r-- | OpenSim/Region/CoreModules/Scripting/DynamicTexture/DynamicTextureModule.cs | 59 |
2 files changed, 110 insertions, 10 deletions
diff --git a/OpenSim/Region/CoreModules/Scripting/DynamicTexture/DynamicTexture.cs b/OpenSim/Region/CoreModules/Scripting/DynamicTexture/DynamicTexture.cs new file mode 100644 index 0000000..fce9490 --- /dev/null +++ b/OpenSim/Region/CoreModules/Scripting/DynamicTexture/DynamicTexture.cs | |||
@@ -0,0 +1,61 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Drawing; | ||
30 | using OpenSim.Region.Framework.Interfaces; | ||
31 | |||
32 | namespace OpenSim.Region.CoreModules.Scripting.DynamicTexture | ||
33 | { | ||
34 | public class DynamicTexture : IDynamicTexture | ||
35 | { | ||
36 | public string InputCommands { get; private set; } | ||
37 | public Uri InputUri { get; private set; } | ||
38 | public string InputParams { get; private set; } | ||
39 | public byte[] Data { get; private set; } | ||
40 | public Size Size { get; private set; } | ||
41 | public bool IsReuseable { get; private set; } | ||
42 | |||
43 | public DynamicTexture(string inputCommands, string inputParams, byte[] data, Size size, bool isReuseable) | ||
44 | { | ||
45 | InputCommands = inputCommands; | ||
46 | InputParams = inputParams; | ||
47 | Data = data; | ||
48 | Size = size; | ||
49 | IsReuseable = isReuseable; | ||
50 | } | ||
51 | |||
52 | public DynamicTexture(Uri inputUri, string inputParams, byte[] data, Size size, bool isReuseable) | ||
53 | { | ||
54 | InputUri = inputUri; | ||
55 | InputParams = inputParams; | ||
56 | Data = data; | ||
57 | Size = size; | ||
58 | IsReuseable = isReuseable; | ||
59 | } | ||
60 | } | ||
61 | } \ No newline at end of file | ||
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 | |||
42 | { | 42 | { |
43 | public class DynamicTextureModule : IRegionModule, IDynamicTextureManager | 43 | public class DynamicTextureModule : IRegionModule, IDynamicTextureManager |
44 | { | 44 | { |
45 | // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 45 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
46 | 46 | ||
47 | private const int ALL_SIDES = -1; | 47 | private const int ALL_SIDES = -1; |
48 | 48 | ||
@@ -54,6 +54,17 @@ namespace OpenSim.Region.CoreModules.Scripting.DynamicTexture | |||
54 | /// </summary> | 54 | /// </summary> |
55 | public bool ReuseTextures { get; set; } | 55 | public bool ReuseTextures { get; set; } |
56 | 56 | ||
57 | /// <summary> | ||
58 | /// If false, then textures which have a low data size are not reused when ReuseTextures = true. | ||
59 | /// </summary> | ||
60 | /// <remarks> | ||
61 | /// LL viewers 3.3.4 and before appear to not fully render textures pulled from the viewer cache if those | ||
62 | /// textures have a relatively high pixel surface but a small data size. Typically, this appears to happen | ||
63 | /// if the data size is smaller than the viewer's discard level 2 size estimate. So if this is setting is | ||
64 | /// false, textures smaller than the calculation in IsSizeReuseable are always regenerated rather than reused | ||
65 | /// to work around this problem.</remarks> | ||
66 | public bool ReuseLowDataTextures { get; set; } | ||
67 | |||
57 | private Dictionary<UUID, Scene> RegisteredScenes = new Dictionary<UUID, Scene>(); | 68 | private Dictionary<UUID, Scene> RegisteredScenes = new Dictionary<UUID, Scene>(); |
58 | 69 | ||
59 | private Dictionary<string, IDynamicTextureRender> RenderPlugins = | 70 | private Dictionary<string, IDynamicTextureRender> RenderPlugins = |
@@ -83,18 +94,17 @@ namespace OpenSim.Region.CoreModules.Scripting.DynamicTexture | |||
83 | /// <summary> | 94 | /// <summary> |
84 | /// Called by code which actually renders the dynamic texture to supply texture data. | 95 | /// Called by code which actually renders the dynamic texture to supply texture data. |
85 | /// </summary> | 96 | /// </summary> |
86 | /// <param name="id"></param> | 97 | /// <param name="updaterId"></param> |
87 | /// <param name="data"></param> | 98 | /// <param name="texture"></param> |
88 | /// <param name="isReuseable">True if the data generated can be reused for subsequent identical requests</param> | 99 | public void ReturnData(UUID updaterId, IDynamicTexture texture) |
89 | public void ReturnData(UUID id, byte[] data, bool isReuseable) | ||
90 | { | 100 | { |
91 | DynamicTextureUpdater updater = null; | 101 | DynamicTextureUpdater updater = null; |
92 | 102 | ||
93 | lock (Updaters) | 103 | lock (Updaters) |
94 | { | 104 | { |
95 | if (Updaters.ContainsKey(id)) | 105 | if (Updaters.ContainsKey(updaterId)) |
96 | { | 106 | { |
97 | updater = Updaters[id]; | 107 | updater = Updaters[updaterId]; |
98 | } | 108 | } |
99 | } | 109 | } |
100 | 110 | ||
@@ -103,11 +113,16 @@ namespace OpenSim.Region.CoreModules.Scripting.DynamicTexture | |||
103 | if (RegisteredScenes.ContainsKey(updater.SimUUID)) | 113 | if (RegisteredScenes.ContainsKey(updater.SimUUID)) |
104 | { | 114 | { |
105 | Scene scene = RegisteredScenes[updater.SimUUID]; | 115 | Scene scene = RegisteredScenes[updater.SimUUID]; |
106 | UUID newTextureID = updater.DataReceived(data, scene); | 116 | UUID newTextureID = updater.DataReceived(texture.Data, scene); |
107 | 117 | ||
108 | if (ReuseTextures && isReuseable && !updater.BlendWithOldTexture) | 118 | if (ReuseTextures |
119 | && !updater.BlendWithOldTexture | ||
120 | && texture.IsReuseable | ||
121 | && (ReuseLowDataTextures || IsDataSizeReuseable(texture))) | ||
122 | { | ||
109 | m_reuseableDynamicTextures.Store( | 123 | m_reuseableDynamicTextures.Store( |
110 | GenerateReusableTextureKey(updater.BodyData, updater.Params), newTextureID); | 124 | GenerateReusableTextureKey(texture.InputCommands, texture.InputParams), newTextureID); |
125 | } | ||
111 | } | 126 | } |
112 | } | 127 | } |
113 | 128 | ||
@@ -123,6 +138,27 @@ namespace OpenSim.Region.CoreModules.Scripting.DynamicTexture | |||
123 | } | 138 | } |
124 | } | 139 | } |
125 | 140 | ||
141 | /// <summary> | ||
142 | /// Determines whether the texture is reuseable based on its data size. | ||
143 | /// </summary> | ||
144 | /// <remarks> | ||
145 | /// This is a workaround for a viewer bug where very small data size textures relative to their pixel size | ||
146 | /// are not redisplayed properly when pulled from cache. The calculation here is based on the typical discard | ||
147 | /// level of 2, a 'rate' of 0.125 and 4 components (which makes for a factor of 0.5). | ||
148 | /// </remarks> | ||
149 | /// <returns></returns> | ||
150 | private bool IsDataSizeReuseable(IDynamicTexture texture) | ||
151 | { | ||
152 | // Console.WriteLine("{0} {1}", texture.Size.Width, texture.Size.Height); | ||
153 | int discardLevel2DataThreshold = (int)Math.Ceiling((texture.Size.Width >> 2) * (texture.Size.Height >> 2) * 0.5); | ||
154 | |||
155 | // m_log.DebugFormat( | ||
156 | // "[DYNAMIC TEXTURE MODULE]: Discard level 2 threshold {0}, texture data length {1}", | ||
157 | // discardLevel2DataThreshold, texture.Data.Length); | ||
158 | |||
159 | return discardLevel2DataThreshold < texture.Data.Length; | ||
160 | } | ||
161 | |||
126 | public UUID AddDynamicTextureURL(UUID simID, UUID primID, string contentType, string url, | 162 | public UUID AddDynamicTextureURL(UUID simID, UUID primID, string contentType, string url, |
127 | string extraParams, int updateTimer) | 163 | string extraParams, int updateTimer) |
128 | { | 164 | { |
@@ -293,7 +329,10 @@ namespace OpenSim.Region.CoreModules.Scripting.DynamicTexture | |||
293 | { | 329 | { |
294 | IConfig texturesConfig = config.Configs["Textures"]; | 330 | IConfig texturesConfig = config.Configs["Textures"]; |
295 | if (texturesConfig != null) | 331 | if (texturesConfig != null) |
332 | { | ||
296 | ReuseTextures = texturesConfig.GetBoolean("ReuseDynamicTextures", false); | 333 | ReuseTextures = texturesConfig.GetBoolean("ReuseDynamicTextures", false); |
334 | ReuseLowDataTextures = texturesConfig.GetBoolean("ReuseDynamicLowDataTextures", false); | ||
335 | } | ||
297 | 336 | ||
298 | if (!RegisteredScenes.ContainsKey(scene.RegionInfo.RegionID)) | 337 | if (!RegisteredScenes.ContainsKey(scene.RegionInfo.RegionID)) |
299 | { | 338 | { |