OLD | NEW |
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" |
(...skipping 17 matching lines...) Expand all Loading... |
28 [self setContentsGravity:kCAGravityTopLeft]; | 28 [self setContentsGravity:kCAGravityTopLeft]; |
29 [self setFrame:NSRectToCGRect( | 29 [self setFrame:NSRectToCGRect( |
30 [renderWidgetHostView_->cocoa_view() bounds])]; | 30 [renderWidgetHostView_->cocoa_view() bounds])]; |
31 [self setNeedsDisplay]; | 31 [self setNeedsDisplay]; |
32 [self updateScaleFactor]; | 32 [self updateScaleFactor]; |
33 } | 33 } |
34 return self; | 34 return self; |
35 } | 35 } |
36 | 36 |
37 - (BOOL)ensureContext { | 37 - (BOOL)ensureContext { |
38 if (context_) | 38 if (context_.get()) |
39 return YES; | 39 return YES; |
40 | 40 |
41 if (!renderWidgetHostView_) | 41 if (!renderWidgetHostView_) |
42 return NO; | 42 return NO; |
43 | 43 |
44 if (renderWidgetHostView_->compositing_iosurface_) { | 44 if (renderWidgetHostView_->compositing_iosurface_) { |
45 context_ = renderWidgetHostView_->compositing_iosurface_->context(); | 45 context_ = renderWidgetHostView_->compositing_iosurface_->context(); |
46 [context_->nsgl_context() clearDrawable]; | 46 [context_->nsgl_context() clearDrawable]; |
47 } | 47 } |
48 | 48 |
49 if (!context_) { | 49 if (!context_.get()) { |
50 context_ = content::CompositingIOSurfaceContext::Get( | 50 context_ = content::CompositingIOSurfaceContext::Get( |
51 renderWidgetHostView_->window_number()); | 51 renderWidgetHostView_->window_number()); |
52 } | 52 } |
53 | 53 |
54 return context_ ? YES : NO; | 54 return context_.get() ? YES : NO; |
55 } | 55 } |
56 | 56 |
57 - (void)updateScaleFactor { | 57 - (void)updateScaleFactor { |
58 if (!renderWidgetHostView_ || | 58 if (!renderWidgetHostView_ || |
59 ![self respondsToSelector:(@selector(contentsScale))] || | 59 ![self respondsToSelector:(@selector(contentsScale))] || |
60 ![self respondsToSelector:(@selector(setContentsScale:))]) | 60 ![self respondsToSelector:(@selector(setContentsScale:))]) |
61 return; | 61 return; |
62 | 62 |
63 float current_scale_factor = [self contentsScale]; | 63 float current_scale_factor = [self contentsScale]; |
64 float new_scale_factor = current_scale_factor; | 64 float new_scale_factor = current_scale_factor; |
(...skipping 17 matching lines...) Expand all Loading... |
82 | 82 |
83 // The remaining methods implement the CAOpenGLLayer interface. | 83 // The remaining methods implement the CAOpenGLLayer interface. |
84 | 84 |
85 - (CGLContextObj)copyCGLContextForPixelFormat:(CGLPixelFormatObj)pixelFormat { | 85 - (CGLContextObj)copyCGLContextForPixelFormat:(CGLPixelFormatObj)pixelFormat { |
86 if ([self ensureContext]) | 86 if ([self ensureContext]) |
87 return context_->cgl_context(); | 87 return context_->cgl_context(); |
88 return nil; | 88 return nil; |
89 } | 89 } |
90 | 90 |
91 - (void)releaseCGLContext:(CGLContextObj)glContext { | 91 - (void)releaseCGLContext:(CGLContextObj)glContext { |
92 if (!context_) | 92 if (!context_.get()) |
93 return; | 93 return; |
94 | 94 |
95 DCHECK(glContext == context_->cgl_context()); | 95 DCHECK(glContext == context_->cgl_context()); |
96 context_ = nil; | 96 context_ = nil; |
97 } | 97 } |
98 | 98 |
99 - (void)drawInCGLContext:(CGLContextObj)glContext | 99 - (void)drawInCGLContext:(CGLContextObj)glContext |
100 pixelFormat:(CGLPixelFormatObj)pixelFormat | 100 pixelFormat:(CGLPixelFormatObj)pixelFormat |
101 forLayerTime:(CFTimeInterval)timeInterval | 101 forLayerTime:(CFTimeInterval)timeInterval |
102 displayTime:(const CVTimeStamp*)timeStamp { | 102 displayTime:(const CVTimeStamp*)timeStamp { |
103 if (!context_ || !renderWidgetHostView_ || | 103 if (!context_.get() || !renderWidgetHostView_ || |
104 !renderWidgetHostView_->compositing_iosurface_) { | 104 !renderWidgetHostView_->compositing_iosurface_) { |
105 glClearColor(1, 1, 1, 1); | 105 glClearColor(1, 1, 1, 1); |
106 glClear(GL_COLOR_BUFFER_BIT); | 106 glClear(GL_COLOR_BUFFER_BIT); |
107 return; | 107 return; |
108 } | 108 } |
109 | 109 |
110 DCHECK(glContext == context_->cgl_context()); | 110 DCHECK(glContext == context_->cgl_context()); |
111 | 111 |
112 gfx::Size window_size([self frame].size); | 112 gfx::Size window_size([self frame].size); |
113 float window_scale_factor = 1.f; | 113 float window_scale_factor = 1.f; |
114 if ([self respondsToSelector:(@selector(contentsScale))]) | 114 if ([self respondsToSelector:(@selector(contentsScale))]) |
115 window_scale_factor = [self contentsScale]; | 115 window_scale_factor = [self contentsScale]; |
116 | 116 |
117 if (!renderWidgetHostView_->compositing_iosurface_->DrawIOSurface( | 117 if (!renderWidgetHostView_->compositing_iosurface_->DrawIOSurface( |
118 window_size, | 118 window_size, |
119 window_scale_factor, | 119 window_scale_factor, |
120 renderWidgetHostView_->frame_subscriber(), | 120 renderWidgetHostView_->frame_subscriber(), |
121 true)) { | 121 true)) { |
122 renderWidgetHostView_->GotAcceleratedCompositingError(); | 122 renderWidgetHostView_->GotAcceleratedCompositingError(); |
123 } | 123 } |
124 } | 124 } |
125 | 125 |
126 @end | 126 @end |
OLD | NEW |