| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "gpu/ipc/service/gpu_memory_buffer_factory_surface_texture.h" | |
| 6 | |
| 7 #include "gpu/ipc/common/android/surface_texture_manager.h" | |
| 8 #include "ui/gl/android/surface_texture.h" | |
| 9 #include "ui/gl/gl_image_surface_texture.h" | |
| 10 | |
| 11 namespace gpu { | |
| 12 | |
| 13 GpuMemoryBufferFactorySurfaceTexture::GpuMemoryBufferFactorySurfaceTexture() { | |
| 14 } | |
| 15 | |
| 16 GpuMemoryBufferFactorySurfaceTexture::~GpuMemoryBufferFactorySurfaceTexture() { | |
| 17 } | |
| 18 | |
| 19 gfx::GpuMemoryBufferHandle | |
| 20 GpuMemoryBufferFactorySurfaceTexture::CreateGpuMemoryBuffer( | |
| 21 gfx::GpuMemoryBufferId id, | |
| 22 const gfx::Size& size, | |
| 23 gfx::BufferFormat format, | |
| 24 gfx::BufferUsage usage, | |
| 25 int client_id, | |
| 26 SurfaceHandle surface_handle) { | |
| 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 | |
| 29 // attaches the surface texture to a real texture id. glDeleteTextures | |
| 30 // silently ignores 0. | |
| 31 const int kDummyTextureId = 0; | |
| 32 scoped_refptr<gl::SurfaceTexture> surface_texture = | |
| 33 gl::SurfaceTexture::Create(kDummyTextureId); | |
| 34 if (!surface_texture.get()) | |
| 35 return gfx::GpuMemoryBufferHandle(); | |
| 36 | |
| 37 SurfaceTextureManager::GetInstance()->RegisterSurfaceTexture( | |
| 38 id.id, client_id, surface_texture.get()); | |
| 39 | |
| 40 { | |
| 41 base::AutoLock lock(surface_textures_lock_); | |
| 42 | |
| 43 SurfaceTextureMapKey key(id.id, client_id); | |
| 44 DCHECK(surface_textures_.find(key) == surface_textures_.end()); | |
| 45 surface_textures_[key] = surface_texture; | |
| 46 } | |
| 47 | |
| 48 gfx::GpuMemoryBufferHandle handle; | |
| 49 handle.type = gfx::SURFACE_TEXTURE_BUFFER; | |
| 50 handle.id = id; | |
| 51 return handle; | |
| 52 } | |
| 53 | |
| 54 void GpuMemoryBufferFactorySurfaceTexture::DestroyGpuMemoryBuffer( | |
| 55 gfx::GpuMemoryBufferId id, | |
| 56 int client_id) { | |
| 57 { | |
| 58 base::AutoLock lock(surface_textures_lock_); | |
| 59 | |
| 60 SurfaceTextureMapKey key(id.id, client_id); | |
| 61 DCHECK(surface_textures_.find(key) != surface_textures_.end()); | |
| 62 surface_textures_.erase(key); | |
| 63 } | |
| 64 | |
| 65 SurfaceTextureManager::GetInstance()->UnregisterSurfaceTexture( | |
| 66 id.id, client_id); | |
| 67 } | |
| 68 | |
| 69 ImageFactory* GpuMemoryBufferFactorySurfaceTexture::AsImageFactory() { | |
| 70 return this; | |
| 71 } | |
| 72 | |
| 73 scoped_refptr<gl::GLImage> | |
| 74 GpuMemoryBufferFactorySurfaceTexture::CreateImageForGpuMemoryBuffer( | |
| 75 const gfx::GpuMemoryBufferHandle& handle, | |
| 76 const gfx::Size& size, | |
| 77 gfx::BufferFormat format, | |
| 78 unsigned internalformat, | |
| 79 int client_id, | |
| 80 SurfaceHandle surface_handle) { | |
| 81 base::AutoLock lock(surface_textures_lock_); | |
| 82 | |
| 83 DCHECK_EQ(handle.type, gfx::SURFACE_TEXTURE_BUFFER); | |
| 84 | |
| 85 SurfaceTextureMapKey key(handle.id.id, client_id); | |
| 86 SurfaceTextureMap::iterator it = surface_textures_.find(key); | |
| 87 if (it == surface_textures_.end()) | |
| 88 return scoped_refptr<gl::GLImage>(); | |
| 89 | |
| 90 scoped_refptr<gl::GLImageSurfaceTexture> image( | |
| 91 new gl::GLImageSurfaceTexture(size)); | |
| 92 if (!image->Initialize(it->second.get())) | |
| 93 return scoped_refptr<gl::GLImage>(); | |
| 94 | |
| 95 return image; | |
| 96 } | |
| 97 | |
| 98 } // namespace gpu | |
| OLD | NEW |