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/gpu/drm_thread.h" | |
17 #include "ui/ozone/platform/drm/gpu/drm_window.h" | 18 #include "ui/ozone/platform/drm/gpu/drm_window.h" |
18 #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/proxy_helpers.h" | |
19 | 21 |
20 namespace ui { | 22 namespace ui { |
21 | 23 |
22 namespace { | 24 namespace { |
23 | 25 |
24 int GetGbmFormatFromBufferFormat(gfx::BufferFormat fmt) { | 26 int GetGbmFormatFromBufferFormat(gfx::BufferFormat fmt) { |
25 switch (fmt) { | 27 switch (fmt) { |
26 case gfx::BufferFormat::BGRA_8888: | 28 case gfx::BufferFormat::BGRA_8888: |
27 return GBM_FORMAT_ARGB8888; | 29 return GBM_FORMAT_ARGB8888; |
28 case gfx::BufferFormat::BGRX_8888: | 30 case gfx::BufferFormat::BGRX_8888: |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
65 return nullptr; | 67 return nullptr; |
66 | 68 |
67 scoped_refptr<GbmBuffer> buffer(new GbmBuffer(gbm, bo, usage)); | 69 scoped_refptr<GbmBuffer> buffer(new GbmBuffer(gbm, bo, usage)); |
68 if (use_scanout && !buffer->GetFramebufferId()) | 70 if (use_scanout && !buffer->GetFramebufferId()) |
69 return nullptr; | 71 return nullptr; |
70 | 72 |
71 return buffer; | 73 return buffer; |
72 } | 74 } |
73 | 75 |
74 GbmPixmap::GbmPixmap(const scoped_refptr<GbmBuffer>& buffer, | 76 GbmPixmap::GbmPixmap(const scoped_refptr<GbmBuffer>& buffer, |
75 ScreenManager* screen_manager) | 77 DrmThread* drm_thread) |
76 : buffer_(buffer), screen_manager_(screen_manager) { | 78 : buffer_(buffer), drm_thread_(drm_thread) {} |
77 } | |
78 | 79 |
79 bool GbmPixmap::Initialize() { | 80 bool GbmPixmap::Initialize() { |
80 // We want to use the GBM API because it's going to call into libdrm | 81 // We want to use the GBM API because it's going to call into libdrm |
81 // which might do some optimizations on buffer allocation, | 82 // which might do some optimizations on buffer allocation, |
82 // especially when sharing buffers via DMABUF. | 83 // especially when sharing buffers via DMABUF. |
83 dma_buf_ = gbm_bo_get_fd(buffer_->bo()); | 84 dma_buf_ = gbm_bo_get_fd(buffer_->bo()); |
84 if (dma_buf_ < 0) { | 85 if (dma_buf_ < 0) { |
85 PLOG(ERROR) << "Failed to export buffer to dma_buf"; | 86 PLOG(ERROR) << "Failed to export buffer to dma_buf"; |
86 return false; | 87 return false; |
87 } | 88 } |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
138 ShouldApplyScaling(display_bounds, crop_rect, &required_size)) { | 139 ShouldApplyScaling(display_bounds, crop_rect, &required_size)) { |
139 scoped_refptr<NativePixmap> scaled_pixmap = GetScaledPixmap(required_size); | 140 scoped_refptr<NativePixmap> scaled_pixmap = GetScaledPixmap(required_size); |
140 if (scaled_pixmap) { | 141 if (scaled_pixmap) { |
141 return scaled_pixmap->ScheduleOverlayPlane( | 142 return scaled_pixmap->ScheduleOverlayPlane( |
142 widget, plane_z_order, plane_transform, display_bounds, crop_rect); | 143 widget, plane_z_order, plane_transform, display_bounds, crop_rect); |
143 } else { | 144 } else { |
144 return false; | 145 return false; |
145 } | 146 } |
146 } | 147 } |
147 | 148 |
148 screen_manager_->GetWindow(widget)->QueueOverlayPlane(OverlayPlane( | 149 if (widget != cached_widget_) { |
149 buffer_, plane_z_order, plane_transform, display_bounds, crop_rect)); | 150 cached_widget_ = widget; |
151 cached_window_ = drm_thread_->GetWindow(cached_widget_); | |
spang
2015/09/18 00:46:25
How about:
(1) store window_id -> Surface map in
dnicoara
2015/09/18 17:43:08
Acknowledged.
| |
152 } | |
153 | |
154 drm_thread_->task_runner()->PostTask( | |
155 FROM_HERE, | |
156 base::Bind(&DrmWindow::QueueOverlayPlane, cached_window_, | |
157 OverlayPlane(buffer_, plane_z_order, plane_transform, | |
158 display_bounds, crop_rect))); | |
150 return true; | 159 return true; |
151 } | 160 } |
152 | 161 |
153 bool GbmPixmap::ShouldApplyScaling(const gfx::Rect& display_bounds, | 162 bool GbmPixmap::ShouldApplyScaling(const gfx::Rect& display_bounds, |
154 const gfx::RectF& crop_rect, | 163 const gfx::RectF& crop_rect, |
155 gfx::Size* required_size) { | 164 gfx::Size* required_size) { |
156 if (crop_rect.width() == 0 || crop_rect.height() == 0) { | 165 if (crop_rect.width() == 0 || crop_rect.height() == 0) { |
157 PLOG(ERROR) << "ShouldApplyScaling passed zero scaling target."; | 166 PLOG(ERROR) << "ShouldApplyScaling passed zero scaling target."; |
158 return false; | 167 return false; |
159 } | 168 } |
160 | 169 |
161 gfx::Size pixmap_size = buffer_->GetSize(); | 170 gfx::Size pixmap_size = buffer_->GetSize(); |
162 // If the required size is not integer-sized, round it to the next integer. | 171 // If the required size is not integer-sized, round it to the next integer. |
163 *required_size = gfx::ToCeiledSize( | 172 *required_size = gfx::ToCeiledSize( |
164 gfx::SizeF(display_bounds.width() / crop_rect.width(), | 173 gfx::SizeF(display_bounds.width() / crop_rect.width(), |
165 display_bounds.height() / crop_rect.height())); | 174 display_bounds.height() / crop_rect.height())); |
166 return pixmap_size != *required_size; | 175 return pixmap_size != *required_size; |
167 } | 176 } |
168 | 177 |
169 } // namespace ui | 178 } // namespace ui |
OLD | NEW |