Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / ash / desktop_background / wallpaper_resizer.h
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef ASH_DESKTOP_BACKGROUND_DESKTOP_WALLPAPER_RESIZER_H_
6 #define ASH_DESKTOP_BACKGROUND_DESKTOP_WALLPAPER_RESIZER_H_
7
8 #include "ash/ash_export.h"
9 #include "ash/desktop_background/desktop_background_controller.h"
10 #include "base/memory/weak_ptr.h"
11 #include "base/observer_list.h"
12 #include "skia/ext/image_operations.h"
13 #include "third_party/skia/include/core/SkBitmap.h"
14 #include "ui/gfx/image/image_skia.h"
15 #include "ui/gfx/size.h"
16
17 namespace ash {
18
19 class WallpaperResizerObserver;
20
21 // Stores the current wallpaper data and resize it to |target_size| if needed.
22 class ASH_EXPORT WallpaperResizer {
23  public:
24   // Returns a unique identifier corresponding to |image|, suitable for
25   // comparison against the value returned by original_image_id(). If the image
26   // is modified, its ID will change.
27   static uint32_t GetImageId(const gfx::ImageSkia& image);
28
29   WallpaperResizer(int image_resource_id,
30                    const gfx::Size& target_size,
31                    WallpaperLayout layout);
32
33   WallpaperResizer(const gfx::ImageSkia& image,
34                    const gfx::Size& target_size,
35                    WallpaperLayout layout);
36
37   ~WallpaperResizer();
38
39   const gfx::ImageSkia& image() const { return image_; }
40   uint32_t original_image_id() const { return original_image_id_; }
41   WallpaperLayout layout() const { return layout_; }
42
43   int resource_id() const { return resource_id_; }
44
45   // Called on the UI thread to run Resize() on the worker pool and post an
46   // OnResizeFinished() task back to the UI thread on completion.
47   void StartResize();
48
49   // Add/Remove observers.
50   void AddObserver(WallpaperResizerObserver* observer);
51   void RemoveObserver(WallpaperResizerObserver* observer);
52
53  private:
54   // Copies |resized_bitmap| to |image_| and notifies observers after Resize()
55   // has finished running.
56   void OnResizeFinished(SkBitmap* resized_bitmap);
57
58   ObserverList<WallpaperResizerObserver> observers_;
59
60   // Image that should currently be used for wallpaper. It initially
61   // contains the original image and is updated to contain the resized
62   // image by OnResizeFinished().
63   gfx::ImageSkia image_;
64
65   // Unique identifier corresponding to the original (i.e. pre-resize) |image_|.
66   uint32_t original_image_id_;
67
68   // kInvalidResourceID if image was not obtained from resources.
69   const int resource_id_;
70
71   gfx::Size target_size_;
72
73   WallpaperLayout layout_;
74
75   base::WeakPtrFactory<WallpaperResizer> weak_ptr_factory_;
76
77   DISALLOW_COPY_AND_ASSIGN(WallpaperResizer);
78 };
79
80 }  // namespace ash
81
82
83 #endif  // ASH_DESKTOP_BACKGROUND_DESKTOP_WALLPAPER_RESIZER_H_