1 /* 2 * Copyright (C) 2011 Google Inc. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions are 6 * met: 7 * 8 * * Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * * Redistributions in binary form must reproduce the above 11 * copyright notice, this list of conditions and the following disclaimer 12 * in the documentation and/or other materials provided with the 13 * distribution. 14 * * Neither the name of Google Inc. nor the names of its 15 * contributors may be used to endorse or promote products derived from 16 * this software without specific prior written permission. 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 */ 30 31 #ifndef PaintAggregator_h 32 #define PaintAggregator_h 33 34 #include "platform/geometry/IntPoint.h" 35 #include "platform/geometry/IntRect.h" 36 #include "wtf/Vector.h" 37 38 namespace blink { 39 40 // This class is responsible for aggregating multiple invalidation and scroll 41 // commands to produce a scroll and repaint sequence. 42 class PaintAggregator { 43 public: 44 // This structure describes an aggregation of invalidateRect and scrollRect 45 // calls. If |scrollRect| is non-empty, then that rect should be scrolled 46 // by the amount specified by |scrollDelta|. If |paintRects| is non-empty, 47 // then those rects should be repainted. If |scrollRect| and |paintRects| 48 // are non-empty, then scrolling should be performed before repainting. 49 // |scrollDelta| can only specify scrolling in one direction (i.e., the x 50 // and y members cannot both be non-zero). 51 struct PendingUpdate { 52 PendingUpdate(); 53 ~PendingUpdate(); 54 55 // Returns the rect damaged by scrolling within |scrollRect| by 56 // |scrollDelta|. This rect must be repainted. 57 blink::IntRect calculateScrollDamage() const; 58 59 // Returns the smallest rect containing all paint rects. 60 blink::IntRect calculatePaintBounds() const; 61 62 blink::IntPoint scrollDelta; 63 blink::IntRect scrollRect; 64 WTF::Vector<blink::IntRect> paintRects; 65 }; 66 67 // There is a PendingUpdate if invalidateRect or scrollRect were called and 68 // ClearPendingUpdate was not called. 69 bool hasPendingUpdate() const; 70 void clearPendingUpdate(); 71 72 // Fills |update| and clears the pending update. 73 void popPendingUpdate(PendingUpdate*); 74 75 // The given rect should be repainted. 76 void invalidateRect(const blink::IntRect&); 77 78 // The given rect should be scrolled by the given amounts. 79 void scrollRect(int dx, int dy, const blink::IntRect& clipRect); 80 81 private: 82 blink::IntRect scrollPaintRect(const blink::IntRect& paintRect, int dx, int dy) const; 83 bool shouldInvalidateScrollRect(const blink::IntRect&) const; 84 void invalidateScrollRect(); 85 void combinePaintRects(); 86 87 PendingUpdate m_update; 88 }; 89 90 } // namespace blink 91 92 #endif 93