Home | History | Annotate | Download | only in service
      1 // Copyright (c) 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 "gpu/command_buffer/service/stream_texture_manager_in_process_android.h"
      6 
      7 #include "base/bind.h"
      8 #include "ui/gfx/size.h"
      9 #include "ui/gl/android/surface_texture_bridge.h"
     10 #include "ui/gl/gl_bindings.h"
     11 
     12 namespace gpu {
     13 
     14 StreamTextureManagerInProcess::StreamTextureImpl::StreamTextureImpl(
     15     uint32 service_id,
     16     uint32 stream_id)
     17     : surface_texture_bridge_(new gfx::SurfaceTextureBridge(service_id)),
     18       stream_id_(stream_id) {}
     19 
     20 StreamTextureManagerInProcess::StreamTextureImpl::~StreamTextureImpl() {}
     21 
     22 void StreamTextureManagerInProcess::StreamTextureImpl::Update() {
     23   GLint texture_id = 0;
     24   glGetIntegerv(GL_TEXTURE_BINDING_EXTERNAL_OES, &texture_id);
     25   surface_texture_bridge_->UpdateTexImage();
     26   glBindTexture(GL_TEXTURE_EXTERNAL_OES, texture_id);
     27 }
     28 
     29 gfx::Size StreamTextureManagerInProcess::StreamTextureImpl::GetSize() {
     30   return size_;
     31 }
     32 
     33 void StreamTextureManagerInProcess::StreamTextureImpl::SetSize(gfx::Size size) {
     34   size_ = size;
     35 }
     36 
     37 scoped_refptr<gfx::SurfaceTextureBridge>
     38 StreamTextureManagerInProcess::StreamTextureImpl::GetSurfaceTexture() {
     39   return surface_texture_bridge_;
     40 }
     41 
     42 StreamTextureManagerInProcess::StreamTextureManagerInProcess() : next_id_(1) {}
     43 
     44 StreamTextureManagerInProcess::~StreamTextureManagerInProcess() {
     45   if (!textures_.empty()) {
     46     LOG(WARNING) << "Undestroyed surface textures while tearing down "
     47                     "StreamTextureManager.";
     48   }
     49 }
     50 
     51 GLuint StreamTextureManagerInProcess::CreateStreamTexture(uint32 service_id,
     52                                                           uint32 client_id) {
     53   base::AutoLock lock(map_lock_);
     54   uint32 stream_id = next_id_++;
     55   linked_ptr<StreamTextureImpl> texture(
     56       new StreamTextureImpl(service_id, stream_id));
     57   textures_[service_id] = texture;
     58 
     59   if (next_id_ == 0)
     60     next_id_++;
     61 
     62   return stream_id;
     63 }
     64 
     65 void StreamTextureManagerInProcess::DestroyStreamTexture(uint32 service_id) {
     66   base::AutoLock lock(map_lock_);
     67   textures_.erase(service_id);
     68 }
     69 
     70 gpu::StreamTexture* StreamTextureManagerInProcess::LookupStreamTexture(
     71     uint32 service_id) {
     72   base::AutoLock lock(map_lock_);
     73   TextureMap::const_iterator it = textures_.find(service_id);
     74   if (it != textures_.end())
     75     return it->second.get();
     76 
     77   return NULL;
     78 }
     79 
     80 scoped_refptr<gfx::SurfaceTextureBridge>
     81 StreamTextureManagerInProcess::GetSurfaceTexture(uint32 stream_id) {
     82   base::AutoLock lock(map_lock_);
     83   for (TextureMap::iterator it = textures_.begin(); it != textures_.end();
     84        it++) {
     85     if (it->second->stream_id() == stream_id)
     86       return it->second->GetSurfaceTexture();
     87   }
     88 
     89   return NULL;
     90 }
     91 
     92 }  // namespace gpu
     93