blob: 526ba093d68103bd9e2b7d10c2a4c60515b93c32 [file] [log] [blame]
reed@android.com8a1c16f2008-12-17 15:59:43 +00001/*
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#include "SkPageFlipper.h"
18
19SkPageFlipper::SkPageFlipper() {
20 fWidth = 0;
21 fHeight = 0;
22 fDirty0 = &fDirty0Storage;
23 fDirty1 = &fDirty1Storage;
24
25 fDirty0->setEmpty();
26 fDirty1->setEmpty();
27}
28
29SkPageFlipper::SkPageFlipper(int width, int height) {
30 fWidth = width;
31 fHeight = height;
32 fDirty0 = &fDirty0Storage;
33 fDirty1 = &fDirty1Storage;
34
35 fDirty0->setRect(0, 0, width, height);
36 fDirty1->setEmpty();
37}
38
39void SkPageFlipper::resize(int width, int height) {
40 fWidth = width;
41 fHeight = height;
42
43 // this is the opposite of the constructors
44 fDirty1->setRect(0, 0, width, height);
45 fDirty0->setEmpty();
46}
47
48void SkPageFlipper::inval() {
49 fDirty1->setRect(0, 0, fWidth, fHeight);
50}
51
52void SkPageFlipper::inval(const SkIRect& rect) {
53 SkIRect r;
54 r.set(0, 0, fWidth, fHeight);
55 if (r.intersect(rect)) {
56 fDirty1->op(r, SkRegion::kUnion_Op);
57 }
58}
59
60void SkPageFlipper::inval(const SkRegion& rgn) {
61 SkRegion r;
62 r.setRect(0, 0, fWidth, fHeight);
63 if (r.op(rgn, SkRegion::kIntersect_Op)) {
64 fDirty1->op(r, SkRegion::kUnion_Op);
65 }
66}
67
68void SkPageFlipper::inval(const SkRect& rect, bool antialias) {
69 SkIRect r;
70 rect.round(&r);
71 if (antialias) {
72 r.inset(-1, -1);
73 }
74 this->inval(r);
75}
76
77const SkRegion& SkPageFlipper::update(SkRegion* copyBits) {
78 // Copy over anything new from page0 that isn't dirty in page1
79 copyBits->op(*fDirty0, *fDirty1, SkRegion::kDifference_Op);
80 SkTSwap<SkRegion*>(fDirty0, fDirty1);
81 fDirty1->setEmpty();
82 return *fDirty0;
83}
84
85