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

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

Issue 10783015: Add ability to store hidpi theme images in data pack (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 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 return false; 255 return false;
254 256
255 *dst = image; 257 *dst = image;
256 return true; 258 return true;
257 } 259 }
258 260
259 std::vector<ImageSkiaRep> ImageSkia::image_reps() const { 261 std::vector<ImageSkiaRep> ImageSkia::image_reps() const {
260 if (isNull()) 262 if (isNull())
261 return std::vector<ImageSkiaRep>(); 263 return std::vector<ImageSkiaRep>();
262 264
263 return storage_->image_reps(); 265 ImageSkiaReps internal_image_reps = storage_->image_reps();
266 // Create list of image reps to return, skipping null image reps which were
267 // added for caching purposes only.
268 ImageSkiaReps image_reps;
269 for (ImageSkiaReps::iterator it = internal_image_reps.begin();
270 it != internal_image_reps.end(); ++it) {
271 if (!it->is_null())
272 image_reps.push_back(*it);
273 }
274
275 return image_reps;
264 } 276 }
265 277
266 const SkBitmap* ImageSkia::bitmap() const { 278 const SkBitmap* ImageSkia::bitmap() const {
267 if (isNull()) { 279 if (isNull()) {
268 // Callers expect a ImageSkiaRep even if it is |isNull()|. 280 // Callers expect a ImageSkiaRep even if it is |isNull()|.
269 // TODO(pkotwicz): Fix this. 281 // TODO(pkotwicz): Fix this.
270 return &NullImageRep().sk_bitmap(); 282 return &NullImageRep().sk_bitmap();
271 } 283 }
272 284
273 ImageSkiaReps::iterator it = 285 ImageSkiaReps::iterator it =
274 storage_->FindRepresentation(ui::SCALE_FACTOR_100P, true); 286 storage_->FindRepresentation(ui::SCALE_FACTOR_100P, true);
275 return &it->sk_bitmap(); 287 return &it->sk_bitmap();
276 } 288 }
277 289
278 void ImageSkia::Init(const ImageSkiaRep& image_rep) { 290 void ImageSkia::Init(const ImageSkiaRep& image_rep) {
279 // TODO(pkotwicz): The image should be null whenever image rep is null. 291 // TODO(pkotwicz): The image should be null whenever image rep is null.
280 if (image_rep.sk_bitmap().empty()) { 292 if (image_rep.sk_bitmap().empty()) {
281 storage_ = NULL; 293 storage_ = NULL;
282 return; 294 return;
283 } 295 }
284 storage_ = new internal::ImageSkiaStorage( 296 storage_ = new internal::ImageSkiaStorage(
285 NULL, gfx::Size(image_rep.GetWidth(), image_rep.GetHeight())); 297 NULL, gfx::Size(image_rep.GetWidth(), image_rep.GetHeight()));
286 storage_->image_reps().push_back(image_rep); 298 storage_->image_reps().push_back(image_rep);
287 } 299 }
288 300
289 } // namespace gfx 301 } // namespace gfx
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698