зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1480620. Add DrawTargetOffset. r=bas
This adds a DrawTargetOffset which is basically a simplified DrawTargetTiled that only supports one tile. It useful for situations where Cairo's device offset was used previously. This also replaces WebRender's use of DrawTargetTiled which was just trying to apply offset. MozReview-Commit-ID: I33PB6CnHh0 --HG-- extra : rebase_source : 9fa51a0180343231cfca41daa0e3fa53f1b7befe
This commit is contained in:
Родитель
91ec49bade
Коммит
8715d55e01
|
@ -1761,6 +1761,7 @@ public:
|
|||
* and format.
|
||||
*/
|
||||
static already_AddRefed<DrawTarget> CreateTiledDrawTarget(const TileSet& aTileSet);
|
||||
static already_AddRefed<DrawTarget> CreateOffsetDrawTarget(DrawTarget *aDrawTarget, IntPoint aTileOrigin);
|
||||
|
||||
static bool DoesBackendSupportDataDrawtarget(BackendType aType);
|
||||
|
||||
|
|
|
@ -0,0 +1,192 @@
|
|||
/* -*- 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 "DrawTargetOffset.h"
|
||||
#include "Logging.h"
|
||||
#include "PathHelpers.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace mozilla {
|
||||
namespace gfx {
|
||||
|
||||
DrawTargetOffset::DrawTargetOffset()
|
||||
{
|
||||
}
|
||||
|
||||
bool
|
||||
DrawTargetOffset::Init(DrawTarget *aDrawTarget, IntPoint aOrigin)
|
||||
{
|
||||
mDrawTarget = aDrawTarget;
|
||||
mOrigin = aOrigin;
|
||||
mDrawTarget->SetTransform(Matrix::Translation(-mOrigin.x,
|
||||
-mOrigin.y));
|
||||
mFormat = mDrawTarget->GetFormat();
|
||||
SetPermitSubpixelAA(IsOpaque(mFormat));
|
||||
return true;
|
||||
}
|
||||
|
||||
already_AddRefed<SourceSurface>
|
||||
DrawTargetOffset::Snapshot()
|
||||
{
|
||||
return mDrawTarget->Snapshot();
|
||||
}
|
||||
|
||||
void
|
||||
DrawTargetOffset::DetachAllSnapshots()
|
||||
{}
|
||||
|
||||
// Skip the mClippedOut check since this is only used for Flush() which
|
||||
// should happen even if we're clipped.
|
||||
#define OFFSET_COMMAND(command) \
|
||||
void \
|
||||
DrawTargetOffset::command() \
|
||||
{ \
|
||||
mDrawTarget->command(); \
|
||||
}
|
||||
#define OFFSET_COMMAND1(command, type1) \
|
||||
void \
|
||||
DrawTargetOffset::command(type1 arg1) \
|
||||
{ \
|
||||
mDrawTarget->command(arg1); \
|
||||
}
|
||||
#define OFFSET_COMMAND3(command, type1, type2, type3) \
|
||||
void \
|
||||
DrawTargetOffset::command(type1 arg1, type2 arg2, type3 arg3) \
|
||||
{ \
|
||||
mDrawTarget->command(arg1, arg2, arg3); \
|
||||
}
|
||||
#define OFFSET_COMMAND4(command, type1, type2, type3, type4) \
|
||||
void \
|
||||
DrawTargetOffset::command(type1 arg1, type2 arg2, type3 arg3, type4 arg4) \
|
||||
{ \
|
||||
mDrawTarget->command(arg1, arg2, arg3, arg4); \
|
||||
}
|
||||
#define OFFSET_COMMAND5(command, type1, type2, type3, type4, type5) \
|
||||
void \
|
||||
DrawTargetOffset::command(type1 arg1, type2 arg2, type3 arg3, type4 arg4, type5 arg5) \
|
||||
{ \
|
||||
mDrawTarget->command(arg1, arg2, arg3, arg4, arg5); \
|
||||
}
|
||||
|
||||
OFFSET_COMMAND(Flush)
|
||||
OFFSET_COMMAND4(DrawFilter, FilterNode*, const Rect&, const Point&, const DrawOptions&)
|
||||
OFFSET_COMMAND1(ClearRect, const Rect&)
|
||||
OFFSET_COMMAND4(MaskSurface, const Pattern&, SourceSurface*, Point, const DrawOptions&)
|
||||
OFFSET_COMMAND4(FillGlyphs, ScaledFont*, const GlyphBuffer&, const Pattern&, const DrawOptions&)
|
||||
OFFSET_COMMAND3(Mask, const Pattern&, const Pattern&, const DrawOptions&)
|
||||
|
||||
void
|
||||
DrawTargetOffset::PushClip(const Path* aPath)
|
||||
{
|
||||
mDrawTarget->PushClip(aPath);
|
||||
}
|
||||
|
||||
void
|
||||
DrawTargetOffset::PushClipRect(const Rect& aRect)
|
||||
{
|
||||
mDrawTarget->PushClipRect(aRect);
|
||||
}
|
||||
|
||||
void
|
||||
DrawTargetOffset::PopClip()
|
||||
{
|
||||
mDrawTarget->PopClip();
|
||||
}
|
||||
|
||||
void
|
||||
DrawTargetOffset::CopySurface(SourceSurface *aSurface,
|
||||
const IntRect &aSourceRect,
|
||||
const IntPoint &aDestination)
|
||||
{
|
||||
IntPoint tileOrigin = mOrigin;
|
||||
// CopySurface ignores the transform, account for that here.
|
||||
mDrawTarget->CopySurface(aSurface, aSourceRect, aDestination - tileOrigin);
|
||||
}
|
||||
|
||||
void
|
||||
DrawTargetOffset::SetTransform(const Matrix& aTransform)
|
||||
{
|
||||
Matrix mat = aTransform;
|
||||
mat.PostTranslate(Float(-mOrigin.x), Float(-mOrigin.y));
|
||||
mDrawTarget->SetTransform(mat);
|
||||
|
||||
DrawTarget::SetTransform(aTransform);
|
||||
}
|
||||
|
||||
void
|
||||
DrawTargetOffset::SetPermitSubpixelAA(bool aPermitSubpixelAA)
|
||||
{
|
||||
mDrawTarget->SetPermitSubpixelAA(aPermitSubpixelAA);
|
||||
}
|
||||
|
||||
void
|
||||
DrawTargetOffset::DrawSurface(SourceSurface* aSurface, const Rect& aDest, const Rect& aSource, const DrawSurfaceOptions& aSurfaceOptions, const DrawOptions& aDrawOptions)
|
||||
{
|
||||
mDrawTarget->DrawSurface(aSurface, aDest, aSource, aSurfaceOptions, aDrawOptions);
|
||||
}
|
||||
|
||||
void
|
||||
DrawTargetOffset::FillRect(const Rect& aRect, const Pattern& aPattern, const DrawOptions& aDrawOptions)
|
||||
{
|
||||
mDrawTarget->FillRect(aRect, aPattern, aDrawOptions);
|
||||
}
|
||||
|
||||
void
|
||||
DrawTargetOffset::Stroke(const Path* aPath, const Pattern& aPattern, const StrokeOptions& aStrokeOptions, const DrawOptions& aDrawOptions)
|
||||
{
|
||||
mDrawTarget->Stroke(aPath, aPattern, aStrokeOptions, aDrawOptions);
|
||||
}
|
||||
|
||||
void
|
||||
DrawTargetOffset::StrokeRect(const Rect& aRect, const Pattern& aPattern, const StrokeOptions &aStrokeOptions, const DrawOptions& aDrawOptions)
|
||||
{
|
||||
mDrawTarget->StrokeRect(aRect, aPattern, aStrokeOptions, aDrawOptions);
|
||||
}
|
||||
|
||||
void
|
||||
DrawTargetOffset::StrokeLine(const Point& aStart, const Point& aEnd, const Pattern& aPattern, const StrokeOptions &aStrokeOptions, const DrawOptions& aDrawOptions)
|
||||
{
|
||||
mDrawTarget->StrokeLine(aStart, aEnd, aPattern, aStrokeOptions, aDrawOptions);
|
||||
}
|
||||
|
||||
void
|
||||
DrawTargetOffset::Fill(const Path* aPath, const Pattern& aPattern, const DrawOptions& aDrawOptions)
|
||||
{
|
||||
mDrawTarget->Fill(aPath, aPattern, aDrawOptions);
|
||||
}
|
||||
|
||||
void
|
||||
DrawTargetOffset::PushLayer(bool aOpaque, Float aOpacity, SourceSurface* aMask,
|
||||
const Matrix& aMaskTransform, const IntRect& aBounds,
|
||||
bool aCopyBackground)
|
||||
{
|
||||
IntRect bounds = aBounds;
|
||||
bounds.MoveBy(mOrigin);
|
||||
mDrawTarget->PushLayer(aOpaque, aOpacity, aMask, aMaskTransform, bounds, aCopyBackground);
|
||||
}
|
||||
|
||||
void
|
||||
DrawTargetOffset::PushLayerWithBlend(bool aOpaque, Float aOpacity,
|
||||
SourceSurface* aMask,
|
||||
const Matrix& aMaskTransform,
|
||||
const IntRect& aBounds,
|
||||
bool aCopyBackground,
|
||||
CompositionOp aOp)
|
||||
{
|
||||
IntRect bounds = aBounds;
|
||||
bounds.MoveBy(mOrigin);
|
||||
mDrawTarget->PushLayerWithBlend(aOpaque, aOpacity, aMask, aMaskTransform, bounds, aCopyBackground, aOp);
|
||||
}
|
||||
|
||||
void
|
||||
DrawTargetOffset::PopLayer()
|
||||
{
|
||||
mDrawTarget->PopLayer();
|
||||
}
|
||||
|
||||
} // namespace gfx
|
||||
} // namespace mozilla
|
|
@ -0,0 +1,167 @@
|
|||
/* -*- 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/. */
|
||||
|
||||
#ifndef MOZILLA_GFX_DRAWTARGETOFFSET_H_
|
||||
#define MOZILLA_GFX_DRAWTARGETOFFSET_H_
|
||||
|
||||
#include "2D.h"
|
||||
|
||||
#include "mozilla/Vector.h"
|
||||
|
||||
#include "Filters.h"
|
||||
#include "Logging.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace mozilla {
|
||||
namespace gfx {
|
||||
|
||||
class DrawTargetOffset : public DrawTarget
|
||||
{
|
||||
public:
|
||||
DrawTargetOffset();
|
||||
|
||||
bool Init(DrawTarget *aDrawTarget, IntPoint aOrigin);
|
||||
|
||||
// We'll pestimistically return true here
|
||||
virtual bool IsTiledDrawTarget() const override { return true; }
|
||||
|
||||
virtual bool IsCaptureDT() const override { return mDrawTarget->IsCaptureDT(); }
|
||||
virtual DrawTargetType GetType() const override { return mDrawTarget->GetType(); }
|
||||
virtual BackendType GetBackendType() const override { return mDrawTarget->GetBackendType(); }
|
||||
virtual already_AddRefed<SourceSurface> Snapshot() override;
|
||||
virtual void DetachAllSnapshots() override;
|
||||
virtual IntSize GetSize() const override {
|
||||
return mDrawTarget->GetSize();
|
||||
}
|
||||
virtual IntRect GetRect() const override {
|
||||
return mDrawTarget->GetRect();
|
||||
}
|
||||
|
||||
virtual void Flush() override;
|
||||
virtual void DrawSurface(SourceSurface *aSurface,
|
||||
const Rect &aDest,
|
||||
const Rect &aSource,
|
||||
const DrawSurfaceOptions &aSurfOptions,
|
||||
const DrawOptions &aOptions) override;
|
||||
virtual void DrawFilter(FilterNode *aNode,
|
||||
const Rect &aSourceRect,
|
||||
const Point &aDestPoint,
|
||||
const DrawOptions &aOptions = DrawOptions()) override;
|
||||
virtual void DrawSurfaceWithShadow(SourceSurface *aSurface,
|
||||
const Point &aDest,
|
||||
const Color &aColor,
|
||||
const Point &aOffset,
|
||||
Float aSigma,
|
||||
CompositionOp aOperator) override { /* Not implemented */ MOZ_CRASH("GFX: DrawSurfaceWithShadow"); }
|
||||
|
||||
virtual void ClearRect(const Rect &aRect) override;
|
||||
virtual void MaskSurface(const Pattern &aSource,
|
||||
SourceSurface *aMask,
|
||||
Point aOffset,
|
||||
const DrawOptions &aOptions = DrawOptions()) override;
|
||||
|
||||
virtual void CopySurface(SourceSurface *aSurface,
|
||||
const IntRect &aSourceRect,
|
||||
const IntPoint &aDestination) override;
|
||||
|
||||
virtual void FillRect(const Rect &aRect,
|
||||
const Pattern &aPattern,
|
||||
const DrawOptions &aOptions = DrawOptions()) override;
|
||||
virtual void StrokeRect(const Rect &aRect,
|
||||
const Pattern &aPattern,
|
||||
const StrokeOptions &aStrokeOptions = StrokeOptions(),
|
||||
const DrawOptions &aOptions = DrawOptions()) override;
|
||||
virtual void StrokeLine(const Point &aStart,
|
||||
const Point &aEnd,
|
||||
const Pattern &aPattern,
|
||||
const StrokeOptions &aStrokeOptions = StrokeOptions(),
|
||||
const DrawOptions &aOptions = DrawOptions()) override;
|
||||
virtual void Stroke(const Path *aPath,
|
||||
const Pattern &aPattern,
|
||||
const StrokeOptions &aStrokeOptions = StrokeOptions(),
|
||||
const DrawOptions &aOptions = DrawOptions()) override;
|
||||
virtual void Fill(const Path *aPath,
|
||||
const Pattern &aPattern,
|
||||
const DrawOptions &aOptions = DrawOptions()) override;
|
||||
virtual void FillGlyphs(ScaledFont *aFont,
|
||||
const GlyphBuffer &aBuffer,
|
||||
const Pattern &aPattern,
|
||||
const DrawOptions &aOptions = DrawOptions()) override;
|
||||
virtual void Mask(const Pattern &aSource,
|
||||
const Pattern &aMask,
|
||||
const DrawOptions &aOptions = DrawOptions()) override;
|
||||
virtual void PushClip(const Path *aPath) override;
|
||||
virtual void PushClipRect(const Rect &aRect) override;
|
||||
virtual void PopClip() override;
|
||||
virtual void PushLayer(bool aOpaque, Float aOpacity,
|
||||
SourceSurface* aMask,
|
||||
const Matrix& aMaskTransform,
|
||||
const IntRect& aBounds = IntRect(),
|
||||
bool aCopyBackground = false) override;
|
||||
virtual void PushLayerWithBlend(bool aOpaque, Float aOpacity,
|
||||
SourceSurface* aMask,
|
||||
const Matrix& aMaskTransform,
|
||||
const IntRect& aBounds = IntRect(),
|
||||
bool aCopyBackground = false,
|
||||
CompositionOp = CompositionOp::OP_OVER) override;
|
||||
virtual void PopLayer() override;
|
||||
|
||||
|
||||
virtual void SetTransform(const Matrix &aTransform) override;
|
||||
|
||||
virtual void SetPermitSubpixelAA(bool aPermitSubpixelAA) override;
|
||||
|
||||
virtual already_AddRefed<SourceSurface> CreateSourceSurfaceFromData(unsigned char *aData,
|
||||
const IntSize &aSize,
|
||||
int32_t aStride,
|
||||
SurfaceFormat aFormat) const override
|
||||
{
|
||||
return mDrawTarget->CreateSourceSurfaceFromData(aData, aSize, aStride, aFormat);
|
||||
}
|
||||
virtual already_AddRefed<SourceSurface> OptimizeSourceSurface(SourceSurface *aSurface) const override
|
||||
{
|
||||
return mDrawTarget->OptimizeSourceSurface(aSurface);
|
||||
}
|
||||
|
||||
virtual already_AddRefed<SourceSurface>
|
||||
CreateSourceSurfaceFromNativeSurface(const NativeSurface &aSurface) const override
|
||||
{
|
||||
return mDrawTarget->CreateSourceSurfaceFromNativeSurface(aSurface);
|
||||
}
|
||||
|
||||
virtual already_AddRefed<DrawTarget>
|
||||
CreateSimilarDrawTarget(const IntSize &aSize, SurfaceFormat aFormat) const override
|
||||
{
|
||||
return mDrawTarget->CreateSimilarDrawTarget(aSize, aFormat);
|
||||
}
|
||||
|
||||
virtual already_AddRefed<PathBuilder> CreatePathBuilder(FillRule aFillRule = FillRule::FILL_WINDING) const override
|
||||
{
|
||||
return mDrawTarget->CreatePathBuilder(aFillRule);
|
||||
}
|
||||
|
||||
virtual already_AddRefed<GradientStops>
|
||||
CreateGradientStops(GradientStop *aStops,
|
||||
uint32_t aNumStops,
|
||||
ExtendMode aExtendMode = ExtendMode::CLAMP) const override
|
||||
{
|
||||
return mDrawTarget->CreateGradientStops(aStops, aNumStops, aExtendMode);
|
||||
}
|
||||
virtual already_AddRefed<FilterNode> CreateFilter(FilterType aType) override
|
||||
{
|
||||
return mDrawTarget->CreateFilter(aType);
|
||||
}
|
||||
|
||||
private:
|
||||
RefPtr<DrawTarget> mDrawTarget;
|
||||
IntPoint mOrigin;
|
||||
};
|
||||
|
||||
} // namespace gfx
|
||||
} // namespace mozilla
|
||||
|
||||
#endif
|
|
@ -52,6 +52,7 @@
|
|||
#include "DrawTargetCapture.h"
|
||||
#include "DrawTargetDual.h"
|
||||
#include "DrawTargetTiled.h"
|
||||
#include "DrawTargetOffset.h"
|
||||
#include "DrawTargetWrapAndRecord.h"
|
||||
#include "DrawTargetRecording.h"
|
||||
|
||||
|
@ -543,6 +544,19 @@ Factory::CreateTiledDrawTarget(const TileSet& aTileSet)
|
|||
return dt.forget();
|
||||
}
|
||||
|
||||
already_AddRefed<DrawTarget>
|
||||
Factory::CreateOffsetDrawTarget(DrawTarget *aDrawTarget, IntPoint aTileOrigin)
|
||||
{
|
||||
RefPtr<DrawTargetOffset> dt = new DrawTargetOffset();
|
||||
|
||||
if (!dt->Init(aDrawTarget, aTileOrigin)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return dt.forget();
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
Factory::DoesBackendSupportDataDrawtarget(BackendType aType)
|
||||
{
|
||||
|
|
|
@ -24,6 +24,7 @@ EXPORTS.mozilla.gfx += [
|
|||
'CriticalSection.h',
|
||||
'DataSurfaceHelpers.h',
|
||||
'DrawEventRecorder.h',
|
||||
'DrawTargetOffset.h',
|
||||
'DrawTargetRecording.h',
|
||||
'DrawTargetTiled.h',
|
||||
'DrawTargetWrapAndRecord.h',
|
||||
|
@ -171,6 +172,7 @@ UNIFIED_SOURCES += [
|
|||
'DrawTargetCairo.cpp',
|
||||
'DrawTargetCapture.cpp',
|
||||
'DrawTargetDual.cpp',
|
||||
'DrawTargetOffset.cpp',
|
||||
'DrawTargetRecording.cpp',
|
||||
'DrawTargetTiled.cpp',
|
||||
'DrawTargetWrapAndRecord.cpp',
|
||||
|
|
Загрузка…
Ссылка в новой задаче