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> |
11 | 11 |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/posix/eintr_wrapper.h" |
13 #include "base/trace_event/trace_event.h" | 14 #include "base/trace_event/trace_event.h" |
14 #include "ui/gfx/geometry/size_conversions.h" | 15 #include "ui/gfx/geometry/size_conversions.h" |
| 16 #include "ui/gfx/native_pixmap_handle_ozone.h" |
15 #include "ui/ozone/platform/drm/gpu/drm_window.h" | 17 #include "ui/ozone/platform/drm/gpu/drm_window.h" |
16 #include "ui/ozone/platform/drm/gpu/gbm_device.h" | 18 #include "ui/ozone/platform/drm/gpu/gbm_device.h" |
17 | 19 |
18 namespace ui { | 20 namespace ui { |
19 | 21 |
20 namespace { | 22 namespace { |
21 | 23 |
22 int GetGbmFormatFromBufferFormat(gfx::BufferFormat fmt) { | 24 int GetGbmFormatFromBufferFormat(gfx::BufferFormat fmt) { |
23 switch (fmt) { | 25 switch (fmt) { |
24 case gfx::BufferFormat::BGRA_8888: | 26 case gfx::BufferFormat::BGRA_8888: |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 } | 89 } |
88 | 90 |
89 void GbmPixmap::SetScalingCallback(const ScalingCallback& scaling_callback) { | 91 void GbmPixmap::SetScalingCallback(const ScalingCallback& scaling_callback) { |
90 scaling_callback_ = scaling_callback; | 92 scaling_callback_ = scaling_callback; |
91 } | 93 } |
92 | 94 |
93 scoped_refptr<NativePixmap> GbmPixmap::GetScaledPixmap(gfx::Size new_size) { | 95 scoped_refptr<NativePixmap> GbmPixmap::GetScaledPixmap(gfx::Size new_size) { |
94 return scaling_callback_.Run(new_size); | 96 return scaling_callback_.Run(new_size); |
95 } | 97 } |
96 | 98 |
| 99 gfx::NativePixmapHandle GbmPixmap::ExportHandle() { |
| 100 gfx::NativePixmapHandle handle; |
| 101 |
| 102 int dmabuf_fd = HANDLE_EINTR(dup(dma_buf_)); |
| 103 if (dmabuf_fd < 0) { |
| 104 PLOG(ERROR) << "dup"; |
| 105 return handle; |
| 106 } |
| 107 |
| 108 handle.fd = base::FileDescriptor(dmabuf_fd, true /* auto_close */); |
| 109 handle.stride = gbm_bo_get_stride(buffer_->bo()); |
| 110 return handle; |
| 111 } |
| 112 |
97 GbmPixmap::~GbmPixmap() { | 113 GbmPixmap::~GbmPixmap() { |
98 if (dma_buf_ > 0) | 114 if (dma_buf_ > 0) |
99 close(dma_buf_); | 115 close(dma_buf_); |
100 } | 116 } |
101 | 117 |
102 void* GbmPixmap::GetEGLClientBuffer() { | 118 void* GbmPixmap::GetEGLClientBuffer() { |
103 return nullptr; | 119 return nullptr; |
104 } | 120 } |
105 | 121 |
106 int GbmPixmap::GetDmaBufFd() { | 122 int GbmPixmap::GetDmaBufFd() { |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 | 159 |
144 gfx::Size pixmap_size = buffer_->GetSize(); | 160 gfx::Size pixmap_size = buffer_->GetSize(); |
145 // If the required size is not integer-sized, round it to the next integer. | 161 // If the required size is not integer-sized, round it to the next integer. |
146 *required_size = gfx::ToCeiledSize( | 162 *required_size = gfx::ToCeiledSize( |
147 gfx::SizeF(display_bounds.width() / crop_rect.width(), | 163 gfx::SizeF(display_bounds.width() / crop_rect.width(), |
148 display_bounds.height() / crop_rect.height())); | 164 display_bounds.height() / crop_rect.height())); |
149 return pixmap_size != *required_size; | 165 return pixmap_size != *required_size; |
150 } | 166 } |
151 | 167 |
152 } // namespace ui | 168 } // namespace ui |
OLD | NEW |