| 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 #ifndef UI_GFX_IMAGE_IMAGE_SKIA_H_ | 5 #ifndef UI_GFX_IMAGE_IMAGE_SKIA_H_ |
| 6 #define UI_GFX_IMAGE_IMAGE_SKIA_H_ | 6 #define UI_GFX_IMAGE_IMAGE_SKIA_H_ |
| 7 | 7 |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 } // namespace internal | 21 } // namespace internal |
| 22 | 22 |
| 23 // Container for the same image at different densities, similar to NSImage. | 23 // Container for the same image at different densities, similar to NSImage. |
| 24 // Image height and width are in DIP (Density Indepent Pixel) coordinates. | 24 // Image height and width are in DIP (Density Indepent Pixel) coordinates. |
| 25 // | 25 // |
| 26 // ImageSkia should be used whenever possible instead of SkBitmap. | 26 // ImageSkia should be used whenever possible instead of SkBitmap. |
| 27 // Functions that mutate the image should operate on the gfx::ImageSkiaRep | 27 // Functions that mutate the image should operate on the gfx::ImageSkiaRep |
| 28 // returned from ImageSkia::GetRepresentation, not on ImageSkia. | 28 // returned from ImageSkia::GetRepresentation, not on ImageSkia. |
| 29 // | 29 // |
| 30 // ImageSkia is cheap to copy and intentionally supports copy semantics. | 30 // ImageSkia is cheap to copy and intentionally supports copy semantics. |
| 31 // |
| 32 // TODO(oshima): ImageSkia can and may contain multiple reps |
| 33 // with the same scale factor. Fix the client code and pro |
| 31 class UI_EXPORT ImageSkia { | 34 class UI_EXPORT ImageSkia { |
| 32 public: | 35 public: |
| 33 typedef std::vector<ImageSkiaRep> ImageSkiaReps; | 36 typedef std::vector<ImageSkiaRep> ImageSkiaReps; |
| 34 | 37 |
| 35 // Creates an instance with no bitmaps. | 38 // Creates an instance with no bitmaps. |
| 36 ImageSkia(); | 39 ImageSkia(); |
| 37 | 40 |
| 38 // Creates an instance that will use the |source| to get the image | 41 // Creates an instance that will use the |source| to get the image |
| 39 // for scale factors. |size| specifes the size of the image in DIP. | 42 // for scale factors. |size| specifes the size of the image in DIP. |
| 43 // ImageSkia owns |source|. |
| 40 ImageSkia(ImageSkiaSource* source, const gfx::Size& size); | 44 ImageSkia(ImageSkiaSource* source, const gfx::Size& size); |
| 41 | 45 |
| 42 // Adds ref to passed in bitmap. | 46 // Adds ref to passed in bitmap. |
| 43 // DIP width and height are set based on scale factor of 1x. | 47 // DIP width and height are set based on scale factor of 1x. |
| 44 // TODO(pkotwicz): This is temporary till conversion to gfx::ImageSkia is | 48 // TODO(pkotwicz): This is temporary till conversion to gfx::ImageSkia is |
| 45 // done. | 49 // done. |
| 46 ImageSkia(const SkBitmap& bitmap); | 50 ImageSkia(const SkBitmap& bitmap); |
| 47 | 51 |
| 48 ImageSkia(const gfx::ImageSkiaRep& image_rep); | 52 ImageSkia(const gfx::ImageSkiaRep& image_rep); |
| 49 | 53 |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 // TODO(pkotwicz): Return null SkBitmap when the object has no 1x bitmap. | 117 // TODO(pkotwicz): Return null SkBitmap when the object has no 1x bitmap. |
| 114 const SkBitmap* bitmap() const { return &GetBitmap(); } | 118 const SkBitmap* bitmap() const { return &GetBitmap(); } |
| 115 | 119 |
| 116 // Returns a vector with the image reps contained in this object. | 120 // Returns a vector with the image reps contained in this object. |
| 117 // There is no guarantee that this will return all images rep for | 121 // There is no guarantee that this will return all images rep for |
| 118 // supported scale factors. | 122 // supported scale factors. |
| 119 // TODO(oshima): Update all use of this API and make this to fail | 123 // TODO(oshima): Update all use of this API and make this to fail |
| 120 // when source is used. | 124 // when source is used. |
| 121 std::vector<gfx::ImageSkiaRep> image_reps() const; | 125 std::vector<gfx::ImageSkiaRep> image_reps() const; |
| 122 | 126 |
| 127 // Delete the ImageSkiaSource if any. It will make GetRepresentation |
| 128 // thread safe because it will no longer update the storage. |
| 129 void DeleteSource(); |
| 130 |
| 131 // When the soruce is available, generates all ImageReps for |
| 132 // supported scale factors. |
| 133 void EnsureRepsForSupportedScaleFactors() const; |
| 134 |
| 123 private: | 135 private: |
| 124 // Initialize ImageSkiaStorage with passed in parameters. | 136 // Initialize ImageSkiaStorage with passed in parameters. |
| 125 // If the image rep's bitmap is empty, ImageStorage is set to NULL. | 137 // If the image rep's bitmap is empty, ImageStorage is set to NULL. |
| 126 void Init(const gfx::ImageSkiaRep& image_rep); | 138 void Init(const gfx::ImageSkiaRep& image_rep); |
| 127 | 139 |
| 128 SkBitmap& GetBitmap() const; | 140 SkBitmap& GetBitmap() const; |
| 129 | 141 |
| 130 // A refptr so that ImageRepSkia can be copied cheaply. | 142 // A refptr so that ImageRepSkia can be copied cheaply. |
| 131 scoped_refptr<internal::ImageSkiaStorage> storage_; | 143 scoped_refptr<internal::ImageSkiaStorage> storage_; |
| 132 }; | 144 }; |
| 133 | 145 |
| 134 } // namespace gfx | 146 } // namespace gfx |
| 135 | 147 |
| 136 #endif // UI_GFX_IMAGE_IMAGE_SKIA_H_ | 148 #endif // UI_GFX_IMAGE_IMAGE_SKIA_H_ |
| OLD | NEW |