Line data Source code
1 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* This Source Code Form is subject to the terms of the Mozilla Public
3 : * License, v. 2.0. If a copy of the MPL was not distributed with this
4 : * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 :
6 : #include "WebRenderAPI.h"
7 : #include "LayersLogging.h"
8 : #include "mozilla/webrender/RendererOGL.h"
9 : #include "mozilla/gfx/gfxVars.h"
10 : #include "mozilla/layers/CompositorThread.h"
11 : #include "mozilla/widget/CompositorWidget.h"
12 : #include "mozilla/widget/CompositorWidget.h"
13 : #include "mozilla/layers/SynchronousTask.h"
14 :
15 : #define WRDL_LOG(...)
16 : //#define WRDL_LOG(...) printf_stderr("WRDL: " __VA_ARGS__)
17 :
18 : namespace mozilla {
19 : namespace wr {
20 :
21 : using layers::Stringify;
22 :
23 : class NewRenderer : public RendererEvent
24 : {
25 : public:
26 0 : NewRenderer(WrAPI** aApi, layers::CompositorBridgeParentBase* aBridge,
27 : GLint* aMaxTextureSize,
28 : bool* aUseANGLE,
29 : RefPtr<widget::CompositorWidget>&& aWidget,
30 : layers::SynchronousTask* aTask,
31 : bool aEnableProfiler,
32 : LayoutDeviceIntSize aSize)
33 0 : : mWrApi(aApi)
34 : , mMaxTextureSize(aMaxTextureSize)
35 : , mUseANGLE(aUseANGLE)
36 : , mBridge(aBridge)
37 0 : , mCompositorWidget(Move(aWidget))
38 : , mTask(aTask)
39 : , mEnableProfiler(aEnableProfiler)
40 0 : , mSize(aSize)
41 : {
42 0 : MOZ_COUNT_CTOR(NewRenderer);
43 0 : }
44 :
45 0 : ~NewRenderer()
46 0 : {
47 0 : MOZ_COUNT_DTOR(NewRenderer);
48 0 : }
49 :
50 0 : virtual void Run(RenderThread& aRenderThread, WindowId aWindowId) override
51 : {
52 0 : layers::AutoCompleteTask complete(mTask);
53 :
54 0 : RefPtr<gl::GLContext> gl;
55 0 : if (gfx::gfxVars::UseWebRenderANGLE()) {
56 0 : gl = gl::GLContextProviderEGL::CreateForCompositorWidget(mCompositorWidget, true);
57 0 : if (!gl || !gl->IsANGLE()) {
58 0 : gfxCriticalNote << "Failed ANGLE GL context creation for WebRender: " << gfx::hexa(gl.get());
59 0 : return;
60 : }
61 : }
62 0 : if (!gl) {
63 0 : gl = gl::GLContextProvider::CreateForCompositorWidget(mCompositorWidget, true);
64 : }
65 0 : if (!gl || !gl->MakeCurrent()) {
66 0 : gfxCriticalNote << "Failed GL context creation for WebRender: " << gfx::hexa(gl.get());
67 0 : return;
68 : }
69 :
70 0 : gl->fGetIntegerv(LOCAL_GL_MAX_TEXTURE_SIZE, mMaxTextureSize);
71 0 : *mUseANGLE = gl->IsANGLE();
72 :
73 0 : WrRenderer* wrRenderer = nullptr;
74 0 : if (!wr_window_new(aWindowId, mSize.width, mSize.height, gl.get(),
75 0 : aRenderThread.ThreadPool().Raw(),
76 0 : this->mEnableProfiler, mWrApi, &wrRenderer)) {
77 : // wr_window_new puts a message into gfxCriticalNote if it returns false
78 0 : return;
79 : }
80 0 : MOZ_ASSERT(wrRenderer);
81 :
82 0 : RefPtr<RenderThread> thread = &aRenderThread;
83 0 : auto renderer = MakeUnique<RendererOGL>(Move(thread),
84 0 : Move(gl),
85 0 : Move(mCompositorWidget),
86 : aWindowId,
87 : wrRenderer,
88 0 : mBridge);
89 0 : if (wrRenderer && renderer) {
90 0 : WrExternalImageHandler handler = renderer->GetExternalImageHandler();
91 0 : wr_renderer_set_external_image_handler(wrRenderer, &handler);
92 : }
93 :
94 0 : aRenderThread.AddRenderer(aWindowId, Move(renderer));
95 : }
96 :
97 : private:
98 : WrAPI** mWrApi;
99 : GLint* mMaxTextureSize;
100 : bool* mUseANGLE;
101 : layers::CompositorBridgeParentBase* mBridge;
102 : RefPtr<widget::CompositorWidget> mCompositorWidget;
103 : layers::SynchronousTask* mTask;
104 : bool mEnableProfiler;
105 : LayoutDeviceIntSize mSize;
106 : };
107 :
108 : class RemoveRenderer : public RendererEvent
109 : {
110 : public:
111 0 : explicit RemoveRenderer(layers::SynchronousTask* aTask)
112 0 : : mTask(aTask)
113 : {
114 0 : MOZ_COUNT_CTOR(RemoveRenderer);
115 0 : }
116 :
117 0 : ~RemoveRenderer()
118 0 : {
119 0 : MOZ_COUNT_DTOR(RemoveRenderer);
120 0 : }
121 :
122 0 : virtual void Run(RenderThread& aRenderThread, WindowId aWindowId) override
123 : {
124 0 : aRenderThread.RemoveRenderer(aWindowId);
125 0 : layers::AutoCompleteTask complete(mTask);
126 0 : }
127 :
128 : private:
129 : layers::SynchronousTask* mTask;
130 : };
131 :
132 :
133 : //static
134 : already_AddRefed<WebRenderAPI>
135 0 : WebRenderAPI::Create(bool aEnableProfiler,
136 : layers::CompositorBridgeParentBase* aBridge,
137 : RefPtr<widget::CompositorWidget>&& aWidget,
138 : LayoutDeviceIntSize aSize)
139 : {
140 0 : MOZ_ASSERT(aBridge);
141 0 : MOZ_ASSERT(aWidget);
142 :
143 : static uint64_t sNextId = 1;
144 0 : auto id = NewWindowId(sNextId++);
145 :
146 0 : WrAPI* wrApi = nullptr;
147 0 : GLint maxTextureSize = 0;
148 0 : bool useANGLE = false;
149 :
150 : // Dispatch a synchronous task because the WrApi object needs to be created
151 : // on the render thread. If need be we could delay waiting on this task until
152 : // the next time we need to access the WrApi object.
153 0 : layers::SynchronousTask task("Create Renderer");
154 0 : auto event = MakeUnique<NewRenderer>(&wrApi, aBridge, &maxTextureSize, &useANGLE,
155 0 : Move(aWidget), &task, aEnableProfiler, aSize);
156 0 : RenderThread::Get()->RunEvent(id, Move(event));
157 :
158 0 : task.Wait();
159 :
160 0 : if (!wrApi) {
161 0 : return nullptr;
162 : }
163 :
164 0 : return RefPtr<WebRenderAPI>(new WebRenderAPI(wrApi, id, maxTextureSize, useANGLE)).forget();
165 : }
166 :
167 : WrIdNamespace
168 0 : WebRenderAPI::GetNamespace() {
169 0 : return wr_api_get_namespace(mWrApi);
170 : }
171 :
172 0 : WebRenderAPI::~WebRenderAPI()
173 : {
174 0 : layers::SynchronousTask task("Destroy WebRenderAPI");
175 0 : auto event = MakeUnique<RemoveRenderer>(&task);
176 0 : RunOnRenderThread(Move(event));
177 0 : task.Wait();
178 :
179 0 : wr_api_delete(mWrApi);
180 0 : }
181 :
182 : void
183 0 : WebRenderAPI::UpdateScrollPosition(const WrPipelineId& aPipelineId,
184 : const layers::FrameMetrics::ViewID& aScrollId,
185 : const WrPoint& aScrollPosition)
186 : {
187 0 : wr_scroll_layer_with_id(mWrApi, aPipelineId, aScrollId, aScrollPosition);
188 0 : }
189 :
190 : void
191 0 : WebRenderAPI::GenerateFrame()
192 : {
193 0 : wr_api_generate_frame(mWrApi);
194 0 : }
195 :
196 : void
197 0 : WebRenderAPI::GenerateFrame(const nsTArray<WrOpacityProperty>& aOpacityArray,
198 : const nsTArray<WrTransformProperty>& aTransformArray)
199 : {
200 0 : wr_api_generate_frame_with_properties(mWrApi,
201 0 : aOpacityArray.IsEmpty() ?
202 0 : nullptr : aOpacityArray.Elements(),
203 : aOpacityArray.Length(),
204 0 : aTransformArray.IsEmpty() ?
205 0 : nullptr : aTransformArray.Elements(),
206 0 : aTransformArray.Length());
207 0 : }
208 :
209 : void
210 0 : WebRenderAPI::SetRootDisplayList(gfx::Color aBgColor,
211 : Epoch aEpoch,
212 : LayerSize aViewportSize,
213 : WrPipelineId pipeline_id,
214 : const WrSize& content_size,
215 : WrBuiltDisplayListDescriptor dl_descriptor,
216 : uint8_t *dl_data,
217 : size_t dl_size)
218 : {
219 0 : wr_api_set_root_display_list(mWrApi,
220 : ToWrColor(aBgColor),
221 : aEpoch,
222 : aViewportSize.width, aViewportSize.height,
223 : pipeline_id,
224 : content_size,
225 : dl_descriptor,
226 : dl_data,
227 0 : dl_size);
228 0 : }
229 :
230 : void
231 0 : WebRenderAPI::ClearRootDisplayList(Epoch aEpoch,
232 : WrPipelineId pipeline_id)
233 : {
234 0 : wr_api_clear_root_display_list(mWrApi, aEpoch, pipeline_id);
235 0 : }
236 :
237 : void
238 0 : WebRenderAPI::SetWindowParameters(LayoutDeviceIntSize size)
239 : {
240 0 : wr_api_set_window_parameters(mWrApi, size.width, size.height);
241 0 : }
242 :
243 : void
244 0 : WebRenderAPI::Readback(gfx::IntSize size,
245 : uint8_t *buffer,
246 : uint32_t buffer_size)
247 : {
248 : class Readback : public RendererEvent
249 : {
250 : public:
251 0 : explicit Readback(layers::SynchronousTask* aTask,
252 : gfx::IntSize aSize, uint8_t *aBuffer, uint32_t aBufferSize)
253 0 : : mTask(aTask)
254 : , mSize(aSize)
255 : , mBuffer(aBuffer)
256 0 : , mBufferSize(aBufferSize)
257 : {
258 0 : MOZ_COUNT_CTOR(Readback);
259 0 : }
260 :
261 0 : ~Readback()
262 0 : {
263 0 : MOZ_COUNT_DTOR(Readback);
264 0 : }
265 :
266 0 : virtual void Run(RenderThread& aRenderThread, WindowId aWindowId) override
267 : {
268 0 : aRenderThread.UpdateAndRender(aWindowId);
269 0 : wr_renderer_readback(aRenderThread.GetRenderer(aWindowId)->GetWrRenderer(),
270 0 : mSize.width, mSize.height, mBuffer, mBufferSize);
271 0 : layers::AutoCompleteTask complete(mTask);
272 0 : }
273 :
274 : layers::SynchronousTask* mTask;
275 : gfx::IntSize mSize;
276 : uint8_t *mBuffer;
277 : uint32_t mBufferSize;
278 : };
279 :
280 0 : layers::SynchronousTask task("Readback");
281 0 : auto event = MakeUnique<Readback>(&task, size, buffer, buffer_size);
282 : // This event will be passed from wr_backend thread to renderer thread. That
283 : // implies that all frame data have been processed when the renderer runs this
284 : // read-back event. Then, we could make sure this read-back event gets the
285 : // latest result.
286 0 : RunOnRenderThread(Move(event));
287 :
288 0 : task.Wait();
289 0 : }
290 :
291 : void
292 0 : WebRenderAPI::Pause()
293 : {
294 : class PauseEvent : public RendererEvent
295 : {
296 : public:
297 0 : explicit PauseEvent(layers::SynchronousTask* aTask)
298 0 : : mTask(aTask)
299 : {
300 0 : MOZ_COUNT_CTOR(PauseEvent);
301 0 : }
302 :
303 0 : ~PauseEvent()
304 0 : {
305 0 : MOZ_COUNT_DTOR(PauseEvent);
306 0 : }
307 :
308 0 : virtual void Run(RenderThread& aRenderThread, WindowId aWindowId) override
309 : {
310 0 : aRenderThread.Pause(aWindowId);
311 0 : layers::AutoCompleteTask complete(mTask);
312 0 : }
313 :
314 : layers::SynchronousTask* mTask;
315 : };
316 :
317 0 : layers::SynchronousTask task("Pause");
318 0 : auto event = MakeUnique<PauseEvent>(&task);
319 : // This event will be passed from wr_backend thread to renderer thread. That
320 : // implies that all frame data have been processed when the renderer runs this event.
321 0 : RunOnRenderThread(Move(event));
322 :
323 0 : task.Wait();
324 0 : }
325 :
326 : bool
327 0 : WebRenderAPI::Resume()
328 : {
329 : class ResumeEvent : public RendererEvent
330 : {
331 : public:
332 0 : explicit ResumeEvent(layers::SynchronousTask* aTask, bool* aResult)
333 0 : : mTask(aTask)
334 0 : , mResult(aResult)
335 : {
336 0 : MOZ_COUNT_CTOR(ResumeEvent);
337 0 : }
338 :
339 0 : ~ResumeEvent()
340 0 : {
341 0 : MOZ_COUNT_DTOR(ResumeEvent);
342 0 : }
343 :
344 0 : virtual void Run(RenderThread& aRenderThread, WindowId aWindowId) override
345 : {
346 0 : *mResult = aRenderThread.Resume(aWindowId);
347 0 : layers::AutoCompleteTask complete(mTask);
348 0 : }
349 :
350 : layers::SynchronousTask* mTask;
351 : bool* mResult;
352 : };
353 :
354 0 : bool result = false;
355 0 : layers::SynchronousTask task("Resume");
356 0 : auto event = MakeUnique<ResumeEvent>(&task, &result);
357 : // This event will be passed from wr_backend thread to renderer thread. That
358 : // implies that all frame data have been processed when the renderer runs this event.
359 0 : RunOnRenderThread(Move(event));
360 :
361 0 : task.Wait();
362 0 : return result;
363 : }
364 :
365 : void
366 0 : WebRenderAPI::WaitFlushed()
367 : {
368 : class WaitFlushedEvent : public RendererEvent
369 : {
370 : public:
371 0 : explicit WaitFlushedEvent(layers::SynchronousTask* aTask)
372 0 : : mTask(aTask)
373 : {
374 0 : MOZ_COUNT_CTOR(WaitFlushedEvent);
375 0 : }
376 :
377 0 : ~WaitFlushedEvent()
378 0 : {
379 0 : MOZ_COUNT_DTOR(WaitFlushedEvent);
380 0 : }
381 :
382 0 : virtual void Run(RenderThread& aRenderThread, WindowId aWindowId) override
383 : {
384 0 : layers::AutoCompleteTask complete(mTask);
385 0 : }
386 :
387 : layers::SynchronousTask* mTask;
388 : };
389 :
390 0 : layers::SynchronousTask task("WaitFlushed");
391 0 : auto event = MakeUnique<WaitFlushedEvent>(&task);
392 : // This event will be passed from wr_backend thread to renderer thread. That
393 : // implies that all frame data have been processed when the renderer runs this event.
394 0 : RunOnRenderThread(Move(event));
395 :
396 0 : task.Wait();
397 0 : }
398 :
399 : void
400 0 : WebRenderAPI::SetRootPipeline(PipelineId aPipeline)
401 : {
402 0 : wr_api_set_root_pipeline(mWrApi, aPipeline);
403 0 : }
404 :
405 : void
406 0 : WebRenderAPI::AddImage(ImageKey key, const ImageDescriptor& aDescriptor,
407 : Range<uint8_t> aBytes)
408 : {
409 0 : wr_api_add_image(mWrApi,
410 : key,
411 : &aDescriptor,
412 0 : RangeToByteSlice(aBytes));
413 0 : }
414 :
415 : void
416 0 : WebRenderAPI::AddBlobImage(ImageKey key, const ImageDescriptor& aDescriptor,
417 : Range<uint8_t> aBytes)
418 : {
419 0 : wr_api_add_blob_image(mWrApi,
420 : key,
421 : &aDescriptor,
422 0 : RangeToByteSlice(aBytes));
423 0 : }
424 :
425 : void
426 0 : WebRenderAPI::AddExternalImage(ImageKey key,
427 : const ImageDescriptor& aDescriptor,
428 : ExternalImageId aExtID,
429 : WrExternalImageBufferType aBufferType,
430 : uint8_t aChannelIndex)
431 : {
432 0 : wr_api_add_external_image(mWrApi,
433 : key,
434 : &aDescriptor,
435 : aExtID,
436 : aBufferType,
437 0 : aChannelIndex);
438 0 : }
439 :
440 : void
441 0 : WebRenderAPI::AddExternalImageBuffer(ImageKey key,
442 : const ImageDescriptor& aDescriptor,
443 : ExternalImageId aHandle)
444 : {
445 0 : wr_api_add_external_image_buffer(mWrApi,
446 : key,
447 : &aDescriptor,
448 0 : aHandle);
449 0 : }
450 :
451 : void
452 0 : WebRenderAPI::UpdateImageBuffer(ImageKey aKey,
453 : const ImageDescriptor& aDescriptor,
454 : Range<uint8_t> aBytes)
455 : {
456 0 : wr_api_update_image(mWrApi,
457 : aKey,
458 : &aDescriptor,
459 0 : RangeToByteSlice(aBytes));
460 0 : }
461 :
462 : void
463 0 : WebRenderAPI::DeleteImage(ImageKey aKey)
464 : {
465 0 : wr_api_delete_image(mWrApi, aKey);
466 0 : }
467 :
468 : void
469 0 : WebRenderAPI::AddRawFont(wr::FontKey aKey, Range<uint8_t> aBytes, uint32_t aIndex)
470 : {
471 0 : wr_api_add_raw_font(mWrApi, aKey, &aBytes[0], aBytes.length(), aIndex);
472 0 : }
473 :
474 : void
475 0 : WebRenderAPI::DeleteFont(wr::FontKey aKey)
476 : {
477 0 : wr_api_delete_font(mWrApi, aKey);
478 0 : }
479 :
480 : class EnableProfiler : public RendererEvent
481 : {
482 : public:
483 0 : explicit EnableProfiler(bool aEnabled)
484 0 : : mEnabled(aEnabled)
485 : {
486 0 : MOZ_COUNT_CTOR(EnableProfiler);
487 0 : }
488 :
489 0 : ~EnableProfiler()
490 0 : {
491 0 : MOZ_COUNT_DTOR(EnableProfiler);
492 0 : }
493 :
494 0 : virtual void Run(RenderThread& aRenderThread, WindowId aWindowId) override
495 : {
496 0 : auto renderer = aRenderThread.GetRenderer(aWindowId);
497 0 : if (renderer) {
498 0 : renderer->SetProfilerEnabled(mEnabled);
499 : }
500 0 : }
501 :
502 : private:
503 : bool mEnabled;
504 : };
505 :
506 : void
507 0 : WebRenderAPI::SetProfilerEnabled(bool aEnabled)
508 : {
509 0 : auto event = MakeUnique<EnableProfiler>(aEnabled);
510 0 : RunOnRenderThread(Move(event));
511 0 : }
512 :
513 : void
514 0 : WebRenderAPI::RunOnRenderThread(UniquePtr<RendererEvent> aEvent)
515 : {
516 0 : auto event = reinterpret_cast<uintptr_t>(aEvent.release());
517 0 : wr_api_send_external_event(mWrApi, event);
518 0 : }
519 :
520 0 : DisplayListBuilder::DisplayListBuilder(PipelineId aId,
521 0 : const WrSize& aContentSize)
522 : {
523 0 : MOZ_COUNT_CTOR(DisplayListBuilder);
524 0 : mWrState = wr_state_new(aId, aContentSize);
525 0 : }
526 :
527 0 : DisplayListBuilder::~DisplayListBuilder()
528 : {
529 0 : MOZ_COUNT_DTOR(DisplayListBuilder);
530 0 : wr_state_delete(mWrState);
531 0 : }
532 :
533 : void
534 0 : DisplayListBuilder::Begin(const LayerIntSize& aSize)
535 : {
536 0 : wr_dp_begin(mWrState, aSize.width, aSize.height);
537 0 : }
538 :
539 : void
540 0 : DisplayListBuilder::End()
541 : {
542 0 : wr_dp_end(mWrState);
543 0 : }
544 :
545 : void
546 0 : DisplayListBuilder::Finalize(WrSize& aOutContentSize,
547 : BuiltDisplayList& aOutDisplayList)
548 : {
549 0 : wr_api_finalize_builder(mWrState,
550 : &aOutContentSize,
551 : &aOutDisplayList.dl_desc,
552 0 : &aOutDisplayList.dl.inner);
553 0 : }
554 :
555 : void
556 0 : DisplayListBuilder::PushStackingContext(const WrRect& aBounds,
557 : const uint64_t& aAnimationId,
558 : const float* aOpacity,
559 : const gfx::Matrix4x4* aTransform,
560 : WrTransformStyle aTransformStyle,
561 : const WrMixBlendMode& aMixBlendMode,
562 : const nsTArray<WrFilterOp>& aFilters)
563 : {
564 : WrMatrix matrix;
565 0 : if (aTransform) {
566 0 : matrix = ToWrMatrix(*aTransform);
567 : }
568 0 : const WrMatrix* maybeTransform = aTransform ? &matrix : nullptr;
569 : WRDL_LOG("PushStackingContext b=%s t=%s\n", Stringify(aBounds).c_str(),
570 : aTransform ? Stringify(*aTransform).c_str() : "none");
571 0 : wr_dp_push_stacking_context(mWrState, aBounds, aAnimationId, aOpacity,
572 : maybeTransform, aTransformStyle, aMixBlendMode,
573 0 : aFilters.Elements(), aFilters.Length());
574 0 : }
575 :
576 : void
577 0 : DisplayListBuilder::PopStackingContext()
578 : {
579 : WRDL_LOG("PopStackingContext\n");
580 0 : wr_dp_pop_stacking_context(mWrState);
581 0 : }
582 :
583 : void
584 0 : DisplayListBuilder::PushClip(const WrRect& aClipRect,
585 : const WrImageMask* aMask)
586 : {
587 0 : uint64_t clip_id = wr_dp_push_clip(mWrState, aClipRect, nullptr, 0, aMask);
588 : WRDL_LOG("PushClip id=%" PRIu64 " r=%s m=%p b=%s\n", clip_id,
589 : Stringify(aClipRect).c_str(), aMask,
590 : aMask ? Stringify(aMask->rect).c_str() : "none");
591 0 : mClipIdStack.push_back(WrClipId { clip_id });
592 0 : }
593 :
594 : void
595 0 : DisplayListBuilder::PopClip()
596 : {
597 : WRDL_LOG("PopClip id=%" PRIu64 "\n", mClipIdStack.back().id);
598 0 : mClipIdStack.pop_back();
599 0 : wr_dp_pop_clip(mWrState);
600 0 : }
601 :
602 : void
603 0 : DisplayListBuilder::PushBuiltDisplayList(BuiltDisplayList &dl)
604 : {
605 0 : wr_dp_push_built_display_list(mWrState,
606 : dl.dl_desc,
607 0 : &dl.dl.inner);
608 0 : }
609 :
610 : void
611 0 : DisplayListBuilder::PushScrollLayer(const layers::FrameMetrics::ViewID& aScrollId,
612 : const WrRect& aContentRect,
613 : const WrRect& aClipRect)
614 : {
615 : WRDL_LOG("PushScrollLayer id=%" PRIu64 " co=%s cl=%s\n",
616 : aScrollId, Stringify(aContentRect).c_str(), Stringify(aClipRect).c_str());
617 0 : wr_dp_push_scroll_layer(mWrState, aScrollId, aContentRect, aClipRect);
618 0 : if (!mScrollIdStack.empty()) {
619 0 : auto it = mScrollParents.insert({aScrollId, mScrollIdStack.back()});
620 0 : if (!it.second) { // aScrollId was already a key in mScrollParents
621 : // so check that the parent value is the same.
622 0 : MOZ_ASSERT(it.first->second == mScrollIdStack.back());
623 : }
624 : }
625 0 : mScrollIdStack.push_back(aScrollId);
626 0 : }
627 :
628 : void
629 0 : DisplayListBuilder::PopScrollLayer()
630 : {
631 : WRDL_LOG("PopScrollLayer id=%" PRIu64 "\n", mScrollIdStack.back());
632 0 : mScrollIdStack.pop_back();
633 0 : wr_dp_pop_scroll_layer(mWrState);
634 0 : }
635 :
636 : void
637 0 : DisplayListBuilder::PushClipAndScrollInfo(const layers::FrameMetrics::ViewID& aScrollId,
638 : const WrClipId* aClipId)
639 : {
640 : WRDL_LOG("PushClipAndScroll s=%" PRIu64 " c=%s\n", aScrollId,
641 : aClipId ? Stringify(aClipId->id).c_str() : "none");
642 0 : wr_dp_push_clip_and_scroll_info(mWrState, aScrollId,
643 0 : aClipId ? &(aClipId->id) : nullptr);
644 0 : }
645 :
646 : void
647 0 : DisplayListBuilder::PopClipAndScrollInfo()
648 : {
649 : WRDL_LOG("PopClipAndScroll\n");
650 0 : wr_dp_pop_clip_and_scroll_info(mWrState);
651 0 : }
652 :
653 : void
654 0 : DisplayListBuilder::PushRect(const WrRect& aBounds,
655 : const WrRect& aClip,
656 : const WrColor& aColor)
657 : {
658 : WRDL_LOG("PushRect b=%s cl=%s c=%s\n",
659 : Stringify(aBounds).c_str(),
660 : Stringify(aClip).c_str(),
661 : Stringify(aColor).c_str());
662 0 : wr_dp_push_rect(mWrState, aBounds, aClip, aColor);
663 0 : }
664 :
665 : void
666 0 : DisplayListBuilder::PushLinearGradient(const WrRect& aBounds,
667 : const WrRect& aClip,
668 : const WrPoint& aStartPoint,
669 : const WrPoint& aEndPoint,
670 : const nsTArray<WrGradientStop>& aStops,
671 : wr::GradientExtendMode aExtendMode,
672 : const WrSize aTileSize,
673 : const WrSize aTileSpacing)
674 : {
675 0 : wr_dp_push_linear_gradient(mWrState,
676 : aBounds, aClip,
677 : aStartPoint, aEndPoint,
678 : aStops.Elements(), aStops.Length(),
679 : aExtendMode,
680 0 : aTileSize, aTileSpacing);
681 0 : }
682 :
683 : void
684 0 : DisplayListBuilder::PushRadialGradient(const WrRect& aBounds,
685 : const WrRect& aClip,
686 : const WrPoint& aCenter,
687 : const WrSize& aRadius,
688 : const nsTArray<WrGradientStop>& aStops,
689 : wr::GradientExtendMode aExtendMode,
690 : const WrSize aTileSize,
691 : const WrSize aTileSpacing)
692 : {
693 0 : wr_dp_push_radial_gradient(mWrState,
694 : aBounds, aClip,
695 : aCenter, aRadius,
696 : aStops.Elements(), aStops.Length(),
697 : aExtendMode,
698 0 : aTileSize, aTileSpacing);
699 0 : }
700 :
701 : void
702 0 : DisplayListBuilder::PushImage(const WrRect& aBounds,
703 : const WrRect& aClip,
704 : wr::ImageRendering aFilter,
705 : wr::ImageKey aImage)
706 : {
707 : WrSize size;
708 0 : size.width = aBounds.width;
709 0 : size.height = aBounds.height;
710 0 : PushImage(aBounds, aClip, size, size, aFilter, aImage);
711 0 : }
712 :
713 : void
714 0 : DisplayListBuilder::PushImage(const WrRect& aBounds,
715 : const WrRect& aClip,
716 : const WrSize& aStretchSize,
717 : const WrSize& aTileSpacing,
718 : wr::ImageRendering aFilter,
719 : wr::ImageKey aImage)
720 : {
721 : WRDL_LOG("PushImage b=%s cl=%s s=%s t=%s\n", Stringify(aBounds).c_str(),
722 : Stringify(aClip).c_str(), Stringify(aStretchSize).c_str(),
723 : Stringify(aTileSpacing).c_str());
724 0 : wr_dp_push_image(mWrState, aBounds, aClip, aStretchSize, aTileSpacing, aFilter, aImage);
725 0 : }
726 :
727 : void
728 0 : DisplayListBuilder::PushYCbCrPlanarImage(const WrRect& aBounds,
729 : const WrRect& aClip,
730 : wr::ImageKey aImageChannel0,
731 : wr::ImageKey aImageChannel1,
732 : wr::ImageKey aImageChannel2,
733 : WrYuvColorSpace aColorSpace,
734 : wr::ImageRendering aRendering)
735 : {
736 0 : wr_dp_push_yuv_planar_image(mWrState,
737 : aBounds,
738 : aClip,
739 : aImageChannel0,
740 : aImageChannel1,
741 : aImageChannel2,
742 : aColorSpace,
743 0 : aRendering);
744 0 : }
745 :
746 : void
747 0 : DisplayListBuilder::PushNV12Image(const WrRect& aBounds,
748 : const WrRect& aClip,
749 : wr::ImageKey aImageChannel0,
750 : wr::ImageKey aImageChannel1,
751 : WrYuvColorSpace aColorSpace,
752 : wr::ImageRendering aRendering)
753 : {
754 0 : wr_dp_push_yuv_NV12_image(mWrState,
755 : aBounds,
756 : aClip,
757 : aImageChannel0,
758 : aImageChannel1,
759 : aColorSpace,
760 0 : aRendering);
761 0 : }
762 :
763 : void
764 0 : DisplayListBuilder::PushYCbCrInterleavedImage(const WrRect& aBounds,
765 : const WrRect& aClip,
766 : wr::ImageKey aImageChannel0,
767 : WrYuvColorSpace aColorSpace,
768 : wr::ImageRendering aRendering)
769 : {
770 0 : wr_dp_push_yuv_interleaved_image(mWrState,
771 : aBounds,
772 : aClip,
773 : aImageChannel0,
774 : aColorSpace,
775 0 : aRendering);
776 0 : }
777 :
778 : void
779 0 : DisplayListBuilder::PushIFrame(const WrRect& aBounds,
780 : PipelineId aPipeline)
781 : {
782 0 : wr_dp_push_iframe(mWrState, aBounds, aPipeline);
783 0 : }
784 :
785 : void
786 0 : DisplayListBuilder::PushBorder(const WrRect& aBounds,
787 : const WrRect& aClip,
788 : const WrBorderWidths& aWidths,
789 : const Range<const WrBorderSide>& aSides,
790 : const WrBorderRadius& aRadius)
791 : {
792 0 : MOZ_ASSERT(aSides.length() == 4);
793 0 : if (aSides.length() != 4) {
794 0 : return;
795 : }
796 0 : wr_dp_push_border(mWrState, aBounds, aClip,
797 0 : aWidths, aSides[0], aSides[1], aSides[2], aSides[3], aRadius);
798 : }
799 :
800 : void
801 0 : DisplayListBuilder::PushBorderImage(const WrRect& aBounds,
802 : const WrRect& aClip,
803 : const WrBorderWidths& aWidths,
804 : wr::ImageKey aImage,
805 : const WrNinePatchDescriptor& aPatch,
806 : const WrSideOffsets2Df32& aOutset,
807 : const WrRepeatMode& aRepeatHorizontal,
808 : const WrRepeatMode& aRepeatVertical)
809 : {
810 0 : wr_dp_push_border_image(mWrState, aBounds, aClip,
811 : aWidths, aImage, aPatch, aOutset,
812 0 : aRepeatHorizontal, aRepeatVertical);
813 0 : }
814 :
815 : void
816 0 : DisplayListBuilder::PushBorderGradient(const WrRect& aBounds,
817 : const WrRect& aClip,
818 : const WrBorderWidths& aWidths,
819 : const WrPoint& aStartPoint,
820 : const WrPoint& aEndPoint,
821 : const nsTArray<WrGradientStop>& aStops,
822 : wr::GradientExtendMode aExtendMode,
823 : const WrSideOffsets2Df32& aOutset)
824 : {
825 0 : wr_dp_push_border_gradient(mWrState, aBounds, aClip,
826 : aWidths, aStartPoint, aEndPoint,
827 : aStops.Elements(), aStops.Length(),
828 0 : aExtendMode, aOutset);
829 0 : }
830 :
831 : void
832 0 : DisplayListBuilder::PushBorderRadialGradient(const WrRect& aBounds,
833 : const WrRect& aClip,
834 : const WrBorderWidths& aWidths,
835 : const WrPoint& aCenter,
836 : const WrSize& aRadius,
837 : const nsTArray<WrGradientStop>& aStops,
838 : wr::GradientExtendMode aExtendMode,
839 : const WrSideOffsets2Df32& aOutset)
840 : {
841 0 : wr_dp_push_border_radial_gradient(
842 : mWrState, aBounds, aClip, aWidths, aCenter,
843 : aRadius, aStops.Elements(), aStops.Length(),
844 0 : aExtendMode, aOutset);
845 0 : }
846 :
847 : void
848 0 : DisplayListBuilder::PushText(const WrRect& aBounds,
849 : const WrRect& aClip,
850 : const gfx::Color& aColor,
851 : wr::FontKey aFontKey,
852 : Range<const WrGlyphInstance> aGlyphBuffer,
853 : float aGlyphSize)
854 : {
855 0 : wr_dp_push_text(mWrState, aBounds, aClip,
856 : ToWrColor(aColor),
857 : aFontKey,
858 0 : &aGlyphBuffer[0], aGlyphBuffer.length(),
859 0 : aGlyphSize);
860 0 : }
861 :
862 : void
863 0 : DisplayListBuilder::PushBoxShadow(const WrRect& aRect,
864 : const WrRect& aClip,
865 : const WrRect& aBoxBounds,
866 : const WrPoint& aOffset,
867 : const WrColor& aColor,
868 : const float& aBlurRadius,
869 : const float& aSpreadRadius,
870 : const float& aBorderRadius,
871 : const WrBoxShadowClipMode& aClipMode)
872 : {
873 0 : wr_dp_push_box_shadow(mWrState, aRect, aClip,
874 : aBoxBounds, aOffset, aColor,
875 : aBlurRadius, aSpreadRadius, aBorderRadius,
876 0 : aClipMode);
877 0 : }
878 :
879 : Maybe<WrClipId>
880 0 : DisplayListBuilder::TopmostClipId()
881 : {
882 0 : if (mClipIdStack.empty()) {
883 0 : return Nothing();
884 : }
885 0 : return Some(mClipIdStack.back());
886 : }
887 :
888 : Maybe<layers::FrameMetrics::ViewID>
889 0 : DisplayListBuilder::ParentScrollIdFor(layers::FrameMetrics::ViewID aScrollId)
890 : {
891 0 : auto it = mScrollParents.find(aScrollId);
892 0 : return (it == mScrollParents.end() ? Nothing() : Some(it->second));
893 : }
894 :
895 : } // namespace wr
896 9 : } // namespace mozilla
|