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

Side by Side Diff: ui/gfx/display.cc

Issue 992383002: Fix for the WebInputEventBuilderTest.TestMouseEventScale content_unittests failures on the DrMemory… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed boneheaded error Created 5 years, 9 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 | « ui/gfx/display.h ('k') | 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/gfx/display.h" 5 #include "ui/gfx/display.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/strings/string_number_conversions.h" 11 #include "base/strings/string_number_conversions.h"
12 #include "base/strings/stringprintf.h" 12 #include "base/strings/stringprintf.h"
13 #include "ui/gfx/geometry/insets.h" 13 #include "ui/gfx/geometry/insets.h"
14 #include "ui/gfx/geometry/point_conversions.h" 14 #include "ui/gfx/geometry/point_conversions.h"
15 #include "ui/gfx/geometry/point_f.h" 15 #include "ui/gfx/geometry/point_f.h"
16 #include "ui/gfx/geometry/size_conversions.h" 16 #include "ui/gfx/geometry/size_conversions.h"
17 #include "ui/gfx/switches.h" 17 #include "ui/gfx/switches.h"
18 18
19 namespace gfx { 19 namespace gfx {
20 namespace { 20 namespace {
21 21
22 // This variable tracks whether the forced device scale factor switch needs to
23 // be read from the command line, i.e. if it is set to -1 then the command line
24 // is checked.
25 int g_has_forced_device_scale_factor = -1;
26
27 // This variable caches the forced device scale factor value which is read off
28 // the command line. If the cache is invalidated by setting this variable to
29 // -1.0, we read the forced device scale factor again.
30 float g_forced_device_scale_factor = -1.0;
31
22 bool HasForceDeviceScaleFactorImpl() { 32 bool HasForceDeviceScaleFactorImpl() {
23 return base::CommandLine::ForCurrentProcess()->HasSwitch( 33 return base::CommandLine::ForCurrentProcess()->HasSwitch(
24 switches::kForceDeviceScaleFactor); 34 switches::kForceDeviceScaleFactor);
25 } 35 }
26 36
27 float GetForcedDeviceScaleFactorImpl() { 37 float GetForcedDeviceScaleFactorImpl() {
28 double scale_in_double = 1.0; 38 double scale_in_double = 1.0;
29 if (HasForceDeviceScaleFactorImpl()) { 39 if (HasForceDeviceScaleFactorImpl()) {
30 std::string value = 40 std::string value =
31 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( 41 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
32 switches::kForceDeviceScaleFactor); 42 switches::kForceDeviceScaleFactor);
33 if (!base::StringToDouble(value, &scale_in_double)) 43 if (!base::StringToDouble(value, &scale_in_double))
34 LOG(ERROR) << "Failed to parse the default device scale factor:" << value; 44 LOG(ERROR) << "Failed to parse the default device scale factor:" << value;
35 } 45 }
36 return static_cast<float>(scale_in_double); 46 return static_cast<float>(scale_in_double);
37 } 47 }
38 48
39 int64 internal_display_id_ = -1; 49 int64 internal_display_id_ = -1;
40 50
41 } // namespace 51 } // namespace
42 52
43 const int64 Display::kInvalidDisplayID = -1; 53 const int64 Display::kInvalidDisplayID = -1;
44 54
45 // static 55 // static
46 float Display::GetForcedDeviceScaleFactor() { 56 float Display::GetForcedDeviceScaleFactor() {
47 static const float kForcedDeviceScaleFactor = 57 if (g_forced_device_scale_factor < 0)
48 GetForcedDeviceScaleFactorImpl(); 58 g_forced_device_scale_factor = GetForcedDeviceScaleFactorImpl();
49 return kForcedDeviceScaleFactor; 59 return g_forced_device_scale_factor;
50 } 60 }
51 61
52 //static 62 //static
53 bool Display::HasForceDeviceScaleFactor() { 63 bool Display::HasForceDeviceScaleFactor() {
54 static const bool kHasForceDeviceScaleFactor = 64 if (g_has_forced_device_scale_factor == -1)
55 HasForceDeviceScaleFactorImpl(); 65 g_has_forced_device_scale_factor = HasForceDeviceScaleFactorImpl();
56 return kHasForceDeviceScaleFactor; 66 return !!g_has_forced_device_scale_factor;
67 }
68
69 // static
70 void Display::ResetForceDeviceScaleFactorForTesting() {
71 g_has_forced_device_scale_factor = -1;
72 g_forced_device_scale_factor = -1.0;
57 } 73 }
58 74
59 Display::Display() 75 Display::Display()
60 : id_(kInvalidDisplayID), 76 : id_(kInvalidDisplayID),
61 device_scale_factor_(GetForcedDeviceScaleFactor()), 77 device_scale_factor_(GetForcedDeviceScaleFactor()),
62 rotation_(ROTATE_0), 78 rotation_(ROTATE_0),
63 touch_support_(TOUCH_SUPPORT_UNKNOWN) { 79 touch_support_(TOUCH_SUPPORT_UNKNOWN) {
64 } 80 }
65 81
66 Display::Display(int64 id) 82 Display::Display(int64 id)
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 200
185 int64 Display::InternalDisplayId() { 201 int64 Display::InternalDisplayId() {
186 return internal_display_id_; 202 return internal_display_id_;
187 } 203 }
188 204
189 void Display::SetInternalDisplayId(int64 internal_display_id) { 205 void Display::SetInternalDisplayId(int64 internal_display_id) {
190 internal_display_id_ = internal_display_id; 206 internal_display_id_ = internal_display_id;
191 } 207 }
192 208
193 } // namespace gfx 209 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/display.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698