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

Side by Side Diff: ui/gfx/image/image_skia.h

Issue 10694045: Loading/Creating images for mutiple scale factors on the fly (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: size fix Created 8 years, 5 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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* source, const gfx::Size& size);
sky 2012/07/16 16:41:01 This should document it takes ownership of source.
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
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. Note that it may not have
108 // all image reps for supported scale factors.
109 // TODO(oshima|pkotwicz): Investigate if this can be eliminated
110 // after ImageSkiaSource conversion.
101 bool extractSubset(ImageSkia* dst, const SkIRect& subset) const; 111 bool extractSubset(ImageSkia* dst, const SkIRect& subset) const;
102 112
103 // Returns pointer to an SkBitmap contained by this object. 113 // Returns pointer to an SkBitmap contained by this object.
104 // TODO(pkotwicz): This is temporary till conversion to gfx::ImageSkia is 114 // TODO(pkotwicz): This is temporary till conversion to gfx::ImageSkia is
105 // done. 115 // done.
106 const SkBitmap* bitmap() const; 116 const SkBitmap* bitmap() const;
107 117
108 // Returns a vector with the image reps contained in this object. 118 // Returns a vector with the image reps contained in this object.
119 // There is no guarantee that this will return all images rep for
120 // supported scale factors.
121 // TODO(oshima): Update all use of this API and make this to fail
122 // when source is used.
109 std::vector<gfx::ImageSkiaRep> image_reps() const; 123 std::vector<gfx::ImageSkiaRep> image_reps() const;
110 124
111 private: 125 private:
112 // Initialize ImageSkiaStorage with passed in parameters. 126 // Initialize ImageSkiaStorage with passed in parameters.
113 // If the image rep's bitmap is empty, ImageStorage is set to NULL. 127 // If the image rep's bitmap is empty, ImageStorage is set to NULL.
114 void Init(const gfx::ImageSkiaRep& image_rep); 128 void Init(const gfx::ImageSkiaRep& image_rep);
115 129
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. 130 // A refptr so that ImageRepSkia can be copied cheaply.
126 scoped_refptr<internal::ImageSkiaStorage> storage_; 131 scoped_refptr<internal::ImageSkiaStorage> storage_;
127 }; 132 };
128 133
129 } // namespace gfx 134 } // namespace gfx
130 135
131 #endif // UI_GFX_IMAGE_IMAGE_SKIA_H_ 136 #endif // UI_GFX_IMAGE_IMAGE_SKIA_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698