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 #include <utility> | 11 #include <utility> |
12 | 12 |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
14 #include "base/posix/eintr_wrapper.h" | 14 #include "base/posix/eintr_wrapper.h" |
15 #include "base/trace_event/trace_event.h" | 15 #include "base/trace_event/trace_event.h" |
16 #include "ui/gfx/geometry/size_conversions.h" | 16 #include "ui/gfx/geometry/size_conversions.h" |
17 #include "ui/gfx/native_pixmap_handle_ozone.h" | 17 #include "ui/gfx/native_pixmap_handle_ozone.h" |
18 #include "ui/ozone/platform/drm/common/drm_util.h" | 18 #include "ui/ozone/platform/drm/common/drm_util.h" |
19 #include "ui/ozone/platform/drm/gpu/drm_window.h" | 19 #include "ui/ozone/platform/drm/gpu/drm_window.h" |
20 #include "ui/ozone/platform/drm/gpu/gbm_device.h" | 20 #include "ui/ozone/platform/drm/gpu/gbm_device.h" |
21 #include "ui/ozone/platform/drm/gpu/gbm_surface_factory.h" | 21 #include "ui/ozone/platform/drm/gpu/gbm_surface_factory.h" |
22 #include "ui/ozone/platform/drm/gpu/gbm_surfaceless.h" | 22 #include "ui/ozone/platform/drm/gpu/gbm_surfaceless.h" |
23 #include "ui/ozone/public/ozone_platform.h" // nogncheck | 23 #include "ui/ozone/public/ozone_platform.h" // nogncheck |
24 #include "ui/ozone/public/surface_factory_ozone.h" | 24 #include "ui/ozone/public/surface_factory_ozone.h" |
25 | 25 |
26 namespace { | |
27 // Optimal format for rendering on overlay. | |
28 const gfx::BufferFormat kOverlayRenderFormat = gfx::BufferFormat::UYVY_422; | |
29 } // namespace | |
30 | |
31 namespace ui { | 26 namespace ui { |
32 | 27 |
33 GbmBuffer::GbmBuffer(const scoped_refptr<GbmDevice>& gbm, | 28 GbmBuffer::GbmBuffer(const scoped_refptr<GbmDevice>& gbm, |
34 gbm_bo* bo, | 29 gbm_bo* bo, |
35 gfx::BufferFormat format, | 30 gfx::BufferFormat format, |
36 gfx::BufferUsage usage) | 31 gfx::BufferUsage usage) |
37 : GbmBufferBase(gbm, bo, format, usage), format_(format), usage_(usage) {} | 32 : GbmBufferBase(gbm, bo, format, usage), format_(format), usage_(usage) {} |
38 | 33 |
39 GbmBuffer::~GbmBuffer() { | 34 GbmBuffer::~GbmBuffer() { |
40 if (bo()) | 35 if (bo()) |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
83 PLOG(ERROR) << "Failed to export buffer to dma_buf"; | 78 PLOG(ERROR) << "Failed to export buffer to dma_buf"; |
84 return false; | 79 return false; |
85 } | 80 } |
86 Initialize(std::move(dma_buf), gbm_bo_get_stride(buffer->bo())); | 81 Initialize(std::move(dma_buf), gbm_bo_get_stride(buffer->bo())); |
87 buffer_ = buffer; | 82 buffer_ = buffer; |
88 return true; | 83 return true; |
89 } | 84 } |
90 | 85 |
91 void GbmPixmap::SetProcessingCallback( | 86 void GbmPixmap::SetProcessingCallback( |
92 const ProcessingCallback& processing_callback) { | 87 const ProcessingCallback& processing_callback) { |
93 processing_callback_ = processing_callback; | 88 processing_callback_ = processing_callback; |
kalyank
2016/01/11 08:19:51
This is called on Main thread while CopyBuffer is
| |
89 copy_buffer_handler_ = base::Bind(&GbmPixmap::CopyBuffer, this); | |
94 } | 90 } |
95 | 91 |
96 scoped_refptr<NativePixmap> GbmPixmap::GetProcessedPixmap( | 92 scoped_refptr<NativePixmap> GbmPixmap::GetProcessedPixmap( |
97 gfx::Size target_size, | 93 gfx::Size target_size, |
98 gfx::BufferFormat target_format) { | 94 gfx::BufferFormat target_format) { |
99 ui::OzonePlatform* platform = ui::OzonePlatform::GetInstance(); | 95 return nullptr; |
kalyank
2016/01/11 08:19:51
This is not used any more. Call to CreateNativePix
dnicoara
2016/01/13 17:26:51
Took a quick look and this isn't used anywhere any
kalyank
2016/01/13 19:52:33
We should be, this is public interface and wasn't
dnicoara
2016/01/13 20:21:53
Acknowledged. Haven't seen any, so lets just remov
kalyank
2016/01/14 06:24:05
k, will post a followup patch for this.
| |
100 ui::SurfaceFactoryOzone* factory = platform->GetSurfaceFactoryOzone(); | |
101 // Create a buffer from Ozone. | |
102 scoped_refptr<ui::NativePixmap> processed_pixmap = | |
103 factory->CreateNativePixmap(gfx::kNullAcceleratedWidget, target_size, | |
104 target_format, gfx::BufferUsage::SCANOUT); | |
105 if (!processed_pixmap) { | |
106 LOG(ERROR) << "Failed creating an Ozone NativePixmap for processing"; | |
107 return nullptr; | |
108 } | |
109 if (!processing_callback_.Run(this, processed_pixmap)) { | |
110 LOG(ERROR) << "Failed processing NativePixmap"; | |
111 return nullptr; | |
112 } | |
113 return processed_pixmap; | |
114 } | 96 } |
115 | 97 |
116 gfx::NativePixmapHandle GbmPixmap::ExportHandle() { | 98 gfx::NativePixmapHandle GbmPixmap::ExportHandle() { |
117 gfx::NativePixmapHandle handle; | 99 gfx::NativePixmapHandle handle; |
118 | 100 |
119 base::ScopedFD dmabuf_fd(HANDLE_EINTR(dup(dma_buf_.get()))); | 101 base::ScopedFD dmabuf_fd(HANDLE_EINTR(dup(dma_buf_.get()))); |
120 if (!dmabuf_fd.is_valid()) { | 102 if (!dmabuf_fd.is_valid()) { |
121 PLOG(ERROR) << "dup"; | 103 PLOG(ERROR) << "dup"; |
122 return handle; | 104 return handle; |
123 } | 105 } |
(...skipping 24 matching lines...) Expand all Loading... | |
148 | 130 |
149 gfx::Size GbmPixmap::GetBufferSize() const { | 131 gfx::Size GbmPixmap::GetBufferSize() const { |
150 return buffer_->GetSize(); | 132 return buffer_->GetSize(); |
151 } | 133 } |
152 | 134 |
153 bool GbmPixmap::ScheduleOverlayPlane(gfx::AcceleratedWidget widget, | 135 bool GbmPixmap::ScheduleOverlayPlane(gfx::AcceleratedWidget widget, |
154 int plane_z_order, | 136 int plane_z_order, |
155 gfx::OverlayTransform plane_transform, | 137 gfx::OverlayTransform plane_transform, |
156 const gfx::Rect& display_bounds, | 138 const gfx::Rect& display_bounds, |
157 const gfx::RectF& crop_rect) { | 139 const gfx::RectF& crop_rect) { |
158 gfx::Size target_size; | |
159 gfx::BufferFormat target_format; | |
160 if (plane_z_order && ShouldApplyProcessing(display_bounds, crop_rect, | |
161 &target_size, &target_format)) { | |
162 scoped_refptr<NativePixmap> processed_pixmap = | |
163 GetProcessedPixmap(target_size, target_format); | |
164 if (processed_pixmap) { | |
165 return processed_pixmap->ScheduleOverlayPlane( | |
166 widget, plane_z_order, plane_transform, display_bounds, crop_rect); | |
167 } else { | |
168 return false; | |
169 } | |
170 } | |
171 | |
172 // TODO(reveman): Add support for imported buffers. crbug.com/541558 | 140 // TODO(reveman): Add support for imported buffers. crbug.com/541558 |
173 if (!buffer_) { | 141 if (!buffer_) { |
174 PLOG(ERROR) << "ScheduleOverlayPlane requires a buffer."; | 142 PLOG(ERROR) << "ScheduleOverlayPlane requires a buffer."; |
175 return false; | 143 return false; |
176 } | 144 } |
177 | 145 |
178 DCHECK(buffer_->GetUsage() == gfx::BufferUsage::SCANOUT); | 146 DCHECK(buffer_->GetUsage() == gfx::BufferUsage::SCANOUT); |
179 surface_manager_->GetSurface(widget)->QueueOverlayPlane(OverlayPlane( | 147 |
180 buffer_, plane_z_order, plane_transform, display_bounds, crop_rect)); | 148 surface_manager_->GetSurface(widget)->QueueOverlayPlane( |
149 OverlayPlane(buffer_, plane_z_order, plane_transform, display_bounds, | |
150 crop_rect, copy_buffer_handler_)); | |
151 | |
181 return true; | 152 return true; |
182 } | 153 } |
183 | 154 |
184 bool GbmPixmap::ShouldApplyProcessing(const gfx::Rect& display_bounds, | 155 bool GbmPixmap::CopyBuffer(const scoped_refptr<ScanoutBuffer>& source_buffer, |
185 const gfx::RectF& crop_rect, | 156 scoped_refptr<ScanoutBuffer>& target_buffer) { |
186 gfx::Size* target_size, | 157 DCHECK(source_buffer->GetHandle() == buffer_->GetHandle()); |
kalyank
2016/01/11 08:19:51
This will be called in Drmthread by OverlayValidat
dnicoara
2016/01/13 17:26:51
Perhaps add some comments explaining this since it
kalyank
2016/01/13 19:52:33
Done.
| |
187 gfx::BufferFormat* target_format) { | 158 ui::OzonePlatform* platform = ui::OzonePlatform::GetInstance(); |
188 if (crop_rect.width() == 0 || crop_rect.height() == 0) { | 159 ui::SurfaceFactoryOzone* factory = platform->GetSurfaceFactoryOzone(); |
dnicoara
2016/01/13 17:26:51
You could just drop this since this is |surface_ma
kalyank
2016/01/13 19:52:33
Done.
| |
189 PLOG(ERROR) << "ShouldApplyProcessing passed zero processing target."; | 160 scoped_refptr<GbmPixmap> pixmap( |
161 new GbmPixmap(static_cast<GbmSurfaceFactory*>(factory))); | |
162 | |
163 scoped_refptr<GbmBuffer> gbm_buffer( | |
164 static_cast<GbmBuffer*>(target_buffer.get())); | |
165 | |
166 if (!pixmap->InitializeFromBuffer(gbm_buffer)) | |
167 return false; | |
168 | |
169 DCHECK(!processing_callback_.is_null()); | |
170 DCHECK(GetBufferSize() != pixmap->GetBufferSize() || | |
171 GetBufferFormat() != pixmap->GetBufferFormat()); | |
172 | |
173 if (!processing_callback_.Run(this, pixmap)) { | |
174 LOG(ERROR) << "Failed processing NativePixmap"; | |
190 return false; | 175 return false; |
191 } | 176 } |
192 | 177 |
193 if (!buffer_) { | 178 return true; |
194 PLOG(ERROR) << "ShouldApplyProcessing requires a buffer."; | |
195 return false; | |
196 } | |
197 | |
198 // TODO(william.xie): Figure out the optimal render format for overlay. | |
199 // See http://crbug.com/553264. | |
200 *target_format = kOverlayRenderFormat; | |
201 gfx::Size pixmap_size = buffer_->GetSize(); | |
202 // If the required size is not integer-sized, round it to the next integer. | |
203 *target_size = gfx::ToCeiledSize( | |
204 gfx::SizeF(display_bounds.width() / crop_rect.width(), | |
205 display_bounds.height() / crop_rect.height())); | |
206 | |
207 return pixmap_size != *target_size || GetBufferFormat() != *target_format; | |
208 } | 179 } |
209 | 180 |
210 } // namespace ui | 181 } // namespace ui |
OLD | NEW |