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_surfaceless_browser_compositor_output_surface.h"
7 #include "cc/output/compositor_frame.h"
8 #include "content/browser/compositor/browser_compositor_overlay_candidate_validator.h"
9 #include "content/browser/compositor/buffer_queue.h"
10 #include "content/browser/compositor/reflector_impl.h"
11 #include "content/browser/gpu/gpu_surface_tracker.h"
12 #include "content/common/gpu/client/context_provider_command_buffer.h"
13 #include "content/common/gpu/client/gl_helper.h"
14 #include "gpu/GLES2/gl2extchromium.h"
15 #include "gpu/command_buffer/client/gles2_interface.h"
19 GpuSurfacelessBrowserCompositorOutputSurface::
20 GpuSurfacelessBrowserCompositorOutputSurface(
21 const scoped_refptr
<ContextProviderCommandBuffer
>& context
,
22 const scoped_refptr
<ContextProviderCommandBuffer
>& worker_context
,
24 const scoped_refptr
<ui::CompositorVSyncManager
>& vsync_manager
,
25 scoped_ptr
<BrowserCompositorOverlayCandidateValidator
>
26 overlay_candidate_validator
,
28 unsigned int internalformat
,
29 BrowserGpuMemoryBufferManager
* gpu_memory_buffer_manager
)
30 : GpuBrowserCompositorOutputSurface(context
,
33 overlay_candidate_validator
.Pass()),
34 internalformat_(internalformat
),
35 gpu_memory_buffer_manager_(gpu_memory_buffer_manager
) {
36 capabilities_
.uses_default_gl_framebuffer
= false;
37 capabilities_
.flipped_output_surface
= true;
38 // Set |max_frames_pending| to 2 for surfaceless, which aligns scheduling
39 // more closely with the previous surfaced behavior.
40 // With a surface, swap buffer ack used to return early, before actually
41 // presenting the back buffer, enabling the browser compositor to run ahead.
42 // Surfaceless implementation acks at the time of actual buffer swap, which
43 // shifts the start of the new frame forward relative to the old
45 capabilities_
.max_frames_pending
= 2;
47 gl_helper_
.reset(new GLHelper(context_provider_
->ContextGL(),
48 context_provider_
->ContextSupport()));
49 output_surface_
.reset(new BufferQueue(
50 context_provider_
, target
, internalformat_
, gl_helper_
.get(),
51 gpu_memory_buffer_manager_
, surface_id
));
52 output_surface_
->Initialize();
55 GpuSurfacelessBrowserCompositorOutputSurface::
56 ~GpuSurfacelessBrowserCompositorOutputSurface() {
59 unsigned GpuSurfacelessBrowserCompositorOutputSurface::GetOverlayTextureId()
61 return output_surface_
->current_texture_id();
64 void GpuSurfacelessBrowserCompositorOutputSurface::SwapBuffers(
65 cc::CompositorFrame
* frame
) {
66 DCHECK(output_surface_
);
68 GLuint texture
= output_surface_
->current_texture_id();
69 output_surface_
->SwapBuffers(frame
->gl_frame_data
->sub_buffer_rect
);
70 const gfx::Size
& size
= frame
->gl_frame_data
->size
;
71 context_provider_
->ContextGL()->ScheduleOverlayPlaneCHROMIUM(
73 GL_OVERLAY_TRANSFORM_NONE_CHROMIUM
,
83 GpuBrowserCompositorOutputSurface::SwapBuffers(frame
);
86 void GpuSurfacelessBrowserCompositorOutputSurface::OnSwapBuffersComplete() {
87 DCHECK(output_surface_
);
88 output_surface_
->PageFlipComplete();
89 GpuBrowserCompositorOutputSurface::OnSwapBuffersComplete();
92 void GpuSurfacelessBrowserCompositorOutputSurface::BindFramebuffer() {
93 DCHECK(output_surface_
);
94 output_surface_
->BindFramebuffer();
97 void GpuSurfacelessBrowserCompositorOutputSurface::Reshape(
98 const gfx::Size
& size
,
100 GpuBrowserCompositorOutputSurface::Reshape(size
, scale_factor
);
101 DCHECK(output_surface_
);
102 output_surface_
->Reshape(SurfaceSize(), scale_factor
);
105 void GpuSurfacelessBrowserCompositorOutputSurface::OnSwapBuffersCompleted(
106 const std::vector
<ui::LatencyInfo
>& latency_info
,
107 gfx::SwapResult result
) {
108 #if defined(OS_MACOSX)
111 if (result
== gfx::SwapResult::SWAP_NAK_RECREATE_BUFFERS
) {
112 // Even through the swap failed, this is a fixable error so we can pretend
113 // it succeeded to the rest of the system.
114 result
= gfx::SwapResult::SWAP_ACK
;
115 output_surface_
->RecreateBuffers();
117 GpuBrowserCompositorOutputSurface::OnSwapBuffersCompleted(latency_info
,
122 #if defined(OS_MACOSX)
123 void GpuSurfacelessBrowserCompositorOutputSurface::OnSurfaceDisplayed() {
124 OnSwapBuffersComplete();
128 } // namespace content