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_SWGL_H
8 #define MOZILLA_GFX_RENDERCOMPOSITOR_SWGL_H
10 #include "mozilla/gfx/2D.h"
11 #include "mozilla/webrender/RenderCompositor.h"
17 class RenderCompositorSWGL
: public RenderCompositor
{
19 static UniquePtr
<RenderCompositor
> Create(
20 const RefPtr
<widget::CompositorWidget
>& aWidget
, nsACString
& aError
);
22 RenderCompositorSWGL(const RefPtr
<widget::CompositorWidget
>& aWidget
,
24 virtual ~RenderCompositorSWGL();
26 void* swgl() const override
{ return mContext
; }
28 bool MakeCurrent() override
;
30 bool BeginFrame() override
;
31 void CancelFrame() override
;
32 RenderedFrameId
EndFrame(const nsTArray
<DeviceIntRect
>& aDirtyRects
) final
;
34 void StartCompositing(wr::ColorF aClearColor
,
35 const wr::DeviceIntRect
* aDirtyRects
,
36 size_t aNumDirtyRects
,
37 const wr::DeviceIntRect
* aOpaqueRects
,
38 size_t aNumOpaqueRects
) override
;
40 bool UsePartialPresent() override
{ return true; }
41 bool RequestFullRender() override
;
43 void Pause() override
;
44 bool Resume() override
;
46 layers::WebRenderBackend
BackendType() const override
{
47 return layers::WebRenderBackend::SOFTWARE
;
49 layers::WebRenderCompositor
CompositorType() const override
{
50 return layers::WebRenderCompositor::SOFTWARE
;
53 bool SurfaceOriginIsTopLeft() override
{ return true; }
55 LayoutDeviceIntSize
GetBufferSize() override
;
57 bool SupportsExternalBufferTextures() const override
{ return true; }
59 // Interface for wr::Compositor
60 void GetCompositorCapabilities(CompositorCapabilities
* aCaps
) override
;
63 void* mContext
= nullptr;
64 RefPtr
<gfx::DrawTarget
> mDT
;
65 LayoutDeviceIntRegion mDirtyRegion
;
66 // Keep consistent buffer size between BeginFrame and EndFrame/CancelFrame
67 // calls to make sure we don't change buffer size during rendering.
68 Maybe
<LayoutDeviceIntSize
> mRenderWidgetSize
;
69 RefPtr
<gfx::DataSourceSurface
> mSurface
;
70 uint8_t* mMappedData
= nullptr;
71 int32_t mMappedStride
= 0;
73 // On Wayland we need to request full render if widget size is changed
74 // because SW rendering backend reallocates and clears target surface.
75 LayoutDeviceIntSize mLastRenderWidgetSize
;
76 bool mRequestFullRender
= false;
79 void ClearMappedBuffer();
81 bool AllocateMappedBuffer(const wr::DeviceIntRect
* aOpaqueRects
,
82 size_t aNumOpaqueRects
);
84 void CommitMappedBuffer(bool aDirty
= true);
88 } // namespace mozilla