summaryrefslogtreecommitdiffstats
path: root/cc/output/overlay_processor.h
blob: 8f3704cd67cf63ad42a054990ff8660526aca2bb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CC_OUTPUT_OVERLAY_PROCESSOR_H_
#define CC_OUTPUT_OVERLAY_PROCESSOR_H_

#include "base/basictypes.h"
#include "base/memory/scoped_ptr.h"
#include "cc/base/cc_export.h"
#include "cc/output/ca_layer_overlay.h"
#include "cc/output/overlay_candidate.h"
#include "cc/quads/render_pass.h"

namespace cc {
class OutputSurface;
class ResourceProvider;

class CC_EXPORT OverlayProcessor {
 public:
  class CC_EXPORT Strategy {
   public:
    virtual ~Strategy() {}
    // Returns false if the strategy cannot be made to work with the
    // current set of render passes. Returns true if the strategy was successful
    // and adds any additional passes necessary to represent overlays to
    // |render_passes|.
    virtual bool Attempt(ResourceProvider* resource_provider,
                         RenderPassList* render_passes,
                         OverlayCandidateList* candidates) = 0;
  };
  using StrategyList = std::vector<scoped_ptr<Strategy>>;

  explicit OverlayProcessor(OutputSurface* surface);
  virtual ~OverlayProcessor();
  // Virtual to allow testing different strategies.
  virtual void Initialize();

  gfx::Rect GetAndResetOverlayDamage();

  void ProcessForOverlays(ResourceProvider* resource_provider,
                          RenderPassList* render_passes,
                          OverlayCandidateList* overlay_candidates,
                          CALayerOverlayList* ca_layer_overlays,
                          gfx::Rect* damage_rect);

  // Notify the processor that ProcessForOverlays is being skipped this frame.
  void SkipProcessForOverlays();

 protected:
  StrategyList strategies_;
  OutputSurface* surface_;
  gfx::Rect overlay_damage_rect_;
  gfx::Rect previous_frame_underlay_rect_;

 private:
  bool ProcessForCALayers(ResourceProvider* resource_provider,
                          RenderPassList* render_passes,
                          OverlayCandidateList* overlay_candidates,
                          CALayerOverlayList* ca_layer_overlays,
                          gfx::Rect* damage_rect);
  // Update |damage_rect| by removing damage casued by |candidates|.
  void UpdateDamageRect(OverlayCandidateList* candidates,
                        gfx::Rect* damage_rect);

  DISALLOW_COPY_AND_ASSIGN(OverlayProcessor);
};

}  // namespace cc

#endif  // CC_OUTPUT_OVERLAY_PROCESSOR_H_