OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 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/render_widget_helper.h" |
| 6 |
| 7 #import <Cocoa/Cocoa.h> |
| 8 |
| 9 #include "base/bind.h" |
| 10 #include "content/browser/gpu/gpu_process_host.h" |
| 11 #include "content/browser/gpu/gpu_surface_tracker.h" |
| 12 #include "content/common/gpu/gpu_messages.h" |
| 13 |
| 14 // Declare methods used to present swaps to this view. |
| 15 @interface NSView (ContentCompositingView) |
| 16 - (void)onNativeSurfaceBuffersSwappedWithParams: |
| 17 (GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params)params; |
| 18 @end |
| 19 |
| 20 @implementation NSView (ContentCompositingView) |
| 21 - (void)onNativeSurfaceBuffersSwappedWithParams: |
| 22 (GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params)params { |
| 23 } |
| 24 @end |
| 25 |
| 26 namespace { |
| 27 |
| 28 void OnNativeSurfaceBuffersSwappedOnUIThread( |
| 29 const GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params& params) { |
| 30 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 31 gfx::AcceleratedWidget native_widget = |
| 32 content::GpuSurfaceTracker::Get()->AcquireNativeWidget(params.surface_id); |
| 33 [native_widget onNativeSurfaceBuffersSwappedWithParams:params]; |
| 34 } |
| 35 |
| 36 } // namespace |
| 37 |
| 38 namespace content { |
| 39 |
| 40 void RenderWidgetHelper::OnNativeSurfaceBuffersSwappedOnIOThread( |
| 41 GpuProcessHost* gpu_process_host, |
| 42 const GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params& params) { |
| 43 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 44 |
| 45 // Immediately acknowledge this frame on the IO thread instead of the UI |
| 46 // thread. The UI thread will wait on the GPU process. If the UI thread |
| 47 // were to be responsible for acking swaps, then there would be a cycle |
| 48 // and a potential deadlock. |
| 49 // TODO(ccameron): This immediate ack circumvents GPU back-pressure that |
| 50 // is necessary to throttle renderers. Fix that. |
| 51 // TODO(ccameron): It is possible that the IOSurface will be deleted or |
| 52 // reused soon as it is acked. Take out a reference to the IOSurface here, |
| 53 // to ensure the IOSurface does not disappear before routing to the UI |
| 54 // thread. |
| 55 AcceleratedSurfaceMsg_BufferPresented_Params ack_params; |
| 56 ack_params.sync_point = 0; |
| 57 ack_params.renderer_id = 0; |
| 58 gpu_process_host->Send(new AcceleratedSurfaceMsg_BufferPresented( |
| 59 params.route_id, ack_params)); |
| 60 |
| 61 BrowserThread::PostTask( |
| 62 BrowserThread::UI, |
| 63 FROM_HERE, |
| 64 base::Bind(&OnNativeSurfaceBuffersSwappedOnUIThread, params)); |
| 65 } |
| 66 |
| 67 } // namespace content |
OLD | NEW |