Commit 5fd46c2e authored by Alexey Baskakov's avatar Alexey Baskakov Committed by Commit Bot

dpwa: Fix blurry icons in chrome://apps UI.

The last compression step should take scaled skia image representation
as the input:

We should compress the image with the proper intended scale.

Drive-by: Remove two duplicate apps_util::ConvertDipToPx() calls.

Background: see previous change
https://chromium-review.googlesource.com/c/chromium/src/+/2325349

Bug: 1112737
Change-Id: I16226014840408fc6b4792081fb528d411122de6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2338335
Commit-Queue: Alexey Baskakov <loyso@chromium.org>
Reviewed-by: default avatarDaniel Murphy <dmurph@chromium.org>
Reviewed-by: default avatarDominick Ng <dominickn@chromium.org>
Cr-Commit-Position: refs/heads/master@{#796327}
parent a5ee41d4
...@@ -391,6 +391,9 @@ class IconLoadingPipeline : public base::RefCounted<IconLoadingPipeline> { ...@@ -391,6 +391,9 @@ class IconLoadingPipeline : public base::RefCounted<IconLoadingPipeline> {
// The scale factor the icon is intended for. See gfx::ImageSkiaRep::scale // The scale factor the icon is intended for. See gfx::ImageSkiaRep::scale
// comments. // comments.
float icon_scale_ = 0.0f; float icon_scale_ = 0.0f;
// A scale factor to take as input for the IconType::kCompressed response. See
// gfx::ImageSkia::GetRepresentation() comments.
float icon_scale_for_compressed_response_ = 1.0f;
bool is_placeholder_icon_; bool is_placeholder_icon_;
apps::IconEffects icon_effects_; apps::IconEffects icon_effects_;
...@@ -441,6 +444,16 @@ void IconLoadingPipeline::LoadWebAppIcon( ...@@ -441,6 +444,16 @@ void IconLoadingPipeline::LoadWebAppIcon(
fallback_favicon_url_ = launch_url; fallback_favicon_url_ = launch_url;
profile_ = profile; profile_ = profile;
// In all other callpaths MaybeApplyEffectsAndComplete() uses
// |icon_scale_for_compressed_response_| to apps::EncodeImageToPngBytes(). In
// most cases IconLoadingPipeline always uses the 1.0 intended icon scale
// factor as an intermediate representation to be compressed and returned.
// TODO(crbug.com/1112737): Investigate how to unify it and set
// |icon_scale_for_compressed_response_| value in IconLoadingPipeline()
// constructor.
icon_scale_for_compressed_response_ = icon_scale_;
if (icon_manager.HasSmallestIcon(web_app_id, icon_size_in_px_)) { if (icon_manager.HasSmallestIcon(web_app_id, icon_size_in_px_)) {
switch (icon_type_) { switch (icon_type_) {
case apps::mojom::IconType::kCompressed: case apps::mojom::IconType::kCompressed:
...@@ -509,11 +522,8 @@ void IconLoadingPipeline::LoadExtensionIcon( ...@@ -509,11 +522,8 @@ void IconLoadingPipeline::LoadExtensionIcon(
// LoadImageAtEveryScaleFactorAsync here, because the caller has asked // LoadImageAtEveryScaleFactorAsync here, because the caller has asked
// for compressed icons (i.e. PNG-formatted data), not uncompressed // for compressed icons (i.e. PNG-formatted data), not uncompressed
// (i.e. a gfx::ImageSkia). // (i.e. a gfx::ImageSkia).
constexpr bool quantize_to_supported_scale_factor = true;
int size_hint_in_px = apps_util::ConvertDipToPx(
size_hint_in_dip_, quantize_to_supported_scale_factor);
LoadCompressedDataFromExtension( LoadCompressedDataFromExtension(
extension, size_hint_in_px, extension, icon_size_in_px_,
base::BindOnce(&IconLoadingPipeline::CompleteWithCompressed, base::BindOnce(&IconLoadingPipeline::CompleteWithCompressed,
base::WrapRefCounted(this))); base::WrapRefCounted(this)));
return; return;
...@@ -774,7 +784,8 @@ void IconLoadingPipeline::MaybeApplyEffectsAndComplete( ...@@ -774,7 +784,8 @@ void IconLoadingPipeline::MaybeApplyEffectsAndComplete(
processed_image.MakeThreadSafe(); processed_image.MakeThreadSafe();
base::ThreadPool::PostTaskAndReplyWithResult( base::ThreadPool::PostTaskAndReplyWithResult(
FROM_HERE, {base::MayBlock(), base::TaskPriority::USER_VISIBLE}, FROM_HERE, {base::MayBlock(), base::TaskPriority::USER_VISIBLE},
base::BindOnce(&apps::EncodeImageToPngBytes, processed_image), base::BindOnce(&apps::EncodeImageToPngBytes, processed_image,
icon_scale_for_compressed_response_),
base::BindOnce(&IconLoadingPipeline::CompleteWithCompressed, base::BindOnce(&IconLoadingPipeline::CompleteWithCompressed,
base::WrapRefCounted(this))); base::WrapRefCounted(this)));
} }
...@@ -807,10 +818,8 @@ void IconLoadingPipeline::CompleteWithImageSkia(gfx::ImageSkia image) { ...@@ -807,10 +818,8 @@ void IconLoadingPipeline::CompleteWithImageSkia(gfx::ImageSkia image) {
} }
void IconLoadingPipeline::MaybeLoadFallbackOrCompleteEmpty() { void IconLoadingPipeline::MaybeLoadFallbackOrCompleteEmpty() {
const int icon_size_in_px = apps_util::ConvertDipToPx(
size_hint_in_dip_, /*quantize_to_supported_scale_factor=*/true);
if (fallback_favicon_url_.is_valid() && if (fallback_favicon_url_.is_valid() &&
icon_size_in_px == kFaviconFallbackImagePx) { icon_size_in_px_ == kFaviconFallbackImagePx) {
GURL favicon_url = fallback_favicon_url_; GURL favicon_url = fallback_favicon_url_;
// Reset to avoid infinite loops. // Reset to avoid infinite loops.
fallback_favicon_url_ = GURL(); fallback_favicon_url_ = GURL();
...@@ -899,14 +908,16 @@ CompressedDataToImageSkiaCallback( ...@@ -899,14 +908,16 @@ CompressedDataToImageSkiaCallback(
std::move(callback), icon_scale); std::move(callback), icon_scale);
} }
std::vector<uint8_t> EncodeImageToPngBytes(const gfx::ImageSkia image) { std::vector<uint8_t> EncodeImageToPngBytes(const gfx::ImageSkia image,
float rep_icon_scale) {
base::ScopedBlockingCall scoped_blocking_call(FROM_HERE, base::ScopedBlockingCall scoped_blocking_call(FROM_HERE,
base::BlockingType::MAY_BLOCK); base::BlockingType::MAY_BLOCK);
std::vector<uint8_t> image_data; std::vector<uint8_t> image_data;
const gfx::ImageSkiaRep& image_skia_rep = image.GetRepresentation(1.0f); const gfx::ImageSkiaRep& image_skia_rep =
if (image_skia_rep.scale() != 1.0f) { image.GetRepresentation(rep_icon_scale);
if (image_skia_rep.scale() != rep_icon_scale) {
return image_data; return image_data;
} }
......
...@@ -60,10 +60,12 @@ CompressedDataToImageSkiaCallback( ...@@ -60,10 +60,12 @@ CompressedDataToImageSkiaCallback(
base::OnceCallback<void(gfx::ImageSkia)> callback, base::OnceCallback<void(gfx::ImageSkia)> callback,
float icon_scale); float icon_scale);
// Encode the ImageSkia to the compressed PNG data with the image's 1.0f scale // Encodes a single SkBitmap representation from the given ImageSkia to the
// factor representation. Return the encoded PNG data. // compressed PNG data. |rep_icon_scale| argument denotes, which ImageSkiaRep to
// This function should not be called on the UI thread. // take as input. See ImageSkia::GetRepresentation() comments. Returns the
std::vector<uint8_t> EncodeImageToPngBytes(const gfx::ImageSkia image); // encoded PNG data. This function should not be called on the UI thread.
std::vector<uint8_t> EncodeImageToPngBytes(const gfx::ImageSkia image,
float rep_icon_scale);
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
void ArcRawIconPngDataToImageSkia( void ArcRawIconPngDataToImageSkia(
......
...@@ -130,7 +130,8 @@ void OnArcAppIconCompletelyLoaded( ...@@ -130,7 +130,8 @@ void OnArcAppIconCompletelyLoaded(
iv->uncompressed.MakeThreadSafe(); iv->uncompressed.MakeThreadSafe();
base::ThreadPool::PostTaskAndReplyWithResult( base::ThreadPool::PostTaskAndReplyWithResult(
FROM_HERE, {base::MayBlock(), base::TaskPriority::USER_VISIBLE}, FROM_HERE, {base::MayBlock(), base::TaskPriority::USER_VISIBLE},
base::BindOnce(&apps::EncodeImageToPngBytes, iv->uncompressed), base::BindOnce(&apps::EncodeImageToPngBytes, iv->uncompressed,
/*rep_icon_scale=*/1.0f),
base::BindOnce(&CompleteWithCompressed, std::move(callback))); base::BindOnce(&CompleteWithCompressed, std::move(callback)));
return; return;
} }
......
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