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