lltextureview.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824
  1. /**
  2. * @file lltextureview.cpp
  3. * @brief LLTextureView class implementation
  4. *
  5. * $LicenseInfo:firstyear=2001&license=viewergpl$
  6. *
  7. * Copyright (c) 2001-2009, Linden Research, Inc.
  8. *
  9. * Second Life Viewer Source Code
  10. * The source code in this file ("Source Code") is provided by Linden Lab
  11. * to you under the terms of the GNU General Public License, version 2.0
  12. * ("GPL"), unless you have obtained a separate licensing agreement
  13. * ("Other License"), formally executed by you and Linden Lab. Terms of
  14. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16. *
  17. * There are special exceptions to the terms and conditions of the GPL as
  18. * it is applied to this Source Code. View the full text of the exception
  19. * in the file doc/FLOSS-exception.txt in this software distribution, or
  20. * online at
  21. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22. *
  23. * By copying, modifying or distributing this software, you acknowledge
  24. * that you have read and understood your obligations described above,
  25. * and agree to abide by those obligations.
  26. *
  27. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29. * COMPLETENESS OR PERFORMANCE.
  30. * $/LicenseInfo$
  31. */
  32. #include "llviewerprecompiledheaders.h"
  33. #include "lltextureview.h"
  34. #include "llconsole.h" // For CONSOLE_PADDING_LEFT
  35. #include "llimagedecodethread.h"
  36. #include "llimagegl.h"
  37. #include "llrender.h"
  38. #include "llvertexbuffer.h"
  39. #include "llappviewer.h"
  40. #include "llhoverview.h"
  41. #include "llselectmgr.h"
  42. #include "lltexturecache.h"
  43. #include "lltexturefetch.h"
  44. #include "llviewercontrol.h"
  45. #include "llviewerobject.h"
  46. #include "llviewertexturelist.h"
  47. #include "llviewerwindow.h"
  48. #include "llvovolume.h"
  49. LLTextureView* gTextureViewp = NULL;
  50. #define HIGH_PRIORITY 100000000.f
  51. ///////////////////////////////////////////////////////////////////////////////
  52. static const char* mem_format_str =
  53. "Mem (MB): GL tex: %d/%d Bound: %d/%d VB: %d Free VRAM: %d/%d Cache: %d/%d";
  54. static const char* tex_format_str =
  55. "Tex(Raw): %d(%d) Fetches: %d(%d) HTTP: %d UDP BW: %.0f Cache R/W: %d/%d Decodes: %d Bias: %.3f";
  56. static const char* fetcher_format_str =
  57. "Fetch boost factor: %.1f - Upd/frame: %d - GL img created: immediate: %d / threaded: %d";
  58. static const char* fetch1_format_str = "%s %7.0f %d(%d) 0x%08x(%8.0f)";
  59. static const char* fetch2_format_str = "%s %7.0f %d(%d) %8.0f(0x%08x) %1.2f";
  60. static const char* image_format_str1 = "%4dx%4d (%d) %7d";
  61. static const char* image_format_str2 = "%4dx%4d (%d) %6d";
  62. static const std::string title_string1a("Tex UUID Area DDis(Req) DecodePri(Fetch) [download]");
  63. static const std::string title_string1b("Tex UUID Area DDis(Req) Fetch(DecodePri) [download]");
  64. static const std::string title_string2("State");
  65. static const std::string title_string3("Pkt Bnd");
  66. static const std::string title_string4(" W x H (Dis) Mem");
  67. static const std::string exclam_string("!");
  68. static const std::string star_string("*");
  69. // State. *HACK: mirrored from lltexturefetch.cpp
  70. static struct { const std::string desc; LLColor4* color; } fetch_state_desc[] = {
  71. { "---", &LLColor4::red }, // INVALID
  72. { "INI", &LLColor4::white }, // INIT
  73. { "DSK", &LLColor4::cyan }, // LOAD_FROM_TEXTURE_CACHE
  74. { "DSK", &LLColor4::blue }, // CACHE_POST
  75. { "NET", &LLColor4::green }, // LOAD_FROM_NETWORK
  76. { "SIM", &LLColor4::green }, // LOAD_FROM_SIMULATOR
  77. { "HTW", &LLColor4::green }, // WAIT_HTTP_RESOURCE
  78. { "HTW", &LLColor4::green }, // WAIT_HTTP_RESOURCE2
  79. { "REQ", &LLColor4::yellow }, // SEND_HTTP_REQ
  80. { "HTP", &LLColor4::green }, // WAIT_HTTP_REQ
  81. { "DEC", &LLColor4::yellow }, // DECODE_IMAGE
  82. { "DEC", &LLColor4::green }, // DECODE_IMAGE_UPDATE
  83. { "WRT", &LLColor4::purple }, // WRITE_TO_CACHE
  84. { "WRT", &LLColor4::orange }, // WAIT_ON_WRITE
  85. { "END", &LLColor4::red }, // DONE
  86. #define LAST_STATE 14
  87. { "CRE", &LLColor4::magenta }, // LAST_STATE+1
  88. { "FUL", &LLColor4::green }, // LAST_STATE+2
  89. { "BAD", &LLColor4::red }, // LAST_STATE+3
  90. { "MIS", &LLColor4::red }, // LAST_STATE+4
  91. { "---", &LLColor4::white }, // LAST_STATE+5
  92. };
  93. constexpr S32 fetch_state_desc_size = (S32)LL_ARRAY_SIZE(fetch_state_desc);
  94. constexpr S32 TEXTUREVIEW_WIDTH = 648;
  95. constexpr S32 TEXTUREVIEW_TOP_DELTA = 50;
  96. constexpr S32 TITLE_X1 = 0;
  97. constexpr S32 BAR_LEFT = TITLE_X1 + 290;
  98. constexpr S32 BAR_WIDTH = 100;
  99. constexpr S32 BAR_HEIGHT = 8;
  100. constexpr S32 TITLE_X2 = BAR_LEFT + BAR_WIDTH + 10;
  101. constexpr S32 TITLE_X3 = TITLE_X2 + 40;
  102. constexpr S32 TITLE_X4 = TITLE_X3 + 50;
  103. ///////////////////////////////////////////////////////////////////////////////
  104. class LLTextureBar final : public LLView
  105. {
  106. protected:
  107. LOG_CLASS(LLTextureBar);
  108. public:
  109. LLTextureBar(const std::string& name, const LLRect& r, LLTextureView* view)
  110. : LLView(name, r, false),
  111. mHilite(0),
  112. mTextureView(view)
  113. {
  114. }
  115. void draw() override;
  116. // Returns the height of this object, given the set options.
  117. LL_INLINE LLRect getRequiredRect() override
  118. {
  119. LLRect rect;
  120. rect.mTop = BAR_HEIGHT;
  121. return rect;
  122. }
  123. // Used for sorting
  124. struct sort
  125. {
  126. LL_INLINE bool operator()(const LLView* i1, const LLView* i2)
  127. {
  128. LLViewerFetchedTexture* i1p = ((LLTextureBar*)i1)->mImagep;
  129. LLViewerFetchedTexture* i2p = ((LLTextureBar*)i2)->mImagep;
  130. F32 pri1 = i1p->getDecodePriority();
  131. F32 pri2 = i2p->getDecodePriority();
  132. if (pri1 > pri2)
  133. {
  134. return true;
  135. }
  136. if (pri2 > pri1)
  137. {
  138. return false;
  139. }
  140. return i1p->getID() < i2p->getID();
  141. }
  142. };
  143. struct sort_fetch
  144. {
  145. LL_INLINE bool operator()(const LLView* i1, const LLView* i2)
  146. {
  147. LLViewerFetchedTexture* i1p = ((LLTextureBar*)i1)->mImagep;
  148. LLViewerFetchedTexture* i2p = ((LLTextureBar*)i2)->mImagep;
  149. U32 pri1 = i1p->getFetchPriority();
  150. U32 pri2 = i2p->getFetchPriority();
  151. if (pri1 > pri2)
  152. {
  153. return true;
  154. }
  155. if (pri2 > pri1)
  156. {
  157. return false;
  158. }
  159. return i1p->getID() < i2p->getID();
  160. }
  161. };
  162. private:
  163. LLTextureView* mTextureView;
  164. public:
  165. LLPointer<LLViewerFetchedTexture> mImagep;
  166. S32 mHilite;
  167. };
  168. void LLTextureBar::draw()
  169. {
  170. static LLFontGL* fontp = LLFontGL::getFontMonospace();
  171. if (!fontp)
  172. {
  173. llwarns_sparse << "No monospace font !" << llendl;
  174. return;
  175. }
  176. if (!mImagep || !gTextureFetchp)
  177. {
  178. return;
  179. }
  180. LLColor4 color;
  181. if (mHilite)
  182. {
  183. S32 idx = llclamp(mHilite, 1, 3);
  184. if (idx == 1)
  185. {
  186. color = LLColor4::orange;
  187. }
  188. else if (idx == 2)
  189. {
  190. color = LLColor4::yellow;
  191. }
  192. else
  193. {
  194. color = LLColor4::pink2;
  195. }
  196. }
  197. else if (mImagep->mDontDiscard)
  198. {
  199. color = LLColor4::green4;
  200. }
  201. else if (mImagep->getBoostLevel() > LLGLTexture::BOOST_ALM)
  202. {
  203. color = LLColor4::magenta;
  204. }
  205. else if (mImagep->getDecodePriority() <= 0.f)
  206. {
  207. color = LLColor4::grey;
  208. color[VALPHA] = 0.7f;
  209. }
  210. else
  211. {
  212. color = LLColor4::white;
  213. color[VALPHA] = 0.7f;
  214. }
  215. // We need to draw the texture UUID or name, the progress bar for the
  216. // texture (highlighted if it is being downloaded) and various numerical
  217. // stats.
  218. LLGLSUIDefault gls_ui;
  219. static char uuid_str[UUID_STR_LENGTH];
  220. mImagep->mID.toCString(uuid_str);
  221. uuid_str[7] = '\0'; // Keep only the first six digits
  222. std::string tex_str;
  223. if (mTextureView->mOrderFetch)
  224. {
  225. tex_str = llformat(fetch1_format_str, uuid_str,
  226. mImagep->mMaxVirtualSize,
  227. mImagep->mDesiredDiscardLevel,
  228. mImagep->mRequestedDiscardLevel,
  229. mImagep->mFetchPriority,
  230. mImagep->getDecodePriority());
  231. }
  232. else
  233. {
  234. tex_str = llformat(fetch2_format_str, uuid_str,
  235. mImagep->mMaxVirtualSize,
  236. mImagep->mDesiredDiscardLevel,
  237. mImagep->mRequestedDiscardLevel,
  238. mImagep->getDecodePriority(),
  239. mImagep->mFetchPriority,
  240. mImagep->mDownloadProgress);
  241. }
  242. fontp->renderUTF8(tex_str, 0, TITLE_X1, getRect().getHeight(), color,
  243. LLFontGL::LEFT, LLFontGL::TOP);
  244. S32 state = mImagep->mNeedsCreateTexture ? LAST_STATE + 1 :
  245. mImagep->mFullyLoaded ? LAST_STATE + 2 :
  246. mImagep->mMinDiscardLevel > 0 ? LAST_STATE + 3 :
  247. mImagep->mIsMissingAsset ? LAST_STATE + 4 :
  248. !mImagep->mIsFetching ? LAST_STATE + 5 :
  249. mImagep->mFetchState;
  250. state = llclamp(state, 0, fetch_state_desc_size - 1);
  251. fontp->renderUTF8(fetch_state_desc[state].desc, 0, TITLE_X2,
  252. getRect().getHeight(),
  253. *(fetch_state_desc[state].color),
  254. LLFontGL::LEFT, LLFontGL::TOP);
  255. gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
  256. // Draw the progress bar.
  257. S32 left = BAR_LEFT;
  258. S32 right = left + BAR_WIDTH;
  259. S32 top = 0;
  260. S32 bottom = top + 6;
  261. gGL.color4f(0.f, 0.f, 0.f, 0.75f);
  262. gl_rect_2d(left, top, right, bottom);
  263. F32 data_progress = mImagep->mDownloadProgress;
  264. if (data_progress > 0.f && data_progress <= 1.f)
  265. {
  266. // Downloaded bytes
  267. right = left + llfloor(data_progress * (F32)BAR_WIDTH);
  268. if (right > left)
  269. {
  270. gGL.color4f(0.f, 0.f, 1.f, 0.75f);
  271. gl_rect_2d(left, top, right, bottom);
  272. }
  273. }
  274. else if (data_progress > 1.f)
  275. {
  276. // Small cached textures generate this oddity. SNOW-168
  277. right = left + BAR_WIDTH;
  278. gGL.color4f(0.f, 0.33f, 0.f, 0.75f);
  279. gl_rect_2d(left, top, right, bottom);
  280. }
  281. S32 pip_width = 6;
  282. S32 pip_space = 14;
  283. S32 pip_x = TITLE_X3 + pip_space / 2;
  284. // Draw the packet pip
  285. LLColor4 clr;
  286. constexpr F32 pip_max_time = 5.f;
  287. F32 last_event = gFrameTimeSeconds - mImagep->mLastPacketTime;
  288. if (last_event < pip_max_time)
  289. {
  290. clr = LLColor4::white;
  291. }
  292. else
  293. {
  294. last_event = mImagep->mRequestDeltaTime;
  295. if (last_event < pip_max_time)
  296. {
  297. clr = LLColor4::green;
  298. }
  299. else
  300. {
  301. last_event = mImagep->mFetchDeltaTime;
  302. if (last_event < pip_max_time)
  303. {
  304. clr = LLColor4::yellow;
  305. }
  306. }
  307. }
  308. if (last_event < pip_max_time)
  309. {
  310. clr.setAlpha(1.f - last_event / pip_max_time);
  311. gGL.color4fv(clr.mV);
  312. gl_rect_2d(pip_x, top, pip_x + pip_width, bottom);
  313. }
  314. pip_x += pip_width + pip_space;
  315. // We do not want to show bind/resident pips for textures using the default
  316. // texture
  317. if (mImagep->hasGLTexture())
  318. {
  319. // Draw the bound pip
  320. last_event = mImagep->getTimePassedSinceLastBound();
  321. if (last_event < 1.f)
  322. {
  323. clr = LLColor4::magenta1;
  324. clr.setAlpha(1.f - last_event);
  325. gGL.color4fv(clr.mV);
  326. gl_rect_2d(pip_x, top, pip_x + pip_width, bottom);
  327. }
  328. }
  329. pip_x += pip_width + pip_space;
  330. {
  331. LLGLSUIDefault gls_ui;
  332. // Draw the image size at the end
  333. S32 discard = mImagep->getDiscardLevel();
  334. std::string num_str =
  335. llformat(discard >= 0 ? image_format_str1 : image_format_str2,
  336. mImagep->getWidth(), mImagep->getHeight(), discard,
  337. mImagep->hasGLTexture() ? mImagep->getTextureMemory()
  338. : 0);
  339. fontp->renderUTF8(num_str, 0, TITLE_X4, getRect().getHeight(), color,
  340. LLFontGL::LEFT, LLFontGL::TOP);
  341. }
  342. }
  343. ////////////////////////////////////////////////////////////////////////////
  344. class LLGLTexMemBar final : public LLView
  345. {
  346. protected:
  347. LOG_CLASS(LLGLTexMemBar);
  348. public:
  349. LLGLTexMemBar(const std::string& name, LLTextureView* texview)
  350. : LLView(name, false),
  351. mTextureView(texview)
  352. {
  353. S32 line_height =
  354. (S32)(LLFontGL::getFontMonospace()->getLineHeight() + .5f);
  355. setRect(LLRect(0, 0, 100, line_height * 5));
  356. }
  357. void draw() override;
  358. LL_INLINE bool handleMouseDown(S32, S32, MASK) override
  359. {
  360. return false;
  361. }
  362. // Returns the height of this object, given the set options.
  363. LL_INLINE LLRect getRequiredRect() override
  364. {
  365. LLRect rect;
  366. // Room for four lines of text
  367. rect.mTop = (7 * BAR_HEIGHT) / 2;
  368. return rect;
  369. }
  370. private:
  371. LLTextureView* mTextureView;
  372. };
  373. void LLGLTexMemBar::draw()
  374. {
  375. static LLFontGL* fontp = LLFontGL::getFontMonospace();
  376. if (!fontp)
  377. {
  378. llwarns_sparse << "No monospace font !" << llendl;
  379. return;
  380. }
  381. static S32 line_height = S32(fontp->getLineHeight() + 0.5f);
  382. if (!gTextureFetchp || !gTextureCachep)
  383. {
  384. return;
  385. }
  386. S32 cache_usage = BYTES2MEGABYTES(gTextureCachep->getUsage());
  387. S32 cache_max_usage = BYTES2MEGABYTES(LLTextureCache::getMaxUsage());
  388. LLGLSUIDefault gls_ui;
  389. LLColor4 text_color(1.f, 1.f, 1.f, 0.75f);
  390. LLColor4 color;
  391. std::string text = llformat(mem_format_str,
  392. LLViewerTexture::sTotalTexMemoryMB,
  393. LLViewerTexture::sMaxTotalTexMemMB,
  394. LLViewerTexture::sBoundTexMemoryMB,
  395. LLViewerTexture::sMaxBoundTexMemMB,
  396. LLVertexBuffer::getVRAMMegabytes(),
  397. LLImageGLThread::getFreeVRAMMegabytes(),
  398. gGLManager.mTexVRAM, cache_usage,
  399. cache_max_usage);
  400. fontp->renderUTF8(text, 0, 0, line_height * 4, text_color, LLFontGL::LEFT,
  401. LLFontGL::TOP);
  402. S32 raw_count = LLImageRaw::sRawImageCount;
  403. text = llformat(tex_format_str, gTextureList.getNumImages(), raw_count,
  404. gTextureFetchp->getApproxNumRequests(),
  405. gTextureFetchp->getNumDeletes(),
  406. gTextureFetchp->getNumHTTPRequests(),
  407. gTextureFetchp->getTextureBandwidth(),
  408. gTextureCachep->getNumReads(),
  409. gTextureCachep->getNumWrites(),
  410. gImageDecodeThreadp->getPending(),
  411. LLViewerTexture::sDesiredDiscardBias);
  412. fontp->renderUTF8(text, 0, 0, line_height * 3, text_color, LLFontGL::LEFT,
  413. LLFontGL::TOP);
  414. text = llformat(fetcher_format_str,
  415. LLViewerTextureList::sFetchingBoostFactor,
  416. (S32)LLViewerTextureList::sNumUpdatesStat.getMean(),
  417. LLViewerFetchedTexture::sMainThreadCreations,
  418. LLViewerFetchedTexture::sImageThreadCreations);
  419. if (LLViewerFetchedTexture::sImageThreadCreationsCapped)
  420. {
  421. text += " (queue full)";
  422. }
  423. else
  424. {
  425. text += llformat(" (%d)",
  426. LLViewerFetchedTexture::sImageThreadQueueSize);
  427. }
  428. fontp->renderUTF8(text, 0, 0, line_height * 2, text_color, LLFontGL::LEFT,
  429. LLFontGL::TOP);
  430. S32 dx1 = 0;
  431. if (gTextureFetchp->mDebugPause)
  432. {
  433. fontp->renderUTF8(exclam_string, 0, TITLE_X1, line_height, text_color,
  434. LLFontGL::LEFT, LLFontGL::TOP);
  435. dx1 += 8;
  436. }
  437. if (mTextureView->mFreezeView)
  438. {
  439. fontp->renderUTF8(star_string, 0, TITLE_X1, line_height, text_color,
  440. LLFontGL::LEFT, LLFontGL::TOP);
  441. dx1 += 8;
  442. }
  443. if (mTextureView->mOrderFetch)
  444. {
  445. fontp->renderUTF8(title_string1b, 0, TITLE_X1 + dx1, line_height,
  446. text_color, LLFontGL::LEFT, LLFontGL::TOP);
  447. }
  448. else
  449. {
  450. fontp->renderUTF8(title_string1a, 0, TITLE_X1 + dx1, line_height,
  451. text_color, LLFontGL::LEFT, LLFontGL::TOP);
  452. }
  453. fontp->renderUTF8(title_string2, 0, TITLE_X2, line_height, text_color,
  454. LLFontGL::LEFT, LLFontGL::TOP);
  455. fontp->renderUTF8(title_string3, 0, TITLE_X3, line_height, text_color,
  456. LLFontGL::LEFT, LLFontGL::TOP);
  457. fontp->renderUTF8(title_string4, 0, TITLE_X4, line_height, text_color,
  458. LLFontGL::LEFT, LLFontGL::TOP);
  459. }
  460. ////////////////////////////////////////////////////////////////////////////
  461. LLTextureView::LLTextureView(const std::string& name)
  462. : LLContainerView(name, LLRect()),
  463. mFreezeView(false),
  464. mOrderFetch(false),
  465. mPrintList(false),
  466. mNumTextureBars(0),
  467. mGLTexMemBar(NULL)
  468. {
  469. llassert(gTextureViewp == NULL);
  470. gTextureViewp = this;
  471. setVisible(false);
  472. setFollowsTop();
  473. setFollowsLeft();
  474. // NOTE: we must ensure the initial rect got a valid (non-zero) size, else
  475. // draw() is never called, and the rect is never resized (and stays
  476. // invisible)... HB
  477. S32 cur_height = gViewerWindowp->getVirtualWindowRect().getHeight();
  478. LLRect rect;
  479. rect.setLeftTopAndSize(CONSOLE_PADDING_LEFT,
  480. cur_height - TEXTUREVIEW_TOP_DELTA,
  481. TEXTUREVIEW_WIDTH, cur_height / 2);
  482. setRect(rect);
  483. reshape(rect.getWidth(), rect.getHeight(), false);
  484. }
  485. LLTextureView::~LLTextureView()
  486. {
  487. for_each(mTextureBars.begin(), mTextureBars.end(), DeletePointer());
  488. mTextureBars.clear();
  489. // Children all cleaned up by default view destructor.
  490. if (mGLTexMemBar)
  491. {
  492. delete mGLTexMemBar;
  493. mGLTexMemBar = NULL;
  494. }
  495. gTextureViewp = NULL;
  496. }
  497. typedef std::pair<F32, LLViewerFetchedTexture*> decode_pair_t;
  498. struct compare_decode_pair
  499. {
  500. LL_INLINE bool operator()(const decode_pair_t& a,
  501. const decode_pair_t& b) const
  502. {
  503. return a.first > b.first;
  504. }
  505. };
  506. //virtual
  507. void LLTextureView::draw()
  508. {
  509. static S32 window_height = -1;
  510. S32 cur_height = gViewerWindowp->getVirtualWindowRect().getHeight();
  511. if (cur_height != window_height)
  512. {
  513. window_height = cur_height;
  514. LLRect rect;
  515. rect.setLeftTopAndSize(CONSOLE_PADDING_LEFT,
  516. cur_height - TEXTUREVIEW_TOP_DELTA,
  517. TEXTUREVIEW_WIDTH, cur_height / 2);
  518. setRect(rect);
  519. reshape(rect.getWidth(), rect.getHeight(), false);
  520. }
  521. if (!mFreezeView)
  522. {
  523. for_each(mTextureBars.begin(), mTextureBars.end(), DeletePointer());
  524. mTextureBars.clear();
  525. if (mGLTexMemBar)
  526. {
  527. delete mGLTexMemBar;
  528. mGLTexMemBar = NULL;
  529. }
  530. typedef std::multiset<decode_pair_t,
  531. compare_decode_pair> display_list_t;
  532. display_list_t display_image_list;
  533. if (mPrintList)
  534. {
  535. llinfos << "ID\tMEM\tBOOST\tPRI\tWIDTH\tHEIGHT\tDISCARD" << llendl;
  536. }
  537. for (LLViewerTextureList::priority_list_t::iterator
  538. iter = gTextureList.mImageList.begin(),
  539. end = gTextureList.mImageList.end();
  540. iter != end; ++iter)
  541. {
  542. LLPointer<LLViewerFetchedTexture> imagep = *iter;
  543. if (!imagep->hasFetcher())
  544. {
  545. continue;
  546. }
  547. S32 cur_discard = imagep->getDiscardLevel();
  548. S32 desired_discard = imagep->mDesiredDiscardLevel;
  549. if (mPrintList)
  550. {
  551. S32 tex_mem =
  552. imagep->hasGLTexture() ? imagep->getTextureMemory() : 0;
  553. llinfos << imagep->getID() << "\t" << tex_mem
  554. << "\t" << imagep->getBoostLevel()
  555. << "\t" << imagep->getDecodePriority()
  556. << "\t" << imagep->getWidth()
  557. << "\t" << imagep->getHeight()
  558. << "\t" << cur_discard << llendl;
  559. }
  560. #if 0
  561. if (imagep->getDontDiscard() || imagep->isMissingAsset())
  562. {
  563. continue;
  564. }
  565. #endif
  566. F32 pri;
  567. if (mOrderFetch)
  568. {
  569. pri = (F32)imagep->mFetchPriority / 256.f;
  570. }
  571. else
  572. {
  573. pri = imagep->getDecodePriority();
  574. }
  575. pri = llclamp(pri, 0.f, HIGH_PRIORITY - 1.f);
  576. if (!mOrderFetch)
  577. {
  578. if (pri < HIGH_PRIORITY)
  579. {
  580. struct f final : public LLSelectedTEFunctor
  581. {
  582. LLViewerFetchedTexture* mImage;
  583. f(LLViewerFetchedTexture* image) : mImage(image)
  584. {
  585. }
  586. bool apply(LLViewerObject* object, S32 te) override
  587. {
  588. return (mImage == object->getTEImage(te));
  589. }
  590. } func(imagep);
  591. bool match = gSelectMgr.getSelection()->applyToTEs(&func,
  592. true);
  593. if (match)
  594. {
  595. pri += 3 * HIGH_PRIORITY;
  596. }
  597. }
  598. if (gHoverViewp && pri < HIGH_PRIORITY &&
  599. (cur_discard< 0 || desired_discard < cur_discard))
  600. {
  601. LLViewerObject* objectp =
  602. gHoverViewp->getLastHoverObject();
  603. if (objectp)
  604. {
  605. S32 tex_count = objectp->getNumTEs();
  606. for (S32 i = 0; i < tex_count; ++i)
  607. {
  608. if (imagep == objectp->getTEImage(i))
  609. {
  610. pri += 2 * HIGH_PRIORITY;
  611. break;
  612. }
  613. }
  614. }
  615. }
  616. if (pri > 0.f && pri < HIGH_PRIORITY)
  617. {
  618. if (gFrameTimeSeconds - imagep->mLastPacketTime < 1.f ||
  619. imagep->mFetchDeltaTime < 0.25f)
  620. {
  621. pri += HIGH_PRIORITY;
  622. }
  623. }
  624. }
  625. if (pri > 0.f)
  626. {
  627. display_image_list.emplace(pri, imagep);
  628. }
  629. }
  630. mPrintList = false;
  631. static S32 max_count = 50;
  632. S32 count = 0;
  633. for (display_list_t::iterator iter2 = display_image_list.begin(),
  634. end2 = display_image_list.end();
  635. iter2 != end2; ++iter2)
  636. {
  637. LLViewerFetchedTexture* imagep = iter2->second;
  638. S32 hilite = 0;
  639. F32 pri = iter2->first;
  640. if (pri >= 1 * HIGH_PRIORITY)
  641. {
  642. hilite = (S32)((pri + 1) / HIGH_PRIORITY) - 1;
  643. }
  644. if ((hilite || count < max_count - 10) && count < max_count)
  645. {
  646. if (addBar(imagep, hilite))
  647. {
  648. ++count;
  649. }
  650. }
  651. }
  652. if (mOrderFetch)
  653. {
  654. sortChildren(LLTextureBar::sort_fetch());
  655. }
  656. else
  657. {
  658. sortChildren(LLTextureBar::sort());
  659. }
  660. mGLTexMemBar = new LLGLTexMemBar("gl texmem bar", this);
  661. addChild(mGLTexMemBar);
  662. reshape(getRect().getWidth(), getRect().getHeight(), true);
  663. LLUI::popMatrix();
  664. LLUI::pushMatrix();
  665. LLUI::translate((F32)getRect().mLeft, (F32)getRect().mBottom);
  666. for (child_list_const_iter_t child_iter = getChildList()->begin(),
  667. child_end = getChildList()->end();
  668. child_iter != child_end; ++child_iter)
  669. {
  670. LLView* viewp = *child_iter;
  671. if (viewp && viewp->getRect().mBottom < 0)
  672. {
  673. viewp->setVisible(false);
  674. }
  675. }
  676. }
  677. LLContainerView::draw();
  678. }
  679. bool LLTextureView::addBar(LLViewerFetchedTexture* imagep, S32 hilite)
  680. {
  681. llassert(imagep);
  682. LLRect r;
  683. LLTextureBar* barp = new LLTextureBar("texture bar", r, this);
  684. if (barp)
  685. {
  686. barp->mImagep = imagep;
  687. barp->mHilite = hilite;
  688. addChild(barp);
  689. ++mNumTextureBars;
  690. mTextureBars.push_back(barp);
  691. return true;
  692. }
  693. llwarns << "Could not create a new bar ! Out of memory ?" << llendl;
  694. return false;
  695. }
  696. bool LLTextureView::handleMouseDown(S32 x, S32 y, MASK mask)
  697. {
  698. if ((mask & (MASK_CONTROL | MASK_SHIFT | MASK_ALT)) ==
  699. (MASK_ALT | MASK_SHIFT))
  700. {
  701. mPrintList = true;
  702. return true;
  703. }
  704. if ((mask & (MASK_CONTROL | MASK_SHIFT | MASK_ALT)) ==
  705. (MASK_CONTROL | MASK_SHIFT))
  706. {
  707. if (gTextureFetchp)
  708. {
  709. gTextureFetchp->mDebugPause = !gTextureFetchp->mDebugPause;
  710. }
  711. return true;
  712. }
  713. if (mask & MASK_SHIFT)
  714. {
  715. mFreezeView = !mFreezeView;
  716. return true;
  717. }
  718. if (mask & MASK_CONTROL)
  719. {
  720. mOrderFetch = !mOrderFetch;
  721. return true;
  722. }
  723. return LLView::handleMouseDown(x, y, mask);
  724. }
  725. bool LLTextureView::handleMouseUp(S32, S32, MASK)
  726. {
  727. return false;
  728. }
  729. bool LLTextureView::handleKey(KEY, MASK, bool)
  730. {
  731. return false;
  732. }