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

Side by Side Diff: ui/base/resource/resource_bundle_mac.mm

Issue 6849030: Add support for multi resolution icons (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "ui/base/resource/resource_bundle.h" 5 #include "ui/base/resource/resource_bundle.h"
6 6
7 #import <AppKit/AppKit.h> 7 #import <AppKit/AppKit.h>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/file_path.h" 10 #include "base/file_path.h"
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 55
56 // On disk, the "en_US" resources are just "en" (http://crbug.com/25578). 56 // On disk, the "en_US" resources are just "en" (http://crbug.com/25578).
57 if ([mac_locale isEqual:@"en_US"]) 57 if ([mac_locale isEqual:@"en_US"])
58 mac_locale = @"en"; 58 mac_locale = @"en";
59 59
60 return GetResourcesPakFilePath(@"locale", mac_locale); 60 return GetResourcesPakFilePath(@"locale", mac_locale);
61 } 61 }
62 62
63 gfx::Image& ResourceBundle::GetNativeImageNamed(int resource_id) { 63 gfx::Image& ResourceBundle::GetNativeImageNamed(int resource_id) {
64 // Check to see if the image is already in the cache. 64 // Check to see if the image is already in the cache.
65 { 65 std::vector<gfx::Image*> images;
66 base::AutoLock lock(*lock_); 66 if (GetImagesFromCacheNamed(resource_id, images) && !images.empty())
67 ImageMap::const_iterator found = images_.find(resource_id); 67 return **images.begin();
68 if (found != images_.end()) {
69 if (!found->second->HasRepresentation(gfx::Image::kNSImageRep)) {
70 DLOG(WARNING) << "ResourceBundle::GetNativeImageNamed() is returning a"
71 << " cached gfx::Image that isn't backed by an NSImage. The image"
72 << " will be converted, rather than going through the NSImage loader."
73 << " resource_id = " << resource_id;
74 }
75 return *found->second;
76 }
77 }
78 68
79 // Load the raw data from the resource pack. 69 // Load the raw data from the resource pack.
80 scoped_refptr<RefCountedStaticMemory> data( 70 scoped_refptr<RefCountedStaticMemory> data(
81 LoadDataResourceBytes(resource_id)); 71 LoadDataResourceBytes(resource_id));
82 72
83 // Create a data object from the raw bytes. 73 // Create a data object from the raw bytes.
84 scoped_nsobject<NSData> ns_data([[NSData alloc] initWithBytes:data->front() 74 scoped_nsobject<NSData> ns_data([[NSData alloc] initWithBytes:data->front()
85 length:data->size()]); 75 length:data->size()]);
86 76
87 // Create the image from the data. The gfx::Image will take ownership of this. 77 // Create the image from the data. The gfx::Image will take ownership of this.
88 scoped_nsobject<NSImage> ns_image([[NSImage alloc] initWithData:ns_data]); 78 scoped_nsobject<NSImage> ns_image([[NSImage alloc] initWithData:ns_data]);
89 79
90 // Cache the converted image. 80 // Cache the converted image.
91 if (ns_image.get()) { 81 if (ns_image.get()) {
92 base::AutoLock lock(*lock_); 82 {
83 base::AutoLock lock(*lock_);
93 84
94 // Another thread raced the load and has already cached the image. 85 // Has another thread raced the load and has already cached the image?
95 if (images_.count(resource_id)) { 86 if (!images_.count(resource_id)) {
96 return *images_[resource_id]; 87 gfx::Image* image = new gfx::Image(ns_image.release());
88 std::vector<gfx::Image*>* images_ptr = new std::vector<gfx::Image*>;
89 images_ptr->push_back(image);
90 images_[resource_id] = images_ptr;
91 return *image;
92 }
97 } 93 }
98 94
99 gfx::Image* image = new gfx::Image(ns_image.release()); 95 if (GetImagesFromCacheNamed(resource_id, images) && !images.empty())
100 images_[resource_id] = image; 96 return **images.begin();
101 return *image;
102 } 97 }
103 98
104 LOG(WARNING) << "Unable to load image with id " << resource_id; 99 LOG(WARNING) << "Unable to load image with id " << resource_id;
105 NOTREACHED(); // Want to assert in debug mode. 100 NOTREACHED(); // Want to assert in debug mode.
106 return *GetEmptyImage(); 101 return *GetEmptyImage();
107 } 102 }
108 103
109 } // namespace ui 104 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698