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 | 22 |
23 namespace { | |
24 // Optimal format for rendering on overlay. | |
25 const gfx::BufferFormat kOverlayRenderFormat = gfx::BufferFormat::UYVY_422; | |
26 } // namespace | |
27 | |
28 namespace ui { | 23 namespace ui { |
29 | 24 |
30 GbmBuffer::GbmBuffer(const scoped_refptr<GbmDevice>& gbm, | 25 GbmBuffer::GbmBuffer(const scoped_refptr<GbmDevice>& gbm, |
31 gbm_bo* bo, | 26 gbm_bo* bo, |
32 gfx::BufferUsage usage) | 27 gfx::BufferUsage usage) |
33 : GbmBufferBase(gbm, bo, usage == gfx::BufferUsage::SCANOUT), | 28 : GbmBufferBase(gbm, bo, usage == gfx::BufferUsage::SCANOUT), |
34 usage_(usage) {} | 29 usage_(usage) {} |
35 | 30 |
36 GbmBuffer::~GbmBuffer() { | 31 GbmBuffer::~GbmBuffer() { |
37 if (bo()) | 32 if (bo()) |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 | 122 |
128 gfx::BufferFormat GbmPixmap::GetBufferFormat() { | 123 gfx::BufferFormat GbmPixmap::GetBufferFormat() { |
129 return GetBufferFormatFromFourCCFormat(buffer_->GetFramebufferPixelFormat()); | 124 return GetBufferFormatFromFourCCFormat(buffer_->GetFramebufferPixelFormat()); |
130 } | 125 } |
131 | 126 |
132 bool GbmPixmap::ScheduleOverlayPlane(gfx::AcceleratedWidget widget, | 127 bool GbmPixmap::ScheduleOverlayPlane(gfx::AcceleratedWidget widget, |
133 int plane_z_order, | 128 int plane_z_order, |
134 gfx::OverlayTransform plane_transform, | 129 gfx::OverlayTransform plane_transform, |
135 const gfx::Rect& display_bounds, | 130 const gfx::Rect& display_bounds, |
136 const gfx::RectF& crop_rect) { | 131 const gfx::RectF& crop_rect) { |
137 gfx::Size target_size; | 132 GbmSurfaceless* surface = surface_manager_->GetSurface(widget); |
138 gfx::BufferFormat target_format; | 133 if (plane_z_order) { |
139 if (plane_z_order && ShouldApplyProcessing(display_bounds, crop_rect, | 134 gfx::Size target_size; |
140 &target_size, &target_format)) { | 135 gfx::BufferFormat target_format; |
141 scoped_refptr<NativePixmap> processed_pixmap = | 136 gfx::BufferFormat format = GetBufferFormat(); |
142 GetProcessedPixmap(target_size, target_format); | 137 surface->EvaluateBufferConfiguration( |
143 if (processed_pixmap) { | 138 display_bounds, crop_rect, buffer_->GetSize(), format, plane_transform, |
144 return processed_pixmap->ScheduleOverlayPlane( | 139 plane_z_order, &target_size, &target_format); |
145 widget, plane_z_order, plane_transform, display_bounds, crop_rect); | 140 if (target_size != buffer_->GetSize() || format != target_format) { |
146 } else { | 141 scoped_refptr<NativePixmap> processed_pixmap = |
147 return false; | 142 GetProcessedPixmap(target_size, target_format); |
| 143 if (processed_pixmap) { |
| 144 return processed_pixmap->ScheduleOverlayPlane( |
| 145 widget, plane_z_order, plane_transform, display_bounds, crop_rect); |
| 146 } else { |
| 147 return false; |
| 148 } |
148 } | 149 } |
149 } | 150 } |
150 | 151 |
151 // TODO(reveman): Add support for imported buffers. crbug.com/541558 | 152 // TODO(reveman): Add support for imported buffers. crbug.com/541558 |
152 if (!buffer_) { | 153 if (!buffer_) { |
153 PLOG(ERROR) << "ScheduleOverlayPlane requires a buffer."; | 154 PLOG(ERROR) << "ScheduleOverlayPlane requires a buffer."; |
154 return false; | 155 return false; |
155 } | 156 } |
156 | 157 |
157 DCHECK(buffer_->GetUsage() == gfx::BufferUsage::SCANOUT); | 158 DCHECK(buffer_->GetUsage() == gfx::BufferUsage::SCANOUT); |
158 surface_manager_->GetSurface(widget)->QueueOverlayPlane(OverlayPlane( | 159 surface->QueueOverlayPlane(OverlayPlane( |
159 buffer_, plane_z_order, plane_transform, display_bounds, crop_rect)); | 160 buffer_, plane_z_order, plane_transform, display_bounds, crop_rect)); |
160 return true; | 161 return true; |
161 } | 162 } |
162 | 163 |
163 bool GbmPixmap::ShouldApplyProcessing(const gfx::Rect& display_bounds, | |
164 const gfx::RectF& crop_rect, | |
165 gfx::Size* target_size, | |
166 gfx::BufferFormat* target_format) { | |
167 if (crop_rect.width() == 0 || crop_rect.height() == 0) { | |
168 PLOG(ERROR) << "ShouldApplyProcessing passed zero processing target."; | |
169 return false; | |
170 } | |
171 | |
172 if (!buffer_) { | |
173 PLOG(ERROR) << "ShouldApplyProcessing requires a buffer."; | |
174 return false; | |
175 } | |
176 | |
177 // TODO(william.xie): Figure out the optimal render format for overlay. | |
178 // See http://crbug.com/553264. | |
179 *target_format = kOverlayRenderFormat; | |
180 gfx::Size pixmap_size = buffer_->GetSize(); | |
181 // If the required size is not integer-sized, round it to the next integer. | |
182 *target_size = gfx::ToCeiledSize( | |
183 gfx::SizeF(display_bounds.width() / crop_rect.width(), | |
184 display_bounds.height() / crop_rect.height())); | |
185 | |
186 return pixmap_size != *target_size || GetBufferFormat() != *target_format; | |
187 } | |
188 | |
189 } // namespace ui | 164 } // namespace ui |
OLD | NEW |