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

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

Issue 16189012: Add a path to use CALayers to display content (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove unused method Created 7 years, 6 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "content/browser/renderer_host/compositing_iosurface_layer_mac.h"
6
7 #include <CoreFoundation/CoreFoundation.h>
8
9 #include "content/browser/renderer_host/render_widget_host_view_mac.h"
10 #include "content/browser/renderer_host/compositing_iosurface_context_mac.h"
11 #include "content/browser/renderer_host/compositing_iosurface_mac.h"
12 #include "ui/base/cocoa/animation_utils.h"
13 #include "ui/gfx/size_conversions.h"
14
15 @interface CALayer (LionAPI)
16 - (CGFloat)contentsScale;
17 - (void)setContentsScale:(CGFloat)contentsScale;
18 @end
19
20 @implementation CompositingIOSurfaceLayer
21
22 @synthesize context = context_;
23
24 - (id)initWithRenderWidgetHostViewMac:(content::RenderWidgetHostViewMac*)r {
25 if (self = [super init]) {
26 renderWidgetHostView_ = r;
27
28 NSView* view = renderWidgetHostView_->cocoa_view();
29 CGRect rect;
30 rect.origin.x = 0;
31 rect.origin.y = 0;
32 rect.size.width = [view bounds].size.width;
33 rect.size.height = [view bounds].size.height;
sail 2013/05/31 23:59:14 use NSRectToCGRect?
ccameron 2013/06/01 00:29:45 Done.
34
35 ScopedCAActionDisabler disabler;
36 [self setAutoresizingMask:kCALayerWidthSizable | kCALayerHeightSizable];
37 [self setContentsGravity:kCAGravityTopLeft];
38 [self setFrame:rect];
39 [self setNeedsDisplay];
40 [self updateScaleFactor];
41 [[view layer] addSublayer:self];
42 }
43 return self;
44 }
45
46 - (BOOL)ensureContext {
47 if (context_)
48 return YES;
49
50 if (!renderWidgetHostView_)
51 return NO;
52
53 if (renderWidgetHostView_->compositing_iosurface_)
54 context_ = renderWidgetHostView_->compositing_iosurface_->context();
55
56 if (!context_) {
57 context_ = content::CompositingIOSurfaceContext::Get(
58 renderWidgetHostView_->window_number(),
59 content::CompositingIOSurfaceMac::SURFACE_ORDER_ABOVE_WINDOW);
60 }
61
62 return context_ ? YES : NO;
63 }
64
65 - (void)updateScaleFactor {
66 if (!renderWidgetHostView_ ||
67 ![self respondsToSelector:(@selector(contentsScale))] ||
68 ![self respondsToSelector:(@selector(setContentsScale:))])
69 return;
70
71 float current_scale_factor = [self contentsScale];
72 float new_scale_factor = current_scale_factor;
73 if (renderWidgetHostView_->compositing_iosurface_) {
74 new_scale_factor =
75 renderWidgetHostView_->compositing_iosurface_->scale_factor();
76 }
77
78 if (new_scale_factor == current_scale_factor)
79 return;
80
81 ScopedCAActionDisabler disabler;
82 [self setContentsScale:new_scale_factor];
83 }
84
85 - (void)disableCompositing{
86 ScopedCAActionDisabler disabler;
87 [self removeFromSuperlayer];
88 renderWidgetHostView_ = nil;
89 }
90
91 // The remaining methods implement the CAOpenGLLayer interface.
92
93 - (CGLContextObj)copyCGLContextForPixelFormat:(CGLPixelFormatObj)pixelFormat {
94 if ([self ensureContext])
95 return context_->cgl_context();
96 return nil;
97 }
98
99 - (void)releaseCGLContext:(CGLContextObj)glContext {
100 if (!context_)
101 return;
102
103 DCHECK(glContext == context_->cgl_context());
104 context_ = nil;
105 }
106
107 - (void)drawInCGLContext:(CGLContextObj)glContext
108 pixelFormat:(CGLPixelFormatObj)pixelFormat
109 forLayerTime:(CFTimeInterval)timeInterval
110 displayTime:(const CVTimeStamp*)timeStamp {
111 if (!context_ || !renderWidgetHostView_ ||
112 !renderWidgetHostView_->compositing_iosurface_) {
113 glClearColor(1, 1, 1, 1);
114 glClear(GL_COLOR_BUFFER_BIT);
115 return;
116 }
117
118 DCHECK(glContext == context_->cgl_context());
119
120 gfx::Size window_size([self frame].size);
121 float window_scale_factor = 1.f;
122 if ([self respondsToSelector:(@selector(contentsScale))])
123 window_scale_factor = [self contentsScale];
124
125 renderWidgetHostView_->compositing_iosurface_->DrawIOSurface(
126 window_size,
127 window_scale_factor,
128 renderWidgetHostView_->frame_subscriber());
129
130 renderWidgetHostView_->AckPendingSwapBuffers();
131 }
132
133 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698