Files
palemoon27/gfx/layers/client/TextureClientPool.cpp
T
roytam1 89d38b5d7a import changes from `dev' branch of rmottola/Arctic-Fox:
- Bug 1173364 - support ARIA table and cell roles, r=marcoz (c6f9fc891e)
- Bug 1205318 - make aria-owns loop alg more sophisticated, r=yzen (d287b1e41c)
- Bug 1205476 - crash in mozilla::a11y::DocAccessible::ProcessInvalidationList(), r=smaug (bf920abdd3)
- Bug 1205476 - crash in mozilla::a11y::DocAccessible::ProcessInvalidationList(), part3, r=davidb (675c3a0ee2)
- Bug 1205476 - crash in mozilla::a11y::DocAccessible::ProcessInvalidationList, part2, r=davidb (a7cd835169)
- Bug 1186786 - Replace nsBaseHashtable::EnumerateRead() calls in accessible/ with iterators. r=tbsaunde. (172fcbe18f)
- Bug 1219299 - rework aria-owns implementation, r=yzen (c297a84b41)
- Bug 1219744 - no child_of/parent_of relations for aria-owns, r=yzen (38ea8be268)
- Bug 1205341 - get rid of aria-owns provided relations, part1: remove ARIA combobox special support (bug 819273 backout), r=yzen (0ca03a27bd)
- Bug 1219743 - remove special ARIA owns support for ARIA menus, r=yzen (64468fdfd1)
- Bug 1200595 - Introduce TextureData and implement it for X11. r=mattwoodrow, Bas, sotaro (2e6bc3f02c)
- Bug 1200595 - Buffer TextureData implementation. r=mattwoodrow (1cb3ffd937)
- Bug 1227415 - Fix copy buffer size r=jolin (344130daec)
- Bug 1200595 - Gralloc TextureData implementation. r=sotaro (a0726233ca)
- Bug 1205725 - Add basic SidebandStream handling to HwcComposer2D r=mwu,nical (42bea59a5f)
- namespace (ab69730d53)
- Bug 1194775 - Paper over a crash in ContentClient. r=Bas (998051cee4)
- minor (c24c0b069d)
- Bug 1197315 - remove PR_snprintf calls in gfx/; r=froydnj (f153fed9c8)
- Bug 1157664 - Initialize mozilla::layers::FPSCOUNTER::mIteratorIndex. r=nical (cf5d2203ee)
- Bug 1157663 - Init mMap in the constructor to avoid half initialized structures. r=nical (d972306493)
- Bug 1167370: Check for Map() call failing. r=bas (707eda52ff)
- Bug 1221276 - Don't crash if we don't have a surface. r=nical (c53141ea3d)
- Bug 1219230 - Use the valid region for determining buffer size instead of the visible region. r=mstange (f2d4783eef)
- Pass the correct moz2d backend in CanvasClients. (bug 1212499, r=mattwoodrow) (c16688afbb)
- Bug 1179987 - Simplify unlocking of tiled texture hosts. r=nical (781200f702)
- Bug 1170189 - Fix tiling crash on Linux. r=jrmuizel (879bbfb506)
- Bug 1170189 - fix a comment in the tiling code. r=BenWa (62b47f1bbd)
- Bug 1179987 - Make tiled TextureSource recycling based on pointer comparisons rather than trying to do it geometrically. r=nical (7bde534929)
- Bug 1189710 - Use correct offset for LayerRenderState in TiledContentHost. r=jrmuizel (cb93c2f98a)
- Bug 1215050 - Make layerscope support TiledPaintedLayer when using HWC. r=mattwoodrow, r=cjku (6bffac30f8)
- Bug 1186208 - Fix crash when tiling is enabled on linux. r=mattwoodrow (b2f2c85734)
- Bug 1197713 - Add missing gfxPrefs.h include to TiledContentHost.cpp. r=nical (22bce4e071)
- Bug 1143575. Async image invalidation does not necessarily need to invalidate the layer; LayerTreeInvalidation will do that for us. r=mattwoodrow (a6144b7127)
- Bug 1219529 - Don't attempt to deallocate shmems after the ipdl protocol is shut down. r=sotaro (3bb89ef36e)
- Bug 1143575. Add assertion for diagnostic purposes. r=nical (e4944dd72f)
- Bug 1202175 - Guard GLX-specific call in SurfaceDescriptorX11. r=jgilbert (167a4aa49b)
- Bug 1132528 - Handle non existent key r=nical (6c12df1446)
- Bug 1137151: Marked destructor of |GrallocReporter| as protected, r=jmuizelaar (57605c4472)
- Bug 1145389 - Add gralloc allocation requet size check r=nical (47c6065148)
- Bug 1181197 - Fix null dereference in SharedPlanarYCbCrImage destructor. r=jgilbert (3f8c390a6f)
- Bug 1195110 - Check if GLContext is destroyed before freeing resources in CompositingRenderTargetOGL. r=jrmuizel (8eac603d84)
- bug 1178956 - Specify precision in OGLShaderProgram.cpp to fix compositor on iOS. r=kip (daa6d9db20)
- Bug 1186725 - InitTextures should check if LockRect() returns an error, r=mattwoodrow (bc87f908a7)
- Bug 1170143 - Add some error checks around the creation of dxgi ycbcrvideo frames. r=Bas (c96e4d9e79)
- Bug 1170143 - Build fix. r=me (a9d0064bc3)
- Bug 1202700 - Use d3d9 device to upload YCbCr surfaces on the client side if possible. r=Bas (3ccd0c68f5)
- Bug 1199361 - Add texture memory reporters for YCbCr TextureClients. r=jrmuizel (723e9d4b10)
- bug 1183967 - fixup correct case of mfidl.h (e9abd04709)
- Bug 1133007 - followup - make CreateServerSocketRunnable's constructor explicit; r=bustage (5de0ec7900)
- Bug 1195653 - Part1.1: Dump SecondaryEffects (EffectTypes::MASK) on Layerscope viewer. r=dglastonbury (v2, carry r+) (a6736ad381)
- Bug 1195653 - Part1.2: Use sSentTextureIds instead of sTextureIdList and move HasTextureIdBeenSent into SendTextureSource. r=dglastonbury (v3, carry r+) (7e0b14bca6)
- Bug 1195653 - Part1.3: Add isMask attribute field to LayerScopePacket.proto. r=dglastonbury (v2, carry r+) (510e50e09a)
- Bug 1195653 - Part1.4: Generated file diffs from patched LayerScopePacket.proto. r=dglastonbury (v1, carry r+) (f1824afcb3)
- Bug 1195653 - Part1.5: Send isMask info to LayerScope viewer by TexturePacket. r=dglastonbury (v3) (1722e5e6fe)
- Bug 1205521 - Part1: (v3) Add texture/mask attribute fields in LayerScopePacket.proto. r=dglastonbury (0cca15f8f5)
- Bug 1205521 - Part2: (v3) Generated file diffs from patched LayerScopePacket.proto. r=dglastonbury (6253724bcf)
- Bug 1205521 - Part3: (v3) Dump texture/mask attributes on layerscope viewer. r=dglastonbury (31d346bad1)
- Bug 1205521 - Part4: (v2) Align LayerScopePacket to fit changes in Bug 1211324. r=dglastonbury (712da0fe9c)
- Bug 1177023 - Log the IsRootContent flag when dumping framemetrics. r=botond (9bea51f318)
- Bug 1153724 - Only assert if the size was reasonable to start. r=mchang (c3d61bbee1)
- namespace (edcce0a0b3)
- Bug 1195857: Make nsPresContext::HasAuthorSpecifiedRules()'s arg 'const', to remove need for const_cast in callers. r=jwatt (274fe66dca)
- Bug 1182414, part 1 - Fix printing crash with range input controls. r=dholbert (352a408a83)
- Bug 1182414, part 2 - Add printing crash test. r=dholbert (0fc9bd4529)
- Bug 1099103 - Prevent numbers input using a grouping separator from being mis-processed as if the separator was a decimal separator. r=dholbert (90276c2f6b)
- Bug 1157142 - Support logical (inline/block) in addition to physical orientation for the <input type=range> element; make inline the default behavior so that range sliders respect writing mode. r=jwatt (2ec37cbba8)
2023-01-30 12:47:09 +08:00

274 lines
8.9 KiB
C++

/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
* 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 "TextureClientPool.h"
#include "CompositableClient.h"
#include "mozilla/layers/CompositableForwarder.h"
#include "gfxPrefs.h"
#include "nsComponentManagerUtils.h"
#define TCP_LOG(...)
//#define TCP_LOG(...) printf_stderr(__VA_ARGS__);
namespace mozilla {
namespace layers {
static void
ShrinkCallback(nsITimer *aTimer, void *aClosure)
{
static_cast<TextureClientPool*>(aClosure)->ShrinkToMinimumSize();
}
TextureClientPool::TextureClientPool(gfx::SurfaceFormat aFormat,
TextureFlags aFlags,
gfx::IntSize aSize,
uint32_t aMaxTextureClients,
uint32_t aShrinkTimeoutMsec,
CompositableForwarder* aAllocator)
: mFormat(aFormat)
, mFlags(aFlags)
, mSize(aSize)
, mMaxTextureClients(aMaxTextureClients)
, mShrinkTimeoutMsec(aShrinkTimeoutMsec)
, mOutstandingClients(0)
, mSurfaceAllocator(aAllocator)
{
TCP_LOG("TexturePool %p created with max size %u and timeout %u\n",
this, mMaxTextureClients, aShrinkTimeoutMsec);
mTimer = do_CreateInstance("@mozilla.org/timer;1");
if (aFormat == gfx::SurfaceFormat::UNKNOWN) {
gfxWarning() << "Creating texture pool for SurfaceFormat::UNKNOWN format";
}
}
TextureClientPool::~TextureClientPool()
{
mTimer->Cancel();
}
#ifdef GFX_DEBUG_TRACK_CLIENTS_IN_POOL
static bool TestClientPool(const char* what,
TextureClient* aClient,
TextureClientPool* aPool)
{
if (!aClient || !aPool) {
return false;
}
TextureClientPool* actual = aClient->mPoolTracker;
bool ok = (actual == aPool);
if (ok) {
ok = (aClient->GetFormat() == aPool->GetFormat());
}
if (!ok) {
if (actual) {
gfxCriticalError() << "Pool error(" << what << "): "
<< aPool << "-" << aPool->GetFormat() << ", "
<< actual << "-" << actual->GetFormat() << ", "
<< aClient->GetFormat();
MOZ_CRASH("Crashing with actual");
} else {
gfxCriticalError() << "Pool error(" << what << "): "
<< aPool << "-" << aPool->GetFormat() << ", nullptr, "
<< aClient->GetFormat();
MOZ_CRASH("Crashing without actual");
}
}
return ok;
}
#endif
already_AddRefed<TextureClient>
TextureClientPool::GetTextureClient()
{
// Try to fetch a client from the pool
RefPtr<TextureClient> textureClient;
if (mTextureClients.size()) {
mOutstandingClients++;
textureClient = mTextureClients.top();
mTextureClients.pop();
#ifdef GFX_DEBUG_TRACK_CLIENTS_IN_POOL
DebugOnly<bool> ok = TestClientPool("fetch", textureClient, this);
MOZ_ASSERT(ok);
#endif
TCP_LOG("TexturePool %p giving %p from pool; size %u outstanding %u\n",
this, textureClient.get(), mTextureClients.size(), mOutstandingClients);
return textureClient.forget();
}
// We're increasing the number of outstanding TextureClients without reusing a
// client, we may need to free a deferred-return TextureClient.
ShrinkToMaximumSize();
// No unused clients in the pool, create one
if (gfxPrefs::ForceShmemTiles()) {
// gfx::BackendType::NONE means use the content backend
textureClient = TextureClient::CreateForRawBufferAccess(mSurfaceAllocator,
mFormat, mSize, gfx::BackendType::NONE,
mFlags, ALLOC_DEFAULT);
} else {
textureClient = TextureClient::CreateForDrawing(mSurfaceAllocator,
mFormat, mSize, BackendSelector::Content, mFlags);
}
mOutstandingClients++;
#ifdef GFX_DEBUG_TRACK_CLIENTS_IN_POOL
if (textureClient) {
textureClient->mPoolTracker = this;
}
#endif
TCP_LOG("TexturePool %p giving new %p; size %u outstanding %u\n",
this, textureClient.get(), mTextureClients.size(), mOutstandingClients);
return textureClient.forget();
}
void
TextureClientPool::ReturnTextureClient(TextureClient *aClient)
{
if (!aClient) {
return;
}
#ifdef GFX_DEBUG_TRACK_CLIENTS_IN_POOL
DebugOnly<bool> ok = TestClientPool("return", aClient, this);
MOZ_ASSERT(ok);
#endif
// Add the client to the pool:
MOZ_ASSERT(mOutstandingClients > mTextureClientsDeferred.size());
mOutstandingClients--;
mTextureClients.push(aClient);
TCP_LOG("TexturePool %p had client %p returned; size %u outstanding %u\n",
this, aClient, mTextureClients.size(), mOutstandingClients);
// Shrink down if we're beyond our maximum size
ShrinkToMaximumSize();
// Kick off the pool shrinking timer if there are still more unused texture
// clients than our desired minimum cache size.
if (mTextureClients.size() > sMinCacheSize) {
TCP_LOG("TexturePool %p scheduling a shrink-to-min-size\n", this);
mTimer->InitWithFuncCallback(ShrinkCallback, this, mShrinkTimeoutMsec,
nsITimer::TYPE_ONE_SHOT);
}
}
void
TextureClientPool::ReturnTextureClientDeferred(TextureClient *aClient)
{
if (!aClient) {
return;
}
#ifdef GFX_DEBUG_TRACK_CLIENTS_IN_POOL
DebugOnly<bool> ok = TestClientPool("defer", aClient, this);
MOZ_ASSERT(ok);
#endif
mTextureClientsDeferred.push(aClient);
TCP_LOG("TexturePool %p had client %p defer-returned, size %u outstanding %u\n",
this, aClient, mTextureClientsDeferred.size(), mOutstandingClients);
ShrinkToMaximumSize();
}
void
TextureClientPool::ShrinkToMaximumSize()
{
uint32_t totalClientsOutstanding = mTextureClients.size() + mOutstandingClients;
TCP_LOG("TexturePool %p shrinking to max size %u; total outstanding %u\n",
this, mMaxTextureClients, totalClientsOutstanding);
// We're over our desired maximum size, immediately shrink down to the
// maximum, or zero if we have too many outstanding texture clients.
// We cull from the deferred TextureClients first, as we can't reuse those
// until they get returned.
while (totalClientsOutstanding > mMaxTextureClients) {
if (mTextureClientsDeferred.size()) {
MOZ_ASSERT(mOutstandingClients > 0);
mOutstandingClients--;
TCP_LOG("TexturePool %p dropped deferred client %p; %u remaining\n",
this, mTextureClientsDeferred.top().get(),
mTextureClientsDeferred.size() - 1);
mTextureClientsDeferred.pop();
} else {
if (!mTextureClients.size()) {
// Getting here means we're over our desired number of TextureClients
// with none in the pool. This can happen for pathological cases, or
// it could mean that mMaxTextureClients needs adjusting for whatever
// device we're running on.
TCP_LOG("TexturePool %p encountering pathological case!\n", this);
break;
}
TCP_LOG("TexturePool %p dropped non-deferred client %p; %u remaining\n",
this, mTextureClients.top().get(), mTextureClients.size() - 1);
mTextureClients.pop();
}
totalClientsOutstanding--;
}
}
void
TextureClientPool::ShrinkToMinimumSize()
{
TCP_LOG("TexturePool %p shrinking to minimum size %u\n", this, sMinCacheSize);
while (mTextureClients.size() > sMinCacheSize) {
TCP_LOG("TexturePool %p popped %p; shrunk to %u\n",
this, mTextureClients.top().get(), mTextureClients.size() - 1);
mTextureClients.pop();
}
}
void
TextureClientPool::ReturnDeferredClients()
{
TCP_LOG("TexturePool %p returning %u deferred clients to pool\n",
this, mTextureClientsDeferred.size());
while (!mTextureClientsDeferred.empty()) {
mTextureClients.push(mTextureClientsDeferred.top());
mTextureClientsDeferred.pop();
MOZ_ASSERT(mOutstandingClients > 0);
mOutstandingClients--;
}
ShrinkToMaximumSize();
// Kick off the pool shrinking timer if there are still more unused texture
// clients than our desired minimum cache size.
if (mTextureClients.size() > sMinCacheSize) {
TCP_LOG("TexturePool %p kicking off shrink-to-min timer\n", this);
mTimer->InitWithFuncCallback(ShrinkCallback, this, mShrinkTimeoutMsec,
nsITimer::TYPE_ONE_SHOT);
}
}
void
TextureClientPool::ReportClientLost()
{
MOZ_ASSERT(mOutstandingClients > mTextureClientsDeferred.size());
mOutstandingClients--;
TCP_LOG("TexturePool %p getting report client lost; down to %u outstanding\n",
this, mOutstandingClients);
}
void
TextureClientPool::Clear()
{
TCP_LOG("TexturePool %p getting cleared\n", this);
while (!mTextureClients.empty()) {
TCP_LOG("TexturePool %p releasing client %p\n",
this, mTextureClients.top().get());
mTextureClients.pop();
}
while (!mTextureClientsDeferred.empty()) {
MOZ_ASSERT(mOutstandingClients > 0);
mOutstandingClients--;
TCP_LOG("TexturePool %p releasing deferred client %p\n",
this, mTextureClientsDeferred.top().get());
mTextureClientsDeferred.pop();
}
}
} // namespace layers
} // namespace mozilla