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.h"
15 #include "cc/output/output_surface.h"
16 #include "ipc/ipc_sync_message_filter.h"
23 class ForwardingMessageFilter
;
28 class CompositorFrame
;
29 class CompositorFrameAck
;
34 class WebGraphicsContext3DCommandBufferImpl
;
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(int32 routing_id
,
46 WebGraphicsContext3DCommandBufferImpl
* context3d
,
47 cc::SoftwareOutputDevice
* software
);
48 virtual ~CompositorOutputSurface();
50 // cc::OutputSurface implementation.
51 virtual bool BindToClient(cc::OutputSurfaceClient
* client
) OVERRIDE
;
52 virtual void SendFrameToParentCompositor(cc::CompositorFrame
*) OVERRIDE
;
53 virtual void PostSubBuffer(gfx::Rect rect
, const cc::LatencyInfo
&) OVERRIDE
;
54 virtual void SwapBuffers(const cc::LatencyInfo
&) OVERRIDE
;
55 #if defined(OS_ANDROID)
56 virtual void SetNeedsBeginFrame(bool enable
) OVERRIDE
;
59 // TODO(epenner): This seems out of place here and would be a better fit
60 // int CompositorThread after it is fully refactored (http://crbug/170828)
61 virtual void UpdateSmoothnessTakesPriority(bool prefer_smoothness
) OVERRIDE
;
64 virtual void OnSwapAck(const cc::CompositorFrameAck
& ack
);
67 class CompositorOutputSurfaceProxy
:
68 public base::RefCountedThreadSafe
<CompositorOutputSurfaceProxy
> {
70 explicit CompositorOutputSurfaceProxy(
71 CompositorOutputSurface
* output_surface
)
72 : output_surface_(output_surface
) {}
73 void ClearOutputSurface() { output_surface_
= NULL
; }
74 void OnMessageReceived(const IPC::Message
& message
) {
76 output_surface_
->OnMessageReceived(message
);
80 friend class base::RefCountedThreadSafe
<CompositorOutputSurfaceProxy
>;
81 ~CompositorOutputSurfaceProxy() {}
82 CompositorOutputSurface
* output_surface_
;
84 DISALLOW_COPY_AND_ASSIGN(CompositorOutputSurfaceProxy
);
87 void OnMessageReceived(const IPC::Message
& message
);
88 void OnUpdateVSyncParameters(
89 base::TimeTicks timebase
, base::TimeDelta interval
);
90 #if defined(OS_ANDROID)
91 void OnBeginFrame(base::TimeTicks frame_time
);
93 bool Send(IPC::Message
* message
);
95 scoped_refptr
<IPC::ForwardingMessageFilter
> output_surface_filter_
;
96 scoped_refptr
<CompositorOutputSurfaceProxy
> output_surface_proxy_
;
97 scoped_refptr
<IPC::SyncMessageFilter
> message_sender_
;
99 bool prefers_smoothness_
;
100 base::PlatformThreadId main_thread_id_
;
103 } // namespace content
105 #endif // CONTENT_RENDERER_GPU_COMPOSITOR_OUTPUT_SURFACE_H_