1 /* libs/graphics/animator/SkBoundable.cpp 2 ** 3 ** Copyright 2006, The Android Open Source Project 4 ** 5 ** Licensed under the Apache License, Version 2.0 (the "License"); 6 ** you may not use this file except in compliance with the License. 7 ** You may obtain a copy of the License at 8 ** 9 ** http://www.apache.org/licenses/LICENSE-2.0 10 ** 11 ** Unless required by applicable law or agreed to in writing, software 12 ** distributed under the License is distributed on an "AS IS" BASIS, 13 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 ** See the License for the specific language governing permissions and 15 ** limitations under the License. 16 */ 17 18 #include "SkBoundable.h" 19 #include "SkAnimateMaker.h" 20 #include "SkCanvas.h" 21 SkBoundable()22SkBoundable::SkBoundable() { 23 clearBounds(); 24 fBounds.fTop = 0; 25 fBounds.fRight = 0; 26 fBounds.fBottom = 0; 27 } 28 clearBounder()29void SkBoundable::clearBounder() { 30 fBounds.fLeft = 0x7fff; 31 } 32 getBounds(SkRect * rect)33void SkBoundable::getBounds(SkRect* rect) { 34 SkASSERT(rect); 35 if (fBounds.fLeft == (int16_t)0x8000U) { 36 INHERITED::getBounds(rect); 37 return; 38 } 39 rect->fLeft = SkIntToScalar(fBounds.fLeft); 40 rect->fTop = SkIntToScalar(fBounds.fTop); 41 rect->fRight = SkIntToScalar(fBounds.fRight); 42 rect->fBottom = SkIntToScalar(fBounds.fBottom); 43 } 44 enableBounder()45void SkBoundable::enableBounder() { 46 fBounds.fLeft = 0; 47 } 48 49 SkBoundableAuto(SkBoundable * boundable,SkAnimateMaker & maker)50SkBoundableAuto::SkBoundableAuto(SkBoundable* boundable, 51 SkAnimateMaker& maker) : fBoundable(boundable), fMaker(maker) { 52 if (fBoundable->hasBounds()) { 53 fMaker.fCanvas->setBounder(&maker.fDisplayList); 54 fMaker.fDisplayList.fBounds.setEmpty(); 55 } 56 } 57 ~SkBoundableAuto()58SkBoundableAuto::~SkBoundableAuto() { 59 if (fBoundable->hasBounds() == false) 60 return; 61 fMaker.fCanvas->setBounder(NULL); 62 fBoundable->setBounds(fMaker.fDisplayList.fBounds); 63 } 64 65