1ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com
28a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com/*
3ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Copyright 2008 The Android Open Source Project
48a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com *
5ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Use of this source code is governed by a BSD-style license that can be
6ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * found in the LICENSE file.
78a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */
88a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
9ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com
108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkPageFlipper.h"
118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comSkPageFlipper::SkPageFlipper() {
138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    fWidth = 0;
148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    fHeight = 0;
158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    fDirty0 = &fDirty0Storage;
168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    fDirty1 = &fDirty1Storage;
178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    fDirty0->setEmpty();
198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    fDirty1->setEmpty();
208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com}
218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comSkPageFlipper::SkPageFlipper(int width, int height) {
238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    fWidth = width;
248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    fHeight = height;
258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    fDirty0 = &fDirty0Storage;
268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    fDirty1 = &fDirty1Storage;
278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    fDirty0->setRect(0, 0, width, height);
298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    fDirty1->setEmpty();
308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com}
318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comvoid SkPageFlipper::resize(int width, int height) {
338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    fWidth = width;
348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    fHeight = height;
35d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com
368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    // this is the opposite of the constructors
378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    fDirty1->setRect(0, 0, width, height);
388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    fDirty0->setEmpty();
398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com}
408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comvoid SkPageFlipper::inval() {
428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    fDirty1->setRect(0, 0, fWidth, fHeight);
438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com}
448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comvoid SkPageFlipper::inval(const SkIRect& rect) {
468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkIRect r;
478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    r.set(0, 0, fWidth, fHeight);
488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    if (r.intersect(rect)) {
498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        fDirty1->op(r, SkRegion::kUnion_Op);
508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    }
518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com}
528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comvoid SkPageFlipper::inval(const SkRegion& rgn) {
548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkRegion r;
558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    r.setRect(0, 0, fWidth, fHeight);
568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    if (r.op(rgn, SkRegion::kIntersect_Op)) {
578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        fDirty1->op(r, SkRegion::kUnion_Op);
588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    }
598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com}
608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comvoid SkPageFlipper::inval(const SkRect& rect, bool antialias) {
628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkIRect r;
638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    rect.round(&r);
648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    if (antialias) {
658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        r.inset(-1, -1);
668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    }
678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    this->inval(r);
688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com}
698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comconst SkRegion& SkPageFlipper::update(SkRegion* copyBits) {
718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    // Copy over anything new from page0 that isn't dirty in page1
728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    copyBits->op(*fDirty0, *fDirty1, SkRegion::kDifference_Op);
738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkTSwap<SkRegion*>(fDirty0, fDirty1);
748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    fDirty1->setEmpty();
758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    return *fDirty0;
768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com}
77