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 <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
(...skipping 27 matching lines...) Expand all Loading... |
38 void SetOpaque(bool opaque) { opaque_ = opaque; } | 38 void SetOpaque(bool opaque) { opaque_ = opaque; } |
39 | 39 |
40 // Draw the UIResourceBitmap onto the provided |canvas| using the style | 40 // Draw the UIResourceBitmap onto the provided |canvas| using the style |
41 // information specified by |paint|. | 41 // information specified by |paint|. |
42 void DrawToCanvas(SkCanvas* canvas, SkPaint* paint); | 42 void DrawToCanvas(SkCanvas* canvas, SkPaint* paint); |
43 | 43 |
44 // User must ensure that |skbitmap| is immutable. The SkBitmap Format should | 44 // User must ensure that |skbitmap| is immutable. The SkBitmap Format should |
45 // be 32-bit RGBA or 8-bit ALPHA. | 45 // be 32-bit RGBA or 8-bit ALPHA. |
46 explicit UIResourceBitmap(const SkBitmap& skbitmap); | 46 explicit UIResourceBitmap(const SkBitmap& skbitmap); |
47 UIResourceBitmap(const gfx::Size& size, bool is_opaque); | 47 UIResourceBitmap(const gfx::Size& size, bool is_opaque); |
48 UIResourceBitmap(sk_sp<SkPixelRef> pixel_ref, const gfx::Size& size); | |
49 UIResourceBitmap(const UIResourceBitmap& other); | 48 UIResourceBitmap(const UIResourceBitmap& other); |
50 ~UIResourceBitmap(); | 49 ~UIResourceBitmap(); |
51 | 50 |
52 // Returns the memory usage of the bitmap. | 51 // Returns the memory usage of the bitmap. |
53 size_t EstimateMemoryUsage() const { | 52 size_t EstimateMemoryUsage() const { |
54 return pixel_ref_ ? pixel_ref_->rowBytes() * size_.height() : 0; | 53 return pixel_ref_ ? pixel_ref_->rowBytes() * size_.height() : 0; |
55 } | 54 } |
56 | 55 |
57 const uint8_t* GetPixels() const { | 56 const uint8_t* GetPixels() const { |
58 return static_cast<const uint8_t*>(pixel_ref_->pixels()); | 57 return static_cast<const uint8_t*>(pixel_ref_->pixels()); |
59 } | 58 } |
60 | 59 |
61 private: | 60 private: |
62 friend class AutoLockUIResourceBitmap; | |
63 | |
64 void Create(sk_sp<SkPixelRef> pixel_ref, | 61 void Create(sk_sp<SkPixelRef> pixel_ref, |
65 const gfx::Size& size, | 62 const gfx::Size& size, |
66 UIResourceFormat format); | 63 UIResourceFormat format); |
67 | 64 |
68 sk_sp<SkPixelRef> pixel_ref_; | 65 sk_sp<SkPixelRef> pixel_ref_; |
69 UIResourceFormat format_; | 66 UIResourceFormat format_; |
70 gfx::Size size_; | 67 gfx::Size size_; |
71 bool opaque_; | 68 bool opaque_; |
72 }; | 69 }; |
73 | 70 |
74 } // namespace cc | 71 } // namespace cc |
75 | 72 |
76 #endif // CC_RESOURCES_UI_RESOURCE_BITMAP_H_ | 73 #endif // CC_RESOURCES_UI_RESOURCE_BITMAP_H_ |
OLD | NEW |