From 53537230f9792e4e0c96d44a3e4fcf0921238572 Mon Sep 17 00:00:00 2001 From: Ryan Hunt Date: Wed, 1 Aug 2018 12:44:33 -0500 Subject: [PATCH] Bug 1478815 part 1 - Add a PadEdges operation to DrawTarget. r=bas This commit adds an operation to perform 'edge padding' on a draw target. By default this is performed using LockBits, but it's overriden in DrawTargetTiled and DrawTargetCapture to propagate the call so it functions correctly. This helps TiledContentClient move from applying this operation on a per texture client basis, to being able to do it on the DrawTargetTiled after painting. This in turn helps move all paint thread operations into DrawTargetCapture. MozReview-Commit-ID: 2ncOTxGXQfk --HG-- rename : gfx/layers/BufferEdgePad.cpp => gfx/2d/BufferEdgePad.cpp rename : gfx/layers/BufferEdgePad.h => gfx/2d/BufferEdgePad.h extra : rebase_source : a3315644fe31f2a432935dcbfdb9969c58b691e1 extra : source : 699c954992f87db7fc792f5562090de42a8162cb --- gfx/2d/2D.h | 7 ++++++ gfx/{layers => 2d}/BufferEdgePad.cpp | 21 +++++++++++------ gfx/{layers => 2d}/BufferEdgePad.h | 15 ++++++------ gfx/2d/DrawCommand.h | 3 ++- gfx/2d/DrawCommands.h | 34 ++++++++++++++++++++++++++++ gfx/2d/DrawTarget.cpp | 8 +++++++ gfx/2d/DrawTargetCapture.cpp | 6 +++++ gfx/2d/DrawTargetCapture.h | 1 + gfx/2d/DrawTargetTiled.cpp | 23 +++++++++++++++++++ gfx/2d/DrawTargetTiled.h | 1 + gfx/2d/moz.build | 1 + gfx/layers/PaintThread.cpp | 1 - gfx/layers/TextureSync.cpp | 7 +++--- gfx/layers/moz.build | 2 -- gfx/src/nsRegion.cpp | 6 ++--- gfx/src/nsRegion.h | 4 ++-- 16 files changed, 114 insertions(+), 26 deletions(-) rename gfx/{layers => 2d}/BufferEdgePad.cpp (82%) rename gfx/{layers => 2d}/BufferEdgePad.h (58%) diff --git a/gfx/2d/2D.h b/gfx/2d/2D.h index c07df090f61a..b2e347d1f0e2 100644 --- a/gfx/2d/2D.h +++ b/gfx/2d/2D.h @@ -34,6 +34,8 @@ #include "mozilla/DebugOnly.h" +#include "nsRegionFwd.h" + #if defined(MOZ_WIDGET_ANDROID) || defined(MOZ_WIDGET_GTK) #ifndef MOZ_ENABLE_FREETYPE #define MOZ_ENABLE_FREETYPE @@ -1296,6 +1298,11 @@ public: */ virtual void Blur(const AlphaBoxBlur& aBlur); + /** + * Performs an in-place edge padding operation. + */ + virtual void PadEdges(const IntRegion& aRegion); + /** * Create a SourceSurface optimized for use with this DrawTarget from * existing bitmap data in memory. diff --git a/gfx/layers/BufferEdgePad.cpp b/gfx/2d/BufferEdgePad.cpp similarity index 82% rename from gfx/layers/BufferEdgePad.cpp rename to gfx/2d/BufferEdgePad.cpp index ad3600262b1f..c31ec06ad905 100644 --- a/gfx/layers/BufferEdgePad.cpp +++ b/gfx/2d/BufferEdgePad.cpp @@ -1,15 +1,22 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* 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/. */ + #include "BufferEdgePad.h" -#include "mozilla/gfx/Point.h" // for IntSize -#include "mozilla/gfx/Types.h" // for SurfaceFormat +#include "2D.h" // for DrawTarget +#include "Point.h" // for IntSize +#include "Types.h" // for SurfaceFormat + +#include "nsRegion.h" namespace mozilla { -namespace layers { - -using namespace gfx; +namespace gfx { void -PadDrawTargetOutFromRegion(RefPtr aDrawTarget, nsIntRegion &aRegion) +PadDrawTargetOutFromRegion(DrawTarget* aDrawTarget, const nsIntRegion &aRegion) { struct LockedBits { uint8_t *data; @@ -89,5 +96,5 @@ PadDrawTargetOutFromRegion(RefPtr aDrawTarget, nsIntRegion &aRegion) } } -} // namespace layers +} // namespace gfx } // namespace mozilla diff --git a/gfx/layers/BufferEdgePad.h b/gfx/2d/BufferEdgePad.h similarity index 58% rename from gfx/layers/BufferEdgePad.h rename to gfx/2d/BufferEdgePad.h index 05b6e0526215..af7b40679d1c 100644 --- a/gfx/layers/BufferEdgePad.h +++ b/gfx/2d/BufferEdgePad.h @@ -4,18 +4,19 @@ * 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/. */ -#ifndef MOZILLA_LAYERS_BUFFER_EDGE_PAD_H -#define MOZILLA_LAYERS_BUFFER_EDGE_PAD_H +#ifndef MOZILLA_GFX_BUFFER_EDGE_PAD_H +#define MOZILLA_GFX_BUFFER_EDGE_PAD_H -#include "mozilla/gfx/2D.h" -#include "nsRegion.h" +#include "nsRegionFwd.h" namespace mozilla { -namespace layers { +namespace gfx { -void PadDrawTargetOutFromRegion(RefPtr aDrawTarget, nsIntRegion &aRegion); +class DrawTarget; + +void PadDrawTargetOutFromRegion(DrawTarget* aDrawTarget, const nsIntRegion &aRegion); } // namespace layers } // namespace mozilla -#endif // MOZILLA_LAYERS_BUFFER_EDGE_PAD_H +#endif // MOZILLA_GFX_BUFFER_EDGE_PAD_H diff --git a/gfx/2d/DrawCommand.h b/gfx/2d/DrawCommand.h index 41a78f416285..f92564e3e472 100644 --- a/gfx/2d/DrawCommand.h +++ b/gfx/2d/DrawCommand.h @@ -45,7 +45,8 @@ enum class CommandType : int8_t { SETTRANSFORM, SETPERMITSUBPIXELAA, FLUSH, - BLUR + BLUR, + PADEDGES, }; class DrawingCommand diff --git a/gfx/2d/DrawCommands.h b/gfx/2d/DrawCommands.h index b69e3fe907a3..db1822a3518e 100644 --- a/gfx/2d/DrawCommands.h +++ b/gfx/2d/DrawCommands.h @@ -1126,6 +1126,40 @@ private: AlphaBoxBlur mBlur; }; +class PadEdgesCommand : public DrawingCommand +{ +public: + explicit PadEdgesCommand(const IntRegion& aRegion) + : mRegion(aRegion) + {} + + CommandType GetType() const override + { + return PadEdgesCommand::Type; + } + + void CloneInto(CaptureCommandList* aList) override + { + CLONE_INTO(PadEdgesCommand)(IntRegion(mRegion)); + } + + void ExecuteOnDT(DrawTarget* aDT, const Matrix*) const override + { + aDT->PadEdges(mRegion); + } + + void Log(TreeLog& aStream) const override + { + aStream << "[PADEDGES]"; + } + + static const bool AffectsSnapshot = true; + static const CommandType Type = CommandType::PADEDGES; + +private: + IntRegion mRegion; +}; + #undef CLONE_INTO } // namespace gfx diff --git a/gfx/2d/DrawTarget.cpp b/gfx/2d/DrawTarget.cpp index f8ab453b5c4e..05ac5e7a1372 100644 --- a/gfx/2d/DrawTarget.cpp +++ b/gfx/2d/DrawTarget.cpp @@ -10,6 +10,8 @@ #include "DrawTargetCapture.h" +#include "BufferEdgePad.h" + #ifdef BUILD_ARM_NEON #include "mozilla/arm.h" #include "LuminanceNEON.h" @@ -288,5 +290,11 @@ DrawTarget::Blur(const AlphaBoxBlur& aBlur) ReleaseBits(data); } +void +DrawTarget::PadEdges(const IntRegion& aRegion) +{ + PadDrawTargetOutFromRegion(this, aRegion); +} + } // namespace gfx } // namespace mozilla diff --git a/gfx/2d/DrawTargetCapture.cpp b/gfx/2d/DrawTargetCapture.cpp index 4158f0064cab..8030b24953f1 100644 --- a/gfx/2d/DrawTargetCapture.cpp +++ b/gfx/2d/DrawTargetCapture.cpp @@ -343,6 +343,12 @@ DrawTargetCaptureImpl::Blur(const AlphaBoxBlur& aBlur) AppendCommand(BlurCommand)(aBlur); } +void +DrawTargetCaptureImpl::PadEdges(const IntRegion& aRegion) +{ + AppendCommand(PadEdgesCommand)(aRegion); +} + void DrawTargetCaptureImpl::ReplayToDrawTarget(DrawTarget* aDT, const Matrix& aTransform) { diff --git a/gfx/2d/DrawTargetCapture.h b/gfx/2d/DrawTargetCapture.h index 967a83b1f511..565ca31d4cf0 100644 --- a/gfx/2d/DrawTargetCapture.h +++ b/gfx/2d/DrawTargetCapture.h @@ -106,6 +106,7 @@ public: bool aCopyBackground) override; virtual void PopLayer() override; virtual void Blur(const AlphaBoxBlur& aBlur) override; + virtual void PadEdges(const IntRegion& aRegion) override; virtual void SetTransform(const Matrix &aTransform) override; diff --git a/gfx/2d/DrawTargetTiled.cpp b/gfx/2d/DrawTargetTiled.cpp index ffb90d8a11fd..8d5b2ac19eb4 100644 --- a/gfx/2d/DrawTargetTiled.cpp +++ b/gfx/2d/DrawTargetTiled.cpp @@ -387,5 +387,28 @@ DrawTargetTiled::PopLayer() mPushedLayers.pop_back(); } +void +DrawTargetTiled::PadEdges(const IntRegion& aRegion) +{ + for (size_t i = 0; i < mTiles.size(); i++) { + if (mTiles[i].mClippedOut) { + continue; + } + + auto tileRect = RoundedOut(Rect(mTiles[i].mTileOrigin.x, + mTiles[i].mTileOrigin.y, + mTiles[i].mDrawTarget->GetSize().width, + mTiles[i].mDrawTarget->GetSize().height)); + + // We only need to pad edges on tiles that intersect the edge of the region + if (aRegion.Intersects(tileRect) && !aRegion.Contains(tileRect)) { + IntRegion padRegion = aRegion; + padRegion.MoveBy(-mTiles[i].mTileOrigin); + padRegion.AndWith(IntRect(0, 0, mTiles[i].mDrawTarget->GetSize().width, mTiles[i].mDrawTarget->GetSize().height)); + mTiles[i].mDrawTarget->PadEdges(padRegion); + } + } +} + } // namespace gfx } // namespace mozilla diff --git a/gfx/2d/DrawTargetTiled.h b/gfx/2d/DrawTargetTiled.h index 15c96e96d1cd..4b029c5da7c2 100644 --- a/gfx/2d/DrawTargetTiled.h +++ b/gfx/2d/DrawTargetTiled.h @@ -124,6 +124,7 @@ public: CompositionOp = CompositionOp::OP_OVER) override; virtual void PopLayer() override; + virtual void PadEdges(const IntRegion& aRegion) override; virtual void SetTransform(const Matrix &aTransform) override; diff --git a/gfx/2d/moz.build b/gfx/2d/moz.build index e72140c9aa29..125613e3e84c 100644 --- a/gfx/2d/moz.build +++ b/gfx/2d/moz.build @@ -163,6 +163,7 @@ elif CONFIG['CPU_ARCH'].startswith('mips'): UNIFIED_SOURCES += [ 'BezierUtils.cpp', 'Blur.cpp', + 'BufferEdgePad.cpp', 'CaptureCommandList.cpp', 'DataSourceSurface.cpp', 'DataSurfaceHelpers.cpp', diff --git a/gfx/layers/PaintThread.cpp b/gfx/layers/PaintThread.cpp index e16add4ead05..aaa146fda02f 100644 --- a/gfx/layers/PaintThread.cpp +++ b/gfx/layers/PaintThread.cpp @@ -12,7 +12,6 @@ #include "gfxPlatform.h" #include "gfxPrefs.h" #include "GeckoProfiler.h" -#include "mozilla/layers/BufferEdgePad.h" #include "mozilla/layers/CompositorBridgeChild.h" #include "mozilla/layers/ShadowLayers.h" #include "mozilla/layers/SyncObject.h" diff --git a/gfx/layers/TextureSync.cpp b/gfx/layers/TextureSync.cpp index 2f3a6bf4e9e3..316f9c2fe2bc 100644 --- a/gfx/layers/TextureSync.cpp +++ b/gfx/layers/TextureSync.cpp @@ -8,6 +8,7 @@ #include +#include "base/process_util.h" #include "chrome/common/mach_ipc_mac.h" #include "mozilla/ipc/SharedMemoryBasic.h" #include "mozilla/layers/CompositorThread.h" @@ -211,7 +212,7 @@ TextureSync::Shutdown() void TextureSync::UpdateTextureLocks(base::ProcessId aProcessId) { - if (aProcessId == getpid()) { + if (aProcessId == base::GetCurrentProcId()) { DispatchCheckTexturesForUnlock(); return; } @@ -224,7 +225,7 @@ TextureSync::UpdateTextureLocks(base::ProcessId aProcessId) bool TextureSync::WaitForTextures(base::ProcessId aProcessId, const nsTArray& textureIds) { - if (aProcessId == getpid()) { + if (aProcessId == base::GetCurrentProcId()) { bool success = WaitForTextureIdsToUnlock(aProcessId, MakeSpan(textureIds)); if (!success) { LOG_ERROR("Failed waiting for textures to unlock.\n"); @@ -243,7 +244,7 @@ TextureSync::WaitForTextures(base::ProcessId aProcessId, const nsTArraypid = getpid(); + req->pid = base::GetCurrentProcId(); bool dataWasSet = smsg.SetData(req, messageSize); if (!dataWasSet) { diff --git a/gfx/layers/moz.build b/gfx/layers/moz.build index f0ebc6fa2dea..a33cf6f24334 100755 --- a/gfx/layers/moz.build +++ b/gfx/layers/moz.build @@ -125,7 +125,6 @@ EXPORTS.mozilla.layers += [ 'basic/MacIOSurfaceTextureHostBasic.h', 'basic/TextureHostBasic.h', 'BSPTree.h', - 'BufferEdgePad.h', 'BufferTexture.h', 'CanvasRenderer.h', 'client/CanvasClient.h', @@ -354,7 +353,6 @@ UNIFIED_SOURCES += [ 'basic/BasicPaintedLayer.cpp', 'basic/TextureHostBasic.cpp', 'BSPTree.cpp', - 'BufferEdgePad.cpp', 'BufferTexture.cpp', 'BufferUnrotate.cpp', 'CanvasRenderer.cpp', diff --git a/gfx/src/nsRegion.cpp b/gfx/src/nsRegion.cpp index e16ae48a8d21..037e17a553d6 100644 --- a/gfx/src/nsRegion.cpp +++ b/gfx/src/nsRegion.cpp @@ -289,7 +289,7 @@ void nsRegion::SimplifyOutwardByArea(uint32_t aThreshold) typedef void (*visit_fn)(void *closure, VisitSide side, int x1, int y1, int x2, int y2); -void nsRegion::VisitEdges (visit_fn visit, void *closure) +void nsRegion::VisitEdges (visit_fn visit, void *closure) const { if (mBands.IsEmpty()) { visit(closure, VisitSide::LEFT, mBounds.X(), mBounds.Y(), mBounds.X(), mBounds.YMost()); @@ -310,7 +310,7 @@ void nsRegion::VisitEdges (visit_fn visit, void *closure) if (band != bandFinal) { do { - Band& topBand = *band; + const Band& topBand = *band; band++; for (const Strip& strip : band->mStrips) { @@ -320,7 +320,7 @@ void nsRegion::VisitEdges (visit_fn visit, void *closure) if (band->top == topBand.bottom) { // Two bands touching each other vertically. - Band& bottomBand = *band; + const Band& bottomBand = *band; auto topStrip = std::begin(topBand.mStrips); auto bottomStrip = std::begin(bottomBand.mStrips); diff --git a/gfx/src/nsRegion.h b/gfx/src/nsRegion.h index 3048f6e0e980..29a8d799773c 100644 --- a/gfx/src/nsRegion.h +++ b/gfx/src/nsRegion.h @@ -1949,7 +1949,7 @@ public: * are the coordinates of the line. (x1 == x2) || (y1 == y2) */ typedef void(*visitFn)(void *closure, VisitSide side, int x1, int y1, int x2, int y2); - void VisitEdges(visitFn, void *closure); + void VisitEdges(visitFn, void *closure) const; nsCString ToString() const; @@ -2564,7 +2564,7 @@ public: } typedef void (*visitFn)(void *closure, VisitSide side, int x1, int y1, int x2, int y2); - void VisitEdges (visitFn visit, void *closure) + void VisitEdges (visitFn visit, void *closure) const { mImpl.VisitEdges (visit, closure); }