Bug 946475 - Avoid using AutoSaveRestoreClippedOut for ClearRect when the cumulative clip can be represented as a single axis aligned rectangle. r=Bas

This commit is contained in:
Matt Woodrow 2013-12-12 10:11:37 +13:00
parent 2c52ae2935
commit ccc8dd1ae7
2 changed files with 55 additions and 2 deletions

View File

@ -766,14 +766,34 @@ DrawTargetD2D::ClearRect(const Rect &aRect)
MarkChanged();
PushClipRect(aRect);
FlushTransformToRT();
PopAllClips();
AutoSaveRestoreClippedOut restoreClippedOut(this);
restoreClippedOut.Save();
D2D1_RECT_F clipRect;
bool isPixelAligned;
bool pushedClip = false;
if (mTransform.IsRectilinear() &&
GetDeviceSpaceClipRect(clipRect, isPixelAligned)) {
if (mTransformDirty ||
!mTransform.IsIdentity()) {
mRT->SetTransform(D2D1::IdentityMatrix());
mTransformDirty = true;
}
mRT->PushAxisAlignedClip(clipRect, isPixelAligned ? D2D1_ANTIALIAS_MODE_ALIASED : D2D1_ANTIALIAS_MODE_PER_PRIMITIVE);
pushedClip = true;
} else {
FlushTransformToRT();
restoreClippedOut.Save();
}
mRT->Clear(D2D1::ColorF(0, 0.0f));
if (pushedClip) {
mRT->PopAxisAlignedClip();
}
PopClip();
return;
}
@ -1763,9 +1783,40 @@ IntersectRect(const D2D1_RECT_F& aRect1, const D2D1_RECT_F& aRect2)
result.top = max(aRect1.top, aRect2.top);
result.right = min(aRect1.right, aRect2.right);
result.bottom = min(aRect1.bottom, aRect2.bottom);
result.right = max(result.right, result.left);
result.bottom = max(result.bottom, result.top);
return result;
}
bool
DrawTargetD2D::GetDeviceSpaceClipRect(D2D1_RECT_F& aClipRect, bool& aIsPixelAligned)
{
if (!mPushedClips.size()) {
return false;
}
std::vector<DrawTargetD2D::PushedClip>::iterator iter = mPushedClips.begin();
if (iter->mPath) {
return false;
}
aClipRect = iter->mBounds;
aIsPixelAligned = iter->mIsPixelAligned;
iter++;
for (;iter != mPushedClips.end(); iter++) {
if (iter->mPath) {
return false;
}
aClipRect = IntersectRect(aClipRect, iter->mBounds);
if (!iter->mIsPixelAligned) {
aIsPixelAligned = false;
}
}
return true;
}
TemporaryRef<ID2D1Geometry>
DrawTargetD2D::GetClippedGeometry(IntRect *aClipBounds)
{

View File

@ -205,6 +205,8 @@ private:
// bounds to correctly reflect the total clip. This is in device space.
TemporaryRef<ID2D1Geometry> GetClippedGeometry(IntRect *aClipBounds);
bool GetDeviceSpaceClipRect(D2D1_RECT_F& aClipRect, bool& aIsPixelAligned);
TemporaryRef<ID2D1Brush> CreateBrushForPattern(const Pattern &aPattern, Float aAlpha = 1.0f);
TemporaryRef<ID3D10Texture2D> CreateGradientTexture(const GradientStopsD2D *aStops);