mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 975346 - Part 1: General functions for Effects. r=dglastonbury
1. Support GenEffectChain() for LayerComposite. Each layer can use this API to gen the EffectChain (only primary effect now) 2. Support GenEffect() for CompositableHost. 3. Move AutoLock to compositeHost.
This commit is contained in:
parent
e99f23fe2a
commit
fc4b3f1b0b
@ -87,18 +87,6 @@ CanvasLayerComposite::RenderLayer(const nsIntRect& aClipRect)
|
||||
}
|
||||
#endif
|
||||
|
||||
GraphicsFilter filter = mFilter;
|
||||
#ifdef ANDROID
|
||||
// Bug 691354
|
||||
// Using the LINEAR filter we get unexplained artifacts.
|
||||
// Use NEAREST when no scaling is required.
|
||||
Matrix matrix;
|
||||
bool is2D = GetEffectiveTransform().Is2D(&matrix);
|
||||
if (is2D && !ThebesMatrix(matrix).HasNonTranslationOrFlip()) {
|
||||
filter = GraphicsFilter::FILTER_NEAREST;
|
||||
}
|
||||
#endif
|
||||
|
||||
EffectChain effectChain(this);
|
||||
AddBlendModeEffect(effectChain);
|
||||
|
||||
@ -108,7 +96,7 @@ CanvasLayerComposite::RenderLayer(const nsIntRect& aClipRect)
|
||||
mImageHost->Composite(effectChain,
|
||||
GetEffectiveOpacity(),
|
||||
GetEffectiveTransform(),
|
||||
gfx::ToFilter(filter),
|
||||
GetEffectFilter(),
|
||||
clipRect);
|
||||
mImageHost->BumpFlashCounter();
|
||||
}
|
||||
@ -132,6 +120,30 @@ CanvasLayerComposite::CleanupResources()
|
||||
mImageHost = nullptr;
|
||||
}
|
||||
|
||||
gfx::Filter
|
||||
CanvasLayerComposite::GetEffectFilter()
|
||||
{
|
||||
GraphicsFilter filter = mFilter;
|
||||
#ifdef ANDROID
|
||||
// Bug 691354
|
||||
// Using the LINEAR filter we get unexplained artifacts.
|
||||
// Use NEAREST when no scaling is required.
|
||||
Matrix matrix;
|
||||
bool is2D = GetEffectiveTransform().Is2D(&matrix);
|
||||
if (is2D && !ThebesMatrix(matrix).HasNonTranslationOrFlip()) {
|
||||
filter = GraphicsFilter::FILTER_NEAREST;
|
||||
}
|
||||
#endif
|
||||
return gfx::ToFilter(filter);
|
||||
}
|
||||
|
||||
void
|
||||
CanvasLayerComposite::GenEffectChain(EffectChain& aEffect)
|
||||
{
|
||||
aEffect.mLayerRef = this;
|
||||
aEffect.mPrimaryEffect = mImageHost->GenEffect(GetEffectFilter());
|
||||
}
|
||||
|
||||
void
|
||||
CanvasLayerComposite::PrintInfo(std::stringstream& aStream, const char* aPrefix)
|
||||
{
|
||||
|
@ -52,6 +52,8 @@ public:
|
||||
|
||||
virtual void CleanupResources() MOZ_OVERRIDE;
|
||||
|
||||
virtual void GenEffectChain(EffectChain& aEffect) MOZ_OVERRIDE;
|
||||
|
||||
CompositableHost* GetCompositableHost() MOZ_OVERRIDE;
|
||||
|
||||
virtual LayerComposite* AsLayerComposite() MOZ_OVERRIDE { return this; }
|
||||
@ -63,6 +65,9 @@ public:
|
||||
protected:
|
||||
virtual void PrintInfo(std::stringstream& aStream, const char* aPrefix) MOZ_OVERRIDE;
|
||||
|
||||
private:
|
||||
gfx::Filter GetEffectFilter();
|
||||
|
||||
private:
|
||||
RefPtr<CompositableHost> mImageHost;
|
||||
};
|
||||
|
@ -24,11 +24,9 @@ void
|
||||
ColorLayerComposite::RenderLayer(const nsIntRect& aClipRect)
|
||||
{
|
||||
EffectChain effects(this);
|
||||
gfxRGBA color(GetColor());
|
||||
effects.mPrimaryEffect = new EffectSolidColor(gfx::Color(color.r,
|
||||
color.g,
|
||||
color.b,
|
||||
color.a));
|
||||
|
||||
GenEffectChain(effects);
|
||||
|
||||
nsIntRect boundRect = GetBounds();
|
||||
|
||||
LayerManagerComposite::AutoAddMaskEffect autoMaskEffect(GetMaskLayer(),
|
||||
@ -50,5 +48,16 @@ ColorLayerComposite::RenderLayer(const nsIntRect& aClipRect)
|
||||
transform);
|
||||
}
|
||||
|
||||
void
|
||||
ColorLayerComposite::GenEffectChain(EffectChain& aEffect)
|
||||
{
|
||||
aEffect.mLayerRef = this;
|
||||
gfxRGBA color(GetColor());
|
||||
aEffect.mPrimaryEffect = new EffectSolidColor(gfx::Color(color.r,
|
||||
color.g,
|
||||
color.b,
|
||||
color.a));
|
||||
}
|
||||
|
||||
} /* layers */
|
||||
} /* mozilla */
|
||||
|
@ -44,6 +44,8 @@ public:
|
||||
virtual void RenderLayer(const nsIntRect& aClipRect) MOZ_OVERRIDE;
|
||||
virtual void CleanupResources() MOZ_OVERRIDE {};
|
||||
|
||||
virtual void GenEffectChain(EffectChain& aEffect) MOZ_OVERRIDE;
|
||||
|
||||
CompositableHost* GetCompositableHost() MOZ_OVERRIDE { return nullptr; }
|
||||
|
||||
virtual LayerComposite* AsLayerComposite() MOZ_OVERRIDE { return this; }
|
||||
|
@ -17,6 +17,7 @@
|
||||
#include "mozilla/gfx/Types.h" // for Filter
|
||||
#include "mozilla/ipc/ProtocolUtils.h"
|
||||
#include "mozilla/layers/CompositorTypes.h" // for TextureInfo, etc
|
||||
#include "mozilla/layers/Effects.h" // for Texture Effect
|
||||
#include "mozilla/layers/LayersTypes.h" // for LayerRenderState, etc
|
||||
#include "mozilla/layers/TextureHost.h" // for TextureHost
|
||||
#include "mozilla/mozalloc.h" // for operator delete
|
||||
@ -289,6 +290,14 @@ public:
|
||||
|
||||
void SetAsyncID(uint64_t aID) { mAsyncID = aID; }
|
||||
|
||||
virtual bool Lock() { return false; }
|
||||
|
||||
virtual void Unlock() { }
|
||||
|
||||
virtual TemporaryRef<TexturedEffect> GenEffect(const gfx::Filter& aFilter) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
protected:
|
||||
TextureInfo mTextureInfo;
|
||||
uint64_t mAsyncID;
|
||||
@ -301,6 +310,29 @@ protected:
|
||||
bool mKeepAttached;
|
||||
};
|
||||
|
||||
class AutoLockCompositableHost MOZ_FINAL
|
||||
{
|
||||
public:
|
||||
AutoLockCompositableHost(CompositableHost* aHost)
|
||||
: mHost(aHost)
|
||||
{
|
||||
mSucceeded = mHost->Lock();
|
||||
}
|
||||
|
||||
~AutoLockCompositableHost()
|
||||
{
|
||||
if (mSucceeded) {
|
||||
mHost->Unlock();
|
||||
}
|
||||
}
|
||||
|
||||
bool Failed() const { return !mSucceeded; }
|
||||
|
||||
private:
|
||||
RefPtr<CompositableHost> mHost;
|
||||
bool mSucceeded;
|
||||
};
|
||||
|
||||
/**
|
||||
* Global CompositableMap, to use in the compositor thread only.
|
||||
*
|
||||
|
@ -35,27 +35,6 @@ ContentHostBase::~ContentHostBase()
|
||||
{
|
||||
}
|
||||
|
||||
struct AutoLockContentHost
|
||||
{
|
||||
AutoLockContentHost(ContentHostBase* aHost)
|
||||
: mHost(aHost)
|
||||
{
|
||||
mSucceeded = mHost->Lock();
|
||||
}
|
||||
|
||||
~AutoLockContentHost()
|
||||
{
|
||||
if (mSucceeded) {
|
||||
mHost->Unlock();
|
||||
}
|
||||
}
|
||||
|
||||
bool Failed() { return !mSucceeded; }
|
||||
|
||||
ContentHostBase* mHost;
|
||||
bool mSucceeded;
|
||||
};
|
||||
|
||||
void
|
||||
ContentHostBase::Composite(EffectChain& aEffectChain,
|
||||
float aOpacity,
|
||||
@ -67,7 +46,7 @@ ContentHostBase::Composite(EffectChain& aEffectChain,
|
||||
{
|
||||
NS_ASSERTION(aVisibleRegion, "Requires a visible region");
|
||||
|
||||
AutoLockContentHost lock(this);
|
||||
AutoLockCompositableHost lock(this);
|
||||
if (lock.Failed()) {
|
||||
return;
|
||||
}
|
||||
@ -78,9 +57,8 @@ ContentHostBase::Composite(EffectChain& aEffectChain,
|
||||
if (!source) {
|
||||
return;
|
||||
}
|
||||
RefPtr<TexturedEffect> effect =
|
||||
CreateTexturedEffect(source, sourceOnWhite, aFilter, true);
|
||||
|
||||
RefPtr<TexturedEffect> effect = GenEffect(aFilter);
|
||||
if (!effect) {
|
||||
return;
|
||||
}
|
||||
@ -229,6 +207,16 @@ ContentHostBase::Composite(EffectChain& aEffectChain,
|
||||
aTransform, mFlashCounter);
|
||||
}
|
||||
|
||||
TemporaryRef<TexturedEffect>
|
||||
ContentHostBase::GenEffect(const gfx::Filter& aFilter)
|
||||
{
|
||||
RefPtr<NewTextureSource> source = GetTextureSource();
|
||||
RefPtr<NewTextureSource> sourceOnWhite = GetTextureSourceOnWhite();
|
||||
if (!source) {
|
||||
return nullptr;
|
||||
}
|
||||
return CreateTexturedEffect(source, sourceOnWhite, aFilter, true);
|
||||
}
|
||||
|
||||
void
|
||||
ContentHostTexture::UseTextureHost(TextureHost* aTexture)
|
||||
|
@ -102,12 +102,11 @@ public:
|
||||
|
||||
virtual void SetPaintWillResample(bool aResample) { mPaintWillResample = aResample; }
|
||||
|
||||
virtual bool Lock() = 0;
|
||||
virtual void Unlock() = 0;
|
||||
|
||||
virtual NewTextureSource* GetTextureSource() = 0;
|
||||
virtual NewTextureSource* GetTextureSourceOnWhite() = 0;
|
||||
|
||||
virtual TemporaryRef<TexturedEffect> GenEffect(const gfx::Filter& aFilter) MOZ_OVERRIDE;
|
||||
|
||||
protected:
|
||||
virtual nsIntPoint GetOriginOffset()
|
||||
{
|
||||
@ -150,7 +149,7 @@ public:
|
||||
virtual void UseComponentAlphaTextures(TextureHost* aTextureOnBlack,
|
||||
TextureHost* aTextureOnWhite) MOZ_OVERRIDE;
|
||||
|
||||
virtual bool Lock() {
|
||||
virtual bool Lock() MOZ_OVERRIDE {
|
||||
MOZ_ASSERT(!mLocked);
|
||||
if (!mTextureHost) {
|
||||
return false;
|
||||
@ -166,7 +165,7 @@ public:
|
||||
mLocked = true;
|
||||
return true;
|
||||
}
|
||||
virtual void Unlock() {
|
||||
virtual void Unlock() MOZ_OVERRIDE {
|
||||
MOZ_ASSERT(mLocked);
|
||||
mTextureHost->Unlock();
|
||||
if (mTextureHostOnWhite) {
|
||||
@ -175,11 +174,11 @@ public:
|
||||
mLocked = false;
|
||||
}
|
||||
|
||||
virtual NewTextureSource* GetTextureSource() {
|
||||
virtual NewTextureSource* GetTextureSource() MOZ_OVERRIDE {
|
||||
MOZ_ASSERT(mLocked);
|
||||
return mTextureHost->GetTextureSources();
|
||||
}
|
||||
virtual NewTextureSource* GetTextureSourceOnWhite() {
|
||||
virtual NewTextureSource* GetTextureSourceOnWhite() MOZ_OVERRIDE {
|
||||
MOZ_ASSERT(mLocked);
|
||||
if (mTextureHostOnWhite) {
|
||||
return mTextureHostOnWhite->GetTextureSources();
|
||||
@ -281,20 +280,20 @@ public:
|
||||
|
||||
virtual void PrintInfo(std::stringstream& aStream, const char* aPrefix) MOZ_OVERRIDE;
|
||||
|
||||
virtual bool Lock() {
|
||||
virtual bool Lock() MOZ_OVERRIDE {
|
||||
MOZ_ASSERT(!mLocked);
|
||||
ProcessTextureUpdates();
|
||||
mLocked = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual void Unlock() {
|
||||
virtual void Unlock() MOZ_OVERRIDE {
|
||||
MOZ_ASSERT(mLocked);
|
||||
mLocked = false;
|
||||
}
|
||||
|
||||
virtual NewTextureSource* GetTextureSource();
|
||||
virtual NewTextureSource* GetTextureSourceOnWhite();
|
||||
virtual NewTextureSource* GetTextureSource() MOZ_OVERRIDE;
|
||||
virtual NewTextureSource* GetTextureSourceOnWhite() MOZ_OVERRIDE;
|
||||
|
||||
private:
|
||||
|
||||
|
@ -31,6 +31,7 @@ ImageHost::ImageHost(const TextureInfo& aTextureInfo)
|
||||
: CompositableHost(aTextureInfo)
|
||||
, mFrontBuffer(nullptr)
|
||||
, mHasPictureRect(false)
|
||||
, mLocked(false)
|
||||
{}
|
||||
|
||||
ImageHost::~ImageHost() {}
|
||||
@ -81,24 +82,17 @@ ImageHost::Composite(EffectChain& aEffectChain,
|
||||
mFrontBuffer->SetCompositor(GetCompositor());
|
||||
mFrontBuffer->SetCompositableBackendSpecificData(GetCompositableBackendSpecificData());
|
||||
|
||||
AutoLockTextureHost autoLock(mFrontBuffer);
|
||||
AutoLockCompositableHost autoLock(this);
|
||||
if (autoLock.Failed()) {
|
||||
NS_WARNING("failed to lock front buffer");
|
||||
return;
|
||||
}
|
||||
RefPtr<NewTextureSource> source = mFrontBuffer->GetTextureSources();
|
||||
RefPtr<NewTextureSource> source = GetTextureSource();
|
||||
if (!source) {
|
||||
return;
|
||||
}
|
||||
|
||||
bool isAlphaPremultiplied = true;
|
||||
if (mFrontBuffer->GetFlags() & TextureFlags::NON_PREMULTIPLIED)
|
||||
isAlphaPremultiplied = false;
|
||||
|
||||
RefPtr<TexturedEffect> effect = CreateTexturedEffect(mFrontBuffer->GetFormat(),
|
||||
source,
|
||||
aFilter,
|
||||
isAlphaPremultiplied);
|
||||
RefPtr<TexturedEffect> effect = GenEffect(aFilter);
|
||||
if (!effect) {
|
||||
return;
|
||||
}
|
||||
@ -243,5 +237,48 @@ ImageHost::GetAsSurface()
|
||||
}
|
||||
#endif
|
||||
|
||||
bool
|
||||
ImageHost::Lock()
|
||||
{
|
||||
MOZ_ASSERT(!mLocked);
|
||||
if (!mFrontBuffer->Lock()) {
|
||||
return false;
|
||||
}
|
||||
mLocked = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
ImageHost::Unlock()
|
||||
{
|
||||
MOZ_ASSERT(mLocked);
|
||||
mFrontBuffer->Unlock();
|
||||
mLocked = false;
|
||||
}
|
||||
|
||||
TemporaryRef<NewTextureSource>
|
||||
ImageHost::GetTextureSource()
|
||||
{
|
||||
MOZ_ASSERT(mLocked);
|
||||
return mFrontBuffer->GetTextureSources();
|
||||
}
|
||||
|
||||
TemporaryRef<TexturedEffect>
|
||||
ImageHost::GenEffect(const gfx::Filter& aFilter)
|
||||
{
|
||||
RefPtr<NewTextureSource> source = GetTextureSource();
|
||||
if (!source) {
|
||||
return nullptr;
|
||||
}
|
||||
bool isAlphaPremultiplied = true;
|
||||
if (mFrontBuffer->GetFlags() & TextureFlags::NON_PREMULTIPLIED)
|
||||
isAlphaPremultiplied = false;
|
||||
|
||||
return CreateTexturedEffect(mFrontBuffer->GetFormat(),
|
||||
source,
|
||||
aFilter,
|
||||
isAlphaPremultiplied);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -79,11 +79,20 @@ public:
|
||||
virtual TemporaryRef<gfx::DataSourceSurface> GetAsSurface() MOZ_OVERRIDE;
|
||||
#endif
|
||||
|
||||
virtual bool Lock() MOZ_OVERRIDE;
|
||||
|
||||
virtual void Unlock() MOZ_OVERRIDE;
|
||||
|
||||
virtual TemporaryRef<NewTextureSource> GetTextureSource();
|
||||
|
||||
virtual TemporaryRef<TexturedEffect> GenEffect(const gfx::Filter& aFilter) MOZ_OVERRIDE;
|
||||
|
||||
protected:
|
||||
|
||||
RefPtr<TextureHost> mFrontBuffer;
|
||||
nsIntRect mPictureRect;
|
||||
bool mHasPictureRect;
|
||||
bool mLocked;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -107,7 +107,7 @@ ImageLayerComposite::RenderLayer(const nsIntRect& aClipRect)
|
||||
mImageHost->Composite(effectChain,
|
||||
GetEffectiveOpacity(),
|
||||
GetEffectiveTransform(),
|
||||
gfx::ToFilter(mFilter),
|
||||
GetEffectFilter(),
|
||||
clipRect);
|
||||
mImageHost->BumpFlashCounter();
|
||||
}
|
||||
@ -161,6 +161,19 @@ ImageLayerComposite::CleanupResources()
|
||||
mImageHost = nullptr;
|
||||
}
|
||||
|
||||
gfx::Filter
|
||||
ImageLayerComposite::GetEffectFilter()
|
||||
{
|
||||
return gfx::ToFilter(mFilter);
|
||||
}
|
||||
|
||||
void
|
||||
ImageLayerComposite::GenEffectChain(EffectChain& aEffect)
|
||||
{
|
||||
aEffect.mLayerRef = this;
|
||||
aEffect.mPrimaryEffect = mImageHost->GenEffect(GetEffectFilter());
|
||||
}
|
||||
|
||||
void
|
||||
ImageLayerComposite::PrintInfo(std::stringstream& aStream, const char* aPrefix)
|
||||
{
|
||||
|
@ -51,6 +51,8 @@ public:
|
||||
|
||||
CompositableHost* GetCompositableHost() MOZ_OVERRIDE;
|
||||
|
||||
virtual void GenEffectChain(EffectChain& aEffect) MOZ_OVERRIDE;
|
||||
|
||||
virtual LayerComposite* AsLayerComposite() MOZ_OVERRIDE { return this; }
|
||||
|
||||
virtual const char* Name() const { return "ImageLayerComposite"; }
|
||||
@ -58,6 +60,9 @@ public:
|
||||
protected:
|
||||
virtual void PrintInfo(std::stringstream& aStream, const char* aPrefix) MOZ_OVERRIDE;
|
||||
|
||||
private:
|
||||
gfx::Filter GetEffectFilter();
|
||||
|
||||
private:
|
||||
RefPtr<CompositableHost> mImageHost;
|
||||
};
|
||||
|
@ -74,7 +74,7 @@ class LayerManagerComposite : public LayerManager
|
||||
public:
|
||||
LayerManagerComposite(Compositor* aCompositor);
|
||||
~LayerManagerComposite();
|
||||
|
||||
|
||||
virtual void Destroy() MOZ_OVERRIDE;
|
||||
|
||||
/**
|
||||
@ -267,7 +267,7 @@ private:
|
||||
RefPtr<Compositor> mCompositor;
|
||||
nsAutoPtr<LayerProperties> mClonedLayerTreeProperties;
|
||||
|
||||
/**
|
||||
/**
|
||||
* Context target, nullptr when drawing directly to our swap chain.
|
||||
*/
|
||||
RefPtr<gfx::DrawTarget> mTarget;
|
||||
@ -336,11 +336,12 @@ public:
|
||||
|
||||
virtual TiledLayerComposer* GetTiledLayerComposer() { return nullptr; }
|
||||
|
||||
|
||||
virtual void DestroyFrontBuffer() { }
|
||||
|
||||
void AddBlendModeEffect(EffectChain& aEffectChain);
|
||||
|
||||
virtual void GenEffectChain(EffectChain& aEffect) { }
|
||||
|
||||
/**
|
||||
* The following methods are
|
||||
*
|
||||
|
@ -147,7 +147,7 @@ ThebesLayerComposite::RenderLayer(const nsIntRect& aClipRect)
|
||||
mBuffer->Composite(effectChain,
|
||||
GetEffectiveOpacity(),
|
||||
GetEffectiveTransform(),
|
||||
gfx::Filter::LINEAR,
|
||||
GetEffectFilter(),
|
||||
clipRect,
|
||||
&visibleRegion,
|
||||
mRequiresTiledProperties ? &tiledLayerProps
|
||||
@ -180,6 +180,13 @@ ThebesLayerComposite::CleanupResources()
|
||||
mBuffer = nullptr;
|
||||
}
|
||||
|
||||
void
|
||||
ThebesLayerComposite::GenEffectChain(EffectChain& aEffect)
|
||||
{
|
||||
aEffect.mLayerRef = this;
|
||||
aEffect.mPrimaryEffect = mBuffer->GenEffect(GetEffectFilter());
|
||||
}
|
||||
|
||||
CSSToScreenScale
|
||||
ThebesLayerComposite::GetEffectiveResolution()
|
||||
{
|
||||
|
@ -56,6 +56,8 @@ public:
|
||||
|
||||
virtual void CleanupResources() MOZ_OVERRIDE;
|
||||
|
||||
virtual void GenEffectChain(EffectChain& aEffect) MOZ_OVERRIDE;
|
||||
|
||||
virtual bool SetCompositableHost(CompositableHost* aHost) MOZ_OVERRIDE;
|
||||
|
||||
virtual LayerComposite* AsLayerComposite() MOZ_OVERRIDE { return this; }
|
||||
@ -81,8 +83,11 @@ protected:
|
||||
virtual void PrintInfo(std::stringstream& aStream, const char* aPrefix) MOZ_OVERRIDE;
|
||||
|
||||
private:
|
||||
gfx::Filter GetEffectFilter() { return gfx::Filter::LINEAR; }
|
||||
|
||||
CSSToScreenScale GetEffectiveResolution();
|
||||
|
||||
private:
|
||||
RefPtr<ContentHost> mBuffer;
|
||||
bool mRequiresTiledProperties;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user