Track webapp meta tag adoption
[chromium-blink-merge.git] / cc / resources / texture_mailbox.cc
blob149d56c8d1ac12031cf85f1646fa7d8fe952a406
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 #include "cc/resources/texture_mailbox.h"
7 #include "base/logging.h"
8 #include "third_party/khronos/GLES2/gl2.h"
10 namespace cc {
12 TextureMailbox::TextureMailbox()
13 : target_(GL_TEXTURE_2D),
14 sync_point_(0),
15 shared_memory_(NULL) {
18 TextureMailbox::TextureMailbox(const std::string& mailbox_name)
19 : target_(GL_TEXTURE_2D),
20 sync_point_(0),
21 shared_memory_(NULL) {
22 if (!mailbox_name.empty()) {
23 CHECK(mailbox_name.size() == sizeof(name_.name));
24 name_.SetName(reinterpret_cast<const int8*>(mailbox_name.data()));
28 TextureMailbox::TextureMailbox(const gpu::Mailbox& mailbox_name)
29 : target_(GL_TEXTURE_2D),
30 sync_point_(0),
31 shared_memory_(NULL) {
32 name_.SetName(mailbox_name.name);
35 TextureMailbox::TextureMailbox(const gpu::Mailbox& mailbox_name,
36 unsigned sync_point)
37 : target_(GL_TEXTURE_2D),
38 sync_point_(sync_point),
39 shared_memory_(NULL) {
40 name_.SetName(mailbox_name.name);
43 TextureMailbox::TextureMailbox(const gpu::Mailbox& mailbox_name,
44 unsigned texture_target,
45 unsigned sync_point)
46 : target_(texture_target),
47 sync_point_(sync_point),
48 shared_memory_(NULL) {
49 name_.SetName(mailbox_name.name);
52 TextureMailbox::TextureMailbox(base::SharedMemory* shared_memory,
53 gfx::Size size)
54 : target_(GL_TEXTURE_2D),
55 sync_point_(0),
56 shared_memory_(shared_memory),
57 shared_memory_size_(size) {}
59 TextureMailbox::~TextureMailbox() {}
61 bool TextureMailbox::Equals(const TextureMailbox& other) const {
62 if (other.IsTexture())
63 return ContainsMailbox(other.name());
64 else if (other.IsSharedMemory())
65 return ContainsHandle(other.shared_memory_->handle());
67 DCHECK(!other.IsValid());
68 return !IsValid();
71 bool TextureMailbox::ContainsMailbox(const gpu::Mailbox& other) const {
72 return IsTexture() && !memcmp(data(), other.name, sizeof(name_.name));
75 bool TextureMailbox::ContainsHandle(base::SharedMemoryHandle handle) const {
76 return shared_memory_ && shared_memory_->handle() == handle;
79 void TextureMailbox::SetName(const gpu::Mailbox& name) {
80 DCHECK(shared_memory_ == NULL);
81 name_ = name;
84 size_t TextureMailbox::shared_memory_size_in_bytes() const {
85 return 4 * shared_memory_size_.GetArea();
88 } // namespace cc