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