| 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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 int GbmBuffer::GetStride(size_t index) const { | 68 int GbmBuffer::GetStride(size_t index) const { |
| 69 DCHECK_LT(index, planes_.size()); | 69 DCHECK_LT(index, planes_.size()); |
| 70 return planes_[index].stride; | 70 return planes_[index].stride; |
| 71 } | 71 } |
| 72 | 72 |
| 73 int GbmBuffer::GetOffset(size_t index) const { | 73 int GbmBuffer::GetOffset(size_t index) const { |
| 74 DCHECK_LT(index, planes_.size()); | 74 DCHECK_LT(index, planes_.size()); |
| 75 return planes_[index].offset; | 75 return planes_[index].offset; |
| 76 } | 76 } |
| 77 | 77 |
| 78 size_t GbmBuffer::GetSize(size_t index) const { | |
| 79 DCHECK_LT(index, planes_.size()); | |
| 80 return planes_[index].size; | |
| 81 } | |
| 82 | |
| 83 uint64_t GbmBuffer::GetFormatModifier(size_t index) const { | 78 uint64_t GbmBuffer::GetFormatModifier(size_t index) const { |
| 84 DCHECK_LT(index, planes_.size()); | 79 DCHECK_LT(index, planes_.size()); |
| 85 return planes_[index].modifier; | 80 return planes_[index].modifier; |
| 86 } | 81 } |
| 87 | 82 |
| 88 // TODO(reveman): This should not be needed once crbug.com/597932 is fixed, | 83 // TODO(reveman): This should not be needed once crbug.com/597932 is fixed, |
| 89 // as the size would be queried directly from the underlying bo. | 84 // as the size would be queried directly from the underlying bo. |
| 90 gfx::Size GbmBuffer::GetSize() const { | 85 gfx::Size GbmBuffer::GetSize() const { |
| 91 return size_; | 86 return size_; |
| 92 } | 87 } |
| (...skipping 28 matching lines...) Expand all Loading... |
| 121 std::vector<base::ScopedFD> fds; | 116 std::vector<base::ScopedFD> fds; |
| 122 std::vector<gfx::NativePixmapPlane> planes; | 117 std::vector<gfx::NativePixmapPlane> planes; |
| 123 | 118 |
| 124 DCHECK_EQ(gbm_bo_get_num_planes(bo), | 119 DCHECK_EQ(gbm_bo_get_num_planes(bo), |
| 125 gfx::NumberOfPlanesForBufferFormat(format)); | 120 gfx::NumberOfPlanesForBufferFormat(format)); |
| 126 for (size_t i = 0; i < gfx::NumberOfPlanesForBufferFormat(format); ++i) { | 121 for (size_t i = 0; i < gfx::NumberOfPlanesForBufferFormat(format); ++i) { |
| 127 // The fd returned by gbm_bo_get_fd is not ref-counted and need to be | 122 // The fd returned by gbm_bo_get_fd is not ref-counted and need to be |
| 128 // kept open for the lifetime of the buffer. | 123 // kept open for the lifetime of the buffer. |
| 129 base::ScopedFD fd(gbm_bo_get_plane_fd(bo, i)); | 124 base::ScopedFD fd(gbm_bo_get_plane_fd(bo, i)); |
| 130 | 125 |
| 131 // TODO(dcastagna): support multiple fds. | 126 if (!fd.is_valid()) { |
| 132 // crbug.com/642410 | 127 PLOG(ERROR) << "Failed to export buffer to dma_buf"; |
| 133 if (!i) { | 128 gbm_bo_destroy(bo); |
| 134 if (!fd.is_valid()) { | 129 return nullptr; |
| 135 PLOG(ERROR) << "Failed to export buffer to dma_buf"; | |
| 136 gbm_bo_destroy(bo); | |
| 137 return nullptr; | |
| 138 } | |
| 139 fds.emplace_back(std::move(fd)); | |
| 140 } | 130 } |
| 131 fds.emplace_back(std::move(fd)); |
| 141 | 132 |
| 142 planes.emplace_back( | 133 planes.emplace_back(gbm_bo_get_plane_stride(bo, i), |
| 143 gbm_bo_get_plane_stride(bo, i), gbm_bo_get_plane_offset(bo, i), | 134 gbm_bo_get_plane_offset(bo, i), |
| 144 gbm_bo_get_plane_size(bo, i), gbm_bo_get_plane_format_modifier(bo, i)); | 135 gbm_bo_get_plane_format_modifier(bo, i)); |
| 145 } | 136 } |
| 146 scoped_refptr<GbmBuffer> buffer(new GbmBuffer( | 137 scoped_refptr<GbmBuffer> buffer(new GbmBuffer( |
| 147 gbm, bo, format, usage, std::move(fds), size, std::move(planes))); | 138 gbm, bo, format, usage, std::move(fds), size, std::move(planes))); |
| 148 if (usage == gfx::BufferUsage::SCANOUT && !buffer->GetFramebufferId()) | 139 if (usage == gfx::BufferUsage::SCANOUT && !buffer->GetFramebufferId()) |
| 149 return nullptr; | 140 return nullptr; |
| 150 | 141 |
| 151 return buffer; | 142 return buffer; |
| 152 } | 143 } |
| 153 | 144 |
| 154 // static | 145 // static |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 if (i < buffer_->GetFdCount()) { | 209 if (i < buffer_->GetFdCount()) { |
| 219 base::ScopedFD scoped_fd(HANDLE_EINTR(dup(buffer_->GetFd(i)))); | 210 base::ScopedFD scoped_fd(HANDLE_EINTR(dup(buffer_->GetFd(i)))); |
| 220 if (!scoped_fd.is_valid()) { | 211 if (!scoped_fd.is_valid()) { |
| 221 PLOG(ERROR) << "dup"; | 212 PLOG(ERROR) << "dup"; |
| 222 return gfx::NativePixmapHandle(); | 213 return gfx::NativePixmapHandle(); |
| 223 } | 214 } |
| 224 handle.fds.emplace_back( | 215 handle.fds.emplace_back( |
| 225 base::FileDescriptor(scoped_fd.release(), true /* auto_close */)); | 216 base::FileDescriptor(scoped_fd.release(), true /* auto_close */)); |
| 226 } | 217 } |
| 227 handle.planes.emplace_back(buffer_->GetStride(i), buffer_->GetOffset(i), | 218 handle.planes.emplace_back(buffer_->GetStride(i), buffer_->GetOffset(i), |
| 228 buffer_->GetSize(i), | |
| 229 buffer_->GetFormatModifier(i)); | 219 buffer_->GetFormatModifier(i)); |
| 230 } | 220 } |
| 231 return handle; | 221 return handle; |
| 232 } | 222 } |
| 233 | 223 |
| 234 GbmPixmap::~GbmPixmap() { | 224 GbmPixmap::~GbmPixmap() { |
| 235 } | 225 } |
| 236 | 226 |
| 237 void* GbmPixmap::GetEGLClientBuffer() const { | 227 void* GbmPixmap::GetEGLClientBuffer() const { |
| 238 return nullptr; | 228 return nullptr; |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 312 DCHECK(!processing_callback_.is_null()); | 302 DCHECK(!processing_callback_.is_null()); |
| 313 if (!processing_callback_.Run(this, processed_pixmap_)) { | 303 if (!processing_callback_.Run(this, processed_pixmap_)) { |
| 314 LOG(ERROR) << "Failed processing NativePixmap"; | 304 LOG(ERROR) << "Failed processing NativePixmap"; |
| 315 return nullptr; | 305 return nullptr; |
| 316 } | 306 } |
| 317 | 307 |
| 318 return processed_pixmap_->buffer(); | 308 return processed_pixmap_->buffer(); |
| 319 } | 309 } |
| 320 | 310 |
| 321 } // namespace ui | 311 } // namespace ui |
| OLD | NEW |