blob: 8e51e637a68d85ff72c7bd5a295bb7e5493d35f2 [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
reed@android.com8a1c16f2008-12-17 15:59:43 +00002/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00003 * Copyright 2008 The Android Open Source Project
reed@android.com8a1c16f2008-12-17 15:59:43 +00004 *
epoger@google.comec3ed6a2011-07-28 14:26:00 +00005 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
reed@android.com8a1c16f2008-12-17 15:59:43 +00007 */
8
epoger@google.comec3ed6a2011-07-28 14:26:00 +00009
reed@android.com8a1c16f2008-12-17 15:59:43 +000010#include "SkPageFlipper.h"
11
12SkPageFlipper::SkPageFlipper() {
13 fWidth = 0;
14 fHeight = 0;
15 fDirty0 = &fDirty0Storage;
16 fDirty1 = &fDirty1Storage;
17
18 fDirty0->setEmpty();
19 fDirty1->setEmpty();
20}
21
22SkPageFlipper::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
32void 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
41void SkPageFlipper::inval() {
42 fDirty1->setRect(0, 0, fWidth, fHeight);
43}
44
45void 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
53void 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
61void 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
70const 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
78