Chromium Code Reviews| Index: ui/gfx/image/image_skia.h |
| diff --git a/ui/gfx/image/image_skia.h b/ui/gfx/image/image_skia.h |
| index 2518b2c447c9276917833f8b48c018cdd932d23b..25db6502e3f8f518c83f67ed34036298f125f9e4 100644 |
| --- a/ui/gfx/image/image_skia.h |
| +++ b/ui/gfx/image/image_skia.h |
| @@ -8,6 +8,7 @@ |
| #include <vector> |
| #include "base/basictypes.h" |
| +#include "base/gtest_prod_util.h" |
| #include "base/memory/ref_counted.h" |
| #include "ui/base/ui_export.h" |
| #include "ui/gfx/image/image_skia_rep.h" |
| @@ -20,6 +21,10 @@ namespace internal { |
| class ImageSkiaStorage; |
| } // namespace internal |
| +namespace test { |
| +class TestOnThread; |
| +} |
| + |
| // Container for the same image at different densities, similar to NSImage. |
| // Image height and width are in DIP (Density Indepent Pixel) coordinates. |
| // |
| @@ -37,6 +42,7 @@ class UI_EXPORT ImageSkia { |
| // Creates an instance that will use the |source| to get the image |
| // for scale factors. |size| specifes the size of the image in DIP. |
| + // ImageSkia owns |source|. |
| ImageSkia(ImageSkiaSource* source, const gfx::Size& size); |
| // Adds ref to passed in bitmap. |
| @@ -62,6 +68,15 @@ class UI_EXPORT ImageSkia { |
| ~ImageSkia(); |
| + // Returns a deep copy of this ImageSkia which has its own storage with |
| + // the ImageSkiaRep instances that this ImageSkia currently have. |
|
sky
2012/08/28 17:18:14
have -> has
oshima
2012/08/28 21:23:34
Done.
|
| + // This can be safely passed to and/ manipulated by another thread. |
|
sky
2012/08/28 17:18:14
This -> 'The returned value'
'and/' -> 'and'
oshima
2012/08/28 21:23:34
Done.
|
| + // Note that this does NOT generate ImageSkiaReps from its source. |
| + // If you want to create a deep copy with ImageSkiaReps for supported |
| + // scale factors, you need to explicitly call |
| + // |EnsureRepsForSupportedScaleFactors()| first. |
| + ImageSkia DeepCopy() const; |
| + |
| // Returns true if this object is backed by the same ImageSkiaStorage as |
| // |other|. Will also return true if both images are isNull(). |
| bool BackedBySameObjectAs(const gfx::ImageSkia& other) const; |
| @@ -82,16 +97,23 @@ class UI_EXPORT ImageSkia { |
| const gfx::ImageSkiaRep& GetRepresentation( |
| ui::ScaleFactor scale_factor) const; |
| -#if defined(OS_MACOSX) |
| - // Returns the image reps contained by this object. |
| - // If the image has a source, this method will attempt to generate |
| - // representations from the source for all supported scale factors. |
| - // Mac only for now. |
| - std::vector<ImageSkiaRep> GetRepresentations() const; |
| -#endif // OS_MACOSX |
| + // Make the ImageSkia instance read-only. Note that this only prevent |
| + // modification from client code, and the storage may still be |
| + // modified by the source if any (thus, it's not thread safe). This |
| + // detaches the storage from currently accessing thread, so its safe |
| + // to pass it to other thread as long as it is accessed only by that |
| + // thread. If this ImageSkia's storage will be accessed by multiple |
| + // threads, use |MakeThreadSafe()| method. |
| + void SetReadOnly(); |
| + |
| + // Make the image thread safe by making the storage read only and remove |
| + // its source if any. All ImageSkia that shares the same storage will also |
| + // become thread safe. Note that in order to make it 100% thread safe, |
| + // this must be called before it's been passed to anther thread. |
| + void MakeThreadSafe(); |
| + bool IsThreadSafe() 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. |
| @@ -109,17 +131,33 @@ class UI_EXPORT ImageSkia { |
| // Returns a vector with the image reps contained in this object. |
| // There is no guarantee that this will return all images rep for |
| // supported scale factors. |
| - // TODO(oshima): Update all use of this API and make this to fail |
| - // when source is used. |
| std::vector<gfx::ImageSkiaRep> image_reps() const; |
| + // When the source is available, generates all ImageReps for |
| + // supported scale factors. This method is defined as const as |
| + // the state change in the storage is agnostic to the caller. |
| + void EnsureRepsForSupportedScaleFactors() const; |
| + |
| private: |
| + friend class test::TestOnThread; |
| + FRIEND_TEST_ALL_PREFIXES(ImageSkiaTest, EmptyOnThreadTest); |
| + FRIEND_TEST_ALL_PREFIXES(ImageSkiaTest, StaticOnThreadTest); |
| + FRIEND_TEST_ALL_PREFIXES(ImageSkiaTest, SourceOnThreadTest); |
| + |
| // Initialize ImageSkiaStorage with passed in parameters. |
| // If the image rep's bitmap is empty, ImageStorage is set to NULL. |
| void Init(const gfx::ImageSkiaRep& image_rep); |
| SkBitmap& GetBitmap() const; |
| + // Checks if the current thread can read/modify the ImageSkia. |
| + bool CanRead() const; |
| + bool CanModify() const; |
| + |
| + // Detach the storage from the currently assinged thread |
| + // so that other thread can access the storage. |
| + void DetachStorageFromThread(); |
| + |
| // A refptr so that ImageRepSkia can be copied cheaply. |
| scoped_refptr<internal::ImageSkiaStorage> storage_; |
| }; |