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
{ return RenderThread::Get()->SharedGL(); }
53 bool MakeCurrent() override
;
55 bool UseANGLE() const override
{ return true; }
57 bool UseDComp() const override
{ return !!mDCLayerTree
; }
59 bool UseTripleBuffering() const override
{ return mUseTripleBuffering
; }
61 layers::WebRenderCompositor
CompositorType() const override
{
63 return layers::WebRenderCompositor::DIRECT_COMPOSITION
;
65 return layers::WebRenderCompositor::DRAW
;
68 LayoutDeviceIntSize
GetBufferSize() override
;
70 GLenum
IsContextLost(bool aForce
) override
;
72 bool SurfaceOriginIsTopLeft() override
{ return true; }
74 bool SupportAsyncScreenshot() override
;
76 bool ShouldUseNativeCompositor() override
;
77 uint32_t GetMaxUpdateRects() override
;
79 // Interface for wr::Compositor
80 void CompositorBeginFrame() override
;
81 void CompositorEndFrame() override
;
82 void Bind(wr::NativeTileId aId
, wr::DeviceIntPoint
* aOffset
, uint32_t* aFboId
,
83 wr::DeviceIntRect aDirtyRect
,
84 wr::DeviceIntRect aValidRect
) override
;
85 void Unbind() override
;
86 void CreateSurface(wr::NativeSurfaceId aId
, wr::DeviceIntPoint aVirtualOffset
,
87 wr::DeviceIntSize aTileSize
, bool aIsOpaque
) override
;
88 void CreateExternalSurface(wr::NativeSurfaceId aId
, bool aIsOpaque
) override
;
89 void DestroySurface(NativeSurfaceId aId
) override
;
90 void CreateTile(wr::NativeSurfaceId aId
, int32_t aX
, int32_t aY
) override
;
91 void DestroyTile(wr::NativeSurfaceId aId
, int32_t aX
, int32_t aY
) override
;
92 void AttachExternalImage(wr::NativeSurfaceId aId
,
93 wr::ExternalImageId aExternalImage
) override
;
94 void AddSurface(wr::NativeSurfaceId aId
,
95 const wr::CompositorSurfaceTransform
& aTransform
,
96 wr::DeviceIntRect aClipRect
,
97 wr::ImageRendering aImageRendering
) override
;
98 void EnableNativeCompositor(bool aEnable
) override
;
99 CompositorCapabilities
GetCompositorCapabilities() override
;
101 // Interface for partial present
102 bool UsePartialPresent() override
;
103 bool RequestFullRender() override
;
104 uint32_t GetMaxPartialPresentRects() override
;
106 bool MaybeReadback(const gfx::IntSize
& aReadbackSize
,
107 const wr::ImageFormat
& aReadbackFormat
,
108 const Range
<uint8_t>& aReadbackBuffer
,
109 bool* aNeedsYFlip
) override
;
112 bool UseCompositor();
113 void InitializeUsePartialPresent();
114 void InsertGraphicsCommandsFinishedWaitQuery(
115 RenderedFrameId aRenderedFrameId
);
116 bool WaitForPreviousGraphicsCommandsFinishedQuery(bool aWaitAll
= false);
117 bool ResizeBufferIfNeeded();
118 bool CreateEGLSurface();
119 void DestroyEGLSurface();
120 ID3D11Device
* GetDeviceOfEGLDisplay(nsACString
& aError
);
121 bool CreateSwapChain(nsACString
& aError
);
122 void CreateSwapChainForDCompIfPossible(IDXGIFactory2
* aDXGIFactory2
);
123 RefPtr
<IDXGISwapChain1
> CreateSwapChainForDComp(bool aUseTripleBuffering
,
125 bool ShutdownEGLLibraryIfNecessary(nsACString
& aError
);
126 RefPtr
<ID3D11Query
> GetD3D11Query();
127 void ReleaseNativeCompositorResources();
128 HWND
GetCompositorHwnd();
130 EGLConfig mEGLConfig
;
131 EGLSurface mEGLSurface
;
133 bool mUseTripleBuffering
;
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
;
150 bool mUsePartialPresent
;
152 // Used to know a timing of disabling native compositor.
153 bool mDisablingNativeCompositor
;
157 } // namespace mozilla