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 struct RendererCapabilitiesImpl
{
20 RendererCapabilitiesImpl();
21 ~RendererCapabilitiesImpl();
23 // Capabilities copied to main thread.
24 ResourceFormat best_texture_format
;
25 bool allow_partial_texture_updates
;
27 bool using_shared_memory_resources
;
29 // Capabilities used on compositor thread only.
30 bool using_partial_swap
;
32 bool avoid_pow2_textures
;
34 bool using_discard_framebuffer
;
35 bool allow_rasterize_on_demand
;
37 RendererCapabilities
MainThreadCapabilities() const;
40 class CC_EXPORT RendererClient
{
42 virtual void SetFullRootLayerDamage() = 0;
45 class CC_EXPORT Renderer
{
47 virtual ~Renderer() {}
49 virtual const RendererCapabilitiesImpl
& Capabilities() const = 0;
51 virtual void DecideRenderPassAllocationsForFrame(
52 const RenderPassList
& render_passes_in_draw_order
) {}
53 virtual bool HasAllocatedResourcesForTesting(RenderPass::Id id
) const;
55 // This passes ownership of the render passes to the renderer. It should
56 // consume them, and empty the list. The parameters here may change from frame
57 // to frame and should not be cached.
58 // The |device_viewport_rect| and |device_clip_rect| are in non-y-flipped
60 virtual void DrawFrame(RenderPassList
* render_passes_in_draw_order
,
61 float device_scale_factor
,
62 const gfx::Rect
& device_viewport_rect
,
63 const gfx::Rect
& device_clip_rect
,
64 bool disable_picture_quad_image_filtering
) = 0;
66 // Waits for rendering to finish.
67 virtual void Finish() = 0;
69 virtual void DoNoOp() {}
71 // Puts backbuffer onscreen.
72 virtual void SwapBuffers(const CompositorFrameMetadata
& metadata
) = 0;
73 virtual void ReceiveSwapBuffersAck(const CompositorFrameAck
& ack
) {}
75 virtual bool IsContextLost();
77 bool visible() const { return visible_
; }
78 void SetVisible(bool visible
);
80 virtual void SendManagedMemoryStats(size_t bytes_visible
,
81 size_t bytes_visible_and_nearby
,
82 size_t bytes_allocated
) = 0;
85 explicit Renderer(RendererClient
* client
, const LayerTreeSettings
* settings
)
86 : client_(client
), settings_(settings
), visible_(true) {}
88 virtual void DidChangeVisibility() = 0;
90 RendererClient
* client_
;
91 const LayerTreeSettings
* settings_
;
95 DISALLOW_COPY_AND_ASSIGN(Renderer
);
100 #endif // CC_OUTPUT_RENDERER_H_