Bug 1454293 [wpt PR 10484] - null is not the correct origin for createDocument()...
[gecko.git] / widget / CompositorWidget.cpp
blob7d729c1b8b939150880c18f1e305c108db74b7f3
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)
18 CompositorWidget::~CompositorWidget()
22 already_AddRefed<gfx::DrawTarget>
23 CompositorWidget::StartRemoteDrawing()
25 return nullptr;
28 void
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()));
58 } else {
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();
72 uint32_t
73 CompositorWidget::GetGLFrameBufferFormat()
75 return LOCAL_GL_RGBA;
78 RefPtr<VsyncObserver>
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");
85 return nullptr;
88 } // namespace widget
89 } // namespace mozilla