blob: 1a188565aacccbc2e6521a1c8871a2bf6c849aa6 [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
reed@android.com8a1c16f2008-12-17 15:59:43 +00002/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00003 * Copyright 2008 The Android Open Source Project
reed@android.com8a1c16f2008-12-17 15:59:43 +00004 *
epoger@google.comec3ed6a2011-07-28 14:26:00 +00005 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
reed@android.com8a1c16f2008-12-17 15:59:43 +00007 */
8
epoger@google.comec3ed6a2011-07-28 14:26:00 +00009
reed@android.com8a1c16f2008-12-17 15:59:43 +000010#ifndef SkPageFlipper_DEFINED
11#define SkPageFlipper_DEFINED
12
13#include "SkRegion.h"
14
15/** SkPageFlipper manages alternating inval/dirty regions for a rectangular area
16 (like a bitmap). You call inval() to accumulate inval areas, and then when
17 you're ready to "flip" pages (i.e. draw into the one you've been
18 invalidating) you call update, which swaps the inval regions, and returns
19 two things to you: 1) the final inval region to be drawn into, and 2) the
20 region of pixels that should be copied from the "front" page onto the one
21 you're about to draw into. This copyBits region will be disjoint from the
22 inval region, so both need to be handled.
23 */
24class SkPageFlipper {
25public:
26 SkPageFlipper();
27 SkPageFlipper(int width, int height);
28
29 int width() const { return fWidth; }
30 int height() const { return fHeight; }
31
32 void resize(int width, int height);
33
34 bool isDirty() const { return !fDirty1->isEmpty(); }
35 const SkRegion& dirtyRgn() const { return *fDirty1; }
36
37 void inval();
38 void inval(const SkIRect&);
39 void inval(const SkRegion&);
40 void inval(const SkRect&, bool antialias);
41
42 /** When you're ready to write to the back page, call update. The returned
43 region is the invalidate are that needs to be drawn to. The copyBits
44 region (provided by the caller) is the area that should be copied from
45 the front page to the back page (will not intersect with the returned
46 inval region.
47
48 Once this is called, the two internal regions are swapped, so the *new*
49 back inval region is ready to receive new inval calls.
50 */
51 const SkRegion& update(SkRegion* copyBits);
52
53private:
54 SkRegion* fDirty0;
55 SkRegion* fDirty1;
56 SkRegion fDirty0Storage;
57 SkRegion fDirty1Storage;
58 int fWidth;
59 int fHeight;
60};
61
62#endif
63