OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // This file defines utility functions for X11 (Linux only). This code has been | 5 // This file defines utility functions for X11 (Linux only). This code has been |
6 // ported from XCB since we can't use XCB on Ubuntu while its 32-bit support | 6 // ported from XCB since we can't use XCB on Ubuntu while its 32-bit support |
7 // remains woefully incomplete. | 7 // remains woefully incomplete. |
8 | 8 |
9 #include "ui/base/x/x11_util.h" | 9 #include "ui/base/x/x11_util.h" |
10 | 10 |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 | 160 |
161 void Unref(::Cursor cursor) { | 161 void Unref(::Cursor cursor) { |
162 if (cache_[cursor]->Unref()) | 162 if (cache_[cursor]->Unref()) |
163 cache_.erase(cursor); | 163 cache_.erase(cursor); |
164 } | 164 } |
165 | 165 |
166 void Clear() { | 166 void Clear() { |
167 cache_.clear(); | 167 cache_.clear(); |
168 } | 168 } |
169 | 169 |
| 170 const XcursorImage* GetXcursorImage(::Cursor cursor) const { |
| 171 return cache_.find(cursor)->second->image(); |
| 172 } |
| 173 |
170 private: | 174 private: |
171 friend struct DefaultSingletonTraits<XCustomCursorCache>; | 175 friend struct DefaultSingletonTraits<XCustomCursorCache>; |
172 | 176 |
173 class XCustomCursor { | 177 class XCustomCursor { |
174 public: | 178 public: |
175 // This takes ownership of the image. | 179 // This takes ownership of the image. |
176 XCustomCursor(XcursorImage* image) | 180 XCustomCursor(XcursorImage* image) |
177 : image_(image), | 181 : image_(image), |
178 ref_(1) { | 182 ref_(1) { |
179 cursor_ = XcursorImageLoadCursor(gfx::GetXDisplay(), image); | 183 cursor_ = XcursorImageLoadCursor(gfx::GetXDisplay(), image); |
(...skipping 12 matching lines...) Expand all Loading... |
192 | 196 |
193 // Returns true if the cursor was destroyed because of the unref. | 197 // Returns true if the cursor was destroyed because of the unref. |
194 bool Unref() { | 198 bool Unref() { |
195 if (--ref_ == 0) { | 199 if (--ref_ == 0) { |
196 delete this; | 200 delete this; |
197 return true; | 201 return true; |
198 } | 202 } |
199 return false; | 203 return false; |
200 } | 204 } |
201 | 205 |
| 206 const XcursorImage* image() const { |
| 207 return image_; |
| 208 }; |
| 209 |
202 private: | 210 private: |
203 XcursorImage* image_; | 211 XcursorImage* image_; |
204 int ref_; | 212 int ref_; |
205 ::Cursor cursor_; | 213 ::Cursor cursor_; |
206 | 214 |
207 DISALLOW_COPY_AND_ASSIGN(XCustomCursor); | 215 DISALLOW_COPY_AND_ASSIGN(XCustomCursor); |
208 }; | 216 }; |
209 | 217 |
210 XCustomCursorCache() {} | 218 XCustomCursorCache() {} |
211 ~XCustomCursorCache() { | 219 ~XCustomCursorCache() { |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
308 | 316 |
309 return render_supported; | 317 return render_supported; |
310 } | 318 } |
311 | 319 |
312 ::Cursor GetXCursor(int cursor_shape) { | 320 ::Cursor GetXCursor(int cursor_shape) { |
313 if (!cursor_cache) | 321 if (!cursor_cache) |
314 cursor_cache = new XCursorCache; | 322 cursor_cache = new XCursorCache; |
315 return cursor_cache->GetCursor(cursor_shape); | 323 return cursor_cache->GetCursor(cursor_shape); |
316 } | 324 } |
317 | 325 |
318 void ResetXCursorCache() { | |
319 delete cursor_cache; | |
320 cursor_cache = NULL; | |
321 } | |
322 | |
323 ::Cursor CreateReffedCustomXCursor(XcursorImage* image) { | 326 ::Cursor CreateReffedCustomXCursor(XcursorImage* image) { |
324 return XCustomCursorCache::GetInstance()->InstallCustomCursor(image); | 327 return XCustomCursorCache::GetInstance()->InstallCustomCursor(image); |
325 } | 328 } |
326 | 329 |
327 void RefCustomXCursor(::Cursor cursor) { | 330 void RefCustomXCursor(::Cursor cursor) { |
328 XCustomCursorCache::GetInstance()->Ref(cursor); | 331 XCustomCursorCache::GetInstance()->Ref(cursor); |
329 } | 332 } |
330 | 333 |
331 void UnrefCustomXCursor(::Cursor cursor) { | 334 void UnrefCustomXCursor(::Cursor cursor) { |
332 XCustomCursorCache::GetInstance()->Unref(cursor); | 335 XCustomCursorCache::GetInstance()->Unref(cursor); |
(...skipping 931 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1264 ::Cursor XScopedCursor::get() const { | 1267 ::Cursor XScopedCursor::get() const { |
1265 return cursor_; | 1268 return cursor_; |
1266 } | 1269 } |
1267 | 1270 |
1268 void XScopedCursor::reset(::Cursor cursor) { | 1271 void XScopedCursor::reset(::Cursor cursor) { |
1269 if (cursor_) | 1272 if (cursor_) |
1270 XFreeCursor(display_, cursor_); | 1273 XFreeCursor(display_, cursor_); |
1271 cursor_ = cursor; | 1274 cursor_ = cursor; |
1272 } | 1275 } |
1273 | 1276 |
| 1277 namespace test { |
| 1278 |
| 1279 void ResetXCursorCache() { |
| 1280 delete cursor_cache; |
| 1281 cursor_cache = NULL; |
| 1282 } |
| 1283 |
| 1284 const XcursorImage* GetCachedXcursorImage(::Cursor cursor) { |
| 1285 return XCustomCursorCache::GetInstance()->GetXcursorImage(cursor); |
| 1286 } |
| 1287 } |
| 1288 |
1274 // ---------------------------------------------------------------------------- | 1289 // ---------------------------------------------------------------------------- |
1275 // These functions are declared in x11_util_internal.h because they require | 1290 // These functions are declared in x11_util_internal.h because they require |
1276 // XLib.h to be included, and it conflicts with many other headers. | 1291 // XLib.h to be included, and it conflicts with many other headers. |
1277 XRenderPictFormat* GetRenderARGB32Format(XDisplay* dpy) { | 1292 XRenderPictFormat* GetRenderARGB32Format(XDisplay* dpy) { |
1278 static XRenderPictFormat* pictformat = NULL; | 1293 static XRenderPictFormat* pictformat = NULL; |
1279 if (pictformat) | 1294 if (pictformat) |
1280 return pictformat; | 1295 return pictformat; |
1281 | 1296 |
1282 // First look for a 32-bit format which ignores the alpha value | 1297 // First look for a 32-bit format which ignores the alpha value |
1283 XRenderPictFormat templ; | 1298 XRenderPictFormat templ; |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1357 << "request_code " << static_cast<int>(error_event.request_code) << ", " | 1372 << "request_code " << static_cast<int>(error_event.request_code) << ", " |
1358 << "minor_code " << static_cast<int>(error_event.minor_code) | 1373 << "minor_code " << static_cast<int>(error_event.minor_code) |
1359 << " (" << request_str << ")"; | 1374 << " (" << request_str << ")"; |
1360 } | 1375 } |
1361 | 1376 |
1362 // ---------------------------------------------------------------------------- | 1377 // ---------------------------------------------------------------------------- |
1363 // End of x11_util_internal.h | 1378 // End of x11_util_internal.h |
1364 | 1379 |
1365 | 1380 |
1366 } // namespace ui | 1381 } // namespace ui |
OLD | NEW |