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/debug/trace_event.h" | 7 #include "base/debug/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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 cursor_frame_(0), | 54 cursor_frame_(0), |
55 cursor_frame_delay_ms_(0) { | 55 cursor_frame_delay_ms_(0) { |
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 screen_manager_->AddObserver(this); |
| 65 |
64 uint64_t cursor_width = 64; | 66 uint64_t cursor_width = 64; |
65 uint64_t cursor_height = 64; | 67 uint64_t cursor_height = 64; |
66 drm_->GetCapability(DRM_CAP_CURSOR_WIDTH, &cursor_width); | 68 drm_->GetCapability(DRM_CAP_CURSOR_WIDTH, &cursor_width); |
67 drm_->GetCapability(DRM_CAP_CURSOR_HEIGHT, &cursor_height); | 69 drm_->GetCapability(DRM_CAP_CURSOR_HEIGHT, &cursor_height); |
68 | 70 |
69 SkImageInfo info = SkImageInfo::MakeN32Premul(cursor_width, cursor_height); | 71 SkImageInfo info = SkImageInfo::MakeN32Premul(cursor_width, cursor_height); |
70 for (size_t i = 0; i < arraysize(cursor_buffers_); ++i) { | 72 for (size_t i = 0; i < arraysize(cursor_buffers_); ++i) { |
71 cursor_buffers_[i] = new DriBuffer(drm_); | 73 cursor_buffers_[i] = new DriBuffer(drm_); |
72 if (!cursor_buffers_[i]->Initialize(info)) { | 74 if (!cursor_buffers_[i]->Initialize(info)) { |
73 LOG(ERROR) << "Failed to initialize cursor buffer"; | 75 LOG(ERROR) << "Failed to initialize cursor buffer"; |
74 return; | 76 return; |
75 } | 77 } |
76 } | 78 } |
77 } | 79 } |
78 | 80 |
79 void DriWindowDelegateImpl::Shutdown() { | 81 void DriWindowDelegateImpl::Shutdown() { |
80 TRACE_EVENT1("dri", "DriWindowDelegateImpl::Shutdown", "widget", widget_); | 82 TRACE_EVENT1("dri", "DriWindowDelegateImpl::Shutdown", "widget", widget_); |
| 83 screen_manager_->RemoveObserver(this); |
81 } | 84 } |
82 | 85 |
83 gfx::AcceleratedWidget DriWindowDelegateImpl::GetAcceleratedWidget() { | 86 gfx::AcceleratedWidget DriWindowDelegateImpl::GetAcceleratedWidget() { |
84 return widget_; | 87 return widget_; |
85 } | 88 } |
86 | 89 |
87 HardwareDisplayController* DriWindowDelegateImpl::GetController() { | 90 HardwareDisplayController* DriWindowDelegateImpl::GetController() { |
88 return controller_.get(); | 91 return controller_; |
89 } | 92 } |
90 | 93 |
91 void DriWindowDelegateImpl::OnBoundsChanged(const gfx::Rect& bounds) { | 94 void DriWindowDelegateImpl::OnBoundsChanged(const gfx::Rect& bounds) { |
92 TRACE_EVENT2("dri", "DriWindowDelegateImpl::OnBoundsChanged", "widget", | 95 TRACE_EVENT2("dri", "DriWindowDelegateImpl::OnBoundsChanged", "widget", |
93 widget_, "bounds", bounds.ToString()); | 96 widget_, "bounds", bounds.ToString()); |
| 97 bounds_ = bounds; |
94 controller_ = screen_manager_->GetDisplayController(bounds); | 98 controller_ = screen_manager_->GetDisplayController(bounds); |
95 } | 99 } |
96 | 100 |
97 void DriWindowDelegateImpl::SetCursor(const std::vector<SkBitmap>& bitmaps, | 101 void DriWindowDelegateImpl::SetCursor(const std::vector<SkBitmap>& bitmaps, |
98 const gfx::Point& location, | 102 const gfx::Point& location, |
99 int frame_delay_ms) { | 103 int frame_delay_ms) { |
100 cursor_bitmaps_ = bitmaps; | 104 cursor_bitmaps_ = bitmaps; |
101 cursor_location_ = location; | 105 cursor_location_ = location; |
102 cursor_frame_ = 0; | 106 cursor_frame_ = 0; |
103 cursor_frame_delay_ms_ = frame_delay_ms; | 107 cursor_frame_delay_ms_ = frame_delay_ms; |
(...skipping 17 matching lines...) Expand all Loading... |
121 ResetCursor(false); | 125 ResetCursor(false); |
122 } | 126 } |
123 | 127 |
124 void DriWindowDelegateImpl::MoveCursor(const gfx::Point& location) { | 128 void DriWindowDelegateImpl::MoveCursor(const gfx::Point& location) { |
125 cursor_location_ = location; | 129 cursor_location_ = location; |
126 | 130 |
127 if (controller_) | 131 if (controller_) |
128 controller_->MoveCursor(location); | 132 controller_->MoveCursor(location); |
129 } | 133 } |
130 | 134 |
| 135 void DriWindowDelegateImpl::OnDisplayChanged( |
| 136 HardwareDisplayController* controller) { |
| 137 DCHECK(controller); |
| 138 |
| 139 gfx::Rect controller_bounds = |
| 140 gfx::Rect(controller->origin(), controller->GetModeSize()); |
| 141 if (controller_) { |
| 142 if (controller_ != controller) |
| 143 return; |
| 144 |
| 145 if (controller->IsDisabled() || bounds_ != controller_bounds) |
| 146 controller_ = nullptr; |
| 147 } else { |
| 148 if (bounds_ == controller_bounds && !controller->IsDisabled()) |
| 149 controller_ = controller; |
| 150 } |
| 151 } |
| 152 |
| 153 void DriWindowDelegateImpl::OnDisplayRemoved( |
| 154 HardwareDisplayController* controller) { |
| 155 if (controller_ == controller) |
| 156 controller_ = nullptr; |
| 157 } |
| 158 |
131 void DriWindowDelegateImpl::ResetCursor(bool bitmap_only) { | 159 void DriWindowDelegateImpl::ResetCursor(bool bitmap_only) { |
132 if (cursor_bitmaps_.size()) { | 160 if (cursor_bitmaps_.size()) { |
133 // Draw new cursor into backbuffer. | 161 // Draw new cursor into backbuffer. |
134 UpdateCursorImage(cursor_buffers_[cursor_frontbuffer_ ^ 1].get(), | 162 UpdateCursorImage(cursor_buffers_[cursor_frontbuffer_ ^ 1].get(), |
135 cursor_bitmaps_[cursor_frame_]); | 163 cursor_bitmaps_[cursor_frame_]); |
136 | 164 |
137 // Reset location & buffer. | 165 // Reset location & buffer. |
138 if (controller_) { | 166 if (controller_) { |
139 if (!bitmap_only) | 167 if (!bitmap_only) |
140 controller_->MoveCursor(cursor_location_); | 168 controller_->MoveCursor(cursor_location_); |
141 controller_->SetCursor(cursor_buffers_[cursor_frontbuffer_ ^ 1]); | 169 controller_->SetCursor(cursor_buffers_[cursor_frontbuffer_ ^ 1]); |
142 cursor_frontbuffer_ ^= 1; | 170 cursor_frontbuffer_ ^= 1; |
143 } | 171 } |
144 } else { | 172 } else { |
145 // No cursor set. | 173 // No cursor set. |
146 if (controller_) | 174 if (controller_) |
147 controller_->UnsetCursor(); | 175 controller_->UnsetCursor(); |
148 } | 176 } |
149 } | 177 } |
150 | 178 |
151 void DriWindowDelegateImpl::OnCursorAnimationTimeout() { | 179 void DriWindowDelegateImpl::OnCursorAnimationTimeout() { |
152 cursor_frame_++; | 180 cursor_frame_++; |
153 cursor_frame_ %= cursor_bitmaps_.size(); | 181 cursor_frame_ %= cursor_bitmaps_.size(); |
154 | 182 |
155 ResetCursor(true); | 183 ResetCursor(true); |
156 } | 184 } |
157 | 185 |
158 } // namespace ui | 186 } // namespace ui |
OLD | NEW |