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

Side by Side Diff: chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.cc

Issue 2931063004: Extract colors from wallpaper and dynamically update login screen overlay (Closed)
Patch Set: Add image-loading class to small pods container Created 3 years, 6 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h" 5 #include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "ash/ash_constants.h" 9 #include "ash/ash_constants.h"
10 #include "ash/public/cpp/shelf_types.h" 10 #include "ash/public/cpp/shelf_types.h"
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 WallpaperManager* manager = WallpaperManager::Get(); 320 WallpaperManager* manager = WallpaperManager::Get();
321 if (manager->pending_inactive_ == this) 321 if (manager->pending_inactive_ == this)
322 manager->pending_inactive_ = NULL; 322 manager->pending_inactive_ = NULL;
323 323
324 started_load_at_ = base::Time::Now(); 324 started_load_at_ = base::Time::Now();
325 325
326 if (default_) { 326 if (default_) {
327 manager->DoSetDefaultWallpaper(account_id_, std::move(on_finish_)); 327 manager->DoSetDefaultWallpaper(account_id_, std::move(on_finish_));
328 } else if (!user_wallpaper_.isNull()) { 328 } else if (!user_wallpaper_.isNull()) {
329 SetWallpaper(user_wallpaper_, info_.layout); 329 SetWallpaper(user_wallpaper_, info_.layout);
330 manager->CalculateProminentColor(user_wallpaper_);
330 } else if (!wallpaper_path_.empty()) { 331 } else if (!wallpaper_path_.empty()) {
331 manager->task_runner_->PostTask( 332 manager->task_runner_->PostTask(
332 FROM_HERE, 333 FROM_HERE,
333 base::Bind(&WallpaperManager::GetCustomWallpaperInternal, account_id_, 334 base::Bind(&WallpaperManager::GetCustomWallpaperInternal, account_id_,
334 info_, wallpaper_path_, true /* update wallpaper */, 335 info_, wallpaper_path_, true /* update wallpaper */,
335 base::ThreadTaskRunnerHandle::Get(), 336 base::ThreadTaskRunnerHandle::Get(),
336 base::Passed(std::move(on_finish_)), 337 base::Passed(std::move(on_finish_)),
337 manager->weak_factory_.GetWeakPtr())); 338 manager->weak_factory_.GetWeakPtr()));
338 } else if (!info_.location.empty()) { 339 } else if (!info_.location.empty()) {
339 manager->LoadWallpaper(account_id_, info_, true, std::move(on_finish_)); 340 manager->LoadWallpaper(account_id_, info_, true, std::move(on_finish_));
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after
720 } 721 }
721 722
722 CreateSolidDefaultWallpaper(); 723 CreateSolidDefaultWallpaper();
723 } 724 }
724 // 1x1 wallpaper is actually solid color, so it should be stretched. 725 // 1x1 wallpaper is actually solid color, so it should be stretched.
725 if (default_wallpaper_image_->image().width() == 1 && 726 if (default_wallpaper_image_->image().width() == 1 &&
726 default_wallpaper_image_->image().height() == 1) 727 default_wallpaper_image_->image().height() == 1)
727 layout = wallpaper::WALLPAPER_LAYOUT_STRETCH; 728 layout = wallpaper::WALLPAPER_LAYOUT_STRETCH;
728 729
729 SetWallpaper(default_wallpaper_image_->image(), layout); 730 SetWallpaper(default_wallpaper_image_->image(), layout);
731 CalculateProminentColor(default_wallpaper_image_->image());
730 } 732 }
731 733
732 void WallpaperManager::SetUserWallpaperInfo(const AccountId& account_id, 734 void WallpaperManager::SetUserWallpaperInfo(const AccountId& account_id,
733 const WallpaperInfo& info, 735 const WallpaperInfo& info,
734 bool is_persistent) { 736 bool is_persistent) {
735 DCHECK_CURRENTLY_ON(BrowserThread::UI); 737 DCHECK_CURRENTLY_ON(BrowserThread::UI);
736 current_user_wallpaper_info_ = info; 738 current_user_wallpaper_info_ = info;
737 if (!is_persistent) 739 if (!is_persistent)
738 return; 740 return;
739 741
(...skipping 498 matching lines...) Expand 10 before | Expand all | Expand 10 after
1238 SetUserWallpaperInfo(account_id, info, true); 1240 SetUserWallpaperInfo(account_id, info, true);
1239 1241
1240 if (update_wallpaper) 1242 if (update_wallpaper)
1241 DoSetDefaultWallpaper(account_id, std::move(on_finish)); 1243 DoSetDefaultWallpaper(account_id, std::move(on_finish));
1242 return; 1244 return;
1243 } 1245 }
1244 1246
1245 // Update the image, but keep the path which was set earlier. 1247 // Update the image, but keep the path which was set earlier.
1246 wallpaper_cache_[account_id].second = user_image->image(); 1248 wallpaper_cache_[account_id].second = user_image->image();
1247 1249
1248 if (update_wallpaper) 1250 if (update_wallpaper) {
1249 SetWallpaper(user_image->image(), layout); 1251 SetWallpaper(user_image->image(), layout);
1252 CalculateProminentColor(user_image->image());
1253 }
1250 } 1254 }
1251 1255
1252 void WallpaperManager::StartLoad(const AccountId& account_id, 1256 void WallpaperManager::StartLoad(const AccountId& account_id,
1253 const WallpaperInfo& info, 1257 const WallpaperInfo& info,
1254 bool update_wallpaper, 1258 bool update_wallpaper,
1255 const base::FilePath& wallpaper_path, 1259 const base::FilePath& wallpaper_path,
1256 MovableOnDestroyCallbackHolder on_finish) { 1260 MovableOnDestroyCallbackHolder on_finish) {
1257 DCHECK_CURRENTLY_ON(BrowserThread::UI); 1261 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1258 TRACE_EVENT_ASYNC_BEGIN0("ui", "LoadAndDecodeWallpaper", this); 1262 TRACE_EVENT_ASYNC_BEGIN0("ui", "LoadAndDecodeWallpaper", this);
1259 if (update_wallpaper) { 1263 if (update_wallpaper) {
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
1444 Profile* profile = ProfileHelper::Get()->GetProfileByUser(user); 1448 Profile* profile = ProfileHelper::Get()->GetProfileByUser(user);
1445 1449
1446 UMA_HISTOGRAM_ENUMERATION( 1450 UMA_HISTOGRAM_ENUMERATION(
1447 "Ash.Wallpaper.Apps", 1451 "Ash.Wallpaper.Apps",
1448 wallpaper_manager_util::ShouldUseAndroidWallpapersApp(profile) 1452 wallpaper_manager_util::ShouldUseAndroidWallpapersApp(profile)
1449 ? WALLPAPERS_APP_ANDROID 1453 ? WALLPAPERS_APP_ANDROID
1450 : WALLPAPERS_PICKER_APP_CHROMEOS, 1454 : WALLPAPERS_PICKER_APP_CHROMEOS,
1451 WALLPAPERS_APPS_NUM); 1455 WALLPAPERS_APPS_NUM);
1452 } 1456 }
1453 1457
1458 void WallpaperManager::SetLoginOverlayCalculatorObserver(
1459 wallpaper::WallpaperColorCalculatorObserver* observer) {
1460 if (color_calculator_ && !observer) {
1461 color_calculator_->RemoveObserver(login_overlay_calculator_observer_);
1462 color_calculator_.reset();
1463 }
1464 login_overlay_calculator_observer_ = observer;
1465 }
1466
1467 void WallpaperManager::CalculateProminentColor(const gfx::ImageSkia& image) {
1468 // No need to calculate colors if there's no observer.
1469 if (!login_overlay_calculator_observer_)
1470 return;
1471 if (color_calculator_) {
1472 color_calculator_->RemoveObserver(login_overlay_calculator_observer_);
1473 color_calculator_.reset();
1474 }
1475
1476 color_utils::LumaRange luma = color_utils::LumaRange::DARK;
1477 color_utils::SaturationRange saturation = color_utils::SaturationRange::MUTED;
1478
1479 color_calculator_ = base::MakeUnique<wallpaper::WallpaperColorCalculator>(
1480 image, luma, saturation, task_runner_);
1481 color_calculator_->AddObserver(login_overlay_calculator_observer_);
1482 if (!color_calculator_->StartCalculation())
1483 SetLoginOverlayCalculatorObserver(nullptr);
1484 }
1485
1486 void WallpaperManager::getLoginOverlayColors(std::string* dm_color,
1487 std::string* scroll_color,
1488 std::string* background_color) {
1489 SkColor dm_sk_color = color_calculator_->prominent_color();
1490 // The dark muted color should have 100% opacity.
1491 dm_sk_color = SkColorSetA(dm_sk_color, 0xFF);
1492 SkColor base_sk_color = color_utils::GetResultingPaintColor(
1493 SkColorSetA(ash::kShelfDefaultBaseColor,
1494 ash::kShelfTranslucentColorDarkenAlpha),
1495 dm_sk_color);
1496 SkColor background_sk_color =
1497 SkColorSetA(base_sk_color, ash::kShelfTranslucentAlpha);
1498 // The alpha value for the login screen background. This constant will be
1499 // moved to a separate file when views-based login screen is being developed.
1500 constexpr int kLoginTranslucentAlpha = 76;
1501 SkColor scroll_sk_color = SkColorSetA(base_sk_color, kLoginTranslucentAlpha);
1502 *dm_color = color_utils::SkColorToRgbaString(dm_sk_color);
jdufault 2017/06/10 03:05:59 Output the SkColor values and have the string tran
Wenzhao (Colin) Zang 2017/06/12 21:10:57 Done.
1503 *scroll_color = color_utils::SkColorToRgbaString(scroll_sk_color);
1504 *background_color = color_utils::SkColorToRgbaString(background_sk_color);
1505 }
1506
1454 } // namespace chromeos 1507 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698