blob: ca1271061f03ef578daa626c8ec08bdd87e10427 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CC_RESOURCES_SHARED_BITMAP_H_
#define CC_RESOURCES_SHARED_BITMAP_H_
#include "base/basictypes.h"
#include "base/callback.h"
#include "base/memory/shared_memory.h"
#include "cc/base/cc_export.h"
#include "gpu/command_buffer/common/mailbox.h"
#include "ui/gfx/geometry/size.h"
namespace base { class SharedMemory; }
namespace cc {
typedef gpu::Mailbox SharedBitmapId;
class CC_EXPORT SharedBitmap {
public:
SharedBitmap(base::SharedMemory* memory,
const SharedBitmapId& id,
const base::Callback<void(SharedBitmap* bitmap)>& free_callback);
SharedBitmap(uint8* pixels,
const SharedBitmapId& id,
const base::Callback<void(SharedBitmap* bitmap)>& free_callback);
~SharedBitmap();
bool operator<(const SharedBitmap& right) const {
if (memory_ < right.memory_)
return true;
if (memory_ > right.memory_)
return false;
return id_ < right.id_;
}
uint8* pixels() { return pixels_; }
base::SharedMemory* memory() { return memory_; }
SharedBitmapId id() { return id_; }
// Returns true if the size is valid and false otherwise.
static bool SizeInBytes(const gfx::Size& size, size_t* size_in_bytes);
// Dies with a CRASH() if the size can not be represented as a positive number
// of bytes.
static size_t CheckedSizeInBytes(const gfx::Size& size);
// Returns the size in bytes but may overflow or return 0. Only do this for
// sizes that have already been checked.
static size_t UncheckedSizeInBytes(const gfx::Size& size);
// Returns true if the size is valid and false otherwise.
static bool VerifySizeInBytes(const gfx::Size& size);
static SharedBitmapId GenerateId();
private:
base::SharedMemory* memory_;
uint8* pixels_;
SharedBitmapId id_;
base::Callback<void(SharedBitmap* bitmap)> free_callback_;
DISALLOW_COPY_AND_ASSIGN(SharedBitmap);
};
} // namespace cc
#endif // CC_RESOURCES_SHARED_BITMAP_H_
|