180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru/* 380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * Copyright 2008 The Android Open Source Project 480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * 580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * Use of this source code is governed by a BSD-style license that can be 680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * found in the LICENSE file. 780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru */ 880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 1080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include "SkPageFlipper.h" 1180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 1280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste QueruSkPageFlipper::SkPageFlipper() { 1380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru fWidth = 0; 1480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru fHeight = 0; 1580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru fDirty0 = &fDirty0Storage; 1680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru fDirty1 = &fDirty1Storage; 1780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 1880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru fDirty0->setEmpty(); 1980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru fDirty1->setEmpty(); 2080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 2180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 2280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste QueruSkPageFlipper::SkPageFlipper(int width, int height) { 2380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru fWidth = width; 2480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru fHeight = height; 2580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru fDirty0 = &fDirty0Storage; 2680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru fDirty1 = &fDirty1Storage; 2780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 2880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru fDirty0->setRect(0, 0, width, height); 2980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru fDirty1->setEmpty(); 3080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 3180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 3280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruvoid SkPageFlipper::resize(int width, int height) { 3380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru fWidth = width; 3480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru fHeight = height; 3580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 3680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru // this is the opposite of the constructors 3780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru fDirty1->setRect(0, 0, width, height); 3880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru fDirty0->setEmpty(); 3980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 4080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 4180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruvoid SkPageFlipper::inval() { 4280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru fDirty1->setRect(0, 0, fWidth, fHeight); 4380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 4480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 4580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruvoid SkPageFlipper::inval(const SkIRect& rect) { 4680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkIRect r; 4780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru r.set(0, 0, fWidth, fHeight); 4880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (r.intersect(rect)) { 4980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru fDirty1->op(r, SkRegion::kUnion_Op); 5080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 5180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 5280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 5380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruvoid SkPageFlipper::inval(const SkRegion& rgn) { 5480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkRegion r; 5580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru r.setRect(0, 0, fWidth, fHeight); 5680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (r.op(rgn, SkRegion::kIntersect_Op)) { 5780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru fDirty1->op(r, SkRegion::kUnion_Op); 5880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 5980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 6080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 6180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruvoid SkPageFlipper::inval(const SkRect& rect, bool antialias) { 6280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkIRect r; 6380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru rect.round(&r); 6480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (antialias) { 6580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru r.inset(-1, -1); 6680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 6780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru this->inval(r); 6880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 6980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 7080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruconst SkRegion& SkPageFlipper::update(SkRegion* copyBits) { 7180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru // Copy over anything new from page0 that isn't dirty in page1 7280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru copyBits->op(*fDirty0, *fDirty1, SkRegion::kDifference_Op); 7380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkTSwap<SkRegion*>(fDirty0, fDirty1); 7480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru fDirty1->setEmpty(); 7580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return *fDirty0; 7680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 77