Commit 08578162 authored by pkotwicz@chromium.org's avatar pkotwicz@chromium.org

Enables HiDPI favicon to be displayed in tab strip on CrOS

BUG=138550
Test=Manual
Run ChromeOS with --force-device-scale-factor=2
Go to a website for the first time. Favicon appears in HiDPI in tab strip on CrOS.

Review URL: https://chromiumcodereview.appspot.com/10824296

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@151942 0039d316-1c4b-4281-b951-d872f2087c98
parent 40654568
...@@ -199,11 +199,7 @@ void FaviconTabHelper::OnDidDownloadFavicon( ...@@ -199,11 +199,7 @@ void FaviconTabHelper::OnDidDownloadFavicon(
// TODO: Possibly do bitmap selection in FaviconHandler, so that it can score // TODO: Possibly do bitmap selection in FaviconHandler, so that it can score
// favicons better. // favicons better.
std::vector<ui::ScaleFactor> scale_factors; std::vector<ui::ScaleFactor> scale_factors;
#if defined(OS_MACOSX)
scale_factors = ui::GetSupportedScaleFactors(); scale_factors = ui::GetSupportedScaleFactors();
#else
scale_factors.push_back(ui::SCALE_FACTOR_100P); // TODO: Aura?
#endif
gfx::Image favicon(SelectFaviconFrames( gfx::Image favicon(SelectFaviconFrames(
bitmaps, scale_factors, requested_size, &score)); bitmaps, scale_factors, requested_size, &score));
favicon_handler_->OnDidDownloadFavicon( favicon_handler_->OnDidDownloadFavicon(
......
...@@ -99,7 +99,8 @@ void TabIconView::PaintThrobber(gfx::Canvas* canvas) { ...@@ -99,7 +99,8 @@ void TabIconView::PaintThrobber(gfx::Canvas* canvas) {
image_size, false); image_size, false);
} }
void TabIconView::PaintFavicon(gfx::Canvas* canvas, const SkBitmap& image) { void TabIconView::PaintFavicon(gfx::Canvas* canvas,
const gfx::ImageSkia& image) {
PaintIcon(canvas, image, 0, 0, image.width(), image.height(), true); PaintIcon(canvas, image, 0, 0, image.width(), image.height(), true);
} }
...@@ -142,7 +143,7 @@ void TabIconView::OnPaint(gfx::Canvas* canvas) { ...@@ -142,7 +143,7 @@ void TabIconView::OnPaint(gfx::Canvas* canvas) {
rendered = true; rendered = true;
PaintThrobber(canvas); PaintThrobber(canvas);
} else { } else {
SkBitmap favicon = model_->GetFaviconForTabIconView(); gfx::ImageSkia favicon = model_->GetFaviconForTabIconView();
if (!favicon.isNull()) { if (!favicon.isNull()) {
rendered = true; rendered = true;
PaintFavicon(canvas, favicon); PaintFavicon(canvas, favicon);
......
...@@ -9,8 +9,6 @@ ...@@ -9,8 +9,6 @@
#include "base/compiler_specific.h" #include "base/compiler_specific.h"
#include "ui/views/view.h" #include "ui/views/view.h"
class SkBitmap;
namespace chrome { namespace chrome {
class TabIconViewModel; class TabIconViewModel;
} }
...@@ -39,7 +37,7 @@ class TabIconView : public views::View { ...@@ -39,7 +37,7 @@ class TabIconView : public views::View {
private: private:
void PaintThrobber(gfx::Canvas* canvas); void PaintThrobber(gfx::Canvas* canvas);
void PaintFavicon(gfx::Canvas* canvas, const SkBitmap& bitmap); void PaintFavicon(gfx::Canvas* canvas, const gfx::ImageSkia& image);
void PaintIcon(gfx::Canvas* canvas, void PaintIcon(gfx::Canvas* canvas,
const gfx::ImageSkia& image, const gfx::ImageSkia& image,
int src_x, int src_x,
......
...@@ -514,9 +514,8 @@ void BrowserTabStripController::SetTabRendererDataFromModel( ...@@ -514,9 +514,8 @@ void BrowserTabStripController::SetTabRendererDataFromModel(
TabStatus tab_status) { TabStatus tab_status) {
TabContents* tab_contents = TabContents::FromWebContents(contents); TabContents* tab_contents = TabContents::FromWebContents(contents);
// TODO: Convert data->favicon to gfx::Image.
data->favicon = data->favicon =
tab_contents->favicon_tab_helper()->GetFavicon().AsBitmap(); tab_contents->favicon_tab_helper()->GetFavicon().AsImageSkia();
data->network_state = TabContentsNetworkState(contents); data->network_state = TabContentsNetworkState(contents);
data->title = contents->GetTitle(); data->title = contents->GetTitle();
data->url = contents->GetURL(); data->url = contents->GetURL();
......
...@@ -21,9 +21,7 @@ TabRendererData::~TabRendererData() {} ...@@ -21,9 +21,7 @@ TabRendererData::~TabRendererData() {}
bool TabRendererData::Equals(const TabRendererData& data) { bool TabRendererData::Equals(const TabRendererData& data) {
return return
favicon.pixelRef() && favicon.BackedBySameObjectAs(data.favicon) &&
favicon.pixelRef() == data.favicon.pixelRef() &&
favicon.pixelRefOffset() == data.favicon.pixelRefOffset() &&
network_state == data.network_state && network_state == data.network_state &&
title == data.title && title == data.title &&
url == data.url && url == data.url &&
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
#include "chrome/browser/ui/search/search_types.h" #include "chrome/browser/ui/search/search_types.h"
#include "chrome/browser/ui/search/toolbar_search_animator.h" #include "chrome/browser/ui/search/toolbar_search_animator.h"
#include "googleurl/src/gurl.h" #include "googleurl/src/gurl.h"
#include "third_party/skia/include/core/SkBitmap.h" #include "ui/gfx/image/image_skia.h"
// Wraps the state needed by the renderers. // Wraps the state needed by the renderers.
struct TabRendererData { struct TabRendererData {
...@@ -35,11 +35,10 @@ struct TabRendererData { ...@@ -35,11 +35,10 @@ struct TabRendererData {
crashed_status == base::TERMINATION_STATUS_ABNORMAL_TERMINATION); crashed_status == base::TERMINATION_STATUS_ABNORMAL_TERMINATION);
} }
// Returns true if the TabRendererData is same as given |data|. Two favicons // Returns true if the TabRendererData is same as given |data|.
// are considered equals if two SkBitmaps point to the same SkPixelRef object.
bool Equals(const TabRendererData& data); bool Equals(const TabRendererData& data);
SkBitmap favicon; gfx::ImageSkia favicon;
NetworkState network_state; NetworkState network_state;
string16 title; string16 title;
GURL url; GURL url;
......
...@@ -168,6 +168,10 @@ ImageSkia& ImageSkia::operator=(const SkBitmap& other) { ...@@ -168,6 +168,10 @@ ImageSkia& ImageSkia::operator=(const SkBitmap& other) {
ImageSkia::~ImageSkia() { ImageSkia::~ImageSkia() {
} }
bool ImageSkia::BackedBySameObjectAs(const gfx::ImageSkia& other) const {
return storage_.get() == other.storage_.get();
}
void ImageSkia::AddRepresentation(const ImageSkiaRep& image_rep) { void ImageSkia::AddRepresentation(const ImageSkiaRep& image_rep) {
DCHECK(!image_rep.is_null()); DCHECK(!image_rep.is_null());
......
...@@ -67,6 +67,10 @@ class UI_EXPORT ImageSkia { ...@@ -67,6 +67,10 @@ class UI_EXPORT ImageSkia {
~ImageSkia(); ~ImageSkia();
// Returns true if this object is backed by the same ImageSkiaStorage as
// |other|. Will also return true if both images are isNull().
bool BackedBySameObjectAs(const gfx::ImageSkia& other) const;
// Adds |image_rep| to the image reps contained by this object. // Adds |image_rep| to the image reps contained by this object.
void AddRepresentation(const gfx::ImageSkiaRep& image_rep); void AddRepresentation(const gfx::ImageSkiaRep& image_rep);
......
...@@ -196,4 +196,22 @@ TEST(ImageSkiaTest, OperatorBitmapFromSource) { ...@@ -196,4 +196,22 @@ TEST(ImageSkiaTest, OperatorBitmapFromSource) {
EXPECT_FALSE(bitmap.isNull()); EXPECT_FALSE(bitmap.isNull());
} }
TEST(ImageSkiaTest, BackedBySameObjectAs) {
// Null images should all be backed by the same object (NULL).
ImageSkia image;
ImageSkia unrelated;
EXPECT_TRUE(image.BackedBySameObjectAs(unrelated));
image.AddRepresentation(gfx::ImageSkiaRep(gfx::Size(10, 10),
ui::SCALE_FACTOR_100P));
ImageSkia copy = image;
copy.AddRepresentation(gfx::ImageSkiaRep(gfx::Size(10, 10),
ui::SCALE_FACTOR_200P));
unrelated.AddRepresentation(gfx::ImageSkiaRep(gfx::Size(10, 10),
ui::SCALE_FACTOR_100P));
EXPECT_TRUE(image.BackedBySameObjectAs(copy));
EXPECT_FALSE(image.BackedBySameObjectAs(unrelated));
EXPECT_FALSE(copy.BackedBySameObjectAs(unrelated));
}
} // namespace gfx } // namespace gfx
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