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 |