Use native radiobutton for Default Search Engine picker dialog.
[chromium-blink-merge.git] / content / browser / compositor / gpu_browser_compositor_output_surface.cc
blob114a84f33b4195425bff6edfa041af21c5e07876
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.
5 #include "content/browser/compositor/gpu_browser_compositor_output_surface.h"
7 #include "cc/output/compositor_frame.h"
8 #include "cc/output/output_surface_client.h"
9 #include "content/browser/compositor/browser_compositor_overlay_candidate_validator.h"
10 #include "content/browser/compositor/reflector_impl.h"
11 #include "content/browser/renderer_host/render_widget_host_impl.h"
12 #include "content/common/gpu/client/context_provider_command_buffer.h"
13 #include "content/public/browser/browser_thread.h"
14 #include "gpu/command_buffer/client/context_support.h"
15 #include "gpu/command_buffer/client/gles2_interface.h"
17 namespace content {
19 GpuBrowserCompositorOutputSurface::GpuBrowserCompositorOutputSurface(
20 const scoped_refptr<ContextProviderCommandBuffer>& context,
21 const scoped_refptr<ui::CompositorVSyncManager>& vsync_manager,
22 scoped_ptr<BrowserCompositorOverlayCandidateValidator>
23 overlay_candidate_validator)
24 : BrowserCompositorOutputSurface(context,
25 vsync_manager,
26 overlay_candidate_validator.Pass()),
27 #if defined(OS_MACOSX)
28 should_show_frames_state_(SHOULD_SHOW_FRAMES),
29 #endif
30 swap_buffers_completion_callback_(
31 base::Bind(&GpuBrowserCompositorOutputSurface::OnSwapBuffersCompleted,
32 base::Unretained(this))),
33 update_vsync_parameters_callback_(base::Bind(
34 &BrowserCompositorOutputSurface::OnUpdateVSyncParametersFromGpu,
35 base::Unretained(this))) {
38 GpuBrowserCompositorOutputSurface::~GpuBrowserCompositorOutputSurface() {}
40 CommandBufferProxyImpl*
41 GpuBrowserCompositorOutputSurface::GetCommandBufferProxy() {
42 ContextProviderCommandBuffer* provider_command_buffer =
43 static_cast<content::ContextProviderCommandBuffer*>(
44 context_provider_.get());
45 CommandBufferProxyImpl* command_buffer_proxy =
46 provider_command_buffer->GetCommandBufferProxy();
47 DCHECK(command_buffer_proxy);
48 return command_buffer_proxy;
51 bool GpuBrowserCompositorOutputSurface::BindToClient(
52 cc::OutputSurfaceClient* client) {
53 if (!BrowserCompositorOutputSurface::BindToClient(client))
54 return false;
56 GetCommandBufferProxy()->SetSwapBuffersCompletionCallback(
57 swap_buffers_completion_callback_.callback());
58 GetCommandBufferProxy()->SetUpdateVSyncParametersCallback(
59 update_vsync_parameters_callback_.callback());
60 return true;
63 void GpuBrowserCompositorOutputSurface::SwapBuffers(
64 cc::CompositorFrame* frame) {
65 DCHECK(frame->gl_frame_data);
67 GetCommandBufferProxy()->SetLatencyInfo(frame->metadata.latency_info);
69 if (reflector_) {
70 if (frame->gl_frame_data->sub_buffer_rect ==
71 gfx::Rect(frame->gl_frame_data->size))
72 reflector_->OnSourceSwapBuffers();
73 else
74 reflector_->OnSourcePostSubBuffer(frame->gl_frame_data->sub_buffer_rect);
77 if (frame->gl_frame_data->sub_buffer_rect ==
78 gfx::Rect(frame->gl_frame_data->size)) {
79 context_provider_->ContextSupport()->Swap();
80 } else {
81 context_provider_->ContextSupport()->PartialSwapBuffers(
82 frame->gl_frame_data->sub_buffer_rect);
85 client_->DidSwapBuffers();
87 #if defined(OS_MACOSX)
88 if (should_show_frames_state_ ==
89 SHOULD_NOT_SHOW_FRAMES_NO_SWAP_AFTER_SUSPENDED) {
90 should_show_frames_state_ = SHOULD_SHOW_FRAMES;
92 #endif
95 void GpuBrowserCompositorOutputSurface::OnSwapBuffersCompleted(
96 const std::vector<ui::LatencyInfo>& latency_info) {
97 #if defined(OS_MACOSX)
98 // On Mac, delay acknowledging the swap to the output surface client until
99 // it has been drawn, see OnSurfaceDisplayed();
100 NOTREACHED();
101 #else
102 RenderWidgetHostImpl::CompositorFrameDrawn(latency_info);
103 OnSwapBuffersComplete();
104 #endif
107 #if defined(OS_MACOSX)
108 void GpuBrowserCompositorOutputSurface::OnSurfaceDisplayed() {
109 cc::OutputSurface::OnSwapBuffersComplete();
112 void GpuBrowserCompositorOutputSurface::SetSurfaceSuspendedForRecycle(
113 bool suspended) {
114 if (suspended) {
115 // It may be that there are frames in-flight from the GPU process back to
116 // the browser. Make sure that these frames are not displayed by ignoring
117 // them in GpuProcessHostUIShim, until the browser issues a SwapBuffers for
118 // the new content.
119 should_show_frames_state_ = SHOULD_NOT_SHOW_FRAMES_SUSPENDED;
120 } else {
121 // Discard the backbuffer before drawing the new frame. This is necessary
122 // only when using a ImageTransportSurfaceFBO with a
123 // CALayerStorageProvider. Discarding the backbuffer results in the next
124 // frame using a new CALayer and CAContext, which guarantees that the
125 // browser will not flash stale content when adding the remote CALayer to
126 // the NSView hierarchy (it could flash stale content because the system
127 // window server is not synchronized with any signals we control or
128 // observe).
129 if (should_show_frames_state_ == SHOULD_NOT_SHOW_FRAMES_SUSPENDED) {
130 DiscardBackbuffer();
131 should_show_frames_state_ =
132 SHOULD_NOT_SHOW_FRAMES_NO_SWAP_AFTER_SUSPENDED;
137 bool GpuBrowserCompositorOutputSurface::
138 SurfaceShouldNotShowFramesAfterSuspendForRecycle() const {
139 return should_show_frames_state_ != SHOULD_SHOW_FRAMES;
141 #endif
143 } // namespace content