Chromium Code Reviews| 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/dri/dri_window_delegate_impl.h" | 5 #include "ui/ozone/platform/dri/dri_window_delegate_impl.h" |
| 6 | 6 |
| 7 #include "base/trace_event/trace_event.h" | 7 #include "base/trace_event/trace_event.h" |
| 8 #include "third_party/skia/include/core/SkBitmap.h" | 8 #include "third_party/skia/include/core/SkBitmap.h" |
| 9 #include "third_party/skia/include/core/SkDevice.h" | 9 #include "third_party/skia/include/core/SkDevice.h" |
| 10 #include "third_party/skia/include/core/SkSurface.h" | 10 #include "third_party/skia/include/core/SkSurface.h" |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 56 } | 56 } |
| 57 | 57 |
| 58 DriWindowDelegateImpl::~DriWindowDelegateImpl() { | 58 DriWindowDelegateImpl::~DriWindowDelegateImpl() { |
| 59 } | 59 } |
| 60 | 60 |
| 61 void DriWindowDelegateImpl::Initialize() { | 61 void DriWindowDelegateImpl::Initialize() { |
| 62 TRACE_EVENT1("dri", "DriWindowDelegateImpl::Initialize", "widget", widget_); | 62 TRACE_EVENT1("dri", "DriWindowDelegateImpl::Initialize", "widget", widget_); |
| 63 | 63 |
| 64 device_manager_->UpdateDrmDevice(widget_, nullptr); | 64 device_manager_->UpdateDrmDevice(widget_, nullptr); |
| 65 screen_manager_->AddObserver(this); | 65 screen_manager_->AddObserver(this); |
| 66 scoped_refptr<DriWrapper> drm = | |
| 67 device_manager_->GetDrmDevice(gfx::kNullAcceleratedWidget); | |
| 68 | |
| 69 uint64_t cursor_width = 64; | |
| 70 uint64_t cursor_height = 64; | |
| 71 drm->GetCapability(DRM_CAP_CURSOR_WIDTH, &cursor_width); | |
| 72 drm->GetCapability(DRM_CAP_CURSOR_HEIGHT, &cursor_height); | |
| 73 | |
| 74 SkImageInfo info = SkImageInfo::MakeN32Premul(cursor_width, cursor_height); | |
| 75 for (size_t i = 0; i < arraysize(cursor_buffers_); ++i) { | |
| 76 cursor_buffers_[i] = new DriBuffer(drm); | |
| 77 // Don't register a framebuffer for cursors since they are special (they | |
| 78 // aren't modesetting buffers and drivers may fail to register them due to | |
| 79 // their small sizes). | |
| 80 if (!cursor_buffers_[i]->Initialize( | |
| 81 info, false /* should_register_framebuffer */)) { | |
| 82 LOG(ERROR) << "Failed to initialize cursor buffer"; | |
| 83 return; | |
| 84 } | |
| 85 } | |
| 86 } | 66 } |
| 87 | 67 |
| 88 void DriWindowDelegateImpl::Shutdown() { | 68 void DriWindowDelegateImpl::Shutdown() { |
| 89 TRACE_EVENT1("dri", "DriWindowDelegateImpl::Shutdown", "widget", widget_); | 69 TRACE_EVENT1("dri", "DriWindowDelegateImpl::Shutdown", "widget", widget_); |
| 90 screen_manager_->RemoveObserver(this); | 70 screen_manager_->RemoveObserver(this); |
| 91 device_manager_->RemoveDrmDevice(widget_); | 71 device_manager_->RemoveDrmDevice(widget_); |
| 92 } | 72 } |
| 93 | 73 |
| 94 gfx::AcceleratedWidget DriWindowDelegateImpl::GetAcceleratedWidget() { | 74 gfx::AcceleratedWidget DriWindowDelegateImpl::GetAcceleratedWidget() { |
| 95 return widget_; | 75 return widget_; |
| 96 } | 76 } |
| 97 | 77 |
| 98 HardwareDisplayController* DriWindowDelegateImpl::GetController() { | 78 HardwareDisplayController* DriWindowDelegateImpl::GetController() { |
| 99 return controller_; | 79 return controller_; |
| 100 } | 80 } |
| 101 | 81 |
| 102 void DriWindowDelegateImpl::OnBoundsChanged(const gfx::Rect& bounds) { | 82 void DriWindowDelegateImpl::OnBoundsChanged(const gfx::Rect& bounds) { |
| 103 TRACE_EVENT2("dri", "DriWindowDelegateImpl::OnBoundsChanged", "widget", | 83 TRACE_EVENT2("dri", "DriWindowDelegateImpl::OnBoundsChanged", "widget", |
| 104 widget_, "bounds", bounds.ToString()); | 84 widget_, "bounds", bounds.ToString()); |
| 105 bounds_ = bounds; | 85 bounds_ = bounds; |
| 106 controller_ = screen_manager_->GetDisplayController(bounds); | 86 controller_ = screen_manager_->GetDisplayController(bounds); |
| 107 UpdateWidgetToDrmDeviceMapping(); | 87 UpdateWidgetToDrmDeviceMapping(); |
| 88 UpdateCursorBuffers(); | |
| 108 } | 89 } |
| 109 | 90 |
| 110 void DriWindowDelegateImpl::SetCursor(const std::vector<SkBitmap>& bitmaps, | 91 void DriWindowDelegateImpl::SetCursor(const std::vector<SkBitmap>& bitmaps, |
| 111 const gfx::Point& location, | 92 const gfx::Point& location, |
| 112 int frame_delay_ms) { | 93 int frame_delay_ms) { |
| 113 cursor_bitmaps_ = bitmaps; | 94 cursor_bitmaps_ = bitmaps; |
| 114 cursor_location_ = location; | 95 cursor_location_ = location; |
| 115 cursor_frame_ = 0; | 96 cursor_frame_ = 0; |
| 116 cursor_frame_delay_ms_ = frame_delay_ms; | 97 cursor_frame_delay_ms_ = frame_delay_ms; |
| 117 cursor_timer_.Stop(); | 98 cursor_timer_.Stop(); |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 138 cursor_location_ = location; | 119 cursor_location_ = location; |
| 139 | 120 |
| 140 if (controller_) | 121 if (controller_) |
| 141 controller_->MoveCursor(location); | 122 controller_->MoveCursor(location); |
| 142 } | 123 } |
| 143 | 124 |
| 144 void DriWindowDelegateImpl::OnDisplayChanged( | 125 void DriWindowDelegateImpl::OnDisplayChanged( |
| 145 HardwareDisplayController* controller) { | 126 HardwareDisplayController* controller) { |
| 146 DCHECK(controller); | 127 DCHECK(controller); |
| 147 | 128 |
| 129 // If we have a new controller we need to re-allocate the buffers. | |
| 130 bool should_allocate_cursor_buffers = controller_ != controller; | |
|
alexst (slow to review)
2015/02/26 15:28:21
Why not just have if (controller_ != controller) b
dnicoara
2015/02/26 15:31:29
Because |controller_| may be set to |controller| b
alexst (slow to review)
2015/02/26 15:35:46
Acknowledged.
| |
| 131 | |
| 148 gfx::Rect controller_bounds = | 132 gfx::Rect controller_bounds = |
| 149 gfx::Rect(controller->origin(), controller->GetModeSize()); | 133 gfx::Rect(controller->origin(), controller->GetModeSize()); |
| 150 if (controller_) { | 134 if (controller_) { |
| 151 if (controller_ != controller) | 135 if (controller_ != controller) |
| 152 return; | 136 return; |
| 153 | 137 |
| 154 if (controller->IsDisabled() || bounds_ != controller_bounds) | 138 if (controller->IsDisabled() || bounds_ != controller_bounds) |
| 155 controller_ = nullptr; | 139 controller_ = nullptr; |
| 156 } else { | 140 } else { |
| 157 if (bounds_ == controller_bounds && !controller->IsDisabled()) | 141 if (bounds_ == controller_bounds && !controller->IsDisabled()) |
| 158 controller_ = controller; | 142 controller_ = controller; |
| 159 } | 143 } |
| 160 | 144 |
| 161 UpdateWidgetToDrmDeviceMapping(); | 145 UpdateWidgetToDrmDeviceMapping(); |
| 146 if (should_allocate_cursor_buffers) | |
| 147 UpdateCursorBuffers(); | |
| 162 } | 148 } |
| 163 | 149 |
| 164 void DriWindowDelegateImpl::OnDisplayRemoved( | 150 void DriWindowDelegateImpl::OnDisplayRemoved( |
| 165 HardwareDisplayController* controller) { | 151 HardwareDisplayController* controller) { |
| 166 if (controller_ == controller) | 152 if (controller_ == controller) |
| 167 controller_ = nullptr; | 153 controller_ = nullptr; |
| 168 } | 154 } |
| 169 | 155 |
| 170 void DriWindowDelegateImpl::ResetCursor(bool bitmap_only) { | 156 void DriWindowDelegateImpl::ResetCursor(bool bitmap_only) { |
| 157 if (!controller_) | |
| 158 return; | |
| 159 | |
| 171 if (cursor_bitmaps_.size()) { | 160 if (cursor_bitmaps_.size()) { |
| 172 // Draw new cursor into backbuffer. | 161 // Draw new cursor into backbuffer. |
| 173 UpdateCursorImage(cursor_buffers_[cursor_frontbuffer_ ^ 1].get(), | 162 UpdateCursorImage(cursor_buffers_[cursor_frontbuffer_ ^ 1].get(), |
| 174 cursor_bitmaps_[cursor_frame_]); | 163 cursor_bitmaps_[cursor_frame_]); |
| 175 | 164 |
| 176 // Reset location & buffer. | 165 // Reset location & buffer. |
| 177 if (controller_) { | 166 if (!bitmap_only) |
| 178 if (!bitmap_only) | 167 controller_->MoveCursor(cursor_location_); |
| 179 controller_->MoveCursor(cursor_location_); | 168 controller_->SetCursor(cursor_buffers_[cursor_frontbuffer_ ^ 1]); |
| 180 controller_->SetCursor(cursor_buffers_[cursor_frontbuffer_ ^ 1]); | 169 cursor_frontbuffer_ ^= 1; |
| 181 cursor_frontbuffer_ ^= 1; | |
| 182 } | |
| 183 } else { | 170 } else { |
| 184 // No cursor set. | 171 // No cursor set. |
| 185 if (controller_) | 172 controller_->UnsetCursor(); |
| 186 controller_->UnsetCursor(); | |
| 187 } | 173 } |
| 188 } | 174 } |
| 189 | 175 |
| 190 void DriWindowDelegateImpl::OnCursorAnimationTimeout() { | 176 void DriWindowDelegateImpl::OnCursorAnimationTimeout() { |
| 191 cursor_frame_++; | 177 cursor_frame_++; |
| 192 cursor_frame_ %= cursor_bitmaps_.size(); | 178 cursor_frame_ %= cursor_bitmaps_.size(); |
| 193 | 179 |
| 194 ResetCursor(true); | 180 ResetCursor(true); |
| 195 } | 181 } |
| 196 | 182 |
| 197 void DriWindowDelegateImpl::UpdateWidgetToDrmDeviceMapping() { | 183 void DriWindowDelegateImpl::UpdateWidgetToDrmDeviceMapping() { |
| 198 scoped_refptr<DriWrapper> drm = nullptr; | 184 scoped_refptr<DriWrapper> drm = nullptr; |
| 199 if (controller_) | 185 if (controller_) |
| 200 drm = controller_->GetAllocationDriWrapper(); | 186 drm = controller_->GetAllocationDriWrapper(); |
| 201 | 187 |
| 202 device_manager_->UpdateDrmDevice(widget_, drm); | 188 device_manager_->UpdateDrmDevice(widget_, drm); |
| 203 } | 189 } |
| 204 | 190 |
| 191 void DriWindowDelegateImpl::UpdateCursorBuffers() { | |
| 192 if (!controller_) { | |
| 193 for (size_t i = 0; i < arraysize(cursor_buffers_); ++i) { | |
| 194 cursor_buffers_[i] = nullptr; | |
| 195 } | |
| 196 } else { | |
| 197 scoped_refptr<DriWrapper> drm = controller_->GetAllocationDriWrapper(); | |
| 198 | |
| 199 uint64_t cursor_width = 64; | |
| 200 uint64_t cursor_height = 64; | |
| 201 drm->GetCapability(DRM_CAP_CURSOR_WIDTH, &cursor_width); | |
| 202 drm->GetCapability(DRM_CAP_CURSOR_HEIGHT, &cursor_height); | |
| 203 | |
| 204 SkImageInfo info = SkImageInfo::MakeN32Premul(cursor_width, cursor_height); | |
| 205 for (size_t i = 0; i < arraysize(cursor_buffers_); ++i) { | |
| 206 cursor_buffers_[i] = new DriBuffer(drm); | |
| 207 // Don't register a framebuffer for cursors since they are special (they | |
| 208 // aren't modesetting buffers and drivers may fail to register them due to | |
| 209 // their small sizes). | |
| 210 if (!cursor_buffers_[i]->Initialize( | |
| 211 info, false /* should_register_framebuffer */)) { | |
| 212 LOG(FATAL) << "Failed to initialize cursor buffer"; | |
| 213 return; | |
| 214 } | |
| 215 } | |
| 216 } | |
| 217 } | |
| 218 | |
| 205 } // namespace ui | 219 } // namespace ui |
| OLD | NEW |