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

Side by Side Diff: gpu/ipc/service/gpu_memory_buffer_factory_native_pixmap.cc

Issue 2709163004: Rename GpuMemoryBufferFactoryOzoneNativePixmap to GpuMemoryBufferFactoryNativePixmap (Closed)
Patch Set: Rebase Created 3 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 "gpu/ipc/service/gpu_memory_buffer_factory_ozone_native_pixmap.h" 5 #include "gpu/ipc/service/gpu_memory_buffer_factory_native_pixmap.h"
6 6
7 #include "ui/gfx/client_native_pixmap.h" 7 #include "ui/gfx/client_native_pixmap.h"
8 #include "ui/gfx/native_pixmap.h" 8 #include "ui/gfx/native_pixmap.h"
9 #include "ui/gl/gl_image_native_pixmap.h" 9 #include "ui/gl/gl_image_native_pixmap.h"
10 #include "ui/ozone/public/client_native_pixmap_factory_ozone.h" 10
11 #if defined(USE_OZONE)
11 #include "ui/ozone/public/ozone_platform.h" 12 #include "ui/ozone/public/ozone_platform.h"
12 #include "ui/ozone/public/surface_factory_ozone.h" 13 #include "ui/ozone/public/surface_factory_ozone.h"
14 #endif
13 15
14 namespace gpu { 16 namespace gpu {
15 17
16 GpuMemoryBufferFactoryOzoneNativePixmap:: 18 GpuMemoryBufferFactoryNativePixmap::GpuMemoryBufferFactoryNativePixmap() {}
17 GpuMemoryBufferFactoryOzoneNativePixmap() {}
18 19
19 GpuMemoryBufferFactoryOzoneNativePixmap:: 20 GpuMemoryBufferFactoryNativePixmap::~GpuMemoryBufferFactoryNativePixmap() {}
20 ~GpuMemoryBufferFactoryOzoneNativePixmap() {}
21 21
22 gfx::GpuMemoryBufferHandle 22 gfx::GpuMemoryBufferHandle
23 GpuMemoryBufferFactoryOzoneNativePixmap::CreateGpuMemoryBuffer( 23 GpuMemoryBufferFactoryNativePixmap::CreateGpuMemoryBuffer(
24 gfx::GpuMemoryBufferId id, 24 gfx::GpuMemoryBufferId id,
25 const gfx::Size& size, 25 const gfx::Size& size,
26 gfx::BufferFormat format, 26 gfx::BufferFormat format,
27 gfx::BufferUsage usage, 27 gfx::BufferUsage usage,
28 int client_id, 28 int client_id,
29 SurfaceHandle surface_handle) { 29 SurfaceHandle surface_handle) {
30 #if defined(USE_OZONE)
30 scoped_refptr<gfx::NativePixmap> pixmap = 31 scoped_refptr<gfx::NativePixmap> pixmap =
31 ui::OzonePlatform::GetInstance() 32 ui::OzonePlatform::GetInstance()
32 ->GetSurfaceFactoryOzone() 33 ->GetSurfaceFactoryOzone()
33 ->CreateNativePixmap(surface_handle, size, format, usage); 34 ->CreateNativePixmap(surface_handle, size, format, usage);
34 if (!pixmap.get()) { 35 if (!pixmap.get()) {
35 DLOG(ERROR) << "Failed to create pixmap " << size.ToString() << " format " 36 DLOG(ERROR) << "Failed to create pixmap " << size.ToString() << " format "
36 << static_cast<int>(format) << ", usage " 37 << static_cast<int>(format) << ", usage "
37 << static_cast<int>(usage); 38 << static_cast<int>(usage);
38 return gfx::GpuMemoryBufferHandle(); 39 return gfx::GpuMemoryBufferHandle();
39 } 40 }
40 41
41 gfx::GpuMemoryBufferHandle new_handle; 42 gfx::GpuMemoryBufferHandle new_handle;
42 new_handle.type = gfx::NATIVE_PIXMAP; 43 new_handle.type = gfx::NATIVE_PIXMAP;
43 new_handle.id = id; 44 new_handle.id = id;
44 new_handle.native_pixmap_handle = pixmap->ExportHandle(); 45 new_handle.native_pixmap_handle = pixmap->ExportHandle();
45 46
46 // TODO(reveman): Remove this once crbug.com/628334 has been fixed. 47 // TODO(reveman): Remove this once crbug.com/628334 has been fixed.
47 { 48 {
48 base::AutoLock lock(native_pixmaps_lock_); 49 base::AutoLock lock(native_pixmaps_lock_);
49 NativePixmapMapKey key(id.id, client_id); 50 NativePixmapMapKey key(id.id, client_id);
50 DCHECK(native_pixmaps_.find(key) == native_pixmaps_.end()); 51 DCHECK(native_pixmaps_.find(key) == native_pixmaps_.end());
51 native_pixmaps_[key] = pixmap; 52 native_pixmaps_[key] = pixmap;
52 } 53 }
53 54
54 return new_handle; 55 return new_handle;
56 #else
57 NOTIMPLEMENTED();
58 return gfx::GpuMemoryBufferHandle();
59 #endif
55 } 60 }
56 61
57 void GpuMemoryBufferFactoryOzoneNativePixmap::DestroyGpuMemoryBuffer( 62 void GpuMemoryBufferFactoryNativePixmap::DestroyGpuMemoryBuffer(
58 gfx::GpuMemoryBufferId id, 63 gfx::GpuMemoryBufferId id,
59 int client_id) { 64 int client_id) {
60 base::AutoLock lock(native_pixmaps_lock_); 65 base::AutoLock lock(native_pixmaps_lock_);
61 NativePixmapMapKey key(id.id, client_id); 66 NativePixmapMapKey key(id.id, client_id);
62 native_pixmaps_.erase(key); 67 native_pixmaps_.erase(key);
63 } 68 }
64 69
65 ImageFactory* GpuMemoryBufferFactoryOzoneNativePixmap::AsImageFactory() { 70 ImageFactory* GpuMemoryBufferFactoryNativePixmap::AsImageFactory() {
66 return this; 71 return this;
67 } 72 }
68 73
69 scoped_refptr<gl::GLImage> 74 scoped_refptr<gl::GLImage>
70 GpuMemoryBufferFactoryOzoneNativePixmap::CreateImageForGpuMemoryBuffer( 75 GpuMemoryBufferFactoryNativePixmap::CreateImageForGpuMemoryBuffer(
71 const gfx::GpuMemoryBufferHandle& handle, 76 const gfx::GpuMemoryBufferHandle& handle,
72 const gfx::Size& size, 77 const gfx::Size& size,
73 gfx::BufferFormat format, 78 gfx::BufferFormat format,
74 unsigned internalformat, 79 unsigned internalformat,
75 int client_id, 80 int client_id,
76 SurfaceHandle surface_handle) { 81 SurfaceHandle surface_handle) {
77 DCHECK_EQ(handle.type, gfx::NATIVE_PIXMAP); 82 DCHECK_EQ(handle.type, gfx::NATIVE_PIXMAP);
78 83
79 scoped_refptr<gfx::NativePixmap> pixmap; 84 scoped_refptr<gfx::NativePixmap> pixmap;
80 85
81 // If CreateGpuMemoryBuffer was used to allocate this buffer then avoid 86 // If CreateGpuMemoryBuffer was used to allocate this buffer then avoid
82 // creating a new native pixmap for it. 87 // creating a new native pixmap for it.
83 { 88 {
84 base::AutoLock lock(native_pixmaps_lock_); 89 base::AutoLock lock(native_pixmaps_lock_);
85 NativePixmapMapKey key(handle.id.id, client_id); 90 NativePixmapMapKey key(handle.id.id, client_id);
86 auto it = native_pixmaps_.find(key); 91 auto it = native_pixmaps_.find(key);
87 if (it != native_pixmaps_.end()) 92 if (it != native_pixmaps_.end())
88 pixmap = it->second; 93 pixmap = it->second;
89 } 94 }
90 95
91 // Create new pixmap from handle if one doesn't already exist. 96 // Create new pixmap from handle if one doesn't already exist.
92 if (!pixmap) { 97 if (!pixmap) {
98 #if defined(USE_OZONE)
93 pixmap = ui::OzonePlatform::GetInstance() 99 pixmap = ui::OzonePlatform::GetInstance()
94 ->GetSurfaceFactoryOzone() 100 ->GetSurfaceFactoryOzone()
95 ->CreateNativePixmapFromHandle(surface_handle, size, format, 101 ->CreateNativePixmapFromHandle(surface_handle, size, format,
96 handle.native_pixmap_handle); 102 handle.native_pixmap_handle);
103 #else
104 // TODO(j.isorce): implement this to enable glCreateImageCHROMIUM on Linux.
reveman 2017/04/12 18:11:54 nit: please create a bug for this and link to it h
105 NOTIMPLEMENTED();
106 #endif
97 if (!pixmap.get()) { 107 if (!pixmap.get()) {
98 DLOG(ERROR) << "Failed to create pixmap from handle"; 108 DLOG(ERROR) << "Failed to create pixmap from handle";
99 return nullptr; 109 return nullptr;
100 } 110 }
101 } else { 111 } else {
102 for (const auto& fd : handle.native_pixmap_handle.fds) { 112 for (const auto& fd : handle.native_pixmap_handle.fds) {
103 // Close the fd by wrapping it in a ScopedFD and letting it fall 113 // Close the fd by wrapping it in a ScopedFD and letting it fall
104 // out of scope. 114 // out of scope.
105 base::ScopedFD scoped_fd(fd.fd); 115 base::ScopedFD scoped_fd(fd.fd);
106 } 116 }
107 } 117 }
108 118
109 scoped_refptr<gl::GLImageNativePixmap> image( 119 scoped_refptr<gl::GLImageNativePixmap> image(
110 new gl::GLImageNativePixmap(size, internalformat)); 120 new gl::GLImageNativePixmap(size, internalformat));
111 if (!image->Initialize(pixmap.get(), format)) { 121 if (!image->Initialize(pixmap.get(), format)) {
112 LOG(ERROR) << "Failed to create GLImage " << size.ToString() << " format " 122 LOG(ERROR) << "Failed to create GLImage " << size.ToString() << " format "
113 << static_cast<int>(format); 123 << static_cast<int>(format);
114 return nullptr; 124 return nullptr;
115 } 125 }
116 return image; 126 return image;
117 } 127 }
118 128
119 scoped_refptr<gl::GLImage> 129 scoped_refptr<gl::GLImage>
120 GpuMemoryBufferFactoryOzoneNativePixmap::CreateAnonymousImage( 130 GpuMemoryBufferFactoryNativePixmap::CreateAnonymousImage(
121 const gfx::Size& size, 131 const gfx::Size& size,
122 gfx::BufferFormat format, 132 gfx::BufferFormat format,
123 unsigned internalformat) { 133 unsigned internalformat) {
124 scoped_refptr<gfx::NativePixmap> pixmap = 134 scoped_refptr<gfx::NativePixmap> pixmap;
125 ui::OzonePlatform::GetInstance() 135 #if defined(USE_OZONE)
126 ->GetSurfaceFactoryOzone() 136 pixmap = ui::OzonePlatform::GetInstance()
127 ->CreateNativePixmap(gpu::kNullSurfaceHandle, size, format, 137 ->GetSurfaceFactoryOzone()
128 gfx::BufferUsage::SCANOUT); 138 ->CreateNativePixmap(gpu::kNullSurfaceHandle, size, format,
139 gfx::BufferUsage::SCANOUT);
140 #else
141 NOTIMPLEMENTED();
142 #endif
129 if (!pixmap.get()) { 143 if (!pixmap.get()) {
130 LOG(ERROR) << "Failed to create pixmap " << size.ToString() << " format " 144 LOG(ERROR) << "Failed to create pixmap " << size.ToString() << " format "
131 << static_cast<int>(format); 145 << static_cast<int>(format);
132 return nullptr; 146 return nullptr;
133 } 147 }
134 scoped_refptr<gl::GLImageNativePixmap> image( 148 scoped_refptr<gl::GLImageNativePixmap> image(
135 new gl::GLImageNativePixmap(size, internalformat)); 149 new gl::GLImageNativePixmap(size, internalformat));
136 if (!image->Initialize(pixmap.get(), format)) { 150 if (!image->Initialize(pixmap.get(), format)) {
137 LOG(ERROR) << "Failed to create GLImage " << size.ToString() << " format " 151 LOG(ERROR) << "Failed to create GLImage " << size.ToString() << " format "
138 << static_cast<int>(format); 152 << static_cast<int>(format);
139 return nullptr; 153 return nullptr;
140 } 154 }
141 return image; 155 return image;
142 } 156 }
143 157
144 unsigned GpuMemoryBufferFactoryOzoneNativePixmap::RequiredTextureType() { 158 unsigned GpuMemoryBufferFactoryNativePixmap::RequiredTextureType() {
145 return GL_TEXTURE_EXTERNAL_OES; 159 return GL_TEXTURE_EXTERNAL_OES;
146 } 160 }
147 161
148 } // namespace gpu 162 } // namespace gpu
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698