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 // Optimal format for rendering on overlay. | |
24 const gfx::BufferFormat kOverlayRenderFormat = gfx::BufferFormat::UYVY_422; | |
Pawel Osciak
2015/11/09 03:52:06
Please use an anonymous namespace.
william.xie1
2015/11/09 04:58:01
Done.
| |
25 | |
23 namespace ui { | 26 namespace ui { |
24 | 27 |
25 GbmBuffer::GbmBuffer(const scoped_refptr<GbmDevice>& gbm, | 28 GbmBuffer::GbmBuffer(const scoped_refptr<GbmDevice>& gbm, |
26 gbm_bo* bo, | 29 gbm_bo* bo, |
27 gfx::BufferUsage usage) | 30 gfx::BufferUsage usage) |
28 : GbmBufferBase(gbm, | 31 : GbmBufferBase(gbm, |
29 bo, | 32 bo, |
30 usage == gfx::BufferUsage::GPU_READ || | 33 usage == gfx::BufferUsage::GPU_READ || |
31 usage == gfx::BufferUsage::GPU_READ_WRITE), | 34 usage == gfx::BufferUsage::GPU_READ_WRITE), |
32 usage_(usage) {} | 35 usage_(usage) {} |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
78 base::ScopedFD dma_buf(gbm_bo_get_fd(buffer->bo())); | 81 base::ScopedFD dma_buf(gbm_bo_get_fd(buffer->bo())); |
79 if (!dma_buf.is_valid()) { | 82 if (!dma_buf.is_valid()) { |
80 PLOG(ERROR) << "Failed to export buffer to dma_buf"; | 83 PLOG(ERROR) << "Failed to export buffer to dma_buf"; |
81 return false; | 84 return false; |
82 } | 85 } |
83 Initialize(dma_buf.Pass(), gbm_bo_get_stride(buffer->bo())); | 86 Initialize(dma_buf.Pass(), gbm_bo_get_stride(buffer->bo())); |
84 buffer_ = buffer; | 87 buffer_ = buffer; |
85 return true; | 88 return true; |
86 } | 89 } |
87 | 90 |
88 void GbmPixmap::SetScalingCallback(const ScalingCallback& scaling_callback) { | 91 void GbmPixmap::SetProcessingCallback( |
89 scaling_callback_ = scaling_callback; | 92 const ProcessingCallback& processing_callback) { |
93 processing_callback_ = processing_callback; | |
90 } | 94 } |
91 | 95 |
92 scoped_refptr<NativePixmap> GbmPixmap::GetScaledPixmap(gfx::Size new_size) { | 96 scoped_refptr<NativePixmap> GbmPixmap::GetProcessedPixmap( |
93 return scaling_callback_.Run(new_size); | 97 gfx::Size target_size, |
98 gfx::BufferFormat target_format) { | |
99 return processing_callback_.Run(target_size, target_format); | |
94 } | 100 } |
95 | 101 |
96 gfx::NativePixmapHandle GbmPixmap::ExportHandle() { | 102 gfx::NativePixmapHandle GbmPixmap::ExportHandle() { |
97 gfx::NativePixmapHandle handle; | 103 gfx::NativePixmapHandle handle; |
98 | 104 |
99 base::ScopedFD dmabuf_fd(HANDLE_EINTR(dup(dma_buf_.get()))); | 105 base::ScopedFD dmabuf_fd(HANDLE_EINTR(dup(dma_buf_.get()))); |
100 if (!dmabuf_fd.is_valid()) { | 106 if (!dmabuf_fd.is_valid()) { |
101 PLOG(ERROR) << "dup"; | 107 PLOG(ERROR) << "dup"; |
102 return handle; | 108 return handle; |
103 } | 109 } |
(...skipping 11 matching lines...) Expand all Loading... | |
115 } | 121 } |
116 | 122 |
117 int GbmPixmap::GetDmaBufFd() { | 123 int GbmPixmap::GetDmaBufFd() { |
118 return dma_buf_.get(); | 124 return dma_buf_.get(); |
119 } | 125 } |
120 | 126 |
121 int GbmPixmap::GetDmaBufPitch() { | 127 int GbmPixmap::GetDmaBufPitch() { |
122 return dma_buf_pitch_; | 128 return dma_buf_pitch_; |
123 } | 129 } |
124 | 130 |
131 gfx::BufferFormat GbmPixmap::GetBufferFormat() { | |
132 return GetBufferFormatFromFourCCFormat(buffer_->GetFramebufferPixelFormat()); | |
133 } | |
134 | |
125 bool GbmPixmap::ScheduleOverlayPlane(gfx::AcceleratedWidget widget, | 135 bool GbmPixmap::ScheduleOverlayPlane(gfx::AcceleratedWidget widget, |
126 int plane_z_order, | 136 int plane_z_order, |
127 gfx::OverlayTransform plane_transform, | 137 gfx::OverlayTransform plane_transform, |
128 const gfx::Rect& display_bounds, | 138 const gfx::Rect& display_bounds, |
129 const gfx::RectF& crop_rect) { | 139 const gfx::RectF& crop_rect) { |
130 gfx::Size required_size; | 140 gfx::Size target_size; |
131 if (plane_z_order && | 141 gfx::BufferFormat target_format; |
132 ShouldApplyScaling(display_bounds, crop_rect, &required_size)) { | 142 if (plane_z_order && ShouldApplyProcessing(display_bounds, crop_rect, |
133 scoped_refptr<NativePixmap> scaled_pixmap = GetScaledPixmap(required_size); | 143 &target_size, &target_format)) { |
134 if (scaled_pixmap) { | 144 scoped_refptr<NativePixmap> processed_pixmap = |
135 return scaled_pixmap->ScheduleOverlayPlane( | 145 GetProcessedPixmap(target_size, target_format); |
146 if (processed_pixmap) { | |
147 return processed_pixmap->ScheduleOverlayPlane( | |
136 widget, plane_z_order, plane_transform, display_bounds, crop_rect); | 148 widget, plane_z_order, plane_transform, display_bounds, crop_rect); |
137 } else { | 149 } else { |
138 return false; | 150 return false; |
139 } | 151 } |
140 } | 152 } |
141 | 153 |
142 // TODO(reveman): Add support for imported buffers. crbug.com/541558 | 154 // TODO(reveman): Add support for imported buffers. crbug.com/541558 |
143 if (!buffer_) { | 155 if (!buffer_) { |
144 PLOG(ERROR) << "ScheduleOverlayPlane requires a buffer."; | 156 PLOG(ERROR) << "ScheduleOverlayPlane requires a buffer."; |
145 return false; | 157 return false; |
146 } | 158 } |
147 | 159 |
148 DCHECK(buffer_->GetUsage() == gfx::BufferUsage::GPU_READ || | 160 DCHECK(buffer_->GetUsage() == gfx::BufferUsage::GPU_READ || |
149 buffer_->GetUsage() == gfx::BufferUsage::GPU_READ_WRITE); | 161 buffer_->GetUsage() == gfx::BufferUsage::GPU_READ_WRITE); |
150 surface_manager_->GetSurface(widget)->QueueOverlayPlane(OverlayPlane( | 162 surface_manager_->GetSurface(widget)->QueueOverlayPlane(OverlayPlane( |
151 buffer_, plane_z_order, plane_transform, display_bounds, crop_rect)); | 163 buffer_, plane_z_order, plane_transform, display_bounds, crop_rect)); |
152 return true; | 164 return true; |
153 } | 165 } |
154 | 166 |
155 bool GbmPixmap::ShouldApplyScaling(const gfx::Rect& display_bounds, | 167 bool GbmPixmap::ShouldApplyProcessing(const gfx::Rect& display_bounds, |
156 const gfx::RectF& crop_rect, | 168 const gfx::RectF& crop_rect, |
157 gfx::Size* required_size) { | 169 gfx::Size* target_size, |
170 gfx::BufferFormat* target_format) { | |
158 if (crop_rect.width() == 0 || crop_rect.height() == 0) { | 171 if (crop_rect.width() == 0 || crop_rect.height() == 0) { |
159 PLOG(ERROR) << "ShouldApplyScaling passed zero scaling target."; | 172 PLOG(ERROR) << "ShouldApplyProcessing passed zero processing target."; |
160 return false; | 173 return false; |
161 } | 174 } |
162 | 175 |
163 if (!buffer_) { | 176 if (!buffer_) { |
164 PLOG(ERROR) << "ShouldApplyScaling requires a buffer."; | 177 PLOG(ERROR) << "ShouldApplyProcessing requires a buffer."; |
165 return false; | 178 return false; |
166 } | 179 } |
167 | 180 |
181 // TODO(william.xie): Figure out the optimal render format for overlay. | |
Pawel Osciak
2015/11/09 03:52:06
Could you please submit a crbug.com for this and p
| |
182 *target_format = kOverlayRenderFormat; | |
168 gfx::Size pixmap_size = buffer_->GetSize(); | 183 gfx::Size pixmap_size = buffer_->GetSize(); |
169 // If the required size is not integer-sized, round it to the next integer. | 184 // If the required size is not integer-sized, round it to the next integer. |
170 *required_size = gfx::ToCeiledSize( | 185 *target_size = gfx::ToCeiledSize( |
171 gfx::SizeF(display_bounds.width() / crop_rect.width(), | 186 gfx::SizeF(display_bounds.width() / crop_rect.width(), |
172 display_bounds.height() / crop_rect.height())); | 187 display_bounds.height() / crop_rect.height())); |
173 return pixmap_size != *required_size; | 188 |
189 return pixmap_size != *target_size || GetBufferFormat() != *target_format; | |
174 } | 190 } |
175 | 191 |
176 } // namespace ui | 192 } // namespace ui |
OLD | NEW |