From 924db561d611072dccbe5908cbda5d42514f82da Mon Sep 17 00:00:00 2001 From: Nicolas Silva Date: Mon, 24 Sep 2018 17:53:36 +0200 Subject: [PATCH] Bug 1477819 - Expose Transaction::Notify in WebRender's C++ wrapper. r=jrmuizel Differential Revision: https://phabricator.services.mozilla.com/D6515 --HG-- extra : source : 8d58404d71eb944d9dda642c8dc2f53f1d291671 extra : histedit_source : f469b56422dadfe5a5f67faa9e9efddd5839d1ce --- gfx/webrender_bindings/WebRenderAPI.cpp | 17 +++++++++++++++++ gfx/webrender_bindings/WebRenderAPI.h | 14 ++++++++++++++ gfx/webrender_bindings/src/bindings.rs | 17 +++++++++++++++++ .../webrender_ffi_generated.h | 19 +++++++++++++++++++ 4 files changed, 67 insertions(+) diff --git a/gfx/webrender_bindings/WebRenderAPI.cpp b/gfx/webrender_bindings/WebRenderAPI.cpp index 0e969fa4cae6..65cb7aa3eef8 100644 --- a/gfx/webrender_bindings/WebRenderAPI.cpp +++ b/gfx/webrender_bindings/WebRenderAPI.cpp @@ -588,6 +588,11 @@ TransactionBuilder::Clear() wr_resource_updates_clear(mTxn); } +void +TransactionBuilder::Notify(wr::Checkpoint aWhen, UniquePtr aEvent) { + wr_transaction_notify(mTxn, aWhen, reinterpret_cast(aEvent.release())); +} + void TransactionBuilder::AddImage(ImageKey key, const ImageDescriptor& aDescriptor, wr::Vec& aBytes) @@ -1359,3 +1364,15 @@ DisplayListBuilder::FixedPosScrollTargetTracker::GetScrollTargetForASR(const Act } // namespace wr } // namespace mozilla + +extern "C" { + +void wr_transaction_notification_notified(uintptr_t aHandler, mozilla::wr::Checkpoint aWhen) { + auto handler = reinterpret_cast(aHandler); + handler->Notify(aWhen); + // TODO: it would be better to get a callback when the object is destroyed on the + // rust side and delete then. + delete handler; +} + +} // extern C diff --git a/gfx/webrender_bindings/WebRenderAPI.h b/gfx/webrender_bindings/WebRenderAPI.h index 8dcf1ca40390..450b0e748fa9 100644 --- a/gfx/webrender_bindings/WebRenderAPI.h +++ b/gfx/webrender_bindings/WebRenderAPI.h @@ -50,6 +50,18 @@ struct Line { wr::LineStyle style; }; +/// A handler that can be bundled into a transaction and notified at specific +/// points in the rendering pipeline, such as after scene building or after +/// frame building. +/// +/// If for any reason the handler is dropped before reaching the requested +/// point, it is notified with the value Checkpoint::TransactionDropped. +/// So it is safe to assume that the handler will be notified "at some point". +class NotificationHandler { +public: + virtual void Notify(wr::Checkpoint aCheckpoint) = 0; + virtual ~NotificationHandler() = default; +}; class TransactionBuilder { public: @@ -148,6 +160,8 @@ public: void DeleteFontInstance(wr::FontInstanceKey aKey); + void Notify(wr::Checkpoint aWhen, UniquePtr aHandler); + void Clear(); bool UseSceneBuilderThread() const { return mUseSceneBuilderThread; } diff --git a/gfx/webrender_bindings/src/bindings.rs b/gfx/webrender_bindings/src/bindings.rs index f59a50655149..cde9940ce430 100644 --- a/gfx/webrender_bindings/src/bindings.rs +++ b/gfx/webrender_bindings/src/bindings.rs @@ -504,6 +504,8 @@ extern "C" { fn wr_notifier_external_event(window_id: WrWindowId, raw_event: usize); fn wr_schedule_render(window_id: WrWindowId); + + fn wr_transaction_notification_notified(handler: usize, when: Checkpoint); } impl RenderNotifier for CppNotifier { @@ -1097,6 +1099,21 @@ pub extern "C" fn wr_transaction_is_empty(txn: &Transaction) -> bool { txn.is_empty() } +#[no_mangle] +pub extern "C" fn wr_transaction_notify(txn: &mut Transaction, when: Checkpoint, event: usize) { + struct GeckoNotification(usize); + impl NotificationHandler for GeckoNotification { + fn notify(&self, when: Checkpoint) { + unsafe { + wr_transaction_notification_notified(self.0, when); + } + } + } + + let handler = Arc::new(GeckoNotification(event)); + txn.notify(NotificationRequest::new(when, handler)); +} + #[no_mangle] pub extern "C" fn wr_transaction_update_epoch( txn: &mut Transaction, diff --git a/gfx/webrender_bindings/webrender_ffi_generated.h b/gfx/webrender_bindings/webrender_ffi_generated.h index a29efe9ad966..713ef5cb1450 100644 --- a/gfx/webrender_bindings/webrender_ffi_generated.h +++ b/gfx/webrender_bindings/webrender_ffi_generated.h @@ -43,6 +43,16 @@ enum class BoxShadowClipMode : uint32_t { Sentinel /* this must be last for serialization purposes. */ }; +enum class Checkpoint : uint32_t { + SceneBuilt, + FrameBuilt, + // NotificationRequests get notified with this if they get dropped without having been + // notified. This provides the guarantee that if a request is created it will get notified. + TransactionDropped, + + Sentinel /* this must be last for serialization purposes. */ +}; + enum class ClipMode { Clip, ClipOut, @@ -1752,6 +1762,15 @@ WR_INLINE Transaction *wr_transaction_new(bool aDoAsync) WR_FUNC; +extern void wr_transaction_notification_notified(uintptr_t aHandler, + Checkpoint aWhen); + +WR_INLINE +void wr_transaction_notify(Transaction *aTxn, + Checkpoint aWhen, + uintptr_t aEvent) +WR_FUNC; + WR_INLINE void wr_transaction_remove_pipeline(Transaction *aTxn, WrPipelineId aPipelineId)