| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/common/gpu/gpu_memory_buffer_factory_surface_texture.h" | 5 #include "gpu/ipc/service/gpu_memory_buffer_factory_surface_texture.h" |
| 6 | 6 |
| 7 #include "gpu/ipc/common/android/surface_texture_manager.h" | 7 #include "gpu/ipc/common/android/surface_texture_manager.h" |
| 8 #include "ui/gl/android/surface_texture.h" | 8 #include "ui/gl/android/surface_texture.h" |
| 9 #include "ui/gl/gl_image_surface_texture.h" | 9 #include "ui/gl/gl_image_surface_texture.h" |
| 10 | 10 |
| 11 namespace content { | 11 namespace gpu { |
| 12 | 12 |
| 13 GpuMemoryBufferFactorySurfaceTexture::GpuMemoryBufferFactorySurfaceTexture() { | 13 GpuMemoryBufferFactorySurfaceTexture::GpuMemoryBufferFactorySurfaceTexture() { |
| 14 } | 14 } |
| 15 | 15 |
| 16 GpuMemoryBufferFactorySurfaceTexture::~GpuMemoryBufferFactorySurfaceTexture() { | 16 GpuMemoryBufferFactorySurfaceTexture::~GpuMemoryBufferFactorySurfaceTexture() { |
| 17 } | 17 } |
| 18 | 18 |
| 19 gfx::GpuMemoryBufferHandle | 19 gfx::GpuMemoryBufferHandle |
| 20 GpuMemoryBufferFactorySurfaceTexture::CreateGpuMemoryBuffer( | 20 GpuMemoryBufferFactorySurfaceTexture::CreateGpuMemoryBuffer( |
| 21 gfx::GpuMemoryBufferId id, | 21 gfx::GpuMemoryBufferId id, |
| 22 const gfx::Size& size, | 22 const gfx::Size& size, |
| 23 gfx::BufferFormat format, | 23 gfx::BufferFormat format, |
| 24 gfx::BufferUsage usage, | 24 gfx::BufferUsage usage, |
| 25 int client_id, | 25 int client_id, |
| 26 gpu::SurfaceHandle surface_handle) { | 26 SurfaceHandle surface_handle) { |
| 27 // Note: this needs to be 0 as the surface texture implemenation will take | 27 // Note: this needs to be 0 as the surface texture implemenation will take |
| 28 // ownership of the texture and call glDeleteTextures when the GPU service | 28 // ownership of the texture and call glDeleteTextures when the GPU service |
| 29 // attaches the surface texture to a real texture id. glDeleteTextures | 29 // attaches the surface texture to a real texture id. glDeleteTextures |
| 30 // silently ignores 0. | 30 // silently ignores 0. |
| 31 const int kDummyTextureId = 0; | 31 const int kDummyTextureId = 0; |
| 32 scoped_refptr<gfx::SurfaceTexture> surface_texture = | 32 scoped_refptr<gfx::SurfaceTexture> surface_texture = |
| 33 gfx::SurfaceTexture::Create(kDummyTextureId); | 33 gfx::SurfaceTexture::Create(kDummyTextureId); |
| 34 if (!surface_texture.get()) | 34 if (!surface_texture.get()) |
| 35 return gfx::GpuMemoryBufferHandle(); | 35 return gfx::GpuMemoryBufferHandle(); |
| 36 | 36 |
| 37 gpu::SurfaceTextureManager::GetInstance()->RegisterSurfaceTexture( | 37 SurfaceTextureManager::GetInstance()->RegisterSurfaceTexture( |
| 38 id.id, client_id, surface_texture.get()); | 38 id.id, client_id, surface_texture.get()); |
| 39 | 39 |
| 40 { | 40 { |
| 41 base::AutoLock lock(surface_textures_lock_); | 41 base::AutoLock lock(surface_textures_lock_); |
| 42 | 42 |
| 43 SurfaceTextureMapKey key(id.id, client_id); | 43 SurfaceTextureMapKey key(id.id, client_id); |
| 44 DCHECK(surface_textures_.find(key) == surface_textures_.end()); | 44 DCHECK(surface_textures_.find(key) == surface_textures_.end()); |
| 45 surface_textures_[key] = surface_texture; | 45 surface_textures_[key] = surface_texture; |
| 46 } | 46 } |
| 47 | 47 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 66 gfx::GpuMemoryBufferId id, | 66 gfx::GpuMemoryBufferId id, |
| 67 int client_id) { | 67 int client_id) { |
| 68 { | 68 { |
| 69 base::AutoLock lock(surface_textures_lock_); | 69 base::AutoLock lock(surface_textures_lock_); |
| 70 | 70 |
| 71 SurfaceTextureMapKey key(id.id, client_id); | 71 SurfaceTextureMapKey key(id.id, client_id); |
| 72 DCHECK(surface_textures_.find(key) != surface_textures_.end()); | 72 DCHECK(surface_textures_.find(key) != surface_textures_.end()); |
| 73 surface_textures_.erase(key); | 73 surface_textures_.erase(key); |
| 74 } | 74 } |
| 75 | 75 |
| 76 gpu::SurfaceTextureManager::GetInstance()->UnregisterSurfaceTexture( | 76 SurfaceTextureManager::GetInstance()->UnregisterSurfaceTexture( |
| 77 id.id, client_id); | 77 id.id, client_id); |
| 78 } | 78 } |
| 79 | 79 |
| 80 gpu::ImageFactory* GpuMemoryBufferFactorySurfaceTexture::AsImageFactory() { | 80 ImageFactory* GpuMemoryBufferFactorySurfaceTexture::AsImageFactory() { |
| 81 return this; | 81 return this; |
| 82 } | 82 } |
| 83 | 83 |
| 84 scoped_refptr<gl::GLImage> | 84 scoped_refptr<gl::GLImage> |
| 85 GpuMemoryBufferFactorySurfaceTexture::CreateImageForGpuMemoryBuffer( | 85 GpuMemoryBufferFactorySurfaceTexture::CreateImageForGpuMemoryBuffer( |
| 86 const gfx::GpuMemoryBufferHandle& handle, | 86 const gfx::GpuMemoryBufferHandle& handle, |
| 87 const gfx::Size& size, | 87 const gfx::Size& size, |
| 88 gfx::BufferFormat format, | 88 gfx::BufferFormat format, |
| 89 unsigned internalformat, | 89 unsigned internalformat, |
| 90 int client_id) { | 90 int client_id) { |
| 91 base::AutoLock lock(surface_textures_lock_); | 91 base::AutoLock lock(surface_textures_lock_); |
| 92 | 92 |
| 93 DCHECK_EQ(handle.type, gfx::SURFACE_TEXTURE_BUFFER); | 93 DCHECK_EQ(handle.type, gfx::SURFACE_TEXTURE_BUFFER); |
| 94 | 94 |
| 95 SurfaceTextureMapKey key(handle.id.id, client_id); | 95 SurfaceTextureMapKey key(handle.id.id, client_id); |
| 96 SurfaceTextureMap::iterator it = surface_textures_.find(key); | 96 SurfaceTextureMap::iterator it = surface_textures_.find(key); |
| 97 if (it == surface_textures_.end()) | 97 if (it == surface_textures_.end()) |
| 98 return scoped_refptr<gl::GLImage>(); | 98 return scoped_refptr<gl::GLImage>(); |
| 99 | 99 |
| 100 scoped_refptr<gl::GLImageSurfaceTexture> image( | 100 scoped_refptr<gl::GLImageSurfaceTexture> image( |
| 101 new gl::GLImageSurfaceTexture(size)); | 101 new gl::GLImageSurfaceTexture(size)); |
| 102 if (!image->Initialize(it->second.get())) | 102 if (!image->Initialize(it->second.get())) |
| 103 return scoped_refptr<gl::GLImage>(); | 103 return scoped_refptr<gl::GLImage>(); |
| 104 | 104 |
| 105 return image; | 105 return image; |
| 106 } | 106 } |
| 107 | 107 |
| 108 } // namespace content | 108 } // namespace gpu |
| OLD | NEW |