Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(23)

Side by Side Diff: chrome/common/x11_util.cc

Issue 210021: Changes x11_util::GetRenderVisualFormat to determine the format id... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/common/x11_util_internal.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 "chrome/common/x11_util.h" 9 #include "chrome/common/x11_util.h"
10 10
11 #include <gdk/gdk.h> 11 #include <gdk/gdk.h>
12 #include <gdk/gdkx.h> 12 #include <gdk/gdkx.h>
13 #include <gtk/gtk.h> 13 #include <gtk/gtk.h>
14 14
15 #include <sys/ipc.h> 15 #include <sys/ipc.h>
16 #include <sys/shm.h> 16 #include <sys/shm.h>
17 17
18 #include <list>
18 #include <set> 19 #include <set>
19 20
20 #include "base/logging.h" 21 #include "base/logging.h"
21 #include "base/gfx/size.h" 22 #include "base/gfx/size.h"
22 #include "base/thread.h" 23 #include "base/thread.h"
23 #include "chrome/common/x11_util_internal.h" 24 #include "chrome/common/x11_util_internal.h"
24 25
25 namespace x11_util { 26 namespace x11_util {
26 27
28 namespace {
29
30 // Used to cache the XRenderPictFormat for a visual/display pair.
31 struct CachedPictFormat {
32 bool equals(Display* display, Visual* visual) const {
33 return display == this->display && visual == this->visual;
34 }
35
36 Display* display;
37 Visual* visual;
38 XRenderPictFormat* format;
39 };
40
41 typedef std::list<CachedPictFormat> CachedPictFormats;
42
43 // Returns the cache of pict formats.
44 CachedPictFormats* get_cached_pict_formats() {
evanm 2010/11/09 19:30:17 Why not GetCachedPictFormats?
45 static CachedPictFormats* formats = NULL;
46 if (!formats)
47 formats = new CachedPictFormats();
48 return formats;
49 }
50
51 // Maximum number of CachedPictFormats we keep around.
52 const size_t kMaxCacheSize = 5;
53
54 } // namespace
55
27 bool XDisplayExists() { 56 bool XDisplayExists() {
28 return (gdk_display_get_default() != NULL); 57 return (gdk_display_get_default() != NULL);
29 } 58 }
30 59
31 Display* GetXDisplay() { 60 Display* GetXDisplay() {
32 static Display* display = NULL; 61 static Display* display = NULL;
33 62
34 if (!display) 63 if (!display)
35 display = gdk_x11_get_default_xdisplay(); 64 display = gdk_x11_get_default_xdisplay();
36 65
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 windows->insert(windows->begin(), stack[i]); 352 windows->insert(windows->begin(), stack[i]);
324 } 353 }
325 354
326 if (data) 355 if (data)
327 XFree(data); 356 XFree(data);
328 357
329 return result; 358 return result;
330 } 359 }
331 360
332 XRenderPictFormat* GetRenderVisualFormat(Display* dpy, Visual* visual) { 361 XRenderPictFormat* GetRenderVisualFormat(Display* dpy, Visual* visual) {
333 static XRenderPictFormat* pictformat = NULL;
334 if (pictformat)
335 return pictformat;
336
337 DCHECK(QueryRenderSupport(dpy)); 362 DCHECK(QueryRenderSupport(dpy));
338 363
339 pictformat = XRenderFindVisualFormat(dpy, visual); 364 CachedPictFormats* formats = get_cached_pict_formats();
365
366 for (CachedPictFormats::const_iterator i = formats->begin();
367 i != formats->end(); ++i) {
368 if (i->equals(dpy, visual))
369 return i->format;
370 }
371
372 // Not cached, look up the value.
373 XRenderPictFormat* pictformat = XRenderFindVisualFormat(dpy, visual);
340 CHECK(pictformat) << "XRENDER does not support default visual"; 374 CHECK(pictformat) << "XRENDER does not support default visual";
341 375
376 // And store it in the cache.
377 CachedPictFormat cached_value;
378 cached_value.visual = visual;
379 cached_value.display = dpy;
380 cached_value.format = pictformat;
381 formats->push_front(cached_value);
382
383 if (formats->size() == kMaxCacheSize)
384 formats->pop_back();
385
342 return pictformat; 386 return pictformat;
343 } 387 }
344 388
345 XRenderPictFormat* GetRenderARGB32Format(Display* dpy) { 389 XRenderPictFormat* GetRenderARGB32Format(Display* dpy) {
346 static XRenderPictFormat* pictformat = NULL; 390 static XRenderPictFormat* pictformat = NULL;
347 if (pictformat) 391 if (pictformat)
348 return pictformat; 392 return pictformat;
349 393
350 // First look for a 32-bit format which ignores the alpha value 394 // First look for a 32-bit format which ignores the alpha value
351 XRenderPictFormat templ; 395 XRenderPictFormat templ;
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
460 return false; 504 return false;
461 505
462 if (children) 506 if (children)
463 XFree(children); 507 XFree(children);
464 508
465 *parent_is_root = root_window == *parent_window; 509 *parent_is_root = root_window == *parent_window;
466 return true; 510 return true;
467 } 511 }
468 512
469 } // namespace x11_util 513 } // namespace x11_util
OLDNEW
« no previous file with comments | « no previous file | chrome/common/x11_util_internal.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698