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

Side by Side Diff: ui/views/widget/desktop_aura/desktop_window_tree_host_x11.cc

Issue 2598383002: Fix integer overflow. (Closed)
Patch Set: Fix includes Created 3 years, 11 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
« no previous file with comments | « no previous file | no next file » | 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) 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 #include "ui/views/widget/desktop_aura/desktop_window_tree_host_x11.h" 5 #include "ui/views/widget/desktop_aura/desktop_window_tree_host_x11.h"
6 6
7 #include <X11/extensions/shape.h> 7 #include <X11/extensions/shape.h>
8 #include <X11/extensions/XInput2.h> 8 #include <X11/extensions/XInput2.h>
9 #include <X11/Xatom.h> 9 #include <X11/Xatom.h>
10 #include <X11/Xregion.h> 10 #include <X11/Xregion.h>
11 #include <X11/Xutil.h> 11 #include <X11/Xutil.h>
12 12
13 #include <algorithm>
13 #include <utility> 14 #include <utility>
14 15
15 #include "base/command_line.h" 16 #include "base/command_line.h"
16 #include "base/location.h" 17 #include "base/location.h"
17 #include "base/memory/ptr_util.h" 18 #include "base/memory/ptr_util.h"
18 #include "base/single_thread_task_runner.h" 19 #include "base/single_thread_task_runner.h"
19 #include "base/strings/string_number_conversions.h" 20 #include "base/strings/string_number_conversions.h"
20 #include "base/strings/stringprintf.h" 21 #include "base/strings/stringprintf.h"
21 #include "base/strings/utf_string_conversions.h" 22 #include "base/strings/utf_string_conversions.h"
22 #include "base/threading/thread_task_runner_handle.h" 23 #include "base/threading/thread_task_runner_handle.h"
(...skipping 1062 matching lines...) Expand 10 before | Expand all | Expand 10 after
1085 } 1086 }
1086 1087
1087 bool DesktopWindowTreeHostX11::IsFullscreen() const { 1088 bool DesktopWindowTreeHostX11::IsFullscreen() const {
1088 return is_fullscreen_; 1089 return is_fullscreen_;
1089 } 1090 }
1090 1091
1091 void DesktopWindowTreeHostX11::SetOpacity(float opacity) { 1092 void DesktopWindowTreeHostX11::SetOpacity(float opacity) {
1092 // X server opacity is in terms of 32 bit unsigned int space, and counts from 1093 // X server opacity is in terms of 32 bit unsigned int space, and counts from
1093 // the opposite direction. 1094 // the opposite direction.
1094 // XChangeProperty() expects "cardinality" to be long. 1095 // XChangeProperty() expects "cardinality" to be long.
1095 unsigned long cardinality = static_cast<int>(opacity * 255) * 0x1010101; 1096
sky 2017/01/03 17:54:27 Can you outline where this goes wrong? Before my c
1097 // Clamp opacity to [0.0 .. 1.0] range.
1098 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
1099 // Scale opacity to [0 .. 255] range.
1100 unsigned long opacity_8bit =
1101 static_cast<unsigned long>(clamped_opacity * 255.0f);
1102 // Use opacity value for all channels.
1103 const unsigned long channel_multiplier = 0x1010101;
1104 unsigned long cardinality = opacity_8bit * channel_multiplier;
1096 1105
1097 if (cardinality == 0xffffffff) { 1106 if (cardinality == 0xffffffff) {
1098 XDeleteProperty(xdisplay_, xwindow_, 1107 XDeleteProperty(xdisplay_, xwindow_,
1099 atom_cache_.GetAtom("_NET_WM_WINDOW_OPACITY")); 1108 atom_cache_.GetAtom("_NET_WM_WINDOW_OPACITY"));
1100 } else { 1109 } else {
1101 XChangeProperty(xdisplay_, xwindow_, 1110 XChangeProperty(xdisplay_, xwindow_,
1102 atom_cache_.GetAtom("_NET_WM_WINDOW_OPACITY"), 1111 atom_cache_.GetAtom("_NET_WM_WINDOW_OPACITY"),
1103 XA_CARDINAL, 32, 1112 XA_CARDINAL, 32,
1104 PropModeReplace, 1113 PropModeReplace,
1105 reinterpret_cast<unsigned char*>(&cardinality), 1); 1114 reinterpret_cast<unsigned char*>(&cardinality), 1);
(...skipping 1249 matching lines...) Expand 10 before | Expand all | Expand 10 after
2355 2364
2356 // static 2365 // static
2357 DesktopWindowTreeHost* DesktopWindowTreeHost::Create( 2366 DesktopWindowTreeHost* DesktopWindowTreeHost::Create(
2358 internal::NativeWidgetDelegate* native_widget_delegate, 2367 internal::NativeWidgetDelegate* native_widget_delegate,
2359 DesktopNativeWidgetAura* desktop_native_widget_aura) { 2368 DesktopNativeWidgetAura* desktop_native_widget_aura) {
2360 return new DesktopWindowTreeHostX11(native_widget_delegate, 2369 return new DesktopWindowTreeHostX11(native_widget_delegate,
2361 desktop_native_widget_aura); 2370 desktop_native_widget_aura);
2362 } 2371 }
2363 2372
2364 } // namespace views 2373 } // namespace views
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698