| 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" | |
| 12 #include "third_party/skia/include/core/SkPixelRef.h" | |
| 13 #include "third_party/skia/include/core/SkTypes.h" | 11 #include "third_party/skia/include/core/SkTypes.h" |
| 14 #include "ui/gfx/size.h" | 12 #include "ui/gfx/size.h" |
| 15 | 13 |
| 16 class SkBitmap; | |
| 17 | |
| 18 namespace cc { | 14 namespace cc { |
| 19 | 15 |
| 20 // A bitmap class that contains a ref-counted reference to a SkPixelRef* that | 16 // Ref-counted bitmap class (can’t use SkBitmap because of ETC1). Thread-safety |
| 21 // holds the content of the bitmap (cannot use SkBitmap because of ETC1). | 17 // ensures that both main and impl threads can hold references to the bitmap and |
| 22 // Thread-safety (by ways of SkPixelRef) ensures that both main and impl threads | 18 // that asynchronous uploads are allowed. |
| 23 // can hold references to the bitmap and that asynchronous uploads are allowed. | 19 class CC_EXPORT UIResourceBitmap |
| 24 class CC_EXPORT UIResourceBitmap { | 20 : public base::RefCountedThreadSafe<UIResourceBitmap> { |
| 25 public: | 21 public: |
| 26 enum UIResourceFormat { | 22 enum UIResourceFormat { |
| 27 RGBA8 | 23 RGBA8 |
| 28 }; | 24 }; |
| 29 enum UIResourceWrapMode { | 25 enum UIResourceWrapMode { |
| 30 CLAMP_TO_EDGE, | 26 CLAMP_TO_EDGE, |
| 31 REPEAT | 27 REPEAT |
| 32 }; | 28 }; |
| 33 | 29 |
| 30 // Takes ownership of “pixels”. |
| 31 static scoped_refptr<UIResourceBitmap> Create(uint8_t* pixels, |
| 32 UIResourceFormat format, |
| 33 UIResourceWrapMode wrap_mode, |
| 34 gfx::Size size); |
| 35 |
| 34 gfx::Size GetSize() const { return size_; } | 36 gfx::Size GetSize() const { return size_; } |
| 35 UIResourceFormat GetFormat() const { return format_; } | 37 UIResourceFormat GetFormat() const { return format_; } |
| 36 UIResourceWrapMode GetWrapMode() const { return wrap_mode_; } | 38 UIResourceWrapMode GetWrapMode() const { return wrap_mode_; } |
| 37 uint8_t* GetPixels() const; | 39 uint8_t* GetPixels() { return pixels_.get(); } |
| 38 | 40 |
| 39 // The constructor for the UIResourceBitmap. User must ensure that |skbitmap| | 41 private: |
| 40 // is immutable. The SkBitmap format should be in 32-bit RGBA. Wrap mode is | 42 friend class base::RefCountedThreadSafe<UIResourceBitmap>; |
| 41 // unnecessary for most UI resources and is defaulted to CLAMP_TO_EDGE. | |
| 42 UIResourceBitmap(const SkBitmap& skbitmap, | |
| 43 UIResourceWrapMode wrap_mode = CLAMP_TO_EDGE); | |
| 44 | 43 |
| 44 UIResourceBitmap(); |
| 45 ~UIResourceBitmap(); | 45 ~UIResourceBitmap(); |
| 46 | 46 |
| 47 private: | 47 scoped_ptr<uint8_t[]> pixels_; |
| 48 void Create(const skia::RefPtr<SkPixelRef>& pixel_ref, | |
| 49 UIResourceFormat format, | |
| 50 UIResourceWrapMode wrap_mode, | |
| 51 gfx::Size size); | |
| 52 | |
| 53 skia::RefPtr<SkPixelRef> pixel_ref_; | |
| 54 UIResourceFormat format_; | 48 UIResourceFormat format_; |
| 55 UIResourceWrapMode wrap_mode_; | 49 UIResourceWrapMode wrap_mode_; |
| 56 gfx::Size size_; | 50 gfx::Size size_; |
| 51 |
| 52 DISALLOW_COPY_AND_ASSIGN(UIResourceBitmap); |
| 57 }; | 53 }; |
| 58 | 54 |
| 59 } // namespace cc | 55 } // namespace cc |
| 60 | 56 |
| 61 #endif // CC_RESOURCES_UI_RESOURCE_BITMAP_H_ | 57 #endif // CC_RESOURCES_UI_RESOURCE_BITMAP_H_ |
| OLD | NEW |