OLD | NEW |
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 "ui/ozone/platform/drm/gpu/gbm_buffer.h" | 5 #include "ui/ozone/platform/drm/gpu/gbm_buffer.h" |
6 | 6 |
7 #include <drm.h> | 7 #include <drm.h> |
8 #include <fcntl.h> | 8 #include <fcntl.h> |
9 #include <gbm.h> | 9 #include <gbm.h> |
10 #include <xf86drm.h> | 10 #include <xf86drm.h> |
(...skipping 14 matching lines...) Expand all Loading... |
25 #include "ui/ozone/public/surface_factory_ozone.h" | 25 #include "ui/ozone/public/surface_factory_ozone.h" |
26 | 26 |
27 namespace ui { | 27 namespace ui { |
28 | 28 |
29 GbmBuffer::GbmBuffer(const scoped_refptr<GbmDevice>& gbm, | 29 GbmBuffer::GbmBuffer(const scoped_refptr<GbmDevice>& gbm, |
30 gbm_bo* bo, | 30 gbm_bo* bo, |
31 gfx::BufferFormat format, | 31 gfx::BufferFormat format, |
32 gfx::BufferUsage usage, | 32 gfx::BufferUsage usage, |
33 std::vector<base::ScopedFD>&& fds, | 33 std::vector<base::ScopedFD>&& fds, |
34 const gfx::Size& size, | 34 const gfx::Size& size, |
35 const std::vector<int>& strides) | 35 const std::vector<int>& strides, |
| 36 const std::vector<uint64_t>& modifiers) |
36 : GbmBufferBase(gbm, bo, format, usage), | 37 : GbmBufferBase(gbm, bo, format, usage), |
37 format_(format), | 38 format_(format), |
38 usage_(usage), | 39 usage_(usage), |
39 fds_(std::move(fds)), | 40 fds_(std::move(fds)), |
40 size_(size), | 41 size_(size), |
41 strides_(strides) {} | 42 strides_(strides), |
| 43 modifiers_(modifiers) {} |
42 | 44 |
43 GbmBuffer::~GbmBuffer() { | 45 GbmBuffer::~GbmBuffer() { |
44 if (bo()) | 46 if (bo()) |
45 gbm_bo_destroy(bo()); | 47 gbm_bo_destroy(bo()); |
46 } | 48 } |
47 | 49 |
48 bool GbmBuffer::AreFdsValid() const { | 50 bool GbmBuffer::AreFdsValid() const { |
49 if (fds_.empty()) | 51 if (fds_.empty()) |
50 return false; | 52 return false; |
51 | 53 |
52 for (const auto& fd : fds_) { | 54 for (const auto& fd : fds_) { |
53 if (fd.get() == -1) | 55 if (fd.get() == -1) |
54 return false; | 56 return false; |
55 } | 57 } |
56 return true; | 58 return true; |
57 } | 59 } |
58 | 60 |
59 int GbmBuffer::GetFd(size_t plane) const { | 61 int GbmBuffer::GetFd(size_t plane) const { |
60 DCHECK_LT(plane, fds_.size()); | 62 DCHECK_LT(plane, fds_.size()); |
61 return fds_[plane].get(); | 63 return fds_[plane].get(); |
62 } | 64 } |
63 | 65 |
64 int GbmBuffer::GetStride(size_t plane) const { | 66 int GbmBuffer::GetStride(size_t plane) const { |
65 DCHECK_LT(plane, strides_.size()); | 67 DCHECK_LT(plane, strides_.size()); |
66 return strides_[plane]; | 68 return strides_[plane]; |
67 } | 69 } |
68 | 70 |
| 71 uint64_t GbmBuffer::GetFormatModifier(size_t plane) const { |
| 72 DCHECK_LT(plane, modifiers_.size()); |
| 73 return modifiers_[plane]; |
| 74 } |
| 75 |
69 // TODO(reveman): This should not be needed once crbug.com/597932 is fixed, | 76 // TODO(reveman): This should not be needed once crbug.com/597932 is fixed, |
70 // as the size would be queried directly from the underlying bo. | 77 // as the size would be queried directly from the underlying bo. |
71 gfx::Size GbmBuffer::GetSize() const { | 78 gfx::Size GbmBuffer::GetSize() const { |
72 return size_; | 79 return size_; |
73 } | 80 } |
74 | 81 |
75 // static | 82 // static |
76 scoped_refptr<GbmBuffer> GbmBuffer::CreateBuffer( | 83 scoped_refptr<GbmBuffer> GbmBuffer::CreateBuffer( |
77 const scoped_refptr<GbmDevice>& gbm, | 84 const scoped_refptr<GbmDevice>& gbm, |
78 gfx::BufferFormat format, | 85 gfx::BufferFormat format, |
(...skipping 25 matching lines...) Expand all Loading... |
104 base::ScopedFD fd(gbm_bo_get_fd(bo)); | 111 base::ScopedFD fd(gbm_bo_get_fd(bo)); |
105 if (!fd.is_valid()) { | 112 if (!fd.is_valid()) { |
106 PLOG(ERROR) << "Failed to export buffer to dma_buf"; | 113 PLOG(ERROR) << "Failed to export buffer to dma_buf"; |
107 gbm_bo_destroy(bo); | 114 gbm_bo_destroy(bo); |
108 return nullptr; | 115 return nullptr; |
109 } | 116 } |
110 std::vector<base::ScopedFD> fds; | 117 std::vector<base::ScopedFD> fds; |
111 fds.emplace_back(std::move(fd)); | 118 fds.emplace_back(std::move(fd)); |
112 std::vector<int> strides; | 119 std::vector<int> strides; |
113 strides.push_back(gbm_bo_get_stride(bo)); | 120 strides.push_back(gbm_bo_get_stride(bo)); |
114 scoped_refptr<GbmBuffer> buffer( | 121 std::vector<uint64_t> modifiers; |
115 new GbmBuffer(gbm, bo, format, usage, std::move(fds), size, strides)); | 122 modifiers.push_back(gbm_bo_get_format_modifier(bo)); |
| 123 scoped_refptr<GbmBuffer> buffer(new GbmBuffer( |
| 124 gbm, bo, format, usage, std::move(fds), size, strides, modifiers)); |
116 if (usage == gfx::BufferUsage::SCANOUT && !buffer->GetFramebufferId()) | 125 if (usage == gfx::BufferUsage::SCANOUT && !buffer->GetFramebufferId()) |
117 return nullptr; | 126 return nullptr; |
118 | 127 |
119 return buffer; | 128 return buffer; |
120 } | 129 } |
121 | 130 |
122 // static | 131 // static |
123 scoped_refptr<GbmBuffer> GbmBuffer::CreateBufferFromFds( | 132 scoped_refptr<GbmBuffer> GbmBuffer::CreateBufferFromFds( |
124 const scoped_refptr<GbmDevice>& gbm, | 133 const scoped_refptr<GbmDevice>& gbm, |
125 gfx::BufferFormat format, | 134 gfx::BufferFormat format, |
126 const gfx::Size& size, | 135 const gfx::Size& size, |
127 std::vector<base::ScopedFD>&& fds, | 136 std::vector<base::ScopedFD>&& fds, |
128 const std::vector<int>& strides) { | 137 const std::vector<int>& strides) { |
129 TRACE_EVENT2("drm", "GbmBuffer::CreateBufferFromFD", "device", | 138 TRACE_EVENT2("drm", "GbmBuffer::CreateBufferFromFD", "device", |
130 gbm->device_path().value(), "size", size.ToString()); | 139 gbm->device_path().value(), "size", size.ToString()); |
131 DCHECK_EQ(fds.size(), strides.size()); | 140 DCHECK_EQ(fds.size(), strides.size()); |
| 141 std::vector<uint64_t> modifiers; |
132 // TODO(reveman): Use gbm_bo_import after making buffers survive | 142 // TODO(reveman): Use gbm_bo_import after making buffers survive |
133 // GPU process crashes. crbug.com/597932 | 143 // GPU process crashes. crbug.com/597932 |
134 return make_scoped_refptr(new GbmBuffer(gbm, nullptr, format, | 144 return make_scoped_refptr( |
135 gfx::BufferUsage::GPU_READ, | 145 new GbmBuffer(gbm, nullptr, format, gfx::BufferUsage::GPU_READ, |
136 std::move(fds), size, strides)); | 146 std::move(fds), size, strides, modifiers)); |
137 } | 147 } |
138 | 148 |
139 GbmPixmap::GbmPixmap(GbmSurfaceFactory* surface_manager, | 149 GbmPixmap::GbmPixmap(GbmSurfaceFactory* surface_manager, |
140 const scoped_refptr<GbmBuffer>& buffer) | 150 const scoped_refptr<GbmBuffer>& buffer) |
141 : surface_manager_(surface_manager), buffer_(buffer) {} | 151 : surface_manager_(surface_manager), buffer_(buffer) {} |
142 | 152 |
143 void GbmPixmap::SetProcessingCallback( | 153 void GbmPixmap::SetProcessingCallback( |
144 const ProcessingCallback& processing_callback) { | 154 const ProcessingCallback& processing_callback) { |
145 DCHECK(processing_callback_.is_null()); | 155 DCHECK(processing_callback_.is_null()); |
146 processing_callback_ = processing_callback; | 156 processing_callback_ = processing_callback; |
(...skipping 27 matching lines...) Expand all Loading... |
174 } | 184 } |
175 | 185 |
176 int GbmPixmap::GetDmaBufFd(size_t plane) const { | 186 int GbmPixmap::GetDmaBufFd(size_t plane) const { |
177 return buffer_->GetFd(plane); | 187 return buffer_->GetFd(plane); |
178 } | 188 } |
179 | 189 |
180 int GbmPixmap::GetDmaBufPitch(size_t plane) const { | 190 int GbmPixmap::GetDmaBufPitch(size_t plane) const { |
181 return buffer_->GetStride(plane); | 191 return buffer_->GetStride(plane); |
182 } | 192 } |
183 | 193 |
| 194 uint64_t GbmPixmap::GetDmaBufModifier(size_t plane) const { |
| 195 return buffer_->GetFormatModifier(plane); |
| 196 } |
| 197 |
184 gfx::BufferFormat GbmPixmap::GetBufferFormat() const { | 198 gfx::BufferFormat GbmPixmap::GetBufferFormat() const { |
185 return buffer_->GetFormat(); | 199 return buffer_->GetFormat(); |
186 } | 200 } |
187 | 201 |
188 gfx::Size GbmPixmap::GetBufferSize() const { | 202 gfx::Size GbmPixmap::GetBufferSize() const { |
189 return buffer_->GetSize(); | 203 return buffer_->GetSize(); |
190 } | 204 } |
191 | 205 |
192 bool GbmPixmap::ScheduleOverlayPlane(gfx::AcceleratedWidget widget, | 206 bool GbmPixmap::ScheduleOverlayPlane(gfx::AcceleratedWidget widget, |
193 int plane_z_order, | 207 int plane_z_order, |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
231 DCHECK(!processing_callback_.is_null()); | 245 DCHECK(!processing_callback_.is_null()); |
232 if (!processing_callback_.Run(this, processed_pixmap_)) { | 246 if (!processing_callback_.Run(this, processed_pixmap_)) { |
233 LOG(ERROR) << "Failed processing NativePixmap"; | 247 LOG(ERROR) << "Failed processing NativePixmap"; |
234 return nullptr; | 248 return nullptr; |
235 } | 249 } |
236 | 250 |
237 return processed_pixmap_->buffer(); | 251 return processed_pixmap_->buffer(); |
238 } | 252 } |
239 | 253 |
240 } // namespace ui | 254 } // namespace ui |
OLD | NEW |