Upstream version 11.40.271.0
[platform/framework/web/crosswalk.git] / src / cc / surfaces / surface_sequence.h
1 // Copyright 2014 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.
4
5 #ifndef CC_SURFACES_SURFACE_SEQUENCE_H_
6 #define CC_SURFACES_SURFACE_SEQUENCE_H_
7
8 #include "base/containers/hash_tables.h"
9
10 namespace cc {
11
12 // A per-surface-namespace sequence number that's used to coordinate
13 // dependencies between frames. A sequence number may be satisfied once, and
14 // may be depended on once.
15 struct SurfaceSequence {
16   SurfaceSequence() : id_namespace(0u), sequence(0u) {}
17   SurfaceSequence(uint32_t id_namespace, uint32_t sequence)
18       : id_namespace(id_namespace), sequence(sequence) {}
19   bool is_null() const { return id_namespace == 0u && sequence == 0u; }
20
21   uint32_t id_namespace;
22   uint32_t sequence;
23 };
24
25 inline bool operator==(const SurfaceSequence& a, const SurfaceSequence& b) {
26   return a.id_namespace == b.id_namespace && a.sequence == b.sequence;
27 }
28
29 inline bool operator!=(const SurfaceSequence& a, const SurfaceSequence& b) {
30   return !(a == b);
31 }
32
33 inline bool operator<(const SurfaceSequence& a, const SurfaceSequence& b) {
34   if (a.id_namespace != b.id_namespace)
35     return a.id_namespace < b.id_namespace;
36   return a.sequence < b.sequence;
37 }
38
39 }  // namespace cc
40
41 namespace BASE_HASH_NAMESPACE {
42 template <>
43 struct hash<cc::SurfaceSequence> {
44   size_t operator()(cc::SurfaceSequence key) const {
45     return base::HashPair(key.id_namespace, key.sequence);
46   }
47 };
48 }  // namespace BASE_HASH_NAMESPACE
49
50 #endif  // CC_SURFACES_SURFACE_SEQUENCE_H_