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

Unified Diff: ui/gfx/image/image_skia.h

Issue 10245003: Makes ImageSkia more like SkBitmap (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Updated comment Created 8 years, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/gfx/image/image_mac_unittest.mm ('k') | ui/gfx/image/image_skia.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/gfx/image/image_skia.h
diff --git a/ui/gfx/image/image_skia.h b/ui/gfx/image/image_skia.h
index bdfb53f8d89ae941d143d303b88c35a41af76551..059665cb1d09d0c5cc1da7f9f54053a0723eab10 100644
--- a/ui/gfx/image/image_skia.h
+++ b/ui/gfx/image/image_skia.h
@@ -9,80 +9,114 @@
#include <vector>
#include "base/basictypes.h"
+#include "base/memory/ref_counted.h"
#include "third_party/skia/include/core/SkBitmap.h"
-#include "ui/gfx/canvas.h"
-#include "ui/gfx/size.h"
+#include "ui/base/ui_export.h"
namespace gfx {
-// Container for the same image at different densities, similar to NSImage.
-// Smallest image is assumed to represent 1x density.
+namespace internal {
+class ImageSkiaStorage;
+} // namespace internal
-// ImageSkia should be used for caching and drawing images of different
-// densities. It should not be used as an SkBitmap wrapper.
+// Container for the same image at different densities, similar to NSImage.
+// Image height and width are in DIP (Device Indepent Pixel) coordinates.
+//
+// ImageSkia should be used whenever possible instead of SkBitmap.
+// Functions that mutate the image should operate on the SkBitmap returned
+// from ImageSkia::GetBitmapForScale, not on ImageSkia.
+//
+// ImageSkia is cheap to copy and intentionally supports copy semantics.
class UI_EXPORT ImageSkia {
public:
- explicit ImageSkia(const SkBitmap* bitmap);
- explicit ImageSkia(const std::vector<const SkBitmap*>& bitmaps);
- ~ImageSkia();
+ // Creates instance with no bitmaps.
+ ImageSkia();
- // Build mipmap at time of next call to |DrawToCanvasInt|.
- void BuildMipMap();
-
- // Draws the image with the origin at the specified location. The upper left
- // corner of the image is rendered at the specified location.
- void DrawToCanvasInt(Canvas* canvas, int x, int y);
-
- // Draws the image with the origin at the specified location, using the
- // specified paint. The upper left corner of the image is rendered at the
- // specified location.
- void DrawToCanvasInt(Canvas* canvas,
- int x, int y,
- const SkPaint& paint);
-
- // Draws a portion of the image in the specified location. The src parameters
- // correspond to the region of the image to draw in the region defined
- // by the dest coordinates.
- //
- // If the width or height of the source differs from that of the destination,
- // the image will be scaled. When scaling down, it is highly recommended
- // that you call BuildMipMap() on your image to ensure that it has
- // a mipmap, which will result in much higher-quality output. Set |filter| to
- // use filtering for bitmaps, otherwise the nearest-neighbor algorithm is used
- // for resampling.
- //
- // An optional custom SkPaint can be provided.
- void DrawToCanvasInt(Canvas* canvas,
- int src_x, int src_y, int src_w, int src_h,
- int dest_x, int dest_y, int dest_w, int dest_h,
- bool filter);
- void DrawToCanvasInt(Canvas* canvas,
- int src_x, int src_y, int src_w, int src_h,
- int dest_x, int dest_y, int dest_w, int dest_h,
- bool filter,
- const SkPaint& paint);
-
- // Returns true if |size_| is empty.
- bool IsZeroSized() const { return size_.IsEmpty(); }
+ // Adds ref to passed in bitmap.
+ // DIP width and height are set based on scale factor of 1x.
+ // TODO(pkotwicz): This is temporary till conversion to gfx::ImageSkia is
+ // done.
+ ImageSkia(const SkBitmap& bitmap);
- // Width and height of image in DIP coordinate system.
- int width() const { return size_.width(); }
- int height() const { return size_.height(); }
+ // Adds ref to passed in bitmap.
+ // DIP width and height are set based on |dip_scale_factor|.
+ ImageSkia(const SkBitmap& bitmap, float dip_scale_factor);
- // Returns a vector with the SkBitmaps contained in this object.
- const std::vector<const SkBitmap*>& bitmaps() const { return bitmaps_; }
+ // Copies a reference to |other|'s storage.
+ ImageSkia(const ImageSkia& other);
+
+ // Copies a reference to |other|'s storage.
+ ImageSkia& operator=(const ImageSkia& other);
+
+ // Converts from SkBitmap.
+ // Adds ref to passed in bitmap.
+ // DIP width and height are set based on scale factor of 1x.
+ // TODO(pkotwicz): This is temporary till conversion to gfx::ImageSkia is
+ // done.
+ ImageSkia& operator=(const SkBitmap& other);
+
+ // Converts to SkBitmap.
+ // TODO(pkotwicz): This is temporary till conversion to gfx::ImageSkia is
+ // done.
+ operator SkBitmap&() const;
+
+ ~ImageSkia();
+
+ // Adds |bitmap| for |dip_scale_factor| to bitmaps contained by this object.
+ // Adds ref to passed in bitmap.
+ // DIP width and height are set based on |dip_scale_factor|.
+ void AddBitmapForScale(const SkBitmap& bitmap, float dip_scale_factor);
- private:
// Returns the bitmap whose density best matches |x_scale_factor| and
// |y_scale_factor|.
- const SkBitmap* GetBitmapForScale(float x_scale_factor,
- float y_scale_factor) const;
+ // Returns a null bitmap if object contains no bitmaps.
+ // |bitmap_scale_factor| is set to the scale factor of the returned bitmap.
+ const SkBitmap& GetBitmapForScale(float x_scale_factor,
+ float y_scale_factor,
+ float* bitmap_scale_factor) const;
+
+ // Returns true if object is null or |size_| is empty.
+ bool empty() const;
+
+ // Returns true if this is a null object.
+ // TODO(pkotwicz): Merge this function into empty().
+ bool isNull() const { return storage_ == NULL; }
+
+ // Width and height of image in DIP coordinate system.
+ int width() const;
+ int height() const;
+
+ // Wrapper function for SkBitmap::extractBitmap.
+ // Operates on bitmap at index 0 if available.
+ // TODO(pkotwicz): This is temporary till conversion to gfx::ImageSkia is
+ // done.
+ bool extractSubset(ImageSkia* dst, SkIRect& subset) const;
- std::vector<const SkBitmap*> bitmaps_;
- gfx::Size size_;
- bool mip_map_build_pending_;
+ // Returns pointer to an SkBitmap contained by this object.
+ // TODO(pkotwicz): This is temporary till conversion to gfx::ImageSkia is
+ // done.
+ const SkBitmap* bitmap() const;
- DISALLOW_COPY_AND_ASSIGN(ImageSkia);
+ // Returns a vector with the SkBitmaps contained in this object.
+ const std::vector<SkBitmap> bitmaps() const;
+
+ private:
+ // Initialize ImageStorage with passed in parameters.
+ // If |bitmap.isNull()|, ImageStorage is set to NULL.
+ // Scale factor is set based on default scale factor of 1x.
+ // TODO(pkotwicz): This is temporary till conversion to gfx::ImageSkia is
+ // done.
+ void Init(const SkBitmap& bitmap);
+
+ // Initialize ImageStorage with passed in parameters.
+ // If |bitmap.isNull()|, ImageStorage is set to NULL.
+ void Init(const SkBitmap& bitmap, float scale_factor);
+
+ // A null bitmap to return as not to return a temporary.
+ static SkBitmap* null_bitmap_;
+
+ // A refptr so that ImageRepSkia can be copied cheaply.
+ scoped_refptr<internal::ImageSkiaStorage> storage_;
};
} // namespace gfx
« no previous file with comments | « ui/gfx/image/image_mac_unittest.mm ('k') | ui/gfx/image/image_skia.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698