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_SHARED_BITMAP_H_
6 #define CC_RESOURCES_SHARED_BITMAP_H_
8 #include "base/basictypes.h"
9 #include "base/callback.h"
10 #include "base/memory/shared_memory.h"
11 #include "cc/base/cc_export.h"
12 #include "gpu/command_buffer/common/mailbox.h"
13 #include "ui/gfx/size.h"
15 namespace base
{ class SharedMemory
; }
18 typedef gpu::Mailbox SharedBitmapId
;
20 class CC_EXPORT SharedBitmap
{
22 SharedBitmap(base::SharedMemory
* memory
,
23 const SharedBitmapId
& id
,
24 const base::Callback
<void(SharedBitmap
* bitmap
)>& free_callback
);
26 SharedBitmap(uint8
* pixels
,
27 const SharedBitmapId
& id
,
28 const base::Callback
<void(SharedBitmap
* bitmap
)>& free_callback
);
32 bool operator<(const SharedBitmap
& right
) const {
33 if (memory_
< right
.memory_
)
35 if (memory_
> right
.memory_
)
37 return id_
< right
.id_
;
40 uint8
* pixels() { return pixels_
; }
42 base::SharedMemory
* memory() { return memory_
; }
44 SharedBitmapId
id() { return id_
; }
46 // Returns true if the size is valid and false otherwise.
47 static bool SizeInBytes(const gfx::Size
& size
, size_t* size_in_bytes
);
48 // Dies with a CRASH() if the size can not be represented as a positive number
50 static size_t CheckedSizeInBytes(const gfx::Size
& size
);
51 // Returns the size in bytes but may overflow or return 0. Only do this for
52 // sizes that have already been checked.
53 static size_t UncheckedSizeInBytes(const gfx::Size
& size
);
54 // Returns true if the size is valid and false otherwise.
55 static bool VerifySizeInBytes(const gfx::Size
& size
);
57 static SharedBitmapId
GenerateId();
60 base::SharedMemory
* memory_
;
63 base::Callback
<void(SharedBitmap
* bitmap
)> free_callback_
;
65 DISALLOW_COPY_AND_ASSIGN(SharedBitmap
);
70 #endif // CC_RESOURCES_SHARED_BITMAP_H_