Skip to content

Commit ebe69ea

Browse files
author
yifeidong
committed
Add a mip level filter
- Add a slider in the Resource list to filter resources by mip level.
1 parent 84380c6 commit ebe69ea

16 files changed

Lines changed: 230 additions & 9 deletions

source/frontend/models/proxy_models/resource_proxy_model.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ namespace rmv
6666
return false;
6767
}
6868

69+
if (FilterMipLevelSlider(source_row, kResourceColumnMipLevel, source_parent) == false)
70+
{
71+
return false;
72+
}
73+
6974
// Apply the range-based searching to the virtual address and resource size.
7075
// Only fail if the search string is outside the address range.
7176
bool found_range = false;

source/frontend/models/proxy_models/table_proxy_model.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ namespace rmv
1313
: QSortFilterProxyModel(parent)
1414
, min_size_(0)
1515
, max_size_(UINT64_MAX)
16+
, min_mip_level_(1)
17+
, max_mip_level_(UINT64_MAX)
1618
{
1719
}
1820

@@ -42,6 +44,12 @@ namespace rmv
4244
max_size_ = max;
4345
}
4446

47+
void TableProxyModel::SetMipLevelFilter(uint64_t min, uint64_t max)
48+
{
49+
min_mip_level_ = min;
50+
max_mip_level_ = max;
51+
}
52+
4553
uint64_t TableProxyModel::GetIndexValue(const QModelIndex& index) const
4654
{
4755
const QString data = sourceModel()->data(index).toString();
@@ -108,6 +116,14 @@ namespace rmv
108116
return !(size < min_size_ || size > max_size_);
109117
}
110118

119+
bool TableProxyModel::FilterMipLevelSlider(int row, int column, const QModelIndex& source_parent) const
120+
{
121+
const QModelIndex& mip_filter_index = sourceModel()->index(row, column, source_parent);
122+
const uint32_t mip_level = mip_filter_index.data(Qt::UserRole).toUInt();
123+
124+
return mip_level == 0 || !(mip_level < min_mip_level_ || mip_level > max_mip_level_);
125+
}
126+
111127
bool TableProxyModel::FilterSearchString(int row, const QModelIndex& source_parent) const
112128
{
113129
if (column_filters_.empty() == false && search_filter_.isEmpty() == false)

source/frontend/models/proxy_models/table_proxy_model.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ namespace rmv
4444
/// @param [in] max The maximum size.
4545
void SetSizeFilter(uint64_t min, uint64_t max);
4646

47+
/// @brief Specify range to use as mip level filter.
48+
///
49+
/// @param [in] min The minimum mip level.
50+
/// @param [in] max The maximum mip level.
51+
void SetMipLevelFilter(uint64_t min, uint64_t max);
52+
4753
/// @brief Get content from proxy model.
4854
///
4955
/// @param [in] row The row where the data is located.
@@ -98,6 +104,15 @@ namespace rmv
98104
/// @return true if the table item at row,column is to be shown, false if not.
99105
bool FilterSizeSlider(int row, int column, const QModelIndex& source_parent) const;
100106

107+
/// @brief Filter the mip level slider.
108+
///
109+
/// @param [in] row The row to apply the mip level filter to.
110+
/// @param [in] column The column to apply the mip level filter to.
111+
/// @param [in] source_parent The parent model index in the source model.
112+
///
113+
/// @return true if the table item at row,column is to be shown, false if not.
114+
bool FilterMipLevelSlider(int row, int column, const QModelIndex& source_parent) const;
115+
101116
/// @brief Filter the search string.
102117
///
103118
/// @param [in] row The row to apply the size filter to.
@@ -117,6 +132,8 @@ namespace rmv
117132
QString search_filter_; ///< The current search string.
118133
uint64_t min_size_; ///< The minimum size of the size filter.
119134
uint64_t max_size_; ///< The maximum size of the size filter.
135+
uint64_t min_mip_level_; ///< The minimum size of the mip level filter.
136+
uint64_t max_mip_level_; ///< The maximum size of the mip level filter.
120137
};
121138
} // namespace rmv
122139

source/frontend/models/snapshot/resource_list_model.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,17 @@ namespace rmv
134134
UpdateBottomLabels();
135135
}
136136

137+
void ResourceListModel::FilterByMipLevelChanged(int min_value, int max_value)
138+
{
139+
const uint64_t scaled_min = rmv_util::CalculateThresholdFromStepValue(min_value, rmv::kMipSliderRange - 1);
140+
const uint64_t scaled_max = rmv_util::CalculateThresholdFromStepValue(max_value, rmv::kMipSliderRange - 1);
141+
142+
proxy_model_->SetMipLevelFilter(scaled_min, scaled_max);
143+
proxy_model_->invalidate();
144+
145+
UpdateBottomLabels();
146+
}
147+
137148
ResourceProxyModel* ResourceListModel::GetResourceProxyModel() const
138149
{
139150
return proxy_model_;

source/frontend/models/snapshot/resource_list_model.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@ namespace rmv
5757
/// @param [in] max_value Maximum value of slider span.
5858
void FilterBySizeChanged(int min_value, int max_value);
5959

60+
/// @brief Handle what happens when the mip level filter changes.
61+
///
62+
/// @param [in] min_value Minimum value of slider span.
63+
/// @param [in] max_value Maximum value of slider span.
64+
void FilterByMipLevelChanged(int min_value, int max_value);
65+
6066
/// @brief Read the dataset and update model.
6167
void Update();
6268

source/frontend/util/constants.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ namespace rmv
5555
static const int kHeapComboBoxWidth = 140;
5656
static const int kResourceComboBoxWidth = 140;
5757
static const int kSizeSliderRange = 25;
58+
static const int kMipSliderRange = 16;
5859

5960
// Control window sizes.
6061
static const int kDesktopMargin = 25;

source/frontend/util/rmv_util.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,16 @@ uint64_t rmv_util::CalculateSizeThresholdFromStepValue(const uint32_t step_value
185185
return pow(2, step_value + kThresholdStepOffset);
186186
}
187187

188+
uint64_t rmv_util::CalculateThresholdFromStepValue(const uint32_t step_value, const uint32_t max_steps)
189+
{
190+
if (step_value >= max_steps)
191+
{
192+
return UINT64_MAX;
193+
}
194+
195+
return step_value;
196+
}
197+
188198
QString rmv_util::GetVirtualAllocationName(const RmtVirtualAllocation* virtual_allocation)
189199
{
190200
QString allocation_name;

source/frontend/util/rmv_util.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,14 @@ namespace rmv_util
8484
/// @return The calculated value.
8585
uint64_t CalculateSizeThresholdFromStepValue(const uint32_t step_value, const uint32_t max_steps);
8686

87+
/// @brief Calculate the mapped value given a step value.
88+
///
89+
/// @param [in] step_value An unmapped whole number used to calculate a mapped threshold value.
90+
/// @param [in] max_steps The maximum number of steps in the range.
91+
///
92+
/// @return The calculated value.
93+
uint64_t CalculateThresholdFromStepValue(const uint32_t step_value, const uint32_t max_steps);
94+
8795
/// @brief Retrieves the name of a virtual allocation or a string containing the base address in hexadecimal form.
8896
///
8997
/// @param [in] virtual_allocation A pointer to the virtual allocation object.

source/frontend/util/string_util.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,3 +188,36 @@ QString rmv::string_util::GetMemoryRangeString(const uint64_t min_memory_size, c
188188

189189
return range_string;
190190
}
191+
192+
QString rmv::string_util::GetValueRangeString(const uint64_t min, const uint64_t max)
193+
{
194+
const static char kHyphen[] = " - ";
195+
const static char kInfinity[] = "\xE2\x88\x9E";
196+
QString range_string;
197+
198+
// Append string for range start.
199+
if (min == UINT64_MAX)
200+
{
201+
range_string += kInfinity;
202+
}
203+
else
204+
{
205+
QString value = string_util::LocalizedValue(min);
206+
range_string += value;
207+
}
208+
209+
range_string += kHyphen;
210+
211+
// Append string for range end.
212+
if (max == UINT64_MAX)
213+
{
214+
range_string += kInfinity;
215+
}
216+
else
217+
{
218+
QString value = string_util::LocalizedValue(max);
219+
range_string += value;
220+
}
221+
222+
return range_string;
223+
}

source/frontend/util/string_util.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,13 @@ namespace rmv
8888
/// @return The localized string.
8989
QString GetMemoryRangeString(const uint64_t min_memory_size, const uint64_t max_memory_size);
9090

91+
/// @brief Builds a range string for two int values.
92+
///
93+
/// @param [in] min The lower value of the range.
94+
/// @param [in] max The upper value of the range.
95+
///
96+
/// @return The localized string.
97+
QString GetValueRangeString(const uint64_t min, const uint64_t max);
9198
} // namespace string_util
9299
} // namespace rmv
93100

0 commit comments

Comments
 (0)