epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 3 | * Copyright 2008 The Android Open Source Project |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 4 | * |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 9 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 10 | #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 | */ |
| 24 | class SkPageFlipper { |
| 25 | public: |
| 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 | |
| 53 | private: |
| 54 | SkRegion* fDirty0; |
| 55 | SkRegion* fDirty1; |
| 56 | SkRegion fDirty0Storage; |
| 57 | SkRegion fDirty1Storage; |
| 58 | int fWidth; |
| 59 | int fHeight; |
| 60 | }; |
| 61 | |
| 62 | #endif |
| 63 | |