Skip to content

Commit

Permalink
Remove support for wallpaper files in resources.
Browse files Browse the repository at this point in the history
BUG=363200
TEST=manual.

Review URL: https://codereview.chromium.org/287953003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@270751 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
alemate@chromium.org committed May 15, 2014
1 parent fd3f8e3 commit 3c3f118
Show file tree
Hide file tree
Showing 10 changed files with 71 additions and 119 deletions.
36 changes: 4 additions & 32 deletions ash/desktop_background/desktop_background_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ const int kWallpaperReloadDelayMs = 2000;

} // namespace

const int DesktopBackgroundController::kInvalidResourceID = -1;

DesktopBackgroundController::DesktopBackgroundController()
: locked_(false),
desktop_background_mode_(BACKGROUND_NONE),
Expand Down Expand Up @@ -85,8 +83,7 @@ bool DesktopBackgroundController::SetWallpaperImage(const gfx::ImageSkia& image,
VLOG(1) << "SetWallpaper: image_id=" << WallpaperResizer::GetImageId(image)
<< " layout=" << layout;

if (WallpaperIsAlreadyLoaded(
&image, kInvalidResourceID, true /* compare_layouts */, layout)) {
if (WallpaperIsAlreadyLoaded(image, true /* compare_layouts */, layout)) {
VLOG(1) << "Wallpaper is already loaded";
return false;
}
Expand All @@ -102,26 +99,6 @@ bool DesktopBackgroundController::SetWallpaperImage(const gfx::ImageSkia& image,
return true;
}

bool DesktopBackgroundController::SetWallpaperResource(int resource_id,
WallpaperLayout layout) {
VLOG(1) << "SetWallpaper: resource_id=" << resource_id
<< " layout=" << layout;

if (WallpaperIsAlreadyLoaded(
NULL, resource_id, true /* compare_layouts */, layout)) {
VLOG(1) << "Wallpaper is already loaded";
return false;
}
current_wallpaper_.reset(
new WallpaperResizer(resource_id, GetMaxDisplaySizeInNative(), layout));
current_wallpaper_->StartResize();

FOR_EACH_OBSERVER(DesktopBackgroundControllerObserver, observers_,
OnWallpaperDataChanged());
SetDesktopBackgroundImageMode();
return true;
}

void DesktopBackgroundController::CreateEmptyWallpaper() {
current_wallpaper_.reset(NULL);
SetDesktopBackgroundImageMode();
Expand Down Expand Up @@ -198,8 +175,7 @@ gfx::Size DesktopBackgroundController::GetMaxDisplaySizeInNative() {
}

bool DesktopBackgroundController::WallpaperIsAlreadyLoaded(
const gfx::ImageSkia* image,
int resource_id,
const gfx::ImageSkia& image,
bool compare_layouts,
WallpaperLayout layout) const {
if (!current_wallpaper_.get())
Expand All @@ -209,12 +185,8 @@ bool DesktopBackgroundController::WallpaperIsAlreadyLoaded(
if (compare_layouts && layout != current_wallpaper_->layout())
return false;

if (image) {
return WallpaperResizer::GetImageId(*image) ==
current_wallpaper_->original_image_id();
}

return current_wallpaper_->resource_id() == resource_id;
return WallpaperResizer::GetImageId(image) ==
current_wallpaper_->original_image_id();
}

void DesktopBackgroundController::SetDesktopBackgroundImageMode() {
Expand Down
10 changes: 1 addition & 9 deletions ash/desktop_background/desktop_background_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,6 @@ class ASH_EXPORT DesktopBackgroundController
BACKGROUND_IMAGE,
};

// This is used to initialize Resource ID variables and to denote "no
// resource ID" in parameters.
static const int kInvalidResourceID;

DesktopBackgroundController();
virtual ~DesktopBackgroundController();

Expand All @@ -83,8 +79,6 @@ class ASH_EXPORT DesktopBackgroundController
// Returns true if new image was actually set. And false when duplicate set
// request detected.
bool SetWallpaperImage(const gfx::ImageSkia& image, WallpaperLayout layout);
// The same, but image from resources is used.
bool SetWallpaperResource(int resource_id, WallpaperLayout layout);

// Creates an empty wallpaper. Some tests require a wallpaper widget is ready
// when running. However, the wallpaper widgets are now created
Expand Down Expand Up @@ -116,10 +110,8 @@ class ASH_EXPORT DesktopBackgroundController

// Returns true if the specified wallpaper is already stored
// in |current_wallpaper_|.
// If |image| is NULL, resource_id is compared.
// If |compare_layouts| is false, layout is ignored.
bool WallpaperIsAlreadyLoaded(const gfx::ImageSkia* image,
int resource_id,
bool WallpaperIsAlreadyLoaded(const gfx::ImageSkia& image,
bool compare_layouts,
WallpaperLayout layout) const;

Expand Down
15 changes: 0 additions & 15 deletions ash/desktop_background/wallpaper_resizer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -99,26 +99,11 @@ uint32_t WallpaperResizer::GetImageId(const gfx::ImageSkia& image) {
return image_rep.is_null() ? 0 : image_rep.sk_bitmap().getGenerationID();
}

WallpaperResizer::WallpaperResizer(int image_resource_id,
const gfx::Size& target_size,
WallpaperLayout layout)
: image_(*(ui::ResourceBundle::GetSharedInstance()
.GetImageNamed(image_resource_id)
.ToImageSkia())),
original_image_id_(GetImageId(image_)),
resource_id_(image_resource_id),
target_size_(target_size),
layout_(layout),
weak_ptr_factory_(this) {
image_.MakeThreadSafe();
}

WallpaperResizer::WallpaperResizer(const gfx::ImageSkia& image,
const gfx::Size& target_size,
WallpaperLayout layout)
: image_(image),
original_image_id_(GetImageId(image_)),
resource_id_(DesktopBackgroundController::kInvalidResourceID),
target_size_(target_size),
layout_(layout),
weak_ptr_factory_(this) {
Expand Down
9 changes: 0 additions & 9 deletions ash/desktop_background/wallpaper_resizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ class ASH_EXPORT WallpaperResizer {
// is modified, its ID will change.
static uint32_t GetImageId(const gfx::ImageSkia& image);

WallpaperResizer(int image_resource_id,
const gfx::Size& target_size,
WallpaperLayout layout);

WallpaperResizer(const gfx::ImageSkia& image,
const gfx::Size& target_size,
WallpaperLayout layout);
Expand All @@ -40,8 +36,6 @@ class ASH_EXPORT WallpaperResizer {
uint32_t original_image_id() const { return original_image_id_; }
WallpaperLayout layout() const { return layout_; }

int resource_id() const { return resource_id_; }

// Called on the UI thread to run Resize() on the worker pool and post an
// OnResizeFinished() task back to the UI thread on completion.
void StartResize();
Expand All @@ -65,9 +59,6 @@ class ASH_EXPORT WallpaperResizer {
// Unique identifier corresponding to the original (i.e. pre-resize) |image_|.
uint32_t original_image_id_;

// kInvalidResourceID if image was not obtained from resources.
const int resource_id_;

gfx::Size target_size_;

WallpaperLayout layout_;
Expand Down
5 changes: 0 additions & 5 deletions ash/resources/ash_resources.grd
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@
<output filename="ash_resources_200_percent.pak" type="data_package" context="default_200_percent" />
</outputs>
<release seq="1">
<includes>
<!-- Fallback wallpaper used by Ash. -->
<include name="IDR_AURA_WALLPAPER_DEFAULT_LARGE" file="wallpaper/default_large.jpg" type="BINDATA" />
<include name="IDR_AURA_WALLPAPER_DEFAULT_SMALL" file="wallpaper/default_small.jpg" type="BINDATA" />
</includes>
<structures fallback_to_low_resolution="true">
<!-- KEEP THESE IN ALPHABETICAL ORDER! DO NOT ADD TO RANDOM PLACES JUST
BECAUSE YOUR RESOURCES ARE FUNCTIONALLY RELATED OR FALL UNDER THE
Expand Down
Binary file removed ash/resources/wallpaper/default_large.jpg
Binary file not shown.
Binary file removed ash/resources/wallpaper/default_small.jpg
Binary file not shown.
45 changes: 28 additions & 17 deletions chrome/browser/chromeos/login/wallpaper_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <numeric>
#include <vector>

#include "ash/ash_constants.h"
#include "ash/ash_switches.h"
#include "ash/desktop_background/desktop_background_controller.h"
#include "ash/shell.h"
Expand Down Expand Up @@ -43,8 +44,7 @@
#include "chromeos/dbus/dbus_thread_manager.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/notification_service.h"
#include "grit/ash_resources.h"
#include "ui/base/resource/resource_bundle.h"
#include "third_party/skia/include/core/SkColor.h"
#include "ui/gfx/codec/jpeg_codec.h"
#include "ui/gfx/image/image_skia_operations.h"
#include "ui/gfx/skia_util.h"
Expand Down Expand Up @@ -92,6 +92,10 @@ const unsigned kLoadDefaultDelayMs = 200;
// Maximum wallpaper load delay, milliseconds.
const unsigned kLoadMaxDelayMs = 2000;

// When no wallpaper image is specified, the screen is filled with a solid
// color.
const SkColor kDefaultWallpaperColor = SK_ColorGRAY;

// For our scaling ratios we need to round positive numbers.
int RoundPositive(double x) {
return static_cast<int>(floor(x + 0.5));
Expand Down Expand Up @@ -954,9 +958,9 @@ void WallpaperManager::DoSetDefaultWallpaper(
file = use_small ? &default_small_wallpaper_file_
: &default_large_wallpaper_file_;
}
const ash::WallpaperLayout layout =
use_small ? ash::WALLPAPER_LAYOUT_CENTER
: ash::WALLPAPER_LAYOUT_CENTER_CROPPED;
ash::WallpaperLayout layout = use_small
? ash::WALLPAPER_LAYOUT_CENTER
: ash::WALLPAPER_LAYOUT_CENTER_CROPPED;
DCHECK(file);
if (!default_wallpaper_image_.get() ||
default_wallpaper_image_->file_path() != file->value()) {
Expand All @@ -968,14 +972,13 @@ void WallpaperManager::DoSetDefaultWallpaper(
return;
}

const int resource_id = use_small ? IDR_AURA_WALLPAPER_DEFAULT_SMALL
: IDR_AURA_WALLPAPER_DEFAULT_LARGE;

loaded_wallpapers_ += ash::Shell::GetInstance()
->desktop_background_controller()
->SetWallpaperResource(resource_id, layout);
return;
CreateSolidDefaultWallpaper();
}
// 1x1 wallpaper is actually solid color, so it should be stretched.
if (default_wallpaper_image_->image().width() == 1 &&
default_wallpaper_image_->image().height() == 1)
layout = ash::WALLPAPER_LAYOUT_STRETCH;

ash::Shell::GetInstance()->desktop_background_controller()->SetWallpaperImage(
default_wallpaper_image_->image(), layout);
}
Expand Down Expand Up @@ -1862,11 +1865,9 @@ void WallpaperManager::SetDefaultWallpaperPath(
// as a placeholder only.
const bool need_update_screen =
default_wallpaper_image_.get() &&
dbc->WallpaperIsAlreadyLoaded(
&(default_wallpaper_image_->image()),
ash::DesktopBackgroundController::kInvalidResourceID,
false /* compare_layouts */,
ash::WALLPAPER_LAYOUT_CENTER);
dbc->WallpaperIsAlreadyLoaded(default_wallpaper_image_->image(),
false /* compare_layouts */,
ash::WALLPAPER_LAYOUT_CENTER);

default_wallpaper_image_.reset();
if (GetAppropriateResolution() == WALLPAPER_RESOLUTION_SMALL) {
Expand All @@ -1889,4 +1890,14 @@ void WallpaperManager::SetDefaultWallpaperPath(
}
}

void WallpaperManager::CreateSolidDefaultWallpaper() {
loaded_wallpapers_++;
SkBitmap bitmap;
bitmap.setConfig(SkBitmap::kARGB_8888_Config, 1, 1, 0);
bitmap.allocPixels();
bitmap.eraseColor(kDefaultWallpaperColor);
const gfx::ImageSkia image = gfx::ImageSkia::CreateFrom1xBitmap(bitmap);
default_wallpaper_image_.reset(new UserImage(image));
}

} // namespace chromeos
3 changes: 3 additions & 0 deletions chrome/browser/chromeos/login/wallpaper_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,9 @@ class WallpaperManager: public content::NotificationObserver {
// Returns wallpaper subdirectory name for current resolution.
const char* GetCustomWallpaperSubdirForCurrentResolution();

// Init default_wallpaper_image_ with 1x1 image of default color.
void CreateSolidDefaultWallpaper();

// The number of loaded wallpapers.
int loaded_wallpapers_;

Expand Down
67 changes: 35 additions & 32 deletions chrome/browser/chromeos/login/wallpaper_manager_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@
#include "chrome/test/base/testing_browser_process.h"
#include "chromeos/chromeos_switches.h"
#include "content/public/test/test_utils.h"
#include "grit/ash_resources.h"
#include "ui/aura/env.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/gfx/image/image_skia.h"
#include "ui/gfx/point.h"
#include "ui/gfx/rect.h"
Expand All @@ -46,9 +44,6 @@ namespace chromeos {

namespace {

const int kLargeWallpaperResourceId = IDR_AURA_WALLPAPER_DEFAULT_LARGE;
const int kSmallWallpaperResourceId = IDR_AURA_WALLPAPER_DEFAULT_SMALL;

int kLargeWallpaperWidth = 256;
int kLargeWallpaperHeight = chromeos::kLargeWallpaperMaxHeight;
int kSmallWallpaperWidth = 256;
Expand Down Expand Up @@ -123,19 +118,6 @@ class WallpaperManagerBrowserTest : public InProcessBrowserTest,
WaitAsyncWallpaperLoadStarted();
}

// Saves bitmap |resource_id| to disk.
void SaveUserWallpaperData(const base::FilePath& wallpaper_path,
int resource_id) {
scoped_refptr<base::RefCountedStaticMemory> image_data(
ResourceBundle::GetSharedInstance().LoadDataResourceBytesForScale(
resource_id, ui::SCALE_FACTOR_100P));
int written = base::WriteFile(
wallpaper_path,
reinterpret_cast<const char*>(image_data->front()),
image_data->size());
EXPECT_EQ(static_cast<int>(image_data->size()), written);
}

int LoadedWallpapers() {
return WallpaperManager::Get()->loaded_wallpapers();
}
Expand Down Expand Up @@ -185,10 +167,16 @@ IN_PROC_BROWSER_TEST_P(WallpaperManagerBrowserTest,

// Saves the small/large resolution wallpapers to small/large custom
// wallpaper paths.
SaveUserWallpaperData(small_wallpaper_path,
kSmallWallpaperResourceId);
SaveUserWallpaperData(large_wallpaper_path,
kLargeWallpaperResourceId);
ASSERT_TRUE(wallpaper_manager_test_utils::WriteJPEGFile(
small_wallpaper_path,
kSmallWallpaperWidth,
kSmallWallpaperHeight,
wallpaper_manager_test_utils::kSmallDefaultWallpaperColor));
ASSERT_TRUE(wallpaper_manager_test_utils::WriteJPEGFile(
large_wallpaper_path,
kLargeWallpaperWidth,
kLargeWallpaperHeight,
wallpaper_manager_test_utils::kLargeDefaultWallpaperColor));

std::string relative_path = base::FilePath(kTestUser1Hash).Append(id).value();
// Saves wallpaper info to local state for user |kTestUser1|.
Expand Down Expand Up @@ -269,8 +257,11 @@ IN_PROC_BROWSER_TEST_P(WallpaperManagerBrowserTest,
kSmallWallpaperSubDir,
kTestUser1Hash,
id);
SaveUserWallpaperData(small_wallpaper_path,
kSmallWallpaperResourceId);
ASSERT_TRUE(wallpaper_manager_test_utils::WriteJPEGFile(
small_wallpaper_path,
kSmallWallpaperWidth,
kSmallWallpaperHeight,
wallpaper_manager_test_utils::kSmallDefaultWallpaperColor));

std::string relative_path = base::FilePath(kTestUser1Hash).Append(id).value();
// Saves wallpaper info to local state for user |kTestUser1|.
Expand Down Expand Up @@ -314,8 +305,11 @@ IN_PROC_BROWSER_TEST_P(WallpaperManagerBrowserTest,
};
base::FilePath user_data_dir;
ASSERT_TRUE(PathService::Get(chrome::DIR_USER_DATA, &user_data_dir));
SaveUserWallpaperData(user_data_dir.Append("123"),
kLargeWallpaperResourceId);
ASSERT_TRUE(wallpaper_manager_test_utils::WriteJPEGFile(
user_data_dir.Append("123"),
wallpaper_manager_test_utils::kWallpaperSize,
wallpaper_manager_test_utils::kWallpaperSize,
wallpaper_manager_test_utils::kLargeDefaultWallpaperColor));
WallpaperManager::Get()->SetUserWallpaperInfo(kTestUser1, info, true);
}

Expand Down Expand Up @@ -391,8 +385,11 @@ IN_PROC_BROWSER_TEST_P(WallpaperManagerBrowserTestNoAnimation,
};
base::FilePath user_data_dir;
ASSERT_TRUE(PathService::Get(chrome::DIR_USER_DATA, &user_data_dir));
SaveUserWallpaperData(user_data_dir.Append("123"),
kLargeWallpaperResourceId);
ASSERT_TRUE(wallpaper_manager_test_utils::WriteJPEGFile(
user_data_dir.Append("123"),
wallpaper_manager_test_utils::kWallpaperSize,
wallpaper_manager_test_utils::kWallpaperSize,
wallpaper_manager_test_utils::kLargeDefaultWallpaperColor));
WallpaperManager::Get()->SetUserWallpaperInfo(kTestUser1, info, true);
}

Expand Down Expand Up @@ -485,10 +482,16 @@ IN_PROC_BROWSER_TEST_P(WallpaperManagerBrowserTestCacheUpdate,

// Saves the small/large resolution wallpapers to small/large custom
// wallpaper paths.
SaveUserWallpaperData(small_wallpaper_path,
kSmallWallpaperResourceId);
SaveUserWallpaperData(large_wallpaper_path,
kLargeWallpaperResourceId);
ASSERT_TRUE(wallpaper_manager_test_utils::WriteJPEGFile(
small_wallpaper_path,
kSmallWallpaperWidth,
kSmallWallpaperHeight,
wallpaper_manager_test_utils::kSmallDefaultWallpaperColor));
ASSERT_TRUE(wallpaper_manager_test_utils::WriteJPEGFile(
large_wallpaper_path,
kLargeWallpaperWidth,
kLargeWallpaperHeight,
wallpaper_manager_test_utils::kLargeDefaultWallpaperColor));

std::string relative_path = base::FilePath(kTestUser1Hash).Append(id).value();
// Saves wallpaper info to local state for user |kTestUser1|.
Expand Down

0 comments on commit 3c3f118

Please sign in to comment.