1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #include "CompositorWidget.h"
7 #include "nsBaseWidget.h"
8 #include "VsyncDispatcher.h"
13 CompositorWidget::CompositorWidget(const layers::CompositorOptions
& aOptions
)
14 : mOptions(aOptions
) {}
16 CompositorWidget::~CompositorWidget() = default;
18 already_AddRefed
<gfx::DrawTarget
> CompositorWidget::StartRemoteDrawing() {
22 void CompositorWidget::CleanupRemoteDrawing() { mLastBackBuffer
= nullptr; }
24 already_AddRefed
<gfx::DrawTarget
> CompositorWidget::GetBackBufferDrawTarget(
25 gfx::DrawTarget
* aScreenTarget
, const gfx::IntRect
& aRect
,
26 bool* aOutIsCleared
) {
27 MOZ_ASSERT(aScreenTarget
);
28 gfx::SurfaceFormat format
=
29 aScreenTarget
->GetFormat() == gfx::SurfaceFormat::B8G8R8X8
30 ? gfx::SurfaceFormat::B8G8R8X8
31 : gfx::SurfaceFormat::B8G8R8A8
;
32 gfx::IntSize size
= aRect
.Size();
33 gfx::IntSize clientSize
= Max(size
, GetClientSize().ToUnknownSize());
35 *aOutIsCleared
= false;
36 // Re-use back buffer if possible
37 if (!mLastBackBuffer
||
38 mLastBackBuffer
->GetBackendType() != aScreenTarget
->GetBackendType() ||
39 mLastBackBuffer
->GetFormat() != format
||
40 mLastBackBuffer
->GetSize() != clientSize
) {
42 aScreenTarget
->CreateSimilarDrawTarget(clientSize
, format
);
43 *aOutIsCleared
= true;
45 return do_AddRef(mLastBackBuffer
);
48 already_AddRefed
<gfx::SourceSurface
> CompositorWidget::EndBackBufferDrawing() {
49 RefPtr
<gfx::SourceSurface
> surface
=
50 mLastBackBuffer
? mLastBackBuffer
->Snapshot() : nullptr;
51 return surface
.forget();
54 uint32_t CompositorWidget::GetGLFrameBufferFormat() { return LOCAL_GL_RGBA
; }
56 RefPtr
<VsyncObserver
> CompositorWidget::GetVsyncObserver() const {
57 // This should only used when the widget is in the GPU process, and should be
58 // implemented by IPDL-enabled CompositorWidgets.
59 // GPU process does not have a CompositorVsyncDispatcher.
60 MOZ_ASSERT_UNREACHABLE("Must be implemented by derived class");
64 LayoutDeviceIntRegion
CompositorWidget::GetTransparentRegion() {
65 // By default, we check the transparency mode to determine if the widget is
66 // transparent, and if so, designate the entire widget drawing area as
67 // transparent. Widgets wanting more complex transparency region determination
68 // should override this method.
69 auto* widget
= RealWidget();
70 if (!widget
|| widget
->GetTransparencyMode() != TransparencyMode::Opaque
||
71 widget
->WidgetPaintsBackground()) {
72 return LayoutDeviceIntRect(LayoutDeviceIntPoint(0, 0), GetClientSize());
74 return LayoutDeviceIntRegion();
78 } // namespace mozilla