Home | History | Annotate | Download | only in resources
      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.
      4 
      5 #include "cc/resources/texture_mailbox.h"
      6 
      7 #include "base/logging.h"
      8 #include "third_party/khronos/GLES2/gl2.h"
      9 
     10 namespace cc {
     11 
     12 TextureMailbox::TextureMailbox()
     13     : target_(GL_TEXTURE_2D),
     14       sync_point_(0),
     15       shared_memory_(NULL) {
     16 }
     17 
     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()));
     25   }
     26 }
     27 
     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);
     33 }
     34 
     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);
     41 }
     42 
     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);
     50 }
     51 
     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) {}
     58 
     59 TextureMailbox::~TextureMailbox() {}
     60 
     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());
     66 
     67   DCHECK(!other.IsValid());
     68   return !IsValid();
     69 }
     70 
     71 bool TextureMailbox::ContainsMailbox(const gpu::Mailbox& other) const {
     72   return IsTexture() && !memcmp(data(), other.name, sizeof(name_.name));
     73 }
     74 
     75 bool TextureMailbox::ContainsHandle(base::SharedMemoryHandle handle) const {
     76   return shared_memory_ && shared_memory_->handle() == handle;
     77 }
     78 
     79 void TextureMailbox::SetName(const gpu::Mailbox& name) {
     80   DCHECK(shared_memory_ == NULL);
     81   name_ = name;
     82 }
     83 
     84 size_t TextureMailbox::shared_memory_size_in_bytes() const {
     85   return 4 * shared_memory_size_.GetArea();
     86 }
     87 
     88 }  // namespace cc
     89