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