Bug 1699062 - Flatten toolkit/themes/*/global/alerts/. r=desktop-theme-reviewers,dao
[gecko.git] / gfx / webrender_bindings / WebRenderAPI.cpp
blob50a77b5d21f635dacd152717058f8f70883bbf2f
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "WebRenderAPI.h"
9 #include "mozilla/StaticPrefs_gfx.h"
10 #include "mozilla/ipc/ByteBuf.h"
11 #include "mozilla/webrender/RendererOGL.h"
12 #include "mozilla/gfx/gfxVars.h"
13 #include "mozilla/layers/CompositorThread.h"
14 #include "mozilla/ToString.h"
15 #include "mozilla/webrender/RenderCompositor.h"
16 #include "mozilla/widget/CompositorWidget.h"
17 #include "mozilla/layers/SynchronousTask.h"
18 #include "TextDrawTarget.h"
19 #include "malloc_decls.h"
21 // clang-format off
22 #define WRDL_LOG(...)
23 //#define WRDL_LOG(...) printf_stderr("WRDL(%p): " __VA_ARGS__)
24 //#define WRDL_LOG(...) if (XRE_IsContentProcess()) printf_stderr("WRDL(%p): " __VA_ARGS__)
25 // clang-format on
27 namespace mozilla {
28 using namespace layers;
30 namespace wr {
32 MOZ_DEFINE_MALLOC_SIZE_OF(WebRenderMallocSizeOf)
33 MOZ_DEFINE_MALLOC_ENCLOSING_SIZE_OF(WebRenderMallocEnclosingSizeOf)
35 enum SideBitsPacked {
36 eSideBitsPackedTop = 0x1000,
37 eSideBitsPackedRight = 0x2000,
38 eSideBitsPackedBottom = 0x4000,
39 eSideBitsPackedLeft = 0x8000
42 static uint16_t SideBitsToHitInfoBits(SideBits aSideBits) {
43 uint16_t ret = 0;
44 if (aSideBits & SideBits::eTop) {
45 ret |= eSideBitsPackedTop;
47 if (aSideBits & SideBits::eRight) {
48 ret |= eSideBitsPackedRight;
50 if (aSideBits & SideBits::eBottom) {
51 ret |= eSideBitsPackedBottom;
53 if (aSideBits & SideBits::eLeft) {
54 ret |= eSideBitsPackedLeft;
56 return ret;
59 class NewRenderer : public RendererEvent {
60 public:
61 NewRenderer(wr::DocumentHandle** aDocHandle,
62 layers::CompositorBridgeParent* aBridge,
63 WebRenderBackend* aBackend, WebRenderCompositor* aCompositor,
64 int32_t* aMaxTextureSize, bool* aUseANGLE, bool* aUseDComp,
65 bool* aUseTripleBuffering, bool* aSupportsExternalBufferTextures,
66 RefPtr<widget::CompositorWidget>&& aWidget,
67 layers::SynchronousTask* aTask, LayoutDeviceIntSize aSize,
68 layers::WindowKind aWindowKind, layers::SyncHandle* aHandle,
69 nsACString* aError)
70 : mDocHandle(aDocHandle),
71 mBackend(aBackend),
72 mCompositor(aCompositor),
73 mMaxTextureSize(aMaxTextureSize),
74 mUseANGLE(aUseANGLE),
75 mUseDComp(aUseDComp),
76 mUseTripleBuffering(aUseTripleBuffering),
77 mSupportsExternalBufferTextures(aSupportsExternalBufferTextures),
78 mBridge(aBridge),
79 mCompositorWidget(std::move(aWidget)),
80 mTask(aTask),
81 mSize(aSize),
82 mWindowKind(aWindowKind),
83 mSyncHandle(aHandle),
84 mError(aError) {
85 MOZ_COUNT_CTOR(NewRenderer);
88 MOZ_COUNTED_DTOR(NewRenderer)
90 void Run(RenderThread& aRenderThread, WindowId aWindowId) override {
91 layers::AutoCompleteTask complete(mTask);
93 UniquePtr<RenderCompositor> compositor =
94 RenderCompositor::Create(std::move(mCompositorWidget), *mError);
95 if (!compositor) {
96 if (!mError->IsEmpty()) {
97 gfxCriticalNote << mError->BeginReading();
99 return;
102 *mBackend = compositor->BackendType();
103 *mCompositor = compositor->CompositorType();
104 *mUseANGLE = compositor->UseANGLE();
105 *mUseDComp = compositor->UseDComp();
106 *mUseTripleBuffering = compositor->UseTripleBuffering();
107 *mSupportsExternalBufferTextures =
108 compositor->SupportsExternalBufferTextures();
110 // Only allow the panic on GL error functionality in nightly builds,
111 // since it (deliberately) crashes the GPU process if any GL call
112 // returns an error code.
113 bool panic_on_gl_error = false;
114 #ifdef NIGHTLY_BUILD
115 panic_on_gl_error =
116 StaticPrefs::gfx_webrender_panic_on_gl_error_AtStartup();
117 #endif
119 bool isMainWindow = true; // TODO!
120 bool supportLowPriorityTransactions = isMainWindow;
121 bool supportLowPriorityThreadpool =
122 supportLowPriorityTransactions &&
123 StaticPrefs::gfx_webrender_enable_low_priority_pool();
124 wr::Renderer* wrRenderer = nullptr;
125 char* errorMessage = nullptr;
126 int picTileWidth = StaticPrefs::gfx_webrender_picture_tile_width();
127 int picTileHeight = StaticPrefs::gfx_webrender_picture_tile_height();
128 auto* swgl = compositor->swgl();
129 auto* gl = (compositor->gl() && !swgl) ? compositor->gl() : nullptr;
130 auto* progCache = (aRenderThread.GetProgramCache() && !swgl)
131 ? aRenderThread.GetProgramCache()->Raw()
132 : nullptr;
133 auto* shaders = (aRenderThread.GetShaders() && !swgl)
134 ? aRenderThread.GetShaders()->RawShaders()
135 : nullptr;
137 if (!wr_window_new(
138 aWindowId, mSize.width, mSize.height,
139 mWindowKind == WindowKind::MAIN, supportLowPriorityTransactions,
140 supportLowPriorityThreadpool, gfx::gfxVars::UseGLSwizzle(),
141 gfx::gfxVars::UseWebRenderScissoredCacheClears(),
142 #ifdef NIGHTLY_BUILD
143 StaticPrefs::gfx_webrender_start_debug_server(),
144 #else
145 false,
146 #endif
147 swgl, gl, compositor->SurfaceOriginIsTopLeft(), progCache, shaders,
148 aRenderThread.ThreadPool().Raw(),
149 aRenderThread.ThreadPoolLP().Raw(), &WebRenderMallocSizeOf,
150 &WebRenderMallocEnclosingSizeOf, 0, compositor.get(),
151 compositor->ShouldUseNativeCompositor(),
152 compositor->GetMaxUpdateRects(), compositor->UsePartialPresent(),
153 compositor->GetMaxPartialPresentRects(),
154 compositor->ShouldDrawPreviousPartialPresentRegions(), mDocHandle,
155 &wrRenderer, mMaxTextureSize, &errorMessage,
156 StaticPrefs::gfx_webrender_enable_gpu_markers_AtStartup(),
157 panic_on_gl_error, picTileWidth, picTileHeight)) {
158 // wr_window_new puts a message into gfxCriticalNote if it returns false
159 MOZ_ASSERT(errorMessage);
160 mError->AssignASCII(errorMessage);
161 wr_api_free_error_msg(errorMessage);
162 return;
164 MOZ_ASSERT(wrRenderer);
166 RefPtr<RenderThread> thread = &aRenderThread;
167 auto renderer =
168 MakeUnique<RendererOGL>(std::move(thread), std::move(compositor),
169 aWindowId, wrRenderer, mBridge);
170 if (wrRenderer && renderer) {
171 wr::WrExternalImageHandler handler = renderer->GetExternalImageHandler();
172 wr_renderer_set_external_image_handler(wrRenderer, &handler);
175 if (renderer) {
176 layers::SyncObjectHost* syncObj = renderer->GetSyncObject();
177 if (syncObj) {
178 *mSyncHandle = syncObj->GetSyncHandle();
182 aRenderThread.AddRenderer(aWindowId, std::move(renderer));
185 private:
186 wr::DocumentHandle** mDocHandle;
187 WebRenderBackend* mBackend;
188 WebRenderCompositor* mCompositor;
189 int32_t* mMaxTextureSize;
190 bool* mUseANGLE;
191 bool* mUseDComp;
192 bool* mUseTripleBuffering;
193 bool* mSupportsExternalBufferTextures;
194 layers::CompositorBridgeParent* mBridge;
195 RefPtr<widget::CompositorWidget> mCompositorWidget;
196 layers::SynchronousTask* mTask;
197 LayoutDeviceIntSize mSize;
198 layers::WindowKind mWindowKind;
199 layers::SyncHandle* mSyncHandle;
200 nsACString* mError;
203 class RemoveRenderer : public RendererEvent {
204 public:
205 explicit RemoveRenderer(layers::SynchronousTask* aTask) : mTask(aTask) {
206 MOZ_COUNT_CTOR(RemoveRenderer);
209 MOZ_COUNTED_DTOR_OVERRIDE(RemoveRenderer)
211 void Run(RenderThread& aRenderThread, WindowId aWindowId) override {
212 aRenderThread.RemoveRenderer(aWindowId);
213 layers::AutoCompleteTask complete(mTask);
216 private:
217 layers::SynchronousTask* mTask;
220 TransactionBuilder::TransactionBuilder(WebRenderAPI* aApi,
221 bool aUseSceneBuilderThread)
222 : mUseSceneBuilderThread(aUseSceneBuilderThread),
223 mApiBackend(aApi->GetBackendType()) {
224 mTxn = wr_transaction_new(mUseSceneBuilderThread);
227 TransactionBuilder::~TransactionBuilder() { wr_transaction_delete(mTxn); }
229 void TransactionBuilder::SetLowPriority(bool aIsLowPriority) {
230 wr_transaction_set_low_priority(mTxn, aIsLowPriority);
233 void TransactionBuilder::UpdateEpoch(PipelineId aPipelineId, Epoch aEpoch) {
234 wr_transaction_update_epoch(mTxn, aPipelineId, aEpoch);
237 void TransactionBuilder::SetRootPipeline(PipelineId aPipelineId) {
238 wr_transaction_set_root_pipeline(mTxn, aPipelineId);
241 void TransactionBuilder::RemovePipeline(PipelineId aPipelineId) {
242 wr_transaction_remove_pipeline(mTxn, aPipelineId);
245 void TransactionBuilder::SetDisplayList(
246 const gfx::DeviceColor& aBgColor, Epoch aEpoch,
247 const wr::LayoutSize& aViewportSize, wr::WrPipelineId pipeline_id,
248 wr::BuiltDisplayListDescriptor dl_descriptor, wr::Vec<uint8_t>& dl_data) {
249 wr_transaction_set_display_list(mTxn, aEpoch, ToColorF(aBgColor),
250 aViewportSize, pipeline_id, dl_descriptor,
251 &dl_data.inner);
254 void TransactionBuilder::ClearDisplayList(Epoch aEpoch,
255 wr::WrPipelineId aPipelineId) {
256 wr_transaction_clear_display_list(mTxn, aEpoch, aPipelineId);
259 void TransactionBuilder::GenerateFrame(const VsyncId& aVsyncId) {
260 wr_transaction_generate_frame(mTxn, aVsyncId.mId);
263 void TransactionBuilder::InvalidateRenderedFrame() {
264 wr_transaction_invalidate_rendered_frame(mTxn);
267 void TransactionBuilder::UpdateDynamicProperties(
268 const nsTArray<wr::WrOpacityProperty>& aOpacityArray,
269 const nsTArray<wr::WrTransformProperty>& aTransformArray,
270 const nsTArray<wr::WrColorProperty>& aColorArray) {
271 wr_transaction_update_dynamic_properties(
272 mTxn, aOpacityArray.IsEmpty() ? nullptr : aOpacityArray.Elements(),
273 aOpacityArray.Length(),
274 aTransformArray.IsEmpty() ? nullptr : aTransformArray.Elements(),
275 aTransformArray.Length(),
276 aColorArray.IsEmpty() ? nullptr : aColorArray.Elements(),
277 aColorArray.Length());
280 bool TransactionBuilder::IsEmpty() const {
281 return wr_transaction_is_empty(mTxn);
284 bool TransactionBuilder::IsResourceUpdatesEmpty() const {
285 return wr_transaction_resource_updates_is_empty(mTxn);
288 bool TransactionBuilder::IsRenderedFrameInvalidated() const {
289 return wr_transaction_is_rendered_frame_invalidated(mTxn);
292 void TransactionBuilder::SetDocumentView(
293 const LayoutDeviceIntRect& aDocumentRect) {
294 wr::DeviceIntRect wrDocRect;
295 wrDocRect.origin.x = aDocumentRect.x;
296 wrDocRect.origin.y = aDocumentRect.y;
297 wrDocRect.size.width = aDocumentRect.width;
298 wrDocRect.size.height = aDocumentRect.height;
299 wr_transaction_set_document_view(mTxn, &wrDocRect);
302 void TransactionBuilder::UpdateScrollPosition(
303 const wr::WrPipelineId& aPipelineId,
304 const layers::ScrollableLayerGuid::ViewID& aScrollId,
305 const wr::LayoutPoint& aScrollPosition) {
306 wr_transaction_scroll_layer(mTxn, aPipelineId, aScrollId, aScrollPosition);
309 TransactionWrapper::TransactionWrapper(Transaction* aTxn) : mTxn(aTxn) {}
311 void TransactionWrapper::UpdateDynamicProperties(
312 const nsTArray<wr::WrOpacityProperty>& aOpacityArray,
313 const nsTArray<wr::WrTransformProperty>& aTransformArray,
314 const nsTArray<wr::WrColorProperty>& aColorArray) {
315 wr_transaction_update_dynamic_properties(
316 mTxn, aOpacityArray.IsEmpty() ? nullptr : aOpacityArray.Elements(),
317 aOpacityArray.Length(),
318 aTransformArray.IsEmpty() ? nullptr : aTransformArray.Elements(),
319 aTransformArray.Length(),
320 aColorArray.IsEmpty() ? nullptr : aColorArray.Elements(),
321 aColorArray.Length());
324 void TransactionWrapper::AppendTransformProperties(
325 const nsTArray<wr::WrTransformProperty>& aTransformArray) {
326 wr_transaction_append_transform_properties(
327 mTxn, aTransformArray.IsEmpty() ? nullptr : aTransformArray.Elements(),
328 aTransformArray.Length());
331 void TransactionWrapper::UpdateScrollPosition(
332 const wr::WrPipelineId& aPipelineId,
333 const layers::ScrollableLayerGuid::ViewID& aScrollId,
334 const wr::LayoutPoint& aScrollPosition) {
335 wr_transaction_scroll_layer(mTxn, aPipelineId, aScrollId, aScrollPosition);
338 void TransactionWrapper::UpdatePinchZoom(float aZoom) {
339 wr_transaction_pinch_zoom(mTxn, aZoom);
342 void TransactionWrapper::UpdateIsTransformAsyncZooming(uint64_t aAnimationId,
343 bool aIsZooming) {
344 wr_transaction_set_is_transform_async_zooming(mTxn, aAnimationId, aIsZooming);
347 /*static*/
348 already_AddRefed<WebRenderAPI> WebRenderAPI::Create(
349 layers::CompositorBridgeParent* aBridge,
350 RefPtr<widget::CompositorWidget>&& aWidget, const wr::WrWindowId& aWindowId,
351 LayoutDeviceIntSize aSize, layers::WindowKind aWindowKind,
352 nsACString& aError) {
353 MOZ_ASSERT(aBridge);
354 MOZ_ASSERT(aWidget);
355 static_assert(
356 sizeof(size_t) == sizeof(uintptr_t),
357 "The FFI bindings assume size_t is the same size as uintptr_t!");
359 wr::DocumentHandle* docHandle = nullptr;
360 WebRenderBackend backend = WebRenderBackend::HARDWARE;
361 WebRenderCompositor compositor = WebRenderCompositor::DRAW;
362 int32_t maxTextureSize = 0;
363 bool useANGLE = false;
364 bool useDComp = false;
365 bool useTripleBuffering = false;
366 bool supportsExternalBufferTextures = false;
367 layers::SyncHandle syncHandle = 0;
369 // Dispatch a synchronous task because the DocumentHandle object needs to be
370 // created on the render thread. If need be we could delay waiting on this
371 // task until the next time we need to access the DocumentHandle object.
372 layers::SynchronousTask task("Create Renderer");
373 auto event = MakeUnique<NewRenderer>(
374 &docHandle, aBridge, &backend, &compositor, &maxTextureSize, &useANGLE,
375 &useDComp, &useTripleBuffering, &supportsExternalBufferTextures,
376 std::move(aWidget), &task, aSize, aWindowKind, &syncHandle, &aError);
377 RenderThread::Get()->RunEvent(aWindowId, std::move(event));
379 task.Wait();
381 if (!docHandle) {
382 return nullptr;
385 return RefPtr<WebRenderAPI>(
386 new WebRenderAPI(docHandle, aWindowId, backend, compositor,
387 maxTextureSize, useANGLE, useDComp,
388 useTripleBuffering,
389 supportsExternalBufferTextures, syncHandle))
390 .forget();
393 already_AddRefed<WebRenderAPI> WebRenderAPI::Clone() {
394 wr::DocumentHandle* docHandle = nullptr;
395 wr_api_clone(mDocHandle, &docHandle);
397 RefPtr<WebRenderAPI> renderApi =
398 new WebRenderAPI(docHandle, mId, mBackend, mCompositor, mMaxTextureSize,
399 mUseANGLE, mUseDComp, mUseTripleBuffering,
400 mSupportsExternalBufferTextures, mSyncHandle);
401 renderApi->mRootApi = this; // Hold root api
402 renderApi->mRootDocumentApi = this;
404 return renderApi.forget();
407 wr::WrIdNamespace WebRenderAPI::GetNamespace() {
408 return wr_api_get_namespace(mDocHandle);
411 WebRenderAPI::WebRenderAPI(wr::DocumentHandle* aHandle, wr::WindowId aId,
412 WebRenderBackend aBackend,
413 WebRenderCompositor aCompositor,
414 uint32_t aMaxTextureSize, bool aUseANGLE,
415 bool aUseDComp, bool aUseTripleBuffering,
416 bool aSupportsExternalBufferTextures,
417 layers::SyncHandle aSyncHandle)
418 : mDocHandle(aHandle),
419 mId(aId),
420 mBackend(aBackend),
421 mCompositor(aCompositor),
422 mMaxTextureSize(aMaxTextureSize),
423 mUseANGLE(aUseANGLE),
424 mUseDComp(aUseDComp),
425 mUseTripleBuffering(aUseTripleBuffering),
426 mSupportsExternalBufferTextures(aSupportsExternalBufferTextures),
427 mCaptureSequence(false),
428 mSyncHandle(aSyncHandle) {}
430 WebRenderAPI::~WebRenderAPI() {
431 if (!mRootDocumentApi) {
432 wr_api_delete_document(mDocHandle);
435 if (!mRootApi) {
436 RenderThread::Get()->SetDestroyed(GetId());
438 layers::SynchronousTask task("Destroy WebRenderAPI");
439 auto event = MakeUnique<RemoveRenderer>(&task);
440 RunOnRenderThread(std::move(event));
441 task.Wait();
443 wr_api_shut_down(mDocHandle);
446 wr_api_delete(mDocHandle);
449 void WebRenderAPI::UpdateDebugFlags(uint32_t aFlags) {
450 wr_api_set_debug_flags(mDocHandle, wr::DebugFlags{aFlags});
453 void WebRenderAPI::SendTransaction(TransactionBuilder& aTxn) {
454 wr_api_send_transaction(mDocHandle, aTxn.Raw(), aTxn.UseSceneBuilderThread());
457 SideBits ExtractSideBitsFromHitInfoBits(uint16_t& aHitInfoBits) {
458 SideBits sideBits = SideBits::eNone;
459 if (aHitInfoBits & eSideBitsPackedTop) {
460 sideBits |= SideBits::eTop;
462 if (aHitInfoBits & eSideBitsPackedRight) {
463 sideBits |= SideBits::eRight;
465 if (aHitInfoBits & eSideBitsPackedBottom) {
466 sideBits |= SideBits::eBottom;
468 if (aHitInfoBits & eSideBitsPackedLeft) {
469 sideBits |= SideBits::eLeft;
472 aHitInfoBits &= 0x0fff;
473 return sideBits;
476 std::vector<WrHitResult> WebRenderAPI::HitTest(const wr::WorldPoint& aPoint) {
477 static_assert(gfx::DoesCompositorHitTestInfoFitIntoBits<12>(),
478 "CompositorHitTestFlags MAX value has to be less than number "
479 "of bits in uint16_t minus 4 for SideBitsPacked");
481 nsTArray<wr::HitResult> wrResults;
482 wr_api_hit_test(mDocHandle, aPoint, &wrResults);
484 std::vector<WrHitResult> geckoResults;
485 for (wr::HitResult wrResult : wrResults) {
486 WrHitResult geckoResult;
487 geckoResult.mLayersId = wr::AsLayersId(wrResult.pipeline_id);
488 geckoResult.mScrollId =
489 static_cast<layers::ScrollableLayerGuid::ViewID>(wrResult.scroll_id);
490 geckoResult.mSideBits = ExtractSideBitsFromHitInfoBits(wrResult.hit_info);
491 geckoResult.mHitInfo.deserialize(wrResult.hit_info);
492 geckoResults.push_back(geckoResult);
494 return geckoResults;
497 void WebRenderAPI::Readback(const TimeStamp& aStartTime, gfx::IntSize size,
498 const gfx::SurfaceFormat& aFormat,
499 const Range<uint8_t>& buffer, bool* aNeedsYFlip) {
500 class Readback : public RendererEvent {
501 public:
502 explicit Readback(layers::SynchronousTask* aTask, TimeStamp aStartTime,
503 gfx::IntSize aSize, const gfx::SurfaceFormat& aFormat,
504 const Range<uint8_t>& aBuffer, bool* aNeedsYFlip)
505 : mTask(aTask),
506 mStartTime(aStartTime),
507 mSize(aSize),
508 mFormat(aFormat),
509 mBuffer(aBuffer),
510 mNeedsYFlip(aNeedsYFlip) {
511 MOZ_COUNT_CTOR(Readback);
514 MOZ_COUNTED_DTOR_OVERRIDE(Readback)
516 void Run(RenderThread& aRenderThread, WindowId aWindowId) override {
517 aRenderThread.UpdateAndRender(aWindowId, VsyncId(), mStartTime,
518 /* aRender */ true, Some(mSize),
519 wr::SurfaceFormatToImageFormat(mFormat),
520 Some(mBuffer), mNeedsYFlip);
521 layers::AutoCompleteTask complete(mTask);
524 layers::SynchronousTask* mTask;
525 TimeStamp mStartTime;
526 gfx::IntSize mSize;
527 gfx::SurfaceFormat mFormat;
528 const Range<uint8_t>& mBuffer;
529 bool* mNeedsYFlip;
532 // Disable debug flags during readback. See bug 1436020.
533 UpdateDebugFlags(0);
535 layers::SynchronousTask task("Readback");
536 auto event = MakeUnique<Readback>(&task, aStartTime, size, aFormat, buffer,
537 aNeedsYFlip);
538 // This event will be passed from wr_backend thread to renderer thread. That
539 // implies that all frame data have been processed when the renderer runs this
540 // read-back event. Then, we could make sure this read-back event gets the
541 // latest result.
542 RunOnRenderThread(std::move(event));
544 task.Wait();
546 UpdateDebugFlags(gfx::gfxVars::WebRenderDebugFlags());
549 void WebRenderAPI::ClearAllCaches() { wr_api_clear_all_caches(mDocHandle); }
551 void WebRenderAPI::EnableNativeCompositor(bool aEnable) {
552 wr_api_enable_native_compositor(mDocHandle, aEnable);
555 void WebRenderAPI::EnableMultithreading(bool aEnable) {
556 wr_api_enable_multithreading(mDocHandle, aEnable);
559 void WebRenderAPI::SetBatchingLookback(uint32_t aCount) {
560 wr_api_set_batching_lookback(mDocHandle, aCount);
563 void WebRenderAPI::SetClearColor(const gfx::DeviceColor& aColor) {
564 RenderThread::Get()->SetClearColor(mId, ToColorF(aColor));
567 void WebRenderAPI::SetProfilerUI(const nsCString& aUIString) {
568 RenderThread::Get()->SetProfilerUI(mId, aUIString);
571 void WebRenderAPI::Pause() {
572 class PauseEvent : public RendererEvent {
573 public:
574 explicit PauseEvent(layers::SynchronousTask* aTask) : mTask(aTask) {
575 MOZ_COUNT_CTOR(PauseEvent);
578 MOZ_COUNTED_DTOR_OVERRIDE(PauseEvent)
580 void Run(RenderThread& aRenderThread, WindowId aWindowId) override {
581 aRenderThread.Pause(aWindowId);
582 layers::AutoCompleteTask complete(mTask);
585 layers::SynchronousTask* mTask;
588 layers::SynchronousTask task("Pause");
589 auto event = MakeUnique<PauseEvent>(&task);
590 // This event will be passed from wr_backend thread to renderer thread. That
591 // implies that all frame data have been processed when the renderer runs this
592 // event.
593 RunOnRenderThread(std::move(event));
595 task.Wait();
598 bool WebRenderAPI::Resume() {
599 class ResumeEvent : public RendererEvent {
600 public:
601 explicit ResumeEvent(layers::SynchronousTask* aTask, bool* aResult)
602 : mTask(aTask), mResult(aResult) {
603 MOZ_COUNT_CTOR(ResumeEvent);
606 MOZ_COUNTED_DTOR_OVERRIDE(ResumeEvent)
608 void Run(RenderThread& aRenderThread, WindowId aWindowId) override {
609 *mResult = aRenderThread.Resume(aWindowId);
610 layers::AutoCompleteTask complete(mTask);
613 layers::SynchronousTask* mTask;
614 bool* mResult;
617 bool result = false;
618 layers::SynchronousTask task("Resume");
619 auto event = MakeUnique<ResumeEvent>(&task, &result);
620 // This event will be passed from wr_backend thread to renderer thread. That
621 // implies that all frame data have been processed when the renderer runs this
622 // event.
623 RunOnRenderThread(std::move(event));
625 task.Wait();
626 return result;
629 void WebRenderAPI::NotifyMemoryPressure() {
630 wr_api_notify_memory_pressure(mDocHandle);
633 void WebRenderAPI::AccumulateMemoryReport(MemoryReport* aReport) {
634 wr_api_accumulate_memory_report(mDocHandle, aReport, &WebRenderMallocSizeOf,
635 &WebRenderMallocEnclosingSizeOf);
638 void WebRenderAPI::WakeSceneBuilder() { wr_api_wake_scene_builder(mDocHandle); }
640 void WebRenderAPI::FlushSceneBuilder() {
641 wr_api_flush_scene_builder(mDocHandle);
644 void WebRenderAPI::WaitFlushed() {
645 class WaitFlushedEvent : public RendererEvent {
646 public:
647 explicit WaitFlushedEvent(layers::SynchronousTask* aTask) : mTask(aTask) {
648 MOZ_COUNT_CTOR(WaitFlushedEvent);
651 MOZ_COUNTED_DTOR_OVERRIDE(WaitFlushedEvent)
653 void Run(RenderThread& aRenderThread, WindowId aWindowId) override {
654 layers::AutoCompleteTask complete(mTask);
657 layers::SynchronousTask* mTask;
660 layers::SynchronousTask task("WaitFlushed");
661 auto event = MakeUnique<WaitFlushedEvent>(&task);
662 // This event will be passed from wr_backend thread to renderer thread. That
663 // implies that all frame data have been processed when the renderer runs this
664 // event.
665 RunOnRenderThread(std::move(event));
667 task.Wait();
670 void WebRenderAPI::Capture() {
671 // see CaptureBits
672 // SCENE | FRAME | TILE_CACHE
673 uint8_t bits = 15; // TODO: get from JavaScript
674 const char* path = "wr-capture"; // TODO: get from JavaScript
675 wr_api_capture(mDocHandle, path, bits);
678 void WebRenderAPI::StartCaptureSequence(const nsCString& aPath,
679 uint32_t aFlags) {
680 if (mCaptureSequence) {
681 wr_api_stop_capture_sequence(mDocHandle);
684 wr_api_start_capture_sequence(mDocHandle, PromiseFlatCString(aPath).get(),
685 aFlags);
687 mCaptureSequence = true;
690 void WebRenderAPI::StopCaptureSequence() {
691 if (mCaptureSequence) {
692 wr_api_stop_capture_sequence(mDocHandle);
695 mCaptureSequence = false;
698 void WebRenderAPI::BeginRecording(const TimeStamp& aRecordingStart,
699 wr::PipelineId aRootPipelineId) {
700 class BeginRecordingEvent final : public RendererEvent {
701 public:
702 explicit BeginRecordingEvent(const TimeStamp& aRecordingStart,
703 wr::PipelineId aRootPipelineId)
704 : mRecordingStart(aRecordingStart), mRootPipelineId(aRootPipelineId) {
705 MOZ_COUNT_CTOR(BeginRecordingEvent);
708 ~BeginRecordingEvent() { MOZ_COUNT_DTOR(BeginRecordingEvent); }
710 void Run(RenderThread& aRenderThread, WindowId aWindowId) override {
711 aRenderThread.BeginRecordingForWindow(aWindowId, mRecordingStart,
712 mRootPipelineId);
715 private:
716 TimeStamp mRecordingStart;
717 wr::PipelineId mRootPipelineId;
720 auto event =
721 MakeUnique<BeginRecordingEvent>(aRecordingStart, aRootPipelineId);
722 RunOnRenderThread(std::move(event));
725 RefPtr<WebRenderAPI::WriteCollectedFramesPromise>
726 WebRenderAPI::WriteCollectedFrames() {
727 class WriteCollectedFramesEvent final : public RendererEvent {
728 public:
729 explicit WriteCollectedFramesEvent() {
730 MOZ_COUNT_CTOR(WriteCollectedFramesEvent);
733 MOZ_COUNTED_DTOR(WriteCollectedFramesEvent)
735 void Run(RenderThread& aRenderThread, WindowId aWindowId) override {
736 aRenderThread.WriteCollectedFramesForWindow(aWindowId);
737 mPromise.Resolve(true, __func__);
740 RefPtr<WebRenderAPI::WriteCollectedFramesPromise> GetPromise() {
741 return mPromise.Ensure(__func__);
744 private:
745 MozPromiseHolder<WebRenderAPI::WriteCollectedFramesPromise> mPromise;
748 auto event = MakeUnique<WriteCollectedFramesEvent>();
749 auto promise = event->GetPromise();
751 RunOnRenderThread(std::move(event));
752 return promise;
755 RefPtr<WebRenderAPI::GetCollectedFramesPromise>
756 WebRenderAPI::GetCollectedFrames() {
757 class GetCollectedFramesEvent final : public RendererEvent {
758 public:
759 explicit GetCollectedFramesEvent() {
760 MOZ_COUNT_CTOR(GetCollectedFramesEvent);
763 MOZ_COUNTED_DTOR(GetCollectedFramesEvent);
765 void Run(RenderThread& aRenderThread, WindowId aWindowId) override {
766 Maybe<layers::CollectedFrames> frames =
767 aRenderThread.GetCollectedFramesForWindow(aWindowId);
769 if (frames) {
770 mPromise.Resolve(std::move(*frames), __func__);
771 } else {
772 mPromise.Reject(NS_ERROR_UNEXPECTED, __func__);
776 RefPtr<WebRenderAPI::GetCollectedFramesPromise> GetPromise() {
777 return mPromise.Ensure(__func__);
780 private:
781 MozPromiseHolder<WebRenderAPI::GetCollectedFramesPromise> mPromise;
784 auto event = MakeUnique<GetCollectedFramesEvent>();
785 auto promise = event->GetPromise();
787 RunOnRenderThread(std::move(event));
788 return promise;
791 void TransactionBuilder::Clear() { wr_resource_updates_clear(mTxn); }
793 void TransactionBuilder::Notify(wr::Checkpoint aWhen,
794 UniquePtr<NotificationHandler> aEvent) {
795 wr_transaction_notify(mTxn, aWhen,
796 reinterpret_cast<uintptr_t>(aEvent.release()));
799 void TransactionBuilder::AddImage(ImageKey key,
800 const ImageDescriptor& aDescriptor,
801 wr::Vec<uint8_t>& aBytes) {
802 wr_resource_updates_add_image(mTxn, key, &aDescriptor, &aBytes.inner);
805 void TransactionBuilder::AddBlobImage(BlobImageKey key,
806 const ImageDescriptor& aDescriptor,
807 wr::Vec<uint8_t>& aBytes,
808 const wr::DeviceIntRect& aVisibleRect) {
809 wr_resource_updates_add_blob_image(mTxn, key, &aDescriptor, &aBytes.inner,
810 aVisibleRect);
813 void TransactionBuilder::AddExternalImage(ImageKey key,
814 const ImageDescriptor& aDescriptor,
815 ExternalImageId aExtID,
816 wr::ExternalImageType aImageType,
817 uint8_t aChannelIndex) {
818 wr_resource_updates_add_external_image(mTxn, key, &aDescriptor, aExtID,
819 &aImageType, aChannelIndex);
822 void TransactionBuilder::AddExternalImageBuffer(
823 ImageKey aKey, const ImageDescriptor& aDescriptor,
824 ExternalImageId aHandle) {
825 auto channelIndex = 0;
826 AddExternalImage(aKey, aDescriptor, aHandle, wr::ExternalImageType::Buffer(),
827 channelIndex);
830 void TransactionBuilder::UpdateImageBuffer(ImageKey aKey,
831 const ImageDescriptor& aDescriptor,
832 wr::Vec<uint8_t>& aBytes) {
833 wr_resource_updates_update_image(mTxn, aKey, &aDescriptor, &aBytes.inner);
836 void TransactionBuilder::UpdateBlobImage(BlobImageKey aKey,
837 const ImageDescriptor& aDescriptor,
838 wr::Vec<uint8_t>& aBytes,
839 const wr::DeviceIntRect& aVisibleRect,
840 const wr::LayoutIntRect& aDirtyRect) {
841 wr_resource_updates_update_blob_image(mTxn, aKey, &aDescriptor, &aBytes.inner,
842 aVisibleRect, aDirtyRect);
845 void TransactionBuilder::UpdateExternalImage(ImageKey aKey,
846 const ImageDescriptor& aDescriptor,
847 ExternalImageId aExtID,
848 wr::ExternalImageType aImageType,
849 uint8_t aChannelIndex) {
850 wr_resource_updates_update_external_image(mTxn, aKey, &aDescriptor, aExtID,
851 &aImageType, aChannelIndex);
854 void TransactionBuilder::UpdateExternalImageWithDirtyRect(
855 ImageKey aKey, const ImageDescriptor& aDescriptor, ExternalImageId aExtID,
856 wr::ExternalImageType aImageType, const wr::DeviceIntRect& aDirtyRect,
857 uint8_t aChannelIndex) {
858 wr_resource_updates_update_external_image_with_dirty_rect(
859 mTxn, aKey, &aDescriptor, aExtID, &aImageType, aChannelIndex, aDirtyRect);
862 void TransactionBuilder::SetBlobImageVisibleArea(
863 BlobImageKey aKey, const wr::DeviceIntRect& aArea) {
864 wr_resource_updates_set_blob_image_visible_area(mTxn, aKey, &aArea);
867 void TransactionBuilder::DeleteImage(ImageKey aKey) {
868 wr_resource_updates_delete_image(mTxn, aKey);
871 void TransactionBuilder::DeleteBlobImage(BlobImageKey aKey) {
872 wr_resource_updates_delete_blob_image(mTxn, aKey);
875 void TransactionBuilder::AddRawFont(wr::FontKey aKey, wr::Vec<uint8_t>& aBytes,
876 uint32_t aIndex) {
877 wr_resource_updates_add_raw_font(mTxn, aKey, &aBytes.inner, aIndex);
880 void TransactionBuilder::AddFontDescriptor(wr::FontKey aKey,
881 wr::Vec<uint8_t>& aBytes,
882 uint32_t aIndex) {
883 wr_resource_updates_add_font_descriptor(mTxn, aKey, &aBytes.inner, aIndex);
886 void TransactionBuilder::DeleteFont(wr::FontKey aKey) {
887 wr_resource_updates_delete_font(mTxn, aKey);
890 void TransactionBuilder::AddFontInstance(
891 wr::FontInstanceKey aKey, wr::FontKey aFontKey, float aGlyphSize,
892 const wr::FontInstanceOptions* aOptions,
893 const wr::FontInstancePlatformOptions* aPlatformOptions,
894 wr::Vec<uint8_t>& aVariations) {
895 wr_resource_updates_add_font_instance(mTxn, aKey, aFontKey, aGlyphSize,
896 aOptions, aPlatformOptions,
897 &aVariations.inner);
900 void TransactionBuilder::DeleteFontInstance(wr::FontInstanceKey aKey) {
901 wr_resource_updates_delete_font_instance(mTxn, aKey);
904 void TransactionBuilder::UpdateQualitySettings(
905 bool aForceSubpixelAAWherePossible) {
906 wr_transaction_set_quality_settings(mTxn, aForceSubpixelAAWherePossible);
909 class FrameStartTime : public RendererEvent {
910 public:
911 explicit FrameStartTime(const TimeStamp& aTime) : mTime(aTime) {
912 MOZ_COUNT_CTOR(FrameStartTime);
915 MOZ_COUNTED_DTOR_OVERRIDE(FrameStartTime)
917 void Run(RenderThread& aRenderThread, WindowId aWindowId) override {
918 auto renderer = aRenderThread.GetRenderer(aWindowId);
919 if (renderer) {
920 renderer->SetFrameStartTime(mTime);
924 private:
925 TimeStamp mTime;
928 void WebRenderAPI::SetFrameStartTime(const TimeStamp& aTime) {
929 auto event = MakeUnique<FrameStartTime>(aTime);
930 RunOnRenderThread(std::move(event));
933 void WebRenderAPI::RunOnRenderThread(UniquePtr<RendererEvent> aEvent) {
934 auto event = reinterpret_cast<uintptr_t>(aEvent.release());
935 wr_api_send_external_event(mDocHandle, event);
938 DisplayListBuilder::DisplayListBuilder(PipelineId aId,
939 WebRenderBackend aBackend,
940 size_t aCapacity,
941 layers::DisplayItemCache* aCache)
942 : mCurrentSpaceAndClipChain(wr::RootScrollNodeWithChain()),
943 mActiveFixedPosTracker(nullptr),
944 mPipelineId(aId),
945 mBackend(aBackend),
946 mDisplayItemCache(aCache) {
947 MOZ_COUNT_CTOR(DisplayListBuilder);
948 mWrState = wr_state_new(aId, aCapacity);
950 if (mDisplayItemCache && mDisplayItemCache->IsEnabled()) {
951 mDisplayItemCache->SetPipelineId(aId);
955 DisplayListBuilder::~DisplayListBuilder() {
956 MOZ_COUNT_DTOR(DisplayListBuilder);
957 wr_state_delete(mWrState);
960 void DisplayListBuilder::Save() { wr_dp_save(mWrState); }
961 void DisplayListBuilder::Restore() { wr_dp_restore(mWrState); }
962 void DisplayListBuilder::ClearSave() { wr_dp_clear_save(mWrState); }
964 usize DisplayListBuilder::Dump(usize aIndent, const Maybe<usize>& aStart,
965 const Maybe<usize>& aEnd) {
966 return wr_dump_display_list(mWrState, aIndent, aStart.ptrOr(nullptr),
967 aEnd.ptrOr(nullptr));
970 void DisplayListBuilder::DumpSerializedDisplayList() {
971 wr_dump_serialized_display_list(mWrState);
974 void DisplayListBuilder::Finalize(BuiltDisplayList& aOutDisplayList) {
975 wr_api_finalize_builder(mWrState, &aOutDisplayList.dl_desc,
976 &aOutDisplayList.dl.inner);
979 void DisplayListBuilder::Finalize(layers::DisplayListData& aOutTransaction) {
980 if (mDisplayItemCache && mDisplayItemCache->IsEnabled()) {
981 wr_dp_set_cache_size(mWrState, mDisplayItemCache->CurrentSize());
984 wr::VecU8 dl;
985 wr_api_finalize_builder(mWrState, &aOutTransaction.mDLDesc, &dl.inner);
986 aOutTransaction.mDL.emplace(dl.inner.data, dl.inner.length,
987 dl.inner.capacity);
988 aOutTransaction.mRemotePipelineIds = std::move(mRemotePipelineIds);
989 dl.inner.capacity = 0;
990 dl.inner.data = nullptr;
993 Maybe<wr::WrSpatialId> DisplayListBuilder::PushStackingContext(
994 const wr::StackingContextParams& aParams, const wr::LayoutRect& aBounds,
995 const wr::RasterSpace& aRasterSpace) {
996 MOZ_ASSERT(mClipChainLeaf.isNothing(),
997 "Non-empty leaf from clip chain given, but not used with SC!");
999 wr::LayoutTransform matrix;
1000 const gfx::Matrix4x4* transform = aParams.mTransformPtr;
1001 if (transform) {
1002 matrix = ToLayoutTransform(*transform);
1004 const wr::LayoutTransform* maybeTransform = transform ? &matrix : nullptr;
1005 WRDL_LOG("PushStackingContext b=%s t=%s\n", mWrState,
1006 ToString(aBounds).c_str(),
1007 transform ? ToString(*transform).c_str() : "none");
1009 auto spatialId = wr_dp_push_stacking_context(
1010 mWrState, aBounds, mCurrentSpaceAndClipChain.space, &aParams,
1011 maybeTransform, aParams.mFilters.Elements(), aParams.mFilters.Length(),
1012 aParams.mFilterDatas.Elements(), aParams.mFilterDatas.Length(),
1013 aRasterSpace);
1015 return spatialId.id != 0 ? Some(spatialId) : Nothing();
1018 void DisplayListBuilder::PopStackingContext(bool aIsReferenceFrame) {
1019 WRDL_LOG("PopStackingContext\n", mWrState);
1020 wr_dp_pop_stacking_context(mWrState, aIsReferenceFrame);
1023 wr::WrClipChainId DisplayListBuilder::DefineClipChain(
1024 const nsTArray<wr::WrClipId>& aClips, bool aParentWithCurrentChain) {
1025 CancelGroup();
1027 const uint64_t* parent = nullptr;
1028 if (aParentWithCurrentChain &&
1029 mCurrentSpaceAndClipChain.clip_chain != wr::ROOT_CLIP_CHAIN) {
1030 parent = &mCurrentSpaceAndClipChain.clip_chain;
1032 uint64_t clipchainId = wr_dp_define_clipchain(
1033 mWrState, parent, aClips.Elements(), aClips.Length());
1034 WRDL_LOG("DefineClipChain id=%" PRIu64 " clips=%zu\n", mWrState, clipchainId,
1035 aClips.Length());
1036 return wr::WrClipChainId{clipchainId};
1039 wr::WrClipId DisplayListBuilder::DefineClip(
1040 const Maybe<wr::WrSpaceAndClip>& aParent, const wr::LayoutRect& aClipRect,
1041 const nsTArray<wr::ComplexClipRegion>* aComplex) {
1042 CancelGroup();
1044 WrClipId clipId;
1045 if (aParent) {
1046 clipId = wr_dp_define_clip_with_parent_clip(
1047 mWrState, aParent.ptr(), aClipRect,
1048 aComplex ? aComplex->Elements() : nullptr,
1049 aComplex ? aComplex->Length() : 0);
1050 } else {
1051 clipId = wr_dp_define_clip_with_parent_clip_chain(
1052 mWrState, &mCurrentSpaceAndClipChain, aClipRect,
1053 aComplex ? aComplex->Elements() : nullptr,
1054 aComplex ? aComplex->Length() : 0);
1057 WRDL_LOG("DefineClip id=%zu p=%s r=%s complex=%zu\n", mWrState, clipId.id,
1058 aParent ? ToString(aParent->clip.id).c_str() : "(nil)",
1059 ToString(aClipRect).c_str(), aComplex ? aComplex->Length() : 0);
1061 return clipId;
1064 wr::WrClipId DisplayListBuilder::DefineImageMaskClip(
1065 const wr::ImageMask& aMask) {
1066 CancelGroup();
1068 WrClipId clipId = wr_dp_define_image_mask_clip_with_parent_clip_chain(
1069 mWrState, &mCurrentSpaceAndClipChain, aMask);
1071 return clipId;
1074 wr::WrClipId DisplayListBuilder::DefineRoundedRectClip(
1075 const wr::ComplexClipRegion& aComplex) {
1076 CancelGroup();
1078 WrClipId clipId = wr_dp_define_rounded_rect_clip_with_parent_clip_chain(
1079 mWrState, &mCurrentSpaceAndClipChain, aComplex);
1081 return clipId;
1084 wr::WrClipId DisplayListBuilder::DefineRectClip(wr::LayoutRect aClipRect) {
1085 CancelGroup();
1087 WrClipId clipId = wr_dp_define_rect_clip_with_parent_clip_chain(
1088 mWrState, &mCurrentSpaceAndClipChain, aClipRect);
1090 return clipId;
1093 wr::WrSpatialId DisplayListBuilder::DefineStickyFrame(
1094 const wr::LayoutRect& aContentRect, const float* aTopMargin,
1095 const float* aRightMargin, const float* aBottomMargin,
1096 const float* aLeftMargin, const StickyOffsetBounds& aVerticalBounds,
1097 const StickyOffsetBounds& aHorizontalBounds,
1098 const wr::LayoutVector2D& aAppliedOffset) {
1099 auto spatialId = wr_dp_define_sticky_frame(
1100 mWrState, mCurrentSpaceAndClipChain.space, aContentRect, aTopMargin,
1101 aRightMargin, aBottomMargin, aLeftMargin, aVerticalBounds,
1102 aHorizontalBounds, aAppliedOffset);
1104 WRDL_LOG("DefineSticky id=%zu c=%s t=%s r=%s b=%s l=%s v=%s h=%s a=%s\n",
1105 mWrState, spatialId.id, ToString(aContentRect).c_str(),
1106 aTopMargin ? ToString(*aTopMargin).c_str() : "none",
1107 aRightMargin ? ToString(*aRightMargin).c_str() : "none",
1108 aBottomMargin ? ToString(*aBottomMargin).c_str() : "none",
1109 aLeftMargin ? ToString(*aLeftMargin).c_str() : "none",
1110 ToString(aVerticalBounds).c_str(),
1111 ToString(aHorizontalBounds).c_str(),
1112 ToString(aAppliedOffset).c_str());
1114 return spatialId;
1117 Maybe<wr::WrSpaceAndClip> DisplayListBuilder::GetScrollIdForDefinedScrollLayer(
1118 layers::ScrollableLayerGuid::ViewID aViewId) const {
1119 if (aViewId == layers::ScrollableLayerGuid::NULL_SCROLL_ID) {
1120 return Some(wr::RootScrollNode());
1123 auto it = mScrollIds.find(aViewId);
1124 if (it == mScrollIds.end()) {
1125 return Nothing();
1128 return Some(it->second);
1131 wr::WrSpaceAndClip DisplayListBuilder::DefineScrollLayer(
1132 const layers::ScrollableLayerGuid::ViewID& aViewId,
1133 const Maybe<wr::WrSpaceAndClip>& aParent,
1134 const wr::LayoutRect& aContentRect, const wr::LayoutRect& aClipRect,
1135 const wr::LayoutPoint& aScrollOffset) {
1136 auto it = mScrollIds.find(aViewId);
1137 if (it != mScrollIds.end()) {
1138 return it->second;
1141 // We haven't defined aViewId before, so let's define it now.
1142 wr::WrSpaceAndClip defaultParent = wr::RootScrollNode();
1143 // Note: we are currently ignoring the clipId on the stack here
1144 defaultParent.space = mCurrentSpaceAndClipChain.space;
1146 auto spaceAndClip = wr_dp_define_scroll_layer(
1147 mWrState, aViewId, aParent ? aParent.ptr() : &defaultParent, aContentRect,
1148 aClipRect, aScrollOffset);
1150 WRDL_LOG("DefineScrollLayer id=%" PRIu64 "/%zu p=%s co=%s cl=%s\n", mWrState,
1151 aViewId, spaceAndClip.space.id,
1152 aParent ? ToString(aParent->space.id).c_str() : "(nil)",
1153 ToString(aContentRect).c_str(), ToString(aClipRect).c_str());
1155 mScrollIds[aViewId] = spaceAndClip;
1156 return spaceAndClip;
1159 void DisplayListBuilder::PushRect(const wr::LayoutRect& aBounds,
1160 const wr::LayoutRect& aClip,
1161 bool aIsBackfaceVisible,
1162 const wr::ColorF& aColor) {
1163 wr::LayoutRect clip = MergeClipLeaf(aClip);
1164 WRDL_LOG("PushRect b=%s cl=%s c=%s\n", mWrState, ToString(aBounds).c_str(),
1165 ToString(clip).c_str(), ToString(aColor).c_str());
1166 wr_dp_push_rect(mWrState, aBounds, clip, aIsBackfaceVisible,
1167 &mCurrentSpaceAndClipChain, aColor);
1170 void DisplayListBuilder::PushRoundedRect(const wr::LayoutRect& aBounds,
1171 const wr::LayoutRect& aClip,
1172 bool aIsBackfaceVisible,
1173 const wr::ColorF& aColor) {
1174 wr::LayoutRect clip = MergeClipLeaf(aClip);
1175 WRDL_LOG("PushRoundedRect b=%s cl=%s c=%s\n", mWrState,
1176 ToString(aBounds).c_str(), ToString(clip).c_str(),
1177 ToString(aColor).c_str());
1179 // Draw the rounded rectangle as a border with rounded corners. We could also
1180 // draw this as a rectangle clipped to a rounded rectangle, but:
1181 // - clips are not cached; borders are
1182 // - a simple border like this will be drawn as an image
1183 // - Processing lots of clips is not WebRender's strong point.
1185 // Made the borders thicker than one half the width/height, to avoid
1186 // little white dots at the center at some magnifications.
1187 wr::BorderSide side = {aColor, wr::BorderStyle::Solid};
1188 float h = aBounds.size.width * 0.6f;
1189 float v = aBounds.size.height * 0.6f;
1190 wr::LayoutSideOffsets widths = {v, h, v, h};
1191 wr::BorderRadius radii = {{h, v}, {h, v}, {h, v}, {h, v}};
1193 // Anti-aliased borders are required for rounded borders.
1194 wr_dp_push_border(mWrState, aBounds, clip, aIsBackfaceVisible,
1195 &mCurrentSpaceAndClipChain, wr::AntialiasBorder::Yes,
1196 widths, side, side, side, side, radii);
1199 void DisplayListBuilder::PushHitTest(
1200 const wr::LayoutRect& aBounds, const wr::LayoutRect& aClip,
1201 bool aIsBackfaceVisible,
1202 const layers::ScrollableLayerGuid::ViewID& aScrollId,
1203 gfx::CompositorHitTestInfo aHitInfo, SideBits aSideBits) {
1204 wr::LayoutRect clip = MergeClipLeaf(aClip);
1205 WRDL_LOG("PushHitTest b=%s cl=%s\n", mWrState, ToString(aBounds).c_str(),
1206 ToString(clip).c_str());
1208 static_assert(gfx::DoesCompositorHitTestInfoFitIntoBits<12>(),
1209 "CompositorHitTestFlags MAX value has to be less than number "
1210 "of bits in uint16_t minus 4 for SideBitsPacked");
1212 uint16_t hitInfoBits = static_cast<uint16_t>(aHitInfo.serialize()) |
1213 SideBitsToHitInfoBits(aSideBits);
1215 wr_dp_push_hit_test(mWrState, aBounds, clip, aIsBackfaceVisible,
1216 &mCurrentSpaceAndClipChain, aScrollId, hitInfoBits);
1219 void DisplayListBuilder::PushRectWithAnimation(
1220 const wr::LayoutRect& aBounds, const wr::LayoutRect& aClip,
1221 bool aIsBackfaceVisible, const wr::ColorF& aColor,
1222 const WrAnimationProperty* aAnimation) {
1223 wr::LayoutRect clip = MergeClipLeaf(aClip);
1224 WRDL_LOG("PushRectWithAnimation b=%s cl=%s c=%s\n", mWrState,
1225 ToString(aBounds).c_str(), ToString(clip).c_str(),
1226 ToString(aColor).c_str());
1228 wr_dp_push_rect_with_animation(mWrState, aBounds, clip, aIsBackfaceVisible,
1229 &mCurrentSpaceAndClipChain, aColor,
1230 aAnimation);
1233 void DisplayListBuilder::PushClearRect(const wr::LayoutRect& aBounds) {
1234 wr::LayoutRect clip = MergeClipLeaf(aBounds);
1235 WRDL_LOG("PushClearRect b=%s c=%s\n", mWrState, ToString(aBounds).c_str(),
1236 ToString(clip).c_str());
1237 wr_dp_push_clear_rect(mWrState, aBounds, clip, &mCurrentSpaceAndClipChain);
1240 void DisplayListBuilder::PushClearRectWithComplexRegion(
1241 const wr::LayoutRect& aBounds, const wr::ComplexClipRegion& aRegion) {
1242 wr::LayoutRect clip = MergeClipLeaf(aBounds);
1243 WRDL_LOG("PushClearRectWithComplexRegion b=%s c=%s\n", mWrState,
1244 ToString(aBounds).c_str(), ToString(clip).c_str());
1246 // TODO(gw): This doesn't pass the complex region through to WR, as clear
1247 // rects with complex clips are currently broken. This is the
1248 // only place they are used, and they are used only for a single
1249 // case (close buttons on Win7 machines). We might be able to
1250 // get away with not supporting this at all in WR, using the
1251 // non-clipped clear rect is an improvement for now, at least.
1252 // See https://bugzilla.mozilla.org/show_bug.cgi?id=1636683 for
1253 // more information.
1254 AutoTArray<wr::ComplexClipRegion, 1> clips;
1255 auto clipId = DefineClip(Nothing(), aBounds, &clips);
1256 auto spaceAndClip = WrSpaceAndClip{mCurrentSpaceAndClipChain.space, clipId};
1258 wr_dp_push_clear_rect_with_parent_clip(mWrState, aBounds, clip,
1259 &spaceAndClip);
1262 void DisplayListBuilder::PushBackdropFilter(
1263 const wr::LayoutRect& aBounds, const wr::ComplexClipRegion& aRegion,
1264 const nsTArray<wr::FilterOp>& aFilters,
1265 const nsTArray<wr::WrFilterData>& aFilterDatas, bool aIsBackfaceVisible) {
1266 wr::LayoutRect clip = MergeClipLeaf(aBounds);
1267 WRDL_LOG("PushBackdropFilter b=%s c=%s\n", mWrState,
1268 ToString(aBounds).c_str(), ToString(clip).c_str());
1270 AutoTArray<wr::ComplexClipRegion, 1> clips;
1271 clips.AppendElement(aRegion);
1272 auto clipId = DefineClip(Nothing(), aBounds, &clips);
1273 auto spaceAndClip = WrSpaceAndClip{mCurrentSpaceAndClipChain.space, clipId};
1275 wr_dp_push_backdrop_filter_with_parent_clip(
1276 mWrState, aBounds, clip, aIsBackfaceVisible, &spaceAndClip,
1277 aFilters.Elements(), aFilters.Length(), aFilterDatas.Elements(),
1278 aFilterDatas.Length());
1281 void DisplayListBuilder::PushLinearGradient(
1282 const wr::LayoutRect& aBounds, const wr::LayoutRect& aClip,
1283 bool aIsBackfaceVisible, const wr::LayoutPoint& aStartPoint,
1284 const wr::LayoutPoint& aEndPoint, const nsTArray<wr::GradientStop>& aStops,
1285 wr::ExtendMode aExtendMode, const wr::LayoutSize aTileSize,
1286 const wr::LayoutSize aTileSpacing) {
1287 wr_dp_push_linear_gradient(
1288 mWrState, aBounds, MergeClipLeaf(aClip), aIsBackfaceVisible,
1289 &mCurrentSpaceAndClipChain, aStartPoint, aEndPoint, aStops.Elements(),
1290 aStops.Length(), aExtendMode, aTileSize, aTileSpacing);
1293 void DisplayListBuilder::PushRadialGradient(
1294 const wr::LayoutRect& aBounds, const wr::LayoutRect& aClip,
1295 bool aIsBackfaceVisible, const wr::LayoutPoint& aCenter,
1296 const wr::LayoutSize& aRadius, const nsTArray<wr::GradientStop>& aStops,
1297 wr::ExtendMode aExtendMode, const wr::LayoutSize aTileSize,
1298 const wr::LayoutSize aTileSpacing) {
1299 wr_dp_push_radial_gradient(
1300 mWrState, aBounds, MergeClipLeaf(aClip), aIsBackfaceVisible,
1301 &mCurrentSpaceAndClipChain, aCenter, aRadius, aStops.Elements(),
1302 aStops.Length(), aExtendMode, aTileSize, aTileSpacing);
1305 void DisplayListBuilder::PushConicGradient(
1306 const wr::LayoutRect& aBounds, const wr::LayoutRect& aClip,
1307 bool aIsBackfaceVisible, const wr::LayoutPoint& aCenter, const float aAngle,
1308 const nsTArray<wr::GradientStop>& aStops, wr::ExtendMode aExtendMode,
1309 const wr::LayoutSize aTileSize, const wr::LayoutSize aTileSpacing) {
1310 wr_dp_push_conic_gradient(mWrState, aBounds, MergeClipLeaf(aClip),
1311 aIsBackfaceVisible, &mCurrentSpaceAndClipChain,
1312 aCenter, aAngle, aStops.Elements(), aStops.Length(),
1313 aExtendMode, aTileSize, aTileSpacing);
1316 void DisplayListBuilder::PushImage(
1317 const wr::LayoutRect& aBounds, const wr::LayoutRect& aClip,
1318 bool aIsBackfaceVisible, wr::ImageRendering aFilter, wr::ImageKey aImage,
1319 bool aPremultipliedAlpha, const wr::ColorF& aColor,
1320 bool aPreferCompositorSurface, bool aSupportsExternalCompositing) {
1321 wr::LayoutRect clip = MergeClipLeaf(aClip);
1322 WRDL_LOG("PushImage b=%s cl=%s\n", mWrState, ToString(aBounds).c_str(),
1323 ToString(clip).c_str());
1324 wr_dp_push_image(mWrState, aBounds, clip, aIsBackfaceVisible,
1325 &mCurrentSpaceAndClipChain, aFilter, aImage,
1326 aPremultipliedAlpha, aColor, aPreferCompositorSurface,
1327 aSupportsExternalCompositing);
1330 void DisplayListBuilder::PushRepeatingImage(
1331 const wr::LayoutRect& aBounds, const wr::LayoutRect& aClip,
1332 bool aIsBackfaceVisible, const wr::LayoutSize& aStretchSize,
1333 const wr::LayoutSize& aTileSpacing, wr::ImageRendering aFilter,
1334 wr::ImageKey aImage, bool aPremultipliedAlpha, const wr::ColorF& aColor) {
1335 wr::LayoutRect clip = MergeClipLeaf(aClip);
1336 WRDL_LOG("PushImage b=%s cl=%s s=%s t=%s\n", mWrState,
1337 ToString(aBounds).c_str(), ToString(clip).c_str(),
1338 ToString(aStretchSize).c_str(), ToString(aTileSpacing).c_str());
1339 wr_dp_push_repeating_image(
1340 mWrState, aBounds, clip, aIsBackfaceVisible, &mCurrentSpaceAndClipChain,
1341 aStretchSize, aTileSpacing, aFilter, aImage, aPremultipliedAlpha, aColor);
1344 void DisplayListBuilder::PushYCbCrPlanarImage(
1345 const wr::LayoutRect& aBounds, const wr::LayoutRect& aClip,
1346 bool aIsBackfaceVisible, wr::ImageKey aImageChannel0,
1347 wr::ImageKey aImageChannel1, wr::ImageKey aImageChannel2,
1348 wr::WrColorDepth aColorDepth, wr::WrYuvColorSpace aColorSpace,
1349 wr::WrColorRange aColorRange, wr::ImageRendering aRendering,
1350 bool aPreferCompositorSurface, bool aSupportsExternalCompositing) {
1351 wr_dp_push_yuv_planar_image(
1352 mWrState, aBounds, MergeClipLeaf(aClip), aIsBackfaceVisible,
1353 &mCurrentSpaceAndClipChain, aImageChannel0, aImageChannel1,
1354 aImageChannel2, aColorDepth, aColorSpace, aColorRange, aRendering,
1355 aPreferCompositorSurface, aSupportsExternalCompositing);
1358 void DisplayListBuilder::PushNV12Image(
1359 const wr::LayoutRect& aBounds, const wr::LayoutRect& aClip,
1360 bool aIsBackfaceVisible, wr::ImageKey aImageChannel0,
1361 wr::ImageKey aImageChannel1, wr::WrColorDepth aColorDepth,
1362 wr::WrYuvColorSpace aColorSpace, wr::WrColorRange aColorRange,
1363 wr::ImageRendering aRendering, bool aPreferCompositorSurface,
1364 bool aSupportsExternalCompositing) {
1365 wr_dp_push_yuv_NV12_image(
1366 mWrState, aBounds, MergeClipLeaf(aClip), aIsBackfaceVisible,
1367 &mCurrentSpaceAndClipChain, aImageChannel0, aImageChannel1, aColorDepth,
1368 aColorSpace, aColorRange, aRendering, aPreferCompositorSurface,
1369 aSupportsExternalCompositing);
1372 void DisplayListBuilder::PushYCbCrInterleavedImage(
1373 const wr::LayoutRect& aBounds, const wr::LayoutRect& aClip,
1374 bool aIsBackfaceVisible, wr::ImageKey aImageChannel0,
1375 wr::WrColorDepth aColorDepth, wr::WrYuvColorSpace aColorSpace,
1376 wr::WrColorRange aColorRange, wr::ImageRendering aRendering,
1377 bool aPreferCompositorSurface, bool aSupportsExternalCompositing) {
1378 wr_dp_push_yuv_interleaved_image(
1379 mWrState, aBounds, MergeClipLeaf(aClip), aIsBackfaceVisible,
1380 &mCurrentSpaceAndClipChain, aImageChannel0, aColorDepth, aColorSpace,
1381 aColorRange, aRendering, aPreferCompositorSurface,
1382 aSupportsExternalCompositing);
1385 void DisplayListBuilder::PushIFrame(const wr::LayoutRect& aBounds,
1386 bool aIsBackfaceVisible,
1387 PipelineId aPipeline,
1388 bool aIgnoreMissingPipeline) {
1389 mRemotePipelineIds.AppendElement(aPipeline);
1390 wr_dp_push_iframe(mWrState, aBounds, MergeClipLeaf(aBounds),
1391 aIsBackfaceVisible, &mCurrentSpaceAndClipChain, aPipeline,
1392 aIgnoreMissingPipeline);
1395 void DisplayListBuilder::PushBorder(const wr::LayoutRect& aBounds,
1396 const wr::LayoutRect& aClip,
1397 bool aIsBackfaceVisible,
1398 const wr::LayoutSideOffsets& aWidths,
1399 const Range<const wr::BorderSide>& aSides,
1400 const wr::BorderRadius& aRadius,
1401 wr::AntialiasBorder aAntialias) {
1402 MOZ_ASSERT(aSides.length() == 4);
1403 if (aSides.length() != 4) {
1404 return;
1406 wr_dp_push_border(mWrState, aBounds, MergeClipLeaf(aClip), aIsBackfaceVisible,
1407 &mCurrentSpaceAndClipChain, aAntialias, aWidths, aSides[0],
1408 aSides[1], aSides[2], aSides[3], aRadius);
1411 void DisplayListBuilder::PushBorderImage(const wr::LayoutRect& aBounds,
1412 const wr::LayoutRect& aClip,
1413 bool aIsBackfaceVisible,
1414 const wr::WrBorderImage& aParams) {
1415 wr_dp_push_border_image(mWrState, aBounds, MergeClipLeaf(aClip),
1416 aIsBackfaceVisible, &mCurrentSpaceAndClipChain,
1417 &aParams);
1420 void DisplayListBuilder::PushBorderGradient(
1421 const wr::LayoutRect& aBounds, const wr::LayoutRect& aClip,
1422 bool aIsBackfaceVisible, const wr::LayoutSideOffsets& aWidths,
1423 const int32_t aWidth, const int32_t aHeight, bool aFill,
1424 const wr::DeviceIntSideOffsets& aSlice, const wr::LayoutPoint& aStartPoint,
1425 const wr::LayoutPoint& aEndPoint, const nsTArray<wr::GradientStop>& aStops,
1426 wr::ExtendMode aExtendMode, const wr::LayoutSideOffsets& aOutset) {
1427 wr_dp_push_border_gradient(mWrState, aBounds, MergeClipLeaf(aClip),
1428 aIsBackfaceVisible, &mCurrentSpaceAndClipChain,
1429 aWidths, aWidth, aHeight, aFill, aSlice,
1430 aStartPoint, aEndPoint, aStops.Elements(),
1431 aStops.Length(), aExtendMode, aOutset);
1434 void DisplayListBuilder::PushBorderRadialGradient(
1435 const wr::LayoutRect& aBounds, const wr::LayoutRect& aClip,
1436 bool aIsBackfaceVisible, const wr::LayoutSideOffsets& aWidths, bool aFill,
1437 const wr::LayoutPoint& aCenter, const wr::LayoutSize& aRadius,
1438 const nsTArray<wr::GradientStop>& aStops, wr::ExtendMode aExtendMode,
1439 const wr::LayoutSideOffsets& aOutset) {
1440 wr_dp_push_border_radial_gradient(
1441 mWrState, aBounds, MergeClipLeaf(aClip), aIsBackfaceVisible,
1442 &mCurrentSpaceAndClipChain, aWidths, aFill, aCenter, aRadius,
1443 aStops.Elements(), aStops.Length(), aExtendMode, aOutset);
1446 void DisplayListBuilder::PushBorderConicGradient(
1447 const wr::LayoutRect& aBounds, const wr::LayoutRect& aClip,
1448 bool aIsBackfaceVisible, const wr::LayoutSideOffsets& aWidths, bool aFill,
1449 const wr::LayoutPoint& aCenter, const float aAngle,
1450 const nsTArray<wr::GradientStop>& aStops, wr::ExtendMode aExtendMode,
1451 const wr::LayoutSideOffsets& aOutset) {
1452 wr_dp_push_border_conic_gradient(
1453 mWrState, aBounds, MergeClipLeaf(aClip), aIsBackfaceVisible,
1454 &mCurrentSpaceAndClipChain, aWidths, aFill, aCenter, aAngle,
1455 aStops.Elements(), aStops.Length(), aExtendMode, aOutset);
1458 void DisplayListBuilder::PushText(const wr::LayoutRect& aBounds,
1459 const wr::LayoutRect& aClip,
1460 bool aIsBackfaceVisible,
1461 const wr::ColorF& aColor,
1462 wr::FontInstanceKey aFontKey,
1463 Range<const wr::GlyphInstance> aGlyphBuffer,
1464 const wr::GlyphOptions* aGlyphOptions) {
1465 wr_dp_push_text(mWrState, aBounds, MergeClipLeaf(aClip), aIsBackfaceVisible,
1466 &mCurrentSpaceAndClipChain, aColor, aFontKey,
1467 &aGlyphBuffer[0], aGlyphBuffer.length(), aGlyphOptions);
1470 void DisplayListBuilder::PushLine(const wr::LayoutRect& aClip,
1471 bool aIsBackfaceVisible,
1472 const wr::Line& aLine) {
1473 wr::LayoutRect clip = MergeClipLeaf(aClip);
1474 wr_dp_push_line(mWrState, &clip, aIsBackfaceVisible,
1475 &mCurrentSpaceAndClipChain, &aLine.bounds,
1476 aLine.wavyLineThickness, aLine.orientation, &aLine.color,
1477 aLine.style);
1480 void DisplayListBuilder::PushShadow(const wr::LayoutRect& aRect,
1481 const wr::LayoutRect& aClip,
1482 bool aIsBackfaceVisible,
1483 const wr::Shadow& aShadow,
1484 bool aShouldInflate) {
1485 // Local clip_rects are translated inside of shadows, as they are assumed to
1486 // be part of the element drawing itself, and not a parent frame clipping it.
1487 // As such, it is not sound to apply the MergeClipLeaf optimization inside of
1488 // shadows. So we disable the optimization when we encounter a shadow.
1489 // Shadows don't span frames, so we don't have to worry about MergeClipLeaf
1490 // being re-enabled mid-shadow. The optimization is restored in PopAllShadows.
1491 SuspendClipLeafMerging();
1492 wr_dp_push_shadow(mWrState, aRect, aClip, aIsBackfaceVisible,
1493 &mCurrentSpaceAndClipChain, aShadow, aShouldInflate);
1496 void DisplayListBuilder::PopAllShadows() {
1497 wr_dp_pop_all_shadows(mWrState);
1498 ResumeClipLeafMerging();
1501 void DisplayListBuilder::SuspendClipLeafMerging() {
1502 if (mClipChainLeaf) {
1503 // No one should reinitialize mClipChainLeaf while we're suspended
1504 MOZ_ASSERT(!mSuspendedClipChainLeaf);
1506 mSuspendedClipChainLeaf = mClipChainLeaf;
1507 mSuspendedSpaceAndClipChain = Some(mCurrentSpaceAndClipChain);
1509 auto clipId = DefineRectClip(*mClipChainLeaf);
1510 auto clipChainId = DefineClipChain({clipId}, true);
1512 mCurrentSpaceAndClipChain.clip_chain = clipChainId.id;
1513 mClipChainLeaf = Nothing();
1517 void DisplayListBuilder::ResumeClipLeafMerging() {
1518 if (mSuspendedClipChainLeaf) {
1519 mCurrentSpaceAndClipChain = *mSuspendedSpaceAndClipChain;
1520 mClipChainLeaf = mSuspendedClipChainLeaf;
1522 mSuspendedClipChainLeaf = Nothing();
1523 mSuspendedSpaceAndClipChain = Nothing();
1527 void DisplayListBuilder::PushBoxShadow(
1528 const wr::LayoutRect& aRect, const wr::LayoutRect& aClip,
1529 bool aIsBackfaceVisible, const wr::LayoutRect& aBoxBounds,
1530 const wr::LayoutVector2D& aOffset, const wr::ColorF& aColor,
1531 const float& aBlurRadius, const float& aSpreadRadius,
1532 const wr::BorderRadius& aBorderRadius,
1533 const wr::BoxShadowClipMode& aClipMode) {
1534 wr_dp_push_box_shadow(mWrState, aRect, MergeClipLeaf(aClip),
1535 aIsBackfaceVisible, &mCurrentSpaceAndClipChain,
1536 aBoxBounds, aOffset, aColor, aBlurRadius, aSpreadRadius,
1537 aBorderRadius, aClipMode);
1540 void DisplayListBuilder::StartGroup(nsPaintedDisplayItem* aItem) {
1541 if (!mDisplayItemCache || mDisplayItemCache->IsFull()) {
1542 return;
1545 MOZ_ASSERT(!mCurrentCacheSlot);
1546 mCurrentCacheSlot = mDisplayItemCache->AssignSlot(aItem);
1548 if (mCurrentCacheSlot) {
1549 wr_dp_start_item_group(mWrState);
1553 void DisplayListBuilder::CancelGroup(const bool aDiscard) {
1554 if (!mDisplayItemCache || !mCurrentCacheSlot) {
1555 return;
1558 wr_dp_cancel_item_group(mWrState, aDiscard);
1559 mCurrentCacheSlot = Nothing();
1562 void DisplayListBuilder::FinishGroup() {
1563 if (!mDisplayItemCache || !mCurrentCacheSlot) {
1564 return;
1567 MOZ_ASSERT(mCurrentCacheSlot);
1569 if (wr_dp_finish_item_group(mWrState, mCurrentCacheSlot.ref())) {
1570 mDisplayItemCache->MarkSlotOccupied(mCurrentCacheSlot.ref(),
1571 CurrentSpaceAndClipChain());
1572 mDisplayItemCache->Stats().AddCached();
1575 mCurrentCacheSlot = Nothing();
1578 bool DisplayListBuilder::ReuseItem(nsPaintedDisplayItem* aItem) {
1579 if (!mDisplayItemCache) {
1580 return false;
1583 mDisplayItemCache->Stats().AddTotal();
1585 if (mDisplayItemCache->IsEmpty()) {
1586 return false;
1589 Maybe<uint16_t> slot =
1590 mDisplayItemCache->CanReuseItem(aItem, CurrentSpaceAndClipChain());
1592 if (slot) {
1593 mDisplayItemCache->Stats().AddReused();
1594 wr_dp_push_reuse_items(mWrState, slot.ref());
1595 return true;
1598 return false;
1601 Maybe<layers::ScrollableLayerGuid::ViewID>
1602 DisplayListBuilder::GetContainingFixedPosScrollTarget(
1603 const ActiveScrolledRoot* aAsr) {
1604 return mActiveFixedPosTracker
1605 ? mActiveFixedPosTracker->GetScrollTargetForASR(aAsr)
1606 : Nothing();
1609 Maybe<SideBits> DisplayListBuilder::GetContainingFixedPosSideBits(
1610 const ActiveScrolledRoot* aAsr) {
1611 return mActiveFixedPosTracker
1612 ? mActiveFixedPosTracker->GetSideBitsForASR(aAsr)
1613 : Nothing();
1616 DisplayListBuilder::FixedPosScrollTargetTracker::FixedPosScrollTargetTracker(
1617 DisplayListBuilder& aBuilder, const ActiveScrolledRoot* aAsr,
1618 layers::ScrollableLayerGuid::ViewID aScrollId, SideBits aSideBits)
1619 : mParentTracker(aBuilder.mActiveFixedPosTracker),
1620 mBuilder(aBuilder),
1621 mAsr(aAsr),
1622 mScrollId(aScrollId),
1623 mSideBits(aSideBits) {
1624 aBuilder.mActiveFixedPosTracker = this;
1627 DisplayListBuilder::FixedPosScrollTargetTracker::
1628 ~FixedPosScrollTargetTracker() {
1629 mBuilder.mActiveFixedPosTracker = mParentTracker;
1632 Maybe<layers::ScrollableLayerGuid::ViewID>
1633 DisplayListBuilder::FixedPosScrollTargetTracker::GetScrollTargetForASR(
1634 const ActiveScrolledRoot* aAsr) {
1635 return aAsr == mAsr ? Some(mScrollId) : Nothing();
1638 Maybe<SideBits>
1639 DisplayListBuilder::FixedPosScrollTargetTracker::GetSideBitsForASR(
1640 const ActiveScrolledRoot* aAsr) {
1641 return aAsr == mAsr ? Some(mSideBits) : Nothing();
1644 already_AddRefed<gfxContext> DisplayListBuilder::GetTextContext(
1645 wr::IpcResourceUpdateQueue& aResources,
1646 const layers::StackingContextHelper& aSc,
1647 layers::RenderRootStateManager* aManager, nsDisplayItem* aItem,
1648 nsRect& aBounds, const gfx::Point& aDeviceOffset) {
1649 if (!mCachedTextDT) {
1650 mCachedTextDT = new layout::TextDrawTarget(*this, aResources, aSc, aManager,
1651 aItem, aBounds);
1652 mCachedContext = gfxContext::CreateOrNull(mCachedTextDT, aDeviceOffset);
1653 } else {
1654 mCachedTextDT->Reinitialize(aResources, aSc, aManager, aItem, aBounds);
1655 mCachedContext->SetDeviceOffset(aDeviceOffset);
1656 mCachedContext->SetMatrix(gfx::Matrix());
1659 RefPtr<gfxContext> tmp = mCachedContext;
1660 return tmp.forget();
1663 } // namespace wr
1664 } // namespace mozilla
1666 extern "C" {
1668 void wr_transaction_notification_notified(uintptr_t aHandler,
1669 mozilla::wr::Checkpoint aWhen) {
1670 auto handler = reinterpret_cast<mozilla::wr::NotificationHandler*>(aHandler);
1671 handler->Notify(aWhen);
1672 // TODO: it would be better to get a callback when the object is destroyed on
1673 // the rust side and delete then.
1674 delete handler;
1677 void wr_register_thread_local_arena() {
1678 #ifdef MOZ_MEMORY
1679 jemalloc_thread_local_arena(true);
1680 #endif
1683 } // extern C