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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 ImageSkia* GetErrorImageSkia() { | 59 ImageSkia* GetErrorImageSkia() { |
60 SkBitmap bitmap; | 60 SkBitmap bitmap; |
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 ~PNGImageSource() override {} |
70 | 70 |
71 virtual ImageSkiaRep GetImageForScale(float scale) override { | 71 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 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 class ImageRepPNG : public ImageRep { | 214 class ImageRepPNG : public ImageRep { |
215 public: | 215 public: |
216 ImageRepPNG() : ImageRep(Image::kImageRepPNG) { | 216 ImageRepPNG() : ImageRep(Image::kImageRepPNG) { |
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 ~ImageRepPNG() override {} |
225 } | |
226 | 225 |
227 virtual int Width() const override { | 226 int Width() const override { return Size().width(); } |
228 return Size().width(); | |
229 } | |
230 | 227 |
231 virtual int Height() const override { | 228 int Height() const override { return Size().height(); } |
232 return Size().height(); | |
233 } | |
234 | 229 |
235 virtual gfx::Size Size() const override { | 230 gfx::Size Size() const override { |
236 // Read the PNG data to get the image size, caching it. | 231 // Read the PNG data to get the image size, caching it. |
237 if (!size_cache_) { | 232 if (!size_cache_) { |
238 for (std::vector<ImagePNGRep>::const_iterator it = image_reps().begin(); | 233 for (std::vector<ImagePNGRep>::const_iterator it = image_reps().begin(); |
239 it != image_reps().end(); ++it) { | 234 it != image_reps().end(); ++it) { |
240 if (it->scale == 1.0f) { | 235 if (it->scale == 1.0f) { |
241 size_cache_.reset(new gfx::Size(it->Size())); | 236 size_cache_.reset(new gfx::Size(it->Size())); |
242 return *size_cache_; | 237 return *size_cache_; |
243 } | 238 } |
244 } | 239 } |
245 size_cache_.reset(new gfx::Size); | 240 size_cache_.reset(new gfx::Size); |
(...skipping 14 matching lines...) Expand all Loading... |
260 }; | 255 }; |
261 | 256 |
262 class ImageRepSkia : public ImageRep { | 257 class ImageRepSkia : public ImageRep { |
263 public: | 258 public: |
264 // Takes ownership of |image|. | 259 // Takes ownership of |image|. |
265 explicit ImageRepSkia(ImageSkia* image) | 260 explicit ImageRepSkia(ImageSkia* image) |
266 : ImageRep(Image::kImageRepSkia), | 261 : ImageRep(Image::kImageRepSkia), |
267 image_(image) { | 262 image_(image) { |
268 } | 263 } |
269 | 264 |
270 virtual ~ImageRepSkia() { | 265 ~ImageRepSkia() override {} |
271 } | |
272 | 266 |
273 virtual int Width() const override { | 267 int Width() const override { return image_->width(); } |
274 return image_->width(); | |
275 } | |
276 | 268 |
277 virtual int Height() const override { | 269 int Height() const override { return image_->height(); } |
278 return image_->height(); | |
279 } | |
280 | 270 |
281 virtual gfx::Size Size() const override { | 271 gfx::Size Size() const override { return image_->size(); } |
282 return image_->size(); | |
283 } | |
284 | 272 |
285 ImageSkia* image() { return image_.get(); } | 273 ImageSkia* image() { return image_.get(); } |
286 | 274 |
287 private: | 275 private: |
288 scoped_ptr<ImageSkia> image_; | 276 scoped_ptr<ImageSkia> image_; |
289 | 277 |
290 DISALLOW_COPY_AND_ASSIGN(ImageRepSkia); | 278 DISALLOW_COPY_AND_ASSIGN(ImageRepSkia); |
291 }; | 279 }; |
292 | 280 |
293 #if defined(OS_IOS) | 281 #if defined(OS_IOS) |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
325 }; | 313 }; |
326 #elif defined(OS_MACOSX) | 314 #elif defined(OS_MACOSX) |
327 class ImageRepCocoa : public ImageRep { | 315 class ImageRepCocoa : public ImageRep { |
328 public: | 316 public: |
329 explicit ImageRepCocoa(NSImage* image) | 317 explicit ImageRepCocoa(NSImage* image) |
330 : ImageRep(Image::kImageRepCocoa), | 318 : ImageRep(Image::kImageRepCocoa), |
331 image_(image) { | 319 image_(image) { |
332 CHECK(image); | 320 CHECK(image); |
333 } | 321 } |
334 | 322 |
335 virtual ~ImageRepCocoa() { | 323 ~ImageRepCocoa() override { |
336 base::mac::NSObjectRelease(image_); | 324 base::mac::NSObjectRelease(image_); |
337 image_ = nil; | 325 image_ = nil; |
338 } | 326 } |
339 | 327 |
340 virtual int Width() const override { | 328 int Width() const override { return Size().width(); } |
341 return Size().width(); | |
342 } | |
343 | 329 |
344 virtual int Height() const override { | 330 int Height() const override { return Size().height(); } |
345 return Size().height(); | |
346 } | |
347 | 331 |
348 virtual gfx::Size Size() const override { | 332 gfx::Size Size() const override { return internal::NSImageSize(image_); } |
349 return internal::NSImageSize(image_); | |
350 } | |
351 | 333 |
352 NSImage* image() const { return image_; } | 334 NSImage* image() const { return image_; } |
353 | 335 |
354 private: | 336 private: |
355 NSImage* image_; | 337 NSImage* image_; |
356 | 338 |
357 DISALLOW_COPY_AND_ASSIGN(ImageRepCocoa); | 339 DISALLOW_COPY_AND_ASSIGN(ImageRepCocoa); |
358 }; | 340 }; |
359 #endif // defined(OS_MACOSX) | 341 #endif // defined(OS_MACOSX) |
360 | 342 |
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
770 } | 752 } |
771 return it->second; | 753 return it->second; |
772 } | 754 } |
773 | 755 |
774 void Image::AddRepresentation(internal::ImageRep* rep) const { | 756 void Image::AddRepresentation(internal::ImageRep* rep) const { |
775 CHECK(storage_.get()); | 757 CHECK(storage_.get()); |
776 storage_->representations().insert(std::make_pair(rep->type(), rep)); | 758 storage_->representations().insert(std::make_pair(rep->type(), rep)); |
777 } | 759 } |
778 | 760 |
779 } // namespace gfx | 761 } // namespace gfx |
OLD | NEW |