| OLD | NEW | 
|---|
| 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/icon_loader.h" | 5 #include "chrome/browser/icon_loader.h" | 
| 6 | 6 | 
| 7 #include <map> | 7 #include <map> | 
| 8 #include <string> | 8 #include <string> | 
| 9 #include <utility> | 9 #include <utility> | 
| 10 | 10 | 
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 157     case IconLoader::ALL: | 157     case IconLoader::ALL: | 
| 158     default: | 158     default: | 
| 159       NOTREACHED(); | 159       NOTREACHED(); | 
| 160   } | 160   } | 
| 161   return idr; | 161   return idr; | 
| 162 } | 162 } | 
| 163 | 163 | 
| 164 // Returns a copy of |source| that is |pixel_size| in width and height. If | 164 // Returns a copy of |source| that is |pixel_size| in width and height. If | 
| 165 // |pixel_size| is |kDoNotResize|, returns an unmodified copy of |source|. | 165 // |pixel_size| is |kDoNotResize|, returns an unmodified copy of |source|. | 
| 166 // |source| must be a square image (width == height). | 166 // |source| must be a square image (width == height). | 
| 167 SkBitmap* GenerateBitmapWithSize(SkBitmap* source, int pixel_size) { | 167 SkBitmap GenerateBitmapWithSize(const SkBitmap& source, int pixel_size) { | 
| 168   DCHECK(source); | 168   DCHECK(!source.isNull()); | 
| 169   DCHECK(source->width() == source->height()); | 169   DCHECK(source.width() == source.height()); | 
| 170 | 170 | 
| 171   if (pixel_size == kDoNotResize || source->width() == pixel_size) | 171   if (pixel_size == kDoNotResize || source.width() == pixel_size) | 
| 172     return new SkBitmap(*source); | 172     return source; | 
| 173 | 173 | 
| 174   return new SkBitmap(skia::ImageOperations::Resize( | 174   return skia::ImageOperations::Resize( | 
| 175       *source, skia::ImageOperations::RESIZE_BEST, pixel_size, pixel_size)); | 175     source, skia::ImageOperations::RESIZE_BEST, pixel_size, pixel_size); | 
| 176 } | 176 } | 
| 177 | 177 | 
| 178 int IconSizeToPixelSize(IconLoader::IconSize size) { | 178 int IconSizeToPixelSize(IconLoader::IconSize size) { | 
| 179   switch (size) { | 179   switch (size) { | 
| 180     case IconLoader::SMALL:  return 16; | 180     case IconLoader::SMALL:  return 16; | 
| 181     case IconLoader::NORMAL: return 32; | 181     case IconLoader::NORMAL: return 32; | 
| 182     case IconLoader::LARGE:  // fallthrough | 182     case IconLoader::LARGE:  // fallthrough | 
| 183       // On ChromeOS, we consider LARGE to mean "the largest image we have." | 183       // On ChromeOS, we consider LARGE to mean "the largest image we have." | 
| 184       // Since we have already chosen the largest applicable image resource, we | 184       // Since we have already chosen the largest applicable image resource, we | 
| 185       // return the image as-is. | 185       // return the image as-is. | 
| (...skipping 10 matching lines...) Expand all  Loading... | 
| 196       LAZY_INSTANCE_INITIALIZER; | 196       LAZY_INSTANCE_INITIALIZER; | 
| 197   int idr = icon_mapper.Get().Lookup(group_, icon_size_); | 197   int idr = icon_mapper.Get().Lookup(group_, icon_size_); | 
| 198   ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 198   ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 
| 199   scoped_refptr<base::RefCountedStaticMemory> bytes( | 199   scoped_refptr<base::RefCountedStaticMemory> bytes( | 
| 200       rb.LoadDataResourceBytes(idr)); | 200       rb.LoadDataResourceBytes(idr)); | 
| 201   DCHECK(bytes.get()); | 201   DCHECK(bytes.get()); | 
| 202   SkBitmap bitmap; | 202   SkBitmap bitmap; | 
| 203   if (!gfx::PNGCodec::Decode(bytes->front(), bytes->size(), &bitmap)) | 203   if (!gfx::PNGCodec::Decode(bytes->front(), bytes->size(), &bitmap)) | 
| 204     NOTREACHED(); | 204     NOTREACHED(); | 
| 205   image_.reset(new gfx::Image( | 205   image_.reset(new gfx::Image( | 
| 206       GenerateBitmapWithSize(&bitmap, IconSizeToPixelSize(icon_size_)))); | 206       GenerateBitmapWithSize(bitmap, IconSizeToPixelSize(icon_size_)))); | 
| 207   target_message_loop_->PostTask( | 207   target_message_loop_->PostTask( | 
| 208       FROM_HERE, base::Bind(&IconLoader::NotifyDelegate, this)); | 208       FROM_HERE, base::Bind(&IconLoader::NotifyDelegate, this)); | 
| 209 } | 209 } | 
| OLD | NEW | 
|---|