Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug 975346 - Part 1: General functions for EffectChains #30

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions gfx/layers/composite/CanvasLayerComposite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,28 @@ CanvasLayerComposite::CleanupResources()
mImageHost = nullptr;
}

void
CanvasLayerComposite::GenEffectChain(EffectChain& aEffect,
CompositableHost* aHost)
{
// Add layerRef
aEffect.mLayerRef = this;

// Add primary effect
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
aEffect.mPrimaryEffect = aHost->GenEffect(gfx::ToFilter(filter));
}

nsACString&
CanvasLayerComposite::PrintInfo(nsACString& aTo, const char* aPrefix)
{
Expand Down
2 changes: 2 additions & 0 deletions gfx/layers/composite/CanvasLayerComposite.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ class CanvasLayerComposite : public CanvasLayer,

virtual void CleanupResources() MOZ_OVERRIDE;

virtual void GenEffectChain(EffectChain& aEffect, CompositableHost* aHost) MOZ_OVERRIDE;

CompositableHost* GetCompositableHost() MOZ_OVERRIDE;

virtual LayerComposite* AsLayerComposite() MOZ_OVERRIDE { return this; }
Expand Down
12 changes: 12 additions & 0 deletions gfx/layers/composite/ColorLayerComposite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,17 @@ ColorLayerComposite::RenderLayer(const nsIntRect& aClipRect)
transform);
}

void
ColorLayerComposite::GenEffectChain(EffectChain& aEffect,
CompositableHost* aHost)
{
aEffect.mLayerRef = this;
gfxRGBA color = GetColor();
aEffect.mPrimaryEffect = new EffectSolidColor(gfx::Color(color.r,
color.g,
color.b,
color.a));
}

} /* layers */
} /* mozilla */
2 changes: 2 additions & 0 deletions gfx/layers/composite/ColorLayerComposite.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ class ColorLayerComposite : public ColorLayer,
virtual void RenderLayer(const nsIntRect& aClipRect) MOZ_OVERRIDE;
virtual void CleanupResources() MOZ_OVERRIDE {};

virtual void GenEffectChain(EffectChain& aEffect, CompositableHost* aHost) MOZ_OVERRIDE;

CompositableHost* GetCompositableHost() MOZ_OVERRIDE { return nullptr; }

virtual LayerComposite* AsLayerComposite() MOZ_OVERRIDE { return this; }
Expand Down
32 changes: 32 additions & 0 deletions gfx/layers/composite/CompositableHost.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -289,6 +290,14 @@ class CompositableHost

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;
Expand All @@ -301,6 +310,29 @@ class CompositableHost
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.
*
Expand Down
39 changes: 17 additions & 22 deletions gfx/layers/composite/ContentHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
}
Expand Down Expand Up @@ -288,6 +267,22 @@ ContentHostTexture::Dump(FILE* aFile,
}
#endif

TemporaryRef<TexturedEffect>
ContentHostBase::GenEffect(const gfx::Filter& aFilter)
{
RefPtr<NewTextureSource> source = GetTextureSource();
RefPtr<NewTextureSource> sourceOnWhite = GetTextureSourceOnWhite();
if (!source) {
return nullptr;
}
RefPtr<TexturedEffect> effect =
CreateTexturedEffect(source, sourceOnWhite, aFilter);
if (!effect) {
return nullptr;
}
return effect;
}

static inline void
AddWrappedRegion(const nsIntRegion& aInput, nsIntRegion& aOutput,
const nsIntSize& aSize, const nsIntPoint& aShift)
Expand Down
21 changes: 10 additions & 11 deletions gfx/layers/composite/ContentHost.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,11 @@ class ContentHostBase : public ContentHost

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()
{
Expand Down Expand Up @@ -150,7 +149,7 @@ class ContentHostTexture : public ContentHostBase
virtual void UseComponentAlphaTextures(TextureHost* aTextureOnBlack,
TextureHost* aTextureOnWhite) MOZ_OVERRIDE;

virtual bool Lock() {
virtual bool Lock() MOZ_OVERRIDE {
MOZ_ASSERT(!mLocked);
if (!mTextureHost) {
return false;
Expand All @@ -166,7 +165,7 @@ class ContentHostTexture : public ContentHostBase
mLocked = true;
return true;
}
virtual void Unlock() {
virtual void Unlock() MOZ_OVERRIDE {
MOZ_ASSERT(mLocked);
mTextureHost->Unlock();
if (mTextureHostOnWhite) {
Expand All @@ -175,11 +174,11 @@ class ContentHostTexture : public ContentHostBase
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();
Expand Down Expand Up @@ -281,20 +280,20 @@ class ContentHostIncremental : public ContentHostBase

virtual void PrintInfo(nsACString& aTo, 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:

Expand Down
47 changes: 45 additions & 2 deletions gfx/layers/composite/ImageHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ ImageHost::ImageHost(const TextureInfo& aTextureInfo)
: CompositableHost(aTextureInfo)
, mFrontBuffer(nullptr)
, mHasPictureRect(false)
, mLocked(false)
{}

ImageHost::~ImageHost() {}
Expand Down Expand Up @@ -81,12 +82,12 @@ 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;
}
Expand Down Expand Up @@ -240,5 +241,47 @@ 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;
}
RefPtr<TexturedEffect> effect = CreateTexturedEffect(mFrontBuffer->GetFormat(),
source,
aFilter);
if (!effect) {
return nullptr;
}
return effect;
}

}
}
9 changes: 9 additions & 0 deletions gfx/layers/composite/ImageHost.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,20 @@ class ImageHost : public CompositableHost
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;
};

}
Expand Down
11 changes: 11 additions & 0 deletions gfx/layers/composite/ImageLayerComposite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,17 @@ ImageLayerComposite::CleanupResources()
mImageHost = nullptr;
}

void
ImageLayerComposite::GenEffectChain(EffectChain& aEffect,
CompositableHost* aHost)
{
// Add layerRef
aEffect.mLayerRef = this;

// Add primary effect, if the buffer in aHost is locked.
aEffect.mPrimaryEffect = aHost->GenEffect(gfx::ToFilter(mFilter));
}

nsACString&
ImageLayerComposite::PrintInfo(nsACString& aTo, const char* aPrefix)
{
Expand Down
2 changes: 2 additions & 0 deletions gfx/layers/composite/ImageLayerComposite.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ class ImageLayerComposite : public ImageLayer,

virtual void CleanupResources() MOZ_OVERRIDE;

virtual void GenEffectChain(EffectChain& aEffect, CompositableHost* aHost) MOZ_OVERRIDE;

CompositableHost* GetCompositableHost() MOZ_OVERRIDE;

virtual LayerComposite* AsLayerComposite() MOZ_OVERRIDE { return this; }
Expand Down
6 changes: 4 additions & 2 deletions gfx/layers/composite/LayerManagerComposite.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class LayerManagerComposite : public LayerManager
public:
LayerManagerComposite(Compositor* aCompositor);
~LayerManagerComposite();

virtual void Destroy() MOZ_OVERRIDE;

/**
Expand Down Expand Up @@ -267,7 +267,7 @@ class LayerManagerComposite : public LayerManager
RefPtr<Compositor> mCompositor;
nsAutoPtr<LayerProperties> mClonedLayerTreeProperties;

/**
/**
* Context target, nullptr when drawing directly to our swap chain.
*/
RefPtr<gfx::DrawTarget> mTarget;
Expand Down Expand Up @@ -341,6 +341,8 @@ class LayerComposite

void AddBlendModeEffect(EffectChain& aEffectChain);

virtual void GenEffectChain(EffectChain& aEffect, CompositableHost* aHost) { }

/**
* The following methods are
*
Expand Down
Loading