1 // Copyright 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 CC_OUTPUT_OUTPUT_SURFACE_H_
6 #define CC_OUTPUT_OUTPUT_SURFACE_H_
8 #include "base/basictypes.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "cc/base/cc_export.h"
11 #include "cc/output/software_output_device.h"
12 #include "third_party/WebKit/Source/Platform/chromium/public/WebGraphicsContext3D.h"
21 class CompositorFrame
;
22 class OutputSurfaceClient
;
23 class OutputSurfaceCallbacks
;
26 // Represents the output surface for a compositor. The compositor owns
27 // and manages its destruction. Its lifetime is:
28 // 1. Created on the main thread by the LayerTreeHost through its client.
29 // 2. Passed to the compositor thread and bound to a client via BindToClient.
30 // From here on, it will only be used on the compositor thread.
31 // 3. If the 3D context is lost, then the compositor will delete the output
32 // surface (on the compositor thread) and go back to step 1.
33 class CC_EXPORT OutputSurface
{
35 explicit OutputSurface(scoped_ptr
<WebKit::WebGraphicsContext3D
> context3d
);
37 explicit OutputSurface(scoped_ptr
<cc::SoftwareOutputDevice
> software_device
);
39 OutputSurface(scoped_ptr
<WebKit::WebGraphicsContext3D
> context3d
,
40 scoped_ptr
<cc::SoftwareOutputDevice
> software_device
);
42 virtual ~OutputSurface();
46 : has_parent_compositor(false),
47 max_frames_pending(0) {}
49 bool has_parent_compositor
;
50 int max_frames_pending
;
53 const Capabilities
& capabilities() const {
57 // Obtain the 3d context or the software device associated with this output
58 // surface. Either of these may return a null pointer, but not both.
59 // In the event of a lost context, the entire output surface should be
61 WebKit::WebGraphicsContext3D
* context3d() const {
62 return context3d_
.get();
65 SoftwareOutputDevice
* software_device() const {
66 return software_device_
.get();
69 // Called by the compositor on the compositor thread. This is a place where
70 // thread-specific data for the output surface can be initialized, since from
71 // this point on the output surface will only be used on the compositor
73 virtual bool BindToClient(OutputSurfaceClient
* client
);
75 // Sends frame data to the parent compositor. This should only be called when
76 // capabilities().has_parent_compositor. The implementation may destroy or
77 // steal the contents of the CompositorFrame passed in.
78 virtual void SendFrameToParentCompositor(CompositorFrame
* frame
);
80 virtual void EnsureBackbuffer();
81 virtual void DiscardBackbuffer();
83 virtual void Reshape(gfx::Size size
);
85 virtual void BindFramebuffer();
87 virtual void PostSubBuffer(gfx::Rect rect
, const LatencyInfo
&);
88 virtual void SwapBuffers(const LatencyInfo
&);
90 // Notifies frame-rate smoothness preference. If true, all non-critical
91 // processing should be stopped, or lowered in priority.
92 virtual void UpdateSmoothnessTakesPriority(bool prefer_smoothness
) {}
94 // Requests a vsync notification from the output surface. The notification
95 // will be delivered by calling OutputSurfaceClient::DidVSync for all future
96 // vsync events until the callback is disabled.
97 virtual void EnableVSyncNotification(bool enable_vsync
) {}
100 OutputSurfaceClient
* client_
;
101 struct cc::OutputSurface::Capabilities capabilities_
;
102 scoped_ptr
<WebKit::WebGraphicsContext3D
> context3d_
;
103 scoped_ptr
<cc::SoftwareOutputDevice
> software_device_
;
104 bool has_gl_discard_backbuffer_
;
106 scoped_ptr
<OutputSurfaceCallbacks
> callbacks_
;
109 DISALLOW_COPY_AND_ASSIGN(OutputSurface
);
114 #endif // CC_OUTPUT_OUTPUT_SURFACE_H_