| 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.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" |
| 11 #include "ui/ozone/platform/dri/dri_buffer.h" | 11 #include "ui/ozone/platform/dri/dri_buffer.h" |
| 12 #include "ui/ozone/platform/dri/drm_device.h" | 12 #include "ui/ozone/platform/dri/drm_device.h" |
| 13 #include "ui/ozone/platform/dri/drm_device_manager.h" | 13 #include "ui/ozone/platform/dri/drm_device_manager.h" |
| 14 #include "ui/ozone/platform/dri/screen_manager.h" | 14 #include "ui/ozone/platform/dri/screen_manager.h" |
| 15 | 15 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 35 | 35 |
| 36 SkRect clip; | 36 SkRect clip; |
| 37 clip.set(0, 0, canvas->getDeviceSize().width(), | 37 clip.set(0, 0, canvas->getDeviceSize().width(), |
| 38 canvas->getDeviceSize().height()); | 38 canvas->getDeviceSize().height()); |
| 39 canvas->clipRect(clip, SkRegion::kReplace_Op); | 39 canvas->clipRect(clip, SkRegion::kReplace_Op); |
| 40 canvas->drawBitmapRectToRect(image, &damage, damage); | 40 canvas->drawBitmapRectToRect(image, &damage, damage); |
| 41 } | 41 } |
| 42 | 42 |
| 43 } // namespace | 43 } // namespace |
| 44 | 44 |
| 45 DriWindowDelegateImpl::DriWindowDelegateImpl( | 45 DriWindowDelegate::DriWindowDelegate(gfx::AcceleratedWidget widget, |
| 46 gfx::AcceleratedWidget widget, | 46 DrmDeviceManager* device_manager, |
| 47 DrmDeviceManager* device_manager, | 47 ScreenManager* screen_manager) |
| 48 ScreenManager* screen_manager) | |
| 49 : widget_(widget), | 48 : widget_(widget), |
| 50 device_manager_(device_manager), | 49 device_manager_(device_manager), |
| 51 screen_manager_(screen_manager), | 50 screen_manager_(screen_manager), |
| 52 controller_(NULL), | 51 controller_(NULL), |
| 53 cursor_frontbuffer_(0), | 52 cursor_frontbuffer_(0), |
| 54 cursor_frame_(0), | 53 cursor_frame_(0), |
| 55 cursor_frame_delay_ms_(0) { | 54 cursor_frame_delay_ms_(0) { |
| 56 } | 55 } |
| 57 | 56 |
| 58 DriWindowDelegateImpl::~DriWindowDelegateImpl() { | 57 DriWindowDelegate::~DriWindowDelegate() { |
| 59 } | 58 } |
| 60 | 59 |
| 61 void DriWindowDelegateImpl::Initialize() { | 60 void DriWindowDelegate::Initialize() { |
| 62 TRACE_EVENT1("dri", "DriWindowDelegateImpl::Initialize", "widget", widget_); | 61 TRACE_EVENT1("dri", "DriWindowDelegate::Initialize", "widget", widget_); |
| 63 | 62 |
| 64 device_manager_->UpdateDrmDevice(widget_, nullptr); | 63 device_manager_->UpdateDrmDevice(widget_, nullptr); |
| 65 screen_manager_->AddObserver(this); | 64 screen_manager_->AddObserver(this); |
| 66 } | 65 } |
| 67 | 66 |
| 68 void DriWindowDelegateImpl::Shutdown() { | 67 void DriWindowDelegate::Shutdown() { |
| 69 TRACE_EVENT1("dri", "DriWindowDelegateImpl::Shutdown", "widget", widget_); | 68 TRACE_EVENT1("dri", "DriWindowDelegate::Shutdown", "widget", widget_); |
| 70 screen_manager_->RemoveObserver(this); | 69 screen_manager_->RemoveObserver(this); |
| 71 device_manager_->RemoveDrmDevice(widget_); | 70 device_manager_->RemoveDrmDevice(widget_); |
| 72 } | 71 } |
| 73 | 72 |
| 74 gfx::AcceleratedWidget DriWindowDelegateImpl::GetAcceleratedWidget() { | 73 gfx::AcceleratedWidget DriWindowDelegate::GetAcceleratedWidget() { |
| 75 return widget_; | 74 return widget_; |
| 76 } | 75 } |
| 77 | 76 |
| 78 HardwareDisplayController* DriWindowDelegateImpl::GetController() { | 77 HardwareDisplayController* DriWindowDelegate::GetController() { |
| 79 return controller_; | 78 return controller_; |
| 80 } | 79 } |
| 81 | 80 |
| 82 void DriWindowDelegateImpl::OnBoundsChanged(const gfx::Rect& bounds) { | 81 void DriWindowDelegate::OnBoundsChanged(const gfx::Rect& bounds) { |
| 83 TRACE_EVENT2("dri", "DriWindowDelegateImpl::OnBoundsChanged", "widget", | 82 TRACE_EVENT2("dri", "DriWindowDelegate::OnBoundsChanged", "widget", widget_, |
| 84 widget_, "bounds", bounds.ToString()); | 83 "bounds", bounds.ToString()); |
| 85 bounds_ = bounds; | 84 bounds_ = bounds; |
| 86 controller_ = screen_manager_->GetDisplayController(bounds); | 85 controller_ = screen_manager_->GetDisplayController(bounds); |
| 87 UpdateWidgetToDrmDeviceMapping(); | 86 UpdateWidgetToDrmDeviceMapping(); |
| 88 UpdateCursorBuffers(); | 87 UpdateCursorBuffers(); |
| 89 } | 88 } |
| 90 | 89 |
| 91 void DriWindowDelegateImpl::SetCursor(const std::vector<SkBitmap>& bitmaps, | 90 void DriWindowDelegate::SetCursor(const std::vector<SkBitmap>& bitmaps, |
| 92 const gfx::Point& location, | 91 const gfx::Point& location, |
| 93 int frame_delay_ms) { | 92 int frame_delay_ms) { |
| 94 cursor_bitmaps_ = bitmaps; | 93 cursor_bitmaps_ = bitmaps; |
| 95 cursor_location_ = location; | 94 cursor_location_ = location; |
| 96 cursor_frame_ = 0; | 95 cursor_frame_ = 0; |
| 97 cursor_frame_delay_ms_ = frame_delay_ms; | 96 cursor_frame_delay_ms_ = frame_delay_ms; |
| 98 cursor_timer_.Stop(); | 97 cursor_timer_.Stop(); |
| 99 | 98 |
| 100 if (cursor_frame_delay_ms_) | 99 if (cursor_frame_delay_ms_) |
| 101 cursor_timer_.Start( | 100 cursor_timer_.Start( |
| 102 FROM_HERE, base::TimeDelta::FromMilliseconds(cursor_frame_delay_ms_), | 101 FROM_HERE, base::TimeDelta::FromMilliseconds(cursor_frame_delay_ms_), |
| 103 this, &DriWindowDelegateImpl::OnCursorAnimationTimeout); | 102 this, &DriWindowDelegate::OnCursorAnimationTimeout); |
| 104 | 103 |
| 105 ResetCursor(false); | 104 ResetCursor(false); |
| 106 } | 105 } |
| 107 | 106 |
| 108 void DriWindowDelegateImpl::SetCursorWithoutAnimations( | 107 void DriWindowDelegate::SetCursorWithoutAnimations( |
| 109 const std::vector<SkBitmap>& bitmaps, | 108 const std::vector<SkBitmap>& bitmaps, |
| 110 const gfx::Point& location) { | 109 const gfx::Point& location) { |
| 111 cursor_bitmaps_ = bitmaps; | 110 cursor_bitmaps_ = bitmaps; |
| 112 cursor_location_ = location; | 111 cursor_location_ = location; |
| 113 cursor_frame_ = 0; | 112 cursor_frame_ = 0; |
| 114 cursor_frame_delay_ms_ = 0; | 113 cursor_frame_delay_ms_ = 0; |
| 115 ResetCursor(false); | 114 ResetCursor(false); |
| 116 } | 115 } |
| 117 | 116 |
| 118 void DriWindowDelegateImpl::MoveCursor(const gfx::Point& location) { | 117 void DriWindowDelegate::MoveCursor(const gfx::Point& location) { |
| 119 cursor_location_ = location; | 118 cursor_location_ = location; |
| 120 | 119 |
| 121 if (controller_) | 120 if (controller_) |
| 122 controller_->MoveCursor(location); | 121 controller_->MoveCursor(location); |
| 123 } | 122 } |
| 124 | 123 |
| 125 void DriWindowDelegateImpl::OnDisplayChanged( | 124 void DriWindowDelegate::OnDisplayChanged( |
| 126 HardwareDisplayController* controller) { | 125 HardwareDisplayController* controller) { |
| 127 DCHECK(controller); | 126 DCHECK(controller); |
| 128 | 127 |
| 129 // If we have a new controller we need to re-allocate the buffers. | 128 // If we have a new controller we need to re-allocate the buffers. |
| 130 bool should_allocate_cursor_buffers = controller_ != controller; | 129 bool should_allocate_cursor_buffers = controller_ != controller; |
| 131 | 130 |
| 132 gfx::Rect controller_bounds = | 131 gfx::Rect controller_bounds = |
| 133 gfx::Rect(controller->origin(), controller->GetModeSize()); | 132 gfx::Rect(controller->origin(), controller->GetModeSize()); |
| 134 if (controller_) { | 133 if (controller_) { |
| 135 if (controller_ != controller) | 134 if (controller_ != controller) |
| 136 return; | 135 return; |
| 137 | 136 |
| 138 if (controller->IsDisabled() || bounds_ != controller_bounds) | 137 if (controller->IsDisabled() || bounds_ != controller_bounds) |
| 139 controller_ = nullptr; | 138 controller_ = nullptr; |
| 140 } else { | 139 } else { |
| 141 if (bounds_ == controller_bounds && !controller->IsDisabled()) | 140 if (bounds_ == controller_bounds && !controller->IsDisabled()) |
| 142 controller_ = controller; | 141 controller_ = controller; |
| 143 } | 142 } |
| 144 | 143 |
| 145 UpdateWidgetToDrmDeviceMapping(); | 144 UpdateWidgetToDrmDeviceMapping(); |
| 146 if (should_allocate_cursor_buffers) | 145 if (should_allocate_cursor_buffers) |
| 147 UpdateCursorBuffers(); | 146 UpdateCursorBuffers(); |
| 148 } | 147 } |
| 149 | 148 |
| 150 void DriWindowDelegateImpl::OnDisplayRemoved( | 149 void DriWindowDelegate::OnDisplayRemoved( |
| 151 HardwareDisplayController* controller) { | 150 HardwareDisplayController* controller) { |
| 152 if (controller_ == controller) | 151 if (controller_ == controller) |
| 153 controller_ = nullptr; | 152 controller_ = nullptr; |
| 154 } | 153 } |
| 155 | 154 |
| 156 void DriWindowDelegateImpl::ResetCursor(bool bitmap_only) { | 155 void DriWindowDelegate::ResetCursor(bool bitmap_only) { |
| 157 if (!controller_) | 156 if (!controller_) |
| 158 return; | 157 return; |
| 159 | 158 |
| 160 if (cursor_bitmaps_.size()) { | 159 if (cursor_bitmaps_.size()) { |
| 161 // Draw new cursor into backbuffer. | 160 // Draw new cursor into backbuffer. |
| 162 UpdateCursorImage(cursor_buffers_[cursor_frontbuffer_ ^ 1].get(), | 161 UpdateCursorImage(cursor_buffers_[cursor_frontbuffer_ ^ 1].get(), |
| 163 cursor_bitmaps_[cursor_frame_]); | 162 cursor_bitmaps_[cursor_frame_]); |
| 164 | 163 |
| 165 // Reset location & buffer. | 164 // Reset location & buffer. |
| 166 if (!bitmap_only) | 165 if (!bitmap_only) |
| 167 controller_->MoveCursor(cursor_location_); | 166 controller_->MoveCursor(cursor_location_); |
| 168 controller_->SetCursor(cursor_buffers_[cursor_frontbuffer_ ^ 1]); | 167 controller_->SetCursor(cursor_buffers_[cursor_frontbuffer_ ^ 1]); |
| 169 cursor_frontbuffer_ ^= 1; | 168 cursor_frontbuffer_ ^= 1; |
| 170 } else { | 169 } else { |
| 171 // No cursor set. | 170 // No cursor set. |
| 172 controller_->UnsetCursor(); | 171 controller_->UnsetCursor(); |
| 173 } | 172 } |
| 174 } | 173 } |
| 175 | 174 |
| 176 void DriWindowDelegateImpl::OnCursorAnimationTimeout() { | 175 void DriWindowDelegate::OnCursorAnimationTimeout() { |
| 177 cursor_frame_++; | 176 cursor_frame_++; |
| 178 cursor_frame_ %= cursor_bitmaps_.size(); | 177 cursor_frame_ %= cursor_bitmaps_.size(); |
| 179 | 178 |
| 180 ResetCursor(true); | 179 ResetCursor(true); |
| 181 } | 180 } |
| 182 | 181 |
| 183 void DriWindowDelegateImpl::UpdateWidgetToDrmDeviceMapping() { | 182 void DriWindowDelegate::UpdateWidgetToDrmDeviceMapping() { |
| 184 scoped_refptr<DrmDevice> drm = nullptr; | 183 scoped_refptr<DrmDevice> drm = nullptr; |
| 185 if (controller_) | 184 if (controller_) |
| 186 drm = controller_->GetAllocationDrmDevice(); | 185 drm = controller_->GetAllocationDrmDevice(); |
| 187 | 186 |
| 188 device_manager_->UpdateDrmDevice(widget_, drm); | 187 device_manager_->UpdateDrmDevice(widget_, drm); |
| 189 } | 188 } |
| 190 | 189 |
| 191 void DriWindowDelegateImpl::UpdateCursorBuffers() { | 190 void DriWindowDelegate::UpdateCursorBuffers() { |
| 192 if (!controller_) { | 191 if (!controller_) { |
| 193 for (size_t i = 0; i < arraysize(cursor_buffers_); ++i) { | 192 for (size_t i = 0; i < arraysize(cursor_buffers_); ++i) { |
| 194 cursor_buffers_[i] = nullptr; | 193 cursor_buffers_[i] = nullptr; |
| 195 } | 194 } |
| 196 } else { | 195 } else { |
| 197 scoped_refptr<DrmDevice> drm = controller_->GetAllocationDrmDevice(); | 196 scoped_refptr<DrmDevice> drm = controller_->GetAllocationDrmDevice(); |
| 198 | 197 |
| 199 uint64_t cursor_width = 64; | 198 uint64_t cursor_width = 64; |
| 200 uint64_t cursor_height = 64; | 199 uint64_t cursor_height = 64; |
| 201 drm->GetCapability(DRM_CAP_CURSOR_WIDTH, &cursor_width); | 200 drm->GetCapability(DRM_CAP_CURSOR_WIDTH, &cursor_width); |
| 202 drm->GetCapability(DRM_CAP_CURSOR_HEIGHT, &cursor_height); | 201 drm->GetCapability(DRM_CAP_CURSOR_HEIGHT, &cursor_height); |
| 203 | 202 |
| 204 SkImageInfo info = SkImageInfo::MakeN32Premul(cursor_width, cursor_height); | 203 SkImageInfo info = SkImageInfo::MakeN32Premul(cursor_width, cursor_height); |
| 205 for (size_t i = 0; i < arraysize(cursor_buffers_); ++i) { | 204 for (size_t i = 0; i < arraysize(cursor_buffers_); ++i) { |
| 206 cursor_buffers_[i] = new DriBuffer(drm); | 205 cursor_buffers_[i] = new DriBuffer(drm); |
| 207 // Don't register a framebuffer for cursors since they are special (they | 206 // 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 | 207 // aren't modesetting buffers and drivers may fail to register them due to |
| 209 // their small sizes). | 208 // their small sizes). |
| 210 if (!cursor_buffers_[i]->Initialize( | 209 if (!cursor_buffers_[i]->Initialize( |
| 211 info, false /* should_register_framebuffer */)) { | 210 info, false /* should_register_framebuffer */)) { |
| 212 LOG(FATAL) << "Failed to initialize cursor buffer"; | 211 LOG(FATAL) << "Failed to initialize cursor buffer"; |
| 213 return; | 212 return; |
| 214 } | 213 } |
| 215 } | 214 } |
| 216 } | 215 } |
| 217 } | 216 } |
| 218 | 217 |
| 219 } // namespace ui | 218 } // namespace ui |
| OLD | NEW |