summaryrefslogtreecommitdiff
path: root/chromium/cc/surfaces/surface_reference.h
blob: ac3bb773d10e80d9c3159bf36e1672ea44ed6438 (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
// Copyright 2016 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_SURFACES_SURFACE_REFERENCE_H_
#define CC_SURFACES_SURFACE_REFERENCE_H_

#include <string>

#include "base/hash.h"
#include "cc/surfaces/surface_id.h"
#include "mojo/public/cpp/bindings/struct_traits.h"

namespace cc {
namespace mojom {
class SurfaceReferenceDataView;
}

// Hold a reference from an embedding (parent) to embedded (child) surface.
class SurfaceReference {
 public:
  SurfaceReference();
  SurfaceReference(const SurfaceId& parent_id, const SurfaceId& child_id);
  SurfaceReference(const SurfaceReference& other);

  ~SurfaceReference();

  const SurfaceId& parent_id() const { return parent_id_; }
  const SurfaceId& child_id() const { return child_id_; }

  size_t hash() const {
    return base::HashInts(static_cast<uint64_t>(parent_id_.hash()),
                          static_cast<uint64_t>(child_id_.hash()));
  }

  bool operator==(const SurfaceReference& other) const {
    return parent_id_ == other.parent_id_ && child_id_ == other.child_id_;
  }

  bool operator!=(const SurfaceReference& other) const {
    return !(*this == other);
  }

  bool operator<(const SurfaceReference& other) const {
    return std::tie(parent_id_, child_id_) <
           std::tie(other.parent_id_, other.child_id_);
  }

  std::string ToString() const;

 private:
  friend struct mojo::StructTraits<mojom::SurfaceReferenceDataView,
                                   SurfaceReference>;

  SurfaceId parent_id_;
  SurfaceId child_id_;
};

struct SurfaceReferenceHash {
  size_t operator()(const SurfaceReference& ref) const { return ref.hash(); }
};

}  // namespace cc

#endif  // CC_SURFACES_SURFACE_REFERENCE_H_