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

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

Issue 1134993003: ozone: Implement zero/one-copy texture for Ozone GBM. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: open VGEM device in renderer in ad-hoc manner Created 5 years, 4 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_ozone_native_pixmap.h" 5 #include "content/common/gpu/gpu_memory_buffer_factory_ozone_native_pixmap.h"
6 6
7 #include "base/posix/eintr_wrapper.h"
7 #include "ui/gl/gl_image_ozone_native_pixmap.h" 8 #include "ui/gl/gl_image_ozone_native_pixmap.h"
8 #include "ui/ozone/public/client_native_pixmap_factory.h" 9 #include "ui/ozone/public/client_native_pixmap_factory.h"
9 #include "ui/ozone/public/ozone_platform.h" 10 #include "ui/ozone/public/ozone_platform.h"
10 #include "ui/ozone/public/surface_factory_ozone.h" 11 #include "ui/ozone/public/surface_factory_ozone.h"
11 12
12 namespace content { 13 namespace content {
13 namespace { 14 namespace {
14 15
15 void GetSupportedConfigurations( 16 void GetSupportedConfigurations(
16 std::vector<GpuMemoryBufferFactory::Configuration>* configurations) { 17 std::vector<GpuMemoryBufferFactory::Configuration>* configurations) {
17 std::vector<ui::ClientNativePixmapFactory::Configuration> 18 std::vector<ui::ClientNativePixmapFactory::Configuration>
18 native_pixmap_configurations = 19 native_pixmap_configurations =
19 ui::ClientNativePixmapFactory::GetInstance() 20 ui::ClientNativePixmapFactory::GetInstance()
20 ->GetSupportedConfigurations(); 21 ->GetSupportedConfigurations();
21 for (auto& native_pixmap_configuration : native_pixmap_configurations) { 22 for (auto& native_pixmap_configuration : native_pixmap_configurations) {
22 configurations->push_back({native_pixmap_configuration.format, 23 configurations->push_back({native_pixmap_configuration.format,
23 native_pixmap_configuration.usage}); 24 native_pixmap_configuration.usage});
24 } 25 }
25 } 26 }
26 27
28 bool ShareToClientProcess(int fd, base::FileDescriptor* new_handle) {
29 int duped_handle = HANDLE_EINTR(dup(fd));
30 if (duped_handle < 0) {
31 DPLOG(ERROR) << "dup() failed.";
32 *new_handle = base::FileDescriptor();
33 return false;
34 }
35
36 *new_handle = base::FileDescriptor(duped_handle, true);
37 return true;
38 }
39
27 } // namespace 40 } // namespace
28 41
29 GpuMemoryBufferFactoryOzoneNativePixmap:: 42 GpuMemoryBufferFactoryOzoneNativePixmap::
30 GpuMemoryBufferFactoryOzoneNativePixmap() {} 43 GpuMemoryBufferFactoryOzoneNativePixmap() {}
31 44
32 GpuMemoryBufferFactoryOzoneNativePixmap:: 45 GpuMemoryBufferFactoryOzoneNativePixmap::
33 ~GpuMemoryBufferFactoryOzoneNativePixmap() {} 46 ~GpuMemoryBufferFactoryOzoneNativePixmap() {}
34 47
35 // static 48 // static
36 bool GpuMemoryBufferFactoryOzoneNativePixmap:: 49 bool GpuMemoryBufferFactoryOzoneNativePixmap::
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 } 85 }
73 base::AutoLock lock(native_pixmaps_lock_); 86 base::AutoLock lock(native_pixmaps_lock_);
74 NativePixmapMapKey key(id, client_id); 87 NativePixmapMapKey key(id, client_id);
75 DCHECK(native_pixmaps_.find(key) == native_pixmaps_.end()) 88 DCHECK(native_pixmaps_.find(key) == native_pixmaps_.end())
76 << "pixmap with this key must not exist"; 89 << "pixmap with this key must not exist";
77 native_pixmaps_[key] = pixmap; 90 native_pixmaps_[key] = pixmap;
78 91
79 gfx::GpuMemoryBufferHandle handle; 92 gfx::GpuMemoryBufferHandle handle;
80 handle.type = gfx::OZONE_NATIVE_PIXMAP; 93 handle.type = gfx::OZONE_NATIVE_PIXMAP;
81 handle.id = id; 94 handle.id = id;
95 if (usage == gfx::BufferUsage::MAP) {
96 base::FileDescriptor dma_buf;
97 if (!ShareToClientProcess(pixmap->GetDmaBufFd(), &dma_buf)) {
98 DLOG(ERROR) << "Fail to duplicate a DMA-BUF file descriptor";
99 return gfx::GpuMemoryBufferHandle();
100 }
101 handle.handle = dma_buf;
102 }
82 return handle; 103 return handle;
83 } 104 }
84 105
85 void GpuMemoryBufferFactoryOzoneNativePixmap::DestroyGpuMemoryBuffer( 106 void GpuMemoryBufferFactoryOzoneNativePixmap::DestroyGpuMemoryBuffer(
86 gfx::GpuMemoryBufferId id, 107 gfx::GpuMemoryBufferId id,
87 int client_id) { 108 int client_id) {
88 base::AutoLock lock(native_pixmaps_lock_); 109 base::AutoLock lock(native_pixmaps_lock_);
89 auto it = native_pixmaps_.find(NativePixmapMapKey(id, client_id)); 110 auto it = native_pixmaps_.find(NativePixmapMapKey(id, client_id));
90 DCHECK(it != native_pixmaps_.end()) << "pixmap with this key must exist"; 111 DCHECK(it != native_pixmaps_.end()) << "pixmap with this key must exist";
91 native_pixmaps_.erase(it); 112 native_pixmaps_.erase(it);
(...skipping 25 matching lines...) Expand all
117 scoped_refptr<gfx::GLImageOzoneNativePixmap> image( 138 scoped_refptr<gfx::GLImageOzoneNativePixmap> image(
118 new gfx::GLImageOzoneNativePixmap(size, internalformat)); 139 new gfx::GLImageOzoneNativePixmap(size, internalformat));
119 if (!image->Initialize(pixmap.get(), format)) { 140 if (!image->Initialize(pixmap.get(), format)) {
120 LOG(ERROR) << "Failed to create GLImage"; 141 LOG(ERROR) << "Failed to create GLImage";
121 return nullptr; 142 return nullptr;
122 } 143 }
123 return image; 144 return image;
124 } 145 }
125 146
126 } // namespace content 147 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698