Apply _RELATIVE relocations ahead of others.
[chromium-blink-merge.git] / content / browser / compositor / gpu_browser_compositor_output_surface.cc
blobe68c5c8fd20aef7f8d08f38bce7f0ec20f807927
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/reflector_impl.h"
10 #include "content/browser/renderer_host/render_widget_host_impl.h"
11 #include "content/common/gpu/client/context_provider_command_buffer.h"
12 #include "content/public/browser/browser_thread.h"
13 #include "gpu/command_buffer/client/context_support.h"
14 #include "gpu/command_buffer/client/gles2_interface.h"
16 namespace content {
18 GpuBrowserCompositorOutputSurface::GpuBrowserCompositorOutputSurface(
19 const scoped_refptr<ContextProviderCommandBuffer>& context,
20 int surface_id,
21 IDMap<BrowserCompositorOutputSurface>* output_surface_map,
22 const scoped_refptr<ui::CompositorVSyncManager>& vsync_manager,
23 scoped_ptr<cc::OverlayCandidateValidator> overlay_candidate_validator)
24 : BrowserCompositorOutputSurface(context,
25 surface_id,
26 output_surface_map,
27 vsync_manager),
28 swap_buffers_completion_callback_(
29 base::Bind(&GpuBrowserCompositorOutputSurface::OnSwapBuffersCompleted,
30 base::Unretained(this))) {
31 overlay_candidate_validator_ = overlay_candidate_validator.Pass();
34 GpuBrowserCompositorOutputSurface::~GpuBrowserCompositorOutputSurface() {}
36 CommandBufferProxyImpl*
37 GpuBrowserCompositorOutputSurface::GetCommandBufferProxy() {
38 ContextProviderCommandBuffer* provider_command_buffer =
39 static_cast<content::ContextProviderCommandBuffer*>(
40 context_provider_.get());
41 CommandBufferProxyImpl* command_buffer_proxy =
42 provider_command_buffer->GetCommandBufferProxy();
43 DCHECK(command_buffer_proxy);
44 return command_buffer_proxy;
47 bool GpuBrowserCompositorOutputSurface::BindToClient(
48 cc::OutputSurfaceClient* client) {
49 if (!BrowserCompositorOutputSurface::BindToClient(client))
50 return false;
52 GetCommandBufferProxy()->SetSwapBuffersCompletionCallback(
53 swap_buffers_completion_callback_.callback());
54 return true;
57 void GpuBrowserCompositorOutputSurface::SwapBuffers(
58 cc::CompositorFrame* frame) {
59 DCHECK(frame->gl_frame_data);
61 GetCommandBufferProxy()->SetLatencyInfo(frame->metadata.latency_info);
63 if (reflector_.get()) {
64 if (frame->gl_frame_data->sub_buffer_rect ==
65 gfx::Rect(frame->gl_frame_data->size))
66 reflector_->OnSwapBuffers();
67 else
68 reflector_->OnPostSubBuffer(frame->gl_frame_data->sub_buffer_rect);
71 if (frame->gl_frame_data->sub_buffer_rect ==
72 gfx::Rect(frame->gl_frame_data->size)) {
73 context_provider_->ContextSupport()->Swap();
74 } else {
75 context_provider_->ContextSupport()->PartialSwapBuffers(
76 frame->gl_frame_data->sub_buffer_rect);
79 client_->DidSwapBuffers();
82 void GpuBrowserCompositorOutputSurface::OnSwapBuffersCompleted(
83 const std::vector<ui::LatencyInfo>& latency_info) {
84 #if defined(OS_MACOSX)
85 // On Mac, delay acknowledging the swap to the output surface client until
86 // it has been drawn, see OnSurfaceDisplayed();
87 NOTREACHED();
88 #else
89 if (BrowserThread::CurrentlyOn(BrowserThread::UI)) {
90 RenderWidgetHostImpl::CompositorFrameDrawn(latency_info);
91 } else {
92 BrowserThread::PostTask(
93 BrowserThread::UI,
94 FROM_HERE,
95 base::Bind(&RenderWidgetHostImpl::CompositorFrameDrawn, latency_info));
97 OnSwapBuffersComplete();
98 #endif
101 #if defined(OS_MACOSX)
102 void GpuBrowserCompositorOutputSurface::OnSurfaceDisplayed() {
103 cc::OutputSurface::OnSwapBuffersComplete();
105 #endif
107 } // namespace content