Bug 1449982 - Move the window id allocation to CompositorBridgeParent. r?nical
This includes a signature change from CompositorBridgeParentBase ->
CompositorBridgeParent which is not strictly required, but it makes it less
likely that we'll accidentally create a WebRenderAPI from somewhere else
and pass a nonsense window id. In effect, the signature change makes it
likely that only CompositorBridgeParent will allocate the window ids.
MozReview-Commit-ID: 8AnnmI8RytR
--- a/gfx/layers/ipc/CompositorBridgeParent.cpp
+++ b/gfx/layers/ipc/CompositorBridgeParent.cpp
@@ -1761,17 +1761,18 @@ CompositorBridgeParent::AllocPWebRenderB
#endif
MOZ_ASSERT(wr::AsLayersId(aPipelineId) == mRootLayerTreeID);
MOZ_ASSERT(!mWrBridge);
MOZ_ASSERT(!mCompositor);
MOZ_ASSERT(!mCompositorScheduler);
MOZ_ASSERT(mWidget);
RefPtr<widget::CompositorWidget> widget = mWidget;
- RefPtr<wr::WebRenderAPI> api = wr::WebRenderAPI::Create(this, Move(widget), aSize);
+ wr::WrWindowId windowId = wr::NewWindowId();
+ RefPtr<wr::WebRenderAPI> api = wr::WebRenderAPI::Create(this, Move(widget), windowId, aSize);
if (!api) {
mWrBridge = WebRenderBridgeParent::CreateDestroyed(aPipelineId);
mWrBridge.get()->AddRef(); // IPDL reference
*aIdNamespace = mWrBridge->GetIdNamespace();
*aTextureFactoryIdentifier = TextureFactoryIdentifier(LayersBackend::LAYERS_NONE);
return mWrBridge;
}
mAsyncImageManager = new AsyncImagePipelineManager(api->Clone());
--- a/gfx/webrender_bindings/WebRenderAPI.cpp
+++ b/gfx/webrender_bindings/WebRenderAPI.cpp
@@ -246,49 +246,47 @@ WebRenderAPI::InitExternalLogHandler()
/*static*/ void
WebRenderAPI::ShutdownExternalLogHandler()
{
mozilla::wr::wr_shutdown_external_log_handler();
}
/*static*/ already_AddRefed<WebRenderAPI>
-WebRenderAPI::Create(layers::CompositorBridgeParentBase* aBridge,
+WebRenderAPI::Create(layers::CompositorBridgeParent* aBridge,
RefPtr<widget::CompositorWidget>&& aWidget,
+ const wr::WrWindowId& aWindowId,
LayoutDeviceIntSize aSize)
{
MOZ_ASSERT(aBridge);
MOZ_ASSERT(aWidget);
static_assert(sizeof(size_t) == sizeof(uintptr_t),
"The FFI bindings assume size_t is the same size as uintptr_t!");
- static uint64_t sNextId = 1;
- auto id = NewWindowId(sNextId++);
-
wr::DocumentHandle* docHandle = nullptr;
uint32_t maxTextureSize = 0;
bool useANGLE = false;
layers::SyncHandle syncHandle = 0;
// Dispatch a synchronous task because the DocumentHandle object needs to be created
// on the render thread. If need be we could delay waiting on this task until
// the next time we need to access the DocumentHandle object.
layers::SynchronousTask task("Create Renderer");
auto event = MakeUnique<NewRenderer>(&docHandle, aBridge, &maxTextureSize, &useANGLE,
Move(aWidget), &task, aSize,
&syncHandle);
- RenderThread::Get()->RunEvent(id, Move(event));
+ RenderThread::Get()->RunEvent(aWindowId, Move(event));
task.Wait();
if (!docHandle) {
return nullptr;
}
- return RefPtr<WebRenderAPI>(new WebRenderAPI(docHandle, id, maxTextureSize, useANGLE, syncHandle)).forget();
+ return RefPtr<WebRenderAPI>(new WebRenderAPI(docHandle, aWindowId, maxTextureSize, useANGLE, syncHandle)).forget();
}
already_AddRefed<WebRenderAPI>
WebRenderAPI::Clone()
{
wr::DocumentHandle* docHandle = nullptr;
wr_api_clone(mDocHandle, &docHandle);
--- a/gfx/webrender_bindings/WebRenderAPI.h
+++ b/gfx/webrender_bindings/WebRenderAPI.h
@@ -25,17 +25,17 @@ namespace mozilla {
struct DisplayItemClipChain;
namespace widget {
class CompositorWidget;
}
namespace layers {
-class CompositorBridgeParentBase;
+class CompositorBridgeParent;
class WebRenderBridgeParent;
}
namespace wr {
class DisplayListBuilder;
class RendererOGL;
class RendererEvent;
@@ -147,18 +147,19 @@ protected:
};
class WebRenderAPI
{
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(WebRenderAPI);
public:
/// This can be called on the compositor thread only.
- static already_AddRefed<WebRenderAPI> Create(layers::CompositorBridgeParentBase* aBridge,
+ static already_AddRefed<WebRenderAPI> Create(layers::CompositorBridgeParent* aBridge,
RefPtr<widget::CompositorWidget>&& aWidget,
+ const wr::WrWindowId& aWindowId,
LayoutDeviceIntSize aSize);
already_AddRefed<WebRenderAPI> CreateDocument(LayoutDeviceIntSize aSize, int8_t aLayerIndex);
// Redirect the WR's log to gfxCriticalError/Note.
static void InitExternalLogHandler();
static void ShutdownExternalLogHandler();
--- a/gfx/webrender_bindings/WebRenderTypes.cpp
+++ b/gfx/webrender_bindings/WebRenderTypes.cpp
@@ -6,16 +6,26 @@
#include "WebRenderTypes.h"
#include "mozilla/ipc/ByteBuf.h"
namespace mozilla {
namespace wr {
+WindowId
+NewWindowId()
+{
+ static uint64_t sNextId = 1;
+
+ WindowId id;
+ id.mHandle = sNextId++;
+ return id;
+}
+
void
Assign_WrVecU8(wr::WrVecU8& aVec, mozilla::ipc::ByteBuf&& aOther)
{
aVec.data = aOther.mData;
aVec.length = aOther.mLen;
aVec.capacity = aOther.mCapacity;
aOther.mData = nullptr;
aOther.mLen = 0;
--- a/gfx/webrender_bindings/WebRenderTypes.h
+++ b/gfx/webrender_bindings/WebRenderTypes.h
@@ -39,21 +39,18 @@ typedef wr::WrExternalImageId ExternalIm
typedef wr::WrDebugFlags DebugFlags;
typedef mozilla::Maybe<mozilla::wr::WrImageMask> MaybeImageMask;
typedef Maybe<ExternalImageId> MaybeExternalImageId;
typedef Maybe<FontInstanceOptions> MaybeFontInstanceOptions;
typedef Maybe<FontInstancePlatformOptions> MaybeFontInstancePlatformOptions;
-inline WindowId NewWindowId(uint64_t aId) {
- WindowId id;
- id.mHandle = aId;
- return id;
-}
+/* Generate a brand new window id and return it. */
+WindowId NewWindowId();
inline Epoch NewEpoch(uint32_t aEpoch) {
Epoch e;
e.mHandle = aEpoch;
return e;
}
inline DebugFlags NewDebugFlags(uint32_t aFlags) {