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_surface_factory.h" | 5 #include "ui/ozone/platform/dri/dri_surface_factory.h" |
6 | 6 |
7 #include <errno.h> | 7 #include <errno.h> |
8 | 8 |
9 #include "base/debug/trace_event.h" | 9 #include "base/debug/trace_event.h" |
10 #include "third_party/skia/include/core/SkBitmap.h" | 10 #include "third_party/skia/include/core/SkBitmap.h" |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
48 // static | 48 // static |
49 const gfx::AcceleratedWidget DriSurfaceFactory::kDefaultWidgetHandle = 1; | 49 const gfx::AcceleratedWidget DriSurfaceFactory::kDefaultWidgetHandle = 1; |
50 | 50 |
51 DriSurfaceFactory::DriSurfaceFactory(DriWrapper* drm, | 51 DriSurfaceFactory::DriSurfaceFactory(DriWrapper* drm, |
52 ScreenManager* screen_manager, | 52 ScreenManager* screen_manager, |
53 DriWindowManager* window_manager) | 53 DriWindowManager* window_manager) |
54 : drm_(drm), | 54 : drm_(drm), |
55 screen_manager_(screen_manager), | 55 screen_manager_(screen_manager), |
56 window_manager_(window_manager), | 56 window_manager_(window_manager), |
57 state_(UNINITIALIZED), | 57 state_(UNINITIALIZED), |
58 cursor_frontbuffer_(0) { | 58 cursor_frontbuffer_(0), |
59 cursor_widget_(0), | |
60 cursor_frame_(0), | |
61 cursor_frame_delay_ms_(0) { | |
59 } | 62 } |
60 | 63 |
61 DriSurfaceFactory::~DriSurfaceFactory() { | 64 DriSurfaceFactory::~DriSurfaceFactory() { |
62 if (state_ == INITIALIZED) | 65 if (state_ == INITIALIZED) |
63 ShutdownHardware(); | 66 ShutdownHardware(); |
64 } | 67 } |
65 | 68 |
66 DriSurfaceFactory::HardwareState DriSurfaceFactory::InitializeHardware() { | 69 DriSurfaceFactory::HardwareState DriSurfaceFactory::InitializeHardware() { |
67 if (state_ != UNINITIALIZED) | 70 if (state_ != UNINITIALIZED) |
68 return state_; | 71 return state_; |
(...skipping 20 matching lines...) Expand all Loading... | |
89 } | 92 } |
90 | 93 |
91 void DriSurfaceFactory::ShutdownHardware() { | 94 void DriSurfaceFactory::ShutdownHardware() { |
92 DCHECK(state_ == INITIALIZED); | 95 DCHECK(state_ == INITIALIZED); |
93 state_ = UNINITIALIZED; | 96 state_ = UNINITIALIZED; |
94 } | 97 } |
95 | 98 |
96 scoped_ptr<ui::SurfaceOzoneCanvas> DriSurfaceFactory::CreateCanvasForWidget( | 99 scoped_ptr<ui::SurfaceOzoneCanvas> DriSurfaceFactory::CreateCanvasForWidget( |
97 gfx::AcceleratedWidget widget) { | 100 gfx::AcceleratedWidget widget) { |
98 DCHECK(state_ == INITIALIZED); | 101 DCHECK(state_ == INITIALIZED); |
99 // Initial cursor set. | |
100 ResetCursor(widget); | |
101 | 102 |
102 return scoped_ptr<ui::SurfaceOzoneCanvas>( | 103 return scoped_ptr<ui::SurfaceOzoneCanvas>( |
103 new DriSurface(window_manager_->GetWindowDelegate(widget), drm_)); | 104 new DriSurface(window_manager_->GetWindowDelegate(widget), drm_)); |
104 } | 105 } |
105 | 106 |
106 bool DriSurfaceFactory::LoadEGLGLES2Bindings( | 107 bool DriSurfaceFactory::LoadEGLGLES2Bindings( |
107 AddGLLibraryCallback add_gl_library, | 108 AddGLLibraryCallback add_gl_library, |
108 SetGLGetProcAddressProcCallback set_gl_get_proc_address) { | 109 SetGLGetProcAddressProcCallback set_gl_get_proc_address) { |
109 return false; | 110 return false; |
110 } | 111 } |
111 | 112 |
112 void DriSurfaceFactory::SetHardwareCursor(gfx::AcceleratedWidget widget, | 113 void DriSurfaceFactory::SetHardwareCursor(gfx::AcceleratedWidget widget, |
113 const std::vector<SkBitmap>& bitmaps, | 114 const std::vector<SkBitmap>& bitmaps, |
114 const gfx::Point& location, | 115 const gfx::Point& location, |
115 int frame_delay_ms) { | 116 int frame_delay_ms) { |
117 cursor_widget_ = widget; | |
116 cursor_bitmaps_ = bitmaps; | 118 cursor_bitmaps_ = bitmaps; |
117 cursor_location_ = location; | 119 cursor_location_ = location; |
120 cursor_frame_ = 0; | |
118 cursor_frame_delay_ms_ = frame_delay_ms; | 121 cursor_frame_delay_ms_ = frame_delay_ms; |
122 cursor_timer_.Stop(); | |
119 | 123 |
120 if (bitmaps.size() > 1) | 124 if (cursor_frame_delay_ms_) |
121 NOTIMPLEMENTED(); // No animation of animated cursors. | 125 cursor_timer_.Start( |
126 FROM_HERE, | |
127 base::TimeDelta::FromMilliseconds(cursor_frame_delay_ms_), | |
128 this, | |
129 &DriSurfaceFactory::OnCursorAnimationTimeout); | |
122 | 130 |
123 if (state_ != INITIALIZED) | 131 if (state_ != INITIALIZED) |
124 return; | 132 return; |
125 | 133 |
126 ResetCursor(widget); | 134 ResetCursor(); |
127 } | 135 } |
128 | 136 |
129 void DriSurfaceFactory::MoveHardwareCursor(gfx::AcceleratedWidget widget, | 137 void DriSurfaceFactory::MoveHardwareCursor(gfx::AcceleratedWidget widget, |
130 const gfx::Point& location) { | 138 const gfx::Point& location) { |
131 cursor_location_ = location; | 139 cursor_location_ = location; |
132 | 140 |
133 if (state_ != INITIALIZED) | 141 if (state_ != INITIALIZED) |
134 return; | 142 return; |
135 | 143 |
136 HardwareDisplayController* controller = | 144 HardwareDisplayController* controller = |
137 window_manager_->GetWindowDelegate(widget)->GetController(); | 145 window_manager_->GetWindowDelegate(widget)->GetController(); |
138 if (controller) | 146 if (controller) |
139 controller->MoveCursor(location); | 147 controller->MoveCursor(location); |
140 } | 148 } |
141 | 149 |
142 //////////////////////////////////////////////////////////////////////////////// | 150 //////////////////////////////////////////////////////////////////////////////// |
143 // DriSurfaceFactory private | 151 // DriSurfaceFactory private |
144 | 152 |
145 void DriSurfaceFactory::ResetCursor(gfx::AcceleratedWidget widget) { | 153 void DriSurfaceFactory::ResetCursor() { |
154 if (!cursor_widget_) | |
155 return; | |
156 | |
146 HardwareDisplayController* controller = | 157 HardwareDisplayController* controller = |
147 window_manager_->GetWindowDelegate(widget)->GetController(); | 158 window_manager_->GetWindowDelegate(cursor_widget_)->GetController(); |
148 | 159 |
149 if (cursor_bitmaps_.size()) { | 160 if (cursor_bitmaps_.size()) { |
150 // Draw new cursor into backbuffer. | 161 // Draw new cursor into backbuffer. |
151 UpdateCursorImage(cursor_buffers_[cursor_frontbuffer_ ^ 1].get(), | 162 UpdateCursorImage(cursor_buffers_[cursor_frontbuffer_ ^ 1].get(), |
152 cursor_bitmaps_[0]); | 163 cursor_bitmaps_[cursor_frame_]); |
153 | 164 |
154 // Reset location & buffer. | 165 // Reset location & buffer. |
155 if (controller) { | 166 if (controller) { |
dnicoara
2014/09/08 13:53:18
nit: Is it possible to move this if-statement and
spang
2014/09/08 15:15:49
Done.
spang
2014/09/10 15:22:12
And undone.. your test relies on the previous beha
| |
156 controller->MoveCursor(cursor_location_); | 167 controller->MoveCursor(cursor_location_); |
157 controller->SetCursor(cursor_buffers_[cursor_frontbuffer_ ^ 1]); | 168 controller->SetCursor(cursor_buffers_[cursor_frontbuffer_ ^ 1]); |
158 cursor_frontbuffer_ ^= 1; | 169 cursor_frontbuffer_ ^= 1; |
159 } | 170 } |
160 } else { | 171 } else { |
161 // No cursor set. | 172 // No cursor set. |
162 if (controller) | 173 if (controller) |
163 controller->UnsetCursor(); | 174 controller->UnsetCursor(); |
164 } | 175 } |
165 } | 176 } |
166 | 177 |
178 void DriSurfaceFactory::OnCursorAnimationTimeout() { | |
179 cursor_frame_++; | |
180 cursor_frame_ %= cursor_bitmaps_.size(); | |
181 | |
182 ResetCursor(); | |
183 } | |
184 | |
167 } // namespace ui | 185 } // namespace ui |
OLD | NEW |