Chromium Code Reviews| 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 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 136 scoped_refptr<GbmBuffer> GbmBuffer::CreateBufferFromFds( | 136 scoped_refptr<GbmBuffer> GbmBuffer::CreateBufferFromFds( |
| 137 const scoped_refptr<GbmDevice>& gbm, | 137 const scoped_refptr<GbmDevice>& gbm, |
| 138 gfx::BufferFormat format, | 138 gfx::BufferFormat format, |
| 139 const gfx::Size& size, | 139 const gfx::Size& size, |
| 140 std::vector<base::ScopedFD>&& fds, | 140 std::vector<base::ScopedFD>&& fds, |
| 141 const std::vector<int>& strides, | 141 const std::vector<int>& strides, |
| 142 const std::vector<int>& offsets) { | 142 const std::vector<int>& offsets) { |
| 143 TRACE_EVENT2("drm", "GbmBuffer::CreateBufferFromFD", "device", | 143 TRACE_EVENT2("drm", "GbmBuffer::CreateBufferFromFD", "device", |
| 144 gbm->device_path().value(), "size", size.ToString()); | 144 gbm->device_path().value(), "size", size.ToString()); |
| 145 DCHECK_EQ(fds.size(), strides.size()); | 145 DCHECK_EQ(fds.size(), strides.size()); |
| 146 // TODO(reveman): Use gbm_bo_import after making buffers survive | 146 DCHECK_EQ(fds.size(), 1u); |
| 147 // GPU process crashes. crbug.com/597932 | 147 DCHECK_EQ(offsets[0], 0u); |
| 148 return make_scoped_refptr( | 148 |
| 149 new GbmBuffer(gbm, nullptr, format, gfx::BufferUsage::GPU_READ, | 149 struct gbm_import_fd_data fd_data; |
| 150 std::move(fds), size, strides, offsets)); | 150 fd_data.fd = fds[0].get(); |
| 151 fd_data.width = size.width(); | |
| 152 fd_data.height = size.height(); | |
| 153 fd_data.stride = strides[0]; | |
| 154 fd_data.format = GetFourCCFormatFromBufferFormat(format); | |
| 155 | |
| 156 // Use scanout if supported. | |
| 157 const std::vector<uint32_t>& scanout_formats = | |
| 158 gbm->plane_manager()->GetSupportedFormats(); | |
| 159 bool use_scanout = std::find(scanout_formats.begin(), scanout_formats.end(), | |
| 160 fd_data.format) != scanout_formats.end(); | |
| 161 unsigned flags = 0; | |
| 162 if (use_scanout) | |
| 163 flags = GBM_BO_USE_SCANOUT | GBM_BO_USE_RENDERING; | |
| 164 | |
| 165 // The fd passed to gbm_bo_import is not ref-counted and need to be | |
| 166 // kept open for the lifetime of the buffer. | |
| 167 gbm_bo* bo = gbm_bo_import(gbm->device(), GBM_BO_IMPORT_FD, &fd_data, flags); | |
| 168 if (!bo) | |
| 169 return nullptr; | |
| 170 | |
| 171 scoped_refptr<GbmBuffer> buffer(new GbmBuffer( | |
| 172 gbm, bo, format, | |
| 173 use_scanout ? gfx::BufferUsage::SCANOUT : gfx::BufferUsage::GPU_READ, | |
| 174 std::move(fds), size, strides, offsets)); | |
| 175 if (use_scanout && !buffer->GetFramebufferId()) | |
|
Daniele Castagna
2016/06/16 21:14:26
nit: I'd add a comment explaning why the !framebuf
reveman
2016/06/16 21:46:20
Added a comment. The check is consistent with GbmB
| |
| 176 return nullptr; | |
| 177 | |
| 178 return buffer; | |
| 151 } | 179 } |
| 152 | 180 |
| 153 GbmPixmap::GbmPixmap(GbmSurfaceFactory* surface_manager, | 181 GbmPixmap::GbmPixmap(GbmSurfaceFactory* surface_manager, |
| 154 const scoped_refptr<GbmBuffer>& buffer) | 182 const scoped_refptr<GbmBuffer>& buffer) |
| 155 : surface_manager_(surface_manager), buffer_(buffer) {} | 183 : surface_manager_(surface_manager), buffer_(buffer) {} |
| 156 | 184 |
| 157 void GbmPixmap::SetProcessingCallback( | 185 void GbmPixmap::SetProcessingCallback( |
| 158 const ProcessingCallback& processing_callback) { | 186 const ProcessingCallback& processing_callback) { |
| 159 DCHECK(processing_callback_.is_null()); | 187 DCHECK(processing_callback_.is_null()); |
| 160 processing_callback_ = processing_callback; | 188 processing_callback_ = processing_callback; |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 257 DCHECK(!processing_callback_.is_null()); | 285 DCHECK(!processing_callback_.is_null()); |
| 258 if (!processing_callback_.Run(this, processed_pixmap_)) { | 286 if (!processing_callback_.Run(this, processed_pixmap_)) { |
| 259 LOG(ERROR) << "Failed processing NativePixmap"; | 287 LOG(ERROR) << "Failed processing NativePixmap"; |
| 260 return nullptr; | 288 return nullptr; |
| 261 } | 289 } |
| 262 | 290 |
| 263 return processed_pixmap_->buffer(); | 291 return processed_pixmap_->buffer(); |
| 264 } | 292 } |
| 265 | 293 |
| 266 } // namespace ui | 294 } // namespace ui |
| OLD | NEW |