Chromium Code Reviews| 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/mac_util.h" | 10 #include "base/mac/mac_util.h" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 47 // canDrawInCGLContext for other value meanings. | 47 // canDrawInCGLContext for other value meanings. |
| 48 TRACE_COUNTER_ID1("browser", "PendingSwapAck", this, 2); | 48 TRACE_COUNTER_ID1("browser", "PendingSwapAck", this, 2); |
| 49 | 49 |
| 50 has_pending_frame_ = true; | 50 has_pending_frame_ = true; |
| 51 needs_display_ = true; | 51 needs_display_ = true; |
| 52 timer_.Reset(); | 52 timer_.Reset(); |
| 53 | 53 |
| 54 // If reqested, draw immediately and don't bother trying to use the | 54 // If reqested, draw immediately and don't bother trying to use the |
| 55 // isAsynchronous property to ensure smooth animation. | 55 // isAsynchronous property to ensure smooth animation. |
| 56 if (client_->AcceleratedLayerShouldAckImmediately()) { | 56 if (client_->AcceleratedLayerShouldAckImmediately()) { |
| 57 ImmediatelyForceDisplayAndAck(); | 57 SetNeedsDisplayAndDisplayAndAck(); |
| 58 } else { | 58 } else { |
| 59 if (![layer_ isAsynchronous]) | 59 if (![layer_ isAsynchronous]) |
| 60 [layer_ setAsynchronous:YES]; | 60 [layer_ setAsynchronous:YES]; |
| 61 } | 61 } |
| 62 } | 62 } |
| 63 | 63 |
| 64 void CompositingIOSurfaceLayerHelper::SetNeedsDisplay() { | 64 void CompositingIOSurfaceLayerHelper::SetNeedsDisplay() { |
| 65 needs_display_ = true; | 65 needs_display_ = true; |
| 66 } | 66 } |
| 67 | 67 |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 97 | 97 |
| 98 void CompositingIOSurfaceLayerHelper::AckPendingFrame(bool success) { | 98 void CompositingIOSurfaceLayerHelper::AckPendingFrame(bool success) { |
| 99 if (!has_pending_frame_) | 99 if (!has_pending_frame_) |
| 100 return; | 100 return; |
| 101 has_pending_frame_ = false; | 101 has_pending_frame_ = false; |
| 102 client_->AcceleratedLayerDidDrawFrame(success); | 102 client_->AcceleratedLayerDidDrawFrame(success); |
| 103 // A trace value of 0 indicates that there is no longer a pending swap ack. | 103 // A trace value of 0 indicates that there is no longer a pending swap ack. |
| 104 TRACE_COUNTER_ID1("browser", "PendingSwapAck", this, 0); | 104 TRACE_COUNTER_ID1("browser", "PendingSwapAck", this, 0); |
| 105 } | 105 } |
| 106 | 106 |
| 107 void CompositingIOSurfaceLayerHelper::ImmediatelyForceDisplayAndAck() { | 107 void CompositingIOSurfaceLayerHelper::SetNeedsDisplayAndDisplayAndAck() { |
| 108 // Drawing using setNeedsDisplay and displayIfNeeded will result in | |
| 109 // subsequent canDrawInCGLContext callbacks getting dropped, and jerky | |
| 110 // animation. Disable asynchronous drawing before issuing these calls as a | |
| 111 // workaround. | |
| 112 // http://crbug.com/395827 | |
| 113 if ([layer_ isAsynchronous]) | |
| 114 [layer_ setAsynchronous:NO]; | |
|
Ken Russell (switch to Gerrit)
2014/07/22 19:52:04
I don't know the various state transitions done to
ccameron
2014/07/23 07:50:34
It gets re-set to asynchronous as soon as a new fr
| |
| 115 | |
| 108 [layer_ setNeedsDisplay]; | 116 [layer_ setNeedsDisplay]; |
| 117 DisplayIfNeededAndAck(); | |
| 118 } | |
| 119 | |
| 120 void CompositingIOSurfaceLayerHelper::DisplayIfNeededAndAck() { | |
| 121 if (!needs_display_) | |
| 122 return; | |
| 123 | |
| 124 // As in SetNeedsDisplayAndDisplayAndAck, disable asynchronous drawing before | |
| 125 // issuing displayIfNeeded. | |
| 126 // http://crbug.com/395827 | |
| 127 if ([layer_ isAsynchronous]) | |
| 128 [layer_ setAsynchronous:NO]; | |
| 129 | |
| 109 [layer_ displayIfNeeded]; | 130 [layer_ displayIfNeeded]; |
| 110 | 131 |
| 111 // Calls to setNeedsDisplay can sometimes be ignored, especially if issued | 132 // Calls to setNeedsDisplay can sometimes be ignored, especially if issued |
| 112 // rapidly (e.g, with vsync off). This is unacceptable because the failure | 133 // rapidly (e.g, with vsync off). This is unacceptable because the failure |
| 113 // to ack a single frame will hang the renderer. Ensure that the renderer | 134 // to ack a single frame will hang the renderer. Ensure that the renderer |
| 114 // not be blocked by lying and claiming that we drew the frame. | 135 // not be blocked by lying and claiming that we drew the frame. |
| 115 AckPendingFrame(true); | 136 AckPendingFrame(true); |
| 116 } | 137 } |
| 117 | 138 |
| 118 void CompositingIOSurfaceLayerHelper::TimerFired() { | 139 void CompositingIOSurfaceLayerHelper::TimerFired() { |
| 119 ImmediatelyForceDisplayAndAck(); | 140 SetNeedsDisplayAndDisplayAndAck(); |
| 120 } | 141 } |
| 121 | 142 |
| 122 } // namespace content | 143 } // namespace content |
| 123 | 144 |
| 124 //////////////////////////////////////////////////////////////////////////////// | 145 //////////////////////////////////////////////////////////////////////////////// |
| 125 // CompositingIOSurfaceLayer | 146 // CompositingIOSurfaceLayer |
| 126 | 147 |
| 127 @implementation CompositingIOSurfaceLayer | 148 @implementation CompositingIOSurfaceLayer |
| 128 | 149 |
| 129 - (content::CompositingIOSurfaceMac*)iosurface { | 150 - (content::CompositingIOSurfaceMac*)iosurface { |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 164 } | 185 } |
| 165 | 186 |
| 166 - (void)resetClient { | 187 - (void)resetClient { |
| 167 helper_.reset(); | 188 helper_.reset(); |
| 168 } | 189 } |
| 169 | 190 |
| 170 - (void)gotNewFrame { | 191 - (void)gotNewFrame { |
| 171 helper_->GotNewFrame(); | 192 helper_->GotNewFrame(); |
| 172 } | 193 } |
| 173 | 194 |
| 195 - (void)setNeedsDisplayAndDisplayAndAck { | |
| 196 helper_->SetNeedsDisplayAndDisplayAndAck(); | |
| 197 } | |
| 198 | |
| 199 - (void)displayIfNeededAndAck { | |
| 200 helper_->DisplayIfNeededAndAck(); | |
| 201 } | |
| 202 | |
| 174 // The remaining methods implement the CAOpenGLLayer interface. | 203 // The remaining methods implement the CAOpenGLLayer interface. |
| 175 | 204 |
| 176 - (CGLPixelFormatObj)copyCGLPixelFormatForDisplayMask:(uint32_t)mask { | 205 - (CGLPixelFormatObj)copyCGLPixelFormatForDisplayMask:(uint32_t)mask { |
| 177 if (!context_) | 206 if (!context_) |
| 178 return [super copyCGLPixelFormatForDisplayMask:mask]; | 207 return [super copyCGLPixelFormatForDisplayMask:mask]; |
| 179 return CGLRetainPixelFormat(CGLGetPixelFormat(context_->cgl_context())); | 208 return CGLRetainPixelFormat(CGLGetPixelFormat(context_->cgl_context())); |
| 180 } | 209 } |
| 181 | 210 |
| 182 - (CGLContextObj)copyCGLContextForPixelFormat:(CGLPixelFormatObj)pixelFormat { | 211 - (CGLContextObj)copyCGLContextForPixelFormat:(CGLPixelFormatObj)pixelFormat { |
| 183 if (!context_) | 212 if (!context_) |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 230 if (helper_) | 259 if (helper_) |
| 231 helper_->DidDraw(draw_succeeded); | 260 helper_->DidDraw(draw_succeeded); |
| 232 | 261 |
| 233 [super drawInCGLContext:glContext | 262 [super drawInCGLContext:glContext |
| 234 pixelFormat:pixelFormat | 263 pixelFormat:pixelFormat |
| 235 forLayerTime:timeInterval | 264 forLayerTime:timeInterval |
| 236 displayTime:timeStamp]; | 265 displayTime:timeStamp]; |
| 237 } | 266 } |
| 238 | 267 |
| 239 @end | 268 @end |
| OLD | NEW |