Files
palemoon27/gfx/layers/client/CompositableClient.h
T
roytam1 37721bb087 import changes from `dev' branch of rmottola/Arctic-Fox:
- Remove Compositor::mRenderBounds. (bug 1243071 part 1, r=mattwoodrow) (5f82e99655)
- Use double precision when computing the backdrop copy rect. (bug 1243071 part 2, r=mattwoodrow) (3db95bac33)
- Add software mix-blend mode support to the D3D9 compositor. (bug 1243071 part 3, r=bas,mattwoodrow) (4a68678ab7)
- Bug 1231564 - Don't trigger new composites just to repaint debug overlays. r=BenWa (7dfd13163a)
- Bug 1249312: UseAcceleratedCanvas on Mac should really be UseAcceleratedSkiaCanvas. r=mchang (0b830d9c6e)
- Fix stale intermediate surfaces in the D3D9 compositor. (bug 1244821, r=mattwoodrow) (1827598eaa)
- Bug 1224433 - Part 2: Clamp the invalidation rect to values that fit within nscoord. r=rc (3c08f0531e)
- Bug 1161978 - Use GetEffectiveVisibleRegion() for Layer invalidation r=matt.woodrow (3209eda22d)
- Bug 1242720 - Followup: reduce code duplication. r=jfkthame (37ff368177)
- improve gcc11 and later fix for numeric limits (e7a3e86bb7)
- Bug 1240589 - Import Chromium's upstream rand_util_win.cc to avoid rand_s() crash. r=jld (9be9342c7b)
- Bug 1240589 - Cross compilation fixup. (714a88c2a3)
- Bug 1188211 - Fix more constructors in IPC; r=billm (500382e235)
- Bug 1200131 - Avoid shadowing members in tuple.h; r=njn (0c3f06c4eb)
- Bug 1205942 (part 1) - Fix overflows in time_posix.cc. r=jld. (18961ef5dd)
- Bug 1205942 (part 2) - Fix "always true" warning in child_thread.cc. r=jld. (3c21921822)
- Bug 1205942 (part 3) - Remove unused OS version detection functions from ipc/chromium/. r=jld. (da54914934)
- Bug 1205942 (part 4) - Remove GetWinVersion(). r=jld. (345daa48bb)
- Bug 1141565 - TSan: data race ipc/chromium/src/base/histogram.cc:730 Accumulate. r=gfritzsche. (be428d7396)
- Bug 1240985 - IPC glib deadlock fix (r=jld) (ab640c7c5b)
- Bug 1241901 part 4 - Stop using nsAutoPtr for holding primitive arrays. r=froydnj (f8c2de6f8b)
- Bug 1133073 - Use PR_DuplicateEnvironment to avoid post-fork malloc on all Linux platforms. r=dhylands# Please enter the commit message for your changes. Lines starting (58b793b6db)
- Bug 1215151 - Add XPCOM leak checking for base::Thread. r=jld (5f58074c97)
- bug 1249622 - make ThreadData::list_lock_ a StaticMutex r=froydnj (1fbc823209)
- Bug 1213320 - Detect IPC::Channel leaks with the XPCOM leak checker. r=jld (d483f4abc2)
- bug 1161166 - Move some implementation out of ipc headres to not include headres for EndianU32_* r=billm (6125f1789d)
- Bug 1221056 - Make the destroy messages for PTexture and PCompositable part of the current transaction when applicable. r=sotaro (52e3533e8d)
- Bug 1236167: P1. Do not attempt to destroy a non allocated surface. r=nical (169570d50e)
- Bug 1236167 - Don't attempt to take a compositor snapshot if parameters are incorrect. r=jrmuizel (7b65e2df32)
- Bug 1229780 - Remove TextureClientPool helper functions from ClientLayerManager, r=mwoodrow (3f8cc506d9)
- remove code without reference in FF or TFF (0126b4d3f8)
2023-09-12 11:01:57 +08:00

269 lines
9.2 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/. */
#ifndef MOZILLA_GFX_BUFFERCLIENT_H
#define MOZILLA_GFX_BUFFERCLIENT_H
#include <stdint.h> // for uint64_t
#include <vector> // for vector
#include <map> // for map
#include "mozilla/Assertions.h" // for MOZ_CRASH
#include "mozilla/RefPtr.h" // for already_AddRefed, RefCounted
#include "mozilla/gfx/Types.h" // for SurfaceFormat
#include "mozilla/layers/AsyncTransactionTracker.h" // for AsyncTransactionTracker
#include "mozilla/layers/CompositorTypes.h"
#include "mozilla/layers/LayersTypes.h" // for LayersBackend, TextureDumpMode
#include "mozilla/layers/TextureClient.h" // for TextureClient
#include "mozilla/layers/TextureClientRecycleAllocator.h" // for TextureClientRecycleAllocator
#include "nsISupportsImpl.h" // for MOZ_COUNT_CTOR, etc
namespace mozilla {
namespace layers {
class CompositableClient;
class ImageBridgeChild;
class ImageContainer;
class CompositableForwarder;
class CompositableChild;
class PCompositableChild;
/**
* Handle RemoveTextureFromCompositableAsync() transaction.
*/
class RemoveTextureFromCompositableTracker : public AsyncTransactionTracker {
public:
explicit RemoveTextureFromCompositableTracker(AsyncTransactionWaiter* aWaiter = nullptr)
: AsyncTransactionTracker(aWaiter)
{
MOZ_COUNT_CTOR(RemoveTextureFromCompositableTracker);
}
protected:
~RemoveTextureFromCompositableTracker()
{
MOZ_COUNT_DTOR(RemoveTextureFromCompositableTracker);
ReleaseTextureClient();
}
public:
virtual void Complete() override
{
ReleaseTextureClient();
}
virtual void Cancel() override
{
ReleaseTextureClient();
}
virtual void SetTextureClient(TextureClient* aTextureClient) override
{
ReleaseTextureClient();
mTextureClient = aTextureClient;
}
virtual void SetReleaseFenceHandle(FenceHandle& aReleaseFenceHandle) override
{
if (mTextureClient) {
mTextureClient->SetReleaseFenceHandle(aReleaseFenceHandle);
}
}
protected:
void ReleaseTextureClient();
private:
RefPtr<TextureClient> mTextureClient;
};
/**
* CompositableClient manages the texture-specific logic for composite layers,
* independently of the layer. It is the content side of a CompositableClient/
* CompositableHost pair.
*
* CompositableClient's purpose is to send texture data to the compositor side
* along with any extra information about how the texture is to be composited.
* Things like opacity or transformation belong to layer and not compositable.
*
* Since Compositables are independent of layers it is possible to create one,
* connect it to the compositor side, and start sending images to it. This alone
* is arguably not very useful, but it means that as long as a shadow layer can
* do the proper magic to find a reference to the right CompositableHost on the
* Compositor side, a Compositable client can be used outside of the main
* shadow layer forwarder machinery that is used on the main thread.
*
* The first step is to create a Compositable client and call Connect().
* Connect() creates the underlying IPDL actor (see CompositableChild) and the
* corresponding CompositableHost on the other side.
*
* To do in-transaction texture transfer (the default), call
* ShadowLayerForwarder::Attach(CompositableClient*, ShadowableLayer*). This
* will let the LayerComposite on the compositor side know which CompositableHost
* to use for compositing.
*
* To do async texture transfer (like async-video), the CompositableClient
* should be created with a different CompositableForwarder (like
* ImageBridgeChild) and attachment is done with
* CompositableForwarder::AttachAsyncCompositable that takes an identifier
* instead of a CompositableChild, since the CompositableClient is not managed
* by this layer forwarder (the matching uses a global map on the compositor side,
* see CompositableMap in ImageBridgeParent.cpp)
*
* Subclasses: Painted layers use ContentClients, ImageLayers use ImageClients,
* Canvas layers use CanvasClients (but ImageHosts). We have a different subclass
* where we have a different way of interfacing with the textures - in terms of
* drawing into the compositable and/or passing its contents to the compostior.
*/
class CompositableClient
{
protected:
virtual ~CompositableClient();
public:
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(CompositableClient)
explicit CompositableClient(CompositableForwarder* aForwarder, TextureFlags aFlags = TextureFlags::NO_FLAGS);
virtual void Dump(std::stringstream& aStream,
const char* aPrefix="",
bool aDumpHtml=false,
TextureDumpMode aCompress=TextureDumpMode::Compress) {};
virtual TextureInfo GetTextureInfo() const = 0;
LayersBackend GetCompositorBackendType() const;
already_AddRefed<TextureClient>
CreateBufferTextureClient(gfx::SurfaceFormat aFormat,
gfx::IntSize aSize,
gfx::BackendType aMoz2dBackend = gfx::BackendType::NONE,
TextureFlags aFlags = TextureFlags::DEFAULT);
already_AddRefed<TextureClient>
CreateTextureClientForDrawing(gfx::SurfaceFormat aFormat,
gfx::IntSize aSize,
BackendSelector aSelector,
TextureFlags aTextureFlags,
TextureAllocationFlags aAllocFlags = ALLOC_DEFAULT);
/**
* Establishes the connection with compositor side through IPDL
*/
virtual bool Connect(ImageContainer* aImageContainer = nullptr);
void Destroy();
static bool DestroyFallback(PCompositableChild* aActor);
bool IsConnected() const;
PCompositableChild* GetIPDLActor() const;
// should only be called by a CompositableForwarder
virtual void SetIPDLActor(CompositableChild* aChild);
CompositableForwarder* GetForwarder() const
{
return mForwarder;
}
/**
* This identifier is what lets us attach async compositables with a shadow
* layer. It is not used if the compositable is used with the regular shadow
* layer forwarder.
*
* If this returns zero, it means the compositable is not async (it is used
* on the main thread).
*/
uint64_t GetAsyncID() const;
/**
* Tells the Compositor to create a TextureHost for this TextureClient.
*/
virtual bool AddTextureClient(TextureClient* aClient);
/**
* A hook for the when the Compositable is detached from it's layer.
*/
virtual void OnDetach() {}
/**
* Clear any resources that are not immediately necessary. This may be called
* in low-memory conditions.
*/
virtual void ClearCachedResources();
/**
* Should be called when deataching a TextureClient from a Compositable, because
* some platforms need to do some extra book keeping when this happens (for
* example to properly keep track of fences on Gonk).
*
* See AutoRemoveTexture to automatically invoke this at the end of a scope.
*/
virtual void RemoveTexture(TextureClient* aTexture);
static CompositableClient* FromIPDLActor(PCompositableChild* aActor);
/**
* Allocate and deallocate a CompositableChild actor.
*
* CompositableChild is an implementation detail of CompositableClient that is not
* exposed to the rest of the code base. CreateIPDLActor and DestroyIPDLActor
* are for use with the managing IPDL protocols only (so that they can
* implement AllocCompositableChild and DeallocPCompositableChild).
*/
static PCompositableChild* CreateIPDLActor();
static bool DestroyIPDLActor(PCompositableChild* actor);
void InitIPDLActor(PCompositableChild* aActor, uint64_t aAsyncID = 0);
static void TransactionCompleteted(PCompositableChild* aActor, uint64_t aTransactionId);
static void HoldUntilComplete(PCompositableChild* aActor, AsyncTransactionTracker* aTracker);
static uint64_t GetTrackersHolderId(PCompositableChild* aActor);
TextureFlags GetTextureFlags() const { return mTextureFlags; }
TextureClientRecycleAllocator* GetTextureClientRecycler();
static void DumpTextureClient(std::stringstream& aStream,
TextureClient* aTexture,
TextureDumpMode aCompress);
protected:
CompositableChild* mCompositableChild;
RefPtr<CompositableForwarder> mForwarder;
// Some layers may want to enforce some flags to all their textures
// (like disallowing tiling)
TextureFlags mTextureFlags;
RefPtr<TextureClientRecycleAllocator> mTextureClientRecycler;
friend class CompositableChild;
};
/**
* Helper to call RemoveTexture at the end of a scope.
*/
struct AutoRemoveTexture
{
explicit AutoRemoveTexture(CompositableClient* aCompositable,
TextureClient* aTexture = nullptr)
: mTexture(aTexture)
, mCompositable(aCompositable)
{}
~AutoRemoveTexture();
RefPtr<TextureClient> mTexture;
private:
CompositableClient* mCompositable;
};
} // namespace layers
} // namespace mozilla
#endif