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
3 // found in the LICENSE file.
5 #ifndef CC_RESOURCES_UI_RESOURCE_BITMAP_H_
6 #define CC_RESOURCES_UI_RESOURCE_BITMAP_H_
8 #include "base/memory/ref_counted.h"
9 #include "base/memory/scoped_ptr.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"
14 #include "ui/gfx/size.h"
22 // A bitmap class that contains a ref-counted reference to a SkPixelRef that
23 // holds the content of the bitmap (cannot use SkBitmap because of ETC1).
24 // Thread-safety (by ways of SkPixelRef) ensures that both main and impl threads
25 // can hold references to the bitmap and that asynchronous uploads are allowed.
26 class CC_EXPORT UIResourceBitmap
{
28 enum UIResourceFormat
{
33 enum UIResourceWrapMode
{
38 gfx::Size
GetSize() const { return size_
; }
39 UIResourceFormat
GetFormat() const { return format_
; }
40 UIResourceWrapMode
GetWrapMode() const { return wrap_mode_
; }
41 void SetWrapMode(UIResourceWrapMode wrap_mode
) { wrap_mode_
= wrap_mode
; }
42 bool GetOpaque() const { return opaque_
; }
43 void SetOpaque(bool opaque
) { opaque_
= opaque
; }
45 // User must ensure that |skbitmap| is immutable. The SkBitmap Format should
46 // be 32-bit RGBA or 8-bit ALPHA.
47 explicit UIResourceBitmap(const SkBitmap
& skbitmap
);
48 UIResourceBitmap(const gfx::Size
& size
, bool is_opaque
);
49 UIResourceBitmap(const skia::RefPtr
<SkPixelRef
>& pixel_ref
,
50 const gfx::Size
& size
);
54 friend class AutoLockUIResourceBitmap
;
56 void Create(const skia::RefPtr
<SkPixelRef
>& pixel_ref
,
57 const gfx::Size
& size
,
58 UIResourceFormat format
);
60 skia::RefPtr
<SkPixelRef
> pixel_ref_
;
61 UIResourceFormat format_
;
62 UIResourceWrapMode wrap_mode_
;
67 class CC_EXPORT AutoLockUIResourceBitmap
{
69 explicit AutoLockUIResourceBitmap(const UIResourceBitmap
& bitmap
);
70 ~AutoLockUIResourceBitmap();
71 const uint8_t* GetPixels() const;
74 const UIResourceBitmap
& bitmap_
;
79 #endif // CC_RESOURCES_UI_RESOURCE_BITMAP_H_