Skip to content

Commit

Permalink
Bug 1573343 - Stop using LayoutDevice units in BasicCompositor. r=mat…
Browse files Browse the repository at this point in the history
…twoodrow

ScreenPixels would be a more appropriate unit. But inside BasicCompositor everything
is in the same coordinate space anyway so we're not getting much benefit from the
units. This patch eliminates a lot of .ToUnknown*() calls.

Differential Revision: https://phabricator.services.mozilla.com/D41680

--HG--
extra : moz-landing-system : lando
  • Loading branch information
mstange committed Aug 19, 2019
1 parent cc120aa commit 66fc92f
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 40 deletions.
60 changes: 29 additions & 31 deletions gfx/layers/basic/BasicCompositor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -291,9 +291,9 @@ BasicCompositor::CreateRenderTargetFromSource(
}

already_AddRefed<CompositingRenderTarget>
BasicCompositor::CreateRenderTargetForWindow(
const LayoutDeviceIntRect& aRect, const LayoutDeviceIntRegion& aClearRegion,
BufferMode aBufferMode) {
BasicCompositor::CreateRenderTargetForWindow(const IntRect& aRect,
const IntRegion& aClearRegion,
BufferMode aBufferMode) {
MOZ_ASSERT(mDrawTarget);
MOZ_ASSERT(!aRect.IsZeroArea(),
"Trying to create a render target of invalid size");
Expand All @@ -303,7 +303,6 @@ BasicCompositor::CreateRenderTargetForWindow(
}

RefPtr<BasicCompositingRenderTarget> rt;
IntRect rect = aRect.ToUnknownRect();

bool isCleared = false;
if (aBufferMode != BufferMode::BUFFER_NONE) {
Expand All @@ -313,17 +312,16 @@ BasicCompositor::CreateRenderTargetForWindow(
return nullptr;
}
MOZ_ASSERT(target != mDrawTarget);
rt = new BasicCompositingRenderTarget(target, rect);
rt = new BasicCompositingRenderTarget(target, aRect);
} else {
rt = new BasicCompositingRenderTarget(mDrawTarget, mDrawTargetBounds);
}

rt->mDrawTarget->SetTransform(Matrix::Translation(-rt->GetOrigin()));

if (!aClearRegion.IsEmpty() && !isCleared) {
gfx::IntRegion clearRegion = aClearRegion.ToUnknownRegion();
gfx::IntRect clearRect = clearRegion.GetBounds();
gfxUtils::ClipToRegion(rt->mDrawTarget, clearRegion);
gfx::IntRect clearRect = aClearRegion.GetBounds();
gfxUtils::ClipToRegion(rt->mDrawTarget, aClearRegion);
rt->mDrawTarget->ClearRect(gfx::Rect(clearRect));
rt->mDrawTarget->PopClip();
}
Expand Down Expand Up @@ -894,8 +892,7 @@ void BasicCompositor::BeginFrame(
MOZ_ASSERT(!mIsPendingEndRemoteDrawing);
}

LayoutDeviceIntRect intRect(LayoutDeviceIntPoint(), mWidget->GetClientSize());
IntRect rect = IntRect(0, 0, intRect.Width(), intRect.Height());
IntRect rect(IntPoint(), mWidget->GetClientSize().ToUnknownSize());

const bool shouldInvalidateWindow =
(ShouldRecordFrames() &&
Expand All @@ -904,12 +901,11 @@ void BasicCompositor::BeginFrame(
rect.ToUnknownRect().Size()));

if (shouldInvalidateWindow) {
mInvalidRegion = intRect;
mInvalidRegion = rect;
} else {
LayoutDeviceIntRegion invalidRegionSafe;
IntRegion invalidRegionSafe;
// Sometimes the invalid region is larger than we want to draw.
invalidRegionSafe.And(
LayoutDeviceIntRegion::FromUnknownRegion(aInvalidRegion), intRect);
invalidRegionSafe.And(aInvalidRegion, rect);

mInvalidRegion = invalidRegionSafe;
}
Expand All @@ -931,15 +927,17 @@ void BasicCompositor::BeginFrame(
mDrawTargetBounds = mTargetBounds;
bufferMode = BufferMode::BUFFER_NONE;
} else {
// StartRemoteDrawingInRegion can mutate mInvalidRegion.
LayoutDeviceIntRegion invalidRegion =
LayoutDeviceIntRegion::FromUnknownRegion(mInvalidRegion);
mDrawTarget =
mWidget->StartRemoteDrawingInRegion(mInvalidRegion, &bufferMode);
mWidget->StartRemoteDrawingInRegion(invalidRegion, &bufferMode);
if (!mDrawTarget) {
return;
}
mInvalidRegion = invalidRegion.ToUnknownRegion();
mInvalidRect = mInvalidRegion.GetBounds();
if (mInvalidRect.IsEmpty()) {
mWidget->EndRemoteDrawingInRegion(mDrawTarget, mInvalidRegion);
mWidget->EndRemoteDrawingInRegion(mDrawTarget, invalidRegion);
return;
}

Expand All @@ -949,16 +947,16 @@ void BasicCompositor::BeginFrame(
// comparing the DrawTarget's size with the invalild region's size.
IntSize dtSize = mDrawTarget->GetSize();
if (bufferMode == BufferMode::BUFFER_NONE &&
dtSize == mInvalidRect.Size().ToUnknownSize()) {
mDrawTargetBounds = mInvalidRect.ToUnknownRect();
dtSize == mInvalidRect.Size()) {
mDrawTargetBounds = mInvalidRect;
} else {
mDrawTargetBounds = IntRect(IntPoint(0, 0), dtSize);
}
}

LayoutDeviceIntRegion clearRegion = mInvalidRegion;
IntRegion clearRegion = mInvalidRegion;
if (!aOpaqueRegion.IsEmpty()) {
clearRegion.SubOut(LayoutDeviceIntRegion::FromUnknownRegion(aOpaqueRegion));
clearRegion.SubOut(aOpaqueRegion);
}

// Setup a render target for drawing. In cases where we need to buffer all
Expand All @@ -970,26 +968,26 @@ void BasicCompositor::BeginFrame(

if (!target) {
if (!mTarget) {
mWidget->EndRemoteDrawingInRegion(mDrawTarget, mInvalidRegion);
mWidget->EndRemoteDrawingInRegion(
mDrawTarget,
LayoutDeviceIntRegion::FromUnknownRegion(mInvalidRegion));
}
return;
}
SetRenderTarget(target);

if (ShouldRecordFrames()) {
IntSize windowSize = rect.ToUnknownRect().Size();

// On some platforms (notably Linux with X11) we do not always have a
// full-size draw target. While capturing profiles with screenshots, we need
// access to a full-size target so we can record the contents.
if (!mFullWindowRenderTarget ||
mFullWindowRenderTarget->mDrawTarget->GetSize() != windowSize) {
mFullWindowRenderTarget->mDrawTarget->GetSize() != rect.Size()) {
// We have either (1) just started recording and not yet allocated a
// buffer or (2) are already recording and have resized the window. In
// either case, we need a new render target.
RefPtr<gfx::DrawTarget> drawTarget =
mRenderTarget->mDrawTarget->CreateSimilarDrawTarget(
windowSize, mRenderTarget->mDrawTarget->GetFormat());
rect.Size(), mRenderTarget->mDrawTarget->GetFormat());

mFullWindowRenderTarget =
new BasicCompositingRenderTarget(drawTarget, rect);
Expand Down Expand Up @@ -1074,14 +1072,14 @@ void BasicCompositor::TryToEndRemoteDrawing(bool aForceToEnd) {
// garbage pixels.
// CopySurface ignores both the transform and the clip.
for (auto iter = mInvalidRegion.RectIter(); !iter.Done(); iter.Next()) {
const LayoutDeviceIntRect& r = iter.Get();
mDrawTarget->CopySurface(source, r.ToUnknownRect() - srcOffset,
r.TopLeft().ToUnknownPoint() - dstOffset);
const IntRect& r = iter.Get();
mDrawTarget->CopySurface(source, r - srcOffset, r.TopLeft() - dstOffset);
}
}

if (aForceToEnd || !mTarget) {
mWidget->EndRemoteDrawingInRegion(mDrawTarget, mInvalidRegion);
mWidget->EndRemoteDrawingInRegion(
mDrawTarget, LayoutDeviceIntRegion::FromUnknownRegion(mInvalidRegion));
}

mDrawTarget = nullptr;
Expand All @@ -1098,7 +1096,7 @@ void BasicCompositor::NormalDrawingDone() {
RefPtr<SourceSurface> source = mRenderTarget->mDrawTarget->Snapshot();
IntPoint srcOffset = mRenderTarget->GetOrigin();
for (auto iter = mInvalidRegion.RectIter(); !iter.Done(); iter.Next()) {
IntRect r = iter.Get().ToUnknownRect();
const IntRect& r = iter.Get();
mFullWindowRenderTarget->mDrawTarget->CopySurface(source, r - srcOffset,
r.TopLeft());
}
Expand Down
8 changes: 4 additions & 4 deletions gfx/layers/basic/BasicCompositor.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ class BasicCompositor : public Compositor {
const gfx::IntPoint& aSourcePoint) override;

virtual already_AddRefed<CompositingRenderTarget> CreateRenderTargetForWindow(
const LayoutDeviceIntRect& aRect,
const LayoutDeviceIntRegion& aClearRegion, BufferMode aBufferMode);
const gfx::IntRect& aRect, const gfx::IntRegion& aClearRegion,
BufferMode aBufferMode);

already_AddRefed<DataTextureSource> CreateDataTextureSource(
TextureFlags aFlags = TextureFlags::NO_FLAGS) override;
Expand Down Expand Up @@ -189,8 +189,8 @@ class BasicCompositor : public Compositor {
// The current render target for drawing
RefPtr<BasicCompositingRenderTarget> mRenderTarget;

LayoutDeviceIntRect mInvalidRect;
LayoutDeviceIntRegion mInvalidRegion;
gfx::IntRect mInvalidRect;
gfx::IntRegion mInvalidRegion;

uint32_t mMaxTextureSize;
bool mIsPendingEndRemoteDrawing;
Expand Down
4 changes: 2 additions & 2 deletions widget/CompositorWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ already_AddRefed<gfx::DrawTarget> CompositorWidget::StartRemoteDrawing() {
void CompositorWidget::CleanupRemoteDrawing() { mLastBackBuffer = nullptr; }

already_AddRefed<gfx::DrawTarget> CompositorWidget::GetBackBufferDrawTarget(
gfx::DrawTarget* aScreenTarget, const LayoutDeviceIntRect& aRect,
gfx::DrawTarget* aScreenTarget, const gfx::IntRect& aRect,
bool* aOutIsCleared) {
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 size = aRect.Size();
gfx::IntSize clientSize = Max(size, GetClientSize().ToUnknownSize());

*aOutIsCleared = false;
Expand Down
2 changes: 1 addition & 1 deletion widget/CompositorWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ class CompositorWidget {
* Create a backbuffer for the software compositor.
*/
virtual already_AddRefed<gfx::DrawTarget> GetBackBufferDrawTarget(
gfx::DrawTarget* aScreenTarget, const LayoutDeviceIntRect& aRect,
gfx::DrawTarget* aScreenTarget, const gfx::IntRect& aRect,
bool* aOutIsCleared);

/**
Expand Down
2 changes: 1 addition & 1 deletion widget/windows/WinCompositorWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ bool WinCompositorWidget::NeedsToDeferEndRemoteDrawing() {
}

already_AddRefed<gfx::DrawTarget> WinCompositorWidget::GetBackBufferDrawTarget(
gfx::DrawTarget* aScreenTarget, const LayoutDeviceIntRect& aRect,
gfx::DrawTarget* aScreenTarget, const gfx::IntRect& aRect,
bool* aOutIsCleared) {
MOZ_ASSERT(!mLockedBackBufferData);

Expand Down
2 changes: 1 addition & 1 deletion widget/windows/WinCompositorWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class WinCompositorWidget : public CompositorWidget,
bool NeedsToDeferEndRemoteDrawing() override;
LayoutDeviceIntSize GetClientSize() override;
already_AddRefed<gfx::DrawTarget> GetBackBufferDrawTarget(
gfx::DrawTarget* aScreenTarget, const LayoutDeviceIntRect& aRect,
gfx::DrawTarget* aScreenTarget, const gfx::IntRect& aRect,
bool* aOutIsCleared) override;
already_AddRefed<gfx::SourceSurface> EndBackBufferDrawing() override;
bool InitCompositor(layers::Compositor* aCompositor) override;
Expand Down

0 comments on commit 66fc92f

Please sign in to comment.