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

Side by Side Diff: ui/ozone/platform/drm/gpu/gbm_buffer.cc

Issue 1422563002: [Ozone] Enables overlay render format setting path and by default use UYVY (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 1 month 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
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>
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
23 namespace ui { 28 namespace ui {
24 29
25 GbmBuffer::GbmBuffer(const scoped_refptr<GbmDevice>& gbm, 30 GbmBuffer::GbmBuffer(const scoped_refptr<GbmDevice>& gbm,
26 gbm_bo* bo, 31 gbm_bo* bo,
27 gfx::BufferUsage usage) 32 gfx::BufferUsage usage)
28 : GbmBufferBase(gbm, bo, usage == gfx::BufferUsage::SCANOUT), 33 : GbmBufferBase(gbm, bo, usage == gfx::BufferUsage::SCANOUT),
29 usage_(usage) {} 34 usage_(usage) {}
30 35
31 GbmBuffer::~GbmBuffer() { 36 GbmBuffer::~GbmBuffer() {
32 if (bo()) 37 if (bo())
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 base::ScopedFD dma_buf(gbm_bo_get_fd(buffer->bo())); 78 base::ScopedFD dma_buf(gbm_bo_get_fd(buffer->bo()));
74 if (!dma_buf.is_valid()) { 79 if (!dma_buf.is_valid()) {
75 PLOG(ERROR) << "Failed to export buffer to dma_buf"; 80 PLOG(ERROR) << "Failed to export buffer to dma_buf";
76 return false; 81 return false;
77 } 82 }
78 Initialize(dma_buf.Pass(), gbm_bo_get_stride(buffer->bo())); 83 Initialize(dma_buf.Pass(), gbm_bo_get_stride(buffer->bo()));
79 buffer_ = buffer; 84 buffer_ = buffer;
80 return true; 85 return true;
81 } 86 }
82 87
83 void GbmPixmap::SetScalingCallback(const ScalingCallback& scaling_callback) { 88 void GbmPixmap::SetProcessingCallback(
84 scaling_callback_ = scaling_callback; 89 const ProcessingCallback& processing_callback) {
90 processing_callback_ = processing_callback;
85 } 91 }
86 92
87 scoped_refptr<NativePixmap> GbmPixmap::GetScaledPixmap(gfx::Size new_size) { 93 scoped_refptr<NativePixmap> GbmPixmap::GetProcessedPixmap(
88 return scaling_callback_.Run(new_size); 94 gfx::Size target_size,
95 gfx::BufferFormat target_format) {
96 return processing_callback_.Run(target_size, target_format);
89 } 97 }
90 98
91 gfx::NativePixmapHandle GbmPixmap::ExportHandle() { 99 gfx::NativePixmapHandle GbmPixmap::ExportHandle() {
92 gfx::NativePixmapHandle handle; 100 gfx::NativePixmapHandle handle;
93 101
94 base::ScopedFD dmabuf_fd(HANDLE_EINTR(dup(dma_buf_.get()))); 102 base::ScopedFD dmabuf_fd(HANDLE_EINTR(dup(dma_buf_.get())));
95 if (!dmabuf_fd.is_valid()) { 103 if (!dmabuf_fd.is_valid()) {
96 PLOG(ERROR) << "dup"; 104 PLOG(ERROR) << "dup";
97 return handle; 105 return handle;
98 } 106 }
(...skipping 11 matching lines...) Expand all
110 } 118 }
111 119
112 int GbmPixmap::GetDmaBufFd() { 120 int GbmPixmap::GetDmaBufFd() {
113 return dma_buf_.get(); 121 return dma_buf_.get();
114 } 122 }
115 123
116 int GbmPixmap::GetDmaBufPitch() { 124 int GbmPixmap::GetDmaBufPitch() {
117 return dma_buf_pitch_; 125 return dma_buf_pitch_;
118 } 126 }
119 127
128 gfx::BufferFormat GbmPixmap::GetBufferFormat() {
129 return GetBufferFormatFromFourCCFormat(buffer_->GetFramebufferPixelFormat());
130 }
131
120 bool GbmPixmap::ScheduleOverlayPlane(gfx::AcceleratedWidget widget, 132 bool GbmPixmap::ScheduleOverlayPlane(gfx::AcceleratedWidget widget,
121 int plane_z_order, 133 int plane_z_order,
122 gfx::OverlayTransform plane_transform, 134 gfx::OverlayTransform plane_transform,
123 const gfx::Rect& display_bounds, 135 const gfx::Rect& display_bounds,
124 const gfx::RectF& crop_rect) { 136 const gfx::RectF& crop_rect) {
125 gfx::Size required_size; 137 gfx::Size target_size;
126 if (plane_z_order && 138 gfx::BufferFormat target_format;
127 ShouldApplyScaling(display_bounds, crop_rect, &required_size)) { 139 if (plane_z_order && ShouldApplyProcessing(display_bounds, crop_rect,
128 scoped_refptr<NativePixmap> scaled_pixmap = GetScaledPixmap(required_size); 140 &target_size, &target_format)) {
129 if (scaled_pixmap) { 141 scoped_refptr<NativePixmap> processed_pixmap =
130 return scaled_pixmap->ScheduleOverlayPlane( 142 GetProcessedPixmap(target_size, target_format);
143 if (processed_pixmap) {
144 return processed_pixmap->ScheduleOverlayPlane(
131 widget, plane_z_order, plane_transform, display_bounds, crop_rect); 145 widget, plane_z_order, plane_transform, display_bounds, crop_rect);
132 } else { 146 } else {
133 return false; 147 return false;
134 } 148 }
135 } 149 }
136 150
137 // TODO(reveman): Add support for imported buffers. crbug.com/541558 151 // TODO(reveman): Add support for imported buffers. crbug.com/541558
138 if (!buffer_) { 152 if (!buffer_) {
139 PLOG(ERROR) << "ScheduleOverlayPlane requires a buffer."; 153 PLOG(ERROR) << "ScheduleOverlayPlane requires a buffer.";
140 return false; 154 return false;
141 } 155 }
142 156
143 DCHECK(buffer_->GetUsage() == gfx::BufferUsage::SCANOUT); 157 DCHECK(buffer_->GetUsage() == gfx::BufferUsage::SCANOUT);
144 surface_manager_->GetSurface(widget)->QueueOverlayPlane(OverlayPlane( 158 surface_manager_->GetSurface(widget)->QueueOverlayPlane(OverlayPlane(
145 buffer_, plane_z_order, plane_transform, display_bounds, crop_rect)); 159 buffer_, plane_z_order, plane_transform, display_bounds, crop_rect));
146 return true; 160 return true;
147 } 161 }
148 162
149 bool GbmPixmap::ShouldApplyScaling(const gfx::Rect& display_bounds, 163 bool GbmPixmap::ShouldApplyProcessing(const gfx::Rect& display_bounds,
150 const gfx::RectF& crop_rect, 164 const gfx::RectF& crop_rect,
151 gfx::Size* required_size) { 165 gfx::Size* target_size,
166 gfx::BufferFormat* target_format) {
152 if (crop_rect.width() == 0 || crop_rect.height() == 0) { 167 if (crop_rect.width() == 0 || crop_rect.height() == 0) {
153 PLOG(ERROR) << "ShouldApplyScaling passed zero scaling target."; 168 PLOG(ERROR) << "ShouldApplyProcessing passed zero processing target.";
154 return false; 169 return false;
155 } 170 }
156 171
157 if (!buffer_) { 172 if (!buffer_) {
158 PLOG(ERROR) << "ShouldApplyScaling requires a buffer."; 173 PLOG(ERROR) << "ShouldApplyProcessing requires a buffer.";
159 return false; 174 return false;
160 } 175 }
161 176
177 // TODO(william.xie): Figure out the optimal render format for overlay.
178 // See http://crbug.com/553264.
179 *target_format = kOverlayRenderFormat;
162 gfx::Size pixmap_size = buffer_->GetSize(); 180 gfx::Size pixmap_size = buffer_->GetSize();
163 // If the required size is not integer-sized, round it to the next integer. 181 // If the required size is not integer-sized, round it to the next integer.
164 *required_size = gfx::ToCeiledSize( 182 *target_size = gfx::ToCeiledSize(
165 gfx::SizeF(display_bounds.width() / crop_rect.width(), 183 gfx::SizeF(display_bounds.width() / crop_rect.width(),
166 display_bounds.height() / crop_rect.height())); 184 display_bounds.height() / crop_rect.height()));
167 return pixmap_size != *required_size; 185
186 return pixmap_size != *target_size || GetBufferFormat() != *target_format;
168 } 187 }
169 188
170 } // namespace ui 189 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698