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 RefPtr
<widget::CompositorWidget
>&& aWidget
, nsACString
& aError
);
38 explicit RenderCompositorANGLE(RefPtr
<widget::CompositorWidget
>&& aWidget
);
39 virtual ~RenderCompositorANGLE();
40 bool Initialize(nsACString
& aError
);
42 bool BeginFrame() override
;
43 RenderedFrameId
EndFrame(const nsTArray
<DeviceIntRect
>& aDirtyRects
) final
;
44 bool WaitForGPU() override
;
45 RenderedFrameId
GetLastCompletedFrameId() final
;
46 RenderedFrameId
UpdateFrameId() final
;
47 void Pause() override
;
48 bool Resume() override
;
49 void Update() override
;
51 gl::GLContext
* gl() const override
{
52 return RenderThread::Get()->SingletonGL();
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
;
79 uint32_t GetMaxUpdateRects() override
;
81 // Interface for wr::Compositor
82 void CompositorBeginFrame() override
;
83 void CompositorEndFrame() override
;
84 void Bind(wr::NativeTileId aId
, wr::DeviceIntPoint
* aOffset
, uint32_t* aFboId
,
85 wr::DeviceIntRect aDirtyRect
,
86 wr::DeviceIntRect aValidRect
) override
;
87 void Unbind() override
;
88 void CreateSurface(wr::NativeSurfaceId aId
, wr::DeviceIntPoint aVirtualOffset
,
89 wr::DeviceIntSize aTileSize
, bool aIsOpaque
) override
;
90 void CreateExternalSurface(wr::NativeSurfaceId aId
, bool aIsOpaque
) override
;
91 void DestroySurface(NativeSurfaceId aId
) override
;
92 void CreateTile(wr::NativeSurfaceId aId
, int32_t aX
, int32_t aY
) override
;
93 void DestroyTile(wr::NativeSurfaceId aId
, int32_t aX
, int32_t aY
) override
;
94 void AttachExternalImage(wr::NativeSurfaceId aId
,
95 wr::ExternalImageId aExternalImage
) override
;
96 void AddSurface(wr::NativeSurfaceId aId
,
97 const wr::CompositorSurfaceTransform
& aTransform
,
98 wr::DeviceIntRect aClipRect
,
99 wr::ImageRendering aImageRendering
) override
;
100 void EnableNativeCompositor(bool aEnable
) override
;
101 void GetCompositorCapabilities(CompositorCapabilities
* aCaps
) override
;
103 // Interface for partial present
104 bool UsePartialPresent() override
;
105 bool RequestFullRender() override
;
106 uint32_t GetMaxPartialPresentRects() override
;
108 bool MaybeReadback(const gfx::IntSize
& aReadbackSize
,
109 const wr::ImageFormat
& aReadbackFormat
,
110 const Range
<uint8_t>& aReadbackBuffer
,
111 bool* aNeedsYFlip
) override
;
114 bool UseCompositor();
115 void InitializeUsePartialPresent();
116 void InsertGraphicsCommandsFinishedWaitQuery(
117 RenderedFrameId aRenderedFrameId
);
118 bool WaitForPreviousGraphicsCommandsFinishedQuery(bool aWaitAll
= false);
119 bool ResizeBufferIfNeeded();
120 bool CreateEGLSurface();
121 void DestroyEGLSurface();
122 ID3D11Device
* GetDeviceOfEGLDisplay(nsACString
& aError
);
123 bool CreateSwapChain(nsACString
& aError
);
124 void CreateSwapChainForDCompIfPossible(IDXGIFactory2
* aDXGIFactory2
);
125 RefPtr
<IDXGISwapChain1
> CreateSwapChainForDComp(bool aUseTripleBuffering
,
127 bool ShutdownEGLLibraryIfNecessary(nsACString
& aError
);
128 RefPtr
<ID3D11Query
> GetD3D11Query();
129 void ReleaseNativeCompositorResources();
130 HWND
GetCompositorHwnd();
132 EGLConfig mEGLConfig
;
133 EGLSurface mEGLSurface
;
135 bool mUseTripleBuffering
;
138 RefPtr
<ID3D11Device
> mDevice
;
139 RefPtr
<ID3D11DeviceContext
> mCtx
;
140 RefPtr
<IDXGISwapChain
> mSwapChain
;
141 RefPtr
<IDXGISwapChain1
> mSwapChain1
;
143 UniquePtr
<DCLayerTree
> mDCLayerTree
;
145 std::queue
<std::pair
<RenderedFrameId
, RefPtr
<ID3D11Query
>>>
146 mWaitForPresentQueries
;
147 RefPtr
<ID3D11Query
> mRecycledQuery
;
148 RenderedFrameId mLastCompletedFrameId
;
150 Maybe
<LayoutDeviceIntSize
> mBufferSize
;
151 bool mUseNativeCompositor
;
152 bool mUsePartialPresent
;
154 // Used to know a timing of disabling native compositor.
155 bool mDisablingNativeCompositor
;
159 } // namespace mozilla