Bug 1364302 - Fix HoldExternalImage() handling r=nical

This commit is contained in:
sotaro 2017-05-15 22:18:54 -07:00
Родитель e853c9b0a6
Коммит 3121f12bfb
4 изменённых файлов: 65 добавлений и 25 удалений

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

@ -470,7 +470,6 @@ WebRenderBridgeParent::ProcessWebRenderCommands(const gfx::IntSize &aSize,
mApi->AddExternalImageHandle(key,
descriptor,
wrTexture->GetExternalImageKey());
mCompositableHolder->HoldExternalImage(mPipelineId, aEpoch, texture->AsWebRenderTextureHost());
} else {
// XXX handling YUV
gfx::SurfaceFormat format =
@ -479,7 +478,6 @@ WebRenderBridgeParent::ProcessWebRenderCommands(const gfx::IntSize &aSize,
mApi->AddExternalImageBuffer(key,
descriptor,
wrTexture->GetExternalImageKey());
mCompositableHolder->HoldExternalImage(mPipelineId, aEpoch, texture->AsWebRenderTextureHost());
}
break;
@ -627,7 +625,7 @@ WebRenderBridgeParent::RecvAddExternalImageId(const ExternalImageId& aImageId,
return IPC_OK();
}
wrHost->SetWrCompositableHolder(mCompositableHolder);
wrHost->SetWrBridge(this);
mExternalImageIds.Put(wr::AsUint64(aImageId), wrHost);
return IPC_OK();
@ -650,7 +648,7 @@ WebRenderBridgeParent::RecvAddExternalImageIdForCompositable(const ExternalImage
return IPC_OK();
}
wrHost->SetWrCompositableHolder(mCompositableHolder);
wrHost->SetWrBridge(this);
mExternalImageIds.Put(wr::AsUint64(aImageId), wrHost);
return IPC_OK();
@ -665,7 +663,7 @@ WebRenderBridgeParent::RecvRemoveExternalImageId(const ExternalImageId& aImageId
MOZ_ASSERT(mExternalImageIds.Get(wr::AsUint64(aImageId)).get());
WebRenderImageHost* wrHost = mExternalImageIds.Get(wr::AsUint64(aImageId)).get();
if (wrHost) {
wrHost->SetWrCompositableHolder(nullptr);
wrHost->SetWrBridge(nullptr);
}
mExternalImageIds.Remove(wr::AsUint64(aImageId));
@ -878,11 +876,11 @@ WebRenderBridgeParent::ClearResources()
DeleteOldImages();
}
}
mCompositableHolder->RemovePipeline(mPipelineId);
for (auto iter = mExternalImageIds.Iter(); !iter.Done(); iter.Next()) {
iter.Data()->SetWrCompositableHolder(nullptr);
iter.Data()->SetWrBridge(nullptr);
}
mExternalImageIds.Clear();
mCompositableHolder->RemovePipeline(mPipelineId);
if (mWidget && mCompositorScheduler) {
mCompositorScheduler->Destroy();

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

@ -53,6 +53,7 @@ public:
wr::PipelineId PipelineId() { return mPipelineId; }
wr::WebRenderAPI* GetWebRenderAPI() { return mApi; }
wr::Epoch WrEpoch() { return wr::NewEpoch(mWrEpoch); }
WebRenderCompositableHolder* CompositableHolder() { return mCompositableHolder; }
CompositorVsyncScheduler* CompositorScheduler() { return mCompositorScheduler.get(); }
@ -171,9 +172,12 @@ private:
virtual ~WebRenderBridgeParent();
void DeleteOldImages();
void ProcessWebRenderCommands(const gfx::IntSize &aSize, InfallibleTArray<WebRenderParentCommand>& commands, const wr::Epoch& aEpoch,
const WrSize& aContentSize, const ByteBuffer& dl,
const WrBuiltDisplayListDescriptor& dlDesc);
void ProcessWebRenderCommands(const gfx::IntSize &aSize,
InfallibleTArray<WebRenderParentCommand>& commands,
const wr::Epoch& aEpoch,
const WrSize& aContentSize,
const ByteBuffer& dl,
const WrBuiltDisplayListDescriptor& dlDesc);
void ScheduleComposition();
void ClearResources();
uint64_t GetChildLayerObserverEpoch() const { return mChildLayerObserverEpoch; }

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

@ -9,6 +9,7 @@
#include "mozilla/layers/Compositor.h" // for Compositor
#include "mozilla/layers/Effects.h" // for TexturedEffect, Effect, etc
#include "mozilla/layers/LayerManagerComposite.h" // for TexturedEffect, Effect, etc
#include "mozilla/layers/WebRenderBridgeParent.h"
#include "mozilla/layers/WebRenderCompositableHolder.h"
#include "nsAString.h"
#include "nsDebug.h" // for NS_WARNING, NS_ASSERTION
@ -26,12 +27,12 @@ class ISurfaceAllocator;
WebRenderImageHost::WebRenderImageHost(const TextureInfo& aTextureInfo)
: CompositableHost(aTextureInfo)
, ImageComposite()
, mWrCompositableHolder(nullptr)
, mWrBridge(nullptr)
{}
WebRenderImageHost::~WebRenderImageHost()
{
MOZ_ASSERT(!mWrCompositableHolder);
MOZ_ASSERT(!mWrBridge);
}
void
@ -70,12 +71,13 @@ WebRenderImageHost::UseTextureHost(const nsTArray<TimedTexture>& aTextures)
// slightly different timestamps in order to sync with the audio clock. This
// means that any CompositeUntil() call we made in Composite() may no longer
// guarantee that we'll composite until the next frame is ready. Fix that here.
if (mWrCompositableHolder && mLastFrameID >= 0) {
if (mWrBridge && mLastFrameID >= 0) {
MOZ_ASSERT(mWrBridge->CompositableHolder());
for (size_t i = 0; i < mImages.Length(); ++i) {
bool frameComesAfter = mImages[i].mFrameID > mLastFrameID ||
mImages[i].mProducerID != mLastProducerID;
if (frameComesAfter && !mImages[i].mTimeStamp.IsNull()) {
mWrCompositableHolder->CompositeUntil(mImages[i].mTimeStamp +
mWrBridge->CompositableHolder()->CompositeUntil(mImages[i].mTimeStamp +
TimeDuration::FromMilliseconds(BIAS_TIME_MS));
break;
}
@ -96,6 +98,7 @@ WebRenderImageHost::CleanupResources()
nsTArray<TimedImage> newImages;
mImages.SwapElements(newImages);
newImages.Clear();
SetCurrentTextureHost(nullptr);
}
void
@ -115,8 +118,9 @@ TimeStamp
WebRenderImageHost::GetCompositionTime() const
{
TimeStamp time;
if (mWrCompositableHolder) {
time = mWrCompositableHolder->GetCompositionTime();
if (mWrBridge) {
MOZ_ASSERT(mWrBridge->CompositableHolder());
time = mWrBridge->CompositableHolder()->GetCompositionTime();
}
return time;
}
@ -136,11 +140,13 @@ WebRenderImageHost::GetAsTextureHostForComposite()
{
int imageIndex = ChooseImageIndex();
if (imageIndex < 0) {
SetCurrentTextureHost(nullptr);
return nullptr;
}
if (mWrCompositableHolder && uint32_t(imageIndex) + 1 < mImages.Length()) {
mWrCompositableHolder->CompositeUntil(mImages[imageIndex + 1].mTimeStamp + TimeDuration::FromMilliseconds(BIAS_TIME_MS));
if (mWrBridge && uint32_t(imageIndex) + 1 < mImages.Length()) {
MOZ_ASSERT(mWrBridge->CompositableHolder());
mWrBridge->CompositableHolder()->CompositeUntil(mImages[imageIndex + 1].mTimeStamp + TimeDuration::FromMilliseconds(BIAS_TIME_MS));
}
TimedImage* img = &mImages[imageIndex];
@ -149,7 +155,31 @@ WebRenderImageHost::GetAsTextureHostForComposite()
mLastFrameID = img->mFrameID;
mLastProducerID = img->mProducerID;
}
return img->mTextureHost;
SetCurrentTextureHost(img->mTextureHost);
return mCurrentTextureHost;
}
void
WebRenderImageHost::SetCurrentTextureHost(TextureHost* aTexture)
{
if (aTexture == mCurrentTextureHost.get()) {
return;
}
if (mWrBridge &&
!!mCurrentTextureHost &&
mCurrentTextureHost != aTexture &&
mCurrentTextureHost->AsWebRenderTextureHost()) {
MOZ_ASSERT(mWrBridge->CompositableHolder());
wr::PipelineId piplineId = mWrBridge->PipelineId();
wr::Epoch epoch = mWrBridge->WrEpoch();
mWrBridge->CompositableHolder()->HoldExternalImage(
piplineId,
epoch,
mCurrentTextureHost->AsWebRenderTextureHost());
}
mCurrentTextureHost = aTexture;
}
void WebRenderImageHost::Attach(Layer* aLayer,
@ -246,5 +276,12 @@ WebRenderImageHost::GetImageSize() const
return IntSize();
}
void
WebRenderImageHost::SetWrBridge(WebRenderBridgeParent* aWrBridge)
{
SetCurrentTextureHost(nullptr);
mWrBridge = aWrBridge;
}
} // namespace layers
} // namespace mozilla

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

@ -12,7 +12,7 @@
namespace mozilla {
namespace layers {
class WebRenderCompositableHolder;
class WebRenderBridgeParent;
/**
* ImageHost. Works with ImageClientSingle and ImageClientBuffered
@ -69,16 +69,17 @@ public:
TextureHost* GetAsTextureHostForComposite();
void SetWrCompositableHolder(WebRenderCompositableHolder* aWrCompositableHolder)
{
mWrCompositableHolder = aWrCompositableHolder;
}
void SetWrBridge(WebRenderBridgeParent* aWrBridge);
protected:
// ImageComposite
virtual TimeStamp GetCompositionTime() const override;
WebRenderCompositableHolder* MOZ_NON_OWNING_REF mWrCompositableHolder;
void SetCurrentTextureHost(TextureHost* aTexture);
WebRenderBridgeParent* MOZ_NON_OWNING_REF mWrBridge;
CompositableTextureHostRef mCurrentTextureHost;
};
} // namespace layers