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 "content/common/gpu/gpu_memory_buffer_factory_surface_texture.h" |
| 6 |
| 7 #include "content/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 content { |
| 12 |
| 13 GpuMemoryBufferFactorySurfaceTexture::GpuMemoryBufferFactorySurfaceTexture() { |
| 14 } |
| 15 |
| 16 GpuMemoryBufferFactorySurfaceTexture::~GpuMemoryBufferFactorySurfaceTexture() { |
| 17 } |
| 18 |
| 19 gfx::GpuMemoryBufferHandle |
| 20 GpuMemoryBufferFactorySurfaceTexture::CreateGpuMemoryBuffer( |
| 21 const gfx::GpuMemoryBufferId& id, |
| 22 const gfx::Size& size, |
| 23 unsigned internalformat) { |
| 24 // Note: this needs to be 0 as the surface texture implemenation will take |
| 25 // ownership of the texture and call glDeleteTextures when the GPU service |
| 26 // attaches the surface texture to a real texture id. glDeleteTextures |
| 27 // silently ignores 0. |
| 28 const int kDummyTextureId = 0; |
| 29 scoped_refptr<gfx::SurfaceTexture> surface_texture = |
| 30 gfx::SurfaceTexture::Create(kDummyTextureId); |
| 31 if (!surface_texture.get()) |
| 32 return gfx::GpuMemoryBufferHandle(); |
| 33 |
| 34 SurfaceTextureManager::GetInstance()->RegisterSurfaceTexture( |
| 35 id.primary_id, id.secondary_id, surface_texture.get()); |
| 36 |
| 37 SurfaceTextureMapKey key(id.primary_id, id.secondary_id); |
| 38 DCHECK(surface_textures_.find(key) == surface_textures_.end()); |
| 39 surface_textures_[key] = surface_texture; |
| 40 |
| 41 gfx::GpuMemoryBufferHandle handle; |
| 42 handle.type = gfx::SURFACE_TEXTURE_BUFFER; |
| 43 handle.global_id = id; |
| 44 return handle; |
| 45 } |
| 46 |
| 47 void GpuMemoryBufferFactorySurfaceTexture::DestroyGpuMemoryBuffer( |
| 48 const gfx::GpuMemoryBufferId& id) { |
| 49 SurfaceTextureMapKey key(id.primary_id, id.secondary_id); |
| 50 SurfaceTextureMap::iterator it = surface_textures_.find(key); |
| 51 if (it != surface_textures_.end()) |
| 52 surface_textures_.erase(it); |
| 53 |
| 54 SurfaceTextureManager::GetInstance()->UnregisterSurfaceTexture( |
| 55 id.primary_id, id.secondary_id); |
| 56 } |
| 57 |
| 58 scoped_refptr<gfx::GLImage> |
| 59 GpuMemoryBufferFactorySurfaceTexture::CreateImageForGpuMemoryBuffer( |
| 60 const gfx::GpuMemoryBufferId& id, |
| 61 const gfx::Size& size, |
| 62 unsigned internalformat) { |
| 63 SurfaceTextureMapKey key(id.primary_id, id.secondary_id); |
| 64 SurfaceTextureMap::iterator it = surface_textures_.find(key); |
| 65 if (it == surface_textures_.end()) |
| 66 return scoped_refptr<gfx::GLImage>(); |
| 67 |
| 68 scoped_refptr<gfx::GLImageSurfaceTexture> image( |
| 69 new gfx::GLImageSurfaceTexture(size)); |
| 70 if (!image->Initialize(it->second.get())) |
| 71 return scoped_refptr<gfx::GLImage>(); |
| 72 |
| 73 return image; |
| 74 } |
| 75 |
| 76 } // namespace content |
OLD | NEW |