1// Copyright (c) 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 CONTENT_RENDERER_PAINT_AGGREGATOR_H_ 6#define CONTENT_RENDERER_PAINT_AGGREGATOR_H_ 7 8#include <vector> 9 10#include "base/basictypes.h" 11#include "content/common/content_export.h" 12#include "ui/gfx/rect.h" 13#include "ui/gfx/vector2d.h" 14 15namespace content { 16 17// This class is responsible for aggregating multiple invalidation and scroll 18// commands to produce a scroll and repaint sequence. 19class CONTENT_EXPORT PaintAggregator { 20 public: 21 // This structure describes an aggregation of InvalidateRect and ScrollRect 22 // calls. If |scroll_rect| is non-empty, then that rect should be scrolled 23 // by the amount specified by |scroll_delta|. If |paint_rects| is non-empty, 24 // then those rects should be repainted. If |scroll_rect| and |paint_rects| 25 // are non-empty, then scrolling should be performed before repainting. 26 // |scroll_delta| can only specify scrolling in one direction (i.e., the x 27 // and y members cannot both be non-zero). 28 struct CONTENT_EXPORT PendingUpdate { 29 PendingUpdate(); 30 ~PendingUpdate(); 31 32 // Returns the rect damaged by scrolling within |scroll_rect| by 33 // |scroll_delta|. This rect must be repainted. 34 gfx::Rect GetScrollDamage() const; 35 36 // Returns the smallest rect containing all paint rects. 37 gfx::Rect GetPaintBounds() const; 38 39 gfx::Vector2d scroll_delta; 40 gfx::Rect scroll_rect; 41 std::vector<gfx::Rect> paint_rects; 42 }; 43 44 // There is a PendingUpdate if InvalidateRect or ScrollRect were called and 45 // ClearPendingUpdate was not called. 46 bool HasPendingUpdate() const; 47 void ClearPendingUpdate(); 48 49 // Fills |update| and clears the pending update. 50 void PopPendingUpdate(PendingUpdate* update); 51 52 // The given rect should be repainted. 53 void InvalidateRect(const gfx::Rect& rect); 54 55 // The given rect should be scrolled by the given amounts. 56 void ScrollRect(const gfx::Vector2d& delta, const gfx::Rect& clip_rect); 57 58 private: 59 gfx::Rect ScrollPaintRect(const gfx::Rect& paint_rect, 60 const gfx::Vector2d& delta) const; 61 bool ShouldInvalidateScrollRect(const gfx::Rect& rect) const; 62 void InvalidateScrollRect(); 63 void CombinePaintRects(); 64 65 PendingUpdate update_; 66}; 67 68} // namespace content 69 70#endif // CONTENT_RENDERER_PAINT_AGGREGATOR_H_ 71