summaryrefslogtreecommitdiffstats
path: root/cc/texture_mailbox.cc
blob: c0990b1eb6326e5948de03f0d5241aa921f5639c (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
// 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.

#include "base/logging.h"
#include "cc/texture_mailbox.h"

namespace cc {

TextureMailbox::TextureMailbox()
    : sync_point_(0) {
}

TextureMailbox::TextureMailbox(
    const std::string& mailbox_name,
    const ReleaseCallback& mailbox_callback)
    : callback_(mailbox_callback),
      sync_point_(0) {
  DCHECK(mailbox_name.empty() == mailbox_callback.is_null());
  if (!mailbox_name.empty()) {
    CHECK(mailbox_name.size() == sizeof(name_.name));
    name_.setName(reinterpret_cast<const int8*>(mailbox_name.data()));
  }
}

TextureMailbox::TextureMailbox(
    const Mailbox& mailbox_name,
    const ReleaseCallback& mailbox_callback)
    : callback_(mailbox_callback),
      sync_point_(0) {
  DCHECK(mailbox_name.isZero() == mailbox_callback.is_null());
  name_.setName(mailbox_name.name);
}

TextureMailbox::TextureMailbox(
    const Mailbox& mailbox_name,
    const ReleaseCallback& mailbox_callback,
    unsigned sync_point)
    : callback_(mailbox_callback),
      sync_point_(sync_point) {
  DCHECK(mailbox_name.isZero() == mailbox_callback.is_null());
  name_.setName(mailbox_name.name);
}

TextureMailbox::~TextureMailbox() {
}

bool TextureMailbox::Equals(const Mailbox& other) const {
  return !memcmp(data(), other.name, sizeof(name_.name));
}

bool TextureMailbox::Equals(const TextureMailbox& other) const {
  return Equals(other.name());
}

bool TextureMailbox::IsEmpty() const {
  return name_.isZero();
}

void TextureMailbox::RunReleaseCallback(unsigned sync_point) const {
  if (!callback_.is_null())
    callback_.Run(sync_point);
}

void TextureMailbox::SetName(const Mailbox& other) {
  name_.setName(other.name);
}

}  // namespace cc