llfeaturemanager.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. /**
  2. * @file llfeaturemanager.h
  3. * @brief The feature manager is responsible for determining what features are turned on/off in the app.
  4. *
  5. * $LicenseInfo:firstyear=2003&license=viewergpl$
  6. *
  7. * Copyright (c) 2003-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. #ifndef LL_LLFEATUREMANAGER_H
  33. #define LL_LLFEATUREMANAGER_H
  34. // Note: we do not use boost's unordered_maps/sets, because boost's default
  35. // hashing function for strings is slow and the one we use as an overload is
  36. // not well suited for keys that are so very similar ("Render*"), such as for
  37. // feature names, causing most strings to go into the same unordered map
  38. // bucket. The std::map/set classes will be faster for this particular use...
  39. #include <map>
  40. #include <set>
  41. #include "stdtypes.h"
  42. #include "llstring.h"
  43. typedef enum EGPUClass
  44. {
  45. GPU_CLASS_UNKNOWN = -1,
  46. GPU_CLASS_0 = 0,
  47. GPU_CLASS_1,
  48. GPU_CLASS_2,
  49. GPU_CLASS_3,
  50. GPU_CLASS_4,
  51. GPU_CLASS_5
  52. } EGPUClass;
  53. class LLFeatureInfo
  54. {
  55. public:
  56. LLFeatureInfo()
  57. : mValid(false),
  58. mAvailable(false),
  59. mRecommendedLevel(-1.f)
  60. {
  61. }
  62. LLFeatureInfo(const std::string& name, bool available, F32 level);
  63. LL_INLINE bool isValid() const { return mValid; }
  64. public:
  65. F32 mRecommendedLevel;
  66. bool mValid;
  67. bool mAvailable;
  68. std::string mName;
  69. };
  70. class LLFeatureList
  71. {
  72. protected:
  73. LOG_CLASS(LLFeatureList);
  74. public:
  75. typedef std::map<std::string, LLFeatureInfo> feature_map_t;
  76. LLFeatureList(const std::string& name);
  77. virtual ~LLFeatureList() = default;
  78. bool isFeatureAvailable(const std::string& name);
  79. void setRecommendedLevel(const std::string& name, F32 level);
  80. void maskList(LLFeatureList& mask);
  81. void addFeature(const std::string& name, bool available, F32 level);
  82. LL_INLINE feature_map_t& getFeatures() { return mFeatures; }
  83. void dump();
  84. protected:
  85. std::string mName;
  86. feature_map_t mFeatures;
  87. };
  88. class LLFeatureManager : public LLFeatureList
  89. {
  90. protected:
  91. LOG_CLASS(LLFeatureManager);
  92. public:
  93. LL_INLINE LLFeatureManager()
  94. : LLFeatureList("default"),
  95. mTableVersion(0),
  96. mSafe(false),
  97. mGPUClass(GPU_CLASS_UNKNOWN),
  98. mGPUSupported(false),
  99. mGPUMemoryBandwidth(0)
  100. {
  101. }
  102. LL_INLINE ~LLFeatureManager() { cleanupFeatureTables(); }
  103. // initialize this by loading feature table and gpu table
  104. void init();
  105. // Mask the current feature list with the named list
  106. void maskCurrentList(const std::string& name);
  107. bool loadFeatureTables();
  108. LL_INLINE EGPUClass getGPUClass() const { return mGPUClass; }
  109. LL_INLINE const std::string& getGPUString() const
  110. {
  111. return mGPUString;
  112. }
  113. LL_INLINE bool isGPUSupported() const { return mGPUSupported; }
  114. LL_INLINE F32 getGPUMemoryBandwidth() const { return mGPUMemoryBandwidth; }
  115. void cleanupFeatureTables();
  116. LL_INLINE S32 getVersion() const { return mTableVersion; }
  117. LL_INLINE void setSafe(bool safe) { mSafe = safe; }
  118. LL_INLINE bool isSafe() const { return mSafe; }
  119. LLFeatureList* findMask(const std::string& name);
  120. bool maskFeatures(const std::string& name);
  121. // Set the graphics to low, medium, high, or ultra. skip_features forces
  122. // skipping of mostly hardware settings that we don't want to change when
  123. // we change graphics settings.
  124. void setGraphicsLevel(S32 level, bool skip_features);
  125. void applyBaseMasks();
  126. void applyRecommendedSettings();
  127. // Apply the basic masks. Also, skip one saved in the skip list if true
  128. void applyFeatures(bool skip_features);
  129. protected:
  130. void loadGPUClass(bool benchmark_gpu);
  131. void initBaseMask();
  132. static F32 benchmarkGPU();
  133. protected:
  134. S32 mTableVersion;
  135. std::map<std::string, LLFeatureList*> mMaskList;
  136. std::set<std::string> mSkippedFeatures;
  137. F32 mGPUMemoryBandwidth;
  138. EGPUClass mGPUClass;
  139. bool mGPUSupported;
  140. // To reinitialize everything to the "safe" mask:
  141. bool mSafe;
  142. std::string mGPUString;
  143. };
  144. extern LLFeatureManager gFeatureManager;
  145. #endif // LL_LLFEATUREMANAGER_H