| 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 "ui/gfx/image/image.h" | 5 #include "ui/gfx/image/image.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <set> | 8 #include <set> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 bitmap.allocN32Pixels(16, 16); | 61 bitmap.allocN32Pixels(16, 16); |
| 62 bitmap.eraseARGB(0xff, 0xff, 0, 0); | 62 bitmap.eraseARGB(0xff, 0xff, 0, 0); |
| 63 return new ImageSkia(ImageSkiaRep(bitmap, 1.0f)); | 63 return new ImageSkia(ImageSkiaRep(bitmap, 1.0f)); |
| 64 } | 64 } |
| 65 | 65 |
| 66 class PNGImageSource : public ImageSkiaSource { | 66 class PNGImageSource : public ImageSkiaSource { |
| 67 public: | 67 public: |
| 68 PNGImageSource() {} | 68 PNGImageSource() {} |
| 69 virtual ~PNGImageSource() {} | 69 virtual ~PNGImageSource() {} |
| 70 | 70 |
| 71 virtual ImageSkiaRep GetImageForScale(float scale) OVERRIDE { | 71 virtual ImageSkiaRep GetImageForScale(float scale) override { |
| 72 if (image_skia_reps_.empty()) | 72 if (image_skia_reps_.empty()) |
| 73 return ImageSkiaRep(); | 73 return ImageSkiaRep(); |
| 74 | 74 |
| 75 const ImageSkiaRep* rep = NULL; | 75 const ImageSkiaRep* rep = NULL; |
| 76 // gfx::ImageSkia passes one of the resource scale factors. The source | 76 // gfx::ImageSkia passes one of the resource scale factors. The source |
| 77 // should return: | 77 // should return: |
| 78 // 1) The ImageSkiaRep with the highest scale if all available | 78 // 1) The ImageSkiaRep with the highest scale if all available |
| 79 // scales are smaller than |scale|. | 79 // scales are smaller than |scale|. |
| 80 // 2) The ImageSkiaRep with the smallest one that is larger than |scale|. | 80 // 2) The ImageSkiaRep with the smallest one that is larger than |scale|. |
| 81 for (ImageSkiaRepSet::const_iterator iter = image_skia_reps_.begin(); | 81 for (ImageSkiaRepSet::const_iterator iter = image_skia_reps_.begin(); |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 } | 217 } |
| 218 | 218 |
| 219 ImageRepPNG(const std::vector<ImagePNGRep>& image_png_reps) | 219 ImageRepPNG(const std::vector<ImagePNGRep>& image_png_reps) |
| 220 : ImageRep(Image::kImageRepPNG), | 220 : ImageRep(Image::kImageRepPNG), |
| 221 image_png_reps_(image_png_reps) { | 221 image_png_reps_(image_png_reps) { |
| 222 } | 222 } |
| 223 | 223 |
| 224 virtual ~ImageRepPNG() { | 224 virtual ~ImageRepPNG() { |
| 225 } | 225 } |
| 226 | 226 |
| 227 virtual int Width() const OVERRIDE { | 227 virtual int Width() const override { |
| 228 return Size().width(); | 228 return Size().width(); |
| 229 } | 229 } |
| 230 | 230 |
| 231 virtual int Height() const OVERRIDE { | 231 virtual int Height() const override { |
| 232 return Size().height(); | 232 return Size().height(); |
| 233 } | 233 } |
| 234 | 234 |
| 235 virtual gfx::Size Size() const OVERRIDE { | 235 virtual gfx::Size Size() const override { |
| 236 // Read the PNG data to get the image size, caching it. | 236 // Read the PNG data to get the image size, caching it. |
| 237 if (!size_cache_) { | 237 if (!size_cache_) { |
| 238 for (std::vector<ImagePNGRep>::const_iterator it = image_reps().begin(); | 238 for (std::vector<ImagePNGRep>::const_iterator it = image_reps().begin(); |
| 239 it != image_reps().end(); ++it) { | 239 it != image_reps().end(); ++it) { |
| 240 if (it->scale == 1.0f) { | 240 if (it->scale == 1.0f) { |
| 241 size_cache_.reset(new gfx::Size(it->Size())); | 241 size_cache_.reset(new gfx::Size(it->Size())); |
| 242 return *size_cache_; | 242 return *size_cache_; |
| 243 } | 243 } |
| 244 } | 244 } |
| 245 size_cache_.reset(new gfx::Size); | 245 size_cache_.reset(new gfx::Size); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 263 public: | 263 public: |
| 264 // Takes ownership of |image|. | 264 // Takes ownership of |image|. |
| 265 explicit ImageRepSkia(ImageSkia* image) | 265 explicit ImageRepSkia(ImageSkia* image) |
| 266 : ImageRep(Image::kImageRepSkia), | 266 : ImageRep(Image::kImageRepSkia), |
| 267 image_(image) { | 267 image_(image) { |
| 268 } | 268 } |
| 269 | 269 |
| 270 virtual ~ImageRepSkia() { | 270 virtual ~ImageRepSkia() { |
| 271 } | 271 } |
| 272 | 272 |
| 273 virtual int Width() const OVERRIDE { | 273 virtual int Width() const override { |
| 274 return image_->width(); | 274 return image_->width(); |
| 275 } | 275 } |
| 276 | 276 |
| 277 virtual int Height() const OVERRIDE { | 277 virtual int Height() const override { |
| 278 return image_->height(); | 278 return image_->height(); |
| 279 } | 279 } |
| 280 | 280 |
| 281 virtual gfx::Size Size() const OVERRIDE { | 281 virtual gfx::Size Size() const override { |
| 282 return image_->size(); | 282 return image_->size(); |
| 283 } | 283 } |
| 284 | 284 |
| 285 ImageSkia* image() { return image_.get(); } | 285 ImageSkia* image() { return image_.get(); } |
| 286 | 286 |
| 287 private: | 287 private: |
| 288 scoped_ptr<ImageSkia> image_; | 288 scoped_ptr<ImageSkia> image_; |
| 289 | 289 |
| 290 DISALLOW_COPY_AND_ASSIGN(ImageRepSkia); | 290 DISALLOW_COPY_AND_ASSIGN(ImageRepSkia); |
| 291 }; | 291 }; |
| 292 | 292 |
| 293 #if defined(OS_IOS) | 293 #if defined(OS_IOS) |
| 294 class ImageRepCocoaTouch : public ImageRep { | 294 class ImageRepCocoaTouch : public ImageRep { |
| 295 public: | 295 public: |
| 296 explicit ImageRepCocoaTouch(UIImage* image) | 296 explicit ImageRepCocoaTouch(UIImage* image) |
| 297 : ImageRep(Image::kImageRepCocoaTouch), | 297 : ImageRep(Image::kImageRepCocoaTouch), |
| 298 image_(image) { | 298 image_(image) { |
| 299 CHECK(image); | 299 CHECK(image); |
| 300 } | 300 } |
| 301 | 301 |
| 302 virtual ~ImageRepCocoaTouch() { | 302 virtual ~ImageRepCocoaTouch() { |
| 303 base::mac::NSObjectRelease(image_); | 303 base::mac::NSObjectRelease(image_); |
| 304 image_ = nil; | 304 image_ = nil; |
| 305 } | 305 } |
| 306 | 306 |
| 307 virtual int Width() const OVERRIDE { | 307 virtual int Width() const override { |
| 308 return Size().width(); | 308 return Size().width(); |
| 309 } | 309 } |
| 310 | 310 |
| 311 virtual int Height() const OVERRIDE { | 311 virtual int Height() const override { |
| 312 return Size().height(); | 312 return Size().height(); |
| 313 } | 313 } |
| 314 | 314 |
| 315 virtual gfx::Size Size() const OVERRIDE { | 315 virtual gfx::Size Size() const override { |
| 316 return internal::UIImageSize(image_); | 316 return internal::UIImageSize(image_); |
| 317 } | 317 } |
| 318 | 318 |
| 319 UIImage* image() const { return image_; } | 319 UIImage* image() const { return image_; } |
| 320 | 320 |
| 321 private: | 321 private: |
| 322 UIImage* image_; | 322 UIImage* image_; |
| 323 | 323 |
| 324 DISALLOW_COPY_AND_ASSIGN(ImageRepCocoaTouch); | 324 DISALLOW_COPY_AND_ASSIGN(ImageRepCocoaTouch); |
| 325 }; | 325 }; |
| 326 #elif defined(OS_MACOSX) | 326 #elif defined(OS_MACOSX) |
| 327 class ImageRepCocoa : public ImageRep { | 327 class ImageRepCocoa : public ImageRep { |
| 328 public: | 328 public: |
| 329 explicit ImageRepCocoa(NSImage* image) | 329 explicit ImageRepCocoa(NSImage* image) |
| 330 : ImageRep(Image::kImageRepCocoa), | 330 : ImageRep(Image::kImageRepCocoa), |
| 331 image_(image) { | 331 image_(image) { |
| 332 CHECK(image); | 332 CHECK(image); |
| 333 } | 333 } |
| 334 | 334 |
| 335 virtual ~ImageRepCocoa() { | 335 virtual ~ImageRepCocoa() { |
| 336 base::mac::NSObjectRelease(image_); | 336 base::mac::NSObjectRelease(image_); |
| 337 image_ = nil; | 337 image_ = nil; |
| 338 } | 338 } |
| 339 | 339 |
| 340 virtual int Width() const OVERRIDE { | 340 virtual int Width() const override { |
| 341 return Size().width(); | 341 return Size().width(); |
| 342 } | 342 } |
| 343 | 343 |
| 344 virtual int Height() const OVERRIDE { | 344 virtual int Height() const override { |
| 345 return Size().height(); | 345 return Size().height(); |
| 346 } | 346 } |
| 347 | 347 |
| 348 virtual gfx::Size Size() const OVERRIDE { | 348 virtual gfx::Size Size() const override { |
| 349 return internal::NSImageSize(image_); | 349 return internal::NSImageSize(image_); |
| 350 } | 350 } |
| 351 | 351 |
| 352 NSImage* image() const { return image_; } | 352 NSImage* image() const { return image_; } |
| 353 | 353 |
| 354 private: | 354 private: |
| 355 NSImage* image_; | 355 NSImage* image_; |
| 356 | 356 |
| 357 DISALLOW_COPY_AND_ASSIGN(ImageRepCocoa); | 357 DISALLOW_COPY_AND_ASSIGN(ImageRepCocoa); |
| 358 }; | 358 }; |
| (...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 770 } | 770 } |
| 771 return it->second; | 771 return it->second; |
| 772 } | 772 } |
| 773 | 773 |
| 774 void Image::AddRepresentation(internal::ImageRep* rep) const { | 774 void Image::AddRepresentation(internal::ImageRep* rep) const { |
| 775 CHECK(storage_.get()); | 775 CHECK(storage_.get()); |
| 776 storage_->representations().insert(std::make_pair(rep->type(), rep)); | 776 storage_->representations().insert(std::make_pair(rep->type(), rep)); |
| 777 } | 777 } |
| 778 | 778 |
| 779 } // namespace gfx | 779 } // namespace gfx |
| OLD | NEW |