summaryrefslogtreecommitdiffstats
path: root/gfx/gl/GLScreenBuffer.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'gfx/gl/GLScreenBuffer.cpp')
-rw-r--r--gfx/gl/GLScreenBuffer.cpp38
1 files changed, 18 insertions, 20 deletions
diff --git a/gfx/gl/GLScreenBuffer.cpp b/gfx/gl/GLScreenBuffer.cpp
index 9dda11b41a..6550698eb5 100644
--- a/gfx/gl/GLScreenBuffer.cpp
+++ b/gfx/gl/GLScreenBuffer.cpp
@@ -10,22 +10,13 @@
#include "gfx2DGlue.h"
#include "MozFramebuffer.h"
#include "SharedSurface.h"
+#include "mozilla/gfx/BuildConstants.h"
namespace mozilla::gl {
// -
// SwapChainPresenter
-// We need to apply pooling on Android because of the AndroidSurface slow
-// destructor bugs. They cause a noticeable performance hit. See bug
-// #1646073.
-static constexpr size_t kPoolSize =
-#if defined(MOZ_WIDGET_ANDROID)
- 4;
-#else
- 0;
-#endif
-
UniquePtr<SwapChainPresenter> SwapChain::Acquire(
const gfx::IntSize& size, const gfx::ColorSpace2 colorSpace) {
MOZ_ASSERT(mFactory);
@@ -42,11 +33,9 @@ UniquePtr<SwapChainPresenter> SwapChain::Acquire(
}
}
- // When mDestroyedCallback exists, recycling of SharedSurfaces is managed by
- // the owner of the SwapChain by calling StoreRecycledSurface().
- const auto poolSize = mDestroyedCallback ? 0 : kPoolSize;
-
- if (!mPool.empty() && (!poolSize || mPool.size() == poolSize)) {
+ // When pooling is disabled, recycling of SharedSurfaces is managed by the
+ // owner of the SwapChain by calling StoreRecycledSurface().
+ if (!mPool.empty() && (!mPoolLimit || mPool.size() >= mPoolLimit)) {
surf = mPool.front();
mPool.pop();
}
@@ -55,9 +44,11 @@ UniquePtr<SwapChainPresenter> SwapChain::Acquire(
if (!uniquePtrSurf) return nullptr;
surf.reset(uniquePtrSurf.release());
}
- mPool.push(surf);
- while (mPool.size() > poolSize) {
- mPool.pop();
+ if (mPoolLimit > 0) {
+ mPool.push(surf);
+ while (mPool.size() > mPoolLimit) {
+ mPool.pop();
+ }
}
auto ret = MakeUnique<SwapChainPresenter>(*this);
@@ -74,7 +65,10 @@ void SwapChain::ClearPool() {
bool SwapChain::StoreRecycledSurface(
const std::shared_ptr<SharedSurface>& surf) {
MOZ_ASSERT(mFactory);
- if (!mFactory || NS_WARN_IF(surf->mDesc.gl != mFactory->mDesc.gl)) {
+ // Don't allow external recycled surfaces if SwapChain is managing own pool.
+ MOZ_ASSERT(!mPoolLimit);
+ if (mPoolLimit > 0 || !mFactory ||
+ NS_WARN_IF(surf->mDesc.gl != mFactory->mDesc.gl)) {
// Ensure we don't accidentally store an expired shared surface or from a
// different context.
return false;
@@ -130,7 +124,11 @@ GLuint SwapChainPresenter::Fb() const {
// -
// SwapChain
-SwapChain::SwapChain() = default;
+SwapChain::SwapChain()
+ : // We need to apply pooling on Android because of the AndroidSurface slow
+ // destructor bugs. They cause a noticeable performance hit. See bug
+ // #1646073.
+ mPoolLimit(kIsAndroid ? 4 : 0) {}
SwapChain::~SwapChain() {
if (mPresenter) {