Commit 84de1c55 authored by Vladislav Kaznacheev's avatar Vladislav Kaznacheev Committed by Commit Bot

Normalize Play Store search result icons

Apply MD icon normalizer to icons returned by Play Store search
to ensure that the they are roughly the same size as regular app icons.

Bug: 900685
Test: manual
Change-Id: I1960397c1ef3179590cccaac4fd69176849bce17
Reviewed-on: https://chromium-review.googlesource.com/c/1310915Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Commit-Queue: Vladislav Kaznacheev <kaznacheev@chromium.org>
Cr-Commit-Position: refs/heads/master@{#604576}
parent f2a67dbe
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include <utility> #include <utility>
#include <vector> #include <vector>
#include "chrome/browser/ui/app_list/md_icon_normalizer.h"
#include "chrome/grit/component_extension_resources.h" #include "chrome/grit/component_extension_resources.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "ui/base/resource/resource_bundle.h" #include "ui/base/resource/resource_bundle.h"
...@@ -28,52 +29,53 @@ bool disable_safe_decoding_for_testing = false; ...@@ -28,52 +29,53 @@ bool disable_safe_decoding_for_testing = false;
class IconSource : public gfx::ImageSkiaSource { class IconSource : public gfx::ImageSkiaSource {
public: public:
IconSource(const SkBitmap& decoded_bitmap, int resource_size_in_dip); IconSource(const SkBitmap& bitmap, int dimension_dip, bool normalize);
explicit IconSource(int resource_size_in_dip);
~IconSource() override = default; ~IconSource() override = default;
void SetDecodedImage(const SkBitmap& decoded_bitmap);
private: private:
gfx::ImageSkiaRep GetImageForScale(float scale) override; gfx::ImageSkiaRep GetImageForScale(float scale) override;
const int resource_size_in_dip_; const SkBitmap bitmap_;
gfx::ImageSkia decoded_icon_; const int dimension_dip_;
const bool normalize_;
DISALLOW_COPY_AND_ASSIGN(IconSource); DISALLOW_COPY_AND_ASSIGN(IconSource);
}; };
IconSource::IconSource(int resource_size_in_dip) IconSource::IconSource(const SkBitmap& bitmap,
: resource_size_in_dip_(resource_size_in_dip) {} int dimension_dip,
bool normalize)
void IconSource::SetDecodedImage(const SkBitmap& decoded_bitmap) { : bitmap_(bitmap), dimension_dip_(dimension_dip), normalize_(normalize) {}
decoded_icon_.AddRepresentation(gfx::ImageSkiaRep(
decoded_bitmap, ui::GetScaleForScaleFactor(ui::SCALE_FACTOR_100P)));
}
gfx::ImageSkiaRep IconSource::GetImageForScale(float scale) { gfx::ImageSkiaRep IconSource::GetImageForScale(float scale) {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
// We use the icon if it was decoded successfully, otherwise use the default const int dimension_px = static_cast<int>(dimension_dip_ * scale + 0.5);
// ARC icon. if (bitmap_.isNull()) {
const gfx::ImageSkia* icon_to_scale; const int resource_id =
if (decoded_icon_.isNull()) { dimension_px <= 32 ? IDR_ARC_SUPPORT_ICON_32 : IDR_ARC_SUPPORT_ICON_192;
const int resource_size_in_px = const gfx::ImageSkia* resource_image =
static_cast<int>(resource_size_in_dip_ * scale + 0.5);
const int resource_id = resource_size_in_px <= 32
? IDR_ARC_SUPPORT_ICON_32
: IDR_ARC_SUPPORT_ICON_192;
icon_to_scale =
ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(resource_id); ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(resource_id);
} else { const gfx::ImageSkia resized_image =
icon_to_scale = &decoded_icon_; gfx::ImageSkiaOperations::CreateResizedImage(
*resource_image, skia::ImageOperations::RESIZE_LANCZOS3,
gfx::Size(dimension_dip_, dimension_dip_));
return resized_image.GetRepresentation(scale);
} }
DCHECK(icon_to_scale);
gfx::ImageSkia resized_image = gfx::ImageSkiaOperations::CreateResizedImage( SkBitmap resized_bitmap;
*icon_to_scale, skia::ImageOperations::RESIZE_BEST, if (normalize_) {
gfx::Size(resource_size_in_dip_, resource_size_in_dip_)); resized_bitmap = bitmap_;
return resized_image.GetRepresentation(scale); const gfx::Size size_px(dimension_px, dimension_px);
const gfx::Size padding_px =
app_list::GetMdIconPadding(resized_bitmap, size_px);
app_list::MaybeResizeAndPad(size_px, padding_px, &resized_bitmap);
} else {
resized_bitmap = skia::ImageOperations::Resize(
bitmap_, skia::ImageOperations::RESIZE_LANCZOS3, dimension_px,
dimension_px);
}
return gfx::ImageSkiaRep(resized_bitmap, scale);
} }
} // namespace } // namespace
...@@ -84,9 +86,9 @@ void IconDecodeRequest::DisableSafeDecodingForTesting() { ...@@ -84,9 +86,9 @@ void IconDecodeRequest::DisableSafeDecodingForTesting() {
} }
IconDecodeRequest::IconDecodeRequest(SetIconCallback set_icon_callback, IconDecodeRequest::IconDecodeRequest(SetIconCallback set_icon_callback,
int requested_size) int dimension_dip)
: set_icon_callback_(std::move(set_icon_callback)), : set_icon_callback_(std::move(set_icon_callback)),
requested_size_(requested_size) {} dimension_dip_(dimension_dip) {}
IconDecodeRequest::~IconDecodeRequest() = default; IconDecodeRequest::~IconDecodeRequest() = default;
...@@ -113,28 +115,17 @@ void IconDecodeRequest::StartWithOptions( ...@@ -113,28 +115,17 @@ void IconDecodeRequest::StartWithOptions(
void IconDecodeRequest::OnImageDecoded(const SkBitmap& bitmap) { void IconDecodeRequest::OnImageDecoded(const SkBitmap& bitmap) {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
const gfx::ImageSkia icon(
const gfx::Size resource_size(requested_size_, requested_size_); std::make_unique<IconSource>(bitmap, dimension_dip_, normalized_),
auto icon_source = std::make_unique<IconSource>(requested_size_); gfx::Size(dimension_dip_, dimension_dip_));
icon_source->SetDecodedImage(bitmap);
const gfx::ImageSkia icon =
gfx::ImageSkia(std::move(icon_source), resource_size);
icon.EnsureRepsForSupportedScales(); icon.EnsureRepsForSupportedScales();
std::move(set_icon_callback_).Run(icon); std::move(set_icon_callback_).Run(icon);
} }
void IconDecodeRequest::OnDecodeImageFailed() { void IconDecodeRequest::OnDecodeImageFailed() {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
DLOG(ERROR) << "Failed to decode an icon image."; DLOG(ERROR) << "Failed to decode an icon image.";
OnImageDecoded(SkBitmap());
const gfx::Size resource_size(requested_size_, requested_size_);
auto icon_source = std::make_unique<IconSource>(requested_size_);
const gfx::ImageSkia icon =
gfx::ImageSkia(std::move(icon_source), resource_size);
icon.EnsureRepsForSupportedScales();
std::move(set_icon_callback_).Run(icon);
} }
} // namespace arc } // namespace arc
...@@ -21,7 +21,7 @@ class IconDecodeRequest : public ImageDecoder::ImageRequest { ...@@ -21,7 +21,7 @@ class IconDecodeRequest : public ImageDecoder::ImageRequest {
public: public:
using SetIconCallback = base::OnceCallback<void(const gfx::ImageSkia& icon)>; using SetIconCallback = base::OnceCallback<void(const gfx::ImageSkia& icon)>;
IconDecodeRequest(SetIconCallback set_icon_callback, int requested_size); IconDecodeRequest(SetIconCallback set_icon_callback, int dimension_dip);
~IconDecodeRequest() override; ~IconDecodeRequest() override;
// Disables async safe decoding requests when unit tests are executed. // Disables async safe decoding requests when unit tests are executed.
...@@ -35,13 +35,17 @@ class IconDecodeRequest : public ImageDecoder::ImageRequest { ...@@ -35,13 +35,17 @@ class IconDecodeRequest : public ImageDecoder::ImageRequest {
// DisableSafeDecodingForTesting() is called. // DisableSafeDecodingForTesting() is called.
void StartWithOptions(const std::vector<uint8_t>& image_data); void StartWithOptions(const std::vector<uint8_t>& image_data);
// If |normalized| is true, MD normalization is applied to the decoded icon.
void set_normalized(bool normalized) { normalized_ = normalized; }
// ImageDecoder::ImageRequest: // ImageDecoder::ImageRequest:
void OnImageDecoded(const SkBitmap& bitmap) override; void OnImageDecoded(const SkBitmap& bitmap) override;
void OnDecodeImageFailed() override; void OnDecodeImageFailed() override;
private: private:
SetIconCallback set_icon_callback_; SetIconCallback set_icon_callback_;
int requested_size_ = 0; const int dimension_dip_;
bool normalized_ = false;
DISALLOW_COPY_AND_ASSIGN(IconDecodeRequest); DISALLOW_COPY_AND_ASSIGN(IconDecodeRequest);
}; };
......
...@@ -126,6 +126,7 @@ ArcPlayStoreSearchResult::ArcPlayStoreSearchResult( ...@@ -126,6 +126,7 @@ ArcPlayStoreSearchResult::ArcPlayStoreSearchResult(
base::BindOnce(&ArcPlayStoreSearchResult::SetIcon, base::BindOnce(&ArcPlayStoreSearchResult::SetIcon,
weak_ptr_factory_.GetWeakPtr()), weak_ptr_factory_.GetWeakPtr()),
app_list::AppListConfig::instance().search_tile_icon_dimension()); app_list::AppListConfig::instance().search_tile_icon_dimension());
icon_decode_request_->set_normalized(true);
icon_decode_request_->StartWithOptions(icon_png_data()); icon_decode_request_->StartWithOptions(icon_png_data());
} }
......
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