Commit 353c5f9f authored by pkotwicz@chromium.org's avatar pkotwicz@chromium.org

Get rid of implicit conversion to and from ImageSkiaRep

Bug=None
Test=Compiles
R=ben,oshima
TBR=sadrul

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@146022 0039d316-1c4b-4281-b951-d872f2087c98
parent f4e5a127
...@@ -271,7 +271,7 @@ class NetworkMenuIconSource : public gfx::ImageSkiaSource { ...@@ -271,7 +271,7 @@ class NetworkMenuIconSource : public gfx::ImageSkiaSource {
gfx::ImageSkia* images; gfx::ImageSkia* images;
if (type_ == NetworkMenuIcon::ARCS) { if (type_ == NetworkMenuIcon::ARCS) {
if (index_ >= kNumArcsImages) if (index_ >= kNumArcsImages)
return gfx::ImageSkia(); return gfx::ImageSkiaRep();
images = ResourceBundle::GetSharedInstance().GetImageSkiaNamed( images = ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
color_ == NetworkMenuIcon::COLOR_DARK ? color_ == NetworkMenuIcon::COLOR_DARK ?
IDR_STATUSBAR_NETWORK_ARCS_DARK : IDR_STATUSBAR_NETWORK_ARCS_LIGHT); IDR_STATUSBAR_NETWORK_ARCS_DARK : IDR_STATUSBAR_NETWORK_ARCS_LIGHT);
...@@ -279,7 +279,7 @@ class NetworkMenuIconSource : public gfx::ImageSkiaSource { ...@@ -279,7 +279,7 @@ class NetworkMenuIconSource : public gfx::ImageSkiaSource {
height = images->height() / kNumArcsImages; height = images->height() / kNumArcsImages;
} else { } else {
if (index_ >= kNumBarsImages) if (index_ >= kNumBarsImages)
return gfx::ImageSkia(); return gfx::ImageSkiaRep();
images = ResourceBundle::GetSharedInstance().GetImageSkiaNamed( images = ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
color_ == NetworkMenuIcon::COLOR_DARK ? color_ == NetworkMenuIcon::COLOR_DARK ?
......
...@@ -202,7 +202,9 @@ void AvatarMenuItemGtk::Init(GtkThemeService* theme_service) { ...@@ -202,7 +202,9 @@ void AvatarMenuItemGtk::Init(GtkThemeService* theme_service) {
// of the profile icon. // of the profile icon.
if (item_.active) { if (item_.active) {
const SkBitmap* avatar_image = item_.icon.ToSkBitmap(); const SkBitmap* avatar_image = item_.icon.ToSkBitmap();
gfx::Canvas canvas(*avatar_image, /* is_opaque */ true); gfx::ImageSkiaRep avatar_image_rep =
gfx::ImageSkiaRep(*avatar_image, ui::SCALE_FACTOR_100P);
gfx::Canvas canvas(avatar_image_rep, /* is_opaque */ true);
ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
const SkBitmap* check_image = rb.GetImageNamed( const SkBitmap* check_image = rb.GetImageNamed(
......
...@@ -361,7 +361,8 @@ gfx::Canvas* BrowserActionView::GetIconWithBadge() { ...@@ -361,7 +361,8 @@ gfx::Canvas* BrowserActionView::GetIconWithBadge() {
if (icon.isNull()) if (icon.isNull())
icon = button_->default_icon(); icon = button_->default_icon();
gfx::Canvas* canvas = new gfx::Canvas(icon, false); gfx::Canvas* canvas =
new gfx::Canvas(gfx::ImageSkiaRep(icon, ui::SCALE_FACTOR_100P), false);
if (tab_id >= 0) { if (tab_id >= 0) {
gfx::Rect bounds(icon.width(), icon.height() + ToolbarView::kVertSpacing); gfx::Rect bounds(icon.width(), icon.height() + ToolbarView::kVertSpacing);
......
...@@ -349,7 +349,8 @@ gfx::ImageSkia ToolbarView::GetAppMenuIcon( ...@@ -349,7 +349,8 @@ gfx::ImageSkia ToolbarView::GetAppMenuIcon(
return icon; return icon;
// Draw the chrome app menu icon onto the canvas. // Draw the chrome app menu icon onto the canvas.
scoped_ptr<gfx::Canvas> canvas(new gfx::Canvas(icon, false)); gfx::ImageSkiaRep image_rep = gfx::ImageSkiaRep(icon, ui::SCALE_FACTOR_100P);
scoped_ptr<gfx::Canvas> canvas(new gfx::Canvas(image_rep, false));
gfx::ImageSkia badge; gfx::ImageSkia badge;
// Only one badge can be active at any given time. The Upgrade notification // Only one badge can be active at any given time. The Upgrade notification
......
...@@ -86,7 +86,7 @@ base::ListValue* NetworkMenuWebUI::ConvertMenuModel(ui::MenuModel* model) { ...@@ -86,7 +86,7 @@ base::ListValue* NetworkMenuWebUI::ConvertMenuModel(ui::MenuModel* model) {
item->SetString("label", model->GetLabelAt(i)); item->SetString("label", model->GetLabelAt(i));
gfx::ImageSkia icon; gfx::ImageSkia icon;
if (model->GetIconAt(i, &icon)) { if (model->GetIconAt(i, &icon)) {
gfx::ImageSkiaRep icon_bitmap = icon.GetRepresentation( SkBitmap icon_bitmap = icon.GetRepresentation(
ui::GetScaleFactorFromScale(web_ui_->GetDeviceScale())).sk_bitmap(); ui::GetScaleFactorFromScale(web_ui_->GetDeviceScale())).sk_bitmap();
item->SetString("icon", web_ui_util::GetImageDataUrl(icon_bitmap)); item->SetString("icon", web_ui_util::GetImageDataUrl(icon_bitmap));
} }
...@@ -161,7 +161,7 @@ void NetworkDropdown::NetworkMenuIconChanged() { ...@@ -161,7 +161,7 @@ void NetworkDropdown::NetworkMenuIconChanged() {
void NetworkDropdown::SetNetworkIconAndText() { void NetworkDropdown::SetNetworkIconAndText() {
string16 text; string16 text;
const gfx::ImageSkia icon_image = network_icon_->GetIconAndText(&text); const gfx::ImageSkia icon_image = network_icon_->GetIconAndText(&text);
gfx::ImageSkiaRep icon_bitmap = icon_image.GetRepresentation( SkBitmap icon_bitmap = icon_image.GetRepresentation(
ui::GetScaleFactorFromScale(web_ui_->GetDeviceScale())).sk_bitmap(); ui::GetScaleFactorFromScale(web_ui_->GetDeviceScale())).sk_bitmap();
std::string icon_str = std::string icon_str =
icon_image.empty() ? icon_image.empty() ?
......
...@@ -141,7 +141,7 @@ ImageSkia::ImageSkia(ImageSkiaSource* source, const gfx::Size& size) ...@@ -141,7 +141,7 @@ ImageSkia::ImageSkia(ImageSkiaSource* source, const gfx::Size& size)
} }
ImageSkia::ImageSkia(const SkBitmap& bitmap) { ImageSkia::ImageSkia(const SkBitmap& bitmap) {
Init(ImageSkiaRep(bitmap)); Init(ImageSkiaRep(bitmap, ui::SCALE_FACTOR_100P));
} }
ImageSkia::ImageSkia(const ImageSkiaRep& image_rep) { ImageSkia::ImageSkia(const ImageSkiaRep& image_rep) {
...@@ -157,12 +157,7 @@ ImageSkia& ImageSkia::operator=(const ImageSkia& other) { ...@@ -157,12 +157,7 @@ ImageSkia& ImageSkia::operator=(const ImageSkia& other) {
} }
ImageSkia& ImageSkia::operator=(const SkBitmap& other) { ImageSkia& ImageSkia::operator=(const SkBitmap& other) {
Init(ImageSkiaRep(other)); Init(ImageSkiaRep(other, ui::SCALE_FACTOR_100P));
return *this;
}
ImageSkia& ImageSkia::operator=(const ImageSkiaRep& other) {
Init(other);
return *this; return *this;
} }
...@@ -173,13 +168,6 @@ ImageSkia::operator SkBitmap&() const { ...@@ -173,13 +168,6 @@ ImageSkia::operator SkBitmap&() const {
return const_cast<SkBitmap&>(storage_->image_reps()[0].sk_bitmap()); return const_cast<SkBitmap&>(storage_->image_reps()[0].sk_bitmap());
} }
ImageSkia::operator ImageSkiaRep&() const {
if (isNull())
return NullImageRep();
return storage_->image_reps()[0];
}
ImageSkia::~ImageSkia() { ImageSkia::~ImageSkia() {
} }
......
...@@ -61,17 +61,10 @@ class UI_EXPORT ImageSkia { ...@@ -61,17 +61,10 @@ class UI_EXPORT ImageSkia {
// done. // done.
ImageSkia& operator=(const SkBitmap& other); ImageSkia& operator=(const SkBitmap& other);
// Converts from gfx::ImageSkiaRep.
// Adds ref to passed in image rep.
// TODO(pkotwicz): This is temporary till conversion to gfx::ImageSkia is
// done.
ImageSkia& operator=(const gfx::ImageSkiaRep& other);
// Converts to gfx::ImageSkiaRep and SkBitmap. // Converts to gfx::ImageSkiaRep and SkBitmap.
// TODO(pkotwicz): This is temporary till conversion to gfx::ImageSkia is // TODO(pkotwicz): This is temporary till conversion to gfx::ImageSkia is
// done. // done.
operator SkBitmap&() const; operator SkBitmap&() const;
operator gfx::ImageSkiaRep&() const;
~ImageSkia(); ~ImageSkia();
......
...@@ -25,27 +25,12 @@ ImageSkiaRep::ImageSkiaRep(const gfx::Size& size, ...@@ -25,27 +25,12 @@ ImageSkiaRep::ImageSkiaRep(const gfx::Size& size,
bitmap_.allocPixels(); bitmap_.allocPixels();
} }
ImageSkiaRep::ImageSkiaRep(const SkBitmap& src)
: bitmap_(src),
scale_factor_(ui::SCALE_FACTOR_NONE) {
}
ImageSkiaRep::ImageSkiaRep(const SkBitmap& src, ImageSkiaRep::ImageSkiaRep(const SkBitmap& src,
ui::ScaleFactor scale_factor) ui::ScaleFactor scale_factor)
: bitmap_(src), : bitmap_(src),
scale_factor_(scale_factor) { scale_factor_(scale_factor) {
} }
ImageSkiaRep& ImageSkiaRep::operator=(const SkBitmap& other) {
bitmap_ = other;
scale_factor_ = ui::SCALE_FACTOR_NONE;
return *this;
}
ImageSkiaRep::operator SkBitmap&() const {
return const_cast<SkBitmap&>(bitmap_);
}
int ImageSkiaRep::GetWidth() const { int ImageSkiaRep::GetWidth() const {
return static_cast<int>(bitmap_.width() / return static_cast<int>(bitmap_.width() /
ui::GetScaleFactorScale(scale_factor_)); ui::GetScaleFactorScale(scale_factor_));
......
...@@ -24,20 +24,10 @@ class UI_EXPORT ImageSkiaRep { ...@@ -24,20 +24,10 @@ class UI_EXPORT ImageSkiaRep {
// This allocates pixels in the bitmap. // This allocates pixels in the bitmap.
ImageSkiaRep(const gfx::Size& size, ui::ScaleFactor scale_factor); ImageSkiaRep(const gfx::Size& size, ui::ScaleFactor scale_factor);
// Creates a bitmap with a default scale factor of 1x.
// Adds ref to |src|.
// TODO(pkotwicz): This is temporary and should be removed ASAP.
ImageSkiaRep(const SkBitmap& src);
// Creates a bitmap with given scale factor. // Creates a bitmap with given scale factor.
// Adds ref to |src|. // Adds ref to |src|.
ImageSkiaRep(const SkBitmap& src, ui::ScaleFactor scale_factor); ImageSkiaRep(const SkBitmap& src, ui::ScaleFactor scale_factor);
// Converts to and from SkBitmap.
// TODO(pkotwicz): This is temporary and should be removed ASAP.
ImageSkiaRep& operator=(const SkBitmap& other);
operator SkBitmap&() const;
// Returns true if the backing bitmap is null. // Returns true if the backing bitmap is null.
bool is_null() const { return bitmap_.isNull(); } bool is_null() const { return bitmap_.isNull(); }
......
...@@ -183,8 +183,10 @@ class MenuHostWindow : public ui::WindowImpl { ...@@ -183,8 +183,10 @@ class MenuHostWindow : public ui::WindowImpl {
// Draw the icon after the label, otherwise it would be covered // Draw the icon after the label, otherwise it would be covered
// by the label. // by the label.
gfx::ImageSkiaRep icon_image_rep =
data->icon.GetRepresentation(ui::SCALE_FACTOR_100P);
if (data->icon.width() != 0 && data->icon.height() != 0) { if (data->icon.width() != 0 && data->icon.height() != 0) {
gfx::Canvas canvas(data->icon, false); gfx::Canvas canvas(icon_image_rep, false);
skia::DrawToNativeContext( skia::DrawToNativeContext(
canvas.sk_canvas(), hDC, lpdis->rcItem.left + kItemLeftMargin, canvas.sk_canvas(), hDC, lpdis->rcItem.left + kItemLeftMargin,
lpdis->rcItem.top + (lpdis->rcItem.bottom - lpdis->rcItem.top - lpdis->rcItem.top + (lpdis->rcItem.bottom - lpdis->rcItem.top -
......
...@@ -256,7 +256,8 @@ class NativeMenuWin::MenuHostWindow { ...@@ -256,7 +256,8 @@ class NativeMenuWin::MenuHostWindow {
if (data->native_menu_win->model_->GetIconAt(data->model_index, &icon)) { if (data->native_menu_win->model_->GetIconAt(data->model_index, &icon)) {
// We currently don't support items with both icons and checkboxes. // We currently don't support items with both icons and checkboxes.
DCHECK(type != ui::MenuModel::TYPE_CHECK); DCHECK(type != ui::MenuModel::TYPE_CHECK);
gfx::Canvas canvas(icon, false); gfx::Canvas canvas(icon.GetRepresentation(ui::SCALE_FACTOR_100P),
false);
skia::DrawToNativeContext( skia::DrawToNativeContext(
canvas.sk_canvas(), dc, canvas.sk_canvas(), dc,
draw_item_struct->rcItem.left + kItemLeftMargin, draw_item_struct->rcItem.left + kItemLeftMargin,
......
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