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 | 11 |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/posix/eintr_wrapper.h" | 13 #include "base/posix/eintr_wrapper.h" |
14 #include "base/trace_event/trace_event.h" | 14 #include "base/trace_event/trace_event.h" |
15 #include "ui/gfx/geometry/size_conversions.h" | 15 #include "ui/gfx/geometry/size_conversions.h" |
16 #include "ui/gfx/native_pixmap_handle_ozone.h" | 16 #include "ui/gfx/native_pixmap_handle_ozone.h" |
17 #include "ui/ozone/platform/drm/common/drm_util.h" | 17 #include "ui/ozone/platform/drm/common/drm_util.h" |
18 #include "ui/ozone/platform/drm/gpu/drm_window.h" | 18 #include "ui/ozone/platform/drm/gpu/drm_window.h" |
19 #include "ui/ozone/platform/drm/gpu/gbm_device.h" | 19 #include "ui/ozone/platform/drm/gpu/gbm_device.h" |
20 #include "ui/ozone/platform/drm/gpu/gbm_surface_factory.h" | 20 #include "ui/ozone/platform/drm/gpu/gbm_surface_factory.h" |
21 #include "ui/ozone/platform/drm/gpu/gbm_surfaceless.h" | 21 #include "ui/ozone/platform/drm/gpu/gbm_surfaceless.h" |
22 #include "ui/ozone/public/ozone_platform.h" | 22 #include "ui/ozone/public/ozone_platform.h" |
23 #include "ui/ozone/public/surface_factory_ozone.h" | 23 #include "ui/ozone/public/surface_factory_ozone.h" |
24 | 24 |
25 namespace { | |
26 // Optimal format for rendering on overlay. | |
27 const gfx::BufferFormat kOverlayRenderFormat = gfx::BufferFormat::UYVY_422; | |
28 } // namespace | |
29 | |
30 namespace ui { | 25 namespace ui { |
31 | 26 |
32 GbmBuffer::GbmBuffer(const scoped_refptr<GbmDevice>& gbm, | 27 GbmBuffer::GbmBuffer(const scoped_refptr<GbmDevice>& gbm, |
33 gbm_bo* bo, | 28 gbm_bo* bo, |
34 gfx::BufferUsage usage) | 29 gfx::BufferUsage usage) |
35 : GbmBufferBase(gbm, bo, usage == gfx::BufferUsage::SCANOUT), | 30 : GbmBufferBase(gbm, bo, usage == gfx::BufferUsage::SCANOUT), |
36 usage_(usage) {} | 31 usage_(usage) {} |
37 | 32 |
38 GbmBuffer::~GbmBuffer() { | 33 GbmBuffer::~GbmBuffer() { |
39 if (bo()) | 34 if (bo()) |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 return GetBufferFormatFromFourCCFormat(buffer_->GetFramebufferPixelFormat()); | 140 return GetBufferFormatFromFourCCFormat(buffer_->GetFramebufferPixelFormat()); |
146 } | 141 } |
147 | 142 |
148 gfx::Size GbmPixmap::GetBufferSize() const { | 143 gfx::Size GbmPixmap::GetBufferSize() const { |
149 return buffer_->GetSize(); | 144 return buffer_->GetSize(); |
150 } | 145 } |
151 | 146 |
152 bool GbmPixmap::ScheduleOverlayPlane(gfx::AcceleratedWidget widget, | 147 bool GbmPixmap::ScheduleOverlayPlane(gfx::AcceleratedWidget widget, |
153 int plane_z_order, | 148 int plane_z_order, |
154 gfx::OverlayTransform plane_transform, | 149 gfx::OverlayTransform plane_transform, |
| 150 gfx::BufferFormat storage_format, |
155 const gfx::Rect& display_bounds, | 151 const gfx::Rect& display_bounds, |
156 const gfx::RectF& crop_rect) { | 152 const gfx::RectF& crop_rect, |
157 gfx::Size target_size; | 153 bool handle_scaling) { |
158 gfx::BufferFormat target_format; | 154 if (plane_z_order) { |
159 if (plane_z_order && ShouldApplyProcessing(display_bounds, crop_rect, | 155 gfx::Size target_size = buffer_->GetSize(); |
160 &target_size, &target_format)) { | 156 gfx::BufferFormat current_format = |
161 scoped_refptr<NativePixmap> processed_pixmap = | 157 GetBufferFormatFromFourCCFormat(buffer_->GetFramebufferPixelFormat()); |
162 GetProcessedPixmap(target_size, target_format); | 158 if (current_format != storage_format || |
163 if (processed_pixmap) { | 159 (handle_scaling && |
164 return processed_pixmap->ScheduleOverlayPlane( | 160 ShouldScaleContent(display_bounds, crop_rect, &target_size))) { |
165 widget, plane_z_order, plane_transform, display_bounds, crop_rect); | 161 scoped_refptr<NativePixmap> processed_pixmap = |
166 } else { | 162 GetProcessedPixmap(target_size, storage_format); |
167 return false; | 163 if (processed_pixmap) { |
| 164 return processed_pixmap->ScheduleOverlayPlane( |
| 165 widget, plane_z_order, plane_transform, storage_format, |
| 166 display_bounds, crop_rect, handle_scaling); |
| 167 } else { |
| 168 return false; |
| 169 } |
168 } | 170 } |
169 } | 171 } |
170 | 172 |
171 // TODO(reveman): Add support for imported buffers. crbug.com/541558 | 173 // TODO(reveman): Add support for imported buffers. crbug.com/541558 |
172 if (!buffer_) { | 174 if (!buffer_) { |
173 PLOG(ERROR) << "ScheduleOverlayPlane requires a buffer."; | 175 PLOG(ERROR) << "ScheduleOverlayPlane requires a buffer."; |
174 return false; | 176 return false; |
175 } | 177 } |
176 | 178 |
177 DCHECK(buffer_->GetUsage() == gfx::BufferUsage::SCANOUT); | 179 DCHECK(buffer_->GetUsage() == gfx::BufferUsage::SCANOUT); |
178 surface_manager_->GetSurface(widget)->QueueOverlayPlane(OverlayPlane( | 180 surface_manager_->GetSurface(widget)->QueueOverlayPlane(OverlayPlane( |
179 buffer_, plane_z_order, plane_transform, display_bounds, crop_rect)); | 181 buffer_, plane_z_order, plane_transform, display_bounds, crop_rect)); |
180 return true; | 182 return true; |
181 } | 183 } |
182 | 184 |
183 bool GbmPixmap::ShouldApplyProcessing(const gfx::Rect& display_bounds, | 185 bool GbmPixmap::ShouldScaleContent(const gfx::Rect& display_bounds, |
184 const gfx::RectF& crop_rect, | 186 const gfx::RectF& crop_rect, |
185 gfx::Size* target_size, | 187 gfx::Size* target_size) { |
186 gfx::BufferFormat* target_format) { | |
187 if (crop_rect.width() == 0 || crop_rect.height() == 0) { | 188 if (crop_rect.width() == 0 || crop_rect.height() == 0) { |
188 PLOG(ERROR) << "ShouldApplyProcessing passed zero processing target."; | 189 PLOG(ERROR) << "ShouldApplyProcessing passed zero processing target."; |
189 return false; | 190 return false; |
190 } | 191 } |
191 | 192 |
192 if (!buffer_) { | 193 if (!buffer_) { |
193 PLOG(ERROR) << "ShouldApplyProcessing requires a buffer."; | 194 PLOG(ERROR) << "ShouldApplyProcessing requires a buffer."; |
194 return false; | 195 return false; |
195 } | 196 } |
196 | 197 |
197 // TODO(william.xie): Figure out the optimal render format for overlay. | |
198 // See http://crbug.com/553264. | |
199 *target_format = kOverlayRenderFormat; | |
200 gfx::Size pixmap_size = buffer_->GetSize(); | 198 gfx::Size pixmap_size = buffer_->GetSize(); |
201 // If the required size is not integer-sized, round it to the next integer. | 199 // If the required size is not integer-sized, round it to the next integer. |
202 *target_size = gfx::ToCeiledSize( | 200 *target_size = gfx::ToCeiledSize( |
203 gfx::SizeF(display_bounds.width() / crop_rect.width(), | 201 gfx::SizeF(display_bounds.width() / crop_rect.width(), |
204 display_bounds.height() / crop_rect.height())); | 202 display_bounds.height() / crop_rect.height())); |
205 | 203 |
206 return pixmap_size != *target_size || GetBufferFormat() != *target_format; | 204 return pixmap_size != *target_size; |
207 } | 205 } |
208 | 206 |
209 } // namespace ui | 207 } // namespace ui |
OLD | NEW |