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

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 3 years, 12 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 | « ui/ozone/platform/drm/gpu/gbm_buffer.h ('k') | ui/ozone/platform/drm/gpu/gbm_buffer_base.h » ('j') | 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 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,
34 uint32_t addfb_flags,
33 std::vector<base::ScopedFD>&& fds, 35 std::vector<base::ScopedFD>&& fds,
34 const gfx::Size& size, 36 const gfx::Size& size,
37
35 const std::vector<gfx::NativePixmapPlane>&& planes) 38 const std::vector<gfx::NativePixmapPlane>&& planes)
36 : GbmBufferBase(gbm, bo, format, flags), 39 : GbmBufferBase(gbm, bo, format, flags, modifier, addfb_flags),
37 format_(format), 40 format_(format),
38 flags_(flags), 41 flags_(flags),
42 modifier_(modifier),
39 fds_(std::move(fds)), 43 fds_(std::move(fds)),
40 size_(size), 44 size_(size),
41 planes_(std::move(planes)) {} 45 planes_(std::move(planes)) {}
42 46
43 GbmBuffer::~GbmBuffer() { 47 GbmBuffer::~GbmBuffer() {
44 if (bo()) 48 if (bo())
45 gbm_bo_destroy(bo()); 49 gbm_bo_destroy(bo());
46 } 50 }
47 51
48 bool GbmBuffer::AreFdsValid() const { 52 bool GbmBuffer::AreFdsValid() const {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 DCHECK_LT(index, planes_.size()); 88 DCHECK_LT(index, planes_.size());
85 return planes_[index].modifier; 89 return planes_[index].modifier;
86 } 90 }
87 91
88 // TODO(reveman): This should not be needed once crbug.com/597932 is fixed, 92 // TODO(reveman): This should not be needed once crbug.com/597932 is fixed,
89 // as the size would be queried directly from the underlying bo. 93 // as the size would be queried directly from the underlying bo.
90 gfx::Size GbmBuffer::GetSize() const { 94 gfx::Size GbmBuffer::GetSize() const {
91 return size_; 95 return size_;
92 } 96 }
93 97
94 // static 98 scoped_refptr<GbmBuffer> GbmBuffer::CreateBufferForBO(
95 scoped_refptr<GbmBuffer> GbmBuffer::CreateBuffer(
96 const scoped_refptr<GbmDevice>& gbm, 99 const scoped_refptr<GbmDevice>& gbm,
100 gbm_bo* bo,
97 uint32_t format, 101 uint32_t format,
98 const gfx::Size& size, 102 const gfx::Size& size,
99 uint32_t flags) { 103 uint32_t flags,
100 TRACE_EVENT2("drm", "GbmBuffer::CreateBuffer", "device", 104 uint64_t modifier,
101 gbm->device_path().value(), "size", size.ToString()); 105 uint32_t addfb_flags) {
102
103 gbm_bo* bo =
104 gbm_bo_create(gbm->device(), size.width(), size.height(), format, flags);
105 if (!bo) 106 if (!bo)
106 return nullptr; 107 return nullptr;
107 108
108 std::vector<base::ScopedFD> fds; 109 std::vector<base::ScopedFD> fds;
109 std::vector<gfx::NativePixmapPlane> planes; 110 std::vector<gfx::NativePixmapPlane> planes;
110 111
111 for (size_t i = 0; i < gbm_bo_get_num_planes(bo); ++i) { 112 for (size_t i = 0; i < gbm_bo_get_num_planes(bo); ++i) {
112 // The fd returned by gbm_bo_get_fd is not ref-counted and need to be 113 // The fd returned by gbm_bo_get_fd is not ref-counted and need to be
113 // kept open for the lifetime of the buffer. 114 // kept open for the lifetime of the buffer.
114 base::ScopedFD fd(gbm_bo_get_plane_fd(bo, i)); 115 base::ScopedFD fd(gbm_bo_get_plane_fd(bo, i));
115 116
116 // TODO(dcastagna): support multiple fds. 117 // TODO(dcastagna): support multiple fds.
117 // crbug.com/642410 118 // crbug.com/642410
118 if (!i) { 119 if (!i) {
119 if (!fd.is_valid()) { 120 if (!fd.is_valid()) {
120 PLOG(ERROR) << "Failed to export buffer to dma_buf"; 121 PLOG(ERROR) << "Failed to export buffer to dma_buf";
121 gbm_bo_destroy(bo); 122 gbm_bo_destroy(bo);
122 return nullptr; 123 return nullptr;
123 } 124 }
124 fds.emplace_back(std::move(fd)); 125 fds.emplace_back(std::move(fd));
125 } 126 }
126 127
127 planes.emplace_back( 128 planes.emplace_back(
128 gbm_bo_get_plane_stride(bo, i), gbm_bo_get_plane_offset(bo, i), 129 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)); 130 gbm_bo_get_plane_size(bo, i), gbm_bo_get_plane_format_modifier(bo, i));
130 } 131 }
131 scoped_refptr<GbmBuffer> buffer(new GbmBuffer( 132 scoped_refptr<GbmBuffer> buffer(new GbmBuffer(gbm, bo, format, flags,
132 gbm, bo, format, flags, std::move(fds), size, std::move(planes))); 133 modifier, addfb_flags,
134 std::move(fds), size,
135 std::move(planes)));
133 if (flags & GBM_BO_USE_SCANOUT && !buffer->GetFramebufferId()) 136 if (flags & GBM_BO_USE_SCANOUT && !buffer->GetFramebufferId())
134 return nullptr; 137 return nullptr;
135 138
136 return buffer; 139 return buffer;
137 } 140 }
138 141
139 // static 142 // static
143 scoped_refptr<GbmBuffer> GbmBuffer::CreateBufferWithModifiers(
144 const scoped_refptr<GbmDevice>& gbm,
145 uint32_t format,
146 const gfx::Size& size,
147 uint32_t flags,
148 const std::vector<uint64_t>& modifiers) {
149 TRACE_EVENT2("drm", "GbmBuffer::CreateBufferWithModifiers", "device",
150 gbm->device_path().value(), "size", size.ToString());
151
152 gbm_bo* bo = gbm_bo_create_with_modifiers(gbm->device(),
153 size.width(), size.height(),
154 format,
155 modifiers.data(),
156 modifiers.size());
157
158 return CreateBufferForBO(gbm, bo, format, size, flags,
159 gbm_bo_get_format_modifier(bo),
160 DRM_MODE_FB_MODIFIERS);
161 }
162
163 // static
164 scoped_refptr<GbmBuffer> GbmBuffer::CreateBuffer(
165 const scoped_refptr<GbmDevice>& gbm,
166 uint32_t format,
167 const gfx::Size& size,
168 uint32_t flags) {
169 TRACE_EVENT2("drm", "GbmBuffer::CreateBuffer", "device",
170 gbm->device_path().value(), "size", size.ToString());
171
172 gbm_bo* bo = gbm_bo_create(gbm->device(),
173 size.width(), size.height(), format, flags);
174
175 return CreateBufferForBO(gbm, bo, format, size, flags, 0, 0);
176 }
177
178 // static
140 scoped_refptr<GbmBuffer> GbmBuffer::CreateBufferFromFds( 179 scoped_refptr<GbmBuffer> GbmBuffer::CreateBufferFromFds(
141 const scoped_refptr<GbmDevice>& gbm, 180 const scoped_refptr<GbmDevice>& gbm,
142 uint32_t format, 181 uint32_t format,
143 const gfx::Size& size, 182 const gfx::Size& size,
144 std::vector<base::ScopedFD>&& fds, 183 std::vector<base::ScopedFD>&& fds,
145 const std::vector<gfx::NativePixmapPlane>& planes) { 184 const std::vector<gfx::NativePixmapPlane>& planes) {
146 TRACE_EVENT2("drm", "GbmBuffer::CreateBufferFromFD", "device", 185 TRACE_EVENT2("drm", "GbmBuffer::CreateBufferFromFD", "device",
147 gbm->device_path().value(), "size", size.ToString()); 186 gbm->device_path().value(), "size", size.ToString());
148 DCHECK_LE(fds.size(), planes.size()); 187 DCHECK_LE(fds.size(), planes.size());
149 DCHECK_EQ(planes[0].offset, 0); 188 DCHECK_EQ(planes[0].offset, 0);
(...skipping 20 matching lines...) Expand all
170 if (!bo) { 209 if (!bo) {
171 LOG(ERROR) << "nullptr returned from gbm_bo_import"; 210 LOG(ERROR) << "nullptr returned from gbm_bo_import";
172 return nullptr; 211 return nullptr;
173 } 212 }
174 } 213 }
175 214
176 uint32_t flags = GBM_BO_USE_RENDERING; 215 uint32_t flags = GBM_BO_USE_RENDERING;
177 if (use_scanout) 216 if (use_scanout)
178 flags |= GBM_BO_USE_SCANOUT; 217 flags |= GBM_BO_USE_SCANOUT;
179 scoped_refptr<GbmBuffer> buffer(new GbmBuffer( 218 scoped_refptr<GbmBuffer> buffer(new GbmBuffer(
180 gbm, bo, format, flags, std::move(fds), size, std::move(planes))); 219 gbm, bo, format, flags, 0, 0, std::move(fds), size, std::move(planes)));
181 // If scanout support for buffer is expected then make sure we managed to 220 // 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. 221 // create a framebuffer for it as otherwise using it for scanout will fail.
183 if (use_scanout && !buffer->GetFramebufferId()) 222 if (use_scanout && !buffer->GetFramebufferId())
184 return nullptr; 223 return nullptr;
185 224
186 return buffer; 225 return buffer;
187 } 226 }
188 227
189 GbmPixmap::GbmPixmap(GbmSurfaceFactory* surface_manager, 228 GbmPixmap::GbmPixmap(GbmSurfaceFactory* surface_manager,
190 const scoped_refptr<GbmBuffer>& buffer) 229 const scoped_refptr<GbmBuffer>& buffer)
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 DCHECK(!processing_callback_.is_null()); 338 DCHECK(!processing_callback_.is_null());
300 if (!processing_callback_.Run(this, processed_pixmap_)) { 339 if (!processing_callback_.Run(this, processed_pixmap_)) {
301 LOG(ERROR) << "Failed processing NativePixmap"; 340 LOG(ERROR) << "Failed processing NativePixmap";
302 return nullptr; 341 return nullptr;
303 } 342 }
304 343
305 return processed_pixmap_->buffer(); 344 return processed_pixmap_->buffer();
306 } 345 }
307 346
308 } // namespace ui 347 } // namespace ui
OLDNEW
« no previous file with comments | « ui/ozone/platform/drm/gpu/gbm_buffer.h ('k') | ui/ozone/platform/drm/gpu/gbm_buffer_base.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698