From df4c374ed96186bc13d57dfa5ea403a53107bbaa Mon Sep 17 00:00:00 2001 From: Kartikaya Gupta Date: Wed, 16 Nov 2016 13:54:13 -0500 Subject: [PATCH] Bug 1318066 - Provide WR with the path to the resources directory. r=jrmuizel? MozReview-Commit-ID: JSatfZmk6Fh --- gfx/layers/ipc/CompositorBridgeChild.cpp | 3 ++- gfx/layers/ipc/CompositorBridgeChild.h | 3 ++- gfx/layers/ipc/CompositorBridgeParent.cpp | 6 ++++-- gfx/layers/ipc/CompositorBridgeParent.h | 3 ++- .../ipc/CrossProcessCompositorBridgeParent.cpp | 5 +++-- .../ipc/CrossProcessCompositorBridgeParent.h | 3 ++- gfx/layers/ipc/PCompositorBridge.ipdl | 2 +- gfx/layers/wr/WebRenderBridgeParent.cpp | 5 ++++- gfx/layers/wr/WebRenderBridgeParent.h | 1 + gfx/layers/wr/WebRenderLayerManager.cpp | 17 ++++++++++++++++- gfx/webrender/src/bindings.rs | 11 ++++++----- gfx/webrender/webrender.h | 2 +- 12 files changed, 44 insertions(+), 17 deletions(-) diff --git a/gfx/layers/ipc/CompositorBridgeChild.cpp b/gfx/layers/ipc/CompositorBridgeChild.cpp index 3189d853eb15..c2acf4226211 100644 --- a/gfx/layers/ipc/CompositorBridgeChild.cpp +++ b/gfx/layers/ipc/CompositorBridgeChild.cpp @@ -1146,7 +1146,8 @@ CompositorBridgeChild::HandleFatalError(const char* aName, const char* aMsg) con } PWebRenderBridgeChild* -CompositorBridgeChild::AllocPWebRenderBridgeChild(const uint64_t& aPipelineId) +CompositorBridgeChild::AllocPWebRenderBridgeChild(const uint64_t& aPipelineId, + const nsString& aResourcePath) { WebRenderBridgeChild* child = new WebRenderBridgeChild(aPipelineId); child->AddRef(); diff --git a/gfx/layers/ipc/CompositorBridgeChild.h b/gfx/layers/ipc/CompositorBridgeChild.h index ccb9dd9bd0a7..398282d30086 100644 --- a/gfx/layers/ipc/CompositorBridgeChild.h +++ b/gfx/layers/ipc/CompositorBridgeChild.h @@ -228,7 +228,8 @@ public: void WillEndTransaction(); - PWebRenderBridgeChild* AllocPWebRenderBridgeChild(const uint64_t& aPipelineId) override; + PWebRenderBridgeChild* AllocPWebRenderBridgeChild(const uint64_t& aPipelineId, + const nsString& aResourcePath) override; bool DeallocPWebRenderBridgeChild(PWebRenderBridgeChild* aActor) override; private: diff --git a/gfx/layers/ipc/CompositorBridgeParent.cpp b/gfx/layers/ipc/CompositorBridgeParent.cpp index 83c0bd12ca9f..ebfcbbf4a813 100644 --- a/gfx/layers/ipc/CompositorBridgeParent.cpp +++ b/gfx/layers/ipc/CompositorBridgeParent.cpp @@ -1841,7 +1841,8 @@ CompositorBridgeParent::RecvAdoptChild(const uint64_t& child) } PWebRenderBridgeParent* -CompositorBridgeParent::AllocPWebRenderBridgeParent(const uint64_t& aPipelineId) +CompositorBridgeParent::AllocPWebRenderBridgeParent(const uint64_t& aPipelineId, + const nsString& aResourcePath) { #ifndef MOZ_ENABLE_WEBRENDER // Extra guard since this in the parent process and we don't want a malicious @@ -1851,7 +1852,8 @@ CompositorBridgeParent::AllocPWebRenderBridgeParent(const uint64_t& aPipelineId) MOZ_ASSERT(aPipelineId == mRootLayerTreeID); RefPtr glc(gl::GLContextProvider::CreateForCompositorWidget(mWidget, true)); - WebRenderBridgeParent* parent = new WebRenderBridgeParent(aPipelineId, mWidget, glc.get(), nullptr); + WebRenderBridgeParent* parent = new WebRenderBridgeParent(aPipelineId, + &aResourcePath, mWidget, glc.get(), nullptr); parent->AddRef(); // IPDL reference MonitorAutoLock lock(*sIndirectLayerTreesLock); MOZ_ASSERT(sIndirectLayerTrees[aPipelineId].mWRBridge == nullptr); diff --git a/gfx/layers/ipc/CompositorBridgeParent.h b/gfx/layers/ipc/CompositorBridgeParent.h index f72537ee6827..e28ec9f0900b 100644 --- a/gfx/layers/ipc/CompositorBridgeParent.h +++ b/gfx/layers/ipc/CompositorBridgeParent.h @@ -539,7 +539,8 @@ public: return !!mApzcTreeManager; } - PWebRenderBridgeParent* AllocPWebRenderBridgeParent(const uint64_t& aPipelineId) override; + PWebRenderBridgeParent* AllocPWebRenderBridgeParent(const uint64_t& aPipelineId, + const nsString& aResourcePath) override; bool DeallocPWebRenderBridgeParent(PWebRenderBridgeParent* aActor) override; private: diff --git a/gfx/layers/ipc/CrossProcessCompositorBridgeParent.cpp b/gfx/layers/ipc/CrossProcessCompositorBridgeParent.cpp index 9bf807081b63..8d1619b23def 100644 --- a/gfx/layers/ipc/CrossProcessCompositorBridgeParent.cpp +++ b/gfx/layers/ipc/CrossProcessCompositorBridgeParent.cpp @@ -248,7 +248,8 @@ CrossProcessCompositorBridgeParent::DeallocPAPZParent(PAPZParent* aActor) } PWebRenderBridgeParent* -CrossProcessCompositorBridgeParent::AllocPWebRenderBridgeParent(const uint64_t& aPipelineId) +CrossProcessCompositorBridgeParent::AllocPWebRenderBridgeParent(const uint64_t& aPipelineId, + const nsString& aResourcePath) { #ifndef MOZ_ENABLE_WEBRENDER // Extra guard since this in the parent process and we don't want a malicious @@ -268,7 +269,7 @@ CrossProcessCompositorBridgeParent::AllocPWebRenderBridgeParent(const uint64_t& WebRenderBridgeParent* root = sIndirectLayerTrees[cbp->RootLayerTreeId()].mWRBridge.get(); WebRenderBridgeParent* parent = new WebRenderBridgeParent( - aPipelineId, nullptr, root->GLContext(), root->WindowState()); + aPipelineId, nullptr, nullptr, root->GLContext(), root->WindowState()); parent->AddRef(); // IPDL reference sIndirectLayerTrees[aPipelineId].mWRBridge = parent; diff --git a/gfx/layers/ipc/CrossProcessCompositorBridgeParent.h b/gfx/layers/ipc/CrossProcessCompositorBridgeParent.h index 3c52fb55b99a..ffe2d7999efb 100644 --- a/gfx/layers/ipc/CrossProcessCompositorBridgeParent.h +++ b/gfx/layers/ipc/CrossProcessCompositorBridgeParent.h @@ -153,7 +153,8 @@ public: virtual void UpdatePaintTime(LayerTransactionParent* aLayerTree, const TimeDuration& aPaintTime) override; - PWebRenderBridgeParent* AllocPWebRenderBridgeParent(const uint64_t& aPipelineId) override; + PWebRenderBridgeParent* AllocPWebRenderBridgeParent(const uint64_t& aPipelineId, + const nsString& aResourcePath) override; bool DeallocPWebRenderBridgeParent(PWebRenderBridgeParent* aActor) override; protected: diff --git a/gfx/layers/ipc/PCompositorBridge.ipdl b/gfx/layers/ipc/PCompositorBridge.ipdl index e2bc38581d9a..25c845066d99 100644 --- a/gfx/layers/ipc/PCompositorBridge.ipdl +++ b/gfx/layers/ipc/PCompositorBridge.ipdl @@ -231,7 +231,7 @@ parent: sync SyncWithCompositor(); // The pipelineId is the same as the layersId - async PWebRenderBridge(uint64_t pipelineId); + async PWebRenderBridge(uint64_t pipelineId, nsString resourcePath); child: // Send back Compositor Frame Metrics from APZCs so tiled layers can diff --git a/gfx/layers/wr/WebRenderBridgeParent.cpp b/gfx/layers/wr/WebRenderBridgeParent.cpp index c213a28a96f9..18f2521b8d9c 100644 --- a/gfx/layers/wr/WebRenderBridgeParent.cpp +++ b/gfx/layers/wr/WebRenderBridgeParent.cpp @@ -14,6 +14,7 @@ namespace mozilla { namespace layers { WebRenderBridgeParent::WebRenderBridgeParent(const uint64_t& aPipelineId, + const nsString* aResourcePath, widget::CompositorWidget* aWidget, gl::GLContext* aGlContext, wrwindowstate* aWrWindowState) @@ -29,7 +30,9 @@ WebRenderBridgeParent::WebRenderBridgeParent(const uint64_t& aPipelineId, // i.e. the one created by the CompositorBridgeParent as opposed to the // CrossProcessCompositorBridgeParent MOZ_ASSERT(mWidget); - mWRWindowState = wr_init_window(mPipelineId); + MOZ_ASSERT(aResourcePath); + mWRWindowState = wr_init_window(mPipelineId, + NS_ConvertUTF16toUTF8(*aResourcePath).get()); } } diff --git a/gfx/layers/wr/WebRenderBridgeParent.h b/gfx/layers/wr/WebRenderBridgeParent.h index ff6fee471856..f71ca369152d 100644 --- a/gfx/layers/wr/WebRenderBridgeParent.h +++ b/gfx/layers/wr/WebRenderBridgeParent.h @@ -29,6 +29,7 @@ class WebRenderBridgeParent final : public PWebRenderBridgeParent public: WebRenderBridgeParent(const uint64_t& aPipelineId, + const nsString* aResourcePath, widget::CompositorWidget* aWidget, gl::GLContext* aGlContext, wrwindowstate* aWrWindowState); diff --git a/gfx/layers/wr/WebRenderLayerManager.cpp b/gfx/layers/wr/WebRenderLayerManager.cpp index 7b849c85cf6a..a282c7d7c0ab 100644 --- a/gfx/layers/wr/WebRenderLayerManager.cpp +++ b/gfx/layers/wr/WebRenderLayerManager.cpp @@ -11,6 +11,8 @@ #include "mozilla/layers/AsyncCompositionManager.h" #include "mozilla/layers/WebRenderBridgeChild.h" #include "mozilla/widget/PlatformWidgetTypes.h" +#include "nsDirectoryService.h" +#include "nsDirectoryServiceDefs.h" #include "nsThreadUtils.h" #include "TreeTraversal.h" #include "WebRenderCanvasLayer.h" @@ -142,7 +144,20 @@ WebRenderLayerManager::Initialize(PCompositorBridgeChild* aCBChild, uint64_t aLa { MOZ_ASSERT(mWRChild == nullptr); - PWebRenderBridgeChild* bridge = aCBChild->SendPWebRenderBridgeConstructor(aLayersId); + // Since the WebRenderBridgeParent might be in the compositor process with + // no access to the directory service, we have to get the directory here and + // send it over. We only need to do this for the parent process; the content + // processes ignore it anyway since they don't initialize new WR renderer + // instances. + nsAutoString resourcePath; + if (XRE_IsParentProcess()) { + nsCOMPtr greDir; + nsDirectoryService::gService->Get(NS_GRE_DIR, NS_GET_IID(nsIFile), getter_AddRefs(greDir)); + greDir->Append(NS_LITERAL_STRING("webrender")); + greDir->GetPath(resourcePath); + } + + PWebRenderBridgeChild* bridge = aCBChild->SendPWebRenderBridgeConstructor(aLayersId, resourcePath); MOZ_ASSERT(bridge); mWRChild = static_cast(bridge); LayoutDeviceIntSize size = mWidget->GetClientSize(); diff --git a/gfx/webrender/src/bindings.rs b/gfx/webrender/src/bindings.rs index 43ecc809e3f2..b08715c8731b 100644 --- a/gfx/webrender/src/bindings.rs +++ b/gfx/webrender/src/bindings.rs @@ -11,7 +11,7 @@ use webrender_traits::{Epoch, ColorF}; use webrender_traits::{ImageFormat, ImageKey, ImageMask, ImageRendering, RendererKind}; use std::mem; use std::slice; -use std::os::raw::c_uchar; +use std::os::raw::{c_char, c_uchar}; #[cfg(target_os = "linux")] mod linux { @@ -238,9 +238,10 @@ pub struct WrState { } #[no_mangle] -pub extern fn wr_init_window(root_pipeline_id: u64) -> *mut WrWindowState { - // hack to find the directory for the shaders - let res_path = concat!(env!("CARGO_MANIFEST_DIR"),"/res"); +pub extern fn wr_init_window(root_pipeline_id: u64, path_utf8: *const c_char) -> *mut WrWindowState { + let res_path = unsafe { + CStr::from_ptr(path_utf8).to_string_lossy().into_owned() + }; let library = GlLibrary::new(); gl::load_with(|symbol| library.query(symbol)); @@ -556,4 +557,4 @@ pub extern fn wr_free_buffer(vec_ptr: *mut c_uchar, length: u32, capacity: u32) unsafe { let rebuilt = Vec::from_raw_parts(vec_ptr, length as usize, capacity as usize); } -} \ No newline at end of file +} diff --git a/gfx/webrender/webrender.h b/gfx/webrender/webrender.h index 1cf2757a1c79..a4b1a9307988 100644 --- a/gfx/webrender/webrender.h +++ b/gfx/webrender/webrender.h @@ -47,7 +47,7 @@ struct wrstate; #endif WR_INLINE wrwindowstate* -wr_init_window(uint64_t root_pipeline_id) +wr_init_window(uint64_t root_pipeline_id, const char* path_utf8) WR_FUNC; WR_INLINE wrstate*