[Android] Implement 3-way sensor fallback for Device Orientation.
[chromium-blink-merge.git] / ui / gfx / mac / scoped_cocoa_disable_screen_updates.h
blob61c9f58e5b371adee2825c80f340291253ffb6d4
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
3 // found in the LICENSE file.
5 #ifndef UI_GFX_MAC_SCOPED_COCOA_DISABLE_SCREEN_UPDATES_H_
6 #define UI_GFX_MAC_SCOPED_COCOA_DISABLE_SCREEN_UPDATES_H_
8 #import <Cocoa/Cocoa.h>
10 #include "base/basictypes.h"
11 #include "base/mac/mac_util.h"
13 namespace gfx {
15 // A stack-based class to disable Cocoa screen updates. When instantiated, it
16 // disables screen updates and enables them when destroyed. Update disabling
17 // can be nested, and there is a time-maximum (about 1 second) after which
18 // Cocoa will automatically re-enable updating. This class doesn't attempt to
19 // overrule that.
20 class ScopedCocoaDisableScreenUpdates {
21 public:
22 ScopedCocoaDisableScreenUpdates() {
23 if (base::mac::IsOSElCapitanOrLater()) {
24 // Beginning with OS X 10.11, [NSAnimationContext beginGrouping] is the
25 // preferred way of disabling screen updates. Use of
26 // NSDisableScreenUpdates() is discouraged.
27 [NSAnimationContext beginGrouping];
28 } else {
29 NSDisableScreenUpdates();
32 ~ScopedCocoaDisableScreenUpdates() {
33 if (base::mac::IsOSElCapitanOrLater()) {
34 [NSAnimationContext endGrouping];
35 } else {
36 NSEnableScreenUpdates();
40 private:
41 DISALLOW_COPY_AND_ASSIGN(ScopedCocoaDisableScreenUpdates);
44 } // namespace gfx
46 #endif // UI_GFX_MAC_SCOPED_COCOA_DISABLE_SCREEN_UPDATES_H_