Add ICU message format support
[chromium-blink-merge.git] / content / common / gpu / gpu_memory_buffer_factory_surface_texture.cc
blob7c3c806f4839acf0f7a5ad91ed04b7dddca06948
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.
5 #include "content/common/gpu/gpu_memory_buffer_factory_surface_texture.h"
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"
11 namespace content {
12 namespace {
14 const GpuMemoryBufferFactory::Configuration kSupportedConfigurations[] = {
15 {gfx::BufferFormat::RGBA_8888, gfx::BufferUsage::MAP}};
17 } // namespace
19 GpuMemoryBufferFactorySurfaceTexture::GpuMemoryBufferFactorySurfaceTexture() {
22 GpuMemoryBufferFactorySurfaceTexture::~GpuMemoryBufferFactorySurfaceTexture() {
25 // static
26 bool GpuMemoryBufferFactorySurfaceTexture::
27 IsGpuMemoryBufferConfigurationSupported(gfx::BufferFormat format,
28 gfx::BufferUsage usage) {
29 for (auto& configuration : kSupportedConfigurations) {
30 if (configuration.format == format && configuration.usage == usage)
31 return true;
34 return false;
37 void GpuMemoryBufferFactorySurfaceTexture::
38 GetSupportedGpuMemoryBufferConfigurations(
39 std::vector<Configuration>* configurations) {
40 configurations->assign(
41 kSupportedConfigurations,
42 kSupportedConfigurations + arraysize(kSupportedConfigurations));
45 gfx::GpuMemoryBufferHandle
46 GpuMemoryBufferFactorySurfaceTexture::CreateGpuMemoryBuffer(
47 gfx::GpuMemoryBufferId id,
48 const gfx::Size& size,
49 gfx::BufferFormat format,
50 gfx::BufferUsage usage,
51 int client_id,
52 gfx::PluginWindowHandle surface_handle) {
53 // Note: this needs to be 0 as the surface texture implemenation will take
54 // ownership of the texture and call glDeleteTextures when the GPU service
55 // attaches the surface texture to a real texture id. glDeleteTextures
56 // silently ignores 0.
57 const int kDummyTextureId = 0;
58 scoped_refptr<gfx::SurfaceTexture> surface_texture =
59 gfx::SurfaceTexture::Create(kDummyTextureId);
60 if (!surface_texture.get())
61 return gfx::GpuMemoryBufferHandle();
63 SurfaceTextureManager::GetInstance()->RegisterSurfaceTexture(
64 id, client_id, surface_texture.get());
67 base::AutoLock lock(surface_textures_lock_);
69 SurfaceTextureMapKey key(id, client_id);
70 DCHECK(surface_textures_.find(key) == surface_textures_.end());
71 surface_textures_[key] = surface_texture;
74 gfx::GpuMemoryBufferHandle handle;
75 handle.type = gfx::SURFACE_TEXTURE_BUFFER;
76 handle.id = id;
77 return handle;
80 void GpuMemoryBufferFactorySurfaceTexture::DestroyGpuMemoryBuffer(
81 gfx::GpuMemoryBufferId id,
82 int client_id) {
84 base::AutoLock lock(surface_textures_lock_);
86 SurfaceTextureMapKey key(id, client_id);
87 DCHECK(surface_textures_.find(key) != surface_textures_.end());
88 surface_textures_.erase(key);
91 SurfaceTextureManager::GetInstance()->UnregisterSurfaceTexture(id, client_id);
94 gpu::ImageFactory* GpuMemoryBufferFactorySurfaceTexture::AsImageFactory() {
95 return this;
98 scoped_refptr<gfx::GLImage>
99 GpuMemoryBufferFactorySurfaceTexture::CreateImageForGpuMemoryBuffer(
100 const gfx::GpuMemoryBufferHandle& handle,
101 const gfx::Size& size,
102 gfx::BufferFormat format,
103 unsigned internalformat,
104 int client_id) {
105 base::AutoLock lock(surface_textures_lock_);
107 DCHECK_EQ(handle.type, gfx::SURFACE_TEXTURE_BUFFER);
109 SurfaceTextureMapKey key(handle.id, client_id);
110 SurfaceTextureMap::iterator it = surface_textures_.find(key);
111 if (it == surface_textures_.end())
112 return scoped_refptr<gfx::GLImage>();
114 scoped_refptr<gfx::GLImageSurfaceTexture> image(
115 new gfx::GLImageSurfaceTexture(size));
116 if (!image->Initialize(it->second.get()))
117 return scoped_refptr<gfx::GLImage>();
119 return image;
122 } // namespace content