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

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

Issue 6849030: Add support for multi resolution icons (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added header Created 9 years, 8 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
« no previous file with comments | « ui/base/resource/resource_bundle_posix.cc ('k') | ui/gfx/image.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 // An Image wraps an image any flavor, be it platform-native GdkBitmap/NSImage, 5 // An Image wraps an image any flavor, be it platform-native GdkBitmap/NSImage,
6 // or a SkBitmap. This also provides easy conversion to other image types 6 // or a SkBitmap. This also provides easy conversion to other image types
7 // through operator overloading. It will cache the converted representations 7 // through operator overloading. It will cache the converted representations
8 // internally to prevent double-conversion. 8 // internally to prevent double-conversion.
9 // 9 //
10 // The lifetime of both the initial representation and any converted ones are 10 // The lifetime of both the initial representation and any converted ones are
11 // tied to the lifetime of the Image object itself. 11 // tied to the lifetime of the Image object itself.
12 12
13 #ifndef UI_GFX_IMAGE_H_ 13 #ifndef UI_GFX_IMAGE_H_
14 #define UI_GFX_IMAGE_H_ 14 #define UI_GFX_IMAGE_H_
15 #pragma once 15 #pragma once
16 16
17 #include <map> 17 #include <map>
18 #include <vector>
18 19
19 #include "base/basictypes.h" 20 #include "base/basictypes.h"
20 #include "base/gtest_prod_util.h" 21 #include "base/gtest_prod_util.h"
21 #include "build/build_config.h" 22 #include "build/build_config.h"
22 #include "ui/gfx/native_widget_types.h" // Forward-declares GdkPixbuf and NSIma ge. 23 #include "ui/gfx/native_widget_types.h" // Forward-declares GdkPixbuf and NSIma ge.
23 24
24 class SkBitmap; 25 class SkBitmap;
25 26
26 namespace { 27 namespace {
27 class ImageTest; 28 class ImageTest;
29 class ImageMacTest;
28 } 30 }
29 31
30 namespace gfx { 32 namespace gfx {
31 33
32 namespace internal { 34 namespace internal {
33 class ImageRep; 35 class ImageRep;
34 } 36 }
35 37
36 class Image { 38 class Image {
37 public: 39 public:
38 enum RepresentationType { 40 enum RepresentationType {
39 kGdkPixbufRep, 41 kGdkPixbufRep,
40 kNSImageRep, 42 kNSImageRep,
41 kSkBitmapRep, 43 kSkBitmapRep,
42 }; 44 };
43 45
44 // Creates a new image with the default representation. The object will take 46 // Creates a new image with the default representation. The object will take
45 // ownership of the image. 47 // ownership of the image.
46 explicit Image(const SkBitmap* bitmap); 48 explicit Image(const SkBitmap* bitmap);
49 // To create an Image that supports multiple resolutions pass a vector
50 // of bitmaps, one for each resolution.
51 explicit Image(const std::vector<const SkBitmap*>& bitmaps);
52
47 #if defined(OS_LINUX) 53 #if defined(OS_LINUX)
48 // Does not increase |pixbuf|'s reference count; expects to take ownership. 54 // Does not increase |pixbuf|'s reference count; expects to take ownership.
49 explicit Image(GdkPixbuf* pixbuf); 55 explicit Image(GdkPixbuf* pixbuf);
50 #elif defined(OS_MACOSX) 56 #elif defined(OS_MACOSX)
51 // Does not retain |image|; expects to take ownership. 57 // Does not retain |image|; expects to take ownership.
58 // A single NSImage object can contain multiple bitmaps so there's no reason
59 // to pass a vector of these.
52 explicit Image(NSImage* image); 60 explicit Image(NSImage* image);
53 #endif 61 #endif
54 62
55 // Deletes the image and all of its cached representations. 63 // Deletes the image and all of its cached representations.
56 ~Image(); 64 ~Image();
57 65
58 // Conversion handlers. 66 // Conversion handlers.
59 operator const SkBitmap*(); 67 operator const SkBitmap*();
60 operator const SkBitmap&(); 68 operator const SkBitmap&();
61 #if defined(OS_LINUX) 69 #if defined(OS_LINUX)
62 operator GdkPixbuf*(); 70 operator GdkPixbuf*();
63 #elif defined(OS_MACOSX) 71 #elif defined(OS_MACOSX)
64 operator NSImage*(); 72 operator NSImage*();
65 #endif 73 #endif
66 74
75 // Gets the number of bitmaps in this image. This may cause a conversion
Robert Sesek 2011/04/19 21:12:56 Add a comment that states these methods are primar
sail 2011/04/19 21:27:26 Done.
76 // to a bitmap representation.
77 size_t GetNumberOfSkBitmaps();
78
79 // Gets the bitmap at the given index. This may cause a conversion
80 // to a bitmap representation.
81 const SkBitmap* GetSkBitmapAtIndex(size_t index);
82
67 // Inspects the representations map to see if the given type exists. 83 // Inspects the representations map to see if the given type exists.
68 bool HasRepresentation(RepresentationType type); 84 bool HasRepresentation(RepresentationType type);
69 85
70 // Swaps this image's internal representations with |other|. 86 // Swaps this image's internal representations with |other|.
71 void SwapRepresentations(gfx::Image* other); 87 void SwapRepresentations(gfx::Image* other);
72 88
73 private: 89 private:
74 typedef std::map<RepresentationType, internal::ImageRep*> RepresentationMap; 90 typedef std::map<RepresentationType, internal::ImageRep*> RepresentationMap;
75 91
76 // Returns the ImageRep for the default representation. 92 // Returns the ImageRep for the default representation.
77 internal::ImageRep* DefaultRepresentation(); 93 internal::ImageRep* DefaultRepresentation();
78 94
79 // Returns a ImageRep for the given representation type, converting and 95 // Returns a ImageRep for the given representation type, converting and
80 // caching if necessary. 96 // caching if necessary.
81 internal::ImageRep* GetRepresentation(RepresentationType rep); 97 internal::ImageRep* GetRepresentation(RepresentationType rep);
82 98
83 // Stores a representation into the map. 99 // Stores a representation into the map.
84 void AddRepresentation(internal::ImageRep* rep); 100 void AddRepresentation(internal::ImageRep* rep);
85 101
86 // The type of image that was passed to the constructor. This key will always 102 // The type of image that was passed to the constructor. This key will always
87 // exist in the |representations_| map. 103 // exist in the |representations_| map.
88 RepresentationType default_representation_; 104 RepresentationType default_representation_;
89 105
90 // All the representations of an Image. Size will always be at least one, with 106 // All the representations of an Image. Size will always be at least one, with
91 // more for any converted representations. 107 // more for any converted representations.
92 RepresentationMap representations_; 108 RepresentationMap representations_;
93 109
94 friend class ::ImageTest; 110 friend class ::ImageTest;
111 friend class ::ImageMacTest;
95 DISALLOW_COPY_AND_ASSIGN(Image); 112 DISALLOW_COPY_AND_ASSIGN(Image);
96 }; 113 };
97 114
98 } // namespace gfx 115 } // namespace gfx
99 116
100 #endif // UI_GFX_IMAGE_H_ 117 #endif // UI_GFX_IMAGE_H_
OLDNEW
« no previous file with comments | « ui/base/resource/resource_bundle_posix.cc ('k') | ui/gfx/image.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698