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

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

Issue 2768343002: Change namespace from ui to gfx for NativePixmap related code (Closed)
Patch Set: Addressed sadrul's remark Created 3 years, 9 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_ozone_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/native_pixmap.h" 12 #include "ui/gfx/native_pixmap.h"
13 #include "ui/ozone/public/client_native_pixmap_factory_ozone.h" 13 #include "ui/ozone/public/client_native_pixmap_factory_ozone.h"
14 #include "ui/ozone/public/ozone_platform.h" 14 #include "ui/ozone/public/ozone_platform.h"
15 #include "ui/ozone/public/surface_factory_ozone.h" 15 #include "ui/ozone/public/surface_factory_ozone.h"
16 16
17 namespace gpu { 17 namespace gpu {
18 namespace { 18 namespace {
19 19
20 void FreeNativePixmapForTesting(scoped_refptr<ui::NativePixmap> native_pixmap) { 20 void FreeNativePixmapForTesting(
21 scoped_refptr<gfx::NativePixmap> native_pixmap) {
21 // Nothing to do here. |native_pixmap| will be freed when this function 22 // Nothing to do here. |native_pixmap| will be freed when this function
22 // returns and reference count drops to 0. 23 // returns and reference count drops to 0.
23 } 24 }
24 25
25 } // namespace 26 } // namespace
26 27
27 GpuMemoryBufferImplOzoneNativePixmap::GpuMemoryBufferImplOzoneNativePixmap( 28 GpuMemoryBufferImplOzoneNativePixmap::GpuMemoryBufferImplOzoneNativePixmap(
28 gfx::GpuMemoryBufferId id, 29 gfx::GpuMemoryBufferId id,
29 const gfx::Size& size, 30 const gfx::Size& size,
30 gfx::BufferFormat format, 31 gfx::BufferFormat format,
31 const DestructionCallback& callback, 32 const DestructionCallback& callback,
32 std::unique_ptr<ui::ClientNativePixmap> pixmap, 33 std::unique_ptr<gfx::ClientNativePixmap> pixmap,
33 const std::vector<gfx::NativePixmapPlane>& planes, 34 const std::vector<gfx::NativePixmapPlane>& planes,
34 base::ScopedFD fd) 35 base::ScopedFD fd)
35 : GpuMemoryBufferImpl(id, size, format, callback), 36 : GpuMemoryBufferImpl(id, size, format, callback),
36 pixmap_(std::move(pixmap)), 37 pixmap_(std::move(pixmap)),
37 planes_(planes), 38 planes_(planes),
38 fd_(std::move(fd)) {} 39 fd_(std::move(fd)) {}
39 40
40 GpuMemoryBufferImplOzoneNativePixmap::~GpuMemoryBufferImplOzoneNativePixmap() {} 41 GpuMemoryBufferImplOzoneNativePixmap::~GpuMemoryBufferImplOzoneNativePixmap() {}
41 42
42 // static 43 // static
43 std::unique_ptr<GpuMemoryBufferImplOzoneNativePixmap> 44 std::unique_ptr<GpuMemoryBufferImplOzoneNativePixmap>
44 GpuMemoryBufferImplOzoneNativePixmap::CreateFromHandle( 45 GpuMemoryBufferImplOzoneNativePixmap::CreateFromHandle(
45 const gfx::GpuMemoryBufferHandle& handle, 46 const gfx::GpuMemoryBufferHandle& handle,
46 const gfx::Size& size, 47 const gfx::Size& size,
47 gfx::BufferFormat format, 48 gfx::BufferFormat format,
48 gfx::BufferUsage usage, 49 gfx::BufferUsage usage,
49 const DestructionCallback& callback) { 50 const DestructionCallback& callback) {
50
51 // GpuMemoryBufferImpl needs the FD to implement GetHandle() but 51 // GpuMemoryBufferImpl needs the FD to implement GetHandle() but
52 // ui::ClientNativePixmapFactory::ImportFromHandle is expected to take 52 // gfx::ClientNativePixmapFactory::ImportFromHandle is expected to take
53 // ownership of the FD passed in the handle so we have to dup it here in 53 // 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. 54 // order to pass a valid FD to the GpuMemoryBufferImpl ctor.
55 base::ScopedFD scoped_fd; 55 base::ScopedFD scoped_fd;
56 if (!handle.native_pixmap_handle.fds.empty()) { 56 if (!handle.native_pixmap_handle.fds.empty()) {
57 scoped_fd.reset(HANDLE_EINTR(dup(handle.native_pixmap_handle.fds[0].fd))); 57 scoped_fd.reset(HANDLE_EINTR(dup(handle.native_pixmap_handle.fds[0].fd)));
58 if (!scoped_fd.is_valid()) { 58 if (!scoped_fd.is_valid()) {
59 PLOG(ERROR) << "dup"; 59 PLOG(ERROR) << "dup";
60 return nullptr; 60 return nullptr;
61 } 61 }
62 } 62 }
63 63
64 gfx::NativePixmapHandle native_pixmap_handle; 64 gfx::NativePixmapHandle native_pixmap_handle;
65 if (scoped_fd.is_valid()) { 65 if (scoped_fd.is_valid()) {
66 native_pixmap_handle.fds.emplace_back(handle.native_pixmap_handle.fds[0].fd, 66 native_pixmap_handle.fds.emplace_back(handle.native_pixmap_handle.fds[0].fd,
67 true /* auto_close */); 67 true /* auto_close */);
68 } 68 }
69 native_pixmap_handle.planes = handle.native_pixmap_handle.planes; 69 native_pixmap_handle.planes = handle.native_pixmap_handle.planes;
70 std::unique_ptr<ui::ClientNativePixmap> native_pixmap = 70 std::unique_ptr<gfx::ClientNativePixmap> native_pixmap =
71 ui::ClientNativePixmapFactory::GetInstance()->ImportFromHandle( 71 gfx::ClientNativePixmapFactory::GetInstance()->ImportFromHandle(
72 native_pixmap_handle, size, usage); 72 native_pixmap_handle, size, usage);
73 DCHECK(native_pixmap); 73 DCHECK(native_pixmap);
74 74
75 return base::WrapUnique(new GpuMemoryBufferImplOzoneNativePixmap( 75 return base::WrapUnique(new GpuMemoryBufferImplOzoneNativePixmap(
76 handle.id, size, format, callback, std::move(native_pixmap), 76 handle.id, size, format, callback, std::move(native_pixmap),
77 handle.native_pixmap_handle.planes, std::move(scoped_fd))); 77 handle.native_pixmap_handle.planes, std::move(scoped_fd)));
78 } 78 }
79 79
80 // static 80 // static
81 bool GpuMemoryBufferImplOzoneNativePixmap::IsConfigurationSupported( 81 bool GpuMemoryBufferImplOzoneNativePixmap::IsConfigurationSupported(
82 gfx::BufferFormat format, 82 gfx::BufferFormat format,
83 gfx::BufferUsage usage) { 83 gfx::BufferUsage usage) {
84 return gpu::IsNativeGpuMemoryBufferConfigurationSupported(format, usage); 84 return gpu::IsNativeGpuMemoryBufferConfigurationSupported(format, usage);
85 } 85 }
86 86
87 // static 87 // static
88 base::Closure GpuMemoryBufferImplOzoneNativePixmap::AllocateForTesting( 88 base::Closure GpuMemoryBufferImplOzoneNativePixmap::AllocateForTesting(
89 const gfx::Size& size, 89 const gfx::Size& size,
90 gfx::BufferFormat format, 90 gfx::BufferFormat format,
91 gfx::BufferUsage usage, 91 gfx::BufferUsage usage,
92 gfx::GpuMemoryBufferHandle* handle) { 92 gfx::GpuMemoryBufferHandle* handle) {
93 DCHECK(IsConfigurationSupported(format, usage)); 93 DCHECK(IsConfigurationSupported(format, usage));
94 scoped_refptr<ui::NativePixmap> pixmap = 94 scoped_refptr<gfx::NativePixmap> pixmap =
95 ui::OzonePlatform::GetInstance() 95 ui::OzonePlatform::GetInstance()
96 ->GetSurfaceFactoryOzone() 96 ->GetSurfaceFactoryOzone()
97 ->CreateNativePixmap(gfx::kNullAcceleratedWidget, size, format, 97 ->CreateNativePixmap(gfx::kNullAcceleratedWidget, size, format,
98 usage); 98 usage);
99 handle->type = gfx::NATIVE_PIXMAP; 99 handle->type = gfx::NATIVE_PIXMAP;
100 handle->native_pixmap_handle = pixmap->ExportHandle(); 100 handle->native_pixmap_handle = pixmap->ExportHandle();
101 return base::Bind(&FreeNativePixmapForTesting, pixmap); 101 return base::Bind(&FreeNativePixmapForTesting, pixmap);
102 } 102 }
103 103
104 bool GpuMemoryBufferImplOzoneNativePixmap::Map() { 104 bool GpuMemoryBufferImplOzoneNativePixmap::Map() {
(...skipping 25 matching lines...) Expand all
130 handle.id = id_; 130 handle.id = id_;
131 if (fd_.is_valid()) { 131 if (fd_.is_valid()) {
132 handle.native_pixmap_handle.fds.emplace_back(fd_.get(), 132 handle.native_pixmap_handle.fds.emplace_back(fd_.get(),
133 false /* auto_close */); 133 false /* auto_close */);
134 } 134 }
135 handle.native_pixmap_handle.planes = planes_; 135 handle.native_pixmap_handle.planes = planes_;
136 return handle; 136 return handle;
137 } 137 }
138 138
139 } // namespace gpu 139 } // namespace gpu
OLDNEW
« no previous file with comments | « gpu/ipc/client/gpu_memory_buffer_impl_ozone_native_pixmap.h ('k') | gpu/ipc/common/gpu_memory_buffer_support.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698