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