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_ANGLE_H
8 #define MOZILLA_GFX_RENDERCOMPOSITOR_ANGLE_H
13 #include "mozilla/Maybe.h"
14 #include "mozilla/webrender/RenderCompositor.h"
15 #include "mozilla/webrender/RenderThread.h"
17 struct ID3D11DeviceContext
;
21 struct IDXGISwapChain
;
22 struct IDXGISwapChain1
;
33 class RenderCompositorANGLE
: public RenderCompositor
{
35 static UniquePtr
<RenderCompositor
> Create(
36 const RefPtr
<widget::CompositorWidget
>& aWidget
, nsACString
& aError
);
38 explicit RenderCompositorANGLE(
39 const RefPtr
<widget::CompositorWidget
>& aWidget
,
40 RefPtr
<gl::GLContext
>&& aGL
);
41 virtual ~RenderCompositorANGLE();
42 bool Initialize(nsACString
& aError
);
44 bool BeginFrame() override
;
45 RenderedFrameId
EndFrame(const nsTArray
<DeviceIntRect
>& aDirtyRects
) final
;
46 bool WaitForGPU() override
;
47 RenderedFrameId
GetLastCompletedFrameId() final
;
48 RenderedFrameId
UpdateFrameId() final
;
49 void Pause() override
;
50 bool Resume() override
;
51 void Update() override
;
53 gl::GLContext
* gl() const override
{ return mGL
; }
55 bool MakeCurrent() override
;
57 bool UseANGLE() const override
{ return true; }
59 bool UseDComp() const override
{ return !!mDCLayerTree
; }
61 bool UseTripleBuffering() const override
{ return mUseTripleBuffering
; }
63 layers::WebRenderCompositor
CompositorType() const override
{
65 return layers::WebRenderCompositor::DIRECT_COMPOSITION
;
67 return layers::WebRenderCompositor::DRAW
;
70 LayoutDeviceIntSize
GetBufferSize() override
;
72 GLenum
IsContextLost(bool aForce
) override
;
74 bool SurfaceOriginIsTopLeft() override
{ return true; }
76 bool SupportAsyncScreenshot() override
;
78 bool ShouldUseNativeCompositor() override
;
80 // Interface for wr::Compositor
81 void CompositorBeginFrame() override
;
82 void CompositorEndFrame() override
;
83 void Bind(wr::NativeTileId aId
, wr::DeviceIntPoint
* aOffset
, uint32_t* aFboId
,
84 wr::DeviceIntRect aDirtyRect
,
85 wr::DeviceIntRect aValidRect
) override
;
86 void Unbind() override
;
87 void CreateSurface(wr::NativeSurfaceId aId
, wr::DeviceIntPoint aVirtualOffset
,
88 wr::DeviceIntSize aTileSize
, bool aIsOpaque
) override
;
89 void CreateExternalSurface(wr::NativeSurfaceId aId
, bool aIsOpaque
) override
;
90 void DestroySurface(NativeSurfaceId aId
) override
;
91 void CreateTile(wr::NativeSurfaceId aId
, int32_t aX
, int32_t aY
) override
;
92 void DestroyTile(wr::NativeSurfaceId aId
, int32_t aX
, int32_t aY
) override
;
93 void AttachExternalImage(wr::NativeSurfaceId aId
,
94 wr::ExternalImageId aExternalImage
) override
;
95 void AddSurface(wr::NativeSurfaceId aId
,
96 const wr::CompositorSurfaceTransform
& aTransform
,
97 wr::DeviceIntRect aClipRect
,
98 wr::ImageRendering aImageRendering
) override
;
99 void EnableNativeCompositor(bool aEnable
) override
;
100 void GetCompositorCapabilities(CompositorCapabilities
* aCaps
) override
;
102 // Interface for partial present
103 bool UsePartialPresent() override
;
104 bool RequestFullRender() override
;
105 uint32_t GetMaxPartialPresentRects() override
;
107 bool MaybeReadback(const gfx::IntSize
& aReadbackSize
,
108 const wr::ImageFormat
& aReadbackFormat
,
109 const Range
<uint8_t>& aReadbackBuffer
,
110 bool* aNeedsYFlip
) override
;
113 bool UseCompositor();
114 void InitializeUsePartialPresent();
115 void InsertGraphicsCommandsFinishedWaitQuery(
116 RenderedFrameId aRenderedFrameId
);
117 bool WaitForPreviousGraphicsCommandsFinishedQuery(bool aWaitAll
= false);
118 bool ResizeBufferIfNeeded();
119 bool CreateEGLSurface();
120 void DestroyEGLSurface();
121 ID3D11Device
* GetDeviceOfEGLDisplay(nsACString
& aError
);
122 bool CreateSwapChain(nsACString
& aError
);
123 void CreateSwapChainForDCompIfPossible(IDXGIFactory2
* aDXGIFactory2
);
124 RefPtr
<IDXGISwapChain1
> CreateSwapChainForDComp(bool aUseTripleBuffering
);
125 RefPtr
<ID3D11Query
> GetD3D11Query();
126 void ReleaseNativeCompositorResources();
127 HWND
GetCompositorHwnd();
129 RefPtr
<gl::GLContext
> mGL
;
131 EGLConfig mEGLConfig
= nullptr;
132 EGLSurface mEGLSurface
= nullptr;
134 bool mUseTripleBuffering
= false;
136 RefPtr
<ID3D11Device
> mDevice
;
137 RefPtr
<ID3D11DeviceContext
> mCtx
;
138 RefPtr
<IDXGISwapChain
> mSwapChain
;
139 RefPtr
<IDXGISwapChain1
> mSwapChain1
;
141 UniquePtr
<DCLayerTree
> mDCLayerTree
;
143 std::queue
<std::pair
<RenderedFrameId
, RefPtr
<ID3D11Query
>>>
144 mWaitForPresentQueries
;
145 RefPtr
<ID3D11Query
> mRecycledQuery
;
146 RenderedFrameId mLastCompletedFrameId
;
148 Maybe
<LayoutDeviceIntSize
> mBufferSize
;
149 bool mUseNativeCompositor
= true;
150 bool mUsePartialPresent
= false;
151 bool mFullRender
= false;
152 // Used to know a timing of disabling native compositor.
153 bool mDisablingNativeCompositor
= false;
154 bool mFirstPresent
= true;
158 } // namespace mozilla