| 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/dri/gbm_buffer.h" | 5 #include "ui/ozone/platform/dri/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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 return NULL; | 62 return NULL; |
| 63 | 63 |
| 64 return buffer; | 64 return buffer; |
| 65 } | 65 } |
| 66 | 66 |
| 67 GbmPixmap::GbmPixmap(scoped_refptr<GbmBuffer> buffer) | 67 GbmPixmap::GbmPixmap(scoped_refptr<GbmBuffer> buffer) |
| 68 : buffer_(buffer), dma_buf_(-1) { | 68 : buffer_(buffer), dma_buf_(-1) { |
| 69 } | 69 } |
| 70 | 70 |
| 71 bool GbmPixmap::Initialize(DriWrapper* dri) { | 71 bool GbmPixmap::Initialize(DriWrapper* dri) { |
| 72 if (drmPrimeHandleToFD(dri->get_fd(), buffer_->GetHandle(), DRM_CLOEXEC, | 72 // We want to use the GBM API because it's going to call into libdrm |
| 73 &dma_buf_)) { | 73 // which might do some optimizations on buffer allocation, |
| 74 // especially when sharing buffers via DMABUF. |
| 75 dma_buf_ = gbm_bo_get_fd(buffer_->bo()); |
| 76 if (dma_buf_ < 0) { |
| 74 LOG(ERROR) << "Failed to export buffer to dma_buf"; | 77 LOG(ERROR) << "Failed to export buffer to dma_buf"; |
| 75 return false; | 78 return false; |
| 76 } | 79 } |
| 77 | |
| 78 return true; | 80 return true; |
| 79 } | 81 } |
| 80 | 82 |
| 81 GbmPixmap::~GbmPixmap() { | 83 GbmPixmap::~GbmPixmap() { |
| 82 if (dma_buf_ > 0) | 84 if (dma_buf_ > 0) |
| 83 close(dma_buf_); | 85 close(dma_buf_); |
| 84 } | 86 } |
| 85 | 87 |
| 86 void* GbmPixmap::GetEGLClientBuffer() { | 88 void* GbmPixmap::GetEGLClientBuffer() { |
| 87 return NULL; | 89 return NULL; |
| 88 } | 90 } |
| 89 | 91 |
| 90 int GbmPixmap::GetDmaBufFd() { | 92 int GbmPixmap::GetDmaBufFd() { |
| 91 return dma_buf_; | 93 return dma_buf_; |
| 92 } | 94 } |
| 93 | 95 |
| 94 int GbmPixmap::GetDmaBufPitch() { | 96 int GbmPixmap::GetDmaBufPitch() { |
| 95 return gbm_bo_get_stride(buffer_->bo()); | 97 return gbm_bo_get_stride(buffer_->bo()); |
| 96 } | 98 } |
| 97 | 99 |
| 98 } // namespace ui | 100 } // namespace ui |
| OLD | NEW |