Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 CC_RESOURCES_UI_RESOURCE_BITMAP_H_ | 5 #ifndef CC_RESOURCES_UI_RESOURCE_BITMAP_H_ |
| 6 #define CC_RESOURCES_UI_RESOURCE_BITMAP_H_ | 6 #define CC_RESOURCES_UI_RESOURCE_BITMAP_H_ |
| 7 | 7 |
| 8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "cc/base/cc_export.h" | 10 #include "cc/base/cc_export.h" |
| 11 #include "skia/ext/refptr.h" | 11 #include "skia/ext/refptr.h" |
| 12 #include "third_party/skia/include/core/SkPixelRef.h" | 12 #include "third_party/skia/include/core/SkPixelRef.h" |
| 13 #include "third_party/skia/include/core/SkTypes.h" | 13 #include "third_party/skia/include/core/SkTypes.h" |
| 14 #include "ui/gfx/size.h" | 14 #include "ui/gfx/size.h" |
| 15 | 15 |
| 16 class SkBitmap; | 16 class SkBitmap; |
| 17 | 17 |
| 18 namespace cc { | 18 namespace cc { |
| 19 | 19 |
| 20 // A bitmap class that contains a ref-counted reference to a SkPixelRef* that | 20 class ETC1PixelRef; |
| 21 | |
| 22 // A bitmap class that contains a ref-counted reference to a SkPixelRef that | |
| 21 // holds the content of the bitmap (cannot use SkBitmap because of ETC1). | 23 // holds the content of the bitmap (cannot use SkBitmap because of ETC1). |
| 22 // Thread-safety (by ways of SkPixelRef) ensures that both main and impl threads | 24 // Thread-safety (by ways of SkPixelRef) ensures that both main and impl threads |
| 23 // can hold references to the bitmap and that asynchronous uploads are allowed. | 25 // can hold references to the bitmap and that asynchronous uploads are allowed. |
| 24 class CC_EXPORT UIResourceBitmap { | 26 class CC_EXPORT UIResourceBitmap { |
| 25 public: | 27 public: |
| 26 enum UIResourceFormat { | 28 enum UIResourceFormat { |
| 27 RGBA8, | 29 RGBA8, |
| 28 ETC1 | 30 ETC1 |
| 29 }; | 31 }; |
| 30 enum UIResourceWrapMode { | 32 enum UIResourceWrapMode { |
| 31 CLAMP_TO_EDGE, | 33 CLAMP_TO_EDGE, |
| 32 REPEAT | 34 REPEAT |
| 33 }; | 35 }; |
| 34 | 36 |
| 35 gfx::Size GetSize() const { return size_; } | 37 gfx::Size GetSize() const { return size_; } |
| 36 UIResourceFormat GetFormat() const { return format_; } | 38 UIResourceFormat GetFormat() const { return format_; } |
| 37 UIResourceWrapMode GetWrapMode() const { return wrap_mode_; } | 39 UIResourceWrapMode GetWrapMode() const { return wrap_mode_; } |
| 38 void SetWrapMode(UIResourceWrapMode wrap_mode) { wrap_mode_ = wrap_mode; } | 40 void SetWrapMode(UIResourceWrapMode wrap_mode) { wrap_mode_ = wrap_mode; } |
| 39 bool GetOpaque() const { return opaque_; } | 41 bool GetOpaque() const { return opaque_; } |
| 40 void SetOpaque(bool opaque) { opaque_ = opaque; } | 42 void SetOpaque(bool opaque) { opaque_ = opaque; } |
| 41 | 43 |
| 42 // The constructor for the UIResourceBitmap. User must ensure that |skbitmap| | 44 // User must ensure that |skbitmap| is immutable. The SkBitmap Format should |
| 43 // is immutable. The SkBitmap format should be in 32-bit RGBA. Wrap mode is | 45 // be 32-bit RGBA. |
| 44 // unnecessary for most UI resources and is defaulted to CLAMP_TO_EDGE. | |
| 45 explicit UIResourceBitmap(const SkBitmap& skbitmap); | 46 explicit UIResourceBitmap(const SkBitmap& skbitmap); |
| 46 | 47 |
| 47 UIResourceBitmap(const skia::RefPtr<SkPixelRef>& pixel_ref, | 48 UIResourceBitmap(const skia::RefPtr<ETC1PixelRef>& etc1_pixel_ref, |
| 48 UIResourceFormat format, | |
| 49 gfx::Size size); | 49 gfx::Size size); |
|
aelias_OOO_until_Jul13
2013/11/07 19:30:27
Then this doesn't need a gfx::Size either.
| |
| 50 | 50 |
| 51 ~UIResourceBitmap(); | 51 ~UIResourceBitmap(); |
| 52 | 52 |
| 53 private: | 53 private: |
| 54 friend class AutoLockUIResourceBitmap; | 54 friend class AutoLockUIResourceBitmap; |
| 55 void Create(const skia::RefPtr<SkPixelRef>& pixel_ref, | 55 void Create(const skia::RefPtr<SkPixelRef>& pixel_ref, |
| 56 UIResourceFormat format, | 56 UIResourceFormat format, |
| 57 gfx::Size size); | 57 gfx::Size size); |
| 58 | 58 |
| 59 skia::RefPtr<SkPixelRef> pixel_ref_; | 59 skia::RefPtr<SkPixelRef> pixel_ref_; |
| 60 UIResourceFormat format_; | 60 UIResourceFormat format_; |
| 61 UIResourceWrapMode wrap_mode_; | 61 UIResourceWrapMode wrap_mode_; |
| 62 gfx::Size size_; | 62 gfx::Size size_; |
| 63 bool opaque_; | 63 bool opaque_; |
| 64 }; | 64 }; |
| 65 | 65 |
| 66 class CC_EXPORT AutoLockUIResourceBitmap { | 66 class CC_EXPORT AutoLockUIResourceBitmap { |
| 67 public: | 67 public: |
| 68 explicit AutoLockUIResourceBitmap(const UIResourceBitmap& bitmap); | 68 explicit AutoLockUIResourceBitmap(const UIResourceBitmap& bitmap); |
| 69 ~AutoLockUIResourceBitmap(); | 69 ~AutoLockUIResourceBitmap(); |
| 70 const uint8_t* GetPixels() const; | 70 const uint8_t* GetPixels() const; |
| 71 | 71 |
| 72 private: | 72 private: |
| 73 const UIResourceBitmap& bitmap_; | 73 const UIResourceBitmap& bitmap_; |
| 74 }; | 74 }; |
| 75 | 75 |
| 76 } // namespace cc | 76 } // namespace cc |
| 77 | 77 |
| 78 #endif // CC_RESOURCES_UI_RESOURCE_BITMAP_H_ | 78 #endif // CC_RESOURCES_UI_RESOURCE_BITMAP_H_ |
| OLD | NEW |