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

Unified Diff: ui/gfx/scoped_ns_graphics_context_save_gstate_mac.mm

Issue 7572031: Always call the class methods to save/restore contexts. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: reword Created 9 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/gfx/scoped_ns_graphics_context_save_gstate_mac.mm
diff --git a/ui/gfx/scoped_ns_graphics_context_save_gstate_mac.mm b/ui/gfx/scoped_ns_graphics_context_save_gstate_mac.mm
index f3992ea0b694a520c9b45b869151144d4237836b..ec15bc341fabd2f3f26420a4e39aec9fe6743134 100644
--- a/ui/gfx/scoped_ns_graphics_context_save_gstate_mac.mm
+++ b/ui/gfx/scoped_ns_graphics_context_save_gstate_mac.mm
@@ -4,19 +4,31 @@
#include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h"
-#include <AppKit/AppKit.h>
+#import <AppKit/AppKit.h>
+
+#include "base/logging.h"
+#include "base/mac/mac_util.h"
namespace gfx {
-ScopedNSGraphicsContextSaveGState::ScopedNSGraphicsContextSaveGState(
- NSGraphicsContext* context) : context_([context retain]) {
- if (!context_)
- context_.reset([[NSGraphicsContext currentContext] retain]);
- [context_ saveGraphicsState];
+ScopedNSGraphicsContextSaveGState::ScopedNSGraphicsContextSaveGState()
+ : context_([NSGraphicsContext currentContext]) {
+ [NSGraphicsContext saveGraphicsState];
}
ScopedNSGraphicsContextSaveGState::~ScopedNSGraphicsContextSaveGState() {
- [context_ restoreGraphicsState];
+ [NSGraphicsContext restoreGraphicsState];
+ if (!context_ && base::mac::IsOSLeopardOrEarlier()) {
+ // On 10.5 and earlier, there is a bug. If the current graphics context was
+ // nil when +[NSGraphicsContext saveGraphicsState] was called, then calling
+ // +[NSGraphicsContext restoreGraphicsState] will not restore a nil current
+ // context, but will leave the current context in place. Because allowing
+ // that stale context (which is likely been dealloced) to remain current
Mark Mentovai 2011/08/05 22:11:32 (which is likely to be dealloced)
+ // will only lead to heartache and pain, the current context must be
+ // manually nilled out.
+ [NSGraphicsContext setCurrentContext:nil];
+ }
+ DCHECK_EQ(context_, [NSGraphicsContext currentContext]);
}
} // namespace gfx
« no previous file with comments | « ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698