renderer.h revision c2e0dbddbe15c98d52c4786dac06cb8952a8ae6d
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.
4
5#ifndef CC_OUTPUT_RENDERER_H_
6#define CC_OUTPUT_RENDERER_H_
7
8#include "base/basictypes.h"
9#include "cc/base/cc_export.h"
10#include "cc/debug/latency_info.h"
11#include "cc/quads/render_pass.h"
12#include "cc/resources/managed_memory_policy.h"
13#include "cc/trees/layer_tree_host.h"
14
15namespace cc {
16
17class CompositorFrameAck;
18class CompositorFrameMetadata;
19class ScopedResource;
20
21class CC_EXPORT RendererClient {
22 public:
23  virtual gfx::Size DeviceViewportSize() const = 0;
24  virtual const LayerTreeSettings& Settings() const = 0;
25  virtual void SetFullRootLayerDamage() = 0;
26  virtual void SetManagedMemoryPolicy(const ManagedMemoryPolicy& policy) = 0;
27  virtual void EnforceManagedMemoryPolicy(
28      const ManagedMemoryPolicy& policy) = 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
34 protected:
35  virtual ~RendererClient() {}
36};
37
38class CC_EXPORT Renderer {
39 public:
40  virtual ~Renderer() {}
41
42  virtual const RendererCapabilities& Capabilities() const = 0;
43
44  const LayerTreeSettings& Settings() const { return client_->Settings(); }
45
46  gfx::Size ViewportSize() const { return client_->DeviceViewportSize(); }
47  int ViewportWidth() const { return ViewportSize().width(); }
48  int ViewportHeight() const { return ViewportSize().height(); }
49
50  virtual void ViewportChanged() {}
51  virtual void ReceiveCompositorFrameAck(const CompositorFrameAck& ack) {}
52
53  virtual void DecideRenderPassAllocationsForFrame(
54      const RenderPassList& render_passes_in_draw_order) {}
55  virtual bool HaveCachedResourcesForRenderPassId(RenderPass::Id id) const;
56
57  // This passes ownership of the render passes to the renderer. It should
58  // consume them, and empty the list.
59  virtual void DrawFrame(RenderPassList* render_passes_in_draw_order) = 0;
60
61  // Waits for rendering to finish.
62  virtual void Finish() = 0;
63
64  virtual void DoNoOp() {}
65
66  // Puts backbuffer onscreen.
67  virtual void SwapBuffers(const LatencyInfo& latency_info) = 0;
68
69  virtual void GetFramebufferPixels(void* pixels, gfx::Rect rect) = 0;
70
71  virtual bool IsContextLost();
72
73  virtual void SetVisible(bool visible) = 0;
74
75  virtual void SendManagedMemoryStats(size_t bytes_visible,
76                                      size_t bytes_visible_and_nearby,
77                                      size_t bytes_allocated) = 0;
78
79 protected:
80  explicit Renderer(RendererClient* client)
81      : client_(client) {}
82
83  RendererClient* client_;
84
85  DISALLOW_COPY_AND_ASSIGN(Renderer);
86};
87
88}  // namespace cc
89
90#endif  // CC_OUTPUT_RENDERER_H_
91