Commit 16fe4402 authored by tapted's avatar tapted Committed by Commit bot

In test code, allow any 100% data pack to provide fallbacks.

A test is allowed to request a 200% resource and fallback to a 100%
resource. Currently only the last-added 100% data pack provides
fallbacks, which may only be a small supplement.

Instead, scan through all 100% data packs. But only when
InitSharedInstanceWithPakPath() has invoked
ResourceBundle::LoadTestResources().

BUG=636995

Review-Url: https://codereview.chromium.org/2406763002
Cr-Commit-Position: refs/heads/master@{#427272}
parent df6cf99f
......@@ -822,32 +822,31 @@ bool ResourceBundle::LoadBitmap(int resource_id,
SkBitmap* bitmap,
bool* fell_back_to_1x) const {
DCHECK(fell_back_to_1x);
ResourceHandle* data_handle_100_percent = nullptr;
for (size_t i = 0; i < data_packs_.size(); ++i) {
if (data_packs_[i]->GetScaleFactor() == ui::SCALE_FACTOR_NONE &&
LoadBitmap(*data_packs_[i], resource_id, bitmap, fell_back_to_1x)) {
for (const auto& pack : data_packs_) {
if (pack->GetScaleFactor() == ui::SCALE_FACTOR_NONE &&
LoadBitmap(*pack, resource_id, bitmap, fell_back_to_1x)) {
DCHECK(!*fell_back_to_1x);
*scale_factor = ui::SCALE_FACTOR_NONE;
return true;
}
if (data_packs_[i]->GetScaleFactor() == ui::SCALE_FACTOR_100P)
data_handle_100_percent = data_packs_[i];
if (data_packs_[i]->GetScaleFactor() == *scale_factor &&
LoadBitmap(*data_packs_[i], resource_id, bitmap, fell_back_to_1x)) {
if (pack->GetScaleFactor() == *scale_factor &&
LoadBitmap(*pack, resource_id, bitmap, fell_back_to_1x)) {
return true;
}
}
// Unit tests may only have 1x data pack. Allow them to fallback to 1x
// resources.
if (*scale_factor != ui::SCALE_FACTOR_100P && is_test_resources_ &&
data_handle_100_percent &&
LoadBitmap(*data_handle_100_percent, resource_id, bitmap,
fell_back_to_1x)) {
if (is_test_resources_ && *scale_factor != ui::SCALE_FACTOR_100P) {
for (const auto& pack : data_packs_) {
if (pack->GetScaleFactor() == ui::SCALE_FACTOR_100P &&
LoadBitmap(*pack, resource_id, bitmap, fell_back_to_1x)) {
*fell_back_to_1x = true;
return true;
}
}
}
return false;
}
......
......@@ -355,7 +355,7 @@ class UI_BASE_EXPORT ResourceBundle {
// Fills the |bitmap| given the |resource_id| and |scale_factor|.
// Returns false if the resource does not exist. This may fall back to
// the data pack with SCALE_FACTOR_NONE, and when this happens,
// |scale_factor| will be set to SCALE_FACTOR_100P.
// |scale_factor| will be set to SCALE_FACTOR_NONE.
bool LoadBitmap(int resource_id,
ScaleFactor* scale_factor,
SkBitmap* bitmap,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment