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

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

Issue 216733002: Reduce the scope of CGL current contexts (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 9 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 | « no previous file | 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) 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 1319 matching lines...) Expand 10 before | Expand all | Expand 10 after
1330 render_widget_host_->Send(new ViewMsg_PluginImeCompositionCompleted( 1330 render_widget_host_->Send(new ViewMsg_PluginImeCompositionCompleted(
1331 render_widget_host_->GetRoutingID(), text, plugin_id)); 1331 render_widget_host_->GetRoutingID(), text, plugin_id));
1332 } 1332 }
1333 } 1333 }
1334 1334
1335 void RenderWidgetHostViewMac::CompositorSwapBuffers( 1335 void RenderWidgetHostViewMac::CompositorSwapBuffers(
1336 uint64 surface_handle, 1336 uint64 surface_handle,
1337 const gfx::Size& size, 1337 const gfx::Size& size,
1338 float surface_scale_factor, 1338 float surface_scale_factor,
1339 const std::vector<ui::LatencyInfo>& latency_info) { 1339 const std::vector<ui::LatencyInfo>& latency_info) {
1340 DCHECK(!CGLGetCurrentContext());
Ken Russell (switch to Gerrit) 2014/03/28 16:18:41 Have you run a debug build with this DCHECK in pla
ccameron 2014/03/28 16:22:49 Yes, but, you bring up a good point -- I haven't r
1341
1340 // Ensure that the frame be acked unless it is explicitly passed to a 1342 // Ensure that the frame be acked unless it is explicitly passed to a
1341 // display function. 1343 // display function.
1342 base::ScopedClosureRunner scoped_ack( 1344 base::ScopedClosureRunner scoped_ack(
1343 base::Bind(&RenderWidgetHostViewMac::SendPendingSwapAck, 1345 base::Bind(&RenderWidgetHostViewMac::SendPendingSwapAck,
1344 weak_factory_.GetWeakPtr())); 1346 weak_factory_.GetWeakPtr()));
1345 1347
1346 if (render_widget_host_->is_hidden()) 1348 if (render_widget_host_->is_hidden())
1347 return; 1349 return;
1348 1350
1349 // Ensure that if this function exits before the frame is set up (but not 1351 // Ensure that if this function exits before the frame is set up (but not
1350 // necessarily drawn) then it is treated as an error. 1352 // necessarily drawn) then it is treated as an error.
1351 base::ScopedClosureRunner scoped_error( 1353 base::ScopedClosureRunner scoped_error(
1352 base::Bind(&RenderWidgetHostViewMac::GotAcceleratedCompositingError, 1354 base::Bind(&RenderWidgetHostViewMac::GotAcceleratedCompositingError,
1353 weak_factory_.GetWeakPtr())); 1355 weak_factory_.GetWeakPtr()));
1354 1356
1355 AddPendingLatencyInfo(latency_info); 1357 AddPendingLatencyInfo(latency_info);
1356 1358
1357 // Ensure compositing_iosurface_ and compositing_iosurface_context_ be 1359 // Ensure compositing_iosurface_ and compositing_iosurface_context_ be
1358 // allocated. 1360 // allocated.
1359 if (!EnsureCompositedIOSurface()) { 1361 if (!EnsureCompositedIOSurface()) {
1360 LOG(ERROR) << "Failed EnsureCompositingIOSurface"; 1362 LOG(ERROR) << "Failed EnsureCompositingIOSurface";
1361 return; 1363 return;
1362 } 1364 }
1363 1365
1364 // Make the context current and update the IOSurface with the handle 1366 // Make the context current and update the IOSurface with the handle
1365 // passed in by the swap command. 1367 // passed in by the swap command.
1366 gfx::ScopedCGLSetCurrentContext scoped_set_current_context( 1368 {
1367 compositing_iosurface_context_->cgl_context()); 1369 gfx::ScopedCGLSetCurrentContext scoped_set_current_context(
1368 if (!compositing_iosurface_->SetIOSurfaceWithContextCurrent( 1370 compositing_iosurface_context_->cgl_context());
1369 compositing_iosurface_context_, surface_handle, size, 1371 if (!compositing_iosurface_->SetIOSurfaceWithContextCurrent(
1370 surface_scale_factor)) { 1372 compositing_iosurface_context_, surface_handle, size,
1371 LOG(ERROR) << "Failed SetIOSurface on CompositingIOSurfaceMac"; 1373 surface_scale_factor)) {
1372 return; 1374 LOG(ERROR) << "Failed SetIOSurface on CompositingIOSurfaceMac";
1375 return;
1376 }
1373 } 1377 }
1374 1378
1375 // Grab video frames now that the IOSurface has been set up. Note that this 1379 // Grab video frames now that the IOSurface has been set up. Note that this
1376 // will be done in an offscreen context, so it is necessary to re-set the 1380 // will be done in an offscreen context, so it is necessary to re-set the
1377 // current context afterward. 1381 // current context afterward.
1378 bool frame_was_captured = false; 1382 bool frame_was_captured = false;
1379 if (frame_subscriber_) { 1383 if (frame_subscriber_) {
1380 const base::TimeTicks present_time = base::TimeTicks::Now(); 1384 const base::TimeTicks present_time = base::TimeTicks::Now();
1381 scoped_refptr<media::VideoFrame> frame; 1385 scoped_refptr<media::VideoFrame> frame;
1382 RenderWidgetHostViewFrameSubscriber::DeliverFrameCallback callback; 1386 RenderWidgetHostViewFrameSubscriber::DeliverFrameCallback callback;
1383 if (frame_subscriber_->ShouldCaptureFrame(present_time, 1387 if (frame_subscriber_->ShouldCaptureFrame(present_time,
1384 &frame, &callback)) { 1388 &frame, &callback)) {
1385 // Flush the context that updated the IOSurface, to ensure that the 1389 // Flush the context that updated the IOSurface, to ensure that the
1386 // context that does the copy picks up the correct version. 1390 // context that does the copy picks up the correct version.
1387 glFlush(); 1391 {
ccameron 2014/03/28 10:01:48 Of note is that this should potentially be moved u
1392 gfx::ScopedCGLSetCurrentContext scoped_set_current_context(
1393 compositing_iosurface_context_->cgl_context());
1394 glFlush();
1395 }
1388 compositing_iosurface_->CopyToVideoFrame( 1396 compositing_iosurface_->CopyToVideoFrame(
1389 gfx::Rect(size), frame, 1397 gfx::Rect(size), frame,
1390 base::Bind(callback, present_time)); 1398 base::Bind(callback, present_time));
1391 DCHECK_EQ(CGLGetCurrentContext(),
1392 compositing_iosurface_context_->cgl_context());
1393 frame_was_captured = true; 1399 frame_was_captured = true;
1394 } 1400 }
1395 } 1401 }
1396 1402
1397 // At this point the surface, its context, and its layer have been set up, so 1403 // At this point the surface, its context, and its layer have been set up, so
1398 // don't generate an error (one may be generated when drawing). 1404 // don't generate an error (one may be generated when drawing).
1399 ignore_result(scoped_error.Release()); 1405 ignore_result(scoped_error.Release());
1400 1406
1401 GotAcceleratedFrame(); 1407 GotAcceleratedFrame();
1402 1408
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1440 } 1446 }
1441 1447
1442 // If we reach here, then the frame will be displayed by a future draw 1448 // If we reach here, then the frame will be displayed by a future draw
1443 // call, so don't make the callback. 1449 // call, so don't make the callback.
1444 ignore_result(scoped_ack.Release()); 1450 ignore_result(scoped_ack.Release());
1445 if (use_core_animation_) { 1451 if (use_core_animation_) {
1446 DCHECK(compositing_iosurface_layer_); 1452 DCHECK(compositing_iosurface_layer_);
1447 compositing_iosurface_layer_async_timer_.Reset(); 1453 compositing_iosurface_layer_async_timer_.Reset();
1448 [compositing_iosurface_layer_ gotNewFrame]; 1454 [compositing_iosurface_layer_ gotNewFrame];
1449 } else { 1455 } else {
1456 gfx::ScopedCGLSetCurrentContext scoped_set_current_context(
1457 compositing_iosurface_context_->cgl_context());
1450 DrawIOSurfaceWithoutCoreAnimation(); 1458 DrawIOSurfaceWithoutCoreAnimation();
1451 } 1459 }
1452 1460
1453 // The IOSurface's size may have changed, so re-layout the layers to take 1461 // The IOSurface's size may have changed, so re-layout the layers to take
1454 // this into account. This may force an immediate draw. 1462 // this into account. This may force an immediate draw.
1455 LayoutLayers(); 1463 LayoutLayers();
1456 } 1464 }
1457 1465
1458 void RenderWidgetHostViewMac::DrawIOSurfaceWithoutCoreAnimation() { 1466 void RenderWidgetHostViewMac::DrawIOSurfaceWithoutCoreAnimation() {
1459 CHECK(!use_core_animation_); 1467 CHECK(!use_core_animation_);
(...skipping 2827 matching lines...) Expand 10 before | Expand all | Expand 10 after
4287 } 4295 }
4288 4296
4289 - (void)disableRendering { 4297 - (void)disableRendering {
4290 // Disable the fade-out animation as the layer is removed. 4298 // Disable the fade-out animation as the layer is removed.
4291 ScopedCAActionDisabler disabler; 4299 ScopedCAActionDisabler disabler;
4292 [self removeFromSuperlayer]; 4300 [self removeFromSuperlayer];
4293 renderWidgetHostView_ = nil; 4301 renderWidgetHostView_ = nil;
4294 } 4302 }
4295 4303
4296 @end // implementation SoftwareLayer 4304 @end // implementation SoftwareLayer
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698