2017-10-27 23:10:06 +00:00
|
|
|
/* -*- 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
|
2017-10-27 22:55:37 +00:00
|
|
|
* 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/. */
|
2017-03-22 03:32:53 +00:00
|
|
|
#ifndef mozilla_gfx_layers_TextureSourceProvider_h
|
|
|
|
#define mozilla_gfx_layers_TextureSourceProvider_h
|
|
|
|
|
|
|
|
#include "nsISupportsImpl.h"
|
|
|
|
#include "mozilla/AlreadyAddRefed.h"
|
|
|
|
#include "mozilla/TimeStamp.h"
|
|
|
|
#include "mozilla/layers/CompositorTypes.h"
|
|
|
|
#include "nsTArray.h"
|
|
|
|
|
|
|
|
struct ID3D11Device;
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace gfx {
|
|
|
|
class DataSourceSurface;
|
|
|
|
} // namespace gfx
|
2017-03-22 03:32:53 +00:00
|
|
|
namespace gl {
|
|
|
|
class GLContext;
|
|
|
|
} // namespace gl
|
2017-03-22 03:32:53 +00:00
|
|
|
namespace layers {
|
|
|
|
|
|
|
|
class TextureHost;
|
|
|
|
class DataTextureSource;
|
|
|
|
class Compositor;
|
2018-12-11 08:54:14 +00:00
|
|
|
class CompositorOGL;
|
2017-03-22 03:32:53 +00:00
|
|
|
|
|
|
|
// Provided by a HostLayerManager or Compositor for allocating backend-specific
|
|
|
|
// texture types.
|
|
|
|
class TextureSourceProvider {
|
|
|
|
public:
|
|
|
|
NS_INLINE_DECL_REFCOUNTING(TextureSourceProvider)
|
|
|
|
|
|
|
|
virtual already_AddRefed<DataTextureSource> CreateDataTextureSource(
|
|
|
|
TextureFlags aFlags = TextureFlags::NO_FLAGS) = 0;
|
|
|
|
|
|
|
|
virtual already_AddRefed<DataTextureSource> CreateDataTextureSourceAround(
|
|
|
|
gfx::DataSourceSurface* aSurface) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual already_AddRefed<DataTextureSource>
|
|
|
|
CreateDataTextureSourceAroundYCbCr(TextureHost* aTexture) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual TimeStamp GetLastCompositionEndTime() const = 0;
|
|
|
|
|
|
|
|
// Return true if the effect type is supported.
|
|
|
|
//
|
|
|
|
// By default Compositor implementations should support all effects but in
|
|
|
|
// some rare cases it is not possible to support an effect efficiently.
|
|
|
|
// This is the case for BasicCompositor with EffectYCbCr.
|
|
|
|
virtual bool SupportsEffect(EffectTypes aEffect) { return true; }
|
|
|
|
|
|
|
|
/// Most compositor backends operate asynchronously under the hood. This
|
|
|
|
/// means that when a layer stops using a texture it is often desirable to
|
|
|
|
/// wait for the end of the next composition before releasing the texture's
|
|
|
|
/// ReadLock.
|
|
|
|
/// This function provides a convenient way to do this delayed unlocking, if
|
|
|
|
/// the texture itself requires it.
|
2017-09-22 16:48:12 +00:00
|
|
|
virtual void UnlockAfterComposition(TextureHost* aTexture);
|
2017-03-22 03:32:53 +00:00
|
|
|
|
|
|
|
/// Most compositor backends operate asynchronously under the hood. This
|
|
|
|
/// means that when a layer stops using a texture it is often desirable to
|
|
|
|
/// wait for the end of the next composition before NotifyNotUsed() call.
|
|
|
|
/// This function provides a convenient way to do this delayed NotifyNotUsed()
|
|
|
|
/// call, if the texture itself requires it.
|
|
|
|
/// See bug 1260611 and bug 1252835
|
|
|
|
///
|
|
|
|
/// Returns true if notified, false otherwise.
|
|
|
|
virtual bool NotifyNotUsedAfterComposition(TextureHost* aTextureHost);
|
|
|
|
|
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-05 22:46:26 +00:00
|
|
|
virtual void MaybeUnlockBeforeNextComposition(TextureHost* aTextureHost) {}
|
|
|
|
virtual void TryUnlockTextures() {}
|
|
|
|
|
2017-03-22 03:32:53 +00:00
|
|
|
// If overridden, make sure to call the base function.
|
|
|
|
virtual void Destroy();
|
|
|
|
|
|
|
|
void FlushPendingNotifyNotUsed();
|
|
|
|
|
|
|
|
// If this provider is also a Compositor, return the compositor. Otherwise
|
|
|
|
// return null.
|
|
|
|
virtual Compositor* AsCompositor() { return nullptr; }
|
|
|
|
|
2018-12-11 08:54:14 +00:00
|
|
|
// If this provider is also a CompositorOGL, return the compositor. Otherwise
|
|
|
|
// return nullptr.
|
|
|
|
virtual CompositorOGL* AsCompositorOGL() { return nullptr; }
|
|
|
|
|
2017-03-22 03:32:53 +00:00
|
|
|
#ifdef XP_WIN
|
|
|
|
// On Windows, if this provides Direct3D textures, it must expose the device.
|
|
|
|
virtual ID3D11Device* GetD3D11Device() const { return nullptr; }
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// If this provides OpenGL textures, it must expose the GLContext.
|
|
|
|
virtual gl::GLContext* GetGLContext() const { return nullptr; }
|
|
|
|
|
2017-03-22 03:32:53 +00:00
|
|
|
virtual int32_t GetMaxTextureSize() const = 0;
|
|
|
|
|
2017-03-22 03:32:56 +00:00
|
|
|
// Return whether or not this provider is still valid (i.e., is still being
|
|
|
|
// used to composite).
|
|
|
|
virtual bool IsValid() const = 0;
|
|
|
|
|
2017-06-20 08:17:21 +00:00
|
|
|
public:
|
|
|
|
class MOZ_STACK_CLASS AutoReadUnlockTextures {
|
|
|
|
public:
|
|
|
|
explicit AutoReadUnlockTextures(TextureSourceProvider* aProvider)
|
|
|
|
: mProvider(aProvider) {}
|
|
|
|
~AutoReadUnlockTextures() { mProvider->ReadUnlockTextures(); }
|
|
|
|
|
|
|
|
private:
|
|
|
|
RefPtr<TextureSourceProvider> mProvider;
|
|
|
|
};
|
|
|
|
|
2017-03-22 03:32:53 +00:00
|
|
|
protected:
|
|
|
|
// Should be called at the end of each composition.
|
|
|
|
void ReadUnlockTextures();
|
|
|
|
|
|
|
|
virtual ~TextureSourceProvider();
|
|
|
|
|
|
|
|
private:
|
|
|
|
// An array of locks that will need to be unlocked after the next composition.
|
|
|
|
nsTArray<RefPtr<TextureHost>> mUnlockAfterComposition;
|
|
|
|
|
|
|
|
// An array of TextureHosts that will need to call NotifyNotUsed() after the
|
|
|
|
// next composition.
|
|
|
|
nsTArray<RefPtr<TextureHost>> mNotifyNotUsedAfterComposition;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace layers
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_gfx_layers_TextureSourceProvider_h
|