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 namespace { | 12 namespace { |
13 | 13 |
14 const GpuMemoryBufferFactory::Configuration kSupportedConfigurations[] = { | 14 const GpuMemoryBufferFactory::Configuration kSupportedConfigurations[] = { |
15 { gfx::GpuMemoryBuffer::RGBA_8888, gfx::GpuMemoryBuffer::MAP } | 15 {gfx::BufferFormat::RGBA_8888, gfx::BufferUsage::MAP}}; |
16 }; | |
17 | 16 |
18 } // namespace | 17 } // namespace |
19 | 18 |
20 GpuMemoryBufferFactorySurfaceTexture::GpuMemoryBufferFactorySurfaceTexture() { | 19 GpuMemoryBufferFactorySurfaceTexture::GpuMemoryBufferFactorySurfaceTexture() { |
21 } | 20 } |
22 | 21 |
23 GpuMemoryBufferFactorySurfaceTexture::~GpuMemoryBufferFactorySurfaceTexture() { | 22 GpuMemoryBufferFactorySurfaceTexture::~GpuMemoryBufferFactorySurfaceTexture() { |
24 } | 23 } |
25 | 24 |
26 // static | 25 // static |
27 bool GpuMemoryBufferFactorySurfaceTexture:: | 26 bool GpuMemoryBufferFactorySurfaceTexture:: |
28 IsGpuMemoryBufferConfigurationSupported(gfx::GpuMemoryBuffer::Format format, | 27 IsGpuMemoryBufferConfigurationSupported(gfx::BufferFormat format, |
29 gfx::GpuMemoryBuffer::Usage usage) { | 28 gfx::BufferUsage usage) { |
30 for (auto& configuration : kSupportedConfigurations) { | 29 for (auto& configuration : kSupportedConfigurations) { |
31 if (configuration.format == format && configuration.usage == usage) | 30 if (configuration.format == format && configuration.usage == usage) |
32 return true; | 31 return true; |
33 } | 32 } |
34 | 33 |
35 return false; | 34 return false; |
36 } | 35 } |
37 | 36 |
38 void GpuMemoryBufferFactorySurfaceTexture:: | 37 void GpuMemoryBufferFactorySurfaceTexture:: |
39 GetSupportedGpuMemoryBufferConfigurations( | 38 GetSupportedGpuMemoryBufferConfigurations( |
40 std::vector<Configuration>* configurations) { | 39 std::vector<Configuration>* configurations) { |
41 configurations->assign( | 40 configurations->assign( |
42 kSupportedConfigurations, | 41 kSupportedConfigurations, |
43 kSupportedConfigurations + arraysize(kSupportedConfigurations)); | 42 kSupportedConfigurations + arraysize(kSupportedConfigurations)); |
44 } | 43 } |
45 | 44 |
46 gfx::GpuMemoryBufferHandle | 45 gfx::GpuMemoryBufferHandle |
47 GpuMemoryBufferFactorySurfaceTexture::CreateGpuMemoryBuffer( | 46 GpuMemoryBufferFactorySurfaceTexture::CreateGpuMemoryBuffer( |
48 gfx::GpuMemoryBufferId id, | 47 gfx::GpuMemoryBufferId id, |
49 const gfx::Size& size, | 48 const gfx::Size& size, |
50 gfx::GpuMemoryBuffer::Format format, | 49 gfx::BufferFormat format, |
51 gfx::GpuMemoryBuffer::Usage usage, | 50 gfx::BufferUsage usage, |
52 int client_id, | 51 int client_id, |
53 gfx::PluginWindowHandle surface_handle) { | 52 gfx::PluginWindowHandle surface_handle) { |
54 // Note: this needs to be 0 as the surface texture implemenation will take | 53 // Note: this needs to be 0 as the surface texture implemenation will take |
55 // ownership of the texture and call glDeleteTextures when the GPU service | 54 // ownership of the texture and call glDeleteTextures when the GPU service |
56 // attaches the surface texture to a real texture id. glDeleteTextures | 55 // attaches the surface texture to a real texture id. glDeleteTextures |
57 // silently ignores 0. | 56 // silently ignores 0. |
58 const int kDummyTextureId = 0; | 57 const int kDummyTextureId = 0; |
59 scoped_refptr<gfx::SurfaceTexture> surface_texture = | 58 scoped_refptr<gfx::SurfaceTexture> surface_texture = |
60 gfx::SurfaceTexture::Create(kDummyTextureId); | 59 gfx::SurfaceTexture::Create(kDummyTextureId); |
61 if (!surface_texture.get()) | 60 if (!surface_texture.get()) |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 } | 92 } |
94 | 93 |
95 gpu::ImageFactory* GpuMemoryBufferFactorySurfaceTexture::AsImageFactory() { | 94 gpu::ImageFactory* GpuMemoryBufferFactorySurfaceTexture::AsImageFactory() { |
96 return this; | 95 return this; |
97 } | 96 } |
98 | 97 |
99 scoped_refptr<gfx::GLImage> | 98 scoped_refptr<gfx::GLImage> |
100 GpuMemoryBufferFactorySurfaceTexture::CreateImageForGpuMemoryBuffer( | 99 GpuMemoryBufferFactorySurfaceTexture::CreateImageForGpuMemoryBuffer( |
101 const gfx::GpuMemoryBufferHandle& handle, | 100 const gfx::GpuMemoryBufferHandle& handle, |
102 const gfx::Size& size, | 101 const gfx::Size& size, |
103 gfx::GpuMemoryBuffer::Format format, | 102 gfx::BufferFormat format, |
104 unsigned internalformat, | 103 unsigned internalformat, |
105 int client_id) { | 104 int client_id) { |
106 base::AutoLock lock(surface_textures_lock_); | 105 base::AutoLock lock(surface_textures_lock_); |
107 | 106 |
108 DCHECK_EQ(handle.type, gfx::SURFACE_TEXTURE_BUFFER); | 107 DCHECK_EQ(handle.type, gfx::SURFACE_TEXTURE_BUFFER); |
109 | 108 |
110 SurfaceTextureMapKey key(handle.id, client_id); | 109 SurfaceTextureMapKey key(handle.id, client_id); |
111 SurfaceTextureMap::iterator it = surface_textures_.find(key); | 110 SurfaceTextureMap::iterator it = surface_textures_.find(key); |
112 if (it == surface_textures_.end()) | 111 if (it == surface_textures_.end()) |
113 return scoped_refptr<gfx::GLImage>(); | 112 return scoped_refptr<gfx::GLImage>(); |
114 | 113 |
115 scoped_refptr<gfx::GLImageSurfaceTexture> image( | 114 scoped_refptr<gfx::GLImageSurfaceTexture> image( |
116 new gfx::GLImageSurfaceTexture(size)); | 115 new gfx::GLImageSurfaceTexture(size)); |
117 if (!image->Initialize(it->second.get())) | 116 if (!image->Initialize(it->second.get())) |
118 return scoped_refptr<gfx::GLImage>(); | 117 return scoped_refptr<gfx::GLImage>(); |
119 | 118 |
120 return image; | 119 return image; |
121 } | 120 } |
122 | 121 |
123 } // namespace content | 122 } // namespace content |
OLD | NEW |