| 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_mac.h" | 5 #include "content/browser/compositor/browser_compositor_view_mac.h" |
| 6 | 6 |
| 7 #include "base/debug/trace_event.h" | 7 #include "base/debug/trace_event.h" |
| 8 #include "base/mac/scoped_cftyperef.h" | 8 #include "base/mac/scoped_cftyperef.h" |
| 9 #include "content/browser/compositor/gpu_process_transport_factory.h" |
| 9 #include "content/browser/renderer_host/compositing_iosurface_context_mac.h" | 10 #include "content/browser/renderer_host/compositing_iosurface_context_mac.h" |
| 10 #include "content/browser/renderer_host/compositing_iosurface_mac.h" | 11 #include "content/browser/renderer_host/compositing_iosurface_mac.h" |
| 11 #include "content/browser/renderer_host/software_layer_mac.h" | 12 #include "content/browser/renderer_host/software_layer_mac.h" |
| 12 #include "content/public/browser/context_factory.h" | 13 #include "content/public/browser/context_factory.h" |
| 13 #include "ui/base/cocoa/animation_utils.h" | 14 #include "ui/base/cocoa/animation_utils.h" |
| 14 #include "ui/gl/scoped_cgl.h" | 15 #include "ui/gl/scoped_cgl.h" |
| 15 | 16 |
| 16 @interface BrowserCompositorViewMac (Private) | 17 @interface BrowserCompositorViewMac (Private) |
| 17 - (void)layerDidDrawFrame; | 18 - (void)layerDidDrawFrame; |
| 18 - (void)gotAcceleratedLayerError; | 19 - (void)gotAcceleratedLayerError; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 41 }; | 42 }; |
| 42 | 43 |
| 43 } // namespace content | 44 } // namespace content |
| 44 | 45 |
| 45 | 46 |
| 46 // The default implementation of additions to the NSView interface for browser | 47 // The default implementation of additions to the NSView interface for browser |
| 47 // compositing should never be called. Log an error if they are. | 48 // compositing should never be called. Log an error if they are. |
| 48 @implementation NSView (BrowserCompositorView) | 49 @implementation NSView (BrowserCompositorView) |
| 49 | 50 |
| 50 - (void)gotAcceleratedIOSurfaceFrame:(uint64)surface_handle | 51 - (void)gotAcceleratedIOSurfaceFrame:(uint64)surface_handle |
| 52 withOutputSurfaceID:(int)surface_id |
| 51 withPixelSize:(gfx::Size)pixel_size | 53 withPixelSize:(gfx::Size)pixel_size |
| 52 withScaleFactor:(float)scale_factor { | 54 withScaleFactor:(float)scale_factor { |
| 53 DLOG(ERROR) << "-[NSView gotAcceleratedIOSurfaceFrame] called on " | 55 DLOG(ERROR) << "-[NSView gotAcceleratedIOSurfaceFrame] called on " |
| 54 << "non-overriden class."; | 56 << "non-overriden class."; |
| 55 } | 57 } |
| 56 | 58 |
| 57 - (void)gotSoftwareFrame:(cc::SoftwareFrameData*)frame_data | 59 - (void)gotSoftwareFrame:(cc::SoftwareFrameData*)frame_data |
| 58 withScaleFactor:(float)scale_factor | 60 withScaleFactor:(float)scale_factor |
| 59 withCanvas:(SkCanvas*)canvas { | 61 withCanvas:(SkCanvas*)canvas { |
| 60 DLOG(ERROR) << "-[NSView gotSoftwareFrame] called on non-overridden class."; | 62 DLOG(ERROR) << "-[NSView gotSoftwareFrame] called on non-overridden class."; |
| 61 } | 63 } |
| 62 | 64 |
| 63 @end // NSView (BrowserCompositorView) | 65 @end // NSView (BrowserCompositorView) |
| 64 | 66 |
| 65 @implementation BrowserCompositorViewMac : NSView | 67 @implementation BrowserCompositorViewMac : NSView |
| 66 | 68 |
| 67 - (id)initWithSuperview:(NSView*)view { | 69 - (id)initWithSuperview:(NSView*)view { |
| 68 if (self = [super init]) { | 70 if (self = [super init]) { |
| 71 accelerated_layer_output_surface_id_ = 0; |
| 69 helper_.reset(new content::BrowserCompositorViewMacHelper(self)); | 72 helper_.reset(new content::BrowserCompositorViewMacHelper(self)); |
| 70 | 73 |
| 71 // Disable the fade-in animation as the layer and view are added. | 74 // Disable the fade-in animation as the layer and view are added. |
| 72 ScopedCAActionDisabler disabler; | 75 ScopedCAActionDisabler disabler; |
| 73 | 76 |
| 74 // Make this view host a transparent layer. | 77 // Make this view host a transparent layer. |
| 75 background_layer_.reset([[CALayer alloc] init]); | 78 background_layer_.reset([[CALayer alloc] init]); |
| 76 [background_layer_ setContentsGravity:kCAGravityTopLeft]; | 79 [background_layer_ setContentsGravity:kCAGravityTopLeft]; |
| 77 [self setLayer:background_layer_]; | 80 [self setLayer:background_layer_]; |
| 78 [self setWantsLayer:YES]; | 81 [self setWantsLayer:YES]; |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 | 142 |
| 140 - (void)resetClient { | 143 - (void)resetClient { |
| 141 [accelerated_layer_ resetClient]; | 144 [accelerated_layer_ resetClient]; |
| 142 } | 145 } |
| 143 | 146 |
| 144 - (ui::Compositor*)compositor { | 147 - (ui::Compositor*)compositor { |
| 145 return compositor_.get(); | 148 return compositor_.get(); |
| 146 } | 149 } |
| 147 | 150 |
| 148 - (void)gotAcceleratedIOSurfaceFrame:(uint64)surface_handle | 151 - (void)gotAcceleratedIOSurfaceFrame:(uint64)surface_handle |
| 152 withOutputSurfaceID:(int)surface_id |
| 149 withPixelSize:(gfx::Size)pixel_size | 153 withPixelSize:(gfx::Size)pixel_size |
| 150 withScaleFactor:(float)scale_factor { | 154 withScaleFactor:(float)scale_factor { |
| 155 DCHECK(!accelerated_layer_output_surface_id_); |
| 156 accelerated_layer_output_surface_id_ = surface_id; |
| 157 |
| 151 ScopedCAActionDisabler disabler; | 158 ScopedCAActionDisabler disabler; |
| 152 | 159 |
| 153 // If there is already an accelerated layer, but it has the wrong scale | 160 // If there is already an accelerated layer, but it has the wrong scale |
| 154 // factor or it was poisoned, remove the old layer and replace it. | 161 // factor or it was poisoned, remove the old layer and replace it. |
| 155 base::scoped_nsobject<CompositingIOSurfaceLayer> old_accelerated_layer; | 162 base::scoped_nsobject<CompositingIOSurfaceLayer> old_accelerated_layer; |
| 156 if (accelerated_layer_ && ( | 163 if (accelerated_layer_ && ( |
| 157 [accelerated_layer_ context]->HasBeenPoisoned() || | 164 [accelerated_layer_ context]->HasBeenPoisoned() || |
| 158 [accelerated_layer_ iosurface]->scale_factor() != scale_factor)) { | 165 [accelerated_layer_ iosurface]->scale_factor() != scale_factor)) { |
| 159 old_accelerated_layer = accelerated_layer_; | 166 old_accelerated_layer = accelerated_layer_; |
| 160 accelerated_layer_.reset(); | 167 accelerated_layer_.reset(); |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 | 238 |
| 232 // This call can be nested insider ui::Compositor commit calls, and can also | 239 // This call can be nested insider ui::Compositor commit calls, and can also |
| 233 // make additional ui::Compositor commit calls. Avoid the potential recursion | 240 // make additional ui::Compositor commit calls. Avoid the potential recursion |
| 234 // by acknowledging the frame asynchronously. | 241 // by acknowledging the frame asynchronously. |
| 235 [self performSelector:@selector(layerDidDrawFrame) | 242 [self performSelector:@selector(layerDidDrawFrame) |
| 236 withObject:nil | 243 withObject:nil |
| 237 afterDelay:0]; | 244 afterDelay:0]; |
| 238 } | 245 } |
| 239 | 246 |
| 240 - (void)layerDidDrawFrame { | 247 - (void)layerDidDrawFrame { |
| 248 if (!accelerated_layer_output_surface_id_) |
| 249 return; |
| 250 |
| 251 content::ImageTransportFactory::GetInstance()->OnSurfaceDisplayed( |
| 252 accelerated_layer_output_surface_id_); |
| 253 accelerated_layer_output_surface_id_ = 0; |
| 241 } | 254 } |
| 242 | 255 |
| 243 @end // BrowserCompositorViewMac | 256 @end // BrowserCompositorViewMac |
| OLD | NEW |