OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "content/browser/renderer_host/compositing_iosurface_layer_mac.h" | 5 #include "content/browser/renderer_host/compositing_iosurface_layer_mac.h" |
6 | 6 |
7 #include <CoreFoundation/CoreFoundation.h> | 7 #include <CoreFoundation/CoreFoundation.h> |
8 #include <OpenGL/gl.h> | 8 #include <OpenGL/gl.h> |
9 | 9 |
10 #include "base/mac/sdk_forward_declarations.h" | 10 #include "base/mac/sdk_forward_declarations.h" |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 | 95 |
96 // Cache a copy of renderWidgetHostView_ because it may be reset if | 96 // Cache a copy of renderWidgetHostView_ because it may be reset if |
97 // a software frame is received in GetBackingStore. | 97 // a software frame is received in GetBackingStore. |
98 content::RenderWidgetHostViewMac* cached_view = renderWidgetHostView_; | 98 content::RenderWidgetHostViewMac* cached_view = renderWidgetHostView_; |
99 | 99 |
100 // If a resize is in progress then GetBackingStore request a frame of the | 100 // If a resize is in progress then GetBackingStore request a frame of the |
101 // current window size and block until a frame of the right size comes in. | 101 // current window size and block until a frame of the right size comes in. |
102 // This makes the window content not lag behind the resize (at the cost of | 102 // This makes the window content not lag behind the resize (at the cost of |
103 // blocking on the browser's main thread). | 103 // blocking on the browser's main thread). |
104 if (cached_view->render_widget_host_) { | 104 if (cached_view->render_widget_host_) { |
105 cached_view->about_to_validate_and_paint_ = true; | 105 // Note that GetBackingStore can potentially spawn a nested run loop, which |
106 (void)cached_view->render_widget_host_->GetBackingStore(true); | 106 // may change the current GL context, or, because the GL contexts are |
107 cached_view->about_to_validate_and_paint_ = false; | 107 // shared, may change the currently-bound FBO. Ensure that, when the run |
108 CGLSetCurrentContext(glContext); | 108 // loop returns, the original GL context remain current, and the original |
| 109 // FBO remain bound. |
| 110 // TODO(ccameron): This is far too fragile a mechanism to rely on. Find |
| 111 // a way to avoid doing this. |
| 112 GLuint previous_framebuffer = 0; |
| 113 glGetIntegerv(GL_FRAMEBUFFER_BINDING, |
| 114 reinterpret_cast<GLint*>(&previous_framebuffer)); |
| 115 { |
| 116 gfx::ScopedCGLSetCurrentContext scoped_set_current_context(NULL); |
| 117 cached_view->about_to_validate_and_paint_ = true; |
| 118 (void)cached_view->render_widget_host_->GetBackingStore(true); |
| 119 cached_view->about_to_validate_and_paint_ = false; |
| 120 } |
| 121 CHECK_EQ(CGLGetCurrentContext(), glContext) |
| 122 << "original GL context failed to re-bind after nested run loop, " |
| 123 << "browser crash is imminent."; |
| 124 glBindFramebuffer(GL_FRAMEBUFFER, previous_framebuffer); |
109 } | 125 } |
110 | 126 |
111 // If a transition to software mode has occurred, this layer should be | 127 // If a transition to software mode has occurred, this layer should be |
112 // removed from the heirarchy now, so don't draw anything. | 128 // removed from the heirarchy now, so don't draw anything. |
113 if (!renderWidgetHostView_) | 129 if (!renderWidgetHostView_) |
114 return; | 130 return; |
115 | 131 |
116 gfx::Rect window_rect([self frame]); | 132 gfx::Rect window_rect([self frame]); |
117 float window_scale_factor = 1.f; | 133 float window_scale_factor = 1.f; |
118 if ([self respondsToSelector:(@selector(contentsScale))]) | 134 if ([self respondsToSelector:(@selector(contentsScale))]) |
119 window_scale_factor = [self contentsScale]; | 135 window_scale_factor = [self contentsScale]; |
120 | 136 |
121 if (!renderWidgetHostView_->compositing_iosurface_->DrawIOSurface( | 137 if (!renderWidgetHostView_->compositing_iosurface_->DrawIOSurface( |
122 context_, | 138 context_, |
123 window_rect, | 139 window_rect, |
124 window_scale_factor, | 140 window_scale_factor, |
125 false)) { | 141 false)) { |
126 renderWidgetHostView_->GotAcceleratedCompositingError(); | 142 renderWidgetHostView_->GotAcceleratedCompositingError(); |
127 return; | 143 return; |
128 } | 144 } |
129 | 145 |
130 renderWidgetHostView_->SendPendingLatencyInfoToHost(); | 146 renderWidgetHostView_->SendPendingLatencyInfoToHost(); |
131 } | 147 } |
132 | 148 |
133 @end | 149 @end |
OLD | NEW |