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
;
25 // Represents the output surface for a compositor. The compositor owns
26 // and manages its destruction. Its lifetime is:
27 // 1. Created on the main thread by the LayerTreeHost through its client.
28 // 2. Passed to the compositor thread and bound to a client via BindToClient.
29 // From here on, it will only be used on the compositor thread.
30 // 3. If the 3D context is lost, then the compositor will delete the output
31 // surface (on the compositor thread) and go back to step 1.
32 class CC_EXPORT OutputSurface
{
34 explicit OutputSurface(scoped_ptr
<WebKit::WebGraphicsContext3D
> context3d
);
36 explicit OutputSurface(scoped_ptr
<cc::SoftwareOutputDevice
> software_device
);
38 OutputSurface(scoped_ptr
<WebKit::WebGraphicsContext3D
> context3d
,
39 scoped_ptr
<cc::SoftwareOutputDevice
> software_device
);
41 virtual ~OutputSurface();
45 : has_parent_compositor(false),
46 max_frames_pending(0) {}
48 bool has_parent_compositor
;
49 int max_frames_pending
;
52 const Capabilities
& capabilities() const {
56 // Obtain the 3d context or the software device associated with this output
57 // surface. Either of these may return a null pointer, but not both.
58 // In the event of a lost context, the entire output surface should be
60 WebKit::WebGraphicsContext3D
* context3d() const {
61 return context3d_
.get();
64 SoftwareOutputDevice
* software_device() const {
65 return software_device_
.get();
68 // Called by the compositor on the compositor thread. This is a place where
69 // thread-specific data for the output surface can be initialized, since from
70 // this point on the output surface will only be used on the compositor
72 virtual bool BindToClient(OutputSurfaceClient
* client
);
74 // Sends frame data to the parent compositor. This should only be called when
75 // capabilities().has_parent_compositor. The implementation may destroy or
76 // steal the contents of the CompositorFrame passed in.
77 virtual void SendFrameToParentCompositor(CompositorFrame
* frame
);
79 virtual void EnsureBackbuffer();
80 virtual void DiscardBackbuffer();
82 virtual void Reshape(gfx::Size size
);
84 virtual void BindFramebuffer();
86 virtual void PostSubBuffer(gfx::Rect rect
, const LatencyInfo
&);
87 virtual void SwapBuffers(const LatencyInfo
&);
89 // Notifies frame-rate smoothness preference. If true, all non-critical
90 // processing should be stopped, or lowered in priority.
91 virtual void UpdateSmoothnessTakesPriority(bool prefer_smoothness
) {}
93 // Requests a vsync notification from the output surface. The notification
94 // will be delivered by calling OutputSurfaceClient::DidVSync for all future
95 // vsync events until the callback is disabled.
96 virtual void EnableVSyncNotification(bool enable_vsync
) {}
99 OutputSurfaceClient
* client_
;
100 struct cc::OutputSurface::Capabilities capabilities_
;
101 scoped_ptr
<WebKit::WebGraphicsContext3D
> context3d_
;
102 scoped_ptr
<cc::SoftwareOutputDevice
> software_device_
;
103 bool has_gl_discard_backbuffer_
;
106 DISALLOW_COPY_AND_ASSIGN(OutputSurface
);
111 #endif // CC_OUTPUT_OUTPUT_SURFACE_H_