1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/skia/trunk/include/images/SkPageFlipper.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,62 @@ 1.4 + 1.5 +/* 1.6 + * Copyright 2008 The Android Open Source Project 1.7 + * 1.8 + * Use of this source code is governed by a BSD-style license that can be 1.9 + * found in the LICENSE file. 1.10 + */ 1.11 + 1.12 + 1.13 +#ifndef SkPageFlipper_DEFINED 1.14 +#define SkPageFlipper_DEFINED 1.15 + 1.16 +#include "SkRegion.h" 1.17 + 1.18 +/** SkPageFlipper manages alternating inval/dirty regions for a rectangular area 1.19 + (like a bitmap). You call inval() to accumulate inval areas, and then when 1.20 + you're ready to "flip" pages (i.e. draw into the one you've been 1.21 + invalidating) you call update, which swaps the inval regions, and returns 1.22 + two things to you: 1) the final inval region to be drawn into, and 2) the 1.23 + region of pixels that should be copied from the "front" page onto the one 1.24 + you're about to draw into. This copyBits region will be disjoint from the 1.25 + inval region, so both need to be handled. 1.26 + */ 1.27 +class SkPageFlipper { 1.28 +public: 1.29 + SkPageFlipper(); 1.30 + SkPageFlipper(int width, int height); 1.31 + 1.32 + int width() const { return fWidth; } 1.33 + int height() const { return fHeight; } 1.34 + 1.35 + void resize(int width, int height); 1.36 + 1.37 + bool isDirty() const { return !fDirty1->isEmpty(); } 1.38 + const SkRegion& dirtyRgn() const { return *fDirty1; } 1.39 + 1.40 + void inval(); 1.41 + void inval(const SkIRect&); 1.42 + void inval(const SkRegion&); 1.43 + void inval(const SkRect&, bool antialias); 1.44 + 1.45 + /** When you're ready to write to the back page, call update. The returned 1.46 + region is the invalidate are that needs to be drawn to. The copyBits 1.47 + region (provided by the caller) is the area that should be copied from 1.48 + the front page to the back page (will not intersect with the returned 1.49 + inval region. 1.50 + 1.51 + Once this is called, the two internal regions are swapped, so the *new* 1.52 + back inval region is ready to receive new inval calls. 1.53 + */ 1.54 + const SkRegion& update(SkRegion* copyBits); 1.55 + 1.56 +private: 1.57 + SkRegion* fDirty0; 1.58 + SkRegion* fDirty1; 1.59 + SkRegion fDirty0Storage; 1.60 + SkRegion fDirty1Storage; 1.61 + int fWidth; 1.62 + int fHeight; 1.63 +}; 1.64 + 1.65 +#endif