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

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: Rebase Created 6 years, 8 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 1345 matching lines...) Expand 10 before | Expand all | Expand 10 after
1356 1356
1357 // Ensure compositing_iosurface_ and compositing_iosurface_context_ be 1357 // Ensure compositing_iosurface_ and compositing_iosurface_context_ be
1358 // allocated. 1358 // allocated.
1359 if (!EnsureCompositedIOSurface()) { 1359 if (!EnsureCompositedIOSurface()) {
1360 LOG(ERROR) << "Failed EnsureCompositingIOSurface"; 1360 LOG(ERROR) << "Failed EnsureCompositingIOSurface";
1361 return; 1361 return;
1362 } 1362 }
1363 1363
1364 // Make the context current and update the IOSurface with the handle 1364 // Make the context current and update the IOSurface with the handle
1365 // passed in by the swap command. 1365 // passed in by the swap command.
1366 gfx::ScopedCGLSetCurrentContext scoped_set_current_context( 1366 {
1367 compositing_iosurface_context_->cgl_context()); 1367 gfx::ScopedCGLSetCurrentContext scoped_set_current_context(
1368 if (!compositing_iosurface_->SetIOSurfaceWithContextCurrent( 1368 compositing_iosurface_context_->cgl_context());
1369 compositing_iosurface_context_, surface_handle, size, 1369 if (!compositing_iosurface_->SetIOSurfaceWithContextCurrent(
1370 surface_scale_factor)) { 1370 compositing_iosurface_context_, surface_handle, size,
1371 LOG(ERROR) << "Failed SetIOSurface on CompositingIOSurfaceMac"; 1371 surface_scale_factor)) {
1372 return; 1372 LOG(ERROR) << "Failed SetIOSurface on CompositingIOSurfaceMac";
1373 return;
1374 }
1373 } 1375 }
1374 1376
1375 // Grab video frames now that the IOSurface has been set up. Note that this 1377 // 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 1378 // will be done in an offscreen context, so it is necessary to re-set the
1377 // current context afterward. 1379 // current context afterward.
1378 bool frame_was_captured = false; 1380 bool frame_was_captured = false;
1379 if (frame_subscriber_) { 1381 if (frame_subscriber_) {
1380 const base::TimeTicks present_time = base::TimeTicks::Now(); 1382 const base::TimeTicks present_time = base::TimeTicks::Now();
1381 scoped_refptr<media::VideoFrame> frame; 1383 scoped_refptr<media::VideoFrame> frame;
1382 RenderWidgetHostViewFrameSubscriber::DeliverFrameCallback callback; 1384 RenderWidgetHostViewFrameSubscriber::DeliverFrameCallback callback;
1383 if (frame_subscriber_->ShouldCaptureFrame(present_time, 1385 if (frame_subscriber_->ShouldCaptureFrame(present_time,
1384 &frame, &callback)) { 1386 &frame, &callback)) {
1385 // Flush the context that updated the IOSurface, to ensure that the 1387 // Flush the context that updated the IOSurface, to ensure that the
1386 // context that does the copy picks up the correct version. 1388 // context that does the copy picks up the correct version.
1387 glFlush(); 1389 {
1390 gfx::ScopedCGLSetCurrentContext scoped_set_current_context(
1391 compositing_iosurface_context_->cgl_context());
1392 glFlush();
1393 }
1388 compositing_iosurface_->CopyToVideoFrame( 1394 compositing_iosurface_->CopyToVideoFrame(
1389 gfx::Rect(size), frame, 1395 gfx::Rect(size), frame,
1390 base::Bind(callback, present_time)); 1396 base::Bind(callback, present_time));
1391 DCHECK_EQ(CGLGetCurrentContext(),
1392 compositing_iosurface_context_->cgl_context());
1393 frame_was_captured = true; 1397 frame_was_captured = true;
1394 } 1398 }
1395 } 1399 }
1396 1400
1397 // At this point the surface, its context, and its layer have been set up, so 1401 // 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). 1402 // don't generate an error (one may be generated when drawing).
1399 ignore_result(scoped_error.Release()); 1403 ignore_result(scoped_error.Release());
1400 1404
1401 GotAcceleratedFrame(); 1405 GotAcceleratedFrame();
1402 1406
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1440 } 1444 }
1441 1445
1442 // If we reach here, then the frame will be displayed by a future draw 1446 // If we reach here, then the frame will be displayed by a future draw
1443 // call, so don't make the callback. 1447 // call, so don't make the callback.
1444 ignore_result(scoped_ack.Release()); 1448 ignore_result(scoped_ack.Release());
1445 if (use_core_animation_) { 1449 if (use_core_animation_) {
1446 DCHECK(compositing_iosurface_layer_); 1450 DCHECK(compositing_iosurface_layer_);
1447 compositing_iosurface_layer_async_timer_.Reset(); 1451 compositing_iosurface_layer_async_timer_.Reset();
1448 [compositing_iosurface_layer_ gotNewFrame]; 1452 [compositing_iosurface_layer_ gotNewFrame];
1449 } else { 1453 } else {
1454 gfx::ScopedCGLSetCurrentContext scoped_set_current_context(
1455 compositing_iosurface_context_->cgl_context());
1450 DrawIOSurfaceWithoutCoreAnimation(); 1456 DrawIOSurfaceWithoutCoreAnimation();
1451 } 1457 }
1452 1458
1453 // The IOSurface's size may have changed, so re-layout the layers to take 1459 // The IOSurface's size may have changed, so re-layout the layers to take
1454 // this into account. This may force an immediate draw. 1460 // this into account. This may force an immediate draw.
1455 LayoutLayers(); 1461 LayoutLayers();
1456 } 1462 }
1457 1463
1458 void RenderWidgetHostViewMac::DrawIOSurfaceWithoutCoreAnimation() { 1464 void RenderWidgetHostViewMac::DrawIOSurfaceWithoutCoreAnimation() {
1459 CHECK(!use_core_animation_); 1465 CHECK(!use_core_animation_);
(...skipping 2827 matching lines...) Expand 10 before | Expand all | Expand 10 after
4287 } 4293 }
4288 4294
4289 - (void)disableRendering { 4295 - (void)disableRendering {
4290 // Disable the fade-out animation as the layer is removed. 4296 // Disable the fade-out animation as the layer is removed.
4291 ScopedCAActionDisabler disabler; 4297 ScopedCAActionDisabler disabler;
4292 [self removeFromSuperlayer]; 4298 [self removeFromSuperlayer];
4293 renderWidgetHostView_ = nil; 4299 renderWidgetHostView_ = nil;
4294 } 4300 }
4295 4301
4296 @end // implementation SoftwareLayer 4302 @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