1 // Copyright (c) 2012 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_RENDERER_GPU_COMPOSITOR_OUTPUT_SURFACE_H_
6 #define CONTENT_RENDERER_GPU_COMPOSITOR_OUTPUT_SURFACE_H_
8 #include "base/basictypes.h"
9 #include "base/compiler_specific.h"
10 #include "base/memory/ref_counted.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/threading/non_thread_safe.h"
13 #include "base/threading/platform_thread.h"
14 #include "base/time/time.h"
15 #include "cc/output/begin_frame_args.h"
16 #include "cc/output/output_surface.h"
17 #include "ipc/ipc_sync_message_filter.h"
24 class ForwardingMessageFilter
;
29 class CompositorFrame
;
30 class CompositorFrameAck
;
34 class ContextProviderCommandBuffer
;
36 // This class can be created only on the main thread, but then becomes pinned
37 // to a fixed thread when bindToClient is called.
38 class CompositorOutputSurface
39 : NON_EXPORTED_BASE(public cc::OutputSurface
),
40 NON_EXPORTED_BASE(public base::NonThreadSafe
) {
42 static IPC::ForwardingMessageFilter
* CreateFilter(
43 base::TaskRunner
* target_task_runner
);
45 CompositorOutputSurface(
47 uint32 output_surface_id
,
48 const scoped_refptr
<ContextProviderCommandBuffer
>& context_provider
,
49 scoped_ptr
<cc::SoftwareOutputDevice
> software
,
50 bool use_swap_compositor_frame_message
);
51 virtual ~CompositorOutputSurface();
53 // cc::OutputSurface implementation.
54 virtual bool BindToClient(cc::OutputSurfaceClient
* client
) OVERRIDE
;
55 virtual void SwapBuffers(cc::CompositorFrame
* frame
) OVERRIDE
;
56 #if defined(OS_ANDROID)
57 virtual void SetNeedsBeginImplFrame(bool enable
) OVERRIDE
;
60 // TODO(epenner): This seems out of place here and would be a better fit
61 // int CompositorThread after it is fully refactored (http://crbug/170828)
62 virtual void UpdateSmoothnessTakesPriority(bool prefer_smoothness
) OVERRIDE
;
65 virtual void OnSwapAck(uint32 output_surface_id
,
66 const cc::CompositorFrameAck
& ack
);
67 virtual void OnReclaimResources(uint32 output_surface_id
,
68 const cc::CompositorFrameAck
& ack
);
69 uint32 output_surface_id_
;
72 class CompositorOutputSurfaceProxy
:
73 public base::RefCountedThreadSafe
<CompositorOutputSurfaceProxy
> {
75 explicit CompositorOutputSurfaceProxy(
76 CompositorOutputSurface
* output_surface
)
77 : output_surface_(output_surface
) {}
78 void ClearOutputSurface() { output_surface_
= NULL
; }
79 void OnMessageReceived(const IPC::Message
& message
) {
81 output_surface_
->OnMessageReceived(message
);
85 friend class base::RefCountedThreadSafe
<CompositorOutputSurfaceProxy
>;
86 ~CompositorOutputSurfaceProxy() {}
87 CompositorOutputSurface
* output_surface_
;
89 DISALLOW_COPY_AND_ASSIGN(CompositorOutputSurfaceProxy
);
92 void OnMessageReceived(const IPC::Message
& message
);
93 void OnUpdateVSyncParameters(
94 base::TimeTicks timebase
, base::TimeDelta interval
);
95 #if defined(OS_ANDROID)
96 void OnBeginImplFrame(const cc::BeginFrameArgs
& args
);
98 bool Send(IPC::Message
* message
);
100 bool use_swap_compositor_frame_message_
;
102 scoped_refptr
<IPC::ForwardingMessageFilter
> output_surface_filter_
;
103 scoped_refptr
<CompositorOutputSurfaceProxy
> output_surface_proxy_
;
104 scoped_refptr
<IPC::SyncMessageFilter
> message_sender_
;
106 bool prefers_smoothness_
;
107 base::PlatformThreadHandle main_thread_handle_
;
110 } // namespace content
112 #endif // CONTENT_RENDERER_GPU_COMPOSITOR_OUTPUT_SURFACE_H_