summaryrefslogtreecommitdiff
path: root/indra/newview/lltextureview.cpp
blob: 01bc0bd5fdb37f25c924d39a3771c4594a98d8b5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
/** 
 * @file lltextureview.cpp
 * @brief LLTextureView class implementation
 *
 * Copyright (c) 2001-$CurrentYear$, Linden Research, Inc.
 * $License$
 */

#include "llviewerprecompiledheaders.h"

#include <set>

#include "lltextureview.h"

#include "llrect.h"
#include "llerror.h"

#include "viewer.h"
#include "llui.h"

#include "llviewerimagelist.h"
#include "llselectmgr.h"
#include "llviewerobject.h"
#include "llviewerimage.h"
#include "llhoverview.h"

LLTextureView *gTextureView = NULL;

//static
std::set<LLViewerImage*> LLTextureView::sDebugImages;

// Used for sorting
struct SortTextureBars
{
	bool operator()(const LLView* i1, const LLView* i2)
	{
		LLTextureBar* bar1p = (LLTextureBar*)i1;
		LLTextureBar* bar2p = (LLTextureBar*)i2;
		LLViewerImage *i1p = bar1p->mImagep;
		LLViewerImage *i2p = bar2p->mImagep;
		F32 pri1 = i1p->getDecodePriority(); // i1p->mRequestedDownloadPriority
		F32 pri2 = i2p->getDecodePriority(); // i2p->mRequestedDownloadPriority
		if (pri1 > pri2)
			return true;
		else if (pri2 > pri1)
			return false;
		else
			return i1p->getID() < i2p->getID();
	}
};

LLTextureView::LLTextureView(const std::string& name, const LLRect& rect)
:	LLContainerView(name, rect)
{
	setVisible(FALSE);
	mFreezeView = FALSE;
	
	mNumTextureBars = 0;
	setDisplayChildren(TRUE);
	mGLTexMemBar = 0;
}

LLTextureView::~LLTextureView()
{
	// Children all cleaned up by default view destructor.
	delete mGLTexMemBar;
	mGLTexMemBar = 0;
}

EWidgetType LLTextureView::getWidgetType() const
{
	return WIDGET_TYPE_TEXTURE_VIEW;
}

LLString LLTextureView::getWidgetTag() const
{
	return LL_TEXTURE_VIEW_TAG;
}


typedef std::pair<F32,LLViewerImage*> decode_pair_t;
struct compare_decode_pair
{
	bool operator()(const decode_pair_t& a, const decode_pair_t& b)
	{
		return a.first > b.first;
	}
};

void LLTextureView::draw()
{
	if (!mFreezeView)
	{
// 		LLViewerObject *objectp;
// 		S32 te;

		for_each(mTextureBars.begin(), mTextureBars.end(), DeletePointer());
		mTextureBars.clear();
	
		delete mGLTexMemBar;
		mGLTexMemBar = 0;
	
		typedef std::multiset<decode_pair_t, compare_decode_pair > display_list_t;
		display_list_t display_image_list;
	
		for (LLViewerImageList::image_list_t::iterator iter = gImageList.mImageList.begin();
			 iter != gImageList.mImageList.end(); )
		{
			LLPointer<LLViewerImage> imagep = *iter++;
#if 1
			if (imagep->getDontDiscard())
			{
				continue;
			}
#endif
			if (imagep->isMissingAsset())
			{
				continue;
			}
			
#define HIGH_PRIORITY 100000000.f
			F32 pri = imagep->getDecodePriority();

			if (sDebugImages.find(imagep) != sDebugImages.end())
			{
				pri += 3*HIGH_PRIORITY;
			}
			
#if 1
			if (pri < HIGH_PRIORITY && gSelectMgr)
			{
				S32 te;
				LLViewerObject *objectp;
				for (gSelectMgr->getFirstTE(&objectp, &te); objectp; gSelectMgr->getNextTE(&objectp, &te))
				{
					if (imagep == objectp->getTEImage(te))
					{
						pri += 2*HIGH_PRIORITY;
						break;
					}
				}
			}
#endif
#if 1
			if (pri < HIGH_PRIORITY)
			{
				LLViewerObject *objectp = gHoverView->getLastHoverObject();
				if (objectp)
				{
					S32 tex_count = objectp->getNumTEs();
					for (S32 i = 0; i < tex_count; i++)
					{
						if (imagep == objectp->getTEImage(i))
						{
							pri += 2*HIGH_PRIORITY;
							break;
						}
					}
				}
			}
#endif
#if 0
			if (pri < HIGH_PRIORITY)
			{
				if (imagep->mBoostPriority)
				{
					pri += 4*HIGH_PRIORITY;
				}
			}
#endif
#if 1
			if (pri > 0.f && pri < HIGH_PRIORITY)
			{
				if (imagep->mLastPacketTimer.getElapsedTimeF32() < 1.f ||
					imagep->mLastDecodeTime.getElapsedTimeF32() < 1.f)
				{
					pri += 1*HIGH_PRIORITY;
				}
			}
#endif
//	 		if (pri > 0.0f)
			{
				display_image_list.insert(std::make_pair(pri, imagep));
			}
		}

		static S32 max_count = 50;
		S32 count = 0;
		for (display_list_t::iterator iter = display_image_list.begin();
			 iter != display_image_list.end(); iter++)
		{
			LLViewerImage* imagep = iter->second;
			S32 hilite = 0;
			F32 pri = iter->first;
			if (pri >= 1 * HIGH_PRIORITY)
			{
				hilite = (S32)((pri+1) / HIGH_PRIORITY) - 1;
			}
			if ((hilite || count < max_count-10) && (count < max_count))
			{
				if (addBar(imagep, hilite))
				{
					count++;
				}
			}
		}

		sortChildren(SortTextureBars());
	
		mGLTexMemBar = new LLGLTexMemBar("gl texmem bar");
		addChild(mGLTexMemBar);
	
		reshape(mRect.getWidth(), mRect.getHeight(), TRUE);

		/*
		  count = gImageList.getNumImages();
		  char info_string[512];
		  sprintf(info_string, "Global Info:\nTexture Count: %d", count);
		  mInfoTextp->setText(info_string);
		*/


		for (child_list_const_iter_t child_iter = getChildList()->begin();
			 child_iter != getChildList()->end(); ++child_iter)
		{
			LLView *viewp = *child_iter;
			if (viewp->getRect().mBottom < 0)
			{
				viewp->setVisible(FALSE);
			}
		}
	}
	
	LLContainerView::draw();

}

BOOL LLTextureView::addBar(LLViewerImage *imagep, S32 hilite)
{
	if (!imagep)
	{
		return FALSE;
	}

	LLTextureBar *barp;
	LLRect r;

	mNumTextureBars++;

	for (std::vector<LLTextureBar*>::iterator iter = mTextureBars.begin();
		 iter != mTextureBars.end(); iter++)
	{
		LLTextureBar* barp = *iter;
		if (barp->mImagep == imagep)
		{
			barp->mHilite = hilite;
			return FALSE;
		}
	}

	barp = new LLTextureBar("texture bar", r);
	barp->mImagep = imagep;	
	barp->mHilite = hilite;

	addChild(barp);
	mTextureBars.push_back(barp);

	// Rearrange all child bars.
	reshape(mRect.getWidth(), mRect.getHeight());
	return TRUE;
}

BOOL LLTextureView::handleMouseDown(S32 x, S32 y, MASK mask)
{
	if (mask & MASK_SHIFT)
	{
		mFreezeView = !mFreezeView;
		return TRUE;
	}
	else if (mask & MASK_CONTROL)
	{
		return FALSE;
	}
	else
	{
		return FALSE;
	}
}

BOOL LLTextureView::handleMouseUp(S32 x, S32 y, MASK mask)
{
	return FALSE;
}

BOOL LLTextureView::handleKey(KEY key, MASK mask, BOOL called_from_parent)
{
	if (key == ' ')
	{
		mFreezeView = !mFreezeView;
		return TRUE;
	}
	return FALSE;
}