Bug 1833753 [wpt PR 40065] - Allow newly-added test to also pass when mutation events...
[gecko.git] / gfx / webrender_bindings / RenderCompositor.h
blob89b06395c1f52cb1891560b978337ba14a3324b4
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 #ifndef MOZILLA_GFX_RENDERCOMPOSITOR_H
8 #define MOZILLA_GFX_RENDERCOMPOSITOR_H
10 #include "mozilla/ipc/FileDescriptor.h"
11 #include "mozilla/RefPtr.h"
12 #include "mozilla/UniquePtr.h"
13 #include "mozilla/webrender/WebRenderTypes.h"
14 #include "Units.h"
16 #include "GLTypes.h"
18 namespace mozilla {
20 namespace gl {
21 class GLContext;
24 namespace layers {
25 class CompositionRecorder;
26 class SyncObjectHost;
27 } // namespace layers
29 namespace widget {
30 class CompositorWidget;
33 namespace wr {
35 class RenderCompositorLayersSWGL;
36 class RenderCompositorD3D11SWGL;
38 class RenderCompositor {
39 public:
40 static UniquePtr<RenderCompositor> Create(
41 const RefPtr<widget::CompositorWidget>& aWidget, nsACString& aError);
43 RenderCompositor(const RefPtr<widget::CompositorWidget>& aWidget);
44 virtual ~RenderCompositor();
46 virtual bool BeginFrame() = 0;
48 // Optional handler in case the frame was aborted allowing the compositor
49 // to clean up relevant resources if required.
50 virtual void CancelFrame() {}
52 // Called to notify the RenderCompositor that all of the commands for a frame
53 // have been pushed to the queue.
54 // @return a RenderedFrameId for the frame
55 virtual RenderedFrameId EndFrame(
56 const nsTArray<DeviceIntRect>& aDirtyRects) = 0;
57 // Returns false when waiting gpu tasks is failed.
58 // It might happen when rendering context is lost.
59 virtual bool WaitForGPU() { return true; }
61 // Check for and return the last completed frame.
62 // @return the last (highest) completed RenderedFrameId
63 virtual RenderedFrameId GetLastCompletedFrameId() {
64 return mLatestRenderFrameId.Prev();
67 // Update FrameId when WR rendering does not happen.
68 virtual RenderedFrameId UpdateFrameId() { return GetNextRenderFrameId(); }
70 virtual void Pause() = 0;
71 virtual bool Resume() = 0;
72 // Called when WR rendering is skipped
73 virtual void Update() {}
75 virtual gl::GLContext* gl() const { return nullptr; }
76 virtual void* swgl() const { return nullptr; }
78 virtual bool MakeCurrent();
80 virtual bool UseANGLE() const { return false; }
82 virtual bool UseDComp() const { return false; }
84 virtual bool UseTripleBuffering() const { return false; }
86 virtual layers::WebRenderBackend BackendType() const {
87 return layers::WebRenderBackend::HARDWARE;
89 virtual layers::WebRenderCompositor CompositorType() const {
90 return layers::WebRenderCompositor::DRAW;
93 virtual RenderCompositorD3D11SWGL* AsRenderCompositorD3D11SWGL() {
94 return nullptr;
97 virtual RenderCompositorLayersSWGL* AsRenderCompositorLayersSWGL() {
98 return nullptr;
101 // True if AttachExternalImage supports being used with an external
102 // image that maps to a RenderBufferTextureHost
103 virtual bool SupportsExternalBufferTextures() const { return false; }
105 virtual LayoutDeviceIntSize GetBufferSize() = 0;
107 widget::CompositorWidget* GetWidget() const { return mWidget; }
109 layers::SyncObjectHost* GetSyncObject() const { return mSyncObject.get(); }
111 virtual GLenum IsContextLost(bool aForce);
113 virtual bool SupportAsyncScreenshot() { return true; }
115 virtual bool ShouldUseNativeCompositor() { return false; }
117 // Interface for wr::Compositor
118 virtual void CompositorBeginFrame() {}
119 virtual void CompositorEndFrame() {}
120 virtual void Bind(wr::NativeTileId aId, wr::DeviceIntPoint* aOffset,
121 uint32_t* aFboId, wr::DeviceIntRect aDirtyRect,
122 wr::DeviceIntRect aValidRect) {}
123 virtual void Unbind() {}
124 virtual bool MapTile(wr::NativeTileId aId, wr::DeviceIntRect aDirtyRect,
125 wr::DeviceIntRect aValidRect, void** aData,
126 int32_t* aStride) {
127 return false;
129 virtual void UnmapTile() {}
130 virtual void CreateSurface(wr::NativeSurfaceId aId,
131 wr::DeviceIntPoint aVirtualOffset,
132 wr::DeviceIntSize aTileSize, bool aIsOpaque) {}
133 virtual void CreateExternalSurface(wr::NativeSurfaceId aId, bool aIsOpaque) {}
134 virtual void CreateBackdropSurface(wr::NativeSurfaceId aId,
135 wr::ColorF aColor) {}
136 virtual void DestroySurface(NativeSurfaceId aId) {}
137 virtual void CreateTile(wr::NativeSurfaceId, int32_t aX, int32_t aY) {}
138 virtual void DestroyTile(wr::NativeSurfaceId, int32_t aX, int32_t aY) {}
139 virtual void AttachExternalImage(wr::NativeSurfaceId aId,
140 wr::ExternalImageId aExternalImage) {}
141 virtual void AddSurface(wr::NativeSurfaceId aId,
142 const wr::CompositorSurfaceTransform& aTransform,
143 wr::DeviceIntRect aClipRect,
144 wr::ImageRendering aImageRendering) {}
145 // Called in the middle of a frame after all surfaces have been added but
146 // before tiles are updated to signal that early compositing can start
147 virtual void StartCompositing(wr::ColorF aClearColor,
148 const wr::DeviceIntRect* aDirtyRects,
149 size_t aNumDirtyRects,
150 const wr::DeviceIntRect* aOpaqueRects,
151 size_t aNumOpaqueRects) {}
152 virtual void EnableNativeCompositor(bool aEnable) {}
153 virtual void DeInit() {}
154 // Overrides any of the default compositor capabilities for behavior this
155 // compositor might require.
156 virtual void GetCompositorCapabilities(CompositorCapabilities* aCaps);
158 virtual void GetWindowVisibility(WindowVisibility* aVisibility);
160 // Interface for partial present
161 virtual bool UsePartialPresent() { return false; }
162 virtual bool RequestFullRender() { return false; }
163 virtual uint32_t GetMaxPartialPresentRects() { return 0; }
164 virtual bool ShouldDrawPreviousPartialPresentRegions() { return false; }
165 // Returns the age of the current backbuffer., This should be used, if
166 // ShouldDrawPreviousPartialPresentRegions() returns true, to determine the
167 // region which must be rendered in addition to the current frame's dirty
168 // rect.
169 virtual size_t GetBufferAge() const { return 0; }
170 // Allows webrender to specify the total region that will be rendered to this
171 // frame, ie the frame's dirty region and some previous frames' dirty regions,
172 // if applicable (calculated using the buffer age). Must be called before
173 // anything has been rendered to the main framebuffer.
174 virtual void SetBufferDamageRegion(const wr::DeviceIntRect* aRects,
175 size_t aNumRects) {}
177 // Whether the surface origin is top-left.
178 virtual bool SurfaceOriginIsTopLeft() { return false; }
180 // Does readback if wr_renderer_readback() could not get correct WR rendered
181 // result. It could happen when WebRender renders to multiple overlay layers.
182 virtual bool MaybeReadback(const gfx::IntSize& aReadbackSize,
183 const wr::ImageFormat& aReadbackFormat,
184 const Range<uint8_t>& aReadbackBuffer,
185 bool* aNeedsYFlip) {
186 return false;
188 virtual void MaybeRequestAllowFrameRecording(bool aWillRecord) {}
189 virtual bool MaybeRecordFrame(layers::CompositionRecorder& aRecorder) {
190 return false;
192 virtual bool MaybeGrabScreenshot(const gfx::IntSize& aWindowSize) {
193 return false;
195 virtual bool MaybeProcessScreenshotQueue() { return false; }
197 // Returns FileDescriptor of release fence.
198 // Release fence is a fence that is used for waiting until usage/composite of
199 // AHardwareBuffer is ended. The fence is delivered to client side via
200 // ImageBridge. It is used only on android.
201 virtual ipc::FileDescriptor GetAndResetReleaseFence() {
202 return ipc::FileDescriptor();
205 virtual bool IsPaused() { return false; }
207 protected:
208 // We default this to 2, so that mLatestRenderFrameId.Prev() is always valid.
209 RenderedFrameId mLatestRenderFrameId = RenderedFrameId{2};
210 RenderedFrameId GetNextRenderFrameId() {
211 mLatestRenderFrameId = mLatestRenderFrameId.Next();
212 return mLatestRenderFrameId;
215 RefPtr<widget::CompositorWidget> mWidget;
216 RefPtr<layers::SyncObjectHost> mSyncObject;
219 } // namespace wr
220 } // namespace mozilla
222 #endif