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"
12 TextureMailbox::TextureMailbox()
13 : target_(GL_TEXTURE_2D),
15 shared_memory_(NULL) {
18 TextureMailbox::TextureMailbox(const std::string& mailbox_name)
19 : target_(GL_TEXTURE_2D),
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),
31 shared_memory_(NULL) {
32 name_.SetName(mailbox_name.name);
35 TextureMailbox::TextureMailbox(const gpu::Mailbox& mailbox_name,
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,
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,
54 : target_(GL_TEXTURE_2D),
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());
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);
84 size_t TextureMailbox::shared_memory_size_in_bytes() const {
85 return 4 * shared_memory_size_.GetArea();