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" |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 } | 68 } |
69 | 69 |
70 - (void)gotAcceleratedLayerError { | 70 - (void)gotAcceleratedLayerError { |
71 if (!accelerated_layer_) | 71 if (!accelerated_layer_) |
72 return; | 72 return; |
73 | 73 |
74 [accelerated_layer_ context]->PoisonContextAndSharegroup(); | 74 [accelerated_layer_ context]->PoisonContextAndSharegroup(); |
75 compositor_->ScheduleFullRedraw(); | 75 compositor_->ScheduleFullRedraw(); |
76 } | 76 } |
77 | 77 |
| 78 - (bool)hasFrameWithSizeInDIP:(gfx::Size)desiredSizeInDIP { |
| 79 gfx::Size layerSize; |
| 80 if (accelerated_layer_) |
| 81 layerSize = gfx::Rect([accelerated_layer_ bounds]).size(); |
| 82 if (software_layer_) |
| 83 layerSize = gfx::Rect([software_layer_ bounds]).size(); |
| 84 return layerSize == desiredSizeInDIP; |
| 85 } |
| 86 |
78 - (ui::Compositor*)compositor { | 87 - (ui::Compositor*)compositor { |
79 return compositor_.get(); | 88 return compositor_.get(); |
80 } | 89 } |
81 | 90 |
82 - (void)gotAcceleratedIOSurfaceFrame:(IOSurfaceID)surface_handle | 91 - (void)gotAcceleratedIOSurfaceFrame:(IOSurfaceID)surface_handle |
83 withOutputSurfaceID:(int)surface_id | 92 withOutputSurfaceID:(int)surface_id |
84 withLatencyInfo:(std::vector<ui::LatencyInfo>) latency_info | 93 withLatencyInfo:(std::vector<ui::LatencyInfo>) latency_info |
85 withPixelSize:(gfx::Size)pixel_size | 94 withPixelSize:(gfx::Size)pixel_size |
86 withScaleFactor:(float)scale_factor { | 95 withScaleFactor:(float)scale_factor { |
87 DCHECK(!accelerated_layer_output_surface_id_); | 96 DCHECK(!accelerated_layer_output_surface_id_); |
88 accelerated_layer_output_surface_id_ = surface_id; | 97 accelerated_layer_output_surface_id_ = surface_id; |
89 accelerated_latency_info_.insert(accelerated_latency_info_.end(), | 98 accelerated_latency_info_.insert(accelerated_latency_info_.end(), |
90 latency_info.begin(), latency_info.end()); | 99 latency_info.begin(), latency_info.end()); |
91 | 100 |
| 101 // Disable the fade-in animation as the layer is added, removed, or resized. |
92 ScopedCAActionDisabler disabler; | 102 ScopedCAActionDisabler disabler; |
93 | 103 |
94 // If there is already an accelerated layer, but it has the wrong scale | 104 // If there is already an accelerated layer, but it has the wrong scale |
95 // factor or it was poisoned, remove the old layer and replace it. | 105 // factor or it was poisoned, remove the old layer and replace it. |
96 base::scoped_nsobject<CompositingIOSurfaceLayer> old_accelerated_layer; | 106 base::scoped_nsobject<CompositingIOSurfaceLayer> old_accelerated_layer; |
97 if (accelerated_layer_ && ( | 107 if (accelerated_layer_ && ( |
98 [accelerated_layer_ context]->HasBeenPoisoned() || | 108 [accelerated_layer_ context]->HasBeenPoisoned() || |
99 [accelerated_layer_ iosurface]->scale_factor() != scale_factor)) { | 109 [accelerated_layer_ iosurface]->scale_factor() != scale_factor)) { |
100 old_accelerated_layer = accelerated_layer_; | 110 old_accelerated_layer = accelerated_layer_; |
101 accelerated_layer_.reset(); | 111 accelerated_layer_.reset(); |
102 } | 112 } |
103 | 113 |
104 // If there is not a layer for accelerated frames, create one. | 114 // If there is not a layer for accelerated frames, create one. |
105 if (!accelerated_layer_) { | 115 if (!accelerated_layer_) { |
106 // Disable the fade-in animation as the layer is added. | |
107 ScopedCAActionDisabler disabler; | |
108 scoped_refptr<content::CompositingIOSurfaceMac> iosurface = | 116 scoped_refptr<content::CompositingIOSurfaceMac> iosurface = |
109 content::CompositingIOSurfaceMac::Create(); | 117 content::CompositingIOSurfaceMac::Create(); |
110 accelerated_layer_.reset([[CompositingIOSurfaceLayer alloc] | 118 accelerated_layer_.reset([[CompositingIOSurfaceLayer alloc] |
111 initWithIOSurface:iosurface | 119 initWithIOSurface:iosurface |
112 withScaleFactor:scale_factor | 120 withScaleFactor:scale_factor |
113 withClient:helper_.get()]); | 121 withClient:helper_.get()]); |
114 [[self layer] addSublayer:accelerated_layer_]; | 122 [[self layer] addSublayer:accelerated_layer_]; |
115 } | 123 } |
116 | 124 |
117 { | 125 { |
(...skipping 10 matching lines...) Expand all Loading... |
128 // Set the bounds of the accelerated layer to match the size of the frame. | 136 // Set the bounds of the accelerated layer to match the size of the frame. |
129 // If the bounds changed, force the content to be displayed immediately. | 137 // If the bounds changed, force the content to be displayed immediately. |
130 CGRect new_layer_bounds = CGRectMake( | 138 CGRect new_layer_bounds = CGRectMake( |
131 0, | 139 0, |
132 0, | 140 0, |
133 [accelerated_layer_ iosurface]->dip_io_surface_size().width(), | 141 [accelerated_layer_ iosurface]->dip_io_surface_size().width(), |
134 [accelerated_layer_ iosurface]->dip_io_surface_size().height()); | 142 [accelerated_layer_ iosurface]->dip_io_surface_size().height()); |
135 bool bounds_changed = !CGRectEqualToRect( | 143 bool bounds_changed = !CGRectEqualToRect( |
136 new_layer_bounds, [accelerated_layer_ bounds]); | 144 new_layer_bounds, [accelerated_layer_ bounds]); |
137 [accelerated_layer_ setBounds:new_layer_bounds]; | 145 [accelerated_layer_ setBounds:new_layer_bounds]; |
138 if (bounds_changed) { | 146 if (bounds_changed || |
| 147 (client_ && client_->BrowserCompositorShouldDrawImmediately())) { |
139 [accelerated_layer_ setNeedsDisplay]; | 148 [accelerated_layer_ setNeedsDisplay]; |
140 [accelerated_layer_ displayIfNeeded]; | 149 [accelerated_layer_ displayIfNeeded]; |
141 } | 150 } |
142 | 151 |
143 // If there was a software layer or an old accelerated layer, remove it. | 152 // If there was a software layer or an old accelerated layer, remove it. |
144 // Disable the fade-out animation as the layer is removed. | 153 // Disable the fade-out animation as the layer is removed. |
145 { | 154 { |
146 ScopedCAActionDisabler disabler; | |
147 [software_layer_ removeFromSuperlayer]; | 155 [software_layer_ removeFromSuperlayer]; |
148 software_layer_.reset(); | 156 software_layer_.reset(); |
149 [old_accelerated_layer resetClient]; | 157 [old_accelerated_layer resetClient]; |
150 [old_accelerated_layer removeFromSuperlayer]; | 158 [old_accelerated_layer removeFromSuperlayer]; |
151 old_accelerated_layer.reset(); | 159 old_accelerated_layer.reset(); |
152 } | 160 } |
153 } | 161 } |
154 | 162 |
155 - (void)gotSoftwareFrame:(cc::SoftwareFrameData*)frame_data | 163 - (void)gotSoftwareFrame:(cc::SoftwareFrameData*)frame_data |
156 withScaleFactor:(float)scale_factor | 164 withScaleFactor:(float)scale_factor |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 | 220 |
213 void BrowserCompositorViewCocoaHelper::AcceleratedLayerDidDrawFrame( | 221 void BrowserCompositorViewCocoaHelper::AcceleratedLayerDidDrawFrame( |
214 bool succeeded) { | 222 bool succeeded) { |
215 [view_ layerDidDrawFrame]; | 223 [view_ layerDidDrawFrame]; |
216 if (!succeeded) | 224 if (!succeeded) |
217 [view_ gotAcceleratedLayerError]; | 225 [view_ gotAcceleratedLayerError]; |
218 } | 226 } |
219 | 227 |
220 } | 228 } |
221 | 229 |
OLD | NEW |