| 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 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 13 #include "ui/base/ui_export.h" | 13 #include "ui/base/ui_export.h" |
| 14 #include "ui/gfx/image/image_skia_rep.h" | 14 #include "ui/gfx/image/image_skia_rep.h" |
| 15 | 15 |
| 16 namespace gfx { | 16 namespace gfx { |
| 17 class ImageSkiaSource; |
| 18 class Size; |
| 17 | 19 |
| 18 namespace internal { | 20 namespace internal { |
| 19 class ImageSkiaStorage; | 21 class ImageSkiaStorage; |
| 20 } // namespace internal | 22 } // namespace internal |
| 21 | 23 |
| 22 // Container for the same image at different densities, similar to NSImage. | 24 // Container for the same image at different densities, similar to NSImage. |
| 23 // Image height and width are in DIP (Device Indepent Pixel) coordinates. | 25 // Image height and width are in DIP (Density Indepent Pixel) coordinates. |
| 24 // | 26 // |
| 25 // ImageSkia should be used whenever possible instead of SkBitmap. | 27 // ImageSkia should be used whenever possible instead of SkBitmap. |
| 26 // Functions that mutate the image should operate on the gfx::ImageSkiaRep | 28 // Functions that mutate the image should operate on the gfx::ImageSkiaRep |
| 27 // returned from ImageSkia::GetRepresentation, not on ImageSkia. | 29 // returned from ImageSkia::GetRepresentation, not on ImageSkia. |
| 28 // | 30 // |
| 29 // ImageSkia is cheap to copy and intentionally supports copy semantics. | 31 // ImageSkia is cheap to copy and intentionally supports copy semantics. |
| 30 class UI_EXPORT ImageSkia { | 32 class UI_EXPORT ImageSkia { |
| 31 public: | 33 public: |
| 32 typedef std::vector<ImageSkiaRep> ImageSkiaReps; | 34 typedef std::vector<ImageSkiaRep> ImageSkiaReps; |
| 33 | 35 |
| 34 // Creates instance with no bitmaps. | 36 // Creates an instance with no bitmaps. |
| 35 ImageSkia(); | 37 ImageSkia(); |
| 36 | 38 |
| 39 // Creates an instance that will use the |source| to get the image |
| 40 // for scale factors. |size| specifes the size of the image in DIP. |
| 41 ImageSkia(ImageSkiaSource* soruce, const gfx::Size& size); |
| 42 |
| 37 // Adds ref to passed in bitmap. | 43 // Adds ref to passed in bitmap. |
| 38 // DIP width and height are set based on scale factor of 1x. | 44 // DIP width and height are set based on scale factor of 1x. |
| 39 // TODO(pkotwicz): This is temporary till conversion to gfx::ImageSkia is | 45 // TODO(pkotwicz): This is temporary till conversion to gfx::ImageSkia is |
| 40 // done. | 46 // done. |
| 41 ImageSkia(const SkBitmap& bitmap); | 47 ImageSkia(const SkBitmap& bitmap); |
| 42 | 48 |
| 43 ImageSkia(const gfx::ImageSkiaRep& image_rep); | 49 ImageSkia(const gfx::ImageSkiaRep& image_rep); |
| 44 | 50 |
| 45 // Copies a reference to |other|'s storage. | 51 // Copies a reference to |other|'s storage. |
| 46 ImageSkia(const ImageSkia& other); | 52 ImageSkia(const ImageSkia& other); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 // Returns true if object is null or its size is empty. | 94 // Returns true if object is null or its size is empty. |
| 89 bool empty() const; | 95 bool empty() const; |
| 90 | 96 |
| 91 // Returns true if this is a null object. | 97 // Returns true if this is a null object. |
| 92 // TODO(pkotwicz): Merge this function into empty(). | 98 // TODO(pkotwicz): Merge this function into empty(). |
| 93 bool isNull() const { return storage_ == NULL; } | 99 bool isNull() const { return storage_ == NULL; } |
| 94 | 100 |
| 95 // Width and height of image in DIP coordinate system. | 101 // Width and height of image in DIP coordinate system. |
| 96 int width() const; | 102 int width() const; |
| 97 int height() const; | 103 int height() const; |
| 104 gfx::Size size() const; |
| 98 | 105 |
| 99 // Wrapper function for SkBitmap::extractBitmap. | 106 // Wrapper function for SkBitmap::extractBitmap. |
| 100 // Operates on each stored image rep. | 107 // Operates on each stored image rep. |
| 101 bool extractSubset(ImageSkia* dst, const SkIRect& subset) const; | 108 bool extractSubset(ImageSkia* dst, const SkIRect& subset) const; |
| 102 | 109 |
| 103 // Returns pointer to an SkBitmap contained by this object. | 110 // Returns pointer to an SkBitmap contained by this object. |
| 104 // TODO(pkotwicz): This is temporary till conversion to gfx::ImageSkia is | 111 // TODO(pkotwicz): This is temporary till conversion to gfx::ImageSkia is |
| 105 // done. | 112 // done. |
| 106 const SkBitmap* bitmap() const; | 113 const SkBitmap* bitmap() const; |
| 107 | 114 |
| 108 // Returns a vector with the image reps contained in this object. | 115 // Returns a vector with the image reps contained in this object. |
| 109 std::vector<gfx::ImageSkiaRep> image_reps() const; | 116 std::vector<gfx::ImageSkiaRep> image_reps() const; |
| 110 | 117 |
| 111 private: | 118 private: |
| 112 // Initialize ImageSkiaStorage with passed in parameters. | 119 // Initialize ImageSkiaStorage with passed in parameters. |
| 113 // If the image rep's bitmap is empty, ImageStorage is set to NULL. | 120 // If the image rep's bitmap is empty, ImageStorage is set to NULL. |
| 114 void Init(const gfx::ImageSkiaRep& image_rep); | 121 void Init(const gfx::ImageSkiaRep& image_rep); |
| 115 | 122 |
| 116 // A null image rep to return as not to return a temporary. | |
| 117 static gfx::ImageSkiaRep& NullImageRep(); | |
| 118 | |
| 119 // Returns the iterator of the image rep whose density best matches | |
| 120 // |scale_factor|. | |
| 121 // ImageSkiaStorage cannot be NULL when this function is called. | |
| 122 ImageSkiaReps::iterator FindRepresentation( | |
| 123 ui::ScaleFactor scale_factor) const; | |
| 124 | |
| 125 // A refptr so that ImageRepSkia can be copied cheaply. | 123 // A refptr so that ImageRepSkia can be copied cheaply. |
| 126 scoped_refptr<internal::ImageSkiaStorage> storage_; | 124 scoped_refptr<internal::ImageSkiaStorage> storage_; |
| 127 }; | 125 }; |
| 128 | 126 |
| 129 } // namespace gfx | 127 } // namespace gfx |
| 130 | 128 |
| 131 #endif // UI_GFX_IMAGE_IMAGE_SKIA_H_ | 129 #endif // UI_GFX_IMAGE_IMAGE_SKIA_H_ |
| OLD | NEW |