Bug 1044702 - Use Moz2D source clipping when we can. r=Bas

--HG--
extra : rebase_source : 24eb333909db5278ff1a8babf9b4b907650695fa
This commit is contained in:
Matt Woodrow 2014-09-12 17:18:21 +12:00
Родитель 004810cf46
Коммит 384ef32e14
4 изменённых файлов: 68 добавлений и 3 удалений

Просмотреть файл

@ -26,6 +26,29 @@ gfxSurfaceDrawable::gfxSurfaceDrawable(SourceSurface* aSurface,
{
}
bool
gfxSurfaceDrawable::DrawWithSamplingRect(gfxContext* aContext,
const gfxRect& aFillRect,
const gfxRect& aSamplingRect,
bool aRepeat,
const GraphicsFilter& aFilter,
gfxFloat aOpacity)
{
// When drawing with CLAMP we can expand the sampling rect to the nearest pixel
// without changing the result.
gfxRect samplingRect = aSamplingRect;
samplingRect.RoundOut();
IntRect intRect(samplingRect.x, samplingRect.y, samplingRect.width, samplingRect.height);
IntSize size = mSourceSurface->GetSize();
if (!IntRect(0, 0, size.width, size.height).Contains(intRect)) {
return false;
}
DrawInternal(aContext, aFillRect, intRect, false, aFilter, aOpacity, gfxMatrix());
return true;
}
bool
gfxSurfaceDrawable::Draw(gfxContext* aContext,
const gfxRect& aFillRect,
@ -33,6 +56,19 @@ gfxSurfaceDrawable::Draw(gfxContext* aContext,
const GraphicsFilter& aFilter,
gfxFloat aOpacity,
const gfxMatrix& aTransform)
{
DrawInternal(aContext, aFillRect, IntRect(), aRepeat, aFilter, aOpacity, aTransform);
return true;
}
void
gfxSurfaceDrawable::DrawInternal(gfxContext* aContext,
const gfxRect& aFillRect,
const IntRect& aSamplingRect,
bool aRepeat,
const GraphicsFilter& aFilter,
gfxFloat aOpacity,
const gfxMatrix& aTransform)
{
ExtendMode extend = ExtendMode::CLAMP;
@ -44,7 +80,7 @@ gfxSurfaceDrawable::Draw(gfxContext* aContext,
patternTransform.Invert();
SurfacePattern pattern(mSourceSurface, extend,
patternTransform, ToFilter(aFilter));
patternTransform, ToFilter(aFilter), aSamplingRect);
Rect fillRect = ToRect(aFillRect);
DrawTarget* dt = aContext->GetDrawTarget();
@ -64,7 +100,6 @@ gfxSurfaceDrawable::Draw(gfxContext* aContext,
AntialiasMode::SUBPIXEL;
dt->FillRect(fillRect, pattern, DrawOptions(aOpacity, op, aaMode));
}
return true;
}
gfxCallbackDrawable::gfxCallbackDrawable(gfxDrawingCallback* aCallback,

Просмотреть файл

@ -40,6 +40,16 @@ public:
const GraphicsFilter& aFilter,
gfxFloat aOpacity = 1.0,
const gfxMatrix& aTransform = gfxMatrix()) = 0;
virtual bool DrawWithSamplingRect(gfxContext* aContext,
const gfxRect& aFillRect,
const gfxRect& aSamplingRect,
bool aRepeat,
const GraphicsFilter& aFilter,
gfxFloat aOpacity = 1.0)
{
return false;
}
virtual gfxIntSize Size() { return mSize; }
protected:
@ -65,8 +75,22 @@ public:
const GraphicsFilter& aFilter,
gfxFloat aOpacity = 1.0,
const gfxMatrix& aTransform = gfxMatrix());
virtual bool DrawWithSamplingRect(gfxContext* aContext,
const gfxRect& aFillRect,
const gfxRect& aSamplingRect,
bool aRepeat,
const GraphicsFilter& aFilter,
gfxFloat aOpacity = 1.0);
protected:
void DrawInternal(gfxContext* aContext,
const gfxRect& aFillRect,
const mozilla::gfx::IntRect& aSamplingRect,
bool aRepeat,
const GraphicsFilter& aFilter,
gfxFloat aOpacity,
const gfxMatrix& aTransform = gfxMatrix());
mozilla::RefPtr<mozilla::gfx::SourceSurface> mSourceSurface;
const gfxMatrix mTransform;
};

Просмотреть файл

@ -593,6 +593,12 @@ gfxUtils::DrawPixelSnapped(gfxContext* aContext,
imageRect.Width(), imageRect.Height(),
region.Width(), region.Height());
if (aRegion.IsRestricted() &&
drawable->DrawWithSamplingRect(aContext, aRegion.Rect(), aRegion.Restriction(),
doTile, aFilter, aOpacity)) {
return;
}
// On Mobile, we don't ever want to do this; it has the potential for
// allocating very large temporary surfaces, especially since we'll
// do full-page snapshots often (see bug 749426).

Просмотреть файл

@ -860,7 +860,7 @@ skip-if(B2G) == 402807-1.html 402807-1-ref.html
== 403129-3.html 403129-3-ref.html
== 403129-4.html 403129-4-ref.html
random == 403134-1.html 403134-1-ref.html # bug 405377
skip-if(B2G) fails-if(Android) == 403181-1.xml 403181-1-ref.xml
skip-if(B2G) == 403181-1.xml 403181-1-ref.xml
== 403249-1a.html 403249-1-ref.html
== 403249-1b.html 403249-1-ref.html
== 403249-2a.html 403249-2-ref.html