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

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

Issue 2576263002: ozone: Allocate scanout buffer according to KMS modifiers (Closed)
Patch Set: ozone: Allocate scanout buffer according to KMS modifiers Created 4 years 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
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 12 matching lines...) Expand all
23 #include "ui/ozone/platform/drm/gpu/gbm_surfaceless.h" 23 #include "ui/ozone/platform/drm/gpu/gbm_surfaceless.h"
24 #include "ui/ozone/public/ozone_platform.h" 24 #include "ui/ozone/public/ozone_platform.h"
25 #include "ui/ozone/public/surface_factory_ozone.h" 25 #include "ui/ozone/public/surface_factory_ozone.h"
26 26
27 namespace ui { 27 namespace ui {
28 28
29 GbmBuffer::GbmBuffer(const scoped_refptr<GbmDevice>& gbm, 29 GbmBuffer::GbmBuffer(const scoped_refptr<GbmDevice>& gbm,
30 gbm_bo* bo, 30 gbm_bo* bo,
31 uint32_t format, 31 uint32_t format,
32 uint32_t flags, 32 uint32_t flags,
33 uint64_t modifier,
33 std::vector<base::ScopedFD>&& fds, 34 std::vector<base::ScopedFD>&& fds,
34 const gfx::Size& size, 35 const gfx::Size& size,
35 const std::vector<gfx::NativePixmapPlane>&& planes) 36 const std::vector<gfx::NativePixmapPlane>&& planes)
36 : GbmBufferBase(gbm, bo, format, flags), 37 : GbmBufferBase(gbm, bo, format, flags),
37 format_(format), 38 format_(format),
38 flags_(flags), 39 flags_(flags),
40 modifier_(modifier),
39 fds_(std::move(fds)), 41 fds_(std::move(fds)),
40 size_(size), 42 size_(size),
41 planes_(std::move(planes)) {} 43 planes_(std::move(planes)) {}
42 44
43 GbmBuffer::~GbmBuffer() { 45 GbmBuffer::~GbmBuffer() {
44 if (bo()) 46 if (bo())
45 gbm_bo_destroy(bo()); 47 gbm_bo_destroy(bo());
46 } 48 }
47 49
48 bool GbmBuffer::AreFdsValid() const { 50 bool GbmBuffer::AreFdsValid() const {
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 return nullptr; 124 return nullptr;
123 } 125 }
124 fds.emplace_back(std::move(fd)); 126 fds.emplace_back(std::move(fd));
125 } 127 }
126 128
127 planes.emplace_back( 129 planes.emplace_back(
128 gbm_bo_get_plane_stride(bo, i), gbm_bo_get_plane_offset(bo, i), 130 gbm_bo_get_plane_stride(bo, i), gbm_bo_get_plane_offset(bo, i),
129 gbm_bo_get_plane_size(bo, i), gbm_bo_get_plane_format_modifier(bo, i)); 131 gbm_bo_get_plane_size(bo, i), gbm_bo_get_plane_format_modifier(bo, i));
130 } 132 }
131 scoped_refptr<GbmBuffer> buffer(new GbmBuffer( 133 scoped_refptr<GbmBuffer> buffer(new GbmBuffer(
132 gbm, bo, format, flags, std::move(fds), size, std::move(planes))); 134 gbm, bo, format, flags, 0, std::move(fds), size, std::move(planes)));
133 if (flags & GBM_BO_USE_SCANOUT && !buffer->GetFramebufferId()) 135 if (flags & GBM_BO_USE_SCANOUT && !buffer->GetFramebufferId())
134 return nullptr; 136 return nullptr;
135 137
138 return buffer;
139 }
140
141 // static
142 scoped_refptr<GbmBuffer> GbmBuffer::CreateBufferWithModifiers(
dnicoara 2016/12/19 19:44:46 It seems that only the gbm_bo_create()/gbm_bo_crea
Daniele Castagna 2016/12/20 18:03:28 Maybe we could have just GbmBuffer::CreateBuffer t
hoegsberg1 2016/12/22 23:05:20 I wanted to keep the two paths separate: either yo
143 const scoped_refptr<GbmDevice>& gbm,
144 uint32_t format,
145 const gfx::Size& size,
146 uint32_t flags,
147 const std::vector<uint64_t>& modifiers) {
148 TRACE_EVENT2("drm", "GbmBuffer::CreateBufferWithModifiers", "device",
149 gbm->device_path().value(), "size", size.ToString());
150
151 gbm_bo* bo =
152 gbm_bo_create_with_modifiers(gbm->device(), size.width(), size.height(),
153 format, &modifiers[0], modifiers.size());
dnicoara 2016/12/19 19:44:46 nit: Prefer modifiers.data().
hoegsberg1 2016/12/22 23:05:20 Acknowledged.
154 if (!bo)
155 return nullptr;
156
157 uint64_t modifier = gbm_bo_get_format_modifier(bo);
158
159 std::vector<base::ScopedFD> fds;
160 std::vector<gfx::NativePixmapPlane> planes;
161
162 for (size_t i = 0; i < gbm_bo_get_num_planes(bo); ++i) {
163 // The fd returned by gbm_bo_get_fd is not ref-counted and need to be
164 // kept open for the lifetime of the buffer.
165 base::ScopedFD fd(gbm_bo_get_plane_fd(bo, i));
166
167 // TODO(dcastagna): support multiple fds.
168 // crbug.com/642410
169 if (!i) {
170 if (!fd.is_valid()) {
171 PLOG(ERROR) << "Failed to export buffer to dma_buf";
172 gbm_bo_destroy(bo);
173 return nullptr;
174 }
175 fds.emplace_back(std::move(fd));
176 }
177
178 planes.emplace_back(
179 gbm_bo_get_plane_stride(bo, i), gbm_bo_get_plane_offset(bo, i),
180 gbm_bo_get_plane_size(bo, i), gbm_bo_get_plane_format_modifier(bo, i));
181 }
182 scoped_refptr<GbmBuffer> buffer(new GbmBuffer(gbm, bo, format, flags,
183 modifier, std::move(fds), size,
184 std::move(planes)));
185 if (flags & GBM_BO_USE_SCANOUT && !buffer->GetFramebufferId())
186 return nullptr;
187
136 return buffer; 188 return buffer;
137 } 189 }
138 190
139 // static 191 // static
140 scoped_refptr<GbmBuffer> GbmBuffer::CreateBufferFromFds( 192 scoped_refptr<GbmBuffer> GbmBuffer::CreateBufferFromFds(
141 const scoped_refptr<GbmDevice>& gbm, 193 const scoped_refptr<GbmDevice>& gbm,
142 uint32_t format, 194 uint32_t format,
143 const gfx::Size& size, 195 const gfx::Size& size,
144 std::vector<base::ScopedFD>&& fds, 196 std::vector<base::ScopedFD>&& fds,
145 const std::vector<gfx::NativePixmapPlane>& planes) { 197 const std::vector<gfx::NativePixmapPlane>& planes) {
(...skipping 24 matching lines...) Expand all
170 if (!bo) { 222 if (!bo) {
171 LOG(ERROR) << "nullptr returned from gbm_bo_import"; 223 LOG(ERROR) << "nullptr returned from gbm_bo_import";
172 return nullptr; 224 return nullptr;
173 } 225 }
174 } 226 }
175 227
176 uint32_t flags = GBM_BO_USE_RENDERING; 228 uint32_t flags = GBM_BO_USE_RENDERING;
177 if (use_scanout) 229 if (use_scanout)
178 flags |= GBM_BO_USE_SCANOUT; 230 flags |= GBM_BO_USE_SCANOUT;
179 scoped_refptr<GbmBuffer> buffer(new GbmBuffer( 231 scoped_refptr<GbmBuffer> buffer(new GbmBuffer(
180 gbm, bo, format, flags, std::move(fds), size, std::move(planes))); 232 gbm, bo, format, 0, flags, std::move(fds), size, std::move(planes)));
181 // If scanout support for buffer is expected then make sure we managed to 233 // If scanout support for buffer is expected then make sure we managed to
182 // create a framebuffer for it as otherwise using it for scanout will fail. 234 // create a framebuffer for it as otherwise using it for scanout will fail.
183 if (use_scanout && !buffer->GetFramebufferId()) 235 if (use_scanout && !buffer->GetFramebufferId())
184 return nullptr; 236 return nullptr;
185 237
186 return buffer; 238 return buffer;
187 } 239 }
188 240
189 GbmPixmap::GbmPixmap(GbmSurfaceFactory* surface_manager, 241 GbmPixmap::GbmPixmap(GbmSurfaceFactory* surface_manager,
190 const scoped_refptr<GbmBuffer>& buffer) 242 const scoped_refptr<GbmBuffer>& buffer)
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 DCHECK(!processing_callback_.is_null()); 351 DCHECK(!processing_callback_.is_null());
300 if (!processing_callback_.Run(this, processed_pixmap_)) { 352 if (!processing_callback_.Run(this, processed_pixmap_)) {
301 LOG(ERROR) << "Failed processing NativePixmap"; 353 LOG(ERROR) << "Failed processing NativePixmap";
302 return nullptr; 354 return nullptr;
303 } 355 }
304 356
305 return processed_pixmap_->buffer(); 357 return processed_pixmap_->buffer();
306 } 358 }
307 359
308 } // namespace ui 360 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698