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

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
« no previous file with comments | « ui/gfx/image/image_skia.h ('k') | ui/gfx/image/image_skia_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
236 ImageSkiaReps internal_image_reps = storage_->image_reps();
237 // Create list of image reps to return, skipping null image reps which were
238 // added for caching purposes only.
239 ImageSkiaReps image_reps;
240 for (ImageSkiaReps::iterator it = internal_image_reps.begin();
241 it != internal_image_reps.end(); ++it) {
242 if (!it->is_null())
243 image_reps.push_back(*it);
244 }
245
246 return image_reps;
247 }
248
249 #endif // OS_MACOSX
250
216 bool ImageSkia::empty() const { 251 bool ImageSkia::empty() const {
217 return isNull() || storage_->size().IsEmpty(); 252 return isNull() || storage_->size().IsEmpty();
218 } 253 }
219 254
220 int ImageSkia::width() const { 255 int ImageSkia::width() const {
221 return isNull() ? 0 : storage_->size().width(); 256 return isNull() ? 0 : storage_->size().width();
222 } 257 }
223 258
224 gfx::Size ImageSkia::size() const { 259 gfx::Size ImageSkia::size() const {
225 return gfx::Size(width(), height()); 260 return gfx::Size(width(), height());
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 if (image_rep.sk_bitmap().empty()) { 315 if (image_rep.sk_bitmap().empty()) {
281 storage_ = NULL; 316 storage_ = NULL;
282 return; 317 return;
283 } 318 }
284 storage_ = new internal::ImageSkiaStorage( 319 storage_ = new internal::ImageSkiaStorage(
285 NULL, gfx::Size(image_rep.GetWidth(), image_rep.GetHeight())); 320 NULL, gfx::Size(image_rep.GetWidth(), image_rep.GetHeight()));
286 storage_->image_reps().push_back(image_rep); 321 storage_->image_reps().push_back(image_rep);
287 } 322 }
288 323
289 } // namespace gfx 324 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/image/image_skia.h ('k') | ui/gfx/image/image_skia_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698