Home | History | Annotate | Download | only in images
      1 /*
      2  * Copyright (C) 2008 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 #ifndef SkPageFlipper_DEFINED
     18 #define SkPageFlipper_DEFINED
     19 
     20 #include "SkRegion.h"
     21 
     22 /** SkPageFlipper manages alternating inval/dirty regions for a rectangular area
     23     (like a bitmap). You call inval() to accumulate inval areas, and then when
     24     you're ready to "flip" pages (i.e. draw into the one you've been
     25     invalidating) you call update, which swaps the inval regions, and returns
     26     two things to you: 1) the final inval region to be drawn into, and 2) the
     27     region of pixels that should be copied from the "front" page onto the one
     28     you're about to draw into. This copyBits region will be disjoint from the
     29     inval region, so both need to be handled.
     30  */
     31 class SkPageFlipper {
     32 public:
     33     SkPageFlipper();
     34     SkPageFlipper(int width, int height);
     35 
     36     int width() const { return fWidth; }
     37     int height() const { return fHeight; }
     38 
     39     void resize(int width, int height);
     40 
     41     bool isDirty() const { return !fDirty1->isEmpty(); }
     42     const SkRegion& dirtyRgn() const { return *fDirty1; }
     43 
     44     void inval();
     45     void inval(const SkIRect&);
     46     void inval(const SkRegion&);
     47     void inval(const SkRect&, bool antialias);
     48 
     49     /** When you're ready to write to the back page, call update. The returned
     50         region is the invalidate are that needs to be drawn to. The copyBits
     51         region (provided by the caller) is the area that should be copied from
     52         the front page to the back page (will not intersect with the returned
     53         inval region.
     54 
     55         Once this is called, the two internal regions are swapped, so the *new*
     56         back inval region is ready to receive new inval calls.
     57      */
     58     const SkRegion& update(SkRegion* copyBits);
     59 
     60 private:
     61     SkRegion*   fDirty0;
     62     SkRegion*   fDirty1;
     63     SkRegion    fDirty0Storage;
     64     SkRegion    fDirty1Storage;
     65     int         fWidth;
     66     int         fHeight;
     67 };
     68 
     69 #endif
     70 
     71