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

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

Issue 165623002: Dynamically set CAOpenGLLAyer to be asynchronous (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Incorporate review feedback Created 6 years, 10 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/compositing_iosurface_layer_mac.h" 5 #include "content/browser/renderer_host/compositing_iosurface_layer_mac.h"
6 6
7 #include <CoreFoundation/CoreFoundation.h> 7 #include <CoreFoundation/CoreFoundation.h>
8 #include <OpenGL/gl.h> 8 #include <OpenGL/gl.h>
9 9
10 #include "base/mac/sdk_forward_declarations.h" 10 #include "base/mac/sdk_forward_declarations.h"
11 #include "content/browser/renderer_host/render_widget_host_impl.h" 11 #include "content/browser/renderer_host/render_widget_host_impl.h"
12 #include "content/browser/renderer_host/render_widget_host_view_mac.h" 12 #include "content/browser/renderer_host/render_widget_host_view_mac.h"
13 #include "content/browser/renderer_host/compositing_iosurface_context_mac.h" 13 #include "content/browser/renderer_host/compositing_iosurface_context_mac.h"
14 #include "content/browser/renderer_host/compositing_iosurface_mac.h" 14 #include "content/browser/renderer_host/compositing_iosurface_mac.h"
15 #include "ui/base/cocoa/animation_utils.h" 15 #include "ui/base/cocoa/animation_utils.h"
16 #include "ui/gfx/size_conversions.h" 16 #include "ui/gfx/size_conversions.h"
17 #include "ui/gl/gpu_switching_manager.h" 17 #include "ui/gl/gpu_switching_manager.h"
18 18
19 @implementation CompositingIOSurfaceLayer 19 @implementation CompositingIOSurfaceLayer
20 20
21 @synthesize context = context_; 21 @synthesize context = context_;
22 22
23 - (id)initWithRenderWidgetHostViewMac:(content::RenderWidgetHostViewMac*)r { 23 - (id)initWithRenderWidgetHostViewMac:(content::RenderWidgetHostViewMac*)r {
24 if (self = [super init]) { 24 if (self = [super init]) {
25 renderWidgetHostView_ = r; 25 renderWidgetHostView_ = r;
26 context_ = content::CompositingIOSurfaceContext::Get( 26 context_ = content::CompositingIOSurfaceContext::Get(
27 content::CompositingIOSurfaceContext::kOffscreenContextWindowNumber); 27 content::CompositingIOSurfaceContext::kOffscreenContextWindowNumber);
28 DCHECK(context_); 28 DCHECK(context_);
29 needsDisplay_ = NO;
29 30
30 ScopedCAActionDisabler disabler; 31 ScopedCAActionDisabler disabler;
31 [self setBackgroundColor:CGColorGetConstantColor(kCGColorWhite)]; 32 [self setBackgroundColor:CGColorGetConstantColor(kCGColorWhite)];
32 [self setContentsGravity:kCAGravityTopLeft]; 33 [self setContentsGravity:kCAGravityTopLeft];
33 [self setFrame:NSRectToCGRect( 34 [self setFrame:NSRectToCGRect(
34 [renderWidgetHostView_->cocoa_view() bounds])]; 35 [renderWidgetHostView_->cocoa_view() bounds])];
35 [self setNeedsDisplay]; 36 [self setNeedsDisplay];
36 [self updateScaleFactor]; 37 [self updateScaleFactor];
37 } 38 }
38 return self; 39 return self;
(...skipping 18 matching lines...) Expand all
57 ScopedCAActionDisabler disabler; 58 ScopedCAActionDisabler disabler;
58 [self setContentsScale:new_scale_factor]; 59 [self setContentsScale:new_scale_factor];
59 } 60 }
60 61
61 - (void)disableCompositing{ 62 - (void)disableCompositing{
62 ScopedCAActionDisabler disabler; 63 ScopedCAActionDisabler disabler;
63 [self removeFromSuperlayer]; 64 [self removeFromSuperlayer];
64 renderWidgetHostView_ = nil; 65 renderWidgetHostView_ = nil;
65 } 66 }
66 67
68 - (void)gotNewFrame {
69 if (![self isAsynchronous]) {
70 [self setNeedsDisplay];
71 [self setAsynchronous:YES];
72 } else {
73 needsDisplay_ = YES;
74 }
75 }
76
77 - (void)timerSinceGotNewFrameFired {
78 if (![self isAsynchronous])
79 return;
80
81 [self setAsynchronous:NO];
82 if (needsDisplay_)
83 [self setNeedsDisplay];
84 }
85
67 // The remaining methods implement the CAOpenGLLayer interface. 86 // The remaining methods implement the CAOpenGLLayer interface.
68 87
69 - (CGLPixelFormatObj)copyCGLPixelFormatForDisplayMask:(uint32_t)mask { 88 - (CGLPixelFormatObj)copyCGLPixelFormatForDisplayMask:(uint32_t)mask {
70 if (!context_) 89 if (!context_)
71 return [super copyCGLPixelFormatForDisplayMask:mask]; 90 return [super copyCGLPixelFormatForDisplayMask:mask];
72 return CGLRetainPixelFormat(CGLGetPixelFormat(context_->cgl_context())); 91 return CGLRetainPixelFormat(CGLGetPixelFormat(context_->cgl_context()));
73 } 92 }
74 93
75 - (CGLContextObj)copyCGLContextForPixelFormat:(CGLPixelFormatObj)pixelFormat { 94 - (CGLContextObj)copyCGLContextForPixelFormat:(CGLPixelFormatObj)pixelFormat {
76 if (!context_) 95 if (!context_)
77 return [super copyCGLContextForPixelFormat:pixelFormat]; 96 return [super copyCGLContextForPixelFormat:pixelFormat];
78 return CGLRetainContext(context_->cgl_context()); 97 return CGLRetainContext(context_->cgl_context());
79 } 98 }
80 99
100 - (void)setNeedsDisplay {
101 needsDisplay_ = YES;
102 [super setNeedsDisplay];
103 }
104
105 - (BOOL)canDrawInCGLContext:(CGLContextObj)glContext
106 pixelFormat:(CGLPixelFormatObj)pixelFormat
107 forLayerTime:(CFTimeInterval)timeInterval
108 displayTime:(const CVTimeStamp*)timeStamp {
109 return needsDisplay_;
110 }
111
81 - (void)drawInCGLContext:(CGLContextObj)glContext 112 - (void)drawInCGLContext:(CGLContextObj)glContext
82 pixelFormat:(CGLPixelFormatObj)pixelFormat 113 pixelFormat:(CGLPixelFormatObj)pixelFormat
83 forLayerTime:(CFTimeInterval)timeInterval 114 forLayerTime:(CFTimeInterval)timeInterval
84 displayTime:(const CVTimeStamp*)timeStamp { 115 displayTime:(const CVTimeStamp*)timeStamp {
85 TRACE_EVENT0("browser", "CompositingIOSurfaceLayer::drawInCGLContext"); 116 TRACE_EVENT0("browser", "CompositingIOSurfaceLayer::drawInCGLContext");
86 117
87 if (!context_ || 118 if (!context_ ||
88 (context_ && context_->cgl_context() != glContext) || 119 (context_ && context_->cgl_context() != glContext) ||
89 !renderWidgetHostView_ || 120 !renderWidgetHostView_ ||
90 !renderWidgetHostView_->compositing_iosurface_) { 121 !renderWidgetHostView_->compositing_iosurface_) {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 167
137 if (!renderWidgetHostView_->compositing_iosurface_->DrawIOSurface( 168 if (!renderWidgetHostView_->compositing_iosurface_->DrawIOSurface(
138 context_, 169 context_,
139 window_rect, 170 window_rect,
140 window_scale_factor, 171 window_scale_factor,
141 false)) { 172 false)) {
142 renderWidgetHostView_->GotAcceleratedCompositingError(); 173 renderWidgetHostView_->GotAcceleratedCompositingError();
143 return; 174 return;
144 } 175 }
145 176
177 needsDisplay_ = NO;
146 renderWidgetHostView_->SendPendingLatencyInfoToHost(); 178 renderWidgetHostView_->SendPendingLatencyInfoToHost();
147 } 179 }
148 180
149 @end 181 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698