summaryrefslogtreecommitdiffstats
path: root/chrome/renderer/paint_aggregator.h
blob: 6efac35eaa4288abd1be5ee166766dd1851a7bc3 (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
// Copyright (c) 2009 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 CHROME_RENDERER_PAINT_AGGREGATOR_H_
#define CHROME_RENDERER_PAINT_AGGREGATOR_H_
#pragma once

#include <vector>

#include "gfx/rect.h"

// This class is responsible for aggregating multiple invalidation and scroll
// commands to produce a scroll and repaint sequence.
class PaintAggregator {
 public:
  // This structure describes an aggregation of InvalidateRect and ScrollRect
  // calls.  If |scroll_rect| is non-empty, then that rect should be scrolled
  // by the amount specified by |scroll_delta|.  If |paint_rects| is non-empty,
  // then those rects should be repainted.  If |scroll_rect| and |paint_rects|
  // are non-empty, then scrolling should be performed before repainting.
  // |scroll_delta| can only specify scrolling in one direction (i.e., the x
  // and y members cannot both be non-zero).
  struct PendingUpdate {
    gfx::Point scroll_delta;
    gfx::Rect scroll_rect;
    std::vector<gfx::Rect> paint_rects;

    // Returns the rect damaged by scrolling within |scroll_rect| by
    // |scroll_delta|.  This rect must be repainted.
    gfx::Rect GetScrollDamage() const;

    // Returns the smallest rect containing all paint rects.
    gfx::Rect GetPaintBounds() const;
  };

  // There is a PendingUpdate if InvalidateRect or ScrollRect were called and
  // ClearPendingUpdate was not called.
  bool HasPendingUpdate() const;
  void ClearPendingUpdate();

  const PendingUpdate& GetPendingUpdate() const { return update_; }

  // The given rect should be repainted.
  void InvalidateRect(const gfx::Rect& rect);

  // The given rect should be scrolled by the given amounts.
  void ScrollRect(int dx, int dy, const gfx::Rect& clip_rect);

 private:
  gfx::Rect ScrollPaintRect(const gfx::Rect& paint_rect, int dx, int dy) const;
  bool ShouldInvalidateScrollRect(const gfx::Rect& rect) const;
  void InvalidateScrollRect();
  void CombinePaintRects();

  PendingUpdate update_;
};

#endif  // CHROME_RENDERER_PAINT_AGGREGATOR_H_