Bug 1527661 [wpt PR 15356] - Update wpt metadata, a=testonly
[gecko.git] / widget / CompositorWidget.cpp
blobc371cb5a11a715c6e32fbd041e70c4d67a5da760
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"
6 #include "GLConsts.h"
7 #include "nsBaseWidget.h"
8 #include "VsyncDispatcher.h"
10 namespace mozilla {
11 namespace widget {
13 CompositorWidget::CompositorWidget(const layers::CompositorOptions& aOptions)
14 : mOptions(aOptions) {}
16 CompositorWidget::~CompositorWidget() {}
18 already_AddRefed<gfx::DrawTarget> CompositorWidget::StartRemoteDrawing() {
19 return nullptr;
22 void CompositorWidget::CleanupRemoteDrawing() { mLastBackBuffer = nullptr; }
24 already_AddRefed<gfx::DrawTarget> CompositorWidget::GetBackBufferDrawTarget(
25 gfx::DrawTarget* aScreenTarget, const LayoutDeviceIntRect& aRect,
26 const LayoutDeviceIntRect& aClearRect) {
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.ToUnknownRect().Size();
33 gfx::IntSize clientSize(GetClientSize().ToUnknownSize());
35 RefPtr<gfx::DrawTarget> target;
36 // Re-use back buffer if possible
37 if (mLastBackBuffer &&
38 mLastBackBuffer->GetBackendType() == aScreenTarget->GetBackendType() &&
39 mLastBackBuffer->GetFormat() == format &&
40 size <= mLastBackBuffer->GetSize() &&
41 mLastBackBuffer->GetSize() <= clientSize) {
42 target = mLastBackBuffer;
43 target->SetTransform(gfx::Matrix());
44 if (!aClearRect.IsEmpty()) {
45 gfx::IntRect clearRect =
46 aClearRect.ToUnknownRect() - aRect.ToUnknownRect().TopLeft();
47 target->ClearRect(gfx::Rect(clearRect.X(), clearRect.Y(),
48 clearRect.Width(), clearRect.Height()));
50 } else {
51 target = aScreenTarget->CreateSimilarDrawTarget(size, format);
52 mLastBackBuffer = target;
54 return target.forget();
57 already_AddRefed<gfx::SourceSurface> CompositorWidget::EndBackBufferDrawing() {
58 RefPtr<gfx::SourceSurface> surface =
59 mLastBackBuffer ? mLastBackBuffer->Snapshot() : nullptr;
60 return surface.forget();
63 uint32_t CompositorWidget::GetGLFrameBufferFormat() { return LOCAL_GL_RGBA; }
65 RefPtr<VsyncObserver> CompositorWidget::GetVsyncObserver() const {
66 // This should only used when the widget is in the GPU process, and should be
67 // implemented by IPDL-enabled CompositorWidgets.
68 // GPU process does not have a CompositorVsyncDispatcher.
69 MOZ_ASSERT_UNREACHABLE("Must be implemented by derived class");
70 return nullptr;
73 } // namespace widget
74 } // namespace mozilla