OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/compositor/browser_compositor_view_private_mac.h" | 5 #include "content/browser/compositor/browser_compositor_view_private_mac.h" |
6 | 6 |
7 #include "base/debug/trace_event.h" | 7 #include "base/debug/trace_event.h" |
8 #include "content/browser/compositor/gpu_process_transport_factory.h" | 8 #include "content/browser/compositor/gpu_process_transport_factory.h" |
9 #include "content/browser/renderer_host/compositing_iosurface_context_mac.h" | 9 #include "content/browser/renderer_host/compositing_iosurface_context_mac.h" |
10 #include "content/browser/renderer_host/compositing_iosurface_mac.h" | 10 #include "content/browser/renderer_host/compositing_iosurface_mac.h" |
11 #include "content/browser/renderer_host/software_layer_mac.h" | 11 #include "content/browser/renderer_host/software_layer_mac.h" |
12 #include "content/public/browser/context_factory.h" | 12 #include "content/public/browser/context_factory.h" |
13 #include "ui/base/cocoa/animation_utils.h" | 13 #include "ui/base/cocoa/animation_utils.h" |
14 #include "ui/gl/scoped_cgl.h" | 14 #include "ui/gl/scoped_cgl.h" |
15 | 15 |
| 16 @interface CompositingIOSurfaceLayer(Private) |
| 17 - (void)immediatelyForceDisplayAndAck; |
| 18 @end |
| 19 |
16 //////////////////////////////////////////////////////////////////////////////// | 20 //////////////////////////////////////////////////////////////////////////////// |
17 // BrowserCompositorViewCocoa | 21 // BrowserCompositorViewCocoa |
18 | 22 |
19 @implementation BrowserCompositorViewCocoa : NSView | 23 @implementation BrowserCompositorViewCocoa : NSView |
20 | 24 |
21 - (id)init { | 25 - (id)init { |
22 if (self = [super init]) { | 26 if (self = [super init]) { |
23 accelerated_layer_output_surface_id_ = 0; | 27 accelerated_layer_output_surface_id_ = 0; |
24 client_ = NULL; | 28 client_ = NULL; |
25 helper_.reset(new content::BrowserCompositorViewCocoaHelper(self)); | 29 helper_.reset(new content::BrowserCompositorViewCocoaHelper(self)); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 - (void)gotAcceleratedIOSurfaceFrame:(IOSurfaceID)surface_handle | 95 - (void)gotAcceleratedIOSurfaceFrame:(IOSurfaceID)surface_handle |
92 withOutputSurfaceID:(int)surface_id | 96 withOutputSurfaceID:(int)surface_id |
93 withLatencyInfo:(std::vector<ui::LatencyInfo>) latency_info | 97 withLatencyInfo:(std::vector<ui::LatencyInfo>) latency_info |
94 withPixelSize:(gfx::Size)pixel_size | 98 withPixelSize:(gfx::Size)pixel_size |
95 withScaleFactor:(float)scale_factor { | 99 withScaleFactor:(float)scale_factor { |
96 DCHECK(!accelerated_layer_output_surface_id_); | 100 DCHECK(!accelerated_layer_output_surface_id_); |
97 accelerated_layer_output_surface_id_ = surface_id; | 101 accelerated_layer_output_surface_id_ = surface_id; |
98 accelerated_latency_info_.insert(accelerated_latency_info_.end(), | 102 accelerated_latency_info_.insert(accelerated_latency_info_.end(), |
99 latency_info.begin(), latency_info.end()); | 103 latency_info.begin(), latency_info.end()); |
100 | 104 |
| 105 // If the client that wanted to display this frame has disappeared, don't |
| 106 // bother creating the layers, just un-block the compositor and quit. |
| 107 if (!client_) { |
| 108 [self layerDidDrawFrame]; |
| 109 return; |
| 110 } |
| 111 |
101 // Disable the fade-in animation as the layer is added, removed, or resized. | 112 // Disable the fade-in animation as the layer is added, removed, or resized. |
102 ScopedCAActionDisabler disabler; | 113 ScopedCAActionDisabler disabler; |
103 | 114 |
104 // If there is already an accelerated layer, but it has the wrong scale | 115 // If there is already an accelerated layer, but it has the wrong scale |
105 // factor or it was poisoned, remove the old layer and replace it. | 116 // factor or it was poisoned, remove the old layer and replace it. |
106 base::scoped_nsobject<CompositingIOSurfaceLayer> old_accelerated_layer; | 117 base::scoped_nsobject<CompositingIOSurfaceLayer> old_accelerated_layer; |
107 if (accelerated_layer_ && ( | 118 if (accelerated_layer_ && ( |
108 [accelerated_layer_ context]->HasBeenPoisoned() || | 119 [accelerated_layer_ context]->HasBeenPoisoned() || |
109 [accelerated_layer_ iosurface]->scale_factor() != scale_factor)) { | 120 [accelerated_layer_ iosurface]->scale_factor() != scale_factor)) { |
110 old_accelerated_layer = accelerated_layer_; | 121 old_accelerated_layer = accelerated_layer_; |
(...skipping 18 matching lines...) Expand all Loading... |
129 result = [accelerated_layer_ iosurface]->SetIOSurfaceWithContextCurrent( | 140 result = [accelerated_layer_ iosurface]->SetIOSurfaceWithContextCurrent( |
130 [accelerated_layer_ context], surface_handle, pixel_size, scale_factor); | 141 [accelerated_layer_ context], surface_handle, pixel_size, scale_factor); |
131 if (!result) | 142 if (!result) |
132 LOG(ERROR) << "Failed SetIOSurface on CompositingIOSurfaceMac"; | 143 LOG(ERROR) << "Failed SetIOSurface on CompositingIOSurfaceMac"; |
133 } | 144 } |
134 [accelerated_layer_ gotNewFrame]; | 145 [accelerated_layer_ gotNewFrame]; |
135 | 146 |
136 // Set the bounds of the accelerated layer to match the size of the frame. | 147 // Set the bounds of the accelerated layer to match the size of the frame. |
137 // If the bounds changed, force the content to be displayed immediately. | 148 // If the bounds changed, force the content to be displayed immediately. |
138 CGRect new_layer_bounds = CGRectMake( | 149 CGRect new_layer_bounds = CGRectMake( |
139 0, | 150 0, |
140 0, | 151 0, |
141 [accelerated_layer_ iosurface]->dip_io_surface_size().width(), | 152 [accelerated_layer_ iosurface]->dip_io_surface_size().width(), |
142 [accelerated_layer_ iosurface]->dip_io_surface_size().height()); | 153 [accelerated_layer_ iosurface]->dip_io_surface_size().height()); |
143 bool bounds_changed = !CGRectEqualToRect( | 154 bool bounds_changed = !CGRectEqualToRect( |
144 new_layer_bounds, [accelerated_layer_ bounds]); | 155 new_layer_bounds, [accelerated_layer_ bounds]); |
145 [accelerated_layer_ setBounds:new_layer_bounds]; | 156 [accelerated_layer_ setBounds:new_layer_bounds]; |
146 if (bounds_changed || | 157 if (bounds_changed || |
147 (client_ && client_->BrowserCompositorShouldDrawImmediately())) { | 158 (client_ && client_->BrowserCompositorShouldDrawImmediately())) { |
148 [accelerated_layer_ setNeedsDisplay]; | 159 [accelerated_layer_ immediatelyForceDisplayAndAck]; |
149 [accelerated_layer_ displayIfNeeded]; | |
150 } | 160 } |
151 | 161 |
152 // If there was a software layer or an old accelerated layer, remove it. | 162 // If there was a software layer or an old accelerated layer, remove it. |
153 // Disable the fade-out animation as the layer is removed. | 163 // Disable the fade-out animation as the layer is removed. |
154 { | 164 { |
155 [software_layer_ removeFromSuperlayer]; | 165 [software_layer_ removeFromSuperlayer]; |
156 software_layer_.reset(); | 166 software_layer_.reset(); |
157 [old_accelerated_layer resetClient]; | 167 [old_accelerated_layer resetClient]; |
158 [old_accelerated_layer removeFromSuperlayer]; | 168 [old_accelerated_layer removeFromSuperlayer]; |
159 old_accelerated_layer.reset(); | 169 old_accelerated_layer.reset(); |
160 } | 170 } |
161 } | 171 } |
162 | 172 |
163 - (void)gotSoftwareFrame:(cc::SoftwareFrameData*)frame_data | 173 - (void)gotSoftwareFrame:(cc::SoftwareFrameData*)frame_data |
164 withScaleFactor:(float)scale_factor | 174 withScaleFactor:(float)scale_factor |
165 withCanvas:(SkCanvas*)canvas { | 175 withCanvas:(SkCanvas*)canvas { |
166 if (!frame_data || !canvas) | 176 if (!frame_data || !canvas) |
167 return; | 177 return; |
168 | 178 |
| 179 // If the client that requested frame has disappeared, quit immediately (no |
| 180 // acknowledgement is needed to un-block the software compositor). |
| 181 if (!client_) |
| 182 return; |
| 183 |
169 // If there is not a layer for software frames, create one. | 184 // If there is not a layer for software frames, create one. |
170 if (!software_layer_) { | 185 if (!software_layer_) { |
171 // Disable the fade-in animation as the layer is added. | 186 // Disable the fade-in animation as the layer is added. |
172 ScopedCAActionDisabler disabler; | 187 ScopedCAActionDisabler disabler; |
173 software_layer_.reset([[SoftwareLayer alloc] init]); | 188 software_layer_.reset([[SoftwareLayer alloc] init]); |
174 [[self layer] addSublayer:software_layer_]; | 189 [[self layer] addSublayer:software_layer_]; |
175 } | 190 } |
176 | 191 |
177 SkImageInfo info; | 192 SkImageInfo info; |
178 size_t row_bytes; | 193 size_t row_bytes; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 | 235 |
221 void BrowserCompositorViewCocoaHelper::AcceleratedLayerDidDrawFrame( | 236 void BrowserCompositorViewCocoaHelper::AcceleratedLayerDidDrawFrame( |
222 bool succeeded) { | 237 bool succeeded) { |
223 [view_ layerDidDrawFrame]; | 238 [view_ layerDidDrawFrame]; |
224 if (!succeeded) | 239 if (!succeeded) |
225 [view_ gotAcceleratedLayerError]; | 240 [view_ gotAcceleratedLayerError]; |
226 } | 241 } |
227 | 242 |
228 } | 243 } |
229 | 244 |
OLD | NEW |