michael@0: michael@0: /* michael@0: * Copyright 2008 The Android Open Source Project michael@0: * michael@0: * Use of this source code is governed by a BSD-style license that can be michael@0: * found in the LICENSE file. michael@0: */ michael@0: michael@0: michael@0: #include "SkPageFlipper.h" michael@0: michael@0: SkPageFlipper::SkPageFlipper() { michael@0: fWidth = 0; michael@0: fHeight = 0; michael@0: fDirty0 = &fDirty0Storage; michael@0: fDirty1 = &fDirty1Storage; michael@0: michael@0: fDirty0->setEmpty(); michael@0: fDirty1->setEmpty(); michael@0: } michael@0: michael@0: SkPageFlipper::SkPageFlipper(int width, int height) { michael@0: fWidth = width; michael@0: fHeight = height; michael@0: fDirty0 = &fDirty0Storage; michael@0: fDirty1 = &fDirty1Storage; michael@0: michael@0: fDirty0->setRect(0, 0, width, height); michael@0: fDirty1->setEmpty(); michael@0: } michael@0: michael@0: void SkPageFlipper::resize(int width, int height) { michael@0: fWidth = width; michael@0: fHeight = height; michael@0: michael@0: // this is the opposite of the constructors michael@0: fDirty1->setRect(0, 0, width, height); michael@0: fDirty0->setEmpty(); michael@0: } michael@0: michael@0: void SkPageFlipper::inval() { michael@0: fDirty1->setRect(0, 0, fWidth, fHeight); michael@0: } michael@0: michael@0: void SkPageFlipper::inval(const SkIRect& rect) { michael@0: SkIRect r; michael@0: r.set(0, 0, fWidth, fHeight); michael@0: if (r.intersect(rect)) { michael@0: fDirty1->op(r, SkRegion::kUnion_Op); michael@0: } michael@0: } michael@0: michael@0: void SkPageFlipper::inval(const SkRegion& rgn) { michael@0: SkRegion r; michael@0: r.setRect(0, 0, fWidth, fHeight); michael@0: if (r.op(rgn, SkRegion::kIntersect_Op)) { michael@0: fDirty1->op(r, SkRegion::kUnion_Op); michael@0: } michael@0: } michael@0: michael@0: void SkPageFlipper::inval(const SkRect& rect, bool antialias) { michael@0: SkIRect r; michael@0: rect.round(&r); michael@0: if (antialias) { michael@0: r.inset(-1, -1); michael@0: } michael@0: this->inval(r); michael@0: } michael@0: michael@0: const SkRegion& SkPageFlipper::update(SkRegion* copyBits) { michael@0: // Copy over anything new from page0 that isn't dirty in page1 michael@0: copyBits->op(*fDirty0, *fDirty1, SkRegion::kDifference_Op); michael@0: SkTSwap(fDirty0, fDirty1); michael@0: fDirty1->setEmpty(); michael@0: return *fDirty0; michael@0: }