gecko-dev/gfx/2d/DrawTargetCapture.cpp

202 строки
5.7 KiB
C++
Исходник Обычный вид История

/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
* 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 "DrawTargetCapture.h"
#include "DrawCommand.h"
namespace mozilla {
namespace gfx {
DrawTargetCaptureImpl::~DrawTargetCaptureImpl()
{
uint8_t* start = &mDrawCommandStorage.front();
uint8_t* current = start;
while (current < start + mDrawCommandStorage.size()) {
reinterpret_cast<DrawingCommand*>(current + sizeof(uint32_t))->~DrawingCommand();
current += *(uint32_t*)current;
}
}
bool
DrawTargetCaptureImpl::Init(const IntSize& aSize, DrawTarget* aRefDT)
{
if (!aRefDT) {
return false;
}
mRefDT = aRefDT;
mSize = aSize;
return true;
}
already_AddRefed<SourceSurface>
DrawTargetCaptureImpl::Snapshot()
{
Bug 1207245 - part 6 - rename nsRefPtr<T> to RefPtr<T>; r=ehsan; a=Tomcat The bulk of this commit was generated with a script, executed at the top level of a typical source code checkout. The only non-machine-generated part was modifying MFBT's moz.build to reflect the new naming. CLOSED TREE makes big refactorings like this a piece of cake. # The main substitution. find . -name '*.cpp' -o -name '*.cc' -o -name '*.h' -o -name '*.mm' -o -name '*.idl'| \ xargs perl -p -i -e ' s/nsRefPtr\.h/RefPtr\.h/g; # handle includes s/nsRefPtr ?</RefPtr</g; # handle declarations and variables ' # Handle a special friend declaration in gfx/layers/AtomicRefCountedWithFinalize.h. perl -p -i -e 's/::nsRefPtr;/::RefPtr;/' gfx/layers/AtomicRefCountedWithFinalize.h # Handle nsRefPtr.h itself, a couple places that define constructors # from nsRefPtr, and code generators specially. We do this here, rather # than indiscriminantly s/nsRefPtr/RefPtr/, because that would rename # things like nsRefPtrHashtable. perl -p -i -e 's/nsRefPtr/RefPtr/g' \ mfbt/nsRefPtr.h \ xpcom/glue/nsCOMPtr.h \ xpcom/base/OwningNonNull.h \ ipc/ipdl/ipdl/lower.py \ ipc/ipdl/ipdl/builtin.py \ dom/bindings/Codegen.py \ python/lldbutils/lldbutils/utils.py # In our indiscriminate substitution above, we renamed # nsRefPtrGetterAddRefs, the class behind getter_AddRefs. Fix that up. find . -name '*.cpp' -o -name '*.h' -o -name '*.idl' | \ xargs perl -p -i -e 's/nsRefPtrGetterAddRefs/RefPtrGetterAddRefs/g' if [ -d .git ]; then git mv mfbt/nsRefPtr.h mfbt/RefPtr.h else hg mv mfbt/nsRefPtr.h mfbt/RefPtr.h fi --HG-- rename : mfbt/nsRefPtr.h => mfbt/RefPtr.h
2015-10-18 08:24:48 +03:00
RefPtr<DrawTarget> dt = mRefDT->CreateSimilarDrawTarget(mSize, mRefDT->GetFormat());
ReplayToDrawTarget(dt, Matrix());
return dt->Snapshot();
}
void
DrawTargetCaptureImpl::DetachAllSnapshots()
{}
#define AppendCommand(arg) new (AppendToCommandList<arg>()) arg
void
DrawTargetCaptureImpl::DrawSurface(SourceSurface *aSurface,
const Rect &aDest,
const Rect &aSource,
const DrawSurfaceOptions &aSurfOptions,
const DrawOptions &aOptions)
{
aSurface->GuaranteePersistance();
AppendCommand(DrawSurfaceCommand)(aSurface, aDest, aSource, aSurfOptions, aOptions);
}
void
DrawTargetCaptureImpl::DrawFilter(FilterNode *aNode,
const Rect &aSourceRect,
const Point &aDestPoint,
const DrawOptions &aOptions)
{
// @todo XXX - this won't work properly long term yet due to filternodes not
// being immutable.
AppendCommand(DrawFilterCommand)(aNode, aSourceRect, aDestPoint, aOptions);
}
void
DrawTargetCaptureImpl::ClearRect(const Rect &aRect)
{
AppendCommand(ClearRectCommand)(aRect);
}
void
DrawTargetCaptureImpl::MaskSurface(const Pattern &aSource,
SourceSurface *aMask,
Point aOffset,
const DrawOptions &aOptions)
{
aMask->GuaranteePersistance();
AppendCommand(MaskSurfaceCommand)(aSource, aMask, aOffset, aOptions);
}
void
DrawTargetCaptureImpl::CopySurface(SourceSurface* aSurface,
const IntRect& aSourceRect,
const IntPoint& aDestination)
{
aSurface->GuaranteePersistance();
AppendCommand(CopySurfaceCommand)(aSurface, aSourceRect, aDestination);
}
void
DrawTargetCaptureImpl::FillRect(const Rect& aRect,
const Pattern& aPattern,
const DrawOptions& aOptions)
{
AppendCommand(FillRectCommand)(aRect, aPattern, aOptions);
}
void
DrawTargetCaptureImpl::StrokeRect(const Rect& aRect,
const Pattern& aPattern,
const StrokeOptions& aStrokeOptions,
const DrawOptions& aOptions)
{
AppendCommand(StrokeRectCommand)(aRect, aPattern, aStrokeOptions, aOptions);
}
void
DrawTargetCaptureImpl::StrokeLine(const Point& aStart,
const Point& aEnd,
const Pattern& aPattern,
const StrokeOptions& aStrokeOptions,
const DrawOptions& aOptions)
{
AppendCommand(StrokeLineCommand)(aStart, aEnd, aPattern, aStrokeOptions, aOptions);
}
void
DrawTargetCaptureImpl::Stroke(const Path* aPath,
const Pattern& aPattern,
const StrokeOptions& aStrokeOptions,
const DrawOptions& aOptions)
{
AppendCommand(StrokeCommand)(aPath, aPattern, aStrokeOptions, aOptions);
}
void
DrawTargetCaptureImpl::Fill(const Path* aPath,
const Pattern& aPattern,
const DrawOptions& aOptions)
{
AppendCommand(FillCommand)(aPath, aPattern, aOptions);
}
void
DrawTargetCaptureImpl::FillGlyphs(ScaledFont* aFont,
const GlyphBuffer& aBuffer,
const Pattern& aPattern,
const DrawOptions& aOptions,
const GlyphRenderingOptions* aRenderingOptions)
{
AppendCommand(FillGlyphsCommand)(aFont, aBuffer, aPattern, aOptions, aRenderingOptions);
}
void
DrawTargetCaptureImpl::Mask(const Pattern &aSource,
const Pattern &aMask,
const DrawOptions &aOptions)
{
AppendCommand(MaskCommand)(aSource, aMask, aOptions);
}
void
DrawTargetCaptureImpl::PushClip(const Path* aPath)
{
AppendCommand(PushClipCommand)(aPath);
}
void
DrawTargetCaptureImpl::PushClipRect(const Rect& aRect)
{
AppendCommand(PushClipRectCommand)(aRect);
}
void
DrawTargetCaptureImpl::PopClip()
{
AppendCommand(PopClipCommand)();
}
void
DrawTargetCaptureImpl::SetTransform(const Matrix& aTransform)
{
AppendCommand(SetTransformCommand)(aTransform);
}
void
DrawTargetCaptureImpl::ReplayToDrawTarget(DrawTarget* aDT, const Matrix& aTransform)
{
uint8_t* start = &mDrawCommandStorage.front();
uint8_t* current = start;
while (current < start + mDrawCommandStorage.size()) {
reinterpret_cast<DrawingCommand*>(current + sizeof(uint32_t))->ExecuteOnDT(aDT, &aTransform);
current += *(uint32_t*)current;
}
}
} // namespace gfx
} // namespace mozilla