gecko-dev/gfx/layers/wr/WebRenderBridgeChild.h

223 lines
7.6 KiB
C
Raw Normal View History

/* -*- 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/. */
#ifndef mozilla_layers_WebRenderBridgeChild_h
#define mozilla_layers_WebRenderBridgeChild_h
#include "mozilla/layers/CompositableForwarder.h"
#include "mozilla/layers/PWebRenderBridgeChild.h"
namespace mozilla {
namespace widget {
class CompositorWidget;
}
namespace wr {
class DisplayListBuilder;
class ResourceUpdateQueue;
class IpcResourceUpdateQueue;
}
namespace layers {
class CompositableClient;
class CompositorBridgeChild;
class StackingContextHelper;
class TextureForwarder;
class WebRenderLayerManager;
template<class T>
class ThreadSafeWeakPtrHashKey : public PLDHashEntryHdr
{
public:
typedef RefPtr<T> KeyType;
typedef const T* KeyTypePointer;
explicit ThreadSafeWeakPtrHashKey(KeyTypePointer aKey) : mKey(do_AddRef(const_cast<T*>(aKey))) {}
KeyType GetKey() const { return do_AddRef(mKey); }
bool KeyEquals(KeyTypePointer aKey) const { return mKey == aKey; }
static KeyTypePointer KeyToPointer(const KeyType& aKey) { return aKey.get(); }
static PLDHashNumber HashKey(KeyTypePointer aKey)
{
return NS_PTR_TO_UINT32(aKey) >> 2;
}
enum { ALLOW_MEMMOVE = true };
private:
ThreadSafeWeakPtr<T> mKey;
};
typedef ThreadSafeWeakPtrHashKey<gfx::UnscaledFont> UnscaledFontHashKey;
typedef ThreadSafeWeakPtrHashKey<gfx::ScaledFont> ScaledFontHashKey;
class WebRenderBridgeChild final : public PWebRenderBridgeChild
, public CompositableForwarder
{
2016-11-29 02:08:08 +00:00
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(WebRenderBridgeChild, override)
public:
explicit WebRenderBridgeChild(const wr::PipelineId& aPipelineId);
void AddWebRenderParentCommand(const WebRenderParentCommand& aCmd);
void AddWebRenderParentCommands(const nsTArray<WebRenderParentCommand>& aCommands);
void UpdateResources(wr::IpcResourceUpdateQueue& aResources);
void BeginTransaction();
void EndTransaction(const wr::LayoutSize& aContentSize,
wr::BuiltDisplayList& dl,
wr::IpcResourceUpdateQueue& aResources,
const gfx::IntSize& aSize,
uint64_t aTransactionId,
const WebRenderScrollData& aScrollData,
const mozilla::TimeStamp& aTxnStartTime);
void EndEmptyTransaction(const FocusTarget& aFocusTarget,
uint64_t aTransactionId,
const mozilla::TimeStamp& aTxnStartTime);
void ProcessWebRenderParentCommands();
CompositorBridgeChild* GetCompositorBridgeChild();
wr::PipelineId GetPipeline() { return mPipelineId; }
// KnowsCompositor
2016-11-29 02:08:08 +00:00
TextureForwarder* GetTextureForwarder() override;
LayersIPCActor* GetLayersIPCActor() override;
void AddPipelineIdForAsyncCompositable(const wr::PipelineId& aPipelineId,
const CompositableHandle& aHandlee);
void AddPipelineIdForCompositable(const wr::PipelineId& aPipelineId,
const CompositableHandle& aHandlee);
void RemovePipelineIdForCompositable(const wr::PipelineId& aPipelineId);
wr::ExternalImageId AllocExternalImageIdForCompositable(CompositableClient* aCompositable);
void DeallocExternalImageId(const wr::ExternalImageId& aImageId);
/**
* Clean this up, finishing with SendShutDown() which will cause __delete__
* to be sent from the parent side.
*/
void Destroy(bool aIsSync);
bool IPCOpen() const { return mIPCOpen && !mDestroyed; }
bool IsDestroyed() const { return mDestroyed; }
uint32_t GetNextResourceId() { return ++mResourceId; }
wr::IdNamespace GetNamespace() { return mIdNamespace; }
void SetNamespace(wr::IdNamespace aIdNamespace)
{
mIdNamespace = aIdNamespace;
}
wr::FontKey GetNextFontKey()
{
return wr::FontKey { GetNamespace(), GetNextResourceId() };
}
wr::FontInstanceKey GetNextFontInstanceKey()
{
return wr::FontInstanceKey { GetNamespace(), GetNextResourceId() };
}
wr::WrImageKey GetNextImageKey()
{
return wr::WrImageKey{ GetNamespace(), GetNextResourceId() };
}
void PushGlyphs(wr::DisplayListBuilder& aBuilder, const nsTArray<wr::GlyphInstance>& aGlyphs,
gfx::ScaledFont* aFont, const wr::ColorF& aColor,
Bug 1357545 - handle text-shadows/decorations with webrender (layers-free) r=jrmuizel This replaces our DrawTargetCapture hack with a similar but more powerful TextDrawTarget hack. The old design had several limitations: * It couldn't handle shadows * It couldn't handle selections * It couldn't handle font/color changes in a single text-run * It couldn't handle decorations (underline, overline, line-through) Mostly this was a consequence of the fact that it only modified the start and end of the rendering algorithm, and therefore couldn't distinguish draw calls for different parts of the text. This new design is based on a similar principle as DrawTargetCapture, but also passes down the TextDrawTarget in the drawing arguments, so that the drawing algorithm can notify us of changes in phase (e.g. "now we're doing underlines"). This also lets us directly pass data to TextDrawTarget when possible (as is done for shadows and selections). In doing this, I also improved the logic copied from ContainsOnlyColoredGlyphs to handle changes in font/color mid-text-run (which can happen because of font fallback). The end result is: * We handle all shadows natively * We handle all selections natively * We handle all decorations natively * We handle font/color changes in a single text-run * Although we still hackily intercept draw calls * But we don't need to buffer commands, reducing total memcopies In addition, this change integrates webrender's PushTextShadow and PushLine APIs, which were designed for this use case. This is only done in the layerless path; WebrenderTextLayer continues to be semantically limited, as we aren't actively maintaining non-layers-free webrender anymore. This also doesn't modify TextLayers, to minimize churn. In theory they can be augmented to support the richer semantics that TextDrawTarget has, but there's little motivation since the API is largely unused with this change. MozReview-Commit-ID: 4IjTsSW335h --HG-- extra : rebase_source : d69f69648ade5c7a8e6bb756f4b8ab9e2543e576
2017-06-19 14:58:28 +00:00
const StackingContextHelper& aSc,
const wr::LayerRect& aBounds, const wr::LayerRect& aClip,
bool aBackfaceVisible,
const wr::GlyphOptions* aGlyphOptions = nullptr);
wr::FontInstanceKey GetFontKeyForScaledFont(gfx::ScaledFont* aScaledFont);
wr::FontKey GetFontKeyForUnscaledFont(gfx::UnscaledFont* aUnscaledFont);
void RemoveExpiredFontKeys();
void ClearReadLocks();
void BeginClearCachedResources();
void EndClearCachedResources();
void SetWebRenderLayerManager(WebRenderLayerManager* aManager);
ipc::IShmemAllocator* GetShmemAllocator();
private:
friend class CompositorBridgeChild;
~WebRenderBridgeChild() {}
wr::ExternalImageId GetNextExternalImageId();
// CompositableForwarder
void Connect(CompositableClient* aCompositable,
ImageContainer* aImageContainer = nullptr) override;
void UseTiledLayerBuffer(CompositableClient* aCompositable,
const SurfaceDescriptorTiles& aTiledDescriptor) override;
void UpdateTextureRegion(CompositableClient* aCompositable,
const ThebesBufferData& aThebesBufferData,
const nsIntRegion& aUpdatedRegion) override;
void ReleaseCompositable(const CompositableHandle& aHandle) override;
bool DestroyInTransaction(PTextureChild* aTexture) override;
bool DestroyInTransaction(const CompositableHandle& aHandle);
void RemoveTextureFromCompositable(CompositableClient* aCompositable,
TextureClient* aTexture) override;
void UseTextures(CompositableClient* aCompositable,
const nsTArray<TimedTextureClient>& aTextures) override;
void UseComponentAlphaTextures(CompositableClient* aCompositable,
TextureClient* aClientOnBlack,
TextureClient* aClientOnWhite) override;
void UpdateFwdTransactionId() override;
uint64_t GetFwdTransactionId() override;
bool InForwarderThread() override;
void ActorDestroy(ActorDestroyReason why) override;
virtual mozilla::ipc::IPCResult RecvWrUpdated(const wr::IdNamespace& aNewIdNamespace) override;
void AddIPDLReference() {
MOZ_ASSERT(mIPCOpen == false);
mIPCOpen = true;
AddRef();
}
void ReleaseIPDLReference() {
MOZ_ASSERT(mIPCOpen == true);
mIPCOpen = false;
Release();
}
bool AddOpDestroy(const OpDestroy& aOp);
nsTArray<WebRenderParentCommand> mParentCommands;
nsTArray<OpDestroy> mDestroyedActors;
nsDataHashtable<nsUint64HashKey, CompositableClient*> mCompositables;
nsTArray<nsTArray<ReadLockInit>> mReadLocks;
uint64_t mReadLockSequenceNumber;
bool mIsInTransaction;
bool mIsInClearCachedResources;
wr::IdNamespace mIdNamespace;
uint32_t mResourceId;
wr::PipelineId mPipelineId;
WebRenderLayerManager* mManager;
bool mIPCOpen;
bool mDestroyed;
uint32_t mFontKeysDeleted;
nsDataHashtable<UnscaledFontHashKey, wr::FontKey> mFontKeys;
uint32_t mFontInstanceKeysDeleted;
nsDataHashtable<ScaledFontHashKey, wr::FontInstanceKey> mFontInstanceKeys;
};
} // namespace layers
} // namespace mozilla
#endif // mozilla_layers_WebRenderBridgeChild_h