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

Side by Side Diff: ui/gfx/image/image_skia.cc

Issue 10780010: Introduces ImageSkia::GetRepresentations() for Mac (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 5 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 "ui/gfx/image/image_skia.h" 5 #include "ui/gfx/image/image_skia.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 #include <limits> 9 #include <limits>
10 10
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 // A helper class such that ImageSkia can be cheaply copied. ImageSkia holds a 46 // A helper class such that ImageSkia can be cheaply copied. ImageSkia holds a
47 // refptr instance of ImageSkiaStorage, which in turn holds all of ImageSkia's 47 // refptr instance of ImageSkiaStorage, which in turn holds all of ImageSkia's
48 // information. 48 // information.
49 class ImageSkiaStorage : public base::RefCounted<ImageSkiaStorage> { 49 class ImageSkiaStorage : public base::RefCounted<ImageSkiaStorage> {
50 public: 50 public:
51 ImageSkiaStorage(ImageSkiaSource* source, const gfx::Size& size) 51 ImageSkiaStorage(ImageSkiaSource* source, const gfx::Size& size)
52 : source_(source), 52 : source_(source),
53 size_(size) { 53 size_(size) {
54 } 54 }
55 55
56 bool has_source() const { return source_.get() != NULL; }
57
56 std::vector<gfx::ImageSkiaRep>& image_reps() { return image_reps_; } 58 std::vector<gfx::ImageSkiaRep>& image_reps() { return image_reps_; }
57 59
58 const gfx::Size& size() const { return size_; } 60 const gfx::Size& size() const { return size_; }
59 61
60 // Returns the iterator of the image rep whose density best matches 62 // Returns the iterator of the image rep whose density best matches
61 // |scale_factor|. If the image for the |scale_factor| doesn't exist 63 // |scale_factor|. If the image for the |scale_factor| doesn't exist
62 // in the storage and |storage| is set, it fetches new image by calling 64 // in the storage and |storage| is set, it fetches new image by calling
63 // |ImageSkiaSource::GetImageForScale|. If the source returns the 65 // |ImageSkiaSource::GetImageForScale|. If the source returns the
64 // image with different scale factor (if the image doesn't exist in 66 // image with different scale factor (if the image doesn't exist in
65 // resource, for example), it will fallback to closest image rep. 67 // resource, for example), it will fallback to closest image rep.
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 if (isNull()) 208 if (isNull())
207 return NullImageRep(); 209 return NullImageRep();
208 210
209 ImageSkiaReps::iterator it = storage_->FindRepresentation(scale_factor, true); 211 ImageSkiaReps::iterator it = storage_->FindRepresentation(scale_factor, true);
210 if (it == storage_->image_reps().end()) 212 if (it == storage_->image_reps().end())
211 return NullImageRep(); 213 return NullImageRep();
212 214
213 return *it; 215 return *it;
214 } 216 }
215 217
218 #if defined(OS_MACOSX)
219
220 std::vector<ImageSkiaRep> ImageSkia::GetRepresentations() const {
221 if (isNull())
222 return std::vector<ImageSkiaRep>();
223
224 if (!storage_->has_source())
225 return image_reps();
226
227 // Attempt to generate image reps for as many scale factors supported by
228 // this platform as possible.
229 // Do not build return array here because the mapping from scale factor to
230 // image rep is one to many in some cases.
231 std::vector<ui::ScaleFactor> supported_scale_factors =
232 ui::GetSupportedScaleFactors();
233 for (size_t i = 0; i < supported_scale_factors.size(); ++i) {
234 storage_->FindRepresentation(supported_scale_factors[i], true);
235 }
oshima 2012/07/17 16:43:21 nuke {}
236
237 ImageSkiaReps internal_image_reps = storage_->image_reps();
238 // Create list of image reps to return, skipping null image reps which were
239 // added for caching purposes only.
240 ImageSkiaReps image_reps;
241 for (ImageSkiaReps::iterator it = internal_image_reps.begin();
242 it != internal_image_reps.end(); ++it) {
243 if (!it->is_null())
244 image_reps.push_back(*it);
245 }
246
247 return image_reps;
248 }
249
250 #endif // OS_MACOSX
251
216 bool ImageSkia::empty() const { 252 bool ImageSkia::empty() const {
217 return isNull() || storage_->size().IsEmpty(); 253 return isNull() || storage_->size().IsEmpty();
218 } 254 }
219 255
220 int ImageSkia::width() const { 256 int ImageSkia::width() const {
221 return isNull() ? 0 : storage_->size().width(); 257 return isNull() ? 0 : storage_->size().width();
222 } 258 }
223 259
224 gfx::Size ImageSkia::size() const { 260 gfx::Size ImageSkia::size() const {
225 return gfx::Size(width(), height()); 261 return gfx::Size(width(), height());
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 if (image_rep.sk_bitmap().empty()) { 314 if (image_rep.sk_bitmap().empty()) {
279 storage_ = NULL; 315 storage_ = NULL;
280 return; 316 return;
281 } 317 }
282 storage_ = new internal::ImageSkiaStorage( 318 storage_ = new internal::ImageSkiaStorage(
283 NULL, gfx::Size(image_rep.GetWidth(), image_rep.GetHeight())); 319 NULL, gfx::Size(image_rep.GetWidth(), image_rep.GetHeight()));
284 storage_->image_reps().push_back(image_rep); 320 storage_->image_reps().push_back(image_rep);
285 } 321 }
286 322
287 } // namespace gfx 323 } // namespace gfx
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698