Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #ifndef UI_BASE_X_X11_UTIL_INTERNAL_H_ | 5 #ifndef UI_BASE_X_X11_UTIL_INTERNAL_H_ |
| 6 #define UI_BASE_X_X11_UTIL_INTERNAL_H_ | 6 #define UI_BASE_X_X11_UTIL_INTERNAL_H_ |
| 7 | 7 |
| 8 // This file declares utility functions for X11 (Linux only). | 8 // This file declares utility functions for X11 (Linux only). |
| 9 // | 9 // |
| 10 // These functions require the inclusion of the Xlib headers. Since the Xlib | 10 // These functions require the inclusion of the Xlib headers. Since the Xlib |
| 11 // headers pollute so much of the namespace, this should only be included | 11 // headers pollute so much of the namespace, this should only be included |
| 12 // when needed. | 12 // when needed. |
| 13 | 13 |
| 14 extern "C" { | 14 extern "C" { |
| 15 #include <X11/extensions/Xrender.h> | 15 #include <X11/extensions/Xrender.h> |
| 16 #include <X11/extensions/XShm.h> | 16 #include <X11/extensions/XShm.h> |
| 17 #include <X11/Xatom.h> | 17 #include <X11/Xatom.h> |
| 18 #include <X11/Xlib.h> | 18 #include <X11/Xlib.h> |
| 19 } | 19 } |
| 20 | 20 |
| 21 #include <memory> | |
| 22 #include <unordered_map> | |
| 23 | |
| 21 #include "build/build_config.h" | 24 #include "build/build_config.h" |
| 22 #include "ui/base/x/ui_base_x_export.h" | 25 #include "ui/base/x/ui_base_x_export.h" |
| 26 #include "ui/gfx/x/x11_types.h" | |
| 27 | |
| 28 namespace base { | |
| 29 template <typename T> | |
| 30 struct DefaultSingletonTraits; | |
| 31 } | |
| 23 | 32 |
| 24 namespace ui { | 33 namespace ui { |
| 25 | 34 |
| 26 // -------------------------------------------------------------------------- | 35 // -------------------------------------------------------------------------- |
| 27 // NOTE: these functions cache the results and must be called from the UI | 36 // NOTE: these functions cache the results and must be called from the UI |
| 28 // thread. | 37 // thread. |
| 29 // Get the XRENDER format id for ARGB32 (Skia's format). | 38 // Get the XRENDER format id for ARGB32 (Skia's format). |
| 30 // | 39 // |
| 31 // NOTE:Currently this don't support multiple screens/displays. | 40 // NOTE:Currently this don't support multiple screens/displays. |
| 32 UI_BASE_X_EXPORT XRenderPictFormat* GetRenderARGB32Format(Display* dpy); | 41 UI_BASE_X_EXPORT XRenderPictFormat* GetRenderARGB32Format(Display* dpy); |
| 33 | 42 |
| 34 // -------------------------------------------------------------------------- | 43 // -------------------------------------------------------------------------- |
| 35 // X11 error handling. | 44 // X11 error handling. |
| 36 // Sets the X Error Handlers. Passing NULL for either will enable the default | 45 // Sets the X Error Handlers. Passing NULL for either will enable the default |
| 37 // error handler, which if called will log the error and abort the process. | 46 // error handler, which if called will log the error and abort the process. |
| 38 UI_BASE_X_EXPORT void SetX11ErrorHandlers(XErrorHandler error_handler, | 47 UI_BASE_X_EXPORT void SetX11ErrorHandlers(XErrorHandler error_handler, |
| 39 XIOErrorHandler io_error_handler); | 48 XIOErrorHandler io_error_handler); |
| 40 | 49 |
| 41 // NOTE: This function should not be called directly from the | 50 // NOTE: This function should not be called directly from the |
| 42 // X11 Error handler because it queries the server to decode the | 51 // X11 Error handler because it queries the server to decode the |
| 43 // error message, which may trigger other errors. A suitable workaround | 52 // error message, which may trigger other errors. A suitable workaround |
| 44 // is to post a task in the error handler to call this function. | 53 // is to post a task in the error handler to call this function. |
| 45 UI_BASE_X_EXPORT void LogErrorEventDescription(Display* dpy, | 54 UI_BASE_X_EXPORT void LogErrorEventDescription(Display* dpy, |
| 46 const XErrorEvent& error_event); | 55 const XErrorEvent& error_event); |
| 47 | 56 |
| 48 // -------------------------------------------------------------------------- | 57 // -------------------------------------------------------------------------- |
| 49 // Selects a visual with a preference for alpha support on compositing window | 58 // Selects a visual with a preference for alpha support on compositing window |
| 50 // managers. The caller must compare depth to 32 to know if the returned visual | 59 // managers. |
| 51 // supports transparency. NULL parameters are allowed to install or query the | |
| 52 // cached visual and depth. | |
| 53 #if !defined(OS_CHROMEOS) | 60 #if !defined(OS_CHROMEOS) |
| 54 UI_BASE_X_EXPORT void ChooseVisualForWindow(bool enable_transparent_visuals, | 61 class UI_BASE_X_EXPORT XVisualManager { |
| 55 Visual** visual, | 62 public: |
| 56 int* depth); | 63 static XVisualManager* GetInstance(); |
| 64 | |
| 65 void ChooseVisualForWindow(bool want_argb_visual, | |
| 66 Visual** visual, | |
| 67 int* depth, | |
| 68 Colormap* colormap, | |
| 69 bool* using_argb_visual); | |
| 70 | |
| 71 // Called by GpuDataManagerImplPrivate when GPUInfo becomes available. It is | |
| 72 // necessary for the GPU process to find out which visuals are best for GL | |
| 73 // because we don't want to load GL in the browser process. | |
| 74 void OnGPUInfoChanged(bool software_rendering, | |
| 75 VisualID default_visual_id, | |
| 76 VisualID transparent_visual_id); | |
| 77 | |
| 78 ~XVisualManager(); | |
| 79 | |
| 80 private: | |
| 81 friend struct base::DefaultSingletonTraits<XVisualManager>; | |
| 82 | |
| 83 class XVisualData { | |
| 84 public: | |
| 85 XVisualData(XVisualInfo visual_info); | |
|
piman
2016/09/22 21:24:55
nit: explicit
Tom (Use chromium acct)
2016/09/23 20:00:37
Done.
| |
| 86 ~XVisualData(); | |
| 87 | |
| 88 Colormap GetColormap(); | |
| 89 | |
| 90 const XVisualInfo visual_info; | |
| 91 | |
| 92 private: | |
| 93 Colormap colormap_; | |
| 94 }; | |
| 95 | |
| 96 XVisualManager(); | |
| 97 | |
| 98 std::unordered_map<VisualID, std::unique_ptr<XVisualData>> visuals_; | |
| 99 | |
| 100 XDisplay* display_; | |
| 101 | |
| 102 VisualID default_visual_id_; | |
| 103 VisualID transparent_visual_id_; | |
| 104 | |
| 105 bool using_compositing_wm_; | |
| 106 bool using_software_rendering_; | |
| 107 bool have_gpu_argb_visual_; | |
| 108 }; | |
| 57 #endif | 109 #endif |
| 58 | 110 |
| 59 } // namespace ui | 111 } // namespace ui |
| 60 | 112 |
| 61 #endif // UI_BASE_X_X11_UTIL_INTERNAL_H_ | 113 #endif // UI_BASE_X_X11_UTIL_INTERNAL_H_ |
| OLD | NEW |