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 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 case gfx::BufferUsage::GPU_READ_CPU_READ_WRITE_PERSISTENT: | 106 case gfx::BufferUsage::GPU_READ_CPU_READ_WRITE_PERSISTENT: |
107 flags = GBM_BO_USE_LINEAR; | 107 flags = GBM_BO_USE_LINEAR; |
108 break; | 108 break; |
109 } | 109 } |
110 | 110 |
111 gbm_bo* bo = gbm_bo_create(gbm->device(), size.width(), size.height(), | 111 gbm_bo* bo = gbm_bo_create(gbm->device(), size.width(), size.height(), |
112 GetFourCCFormatFromBufferFormat(format), flags); | 112 GetFourCCFormatFromBufferFormat(format), flags); |
113 if (!bo) | 113 if (!bo) |
114 return nullptr; | 114 return nullptr; |
115 | 115 |
116 // The fd returned by gbm_bo_get_fd is not ref-counted and need to be | 116 std::vector<base::ScopedFD> fds; |
117 // kept open for the lifetime of the buffer. | 117 std::vector<gfx::NativePixmapPlane> planes; |
118 base::ScopedFD fd(gbm_bo_get_fd(bo)); | 118 |
119 if (!fd.is_valid()) { | 119 DCHECK_EQ(gbm_bo_get_num_planes(bo), |
120 PLOG(ERROR) << "Failed to export buffer to dma_buf"; | 120 gfx::NumberOfPlanesForBufferFormat(format)); |
121 gbm_bo_destroy(bo); | 121 for (size_t i = 0; i < gfx::NumberOfPlanesForBufferFormat(format); ++i) { |
122 return nullptr; | 122 // The fd returned by gbm_bo_get_fd is not ref-counted and need to be |
| 123 // kept open for the lifetime of the buffer. |
| 124 base::ScopedFD fd(gbm_bo_get_plane_fd(bo, i)); |
| 125 |
| 126 if (!fd.is_valid()) { |
| 127 PLOG(ERROR) << "Failed to export buffer to dma_buf"; |
| 128 gbm_bo_destroy(bo); |
| 129 return nullptr; |
| 130 } |
| 131 fds.emplace_back(std::move(fd)); |
| 132 |
| 133 planes.emplace_back(gbm_bo_get_plane_stride(bo, i), |
| 134 gbm_bo_get_plane_offset(bo, i), |
| 135 gbm_bo_get_plane_format_modifier(bo, i)); |
123 } | 136 } |
124 std::vector<base::ScopedFD> fds; | |
125 fds.emplace_back(std::move(fd)); | |
126 std::vector<gfx::NativePixmapPlane> planes; | |
127 planes.emplace_back(gbm_bo_get_stride(bo), gbm_bo_get_plane_offset(bo, 0), | |
128 gbm_bo_get_format_modifier(bo)); | |
129 scoped_refptr<GbmBuffer> buffer(new GbmBuffer( | 137 scoped_refptr<GbmBuffer> buffer(new GbmBuffer( |
130 gbm, bo, format, usage, std::move(fds), size, std::move(planes))); | 138 gbm, bo, format, usage, std::move(fds), size, std::move(planes))); |
131 if (usage == gfx::BufferUsage::SCANOUT && !buffer->GetFramebufferId()) | 139 if (usage == gfx::BufferUsage::SCANOUT && !buffer->GetFramebufferId()) |
132 return nullptr; | 140 return nullptr; |
133 | 141 |
134 return buffer; | 142 return buffer; |
135 } | 143 } |
136 | 144 |
137 // static | 145 // static |
138 scoped_refptr<GbmBuffer> GbmBuffer::CreateBufferFromFds( | 146 scoped_refptr<GbmBuffer> GbmBuffer::CreateBufferFromFds( |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
294 DCHECK(!processing_callback_.is_null()); | 302 DCHECK(!processing_callback_.is_null()); |
295 if (!processing_callback_.Run(this, processed_pixmap_)) { | 303 if (!processing_callback_.Run(this, processed_pixmap_)) { |
296 LOG(ERROR) << "Failed processing NativePixmap"; | 304 LOG(ERROR) << "Failed processing NativePixmap"; |
297 return nullptr; | 305 return nullptr; |
298 } | 306 } |
299 | 307 |
300 return processed_pixmap_->buffer(); | 308 return processed_pixmap_->buffer(); |
301 } | 309 } |
302 | 310 |
303 } // namespace ui | 311 } // namespace ui |
OLD | NEW |