Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(55)

Side by Side Diff: content/common/gpu/gpu_memory_buffer_factory_surface_texture.cc

Issue 1050923003: zero-copy: Clarify to allocate/destroy GpuMemoryBuffer on any thread and use it on the main thread o (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 } 44 }
45 45
46 gfx::GpuMemoryBufferHandle 46 gfx::GpuMemoryBufferHandle
47 GpuMemoryBufferFactorySurfaceTexture::CreateGpuMemoryBuffer( 47 GpuMemoryBufferFactorySurfaceTexture::CreateGpuMemoryBuffer(
48 gfx::GpuMemoryBufferId id, 48 gfx::GpuMemoryBufferId id,
49 const gfx::Size& size, 49 const gfx::Size& size,
50 gfx::GpuMemoryBuffer::Format format, 50 gfx::GpuMemoryBuffer::Format format,
51 gfx::GpuMemoryBuffer::Usage usage, 51 gfx::GpuMemoryBuffer::Usage usage,
52 int client_id, 52 int client_id,
53 gfx::PluginWindowHandle surface_handle) { 53 gfx::PluginWindowHandle surface_handle) {
54 DCHECK(thread_checker_.CalledOnValidThread());
54 // Note: this needs to be 0 as the surface texture implemenation will take 55 // 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 56 // ownership of the texture and call glDeleteTextures when the GPU service
56 // attaches the surface texture to a real texture id. glDeleteTextures 57 // attaches the surface texture to a real texture id. glDeleteTextures
57 // silently ignores 0. 58 // silently ignores 0.
58 const int kDummyTextureId = 0; 59 const int kDummyTextureId = 0;
59 scoped_refptr<gfx::SurfaceTexture> surface_texture = 60 scoped_refptr<gfx::SurfaceTexture> surface_texture =
60 gfx::SurfaceTexture::Create(kDummyTextureId); 61 gfx::SurfaceTexture::Create(kDummyTextureId);
61 if (!surface_texture.get()) 62 if (!surface_texture.get())
62 return gfx::GpuMemoryBufferHandle(); 63 return gfx::GpuMemoryBufferHandle();
63 64
64 SurfaceTextureManager::GetInstance()->RegisterSurfaceTexture( 65 SurfaceTextureManager::GetInstance()->RegisterSurfaceTexture(
65 id, client_id, surface_texture.get()); 66 id, client_id, surface_texture.get());
66 67
67 { 68 SurfaceTextureMapKey key(id, client_id);
68 base::AutoLock lock(surface_textures_lock_); 69 DCHECK(surface_textures_.find(key) == surface_textures_.end());
69 70 surface_textures_[key] = surface_texture;
70 SurfaceTextureMapKey key(id, client_id);
71 DCHECK(surface_textures_.find(key) == surface_textures_.end());
72 surface_textures_[key] = surface_texture;
73 }
74 71
75 gfx::GpuMemoryBufferHandle handle; 72 gfx::GpuMemoryBufferHandle handle;
76 handle.type = gfx::SURFACE_TEXTURE_BUFFER; 73 handle.type = gfx::SURFACE_TEXTURE_BUFFER;
77 handle.id = id; 74 handle.id = id;
78 return handle; 75 return handle;
79 } 76 }
80 77
81 void GpuMemoryBufferFactorySurfaceTexture::DestroyGpuMemoryBuffer( 78 void GpuMemoryBufferFactorySurfaceTexture::DestroyGpuMemoryBuffer(
82 gfx::GpuMemoryBufferId id, 79 gfx::GpuMemoryBufferId id,
83 int client_id) { 80 int client_id) {
84 { 81 DCHECK(thread_checker_.CalledOnValidThread());
85 base::AutoLock lock(surface_textures_lock_); 82 SurfaceTextureMapKey key(id, client_id);
86 83 SurfaceTextureMap::iterator it = surface_textures_.find(key);
87 SurfaceTextureMapKey key(id, client_id); 84 if (it != surface_textures_.end())
88 SurfaceTextureMap::iterator it = surface_textures_.find(key); 85 surface_textures_.erase(it);
89 if (it != surface_textures_.end())
90 surface_textures_.erase(it);
91 }
92 86
93 SurfaceTextureManager::GetInstance()->UnregisterSurfaceTexture(id, client_id); 87 SurfaceTextureManager::GetInstance()->UnregisterSurfaceTexture(id, client_id);
94 } 88 }
95 89
96 gpu::ImageFactory* GpuMemoryBufferFactorySurfaceTexture::AsImageFactory() { 90 gpu::ImageFactory* GpuMemoryBufferFactorySurfaceTexture::AsImageFactory() {
97 return this; 91 return this;
98 } 92 }
99 93
100 scoped_refptr<gfx::GLImage> 94 scoped_refptr<gfx::GLImage>
101 GpuMemoryBufferFactorySurfaceTexture::CreateImageForGpuMemoryBuffer( 95 GpuMemoryBufferFactorySurfaceTexture::CreateImageForGpuMemoryBuffer(
102 const gfx::GpuMemoryBufferHandle& handle, 96 const gfx::GpuMemoryBufferHandle& handle,
103 const gfx::Size& size, 97 const gfx::Size& size,
104 gfx::GpuMemoryBuffer::Format format, 98 gfx::GpuMemoryBuffer::Format format,
105 unsigned internalformat, 99 unsigned internalformat,
106 int client_id) { 100 int client_id) {
107 base::AutoLock lock(surface_textures_lock_); 101 DCHECK(thread_checker_.CalledOnValidThread());
108
109 DCHECK_EQ(handle.type, gfx::SURFACE_TEXTURE_BUFFER); 102 DCHECK_EQ(handle.type, gfx::SURFACE_TEXTURE_BUFFER);
110 103
111 SurfaceTextureMapKey key(handle.id, client_id); 104 SurfaceTextureMapKey key(handle.id, client_id);
112 SurfaceTextureMap::iterator it = surface_textures_.find(key); 105 SurfaceTextureMap::iterator it = surface_textures_.find(key);
113 if (it == surface_textures_.end()) 106 if (it == surface_textures_.end())
114 return scoped_refptr<gfx::GLImage>(); 107 return scoped_refptr<gfx::GLImage>();
115 108
116 scoped_refptr<gfx::GLImageSurfaceTexture> image( 109 scoped_refptr<gfx::GLImageSurfaceTexture> image(
117 new gfx::GLImageSurfaceTexture(size)); 110 new gfx::GLImageSurfaceTexture(size));
118 if (!image->Initialize(it->second.get())) 111 if (!image->Initialize(it->second.get()))
119 return scoped_refptr<gfx::GLImage>(); 112 return scoped_refptr<gfx::GLImage>();
120 113
121 return image; 114 return image;
122 } 115 }
123 116
124 } // namespace content 117 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698