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_RENDERER_H_
6 #define CC_OUTPUT_RENDERER_H_
8 #include "base/basictypes.h"
9 #include "cc/base/cc_export.h"
10 #include "cc/quads/render_pass.h"
11 #include "cc/trees/layer_tree_host.h"
15 class CompositorFrameAck
;
16 class CompositorFrameMetadata
;
19 class CC_EXPORT RendererClient
{
21 // These return the draw viewport and clip in non-y-flipped window space.
22 // Note that while a draw is in progress, these are guaranteed to be
23 // contained within the output surface size.
24 virtual gfx::Rect
DeviceViewport() const = 0;
25 virtual gfx::Rect
DeviceClip() const = 0;
26 virtual void SetFullRootLayerDamage() = 0;
27 virtual CompositorFrameMetadata
MakeCompositorFrameMetadata() const = 0;
30 virtual ~RendererClient() {}
33 class CC_EXPORT Renderer
{
35 virtual ~Renderer() {}
37 virtual const RendererCapabilities
& Capabilities() const = 0;
39 virtual void ViewportChanged() {}
41 virtual bool CanReadPixels() const = 0;
43 virtual void DecideRenderPassAllocationsForFrame(
44 const RenderPassList
& render_passes_in_draw_order
) {}
45 virtual bool HaveCachedResourcesForRenderPassId(RenderPass::Id id
) const;
47 // This passes ownership of the render passes to the renderer. It should
48 // consume them, and empty the list. The parameters here may change from frame
49 // to frame and should not be cached.
50 virtual void DrawFrame(RenderPassList
* render_passes_in_draw_order
,
51 ContextProvider
* offscreen_context_provider
,
52 float device_scale_factor
,
53 bool allow_partial_swap
) = 0;
55 // Waits for rendering to finish.
56 virtual void Finish() = 0;
58 virtual void DoNoOp() {}
60 // Puts backbuffer onscreen.
61 virtual void SwapBuffers() = 0;
62 virtual void ReceiveSwapBuffersAck(const CompositorFrameAck
& ack
) {}
64 virtual void GetFramebufferPixels(void* pixels
, gfx::Rect rect
) = 0;
66 virtual bool IsContextLost();
68 virtual void SetVisible(bool visible
) = 0;
70 virtual void SendManagedMemoryStats(size_t bytes_visible
,
71 size_t bytes_visible_and_nearby
,
72 size_t bytes_allocated
) = 0;
74 virtual void SetDiscardBackBufferWhenNotVisible(bool discard
) = 0;
77 explicit Renderer(RendererClient
* client
, const LayerTreeSettings
* settings
)
78 : client_(client
), settings_(settings
) {}
80 RendererClient
* client_
;
81 const LayerTreeSettings
* settings_
;
84 DISALLOW_COPY_AND_ASSIGN(Renderer
);
89 #endif // CC_OUTPUT_RENDERER_H_