#include "SkRefCnt.h"
#include "SkPath.h"
#include "SkRegion.h"
-#include "SkScalarCompare.h"
#include "SkXfermode.h"
class SkBounder;
not intersect the current clip)
*/
bool quickRejectY(SkScalar top, SkScalar bottom) const {
- SkASSERT(SkScalarToCompareType(top) <= SkScalarToCompareType(bottom));
- const SkRectCompareType& clipR = this->getLocalClipBoundsCompareType();
+ SkASSERT(top <= bottom);
+ const SkRect& clipR = this->getLocalClipBounds();
// In the case where the clip is empty and we are provided with a
// negative top and positive bottom parameter then this test will return
// false even though it will be clipped. We have chosen to exclude that
// check as it is rare and would result double the comparisons.
- return SkScalarToCompareType(top) >= clipR.fBottom
- || SkScalarToCompareType(bottom) <= clipR.fTop;
+ return top >= clipR.fBottom || bottom <= clipR.fTop;
}
/** Return the bounds of the current clip (in local coordinates) in the
/* These maintain a cache of the clip bounds in local coordinates,
(converted to 2s-compliment if floats are slow).
*/
- mutable SkRectCompareType fLocalBoundsCompareType;
- mutable bool fLocalBoundsCompareTypeDirty;
+ mutable SkRect fCachedLocalClipBounds;
+ mutable bool fCachedLocalClipBoundsDirty;
bool fAllowSoftClip;
bool fAllowSimplifyClip;
- const SkRectCompareType& getLocalClipBoundsCompareType() const {
- if (fLocalBoundsCompareTypeDirty) {
- this->computeLocalClipBoundsCompareType();
- fLocalBoundsCompareTypeDirty = false;
+ const SkRect& getLocalClipBounds() const {
+ if (fCachedLocalClipBoundsDirty) {
+ if (!this->getClipBounds(&fCachedLocalClipBounds)) {
+ fCachedLocalClipBounds.setEmpty();
+ }
+ fCachedLocalClipBoundsDirty = false;
}
- return fLocalBoundsCompareType;
+ return fCachedLocalClipBounds;
}
- void computeLocalClipBoundsCompareType() const;
-
class AutoValidateClip : ::SkNoncopyable {
public:
+++ /dev/null
-
-/*
- * Copyright 2006 The Android Open Source Project
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-
-#ifndef SkScalarCompare_DEFINED
-#define SkScalarCompare_DEFINED
-
-#include "SkFloatBits.h"
-#include "SkRect.h"
-
-/** Skia can spend a lot of time just comparing scalars (e.g. quickReject).
- When scalar==fixed, this is very fast, and when scalar==hardware-float, this
- is also reasonable, but if scalar==software-float, then each compare can be
- a function call and take real time. To account for that, we have the flag
- SK_SCALAR_SLOW_COMPARES.
-
- If this is defined, we have a special trick where we quickly convert floats
- to a 2's compliment form, and then treat them as signed 32bit integers. In
- this form we lose a few subtlties (e.g. NaNs always comparing false) but
- we gain the speed of integer compares.
- */
-
-#ifdef SK_SCALAR_SLOW_COMPARES
- typedef int32_t SkScalarCompareType;
- typedef SkIRect SkRectCompareType;
- #define SkScalarToCompareType(x) SkScalarAs2sCompliment(x)
-#else
- typedef SkScalar SkScalarCompareType;
- typedef SkRect SkRectCompareType;
- #define SkScalarToCompareType(x) (x)
-#endif
-
-#endif
#include "SkPicture.h"
#include "SkRasterClip.h"
#include "SkRRect.h"
-#include "SkScalarCompare.h"
#include "SkSurface_Base.h"
#include "SkTemplates.h"
#include "SkTextFormatParams.h"
SkBaseDevice* SkCanvas::init(SkBaseDevice* device) {
fBounder = NULL;
- fLocalBoundsCompareType.setEmpty();
- fLocalBoundsCompareTypeDirty = true;
+ fCachedLocalClipBounds.setEmpty();
+ fCachedLocalClipBoundsDirty = true;
fAllowSoftClip = true;
fAllowSimplifyClip = false;
fDeviceCMDirty = false;
SkASSERT(fMCStack.count() != 0);
fDeviceCMDirty = true;
- fLocalBoundsCompareTypeDirty = true;
+ fCachedLocalClipBoundsDirty = true;
if (SkCanvas::kClip_SaveFlag & fMCRec->fFlags) {
fClipStack.restore();
bool SkCanvas::translate(SkScalar dx, SkScalar dy) {
fDeviceCMDirty = true;
- fLocalBoundsCompareTypeDirty = true;
+ fCachedLocalClipBoundsDirty = true;
return fMCRec->fMatrix->preTranslate(dx, dy);
}
bool SkCanvas::scale(SkScalar sx, SkScalar sy) {
fDeviceCMDirty = true;
- fLocalBoundsCompareTypeDirty = true;
+ fCachedLocalClipBoundsDirty = true;
return fMCRec->fMatrix->preScale(sx, sy);
}
bool SkCanvas::rotate(SkScalar degrees) {
fDeviceCMDirty = true;
- fLocalBoundsCompareTypeDirty = true;
+ fCachedLocalClipBoundsDirty = true;
return fMCRec->fMatrix->preRotate(degrees);
}
bool SkCanvas::skew(SkScalar sx, SkScalar sy) {
fDeviceCMDirty = true;
- fLocalBoundsCompareTypeDirty = true;
+ fCachedLocalClipBoundsDirty = true;
return fMCRec->fMatrix->preSkew(sx, sy);
}
bool SkCanvas::concat(const SkMatrix& matrix) {
fDeviceCMDirty = true;
- fLocalBoundsCompareTypeDirty = true;
+ fCachedLocalClipBoundsDirty = true;
return fMCRec->fMatrix->preConcat(matrix);
}
void SkCanvas::setMatrix(const SkMatrix& matrix) {
fDeviceCMDirty = true;
- fLocalBoundsCompareTypeDirty = true;
+ fCachedLocalClipBoundsDirty = true;
*fMCRec->fMatrix = matrix;
}
if (this->quickReject(rect)) {
fDeviceCMDirty = true;
- fLocalBoundsCompareTypeDirty = true;
+ fCachedLocalClipBoundsDirty = true;
fClipStack.clipEmpty();
return fMCRec->fRasterClip->setEmpty();
AutoValidateClip avc(this);
fDeviceCMDirty = true;
- fLocalBoundsCompareTypeDirty = true;
+ fCachedLocalClipBoundsDirty = true;
doAA &= fAllowSoftClip;
if (fMCRec->fMatrix->rectStaysRect()) {
if (this->quickReject(path.getBounds())) {
fDeviceCMDirty = true;
- fLocalBoundsCompareTypeDirty = true;
+ fCachedLocalClipBoundsDirty = true;
fClipStack.clipEmpty();
return fMCRec->fRasterClip->setEmpty();
AutoValidateClip avc(this);
fDeviceCMDirty = true;
- fLocalBoundsCompareTypeDirty = true;
+ fCachedLocalClipBoundsDirty = true;
doAA &= fAllowSoftClip;
SkPath devPath;
AutoValidateClip avc(this);
fDeviceCMDirty = true;
- fLocalBoundsCompareTypeDirty = true;
+ fCachedLocalClipBoundsDirty = true;
// todo: signal fClipStack that we have a region, and therefore (I guess)
// we have to ignore it, and use the region directly?
///////////////////////////////////////////////////////////////////////////////
-void SkCanvas::computeLocalClipBoundsCompareType() const {
- SkRect r;
-
- if (!this->getClipBounds(&r)) {
- fLocalBoundsCompareType.setEmpty();
- } else {
- fLocalBoundsCompareType.set(SkScalarToCompareType(r.fLeft),
- SkScalarToCompareType(r.fTop),
- SkScalarToCompareType(r.fRight),
- SkScalarToCompareType(r.fBottom));
- }
-}
-
bool SkCanvas::quickReject(const SkRect& rect) const {
if (!rect.isFinite())
dst.roundOut(&idst);
return !SkIRect::Intersects(idst, fMCRec->fRasterClip->getBounds());
} else {
- const SkRectCompareType& clipR = this->getLocalClipBoundsCompareType();
+ const SkRect& clipR = this->getLocalClipBounds();
// for speed, do the most likely reject compares first
- SkScalarCompareType userT = SkScalarToCompareType(rect.fTop);
- SkScalarCompareType userB = SkScalarToCompareType(rect.fBottom);
- if (userT >= clipR.fBottom || userB <= clipR.fTop) {
+ // TODO: should we use | instead, or compare all 4 at once?
+ if (rect.fTop >= clipR.fBottom || rect.fBottom <= clipR.fTop) {
return true;
}
- SkScalarCompareType userL = SkScalarToCompareType(rect.fLeft);
- SkScalarCompareType userR = SkScalarToCompareType(rect.fRight);
- if (userL >= clipR.fRight || userR <= clipR.fLeft) {
+ if (rect.fLeft >= clipR.fRight || rect.fRight <= clipR.fLeft) {
return true;
}
return false;