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_ca_layer_tree_mac.h" | 5 #include "ui/accelerated_widget_mac/accelerated_widget_mac.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 | 8 |
9 #include "cc/output/software_frame_data.h" | |
10 #include "base/debug/trace_event.h" | 9 #include "base/debug/trace_event.h" |
11 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
12 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
13 #include "content/browser/compositor/io_surface_layer_mac.h" | 12 #include "third_party/skia/include/core/SkCanvas.h" |
14 #include "content/browser/compositor/software_layer_mac.h" | 13 #include "ui/accelerated_widget_mac/io_surface_layer.h" |
15 #include "content/common/gpu/surface_handle_types_mac.h" | 14 #include "ui/accelerated_widget_mac/surface_handle_types.h" |
16 #include "content/public/browser/context_factory.h" | |
17 #include "ui/base/cocoa/animation_utils.h" | 15 #include "ui/base/cocoa/animation_utils.h" |
18 #include "ui/gfx/geometry/dip_util.h" | 16 #include "ui/gfx/geometry/dip_util.h" |
19 #include "ui/gl/scoped_cgl.h" | 17 #include "ui/gl/scoped_cgl.h" |
20 | 18 |
21 namespace content { | 19 namespace ui { |
22 namespace { | 20 namespace { |
23 | 21 |
24 typedef std::map<gfx::AcceleratedWidget,AcceleratedWidgetMac*> | 22 typedef std::map<gfx::AcceleratedWidget,AcceleratedWidgetMac*> |
25 WidgetToHelperMap; | 23 WidgetToHelperMap; |
26 base::LazyInstance<WidgetToHelperMap> g_widget_to_helper_map; | 24 base::LazyInstance<WidgetToHelperMap> g_widget_to_helper_map; |
27 | 25 |
28 AcceleratedWidgetMac* GetHelperFromAcceleratedWidget( | 26 AcceleratedWidgetMac* GetHelperFromAcceleratedWidget( |
29 gfx::AcceleratedWidget widget) { | 27 gfx::AcceleratedWidget widget) { |
30 WidgetToHelperMap::const_iterator found = | 28 WidgetToHelperMap::const_iterator found = |
31 g_widget_to_helper_map.Pointer()->find(widget); | 29 g_widget_to_helper_map.Pointer()->find(widget); |
32 // This can end up being accessed after the underlying widget has been | 30 // This can end up being accessed after the underlying widget has been |
33 // destroyed, but while the ui::Compositor is still being destroyed. | 31 // destroyed, but while the ui::Compositor is still being destroyed. |
34 // Return NULL in these cases. | 32 // Return NULL in these cases. |
35 if (found == g_widget_to_helper_map.Pointer()->end()) | 33 if (found == g_widget_to_helper_map.Pointer()->end()) |
36 return NULL; | 34 return NULL; |
37 return found->second; | 35 return found->second; |
38 } | 36 } |
39 | 37 |
40 } | 38 } // namespace |
41 | 39 |
42 //////////////////////////////////////////////////////////////////////////////// | 40 //////////////////////////////////////////////////////////////////////////////// |
43 // AcceleratedWidgetMac | 41 // AcceleratedWidgetMac |
44 | 42 |
45 AcceleratedWidgetMac::AcceleratedWidgetMac() | 43 AcceleratedWidgetMac::AcceleratedWidgetMac(bool needs_gl_finish_workaround) |
46 : view_(NULL) { | 44 : view_(NULL), |
| 45 needs_gl_finish_workaround_(needs_gl_finish_workaround) { |
47 // Disable the fade-in animation as the layers are added. | 46 // Disable the fade-in animation as the layers are added. |
48 ScopedCAActionDisabler disabler; | 47 ScopedCAActionDisabler disabler; |
49 | 48 |
50 // Add a flipped transparent layer as a child, so that we don't need to | 49 // Add a flipped transparent layer as a child, so that we don't need to |
51 // fiddle with the position of sub-layers -- they will always be at the | 50 // fiddle with the position of sub-layers -- they will always be at the |
52 // origin. | 51 // origin. |
53 flipped_layer_.reset([[CALayer alloc] init]); | 52 flipped_layer_.reset([[CALayer alloc] init]); |
54 [flipped_layer_ setGeometryFlipped:YES]; | 53 [flipped_layer_ setGeometryFlipped:YES]; |
55 [flipped_layer_ setAnchorPoint:CGPointMake(0, 0)]; | 54 [flipped_layer_ setAnchorPoint:CGPointMake(0, 0)]; |
56 [flipped_layer_ | 55 [flipped_layer_ |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 // Create or re-create an IOSurface layer if needed. If there already exists | 207 // Create or re-create an IOSurface layer if needed. If there already exists |
209 // a layer but it has the wrong scale factor or it was poisoned, re-create the | 208 // a layer but it has the wrong scale factor or it was poisoned, re-create the |
210 // layer. | 209 // layer. |
211 bool needs_new_layer = | 210 bool needs_new_layer = |
212 !io_surface_layer_ || | 211 !io_surface_layer_ || |
213 [io_surface_layer_ hasBeenPoisoned] || | 212 [io_surface_layer_ hasBeenPoisoned] || |
214 [io_surface_layer_ scaleFactor] != scale_factor; | 213 [io_surface_layer_ scaleFactor] != scale_factor; |
215 if (needs_new_layer) { | 214 if (needs_new_layer) { |
216 io_surface_layer_.reset( | 215 io_surface_layer_.reset( |
217 [[IOSurfaceLayer alloc] initWithClient:this | 216 [[IOSurfaceLayer alloc] initWithClient:this |
218 withScaleFactor:scale_factor]); | 217 withScaleFactor:scale_factor |
| 218 needsGLFinishWorkaround:needs_gl_finish_workaround_]); |
219 if (io_surface_layer_) | 219 if (io_surface_layer_) |
220 [flipped_layer_ addSublayer:io_surface_layer_]; | 220 [flipped_layer_ addSublayer:io_surface_layer_]; |
221 else | 221 else |
222 LOG(ERROR) << "Failed to create IOSurfaceLayer"; | 222 LOG(ERROR) << "Failed to create IOSurfaceLayer"; |
223 } | 223 } |
224 | 224 |
225 // Open the provided IOSurface. | 225 // Open the provided IOSurface. |
226 if (io_surface_layer_) { | 226 if (io_surface_layer_) { |
227 bool result = [io_surface_layer_ gotFrameWithIOSurface:io_surface_id | 227 bool result = [io_surface_layer_ gotFrameWithIOSurface:io_surface_id |
228 withPixelSize:pixel_size | 228 withPixelSize:pixel_size |
(...skipping 30 matching lines...) Expand all Loading... |
259 // If this replacing a same-type layer, remove it now that the new layer is | 259 // If this replacing a same-type layer, remove it now that the new layer is |
260 // in the hierarchy. | 260 // in the hierarchy. |
261 if (old_io_surface_layer != io_surface_layer_) | 261 if (old_io_surface_layer != io_surface_layer_) |
262 DestroyIOSurfaceLayer(old_io_surface_layer); | 262 DestroyIOSurfaceLayer(old_io_surface_layer); |
263 | 263 |
264 // Remove any different-type layers that this is replacing. | 264 // Remove any different-type layers that this is replacing. |
265 DestroyCAContextLayer(ca_context_layer_); | 265 DestroyCAContextLayer(ca_context_layer_); |
266 DestroySoftwareLayer(); | 266 DestroySoftwareLayer(); |
267 } | 267 } |
268 | 268 |
269 void AcceleratedWidgetMac::GotSoftwareFrame( | 269 void AcceleratedWidgetMac::GotSoftwareFrame(float scale_factor, |
270 cc::SoftwareFrameData* frame_data, | 270 SkCanvas* canvas) { |
271 float scale_factor, | 271 if (!canvas || !view_) |
272 SkCanvas* canvas) { | |
273 if (!frame_data || !canvas || !view_) | |
274 return; | 272 return; |
275 | 273 |
276 // Disable the fade-in or fade-out effect if we create or remove layers. | 274 // Disable the fade-in or fade-out effect if we create or remove layers. |
277 ScopedCAActionDisabler disabler; | 275 ScopedCAActionDisabler disabler; |
278 | 276 |
279 // If there is not a layer for software frames, create one. | 277 // If there is not a layer for software frames, create one. |
280 if (!software_layer_) { | 278 if (!software_layer_) { |
281 software_layer_.reset([[SoftwareLayer alloc] init]); | 279 software_layer_.reset([[SoftwareLayer alloc] init]); |
282 [flipped_layer_ addSublayer:software_layer_]; | 280 [flipped_layer_ addSublayer:software_layer_]; |
283 } | 281 } |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
372 *disable_throttling = | 370 *disable_throttling = |
373 accelerated_widget_mac->IsRendererThrottlingDisabled(); | 371 accelerated_widget_mac->IsRendererThrottlingDisabled(); |
374 *renderer_id = accelerated_widget_mac->GetRendererID(); | 372 *renderer_id = accelerated_widget_mac->GetRendererID(); |
375 } else { | 373 } else { |
376 *disable_throttling = false; | 374 *disable_throttling = false; |
377 *renderer_id = 0; | 375 *renderer_id = 0; |
378 } | 376 } |
379 } | 377 } |
380 | 378 |
381 void AcceleratedWidgetMacGotSoftwareFrame( | 379 void AcceleratedWidgetMacGotSoftwareFrame( |
382 gfx::AcceleratedWidget widget, | 380 gfx::AcceleratedWidget widget, float scale_factor, SkCanvas* canvas) { |
383 cc::SoftwareFrameData* frame_data, float scale_factor, SkCanvas* canvas) { | |
384 AcceleratedWidgetMac* accelerated_widget_mac = | 381 AcceleratedWidgetMac* accelerated_widget_mac = |
385 GetHelperFromAcceleratedWidget(widget); | 382 GetHelperFromAcceleratedWidget(widget); |
386 if (accelerated_widget_mac) | 383 if (accelerated_widget_mac) |
387 accelerated_widget_mac->GotSoftwareFrame(frame_data, scale_factor, canvas); | 384 accelerated_widget_mac->GotSoftwareFrame(scale_factor, canvas); |
388 } | 385 } |
389 | 386 |
390 } // namespace content | 387 } // namespace ui |
OLD | NEW |