summaryrefslogtreecommitdiffstats
path: root/ash/app_list/icon_cache.h
blob: f06ac1d921222ec666a9d3334f878fcd1c0d92cd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef ASH_APP_LIST_ICON_CACHE_H_
#define ASH_APP_LIST_ICON_CACHE_H_
#pragma once

#include <map>
#include <string>

#include "base/basictypes.h"
#include "third_party/skia/include/core/SkBitmap.h"

namespace gfx {
class Size;
}

namespace ash {

// IconCache stores processed image, keyed by the source image and desired size.
class IconCache {
 public:
  static void CreateInstance();
  static void DeleteInstance();

  static IconCache* GetInstance();

  void MarkAllEntryUnused();
  void PurgeAllUnused();

  bool Get(const SkBitmap& src,
           const gfx::Size& size,
           SkBitmap* processed);
  void Put(const SkBitmap& src,
           const gfx::Size& size,
           const SkBitmap& processed);

 private:
  struct Item {
    SkBitmap image;
    bool used;
  };
  typedef std::map<std::string, Item> Cache;

  IconCache();
  ~IconCache();

  static IconCache* instance_;

  Cache cache_;

  DISALLOW_COPY_AND_ASSIGN(IconCache);
};

}  // namespace ash

#endif  // ASH_APP_LIST_ICON_CACHE_H_