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

Side by Side Diff: chrome/browser/themes/browser_theme_pack.h

Issue 13497002: Crop images from custom themes before storing them into the theme pack (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 7 years, 8 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
« no previous file with comments | « no previous file | chrome/browser/themes/browser_theme_pack.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #ifndef CHROME_BROWSER_THEMES_BROWSER_THEME_PACK_H_ 5 #ifndef CHROME_BROWSER_THEMES_BROWSER_THEME_PACK_H_
6 #define CHROME_BROWSER_THEMES_BROWSER_THEME_PACK_H_ 6 #define CHROME_BROWSER_THEMES_BROWSER_THEME_PACK_H_
7 7
8 #include <map> 8 #include <map>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/basictypes.h" 12 #include "base/basictypes.h"
13 #include "base/memory/ref_counted.h" 13 #include "base/memory/ref_counted.h"
14 #include "base/memory/scoped_ptr.h" 14 #include "base/memory/scoped_ptr.h"
15 #include "base/sequenced_task_runner_helpers.h" 15 #include "base/sequenced_task_runner_helpers.h"
16 #include "chrome/common/extensions/extension.h" 16 #include "chrome/common/extensions/extension.h"
17 #include "content/public/browser/browser_thread.h" 17 #include "content/public/browser/browser_thread.h"
18 #include "third_party/skia/include/core/SkColor.h" 18 #include "third_party/skia/include/core/SkColor.h"
19 #include "ui/base/layout.h" 19 #include "ui/base/layout.h"
20 #include "ui/gfx/color_utils.h" 20 #include "ui/gfx/color_utils.h"
21 #include "ui/gfx/image/image.h"
21 22
22 namespace base { 23 namespace base {
23 class DictionaryValue; 24 class DictionaryValue;
24 class FilePath; 25 class FilePath;
25 class RefCountedMemory; 26 class RefCountedMemory;
26 } 27 }
27 28
28 namespace extensions { 29 namespace extensions {
29 class Extensions; 30 class Extensions;
30 } 31 }
31 32
32 namespace gfx {
33 class Image;
34 }
35
36 namespace ui { 33 namespace ui {
37 class DataPack; 34 class DataPack;
38 } 35 }
39 36
40 // An optimized representation of a theme, backed by a mmapped DataPack. 37 // An optimized representation of a theme, backed by a mmapped DataPack.
41 // 38 //
42 // The idea is to pre-process all images (tinting, compositing, etc) at theme 39 // The idea is to pre-process all images (tinting, compositing, etc) at theme
43 // install time, save all the PNG-ified data into an mmappable file so we don't 40 // install time, save all the PNG-ified data into an mmappable file so we don't
44 // suffer multiple file system access times, therefore solving two of the 41 // suffer multiple file system access times, therefore solving two of the
45 // problems with the previous implementation. 42 // problems with the previous implementation.
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 bool WriteToDisk(const base::FilePath& path) const; 74 bool WriteToDisk(const base::FilePath& path) const;
78 75
79 // If this theme specifies data for the corresponding |id|, return true and 76 // If this theme specifies data for the corresponding |id|, return true and
80 // write the corresponding value to the output parameter. These functions 77 // write the corresponding value to the output parameter. These functions
81 // don't return the default data. These methods should only be called from 78 // don't return the default data. These methods should only be called from
82 // the UI thread. (But this isn't enforced because of unit tests). 79 // the UI thread. (But this isn't enforced because of unit tests).
83 bool GetTint(int id, color_utils::HSL* hsl) const; 80 bool GetTint(int id, color_utils::HSL* hsl) const;
84 bool GetColor(int id, SkColor* color) const; 81 bool GetColor(int id, SkColor* color) const;
85 bool GetDisplayProperty(int id, int* result) const; 82 bool GetDisplayProperty(int id, int* result) const;
86 83
87 // Returns an image if we have a custom image for |id|, otherwise NULL. 84 // Returns the theme pack image for |id|. Returns an empty image if an image
88 const gfx::Image* GetImageNamed(int id) const; 85 // is not found.
86 gfx::Image GetImageNamed(int id);
89 87
90 // Returns the raw PNG encoded data for IDR_THEME_NTP_*. This method is only 88 // Returns the raw PNG encoded data for IDR_THEME_NTP_*. This method is only
91 // supposed to work for the NTP attribution and background resources. 89 // supposed to work for the NTP attribution and background resources.
92 base::RefCountedMemory* GetRawData(int id, 90 base::RefCountedMemory* GetRawData(int id,
93 ui::ScaleFactor scale_factor) const; 91 ui::ScaleFactor scale_factor) const;
94 92
95 // Returns the set of image idrs which can be overwritten by a user provided 93 // Returns the set of image idrs which can be overwritten by a user provided
96 // theme. 94 // theme.
97 static void GetThemeableImageIDRs(std::set<int>* result); 95 static void GetThemeableImageIDRs(std::set<int>* result);
98 96
99 // Whether this theme provides an image for |id|. 97 // Whether this theme provides an image for |id|.
100 bool HasCustomImage(int id) const; 98 bool HasCustomImage(int id) const;
101 99
102 private: 100 private:
103 friend struct content::BrowserThread::DeleteOnThread< 101 friend struct content::BrowserThread::DeleteOnThread<
104 content::BrowserThread::FILE>; 102 content::BrowserThread::FILE>;
105 friend class base::DeleteHelper<BrowserThemePack>; 103 friend class base::DeleteHelper<BrowserThemePack>;
106 friend class BrowserThemePackTest; 104 friend class BrowserThemePackTest;
107 105
108 // Cached images. We cache all retrieved and generated images and keep 106 // Cached images.
109 // track of the pointers. We own these and will delete them when we're done 107 typedef std::map<int, gfx::Image> ImageCache;
110 // using them.
111 typedef std::map<int, const gfx::Image*> ImageCache;
112 108
113 // The raw PNG memory associated with a certain id. 109 // The raw PNG memory associated with a certain id.
114 typedef std::map<int, scoped_refptr<base::RefCountedMemory> > RawImages; 110 typedef std::map<int, scoped_refptr<base::RefCountedMemory> > RawImages;
115 111
116 // The type passed to ui::DataPack::WritePack. 112 // The type passed to ui::DataPack::WritePack.
117 typedef std::map<uint16, base::StringPiece> RawDataForWriting; 113 typedef std::map<uint16, base::StringPiece> RawDataForWriting;
118 114
119 // An association between an id and the base::FilePath that has the image data . 115 // An association between an id and the base::FilePath that has the image data .
120 typedef std::map<int, base::FilePath> FilePathMap; 116 typedef std::map<int, base::FilePath> FilePathMap;
121 117
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 // Loads the unmodified images packed in the extension to SkBitmaps. Returns 150 // Loads the unmodified images packed in the extension to SkBitmaps. Returns
155 // true if all images loaded. 151 // true if all images loaded.
156 bool LoadRawBitmapsTo(const FilePathMap& file_paths, 152 bool LoadRawBitmapsTo(const FilePathMap& file_paths,
157 ImageCache* image_cache); 153 ImageCache* image_cache);
158 154
159 // Populate |images| cache with empty gfx::Images. Image reps are lazily 155 // Populate |images| cache with empty gfx::Images. Image reps are lazily
160 // generated when an image rep is requested via ImageSkia::GetRepresentation. 156 // generated when an image rep is requested via ImageSkia::GetRepresentation.
161 // Source and destination is |images|. 157 // Source and destination is |images|.
162 void CreateImages(ImageCache* images) const; 158 void CreateImages(ImageCache* images) const;
163 159
160 // Crops images down to a size such that most of the cropped image will be
161 // displayed in the UI. Cropping is useful because images from custom themes
162 // can be of any size. Source and destination is |images|.
163 void CropImages(ImageCache* images) const;
164
164 // Creates tinted and composited frame images. Source and destination is 165 // Creates tinted and composited frame images. Source and destination is
165 // |images|. 166 // |images|.
166 void CreateFrameImages(ImageCache* images) const; 167 void CreateFrameImages(ImageCache* images) const;
167 168
168 // Creates button images tinted with |button_tint| and places them in 169 // Creates button images tinted with |button_tint| and places them in
169 // processed_images. 170 // processed_images.
170 void CreateTintedButtons(const color_utils::HSL& button_tint, 171 void CreateTintedButtons(const color_utils::HSL& button_tint,
171 ImageCache* processed_images) const; 172 ImageCache* processed_images) const;
172 173
173 // Creates the semi-transparent tab background images, putting the results 174 // Creates the semi-transparent tab background images, putting the results
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 250
250 // References to raw PNG data. This map isn't touched when |data_pack_| is 251 // References to raw PNG data. This map isn't touched when |data_pack_| is
251 // non-NULL; |image_memory_| is only filled during BuildFromExtension(). Any 252 // non-NULL; |image_memory_| is only filled during BuildFromExtension(). Any
252 // image data that needs to be written to the DataPack during WriteToDisk() 253 // image data that needs to be written to the DataPack during WriteToDisk()
253 // needs to be in |image_memory_|. 254 // needs to be in |image_memory_|.
254 RawImages image_memory_; 255 RawImages image_memory_;
255 256
256 // Loaded images. These are loaded from |image_memory_|, from |data_pack_|, 257 // Loaded images. These are loaded from |image_memory_|, from |data_pack_|,
257 // and by BuildFromExtension(). These images should only be accessed on the UI 258 // and by BuildFromExtension(). These images should only be accessed on the UI
258 // thread. 259 // thread.
259 mutable ImageCache images_on_ui_thread_; 260 ImageCache images_on_ui_thread_;
260 261
261 // Cache of images created in BuildFromExtension(). Once the theme pack is 262 // Cache of images created in BuildFromExtension(). Once the theme pack is
262 // created, this cache should only be accessed on the file thread. There 263 // created, this cache should only be accessed on the file thread. There
263 // should be no IDs in |image_memory_| that are in |images_on_file_thread_| 264 // should be no IDs in |image_memory_| that are in |images_on_file_thread_|
264 // or vice versa. 265 // or vice versa.
265 ImageCache images_on_file_thread_; 266 ImageCache images_on_file_thread_;
266 267
267 DISALLOW_COPY_AND_ASSIGN(BrowserThemePack); 268 DISALLOW_COPY_AND_ASSIGN(BrowserThemePack);
268 }; 269 };
269 270
270 #endif // CHROME_BROWSER_THEMES_BROWSER_THEME_PACK_H_ 271 #endif // CHROME_BROWSER_THEMES_BROWSER_THEME_PACK_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/themes/browser_theme_pack.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698