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 // Draw viewport in non-y-flipped window space. Note that while a draw is in
22 // progress, this is guaranteed to be contained within the output surface
24 virtual gfx::Rect
DeviceViewport() const = 0;
26 virtual float DeviceScaleFactor() const = 0;
27 virtual const LayerTreeSettings
& Settings() const = 0;
28 virtual void SetFullRootLayerDamage() = 0;
29 virtual bool HasImplThread() const = 0;
30 virtual bool ShouldClearRootRenderPass() const = 0;
31 virtual CompositorFrameMetadata
MakeCompositorFrameMetadata() const = 0;
32 virtual bool AllowPartialSwap() const = 0;
33 virtual bool ExternalStencilTestEnabled() const = 0;
36 virtual ~RendererClient() {}
39 class CC_EXPORT Renderer
{
41 virtual ~Renderer() {}
43 virtual const RendererCapabilities
& Capabilities() const = 0;
45 const LayerTreeSettings
& Settings() const { return client_
->Settings(); }
47 virtual void ViewportChanged() {}
49 virtual bool CanReadPixels() const = 0;
51 virtual void DecideRenderPassAllocationsForFrame(
52 const RenderPassList
& render_passes_in_draw_order
) {}
53 virtual bool HaveCachedResourcesForRenderPassId(RenderPass::Id id
) const;
55 // This passes ownership of the render passes to the renderer. It should
56 // consume them, and empty the list.
57 virtual void DrawFrame(RenderPassList
* render_passes_in_draw_order
) = 0;
59 // Waits for rendering to finish.
60 virtual void Finish() = 0;
62 virtual void DoNoOp() {}
64 // Puts backbuffer onscreen.
65 virtual void SwapBuffers() = 0;
66 virtual void ReceiveSwapBuffersAck(const CompositorFrameAck
& ack
) {}
68 virtual void GetFramebufferPixels(void* pixels
, gfx::Rect rect
) = 0;
70 virtual bool IsContextLost();
72 virtual void SetVisible(bool visible
) = 0;
74 virtual void SendManagedMemoryStats(size_t bytes_visible
,
75 size_t bytes_visible_and_nearby
,
76 size_t bytes_allocated
) = 0;
78 virtual void SetDiscardBackBufferWhenNotVisible(bool discard
) = 0;
81 explicit Renderer(RendererClient
* client
)
84 RendererClient
* client_
;
87 DISALLOW_COPY_AND_ASSIGN(Renderer
);
92 #endif // CC_OUTPUT_RENDERER_H_