Bug 1059583 - Add CanvasLayer::MustLayerUpdateBeSynchronous. - r=kamidphish,mattwoodrow

This commit is contained in:
Jeff Gilbert 2014-09-09 16:20:08 -07:00
parent f4d3720459
commit 1dd08fbe33
6 changed files with 54 additions and 13 deletions

View File

@ -1170,6 +1170,18 @@ private:
} // end namespace mozilla
bool
WebGLContext::HasAlpha() const
{
return gl->Caps().alpha;
}
static bool
IsElementFullscreen(dom::Element* elem)
{
return elem->State().HasState(NS_EVENT_STATE_FULL_SCREEN);
}
already_AddRefed<layers::CanvasLayer>
WebGLContext::GetCanvasLayer(nsDisplayListBuilder* aBuilder,
CanvasLayer *aOldLayer,
@ -1212,14 +1224,20 @@ WebGLContext::GetCanvasLayer(nsDisplayListBuilder* aBuilder,
canvasLayer->SetUserData(&gWebGLLayerUserData, userData);
CanvasLayer::Data data;
data.mGLContext = gl;
data.mSize = nsIntSize(mWidth, mHeight);
data.mHasAlpha = gl->Caps().alpha;
data.mHasAlpha = HasAlpha();
data.mIsGLAlphaPremult = IsPremultAlpha() || !data.mHasAlpha;
data.mIsElemFullscreen = IsElementFullscreen(GetCanvas());
canvasLayer->Initialize(data);
uint32_t flags = gl->Caps().alpha ? 0 : Layer::CONTENT_OPAQUE;
canvasLayer->SetContentFlags(flags);
if (!data.mHasAlpha) {
uint32_t flags = canvasLayer->GetContentFlags();
flags |= Layer::CONTENT_OPAQUE;
canvasLayer->SetContentFlags(flags);
}
canvasLayer->Updated();
mResetLayer = false;

View File

@ -186,7 +186,7 @@ public:
mozilla::TemporaryRef<mozilla::gfx::SourceSurface> GetSurfaceSnapshot(bool* aPremultAlpha) MOZ_OVERRIDE;
NS_IMETHOD SetIsOpaque(bool b) MOZ_OVERRIDE { return NS_OK; };
bool GetIsOpaque() MOZ_OVERRIDE { return false; }
bool GetIsOpaque() MOZ_OVERRIDE { return !HasAlpha(); }
NS_IMETHOD SetContextOptions(JSContext* aCx,
JS::Handle<JS::Value> aOptions) MOZ_OVERRIDE;
@ -248,6 +248,7 @@ public:
gl::GLContext* GL() const { return gl; }
bool IsPremultAlpha() const { return mOptions.premultipliedAlpha; }
bool HasAlpha() const;
bool PresentScreenBuffer();

View File

@ -325,6 +325,15 @@ public:
} // end anonymous namespace
static bool
IsNoNeedForPremultForFormats(WebGLTexelFormat srcFormat,
WebGLTexelFormat dstFormat)
{
return !HasAlpha(srcFormat) ||
!HasColor(srcFormat) ||
!HasColor(dstFormat);
}
void
WebGLContext::ConvertImage(size_t width, size_t height, size_t srcStride, size_t dstStride,
const uint8_t* src, uint8_t *dst,
@ -335,13 +344,11 @@ WebGLContext::ConvertImage(size_t width, size_t height, size_t srcStride, size_t
if (width <= 0 || height <= 0)
return;
const bool FormatsRequireNoPremultiplicationOp =
!HasAlpha(srcFormat) ||
!HasColor(srcFormat) ||
!HasColor(dstFormat);
const bool noNeedForPremultFromFormats = IsNoNeedForPremultForFormats(srcFormat,
dstFormat);
if (srcFormat == dstFormat &&
(FormatsRequireNoPremultiplicationOp || srcPremultiplied == dstPremultiplied))
(noNeedForPremultFromFormats || srcPremultiplied == dstPremultiplied))
{
// fast exit path: we just have to memcpy all the rows.
//
@ -381,7 +388,7 @@ WebGLContext::ConvertImage(size_t width, size_t height, size_t srcStride, size_t
WebGLImageConverter converter(width, height, src, dstStart, srcStride, signedDstStride);
const WebGLTexelPremultiplicationOp premultiplicationOp
= FormatsRequireNoPremultiplicationOp ? WebGLTexelPremultiplicationOp::None
= noNeedForPremultFromFormats ? WebGLTexelPremultiplicationOp::None
: (!srcPremultiplied && dstPremultiplied) ? WebGLTexelPremultiplicationOp::Premultiply
: (srcPremultiplied && !dstPremultiplied) ? WebGLTexelPremultiplicationOp::Unpremultiply
: WebGLTexelPremultiplicationOp::None;

View File

@ -47,6 +47,8 @@ CopyableCanvasLayer::Initialize(const Data& aData)
{
NS_ASSERTION(mSurface == nullptr, "BasicCanvasLayer::Initialize called twice!");
mIsElemFullscreen = aData.mIsElemFullscreen;
if (aData.mGLContext) {
mGLContext = aData.mGLContext;
mStream = aData.mStream;

View File

@ -784,7 +784,7 @@ Layer::GetEffectiveOpacity()
}
return opacity;
}
CompositionOp
Layer::GetEffectiveMixBlendMode()
{
@ -1188,7 +1188,7 @@ RefLayer::FillSpecificAttributes(SpecificLayerAttributes& aAttrs)
aAttrs = RefLayerAttributes(GetReferentId());
}
/**
/**
* StartFrameTimeRecording, together with StopFrameTimeRecording
* enable recording of frame intervals.
*
@ -1979,5 +1979,11 @@ ToOutsideIntRect(const gfxRect &aRect)
PRLogModuleInfo* LayerManager::sLog;
bool
CanvasLayer::MustLayerUpdateBeSynchronous() const
{
return !mIsElemFullscreen;
}
} // namespace layers
} // namespace mozilla

View File

@ -1177,7 +1177,7 @@ public:
float GetOpacity() { return mOpacity; }
gfx::CompositionOp GetMixBlendMode() const { return mMixBlendMode; }
const nsIntRect* GetClipRect() { return mUseClipRect ? &mClipRect : nullptr; }
uint32_t GetContentFlags() { return mContentFlags; }
uint32_t GetContentFlags() const { return mContentFlags; }
const nsIntRegion& GetVisibleRegion() const { return mVisibleRegion; }
const FrameMetrics& GetFrameMetrics(uint32_t aIndex) const;
uint32_t GetFrameMetricsCount() const { return mFrameMetrics.Length(); }
@ -1999,6 +1999,7 @@ public:
, mSize(0,0)
, mHasAlpha(false)
, mIsGLAlphaPremult(true)
, mIsElemFullscreen(false)
{ }
// One of these two must be specified for Canvas2D, but never both
@ -2019,6 +2020,8 @@ public:
// Whether mGLContext contains data that is alpha-premultiplied.
bool mIsGLAlphaPremult;
bool mIsElemFullscreen;
};
/**
@ -2120,6 +2123,8 @@ public:
ComputeEffectiveTransformForMaskLayer(aTransformToSurface);
}
bool MustLayerUpdateBeSynchronous() const;
protected:
CanvasLayer(LayerManager* aManager, void* aImplData)
: Layer(aManager, aImplData)
@ -2129,6 +2134,7 @@ protected:
, mPostTransCallbackData(nullptr)
, mFilter(GraphicsFilter::FILTER_GOOD)
, mDirty(false)
, mIsElemFullscreen(false)
{}
virtual void PrintInfo(std::stringstream& aStream, const char* aPrefix);
@ -2151,6 +2157,7 @@ protected:
DidTransactionCallback mPostTransCallback;
void* mPostTransCallbackData;
GraphicsFilter mFilter;
bool mIsElemFullscreen;
private:
/**