2016-06-30 05:35:24 +03:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
2016-07-01 11:15:16 +03:00
|
|
|
#include "CompositorWidget.h"
|
2016-06-30 05:35:24 +03:00
|
|
|
#include "GLConsts.h"
|
|
|
|
#include "nsBaseWidget.h"
|
|
|
|
#include "VsyncDispatcher.h"
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace widget {
|
|
|
|
|
2016-07-01 11:15:16 +03:00
|
|
|
CompositorWidget::~CompositorWidget()
|
2016-06-30 05:35:24 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<gfx::DrawTarget>
|
2016-07-01 11:15:16 +03:00
|
|
|
CompositorWidget::StartRemoteDrawing()
|
2016-06-30 05:35:24 +03:00
|
|
|
{
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-07-01 11:15:16 +03:00
|
|
|
CompositorWidget::CleanupRemoteDrawing()
|
2016-06-30 05:35:24 +03:00
|
|
|
{
|
|
|
|
mLastBackBuffer = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<gfx::DrawTarget>
|
2016-07-01 11:15:16 +03:00
|
|
|
CompositorWidget::GetBackBufferDrawTarget(gfx::DrawTarget* aScreenTarget,
|
|
|
|
const LayoutDeviceIntRect& aRect,
|
|
|
|
const LayoutDeviceIntRect& aClearRect)
|
2016-06-30 05:35:24 +03:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(aScreenTarget);
|
|
|
|
gfx::SurfaceFormat format =
|
|
|
|
aScreenTarget->GetFormat() == gfx::SurfaceFormat::B8G8R8X8 ? gfx::SurfaceFormat::B8G8R8X8 : gfx::SurfaceFormat::B8G8R8A8;
|
|
|
|
gfx::IntSize size = aRect.ToUnknownRect().Size();
|
|
|
|
gfx::IntSize clientSize(GetClientSize().ToUnknownSize());
|
|
|
|
|
|
|
|
RefPtr<gfx::DrawTarget> target;
|
|
|
|
// Re-use back buffer if possible
|
|
|
|
if (mLastBackBuffer &&
|
|
|
|
mLastBackBuffer->GetBackendType() == aScreenTarget->GetBackendType() &&
|
|
|
|
mLastBackBuffer->GetFormat() == format &&
|
|
|
|
size <= mLastBackBuffer->GetSize() &&
|
|
|
|
mLastBackBuffer->GetSize() <= clientSize) {
|
|
|
|
target = mLastBackBuffer;
|
|
|
|
target->SetTransform(gfx::Matrix());
|
|
|
|
if (!aClearRect.IsEmpty()) {
|
|
|
|
gfx::IntRect clearRect = aClearRect.ToUnknownRect() - aRect.ToUnknownRect().TopLeft();
|
|
|
|
target->ClearRect(gfx::Rect(clearRect.x, clearRect.y, clearRect.width, clearRect.height));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
target = aScreenTarget->CreateSimilarDrawTarget(size, format);
|
|
|
|
mLastBackBuffer = target;
|
|
|
|
}
|
|
|
|
return target.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<gfx::SourceSurface>
|
2016-07-01 11:15:16 +03:00
|
|
|
CompositorWidget::EndBackBufferDrawing()
|
2016-06-30 05:35:24 +03:00
|
|
|
{
|
|
|
|
RefPtr<gfx::SourceSurface> surface = mLastBackBuffer ? mLastBackBuffer->Snapshot() : nullptr;
|
|
|
|
return surface.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t
|
2016-07-01 11:15:16 +03:00
|
|
|
CompositorWidget::GetGLFrameBufferFormat()
|
2016-06-30 05:35:24 +03:00
|
|
|
{
|
|
|
|
return LOCAL_GL_RGBA;
|
|
|
|
}
|
|
|
|
|
2016-07-19 21:56:07 +03:00
|
|
|
RefPtr<VsyncObserver>
|
|
|
|
CompositorWidget::GetVsyncObserver() const
|
|
|
|
{
|
|
|
|
// This should only used when the widget is in the GPU process, and should be
|
|
|
|
// implemented by IPDL-enabled CompositorWidgets.
|
|
|
|
// GPU process does not have a CompositorVsyncDispatcher.
|
|
|
|
MOZ_ASSERT_UNREACHABLE("Must be implemented by derived class");
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2016-06-30 05:35:24 +03:00
|
|
|
} // namespace widget
|
|
|
|
} // namespace mozilla
|