Home | History | Annotate | Download | only in images
      1 
      2 /*
      3  * Copyright 2008 The Android Open Source Project
      4  *
      5  * Use of this source code is governed by a BSD-style license that can be
      6  * found in the LICENSE file.
      7  */
      8 
      9 
     10 #include "SkPageFlipper.h"
     11 
     12 SkPageFlipper::SkPageFlipper() {
     13     fWidth = 0;
     14     fHeight = 0;
     15     fDirty0 = &fDirty0Storage;
     16     fDirty1 = &fDirty1Storage;
     17 
     18     fDirty0->setEmpty();
     19     fDirty1->setEmpty();
     20 }
     21 
     22 SkPageFlipper::SkPageFlipper(int width, int height) {
     23     fWidth = width;
     24     fHeight = height;
     25     fDirty0 = &fDirty0Storage;
     26     fDirty1 = &fDirty1Storage;
     27 
     28     fDirty0->setRect(0, 0, width, height);
     29     fDirty1->setEmpty();
     30 }
     31 
     32 void SkPageFlipper::resize(int width, int height) {
     33     fWidth = width;
     34     fHeight = height;
     35 
     36     // this is the opposite of the constructors
     37     fDirty1->setRect(0, 0, width, height);
     38     fDirty0->setEmpty();
     39 }
     40 
     41 void SkPageFlipper::inval() {
     42     fDirty1->setRect(0, 0, fWidth, fHeight);
     43 }
     44 
     45 void SkPageFlipper::inval(const SkIRect& rect) {
     46     SkIRect r;
     47     r.set(0, 0, fWidth, fHeight);
     48     if (r.intersect(rect)) {
     49         fDirty1->op(r, SkRegion::kUnion_Op);
     50     }
     51 }
     52 
     53 void SkPageFlipper::inval(const SkRegion& rgn) {
     54     SkRegion r;
     55     r.setRect(0, 0, fWidth, fHeight);
     56     if (r.op(rgn, SkRegion::kIntersect_Op)) {
     57         fDirty1->op(r, SkRegion::kUnion_Op);
     58     }
     59 }
     60 
     61 void SkPageFlipper::inval(const SkRect& rect, bool antialias) {
     62     SkIRect r;
     63     rect.round(&r);
     64     if (antialias) {
     65         r.inset(-1, -1);
     66     }
     67     this->inval(r);
     68 }
     69 
     70 const SkRegion& SkPageFlipper::update(SkRegion* copyBits) {
     71     // Copy over anything new from page0 that isn't dirty in page1
     72     copyBits->op(*fDirty0, *fDirty1, SkRegion::kDifference_Op);
     73     SkTSwap<SkRegion*>(fDirty0, fDirty1);
     74     fDirty1->setEmpty();
     75     return *fDirty0;
     76 }
     77