 Chromium Code Reviews
 Chromium Code Reviews Issue 6849030:
  Add support for multi resolution icons   (Closed) 
  Base URL: svn://svn.chromium.org/chrome/trunk/src
    
  
    Issue 6849030:
  Add support for multi resolution icons   (Closed) 
  Base URL: svn://svn.chromium.org/chrome/trunk/src| OLD | NEW | 
|---|---|
| 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; | 
| 28 } | 29 } | 
| 29 | 30 | 
| 30 namespace gfx { | 31 namespace gfx { | 
| 31 | 32 | 
| 32 namespace internal { | 33 namespace internal { | 
| 33 class ImageRep; | 34 class ImageRep; | 
| 34 } | 35 } | 
| 35 | 36 | 
| 36 class Image { | 37 class Image { | 
| 37 public: | 38 public: | 
| 38 enum RepresentationType { | 39 enum RepresentationType { | 
| 39 kGdkPixbufRep, | 40 kGdkPixbufRep, | 
| 40 kNSImageRep, | 41 kNSImageRep, | 
| 41 kSkBitmapRep, | 42 kSkBitmapRep, | 
| 42 }; | 43 }; | 
| 43 | 44 | 
| 44 // Creates a new image with the default representation. The object will take | 45 // Creates a new image with the default representation. The object will take | 
| 45 // ownership of the image. | 46 // ownership of the image. | 
| 46 explicit Image(const SkBitmap* bitmap); | 47 explicit Image(const SkBitmap* bitmap); | 
| 48 // To create an Image that supports multiple resolutions pass a vector | |
| 49 // of bitmaps, one for each resolution. | |
| 50 explicit Image(const std::vector<const SkBitmap*>& bitmaps); | |
| 51 | |
| 47 #if defined(OS_LINUX) | 52 #if defined(OS_LINUX) | 
| 48 // Does not increase |pixbuf|'s reference count; expects to take ownership. | 53 // Does not increase |pixbuf|'s reference count; expects to take ownership. | 
| 54 // TODO Add support for multiple resolutions when necessary. | |
| 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 size_t GetNumberOfSkBitmaps(); | |
| 
Robert Sesek
2011/04/15 20:27:20
I'm not in love with this interface. It's not real
 
sail
2011/04/16 01:25:00
I agree the name sucks. It'll be supper easy to ch
 | |
| 76 const SkBitmap* GetSkBitmapAtIndex(size_t index); | |
| 77 | |
| 67 // Inspects the representations map to see if the given type exists. | 78 // Inspects the representations map to see if the given type exists. | 
| 68 bool HasRepresentation(RepresentationType type); | 79 bool HasRepresentation(RepresentationType type); | 
| 69 | 80 | 
| 70 // Swaps this image's internal representations with |other|. | 81 // Swaps this image's internal representations with |other|. | 
| 71 void SwapRepresentations(gfx::Image* other); | 82 void SwapRepresentations(gfx::Image* other); | 
| 72 | 83 | 
| 73 private: | 84 private: | 
| 74 typedef std::map<RepresentationType, internal::ImageRep*> RepresentationMap; | 85 typedef std::map<RepresentationType, internal::ImageRep*> RepresentationMap; | 
| 75 | 86 | 
| 76 // Returns the ImageRep for the default representation. | 87 // Returns the ImageRep for the default representation. | 
| (...skipping 14 matching lines...) Expand all Loading... | |
| 91 // more for any converted representations. | 102 // more for any converted representations. | 
| 92 RepresentationMap representations_; | 103 RepresentationMap representations_; | 
| 93 | 104 | 
| 94 friend class ::ImageTest; | 105 friend class ::ImageTest; | 
| 95 DISALLOW_COPY_AND_ASSIGN(Image); | 106 DISALLOW_COPY_AND_ASSIGN(Image); | 
| 96 }; | 107 }; | 
| 97 | 108 | 
| 98 } // namespace gfx | 109 } // namespace gfx | 
| 99 | 110 | 
| 100 #endif // UI_GFX_IMAGE_H_ | 111 #endif // UI_GFX_IMAGE_H_ | 
| OLD | NEW |