Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(131)

Side by Side Diff: ui/ozone/platform/drm/gpu/gbm_buffer.cc

Issue 1837703002: gpu: Export/import buffers created by Ozone GMB factory. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: move dup() to ShareGpuMemoryBufferToGpuProcess Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « gpu/ipc/service/gpu_memory_buffer_factory_ozone_native_pixmap.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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], 0);
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 scanout support for buffer is expected then make sure we managed to
176 // create a framebuffer for it as otherwise using it for scanout will fail.
177 if (use_scanout && !buffer->GetFramebufferId())
178 return nullptr;
179
180 return buffer;
151 } 181 }
152 182
153 GbmPixmap::GbmPixmap(GbmSurfaceFactory* surface_manager, 183 GbmPixmap::GbmPixmap(GbmSurfaceFactory* surface_manager,
154 const scoped_refptr<GbmBuffer>& buffer) 184 const scoped_refptr<GbmBuffer>& buffer)
155 : surface_manager_(surface_manager), buffer_(buffer) {} 185 : surface_manager_(surface_manager), buffer_(buffer) {}
156 186
157 void GbmPixmap::SetProcessingCallback( 187 void GbmPixmap::SetProcessingCallback(
158 const ProcessingCallback& processing_callback) { 188 const ProcessingCallback& processing_callback) {
159 DCHECK(processing_callback_.is_null()); 189 DCHECK(processing_callback_.is_null());
160 processing_callback_ = processing_callback; 190 processing_callback_ = processing_callback;
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 DCHECK(!processing_callback_.is_null()); 287 DCHECK(!processing_callback_.is_null());
258 if (!processing_callback_.Run(this, processed_pixmap_)) { 288 if (!processing_callback_.Run(this, processed_pixmap_)) {
259 LOG(ERROR) << "Failed processing NativePixmap"; 289 LOG(ERROR) << "Failed processing NativePixmap";
260 return nullptr; 290 return nullptr;
261 } 291 }
262 292
263 return processed_pixmap_->buffer(); 293 return processed_pixmap_->buffer();
264 } 294 }
265 295
266 } // namespace ui 296 } // namespace ui
OLDNEW
« no previous file with comments | « gpu/ipc/service/gpu_memory_buffer_factory_ozone_native_pixmap.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698