Commit f0e79eb5 authored by nancylingwang@google.com's avatar nancylingwang@google.com Committed by Commit Bot

Modify ArcAppIcon to fetch two layer icons.

This is the preparing for the adaptive icon feature. For kUncompressed
and kCompressed, no change, just refactor.

Add a new type kAdaptive for ArcAppIcon to fetch both the foreground and
background image, which will be used for adaptive icons. Currently no
one uses the new type yet. There will be some follow up CLs to change
other code to use the new type kAdaptive, hidden with the flag for M85.

BUG=1083331

Change-Id: I0c078d6d9c821aa810c849bda04875a4a3155a60
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2249201
Commit-Queue: Nancy Wang <nancylingwang@chromium.org>
Reviewed-by: default avatarLong Cheng <lgcheng@google.com>
Reviewed-by: default avatarDominick Ng <dominickn@chromium.org>
Cr-Commit-Position: refs/heads/master@{#781210}
parent 483bd143
...@@ -17,6 +17,8 @@ ...@@ -17,6 +17,8 @@
#include "ui/gfx/image/image.h" #include "ui/gfx/image/image.h"
#include "ui/gfx/image/image_skia.h" #include "ui/gfx/image/image_skia.h"
struct ArcAppIconDescriptor;
namespace apps { namespace apps {
class ArcIconOnceLoader; class ArcIconOnceLoader;
} }
...@@ -52,6 +54,7 @@ class ArcAppIcon { ...@@ -52,6 +54,7 @@ class ArcAppIcon {
enum IconType { enum IconType {
kUncompressed, kUncompressed,
kCompressed, kCompressed,
kAdaptive,
}; };
ArcAppIcon(content::BrowserContext* context, ArcAppIcon(content::BrowserContext* context,
...@@ -84,6 +87,18 @@ class ArcAppIcon { ...@@ -84,6 +87,18 @@ class ArcAppIcon {
DCHECK_EQ(IconType::kCompressed, icon_type_); DCHECK_EQ(IconType::kCompressed, icon_type_);
return compressed_images_; return compressed_images_;
} }
// Returns |foreground_image_skia_| and valid if the |icon_type_| is
// IconType::kAdaptive.
const gfx::ImageSkia& foreground_image_skia() const {
DCHECK_EQ(IconType::kAdaptive, icon_type_);
return foreground_image_skia_;
}
// Returns |background_image_skia_| and valid if the |icon_type_| is
// IconType::kAdaptive.
const gfx::ImageSkia& background_image_skia() const {
DCHECK_EQ(IconType::kAdaptive, icon_type_);
return background_image_skia_;
}
// Disables async safe decoding requests when unit tests are executed. This is // Disables async safe decoding requests when unit tests are executed. This is
// done to avoid two problems. Problems come because icons are decoded at a // done to avoid two problems. Problems come because icons are decoded at a
...@@ -124,12 +139,36 @@ class ArcAppIcon { ...@@ -124,12 +139,36 @@ class ArcAppIcon {
void LoadForScaleFactor(ui::ScaleFactor scale_factor); void LoadForScaleFactor(ui::ScaleFactor scale_factor);
void MaybeRequestIcon(ui::ScaleFactor scale_factor); void MaybeRequestIcon(ui::ScaleFactor scale_factor);
static std::unique_ptr<ArcAppIcon::ReadResult> ReadOnFileThread( static std::unique_ptr<ArcAppIcon::ReadResult> ReadOnBackgroundThread(
ArcAppIcon::IconType icon_type,
ui::ScaleFactor scale_factor,
const std::vector<base::FilePath>& paths,
const base::FilePath& default_app_path);
static std::unique_ptr<ArcAppIcon::ReadResult> ReadSingleIconFile(
ui::ScaleFactor scale_factor, ui::ScaleFactor scale_factor,
const base::FilePath& path, const base::FilePath& path,
const base::FilePath& default_app_path); const base::FilePath& default_app_path);
static std::unique_ptr<ArcAppIcon::ReadResult> ReadAdaptiveIconFiles(
ui::ScaleFactor scale_factor,
const std::vector<base::FilePath>& paths,
const base::FilePath& default_app_path);
static std::unique_ptr<ArcAppIcon::ReadResult> ReadFile(
bool request_to_install,
ui::ScaleFactor scale_factor,
bool resize_allowed,
const base::FilePath& path);
void OnIconRead(std::unique_ptr<ArcAppIcon::ReadResult> read_result); void OnIconRead(std::unique_ptr<ArcAppIcon::ReadResult> read_result);
void UpdateUncompressed(ui::ScaleFactor scale_factor, const SkBitmap& bitmap); void DecodeImage(
const std::string& unsafe_icon_data,
const ArcAppIconDescriptor& descriptor,
bool resize_allowed,
gfx::ImageSkia& image_skia,
std::map<ui::ScaleFactor, base::Time>& incomplete_scale_factors);
void UpdateImageSkia(
ui::ScaleFactor scale_factor,
const SkBitmap& bitmap,
gfx::ImageSkia& image_skia,
std::map<ui::ScaleFactor, base::Time>& incomplete_scale_factors);
void UpdateCompressed(ui::ScaleFactor scale_factor, std::string data); void UpdateCompressed(ui::ScaleFactor scale_factor, std::string data);
void DiscardDecodeRequest(DecodeRequest* request); void DiscardDecodeRequest(DecodeRequest* request);
...@@ -148,7 +187,12 @@ class ArcAppIcon { ...@@ -148,7 +187,12 @@ class ArcAppIcon {
gfx::ImageSkia image_skia_; gfx::ImageSkia image_skia_;
std::map<ui::ScaleFactor, std::string> compressed_images_; std::map<ui::ScaleFactor, std::string> compressed_images_;
gfx::ImageSkia foreground_image_skia_;
gfx::ImageSkia background_image_skia_;
std::map<ui::ScaleFactor, base::Time> incomplete_scale_factors_; std::map<ui::ScaleFactor, base::Time> incomplete_scale_factors_;
std::map<ui::ScaleFactor, base::Time> foreground_incomplete_scale_factors_;
std::map<ui::ScaleFactor, base::Time> background_incomplete_scale_factors_;
// Contains pending image decode requests. // Contains pending image decode requests.
std::vector<std::unique_ptr<DecodeRequest>> decode_requests_; std::vector<std::unique_ptr<DecodeRequest>> decode_requests_;
......
...@@ -18,6 +18,8 @@ int GetScalePercent(ui::ScaleFactor scale_factor) { ...@@ -18,6 +18,8 @@ int GetScalePercent(ui::ScaleFactor scale_factor) {
// Template for the icon name. First part is scale percent and second is // Template for the icon name. First part is scale percent and second is
// resource size in dip. // resource size in dip.
constexpr char kIconNameTemplate[] = "icon_%dp_%d.png"; constexpr char kIconNameTemplate[] = "icon_%dp_%d.png";
constexpr char kForegroundIconNameTemplate[] = "foreground_icon_%dp_%d.png";
constexpr char kBackgroundIconNameTemplate[] = "background_icon_%dp_%d.png";
} // namespace } // namespace
...@@ -38,6 +40,16 @@ std::string ArcAppIconDescriptor::GetName() const { ...@@ -38,6 +40,16 @@ std::string ArcAppIconDescriptor::GetName() const {
dip_size); dip_size);
} }
std::string ArcAppIconDescriptor::GetForegroundIconName() const {
return base::StringPrintf(kForegroundIconNameTemplate,
GetScalePercent(scale_factor), dip_size);
}
std::string ArcAppIconDescriptor::GetBackgroundIconName() const {
return base::StringPrintf(kBackgroundIconNameTemplate,
GetScalePercent(scale_factor), dip_size);
}
bool ArcAppIconDescriptor::operator==(const ArcAppIconDescriptor& other) const { bool ArcAppIconDescriptor::operator==(const ArcAppIconDescriptor& other) const {
return scale_factor == other.scale_factor && dip_size == other.dip_size; return scale_factor == other.scale_factor && dip_size == other.dip_size;
} }
......
...@@ -16,6 +16,10 @@ struct ArcAppIconDescriptor { ...@@ -16,6 +16,10 @@ struct ArcAppIconDescriptor {
int GetSizeInPixels() const; int GetSizeInPixels() const;
// Used as a file name to store icon on the disk. // Used as a file name to store icon on the disk.
std::string GetName() const; std::string GetName() const;
// Used as a file name to store the foreground icon on the disk.
std::string GetForegroundIconName() const;
// Used as a file name to store the background icon on the disk.
std::string GetBackgroundIconName() const;
bool operator==(const ArcAppIconDescriptor& other) const; bool operator==(const ArcAppIconDescriptor& other) const;
bool operator!=(const ArcAppIconDescriptor& other) const; bool operator!=(const ArcAppIconDescriptor& other) const;
......
...@@ -413,6 +413,20 @@ base::FilePath ArcAppListPrefs::GetIconPath( ...@@ -413,6 +413,20 @@ base::FilePath ArcAppListPrefs::GetIconPath(
return GetAppPath(app_id).AppendASCII(descriptor.GetName()); return GetAppPath(app_id).AppendASCII(descriptor.GetName());
} }
base::FilePath ArcAppListPrefs::GetForegroundIconPath(
const std::string& app_id,
const ArcAppIconDescriptor& descriptor) {
active_icons_[app_id].insert(descriptor);
return GetAppPath(app_id).AppendASCII(descriptor.GetForegroundIconName());
}
// Constructs path to the app background icon for specific scale factor.
base::FilePath ArcAppListPrefs::GetBackgroundIconPath(
const std::string& app_id,
const ArcAppIconDescriptor& descriptor) {
active_icons_[app_id].insert(descriptor);
return GetAppPath(app_id).AppendASCII(descriptor.GetBackgroundIconName());
}
bool ArcAppListPrefs::IsIconRequestRecorded( bool ArcAppListPrefs::IsIconRequestRecorded(
const std::string& app_id, const std::string& app_id,
const ArcAppIconDescriptor& descriptor) const { const ArcAppIconDescriptor& descriptor) const {
......
...@@ -273,6 +273,12 @@ class ArcAppListPrefs : public KeyedService, ...@@ -273,6 +273,12 @@ class ArcAppListPrefs : public KeyedService,
// Constructs path to app icon for specific scale factor. // Constructs path to app icon for specific scale factor.
base::FilePath GetIconPath(const std::string& app_id, base::FilePath GetIconPath(const std::string& app_id,
const ArcAppIconDescriptor& descriptor); const ArcAppIconDescriptor& descriptor);
// Constructs path to the app foreground icon for specific scale factor.
base::FilePath GetForegroundIconPath(const std::string& app_id,
const ArcAppIconDescriptor& descriptor);
// Constructs path to the app background icon for specific scale factor.
base::FilePath GetBackgroundIconPath(const std::string& app_id,
const ArcAppIconDescriptor& descriptor);
// Constructs path to default app icon for specific scale factor. This path // Constructs path to default app icon for specific scale factor. This path
// is used to resolve icon if no icon is available at |GetIconPath|. // is used to resolve icon if no icon is available at |GetIconPath|.
base::FilePath MaybeGetIconPathForDefaultApp( base::FilePath MaybeGetIconPathForDefaultApp(
......
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