OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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/compositor/gpu_browser_compositor_output_surface.h" | 5 #include "content/browser/compositor/gpu_browser_compositor_output_surface.h" |
6 | 6 |
7 #include "cc/output/compositor_frame.h" | 7 #include "cc/output/compositor_frame.h" |
8 #include "cc/output/output_surface_client.h" | 8 #include "cc/output/output_surface_client.h" |
9 #include "content/browser/compositor/browser_compositor_overlay_candidate_valida
tor.h" | 9 #include "content/browser/compositor/browser_compositor_overlay_candidate_valida
tor.h" |
10 #include "content/browser/compositor/reflector_impl.h" | 10 #include "content/browser/compositor/reflector_impl.h" |
11 #include "content/browser/renderer_host/render_widget_host_impl.h" | 11 #include "content/browser/renderer_host/render_widget_host_impl.h" |
12 #include "content/common/gpu/client/context_provider_command_buffer.h" | 12 #include "content/common/gpu/client/context_provider_command_buffer.h" |
13 #include "content/public/browser/browser_thread.h" | 13 #include "content/public/browser/browser_thread.h" |
14 #include "gpu/command_buffer/client/context_support.h" | 14 #include "gpu/command_buffer/client/context_support.h" |
15 #include "gpu/command_buffer/client/gles2_interface.h" | 15 #include "gpu/command_buffer/client/gles2_interface.h" |
16 | 16 |
17 namespace content { | 17 namespace content { |
18 | 18 |
19 GpuBrowserCompositorOutputSurface::GpuBrowserCompositorOutputSurface( | 19 GpuBrowserCompositorOutputSurface::GpuBrowserCompositorOutputSurface( |
20 const scoped_refptr<ContextProviderCommandBuffer>& context, | 20 const scoped_refptr<ContextProviderCommandBuffer>& context, |
21 const scoped_refptr<ui::CompositorVSyncManager>& vsync_manager, | 21 const scoped_refptr<ui::CompositorVSyncManager>& vsync_manager, |
22 scoped_ptr<BrowserCompositorOverlayCandidateValidator> | 22 scoped_ptr<BrowserCompositorOverlayCandidateValidator> |
23 overlay_candidate_validator) | 23 overlay_candidate_validator) |
24 : BrowserCompositorOutputSurface(context, | 24 : BrowserCompositorOutputSurface(context, |
25 vsync_manager, | 25 vsync_manager, |
26 overlay_candidate_validator.Pass()), | 26 overlay_candidate_validator.Pass()), |
27 #if defined(OS_MACOSX) | 27 #if defined(OS_MACOSX) |
28 should_not_show_frames_(false), | 28 should_show_frames_state_(SHOULD_SHOW_FRAMES), |
29 #endif | 29 #endif |
30 swap_buffers_completion_callback_( | 30 swap_buffers_completion_callback_( |
31 base::Bind(&GpuBrowserCompositorOutputSurface::OnSwapBuffersCompleted, | 31 base::Bind(&GpuBrowserCompositorOutputSurface::OnSwapBuffersCompleted, |
32 base::Unretained(this))), | 32 base::Unretained(this))), |
33 update_vsync_parameters_callback_(base::Bind( | 33 update_vsync_parameters_callback_(base::Bind( |
34 &BrowserCompositorOutputSurface::OnUpdateVSyncParametersFromGpu, | 34 &BrowserCompositorOutputSurface::OnUpdateVSyncParametersFromGpu, |
35 base::Unretained(this))) { | 35 base::Unretained(this))) { |
36 } | 36 } |
37 | 37 |
38 GpuBrowserCompositorOutputSurface::~GpuBrowserCompositorOutputSurface() {} | 38 GpuBrowserCompositorOutputSurface::~GpuBrowserCompositorOutputSurface() {} |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 gfx::Rect(frame->gl_frame_data->size)) { | 78 gfx::Rect(frame->gl_frame_data->size)) { |
79 context_provider_->ContextSupport()->Swap(); | 79 context_provider_->ContextSupport()->Swap(); |
80 } else { | 80 } else { |
81 context_provider_->ContextSupport()->PartialSwapBuffers( | 81 context_provider_->ContextSupport()->PartialSwapBuffers( |
82 frame->gl_frame_data->sub_buffer_rect); | 82 frame->gl_frame_data->sub_buffer_rect); |
83 } | 83 } |
84 | 84 |
85 client_->DidSwapBuffers(); | 85 client_->DidSwapBuffers(); |
86 | 86 |
87 #if defined(OS_MACOSX) | 87 #if defined(OS_MACOSX) |
88 if (should_not_show_frames_) | 88 if (should_show_frames_state_ == |
89 should_not_show_frames_ = false; | 89 SHOULD_NOT_SHOW_FRAMES_NO_SWAP_AFTER_SUSPENDED) { |
| 90 should_show_frames_state_ = SHOULD_SHOW_FRAMES; |
| 91 } |
90 #endif | 92 #endif |
91 } | 93 } |
92 | 94 |
93 void GpuBrowserCompositorOutputSurface::OnSwapBuffersCompleted( | 95 void GpuBrowserCompositorOutputSurface::OnSwapBuffersCompleted( |
94 const std::vector<ui::LatencyInfo>& latency_info) { | 96 const std::vector<ui::LatencyInfo>& latency_info) { |
95 #if defined(OS_MACOSX) | 97 #if defined(OS_MACOSX) |
96 // On Mac, delay acknowledging the swap to the output surface client until | 98 // On Mac, delay acknowledging the swap to the output surface client until |
97 // it has been drawn, see OnSurfaceDisplayed(); | 99 // it has been drawn, see OnSurfaceDisplayed(); |
98 NOTREACHED(); | 100 NOTREACHED(); |
99 #else | 101 #else |
100 if (BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 102 if (BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
101 RenderWidgetHostImpl::CompositorFrameDrawn(latency_info); | 103 RenderWidgetHostImpl::CompositorFrameDrawn(latency_info); |
102 } else { | 104 } else { |
103 BrowserThread::PostTask( | 105 BrowserThread::PostTask( |
104 BrowserThread::UI, | 106 BrowserThread::UI, |
105 FROM_HERE, | 107 FROM_HERE, |
106 base::Bind(&RenderWidgetHostImpl::CompositorFrameDrawn, latency_info)); | 108 base::Bind(&RenderWidgetHostImpl::CompositorFrameDrawn, latency_info)); |
107 } | 109 } |
108 OnSwapBuffersComplete(); | 110 OnSwapBuffersComplete(); |
109 #endif | 111 #endif |
110 } | 112 } |
111 | 113 |
112 #if defined(OS_MACOSX) | 114 #if defined(OS_MACOSX) |
113 void GpuBrowserCompositorOutputSurface::OnSurfaceDisplayed() { | 115 void GpuBrowserCompositorOutputSurface::OnSurfaceDisplayed() { |
114 cc::OutputSurface::OnSwapBuffersComplete(); | 116 cc::OutputSurface::OnSwapBuffersComplete(); |
115 } | 117 } |
116 | 118 |
117 void GpuBrowserCompositorOutputSurface::OnSurfaceRecycled() { | 119 void GpuBrowserCompositorOutputSurface::SetSurfaceSuspendedForRecycle( |
118 // Discard the backbuffer immediately. This is necessary only when using a | 120 bool suspended) { |
119 // ImageTransportSurfaceFBO with a CALayerStorageProvider. Discarding the | 121 if (suspended) { |
120 // backbuffer results in the next frame using a new CALayer and CAContext, | 122 // It may be that there are frames in-flight from the GPU process back to |
121 // which guarantees that the browser will not flash stale content when adding | 123 // the browser. Make sure that these frames are not displayed by ignoring |
122 // the remote CALayer to the NSView hierarchy (it could flash stale content | 124 // them in GpuProcessHostUIShim, until the browser issues a SwapBuffers for |
123 // because the system window server is not synchronized with any signals we | 125 // the new content. |
124 // control or observe). | 126 should_show_frames_state_ = SHOULD_NOT_SHOW_FRAMES_SUSPENDED; |
125 DiscardBackbuffer(); | 127 } else { |
126 // It may be that there are frames in-flight from the GPU process back to the | 128 // Discard the backbuffer before drawing the new frame. This is necessary |
127 // browser. Make sure that these frames are not displayed by ignoring them in | 129 // only when using a ImageTransportSurfaceFBO with a |
128 // GpuProcessHostUIShim, until the browser issues a SwapBuffers for the new | 130 // CALayerStorageProvider. Discarding the backbuffer results in the next |
129 // content. | 131 // frame using a new CALayer and CAContext, which guarantees that the |
130 should_not_show_frames_ = true; | 132 // browser will not flash stale content when adding the remote CALayer to |
| 133 // the NSView hierarchy (it could flash stale content because the system |
| 134 // window server is not synchronized with any signals we control or |
| 135 // observe). |
| 136 if (should_show_frames_state_ == SHOULD_NOT_SHOW_FRAMES_SUSPENDED) { |
| 137 DiscardBackbuffer(); |
| 138 should_show_frames_state_ = |
| 139 SHOULD_NOT_SHOW_FRAMES_NO_SWAP_AFTER_SUSPENDED; |
| 140 } |
| 141 } |
131 } | 142 } |
132 | 143 |
133 bool GpuBrowserCompositorOutputSurface::ShouldNotShowFramesAfterRecycle() | 144 bool GpuBrowserCompositorOutputSurface:: |
134 const { | 145 SurfaceShouldNotShowFramesAfterSuspendForRecycle() const { |
135 return should_not_show_frames_; | 146 return should_show_frames_state_ != SHOULD_SHOW_FRAMES; |
136 } | 147 } |
137 #endif | 148 #endif |
138 | 149 |
139 } // namespace content | 150 } // namespace content |
OLD | NEW |