Bug 927892 - Resolve the parsed canvas filter to a FilterDescription. r=roc

--HG--
extra : rebase_source : 46fa0017ccc4ee3ab2e0edcf143703cf0100d422
This commit is contained in:
Markus Stange 2014-09-23 17:47:18 -04:00
Родитель fc15fff085
Коммит 963040a51c
2 изменённых файлов: 62 добавлений и 0 удалений

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

@ -102,6 +102,8 @@
#include "SVGContentUtils.h"
#include "SVGImageContext.h"
#include "nsIScreenManager.h"
#include "nsFilterInstance.h"
#include "nsSVGLength2.h"
#undef free // apparently defined by some windows header, clashing with a free()
// method in SkTypes.h
@ -1858,9 +1860,47 @@ CanvasRenderingContext2D::SetFilter(const nsAString& filter, ErrorResult& error)
if (ParseFilter(filter, filterChain, error)) {
CurrentState().filterString = filter;
filterChain.SwapElements(CurrentState().filterChain);
if (mCanvasElement) {
UpdateFilter();
}
}
}
class CanvasUserSpaceMetrics : public UserSpaceMetricsWithSize
{
public:
CanvasUserSpaceMetrics(const gfx::IntSize& aSize)
: mSize(aSize)
{
}
virtual float GetEmLength() const MOZ_OVERRIDE
{ return 10.0f; }
virtual float GetExLength() const MOZ_OVERRIDE
{ return 10.0f; }
virtual gfx::Size GetSize() const MOZ_OVERRIDE
{ return Size(mSize); }
private:
gfx::IntSize mSize;
};
void
CanvasRenderingContext2D::UpdateFilter()
{
nsIPresShell* presShell = GetPresShell();
if (!presShell || presShell->IsDestroying()) {
return;
}
CurrentState().filter =
nsFilterInstance::GetFilterDescription(mCanvasElement,
CurrentState().filterChain,
CanvasUserSpaceMetrics(IntSize(mWidth, mHeight)),
gfxRect(0, 0, mWidth, mHeight),
CurrentState().filterAdditionalImages);
}
//
// rects
//

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

@ -25,6 +25,7 @@
#include "imgIEncoder.h"
#include "nsLayoutUtils.h"
#include "mozilla/EnumeratedArray.h"
#include "FilterSupport.h"
class nsGlobalWindow;
class nsXULElement;
@ -704,6 +705,12 @@ protected:
*/
mozilla::gfx::SurfaceFormat GetSurfaceFormat() const;
/**
* Update CurrentState().filter with the filter description for
* CurrentState().filterChain.
*/
void UpdateFilter();
void DrawImage(const HTMLImageOrCanvasOrVideoElement &imgElt,
double sx, double sy, double sw, double sh,
double dx, double dy, double dw, double dh,
@ -838,6 +845,16 @@ protected:
(state.shadowBlur != 0.f || state.shadowOffset.x != 0.f || state.shadowOffset.y != 0.f);
}
/**
* Returns true if the result of a drawing operation should be
* drawn with a filter.
*/
bool NeedToApplyFilter()
{
const ContextState& state = CurrentState();
return state.filter.mPrimitives.Length() > 0;
}
mozilla::gfx::CompositionOp UsedOperation()
{
if (NeedToDrawShadow()) {
@ -932,6 +949,8 @@ protected:
lineJoin(other.lineJoin),
filterString(other.filterString),
filterChain(other.filterChain),
filter(other.filter),
filterAdditionalImages(other.filterAdditionalImages),
imageSmoothingEnabled(other.imageSmoothingEnabled)
{ }
@ -992,6 +1011,9 @@ protected:
nsString filterString;
nsTArray<nsStyleFilter> filterChain;
mozilla::gfx::FilterDescription filter;
nsTArray<mozilla::RefPtr<mozilla::gfx::SourceSurface>> filterAdditionalImages;
bool imageSmoothingEnabled;
};