OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/ui/app_list/fast_show_pickler.h" | 5 #include "chrome/browser/ui/app_list/fast_show_pickler.h" |
6 | 6 |
7 #include "third_party/skia/include/core/SkBitmap.h" | 7 #include "third_party/skia/include/core/SkBitmap.h" |
8 #include "ui/app_list/app_list_item_model.h" | 8 #include "ui/app_list/app_list_item_model.h" |
9 #include "ui/gfx/image/image_skia_rep.h" | 9 #include "ui/gfx/image/image_skia_rep.h" |
10 | 10 |
11 namespace { | 11 namespace { |
12 | 12 |
13 using app_list::AppListItemModel; | 13 using app_list::AppListItemModel; |
14 using app_list::AppListModel; | 14 using app_list::AppListModel; |
15 | 15 |
16 // These have the same meaning as SkBitmap::Config. Reproduced here to insure | 16 // These have the same meaning as SkBitmap::Config. Reproduced here to insure |
17 // against their value changing in Skia. If the order of these changes kVersion | 17 // against their value changing in Skia. If the order of these changes kVersion |
18 // should be incremented. | 18 // should be incremented. |
19 enum ImageFormat { | 19 enum ImageFormat { |
20 NONE, | 20 NONE, |
21 A1, | |
22 A8, | 21 A8, |
23 INDEX_8, | 22 INDEX_8, |
24 RGB_565, | 23 RGB_565, |
25 ARGB_4444, | 24 ARGB_4444, |
26 ARGB_8888, | 25 ARGB_8888, |
27 }; | 26 }; |
28 | 27 |
29 bool FormatToConfig(ImageFormat format, SkBitmap::Config* out) { | 28 bool FormatToConfig(ImageFormat format, SkBitmap::Config* out) { |
30 switch (format) { | 29 switch (format) { |
31 case NONE: | 30 case NONE: |
32 *out = SkBitmap::kNo_Config; | 31 *out = SkBitmap::kNo_Config; |
33 break; | 32 break; |
34 case A1: | |
35 *out = SkBitmap::kA1_Config; | |
36 break; | |
37 case A8: | 33 case A8: |
38 *out = SkBitmap::kA8_Config; | 34 *out = SkBitmap::kA8_Config; |
39 break; | 35 break; |
40 case INDEX_8: | 36 case INDEX_8: |
41 *out = SkBitmap::kIndex8_Config; | 37 *out = SkBitmap::kIndex8_Config; |
42 break; | 38 break; |
43 case RGB_565: | 39 case RGB_565: |
44 *out = SkBitmap::kRGB_565_Config; | 40 *out = SkBitmap::kRGB_565_Config; |
45 break; | 41 break; |
46 case ARGB_4444: | 42 case ARGB_4444: |
47 *out = SkBitmap::kARGB_4444_Config; | 43 *out = SkBitmap::kARGB_4444_Config; |
48 break; | 44 break; |
49 case ARGB_8888: | 45 case ARGB_8888: |
50 *out = SkBitmap::kARGB_8888_Config; | 46 *out = SkBitmap::kARGB_8888_Config; |
51 break; | 47 break; |
52 default: return false; | 48 default: return false; |
53 } | 49 } |
54 return true; | 50 return true; |
55 } | 51 } |
56 | 52 |
57 bool ConfigToFormat(SkBitmap::Config config, ImageFormat* out) { | 53 bool ConfigToFormat(SkBitmap::Config config, ImageFormat* out) { |
58 switch (config) { | 54 switch (config) { |
59 case SkBitmap::kNo_Config: | 55 case SkBitmap::kNo_Config: |
60 *out = NONE; | 56 *out = NONE; |
61 break; | 57 break; |
62 case SkBitmap::kA1_Config: | |
63 *out = A1; | |
64 break; | |
65 case SkBitmap::kA8_Config: | 58 case SkBitmap::kA8_Config: |
66 *out = A8; | 59 *out = A8; |
67 break; | 60 break; |
68 case SkBitmap::kIndex8_Config: | 61 case SkBitmap::kIndex8_Config: |
69 *out = INDEX_8; | 62 *out = INDEX_8; |
70 break; | 63 break; |
71 case SkBitmap::kRGB_565_Config: | 64 case SkBitmap::kRGB_565_Config: |
72 *out = RGB_565; | 65 *out = RGB_565; |
73 break; | 66 break; |
74 case SkBitmap::kARGB_4444_Config: | 67 case SkBitmap::kARGB_4444_Config: |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 | 184 |
192 void CopyOverItem(AppListItemModel* src_item, AppListItemModel* dest_item) { | 185 void CopyOverItem(AppListItemModel* src_item, AppListItemModel* dest_item) { |
193 dest_item->SetTitleAndFullName(src_item->title(), src_item->full_name()); | 186 dest_item->SetTitleAndFullName(src_item->title(), src_item->full_name()); |
194 dest_item->SetIcon(src_item->icon(), src_item->has_shadow()); | 187 dest_item->SetIcon(src_item->icon(), src_item->has_shadow()); |
195 } | 188 } |
196 | 189 |
197 } // namespace | 190 } // namespace |
198 | 191 |
199 // The version of the pickle format defined here. This needs to be incremented | 192 // The version of the pickle format defined here. This needs to be incremented |
200 // whenever this format is changed so new clients can invalidate old versions. | 193 // whenever this format is changed so new clients can invalidate old versions. |
201 const int FastShowPickler::kVersion = 1; | 194 const int FastShowPickler::kVersion = 2; |
202 | 195 |
203 scoped_ptr<Pickle> FastShowPickler::PickleAppListModelForFastShow( | 196 scoped_ptr<Pickle> FastShowPickler::PickleAppListModelForFastShow( |
204 AppListModel* model) { | 197 AppListModel* model) { |
205 scoped_ptr<Pickle> result(new Pickle); | 198 scoped_ptr<Pickle> result(new Pickle); |
206 if (!result->WriteInt(kVersion)) | 199 if (!result->WriteInt(kVersion)) |
207 return scoped_ptr<Pickle>(); | 200 return scoped_ptr<Pickle>(); |
208 if (!result->WriteBool(model->signed_in())) | 201 if (!result->WriteBool(model->signed_in())) |
209 return scoped_ptr<Pickle>(); | 202 return scoped_ptr<Pickle>(); |
210 if (!result->WriteInt((int) model->item_list()->item_count())) | 203 if (!result->WriteInt((int) model->item_list()->item_count())) |
211 return scoped_ptr<Pickle>(); | 204 return scoped_ptr<Pickle>(); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 model->SetSignedIn(signed_in); | 239 model->SetSignedIn(signed_in); |
247 for (int i = 0; i < app_count; ++i) { | 240 for (int i = 0; i < app_count; ++i) { |
248 scoped_ptr<AppListItemModel> item(UnpickleAppListItemModel(&it).Pass()); | 241 scoped_ptr<AppListItemModel> item(UnpickleAppListItemModel(&it).Pass()); |
249 if (!item) | 242 if (!item) |
250 return scoped_ptr<AppListModel>(); | 243 return scoped_ptr<AppListModel>(); |
251 model->item_list()->AddItem(item.release()); | 244 model->item_list()->AddItem(item.release()); |
252 } | 245 } |
253 | 246 |
254 return model.Pass(); | 247 return model.Pass(); |
255 } | 248 } |
OLD | NEW |