| 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<gfx::SurfaceTexture> surface_texture = | |
| 33 gfx::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 gfx::GpuMemoryBufferHandle | |
| 55 GpuMemoryBufferFactorySurfaceTexture::CreateGpuMemoryBufferFromHandle( | |
| 56 const gfx::GpuMemoryBufferHandle& handle, | |
| 57 gfx::GpuMemoryBufferId id, | |
| 58 const gfx::Size& size, | |
| 59 gfx::BufferFormat format, | |
| 60 int client_id) { | |
| 61 NOTIMPLEMENTED(); | |
| 62 return gfx::GpuMemoryBufferHandle(); | |
| 63 } | |
| 64 | |
| 65 void GpuMemoryBufferFactorySurfaceTexture::DestroyGpuMemoryBuffer( | |
| 66 gfx::GpuMemoryBufferId id, | |
| 67 int client_id) { | |
| 68 { | |
| 69 base::AutoLock lock(surface_textures_lock_); | |
| 70 | |
| 71 SurfaceTextureMapKey key(id.id, client_id); | |
| 72 DCHECK(surface_textures_.find(key) != surface_textures_.end()); | |
| 73 surface_textures_.erase(key); | |
| 74 } | |
| 75 | |
| 76 SurfaceTextureManager::GetInstance()->UnregisterSurfaceTexture( | |
| 77 id.id, client_id); | |
| 78 } | |
| 79 | |
| 80 ImageFactory* GpuMemoryBufferFactorySurfaceTexture::AsImageFactory() { | |
| 81 return this; | |
| 82 } | |
| 83 | |
| 84 scoped_refptr<gl::GLImage> | |
| 85 GpuMemoryBufferFactorySurfaceTexture::CreateImageForGpuMemoryBuffer( | |
| 86 const gfx::GpuMemoryBufferHandle& handle, | |
| 87 const gfx::Size& size, | |
| 88 gfx::BufferFormat format, | |
| 89 unsigned internalformat, | |
| 90 int client_id) { | |
| 91 base::AutoLock lock(surface_textures_lock_); | |
| 92 | |
| 93 DCHECK_EQ(handle.type, gfx::SURFACE_TEXTURE_BUFFER); | |
| 94 | |
| 95 SurfaceTextureMapKey key(handle.id.id, client_id); | |
| 96 SurfaceTextureMap::iterator it = surface_textures_.find(key); | |
| 97 if (it == surface_textures_.end()) | |
| 98 return scoped_refptr<gl::GLImage>(); | |
| 99 | |
| 100 scoped_refptr<gl::GLImageSurfaceTexture> image( | |
| 101 new gl::GLImageSurfaceTexture(size)); | |
| 102 if (!image->Initialize(it->second.get())) | |
| 103 return scoped_refptr<gl::GLImage>(); | |
| 104 | |
| 105 return image; | |
| 106 } | |
| 107 | |
| 108 } // namespace gpu | |
| OLD | NEW |