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 #ifndef CONTENT_BROWSER_COMPOSITOR_GPU_BROWSER_COMPOSITOR_OUTPUT_SURFACE_H_
6 #define CONTENT_BROWSER_COMPOSITOR_GPU_BROWSER_COMPOSITOR_OUTPUT_SURFACE_H_
8 #include "base/cancelable_callback.h"
9 #include "content/browser/compositor/browser_compositor_output_surface.h"
10 #include "ui/gfx/swap_result.h"
13 class CompositorVSyncManager
;
17 class CommandBufferProxyImpl
;
18 class BrowserCompositorOverlayCandidateValidator
;
19 class ReflectorTexture
;
21 // Adapts a WebGraphicsContext3DCommandBufferImpl into a
22 // cc::OutputSurface that also handles vsync parameter updates
23 // arriving from the GPU process.
24 class GpuBrowserCompositorOutputSurface
25 : public BrowserCompositorOutputSurface
{
27 GpuBrowserCompositorOutputSurface(
28 const scoped_refptr
<ContextProviderCommandBuffer
>& context
,
29 const scoped_refptr
<ContextProviderCommandBuffer
>& worker_context
,
30 const scoped_refptr
<ui::CompositorVSyncManager
>& vsync_manager
,
31 scoped_ptr
<BrowserCompositorOverlayCandidateValidator
>
32 overlay_candidate_validator
);
34 ~GpuBrowserCompositorOutputSurface() override
;
37 // BrowserCompositorOutputSurface:
38 void OnReflectorChanged() override
;
40 // cc::OutputSurface implementation.
41 void SwapBuffers(cc::CompositorFrame
* frame
) override
;
42 bool BindToClient(cc::OutputSurfaceClient
* client
) override
;
43 bool SurfaceIsSuspendForRecycle() const override
;
45 #if defined(OS_MACOSX)
46 void OnSurfaceDisplayed() override
;
47 void SetSurfaceSuspendedForRecycle(bool suspended
) override
;
48 bool SurfaceShouldNotShowFramesAfterSuspendForRecycle() const override
;
49 enum ShouldShowFramesState
{
50 // Frames that come from the GPU process should appear on-screen.
52 // The compositor has been suspended. Any frames that come from the GPU
53 // process are for the pre-suspend content and should not be displayed.
54 SHOULD_NOT_SHOW_FRAMES_SUSPENDED
,
55 // The compositor has been un-suspended, but has not yet issued a swap
56 // since being un-suspended, so any frames that come from the GPU process
57 // are for pre-suspend content and should not be displayed.
58 SHOULD_NOT_SHOW_FRAMES_NO_SWAP_AFTER_SUSPENDED
,
60 ShouldShowFramesState should_show_frames_state_
;
63 CommandBufferProxyImpl
* GetCommandBufferProxy();
64 virtual void OnSwapBuffersCompleted(
65 const std::vector
<ui::LatencyInfo
>& latency_info
,
66 gfx::SwapResult result
);
68 base::CancelableCallback
<void(const std::vector
<ui::LatencyInfo
>&,
70 swap_buffers_completion_callback_
;
71 base::CancelableCallback
<void(base::TimeTicks timebase
,
72 base::TimeDelta interval
)>
73 update_vsync_parameters_callback_
;
75 scoped_ptr
<ReflectorTexture
> reflector_texture_
;
77 DISALLOW_COPY_AND_ASSIGN(GpuBrowserCompositorOutputSurface
);
80 } // namespace content
82 #endif // CONTENT_BROWSER_COMPOSITOR_GPU_BROWSER_COMPOSITOR_OUTPUT_SURFACE_H_