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

Side by Side Diff: gpu/ipc/client/gpu_memory_buffer_impl_native_pixmap.cc

Issue 2710223002: Rename GpuMemoryBufferImplOzoneNativePixmap to GpuMemoryBufferImplNativePixmap (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/client/gpu_memory_buffer_impl_ozone_native_pixmap.h" 5 #include "gpu/ipc/client/gpu_memory_buffer_impl_native_pixmap.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
10 #include "gpu/ipc/common/gpu_memory_buffer_support.h" 10 #include "gpu/ipc/common/gpu_memory_buffer_support.h"
11 #include "ui/gfx/buffer_format_util.h" 11 #include "ui/gfx/buffer_format_util.h"
12 #include "ui/gfx/client_native_pixmap_factory.h"
12 #include "ui/gfx/native_pixmap.h" 13 #include "ui/gfx/native_pixmap.h"
13 #include "ui/ozone/public/client_native_pixmap_factory_ozone.h" 14
15 #if defined(USE_OZONE)
14 #include "ui/ozone/public/ozone_platform.h" 16 #include "ui/ozone/public/ozone_platform.h"
15 #include "ui/ozone/public/surface_factory_ozone.h" 17 #include "ui/ozone/public/surface_factory_ozone.h"
18 #endif
16 19
17 namespace gpu { 20 namespace gpu {
18 namespace { 21 namespace {
19 22
20 void FreeNativePixmapForTesting( 23 void FreeNativePixmapForTesting(
21 scoped_refptr<gfx::NativePixmap> native_pixmap) { 24 scoped_refptr<gfx::NativePixmap> native_pixmap) {
22 // Nothing to do here. |native_pixmap| will be freed when this function 25 // Nothing to do here. |native_pixmap| will be freed when this function
23 // returns and reference count drops to 0. 26 // returns and reference count drops to 0.
24 } 27 }
25 28
26 } // namespace 29 } // namespace
27 30
28 GpuMemoryBufferImplOzoneNativePixmap::GpuMemoryBufferImplOzoneNativePixmap( 31 GpuMemoryBufferImplNativePixmap::GpuMemoryBufferImplNativePixmap(
29 gfx::GpuMemoryBufferId id, 32 gfx::GpuMemoryBufferId id,
30 const gfx::Size& size, 33 const gfx::Size& size,
31 gfx::BufferFormat format, 34 gfx::BufferFormat format,
32 const DestructionCallback& callback, 35 const DestructionCallback& callback,
33 std::unique_ptr<gfx::ClientNativePixmap> pixmap, 36 std::unique_ptr<gfx::ClientNativePixmap> pixmap,
34 const std::vector<gfx::NativePixmapPlane>& planes, 37 const std::vector<gfx::NativePixmapPlane>& planes,
35 base::ScopedFD fd) 38 base::ScopedFD fd)
36 : GpuMemoryBufferImpl(id, size, format, callback), 39 : GpuMemoryBufferImpl(id, size, format, callback),
37 pixmap_(std::move(pixmap)), 40 pixmap_(std::move(pixmap)),
38 planes_(planes), 41 planes_(planes),
39 fd_(std::move(fd)) {} 42 fd_(std::move(fd)) {}
40 43
41 GpuMemoryBufferImplOzoneNativePixmap::~GpuMemoryBufferImplOzoneNativePixmap() {} 44 GpuMemoryBufferImplNativePixmap::~GpuMemoryBufferImplNativePixmap() {}
42 45
43 // static 46 // static
44 std::unique_ptr<GpuMemoryBufferImplOzoneNativePixmap> 47 std::unique_ptr<GpuMemoryBufferImplNativePixmap>
45 GpuMemoryBufferImplOzoneNativePixmap::CreateFromHandle( 48 GpuMemoryBufferImplNativePixmap::CreateFromHandle(
46 const gfx::GpuMemoryBufferHandle& handle, 49 const gfx::GpuMemoryBufferHandle& handle,
47 const gfx::Size& size, 50 const gfx::Size& size,
48 gfx::BufferFormat format, 51 gfx::BufferFormat format,
49 gfx::BufferUsage usage, 52 gfx::BufferUsage usage,
50 const DestructionCallback& callback) { 53 const DestructionCallback& callback) {
51 // GpuMemoryBufferImpl needs the FD to implement GetHandle() but 54 // GpuMemoryBufferImpl needs the FD to implement GetHandle() but
52 // gfx::ClientNativePixmapFactory::ImportFromHandle is expected to take 55 // gfx::ClientNativePixmapFactory::ImportFromHandle is expected to take
53 // ownership of the FD passed in the handle so we have to dup it here in 56 // ownership of the FD passed in the handle so we have to dup it here in
54 // order to pass a valid FD to the GpuMemoryBufferImpl ctor. 57 // order to pass a valid FD to the GpuMemoryBufferImpl ctor.
55 base::ScopedFD scoped_fd; 58 base::ScopedFD scoped_fd;
56 if (!handle.native_pixmap_handle.fds.empty()) { 59 if (!handle.native_pixmap_handle.fds.empty()) {
57 scoped_fd.reset(HANDLE_EINTR(dup(handle.native_pixmap_handle.fds[0].fd))); 60 scoped_fd.reset(HANDLE_EINTR(dup(handle.native_pixmap_handle.fds[0].fd)));
58 if (!scoped_fd.is_valid()) { 61 if (!scoped_fd.is_valid()) {
59 PLOG(ERROR) << "dup"; 62 PLOG(ERROR) << "dup";
60 return nullptr; 63 return nullptr;
61 } 64 }
62 } 65 }
63 66
64 gfx::NativePixmapHandle native_pixmap_handle; 67 gfx::NativePixmapHandle native_pixmap_handle;
65 if (scoped_fd.is_valid()) { 68 if (scoped_fd.is_valid()) {
66 native_pixmap_handle.fds.emplace_back(handle.native_pixmap_handle.fds[0].fd, 69 native_pixmap_handle.fds.emplace_back(handle.native_pixmap_handle.fds[0].fd,
67 true /* auto_close */); 70 true /* auto_close */);
68 } 71 }
69 native_pixmap_handle.planes = handle.native_pixmap_handle.planes; 72 native_pixmap_handle.planes = handle.native_pixmap_handle.planes;
70 std::unique_ptr<gfx::ClientNativePixmap> native_pixmap = 73 std::unique_ptr<gfx::ClientNativePixmap> native_pixmap =
71 gfx::ClientNativePixmapFactory::GetInstance()->ImportFromHandle( 74 gfx::ClientNativePixmapFactory::GetInstance()->ImportFromHandle(
72 native_pixmap_handle, size, usage); 75 native_pixmap_handle, size, usage);
73 DCHECK(native_pixmap); 76 DCHECK(native_pixmap);
74 77
75 return base::WrapUnique(new GpuMemoryBufferImplOzoneNativePixmap( 78 return base::WrapUnique(new GpuMemoryBufferImplNativePixmap(
76 handle.id, size, format, callback, std::move(native_pixmap), 79 handle.id, size, format, callback, std::move(native_pixmap),
77 handle.native_pixmap_handle.planes, std::move(scoped_fd))); 80 handle.native_pixmap_handle.planes, std::move(scoped_fd)));
78 } 81 }
79 82
80 // static 83 // static
81 bool GpuMemoryBufferImplOzoneNativePixmap::IsConfigurationSupported( 84 bool GpuMemoryBufferImplNativePixmap::IsConfigurationSupported(
82 gfx::BufferFormat format, 85 gfx::BufferFormat format,
83 gfx::BufferUsage usage) { 86 gfx::BufferUsage usage) {
87 #if defined(OS_LINUX)
88 return false;
89 #endif
84 return gpu::IsNativeGpuMemoryBufferConfigurationSupported(format, usage); 90 return gpu::IsNativeGpuMemoryBufferConfigurationSupported(format, usage);
85 } 91 }
86 92
87 // static 93 // static
88 base::Closure GpuMemoryBufferImplOzoneNativePixmap::AllocateForTesting( 94 base::Closure GpuMemoryBufferImplNativePixmap::AllocateForTesting(
89 const gfx::Size& size, 95 const gfx::Size& size,
90 gfx::BufferFormat format, 96 gfx::BufferFormat format,
91 gfx::BufferUsage usage, 97 gfx::BufferUsage usage,
92 gfx::GpuMemoryBufferHandle* handle) { 98 gfx::GpuMemoryBufferHandle* handle) {
93 DCHECK(IsConfigurationSupported(format, usage)); 99 DCHECK(IsConfigurationSupported(format, usage));
100 #if defined(USE_OZONE)
94 scoped_refptr<gfx::NativePixmap> pixmap = 101 scoped_refptr<gfx::NativePixmap> pixmap =
95 ui::OzonePlatform::GetInstance() 102 ui::OzonePlatform::GetInstance()
96 ->GetSurfaceFactoryOzone() 103 ->GetSurfaceFactoryOzone()
97 ->CreateNativePixmap(gfx::kNullAcceleratedWidget, size, format, 104 ->CreateNativePixmap(gfx::kNullAcceleratedWidget, size, format,
98 usage); 105 usage);
106 handle->native_pixmap_handle = pixmap->ExportHandle();
107 #else
108 // TODO(j.isorce): use gbm_bo_create / gbm_bo_get_fd from system libgbm.
109 scoped_refptr<gfx::NativePixmap> pixmap;
110 NOTIMPLEMENTED();
111 #endif
99 handle->type = gfx::NATIVE_PIXMAP; 112 handle->type = gfx::NATIVE_PIXMAP;
100 handle->native_pixmap_handle = pixmap->ExportHandle();
101 return base::Bind(&FreeNativePixmapForTesting, pixmap); 113 return base::Bind(&FreeNativePixmapForTesting, pixmap);
102 } 114 }
103 115
104 bool GpuMemoryBufferImplOzoneNativePixmap::Map() { 116 bool GpuMemoryBufferImplNativePixmap::Map() {
105 DCHECK(!mapped_); 117 DCHECK(!mapped_);
106 mapped_ = pixmap_->Map(); 118 mapped_ = pixmap_->Map();
107 return mapped_; 119 return mapped_;
108 } 120 }
109 121
110 void* GpuMemoryBufferImplOzoneNativePixmap::memory(size_t plane) { 122 void* GpuMemoryBufferImplNativePixmap::memory(size_t plane) {
111 DCHECK(mapped_); 123 DCHECK(mapped_);
112 return pixmap_->GetMemoryAddress(plane); 124 return pixmap_->GetMemoryAddress(plane);
113 } 125 }
114 126
115 void GpuMemoryBufferImplOzoneNativePixmap::Unmap() { 127 void GpuMemoryBufferImplNativePixmap::Unmap() {
116 DCHECK(mapped_); 128 DCHECK(mapped_);
117 pixmap_->Unmap(); 129 pixmap_->Unmap();
118 mapped_ = false; 130 mapped_ = false;
119 } 131 }
120 132
121 int GpuMemoryBufferImplOzoneNativePixmap::stride(size_t plane) const { 133 int GpuMemoryBufferImplNativePixmap::stride(size_t plane) const {
122 DCHECK_LT(plane, gfx::NumberOfPlanesForBufferFormat(format_)); 134 DCHECK_LT(plane, gfx::NumberOfPlanesForBufferFormat(format_));
123 return pixmap_->GetStride(plane); 135 return pixmap_->GetStride(plane);
124 } 136 }
125 137
126 gfx::GpuMemoryBufferHandle GpuMemoryBufferImplOzoneNativePixmap::GetHandle() 138 gfx::GpuMemoryBufferHandle GpuMemoryBufferImplNativePixmap::GetHandle() const {
127 const {
128 gfx::GpuMemoryBufferHandle handle; 139 gfx::GpuMemoryBufferHandle handle;
129 handle.type = gfx::NATIVE_PIXMAP; 140 handle.type = gfx::NATIVE_PIXMAP;
130 handle.id = id_; 141 handle.id = id_;
131 if (fd_.is_valid()) { 142 if (fd_.is_valid()) {
132 handle.native_pixmap_handle.fds.emplace_back(fd_.get(), 143 handle.native_pixmap_handle.fds.emplace_back(fd_.get(),
133 false /* auto_close */); 144 false /* auto_close */);
134 } 145 }
135 handle.native_pixmap_handle.planes = planes_; 146 handle.native_pixmap_handle.planes = planes_;
136 return handle; 147 return handle;
137 } 148 }
138 149
139 } // namespace gpu 150 } // namespace gpu
OLDNEW
« no previous file with comments | « gpu/ipc/client/gpu_memory_buffer_impl_native_pixmap.h ('k') | gpu/ipc/client/gpu_memory_buffer_impl_native_pixmap_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698