Chromium Code Reviews| Index: ui/ozone/platform/dri/dri_window_delegate_impl.cc |
| diff --git a/ui/ozone/platform/dri/dri_window_delegate_impl.cc b/ui/ozone/platform/dri/dri_window_delegate_impl.cc |
| index d948321a1b66fe96291c6e54422aa81b7baa56c0..af81012d48472f0b7cca232372ffbe6ffffafa1e 100644 |
| --- a/ui/ozone/platform/dri/dri_window_delegate_impl.cc |
| +++ b/ui/ozone/platform/dri/dri_window_delegate_impl.cc |
| @@ -63,26 +63,6 @@ void DriWindowDelegateImpl::Initialize() { |
| device_manager_->UpdateDrmDevice(widget_, nullptr); |
| screen_manager_->AddObserver(this); |
| - scoped_refptr<DriWrapper> drm = |
| - device_manager_->GetDrmDevice(gfx::kNullAcceleratedWidget); |
| - |
| - uint64_t cursor_width = 64; |
| - uint64_t cursor_height = 64; |
| - drm->GetCapability(DRM_CAP_CURSOR_WIDTH, &cursor_width); |
| - drm->GetCapability(DRM_CAP_CURSOR_HEIGHT, &cursor_height); |
| - |
| - SkImageInfo info = SkImageInfo::MakeN32Premul(cursor_width, cursor_height); |
| - for (size_t i = 0; i < arraysize(cursor_buffers_); ++i) { |
| - cursor_buffers_[i] = new DriBuffer(drm); |
| - // Don't register a framebuffer for cursors since they are special (they |
| - // aren't modesetting buffers and drivers may fail to register them due to |
| - // their small sizes). |
| - if (!cursor_buffers_[i]->Initialize( |
| - info, false /* should_register_framebuffer */)) { |
| - LOG(ERROR) << "Failed to initialize cursor buffer"; |
| - return; |
| - } |
| - } |
| } |
| void DriWindowDelegateImpl::Shutdown() { |
| @@ -105,6 +85,7 @@ void DriWindowDelegateImpl::OnBoundsChanged(const gfx::Rect& bounds) { |
| bounds_ = bounds; |
| controller_ = screen_manager_->GetDisplayController(bounds); |
| UpdateWidgetToDrmDeviceMapping(); |
| + UpdateCursorBuffers(); |
| } |
| void DriWindowDelegateImpl::SetCursor(const std::vector<SkBitmap>& bitmaps, |
| @@ -145,6 +126,9 @@ void DriWindowDelegateImpl::OnDisplayChanged( |
| HardwareDisplayController* controller) { |
| DCHECK(controller); |
| + // If we have a new controller we need to re-allocate the buffers. |
| + 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.
|
| + |
| gfx::Rect controller_bounds = |
| gfx::Rect(controller->origin(), controller->GetModeSize()); |
| if (controller_) { |
| @@ -159,6 +143,8 @@ void DriWindowDelegateImpl::OnDisplayChanged( |
| } |
| UpdateWidgetToDrmDeviceMapping(); |
| + if (should_allocate_cursor_buffers) |
| + UpdateCursorBuffers(); |
| } |
| void DriWindowDelegateImpl::OnDisplayRemoved( |
| @@ -168,22 +154,22 @@ void DriWindowDelegateImpl::OnDisplayRemoved( |
| } |
| void DriWindowDelegateImpl::ResetCursor(bool bitmap_only) { |
| + if (!controller_) |
| + return; |
| + |
| if (cursor_bitmaps_.size()) { |
| // Draw new cursor into backbuffer. |
| UpdateCursorImage(cursor_buffers_[cursor_frontbuffer_ ^ 1].get(), |
| cursor_bitmaps_[cursor_frame_]); |
| // Reset location & buffer. |
| - if (controller_) { |
| - if (!bitmap_only) |
| - controller_->MoveCursor(cursor_location_); |
| - controller_->SetCursor(cursor_buffers_[cursor_frontbuffer_ ^ 1]); |
| - cursor_frontbuffer_ ^= 1; |
| - } |
| + if (!bitmap_only) |
| + controller_->MoveCursor(cursor_location_); |
| + controller_->SetCursor(cursor_buffers_[cursor_frontbuffer_ ^ 1]); |
| + cursor_frontbuffer_ ^= 1; |
| } else { |
| // No cursor set. |
| - if (controller_) |
| - controller_->UnsetCursor(); |
| + controller_->UnsetCursor(); |
| } |
| } |
| @@ -202,4 +188,32 @@ void DriWindowDelegateImpl::UpdateWidgetToDrmDeviceMapping() { |
| device_manager_->UpdateDrmDevice(widget_, drm); |
| } |
| +void DriWindowDelegateImpl::UpdateCursorBuffers() { |
| + if (!controller_) { |
| + for (size_t i = 0; i < arraysize(cursor_buffers_); ++i) { |
| + cursor_buffers_[i] = nullptr; |
| + } |
| + } else { |
| + scoped_refptr<DriWrapper> drm = controller_->GetAllocationDriWrapper(); |
| + |
| + uint64_t cursor_width = 64; |
| + uint64_t cursor_height = 64; |
| + drm->GetCapability(DRM_CAP_CURSOR_WIDTH, &cursor_width); |
| + drm->GetCapability(DRM_CAP_CURSOR_HEIGHT, &cursor_height); |
| + |
| + SkImageInfo info = SkImageInfo::MakeN32Premul(cursor_width, cursor_height); |
| + for (size_t i = 0; i < arraysize(cursor_buffers_); ++i) { |
| + cursor_buffers_[i] = new DriBuffer(drm); |
| + // Don't register a framebuffer for cursors since they are special (they |
| + // aren't modesetting buffers and drivers may fail to register them due to |
| + // their small sizes). |
| + if (!cursor_buffers_[i]->Initialize( |
| + info, false /* should_register_framebuffer */)) { |
| + LOG(FATAL) << "Failed to initialize cursor buffer"; |
| + return; |
| + } |
| + } |
| + } |
| +} |
| + |
| } // namespace ui |