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

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

Issue 3431011: Mac: Fix concurrent access on a non-threadsafe data structure. (Closed)
Patch Set: '' Created 10 years, 3 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
« no previous file with comments | « chrome/browser/renderer_host/render_widget_host_view_mac.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 <QuartzCore/QuartzCore.h> 5 #include <QuartzCore/QuartzCore.h>
6 6
7 #include "chrome/browser/renderer_host/render_widget_host_view_mac.h" 7 #include "chrome/browser/renderer_host/render_widget_host_view_mac.h"
8 8
9 #include "chrome/browser/chrome_thread.h" 9 #include "chrome/browser/chrome_thread.h"
10 #include "app/surface/io_surface_support_mac.h" 10 #include "app/surface/io_surface_support_mac.h"
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 scoped_nsobject<NSOpenGLContext> glContext_; 149 scoped_nsobject<NSOpenGLContext> glContext_;
150 CGLContextObj cglContext_; // weak, backed by |glContext_|. 150 CGLContextObj cglContext_; // weak, backed by |glContext_|.
151 151
152 CVDisplayLinkRef displayLink_; // Owned by us. 152 CVDisplayLinkRef displayLink_; // Owned by us.
153 153
154 RenderWidgetHostViewMac* renderWidgetHostView_; // weak 154 RenderWidgetHostViewMac* renderWidgetHostView_; // weak
155 gfx::PluginWindowHandle pluginHandle_; // weak 155 gfx::PluginWindowHandle pluginHandle_; // weak
156 156
157 // True if the backing IO surface was updated since we last painted. 157 // True if the backing IO surface was updated since we last painted.
158 BOOL surfaceWasSwapped_; 158 BOOL surfaceWasSwapped_;
159
160 // Cocoa methods can only be called on the main thread, so have a copy of the
161 // view's size, since it's required on the displaylink thread.
162 NSSize cachedSize_;
159 } 163 }
160 164
161 - (id)initWithRenderWidgetHostViewMac:(RenderWidgetHostViewMac*)r 165 - (id)initWithRenderWidgetHostViewMac:(RenderWidgetHostViewMac*)r
162 pluginHandle:(gfx::PluginWindowHandle)pluginHandle; 166 pluginHandle:(gfx::PluginWindowHandle)pluginHandle;
163 - (void)drawView; 167 - (void)drawView;
164 168
165 // This _must_ be atomic, since it's accessed from several threads. 169 // This _must_ be atomic, since it's accessed from several threads.
166 @property BOOL surfaceWasSwapped; 170 @property BOOL surfaceWasSwapped;
171
172 // This _must_ be atomic, since it's accessed from several threads.
173 @property NSSize cachedSize;
167 @end 174 @end
168 175
169 @implementation AcceleratedPluginView : NSView 176 @implementation AcceleratedPluginView : NSView
170 @synthesize surfaceWasSwapped = surfaceWasSwapped_; 177 @synthesize surfaceWasSwapped = surfaceWasSwapped_;
178 @synthesize cachedSize = cachedSize_;
171 179
172 - (CVReturn)getFrameForTime:(const CVTimeStamp*)outputTime { 180 - (CVReturn)getFrameForTime:(const CVTimeStamp*)outputTime {
173 // There is no autorelease pool when this method is called because it will be 181 // There is no autorelease pool when this method is called because it will be
174 // called from a background thread. 182 // called from a background thread.
175 base::ScopedNSAutoreleasePool pool; 183 base::ScopedNSAutoreleasePool pool;
176 184
177 if (![self surfaceWasSwapped]) 185 if (![self surfaceWasSwapped])
178 return kCVReturnSuccess; 186 return kCVReturnSuccess;
179 187
180 [self drawView]; 188 [self drawView];
(...skipping 12 matching lines...) Expand all
193 CVReturn result = 201 CVReturn result =
194 [(AcceleratedPluginView*)displayLinkContext getFrameForTime:outputTime]; 202 [(AcceleratedPluginView*)displayLinkContext getFrameForTime:outputTime];
195 return result; 203 return result;
196 } 204 }
197 205
198 - (id)initWithRenderWidgetHostViewMac:(RenderWidgetHostViewMac*)r 206 - (id)initWithRenderWidgetHostViewMac:(RenderWidgetHostViewMac*)r
199 pluginHandle:(gfx::PluginWindowHandle)pluginHandle { 207 pluginHandle:(gfx::PluginWindowHandle)pluginHandle {
200 if ((self = [super initWithFrame:NSZeroRect])) { 208 if ((self = [super initWithFrame:NSZeroRect])) {
201 renderWidgetHostView_ = r; 209 renderWidgetHostView_ = r;
202 pluginHandle_ = pluginHandle; 210 pluginHandle_ = pluginHandle;
211 cachedSize_ = NSZeroSize;
203 212
204 [self setAutoresizingMask:NSViewMaxXMargin|NSViewMinYMargin]; 213 [self setAutoresizingMask:NSViewMaxXMargin|NSViewMinYMargin];
205 214
206 NSOpenGLPixelFormatAttribute attributes[] = 215 NSOpenGLPixelFormatAttribute attributes[] =
207 { NSOpenGLPFAAccelerated, NSOpenGLPFADoubleBuffer, 0}; 216 { NSOpenGLPFAAccelerated, NSOpenGLPFADoubleBuffer, 0};
208 217
209 glPixelFormat_.reset([[NSOpenGLPixelFormat alloc] 218 glPixelFormat_.reset([[NSOpenGLPixelFormat alloc]
210 initWithAttributes:attributes]); 219 initWithAttributes:attributes]);
211 glContext_.reset([[NSOpenGLContext alloc] initWithFormat:glPixelFormat_ 220 glContext_.reset([[NSOpenGLContext alloc] initWithFormat:glPixelFormat_
212 shareContext:nil]); 221 shareContext:nil]);
(...skipping 21 matching lines...) Expand all
234 displayLink_, cglContext_, cglPixelFormat_); 243 displayLink_, cglContext_, cglPixelFormat_);
235 CVDisplayLinkStart(displayLink_); 244 CVDisplayLinkStart(displayLink_);
236 } 245 }
237 return self; 246 return self;
238 } 247 }
239 248
240 - (void)drawView { 249 - (void)drawView {
241 // Called on a background thread. Synchronized via the CGL context lock. 250 // Called on a background thread. Synchronized via the CGL context lock.
242 CGLLockContext(cglContext_); 251 CGLLockContext(cglContext_);
243 252
253 // TODO(thakis): Pixel or view coordinates for size?
244 renderWidgetHostView_->DrawAcceleratedSurfaceInstance( 254 renderWidgetHostView_->DrawAcceleratedSurfaceInstance(
245 cglContext_, pluginHandle_); 255 cglContext_, pluginHandle_, [self cachedSize]);
246 256
247 CGLFlushDrawable(cglContext_); 257 CGLFlushDrawable(cglContext_);
248 CGLUnlockContext(cglContext_); 258 CGLUnlockContext(cglContext_);
249 } 259 }
250 260
251 - (void)drawRect:(NSRect)rect { 261 - (void)drawRect:(NSRect)rect {
252 if (!CommandLine::ForCurrentProcess()->HasSwitch( 262 if (!CommandLine::ForCurrentProcess()->HasSwitch(
253 switches::kDisableHolePunching)) { 263 switches::kDisableHolePunching)) {
254 const NSRect* dirtyRects; 264 const NSRect* dirtyRects;
255 int dirtyRectCount; 265 int dirtyRectCount;
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 } 331 }
322 332
323 if ([[self window] respondsToSelector:@selector(underlaySurfaceRemoved)]) { 333 if ([[self window] respondsToSelector:@selector(underlaySurfaceRemoved)]) {
324 [static_cast<id>([self window]) underlaySurfaceRemoved]; 334 [static_cast<id>([self window]) underlaySurfaceRemoved];
325 } 335 }
326 336
327 if ([newWindow respondsToSelector:@selector(underlaySurfaceAdded)]) { 337 if ([newWindow respondsToSelector:@selector(underlaySurfaceAdded)]) {
328 [static_cast<id>(newWindow) underlaySurfaceAdded]; 338 [static_cast<id>(newWindow) underlaySurfaceAdded];
329 } 339 }
330 } 340 }
341
342 - (void)setFrame:(NSRect)frameRect {
343 [self setCachedSize:frameRect.size];
344 [super setFrame:frameRect];
345 }
346
347 - (void)setFrameSize:(NSSize)newSize {
348 [self setCachedSize:newSize];
349 [super setFrameSize:newSize];
350 }
331 @end 351 @end
332 352
333 // RenderWidgetHostView -------------------------------------------------------- 353 // RenderWidgetHostView --------------------------------------------------------
334 354
335 // static 355 // static
336 RenderWidgetHostView* RenderWidgetHostView::CreateViewForWidget( 356 RenderWidgetHostView* RenderWidgetHostView::CreateViewForWidget(
337 RenderWidgetHost* widget) { 357 RenderWidgetHost* widget) {
338 return new RenderWidgetHostViewMac(widget); 358 return new RenderWidgetHostViewMac(widget);
339 } 359 }
340 360
(...skipping 572 matching lines...) Expand 10 before | Expand all | Expand 10 after
913 if (plugin_views_.end() == it) { 933 if (plugin_views_.end() == it) {
914 return; 934 return;
915 } 935 }
916 bool visible = 936 bool visible =
917 plugin_container_manager_.SurfaceShouldBeVisible(root_handle); 937 plugin_container_manager_.SurfaceShouldBeVisible(root_handle);
918 [it->second setHidden:!visible]; 938 [it->second setHidden:!visible];
919 } 939 }
920 } 940 }
921 941
922 void RenderWidgetHostViewMac::DrawAcceleratedSurfaceInstance( 942 void RenderWidgetHostViewMac::DrawAcceleratedSurfaceInstance(
923 CGLContextObj context, gfx::PluginWindowHandle plugin_handle) { 943 CGLContextObj context,
944 gfx::PluginWindowHandle plugin_handle,
945 NSSize size) {
924 // Called on the display link thread. 946 // Called on the display link thread.
925 PluginViewMap::iterator it = plugin_views_.find(plugin_handle);
926 DCHECK(plugin_views_.end() != it);
927 if (plugin_views_.end() == it) {
928 return;
929 }
930 CGLSetCurrentContext(context); 947 CGLSetCurrentContext(context);
931 // TODO(thakis): Pixel or view coordinates?
932 NSSize size = [it->second frame].size;
933 948
934 glMatrixMode(GL_PROJECTION); 949 glMatrixMode(GL_PROJECTION);
935 glLoadIdentity(); 950 glLoadIdentity();
936 // Note that we place the origin at the upper left corner with +y 951 // Note that we place the origin at the upper left corner with +y
937 // going down 952 // going down
938 glOrtho(0, size.width, size.height, 0, -1, 1); 953 glOrtho(0, size.width, size.height, 0, -1, 1);
939 glMatrixMode(GL_MODELVIEW); 954 glMatrixMode(GL_MODELVIEW);
940 glLoadIdentity(); 955 glLoadIdentity();
941 956
942 plugin_container_manager_.Draw(context, plugin_handle); 957 plugin_container_manager_.Draw(context, plugin_handle);
(...skipping 555 matching lines...) Expand 10 before | Expand all | Expand 10 after
1498 gfx::Rect gpuRect; 1513 gfx::Rect gpuRect;
1499 1514
1500 gfx::PluginWindowHandle root_handle = 1515 gfx::PluginWindowHandle root_handle =
1501 renderWidgetHostView_->plugin_container_manager_.root_container_handle(); 1516 renderWidgetHostView_->plugin_container_manager_.root_container_handle();
1502 if (root_handle != gfx::kNullPluginWindow) { 1517 if (root_handle != gfx::kNullPluginWindow) {
1503 RenderWidgetHostViewMac::PluginViewMap::iterator it = 1518 RenderWidgetHostViewMac::PluginViewMap::iterator it =
1504 renderWidgetHostView_->plugin_views_.find(root_handle); 1519 renderWidgetHostView_->plugin_views_.find(root_handle);
1505 DCHECK(it != renderWidgetHostView_->plugin_views_.end()); 1520 DCHECK(it != renderWidgetHostView_->plugin_views_.end());
1506 if (it != renderWidgetHostView_->plugin_views_.end() && 1521 if (it != renderWidgetHostView_->plugin_views_.end() &&
1507 ![it->second isHidden]) { 1522 ![it->second isHidden]) {
1508 gpuRect = [self flipNSRectToRect:[it->second frame]]; 1523 NSRect frame = [it->second frame];
1524 frame.size = [it->second cachedSize];
1525 gpuRect = [self flipNSRectToRect:frame];
1509 } 1526 }
1510 } 1527 }
1511 1528
1512 [self fillBottomRightRemainderOfRect:gpuRect dirtyRect:damagedRect]; 1529 [self fillBottomRightRemainderOfRect:gpuRect dirtyRect:damagedRect];
1513 return; 1530 return;
1514 } 1531 }
1515 1532
1516 DCHECK( 1533 DCHECK(
1517 renderWidgetHostView_->render_widget_host_->process()->HasConnection()); 1534 renderWidgetHostView_->render_widget_host_->process()->HasConnection());
1518 DCHECK(!renderWidgetHostView_->about_to_validate_and_paint_); 1535 DCHECK(!renderWidgetHostView_->about_to_validate_and_paint_);
(...skipping 890 matching lines...) Expand 10 before | Expand all | Expand 10 after
2409 if (!string) return NO; 2426 if (!string) return NO;
2410 2427
2411 // If the user is currently using an IME, confirm the IME input, 2428 // If the user is currently using an IME, confirm the IME input,
2412 // and then insert the text from the service, the same as TextEdit and Safari. 2429 // and then insert the text from the service, the same as TextEdit and Safari.
2413 [self confirmComposition]; 2430 [self confirmComposition];
2414 [self insertText:string]; 2431 [self insertText:string];
2415 return YES; 2432 return YES;
2416 } 2433 }
2417 2434
2418 @end 2435 @end
OLDNEW
« no previous file with comments | « chrome/browser/renderer_host/render_widget_host_view_mac.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698