gecko-dev/gfx/layers/TextureSourceProvider.cpp

96 строки
2.7 KiB
C++
Исходник Обычный вид История

/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "mozilla/layers/TextureSourceProvider.h"
#include "mozilla/layers/TextureHost.h"
Bug 1265824 - Wait on texture handles with IPC r=jld,mattwoodrow There's a lot going on here, but it all fits under the idea of being able to communicate about texture locking statuses without spinning on IsReadLocked. This is a bit of a trade - we could just always allocate/grab a texture from the pool, which would put a smaller cap on the amount of time we can possibly spend when a texture is locked. However, this eats up more CPU and memory than waiting on the textures to unlock, and could take longer, especially if there were a large number of textures which we just need to wait for for a short amount of time. In any case, we very rarely hit the case where we actually need to wait on the sync IPC to the compositor - most of the time the textures are already unlocked. There is also an async IPC call in here, which we make before flushing async paints. This just causes the compositor to check whether the GPU is done with its textures or not and unlock them if it is. This helps us avoid the case where we take a long time painting asynchronously, turn IPC back on at the end of that, and then have to wait for the compositor to to get into TiledLayerBufferComposite::UseTiles before getting a response. Specifically this eliminates several talos regressions which use ASAP mode. Lastly, there seem to be no other cases of static Monitors being used. This seems like it falls under similar use cases as StaticMutexes, so I added it in. I can move it into its own file if we think it might be generally useful in the future. MozReview-Commit-ID: IYQLwUqMxg2 --HG-- extra : rebase_source : 4f05832f51dae6db98773dcad03cb008a80eca6c
2018-05-06 01:46:26 +03:00
#include "mozilla/layers/PTextureParent.h"
#ifdef XP_DARWIN
#include "mozilla/layers/TextureSync.h"
#endif
namespace mozilla {
namespace layers {
TextureSourceProvider::~TextureSourceProvider()
{
ReadUnlockTextures();
}
void
TextureSourceProvider::ReadUnlockTextures()
{
Bug 1265824 - Wait on texture handles with IPC r=jld,mattwoodrow There's a lot going on here, but it all fits under the idea of being able to communicate about texture locking statuses without spinning on IsReadLocked. This is a bit of a trade - we could just always allocate/grab a texture from the pool, which would put a smaller cap on the amount of time we can possibly spend when a texture is locked. However, this eats up more CPU and memory than waiting on the textures to unlock, and could take longer, especially if there were a large number of textures which we just need to wait for for a short amount of time. In any case, we very rarely hit the case where we actually need to wait on the sync IPC to the compositor - most of the time the textures are already unlocked. There is also an async IPC call in here, which we make before flushing async paints. This just causes the compositor to check whether the GPU is done with its textures or not and unlock them if it is. This helps us avoid the case where we take a long time painting asynchronously, turn IPC back on at the end of that, and then have to wait for the compositor to to get into TiledLayerBufferComposite::UseTiles before getting a response. Specifically this eliminates several talos regressions which use ASAP mode. Lastly, there seem to be no other cases of static Monitors being used. This seems like it falls under similar use cases as StaticMutexes, so I added it in. I can move it into its own file if we think it might be generally useful in the future. MozReview-Commit-ID: IYQLwUqMxg2 --HG-- extra : rebase_source : 4f05832f51dae6db98773dcad03cb008a80eca6c
2018-05-06 01:46:26 +03:00
#ifdef XP_DARWIN
nsClassHashtable<nsUint32HashKey, nsTArray<uint64_t>> texturesIdsToUnlockByPid;
for (auto& texture : mUnlockAfterComposition) {
auto bufferTexture = texture->AsBufferTextureHost();
if (bufferTexture && bufferTexture->IsDirectMap()) {
texture->ReadUnlock();
auto actor = texture->GetIPDLActor();
if (actor) {
base::ProcessId pid = actor->OtherPid();
nsTArray<uint64_t>* textureIds = texturesIdsToUnlockByPid.LookupOrAdd(pid);
textureIds->AppendElement(TextureHost::GetTextureSerial(actor));
}
} else {
texture->ReadUnlock();
}
}
for (auto it = texturesIdsToUnlockByPid.ConstIter(); !it.Done(); it.Next()) {
TextureSync::SetTexturesUnlocked(it.Key(), *it.UserData());
}
#else
for (auto& texture : mUnlockAfterComposition) {
texture->ReadUnlock();
}
Bug 1265824 - Wait on texture handles with IPC r=jld,mattwoodrow There's a lot going on here, but it all fits under the idea of being able to communicate about texture locking statuses without spinning on IsReadLocked. This is a bit of a trade - we could just always allocate/grab a texture from the pool, which would put a smaller cap on the amount of time we can possibly spend when a texture is locked. However, this eats up more CPU and memory than waiting on the textures to unlock, and could take longer, especially if there were a large number of textures which we just need to wait for for a short amount of time. In any case, we very rarely hit the case where we actually need to wait on the sync IPC to the compositor - most of the time the textures are already unlocked. There is also an async IPC call in here, which we make before flushing async paints. This just causes the compositor to check whether the GPU is done with its textures or not and unlock them if it is. This helps us avoid the case where we take a long time painting asynchronously, turn IPC back on at the end of that, and then have to wait for the compositor to to get into TiledLayerBufferComposite::UseTiles before getting a response. Specifically this eliminates several talos regressions which use ASAP mode. Lastly, there seem to be no other cases of static Monitors being used. This seems like it falls under similar use cases as StaticMutexes, so I added it in. I can move it into its own file if we think it might be generally useful in the future. MozReview-Commit-ID: IYQLwUqMxg2 --HG-- extra : rebase_source : 4f05832f51dae6db98773dcad03cb008a80eca6c
2018-05-06 01:46:26 +03:00
#endif
mUnlockAfterComposition.Clear();
}
void
TextureSourceProvider::UnlockAfterComposition(TextureHost* aTexture)
{
mUnlockAfterComposition.AppendElement(aTexture);
}
bool
TextureSourceProvider::NotifyNotUsedAfterComposition(TextureHost* aTextureHost)
{
mNotifyNotUsedAfterComposition.AppendElement(aTextureHost);
// If Compositor holds many TextureHosts without compositing,
// the TextureHosts should be flushed to reduce memory consumption.
const int thresholdCount = 5;
const double thresholdSec = 2.0f;
if (mNotifyNotUsedAfterComposition.Length() > thresholdCount) {
TimeStamp lastCompositionEndTime = GetLastCompositionEndTime();
TimeDuration duration = lastCompositionEndTime ? TimeStamp::Now() - lastCompositionEndTime : TimeDuration();
// Check if we could flush
if (duration.ToSeconds() > thresholdSec) {
FlushPendingNotifyNotUsed();
}
}
return true;
}
void
TextureSourceProvider::FlushPendingNotifyNotUsed()
{
for (auto& textureHost : mNotifyNotUsedAfterComposition) {
textureHost->CallNotifyNotUsed();
}
mNotifyNotUsedAfterComposition.Clear();
}
void
TextureSourceProvider::Destroy()
{
ReadUnlockTextures();
FlushPendingNotifyNotUsed();
}
} // namespace layers
} // namespace mozilla