Chromium Code Reviews| Index: ui/views/widget/desktop_aura/desktop_window_tree_host_x11.cc |
| diff --git a/ui/views/widget/desktop_aura/desktop_window_tree_host_x11.cc b/ui/views/widget/desktop_aura/desktop_window_tree_host_x11.cc |
| index cfc4f0d6f8c37cf2da4e63a17ef5495930eb79f1..c33ace6a3c165c71b682f615d1753b2eafe90fa9 100644 |
| --- a/ui/views/widget/desktop_aura/desktop_window_tree_host_x11.cc |
| +++ b/ui/views/widget/desktop_aura/desktop_window_tree_host_x11.cc |
| @@ -10,6 +10,7 @@ |
| #include <X11/Xregion.h> |
| #include <X11/Xutil.h> |
| +#include <algorithm> |
| #include <utility> |
| #include "base/command_line.h" |
| @@ -1092,7 +1093,15 @@ void DesktopWindowTreeHostX11::SetOpacity(float opacity) { |
| // X server opacity is in terms of 32 bit unsigned int space, and counts from |
| // the opposite direction. |
| // XChangeProperty() expects "cardinality" to be long. |
| - unsigned long cardinality = static_cast<int>(opacity * 255) * 0x1010101; |
|
sky
2017/01/03 17:54:27
Can you outline where this goes wrong? Before my c
|
| + |
| + // Clamp opacity to [0.0 .. 1.0] range. |
| + float clamped_opacity = std::max(0.0f, std::min(1.0f, opacity)); |
|
sky
2017/01/03 17:54:27
We don't do this anywhere else. It's assumed the v
|
| + // Scale opacity to [0 .. 255] range. |
| + unsigned long opacity_8bit = |
| + static_cast<unsigned long>(clamped_opacity * 255.0f); |
| + // Use opacity value for all channels. |
| + const unsigned long channel_multiplier = 0x1010101; |
| + unsigned long cardinality = opacity_8bit * channel_multiplier; |
| if (cardinality == 0xffffffff) { |
| XDeleteProperty(xdisplay_, xwindow_, |