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,31 +822,30 @@ bool ResourceBundle::LoadBitmap(int resource_id, ...@@ -822,31 +822,30 @@ bool ResourceBundle::LoadBitmap(int resource_id,
SkBitmap* bitmap, SkBitmap* bitmap,
bool* fell_back_to_1x) const { bool* fell_back_to_1x) const {
DCHECK(fell_back_to_1x); DCHECK(fell_back_to_1x);
ResourceHandle* data_handle_100_percent = nullptr; for (const auto& pack : data_packs_) {
for (size_t i = 0; i < data_packs_.size(); ++i) { if (pack->GetScaleFactor() == ui::SCALE_FACTOR_NONE &&
if (data_packs_[i]->GetScaleFactor() == ui::SCALE_FACTOR_NONE && LoadBitmap(*pack, resource_id, bitmap, fell_back_to_1x)) {
LoadBitmap(*data_packs_[i], resource_id, bitmap, fell_back_to_1x)) {
DCHECK(!*fell_back_to_1x); DCHECK(!*fell_back_to_1x);
*scale_factor = ui::SCALE_FACTOR_NONE; *scale_factor = ui::SCALE_FACTOR_NONE;
return true; 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 && if (pack->GetScaleFactor() == *scale_factor &&
LoadBitmap(*data_packs_[i], resource_id, bitmap, fell_back_to_1x)) { LoadBitmap(*pack, resource_id, bitmap, fell_back_to_1x)) {
return true; return true;
} }
} }
// Unit tests may only have 1x data pack. Allow them to fallback to 1x // Unit tests may only have 1x data pack. Allow them to fallback to 1x
// resources. // resources.
if (*scale_factor != ui::SCALE_FACTOR_100P && is_test_resources_ && if (is_test_resources_ && *scale_factor != ui::SCALE_FACTOR_100P) {
data_handle_100_percent && for (const auto& pack : data_packs_) {
LoadBitmap(*data_handle_100_percent, resource_id, bitmap, if (pack->GetScaleFactor() == ui::SCALE_FACTOR_100P &&
fell_back_to_1x)) { LoadBitmap(*pack, resource_id, bitmap, fell_back_to_1x)) {
*fell_back_to_1x = true; *fell_back_to_1x = true;
return true; return true;
}
}
} }
return false; return false;
......
...@@ -355,7 +355,7 @@ class UI_BASE_EXPORT ResourceBundle { ...@@ -355,7 +355,7 @@ class UI_BASE_EXPORT ResourceBundle {
// Fills the |bitmap| given the |resource_id| and |scale_factor|. // Fills the |bitmap| given the |resource_id| and |scale_factor|.
// Returns false if the resource does not exist. This may fall back to // Returns false if the resource does not exist. This may fall back to
// the data pack with SCALE_FACTOR_NONE, and when this happens, // 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, bool LoadBitmap(int resource_id,
ScaleFactor* scale_factor, ScaleFactor* scale_factor,
SkBitmap* bitmap, 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