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

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

Issue 10245003: Makes ImageSkia more like SkBitmap (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Updated comment Created 8 years, 7 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/ref_counted_memory.h" 9 #include "base/memory/ref_counted_memory.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 } 304 }
305 } 305 }
306 306
307 return NULL; 307 return NULL;
308 } 308 }
309 309
310 // Shifts a bitmap's HSL values. The caller is responsible for deleting 310 // Shifts a bitmap's HSL values. The caller is responsible for deleting
311 // the returned image. 311 // the returned image.
312 gfx::Image* CreateHSLShiftedImage(const gfx::Image& image, 312 gfx::Image* CreateHSLShiftedImage(const gfx::Image& image,
313 const color_utils::HSL& hsl_shift) { 313 const color_utils::HSL& hsl_shift) {
314 const std::vector<const SkBitmap*>& src_bitmaps = 314 const gfx::ImageSkia* src_image = image.ToImageSkia();
315 image.ToImageSkia()->bitmaps(); 315 const std::vector<SkBitmap> src_bitmaps = src_image->bitmaps();
316 std::vector<const SkBitmap*> dst_bitmaps; 316 gfx::ImageSkia dst_image;
317 for (size_t i = 0; i < src_bitmaps.size(); ++i) { 317 for (size_t i = 0; i < src_bitmaps.size(); ++i) {
318 const SkBitmap* bitmap = src_bitmaps[i]; 318 const SkBitmap& bitmap = src_bitmaps[i];
319 dst_bitmaps.push_back(new SkBitmap( 319 float scale_factor =
320 SkBitmapOperations::CreateHSLShiftedBitmap(*bitmap, hsl_shift))); 320 static_cast<float>(bitmap.width()) / src_image->width();
321 dst_image.AddBitmapForScale(
322 SkBitmapOperations::CreateHSLShiftedBitmap(bitmap, hsl_shift),
323 scale_factor);
321 } 324 }
322 return new gfx::Image(dst_bitmaps); 325 return new gfx::Image(dst_image);
323 } 326 }
324 327
325 } // namespace 328 } // namespace
326 329
327 BrowserThemePack::~BrowserThemePack() { 330 BrowserThemePack::~BrowserThemePack() {
328 if (!data_pack_.get()) { 331 if (!data_pack_.get()) {
329 delete header_; 332 delete header_;
330 delete [] tints_; 333 delete [] tints_;
331 delete [] colors_; 334 delete [] colors_;
332 delete [] display_properties_; 335 delete [] display_properties_;
(...skipping 652 matching lines...) Expand 10 before | Expand all | Expand 10 after
985 void BrowserThemePack::GenerateTabBackgroundImages(ImageCache* bitmaps) const { 988 void BrowserThemePack::GenerateTabBackgroundImages(ImageCache* bitmaps) const {
986 ImageCache temp_output; 989 ImageCache temp_output;
987 for (size_t i = 0; i < arraysize(kTabBackgroundMap); ++i) { 990 for (size_t i = 0; i < arraysize(kTabBackgroundMap); ++i) {
988 int prs_id = kTabBackgroundMap[i].key; 991 int prs_id = kTabBackgroundMap[i].key;
989 int prs_base_id = kTabBackgroundMap[i].value; 992 int prs_base_id = kTabBackgroundMap[i].value;
990 993
991 // We only need to generate the background tab images if we were provided 994 // We only need to generate the background tab images if we were provided
992 // with a PRS_THEME_FRAME. 995 // with a PRS_THEME_FRAME.
993 ImageCache::const_iterator it = bitmaps->find(prs_base_id); 996 ImageCache::const_iterator it = bitmaps->find(prs_base_id);
994 if (it != bitmaps->end()) { 997 if (it != bitmaps->end()) {
995 const gfx::Image& image_to_tint = *(it->second); 998 const gfx::ImageSkia* image_to_tint = (it->second)->ToImageSkia();
996 const std::vector<const SkBitmap*>& bitmaps_to_tint = 999 const std::vector<SkBitmap> bitmaps_to_tint = image_to_tint->bitmaps();
997 image_to_tint.ToImageSkia()->bitmaps(); 1000 gfx::ImageSkia tinted_image;
998 std::vector<const SkBitmap*> tinted_bitmaps;
999 for (size_t j = 0; j < bitmaps_to_tint.size(); ++j) { 1001 for (size_t j = 0; j < bitmaps_to_tint.size(); ++j) {
1000 SkBitmap bg_tint = SkBitmapOperations::CreateHSLShiftedBitmap( 1002 SkBitmap bg_tint = SkBitmapOperations::CreateHSLShiftedBitmap(
1001 *bitmaps_to_tint[j], GetTintInternal( 1003 bitmaps_to_tint[j], GetTintInternal(
1002 ThemeService::TINT_BACKGROUND_TAB)); 1004 ThemeService::TINT_BACKGROUND_TAB));
1003 int vertical_offset = bitmaps->count(prs_id) 1005 int vertical_offset = bitmaps->count(prs_id)
1004 ? kRestoredTabVerticalOffset : 0; 1006 ? kRestoredTabVerticalOffset : 0;
1005 SkBitmap* bg_tab = new SkBitmap(SkBitmapOperations::CreateTiledBitmap( 1007 SkBitmap bg_tab = SkBitmapOperations::CreateTiledBitmap(
1006 bg_tint, 0, vertical_offset, bg_tint.width(), bg_tint.height())); 1008 bg_tint, 0, vertical_offset, bg_tint.width(), bg_tint.height());
1007 1009
1008 // If they've provided a custom image, overlay it. 1010 // If they've provided a custom image, overlay it.
1009 ImageCache::const_iterator overlay_it = bitmaps->find(prs_id); 1011 ImageCache::const_iterator overlay_it = bitmaps->find(prs_id);
1010 if (overlay_it != bitmaps->end()) { 1012 if (overlay_it != bitmaps->end()) {
1011 const SkBitmap* overlay = overlay_it->second->ToSkBitmap(); 1013 const SkBitmap* overlay = overlay_it->second->ToSkBitmap();
1012 SkCanvas canvas(*bg_tab); 1014 SkCanvas canvas(bg_tab);
1013 for (int x = 0; x < bg_tab->width(); x += overlay->width()) 1015 for (int x = 0; x < bg_tab.width(); x += overlay->width())
1014 canvas.drawBitmap(*overlay, static_cast<SkScalar>(x), 0, NULL); 1016 canvas.drawBitmap(*overlay, static_cast<SkScalar>(x), 0, NULL);
1015 } 1017 }
1016 tinted_bitmaps.push_back(bg_tab); 1018 float scale_factor =
1019 static_cast<float>(bg_tab.width()) / image_to_tint->width();
1020 tinted_image.AddBitmapForScale(bg_tab, scale_factor);
1017 } 1021 }
1018 1022
1019 gfx::Image* tinted_image = new gfx::Image(tinted_bitmaps); 1023 temp_output[prs_id] = new gfx::Image(tinted_image);
1020 temp_output[prs_id] = tinted_image;
1021 } 1024 }
1022 } 1025 }
1023 1026
1024 MergeImageCaches(temp_output, bitmaps); 1027 MergeImageCaches(temp_output, bitmaps);
1025 } 1028 }
1026 1029
1027 void BrowserThemePack::RepackImages(const ImageCache& images, 1030 void BrowserThemePack::RepackImages(const ImageCache& images,
1028 RawImages* reencoded_images) const { 1031 RawImages* reencoded_images) const {
1029 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 1032 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
1030 for (ImageCache::const_iterator it = images.begin(); 1033 for (ImageCache::const_iterator it = images.begin();
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
1071 hsl.h = tints_[i].h; 1074 hsl.h = tints_[i].h;
1072 hsl.s = tints_[i].s; 1075 hsl.s = tints_[i].s;
1073 hsl.l = tints_[i].l; 1076 hsl.l = tints_[i].l;
1074 return hsl; 1077 return hsl;
1075 } 1078 }
1076 } 1079 }
1077 } 1080 }
1078 1081
1079 return ThemeService::GetDefaultTint(id); 1082 return ThemeService::GetDefaultTint(id);
1080 } 1083 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/image_loading_tracker_unittest.cc ('k') | chrome/browser/web_applications/web_app_mac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698