renderer.h revision b2df76ea8fec9e32f6f3718986dba0d95315b29c
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 bool CanReadPixels() const = 0;
54
55  virtual void DecideRenderPassAllocationsForFrame(
56      const RenderPassList& render_passes_in_draw_order) {}
57  virtual bool HaveCachedResourcesForRenderPassId(RenderPass::Id id) const;
58
59  // This passes ownership of the render passes to the renderer. It should
60  // consume them, and empty the list.
61  virtual void DrawFrame(RenderPassList* render_passes_in_draw_order) = 0;
62
63  // Waits for rendering to finish.
64  virtual void Finish() = 0;
65
66  virtual void DoNoOp() {}
67
68  // Puts backbuffer onscreen.
69  virtual void SwapBuffers(const LatencyInfo& latency_info) = 0;
70
71  virtual void GetFramebufferPixels(void* pixels, gfx::Rect rect) = 0;
72
73  virtual bool IsContextLost();
74
75  virtual void SetVisible(bool visible) = 0;
76
77  virtual void SendManagedMemoryStats(size_t bytes_visible,
78                                      size_t bytes_visible_and_nearby,
79                                      size_t bytes_allocated) = 0;
80
81 protected:
82  explicit Renderer(RendererClient* client)
83      : client_(client) {}
84
85  RendererClient* client_;
86
87  DISALLOW_COPY_AND_ASSIGN(Renderer);
88};
89
90}  // namespace cc
91
92#endif  // CC_OUTPUT_RENDERER_H_
93