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 "gpu/command_buffer/service/stream_texture_manager_in_process_android.h"
8 #include "ui/gfx/size.h"
9 #include "ui/gl/android/surface_texture.h"
10 #include "ui/gl/gl_bindings.h"
14 StreamTextureManagerInProcess::StreamTextureImpl::StreamTextureImpl(
17 : surface_texture_(new gfx::SurfaceTexture(service_id)),
18 stream_id_(stream_id) {}
20 StreamTextureManagerInProcess::StreamTextureImpl::~StreamTextureImpl() {}
22 void StreamTextureManagerInProcess::StreamTextureImpl::Update() {
24 glGetIntegerv(GL_TEXTURE_BINDING_EXTERNAL_OES, &texture_id);
25 surface_texture_->UpdateTexImage();
26 glBindTexture(GL_TEXTURE_EXTERNAL_OES, texture_id);
29 gfx::Size StreamTextureManagerInProcess::StreamTextureImpl::GetSize() {
33 void StreamTextureManagerInProcess::StreamTextureImpl::SetSize(gfx::Size size) {
37 scoped_refptr<gfx::SurfaceTexture>
38 StreamTextureManagerInProcess::StreamTextureImpl::GetSurfaceTexture() {
39 return surface_texture_;
42 StreamTextureManagerInProcess::StreamTextureManagerInProcess() : next_id_(1) {}
44 StreamTextureManagerInProcess::~StreamTextureManagerInProcess() {
45 if (!textures_.empty()) {
46 LOG(WARNING) << "Undestroyed surface textures while tearing down "
47 "StreamTextureManager.";
51 GLuint StreamTextureManagerInProcess::CreateStreamTexture(uint32 service_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;
65 void StreamTextureManagerInProcess::DestroyStreamTexture(uint32 service_id) {
66 base::AutoLock lock(map_lock_);
67 textures_.erase(service_id);
70 gpu::StreamTexture* StreamTextureManagerInProcess::LookupStreamTexture(
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();
80 scoped_refptr<gfx::SurfaceTexture>
81 StreamTextureManagerInProcess::GetSurfaceTexture(uint32 stream_id) {
82 base::AutoLock lock(map_lock_);
83 for (TextureMap::iterator it = textures_.begin(); it != textures_.end();
85 if (it->second->stream_id() == stream_id)
86 return it->second->GetSurfaceTexture();