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

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

Issue 10086023: Expose array of bitmaps contained by gfx::Image similar to NSImage (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Nicer diff Created 8 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 | Annotate | Revision Log
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 #include "chrome/browser/themes/browser_theme_pack.h" 5 #include "chrome/browser/themes/browser_theme_pack.h"
6 6
7 #include <limits> 7 #include <limits>
8 8
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/stl_util.h" 10 #include "base/stl_util.h"
11 #include "base/string_util.h" 11 #include "base/string_util.h"
12 #include "base/threading/thread_restrictions.h" 12 #include "base/threading/thread_restrictions.h"
13 #include "base/utf_string_conversions.h" 13 #include "base/utf_string_conversions.h"
14 #include "base/values.h" 14 #include "base/values.h"
15 #include "chrome/browser/themes/theme_service.h" 15 #include "chrome/browser/themes/theme_service.h"
16 #include "content/public/browser/browser_thread.h" 16 #include "content/public/browser/browser_thread.h"
17 #include "grit/theme_resources.h" 17 #include "grit/theme_resources.h"
18 #include "grit/theme_resources_standard.h" 18 #include "grit/theme_resources_standard.h"
19 #include "grit/ui_resources.h" 19 #include "grit/ui_resources.h"
20 #include "net/base/file_stream.h" 20 #include "net/base/file_stream.h"
21 #include "net/base/net_errors.h" 21 #include "net/base/net_errors.h"
22 #include "third_party/skia/include/core/SkCanvas.h" 22 #include "third_party/skia/include/core/SkCanvas.h"
23 #include "ui/base/resource/data_pack.h" 23 #include "ui/base/resource/data_pack.h"
24 #include "ui/base/resource/resource_bundle.h" 24 #include "ui/base/resource/resource_bundle.h"
25 #include "ui/gfx/codec/png_codec.h" 25 #include "ui/gfx/codec/png_codec.h"
26 #include "ui/gfx/image/image.h" 26 #include "ui/gfx/image/image.h"
27 #include "ui/gfx/image/image_skia.h"
27 #include "ui/gfx/skbitmap_operations.h" 28 #include "ui/gfx/skbitmap_operations.h"
28 29
29 using content::BrowserThread; 30 using content::BrowserThread;
30 31
31 namespace { 32 namespace {
32 33
33 // Version number of the current theme pack. We just throw out and rebuild 34 // Version number of the current theme pack. We just throw out and rebuild
34 // theme packs that aren't int-equal to this. Increment this number if you 35 // theme packs that aren't int-equal to this. Increment this number if you
35 // change default theme assets. 36 // change default theme assets.
36 const int kThemePackVersion = 20; 37 const int kThemePackVersion = 20;
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 } 304 }
304 305
305 return NULL; 306 return NULL;
306 } 307 }
307 308
308 // Shifts a bitmap's HSL values. The caller is responsible for deleting 309 // Shifts a bitmap's HSL values. The caller is responsible for deleting
309 // the returned image. 310 // the returned image.
310 gfx::Image* CreateHSLShiftedImage(const gfx::Image& image, 311 gfx::Image* CreateHSLShiftedImage(const gfx::Image& image,
311 const color_utils::HSL& hsl_shift) { 312 const color_utils::HSL& hsl_shift) {
312 std::vector<const SkBitmap*> bitmaps; 313 std::vector<const SkBitmap*> bitmaps;
313 for (size_t i = 0; i < image.GetNumberOfSkBitmaps(); ++i) { 314 const gfx::ImageSkia* image_skia = image.ToImageSkia();
314 const SkBitmap* bitmap = image.GetSkBitmapAtIndex(i); 315 for (size_t i = 0; i < image_skia->GetNumberOfBitmaps(); ++i) {
316 const SkBitmap* bitmap = image_skia->GetBitmapAtIndex(i);
315 bitmaps.push_back(new SkBitmap(SkBitmapOperations::CreateHSLShiftedBitmap( 317 bitmaps.push_back(new SkBitmap(SkBitmapOperations::CreateHSLShiftedBitmap(
316 *bitmap, hsl_shift))); 318 *bitmap, hsl_shift)));
317 } 319 }
318 return new gfx::Image(bitmaps); 320 return new gfx::Image(bitmaps);
319 } 321 }
320 322
321 } // namespace 323 } // namespace
322 324
323 BrowserThemePack::~BrowserThemePack() { 325 BrowserThemePack::~BrowserThemePack() {
324 if (!data_pack_.get()) { 326 if (!data_pack_.get()) {
(...skipping 657 matching lines...) Expand 10 before | Expand all | Expand 10 after
982 for (size_t i = 0; i < arraysize(kTabBackgroundMap); ++i) { 984 for (size_t i = 0; i < arraysize(kTabBackgroundMap); ++i) {
983 int prs_id = kTabBackgroundMap[i].key; 985 int prs_id = kTabBackgroundMap[i].key;
984 int prs_base_id = kTabBackgroundMap[i].value; 986 int prs_base_id = kTabBackgroundMap[i].value;
985 987
986 // We only need to generate the background tab images if we were provided 988 // We only need to generate the background tab images if we were provided
987 // with a PRS_THEME_FRAME. 989 // with a PRS_THEME_FRAME.
988 ImageCache::const_iterator it = bitmaps->find(prs_base_id); 990 ImageCache::const_iterator it = bitmaps->find(prs_base_id);
989 if (it != bitmaps->end()) { 991 if (it != bitmaps->end()) {
990 const gfx::Image& image_to_tint = *(it->second); 992 const gfx::Image& image_to_tint = *(it->second);
991 std::vector<const SkBitmap*> tinted_bitmaps; 993 std::vector<const SkBitmap*> tinted_bitmaps;
992 for (size_t j = 0; j < image_to_tint.GetNumberOfSkBitmaps(); ++j) { 994 const gfx::ImageSkia* image_to_tint_skia = image_to_tint.ToImageSkia();
995 for (size_t j = 0; j < image_to_tint_skia->GetNumberOfBitmaps(); ++j) {
993 SkBitmap bg_tint = SkBitmapOperations::CreateHSLShiftedBitmap( 996 SkBitmap bg_tint = SkBitmapOperations::CreateHSLShiftedBitmap(
994 *image_to_tint.GetSkBitmapAtIndex(j), GetTintInternal( 997 *image_to_tint_skia->GetBitmapAtIndex(j), GetTintInternal(
995 ThemeService::TINT_BACKGROUND_TAB)); 998 ThemeService::TINT_BACKGROUND_TAB));
996 int vertical_offset = bitmaps->count(prs_id) 999 int vertical_offset = bitmaps->count(prs_id)
997 ? kRestoredTabVerticalOffset : 0; 1000 ? kRestoredTabVerticalOffset : 0;
998 SkBitmap* bg_tab = new SkBitmap(SkBitmapOperations::CreateTiledBitmap( 1001 SkBitmap* bg_tab = new SkBitmap(SkBitmapOperations::CreateTiledBitmap(
999 bg_tint, 0, vertical_offset, bg_tint.width(), bg_tint.height())); 1002 bg_tint, 0, vertical_offset, bg_tint.width(), bg_tint.height()));
1000 1003
1001 // If they've provided a custom image, overlay it. 1004 // If they've provided a custom image, overlay it.
1002 ImageCache::const_iterator overlay_it = bitmaps->find(prs_id); 1005 ImageCache::const_iterator overlay_it = bitmaps->find(prs_id);
1003 if (overlay_it != bitmaps->end()) { 1006 if (overlay_it != bitmaps->end()) {
1004 const SkBitmap* overlay = overlay_it->second->ToSkBitmap(); 1007 const SkBitmap* overlay = overlay_it->second->ToSkBitmap();
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
1063 hsl.h = tints_[i].h; 1066 hsl.h = tints_[i].h;
1064 hsl.s = tints_[i].s; 1067 hsl.s = tints_[i].s;
1065 hsl.l = tints_[i].l; 1068 hsl.l = tints_[i].l;
1066 return hsl; 1069 return hsl;
1067 } 1070 }
1068 } 1071 }
1069 } 1072 }
1070 1073
1071 return ThemeService::GetDefaultTint(id); 1074 return ThemeService::GetDefaultTint(id);
1072 } 1075 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698