Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(35)

Unified Diff: ash/system/power/power_status_view.cc

Issue 10907037: Only update system power indicators on change (Closed) Base URL: https://git.chromium.org/git/chromium/src@git-svn
Patch Set: Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ash/system/power/power_status_view.cc
diff --git a/ash/system/power/power_status_view.cc b/ash/system/power/power_status_view.cc
index 6f205ade5d352447a3f126f662c79931da7e9b8c..e32c5aa15f52122f7e2f0cb743b92aa6e4dd4b5d 100644
--- a/ash/system/power/power_status_view.cc
+++ b/ash/system/power/power_status_view.cc
@@ -39,6 +39,7 @@ PowerStatusView::PowerStatusView(ViewType view_type,
time_label_(NULL),
time_status_label_(NULL),
icon_(NULL),
+ battery_image_index_(-1),
view_type_(view_type) {
if (view_type == VIEW_DEFAULT) {
time_status_label_ = new views::Label;
@@ -117,10 +118,12 @@ void PowerStatusView::UpdateTextForDefaultView() {
min = (time - base::TimeDelta::FromHours(hour)).InMinutes();
}
+ // Only update label text if the text changes, to save a GPU repaint
+
+ string16 time_status_text;
if (supply_status_.line_power_on && supply_status_.battery_is_full) {
- time_status_label_->SetText(
- ui::ResourceBundle::GetSharedInstance().GetLocalizedString(
- IDS_ASH_STATUS_TRAY_BATTERY_FULL));
+ time_status_text = ui::ResourceBundle::GetSharedInstance()
+ .GetLocalizedString(IDS_ASH_STATUS_TRAY_BATTERY_FULL);
} else {
string16 battery_percentage = l10n_util::GetStringFUTF16(
IDS_ASH_STATUS_TRAY_BATTERY_PERCENT_ONLY,
@@ -141,11 +144,12 @@ void PowerStatusView::UpdateTextForDefaultView() {
base::IntToString16(hour),
minute);
}
- string16 battery_status = battery_time.empty() ?
+ time_status_text = battery_time.empty() ?
battery_percentage :
battery_percentage + ASCIIToUTF16(" - ") + battery_time;
- time_status_label_->SetText(battery_status);
}
+ if (time_status_text != time_status_label_->text())
+ time_status_label_->SetText(time_status_text);
Daniel Erat 2012/09/04 21:51:58 This seems like a worthwhile optimization to do el
}
void PowerStatusView::UpdateTextForNotificationView() {
@@ -160,50 +164,54 @@ void PowerStatusView::UpdateTextForNotificationView() {
min = (time - base::TimeDelta::FromHours(hour)).InMinutes();
}
+ // Only update label text if the text changes, to save a GPU repaint
+
+ string16 status_text;
if (supply_status_.line_power_on && supply_status_.battery_is_full) {
- status_label_->SetText(
- ui::ResourceBundle::GetSharedInstance().GetLocalizedString(
- IDS_ASH_STATUS_TRAY_BATTERY_FULL));
+ status_text = ui::ResourceBundle::GetSharedInstance().GetLocalizedString(
+ IDS_ASH_STATUS_TRAY_BATTERY_FULL);
} else {
- status_label_->SetText(
- l10n_util::GetStringFUTF16(
- IDS_ASH_STATUS_TRAY_BATTERY_PERCENT,
- base::IntToString16(
- static_cast<int>(supply_status_.battery_percentage))));
+ status_text = l10n_util::GetStringFUTF16(
+ IDS_ASH_STATUS_TRAY_BATTERY_PERCENT,
+ base::IntToString16(
+ static_cast<int>(supply_status_.battery_percentage)));
}
+ if (status_text != status_label_->text())
+ status_label_->SetText(status_text);
+ string16 time_text;
if (supply_status_.is_calculating_battery_time) {
- time_label_->SetText(
- ui::ResourceBundle::GetSharedInstance().GetLocalizedString(
- IDS_ASH_STATUS_TRAY_BATTERY_CALCULATING));
+ time_text = ui::ResourceBundle::GetSharedInstance().GetLocalizedString(
+ IDS_ASH_STATUS_TRAY_BATTERY_CALCULATING);
} else if (hour || min) {
if (supply_status_.line_power_on) {
- time_label_->SetText(
- l10n_util::GetStringFUTF16(
- IDS_ASH_STATUS_TRAY_BATTERY_TIME_UNTIL_FULL,
- base::IntToString16(hour),
- base::IntToString16(min)));
+ time_text = l10n_util::GetStringFUTF16(
+ IDS_ASH_STATUS_TRAY_BATTERY_TIME_UNTIL_FULL,
+ base::IntToString16(hour),
+ base::IntToString16(min));
} else {
// This is a low battery warning, which prompts user when battery
// time left is not much (ie in minutes).
min = hour * 60 + min;
ShellDelegate* delegate = Shell::GetInstance()->delegate();
if (delegate) {
- time_label_->SetText(delegate->GetTimeRemainingString(
- base::TimeDelta::FromMinutes(min)));
- } else {
- time_label_->SetText(string16());
+ time_text = delegate->GetTimeRemainingString(
+ base::TimeDelta::FromMinutes(min));
}
}
- } else {
- time_label_->SetText(string16());
}
-
+ if (time_text != time_label_->text())
+ time_label_->SetText(time_text);
}
void PowerStatusView::UpdateIcon() {
if (icon_) {
- icon_->SetImage(TrayPower::GetBatteryImage(supply_status_, ICON_DARK));
+ int index = TrayPower::GetBatteryImageIndex(supply_status_);
+ if (battery_image_index_ != index) {
+ battery_image_index_ = index;
+ icon_->SetImage(
+ TrayPower::GetBatteryImage(battery_image_index_, ICON_DARK));
+ }
icon_->SetVisible(true);
}
}

Powered by Google App Engine
This is Rietveld 408576698