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/buffer_queue.h"
9 #include "content/browser/compositor/reflector_impl.h"
10 #include "content/browser/gpu/gpu_surface_tracker.h"
11 #include "content/common/gpu/client/context_provider_command_buffer.h"
12 #include "content/common/gpu/client/gl_helper.h"
13 #include "gpu/GLES2/gl2extchromium.h"
14 #include "gpu/command_buffer/client/gles2_interface.h"
18 GpuSurfacelessBrowserCompositorOutputSurface::
19 GpuSurfacelessBrowserCompositorOutputSurface(
20 const scoped_refptr
<ContextProviderCommandBuffer
>& context
,
22 const scoped_refptr
<ui::CompositorVSyncManager
>& vsync_manager
,
23 scoped_ptr
<cc::OverlayCandidateValidator
> overlay_candidate_validator
,
24 unsigned internalformat
,
25 BrowserGpuMemoryBufferManager
* gpu_memory_buffer_manager
)
26 : GpuBrowserCompositorOutputSurface(context
,
28 overlay_candidate_validator
.Pass()),
29 internalformat_(internalformat
),
30 gpu_memory_buffer_manager_(gpu_memory_buffer_manager
) {
31 capabilities_
.uses_default_gl_framebuffer
= false;
32 capabilities_
.flipped_output_surface
= true;
33 // Set |max_frames_pending| to 2 for surfaceless, which aligns scheduling
34 // more closely with the previous surfaced behavior.
35 // With a surface, swap buffer ack used to return early, before actually
36 // presenting the back buffer, enabling the browser compositor to run ahead.
37 // Surfaceless implementation acks at the time of actual buffer swap, which
38 // shifts the start of the new frame forward relative to the old
40 capabilities_
.max_frames_pending
= 2;
42 gl_helper_
.reset(new GLHelper(context_provider_
->ContextGL(),
43 context_provider_
->ContextSupport()));
44 output_surface_
.reset(
45 new BufferQueue(context_provider_
, internalformat_
, gl_helper_
.get(),
46 gpu_memory_buffer_manager_
, surface_id
));
47 output_surface_
->Initialize();
50 GpuSurfacelessBrowserCompositorOutputSurface::
51 ~GpuSurfacelessBrowserCompositorOutputSurface() {
54 void GpuSurfacelessBrowserCompositorOutputSurface::SwapBuffers(
55 cc::CompositorFrame
* frame
) {
56 DCHECK(output_surface_
);
58 GLuint texture
= output_surface_
->current_texture_id();
59 output_surface_
->SwapBuffers(frame
->gl_frame_data
->sub_buffer_rect
);
60 const gfx::Size
& size
= frame
->gl_frame_data
->size
;
61 context_provider_
->ContextGL()->ScheduleOverlayPlaneCHROMIUM(
63 GL_OVERLAY_TRANSFORM_NONE_CHROMIUM
,
73 GpuBrowserCompositorOutputSurface::SwapBuffers(frame
);
76 void GpuSurfacelessBrowserCompositorOutputSurface::OnSwapBuffersComplete() {
77 DCHECK(output_surface_
);
78 output_surface_
->PageFlipComplete();
79 GpuBrowserCompositorOutputSurface::OnSwapBuffersComplete();
82 void GpuSurfacelessBrowserCompositorOutputSurface::BindFramebuffer() {
83 DCHECK(output_surface_
);
84 output_surface_
->BindFramebuffer();
87 void GpuSurfacelessBrowserCompositorOutputSurface::Reshape(
88 const gfx::Size
& size
,
90 GpuBrowserCompositorOutputSurface::Reshape(size
, scale_factor
);
91 DCHECK(output_surface_
);
92 output_surface_
->Reshape(SurfaceSize(), scale_factor
);
95 } // namespace content