Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(896)

Side by Side Diff: content/browser/renderer_host/render_widget_host_view_mac.mm

Issue 231863002: Mac: Recreate browser-side GL contexts on GPU switch (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove prototype Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/renderer_host/render_widget_host_view_mac.h" 5 #include "content/browser/renderer_host/render_widget_host_view_mac.h"
6 6
7 #import <objc/runtime.h> 7 #import <objc/runtime.h>
8 #include <QuartzCore/QuartzCore.h> 8 #include <QuartzCore/QuartzCore.h>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after
373 results.deviceScaleFactor = static_cast<int>(display.device_scale_factor()); 373 results.deviceScaleFactor = static_cast<int>(display.device_scale_factor());
374 results.depth = NSBitsPerPixelFromDepth([screen depth]); 374 results.depth = NSBitsPerPixelFromDepth([screen depth]);
375 results.depthPerComponent = NSBitsPerSampleFromDepth([screen depth]); 375 results.depthPerComponent = NSBitsPerSampleFromDepth([screen depth]);
376 results.isMonochrome = 376 results.isMonochrome =
377 [[screen colorSpace] colorSpaceModel] == NSGrayColorSpaceModel; 377 [[screen colorSpace] colorSpaceModel] == NSGrayColorSpaceModel;
378 results.rect = display.bounds(); 378 results.rect = display.bounds();
379 results.availableRect = display.work_area(); 379 results.availableRect = display.work_area();
380 return results; 380 return results;
381 } 381 }
382 382
383 void RemoveLayerFromSuperlayer(
Zhenyao Mo 2014/04/09 22:24:24 This is never called.
ccameron 2014/04/09 22:37:28 This is wrapped up in the ScopedClosureRunner belo
384 base::scoped_nsobject<CompositingIOSurfaceLayer> layer) {
385 // Disable the fade-out animation as the layer is removed.
386 ScopedCAActionDisabler disabler;
387 [layer removeFromSuperlayer];
388 }
389
383 } // namespace 390 } // namespace
384 391
385 namespace content { 392 namespace content {
386 393
387 /////////////////////////////////////////////////////////////////////////////// 394 ///////////////////////////////////////////////////////////////////////////////
388 // RenderWidgetHostView, public: 395 // RenderWidgetHostView, public:
389 396
390 // static 397 // static
391 RenderWidgetHostView* RenderWidgetHostView::CreateViewForWidget( 398 RenderWidgetHostView* RenderWidgetHostView::CreateViewForWidget(
392 RenderWidgetHost* widget) { 399 RenderWidgetHost* widget) {
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
566 573
567 compositing_iosurface_layer_.reset([[CompositingIOSurfaceLayer alloc] 574 compositing_iosurface_layer_.reset([[CompositingIOSurfaceLayer alloc]
568 initWithRenderWidgetHostViewMac:this]); 575 initWithRenderWidgetHostViewMac:this]);
569 DCHECK(compositing_iosurface_layer_); 576 DCHECK(compositing_iosurface_layer_);
570 577
571 // Disable the fade-in animation as the layer is added. 578 // Disable the fade-in animation as the layer is added.
572 ScopedCAActionDisabler disabler; 579 ScopedCAActionDisabler disabler;
573 [background_layer_ addSublayer:compositing_iosurface_layer_]; 580 [background_layer_ addSublayer:compositing_iosurface_layer_];
574 } 581 }
575 582
576 void RenderWidgetHostViewMac::DestroyCompositedIOSurfaceLayer() { 583 void RenderWidgetHostViewMac::DestroyCompositedIOSurfaceLayer(
584 DestroyCompositedIOSurfaceLayerBehavior destroy_layer_behavior) {
577 if (!compositing_iosurface_layer_) 585 if (!compositing_iosurface_layer_)
578 return; 586 return;
579 587
580 // Disable the fade-out animation as the layer is removed. 588 if (destroy_layer_behavior == kRemoveLayerFromHierarchy) {
581 ScopedCAActionDisabler disabler; 589 // Disable the fade-out animation as the layer is removed.
582 [compositing_iosurface_layer_ removeFromSuperlayer]; 590 ScopedCAActionDisabler disabler;
591 [compositing_iosurface_layer_ removeFromSuperlayer];
592 }
583 [compositing_iosurface_layer_ disableCompositing]; 593 [compositing_iosurface_layer_ disableCompositing];
584 compositing_iosurface_layer_.reset(); 594 compositing_iosurface_layer_.reset();
585 } 595 }
586 596
587 void RenderWidgetHostViewMac::DestroyCompositedIOSurfaceAndLayer( 597 void RenderWidgetHostViewMac::DestroyCompositedIOSurfaceAndLayer(
588 DestroyContextBehavior destroy_context_behavior) { 598 DestroyContextBehavior destroy_context_behavior) {
589 // Any pending frames will not be displayed, so ack them now. 599 // Any pending frames will not be displayed, so ack them now.
590 SendPendingSwapAck(); 600 SendPendingSwapAck();
591 601
592 DestroyCompositedIOSurfaceLayer(); 602 DestroyCompositedIOSurfaceLayer(kRemoveLayerFromHierarchy);
593 compositing_iosurface_.reset(); 603 compositing_iosurface_.reset();
594 604
595 switch (destroy_context_behavior) { 605 switch (destroy_context_behavior) {
596 case kLeaveContextBoundToView: 606 case kLeaveContextBoundToView:
597 break; 607 break;
598 case kDestroyContext: 608 case kDestroyContext:
599 ClearBoundContextDrawable(); 609 ClearBoundContextDrawable();
600 compositing_iosurface_context_ = NULL; 610 compositing_iosurface_context_ = NULL;
601 break; 611 break;
602 default: 612 default:
(...skipping 744 matching lines...) Expand 10 before | Expand all | Expand 10 after
1347 return; 1357 return;
1348 1358
1349 // Ensure that if this function exits before the frame is set up (but not 1359 // Ensure that if this function exits before the frame is set up (but not
1350 // necessarily drawn) then it is treated as an error. 1360 // necessarily drawn) then it is treated as an error.
1351 base::ScopedClosureRunner scoped_error( 1361 base::ScopedClosureRunner scoped_error(
1352 base::Bind(&RenderWidgetHostViewMac::GotAcceleratedCompositingError, 1362 base::Bind(&RenderWidgetHostViewMac::GotAcceleratedCompositingError,
1353 weak_factory_.GetWeakPtr())); 1363 weak_factory_.GetWeakPtr()));
1354 1364
1355 AddPendingLatencyInfo(latency_info); 1365 AddPendingLatencyInfo(latency_info);
1356 1366
1367 // If compositing_iosurface_ exists and has been poisoned, destroy it
1368 // and allow EnsureCompositedIOSurface to recreate it below. Keep a
1369 // reference to the destroyed layer around until after the below call
1370 // to LayoutLayers, to avoid flickers.
1371 base::ScopedClosureRunner scoped_layer_remover;
1372 if (compositing_iosurface_context_ &&
1373 compositing_iosurface_context_->HasBeenPoisoned()) {
1374 scoped_layer_remover.Reset(
1375 base::Bind(RemoveLayerFromSuperlayer, compositing_iosurface_layer_));
1376 DestroyCompositedIOSurfaceLayer(kLeaveLayerInHierarchy);
1377 DestroyCompositedIOSurfaceAndLayer(kDestroyContext);
1378 }
1379
1357 // Ensure compositing_iosurface_ and compositing_iosurface_context_ be 1380 // Ensure compositing_iosurface_ and compositing_iosurface_context_ be
1358 // allocated. 1381 // allocated.
1359 if (!EnsureCompositedIOSurface()) { 1382 if (!EnsureCompositedIOSurface()) {
1360 LOG(ERROR) << "Failed EnsureCompositingIOSurface"; 1383 LOG(ERROR) << "Failed EnsureCompositingIOSurface";
1361 return; 1384 return;
1362 } 1385 }
1363 1386
1364 // Make the context current and update the IOSurface with the handle 1387 // Make the context current and update the IOSurface with the handle
1365 // passed in by the swap command. 1388 // passed in by the swap command.
1366 { 1389 {
(...skipping 653 matching lines...) Expand 10 before | Expand all | Expand 10 after
2020 } 2043 }
2021 } 2044 }
2022 2045
2023 void RenderWidgetHostViewMac::WindowFrameChanged() { 2046 void RenderWidgetHostViewMac::WindowFrameChanged() {
2024 if (render_widget_host_) { 2047 if (render_widget_host_) {
2025 render_widget_host_->Send(new ViewMsg_WindowFrameChanged( 2048 render_widget_host_->Send(new ViewMsg_WindowFrameChanged(
2026 render_widget_host_->GetRoutingID(), GetBoundsInRootWindow(), 2049 render_widget_host_->GetRoutingID(), GetBoundsInRootWindow(),
2027 GetViewBounds())); 2050 GetViewBounds()));
2028 } 2051 }
2029 2052
2030 if (compositing_iosurface_) { 2053 if (compositing_iosurface_ && !use_core_animation_) {
ccameron 2014/04/09 22:06:01 There is no migration in non-CoreAnimation mode, s
2031 // This will migrate the context to the appropriate window. 2054 // This will migrate the context to the appropriate window.
2032 if (!EnsureCompositedIOSurface()) 2055 if (!EnsureCompositedIOSurface())
2033 GotAcceleratedCompositingError(); 2056 GotAcceleratedCompositingError();
2034 } 2057 }
2035 } 2058 }
2036 2059
2037 void RenderWidgetHostViewMac::ShowDefinitionForSelection() { 2060 void RenderWidgetHostViewMac::ShowDefinitionForSelection() {
2038 RenderWidgetHostViewMacDictionaryHelper helper(this); 2061 RenderWidgetHostViewMacDictionaryHelper helper(this);
2039 helper.ShowDefinitionForSelection(); 2062 helper.ShowDefinitionForSelection();
2040 } 2063 }
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
2222 2245
2223 // Dynamically calling setContentsScale on a CAOpenGLLayer for which 2246 // Dynamically calling setContentsScale on a CAOpenGLLayer for which
2224 // setAsynchronous is dynamically toggled can result in flashes of corrupt 2247 // setAsynchronous is dynamically toggled can result in flashes of corrupt
2225 // content. Work around this by replacing the entire layer when the scale 2248 // content. Work around this by replacing the entire layer when the scale
2226 // factor changes. 2249 // factor changes.
2227 if (compositing_iosurface_ && 2250 if (compositing_iosurface_ &&
2228 [compositing_iosurface_layer_ 2251 [compositing_iosurface_layer_
2229 respondsToSelector:(@selector(contentsScale))]) { 2252 respondsToSelector:(@selector(contentsScale))]) {
2230 if (compositing_iosurface_->scale_factor() != 2253 if (compositing_iosurface_->scale_factor() !=
2231 [compositing_iosurface_layer_ contentsScale]) { 2254 [compositing_iosurface_layer_ contentsScale]) {
2232 DestroyCompositedIOSurfaceLayer(); 2255 DestroyCompositedIOSurfaceLayer(kRemoveLayerFromHierarchy);
2233 EnsureCompositedIOSurfaceLayer(); 2256 EnsureCompositedIOSurfaceLayer();
2234 } 2257 }
2235 } 2258 }
2236 if (compositing_iosurface_ && compositing_iosurface_layer_) { 2259 if (compositing_iosurface_ && compositing_iosurface_layer_) {
2237 CGRect layer_bounds = CGRectMake( 2260 CGRect layer_bounds = CGRectMake(
2238 0, 2261 0,
2239 0, 2262 0,
2240 compositing_iosurface_->dip_io_surface_size().width(), 2263 compositing_iosurface_->dip_io_surface_size().width(),
2241 compositing_iosurface_->dip_io_surface_size().height()); 2264 compositing_iosurface_->dip_io_surface_size().height());
2242 CGPoint layer_position = CGPointMake( 2265 CGPoint layer_position = CGPointMake(
(...skipping 2044 matching lines...) Expand 10 before | Expand all | Expand 10 after
4287 } 4310 }
4288 4311
4289 - (void)disableRendering { 4312 - (void)disableRendering {
4290 // Disable the fade-out animation as the layer is removed. 4313 // Disable the fade-out animation as the layer is removed.
4291 ScopedCAActionDisabler disabler; 4314 ScopedCAActionDisabler disabler;
4292 [self removeFromSuperlayer]; 4315 [self removeFromSuperlayer];
4293 renderWidgetHostView_ = nil; 4316 renderWidgetHostView_ = nil;
4294 } 4317 }
4295 4318
4296 @end // implementation SoftwareLayer 4319 @end // implementation SoftwareLayer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698