| 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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 int GbmBuffer::GetOffset(size_t index) const { | 76 int GbmBuffer::GetOffset(size_t index) const { |
| 77 DCHECK_LT(index, planes_.size()); | 77 DCHECK_LT(index, planes_.size()); |
| 78 return planes_[index].offset; | 78 return planes_[index].offset; |
| 79 } | 79 } |
| 80 | 80 |
| 81 size_t GbmBuffer::GetSize(size_t index) const { | 81 size_t GbmBuffer::GetSize(size_t index) const { |
| 82 DCHECK_LT(index, planes_.size()); | 82 DCHECK_LT(index, planes_.size()); |
| 83 return planes_[index].size; | 83 return planes_[index].size; |
| 84 } | 84 } |
| 85 | 85 |
| 86 uint64_t GbmBuffer::GetFormatModifier(size_t index) const { | |
| 87 DCHECK_LT(index, planes_.size()); | |
| 88 return planes_[index].modifier; | |
| 89 } | |
| 90 | |
| 91 // TODO(reveman): This should not be needed once crbug.com/597932 is fixed, | 86 // TODO(reveman): This should not be needed once crbug.com/597932 is fixed, |
| 92 // as the size would be queried directly from the underlying bo. | 87 // as the size would be queried directly from the underlying bo. |
| 93 gfx::Size GbmBuffer::GetSize() const { | 88 gfx::Size GbmBuffer::GetSize() const { |
| 94 return size_; | 89 return size_; |
| 95 } | 90 } |
| 96 | 91 |
| 97 scoped_refptr<GbmBuffer> GbmBuffer::CreateBufferForBO( | 92 scoped_refptr<GbmBuffer> GbmBuffer::CreateBufferForBO( |
| 98 const scoped_refptr<GbmDevice>& gbm, | 93 const scoped_refptr<GbmDevice>& gbm, |
| 99 gbm_bo* bo, | 94 gbm_bo* bo, |
| 100 uint32_t format, | 95 uint32_t format, |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 const scoped_refptr<GbmDevice>& gbm, | 156 const scoped_refptr<GbmDevice>& gbm, |
| 162 uint32_t format, | 157 uint32_t format, |
| 163 const gfx::Size& size, | 158 const gfx::Size& size, |
| 164 uint32_t flags) { | 159 uint32_t flags) { |
| 165 TRACE_EVENT2("drm", "GbmBuffer::CreateBuffer", "device", | 160 TRACE_EVENT2("drm", "GbmBuffer::CreateBuffer", "device", |
| 166 gbm->device_path().value(), "size", size.ToString()); | 161 gbm->device_path().value(), "size", size.ToString()); |
| 167 | 162 |
| 168 gbm_bo* bo = | 163 gbm_bo* bo = |
| 169 gbm_bo_create(gbm->device(), size.width(), size.height(), format, flags); | 164 gbm_bo_create(gbm->device(), size.width(), size.height(), format, flags); |
| 170 | 165 |
| 171 return CreateBufferForBO(gbm, bo, format, size, flags, 0, 0); | 166 return CreateBufferForBO(gbm, bo, format, size, flags, |
| 167 gbm_bo_get_format_modifier(bo), 0); |
| 172 } | 168 } |
| 173 | 169 |
| 174 // static | 170 // static |
| 175 scoped_refptr<GbmBuffer> GbmBuffer::CreateBufferFromFds( | 171 scoped_refptr<GbmBuffer> GbmBuffer::CreateBufferFromFds( |
| 176 const scoped_refptr<GbmDevice>& gbm, | 172 const scoped_refptr<GbmDevice>& gbm, |
| 177 uint32_t format, | 173 uint32_t format, |
| 178 const gfx::Size& size, | 174 const gfx::Size& size, |
| 179 std::vector<base::ScopedFD>&& fds, | 175 std::vector<base::ScopedFD>&& fds, |
| 180 const std::vector<gfx::NativePixmapPlane>& planes) { | 176 const std::vector<gfx::NativePixmapPlane>& planes) { |
| 181 TRACE_EVENT2("drm", "GbmBuffer::CreateBufferFromFD", "device", | 177 TRACE_EVENT2("drm", "GbmBuffer::CreateBufferFromFD", "device", |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 base::ScopedFD scoped_fd(HANDLE_EINTR(dup(buffer_->GetFd(i)))); | 239 base::ScopedFD scoped_fd(HANDLE_EINTR(dup(buffer_->GetFd(i)))); |
| 244 if (!scoped_fd.is_valid()) { | 240 if (!scoped_fd.is_valid()) { |
| 245 PLOG(ERROR) << "dup"; | 241 PLOG(ERROR) << "dup"; |
| 246 return gfx::NativePixmapHandle(); | 242 return gfx::NativePixmapHandle(); |
| 247 } | 243 } |
| 248 handle.fds.emplace_back( | 244 handle.fds.emplace_back( |
| 249 base::FileDescriptor(scoped_fd.release(), true /* auto_close */)); | 245 base::FileDescriptor(scoped_fd.release(), true /* auto_close */)); |
| 250 } | 246 } |
| 251 handle.planes.emplace_back(buffer_->GetStride(i), buffer_->GetOffset(i), | 247 handle.planes.emplace_back(buffer_->GetStride(i), buffer_->GetOffset(i), |
| 252 buffer_->GetSize(i), | 248 buffer_->GetSize(i), |
| 253 buffer_->GetFormatModifier(i)); | 249 buffer_->GetFormatModifier()); |
| 254 } | 250 } |
| 255 return handle; | 251 return handle; |
| 256 } | 252 } |
| 257 | 253 |
| 258 GbmPixmap::~GbmPixmap() { | 254 GbmPixmap::~GbmPixmap() { |
| 259 } | 255 } |
| 260 | 256 |
| 261 void* GbmPixmap::GetEGLClientBuffer() const { | 257 void* GbmPixmap::GetEGLClientBuffer() const { |
| 262 return nullptr; | 258 return nullptr; |
| 263 } | 259 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 276 | 272 |
| 277 int GbmPixmap::GetDmaBufPitch(size_t plane) const { | 273 int GbmPixmap::GetDmaBufPitch(size_t plane) const { |
| 278 return buffer_->GetStride(plane); | 274 return buffer_->GetStride(plane); |
| 279 } | 275 } |
| 280 | 276 |
| 281 int GbmPixmap::GetDmaBufOffset(size_t plane) const { | 277 int GbmPixmap::GetDmaBufOffset(size_t plane) const { |
| 282 return buffer_->GetOffset(plane); | 278 return buffer_->GetOffset(plane); |
| 283 } | 279 } |
| 284 | 280 |
| 285 uint64_t GbmPixmap::GetDmaBufModifier(size_t plane) const { | 281 uint64_t GbmPixmap::GetDmaBufModifier(size_t plane) const { |
| 286 return buffer_->GetFormatModifier(plane); | 282 return buffer_->GetFormatModifier(); |
| 287 } | 283 } |
| 288 | 284 |
| 289 gfx::BufferFormat GbmPixmap::GetBufferFormat() const { | 285 gfx::BufferFormat GbmPixmap::GetBufferFormat() const { |
| 290 return ui::GetBufferFormatFromFourCCFormat(buffer_->GetFormat()); | 286 return ui::GetBufferFormatFromFourCCFormat(buffer_->GetFormat()); |
| 291 } | 287 } |
| 292 | 288 |
| 293 gfx::Size GbmPixmap::GetBufferSize() const { | 289 gfx::Size GbmPixmap::GetBufferSize() const { |
| 294 return buffer_->GetSize(); | 290 return buffer_->GetSize(); |
| 295 } | 291 } |
| 296 | 292 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 334 DCHECK(!processing_callback_.is_null()); | 330 DCHECK(!processing_callback_.is_null()); |
| 335 if (!processing_callback_.Run(this, processed_pixmap_)) { | 331 if (!processing_callback_.Run(this, processed_pixmap_)) { |
| 336 LOG(ERROR) << "Failed processing NativePixmap"; | 332 LOG(ERROR) << "Failed processing NativePixmap"; |
| 337 return nullptr; | 333 return nullptr; |
| 338 } | 334 } |
| 339 | 335 |
| 340 return processed_pixmap_->buffer(); | 336 return processed_pixmap_->buffer(); |
| 341 } | 337 } |
| 342 | 338 |
| 343 } // namespace ui | 339 } // namespace ui |
| OLD | NEW |