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
)
18 CompositorWidget::~CompositorWidget()
22 already_AddRefed
<gfx::DrawTarget
>
23 CompositorWidget::StartRemoteDrawing()
29 CompositorWidget::CleanupRemoteDrawing()
31 mLastBackBuffer
= nullptr;
34 already_AddRefed
<gfx::DrawTarget
>
35 CompositorWidget::GetBackBufferDrawTarget(gfx::DrawTarget
* aScreenTarget
,
36 const LayoutDeviceIntRect
& aRect
,
37 const LayoutDeviceIntRect
& aClearRect
)
39 MOZ_ASSERT(aScreenTarget
);
40 gfx::SurfaceFormat format
=
41 aScreenTarget
->GetFormat() == gfx::SurfaceFormat::B8G8R8X8
? gfx::SurfaceFormat::B8G8R8X8
: gfx::SurfaceFormat::B8G8R8A8
;
42 gfx::IntSize size
= aRect
.ToUnknownRect().Size();
43 gfx::IntSize
clientSize(GetClientSize().ToUnknownSize());
45 RefPtr
<gfx::DrawTarget
> target
;
46 // Re-use back buffer if possible
47 if (mLastBackBuffer
&&
48 mLastBackBuffer
->GetBackendType() == aScreenTarget
->GetBackendType() &&
49 mLastBackBuffer
->GetFormat() == format
&&
50 size
<= mLastBackBuffer
->GetSize() &&
51 mLastBackBuffer
->GetSize() <= clientSize
) {
52 target
= mLastBackBuffer
;
53 target
->SetTransform(gfx::Matrix());
54 if (!aClearRect
.IsEmpty()) {
55 gfx::IntRect clearRect
= aClearRect
.ToUnknownRect() - aRect
.ToUnknownRect().TopLeft();
56 target
->ClearRect(gfx::Rect(clearRect
.x
, clearRect
.y
, clearRect
.width
, clearRect
.height
));
59 target
= aScreenTarget
->CreateSimilarDrawTarget(size
, format
);
60 mLastBackBuffer
= target
;
62 return target
.forget();
65 already_AddRefed
<gfx::SourceSurface
>
66 CompositorWidget::EndBackBufferDrawing()
68 RefPtr
<gfx::SourceSurface
> surface
= mLastBackBuffer
? mLastBackBuffer
->Snapshot() : nullptr;
69 return surface
.forget();
73 CompositorWidget::GetGLFrameBufferFormat()
79 CompositorWidget::GetVsyncObserver() const
81 // This should only used when the widget is in the GPU process, and should be
82 // implemented by IPDL-enabled CompositorWidgets.
83 // GPU process does not have a CompositorVsyncDispatcher.
84 MOZ_ASSERT_UNREACHABLE("Must be implemented by derived class");
89 } // namespace mozilla